@Override public String getUniqueId(AIP modelObject) { return modelObject.getId(); }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { String fileId = file.getFileName().toString(); List<String> directoryPath = extractDirectoryPath(transferredResourcePath, file); try { ContentPayload payload = new FSPathContentPayload(file); boolean notifyFileCreated = false; model.createFile(aip.getId(), representationId, directoryPath, fileId, payload, notifyFileCreated); } catch (RODAException e) { LOGGER.error("Could not create file on {}", file.toString(), e); } return FileVisitResult.CONTINUE; }
public static <T extends IsRODAObject> Optional<String> getSearchScopeFromParameters(Plugin<T> plugin, ModelService model) { Optional<String> ret = Optional.empty(); try { String searchScopeFromParameters = plugin.getParameterValues().get(RodaConstants.PLUGIN_PARAMS_PARENT_ID); if (StringUtils.isNotBlank(searchScopeFromParameters)) { AIP aip = model.retrieveAIP(searchScopeFromParameters); ret = Optional.ofNullable(aip.getId()); } } catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException e) { // do nothing } return ret; }
private void createEvent(VirusCheckResult virusCheckResult, Exception exception, PluginState state, AIP aip, ModelService model, IndexService index, boolean notify) throws PluginException { try { StringBuilder outcomeDetailExtension = new StringBuilder(); outcomeDetailExtension.append(virusCheckResult == null ? "" : virusCheckResult.getReport()); if (state != PluginState.SUCCESS && exception != null) { outcomeDetailExtension.append("\n").append(exception.getClass().getName()).append(": ") .append(exception.getMessage()); } PluginHelper.createPluginEvent(this, aip.getId(), model, index, state, outcomeDetailExtension.toString(), notify); } catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException | ValidationException | AlreadyExistsException e) { throw new PluginException("Error while creating the event", e); } }
private static Optional<String> createGhost(String ancestor, Optional<String> parent, ModelService model, IndexService index, String jobId) throws NotFoundException, GenericException, RequestNotValidException, AlreadyExistsException, AuthorizationDeniedException { String username = getJobUsername(jobId, index); Permissions permissions = new Permissions(); permissions.setUserPermissions(username, new HashSet<>(Arrays.asList(Permissions.PermissionType.CREATE, Permissions.PermissionType.READ, Permissions.PermissionType.UPDATE, Permissions.PermissionType.DELETE, Permissions.PermissionType.GRANT))); boolean isGhost = true; AIP ghostAIP = model.createAIP(parent.orElse(null), "", permissions, Arrays.asList(ancestor), jobId, true, username, isGhost); return Optional.ofNullable(ghostAIP.getId()); }
/***********************************************/ private void createAIPMetadata(AIP aip) throws RequestNotValidException, GenericException, AlreadyExistsException, AuthorizationDeniedException, NotFoundException { createAIPMetadata(aip, ModelUtils.getAIPStoragePath(aip.getId())); }
private void updateAIPMetadata(AIP aip) throws GenericException, NotFoundException, RequestNotValidException, AuthorizationDeniedException { updateAIPMetadata(aip, ModelUtils.getAIPStoragePath(aip.getId())); }
private void createIngestEvent(ModelService model, IndexService index, IngestJobPluginInfo jobPluginInfo, Date eventDate) { Map<String, List<String>> aipIdToTransferredResourceId = jobPluginInfo.getAipIdToTransferredResourceIds(); for (Map.Entry<String, List<String>> entry : aipIdToTransferredResourceId.entrySet()) { for (String transferredResourceId : entry.getValue()) { try { AIP aip = model.retrieveAIP(entry.getKey()); TransferredResource tr = index.retrieve(TransferredResource.class, transferredResourceId, Arrays.asList(RodaConstants.INDEX_UUID, RodaConstants.TRANSFERRED_RESOURCE_RELATIVEPATH)); PluginHelper.createPluginEvent(this, aip.getId(), model, index, tr, PluginState.SUCCESS, "", true, eventDate); } catch (NotFoundException | RequestNotValidException | GenericException | AuthorizationDeniedException | ValidationException | AlreadyExistsException e) { LOGGER.warn("Error creating ingest event", e); } } } }
private DescriptiveMetadata updateDescriptiveMetadata(AIP aip, String representationId, String descriptiveMetadataId, String descriptiveMetadataType, String descriptiveMetadataVersion) { DescriptiveMetadata descriptiveMetadata; Optional<DescriptiveMetadata> odm = getDescriptiveMetadata(aip, representationId).stream() .filter(dm -> dm.getId().equals(descriptiveMetadataId)).findFirst(); if (odm.isPresent()) { descriptiveMetadata = odm.get(); descriptiveMetadata.setType(descriptiveMetadataType); descriptiveMetadata.setVersion(descriptiveMetadataVersion); } else { descriptiveMetadata = new DescriptiveMetadata(descriptiveMetadataId, aip.getId(), representationId, descriptiveMetadataType, descriptiveMetadataVersion); aip.addDescriptiveMetadata(descriptiveMetadata); } return descriptiveMetadata; }
public ReturnWithExceptions<Void, ModelObserver> reindexAIPPreservationEvents(AIP aip) { ReturnWithExceptions<Void, ModelObserver> ret = RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseReturn(nodeType); if (ret.isEmpty()) { ret = observer.indexPreservationsEvents(aip.getId()); } return ret; }
@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; }
private void createEvent(AIP aip, ModelService model, IndexService index, PluginState state, boolean notify) throws PluginException { try { PluginHelper.createPluginEvent(this, aip.getId(), model, index, state, "", notify); } catch (RODAException e) { throw new PluginException(e.getMessage(), e); } }
public static List<List<String>> getOtherMetadataInformation(List<String> fields, String otherMetadataType, AIP aip, ModelService model, StorageService storage) { List<List<String>> otherMetadataInformation = new ArrayList<>(); try (CloseableIterable<OptionalWithCause<OtherMetadata>> otherMetadatas = model.listOtherMetadata(aip.getId(), otherMetadataType, true)) { for (OptionalWithCause<OtherMetadata> otherMetadata : otherMetadatas) { if (otherMetadata.isPresent()) { otherMetadataInformation.add(retrieveOtherMetadataInfo(fields, otherMetadata.get(), aip, storage)); } else { LOGGER.error("Cannot retrieve other metadata information", otherMetadata.getCause()); } } } catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException | IOException e) { LOGGER.error("Error retrieving other metadata.", e); } return otherMetadataInformation; }
protected void createUnpackingEventSuccess(ModelService model, IndexService index, TransferredResource transferredResource, AIP aip, String unpackDescription) { setPreservationEventType(UNPACK_EVENT_TYPE); setPreservationSuccessMessage(UNPACK_SUCCESS_MESSAGE); setPreservationFailureMessage(UNPACK_FAILURE_MESSAGE); setPreservationEventDescription(unpackDescription); try { boolean notify = true; PluginHelper.createPluginEvent(this, aip.getId(), model, index, transferredResource, PluginState.SUCCESS, "", notify); } catch (NotFoundException | RequestNotValidException | GenericException | AuthorizationDeniedException | ValidationException | AlreadyExistsException e) { LOGGER.warn("Error creating unpacking event: " + e.getMessage(), e); } }
protected void createWellformedEventSuccess(ModelService model, IndexService index, TransferredResource transferredResource, AIP aip) { setPreservationEventType(WELLFORMED_EVENT_TYPE); setPreservationSuccessMessage(WELLFORMED_SUCCESS_MESSAGE); setPreservationFailureMessage(WELLFORMED_FAILURE_MESSAGE); setPreservationEventDescription(WELLFORMED_DESCRIPTION); try { boolean notify = true; PluginHelper.createPluginEvent(this, aip.getId(), model, index, transferredResource, PluginState.SUCCESS, "", notify); } catch (NotFoundException | RequestNotValidException | GenericException | AuthorizationDeniedException | ValidationException | AlreadyExistsException e) { LOGGER.warn("Error creating unpacking event: " + e.getMessage(), e); } } }
@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; }
private void updateAIPsToBeAppraised(ModelService model, List<AIP> aips, IngestJobPluginInfo jobPluginInfo) { for (AIP aip : aips) { aip.setState(AIPState.UNDER_APPRAISAL); try { aip = model.updateAIPState(aip, PluginHelper.getJobUsername(this, model)); getParameterValues().put(RodaConstants.PLUGIN_PARAMS_OUTCOMEOBJECTID_TO_SOURCEOBJECTID_MAP, JsonUtils.getJsonFromObject(jobPluginInfo.getAipIdToTransferredResourceIds())); // update main report outcomeObjectState PluginHelper.updateJobReportState(this, model, aip.getIngestSIPUUID(), aip.getId(), AIPState.UNDER_APPRAISAL); // update counters of manual intervention jobPluginInfo.incrementOutcomeObjectsWithManualIntervention(); } catch (GenericException | NotFoundException | RequestNotValidException | AuthorizationDeniedException e) { LOGGER.error("Error while updating AIP state to '{}'. Reason: {}", AIPState.UNDER_APPRAISAL, e.getMessage()); } } }
@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> 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; }
@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; }