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 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);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class AzureCertificateHelper method getHttpsURLConnectionProvider.
@NotNull
private static HttpsURLConnectionProvider getHttpsURLConnectionProvider(@NotNull final SSLSocketFactory sslSocketFactory, @NotNull final RestServiceManager manager) {
return new HttpsURLConnectionProvider() {
@Override
@NotNull
public HttpsURLConnection getSSLConnection(@NotNull String managementUrl, @NotNull String path, @NotNull ContentType contentType) throws AzureCmdException {
HttpsURLConnection sslConnection = manager.getSSLConnection(managementUrl, path, contentType);
sslConnection.setSSLSocketFactory(sslSocketFactory);
return sslConnection;
}
};
}
use of com.microsoft.azuretools.azurecommons.helpers.NotNull in project azure-tools-for-java by Microsoft.
the class RestServiceManagerBaseImpl method getSSLConnection.
@NotNull
public HttpsURLConnection getSSLConnection(@NotNull String managementUrl, @NotNull String path, @NotNull ContentType contentType) throws AzureCmdException {
try {
URL myUrl = new URL(managementUrl + path);
HttpsURLConnection conn = (HttpsURLConnection) myUrl.openConnection();
conn.addRequestProperty(USER_AGENT_HEADER, getPlatformUserAgent());
conn.addRequestProperty(TELEMETRY_HEADER, getPlatformUserAgent());
conn.addRequestProperty(X_MS_VERSION_HEADER, AZURE_API_VERSION);
conn.addRequestProperty(ACCEPT_HEADER, "");
if (contentType != null) {
conn.addRequestProperty(CONTENT_TYPE_HEADER, contentType.toString());
}
return conn;
} catch (IOException e) {
throw new AzureCmdException(e.getMessage(), e);
}
}
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);
}
}
Aggregations