doc.addField(RodaConstants.REPRESENTATION_AIP_ID, rep.getAipId()); doc.addField(RodaConstants.REPRESENTATION_ORIGINAL, rep.isOriginal()); doc.addField(RodaConstants.REPRESENTATION_TYPE, rep.getType()); doc.addField(RodaConstants.REPRESENTATION_CREATED_ON, SolrUtils.formatDate(rep.getCreatedOn())); doc.addField(RodaConstants.REPRESENTATION_CREATED_BY, rep.getCreatedBy()); doc.addField(RodaConstants.REPRESENTATION_UPDATED_ON, SolrUtils.formatDate(rep.getUpdatedOn())); doc.addField(RodaConstants.REPRESENTATION_UPDATED_BY, rep.getUpdatedBy()); if (!rep.getRepresentationStates().isEmpty()) { doc.addField(RodaConstants.REPRESENTATION_STATES, rep.getRepresentationStates()); } else if (rep.isOriginal()) { doc.addField(RodaConstants.REPRESENTATION_STATES, Arrays.asList(RepresentationState.ORIGINAL)); SolrUtils.indexDescriptiveMetadataFields(RodaCoreFactory.getModelService(), rep.getAipId(), rep.getId(), rep.getDescriptiveMetadata(), doc); Long numberOfDocumentationFiles; try { Directory documentationDirectory = model.getDocumentationDirectory(rep.getAipId(), rep.getId()); numberOfDocumentationFiles = storage.countResourcesUnderDirectory(documentationDirectory.getStoragePath(), true); } catch (NotFoundException e) { Directory schemasDirectory = model.getSchemasDirectory(rep.getAipId(), rep.getId()); numberOfSchemaFiles = storage.countResourcesUnderDirectory(schemasDirectory.getStoragePath(), true); } catch (NotFoundException e) {
@Override public String toString() { return "IndexedRepresentation [uuid=" + uuid + ", title=" + title + ", sizeInBytes=" + sizeInBytes + ", numberOfDataFiles=" + numberOfDataFiles + ", numberOfDataFolders=" + numberOfDataFolders + " numberOfDocumentationFiles=" + numberOfDocumentationFiles + ", numberOfSchemaFiles=" + numberOfSchemaFiles + ", ancestors=" + ancestors + ", createdOn=" + super.getCreatedOn() + ", createdBy=" + super.getCreatedBy() + ", updatedOn=" + super.getUpdatedOn() + ", updatedBy=" + super.getUpdatedBy() + ", representationStates=" + super.getRepresentationStates() + ']'; }
public void addDescriptiveMetadata(DescriptiveMetadata descriptiveMetadata) { if (descriptiveMetadata.isFromAIP()) { this.descriptiveMetadata.add(descriptiveMetadata); } else { for (Representation representation : this.representations) { if (representation.getId().equals(descriptiveMetadata.getRepresentationId())) { representation.addDescriptiveMetadata(descriptiveMetadata); break; } } } }
public static Representation convertResourceToRepresentation(Resource resource) throws GenericException, NotFoundException, AuthorizationDeniedException, RequestNotValidException { if (resource == null) { throw new RequestNotValidException(RESOURCE_CANNOT_BE_NULL); } StoragePath resourcePath = resource.getStoragePath(); String id = resourcePath.getName(); String aipId = ModelUtils.extractAipId(resourcePath).orElse(null); AIP aip = RodaCoreFactory.getModelService().retrieveAIP(aipId); Optional<Representation> rep = aip.getRepresentations().stream().filter(r -> r.getId().equals(id)).findFirst(); if (rep.isPresent()) { return rep.get(); } else { throw new NotFoundException("Unable to find representation with storage path " + resourcePath); } }
for (Representation representation : aip.getRepresentations()) { DefaultStoragePath representationStoragePath = DefaultStoragePath.parse(RodaConstants.STORAGE_CONTAINER_AIP, aip.getId(), RodaConstants.STORAGE_DIRECTORY_REPRESENTATIONS, representation.getId()); Path representationPath = storage.getDirectAccess(representationStoragePath).getPath(); Date updateDate = new Date(attr.lastModifiedTime().toMillis()); representation.setCreatedOn(createDate); representation.setCreatedBy(aip.getCreatedBy()); representation.setUpdatedOn(updateDate); representation.setUpdatedBy(aip.getUpdatedBy()); if (representation.isOriginal()) { representation.setRepresentationStates(Arrays.asList(RepresentationState.ORIGINAL)); } else { representation.setRepresentationStates(Arrays.asList(RepresentationState.OTHER));
private void processRepresentation(ModelService model, Report report, JobPluginInfo jobPluginInfo, Job job, List<Representation> representations) { for (Representation representation : representations) { Report reportItem = PluginHelper.initPluginReportItem(this, representation.getId(), Representation.class); PluginHelper.updatePartialJobReport(this, model, reportItem, false, job); PluginState state = PluginState.SUCCESS; try { model.changeRepresentationType(representation.getAipId(), representation.getId(), newType, job.getUsername()); } catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException e) { state = PluginState.FAILURE; } finally { jobPluginInfo.incrementObjectsProcessed(state); reportItem.setPluginState(state); StringBuilder outcomeText = new StringBuilder().append("The representation '").append(representation.getId()) .append(" of AIP ").append(representation.getAipId()).append("' changed its type from '") .append(representation.getType()).append("' to '").append(newType).append("'."); model.createUpdateAIPEvent(representation.getAipId(), representation.getId(), null, null, PreservationEventType.UPDATE, EVENT_DESCRIPTION, state, outcomeText.toString(), details, job.getUsername(), true); report.addReport(reportItem); PluginHelper.updatePartialJobReport(this, model, reportItem, true, job); } } }
public void setId(String id) { this.id = id; // As id is not serialized to JSON, set the AIP id in metadata and data if (descriptiveMetadata != null) { for (DescriptiveMetadata dm : descriptiveMetadata) { dm.setAipId(id); } } if (representations != null) { for (Representation representation : representations) { representation.setAipId(id); for (DescriptiveMetadata repDm : representation.getDescriptiveMetadata()) { repDm.setAipId(id); repDm.setRepresentationId(representation.getId()); } } } }
public void changeRepresentationType(String aipId, String representationId, String type, String updatedBy) throws RequestNotValidException, NotFoundException, GenericException, AuthorizationDeniedException { RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); AIP aip = retrieveAIP(aipId); Iterator<Representation> it = aip.getRepresentations().iterator(); while (it.hasNext()) { Representation representation = it.next(); if (representation.getId().equals(representationId)) { representation.setType(type); representation.setUpdatedOn(new Date()); representation.setUpdatedBy(updatedBy); notifyRepresentationUpdated(representation).failOnError(); break; } } updateAIPMetadata(aip); }
public void changeRepresentationStates(String aipId, String representationId, List<String> newStates, String updatedBy) throws RequestNotValidException, NotFoundException, GenericException, AuthorizationDeniedException { RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); AIP aip = retrieveAIP(aipId); Iterator<Representation> it = aip.getRepresentations().iterator(); Optional<Representation> representation = Optional.empty(); while (it.hasNext()) { Representation next = it.next(); if (next.getId().equals(representationId)) { representation = Optional.of(next); break; } } if (representation.isPresent()) { representation.get().setRepresentationStates(newStates); representation.get().setUpdatedOn(new Date()); representation.get().setUpdatedBy(updatedBy); updateAIPMetadata(aip); notifyRepresentationUpdated(representation.get()).failOnError(); } }
private List<DescriptiveMetadata> getDescriptiveMetadata(AIP aip, String representationId) { List<DescriptiveMetadata> descriptiveMetadataList = Collections.emptyList(); if (representationId == null) { // AIP descriptive metadata descriptiveMetadataList = aip.getDescriptiveMetadata(); } else { // Representation descriptive metadata Optional<Representation> oRep = aip.getRepresentations().stream() .filter(rep -> rep.getId().equals(representationId)).findFirst(); if (oRep.isPresent()) { descriptiveMetadataList = oRep.get().getDescriptiveMetadata(); } } return descriptiveMetadataList; }
public Representation createRepresentation(String aipId, String representationId, boolean original, String type, boolean notify, String createdBy) throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException, AlreadyExistsException { RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); Representation representation = new Representation(representationId, aipId, original, type); representation.setCreatedBy(createdBy); representation.setUpdatedBy(createdBy); StoragePath directoryPath = ModelUtils.getRepresentationStoragePath(aipId, representationId); storage.createDirectory(directoryPath); // update AIP metadata AIP aip = ResourceParseUtils.getAIPMetadata(getStorage(), aipId); aip.getRepresentations().add(representation); updateAIPMetadata(aip); if (notify) { notifyRepresentationCreated(representation).failOnError(); } return representation; }
public static List<List<String>> getDescriptiveMetadataInformation(List<String> fields, AIP aip, ModelService model, StorageService storage) { List<List<String>> descriptiveMetadataInformation = new ArrayList<>(); for (DescriptiveMetadata dm : aip.getDescriptiveMetadata()) { descriptiveMetadataInformation.add(retrieveDescriptiveMetadataInfo(fields, aip, dm, storage)); } if (aip.getRepresentations() != null) { for (Representation r : aip.getRepresentations()) { for (DescriptiveMetadata dm : r.getDescriptiveMetadata()) { descriptiveMetadataInformation.add(retrieveDescriptiveMetadataInfo(fields, aip, dm, storage)); } } } return descriptiveMetadataInformation; }
public Representation updateRepresentation(String aipId, String representationId, boolean original, String type, StorageService sourceStorage, StoragePath sourcePath, String updatedBy) throws RequestNotValidException, NotFoundException, GenericException, AuthorizationDeniedException, ValidationException { Representation representation; RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); // XXX possible optimization only creating new files, updating // changed and removing deleted StoragePath representationPath = ModelUtils.getRepresentationStoragePath(aipId, representationId); storage.deleteResource(representationPath); try { storage.copy(sourceStorage, sourcePath, representationPath); } catch (AlreadyExistsException e) { throw new GenericException("Copying after delete gave an unexpected already exists exception", e); } // build return object representation = new Representation(representationId, aipId, original, type); representation.setUpdatedBy(updatedBy); notifyRepresentationUpdated(representation).failOnError(); return representation; }
@Override public ReturnWithExceptions<Void, ModelObserver> representationUpdated(Representation representation) { ReturnWithExceptions<Void, ModelObserver> ret = representationDeleted(representation.getAipId(), representation.getId(), false); representationCreated(representation).addTo(ret); return ret; }
@Override public List<Object> toCsvValues() { return Arrays.asList(uuid, title, sizeInBytes, numberOfDataFiles, numberOfDataFolders, numberOfDocumentationFiles, numberOfSchemaFiles, ancestors, super.getCreatedOn(), super.getCreatedBy(), super.getUpdatedOn(), super.getUpdatedBy(), super.getRepresentationStates()); }
public static List<List<String>> getDataInformation(List<String> fields, AIP aip, ModelService model, StorageService storage) { List<List<String>> dataInformation = new ArrayList<>(); for (Representation representation : aip.getRepresentations()) { boolean recursive = true; try (CloseableIterable<OptionalWithCause<File>> representationFiles = model.listFilesUnder(aip.getId(), representation.getId(), recursive)) { for (OptionalWithCause<File> subfile : representationFiles) { if (subfile.isPresent()) { dataInformation.add(retrieveFileInfo(fields, subfile.get(), aip, model, storage)); } else { LOGGER.error("Cannot retrieve file information", subfile.getCause()); } } } catch (NotFoundException | GenericException | RequestNotValidException | AuthorizationDeniedException | IOException e) { LOGGER.error("Error retrieving files of representation '{}' of AIP '{}': " + e.getMessage(), representation.getId(), aip.getId()); } } return dataInformation; }
representation.getId(), true)) { LOGGER.debug("Processing representation {}", representation); boolean original = false; newRepresentations.add(newRepresentationID); String newRepresentationType = representation.getType(); notify, job.getUsername()); reportItem.setSourceAndOutcomeObjectId(reportItem.getSourceObjectId(), IdUtils.getRepresentationId(representation.getAipId(), newRepresentationID)); outputFormat, file.getId(), representation.getId(), aip.getId());
public Representation createRepresentation(String aipId, String representationId, boolean original, String type, StorageService sourceStorage, StoragePath sourcePath, boolean justData, String createdBy) throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException, AlreadyExistsException { Representation representation; RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); if (justData) { StoragePath dataPath = ModelUtils.getRepresentationDataStoragePath(aipId, representationId); StoragePath sourceDataPath = DefaultStoragePath.parse(sourcePath, RodaConstants.STORAGE_DIRECTORY_DATA); storage.copy(sourceStorage, sourceDataPath, dataPath); } else { StoragePath directoryPath = ModelUtils.getRepresentationStoragePath(aipId, representationId); // verify structure of source representation // 20170324 should we validate the representation??? storage.copy(sourceStorage, sourcePath, directoryPath); } representation = new Representation(representationId, aipId, original, type); representation.setCreatedBy(createdBy); representation.setUpdatedBy(createdBy); // update AIP metadata AIP aip = ResourceParseUtils.getAIPMetadata(getStorage(), aipId); aip.getRepresentations().add(representation); updateAIPMetadata(aip); notifyRepresentationCreated(representation).failOnError(); return representation; }
public static <T extends IsRODAObject> List<LinkingIdentifier> runSiegfriedOnRepresentation(ModelService model, Representation representation) throws GenericException, RequestNotValidException, NotFoundException, AuthorizationDeniedException, PluginException { StoragePath representationDataPath = ModelUtils.getRepresentationDataStoragePath(representation.getAipId(), representation.getId()); try (DirectResourceAccess directAccess = model.getStorage().getDirectAccess(representationDataPath)) { Path representationFsPath = directAccess.getPath(); List<LinkingIdentifier> sources = runSiegfriedOnRepresentationOrFile(model, representation.getAipId(), representation.getId(), new ArrayList<>(), null, representationFsPath); return sources; } catch (IOException e) { throw new GenericException(e); } }