/************************************************/ public CloseableIterable<OptionalWithCause<File>> listFilesUnder(File f, boolean recursive) throws NotFoundException, GenericException, RequestNotValidException, AuthorizationDeniedException { return listFilesUnder(f.getAipId(), f.getRepresentationId(), f.getPath(), f.getId(), recursive); }
public static void createPremisSkeletonOnFile(ModelService model, File file, Collection<String> fixityAlgorithms) throws RequestNotValidException, GenericException, AuthorizationDeniedException, NotFoundException, ValidationException, XmlException, IOException { gov.loc.premis.v3.Representation representation; try { Binary preservationObject = model.retrievePreservationRepresentation(file.getAipId(), file.getRepresentationId()); representation = PremisV3Utils.binaryToRepresentation(preservationObject.getContent(), false); } catch (NotFoundException e) { representation = PremisV3Utils.createBaseRepresentation(file.getAipId(), file.getRepresentationId()); } PremisSkeletonPluginUtils.createPremisSkeletonOnFile(model, file, fixityAlgorithms, representation); }
@JsonIgnore public void addFileData(String aipId, String representationUUID, File file) { if (!updatedData.containsKey(aipId)) { updatedData.put(aipId, new HashMap<String, List<String>>()); } else if (updatedData.get(aipId).containsKey(RodaConstants.RODA_OBJECT_REPRESENTATION) && updatedData.get(aipId).get(RodaConstants.RODA_OBJECT_REPRESENTATION).contains(representationUUID)) { return; } Map<String, List<String>> map = updatedData.get(aipId); if (!updatedData.get(aipId).containsKey(RodaConstants.RODA_OBJECT_FILE)) { map.put(RodaConstants.RODA_OBJECT_FILE, new ArrayList<String>()); } StringBuilder builder = new StringBuilder(); builder.append(file.getRepresentationId()); for (String path : file.getPath()) { builder.append("/").append(path); } builder.append("/").append(file.getId()); map.get(RodaConstants.RODA_OBJECT_FILE).add(builder.toString()); return; } }
private void createNewFilesOnRepresentation(StorageService storage, ModelService model, List<File> unchangedFiles, String newRepresentationID, boolean notify) throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException, UnsupportedOperationException, IOException, AlreadyExistsException { for (File f : unchangedFiles) { StoragePath fileStoragePath = ModelUtils.getFileStoragePath(f); Binary binary = storage.getBinary(fileStoragePath); Path uriPath = Paths.get(binary.getContent().getURI()); ContentPayload payload = new FSPathContentPayload(uriPath); model.createFile(f.getAipId(), newRepresentationID, f.getPath(), f.getId(), payload, notify); } }
public File renameFolder(File folder, String newName, boolean reindexResources) throws AlreadyExistsException, GenericException, NotFoundException, RequestNotValidException, AuthorizationDeniedException { RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); StoragePath folderStoragePath = ModelUtils.getFileStoragePath(folder); if (storage.hasDirectory(folderStoragePath)) { List<String> newFolderPathList = new ArrayList<>(); newFolderPathList.add(folderStoragePath.getContainerName()); newFolderPathList.addAll(folderStoragePath.getDirectoryPath()); newFolderPathList.add(newName); StoragePath newFileStoragePath = DefaultStoragePath.parse(newFolderPathList); storage.move(storage, folderStoragePath, newFileStoragePath); if (reindexResources) { notifyAipUpdated(folder.getAipId()); } return retrieveFile(folder.getAipId(), folder.getRepresentationId(), folder.getPath(), newName); } else { throw new NotFoundException("Folder was moved or does not exist"); } }
IndexedFile toFolder = index.retrieve(IndexedFile.class, destinationId, fileFields); LOGGER.debug("Moving File {} under {}", file.getId(), toFolder.getId()); toAIP = file.getAipId(); toRepresentation = file.getRepresentationId(); File movedFile = model.moveFile(file, toAIP, toRepresentation, toPath, file.getId(), true); outcomeText.append("The file '").append(ModelUtils.getFileStoragePath(file).toString()) .append("' has been manually moved to '").append(ModelUtils.getFileStoragePath(movedFile).toString()) | AuthorizationDeniedException e) { state = PluginState.FAILURE; Report reportItem = PluginHelper.initPluginReportItem(this, file.getId(), File.class); reportItem.addPluginDetails("Could not move file: " + e.getMessage()).setPluginState(state); report.addReport(reportItem); PluginHelper.updatePartialJobReport(this, model, reportItem, true, job); outcomeText.append("The file '").append(file.getId()).append("' has not been manually moved: [") .append(e.getClass().getSimpleName()).append("] ").append(e.getMessage()); model.createUpdateAIPEvent(file.getAipId(), file.getRepresentationId(), null, null, PreservationEventType.UPDATE, EVENT_DESCRIPTION, state, outcomeText.toString(), details, job.getUsername(), true);
public File moveFile(File file, String newAipId, String newRepresentationId, List<String> newDirectoryPath, String newId, boolean reindexResources) throws AlreadyExistsException, GenericException, NotFoundException, RequestNotValidException, AuthorizationDeniedException { RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); StoragePath fileStoragePath = ModelUtils.getFileStoragePath(file); if (!storage.exists(fileStoragePath)) { throw new NotFoundException("File/folder '" + fileStoragePath.toString() + "' were moved or do not exist"); } File newFile = new File(newId, newAipId, newRepresentationId, newDirectoryPath, file.isDirectory()); StoragePath newFileStoragePath = ModelUtils.getFileStoragePath(newFile); storage.move(storage, fileStoragePath, newFileStoragePath); if (reindexResources) { notifyRepresentationUpdated(retrieveRepresentation(newAipId, newRepresentationId)).failOnError(); if (!newAipId.equals(file.getAipId()) || !newRepresentationId.equals(file.getRepresentationId())) { notifyRepresentationUpdated(retrieveRepresentation(file.getAipId(), file.getRepresentationId())).failOnError(); } } return newFile; }
if (oFile.isPresent()) { File file = oFile.get(); if (!file.isDirectory()) { try { model.retrievePreservationFile(aipId, representationId, file.getPath(), file.getId());
private void createNewFilesOnDIP(StorageService storage, ModelService model, List<File> unchangedFiles, String newRepresentationID, boolean notify) throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException, UnsupportedOperationException, IOException, AlreadyExistsException { for (File f : unchangedFiles) { StoragePath fileStoragePath = ModelUtils.getFileStoragePath(f); Binary binary = storage.getBinary(fileStoragePath); Path uriPath = Paths.get(binary.getContent().getURI()); ContentPayload payload = new FSPathContentPayload(uriPath); model.createDIPFile(newRepresentationID, f.getPath(), f.getId(), uriPath.toFile().length(), payload, notify); } }
} else if (object instanceof File) { File file = (File) object; filter.add(new SimpleFilterParameter(RodaConstants.RISK_INCIDENCE_FILE_ID, file.getId()));
@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; }
/** * @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"); } }
} else { for (File file : alteredFiles) { premisSourceFilesIdentifiers.add(PluginHelper.getLinkingIdentifier(aipId, file.getRepresentationId(), file.getPath(), file.getId(), RodaConstants.PRESERVATION_LINKING_OBJECT_SOURCE)); premisTargetFilesIdentifiers.add(PluginHelper.getLinkingIdentifier(aipId, file.getRepresentationId(), file.getPath(), file.getId(), RodaConstants.PRESERVATION_LINKING_OBJECT_OUTCOME));
ObjectIdentifierComplexType oict = file.addNewObjectIdentifier(); oict.setObjectIdentifierValue( URNUtils.createRodaPreservationURN(PreservationMetadataType.FILE, originalFile.getId())); oict.setObjectIdentifierType(getStringPlusAuthority(RodaConstants.PREMIS_IDENTIFIER_TYPE_URN)); ObjectCharacteristicsComplexType occt = file.addNewObjectCharacteristics(); file.addNewOriginalName().setStringValue(originalFile.getId()); StorageComplexType sct = file.addNewStorage(); ContentLocationComplexType clct = sct.addNewContentLocation();
private ReturnWithExceptions<Void, ModelObserver> fileStateUpdated(AIP aip, File file, boolean recursive) { ReturnWithExceptions<Void, ModelObserver> ret = new ReturnWithExceptions<>(this); SolrUtils .update(index, IndexedFile.class, IdUtils.getFileId(file), Collections.singletonMap(RodaConstants.INDEX_STATE, SolrUtils.formatEnum(aip.getState())), (ModelObserver) this) .addTo(ret); if (ret.isEmpty()) { if (recursive && file.isDirectory()) { try (CloseableIterable<OptionalWithCause<File>> allFiles = model.listFilesUnder(file, true)) { for (OptionalWithCause<File> subfile : allFiles) { if (subfile.isPresent()) { fileStateUpdated(aip, subfile.get(), false).addTo(ret); } else { LOGGER.error("Cannot index file sub-resources", subfile.getCause()); ret.add(subfile.getCause()); } } } catch (NotFoundException | GenericException | RequestNotValidException | AuthorizationDeniedException | IOException e) { LOGGER.error("Cannot index file sub-resources: {}", file, e); ret.add(e); } } } else { LOGGER.error("Cannot index file: {}", file); } return ret; }
public File updateFile(File file, ContentPayload contentPayload, boolean createIfNotExists, boolean notify) throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException { return updateFile(file.getAipId(), file.getRepresentationId(), file.getPath(), file.getId(), contentPayload, createIfNotExists, notify); }
private ReturnWithExceptions<Long, ModelObserver> indexFile(AIP aip, File file, List<String> ancestors, boolean recursive) { ReturnWithExceptions<Long, ModelObserver> ret = new ReturnWithExceptions<>(this); Long sizeInBytes = 0L; FileCollection.Info info = new FileCollection.Info(aip, ancestors); SolrUtils.create2(index, (ModelObserver) this, IndexedFile.class, file, info).addTo(ret); sizeInBytes = (Long) info.getAccumulators().get(RodaConstants.FILE_SIZE); if (ret.isEmpty()) { if (recursive && file.isDirectory()) { try (CloseableIterable<OptionalWithCause<File>> allFiles = model.listFilesUnder(file, true)) { for (OptionalWithCause<File> subfile : allFiles) { if (subfile.isPresent()) { sizeInBytes += indexFile(aip, subfile.get(), ancestors, false).addTo(ret).getReturnedObject(); } else { LOGGER.error("Cannot index file", subfile.getCause()); ret.add(subfile.getCause()); } } } catch (NotFoundException | GenericException | RequestNotValidException | AuthorizationDeniedException | IOException e) { LOGGER.error("Cannot index file sub-resources: {}", file, e); ret.add(e); } } } else { LOGGER.error("Cannot index file: {}", file); } ret.setReturnedObject(sizeInBytes); return ret; }
public Binary retrievePreservationFile(File file) throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException { return retrievePreservationFile(file.getAipId(), file.getRepresentationId(), file.getPath(), file.getId()); }
sizeInBytes += indexFile(aip, file.get(), ancestors, false).addTo(ret).getReturnedObject(); if (file.get().isDirectory()) { numberOfDataFolders++; } else {