public static List<String> getAncestors(String parentId, ModelService model) throws RequestNotValidException, GenericException, AuthorizationDeniedException { List<String> ancestors = new ArrayList<>(); String nextAncestorId = parentId; while (nextAncestorId != null) { try { AIP nextAncestor = model.retrieveAIP(nextAncestorId); if (ancestors.contains(nextAncestorId)) { break; } ancestors.add(nextAncestorId); nextAncestorId = nextAncestor.getParentId(); } catch (NotFoundException e) { LOGGER.warn("Could not find one AIP ancestor. Ancestor id: {}", nextAncestorId); nextAncestorId = null; } } return ancestors; }
@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> 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 AIP moveAIP(String aipId, String parentId, String updatedBy) throws GenericException, NotFoundException, RequestNotValidException, AuthorizationDeniedException { RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); if (aipId.equals(parentId)) { throw new RequestNotValidException("Cannot set itself as its parent: " + aipId); } // TODO ADD RESTRICTIONS AIP aip = ResourceParseUtils.getAIPMetadata(getStorage(), aipId); String oldParentId = aip.getParentId(); aip.setParentId(parentId); aip.setUpdatedOn(new Date()); aip.setUpdatedBy(updatedBy); updateAIPMetadata(aip); notifyAipMoved(aip, oldParentId, parentId).failOnError(); return aip; }
private void processAIPPermissions(IndexService index, Job currentJob, AIP aip, Report reportItem) { try { String jobCreatorUsername = currentJob.getUsername(); if (aip.getParentId() != null) { try { IndexedAIP parentAIP = index.retrieve(IndexedAIP.class, aip.getParentId(), RodaConstants.AIP_PERMISSIONS_FIELDS_TO_RETURN); User user = (User) index.retrieve(RODAMember.class, IdUtils.getUserId(jobCreatorUsername),
private void processTransferredResource(IndexService index, ModelService model, Report report, Job job, TransferredResource transferredResource) { Report reportItem = PluginHelper.initPluginReportItem(this, transferredResource); Path bagitPath = Paths.get(transferredResource.getFullPath()); try { LOGGER.debug("Converting {} to AIP", bagitPath); SIP bagit = BagitSIP.parse(bagitPath); Optional<String> computedParentId = PluginHelper.getComputedParent(model, index, bagit.getAncestors(), computedSearchScope, forceSearchScope, job.getId()); AIP aipCreated = BagitToAIPPluginUtils.bagitToAip(bagit, model, METADATA_FILE, Arrays.asList(transferredResource.getName()), reportItem.getJobId(), computedParentId, job.getUsername(), PermissionUtils.getIngestPermissions(job.getUsername()), transferredResource.getUUID()); PluginHelper.createSubmission(model, createSubmission, bagitPath, aipCreated.getId()); createUnpackingEventSuccess(model, index, transferredResource, aipCreated, UNPACK_DESCRIPTION); reportItem.setSourceAndOutcomeObjectId(reportItem.getSourceObjectId(), aipCreated.getId()) .setPluginState(PluginState.SUCCESS); if (aipCreated.getParentId() == null && computedParentId.isPresent()) { reportItem.setPluginDetails(String.format("Parent with id '%s' not found", computedParentId.get())); } createWellformedEventSuccess(model, index, transferredResource, aipCreated); LOGGER.debug("Done with converting {} to AIP {}", bagitPath, aipCreated.getId()); } catch (RODAException | RuntimeException | ParseException e) { reportItem.setPluginState(PluginState.FAILURE).setPluginDetails(e.getMessage()); LOGGER.error("Error converting " + bagitPath + " to AIP", e); } report.addReport(reportItem); PluginHelper.createJobReport(this, model, reportItem); }
@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> 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> 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; }
.setPluginState(PluginState.SUCCESS); if (sip.getAncestors() != null && !sip.getAncestors().isEmpty() && aip.getParentId() == null) { reportItem.setPluginDetails(String.format("Parent with id '%s' not found", parentId));
private void processAIPs(ModelService model, JobPluginInfo jobPluginInfo, Job cachedJob, List<AIP> list) { for (AIP aip : list) { try { LOGGER.debug("Processing AIP {}", aip.getId()); String parentId = aip.getParentId(); if (parentId != null) { try { model.retrieveAIP(parentId); } catch (RODAException e) { // orphan was found aip.setParentId(newParentId); model.updateAIP(aip, cachedJob.getUsername()); // reporting Report reportItem = PluginHelper.initPluginReportItem(this, aip.getId(), AIP.class, AIPState.ACTIVE) .setPluginState(PluginState.SUCCESS) .setPluginDetails(String.format(MOVED_ORPHAN_AIP_FROM_TO, parentId, newParentId)); PluginHelper.updatePartialJobReport(this, model, reportItem, true, cachedJob); } } jobPluginInfo.incrementObjectsProcessedWithSuccess(); } catch (RODAException e) { LOGGER.error("Error processing AIP {} (RemoveOrphansAction)", aip.getId(), e); Report reportItem = PluginHelper.initPluginReportItem(this, aip.getId(), AIP.class, AIPState.ACTIVE) .setPluginState(PluginState.FAILURE).addPluginDetails(e.getMessage()); PluginHelper.updatePartialJobReport(this, model, reportItem, true, cachedJob); jobPluginInfo.incrementObjectsProcessedWithFailure(); } } }
SolrInputDocument doc = super.toSolrDocument(aip, info); doc.addField(RodaConstants.AIP_PARENT_ID, aip.getParentId()); doc.addField(RodaConstants.AIP_TYPE, aip.getType());