@Override public void delete(final MultipartUpload upload) throws BackgroundException { throw new NotfoundException(upload.getUploadId()); } }
public OneDriveFolder toFolder(final Path file, final boolean resolveLastItem) throws BackgroundException { final OneDriveItem item = this.toItem(file, resolveLastItem); if(!(item instanceof OneDriveFolder)) { throw new NotfoundException(String.format("%s is not a folder.", file.getAbsolute())); } return (OneDriveFolder) item; }
public OneDriveFile toFile(final Path file, final boolean resolveLastItem) throws BackgroundException { final OneDriveItem item = this.toItem(file, resolveLastItem); if(!(item instanceof OneDriveFile)) { throw new NotfoundException(String.format("%s is not a file.", file.getAbsolute())); } return (OneDriveFile) item; }
@Override public BackgroundException map(final IOException e) { final StringBuilder buffer = new StringBuilder(); this.append(buffer, e.getMessage()); if(e instanceof NoSuchFileException) { return new NotfoundException(buffer.toString(), e); } if(e instanceof FileSystemException) { return new LocalAccessDeniedException(buffer.toString(), e); } return this.wrap(e, buffer); } }
@Override public boolean accept(final Path file, final Local local, final TransferStatus parent) throws BackgroundException { if(!local.exists()) { // Local file is no more here throw new NotfoundException(local.getAbsolute()); } return true; }
@Override public boolean accept(final Path file, final Local local, final TransferStatus parent) throws BackgroundException { final Local volume = local.getVolume(); if(!volume.exists()) { throw new NotfoundException(String.format("Volume %s not mounted", volume.getAbsolute())); } return true; }
@Override public BackgroundException map(final JargonException e) { final StringBuilder buffer = new StringBuilder(); this.append(buffer, e.getMessage()); if(e instanceof CatNoAccessException) { return new AccessDeniedException(buffer.toString(), e); } if(e instanceof FileNotFoundException) { return new NotfoundException(buffer.toString(), e); } if(e instanceof DataNotFoundException) { return new NotfoundException(buffer.toString(), e); } if(e instanceof AuthenticationException) { return new LoginFailureException(buffer.toString(), e); } if(e instanceof InvalidUserException) { return new LoginFailureException(buffer.toString(), e); } if(e instanceof InvalidGroupException) { return new LoginFailureException(buffer.toString(), e); } return this.wrap(e, buffer); } }
private BackgroundException handle(final FTPException e, final StringBuilder buffer) { final int status = e.getCode(); switch(status) { case FTPReply.INSUFFICIENT_STORAGE: case FTPReply.STORAGE_ALLOCATION_EXCEEDED: return new QuotaException(buffer.toString(), e); case FTPReply.NOT_LOGGED_IN: return new LoginFailureException(buffer.toString(), e); case FTPReply.FAILED_SECURITY_CHECK: case FTPReply.DENIED_FOR_POLICY_REASONS: case FTPReply.NEED_ACCOUNT: case FTPReply.NEED_ACCOUNT_FOR_STORING_FILES: case FTPReply.FILE_NAME_NOT_ALLOWED: case FTPReply.FILE_ACTION_NOT_TAKEN: case FTPReply.ACTION_ABORTED: return new AccessDeniedException(buffer.toString(), e); case FTPReply.UNAVAILABLE_RESOURCE: case FTPReply.FILE_UNAVAILABLE: // Requested action not taken. File unavailable (e.g., file not found, no access) return new NotfoundException(buffer.toString(), e); case FTPReply.SERVICE_NOT_AVAILABLE: return new ConnectionRefusedException(buffer.toString(), e); } return new InteroperabilityException(buffer.toString(), e); } }
public void cancel(final Transfer.Type type, final Path file, final TransferStatus status) throws BackgroundException { try { if(!status.getParameters().containsKey(REQUEST_PARAMETER_JOBID_IDENTIFIER)) { throw new NotfoundException(String.format("Missing job id parameter in status for %s", file.getName())); } final String job = status.getParameters().get(REQUEST_PARAMETER_JOBID_IDENTIFIER); if(log.isDebugEnabled()) { log.debug(String.format("Cancel job %s", job)); } final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); client.cancelJobSpectraS3(new CancelJobSpectraS3Request(job)); } catch(FailedRequestException e) { throw new SpectraExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
@Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { final Path found = this.search(file); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return found.attributes(); } catch(InteroperabilityException | AccessDeniedException | NotfoundException f) { log.warn(String.format("Failure listing directory %s. %s", file.getParent(), f.getMessage())); // Try native implementation final AttributesFinder feature = session._getFeature(AttributesFinder.class); if(feature instanceof DefaultAttributesFinderFeature) { throw f; } return feature.withCache(cache).find(file); } }
@Override public DescriptiveUrl toDownloadUrl(final Path file, final Object o, final PasswordCallback callback) throws BackgroundException { try { final OneDriveItem item = session.toItem(file); if(null == item) { throw new NotfoundException(file.getAbsolute()); } return new DescriptiveUrl(URI.create(item.createSharedLink(OneDriveSharingLink.Type.VIEW).getLink().getWebUrl()), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3"))); } catch(OneDriveAPIException e) { throw new GraphExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
@Override public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) throws BackgroundException { try { final IRODSFileSystemAO fs = session.getClient(); final IRODSFile s = fs.getIRODSFileFactory().instanceIRODSFile(file.getAbsolute()); if(!s.exists()) { throw new NotfoundException(String.format("%s doesn't exist", file.getAbsolute())); } if(status.isExists()) { delete.delete(Collections.singletonList(renamed), connectionCallback, callback); } final IRODSFile d = fs.getIRODSFileFactory().instanceIRODSFile(renamed.getAbsolute()); s.renameTo(d); return renamed; } catch(JargonException e) { throw new IRODSExceptionMappingService().map("Cannot rename {0}", e, file); } }
@Override public void setPermission(final Path file, final Acl acl) throws BackgroundException { try { if(containerService.isContainer(file)) { final CloudBlobContainer container = session.getClient() .getContainerReference(containerService.getContainer(file).getName()); final BlobContainerPermissions permissions = container.downloadPermissions(null, null, context); for(Acl.UserAndRole userAndRole : acl.asList()) { if(userAndRole.getUser() instanceof Acl.GroupUser) { if(userAndRole.getUser().getIdentifier().equals(Acl.GroupUser.EVERYONE)) { permissions.setPublicAccess(BlobContainerPublicAccessType.BLOB); } } } container.uploadPermissions(permissions, null, null, context); } } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } catch(StorageException e) { throw new AzureExceptionMappingService().map("Cannot change permissions of {0}", e, file); } } }
@Override public LifecycleConfiguration getConfiguration(final Path container) throws BackgroundException { try { final List<B2BucketResponse> buckets = session.getClient().listBuckets(); for(B2BucketResponse response : buckets) { if(response.getBucketName().equals(containerService.getContainer(container).getName())) { final List<LifecycleRule> lifecycleRules = response.getLifecycleRules(); for(LifecycleRule rule : lifecycleRules) { return new LifecycleConfiguration( null == rule.getDaysFromUploadingToHiding() ? null : rule.getDaysFromUploadingToHiding().intValue(), null, null == rule.getDaysFromHidingToDeleting() ? null : rule.getDaysFromHidingToDeleting().intValue()); } return LifecycleConfiguration.empty(); } } throw new NotfoundException(container.getAbsolute()); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Failure to write attributes of {0}", e, container); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to write attributes of {0}", e, container); } }
@Override public PathAttributes find(final Path file) throws BackgroundException { try { final IRODSFileSystemAO fs = session.getClient(); final IRODSFile f = fs.getIRODSFileFactory().instanceIRODSFile(file.getAbsolute()); if(!f.exists()) { throw new NotfoundException(file.getAbsolute()); } final PathAttributes attributes = new PathAttributes(); final ObjStat stats = fs.getObjStat(f.getAbsolutePath()); attributes.setModificationDate(stats.getModifiedAt().getTime()); attributes.setCreationDate(stats.getCreatedAt().getTime()); attributes.setSize(stats.getObjSize()); attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(stats.getChecksum())))); attributes.setOwner(stats.getOwnerName()); attributes.setGroup(stats.getOwnerZone()); return attributes; } catch(JargonException e) { throw new IRODSExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } }
@Override public Permission getUnixPermission(final Path file) throws BackgroundException { try { return new FTPAttributesFinderFeature(session).find(file).getPermission(); } catch(InteroperabilityException e) { for(Path f : session.getFeature(ListService.class).list(file.getParent(), new DisabledListProgressListener())) { if(f.equals(file)) { return f.attributes().getPermission(); } } } throw new NotfoundException(file.getAbsolute()); }
@Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } if(new PathContainerService().isContainer(file)) { return PathAttributes.EMPTY; } final AttributedList<Path> list = new FileidDriveListService(session, fileid, file).list(file.getParent(), new DisabledListProgressListener()); final Path found = list.find(new DriveFileidProvider.IgnoreTrashedPathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return found.attributes(); }
@Override public Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final CloudBlob target = session.getClient().getContainerReference(containerService.getContainer(copy).getName()) .getAppendBlobReference(containerService.getKey(copy)); final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(source).getName()) .getBlobReferenceFromServer(containerService.getKey(source)); final BlobRequestOptions options = new BlobRequestOptions(); options.setStoreBlobContentMD5(PreferencesFactory.get().getBoolean("azure.upload.md5")); final URI s = session.getHost().getCredentials().isTokenAuthentication() ? URI.create(blob.getUri().toString() + session.getHost().getCredentials().getToken()) : blob.getUri(); final String id = target.startCopy(s, AccessCondition.generateEmptyCondition(), AccessCondition.generateEmptyCondition(), options, context); if(log.isDebugEnabled()) { log.debug(String.format("Started copy for %s with copy operation ID %s", copy, id)); } // Copy original file attributes return new Path(copy.getParent(), copy.getName(), copy.getType(), new PathAttributes(source.attributes())); } catch(StorageException e) { throw new AzureExceptionMappingService().map("Cannot copy {0}", e, source); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } }
@Override public Acl getPermission(final Path file) throws BackgroundException { try { if(containerService.isContainer(file)) { final CloudBlobContainer container = session.getClient() .getContainerReference(containerService.getContainer(file).getName()); final BlobContainerPermissions permissions = container.downloadPermissions(null, null, context); final Acl acl = new Acl(); if(permissions.getPublicAccess().equals(BlobContainerPublicAccessType.BLOB) || permissions.getPublicAccess().equals(BlobContainerPublicAccessType.CONTAINER)) { acl.addAll(new Acl.GroupUser(Acl.GroupUser.EVERYONE, false), new Acl.Role(Acl.Role.READ)); } return acl; } return Acl.EMPTY; } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } catch(StorageException e) { throw new AzureExceptionMappingService().map("Failure to read attributes of {0}", e, file); } }
@Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new SimplePathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } final AttributedList<Path> list = session._getFeature(ListService.class).list(file.getParent(), listener); final Path found = list.find(new SimplePathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); }