@Test public void testWrite() throws Exception { final DistributionConfiguration configuration = new GoogleStorageWebsiteDistributionConfiguration(session); final Path bucket = new Path(UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory, Path.Type.volume)); new GoogleStorageDirectoryFeature(session).mkdir(bucket, "US", new TransferStatus()); configuration.write(bucket, new Distribution(null, Distribution.WEBSITE, true), new DisabledLoginCallback()); assertTrue(configuration.read(bucket, Distribution.WEBSITE, new DisabledLoginCallback()).isEnabled()); new GoogleStorageDeleteFeature(session).delete(Collections.<Path>singletonList(bucket), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public void write(final Path file, final Distribution distribution, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); try { String suffix = "index.html"; if(StringUtils.isNotBlank(distribution.getIndexDocument())) { suffix = PathNormalizer.name(distribution.getIndexDocument()); } session.getClient().buckets().patch(container.getName(), new Bucket() .setLogging(new Bucket.Logging() .setLogObjectPrefix(distribution.isEnabled() ? PreferencesFactory.get().getProperty("google.logging.prefix") : null) .setLogBucket(StringUtils.isNotBlank(distribution.getLoggingContainer()) ? distribution.getLoggingContainer() : container.getName())) .setWebsite( distribution.isEnabled() ? new Bucket.Website().setMainPageSuffix(suffix) : null )).execute(); } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Cannot write website configuration", e); } }
GoogleStorageWebsiteDistributionConfiguration implements DistributionConfiguration, Index { @Override public void write(final Path file, final Distribution distribution, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); try { String suffix = "index.html"; if(StringUtils.isNotBlank(distribution.getIndexDocument())) { suffix = PathNormalizer.name(distribution.getIndexDocument()); } session.getClient().buckets().patch(container.getName(), new Bucket() .setLogging(new Bucket.Logging() .setLogObjectPrefix(distribution.isEnabled() ? PreferencesFactory.get().getProperty("google.logging.prefix") : null) .setLogBucket(StringUtils.isNotBlank(distribution.getLoggingContainer()) ? distribution.getLoggingContainer() : container.getName())) .setWebsite( distribution.isEnabled() ? new Bucket.Website().setMainPageSuffix(suffix) : null )).execute(); } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Cannot write website configuration", e); } } }
GoogleStorageWebsiteDistributionConfiguration implements DistributionConfiguration, Index { @Override public void write(final Path file, final Distribution distribution, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); try { String suffix = "index.html"; if(StringUtils.isNotBlank(distribution.getIndexDocument())) { suffix = PathNormalizer.name(distribution.getIndexDocument()); } session.getClient().buckets().patch(container.getName(), new Bucket() .setLogging(new Bucket.Logging() .setLogObjectPrefix(distribution.isEnabled() ? PreferencesFactory.get().getProperty("google.logging.prefix") : null) .setLogBucket(StringUtils.isNotBlank(distribution.getLoggingContainer()) ? distribution.getLoggingContainer() : container.getName())) .setWebsite( distribution.isEnabled() ? new Bucket.Website().setMainPageSuffix(suffix) : null )).execute(); } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Cannot write website configuration", e); } } GoogleStorageWebsiteDistributionConfiguration(final GoogleStorageSession session); }
GoogleStorageWebsiteDistributionConfiguration implements DistributionConfiguration, Index { @Override public void write(final Path file, final Distribution distribution, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); try { String suffix = "index.html"; if(StringUtils.isNotBlank(distribution.getIndexDocument())) { suffix = PathNormalizer.name(distribution.getIndexDocument()); } session.getClient().buckets().patch(container.getName(), new Bucket() .setLogging(new Bucket.Logging() .setLogObjectPrefix(distribution.isEnabled() ? PreferencesFactory.get().getProperty("google.logging.prefix") : null) .setLogBucket(StringUtils.isNotBlank(distribution.getLoggingContainer()) ? distribution.getLoggingContainer() : container.getName())) .setWebsite( distribution.isEnabled() ? new Bucket.Website().setMainPageSuffix(suffix) : null )).execute(); } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Cannot write website configuration", e); } } GoogleStorageWebsiteDistributionConfiguration(final GoogleStorageSession session); @Override List<Distribution.Method> getMethods(final Path container); @Override String getName(Distribution.Method method); @Override String getName(); @Override DescriptiveUrlBag toUrl(final Path file); @Override Distribution read(final Path file, final Distribution.Method method, final LoginCallback prompt); @Override void write(final Path file, final Distribution distribution, final LoginCallback prompt); @Override @SuppressWarnings("unchecked") T getFeature(final Class<T> type, final Distribution.Method method); @Override String getHostname(); }
GoogleStorageWebsiteDistributionConfiguration implements DistributionConfiguration, Index { @Override public void write(final Path file, final Distribution distribution, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); try { String suffix = "index.html"; if(StringUtils.isNotBlank(distribution.getIndexDocument())) { suffix = PathNormalizer.name(distribution.getIndexDocument()); } session.getClient().buckets().patch(container.getName(), new Bucket() .setLogging(new Bucket.Logging() .setLogObjectPrefix(distribution.isEnabled() ? PreferencesFactory.get().getProperty("google.logging.prefix") : null) .setLogBucket(StringUtils.isNotBlank(distribution.getLoggingContainer()) ? distribution.getLoggingContainer() : container.getName())) .setWebsite( distribution.isEnabled() ? new Bucket.Website().setMainPageSuffix(suffix) : null )).execute(); } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Cannot write website configuration", e); } } GoogleStorageWebsiteDistributionConfiguration(final GoogleStorageSession session); @Override List<Distribution.Method> getMethods(final Path container); @Override String getName(Distribution.Method method); @Override String getName(); @Override DescriptiveUrlBag toUrl(final Path file); @Override Distribution read(final Path file, final Distribution.Method method, final LoginCallback prompt); @Override void write(final Path file, final Distribution distribution, final LoginCallback prompt); @Override @SuppressWarnings("unchecked") T getFeature(final Class<T> type, final Distribution.Method method); @Override String getHostname();  }