@Test(expected = NotfoundException.class) public void testFindNotFound() throws Exception { final Path container = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final S3AttributesFinderFeature f = new S3AttributesFinderFeature(session); f.find(test); }
@Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } if(file.getType().contains(Path.Type.upload)) { return PathAttributes.EMPTY; } if(containerService.isContainer(file)) { final PathAttributes attributes = new PathAttributes(); attributes.setRegion(new S3LocationFeature(session, session.getClient().getRegionEndpointCache()).getLocation(file).getIdentifier()); return attributes; } if(file.isFile() || file.isPlaceholder()) { try { PathAttributes attr; try { attr = this.toAttributes(session.getClient().getVersionedObjectDetails(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file))); } catch(ServiceException e) { if(null != e.getResponseHeaders()) { if(e.getResponseHeaders().containsKey(AMZ_DELETE_MARKER)) { attr = new PathAttributes().withVersionId(e.getResponseHeaders().get(AMZ_VERSION_ID)); attr.setCustom(Collections.singletonMap(KEY_DELETE_MARKER, Boolean.TRUE.toString())); attr.setDuplicate(true); return attr; } else { throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } else { throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } if(StringUtils.isNotBlank(attr.getVersionId())) { if(references) { try { final AttributedList<Path> list = new S3VersionedObjectListService(session, true).list(file, new DisabledListProgressListener()); final Path versioned = list.find(new DefaultPathPredicate(file)); if(null != versioned) { attr.setDuplicate(versioned.attributes().isDuplicate()); attr.setVersions(versioned.attributes().getVersions()); return attr; } } catch(InteroperabilityException | AccessDeniedException e) { log.warn(String.format("Ignore failure %s reading object versions for %s", e, file)); } } else { try { final String latest = this.toAttributes(session.getClient().getObjectDetails( containerService.getContainer(file).getName(), containerService.getKey(file))).getVersionId(); attr.setDuplicate(!latest.equals(attr.getVersionId())); } catch(ServiceException e) { final BackgroundException failure = new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); if(failure instanceof NotfoundException) { attr.setCustom(Collections.singletonMap(KEY_DELETE_MARKER, Boolean.TRUE.toString())); attr.setDuplicate(true); } else { throw failure; } } } } return attr; } catch(NotfoundException e) { if(file.isPlaceholder()) { try { new S3ObjectListService(session).list(file, new DisabledListProgressListener(), containerService.getKey(file)); } catch(NotfoundException n) { throw e; } return PathAttributes.EMPTY; } throw e; } } return PathAttributes.EMPTY; }
S3AttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } if(file.getType().contains(Path.Type.upload)) { return PathAttributes.EMPTY; } if(containerService.isContainer(file)) { final PathAttributes attributes = new PathAttributes(); attributes.setRegion(new S3LocationFeature(session, session.getClient().getRegionEndpointCache()).getLocation(file).getIdentifier()); return attributes; } if(file.isFile() || file.isPlaceholder()) { try { PathAttributes attr; try { attr = this.toAttributes(session.getClient().getVersionedObjectDetails(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file))); } catch(ServiceException e) { if(null != e.getResponseHeaders()) { if(e.getResponseHeaders().containsKey(AMZ_DELETE_MARKER)) { attr = new PathAttributes().withVersionId(e.getResponseHeaders().get(AMZ_VERSION_ID)); attr.setCustom(Collections.singletonMap(KEY_DELETE_MARKER, Boolean.TRUE.toString())); attr.setDuplicate(true); return attr; } else { throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } else { throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } if(StringUtils.isNotBlank(attr.getVersionId())) { if(references) { try { final AttributedList<Path> list = new S3VersionedObjectListService(session, true).list(file, new DisabledListProgressListener()); final Path versioned = list.find(new DefaultPathPredicate(file)); if(null != versioned) { attr.setDuplicate(versioned.attributes().isDuplicate()); attr.setVersions(versioned.attributes().getVersions()); return attr; } } catch(InteroperabilityException | AccessDeniedException e) { log.warn(String.format("Ignore failure %s reading object versions for %s", e, file)); } } else { try { final String latest = this.toAttributes(session.getClient().getObjectDetails( containerService.getContainer(file).getName(), containerService.getKey(file))).getVersionId(); attr.setDuplicate(!latest.equals(attr.getVersionId())); } catch(ServiceException e) { final BackgroundException failure = new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); if(failure instanceof NotfoundException) { attr.setCustom(Collections.singletonMap(KEY_DELETE_MARKER, Boolean.TRUE.toString())); attr.setDuplicate(true); } else { throw failure; } } } } return attr; } catch(NotfoundException e) { if(file.isPlaceholder()) { try { new S3ObjectListService(session).list(file, new DisabledListProgressListener(), containerService.getKey(file)); } catch(NotfoundException n) { throw e; } return PathAttributes.EMPTY; } throw e; } } return PathAttributes.EMPTY; } }
S3AttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } if(file.getType().contains(Path.Type.upload)) { return PathAttributes.EMPTY; } if(containerService.isContainer(file)) { final PathAttributes attributes = new PathAttributes(); attributes.setRegion(new S3LocationFeature(session, session.getClient().getRegionEndpointCache()).getLocation(file).getIdentifier()); return attributes; } if(file.isFile() || file.isPlaceholder()) { try { PathAttributes attr; try { attr = this.toAttributes(session.getClient().getVersionedObjectDetails(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file))); } catch(ServiceException e) { if(null != e.getResponseHeaders()) { if(e.getResponseHeaders().containsKey(AMZ_DELETE_MARKER)) { attr = new PathAttributes().withVersionId(e.getResponseHeaders().get(AMZ_VERSION_ID)); attr.setCustom(Collections.singletonMap(KEY_DELETE_MARKER, Boolean.TRUE.toString())); attr.setDuplicate(true); return attr; } else { throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } else { throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } if(StringUtils.isNotBlank(attr.getVersionId())) { if(references) { try { final AttributedList<Path> list = new S3VersionedObjectListService(session, true).list(file, new DisabledListProgressListener()); final Path versioned = list.find(new DefaultPathPredicate(file)); if(null != versioned) { attr.setDuplicate(versioned.attributes().isDuplicate()); attr.setVersions(versioned.attributes().getVersions()); return attr; } } catch(InteroperabilityException | AccessDeniedException e) { log.warn(String.format("Ignore failure %s reading object versions for %s", e, file)); } } else { try { final String latest = this.toAttributes(session.getClient().getObjectDetails( containerService.getContainer(file).getName(), containerService.getKey(file))).getVersionId(); attr.setDuplicate(!latest.equals(attr.getVersionId())); } catch(ServiceException e) { final BackgroundException failure = new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); if(failure instanceof NotfoundException) { attr.setCustom(Collections.singletonMap(KEY_DELETE_MARKER, Boolean.TRUE.toString())); attr.setDuplicate(true); } else { throw failure; } } } } return attr; } catch(NotfoundException e) { if(file.isPlaceholder()) { try { new S3ObjectListService(session).list(file, new DisabledListProgressListener(), containerService.getKey(file)); } catch(NotfoundException n) { throw e; } return PathAttributes.EMPTY; } throw e; } } return PathAttributes.EMPTY; } S3AttributesFinderFeature(final S3Session session);  S3AttributesFinderFeature(final S3Session session, final boolean references); }
S3AttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } if(file.getType().contains(Path.Type.upload)) { return PathAttributes.EMPTY; } if(containerService.isContainer(file)) { final PathAttributes attributes = new PathAttributes(); attributes.setRegion(new S3LocationFeature(session, session.getClient().getRegionEndpointCache()).getLocation(file).getIdentifier()); return attributes; } if(file.isFile() || file.isPlaceholder()) { try { PathAttributes attr; try { attr = this.toAttributes(session.getClient().getVersionedObjectDetails(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file))); } catch(ServiceException e) { if(null != e.getResponseHeaders()) { if(e.getResponseHeaders().containsKey(AMZ_DELETE_MARKER)) { attr = new PathAttributes().withVersionId(e.getResponseHeaders().get(AMZ_VERSION_ID)); attr.setCustom(Collections.singletonMap(KEY_DELETE_MARKER, Boolean.TRUE.toString())); attr.setDuplicate(true); return attr; } else { throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } else { throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } if(StringUtils.isNotBlank(attr.getVersionId())) { if(references) { try { final AttributedList<Path> list = new S3VersionedObjectListService(session, true).list(file, new DisabledListProgressListener()); final Path versioned = list.find(new DefaultPathPredicate(file)); if(null != versioned) { attr.setDuplicate(versioned.attributes().isDuplicate()); attr.setVersions(versioned.attributes().getVersions()); return attr; } } catch(InteroperabilityException | AccessDeniedException e) { log.warn(String.format("Ignore failure %s reading object versions for %s", e, file)); } } else { try { final String latest = this.toAttributes(session.getClient().getObjectDetails( containerService.getContainer(file).getName(), containerService.getKey(file))).getVersionId(); attr.setDuplicate(!latest.equals(attr.getVersionId())); } catch(ServiceException e) { final BackgroundException failure = new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); if(failure instanceof NotfoundException) { attr.setCustom(Collections.singletonMap(KEY_DELETE_MARKER, Boolean.TRUE.toString())); attr.setDuplicate(true); } else { throw failure; } } } } return attr; } catch(NotfoundException e) { if(file.isPlaceholder()) { try { new S3ObjectListService(session).list(file, new DisabledListProgressListener(), containerService.getKey(file)); } catch(NotfoundException n) { throw e; } return PathAttributes.EMPTY; } throw e; } } return PathAttributes.EMPTY; } S3AttributesFinderFeature(final S3Session session);  S3AttributesFinderFeature(final S3Session session, final boolean references); @Override PathAttributes find(final Path file); PathAttributes toAttributes(final StorageObject object); }
S3AttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } if(file.getType().contains(Path.Type.upload)) { return PathAttributes.EMPTY; } if(containerService.isContainer(file)) { final PathAttributes attributes = new PathAttributes(); attributes.setRegion(new S3LocationFeature(session, session.getClient().getRegionEndpointCache()).getLocation(file).getIdentifier()); return attributes; } if(file.isFile() || file.isPlaceholder()) { try { PathAttributes attr; try { attr = this.toAttributes(session.getClient().getVersionedObjectDetails(file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file))); } catch(ServiceException e) { if(null != e.getResponseHeaders()) { if(e.getResponseHeaders().containsKey(AMZ_DELETE_MARKER)) { attr = new PathAttributes().withVersionId(e.getResponseHeaders().get(AMZ_VERSION_ID)); attr.setCustom(Collections.singletonMap(KEY_DELETE_MARKER, Boolean.TRUE.toString())); attr.setDuplicate(true); return attr; } else { throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } else { throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } if(StringUtils.isNotBlank(attr.getVersionId())) { if(references) { try { final AttributedList<Path> list = new S3VersionedObjectListService(session, true).list(file, new DisabledListProgressListener()); final Path versioned = list.find(new DefaultPathPredicate(file)); if(null != versioned) { attr.setDuplicate(versioned.attributes().isDuplicate()); attr.setVersions(versioned.attributes().getVersions()); return attr; } } catch(InteroperabilityException | AccessDeniedException e) { log.warn(String.format("Ignore failure %s reading object versions for %s", e, file)); } } else { try { final String latest = this.toAttributes(session.getClient().getObjectDetails( containerService.getContainer(file).getName(), containerService.getKey(file))).getVersionId(); attr.setDuplicate(!latest.equals(attr.getVersionId())); } catch(ServiceException e) { final BackgroundException failure = new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file); if(failure instanceof NotfoundException) { attr.setCustom(Collections.singletonMap(KEY_DELETE_MARKER, Boolean.TRUE.toString())); attr.setDuplicate(true); } else { throw failure; } } } } return attr; } catch(NotfoundException e) { if(file.isPlaceholder()) { try { new S3ObjectListService(session).list(file, new DisabledListProgressListener(), containerService.getKey(file)); } catch(NotfoundException n) { throw e; } return PathAttributes.EMPTY; } throw e; } } return PathAttributes.EMPTY; } S3AttributesFinderFeature(final S3Session session);  S3AttributesFinderFeature(final S3Session session, final boolean references); @Override PathAttributes find(final Path file); PathAttributes toAttributes(final StorageObject object);  }