private static <T extends IsRODAObject> Optional<LiteRODAObject> getFile(T object) { File o = (File) object; List<String> list = new ArrayList<>(); list.add(o.getAipId()); list.add(o.getRepresentationId()); list.addAll(o.getPath()); list.add(o.getId()); return get(File.class, list, false); }
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); }
fileInfo.add(FSUtils.asString(aip.getIngestSIPIds())); } else if (fieldName.equalsIgnoreCase(InventoryReportPlugin.CSV_FIELD_AIP_ID)) { fileInfo.add(file.getAipId()); } else if (fieldName.equalsIgnoreCase(InventoryReportPlugin.CSV_FIELD_REPRESENTATION_ID)) { fileInfo.add(file.getRepresentationId());
/************************************************/ 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 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); }
public Binary retrievePreservationFile(File file) throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException { return retrievePreservationFile(file.getAipId(), file.getRepresentationId(), file.getPath(), file.getId()); }
public static StoragePath getFileStoragePath(File f) throws RequestNotValidException { return getFileStoragePath(f.getAipId(), f.getRepresentationId(), f.getPath(), f.getId()); }
private String getFileFulltext(File file) { String fulltext = ""; try { Binary fulltextBinary = RodaCoreFactory.getModelService().retrieveOtherMetadataBinary(file.getAipId(), file.getRepresentationId(), file.getPath(), file.getId(), RodaConstants.TIKA_FILE_SUFFIX_FULLTEXT, RodaConstants.OTHER_METADATA_TYPE_APACHE_TIKA); if (fulltextBinary.getSizeInBytes() < RodaCoreFactory.getRodaConfigurationAsInt(TEN_MB_IN_BYTES, "core.index.fulltext_threshold_in_bytes")) { try (InputStream inputStream = fulltextBinary.getContent().createInputStream()) { fulltext = IOUtils.toString(inputStream, Charset.forName(RodaConstants.DEFAULT_ENCODING)); } } } catch (RequestNotValidException | GenericException | AuthorizationDeniedException | IOException e) { LOGGER.warn("Error getting fulltext for file: {}", file, e); } catch (NotFoundException e) { LOGGER.trace("Fulltext not found for file: {}", file, e); } return fulltext; }
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"); } }
public static String getFileId(File file) { return getFileId(file.getAipId(), file.getRepresentationId(), file.getPath(), 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; }
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 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; }
@Override public ReturnWithExceptions<Void, ModelObserver> fileUpdated(File file) { ReturnWithExceptions<Void, ModelObserver> ret = fileDeleted(file.getAipId(), file.getRepresentationId(), file.getPath(), file.getId(), false); fileCreated(file).addTo(ret); return ret; }
for (File file : list) { LOGGER.debug("Processing file {} from representation {} from AIP {}", file.getId(), file.getRepresentationId(), file.getAipId()); Report reportItem = PluginHelper.initPluginReportItem(this, IdUtils.getFileId(file), File.class, AIPState.ACTIVE); PluginHelper.updatePartialJobReport(this, model, reportItem, false, job); PluginHelper.createPluginEvent(this, file.getAipId(), file.getRepresentationId(), file.getPath(), file.getId(), model, index, null, null, reportItem.getPluginState(), "", notify); } catch (ValidationException | RequestNotValidException | NotFoundException | GenericException
PluginHelper.updatePartialJobReport(this, model, reportItem, false, job); LOGGER.debug("Processing file {} from representation {} of AIP {}", file.getId(), file.getRepresentationId(), file.getAipId()); List<LinkingIdentifier> outcomes = null; boolean notify = true; PluginHelper.createPluginEvent(this, file.getAipId(), file.getRepresentationId(), file.getPath(), file.getId(), model, index, sources, outcomes, reportItem.getPluginState(), "", notify); } catch (ValidationException | RequestNotValidException | NotFoundException | GenericException
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); } } }
public static <T extends IsRODAObject> List<LinkingIdentifier> runSiegfriedOnFile(ModelService model, File file) throws GenericException, RequestNotValidException, NotFoundException, AuthorizationDeniedException, PluginException { StoragePath fileStoragePath = ModelUtils.getFileStoragePath(file); try (DirectResourceAccess directAccess = model.getStorage().getDirectAccess(fileStoragePath)) { Path filePath = directAccess.getPath(); List<LinkingIdentifier> sources = runSiegfriedOnRepresentationOrFile(model, file.getAipId(), file.getRepresentationId(), file.getPath(), file.getId(), filePath); model.notifyFileUpdated(file).failOnError(); return sources; } catch (IOException e) { throw new GenericException(e); } }
incidence.setDetectedBy(job.getUsername()); incidence.setRiskId(riskId); incidence.setAipId(file.getAipId()); incidence.setRepresentationId(file.getRepresentationId()); incidence.setFilePath(file.getPath()); PluginHelper.createPluginEvent(this, file.getAipId(), file.getRepresentationId(), file.getPath(), file.getId(), model, index, null, null, state, "", true); } catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException