public static String getRiskIncidenceId(StoragePath incidencePath) { return incidencePath.getName().replace(RodaConstants.RISK_INCIDENCE_FILE_EXTENSION, ""); }
public static String getNotificationId(StoragePath notificationPath) { return notificationPath.getName().replace(RodaConstants.NOTIFICATION_FILE_EXTENSION, ""); }
public static String getJobId(StoragePath jobPath) { return jobPath.getName().replace(RodaConstants.JOB_FILE_EXTENSION, ""); }
public static String getRiskId(StoragePath riskPath) { return riskPath.getName().replace(RodaConstants.RISK_FILE_EXTENSION, ""); }
public static String getRepresentationInformationId(StoragePath representationInformationPath) { return representationInformationPath.getName().replace(RodaConstants.REPRESENTATION_INFORMATION_FILE_EXTENSION, ""); }
@Override public String getFileName() { return binary.getStoragePath().getName(); }
public static List<String> getJobAndReportIds(StoragePath jobReportPath) { String reportId = jobReportPath.getName().replace(RodaConstants.JOB_REPORT_FILE_EXTENSION, ""); String jobId = jobReportPath.getDirectoryPath().get(0); return Arrays.asList(jobId, reportId); }
public static AIP getAIPMetadata(StorageService storage, StoragePath storagePath) throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException { return getAIPMetadata(storage, storagePath.getName(), storagePath); }
public static DIP getDIPMetadata(StorageService storage, StoragePath storagePath) throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException { return getDIPMetadata(storage, storagePath.getName(), storagePath); }
public static Optional<String> extractRepresentationId(StoragePath path) { // AIP/[aipId]/representations/[representationId]/... String container = path.getContainerName(); List<String> directoryPath = path.getDirectoryPath(); if (container.equals(RodaConstants.STORAGE_CONTAINER_AIP) && directoryPath.size() > 1 && directoryPath.get(1).equals(RodaConstants.STORAGE_DIRECTORY_REPRESENTATIONS)) { if (directoryPath.size() > 2) { return Optional.of(directoryPath.get(2)); } else { return Optional.of(path.getName()); } } return Optional.empty(); }
public static Optional<String> extractTypeFromAipOtherMetadata(StoragePath path) { // AIP/[aipId]/metadata/other/[type]/... String container = path.getContainerName(); List<String> directoryPath = path.getDirectoryPath(); if (container.equals(RodaConstants.STORAGE_CONTAINER_AIP) && directoryPath.size() > 2 && directoryPath.get(1).equals(RodaConstants.STORAGE_DIRECTORY_METADATA) && directoryPath.get(2).equals(RodaConstants.STORAGE_DIRECTORY_OTHER)) { if (directoryPath.size() > 3) { return Optional.of(directoryPath.get(3)); } else { return Optional.of(path.getName()); } } return Optional.empty(); }
public static Optional<String> extractTypeFromRepresentationOtherMetadata(StoragePath path) { // AIP/[aipId]/representations/[representationId]/metadata/other/[type]/... String container = path.getContainerName(); List<String> directoryPath = path.getDirectoryPath(); if (container.equals(RodaConstants.STORAGE_CONTAINER_AIP) && directoryPath.size() > 4 && directoryPath.get(1).equals(RodaConstants.STORAGE_DIRECTORY_REPRESENTATIONS) && directoryPath.get(3).equals(RodaConstants.STORAGE_DIRECTORY_METADATA) && directoryPath.get(4).equals(RodaConstants.STORAGE_DIRECTORY_OTHER)) { if (directoryPath.size() > 5) { return Optional.of(directoryPath.get(5)); } else { return Optional.of(path.getName()); } } return Optional.empty(); }
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); } }
/** * @deprecated use DownloadUtils instead. */ @Deprecated public static void addToZip(List<ZipEntryInfo> zipEntries, org.roda.core.data.v2.ip.File file, boolean flat) throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException { StorageService storage = RodaCoreFactory.getStorageService(); if (!file.isDirectory()) { StoragePath filePath = ModelUtils.getFileStoragePath(file); Binary binary = storage.getBinary(filePath); ZipEntryInfo info = new ZipEntryInfo(flat ? filePath.getName() : FSUtils.getStoragePathAsString(filePath, true), binary.getContent()); zipEntries.add(info); } else { // do nothing } }
public static File convertResourceToFile(Resource resource) throws GenericException, 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); String representationId = ModelUtils.extractRepresentationId(resourcePath).orElse(null); List<String> filePath = ModelUtils.extractFilePathFromRepresentationData(resourcePath); if (resource instanceof DefaultBinary) { return new File(id, aipId, representationId, filePath, false); } else if (resource instanceof DefaultDirectory) { return new File(id, aipId, representationId, filePath, true); } else { throw new GenericException( "Error while trying to convert something that it isn't a Binary into a representation file"); } }
private ValidationReport isAIPvalid(ModelService model, Directory directory, boolean failIfNoDescriptiveMetadataSchema) throws GenericException, RequestNotValidException, NotFoundException, AuthorizationDeniedException { ValidationReport report = new ValidationReport(); // validate metadata (against schemas) ValidationReport descriptiveMetadataValidationReport = ValidationUtils.isAIPDescriptiveMetadataValid(model, directory.getStoragePath().getName(), failIfNoDescriptiveMetadataSchema); report.setValid(descriptiveMetadataValidationReport.isValid()); report.setIssues(descriptiveMetadataValidationReport.getIssues()); // FIXME validate others aspects return report; }
public static DIPFile convertResourceToDIPFile(Resource resource) throws GenericException, RequestNotValidException { DIPFile ret; if (resource == null) { throw new RequestNotValidException(RESOURCE_CANNOT_BE_NULL); } StoragePath resourcePath = resource.getStoragePath(); String id = resourcePath.getName(); String dipId = ModelUtils.extractDipId(resourcePath).orElse(null); List<String> filePath = ModelUtils.extractFilePathFromDIPData(resourcePath); if (resource instanceof DefaultBinary) { boolean isDirectory = false; ret = new DIPFile(id, dipId, filePath, isDirectory); } else if (resource instanceof DefaultDirectory) { boolean isDirectory = true; ret = new DIPFile(id, dipId, filePath, isDirectory); } else { throw new GenericException( "Error while trying to convert something that is not a Binary or Directory into a DIP file"); } return ret; }
public AIP createAIP(AIPState state, String parentId, String type, Permissions permissions, boolean notify, String createdBy) throws RequestNotValidException, NotFoundException, GenericException, AlreadyExistsException, AuthorizationDeniedException { RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); Directory directory = storage.createRandomDirectory(DefaultStoragePath.parse(RodaConstants.STORAGE_CONTAINER_AIP)); String id = directory.getStoragePath().getName(); Permissions inheritedPermissions = this.addParentPermissions(permissions, parentId); AIP aip = new AIP(id, parentId, type, state, inheritedPermissions, createdBy); createAIPMetadata(aip); if (notify) { notifyAipCreated(aip).failOnError(); } return aip; }
public AIP createAIP(AIPState state, String parentId, String type, Permissions permissions, String ingestSIPUUID, List<String> ingestSIPIds, String ingestJobId, boolean notify, String createdBy) throws RequestNotValidException, NotFoundException, GenericException, AlreadyExistsException, AuthorizationDeniedException { RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); Directory directory = storage.createRandomDirectory(DefaultStoragePath.parse(RodaConstants.STORAGE_CONTAINER_AIP)); String id = directory.getStoragePath().getName(); Permissions inheritedPermissions = this.addParentPermissions(permissions, parentId); AIP aip = new AIP(id, parentId, type, state, inheritedPermissions, createdBy).setIngestSIPIds(ingestSIPIds) .setIngestJobId(ingestJobId).setIngestSIPUUID(ingestSIPUUID); createAIPMetadata(aip); if (notify) { notifyAipCreated(aip).failOnError(); } return aip; }
public AIP createAIP(String parentId, String type, Permissions permissions, List<String> ingestSIPIds, String ingestJobId, boolean notify, String createdBy, boolean isGhost) throws RequestNotValidException, NotFoundException, GenericException, AlreadyExistsException, AuthorizationDeniedException { RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); AIPState state = AIPState.ACTIVE; Directory directory = storage.createRandomDirectory(DefaultStoragePath.parse(RodaConstants.STORAGE_CONTAINER_AIP)); String id = directory.getStoragePath().getName(); Permissions inheritedPermissions = this.addParentPermissions(permissions, parentId); AIP aip = new AIP(id, parentId, type, state, inheritedPermissions, createdBy); aip.setGhost(isGhost); aip.setIngestSIPIds(ingestSIPIds); aip.setIngestJobId(ingestJobId); createAIPMetadata(aip); if (notify) { notifyAipCreated(aip).failOnError(); } return aip; }