public ReturnWithExceptions(List<Exception> errors, T ret, S source) { this.setExceptions(errors); this.setReturnedObject(ret); this.setSource(source); }
public ReturnWithExceptions<T, S> addTo(ReturnWithExceptions<?, S> ts) { ts.add(this); return this; }
public AuthorizationDeniedException(String message, List<String> missingRoles) { super(message); setMissingRoles(missingRoles); }
public void failOnError() throws GenericException { if (!hasNoExceptions()) { if (list.size() == 1 && list.get(0).getExceptions().size() == 1) { // if there is one and only one exception throw it throw new GenericException(list.get(0).getExceptions().get(0)); } else { LOGGER.error(printStackTraces()); throw MultipleGenericException.build(list); } } } }
@SuppressWarnings("unchecked") public static <T extends IsRODAObject> Class<T> parseClass(String classNameToReturn) throws GenericException { Class<T> classToReturn; try { classToReturn = (Class<T>) Class.forName(classNameToReturn); } catch (ClassNotFoundException e) { throw new GenericException("Could not find class " + classNameToReturn); } return classToReturn; } }
public void add(ReturnWithExceptions<?, S> ts) { add(ts.getExceptions()); }
public static MultipleGenericException build(List<ReturnWithExceptions<?, ?>> list) { List<Exception> causes = new ArrayList<>(); for (ReturnWithExceptions<?, ?> item : list) { for (Exception e : item.getExceptions()) { causes.add(e); } } return new MultipleGenericException(causes); }
public static ReturnWithExceptions<Void, ModelObserver> checkIfWriteIsAllowedAndIfFalseReturn(NodeType nodeType) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(); try { checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); } catch (AuthorizationDeniedException e) { ret.add(e); } return ret; }
public boolean hasNoExceptions() { boolean isEmpty = true; for (ReturnWithExceptions<?, ?> item : list) { isEmpty = isEmpty && item.getExceptions().isEmpty(); } return isEmpty; }
@Override public ReturnWithExceptions<Void, ModelObserver> aipDeleted(String aipId, boolean deleteIncidences) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); deleteDocumentFromIndex(IndexedAIP.class, aipId).addTo(ret); deleteDocumentsFromIndex(IndexedRepresentation.class, RodaConstants.REPRESENTATION_AIP_ID, aipId).addTo(ret); deleteDocumentsFromIndex(IndexedFile.class, RodaConstants.FILE_AIP_ID, aipId).addTo(ret); deleteDocumentsFromIndex(IndexedPreservationEvent.class, RodaConstants.PRESERVATION_EVENT_AIP_ID, aipId).addTo(ret); if (deleteIncidences) { deleteDocumentsFromIndex(RiskIncidence.class, RodaConstants.RISK_INCIDENCE_AIP_ID, aipId).addTo(ret); } return ret; }
public Path retrieveFilePath(String path) throws NotFoundException, RequestNotValidException, GenericException { Path p = basePath.resolve(path); if (!FSUtils.exists(p)) { throw new NotFoundException("File not found: " + path); } else if (!FSUtils.isFile(p)) { throw new RequestNotValidException("Requested file is not a regular file: " + path); } return p; }
@Override public ReturnWithExceptions<Void, ModelObserver> dipDeleted(String dipId, boolean commit) { ReturnWithExceptions<Void, ModelObserver> ret = deleteDocumentFromIndex(IndexedDIP.class, commit, dipId); if (ret.isEmpty()) { deleteDocumentsFromIndex(DIPFile.class, RodaConstants.DIPFILE_DIP_ID, dipId, commit).addTo(ret); } return ret; }
public static void throwExceptionIfWriteIsNotAllowed() throws AuthorizationDeniedException { throw new AuthorizationDeniedException("Cannot execute non read-only method in read-only instance"); }
public static Job getJob(String jobId, ModelService model) throws NotFoundException, GenericException, RequestNotValidException, AuthorizationDeniedException { if (jobId != null) { return model.retrieveJob(jobId); } else { throw new NotFoundException("Job not found"); } }
@Override public Binary getBinary(StoragePath storagePath) throws RequestNotValidException, NotFoundException, GenericException { Path binaryPath = FSUtils.getEntityPath(basePath, storagePath); Resource resource = FSUtils.convertPathToResource(basePath, binaryPath); if (resource instanceof Binary) { return (Binary) resource; } else { throw new RequestNotValidException("Looking for a binary but found something else"); } }
public ReturnWithExceptions(S source) { setExceptions(new ArrayList<Exception>()); setReturnedObject(null); setSource(source); }
private static String encodeId(String id) throws GenericException { if (id != null) { return id.replaceAll(SEPARATOR_REGEX, SEPARATOR_URL_ENCODED); } else { throw new GenericException("Was trying to encode an 'id' but it is NULL"); } }
public ReturnWithExceptions() { setExceptions(new ArrayList<Exception>()); setReturnedObject(null); setSource(null); }
public static Class<IsRODAObject> getSelectedClassFromString(String selectedClass) throws GenericException { try { Class<?> clazz = Class.forName(selectedClass); if (IsRODAObject.class.isAssignableFrom(clazz)) { return (Class<IsRODAObject>) clazz; } else { throw new GenericException("Error while getting class from string"); } } catch (ClassNotFoundException e) { throw new GenericException("Error while getting class from string"); } }
private static String decodeId(String id) throws GenericException { if (id != null) { return id.replaceAll(SEPARATOR_URL_ENCODED, SEPARATOR); } else { throw new GenericException("Was trying to decode an 'id' but it is NULL"); } }