Search in sources :

Example 21 with NotNull

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);
}
Also used : TableEntity(com.microsoft.tooling.msservices.model.storage.TableEntity) Property(com.microsoft.tooling.msservices.model.storage.TableEntity.Property) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 22 with NotNull

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);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 23 with NotNull

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;
        }
    };
}
Also used : HttpsURLConnectionProvider(com.microsoft.tooling.msservices.helpers.azure.rest.RestServiceManager.HttpsURLConnectionProvider) ContentType(com.microsoft.tooling.msservices.helpers.azure.rest.RestServiceManager.ContentType) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 24 with NotNull

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);
    }
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) URL(java.net.URL) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 25 with NotNull

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Aggregations

NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)32 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)20 CloudQueue (com.microsoft.azure.storage.queue.CloudQueue)4 CloudQueueClient (com.microsoft.azure.storage.queue.CloudQueueClient)4 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)4 Project (com.intellij.openapi.project.Project)3 Artifact (com.intellij.packaging.artifacts.Artifact)2 CloudQueueMessage (com.microsoft.azure.storage.queue.CloudQueueMessage)2 ContentType (com.microsoft.tooling.msservices.helpers.azure.rest.RestServiceManager.ContentType)2 HttpsURLConnectionProvider (com.microsoft.tooling.msservices.helpers.azure.rest.RestServiceManager.HttpsURLConnectionProvider)2 BlobDirectory (com.microsoft.tooling.msservices.model.storage.BlobDirectory)2 BlobFile (com.microsoft.tooling.msservices.model.storage.BlobFile)2 QueueMessage (com.microsoft.tooling.msservices.model.storage.QueueMessage)2 TableEntity (com.microsoft.tooling.msservices.model.storage.TableEntity)2 Property (com.microsoft.tooling.msservices.model.storage.TableEntity.Property)2 FileType (com.intellij.openapi.fileTypes.FileType)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1 Nullable (com.microsoft.azuretools.azurecommons.helpers.Nullable)1 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)1