private static StoragePath extractToStoragePathChild(StoragePath fromStoragePath, StoragePath fromStoragePathChild, StoragePath toStoragePath) throws RequestNotValidException { List<String> fromChildRelativePath = fromStoragePathChild.asList().subList(fromStoragePath.asList().size(), fromStoragePathChild.asList().size()); List<String> toChildAbsolutePath = new ArrayList<>(toStoragePath.asList()); toChildAbsolutePath.addAll(fromChildRelativePath); return DefaultStoragePath.parse(toChildAbsolutePath); }
public static String getStoragePathAsString(StoragePath storagePath, boolean skipStoragePathContainer, StoragePath anotherStoragePath, boolean skipAnotherStoragePathContainer) { return storagePath.asString(SEPARATOR, SEPARATOR_REGEX, SEPARATOR_REPLACEMENT, skipStoragePathContainer) + SEPARATOR + anotherStoragePath.asString(SEPARATOR, SEPARATOR_REGEX, SEPARATOR_REPLACEMENT, skipAnotherStoragePathContainer); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; AbstractEntity other = (AbstractEntity) obj; if (storagePath == null) { if (other.storagePath != null) return false; } else if (!storagePath.equals(other.storagePath)) return false; return true; }
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 Optional<String> extractAipId(StoragePath path) { // AIP/[aipId]/... String container = path.getContainerName(); List<String> directoryPath = path.getDirectoryPath(); if (container.equals(RodaConstants.STORAGE_CONTAINER_AIP) && !directoryPath.isEmpty()) { return Optional.of(directoryPath.get(0)); } return Optional.empty(); }
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 String getNotificationId(StoragePath notificationPath) { return notificationPath.getName().replace(RodaConstants.NOTIFICATION_FILE_EXTENSION, ""); }
@Override public Directory getDirectory(StoragePath storagePath) throws RequestNotValidException, NotFoundException, GenericException { if (storagePath.isFromAContainer()) { throw new RequestNotValidException("Invalid storage path for a directory: " + storagePath); } Path directoryPath = FSUtils.getEntityPath(basePath, storagePath); Resource resource = FSUtils.convertPathToResource(basePath, directoryPath); if (resource instanceof Directory) { return (Directory) resource; } else { throw new RequestNotValidException("Looking for a directory but found something else: " + storagePath); } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((storagePath == null) ? 0 : storagePath.hashCode()); return result; }
Resource resource = resourceIterator.next(); if (!resource.isDirectory() && !resource.getStoragePath().getContainerName().equals(RodaConstants.STORAGE_CONTAINER_PRESERVATION)) { hasFileResources = true;
public static Optional<String> extractDipId(StoragePath path) { // DIP/[dipId]/... String container = path.getContainerName(); List<String> directoryPath = path.getDirectoryPath(); if (container.equals(RodaConstants.STORAGE_CONTAINER_DIP) && !directoryPath.isEmpty()) { return Optional.of(directoryPath.get(0)); } 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 String getRiskIncidenceId(StoragePath incidencePath) { return incidencePath.getName().replace(RodaConstants.RISK_INCIDENCE_FILE_EXTENSION, ""); }
@Override public Class<? extends Entity> getEntity(StoragePath storagePath) throws NotFoundException { Path entity = FSUtils.getEntityPath(basePath, storagePath); if (FSUtils.exists(entity)) { if (FSUtils.isDirectory(entity)) { if (storagePath.isFromAContainer()) { return DefaultContainer.class; } else { return DefaultDirectory.class; } } else { return DefaultBinary.class; } } else { throw new NotFoundException("Entity was not found: " + storagePath); } }
public static List<String> extractFilePathFromRepresentationOtherMetadata(StoragePath path) { // AIP/[aipId]/representations/[representationId]/metadata/other/[type]/.../file.bin String container = path.getContainerName(); List<String> directoryPath = path.getDirectoryPath(); if (container.equals(RodaConstants.STORAGE_CONTAINER_AIP) && directoryPath.size() > 5 && directoryPath.get(1).equals(RodaConstants.STORAGE_DIRECTORY_REPRESENTATIONS) && directoryPath.get(3).equals(RodaConstants.STORAGE_DIRECTORY_METADATA) && directoryPath.get(4).equals(RodaConstants.STORAGE_DIRECTORY_OTHER)) { return directoryPath.subList(6, directoryPath.size()); } return new ArrayList<>(); }
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 String getJobId(StoragePath jobPath) { return jobPath.getName().replace(RodaConstants.JOB_FILE_EXTENSION, ""); }
public static DefaultStoragePath parse(StoragePath base, String... resourceNames) throws RequestNotValidException { List<String> pathPartials = new ArrayList<>(base.asList()); for (String resourceName : resourceNames) { pathPartials.add(resourceName); } return parse(pathPartials); }
@Override public Container getContainer(StoragePath storagePath) throws RequestNotValidException, NotFoundException { if (!storagePath.isFromAContainer()) { throw new RequestNotValidException("Storage path is not from a container"); } Path containerPath = FSUtils.getEntityPath(basePath, storagePath); Container container; if (FSUtils.exists(containerPath)) { container = new DefaultContainer(storagePath); } else { throw new NotFoundException("Container not found: " + storagePath); } return container; }
public static String getStoragePathAsString(StoragePath storagePath, boolean skipContainer) { return storagePath.asString(SEPARATOR, SEPARATOR_REGEX, SEPARATOR_REPLACEMENT, skipContainer); }