@Test public void testSetMetadata() throws Exception { final Host host = new Host(new AzureProtocol(), "kahy9boj3eib.blob.core.windows.net", new Credentials( System.getProperties().getProperty("azure.account"), System.getProperties().getProperty("azure.key") )); final AzureSession session = new AzureSession(host); new LoginConnectionService(new DisabledLoginCallback(), new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener()).connect(session, PathCache.empty(), new DisabledCancelCallback()); final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new Path(container, UUID.randomUUID().toString() + ".txt", EnumSet.of(Path.Type.file)); new AzureTouchFeature(session, null).touch(test, new TransferStatus()); final String v = UUID.randomUUID().toString(); new AzureMetadataFeature(session, null).setMetadata(test, Collections.<String, String>singletonMap("Test", v)); final Map<String, String> metadata = new AzureMetadataFeature(session, null).getMetadata(test); assertFalse(metadata.isEmpty()); assertTrue(metadata.containsKey("Test")); assertEquals(v, metadata.get("Test")); new AzureDeleteFeature(session, null).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
@Override public void setMetadata(final Path file, final TransferStatus status) throws BackgroundException { try { final BlobRequestOptions options = new BlobRequestOptions(); if(containerService.isContainer(file)) { final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(file).getName()); container.setMetadata(new HashMap<>(status.getMetadata())); container.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context); } else { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); blob.downloadAttributes(); final HashMap<String, String> pruned = new HashMap<>(); for(Map.Entry<String, String> m : status.getMetadata().entrySet()) { final BlobProperties properties = blob.getProperties(); if(HttpHeaders.CACHE_CONTROL.equalsIgnoreCase(m.getKey())) { properties.setCacheControl(m.getValue()); continue; } if(HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(m.getKey())) { properties.setContentType(m.getValue()); continue; } pruned.put(m.getKey(), m.getValue()); } blob.setMetadata(pruned); blob.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context); blob.uploadProperties(); } } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } catch(StorageException e) { throw new AzureExceptionMappingService().map("Failure to write attributes of {0}", e, file); } }
AzureMetadataFeature implements Headers { @Override public void setMetadata(final Path file, final TransferStatus status) throws BackgroundException { try { final BlobRequestOptions options = new BlobRequestOptions(); if(containerService.isContainer(file)) { final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(file).getName()); container.setMetadata(new HashMap<>(status.getMetadata())); container.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context); } else { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); blob.downloadAttributes(); final HashMap<String, String> pruned = new HashMap<>(); for(Map.Entry<String, String> m : status.getMetadata().entrySet()) { final BlobProperties properties = blob.getProperties(); if(HttpHeaders.CACHE_CONTROL.equalsIgnoreCase(m.getKey())) { properties.setCacheControl(m.getValue()); continue; } if(HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(m.getKey())) { properties.setContentType(m.getValue()); continue; } pruned.put(m.getKey(), m.getValue()); } blob.setMetadata(pruned); blob.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context); blob.uploadProperties(); } } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } catch(StorageException e) { throw new AzureExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } }
AzureMetadataFeature implements Headers { @Override public void setMetadata(final Path file, final TransferStatus status) throws BackgroundException { try { final BlobRequestOptions options = new BlobRequestOptions(); if(containerService.isContainer(file)) { final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(file).getName()); container.setMetadata(new HashMap<>(status.getMetadata())); container.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context); } else { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); blob.downloadAttributes(); final HashMap<String, String> pruned = new HashMap<>(); for(Map.Entry<String, String> m : status.getMetadata().entrySet()) { final BlobProperties properties = blob.getProperties(); if(HttpHeaders.CACHE_CONTROL.equalsIgnoreCase(m.getKey())) { properties.setCacheControl(m.getValue()); continue; } if(HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(m.getKey())) { properties.setContentType(m.getValue()); continue; } pruned.put(m.getKey(), m.getValue()); } blob.setMetadata(pruned); blob.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context); blob.uploadProperties(); } } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } catch(StorageException e) { throw new AzureExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } AzureMetadataFeature(final AzureSession session, final OperationContext context); }
AzureMetadataFeature implements Headers { @Override public void setMetadata(final Path file, final TransferStatus status) throws BackgroundException { try { final BlobRequestOptions options = new BlobRequestOptions(); if(containerService.isContainer(file)) { final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(file).getName()); container.setMetadata(new HashMap<>(status.getMetadata())); container.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context); } else { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); blob.downloadAttributes(); final HashMap<String, String> pruned = new HashMap<>(); for(Map.Entry<String, String> m : status.getMetadata().entrySet()) { final BlobProperties properties = blob.getProperties(); if(HttpHeaders.CACHE_CONTROL.equalsIgnoreCase(m.getKey())) { properties.setCacheControl(m.getValue()); continue; } if(HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(m.getKey())) { properties.setContentType(m.getValue()); continue; } pruned.put(m.getKey(), m.getValue()); } blob.setMetadata(pruned); blob.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context); blob.uploadProperties(); } } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } catch(StorageException e) { throw new AzureExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } AzureMetadataFeature(final AzureSession session, final OperationContext context); @Override Map<String, String> getDefault(final Local local); @Override Map<String, String> getMetadata(final Path file); @Override void setMetadata(final Path file, final TransferStatus status); }
AzureMetadataFeature implements Headers { @Override public void setMetadata(final Path file, final TransferStatus status) throws BackgroundException { try { final BlobRequestOptions options = new BlobRequestOptions(); if(containerService.isContainer(file)) { final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(file).getName()); container.setMetadata(new HashMap<>(status.getMetadata())); container.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context); } else { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); blob.downloadAttributes(); final HashMap<String, String> pruned = new HashMap<>(); for(Map.Entry<String, String> m : status.getMetadata().entrySet()) { final BlobProperties properties = blob.getProperties(); if(HttpHeaders.CACHE_CONTROL.equalsIgnoreCase(m.getKey())) { properties.setCacheControl(m.getValue()); continue; } if(HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(m.getKey())) { properties.setContentType(m.getValue()); continue; } pruned.put(m.getKey(), m.getValue()); } blob.setMetadata(pruned); blob.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context); blob.uploadProperties(); } } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } catch(StorageException e) { throw new AzureExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } AzureMetadataFeature(final AzureSession session, final OperationContext context); @Override Map<String, String> getDefault(final Local local); @Override Map<String, String> getMetadata(final Path file); @Override void setMetadata(final Path file, final TransferStatus status);  }