@Override public SolrInputDocument toSolrDocument(TransferredResource tr, IndexingAdditionalInfo info) throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException { SolrInputDocument doc = super.toSolrDocument(tr, info); doc.addField(RodaConstants.TRANSFERRED_RESOURCE_FULLPATH, tr.getFullPath()); if (tr.getParentId() != null) { doc.addField(RodaConstants.TRANSFERRED_RESOURCE_PARENT_ID, tr.getParentId()); doc.addField(RodaConstants.TRANSFERRED_RESOURCE_PARENT_UUID, IdUtils.createUUID(tr.getParentId())); } if (tr.getRelativePath() != null) { doc.addField(RodaConstants.TRANSFERRED_RESOURCE_RELATIVEPATH, tr.getRelativePath()); } doc.addField(RodaConstants.TRANSFERRED_RESOURCE_DATE, SolrUtils.formatDate(tr.getCreationDate())); doc.addField(RodaConstants.TRANSFERRED_RESOURCE_ISFILE, tr.isFile()); doc.addField(RodaConstants.TRANSFERRED_RESOURCE_SIZE, tr.getSize()); doc.addField(RodaConstants.TRANSFERRED_RESOURCE_NAME, tr.getName()); if (tr.getAncestorsPaths() != null && !tr.getAncestorsPaths().isEmpty()) { doc.addField(RodaConstants.TRANSFERRED_RESOURCE_ANCESTORS, tr.getAncestorsPaths()); } doc.addField(RodaConstants.TRANSFERRED_RESOURCE_LAST_SCAN_DATE, SolrUtils.formatDateWithMillis(tr.getLastScanDate())); return doc; }
public static TransferredResource instantiateTransferredResource(Path resourcePath, Path basePath) { Path relativeToBase = basePath.relativize(resourcePath); TransferredResource tr = new TransferredResource(); tr.setFile(!FSUtils.isDirectory(resourcePath)); tr.setFullPath(resourcePath.toString()); String id = relativeToBase.toString(); tr.setId(id); tr.setUUID(IdUtils.getTransferredResourceUUID(relativeToBase)); tr.setName(resourcePath.getFileName().toString()); tr.setRelativePath(relativeToBase.toString()); if (relativeToBase.getParent() != null) { String parentId = relativeToBase.getParent().toString(); tr.setParentId(parentId); tr.setParentUUID(IdUtils.createUUID(parentId)); } List<String> ancestors = new ArrayList<>(); StringBuilder temp = new StringBuilder(); Iterator<Path> pathIterator = relativeToBase.iterator(); while (pathIterator.hasNext()) { temp.append(pathIterator.next().toString()); ancestors.add(temp.toString()); temp.append("/"); } ancestors.remove(ancestors.size() - 1); tr.setAncestorsPaths(ancestors); return tr; }
@SuppressWarnings("unchecked") private void processTransferredResource(ModelService model, Report report, JobPluginInfo jobPluginInfo, Job job, List<TransferredResource> resources) { if (destinationId == null) { destinationId = ""; } try { Map<String, String> moveResult = RodaCoreFactory.getTransferredResourcesScanner() .moveTransferredResource(resources, destinationId, false, true); for (TransferredResource resource : resources) { if (!moveResult.containsKey(resource.getUUID())) { addFailedReport(model, report, jobPluginInfo, job, resource.getUUID(), (Class<T>) TransferredResource.class); } else { jobPluginInfo.incrementObjectsProcessedWithSuccess(); } } } catch (GenericException | IsStillUpdatingException | NotFoundException | RuntimeException | AuthorizationDeniedException e) { LOGGER.error("Could not move transferred resource list", e); for (TransferredResource resource : resources) { addFailedReport(model, report, jobPluginInfo, job, resource.getId(), (Class<T>) TransferredResource.class); } } }
public void deleteTransferredResource(TransferredResource transferredResource) throws GenericException, AuthorizationDeniedException { RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); FSUtils.deletePathQuietly(Paths.get(transferredResource.getFullPath())); notifyTransferredResourceDeleted(transferredResource.getUUID()).failOnError(); }
if (FSUtils.exists(Paths.get(resource.getFullPath()))) { Path newResourcePath = basePath.resolve(newRelativePath); if (addOldRelativePathToNewRelativePath) { newResourcePath = newResourcePath .resolve(resource.getRelativePath().replace(baseFolder + "/" + successFolder + "/", "") .replace(baseFolder + "/" + unsuccessFolder + "/", "")); } else { newResourcePath = newResourcePath.resolve(resource.getName()); FSUtils.move(Paths.get(resource.getFullPath()), newResourcePath, replaceExisting); newResource.setCreationDate(new Date(attr.creationTime().toMillis())); } catch (IOException e) { newResource.setCreationDate(new Date()); newResource.setSize(resource.getSize()); newResource.setLastScanDate(new Date()); index.create(TransferredResource.class, newResource); oldToNewTransferredResourceIds.put(resource.getUUID(), newResource.getUUID()); resourcesToIndex.add(resource); } else {
Path transferredResourcePath = Paths.get(transferredResource.getFullPath()); LOGGER.debug("Converting {} to AIP", transferredResourcePath); AIPState state = AIPState.INGEST_PROCESSING; PermissionUtils.getIngestPermissions(job.getUsername()), transferredResource.getUUID(), Arrays.asList(transferredResource.getName()), job.getId(), false, job.getUsername()); if (transferredResource.isFile()) { String fileId = transferredResource.getName(); List<String> directoryPath = new ArrayList<>(); ContentPayload payload = new FSPathContentPayload(transferredResourcePath); LOGGER.debug("Done with converting {} to AIP {}", transferredResourcePath, aip.getId()); } catch (RODAException | IOException | RuntimeException e) { LOGGER.error("Error converting " + transferredResource.getId() + " to AIP", e); reportItem.setPluginState(PluginState.FAILURE).setPluginDetails(e.getMessage());
RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); if (FSUtils.exists(Paths.get(resource.getFullPath()))) { Path resourcePath = Paths.get(resource.getFullPath()); Path newPath = resourcePath.getParent().resolve(newName); FSUtils.move(resourcePath, newPath, replaceExisting); if (resource.getParentUUID() != null) { try { TransferredResource parent = index.retrieve(TransferredResource.class, resource.getParentUUID(), fieldsToReturn); if (parent != null) { updateTransferredResources(Optional.of(parent.getRelativePath()), true); } else { updateTransferredResources(Optional.empty(), true);
public static String getLinkingIdentifierId(TransferredResource transferredResource) { return getLinkingIdentifierId(RODA_TYPE.TRANSFERRED_RESOURCE, transferredResource.getRelativePath()); }
private void processTransferredResource(IndexService index, ModelService model, Report report, Job job, TransferredResource transferredResource) { Report reportItem = PluginHelper.initPluginReportItem(this, transferredResource); Path bagitPath = Paths.get(transferredResource.getFullPath()); try { LOGGER.debug("Converting {} to AIP", bagitPath); SIP bagit = BagitSIP.parse(bagitPath); Optional<String> computedParentId = PluginHelper.getComputedParent(model, index, bagit.getAncestors(), computedSearchScope, forceSearchScope, job.getId()); AIP aipCreated = BagitToAIPPluginUtils.bagitToAip(bagit, model, METADATA_FILE, Arrays.asList(transferredResource.getName()), reportItem.getJobId(), computedParentId, job.getUsername(), PermissionUtils.getIngestPermissions(job.getUsername()), transferredResource.getUUID()); PluginHelper.createSubmission(model, createSubmission, bagitPath, aipCreated.getId()); createUnpackingEventSuccess(model, index, transferredResource, aipCreated, UNPACK_DESCRIPTION); reportItem.setSourceAndOutcomeObjectId(reportItem.getSourceObjectId(), aipCreated.getId()) .setPluginState(PluginState.SUCCESS); if (aipCreated.getParentId() == null && computedParentId.isPresent()) { reportItem.setPluginDetails(String.format("Parent with id '%s' not found", computedParentId.get())); } createWellformedEventSuccess(model, index, transferredResource, aipCreated); LOGGER.debug("Done with converting {} to AIP {}", bagitPath, aipCreated.getId()); } catch (RODAException | RuntimeException | ParseException e) { reportItem.setPluginState(PluginState.FAILURE).setPluginDetails(e.getMessage()); LOGGER.error("Error converting " + bagitPath + " to AIP", e); } report.addReport(reportItem); PluginHelper.createJobReport(this, model, reportItem); }
public static <T extends IsRODAObject> Report initPluginReportItem(Plugin<T> plugin, TransferredResource transferredResource) { return initPluginReportItem(plugin, Report.NO_OUTCOME_OBJECT_ID, transferredResource.getUUID()) .setSourceObjectClass(TransferredResource.class.getName()).setOutcomeObjectClass(AIP.class.getName()) .setOutcomeObjectState(AIPState.INGEST_PROCESSING).setSourceObjectOriginalName(transferredResource.getName()); }
private void processTransferredResource(ModelService model, Report report, JobPluginInfo pluginInfo, Job job, TransferredResource transferredResource) { Report reportItem = PluginHelper.initPluginReportItem(this, transferredResource); PluginHelper.updatePartialJobReport(this, model, reportItem, false, job); try { LOGGER.debug("Removing SIP {}", transferredResource.getFullPath()); model.deleteTransferredResource(transferredResource); LOGGER.debug("Done with removing SIP {}", transferredResource.getFullPath()); if (createEvent) { model.createRepositoryEvent(PreservationEventType.DELETION, "The process of deleting an object of the repository", PluginState.SUCCESS, "The transferred resource " + transferredResource.getId() + " has been deleted.", "", job.getUsername(), true); } pluginInfo.incrementObjectsProcessedWithSuccess(); } catch (RuntimeException | GenericException | AuthorizationDeniedException e) { if (createEvent) { model.createRepositoryEvent(PreservationEventType.DELETION, "The process of deleting an object of the repository", PluginState.SUCCESS, "The transferred resource " + transferredResource.getId() + " has not been deleted.", "", job.getUsername(), true); } pluginInfo.incrementObjectsProcessedWithFailure(); reportItem.setPluginState(PluginState.FAILURE).setPluginDetails(e.getMessage()); LOGGER.error("Error removing transferred resource " + transferredResource.getFullPath(), e); } report.addReport(reportItem); PluginHelper.updatePartialJobReport(this, model, reportItem, true, job); }
private void processTransferredResource(IndexService index, ModelService model, StorageService storage, Report report, Job job, TransferredResource transferredResource) { Report reportItem = PluginHelper.initPluginReportItem(this, transferredResource); Path earkSIPPath = Paths.get(transferredResource.getFullPath()); LOGGER.debug("Converting {} to AIP", earkSIPPath); transformTransferredResourceIntoAnAIP(index, model, storage, transferredResource, earkSIPPath, createSubmission, reportItem, job.getId(), computedSearchScope, forceSearchScope, jobWorkingDirectory); report.addReport(reportItem); PluginHelper.createJobReport(this, model, reportItem); }
public static ContentPayload getMetadataPayload(TransferredResource transferredResource) { try { Element root = new Element("metadata"); org.jdom2.Document doc = new org.jdom2.Document(); Element child = new Element("field"); child.setAttribute("name", "title"); child.addContent(transferredResource.getName()); root.addContent(child); doc.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); outter.outputString(doc); return new StringContentPayload(outter.outputString(doc)); } catch (IllegalDataException e) { LOGGER.debug("Error generating TransferredResource metadata file {}", e.getMessage()); return new StringContentPayload(""); } }
public TransferredResource createFolder(String parentUUID, String folderName) throws GenericException, NotFoundException, AuthorizationDeniedException { Path parentPath; RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); if (parentUUID != null) { TransferredResource parent = index.retrieve(TransferredResource.class, parentUUID, fieldsToReturn); parentPath = basePath.resolve(parent.getRelativePath()); } else { parentPath = basePath; } try { Path createdPath = Files.createDirectories(parentPath.resolve(folderName)); BasicFileAttributes attrs = Files.readAttributes(createdPath, BasicFileAttributes.class); TransferredResource resource = createTransferredResource(createdPath, attrs, 0L, basePath, new Date()); index.create(TransferredResource.class, resource); return resource; } catch (IOException e) { LOGGER.error("Cannot create folder", e); throw new GenericException("Cannot create folder", e); } }
} else if (object instanceof TransferredResource) { TransferredResource o = (TransferredResource) object; ret = get(TransferredResource.class, Arrays.asList(o.getFullPath()), false); } else if (object instanceof Report) { Report o = (Report) object;
public TransferredResource createFile(String parentUUID, String fileName, InputStream inputStream) throws GenericException, NotFoundException, AlreadyExistsException, AuthorizationDeniedException { Path parentPath; RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); if (StringUtils.isNotBlank(parentUUID)) { TransferredResource parent = index.retrieve(TransferredResource.class, parentUUID, fieldsToReturn); parentPath = basePath.resolve(parent.getRelativePath()); } else { parentPath = basePath; } Path file = parentPath.resolve(fileName); try { try { Files.createDirectories(parentPath); } catch (FileAlreadyExistsException e) { // do nothing and carry on } Files.copy(inputStream, file); BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class); TransferredResource resource = createTransferredResource(file, attrs, attrs.size(), basePath, new Date()); index.create(TransferredResource.class, resource); return resource; } catch (FileAlreadyExistsException e) { LOGGER.error("Cannot create file", e); throw new AlreadyExistsException(file.toString()); } catch (IOException e) { LOGGER.error("Cannot create file", e); throw new GenericException("Cannot create file", e); } }
public void deleteTransferredResource(List<String> ids) throws NotFoundException, GenericException, RequestNotValidException, AuthorizationDeniedException { RodaCoreFactory.checkIfWriteIsAllowedAndIfFalseThrowException(nodeType); for (String uuid : ids) { TransferredResource tr = index.retrieve(TransferredResource.class, uuid, fieldsToReturn); Path relative = Paths.get(tr.getRelativePath()); Path fullPath = basePath.resolve(relative); if (FSUtils.exists(fullPath)) { FSUtils.deletePath(fullPath); Filter filter = new Filter( new SimpleFilterParameter(RodaConstants.TRANSFERRED_RESOURCE_ANCESTORS, relative.toString())); index.delete(TransferredResource.class, filter); } else { throw new NotFoundException("Path does not exist: " + fullPath); } } index.delete(TransferredResource.class, ids); index.commit(TransferredResource.class); }