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; }
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; }
private ReturnWithExceptions<Void, ModelObserver> indexRepresentations(final AIP aip, final List<String> ancestors) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); for (Representation representation : aip.getRepresentations()) { indexRepresentation(aip, representation, ancestors).addTo(ret); } return ret; }
private ReturnWithExceptions<Void, ModelObserver> representationsStateUpdated(final AIP aip) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); for (Representation representation : aip.getRepresentations()) { representationStateUpdated(aip, representation).addTo(ret); } return ret; }
private ReturnWithExceptions<Void, ModelObserver> representationsPermissionsUpdated(final AIP aip) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); for (Representation representation : aip.getRepresentations()) { representationPermissionsUpdated(aip, representation).addTo(ret); } 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> 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> 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 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; }
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; }
@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; }
@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; }
@Override public ReturnWithExceptions<Void, ModelObserver> fileDeleted(String aipId, String representationId, List<String> fileDirectoryPath, String fileId, boolean deleteIncidences) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); String uuid = IdUtils.getFileId(aipId, representationId, fileDirectoryPath, fileId); deleteDocumentFromIndex(IndexedFile.class, uuid).addTo(ret); if (deleteIncidences) { deleteDocumentsFromIndex(RiskIncidence.class, RodaConstants.RISK_INCIDENCE_FILE_ID, fileId).addTo(ret); } return ret; }
@Override public ReturnWithExceptions<Void, ModelObserver> preservationMetadataCreated(PreservationMetadata pm) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); PreservationMetadataType type = pm.getType(); if (PreservationMetadataType.EVENT.equals(type)) { indexPreservationEvent(pm).addTo(ret); } else if (PreservationMetadataType.AGENT.equals(type)) { SolrUtils.create2(index, (ModelObserver) this, IndexedPreservationAgent.class, pm).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; }
@Override public ReturnWithExceptions<Void, ModelObserver> aipStateUpdated(AIP aip) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); // change AIP SolrUtils .update(index, IndexedAIP.class, aip.getId(), Collections.singletonMap(RodaConstants.INDEX_STATE, SolrUtils.formatEnum(aip.getState())), (ModelObserver) this) .addTo(ret); if (ret.isEmpty()) { // change Representations, Files & Preservation events representationsStateUpdated(aip).addTo(ret); preservationEventsStateUpdated(aip).addTo(ret); } return ret; }
@Override public ReturnWithExceptions<Void, ModelObserver> preservationMetadataDeleted( PreservationMetadata preservationMetadata) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); PreservationMetadataType type = preservationMetadata.getType(); String preservationMetadataId = preservationMetadata.getId(); if (PreservationMetadataType.EVENT.equals(type)) { deleteDocumentFromIndex(IndexedPreservationEvent.class, preservationMetadataId).addTo(ret); } else if (PreservationMetadataType.AGENT.equals(type)) { deleteDocumentFromIndex(IndexedPreservationAgent.class, preservationMetadataId).addTo(ret); } return ret; }
@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> aipPermissionsUpdated(AIP aip) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); // change AIP SolrUtils.update(index, IndexedAIP.class, aip.getId(), SolrUtils.getPermissionsAsPreCalculatedFields(aip.getPermissions()), (ModelObserver) this).addTo(ret); if (ret.isEmpty()) { // change Representations, Files and Preservation events representationsPermissionsUpdated(aip).addTo(ret); preservationEventsPermissionsUpdated(aip).addTo(ret); } return ret; }