public static String getLinkingIdentifierId(TransferredResource transferredResource) { return getLinkingIdentifierId(RODA_TYPE.TRANSFERRED_RESOURCE, transferredResource.getRelativePath()); }
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); } }
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); } }
fieldsToReturn); if (parent != null) { updateTransferredResources(Optional.of(parent.getRelativePath()), true); } else { updateTransferredResources(Optional.empty(), true);
if (addOldRelativePathToNewRelativePath) { newResourcePath = newResourcePath .resolve(resource.getRelativePath().replace(baseFolder + "/" + successFolder + "/", "") .replace(baseFolder + "/" + unsuccessFolder + "/", "")); } else {
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); }
@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; }