@Override public ReturnWithExceptions<Void, ModelObserver> aipCreated(final AIP aip) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); try { List<String> ancestors = SolrUtils.getAncestors(aip.getParentId(), model); indexAIP(aip, ancestors).addTo(ret); if (ret.isEmpty()) { indexRepresentations(aip, ancestors).addTo(ret); if (ret.isEmpty()) { indexPreservationsEvents(aip.getId(), null).addTo(ret); } } } catch (RequestNotValidException | GenericException | AuthorizationDeniedException e) { LOGGER.error("Error getting ancestors when creating AIP", e); ret.add(e); } return ret; }
private ReturnWithExceptions<Void, ModelObserver> indexAIP(final AIP aip, final List<String> ancestors, boolean safemode) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); SolrUtils.create2(index, (ModelObserver) this, IndexedAIP.class, aip, new AIPCollection.Info(ancestors, safemode)) .addTo(ret); // if there was an error indexing, try in safe mode if (!ret.isEmpty()) { if (!safemode) { LOGGER.error("Error indexing AIP, trying safe mode", ret.getExceptions().get(0)); indexAIP(aip, ancestors, true).addTo(ret); } else { LOGGER.error("Cannot index created AIP", ret.getExceptions().get(0)); } } return ret; }
public ReturnWithExceptions(List<Exception> errors, T ret, S source) { this.setExceptions(errors); this.setReturnedObject(ret); this.setSource(source); }
public void add(ReturnWithExceptions<?, S> ts) { add(ts.getExceptions()); }
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; }
@Override public ReturnWithExceptions<Void, ModelObserver> dipFileCreated(DIPFile file) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); try { DIP dip = model.retrieveDIP(file.getDipId()); indexDIPFile(dip, file, true).addTo(ret); } catch (NotFoundException | GenericException | AuthorizationDeniedException e) { LOGGER.error("Error indexing DIP file: {}", file, e); ret.add(e); } return ret; }
private ReturnWithExceptions<Long, ModelObserver> indexFile(AIP aip, File file, List<String> ancestors, boolean recursive) { ReturnWithExceptions<Long, ModelObserver> ret = new ReturnWithExceptions<>(this); Long sizeInBytes = 0L; FileCollection.Info info = new FileCollection.Info(aip, ancestors); SolrUtils.create2(index, (ModelObserver) this, IndexedFile.class, file, info).addTo(ret); sizeInBytes = (Long) info.getAccumulators().get(RodaConstants.FILE_SIZE); if (ret.isEmpty()) { if (recursive && file.isDirectory()) { try (CloseableIterable<OptionalWithCause<File>> allFiles = model.listFilesUnder(file, true)) { for (OptionalWithCause<File> subfile : allFiles) { if (subfile.isPresent()) { sizeInBytes += indexFile(aip, subfile.get(), ancestors, false).addTo(ret).getReturnedObject(); } else { LOGGER.error("Cannot index file", subfile.getCause()); ret.add(subfile.getCause()); } } } catch (NotFoundException | GenericException | RequestNotValidException | AuthorizationDeniedException | IOException e) { LOGGER.error("Cannot index file sub-resources: {}", file, e); ret.add(e); } } } else { LOGGER.error("Cannot index file: {}", file); } ret.setReturnedObject(sizeInBytes); return ret; }
private ReturnWithExceptions<Void, ModelObserver> indexRepresentation(final AIP aip, final Representation representation, final List<String> ancestors) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); Long sizeInBytes = 0L; Long numberOfDataFiles = 0L; for (OptionalWithCause<File> file : allFiles) { if (file.isPresent()) { sizeInBytes += indexFile(aip, file.get(), ancestors, false).addTo(ret).getReturnedObject(); ret.add(file.getCause()); SolrUtils.create2(index, (ModelObserver) this, IndexedRepresentation.class, representation, info).addTo(ret); } catch (IOException | RequestNotValidException | GenericException | NotFoundException | AuthorizationDeniedException e) { LOGGER.error("Cannot index representation", e); ret.add(e);
@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; }
@Override public ReturnWithExceptions<Void, ModelObserver> jobCreatedOrUpdated(Job job, boolean reindexJobReports) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); SolrUtils.create2(index, (ModelObserver) this, Job.class, job).addTo(ret); if (ret.isEmpty() && reindexJobReports) { indexJobReports(job).addTo(ret); } return ret; }
public <T extends Serializable> ReturnWithExceptions<Void, ModelObserver> reindex(T object) { ReturnWithExceptions<Void, ModelObserver> ret = RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseReturn(nodeType); if (!ret.isEmpty()) { return ret; } else { LOGGER.error("Error trying to reindex an unconfigured object class: {}", objectClass.getName()); ReturnWithExceptions<Void, ModelObserver> exceptions = new ReturnWithExceptions<>(); exceptions .add(new RODAException("Error trying to reindex an unconfigured object class: " + objectClass.getName())); return exceptions;
public boolean hasNoExceptions() { boolean isEmpty = true; for (ReturnWithExceptions<?, ?> item : list) { isEmpty = isEmpty && item.getExceptions().isEmpty(); } return isEmpty; }
public ReturnWithExceptions<Void, ModelObserver> reindexDIP(DIP dip) { ReturnWithExceptions<Void, ModelObserver> ret = RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseReturn(nodeType); if (ret.isEmpty()) { ret = observer.dipCreated(dip, false); } return ret; }
public ReturnWithExceptions<T, S> addTo(ReturnWithExceptions<?, S> ts) { ts.add(this); return this; }
@Override public ReturnWithExceptions<Void, ModelObserver> aipUpdated(AIP aip) { // TODO Is this the best way to update? ReturnWithExceptions<Void, ModelObserver> ret = aipDeleted(aip.getId(), false); aipCreated(aip).addTo(ret); return ret; }
@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 ReturnWithExceptionsWrapper reindexPreservationAgents() throws RequestNotValidException, GenericException { ReturnWithExceptionsWrapper wrapper = new ReturnWithExceptionsWrapper(); ReturnWithExceptions<Void, ModelObserver> ret = RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseReturn(nodeType); if (!ret.isEmpty()) { wrapper.addToList(ret); } else { try { wrapper = reindexPreservationMetadata(model.listPreservationAgents()); } catch (AuthorizationDeniedException e) { wrapper.addToList(new ReturnWithExceptions<>(e)); } } return wrapper; }
public String printStackTraces() { StringBuilder b = new StringBuilder(); list.forEach(e -> b.append(e.printStackTraces())); return b.toString(); }
public String printStackTraces() { String ret; try (ByteArrayOutputStream bout = new ByteArrayOutputStream(); PrintWriter w = new PrintWriter(bout, true);) { w.println(String.format("%1$s source=%2$s", getClass().getSimpleName(), getSource().getClass().getSimpleName())); exceptions.forEach(e -> { w.println(String.format("[%1$s] %2$s", e.getClass().getName(), e.getMessage())); e.printStackTrace(w); }); w.flush(); ret = new String(bout.toByteArray()); } catch (IOException e1) { ret = null; } return ret; }
private ReturnWithExceptions<Void, ModelObserver> indexPreservationEvent(PreservationMetadata pm) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); AIP aip = null; try { aip = model.retrieveAIP(pm.getAipId()); } catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException e) { LOGGER.error("Error indexing preservation events", e); ret.add(e); } SolrUtils.create2(index, (ModelObserver) this, IndexedPreservationEvent.class, pm, new PreservationEventCollection.Info(aip)).addTo(ret); return ret; }