use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method getTableEntity.
@NotNull
private static TableEntity getTableEntity(@NotNull String tableName, @NotNull DynamicTableEntity dte) {
String partitionKey = Strings.nullToEmpty(dte.getPartitionKey());
String rowKey = Strings.nullToEmpty(dte.getRowKey());
String eTag = Strings.nullToEmpty(dte.getEtag());
Calendar timestamp = new GregorianCalendar();
if (dte.getTimestamp() != null) {
timestamp.setTime(dte.getTimestamp());
}
Map<String, Property> properties = new HashMap<String, Property>();
if (dte.getProperties() != null) {
for (Entry<String, EntityProperty> entry : dte.getProperties().entrySet()) {
if (entry.getKey() != null && entry.getValue() != null) {
String key = entry.getKey();
Property property;
switch(entry.getValue().getEdmType()) {
case BOOLEAN:
property = new Property(entry.getValue().getValueAsBooleanObject());
break;
case DATE_TIME:
Calendar value = new GregorianCalendar();
value.setTime(entry.getValue().getValueAsDate());
property = new Property(value);
break;
case DOUBLE:
property = new Property(entry.getValue().getValueAsDoubleObject());
break;
case GUID:
property = new Property(entry.getValue().getValueAsUUID());
break;
case INT32:
property = new Property(entry.getValue().getValueAsIntegerObject());
break;
case INT64:
property = new Property(entry.getValue().getValueAsLongObject());
break;
case STRING:
property = new Property(entry.getValue().getValueAsString());
break;
default:
property = new Property(entry.getValue().getValueAsString());
break;
}
properties.put(key, property);
}
}
}
return new TableEntity(partitionKey, rowKey, tableName, eTag, timestamp, properties);
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method createBlobDirectory.
@NotNull
public BlobDirectory createBlobDirectory(@NotNull StorageAccount storageAccount, @NotNull BlobDirectory parentBlobDirectory, @NotNull BlobDirectory blobDirectory) throws AzureCmdException {
try {
CloudBlobClient client = getCloudBlobClient(storageAccount);
String containerName = parentBlobDirectory.getContainerName();
CloudBlobContainer container = client.getContainerReference(containerName);
CloudBlobDirectory parentDirectory = container.getDirectoryReference(parentBlobDirectory.getPath());
CloudBlobDirectory directory = parentDirectory.getDirectoryReference(blobDirectory.getName());
String uri = directory.getUri() != null ? directory.getUri().toString() : "";
String path = Strings.nullToEmpty(directory.getPrefix());
blobDirectory.setUri(uri);
blobDirectory.setContainerName(containerName);
blobDirectory.setPath(path);
return blobDirectory;
} catch (Throwable t) {
throw new AzureCmdException("Error creating the Blob Directory", t);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method createBlobFile.
@NotNull
public BlobFile createBlobFile(@NotNull ClientStorageAccount storageAccount, @NotNull BlobDirectory parentBlobDirectory, @NotNull BlobFile blobFile) throws AzureCmdException {
try {
CloudBlobClient client = getCloudBlobClient(storageAccount);
String containerName = parentBlobDirectory.getContainerName();
CloudBlobContainer container = client.getContainerReference(containerName);
CloudBlobDirectory parentDirectory = container.getDirectoryReference(parentBlobDirectory.getPath());
CloudBlob blob = getCloudBlob(parentDirectory, blobFile);
blob.upload(new ByteArrayInputStream(new byte[0]), 0);
return reloadBlob(blob, containerName, blobFile);
} catch (Throwable t) {
throw new AzureCmdException("Error creating the Blob File", t);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method createBlobContainer.
@NotNull
public BlobContainer createBlobContainer(@NotNull String connectionString, @NotNull BlobContainer blobContainer) throws AzureCmdException {
try {
CloudBlobClient client = getCloudBlobClient(connectionString);
CloudBlobContainer container = client.getContainerReference(blobContainer.getName());
container.createIfNotExists();
container.downloadAttributes();
String uri = container.getUri() != null ? container.getUri().toString() : "";
String eTag = "";
Calendar lastModified = new GregorianCalendar();
BlobContainerProperties properties = container.getProperties();
if (properties != null) {
eTag = Strings.nullToEmpty(properties.getEtag());
if (properties.getLastModified() != null) {
lastModified.setTime(properties.getLastModified());
}
}
String publicReadAccessType = "";
BlobContainerPermissions blobContainerPermissions = container.downloadPermissions();
if (blobContainerPermissions != null && blobContainerPermissions.getPublicAccess() != null) {
publicReadAccessType = blobContainerPermissions.getPublicAccess().toString();
}
blobContainer.setUri(uri);
blobContainer.setETag(eTag);
blobContainer.setLastModified(lastModified);
blobContainer.setPublicReadAccessType(publicReadAccessType);
return blobContainer;
} catch (Throwable t) {
throw new AzureCmdException("Error creating the Blob Container", t);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class StorageClientSDKManager method updateTableEntity.
@NotNull
public TableEntity updateTableEntity(@NotNull StorageAccount storageAccount, @NotNull TableEntity tableEntity) throws AzureCmdException {
try {
CloudTableClient client = getCloudTableClient(storageAccount);
CloudTable cloudTable = client.getTableReference(tableEntity.getTableName());
DynamicTableEntity entity = getDynamicTableEntity(tableEntity);
TableRequestOptions tro = new TableRequestOptions();
tro.setTablePayloadFormat(TablePayloadFormat.JsonFullMetadata);
TableResult result = cloudTable.execute(TableOperation.replace(entity), tro, null);
DynamicTableEntity resultEntity = result.getResultAsType();
return getTableEntity(tableEntity.getTableName(), resultEntity);
} catch (Throwable t) {
throw new AzureCmdException("Error updating the Table Entity", t);
}
}
Aggregations