public ReturnWithExceptions<T, S> addTo(ReturnWithExceptions<?, S> ts) { ts.add(this); return this; }
@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<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; }
public void add(ReturnWithExceptions<?, S> ts) { add(ts.getExceptions()); }
public static <T extends IsIndexed, M extends IsModelObject, S extends Object> ReturnWithExceptions<Void, S> create( SolrClient index, Class<T> classToCreate, M instance, S source, boolean commit) { ReturnWithExceptions<Void, S> ret = new ReturnWithExceptions<>(); try { Optional<SolrInputDocument> solrDocument = Optional .of(SolrCollectionRegistry.toSolrDocument(classToCreate, instance)); if (solrDocument.isPresent()) { create(index, SolrCollectionRegistry.getIndexName(classToCreate), solrDocument.get(), source).addTo(ret); if (commit) { commit(index, classToCreate); } } } catch (NotSupportedException | GenericException | RequestNotValidException | NotFoundException | AuthorizationDeniedException e) { LOGGER.error("Error adding document to index", e); ret.add(e); } return ret; }
public static <T extends IsIndexed, S extends Object> ReturnWithExceptions<Void, S> create(SolrClient index, String classToCreate, SolrInputDocument instance, S source) { ReturnWithExceptions<Void, S> ret = new ReturnWithExceptions<>(source); if (instance != null) { try { index.add(classToCreate, instance); } catch (SolrServerException | IOException | SolrException e) { LOGGER.error("Error adding document to index", e); ret.add(e); } } return ret; }
@Override public ReturnWithExceptions<Void, ModelObserver> otherMetadataCreated(OtherMetadata otherMetadataBinary) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); if (RodaConstants.OTHER_METADATA_TYPE_APACHE_TIKA.equalsIgnoreCase(otherMetadataBinary.getType()) && RodaConstants.TIKA_FILE_SUFFIX_METADATA.equalsIgnoreCase(otherMetadataBinary.getFileSuffix())) { try { SolrInputDocument solrFile = SolrUtils.addOtherPropertiesToIndexedFile("tika_", otherMetadataBinary, model, index); SolrUtils.create(index, RodaConstants.INDEX_FILE, solrFile, (ModelObserver) this).addTo(ret); } catch (SolrServerException | RequestNotValidException | GenericException | NotFoundException | AuthorizationDeniedException | XPathExpressionException | ParserConfigurationException | SAXException | IOException e) { LOGGER.error("Error adding other properties to indexed file", e); ret.add(e); } } return ret; }
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 static <T extends IsIndexed, S extends Object> ReturnWithExceptions<Void, S> update(SolrClient index, Class<T> classToCreate, String uuid, Map<String, Object> fields, S source) { ReturnWithExceptions<Void, S> ret = new ReturnWithExceptions<>(); SolrInputDocument doc = new SolrInputDocument(); doc.addField(RodaConstants.INDEX_UUID, uuid); fields.entrySet().forEach(e -> doc.addField(e.getKey(), set(e.getValue()))); try { create(index, SolrCollectionRegistry.getIndexName(classToCreate), doc, source).addTo(ret); } catch (NotSupportedException e) { LOGGER.error("Error adding document to index", e); ret.add(e); } return ret; }
public static <T extends IsIndexed, S extends Object> ReturnWithExceptions<Void, S> delete(SolrClient index, Class<T> classToDelete, List<String> ids, S source, boolean commit) { ReturnWithExceptions<Void, S> ret = new ReturnWithExceptions<>(); try { index.deleteById(SolrCollectionRegistry.getIndexName(classToDelete), ids); if (commit) { commit(index, classToDelete); } } catch (SolrServerException | IOException | SolrException | GenericException | NotSupportedException e) { LOGGER.error("Error deleting document from index"); ret.add(e); } return ret; }
@Override public ReturnWithExceptions<Void, ModelObserver> descriptiveMetadataDeleted(String aipId, String representationId, String descriptiveMetadataBinaryId) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); if (representationId == null) { try { AIP aip = model.retrieveAIP(aipId); List<String> ancestors = SolrUtils.getAncestors(aip.getParentId(), model); indexAIP(aip, ancestors).addTo(ret); } catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException e) { LOGGER.error("Error when descriptive metadata deleted on retrieving the full AIP", e); ret.add(e); } } return ret; }
public static <I extends IsIndexed, M extends IsModelObject, S extends Object> ReturnWithExceptions<Void, S> create2( SolrClient index, S source, Class<I> indexClass, M object, IndexingAdditionalInfo utils) { ReturnWithExceptions<Void, S> ret = new ReturnWithExceptions<>(source); if (object != null) { try { SolrInputDocument solrDocument = SolrCollectionRegistry.toSolrDocument(indexClass, object, utils); if (solrDocument != null) { index.add(SolrCollectionRegistry.getIndexName(indexClass), solrDocument); } } catch (GenericException | NotSupportedException | RequestNotValidException | NotFoundException | AuthorizationDeniedException | SolrServerException | IOException e) { LOGGER.error("Error adding document to index", e); ret.add(e); } } return ret; }
@Override public ReturnWithExceptions<Void, ModelObserver> fileCreated(File file) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); try { AIP aip = model.retrieveAIP(file.getAipId()); List<String> ancestors = SolrUtils.getAncestors(aip.getParentId(), model); indexFile(aip, file, ancestors, true).addTo(ret); } catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException e) { LOGGER.error("Error indexing file: {}", file, e); ret.add(e); } return ret; }
public static <T extends IsIndexed, S extends Object> ReturnWithExceptions<Void, S> delete(SolrClient index, Class<T> classToDelete, Filter filter, S source, boolean commit) { ReturnWithExceptions<Void, S> ret = new ReturnWithExceptions<>(); try { index.deleteByQuery(SolrCollectionRegistry.getIndexName(classToDelete), parseFilter(filter)); if (commit) { commit(index, classToDelete); } } catch (SolrServerException | IOException | SolrException | GenericException | RequestNotValidException | NotSupportedException e) { LOGGER.error("Error deleting documents from index"); ret.add(e); } return ret; }
@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> indexDIPFile(DIP dip, DIPFile file, boolean recursive) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); SolrUtils.create2(index, (ModelObserver) this, DIPFile.class, file, new DIPFileCollection.Info(dip)).addTo(ret); if (recursive && file.isDirectory() && ret.isEmpty()) { try (CloseableIterable<OptionalWithCause<DIPFile>> allFiles = model.listDIPFilesUnder(file, true)) { for (OptionalWithCause<DIPFile> subfile : allFiles) { if (subfile.isPresent()) { indexDIPFile(dip, subfile.get(), false).addTo(ret); } else { LOGGER.error("Cannot index DIP file", subfile.getCause()); ret.add(subfile.getCause()); } } } catch (NotFoundException | GenericException | RequestNotValidException | AuthorizationDeniedException | IOException e) { LOGGER.error("Cannot index DIP file sub-resources: {}", file, e); ret.add(e); } } return ret; }
@Override public ReturnWithExceptions<Void, ModelObserver> representationCreated(Representation representation) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); try { AIP aip = model.retrieveAIP(representation.getAipId()); List<String> ancestors = SolrUtils.getAncestors(aip.getParentId(), model); indexRepresentation(aip, representation, ancestors).addTo(ret); if (ret.isEmpty()) { indexPreservationsEvents(aip.getId(), representation.getId()).addTo(ret); if (aip.getRepresentations().size() == 1) { SolrUtils.update(index, IndexedAIP.class, aip.getId(), Collections.singletonMap(RodaConstants.AIP_HAS_REPRESENTATIONS, true), (ModelObserver) this).addTo(ret); } } } catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException e) { LOGGER.error("Cannot index representation: {}", representation, e); ret.add(e); } return ret; }
@Override public ReturnWithExceptions<Void, ModelObserver> descriptiveMetadataCreated(DescriptiveMetadata descriptiveMetadata) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); try { AIP aip = model.retrieveAIP(descriptiveMetadata.getAipId()); List<String> ancestors = SolrUtils.getAncestors(aip.getParentId(), model); if (descriptiveMetadata.isFromAIP()) { indexAIP(aip, ancestors).addTo(ret); } else { Representation representation = model.retrieveRepresentation(descriptiveMetadata.getAipId(), descriptiveMetadata.getRepresentationId()); indexRepresentation(aip, representation, ancestors).addTo(ret); } } catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException e) { LOGGER.error("Failed to index AIP or representation when creating descriptive metadata", e); ret.add(e); } return ret; }
@Override public ReturnWithExceptions<Void, ModelObserver> descriptiveMetadataUpdated(DescriptiveMetadata descriptiveMetadata) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); try { AIP aip = model.retrieveAIP(descriptiveMetadata.getAipId()); List<String> ancestors = SolrUtils.getAncestors(aip.getParentId(), model); if (descriptiveMetadata.isFromAIP()) { indexAIP(aip, ancestors).addTo(ret); } else { Representation representation = model.retrieveRepresentation(descriptiveMetadata.getAipId(), descriptiveMetadata.getRepresentationId()); indexRepresentation(aip, representation, ancestors).addTo(ret); } } catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException e) { LOGGER.error("Failed to index AIP or representation when updating descriptive metadata", e); ret.add(e); } return ret; }
private ReturnWithExceptions<Void, ModelObserver> preservationEventsPermissionsUpdated(final AIP aip) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); try (CloseableIterable<OptionalWithCause<PreservationMetadata>> preservationMetadata = model .listPreservationMetadata(aip.getId(), true)) { for (OptionalWithCause<PreservationMetadata> opm : preservationMetadata) { if (opm.isPresent()) { PreservationMetadata pm = opm.get(); if (PreservationMetadataType.EVENT.equals(pm.getType())) { preservationEventPermissionsUpdated(pm, aip.getPermissions(), aip.getState()).addTo(ret); } } else { LOGGER.error("Cannot index premis event", opm.getCause()); ret.add(opm.getCause()); } } } catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException | IOException e) { LOGGER.error("Cannot index preservation events", e); ret.add(e); } return ret; }