@Test public void testFindContainer() throws Exception { final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)); container.attributes().setRegion("IAD"); final PathAttributes attributes = new SwiftAttributesFinderFeature(session).find(container); assertEquals(EnumSet.of(Path.Type.volume, Path.Type.directory), container.getType()); }
@Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } final Region region = regionService.lookup(file); try { if(containerService.isContainer(file)) { final ContainerInfo info = session.getClient().getContainerInfo(region, containerService.getContainer(file).getName()); final PathAttributes attributes = new PathAttributes(); attributes.setSize(info.getTotalSize()); attributes.setRegion(info.getRegion().getRegionId()); return attributes; } final ObjectMetadata metadata = session.getClient().getObjectMetaData(region, containerService.getContainer(file).getName(), containerService.getKey(file)); if(file.isDirectory()) { if(!StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } } if(file.isFile()) { if(StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } } return this.toAttributes(metadata); } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to read attributes of {0}", e, file); } }
SwiftAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } final Region region = regionService.lookup(file); try { if(containerService.isContainer(file)) { final ContainerInfo info = session.getClient().getContainerInfo(region, containerService.getContainer(file).getName()); final PathAttributes attributes = new PathAttributes(); attributes.setSize(info.getTotalSize()); attributes.setRegion(info.getRegion().getRegionId()); return attributes; } final ObjectMetadata metadata = session.getClient().getObjectMetaData(region, containerService.getContainer(file).getName(), containerService.getKey(file)); if(file.isDirectory()) { if(!StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } } if(file.isFile()) { if(StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } } return this.toAttributes(metadata); } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } }
SwiftAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } final Region region = regionService.lookup(file); try { if(containerService.isContainer(file)) { final ContainerInfo info = session.getClient().getContainerInfo(region, containerService.getContainer(file).getName()); final PathAttributes attributes = new PathAttributes(); attributes.setSize(info.getTotalSize()); attributes.setRegion(info.getRegion().getRegionId()); return attributes; } final ObjectMetadata metadata = session.getClient().getObjectMetaData(region, containerService.getContainer(file).getName(), containerService.getKey(file)); if(file.isDirectory()) { if(!StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } } if(file.isFile()) { if(StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } } return this.toAttributes(metadata); } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } SwiftAttributesFinderFeature(SwiftSession session);  SwiftAttributesFinderFeature(final SwiftSession session, final SwiftRegionService regionService); }
SwiftAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } final Region region = regionService.lookup(file); try { if(containerService.isContainer(file)) { final ContainerInfo info = session.getClient().getContainerInfo(region, containerService.getContainer(file).getName()); final PathAttributes attributes = new PathAttributes(); attributes.setSize(info.getTotalSize()); attributes.setRegion(info.getRegion().getRegionId()); return attributes; } final ObjectMetadata metadata = session.getClient().getObjectMetaData(region, containerService.getContainer(file).getName(), containerService.getKey(file)); if(file.isDirectory()) { if(!StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } } if(file.isFile()) { if(StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } } return this.toAttributes(metadata); } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } SwiftAttributesFinderFeature(SwiftSession session);  SwiftAttributesFinderFeature(final SwiftSession session, final SwiftRegionService regionService); @Override PathAttributes find(final Path file); }
SwiftAttributesFinderFeature implements AttributesFinder { @Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } final Region region = regionService.lookup(file); try { if(containerService.isContainer(file)) { final ContainerInfo info = session.getClient().getContainerInfo(region, containerService.getContainer(file).getName()); final PathAttributes attributes = new PathAttributes(); attributes.setSize(info.getTotalSize()); attributes.setRegion(info.getRegion().getRegionId()); return attributes; } final ObjectMetadata metadata = session.getClient().getObjectMetaData(region, containerService.getContainer(file).getName(), containerService.getKey(file)); if(file.isDirectory()) { if(!StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } } if(file.isFile()) { if(StringUtils.equals("application/directory", metadata.getMimeType())) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } } return this.toAttributes(metadata); } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to read attributes of {0}", e, file); } } SwiftAttributesFinderFeature(SwiftSession session);  SwiftAttributesFinderFeature(final SwiftSession session, final SwiftRegionService regionService); @Override PathAttributes find(final Path file);  }