fileInfo.add(file.getId()); } else if (fieldName.equalsIgnoreCase(InventoryReportPlugin.CSV_FIELD_ISDIRECTORY)) { fileInfo.add(String.valueOf(file.isDirectory())); } else if (InventoryReportPlugin.CHECKSUM_ALGORITHMS.contains(fieldName.toUpperCase())) { if (!file.isDirectory()) { if (fixities == null) { try {
/** * @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 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; }
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; }
doc.addField(RodaConstants.FILE_REPRESENTATION_UUID, IdUtils.getRepresentationId(file.getAipId(), file.getRepresentationId())); doc.addField(RodaConstants.FILE_ISDIRECTORY, file.isDirectory()); if (!file.isDirectory() && fileId.contains(".") && !fileId.startsWith(".")) { String extension = fileId.substring(fileId.lastIndexOf('.') + 1); doc.addField(RodaConstants.FILE_EXTENSION, extension);
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; }
sizeInBytes += indexFile(aip, file.get(), ancestors, false).addTo(ret).getReturnedObject(); if (file.get().isDirectory()) { numberOfDataFolders++; } else {
if (oFile.isPresent()) { File file = oFile.get(); if (!file.isDirectory()) { try { model.retrievePreservationFile(aipId, representationId, file.getPath(), file.getId());
LOGGER.debug("Processing file {}", file); if (!file.isDirectory()) { IndexedFile ifile = index.retrieve(IndexedFile.class, IdUtils.getFileId(file), RodaConstants.FILE_FORMAT_FIELDS_TO_RETURN);
LOGGER.debug("Processing file {}", file); if (!file.isDirectory()) { IndexedFile ifile = index.retrieve(IndexedFile.class, IdUtils.getFileId(file), RodaConstants.FILE_FORMAT_FIELDS_TO_RETURN);
File file = oFile.get(); if (!file.isDirectory()) { StoragePath storagePath = ModelUtils.getFileStoragePath(file); Binary currentFileBinary = storage.getBinary(storagePath);
if (!file.isDirectory()) { IndexedFile ifile = index.retrieve(IndexedFile.class, IdUtils.getFileId(file), RodaConstants.FILE_FORMAT_FIELDS_TO_RETURN);
public static void createPremisSkeletonOnFile(ModelService model, File file, Collection<String> fixityAlgorithms, gov.loc.premis.v3.Representation representation) throws RequestNotValidException, GenericException, AuthorizationDeniedException, NotFoundException, ValidationException, XmlException, IOException { boolean notifyInSteps = false; if (!file.isDirectory()) { LOGGER.debug("Processing {}", file); try { model.retrievePreservationFile(file.getAipId(), file.getRepresentationId(), file.getPath(), file.getId()); } catch (NotFoundException e) { ContentPayload filePreservation = PremisV3Utils.createBaseFile(file, model, fixityAlgorithms); String pmId; try { PreservationMetadata pm = model.createPreservationMetadata(PreservationMetadataType.FILE, file.getAipId(), file.getRepresentationId(), file.getPath(), file.getId(), filePreservation, notifyInSteps); pmId = pm.getId(); model.notifyFileCreated(file).failOnError(); } catch (AlreadyExistsException e1) { pmId = IdUtils.getPreservationFileId(file.getId()); model.updatePreservationMetadata(pmId, PreservationMetadataType.FILE, file.getAipId(), file.getRepresentationId(), file.getPath(), file.getId(), filePreservation, notifyInSteps); model.notifyFileUpdated(file).failOnError(); } PremisV3Utils.linkFileToRepresentation(pmId, RodaConstants.PREMIS_RELATIONSHIP_TYPE_STRUCTURAL, RodaConstants.PREMIS_RELATIONSHIP_SUBTYPE_HASPART, representation); } } }