use of ch.cyberduck.core.features.TransferAcceleration in project cyberduck by iterate-ch.
the class InfoController method initS3.
/**
*/
private void initS3() {
bucketLocationField.setStringValue(LocaleFactory.localizedString("Unknown"));
bucketLoggingPopup.removeAllItems();
bucketLoggingPopup.addItemWithTitle(LocaleFactory.localizedString("None"));
bucketLoggingPopup.lastItem().setEnabled(false);
storageClassPopup.removeAllItems();
storageClassPopup.addItemWithTitle(LocaleFactory.localizedString("Unknown"));
storageClassPopup.lastItem().setEnabled(false);
storageClassPopup.selectItem(storageClassPopup.lastItem());
encryptionPopup.removeAllItems();
encryptionPopup.addItemWithTitle(LocaleFactory.localizedString("Unknown"));
encryptionPopup.lastItem().setEnabled(false);
encryptionPopup.selectItem(encryptionPopup.lastItem());
if (this.toggleS3Settings(false)) {
final Path file = this.getSelected();
if (session.getFeature(Redundancy.class) != null) {
for (String redundancy : session.getFeature(Redundancy.class).getClasses()) {
storageClassPopup.addItemWithTitle(LocaleFactory.localizedString(redundancy, "S3"));
storageClassPopup.lastItem().setRepresentedObject(redundancy);
}
}
this.background(new RegistryBackgroundAction<Void>(controller, session) {
Location.Name location;
LoggingConfiguration logging;
VersioningConfiguration versioning;
// Available encryption keys in KMS
Set<Encryption.Algorithm> managedEncryptionKeys = new HashSet<>();
final Set<Encryption.Algorithm> selectedEncryptionKeys = new HashSet<>();
final Set<String> selectedStorageClasses = new HashSet<>();
LifecycleConfiguration lifecycle;
Boolean transferAcceleration;
@Override
public Void run(final Session<?> session) throws BackgroundException {
if (session.getFeature(Location.class) != null) {
location = session.getFeature(Location.class).getLocation(file);
}
if (session.getFeature(Logging.class) != null) {
logging = session.getFeature(Logging.class).getConfiguration(file);
}
if (session.getFeature(Versioning.class) != null) {
versioning = session.getFeature(Versioning.class).getConfiguration(file);
}
if (session.getFeature(Lifecycle.class) != null) {
lifecycle = session.getFeature(Lifecycle.class).getConfiguration(file);
}
if (session.getFeature(Redundancy.class) != null) {
for (final Path f : files) {
selectedStorageClasses.add(session.getFeature(Redundancy.class).getClass(f));
}
}
if (session.getFeature(Encryption.class) != null) {
// Add additional keys stored in KMS
managedEncryptionKeys = session.getFeature(Encryption.class).getKeys(file, prompt);
for (final Path f : files) {
selectedEncryptionKeys.add(session.getFeature(Encryption.class).getEncryption(f));
}
managedEncryptionKeys.addAll(selectedEncryptionKeys);
}
if (session.getFeature(TransferAcceleration.class) != null) {
try {
transferAcceleration = session.getFeature(TransferAcceleration.class).getStatus(file);
} catch (InteroperabilityException e) {
log.warn(String.format("Ignore failure %s reading transfer acceleration", e));
// 405 The specified method is not allowed against this resource
}
}
return null;
}
@Override
public void cleanup() {
super.cleanup();
if (logging != null) {
bucketLoggingButton.setState(logging.isEnabled() ? NSCell.NSOnState : NSCell.NSOffState);
if (!logging.getContainers().isEmpty()) {
bucketLoggingPopup.removeAllItems();
}
for (Path c : logging.getContainers()) {
bucketLoggingPopup.addItemWithTitle(c.getName());
bucketLoggingPopup.lastItem().setRepresentedObject(c.getName());
}
if (logging.isEnabled()) {
bucketLoggingPopup.selectItemWithTitle(logging.getLoggingTarget());
} else {
if (!logging.getContainers().isEmpty()) {
// Default to write log files to origin bucket
bucketLoggingPopup.selectItemAtIndex(bucketLoggingPopup.indexOfItemWithRepresentedObject(containerService.getContainer(file).getName()));
}
}
}
if (location != null) {
bucketLocationField.setStringValue(location.toString());
}
if (versioning != null) {
bucketVersioningButton.setState(versioning.isEnabled() ? NSCell.NSOnState : NSCell.NSOffState);
bucketMfaButton.setState(versioning.isMultifactor() ? NSCell.NSOnState : NSCell.NSOffState);
}
for (Encryption.Algorithm algorithm : managedEncryptionKeys) {
encryptionPopup.addItemWithTitle(LocaleFactory.localizedString(algorithm.getDescription(), "S3"));
encryptionPopup.lastItem().setRepresentedObject(algorithm.toString());
}
if (!selectedEncryptionKeys.isEmpty()) {
encryptionPopup.selectItemAtIndex(new NSInteger(-1));
if (-1 != encryptionPopup.indexOfItemWithTitle(LocaleFactory.localizedString("Unknown")).intValue()) {
encryptionPopup.removeItemWithTitle(LocaleFactory.localizedString("Unknown"));
}
}
for (Encryption.Algorithm algorithm : selectedEncryptionKeys) {
encryptionPopup.selectItemAtIndex(encryptionPopup.indexOfItemWithRepresentedObject(algorithm.toString()));
}
for (Encryption.Algorithm algorithm : selectedEncryptionKeys) {
encryptionPopup.itemAtIndex(encryptionPopup.indexOfItemWithRepresentedObject(algorithm.toString())).setState(selectedEncryptionKeys.size() == 1 ? NSCell.NSOnState : NSCell.NSMixedState);
}
if (!selectedStorageClasses.isEmpty()) {
storageClassPopup.selectItemAtIndex(new NSInteger(-1));
if (-1 != storageClassPopup.indexOfItemWithTitle(LocaleFactory.localizedString("Unknown")).intValue()) {
storageClassPopup.removeItemWithTitle(LocaleFactory.localizedString("Unknown"));
}
}
for (String storageClass : selectedStorageClasses) {
if (-1 != storageClassPopup.indexOfItemWithRepresentedObject(storageClass).intValue()) {
storageClassPopup.selectItemAtIndex(storageClassPopup.indexOfItemWithRepresentedObject(storageClass));
}
}
for (String storageClass : selectedStorageClasses) {
if (-1 != storageClassPopup.indexOfItemWithRepresentedObject(storageClass).intValue()) {
storageClassPopup.itemAtIndex(storageClassPopup.indexOfItemWithRepresentedObject(storageClass)).setState(selectedStorageClasses.size() == 1 ? NSCell.NSOnState : NSCell.NSMixedState);
}
}
if (lifecycle != null) {
lifecycleDeleteCheckbox.setState(lifecycle.getExpiration() != null ? NSCell.NSOnState : NSCell.NSOffState);
if (lifecycle.getExpiration() != null) {
final NSInteger index = lifecycleDeletePopup.indexOfItemWithRepresentedObject(String.valueOf(lifecycle.getExpiration()));
if (-1 == index.intValue()) {
lifecycleDeletePopup.addItemWithTitle(MessageFormat.format(LocaleFactory.localizedString("after {0} Days", "S3"), String.valueOf(lifecycle.getExpiration())));
lifecycleDeletePopup.lastItem().setAction(Foundation.selector("lifecyclePopupClicked:"));
lifecycleDeletePopup.lastItem().setTarget(id());
lifecycleDeletePopup.lastItem().setRepresentedObject(String.valueOf(lifecycle.getExpiration()));
}
lifecycleDeletePopup.selectItemAtIndex(lifecycleDeletePopup.indexOfItemWithRepresentedObject(String.valueOf(lifecycle.getExpiration())));
}
lifecycleTransitionCheckbox.setState(lifecycle.getTransition() != null ? NSCell.NSOnState : NSCell.NSOffState);
if (lifecycle.getTransition() != null) {
final NSInteger index = lifecycleTransitionPopup.indexOfItemWithRepresentedObject(String.valueOf(lifecycle.getTransition()));
if (-1 == index.intValue()) {
lifecycleTransitionPopup.addItemWithTitle(MessageFormat.format(LocaleFactory.localizedString("after {0} Days", "S3"), String.valueOf(lifecycle.getTransition())));
lifecycleTransitionPopup.lastItem().setAction(Foundation.selector("lifecyclePopupClicked:"));
lifecycleTransitionPopup.lastItem().setTarget(id());
lifecycleTransitionPopup.lastItem().setRepresentedObject(String.valueOf(lifecycle.getTransition()));
}
lifecycleTransitionPopup.selectItemAtIndex(lifecycleTransitionPopup.indexOfItemWithRepresentedObject(String.valueOf(lifecycle.getTransition())));
}
}
if (transferAcceleration != null) {
bucketTransferAccelerationButton.setState(transferAcceleration ? NSCell.NSOnState : NSCell.NSOffState);
}
toggleS3Settings(true);
}
@Override
public String getActivity() {
return MessageFormat.format(LocaleFactory.localizedString("Reading metadata of {0}", "Status"), this.toString(files));
}
});
}
}
use of ch.cyberduck.core.features.TransferAcceleration in project cyberduck by iterate-ch.
the class WriteTransferAccelerationWorker method run.
@Override
public Boolean run(final Session<?> session) throws BackgroundException {
final TransferAcceleration feature = session.getFeature(TransferAcceleration.class);
if (log.isDebugEnabled()) {
log.debug(String.format("Run with feature %s", feature));
}
final PathContainerService container = session.getFeature(PathContainerService.class);
for (Path file : this.getContainers(container, files)) {
if (this.isCanceled()) {
throw new ConnectionCanceledException();
}
this.write(feature, file);
}
return true;
}
Aggregations