Example usage for javax.xml.bind DatatypeConverter parseDateTime

List of usage examples for javax.xml.bind DatatypeConverter parseDateTime

Introduction

In this page you can find the example usage for javax.xml.bind DatatypeConverter parseDateTime.

Prototype

public static java.util.Calendar parseDateTime(String lexicalXSDDateTime) 

Source Link

Document

Converts the string argument into a Calendar value.

Usage

From source file:com.microsoft.azure.management.sql.RecommendedElasticPoolOperationsImpl.java

/**
* Returns information about an Azure SQL Recommended Elastic Pool.
*
* @param resourceGroupName Required. The name of the Resource Group to
* which the Azure SQL Recommended Server belongs.
* @param serverName Required. The name of the Azure SQL Database Server for
* which the Azure SQL Recommended Elastic Pool is.
* @param recommendedElasticPoolName Required. The name of the Azure SQL
* Recommended Elastic Pool to be retrieved.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.//from   ww  w. ja v a 2  s . c o  m
* @throws ServiceException Thrown if an unexpected response is found.
* @return Represents the response to a Get Azure Sql Recommended Resource
* pool request.
*/
@Override
public RecommendedElasticPoolGetResponse get(String resourceGroupName, String serverName,
        String recommendedElasticPoolName) throws IOException, ServiceException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (serverName == null) {
        throw new NullPointerException("serverName");
    }
    if (recommendedElasticPoolName == null) {
        throw new NullPointerException("recommendedElasticPoolName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("serverName", serverName);
        tracingParameters.put("recommendedElasticPoolName", recommendedElasticPoolName);
        CloudTracing.enter(invocationId, this, "getAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourceGroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    url = url + "/providers/";
    url = url + "Microsoft.Sql";
    url = url + "/servers/";
    url = url + URLEncoder.encode(serverName, "UTF-8");
    url = url + "/recommendedElasticPools/";
    url = url + URLEncoder.encode(recommendedElasticPoolName, "UTF-8");
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2014-04-01");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        RecommendedElasticPoolGetResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new RecommendedElasticPoolGetResponse();
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                RecommendedElasticPool recommendedElasticPoolInstance = new RecommendedElasticPool();
                result.setRecommendedElasticPool(recommendedElasticPoolInstance);

                JsonNode propertiesValue = responseDoc.get("properties");
                if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                    RecommendedElasticPoolProperties propertiesInstance = new RecommendedElasticPoolProperties();
                    recommendedElasticPoolInstance.setProperties(propertiesInstance);

                    JsonNode databaseEditionValue = propertiesValue.get("databaseEdition");
                    if (databaseEditionValue != null && databaseEditionValue instanceof NullNode == false) {
                        String databaseEditionInstance;
                        databaseEditionInstance = databaseEditionValue.getTextValue();
                        propertiesInstance.setDatabaseEdition(databaseEditionInstance);
                    }

                    JsonNode dtuValue = propertiesValue.get("dtu");
                    if (dtuValue != null && dtuValue instanceof NullNode == false) {
                        double dtuInstance;
                        dtuInstance = dtuValue.getDoubleValue();
                        propertiesInstance.setDtu(dtuInstance);
                    }

                    JsonNode databaseDtuMinValue = propertiesValue.get("databaseDtuMin");
                    if (databaseDtuMinValue != null && databaseDtuMinValue instanceof NullNode == false) {
                        double databaseDtuMinInstance;
                        databaseDtuMinInstance = databaseDtuMinValue.getDoubleValue();
                        propertiesInstance.setDatabaseDtuMin(databaseDtuMinInstance);
                    }

                    JsonNode databaseDtuMaxValue = propertiesValue.get("databaseDtuMax");
                    if (databaseDtuMaxValue != null && databaseDtuMaxValue instanceof NullNode == false) {
                        double databaseDtuMaxInstance;
                        databaseDtuMaxInstance = databaseDtuMaxValue.getDoubleValue();
                        propertiesInstance.setDatabaseDtuMax(databaseDtuMaxInstance);
                    }

                    JsonNode storageMBValue = propertiesValue.get("storageMB");
                    if (storageMBValue != null && storageMBValue instanceof NullNode == false) {
                        double storageMBInstance;
                        storageMBInstance = storageMBValue.getDoubleValue();
                        propertiesInstance.setStorageMB(storageMBInstance);
                    }

                    JsonNode observationPeriodStartValue = propertiesValue.get("observationPeriodStart");
                    if (observationPeriodStartValue != null
                            && observationPeriodStartValue instanceof NullNode == false) {
                        Calendar observationPeriodStartInstance;
                        observationPeriodStartInstance = DatatypeConverter
                                .parseDateTime(observationPeriodStartValue.getTextValue());
                        propertiesInstance.setObservationPeriodStart(observationPeriodStartInstance);
                    }

                    JsonNode observationPeriodEndValue = propertiesValue.get("observationPeriodEnd");
                    if (observationPeriodEndValue != null
                            && observationPeriodEndValue instanceof NullNode == false) {
                        Calendar observationPeriodEndInstance;
                        observationPeriodEndInstance = DatatypeConverter
                                .parseDateTime(observationPeriodEndValue.getTextValue());
                        propertiesInstance.setObservationPeriodEnd(observationPeriodEndInstance);
                    }

                    JsonNode maxObservedDtuValue = propertiesValue.get("maxObservedDtu");
                    if (maxObservedDtuValue != null && maxObservedDtuValue instanceof NullNode == false) {
                        double maxObservedDtuInstance;
                        maxObservedDtuInstance = maxObservedDtuValue.getDoubleValue();
                        propertiesInstance.setMaxObservedDtu(maxObservedDtuInstance);
                    }

                    JsonNode maxObservedStorageMBValue = propertiesValue.get("maxObservedStorageMB");
                    if (maxObservedStorageMBValue != null
                            && maxObservedStorageMBValue instanceof NullNode == false) {
                        double maxObservedStorageMBInstance;
                        maxObservedStorageMBInstance = maxObservedStorageMBValue.getDoubleValue();
                        propertiesInstance.setMaxObservedStorageMB(maxObservedStorageMBInstance);
                    }

                    JsonNode databasesArray = propertiesValue.get("databases");
                    if (databasesArray != null && databasesArray instanceof NullNode == false) {
                        for (JsonNode databasesValue : ((ArrayNode) databasesArray)) {
                            Database databaseInstance = new Database();
                            propertiesInstance.getDatabases().add(databaseInstance);

                            JsonNode propertiesValue2 = databasesValue.get("properties");
                            if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) {
                                DatabaseProperties propertiesInstance2 = new DatabaseProperties();
                                databaseInstance.setProperties(propertiesInstance2);

                                JsonNode collationValue = propertiesValue2.get("collation");
                                if (collationValue != null && collationValue instanceof NullNode == false) {
                                    String collationInstance;
                                    collationInstance = collationValue.getTextValue();
                                    propertiesInstance2.setCollation(collationInstance);
                                }

                                JsonNode creationDateValue = propertiesValue2.get("creationDate");
                                if (creationDateValue != null
                                        && creationDateValue instanceof NullNode == false) {
                                    Calendar creationDateInstance;
                                    creationDateInstance = DatatypeConverter
                                            .parseDateTime(creationDateValue.getTextValue());
                                    propertiesInstance2.setCreationDate(creationDateInstance);
                                }

                                JsonNode currentServiceObjectiveIdValue = propertiesValue2
                                        .get("currentServiceObjectiveId");
                                if (currentServiceObjectiveIdValue != null
                                        && currentServiceObjectiveIdValue instanceof NullNode == false) {
                                    String currentServiceObjectiveIdInstance;
                                    currentServiceObjectiveIdInstance = currentServiceObjectiveIdValue
                                            .getTextValue();
                                    propertiesInstance2
                                            .setCurrentServiceObjectiveId(currentServiceObjectiveIdInstance);
                                }

                                JsonNode databaseIdValue = propertiesValue2.get("databaseId");
                                if (databaseIdValue != null && databaseIdValue instanceof NullNode == false) {
                                    String databaseIdInstance;
                                    databaseIdInstance = databaseIdValue.getTextValue();
                                    propertiesInstance2.setDatabaseId(databaseIdInstance);
                                }

                                JsonNode earliestRestoreDateValue = propertiesValue2.get("earliestRestoreDate");
                                if (earliestRestoreDateValue != null
                                        && earliestRestoreDateValue instanceof NullNode == false) {
                                    Calendar earliestRestoreDateInstance;
                                    earliestRestoreDateInstance = DatatypeConverter
                                            .parseDateTime(earliestRestoreDateValue.getTextValue());
                                    propertiesInstance2.setEarliestRestoreDate(earliestRestoreDateInstance);
                                }

                                JsonNode editionValue = propertiesValue2.get("edition");
                                if (editionValue != null && editionValue instanceof NullNode == false) {
                                    String editionInstance;
                                    editionInstance = editionValue.getTextValue();
                                    propertiesInstance2.setEdition(editionInstance);
                                }

                                JsonNode maxSizeBytesValue = propertiesValue2.get("maxSizeBytes");
                                if (maxSizeBytesValue != null
                                        && maxSizeBytesValue instanceof NullNode == false) {
                                    long maxSizeBytesInstance;
                                    maxSizeBytesInstance = maxSizeBytesValue.getLongValue();
                                    propertiesInstance2.setMaxSizeBytes(maxSizeBytesInstance);
                                }

                                JsonNode requestedServiceObjectiveIdValue = propertiesValue2
                                        .get("requestedServiceObjectiveId");
                                if (requestedServiceObjectiveIdValue != null
                                        && requestedServiceObjectiveIdValue instanceof NullNode == false) {
                                    String requestedServiceObjectiveIdInstance;
                                    requestedServiceObjectiveIdInstance = requestedServiceObjectiveIdValue
                                            .getTextValue();
                                    propertiesInstance2.setRequestedServiceObjectiveId(
                                            requestedServiceObjectiveIdInstance);
                                }

                                JsonNode requestedServiceObjectiveNameValue = propertiesValue2
                                        .get("requestedServiceObjectiveName");
                                if (requestedServiceObjectiveNameValue != null
                                        && requestedServiceObjectiveNameValue instanceof NullNode == false) {
                                    String requestedServiceObjectiveNameInstance;
                                    requestedServiceObjectiveNameInstance = requestedServiceObjectiveNameValue
                                            .getTextValue();
                                    propertiesInstance2.setRequestedServiceObjectiveName(
                                            requestedServiceObjectiveNameInstance);
                                }

                                JsonNode serviceLevelObjectiveValue = propertiesValue2
                                        .get("serviceLevelObjective");
                                if (serviceLevelObjectiveValue != null
                                        && serviceLevelObjectiveValue instanceof NullNode == false) {
                                    String serviceLevelObjectiveInstance;
                                    serviceLevelObjectiveInstance = serviceLevelObjectiveValue.getTextValue();
                                    propertiesInstance2.setServiceObjective(serviceLevelObjectiveInstance);
                                }

                                JsonNode statusValue = propertiesValue2.get("status");
                                if (statusValue != null && statusValue instanceof NullNode == false) {
                                    String statusInstance;
                                    statusInstance = statusValue.getTextValue();
                                    propertiesInstance2.setStatus(statusInstance);
                                }

                                JsonNode elasticPoolNameValue = propertiesValue2.get("elasticPoolName");
                                if (elasticPoolNameValue != null
                                        && elasticPoolNameValue instanceof NullNode == false) {
                                    String elasticPoolNameInstance;
                                    elasticPoolNameInstance = elasticPoolNameValue.getTextValue();
                                    propertiesInstance2.setElasticPoolName(elasticPoolNameInstance);
                                }

                                JsonNode serviceTierAdvisorsArray = propertiesValue2.get("serviceTierAdvisors");
                                if (serviceTierAdvisorsArray != null
                                        && serviceTierAdvisorsArray instanceof NullNode == false) {
                                    for (JsonNode serviceTierAdvisorsValue : ((ArrayNode) serviceTierAdvisorsArray)) {
                                        ServiceTierAdvisor serviceTierAdvisorInstance = new ServiceTierAdvisor();
                                        propertiesInstance2.getServiceTierAdvisors()
                                                .add(serviceTierAdvisorInstance);

                                        JsonNode propertiesValue3 = serviceTierAdvisorsValue.get("properties");
                                        if (propertiesValue3 != null
                                                && propertiesValue3 instanceof NullNode == false) {
                                            ServiceTierAdvisorProperties propertiesInstance3 = new ServiceTierAdvisorProperties();
                                            serviceTierAdvisorInstance.setProperties(propertiesInstance3);

                                            JsonNode observationPeriodStartValue2 = propertiesValue3
                                                    .get("observationPeriodStart");
                                            if (observationPeriodStartValue2 != null
                                                    && observationPeriodStartValue2 instanceof NullNode == false) {
                                                Calendar observationPeriodStartInstance2;
                                                observationPeriodStartInstance2 = DatatypeConverter
                                                        .parseDateTime(
                                                                observationPeriodStartValue2.getTextValue());
                                                propertiesInstance3.setObservationPeriodStart(
                                                        observationPeriodStartInstance2);
                                            }

                                            JsonNode observationPeriodEndValue2 = propertiesValue3
                                                    .get("observationPeriodEnd");
                                            if (observationPeriodEndValue2 != null
                                                    && observationPeriodEndValue2 instanceof NullNode == false) {
                                                Calendar observationPeriodEndInstance2;
                                                observationPeriodEndInstance2 = DatatypeConverter.parseDateTime(
                                                        observationPeriodEndValue2.getTextValue());
                                                propertiesInstance3
                                                        .setObservationPeriodEnd(observationPeriodEndInstance2);
                                            }

                                            JsonNode activeTimeRatioValue = propertiesValue3
                                                    .get("activeTimeRatio");
                                            if (activeTimeRatioValue != null
                                                    && activeTimeRatioValue instanceof NullNode == false) {
                                                double activeTimeRatioInstance;
                                                activeTimeRatioInstance = activeTimeRatioValue.getDoubleValue();
                                                propertiesInstance3.setActiveTimeRatio(activeTimeRatioInstance);
                                            }

                                            JsonNode minDtuValue = propertiesValue3.get("minDtu");
                                            if (minDtuValue != null
                                                    && minDtuValue instanceof NullNode == false) {
                                                double minDtuInstance;
                                                minDtuInstance = minDtuValue.getDoubleValue();
                                                propertiesInstance3.setMinDtu(minDtuInstance);
                                            }

                                            JsonNode avgDtuValue = propertiesValue3.get("avgDtu");
                                            if (avgDtuValue != null
                                                    && avgDtuValue instanceof NullNode == false) {
                                                double avgDtuInstance;
                                                avgDtuInstance = avgDtuValue.getDoubleValue();
                                                propertiesInstance3.setAvgDtu(avgDtuInstance);
                                            }

                                            JsonNode maxDtuValue = propertiesValue3.get("maxDtu");
                                            if (maxDtuValue != null
                                                    && maxDtuValue instanceof NullNode == false) {
                                                double maxDtuInstance;
                                                maxDtuInstance = maxDtuValue.getDoubleValue();
                                                propertiesInstance3.setMaxDtu(maxDtuInstance);
                                            }

                                            JsonNode maxSizeInGBValue = propertiesValue3.get("maxSizeInGB");
                                            if (maxSizeInGBValue != null
                                                    && maxSizeInGBValue instanceof NullNode == false) {
                                                double maxSizeInGBInstance;
                                                maxSizeInGBInstance = maxSizeInGBValue.getDoubleValue();
                                                propertiesInstance3.setMaxSizeInGB(maxSizeInGBInstance);
                                            }

                                            JsonNode serviceLevelObjectiveUsageMetricsArray = propertiesValue3
                                                    .get("serviceLevelObjectiveUsageMetrics");
                                            if (serviceLevelObjectiveUsageMetricsArray != null
                                                    && serviceLevelObjectiveUsageMetricsArray instanceof NullNode == false) {
                                                for (JsonNode serviceLevelObjectiveUsageMetricsValue : ((ArrayNode) serviceLevelObjectiveUsageMetricsArray)) {
                                                    SloUsageMetric sloUsageMetricInstance = new SloUsageMetric();
                                                    propertiesInstance3.getServiceLevelObjectiveUsageMetrics()
                                                            .add(sloUsageMetricInstance);

                                                    JsonNode serviceLevelObjectiveValue2 = serviceLevelObjectiveUsageMetricsValue
                                                            .get("serviceLevelObjective");
                                                    if (serviceLevelObjectiveValue2 != null
                                                            && serviceLevelObjectiveValue2 instanceof NullNode == false) {
                                                        String serviceLevelObjectiveInstance2;
                                                        serviceLevelObjectiveInstance2 = serviceLevelObjectiveValue2
                                                                .getTextValue();
                                                        sloUsageMetricInstance.setServiceLevelObjective(
                                                                serviceLevelObjectiveInstance2);
                                                    }

                                                    JsonNode serviceLevelObjectiveIdValue = serviceLevelObjectiveUsageMetricsValue
                                                            .get("serviceLevelObjectiveId");
                                                    if (serviceLevelObjectiveIdValue != null
                                                            && serviceLevelObjectiveIdValue instanceof NullNode == false) {
                                                        String serviceLevelObjectiveIdInstance;
                                                        serviceLevelObjectiveIdInstance = serviceLevelObjectiveIdValue
                                                                .getTextValue();
                                                        sloUsageMetricInstance.setServiceLevelObjectiveId(
                                                                serviceLevelObjectiveIdInstance);
                                                    }

                                                    JsonNode inRangeTimeRatioValue = serviceLevelObjectiveUsageMetricsValue
                                                            .get("inRangeTimeRatio");
                                                    if (inRangeTimeRatioValue != null
                                                            && inRangeTimeRatioValue instanceof NullNode == false) {
                                                        double inRangeTimeRatioInstance;
                                                        inRangeTimeRatioInstance = inRangeTimeRatioValue
                                                                .getDoubleValue();
                                                        sloUsageMetricInstance
                                                                .setInRangeTimeRatio(inRangeTimeRatioInstance);
                                                    }

                                                    JsonNode idValue = serviceLevelObjectiveUsageMetricsValue
                                                            .get("id");
                                                    if (idValue != null
                                                            && idValue instanceof NullNode == false) {
                                                        String idInstance;
                                                        idInstance = idValue.getTextValue();
                                                        sloUsageMetricInstance.setId(idInstance);
                                                    }

                                                    JsonNode nameValue = serviceLevelObjectiveUsageMetricsValue
                                                            .get("name");
                                                    if (nameValue != null
                                                            && nameValue instanceof NullNode == false) {
                                                        String nameInstance;
                                                        nameInstance = nameValue.getTextValue();
                                                        sloUsageMetricInstance.setName(nameInstance);
                                                    }

                                                    JsonNode typeValue = serviceLevelObjectiveUsageMetricsValue
                                                            .get("type");
                                                    if (typeValue != null
                                                            && typeValue instanceof NullNode == false) {
                                                        String typeInstance;
                                                        typeInstance = typeValue.getTextValue();
                                                        sloUsageMetricInstance.setType(typeInstance);
                                                    }

                                                    JsonNode locationValue = serviceLevelObjectiveUsageMetricsValue
                                                            .get("location");
                                                    if (locationValue != null
                                                            && locationValue instanceof NullNode == false) {
                                                        String locationInstance;
                                                        locationInstance = locationValue.getTextValue();
                                                        sloUsageMetricInstance.setLocation(locationInstance);
                                                    }

                                                    JsonNode tagsSequenceElement = ((JsonNode) serviceLevelObjectiveUsageMetricsValue
                                                            .get("tags"));
                                                    if (tagsSequenceElement != null
                                                            && tagsSequenceElement instanceof NullNode == false) {
                                                        Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement
                                                                .getFields();
                                                        while (itr.hasNext()) {
                                                            Map.Entry<String, JsonNode> property = itr.next();
                                                            String tagsKey = property.getKey();
                                                            String tagsValue = property.getValue()
                                                                    .getTextValue();
                                                            sloUsageMetricInstance.getTags().put(tagsKey,
                                                                    tagsValue);
                                                        }
                                                    }
                                                }
                                            }

                                            JsonNode currentServiceLevelObjectiveValue = propertiesValue3
                                                    .get("currentServiceLevelObjective");
                                            if (currentServiceLevelObjectiveValue != null
                                                    && currentServiceLevelObjectiveValue instanceof NullNode == false) {
                                                String currentServiceLevelObjectiveInstance;
                                                currentServiceLevelObjectiveInstance = currentServiceLevelObjectiveValue
                                                        .getTextValue();
                                                propertiesInstance3.setCurrentServiceLevelObjective(
                                                        currentServiceLevelObjectiveInstance);
                                            }

                                            JsonNode currentServiceLevelObjectiveIdValue = propertiesValue3
                                                    .get("currentServiceLevelObjectiveId");
                                            if (currentServiceLevelObjectiveIdValue != null
                                                    && currentServiceLevelObjectiveIdValue instanceof NullNode == false) {
                                                String currentServiceLevelObjectiveIdInstance;
                                                currentServiceLevelObjectiveIdInstance = currentServiceLevelObjectiveIdValue
                                                        .getTextValue();
                                                propertiesInstance3.setCurrentServiceLevelObjectiveId(
                                                        currentServiceLevelObjectiveIdInstance);
                                            }

                                            JsonNode usageBasedRecommendationServiceLevelObjectiveValue = propertiesValue3
                                                    .get("usageBasedRecommendationServiceLevelObjective");
                                            if (usageBasedRecommendationServiceLevelObjectiveValue != null
                                                    && usageBasedRecommendationServiceLevelObjectiveValue instanceof NullNode == false) {
                                                String usageBasedRecommendationServiceLevelObjectiveInstance;
                                                usageBasedRecommendationServiceLevelObjectiveInstance = usageBasedRecommendationServiceLevelObjectiveValue
                                                        .getTextValue();
                                                propertiesInstance3
                                                        .setUsageBasedRecommendationServiceLevelObjective(
                                                                usageBasedRecommendationServiceLevelObjectiveInstance);
                                            }

                                            JsonNode usageBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue3
                                                    .get("usageBasedRecommendationServiceLevelObjectiveId");
                                            if (usageBasedRecommendationServiceLevelObjectiveIdValue != null
                                                    && usageBasedRecommendationServiceLevelObjectiveIdValue instanceof NullNode == false) {
                                                String usageBasedRecommendationServiceLevelObjectiveIdInstance;
                                                usageBasedRecommendationServiceLevelObjectiveIdInstance = usageBasedRecommendationServiceLevelObjectiveIdValue
                                                        .getTextValue();
                                                propertiesInstance3
                                                        .setUsageBasedRecommendationServiceLevelObjectiveId(
                                                                usageBasedRecommendationServiceLevelObjectiveIdInstance);
                                            }

                                            JsonNode databaseSizeBasedRecommendationServiceLevelObjectiveValue = propertiesValue3
                                                    .get("databaseSizeBasedRecommendationServiceLevelObjective");
                                            if (databaseSizeBasedRecommendationServiceLevelObjectiveValue != null
                                                    && databaseSizeBasedRecommendationServiceLevelObjectiveValue instanceof NullNode == false) {
                                                String databaseSizeBasedRecommendationServiceLevelObjectiveInstance;
                                                databaseSizeBasedRecommendationServiceLevelObjectiveInstance = databaseSizeBasedRecommendationServiceLevelObjectiveValue
                                                        .getTextValue();
                                                propertiesInstance3
                                                        .setDatabaseSizeBasedRecommendationServiceLevelObjective(
                                                                databaseSizeBasedRecommendationServiceLevelObjectiveInstance);
                                            }

                                            JsonNode databaseSizeBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue3
                                                    .get("databaseSizeBasedRecommendationServiceLevelObjectiveId");
                                            if (databaseSizeBasedRecommendationServiceLevelObjectiveIdValue != null
                                                    && databaseSizeBasedRecommendationServiceLevelObjectiveIdValue instanceof NullNode == false) {
                                                String databaseSizeBasedRecommendationServiceLevelObjectiveIdInstance;
                                                databaseSizeBasedRecommendationServiceLevelObjectiveIdInstance = databaseSizeBasedRecommendationServiceLevelObjectiveIdValue
                                                        .getTextValue();
                                                propertiesInstance3
                                                        .setDatabaseSizeBasedRecommendationServiceLevelObjectiveId(
                                                                databaseSizeBasedRecommendationServiceLevelObjectiveIdInstance);
                                            }

                                            JsonNode disasterPlanBasedRecommendationServiceLevelObjectiveValue = propertiesValue3
                                                    .get("disasterPlanBasedRecommendationServiceLevelObjective");
                                            if (disasterPlanBasedRecommendationServiceLevelObjectiveValue != null
                                                    && disasterPlanBasedRecommendationServiceLevelObjectiveValue instanceof NullNode == false) {
                                                String disasterPlanBasedRecommendationServiceLevelObjectiveInstance;
                                                disasterPlanBasedRecommendationServiceLevelObjectiveInstance = disasterPlanBasedRecommendationServiceLevelObjectiveValue
                                                        .getTextValue();
                                                propertiesInstance3
                                                        .setDisasterPlanBasedRecommendationServiceLevelObjective(
                                                                disasterPlanBasedRecommendationServiceLevelObjectiveInstance);
                                            }

                                            JsonNode disasterPlanBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue3
                                                    .get("disasterPlanBasedRecommendationServiceLevelObjectiveId");
                                            if (disasterPlanBasedRecommendationServiceLevelObjectiveIdValue != null
                                                    && disasterPlanBasedRecommendationServiceLevelObjectiveIdValue instanceof NullNode == false) {
                                                String disasterPlanBasedRecommendationServiceLevelObjectiveIdInstance;
                                                disasterPlanBasedRecommendationServiceLevelObjectiveIdInstance = disasterPlanBasedRecommendationServiceLevelObjectiveIdValue
                                                        .getTextValue();
                                                propertiesInstance3
                                                        .setDisasterPlanBasedRecommendationServiceLevelObjectiveId(
                                                                disasterPlanBasedRecommendationServiceLevelObjectiveIdInstance);
                                            }

                                            JsonNode overallRecommendationServiceLevelObjectiveValue = propertiesValue3
                                                    .get("overallRecommendationServiceLevelObjective");
                                            if (overallRecommendationServiceLevelObjectiveValue != null
                                                    && overallRecommendationServiceLevelObjectiveValue instanceof NullNode == false) {
                                                String overallRecommendationServiceLevelObjectiveInstance;
                                                overallRecommendationServiceLevelObjectiveInstance = overallRecommendationServiceLevelObjectiveValue
                                                        .getTextValue();
                                                propertiesInstance3
                                                        .setOverallRecommendationServiceLevelObjective(
                                                                overallRecommendationServiceLevelObjectiveInstance);
                                            }

                                            JsonNode overallRecommendationServiceLevelObjectiveIdValue = propertiesValue3
                                                    .get("overallRecommendationServiceLevelObjectiveId");
                                            if (overallRecommendationServiceLevelObjectiveIdValue != null
                                                    && overallRecommendationServiceLevelObjectiveIdValue instanceof NullNode == false) {
                                                String overallRecommendationServiceLevelObjectiveIdInstance;
                                                overallRecommendationServiceLevelObjectiveIdInstance = overallRecommendationServiceLevelObjectiveIdValue
                                                        .getTextValue();
                                                propertiesInstance3
                                                        .setOverallRecommendationServiceLevelObjectiveId(
                                                                overallRecommendationServiceLevelObjectiveIdInstance);
                                            }

                                            JsonNode confidenceValue = propertiesValue3.get("confidence");
                                            if (confidenceValue != null
                                                    && confidenceValue instanceof NullNode == false) {
                                                double confidenceInstance;
                                                confidenceInstance = confidenceValue.getDoubleValue();
                                                propertiesInstance3.setConfidence(confidenceInstance);
                                            }
                                        }

                                        JsonNode idValue2 = serviceTierAdvisorsValue.get("id");
                                        if (idValue2 != null && idValue2 instanceof NullNode == false) {
                                            String idInstance2;
                                            idInstance2 = idValue2.getTextValue();
                                            serviceTierAdvisorInstance.setId(idInstance2);
                                        }

                                        JsonNode nameValue2 = serviceTierAdvisorsValue.get("name");
                                        if (nameValue2 != null && nameValue2 instanceof NullNode == false) {
                                            String nameInstance2;
                                            nameInstance2 = nameValue2.getTextValue();
                                            serviceTierAdvisorInstance.setName(nameInstance2);
                                        }

                                        JsonNode typeValue2 = serviceTierAdvisorsValue.get("type");
                                        if (typeValue2 != null && typeValue2 instanceof NullNode == false) {
                                            String typeInstance2;
                                            typeInstance2 = typeValue2.getTextValue();
                                            serviceTierAdvisorInstance.setType(typeInstance2);
                                        }

                                        JsonNode locationValue2 = serviceTierAdvisorsValue.get("location");
                                        if (locationValue2 != null
                                                && locationValue2 instanceof NullNode == false) {
                                            String locationInstance2;
                                            locationInstance2 = locationValue2.getTextValue();
                                            serviceTierAdvisorInstance.setLocation(locationInstance2);
                                        }

                                        JsonNode tagsSequenceElement2 = ((JsonNode) serviceTierAdvisorsValue
                                                .get("tags"));
                                        if (tagsSequenceElement2 != null
                                                && tagsSequenceElement2 instanceof NullNode == false) {
                                            Iterator<Map.Entry<String, JsonNode>> itr2 = tagsSequenceElement2
                                                    .getFields();
                                            while (itr2.hasNext()) {
                                                Map.Entry<String, JsonNode> property2 = itr2.next();
                                                String tagsKey2 = property2.getKey();
                                                String tagsValue2 = property2.getValue().getTextValue();
                                                serviceTierAdvisorInstance.getTags().put(tagsKey2, tagsValue2);
                                            }
                                        }
                                    }
                                }

                                JsonNode upgradeHintValue = propertiesValue2.get("upgradeHint");
                                if (upgradeHintValue != null && upgradeHintValue instanceof NullNode == false) {
                                    UpgradeHint upgradeHintInstance = new UpgradeHint();
                                    propertiesInstance2.setUpgradeHint(upgradeHintInstance);

                                    JsonNode targetServiceLevelObjectiveValue = upgradeHintValue
                                            .get("targetServiceLevelObjective");
                                    if (targetServiceLevelObjectiveValue != null
                                            && targetServiceLevelObjectiveValue instanceof NullNode == false) {
                                        String targetServiceLevelObjectiveInstance;
                                        targetServiceLevelObjectiveInstance = targetServiceLevelObjectiveValue
                                                .getTextValue();
                                        upgradeHintInstance.setTargetServiceLevelObjective(
                                                targetServiceLevelObjectiveInstance);
                                    }

                                    JsonNode targetServiceLevelObjectiveIdValue = upgradeHintValue
                                            .get("targetServiceLevelObjectiveId");
                                    if (targetServiceLevelObjectiveIdValue != null
                                            && targetServiceLevelObjectiveIdValue instanceof NullNode == false) {
                                        String targetServiceLevelObjectiveIdInstance;
                                        targetServiceLevelObjectiveIdInstance = targetServiceLevelObjectiveIdValue
                                                .getTextValue();
                                        upgradeHintInstance.setTargetServiceLevelObjectiveId(
                                                targetServiceLevelObjectiveIdInstance);
                                    }

                                    JsonNode idValue3 = upgradeHintValue.get("id");
                                    if (idValue3 != null && idValue3 instanceof NullNode == false) {
                                        String idInstance3;
                                        idInstance3 = idValue3.getTextValue();
                                        upgradeHintInstance.setId(idInstance3);
                                    }

                                    JsonNode nameValue3 = upgradeHintValue.get("name");
                                    if (nameValue3 != null && nameValue3 instanceof NullNode == false) {
                                        String nameInstance3;
                                        nameInstance3 = nameValue3.getTextValue();
                                        upgradeHintInstance.setName(nameInstance3);
                                    }

                                    JsonNode typeValue3 = upgradeHintValue.get("type");
                                    if (typeValue3 != null && typeValue3 instanceof NullNode == false) {
                                        String typeInstance3;
                                        typeInstance3 = typeValue3.getTextValue();
                                        upgradeHintInstance.setType(typeInstance3);
                                    }

                                    JsonNode locationValue3 = upgradeHintValue.get("location");
                                    if (locationValue3 != null && locationValue3 instanceof NullNode == false) {
                                        String locationInstance3;
                                        locationInstance3 = locationValue3.getTextValue();
                                        upgradeHintInstance.setLocation(locationInstance3);
                                    }

                                    JsonNode tagsSequenceElement3 = ((JsonNode) upgradeHintValue.get("tags"));
                                    if (tagsSequenceElement3 != null
                                            && tagsSequenceElement3 instanceof NullNode == false) {
                                        Iterator<Map.Entry<String, JsonNode>> itr3 = tagsSequenceElement3
                                                .getFields();
                                        while (itr3.hasNext()) {
                                            Map.Entry<String, JsonNode> property3 = itr3.next();
                                            String tagsKey3 = property3.getKey();
                                            String tagsValue3 = property3.getValue().getTextValue();
                                            upgradeHintInstance.getTags().put(tagsKey3, tagsValue3);
                                        }
                                    }
                                }

                                JsonNode schemasArray = propertiesValue2.get("schemas");
                                if (schemasArray != null && schemasArray instanceof NullNode == false) {
                                    for (JsonNode schemasValue : ((ArrayNode) schemasArray)) {
                                        Schema schemaInstance = new Schema();
                                        propertiesInstance2.getSchemas().add(schemaInstance);

                                        JsonNode propertiesValue4 = schemasValue.get("properties");
                                        if (propertiesValue4 != null
                                                && propertiesValue4 instanceof NullNode == false) {
                                            SchemaProperties propertiesInstance4 = new SchemaProperties();
                                            schemaInstance.setProperties(propertiesInstance4);

                                            JsonNode tablesArray = propertiesValue4.get("tables");
                                            if (tablesArray != null
                                                    && tablesArray instanceof NullNode == false) {
                                                for (JsonNode tablesValue : ((ArrayNode) tablesArray)) {
                                                    Table tableInstance = new Table();
                                                    propertiesInstance4.getTables().add(tableInstance);

                                                    JsonNode propertiesValue5 = tablesValue.get("properties");
                                                    if (propertiesValue5 != null
                                                            && propertiesValue5 instanceof NullNode == false) {
                                                        TableProperties propertiesInstance5 = new TableProperties();
                                                        tableInstance.setProperties(propertiesInstance5);

                                                        JsonNode tableTypeValue = propertiesValue5
                                                                .get("tableType");
                                                        if (tableTypeValue != null
                                                                && tableTypeValue instanceof NullNode == false) {
                                                            String tableTypeInstance;
                                                            tableTypeInstance = tableTypeValue.getTextValue();
                                                            propertiesInstance5.setTableType(tableTypeInstance);
                                                        }

                                                        JsonNode columnsArray = propertiesValue5.get("columns");
                                                        if (columnsArray != null
                                                                && columnsArray instanceof NullNode == false) {
                                                            for (JsonNode columnsValue : ((ArrayNode) columnsArray)) {
                                                                Column columnInstance = new Column();
                                                                propertiesInstance5.getColumns()
                                                                        .add(columnInstance);

                                                                JsonNode propertiesValue6 = columnsValue
                                                                        .get("properties");
                                                                if (propertiesValue6 != null
                                                                        && propertiesValue6 instanceof NullNode == false) {
                                                                    ColumnProperties propertiesInstance6 = new ColumnProperties();
                                                                    columnInstance
                                                                            .setProperties(propertiesInstance6);

                                                                    JsonNode columnTypeValue = propertiesValue6
                                                                            .get("columnType");
                                                                    if (columnTypeValue != null
                                                                            && columnTypeValue instanceof NullNode == false) {
                                                                        String columnTypeInstance;
                                                                        columnTypeInstance = columnTypeValue
                                                                                .getTextValue();
                                                                        propertiesInstance6.setColumnType(
                                                                                columnTypeInstance);
                                                                    }
                                                                }

                                                                JsonNode idValue4 = columnsValue.get("id");
                                                                if (idValue4 != null
                                                                        && idValue4 instanceof NullNode == false) {
                                                                    String idInstance4;
                                                                    idInstance4 = idValue4.getTextValue();
                                                                    columnInstance.setId(idInstance4);
                                                                }

                                                                JsonNode nameValue4 = columnsValue.get("name");
                                                                if (nameValue4 != null
                                                                        && nameValue4 instanceof NullNode == false) {
                                                                    String nameInstance4;
                                                                    nameInstance4 = nameValue4.getTextValue();
                                                                    columnInstance.setName(nameInstance4);
                                                                }

                                                                JsonNode typeValue4 = columnsValue.get("type");
                                                                if (typeValue4 != null
                                                                        && typeValue4 instanceof NullNode == false) {
                                                                    String typeInstance4;
                                                                    typeInstance4 = typeValue4.getTextValue();
                                                                    columnInstance.setType(typeInstance4);
                                                                }

                                                                JsonNode locationValue4 = columnsValue
                                                                        .get("location");
                                                                if (locationValue4 != null
                                                                        && locationValue4 instanceof NullNode == false) {
                                                                    String locationInstance4;
                                                                    locationInstance4 = locationValue4
                                                                            .getTextValue();
                                                                    columnInstance
                                                                            .setLocation(locationInstance4);
                                                                }

                                                                JsonNode tagsSequenceElement4 = ((JsonNode) columnsValue
                                                                        .get("tags"));
                                                                if (tagsSequenceElement4 != null
                                                                        && tagsSequenceElement4 instanceof NullNode == false) {
                                                                    Iterator<Map.Entry<String, JsonNode>> itr4 = tagsSequenceElement4
                                                                            .getFields();
                                                                    while (itr4.hasNext()) {
                                                                        Map.Entry<String, JsonNode> property4 = itr4
                                                                                .next();
                                                                        String tagsKey4 = property4.getKey();
                                                                        String tagsValue4 = property4.getValue()
                                                                                .getTextValue();
                                                                        columnInstance.getTags().put(tagsKey4,
                                                                                tagsValue4);
                                                                    }
                                                                }
                                                            }
                                                        }

                                                        JsonNode recommendedIndexesArray = propertiesValue5
                                                                .get("recommendedIndexes");
                                                        if (recommendedIndexesArray != null
                                                                && recommendedIndexesArray instanceof NullNode == false) {
                                                            for (JsonNode recommendedIndexesValue : ((ArrayNode) recommendedIndexesArray)) {
                                                                RecommendedIndex recommendedIndexInstance = new RecommendedIndex();
                                                                propertiesInstance5.getRecommendedIndexes()
                                                                        .add(recommendedIndexInstance);

                                                                JsonNode propertiesValue7 = recommendedIndexesValue
                                                                        .get("properties");
                                                                if (propertiesValue7 != null
                                                                        && propertiesValue7 instanceof NullNode == false) {
                                                                    RecommendedIndexProperties propertiesInstance7 = new RecommendedIndexProperties();
                                                                    recommendedIndexInstance
                                                                            .setProperties(propertiesInstance7);

                                                                    JsonNode actionValue = propertiesValue7
                                                                            .get("action");
                                                                    if (actionValue != null
                                                                            && actionValue instanceof NullNode == false) {
                                                                        String actionInstance;
                                                                        actionInstance = actionValue
                                                                                .getTextValue();
                                                                        propertiesInstance7
                                                                                .setAction(actionInstance);
                                                                    }

                                                                    JsonNode stateValue = propertiesValue7
                                                                            .get("state");
                                                                    if (stateValue != null
                                                                            && stateValue instanceof NullNode == false) {
                                                                        String stateInstance;
                                                                        stateInstance = stateValue
                                                                                .getTextValue();
                                                                        propertiesInstance7
                                                                                .setState(stateInstance);
                                                                    }

                                                                    JsonNode createdValue = propertiesValue7
                                                                            .get("created");
                                                                    if (createdValue != null
                                                                            && createdValue instanceof NullNode == false) {
                                                                        Calendar createdInstance;
                                                                        createdInstance = DatatypeConverter
                                                                                .parseDateTime(createdValue
                                                                                        .getTextValue());
                                                                        propertiesInstance7
                                                                                .setCreated(createdInstance);
                                                                    }

                                                                    JsonNode lastModifiedValue = propertiesValue7
                                                                            .get("lastModified");
                                                                    if (lastModifiedValue != null
                                                                            && lastModifiedValue instanceof NullNode == false) {
                                                                        Calendar lastModifiedInstance;
                                                                        lastModifiedInstance = DatatypeConverter
                                                                                .parseDateTime(lastModifiedValue
                                                                                        .getTextValue());
                                                                        propertiesInstance7.setLastModified(
                                                                                lastModifiedInstance);
                                                                    }

                                                                    JsonNode indexTypeValue = propertiesValue7
                                                                            .get("indexType");
                                                                    if (indexTypeValue != null
                                                                            && indexTypeValue instanceof NullNode == false) {
                                                                        String indexTypeInstance;
                                                                        indexTypeInstance = indexTypeValue
                                                                                .getTextValue();
                                                                        propertiesInstance7.setIndexType(
                                                                                indexTypeInstance);
                                                                    }

                                                                    JsonNode schemaValue = propertiesValue7
                                                                            .get("schema");
                                                                    if (schemaValue != null
                                                                            && schemaValue instanceof NullNode == false) {
                                                                        String schemaInstance2;
                                                                        schemaInstance2 = schemaValue
                                                                                .getTextValue();
                                                                        propertiesInstance7
                                                                                .setSchema(schemaInstance2);
                                                                    }

                                                                    JsonNode tableValue = propertiesValue7
                                                                            .get("table");
                                                                    if (tableValue != null
                                                                            && tableValue instanceof NullNode == false) {
                                                                        String tableInstance2;
                                                                        tableInstance2 = tableValue
                                                                                .getTextValue();
                                                                        propertiesInstance7
                                                                                .setTable(tableInstance2);
                                                                    }

                                                                    JsonNode columnsArray2 = propertiesValue7
                                                                            .get("columns");
                                                                    if (columnsArray2 != null
                                                                            && columnsArray2 instanceof NullNode == false) {
                                                                        for (JsonNode columnsValue2 : ((ArrayNode) columnsArray2)) {
                                                                            propertiesInstance7.getColumns()
                                                                                    .add(columnsValue2
                                                                                            .getTextValue());
                                                                        }
                                                                    }

                                                                    JsonNode includedColumnsArray = propertiesValue7
                                                                            .get("includedColumns");
                                                                    if (includedColumnsArray != null
                                                                            && includedColumnsArray instanceof NullNode == false) {
                                                                        for (JsonNode includedColumnsValue : ((ArrayNode) includedColumnsArray)) {
                                                                            propertiesInstance7
                                                                                    .getIncludedColumns()
                                                                                    .add(includedColumnsValue
                                                                                            .getTextValue());
                                                                        }
                                                                    }

                                                                    JsonNode indexScriptValue = propertiesValue7
                                                                            .get("indexScript");
                                                                    if (indexScriptValue != null
                                                                            && indexScriptValue instanceof NullNode == false) {
                                                                        String indexScriptInstance;
                                                                        indexScriptInstance = indexScriptValue
                                                                                .getTextValue();
                                                                        propertiesInstance7.setIndexScript(
                                                                                indexScriptInstance);
                                                                    }

                                                                    JsonNode estimatedImpactArray = propertiesValue7
                                                                            .get("estimatedImpact");
                                                                    if (estimatedImpactArray != null
                                                                            && estimatedImpactArray instanceof NullNode == false) {
                                                                        for (JsonNode estimatedImpactValue : ((ArrayNode) estimatedImpactArray)) {
                                                                            OperationImpact operationImpactInstance = new OperationImpact();
                                                                            propertiesInstance7
                                                                                    .getEstimatedImpact()
                                                                                    .add(operationImpactInstance);

                                                                            JsonNode nameValue5 = estimatedImpactValue
                                                                                    .get("name");
                                                                            if (nameValue5 != null
                                                                                    && nameValue5 instanceof NullNode == false) {
                                                                                String nameInstance5;
                                                                                nameInstance5 = nameValue5
                                                                                        .getTextValue();
                                                                                operationImpactInstance
                                                                                        .setName(nameInstance5);
                                                                            }

                                                                            JsonNode unitValue = estimatedImpactValue
                                                                                    .get("unit");
                                                                            if (unitValue != null
                                                                                    && unitValue instanceof NullNode == false) {
                                                                                String unitInstance;
                                                                                unitInstance = unitValue
                                                                                        .getTextValue();
                                                                                operationImpactInstance
                                                                                        .setUnit(unitInstance);
                                                                            }

                                                                            JsonNode changeValueAbsoluteValue = estimatedImpactValue
                                                                                    .get("changeValueAbsolute");
                                                                            if (changeValueAbsoluteValue != null
                                                                                    && changeValueAbsoluteValue instanceof NullNode == false) {
                                                                                double changeValueAbsoluteInstance;
                                                                                changeValueAbsoluteInstance = changeValueAbsoluteValue
                                                                                        .getDoubleValue();
                                                                                operationImpactInstance
                                                                                        .setChangeValueAbsolute(
                                                                                                changeValueAbsoluteInstance);
                                                                            }

                                                                            JsonNode changeValueRelativeValue = estimatedImpactValue
                                                                                    .get("changeValueRelative");
                                                                            if (changeValueRelativeValue != null
                                                                                    && changeValueRelativeValue instanceof NullNode == false) {
                                                                                double changeValueRelativeInstance;
                                                                                changeValueRelativeInstance = changeValueRelativeValue
                                                                                        .getDoubleValue();
                                                                                operationImpactInstance
                                                                                        .setChangeValueRelative(
                                                                                                changeValueRelativeInstance);
                                                                            }
                                                                        }
                                                                    }

                                                                    JsonNode reportedImpactArray = propertiesValue7
                                                                            .get("reportedImpact");
                                                                    if (reportedImpactArray != null
                                                                            && reportedImpactArray instanceof NullNode == false) {
                                                                        for (JsonNode reportedImpactValue : ((ArrayNode) reportedImpactArray)) {
                                                                            OperationImpact operationImpactInstance2 = new OperationImpact();
                                                                            propertiesInstance7
                                                                                    .getReportedImpact()
                                                                                    .add(operationImpactInstance2);

                                                                            JsonNode nameValue6 = reportedImpactValue
                                                                                    .get("name");
                                                                            if (nameValue6 != null
                                                                                    && nameValue6 instanceof NullNode == false) {
                                                                                String nameInstance6;
                                                                                nameInstance6 = nameValue6
                                                                                        .getTextValue();
                                                                                operationImpactInstance2
                                                                                        .setName(nameInstance6);
                                                                            }

                                                                            JsonNode unitValue2 = reportedImpactValue
                                                                                    .get("unit");
                                                                            if (unitValue2 != null
                                                                                    && unitValue2 instanceof NullNode == false) {
                                                                                String unitInstance2;
                                                                                unitInstance2 = unitValue2
                                                                                        .getTextValue();
                                                                                operationImpactInstance2
                                                                                        .setUnit(unitInstance2);
                                                                            }

                                                                            JsonNode changeValueAbsoluteValue2 = reportedImpactValue
                                                                                    .get("changeValueAbsolute");
                                                                            if (changeValueAbsoluteValue2 != null
                                                                                    && changeValueAbsoluteValue2 instanceof NullNode == false) {
                                                                                double changeValueAbsoluteInstance2;
                                                                                changeValueAbsoluteInstance2 = changeValueAbsoluteValue2
                                                                                        .getDoubleValue();
                                                                                operationImpactInstance2
                                                                                        .setChangeValueAbsolute(
                                                                                                changeValueAbsoluteInstance2);
                                                                            }

                                                                            JsonNode changeValueRelativeValue2 = reportedImpactValue
                                                                                    .get("changeValueRelative");
                                                                            if (changeValueRelativeValue2 != null
                                                                                    && changeValueRelativeValue2 instanceof NullNode == false) {
                                                                                double changeValueRelativeInstance2;
                                                                                changeValueRelativeInstance2 = changeValueRelativeValue2
                                                                                        .getDoubleValue();
                                                                                operationImpactInstance2
                                                                                        .setChangeValueRelative(
                                                                                                changeValueRelativeInstance2);
                                                                            }
                                                                        }
                                                                    }
                                                                }

                                                                JsonNode idValue5 = recommendedIndexesValue
                                                                        .get("id");
                                                                if (idValue5 != null
                                                                        && idValue5 instanceof NullNode == false) {
                                                                    String idInstance5;
                                                                    idInstance5 = idValue5.getTextValue();
                                                                    recommendedIndexInstance.setId(idInstance5);
                                                                }

                                                                JsonNode nameValue7 = recommendedIndexesValue
                                                                        .get("name");
                                                                if (nameValue7 != null
                                                                        && nameValue7 instanceof NullNode == false) {
                                                                    String nameInstance7;
                                                                    nameInstance7 = nameValue7.getTextValue();
                                                                    recommendedIndexInstance
                                                                            .setName(nameInstance7);
                                                                }

                                                                JsonNode typeValue5 = recommendedIndexesValue
                                                                        .get("type");
                                                                if (typeValue5 != null
                                                                        && typeValue5 instanceof NullNode == false) {
                                                                    String typeInstance5;
                                                                    typeInstance5 = typeValue5.getTextValue();
                                                                    recommendedIndexInstance
                                                                            .setType(typeInstance5);
                                                                }

                                                                JsonNode locationValue5 = recommendedIndexesValue
                                                                        .get("location");
                                                                if (locationValue5 != null
                                                                        && locationValue5 instanceof NullNode == false) {
                                                                    String locationInstance5;
                                                                    locationInstance5 = locationValue5
                                                                            .getTextValue();
                                                                    recommendedIndexInstance
                                                                            .setLocation(locationInstance5);
                                                                }

                                                                JsonNode tagsSequenceElement5 = ((JsonNode) recommendedIndexesValue
                                                                        .get("tags"));
                                                                if (tagsSequenceElement5 != null
                                                                        && tagsSequenceElement5 instanceof NullNode == false) {
                                                                    Iterator<Map.Entry<String, JsonNode>> itr5 = tagsSequenceElement5
                                                                            .getFields();
                                                                    while (itr5.hasNext()) {
                                                                        Map.Entry<String, JsonNode> property5 = itr5
                                                                                .next();
                                                                        String tagsKey5 = property5.getKey();
                                                                        String tagsValue5 = property5.getValue()
                                                                                .getTextValue();
                                                                        recommendedIndexInstance.getTags()
                                                                                .put(tagsKey5, tagsValue5);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }

                                                    JsonNode idValue6 = tablesValue.get("id");
                                                    if (idValue6 != null
                                                            && idValue6 instanceof NullNode == false) {
                                                        String idInstance6;
                                                        idInstance6 = idValue6.getTextValue();
                                                        tableInstance.setId(idInstance6);
                                                    }

                                                    JsonNode nameValue8 = tablesValue.get("name");
                                                    if (nameValue8 != null
                                                            && nameValue8 instanceof NullNode == false) {
                                                        String nameInstance8;
                                                        nameInstance8 = nameValue8.getTextValue();
                                                        tableInstance.setName(nameInstance8);
                                                    }

                                                    JsonNode typeValue6 = tablesValue.get("type");
                                                    if (typeValue6 != null
                                                            && typeValue6 instanceof NullNode == false) {
                                                        String typeInstance6;
                                                        typeInstance6 = typeValue6.getTextValue();
                                                        tableInstance.setType(typeInstance6);
                                                    }

                                                    JsonNode locationValue6 = tablesValue.get("location");
                                                    if (locationValue6 != null
                                                            && locationValue6 instanceof NullNode == false) {
                                                        String locationInstance6;
                                                        locationInstance6 = locationValue6.getTextValue();
                                                        tableInstance.setLocation(locationInstance6);
                                                    }

                                                    JsonNode tagsSequenceElement6 = ((JsonNode) tablesValue
                                                            .get("tags"));
                                                    if (tagsSequenceElement6 != null
                                                            && tagsSequenceElement6 instanceof NullNode == false) {
                                                        Iterator<Map.Entry<String, JsonNode>> itr6 = tagsSequenceElement6
                                                                .getFields();
                                                        while (itr6.hasNext()) {
                                                            Map.Entry<String, JsonNode> property6 = itr6.next();
                                                            String tagsKey6 = property6.getKey();
                                                            String tagsValue6 = property6.getValue()
                                                                    .getTextValue();
                                                            tableInstance.getTags().put(tagsKey6, tagsValue6);
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        JsonNode idValue7 = schemasValue.get("id");
                                        if (idValue7 != null && idValue7 instanceof NullNode == false) {
                                            String idInstance7;
                                            idInstance7 = idValue7.getTextValue();
                                            schemaInstance.setId(idInstance7);
                                        }

                                        JsonNode nameValue9 = schemasValue.get("name");
                                        if (nameValue9 != null && nameValue9 instanceof NullNode == false) {
                                            String nameInstance9;
                                            nameInstance9 = nameValue9.getTextValue();
                                            schemaInstance.setName(nameInstance9);
                                        }

                                        JsonNode typeValue7 = schemasValue.get("type");
                                        if (typeValue7 != null && typeValue7 instanceof NullNode == false) {
                                            String typeInstance7;
                                            typeInstance7 = typeValue7.getTextValue();
                                            schemaInstance.setType(typeInstance7);
                                        }

                                        JsonNode locationValue7 = schemasValue.get("location");
                                        if (locationValue7 != null
                                                && locationValue7 instanceof NullNode == false) {
                                            String locationInstance7;
                                            locationInstance7 = locationValue7.getTextValue();
                                            schemaInstance.setLocation(locationInstance7);
                                        }

                                        JsonNode tagsSequenceElement7 = ((JsonNode) schemasValue.get("tags"));
                                        if (tagsSequenceElement7 != null
                                                && tagsSequenceElement7 instanceof NullNode == false) {
                                            Iterator<Map.Entry<String, JsonNode>> itr7 = tagsSequenceElement7
                                                    .getFields();
                                            while (itr7.hasNext()) {
                                                Map.Entry<String, JsonNode> property7 = itr7.next();
                                                String tagsKey7 = property7.getKey();
                                                String tagsValue7 = property7.getValue().getTextValue();
                                                schemaInstance.getTags().put(tagsKey7, tagsValue7);
                                            }
                                        }
                                    }
                                }

                                JsonNode defaultSecondaryLocationValue = propertiesValue2
                                        .get("defaultSecondaryLocation");
                                if (defaultSecondaryLocationValue != null
                                        && defaultSecondaryLocationValue instanceof NullNode == false) {
                                    String defaultSecondaryLocationInstance;
                                    defaultSecondaryLocationInstance = defaultSecondaryLocationValue
                                            .getTextValue();
                                    propertiesInstance2
                                            .setDefaultSecondaryLocation(defaultSecondaryLocationInstance);
                                }
                            }

                            JsonNode idValue8 = databasesValue.get("id");
                            if (idValue8 != null && idValue8 instanceof NullNode == false) {
                                String idInstance8;
                                idInstance8 = idValue8.getTextValue();
                                databaseInstance.setId(idInstance8);
                            }

                            JsonNode nameValue10 = databasesValue.get("name");
                            if (nameValue10 != null && nameValue10 instanceof NullNode == false) {
                                String nameInstance10;
                                nameInstance10 = nameValue10.getTextValue();
                                databaseInstance.setName(nameInstance10);
                            }

                            JsonNode typeValue8 = databasesValue.get("type");
                            if (typeValue8 != null && typeValue8 instanceof NullNode == false) {
                                String typeInstance8;
                                typeInstance8 = typeValue8.getTextValue();
                                databaseInstance.setType(typeInstance8);
                            }

                            JsonNode locationValue8 = databasesValue.get("location");
                            if (locationValue8 != null && locationValue8 instanceof NullNode == false) {
                                String locationInstance8;
                                locationInstance8 = locationValue8.getTextValue();
                                databaseInstance.setLocation(locationInstance8);
                            }

                            JsonNode tagsSequenceElement8 = ((JsonNode) databasesValue.get("tags"));
                            if (tagsSequenceElement8 != null
                                    && tagsSequenceElement8 instanceof NullNode == false) {
                                Iterator<Map.Entry<String, JsonNode>> itr8 = tagsSequenceElement8.getFields();
                                while (itr8.hasNext()) {
                                    Map.Entry<String, JsonNode> property8 = itr8.next();
                                    String tagsKey8 = property8.getKey();
                                    String tagsValue8 = property8.getValue().getTextValue();
                                    databaseInstance.getTags().put(tagsKey8, tagsValue8);
                                }
                            }
                        }
                    }

                    JsonNode metricsArray = propertiesValue.get("metrics");
                    if (metricsArray != null && metricsArray instanceof NullNode == false) {
                        for (JsonNode metricsValue : ((ArrayNode) metricsArray)) {
                            RecommendedElasticPoolMetric recommendedElasticPoolMetricInstance = new RecommendedElasticPoolMetric();
                            propertiesInstance.getMetrics().add(recommendedElasticPoolMetricInstance);

                            JsonNode dateTimeValue = metricsValue.get("dateTime");
                            if (dateTimeValue != null && dateTimeValue instanceof NullNode == false) {
                                Calendar dateTimeInstance;
                                dateTimeInstance = DatatypeConverter
                                        .parseDateTime(dateTimeValue.getTextValue());
                                recommendedElasticPoolMetricInstance.setDateTime(dateTimeInstance);
                            }

                            JsonNode dtuValue2 = metricsValue.get("dtu");
                            if (dtuValue2 != null && dtuValue2 instanceof NullNode == false) {
                                double dtuInstance2;
                                dtuInstance2 = dtuValue2.getDoubleValue();
                                recommendedElasticPoolMetricInstance.setDtu(dtuInstance2);
                            }

                            JsonNode sizeGBValue = metricsValue.get("sizeGB");
                            if (sizeGBValue != null && sizeGBValue instanceof NullNode == false) {
                                double sizeGBInstance;
                                sizeGBInstance = sizeGBValue.getDoubleValue();
                                recommendedElasticPoolMetricInstance.setSizeGB(sizeGBInstance);
                            }
                        }
                    }
                }

                JsonNode idValue9 = responseDoc.get("id");
                if (idValue9 != null && idValue9 instanceof NullNode == false) {
                    String idInstance9;
                    idInstance9 = idValue9.getTextValue();
                    recommendedElasticPoolInstance.setId(idInstance9);
                }

                JsonNode nameValue11 = responseDoc.get("name");
                if (nameValue11 != null && nameValue11 instanceof NullNode == false) {
                    String nameInstance11;
                    nameInstance11 = nameValue11.getTextValue();
                    recommendedElasticPoolInstance.setName(nameInstance11);
                }

                JsonNode typeValue9 = responseDoc.get("type");
                if (typeValue9 != null && typeValue9 instanceof NullNode == false) {
                    String typeInstance9;
                    typeInstance9 = typeValue9.getTextValue();
                    recommendedElasticPoolInstance.setType(typeInstance9);
                }

                JsonNode locationValue9 = responseDoc.get("location");
                if (locationValue9 != null && locationValue9 instanceof NullNode == false) {
                    String locationInstance9;
                    locationInstance9 = locationValue9.getTextValue();
                    recommendedElasticPoolInstance.setLocation(locationInstance9);
                }

                JsonNode tagsSequenceElement9 = ((JsonNode) responseDoc.get("tags"));
                if (tagsSequenceElement9 != null && tagsSequenceElement9 instanceof NullNode == false) {
                    Iterator<Map.Entry<String, JsonNode>> itr9 = tagsSequenceElement9.getFields();
                    while (itr9.hasNext()) {
                        Map.Entry<String, JsonNode> property9 = itr9.next();
                        String tagsKey9 = property9.getKey();
                        String tagsValue9 = property9.getValue().getTextValue();
                        recommendedElasticPoolInstance.getTags().put(tagsKey9, tagsValue9);
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.windowsazure.management.servicebus.NotificationHubOperationsImpl.java

/**
* Lists the notification hubs associated with a namespace.
*
* @param namespaceName Required. The namespace name.
* @param notificationHubName Required. The notification hub name.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.//from  w ww  .j a va  2 s  .  com
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public ServiceBusNotificationHubResponse get(String namespaceName, String notificationHubName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate
    if (namespaceName == null) {
        throw new NullPointerException("namespaceName");
    }
    if (notificationHubName == null) {
        throw new NullPointerException("notificationHubName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("namespaceName", namespaceName);
        tracingParameters.put("notificationHubName", notificationHubName);
        CloudTracing.enter(invocationId, this, "getAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/servicebus/namespaces/";
    url = url + URLEncoder.encode(namespaceName, "UTF-8");
    url = url + "/NotificationHubs/";
    url = url + URLEncoder.encode(notificationHubName, "UTF-8");
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "2013-08-01");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        ServiceBusNotificationHubResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ServiceBusNotificationHubResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element entryElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://www.w3.org/2005/Atom",
                    "entry");
            if (entryElement != null) {
                Element titleElement = XmlUtility.getElementByTagNameNS(entryElement,
                        "http://www.w3.org/2005/Atom", "title");
                if (titleElement != null) {
                }

                Element contentElement = XmlUtility.getElementByTagNameNS(entryElement,
                        "http://www.w3.org/2005/Atom", "content");
                if (contentElement != null) {
                    Element notificationHubDescriptionElement = XmlUtility.getElementByTagNameNS(contentElement,
                            "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                            "NotificationHubDescription");
                    if (notificationHubDescriptionElement != null) {
                        ServiceBusNotificationHub notificationHubDescriptionInstance = new ServiceBusNotificationHub();
                        result.setNotificationHub(notificationHubDescriptionInstance);

                        Element registrationTtlElement = XmlUtility.getElementByTagNameNS(
                                notificationHubDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "RegistrationTtl");
                        if (registrationTtlElement != null) {
                            String registrationTtlInstance;
                            registrationTtlInstance = registrationTtlElement.getTextContent();
                            notificationHubDescriptionInstance.setRegistrationTtl(registrationTtlInstance);
                        }

                        Element authorizationRulesSequenceElement = XmlUtility.getElementByTagNameNS(
                                notificationHubDescriptionElement,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "AuthorizationRules");
                        if (authorizationRulesSequenceElement != null) {
                            for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(authorizationRulesSequenceElement,
                                            "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                            "AuthorizationRule")
                                    .size(); i1 = i1 + 1) {
                                org.w3c.dom.Element authorizationRulesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                        .getElementsByTagNameNS(authorizationRulesSequenceElement,
                                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                "AuthorizationRule")
                                        .get(i1));
                                ServiceBusSharedAccessAuthorizationRule authorizationRuleInstance = new ServiceBusSharedAccessAuthorizationRule();
                                notificationHubDescriptionInstance.getAuthorizationRules()
                                        .add(authorizationRuleInstance);

                                Element claimTypeElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "ClaimType");
                                if (claimTypeElement != null) {
                                    String claimTypeInstance;
                                    claimTypeInstance = claimTypeElement.getTextContent();
                                    authorizationRuleInstance.setClaimType(claimTypeInstance);
                                }

                                Element claimValueElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "ClaimValue");
                                if (claimValueElement != null) {
                                    String claimValueInstance;
                                    claimValueInstance = claimValueElement.getTextContent();
                                    authorizationRuleInstance.setClaimValue(claimValueInstance);
                                }

                                Element rightsSequenceElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "Rights");
                                if (rightsSequenceElement != null) {
                                    for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                                            .getElementsByTagNameNS(rightsSequenceElement,
                                                    "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                    "AccessRights")
                                            .size(); i2 = i2 + 1) {
                                        org.w3c.dom.Element rightsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                                .getElementsByTagNameNS(rightsSequenceElement,
                                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                                        "AccessRights")
                                                .get(i2));
                                        authorizationRuleInstance.getRights()
                                                .add(AccessRight.valueOf(rightsElement.getTextContent()));
                                    }
                                }

                                Element createdTimeElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "CreatedTime");
                                if (createdTimeElement != null) {
                                    Calendar createdTimeInstance;
                                    createdTimeInstance = DatatypeConverter
                                            .parseDateTime(createdTimeElement.getTextContent());
                                    authorizationRuleInstance.setCreatedTime(createdTimeInstance);
                                }

                                Element keyNameElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "KeyName");
                                if (keyNameElement != null) {
                                    String keyNameInstance;
                                    keyNameInstance = keyNameElement.getTextContent();
                                    authorizationRuleInstance.setKeyName(keyNameInstance);
                                }

                                Element modifiedTimeElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "ModifiedTime");
                                if (modifiedTimeElement != null) {
                                    Calendar modifiedTimeInstance;
                                    modifiedTimeInstance = DatatypeConverter
                                            .parseDateTime(modifiedTimeElement.getTextContent());
                                    authorizationRuleInstance.setModifiedTime(modifiedTimeInstance);
                                }

                                Element primaryKeyElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "PrimaryKey");
                                if (primaryKeyElement != null) {
                                    String primaryKeyInstance;
                                    primaryKeyInstance = primaryKeyElement.getTextContent();
                                    authorizationRuleInstance.setPrimaryKey(primaryKeyInstance);
                                }

                                Element secondaryKeyElement = XmlUtility.getElementByTagNameNS(
                                        authorizationRulesElement,
                                        "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                        "SecondaryKey");
                                if (secondaryKeyElement != null) {
                                    String secondaryKeyInstance;
                                    secondaryKeyInstance = secondaryKeyElement.getTextContent();
                                    authorizationRuleInstance.setSecondaryKey(secondaryKeyInstance);
                                }
                            }
                        }
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.windowsazure.management.websites.WebSiteManagementClientImpl.java

/**
* The Get Operation Status operation returns the status of the specified
* operation. After calling a long-running operation, you can call Get
* Operation Status to determine whether the operation has succeeded,
* failed, timed out, or is still in progress.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/ee460783.aspx for
* more information)/*from  w  ww .j av a2s .co m*/
*
* @param webSpaceName Required. The name of the webspace for the website
* where the operation was targeted.
* @param siteName Required. The name of the site where the operation was
* targeted.
* @param operationId Required. The operation ID for the operation you wish
* to track. The operation ID is returned in the ID field in the body of
* the response for long-running operations.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return The response body contains the status of the specified
* long-running operation, indicating whether it has succeeded, is
* inprogress, has timed out, or has failed. Note that this status is
* distinct from the HTTP status code returned for the Get Operation Status
* operation itself. If the long-running operation failed, the response
* body includes error information regarding the failure.
*/
@Override
public WebSiteOperationStatusResponse getOperationStatus(String webSpaceName, String siteName,
        String operationId) throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // Validate
    if (webSpaceName == null) {
        throw new NullPointerException("webSpaceName");
    }
    if (siteName == null) {
        throw new NullPointerException("siteName");
    }
    if (operationId == null) {
        throw new NullPointerException("operationId");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("webSpaceName", webSpaceName);
        tracingParameters.put("siteName", siteName);
        tracingParameters.put("operationId", operationId);
        CloudTracing.enter(invocationId, this, "getOperationStatusAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/WebSpaces/";
    url = url + URLEncoder.encode(webSpaceName, "UTF-8");
    url = url + "/sites/";
    url = url + URLEncoder.encode(siteName, "UTF-8");
    url = url + "/operations/";
    url = url + URLEncoder.encode(operationId, "UTF-8");
    String baseUrl = this.getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "2014-04-01");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        WebSiteOperationStatusResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new WebSiteOperationStatusResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element operationElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "Operation");
            if (operationElement != null) {
                Element createdTimeElement = XmlUtility.getElementByTagNameNS(operationElement,
                        "http://schemas.microsoft.com/windowsazure", "CreatedTime");
                if (createdTimeElement != null) {
                    Calendar createdTimeInstance;
                    createdTimeInstance = DatatypeConverter.parseDateTime(createdTimeElement.getTextContent());
                    result.setCreatedTime(createdTimeInstance);
                }

                Element errorsSequenceElement = XmlUtility.getElementByTagNameNS(operationElement,
                        "http://schemas.microsoft.com/windowsazure", "Errors");
                if (errorsSequenceElement != null) {
                    boolean isNil = false;
                    Attr nilAttribute = errorsSequenceElement
                            .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
                    if (nilAttribute != null) {
                        isNil = "true".equals(nilAttribute.getValue());
                    }
                    if (isNil == false) {
                        for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(errorsSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "Error")
                                .size(); i1 = i1 + 1) {
                            org.w3c.dom.Element errorsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(errorsSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "Error")
                                    .get(i1));
                            WebSiteOperationStatusResponse.Error errorInstance = new WebSiteOperationStatusResponse.Error();
                            result.getErrors().add(errorInstance);

                            Element codeElement = XmlUtility.getElementByTagNameNS(errorsElement,
                                    "http://schemas.microsoft.com/windowsazure", "Code");
                            if (codeElement != null) {
                                boolean isNil2 = false;
                                Attr nilAttribute2 = codeElement
                                        .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
                                if (nilAttribute2 != null) {
                                    isNil2 = "true".equals(nilAttribute2.getValue());
                                }
                                if (isNil2 == false) {
                                    String codeInstance;
                                    codeInstance = codeElement.getTextContent();
                                    errorInstance.setCode(codeInstance);
                                }
                            }

                            Element messageElement = XmlUtility.getElementByTagNameNS(errorsElement,
                                    "http://schemas.microsoft.com/windowsazure", "Message");
                            if (messageElement != null) {
                                boolean isNil3 = false;
                                Attr nilAttribute3 = messageElement
                                        .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
                                if (nilAttribute3 != null) {
                                    isNil3 = "true".equals(nilAttribute3.getValue());
                                }
                                if (isNil3 == false) {
                                    String messageInstance;
                                    messageInstance = messageElement.getTextContent();
                                    errorInstance.setMessage(messageInstance);
                                }
                            }

                            Element extendedCodeElement = XmlUtility.getElementByTagNameNS(errorsElement,
                                    "http://schemas.microsoft.com/windowsazure", "ExtendedCode");
                            if (extendedCodeElement != null) {
                                boolean isNil4 = false;
                                Attr nilAttribute4 = extendedCodeElement
                                        .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
                                if (nilAttribute4 != null) {
                                    isNil4 = "true".equals(nilAttribute4.getValue());
                                }
                                if (isNil4 == false) {
                                    String extendedCodeInstance;
                                    extendedCodeInstance = extendedCodeElement.getTextContent();
                                    errorInstance.setExtendedCode(extendedCodeInstance);
                                }
                            }

                            Element messageTemplateElement = XmlUtility.getElementByTagNameNS(errorsElement,
                                    "http://schemas.microsoft.com/windowsazure", "MessageTemplate");
                            if (messageTemplateElement != null) {
                                boolean isNil5 = false;
                                Attr nilAttribute5 = messageTemplateElement
                                        .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
                                if (nilAttribute5 != null) {
                                    isNil5 = "true".equals(nilAttribute5.getValue());
                                }
                                if (isNil5 == false) {
                                    String messageTemplateInstance;
                                    messageTemplateInstance = messageTemplateElement.getTextContent();
                                    errorInstance.setMessageTemplate(messageTemplateInstance);
                                }
                            }

                            Element parametersSequenceElement = XmlUtility.getElementByTagNameNS(errorsElement,
                                    "http://schemas.microsoft.com/windowsazure", "Parameters");
                            if (parametersSequenceElement != null) {
                                boolean isNil6 = false;
                                Attr nilAttribute6 = parametersSequenceElement
                                        .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
                                if (nilAttribute6 != null) {
                                    isNil6 = "true".equals(nilAttribute6.getValue());
                                }
                                if (isNil6 == false) {
                                    for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                                            .getElementsByTagNameNS(parametersSequenceElement,
                                                    "http://schemas.microsoft.com/2003/10/Serialization/Arrays",
                                                    "string")
                                            .size(); i2 = i2 + 1) {
                                        org.w3c.dom.Element parametersElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                                .getElementsByTagNameNS(parametersSequenceElement,
                                                        "http://schemas.microsoft.com/2003/10/Serialization/Arrays",
                                                        "string")
                                                .get(i2));
                                        errorInstance.getParameters().add(parametersElement.getTextContent());
                                    }
                                } else {
                                    errorInstance.setParameters(null);
                                }
                            }

                            Element innerErrorsElement = XmlUtility.getElementByTagNameNS(errorsElement,
                                    "http://schemas.microsoft.com/windowsazure", "InnerErrors");
                            if (innerErrorsElement != null) {
                                boolean isNil7 = false;
                                Attr nilAttribute7 = innerErrorsElement
                                        .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
                                if (nilAttribute7 != null) {
                                    isNil7 = "true".equals(nilAttribute7.getValue());
                                }
                                if (isNil7 == false) {
                                    String innerErrorsInstance;
                                    innerErrorsInstance = innerErrorsElement.getTextContent();
                                    errorInstance.setInnerErrors(innerErrorsInstance);
                                }
                            }
                        }
                    } else {
                        result.setErrors(null);
                    }
                }

                Element expirationTimeElement = XmlUtility.getElementByTagNameNS(operationElement,
                        "http://schemas.microsoft.com/windowsazure", "ExpirationTime");
                if (expirationTimeElement != null) {
                    Calendar expirationTimeInstance;
                    expirationTimeInstance = DatatypeConverter
                            .parseDateTime(expirationTimeElement.getTextContent());
                    result.setExpirationTime(expirationTimeInstance);
                }

                Element geoMasterOperationIdElement = XmlUtility.getElementByTagNameNS(operationElement,
                        "http://schemas.microsoft.com/windowsazure", "GeoMasterOperationId");
                if (geoMasterOperationIdElement != null) {
                    boolean isNil8 = false;
                    Attr nilAttribute8 = geoMasterOperationIdElement
                            .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
                    if (nilAttribute8 != null) {
                        isNil8 = "true".equals(nilAttribute8.getValue());
                    }
                    if (isNil8 == false) {
                        String geoMasterOperationIdInstance;
                        geoMasterOperationIdInstance = geoMasterOperationIdElement.getTextContent();
                        result.setGeoMasterOperationId(geoMasterOperationIdInstance);
                    }
                }

                Element idElement = XmlUtility.getElementByTagNameNS(operationElement,
                        "http://schemas.microsoft.com/windowsazure", "Id");
                if (idElement != null) {
                    boolean isNil9 = false;
                    Attr nilAttribute9 = idElement
                            .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
                    if (nilAttribute9 != null) {
                        isNil9 = "true".equals(nilAttribute9.getValue());
                    }
                    if (isNil9 == false) {
                        String idInstance;
                        idInstance = idElement.getTextContent();
                        result.setOperationId(idInstance);
                    }
                }

                Element modifiedTimeElement = XmlUtility.getElementByTagNameNS(operationElement,
                        "http://schemas.microsoft.com/windowsazure", "ModifiedTime");
                if (modifiedTimeElement != null) {
                    Calendar modifiedTimeInstance;
                    modifiedTimeInstance = DatatypeConverter
                            .parseDateTime(modifiedTimeElement.getTextContent());
                    result.setModifiedTime(modifiedTimeInstance);
                }

                Element nameElement = XmlUtility.getElementByTagNameNS(operationElement,
                        "http://schemas.microsoft.com/windowsazure", "Name");
                if (nameElement != null) {
                    boolean isNil10 = false;
                    Attr nilAttribute10 = nameElement
                            .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil");
                    if (nilAttribute10 != null) {
                        isNil10 = "true".equals(nilAttribute10.getValue());
                    }
                    if (isNil10 == false) {
                        String nameInstance;
                        nameInstance = nameElement.getTextContent();
                        result.setName(nameInstance);
                    }
                }

                Element statusElement = XmlUtility.getElementByTagNameNS(operationElement,
                        "http://schemas.microsoft.com/windowsazure", "Status");
                if (statusElement != null && statusElement.getTextContent() != null
                        && !statusElement.getTextContent().isEmpty()) {
                    WebSiteOperationStatus statusInstance;
                    statusInstance = WebSiteOperationStatus.valueOf(statusElement.getTextContent());
                    result.setStatus(statusInstance);
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.windowsazure.management.sql.RestorableDroppedDatabaseOperationsImpl.java

/**
* Returns a collection of databases that has been dropped but can still be
* restored from a specified server./*www . ja  v  a  2 s.c o  m*/
*
* @param serverName Required. The name of the Azure SQL Database Server to
* query for dropped databases that can still be restored.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return Contains the response to the List Restorable Dropped Databases
* request.
*/
@Override
public RestorableDroppedDatabaseListResponse list(String serverName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // Validate
    if (serverName == null) {
        throw new NullPointerException("serverName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("serverName", serverName);
        CloudTracing.enter(invocationId, this, "listAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/sqlservers/servers/";
    url = url + URLEncoder.encode(serverName, "UTF-8");
    url = url + "/restorabledroppeddatabases";
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("contentview=generic");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "2012-03-01");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        RestorableDroppedDatabaseListResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new RestorableDroppedDatabaseListResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element serviceResourcesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "ServiceResources");
            if (serviceResourcesSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(serviceResourcesSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "ServiceResource")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element serviceResourcesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(serviceResourcesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "ServiceResource")
                            .get(i1));
                    RestorableDroppedDatabase serviceResourceInstance = new RestorableDroppedDatabase();
                    result.getDatabases().add(serviceResourceInstance);

                    Element entityIdElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "EntityId");
                    if (entityIdElement != null) {
                        String entityIdInstance;
                        entityIdInstance = entityIdElement.getTextContent();
                        serviceResourceInstance.setEntityId(entityIdInstance);
                    }

                    Element serverNameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "ServerName");
                    if (serverNameElement != null) {
                        String serverNameInstance;
                        serverNameInstance = serverNameElement.getTextContent();
                        serviceResourceInstance.setServerName(serverNameInstance);
                    }

                    Element editionElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "Edition");
                    if (editionElement != null) {
                        String editionInstance;
                        editionInstance = editionElement.getTextContent();
                        serviceResourceInstance.setEdition(editionInstance);
                    }

                    Element maxSizeBytesElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "MaxSizeBytes");
                    if (maxSizeBytesElement != null) {
                        long maxSizeBytesInstance;
                        maxSizeBytesInstance = DatatypeConverter
                                .parseLong(maxSizeBytesElement.getTextContent());
                        serviceResourceInstance.setMaximumDatabaseSizeInBytes(maxSizeBytesInstance);
                    }

                    Element creationDateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "CreationDate");
                    if (creationDateElement != null) {
                        Calendar creationDateInstance;
                        creationDateInstance = DatatypeConverter
                                .parseDateTime(creationDateElement.getTextContent());
                        serviceResourceInstance.setCreationDate(creationDateInstance);
                    }

                    Element deletionDateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "DeletionDate");
                    if (deletionDateElement != null) {
                        Calendar deletionDateInstance;
                        deletionDateInstance = DatatypeConverter
                                .parseDateTime(deletionDateElement.getTextContent());
                        serviceResourceInstance.setDeletionDate(deletionDateInstance);
                    }

                    Element recoveryPeriodStartDateElement = XmlUtility.getElementByTagNameNS(
                            serviceResourcesElement, "http://schemas.microsoft.com/windowsazure",
                            "RecoveryPeriodStartDate");
                    if (recoveryPeriodStartDateElement != null
                            && recoveryPeriodStartDateElement.getTextContent() != null
                            && !recoveryPeriodStartDateElement.getTextContent().isEmpty()) {
                        Calendar recoveryPeriodStartDateInstance;
                        recoveryPeriodStartDateInstance = DatatypeConverter
                                .parseDateTime(recoveryPeriodStartDateElement.getTextContent());
                        serviceResourceInstance.setRecoveryPeriodStartDate(recoveryPeriodStartDateInstance);
                    }

                    Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "Name");
                    if (nameElement != null) {
                        String nameInstance;
                        nameInstance = nameElement.getTextContent();
                        serviceResourceInstance.setName(nameInstance);
                    }

                    Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "Type");
                    if (typeElement != null) {
                        String typeInstance;
                        typeInstance = typeElement.getTextContent();
                        serviceResourceInstance.setType(typeInstance);
                    }

                    Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "State");
                    if (stateElement != null) {
                        String stateInstance;
                        stateInstance = stateElement.getTextContent();
                        serviceResourceInstance.setState(stateInstance);
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.azure.management.storage.StorageAccountOperationsImpl.java

/**
* Asynchronously creates a new storage account with the specified
* parameters. Existing accounts cannot be updated with this API and should
* instead use the Update Storage Account API. If an account is already
* created and subsequent PUT request is issued with exact same set of
* properties, then HTTP 200 would be returned.
*
* @param resourceGroupName Required. The name of the resource group within
* the user's subscription.//  w  w  w.  ja va2s .  c  o  m
* @param accountName Required. The name of the storage account within the
* specified resource group. Storage account names must be between 3 and 24
* characters in length and use numbers and lower-case letters only.
* @param parameters Required. The parameters to provide for the created
* account.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The Create storage account operation response.
*/
@Override
public StorageAccountCreateResponse beginCreate(String resourceGroupName, String accountName,
        StorageAccountCreateParameters parameters) throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (accountName == null) {
        throw new NullPointerException("accountName");
    }
    if (accountName.length() < 3) {
        throw new IllegalArgumentException("accountName");
    }
    if (accountName.length() > 24) {
        throw new IllegalArgumentException("accountName");
    }
    for (char accountNameChar : accountName.toCharArray()) {
        if (Character.isLowerCase(accountNameChar) == false && Character.isDigit(accountNameChar) == false) {
            throw new IllegalArgumentException("accountName");
        }
    }
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getAccountType() == null) {
        throw new NullPointerException("parameters.AccountType");
    }
    if (parameters.getLocation() == null) {
        throw new NullPointerException("parameters.Location");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("accountName", accountName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "beginCreateAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourceGroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    url = url + "/providers/Microsoft.Storage/storageAccounts/";
    url = url + URLEncoder.encode(accountName, "UTF-8");
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2015-06-15");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPut httpRequest = new HttpPut(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json");
    httpRequest.setHeader("x-ms-client-request-id", UUID.randomUUID().toString());

    // Serialize Request
    String requestContent = null;
    JsonNode requestDoc = null;

    ObjectMapper objectMapper = new ObjectMapper();
    ObjectNode storageAccountCreateParametersJsonValue = objectMapper.createObjectNode();
    requestDoc = storageAccountCreateParametersJsonValue;

    ((ObjectNode) storageAccountCreateParametersJsonValue).put("location", parameters.getLocation());

    if (parameters.getTags() != null) {
        if (parameters.getTags() instanceof LazyCollection == false
                || ((LazyCollection) parameters.getTags()).isInitialized()) {
            ObjectNode tagsDictionary = objectMapper.createObjectNode();
            for (Map.Entry<String, String> entry : parameters.getTags().entrySet()) {
                String tagsKey = entry.getKey();
                String tagsValue = entry.getValue();
                ((ObjectNode) tagsDictionary).put(tagsKey, tagsValue);
            }
            ((ObjectNode) storageAccountCreateParametersJsonValue).put("tags", tagsDictionary);
        }
    }

    ObjectNode propertiesValue = objectMapper.createObjectNode();
    ((ObjectNode) storageAccountCreateParametersJsonValue).put("properties", propertiesValue);

    ((ObjectNode) propertiesValue).put("accountType",
            StorageManagementClientImpl.accountTypeToString(parameters.getAccountType()));

    StringWriter stringWriter = new StringWriter();
    objectMapper.writeValue(stringWriter, requestDoc);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/json");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_ACCEPTED) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        StorageAccountCreateResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_ACCEPTED) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new StorageAccountCreateResponse();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                StorageAccount storageAccountInstance = new StorageAccount();
                result.setStorageAccount(storageAccountInstance);

                JsonNode idValue = responseDoc.get("id");
                if (idValue != null && idValue instanceof NullNode == false) {
                    String idInstance;
                    idInstance = idValue.getTextValue();
                    storageAccountInstance.setId(idInstance);
                }

                JsonNode nameValue = responseDoc.get("name");
                if (nameValue != null && nameValue instanceof NullNode == false) {
                    String nameInstance;
                    nameInstance = nameValue.getTextValue();
                    storageAccountInstance.setName(nameInstance);
                }

                JsonNode typeValue = responseDoc.get("type");
                if (typeValue != null && typeValue instanceof NullNode == false) {
                    String typeInstance;
                    typeInstance = typeValue.getTextValue();
                    storageAccountInstance.setType(typeInstance);
                }

                JsonNode locationValue = responseDoc.get("location");
                if (locationValue != null && locationValue instanceof NullNode == false) {
                    String locationInstance;
                    locationInstance = locationValue.getTextValue();
                    storageAccountInstance.setLocation(locationInstance);
                }

                JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags"));
                if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) {
                    Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields();
                    while (itr.hasNext()) {
                        Map.Entry<String, JsonNode> property = itr.next();
                        String tagsKey2 = property.getKey();
                        String tagsValue2 = property.getValue().getTextValue();
                        storageAccountInstance.getTags().put(tagsKey2, tagsValue2);
                    }
                }

                JsonNode propertiesValue2 = responseDoc.get("properties");
                if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) {
                    JsonNode provisioningStateValue = propertiesValue2.get("provisioningState");
                    if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) {
                        ProvisioningState provisioningStateInstance;
                        provisioningStateInstance = EnumUtility.fromString(ProvisioningState.class,
                                provisioningStateValue.getTextValue());
                        storageAccountInstance.setProvisioningState(provisioningStateInstance);
                    }

                    JsonNode accountTypeValue = propertiesValue2.get("accountType");
                    if (accountTypeValue != null && accountTypeValue instanceof NullNode == false) {
                        AccountType accountTypeInstance;
                        accountTypeInstance = StorageManagementClientImpl
                                .parseAccountType(accountTypeValue.getTextValue());
                        storageAccountInstance.setAccountType(accountTypeInstance);
                    }

                    JsonNode primaryEndpointsValue = propertiesValue2.get("primaryEndpoints");
                    if (primaryEndpointsValue != null && primaryEndpointsValue instanceof NullNode == false) {
                        Endpoints primaryEndpointsInstance = new Endpoints();
                        storageAccountInstance.setPrimaryEndpoints(primaryEndpointsInstance);

                        JsonNode blobValue = primaryEndpointsValue.get("blob");
                        if (blobValue != null && blobValue instanceof NullNode == false) {
                            URI blobInstance;
                            blobInstance = new URI(blobValue.getTextValue());
                            primaryEndpointsInstance.setBlob(blobInstance);
                        }

                        JsonNode queueValue = primaryEndpointsValue.get("queue");
                        if (queueValue != null && queueValue instanceof NullNode == false) {
                            URI queueInstance;
                            queueInstance = new URI(queueValue.getTextValue());
                            primaryEndpointsInstance.setQueue(queueInstance);
                        }

                        JsonNode tableValue = primaryEndpointsValue.get("table");
                        if (tableValue != null && tableValue instanceof NullNode == false) {
                            URI tableInstance;
                            tableInstance = new URI(tableValue.getTextValue());
                            primaryEndpointsInstance.setTable(tableInstance);
                        }

                        JsonNode fileValue = primaryEndpointsValue.get("file");
                        if (fileValue != null && fileValue instanceof NullNode == false) {
                            URI fileInstance;
                            fileInstance = new URI(fileValue.getTextValue());
                            primaryEndpointsInstance.setFile(fileInstance);
                        }
                    }

                    JsonNode primaryLocationValue = propertiesValue2.get("primaryLocation");
                    if (primaryLocationValue != null && primaryLocationValue instanceof NullNode == false) {
                        String primaryLocationInstance;
                        primaryLocationInstance = primaryLocationValue.getTextValue();
                        storageAccountInstance.setPrimaryLocation(primaryLocationInstance);
                    }

                    JsonNode statusOfPrimaryValue = propertiesValue2.get("statusOfPrimary");
                    if (statusOfPrimaryValue != null && statusOfPrimaryValue instanceof NullNode == false) {
                        AccountStatus statusOfPrimaryInstance;
                        statusOfPrimaryInstance = EnumUtility.fromString(AccountStatus.class,
                                statusOfPrimaryValue.getTextValue());
                        storageAccountInstance.setStatusOfPrimary(statusOfPrimaryInstance);
                    }

                    JsonNode lastGeoFailoverTimeValue = propertiesValue2.get("lastGeoFailoverTime");
                    if (lastGeoFailoverTimeValue != null
                            && lastGeoFailoverTimeValue instanceof NullNode == false) {
                        Calendar lastGeoFailoverTimeInstance;
                        lastGeoFailoverTimeInstance = DatatypeConverter
                                .parseDateTime(lastGeoFailoverTimeValue.getTextValue());
                        storageAccountInstance.setLastGeoFailoverTime(lastGeoFailoverTimeInstance);
                    }

                    JsonNode secondaryLocationValue = propertiesValue2.get("secondaryLocation");
                    if (secondaryLocationValue != null && secondaryLocationValue instanceof NullNode == false) {
                        String secondaryLocationInstance;
                        secondaryLocationInstance = secondaryLocationValue.getTextValue();
                        storageAccountInstance.setSecondaryLocation(secondaryLocationInstance);
                    }

                    JsonNode statusOfSecondaryValue = propertiesValue2.get("statusOfSecondary");
                    if (statusOfSecondaryValue != null && statusOfSecondaryValue instanceof NullNode == false) {
                        AccountStatus statusOfSecondaryInstance;
                        statusOfSecondaryInstance = EnumUtility.fromString(AccountStatus.class,
                                statusOfSecondaryValue.getTextValue());
                        storageAccountInstance.setStatusOfSecondary(statusOfSecondaryInstance);
                    }

                    JsonNode creationTimeValue = propertiesValue2.get("creationTime");
                    if (creationTimeValue != null && creationTimeValue instanceof NullNode == false) {
                        Calendar creationTimeInstance;
                        creationTimeInstance = DatatypeConverter
                                .parseDateTime(creationTimeValue.getTextValue());
                        storageAccountInstance.setCreationTime(creationTimeInstance);
                    }

                    JsonNode customDomainValue = propertiesValue2.get("customDomain");
                    if (customDomainValue != null && customDomainValue instanceof NullNode == false) {
                        CustomDomain customDomainInstance = new CustomDomain();
                        storageAccountInstance.setCustomDomain(customDomainInstance);

                        JsonNode nameValue2 = customDomainValue.get("name");
                        if (nameValue2 != null && nameValue2 instanceof NullNode == false) {
                            String nameInstance2;
                            nameInstance2 = nameValue2.getTextValue();
                            customDomainInstance.setName(nameInstance2);
                        }

                        JsonNode useSubDomainValue = customDomainValue.get("useSubDomain");
                        if (useSubDomainValue != null && useSubDomainValue instanceof NullNode == false) {
                            boolean useSubDomainInstance;
                            useSubDomainInstance = useSubDomainValue.getBooleanValue();
                            customDomainInstance.setUseSubDomain(useSubDomainInstance);
                        }
                    }

                    JsonNode secondaryEndpointsValue = propertiesValue2.get("secondaryEndpoints");
                    if (secondaryEndpointsValue != null
                            && secondaryEndpointsValue instanceof NullNode == false) {
                        Endpoints secondaryEndpointsInstance = new Endpoints();
                        storageAccountInstance.setSecondaryEndpoints(secondaryEndpointsInstance);

                        JsonNode blobValue2 = secondaryEndpointsValue.get("blob");
                        if (blobValue2 != null && blobValue2 instanceof NullNode == false) {
                            URI blobInstance2;
                            blobInstance2 = new URI(blobValue2.getTextValue());
                            secondaryEndpointsInstance.setBlob(blobInstance2);
                        }

                        JsonNode queueValue2 = secondaryEndpointsValue.get("queue");
                        if (queueValue2 != null && queueValue2 instanceof NullNode == false) {
                            URI queueInstance2;
                            queueInstance2 = new URI(queueValue2.getTextValue());
                            secondaryEndpointsInstance.setQueue(queueInstance2);
                        }

                        JsonNode tableValue2 = secondaryEndpointsValue.get("table");
                        if (tableValue2 != null && tableValue2 instanceof NullNode == false) {
                            URI tableInstance2;
                            tableInstance2 = new URI(tableValue2.getTextValue());
                            secondaryEndpointsInstance.setTable(tableInstance2);
                        }

                        JsonNode fileValue2 = secondaryEndpointsValue.get("file");
                        if (fileValue2 != null && fileValue2 instanceof NullNode == false) {
                            URI fileInstance2;
                            fileInstance2 = new URI(fileValue2.getTextValue());
                            secondaryEndpointsInstance.setFile(fileInstance2);
                        }
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("Location").length > 0) {
            result.setOperationStatusLink(httpResponse.getFirstHeader("Location").getValue());
        }
        if (httpResponse.getHeaders("Retry-After").length > 0) {
            result.setRetryAfter(
                    DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue()));
        }
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }
        if (statusCode == HttpStatus.SC_CONFLICT || statusCode == HttpStatus.SC_BAD_REQUEST) {
            result.setStatus(OperationStatus.Failed);
        }
        if (statusCode == HttpStatus.SC_OK) {
            result.setStatus(OperationStatus.Succeeded);
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.azure.management.resources.DeploymentOperationOperationsImpl.java

/**
* Gets a list of deployments operations.
*
* @param resourceGroupName Required. The name of the resource group. The
* name is case insensitive./*from  w w w.  j a v a2 s .  c  o m*/
* @param deploymentName Required. The name of the deployment.
* @param parameters Optional. Query parameters.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return List of deployment operations.
*/
@Override
public DeploymentOperationsListResult list(String resourceGroupName, String deploymentName,
        DeploymentOperationsListParameters parameters)
        throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (resourceGroupName != null && resourceGroupName.length() > 1000) {
        throw new IllegalArgumentException("resourceGroupName");
    }
    if (Pattern.matches("^[-\\w\\._]+$", resourceGroupName) == false) {
        throw new IllegalArgumentException("resourceGroupName");
    }
    if (deploymentName == null) {
        throw new NullPointerException("deploymentName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("deploymentName", deploymentName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "listAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourcegroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    url = url + "/deployments/";
    url = url + URLEncoder.encode(deploymentName, "UTF-8");
    url = url + "/operations";
    ArrayList<String> queryParameters = new ArrayList<String>();
    if (parameters != null && parameters.getTop() != null) {
        queryParameters.add("$top=" + URLEncoder.encode(Integer.toString(parameters.getTop()), "UTF-8"));
    }
    queryParameters.add("api-version=" + "2014-04-01-preview");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json; charset=utf-8");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        DeploymentOperationsListResult result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new DeploymentOperationsListResult();
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                JsonNode valueArray = responseDoc.get("value");
                if (valueArray != null && valueArray instanceof NullNode == false) {
                    for (JsonNode valueValue : ((ArrayNode) valueArray)) {
                        DeploymentOperation deploymentOperationInstance = new DeploymentOperation();
                        result.getOperations().add(deploymentOperationInstance);

                        JsonNode idValue = valueValue.get("id");
                        if (idValue != null && idValue instanceof NullNode == false) {
                            String idInstance;
                            idInstance = idValue.getTextValue();
                            deploymentOperationInstance.setId(idInstance);
                        }

                        JsonNode operationIdValue = valueValue.get("operationId");
                        if (operationIdValue != null && operationIdValue instanceof NullNode == false) {
                            String operationIdInstance;
                            operationIdInstance = operationIdValue.getTextValue();
                            deploymentOperationInstance.setOperationId(operationIdInstance);
                        }

                        JsonNode propertiesValue = valueValue.get("properties");
                        if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                            DeploymentOperationProperties propertiesInstance = new DeploymentOperationProperties();
                            deploymentOperationInstance.setProperties(propertiesInstance);

                            JsonNode provisioningStateValue = propertiesValue.get("provisioningState");
                            if (provisioningStateValue != null
                                    && provisioningStateValue instanceof NullNode == false) {
                                String provisioningStateInstance;
                                provisioningStateInstance = provisioningStateValue.getTextValue();
                                propertiesInstance.setProvisioningState(provisioningStateInstance);
                            }

                            JsonNode timestampValue = propertiesValue.get("timestamp");
                            if (timestampValue != null && timestampValue instanceof NullNode == false) {
                                Calendar timestampInstance;
                                timestampInstance = DatatypeConverter
                                        .parseDateTime(timestampValue.getTextValue());
                                propertiesInstance.setTimestamp(timestampInstance);
                            }

                            JsonNode statusCodeValue = propertiesValue.get("statusCode");
                            if (statusCodeValue != null && statusCodeValue instanceof NullNode == false) {
                                String statusCodeInstance;
                                statusCodeInstance = statusCodeValue.getTextValue();
                                propertiesInstance.setStatusCode(statusCodeInstance);
                            }

                            JsonNode statusMessageValue = propertiesValue.get("statusMessage");
                            if (statusMessageValue != null && statusMessageValue instanceof NullNode == false) {
                                String statusMessageInstance;
                                statusMessageInstance = statusMessageValue.getTextValue();
                                propertiesInstance.setStatusMessage(statusMessageInstance);
                            }

                            JsonNode targetResourceValue = propertiesValue.get("targetResource");
                            if (targetResourceValue != null
                                    && targetResourceValue instanceof NullNode == false) {
                                TargetResource targetResourceInstance = new TargetResource();
                                propertiesInstance.setTargetResource(targetResourceInstance);

                                JsonNode idValue2 = targetResourceValue.get("id");
                                if (idValue2 != null && idValue2 instanceof NullNode == false) {
                                    String idInstance2;
                                    idInstance2 = idValue2.getTextValue();
                                    targetResourceInstance.setId(idInstance2);
                                }

                                JsonNode resourceNameValue = targetResourceValue.get("resourceName");
                                if (resourceNameValue != null
                                        && resourceNameValue instanceof NullNode == false) {
                                    String resourceNameInstance;
                                    resourceNameInstance = resourceNameValue.getTextValue();
                                    targetResourceInstance.setResourceName(resourceNameInstance);
                                }

                                JsonNode resourceTypeValue = targetResourceValue.get("resourceType");
                                if (resourceTypeValue != null
                                        && resourceTypeValue instanceof NullNode == false) {
                                    String resourceTypeInstance;
                                    resourceTypeInstance = resourceTypeValue.getTextValue();
                                    targetResourceInstance.setResourceType(resourceTypeInstance);
                                }
                            }
                        }
                    }
                }

                JsonNode nextLinkValue = responseDoc.get("nextLink");
                if (nextLinkValue != null && nextLinkValue instanceof NullNode == false) {
                    String nextLinkInstance;
                    nextLinkInstance = nextLinkValue.getTextValue();
                    result.setNextLink(nextLinkInstance);
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.azure.management.storage.StorageManagementClientImpl.java

/**
* The Get Create Operation Status operation returns the status of the
* specified create operation. After calling the asynchronous Begin Create
* operation, you can call Get Create Operation Status to determine whether
* the operation has succeeded, failed, or is still in progress.
*
* @param operationStatusLink Required. The URL where the status of the
* long-running create operation can be checked.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.//w w  w. j a  v a 2  s .  co  m
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The Create storage account operation response.
*/
@Override
public StorageAccountCreateResponse getCreateOperationStatus(String operationStatusLink)
        throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (operationStatusLink == null) {
        throw new NullPointerException("operationStatusLink");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("operationStatusLink", operationStatusLink);
        CloudTracing.enter(invocationId, this, "getCreateOperationStatusAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + operationStatusLink;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-client-request-id", UUID.randomUUID().toString());

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_ACCEPTED
                && statusCode != HttpStatus.SC_INTERNAL_SERVER_ERROR) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        StorageAccountCreateResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_ACCEPTED
                || statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new StorageAccountCreateResponse();
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                StorageAccount storageAccountInstance = new StorageAccount();
                result.setStorageAccount(storageAccountInstance);

                JsonNode idValue = responseDoc.get("id");
                if (idValue != null && idValue instanceof NullNode == false) {
                    String idInstance;
                    idInstance = idValue.getTextValue();
                    storageAccountInstance.setId(idInstance);
                }

                JsonNode nameValue = responseDoc.get("name");
                if (nameValue != null && nameValue instanceof NullNode == false) {
                    String nameInstance;
                    nameInstance = nameValue.getTextValue();
                    storageAccountInstance.setName(nameInstance);
                }

                JsonNode typeValue = responseDoc.get("type");
                if (typeValue != null && typeValue instanceof NullNode == false) {
                    String typeInstance;
                    typeInstance = typeValue.getTextValue();
                    storageAccountInstance.setType(typeInstance);
                }

                JsonNode locationValue = responseDoc.get("location");
                if (locationValue != null && locationValue instanceof NullNode == false) {
                    String locationInstance;
                    locationInstance = locationValue.getTextValue();
                    storageAccountInstance.setLocation(locationInstance);
                }

                JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags"));
                if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) {
                    Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields();
                    while (itr.hasNext()) {
                        Map.Entry<String, JsonNode> property = itr.next();
                        String tagsKey = property.getKey();
                        String tagsValue = property.getValue().getTextValue();
                        storageAccountInstance.getTags().put(tagsKey, tagsValue);
                    }
                }

                JsonNode propertiesValue = responseDoc.get("properties");
                if (propertiesValue != null && propertiesValue instanceof NullNode == false) {
                    JsonNode provisioningStateValue = propertiesValue.get("provisioningState");
                    if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) {
                        ProvisioningState provisioningStateInstance;
                        provisioningStateInstance = EnumUtility.fromString(ProvisioningState.class,
                                provisioningStateValue.getTextValue());
                        storageAccountInstance.setProvisioningState(provisioningStateInstance);
                    }

                    JsonNode accountTypeValue = propertiesValue.get("accountType");
                    if (accountTypeValue != null && accountTypeValue instanceof NullNode == false) {
                        AccountType accountTypeInstance;
                        accountTypeInstance = com.microsoft.azure.management.storage.StorageManagementClientImpl
                                .parseAccountType(accountTypeValue.getTextValue());
                        storageAccountInstance.setAccountType(accountTypeInstance);
                    }

                    JsonNode primaryEndpointsValue = propertiesValue.get("primaryEndpoints");
                    if (primaryEndpointsValue != null && primaryEndpointsValue instanceof NullNode == false) {
                        Endpoints primaryEndpointsInstance = new Endpoints();
                        storageAccountInstance.setPrimaryEndpoints(primaryEndpointsInstance);

                        JsonNode blobValue = primaryEndpointsValue.get("blob");
                        if (blobValue != null && blobValue instanceof NullNode == false) {
                            URI blobInstance;
                            blobInstance = new URI(blobValue.getTextValue());
                            primaryEndpointsInstance.setBlob(blobInstance);
                        }

                        JsonNode queueValue = primaryEndpointsValue.get("queue");
                        if (queueValue != null && queueValue instanceof NullNode == false) {
                            URI queueInstance;
                            queueInstance = new URI(queueValue.getTextValue());
                            primaryEndpointsInstance.setQueue(queueInstance);
                        }

                        JsonNode tableValue = primaryEndpointsValue.get("table");
                        if (tableValue != null && tableValue instanceof NullNode == false) {
                            URI tableInstance;
                            tableInstance = new URI(tableValue.getTextValue());
                            primaryEndpointsInstance.setTable(tableInstance);
                        }

                        JsonNode fileValue = primaryEndpointsValue.get("file");
                        if (fileValue != null && fileValue instanceof NullNode == false) {
                            URI fileInstance;
                            fileInstance = new URI(fileValue.getTextValue());
                            primaryEndpointsInstance.setFile(fileInstance);
                        }
                    }

                    JsonNode primaryLocationValue = propertiesValue.get("primaryLocation");
                    if (primaryLocationValue != null && primaryLocationValue instanceof NullNode == false) {
                        String primaryLocationInstance;
                        primaryLocationInstance = primaryLocationValue.getTextValue();
                        storageAccountInstance.setPrimaryLocation(primaryLocationInstance);
                    }

                    JsonNode statusOfPrimaryValue = propertiesValue.get("statusOfPrimary");
                    if (statusOfPrimaryValue != null && statusOfPrimaryValue instanceof NullNode == false) {
                        AccountStatus statusOfPrimaryInstance;
                        statusOfPrimaryInstance = EnumUtility.fromString(AccountStatus.class,
                                statusOfPrimaryValue.getTextValue());
                        storageAccountInstance.setStatusOfPrimary(statusOfPrimaryInstance);
                    }

                    JsonNode lastGeoFailoverTimeValue = propertiesValue.get("lastGeoFailoverTime");
                    if (lastGeoFailoverTimeValue != null
                            && lastGeoFailoverTimeValue instanceof NullNode == false) {
                        Calendar lastGeoFailoverTimeInstance;
                        lastGeoFailoverTimeInstance = DatatypeConverter
                                .parseDateTime(lastGeoFailoverTimeValue.getTextValue());
                        storageAccountInstance.setLastGeoFailoverTime(lastGeoFailoverTimeInstance);
                    }

                    JsonNode secondaryLocationValue = propertiesValue.get("secondaryLocation");
                    if (secondaryLocationValue != null && secondaryLocationValue instanceof NullNode == false) {
                        String secondaryLocationInstance;
                        secondaryLocationInstance = secondaryLocationValue.getTextValue();
                        storageAccountInstance.setSecondaryLocation(secondaryLocationInstance);
                    }

                    JsonNode statusOfSecondaryValue = propertiesValue.get("statusOfSecondary");
                    if (statusOfSecondaryValue != null && statusOfSecondaryValue instanceof NullNode == false) {
                        AccountStatus statusOfSecondaryInstance;
                        statusOfSecondaryInstance = EnumUtility.fromString(AccountStatus.class,
                                statusOfSecondaryValue.getTextValue());
                        storageAccountInstance.setStatusOfSecondary(statusOfSecondaryInstance);
                    }

                    JsonNode creationTimeValue = propertiesValue.get("creationTime");
                    if (creationTimeValue != null && creationTimeValue instanceof NullNode == false) {
                        Calendar creationTimeInstance;
                        creationTimeInstance = DatatypeConverter
                                .parseDateTime(creationTimeValue.getTextValue());
                        storageAccountInstance.setCreationTime(creationTimeInstance);
                    }

                    JsonNode customDomainValue = propertiesValue.get("customDomain");
                    if (customDomainValue != null && customDomainValue instanceof NullNode == false) {
                        CustomDomain customDomainInstance = new CustomDomain();
                        storageAccountInstance.setCustomDomain(customDomainInstance);

                        JsonNode nameValue2 = customDomainValue.get("name");
                        if (nameValue2 != null && nameValue2 instanceof NullNode == false) {
                            String nameInstance2;
                            nameInstance2 = nameValue2.getTextValue();
                            customDomainInstance.setName(nameInstance2);
                        }

                        JsonNode useSubDomainValue = customDomainValue.get("useSubDomain");
                        if (useSubDomainValue != null && useSubDomainValue instanceof NullNode == false) {
                            boolean useSubDomainInstance;
                            useSubDomainInstance = useSubDomainValue.getBooleanValue();
                            customDomainInstance.setUseSubDomain(useSubDomainInstance);
                        }
                    }

                    JsonNode secondaryEndpointsValue = propertiesValue.get("secondaryEndpoints");
                    if (secondaryEndpointsValue != null
                            && secondaryEndpointsValue instanceof NullNode == false) {
                        Endpoints secondaryEndpointsInstance = new Endpoints();
                        storageAccountInstance.setSecondaryEndpoints(secondaryEndpointsInstance);

                        JsonNode blobValue2 = secondaryEndpointsValue.get("blob");
                        if (blobValue2 != null && blobValue2 instanceof NullNode == false) {
                            URI blobInstance2;
                            blobInstance2 = new URI(blobValue2.getTextValue());
                            secondaryEndpointsInstance.setBlob(blobInstance2);
                        }

                        JsonNode queueValue2 = secondaryEndpointsValue.get("queue");
                        if (queueValue2 != null && queueValue2 instanceof NullNode == false) {
                            URI queueInstance2;
                            queueInstance2 = new URI(queueValue2.getTextValue());
                            secondaryEndpointsInstance.setQueue(queueInstance2);
                        }

                        JsonNode tableValue2 = secondaryEndpointsValue.get("table");
                        if (tableValue2 != null && tableValue2 instanceof NullNode == false) {
                            URI tableInstance2;
                            tableInstance2 = new URI(tableValue2.getTextValue());
                            secondaryEndpointsInstance.setTable(tableInstance2);
                        }

                        JsonNode fileValue2 = secondaryEndpointsValue.get("file");
                        if (fileValue2 != null && fileValue2 instanceof NullNode == false) {
                            URI fileInstance2;
                            fileInstance2 = new URI(fileValue2.getTextValue());
                            secondaryEndpointsInstance.setFile(fileInstance2);
                        }
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("Location").length > 0) {
            result.setOperationStatusLink(httpResponse.getFirstHeader("Location").getValue());
        }
        if (httpResponse.getHeaders("Retry-After").length > 0) {
            result.setRetryAfter(
                    DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue()));
        }
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }
        if (statusCode == HttpStatus.SC_CONFLICT) {
            result.setStatus(OperationStatus.Failed);
        }
        if (statusCode == HttpStatus.SC_ACCEPTED) {
            result.setStatus(OperationStatus.InProgress);
        }
        if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
            result.setStatus(OperationStatus.InProgress);
        }
        if (statusCode == HttpStatus.SC_OK) {
            result.setStatus(OperationStatus.Succeeded);
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.windowsazure.management.ManagementCertificateOperationsImpl.java

/**
* The Get Management Certificate operation retrieves information about the
* management certificate with the specified thumbprint. Management
* certificates, which are also known as subscription certificates,
* authenticate clients attempting to connect to resources associated with
* your Azure subscription.  (see//from  ww  w .  j av a  2  s  .  c  o m
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154131.aspx for
* more information)
*
* @param thumbprint Required. The thumbprint value of the certificate to
* retrieve information about.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The Get Management Certificate operation response.
*/
@Override
public ManagementCertificateGetResponse get(String thumbprint)
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate
    if (thumbprint == null) {
        throw new NullPointerException("thumbprint");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("thumbprint", thumbprint);
        CloudTracing.enter(invocationId, this, "getAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/certificates/";
    url = url + URLEncoder.encode(thumbprint, "UTF-8");
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "2014-10-01");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        ManagementCertificateGetResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ManagementCertificateGetResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element subscriptionCertificateElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "SubscriptionCertificate");
            if (subscriptionCertificateElement != null) {
                Element subscriptionCertificatePublicKeyElement = XmlUtility.getElementByTagNameNS(
                        subscriptionCertificateElement, "http://schemas.microsoft.com/windowsazure",
                        "SubscriptionCertificatePublicKey");
                if (subscriptionCertificatePublicKeyElement != null) {
                    byte[] subscriptionCertificatePublicKeyInstance;
                    subscriptionCertificatePublicKeyInstance = subscriptionCertificatePublicKeyElement
                            .getTextContent() != null
                                    ? Base64.decode(subscriptionCertificatePublicKeyElement.getTextContent())
                                    : null;
                    result.setPublicKey(subscriptionCertificatePublicKeyInstance);
                }

                Element subscriptionCertificateThumbprintElement = XmlUtility.getElementByTagNameNS(
                        subscriptionCertificateElement, "http://schemas.microsoft.com/windowsazure",
                        "SubscriptionCertificateThumbprint");
                if (subscriptionCertificateThumbprintElement != null) {
                    String subscriptionCertificateThumbprintInstance;
                    subscriptionCertificateThumbprintInstance = subscriptionCertificateThumbprintElement
                            .getTextContent();
                    result.setThumbprint(subscriptionCertificateThumbprintInstance);
                }

                Element subscriptionCertificateDataElement = XmlUtility.getElementByTagNameNS(
                        subscriptionCertificateElement, "http://schemas.microsoft.com/windowsazure",
                        "SubscriptionCertificateData");
                if (subscriptionCertificateDataElement != null) {
                    byte[] subscriptionCertificateDataInstance;
                    subscriptionCertificateDataInstance = subscriptionCertificateDataElement
                            .getTextContent() != null
                                    ? Base64.decode(subscriptionCertificateDataElement.getTextContent())
                                    : null;
                    result.setData(subscriptionCertificateDataInstance);
                }

                Element createdElement = XmlUtility.getElementByTagNameNS(subscriptionCertificateElement,
                        "http://schemas.microsoft.com/windowsazure", "Created");
                if (createdElement != null) {
                    Calendar createdInstance;
                    createdInstance = DatatypeConverter.parseDateTime(createdElement.getTextContent());
                    result.setCreated(createdInstance);
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.windowsazure.management.servicebus.NamespaceOperationsImpl.java

/**
* Creates a new service namespace. Once created, this namespace's resource
* manifest is immutable. This operation is idempotent.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj856303.aspx for
* more information)//from  www  .  j  a v  a  2 s  .  c o m
*
* @param namespaceName Required. The namespace name.
* @param region Optional. The namespace region.
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The response to a request for a particular namespace.
*/
@Override
public ServiceBusNamespaceResponse create(String namespaceName, String region)
        throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException,
        URISyntaxException {
    // Validate
    if (namespaceName == null) {
        throw new NullPointerException("namespaceName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("namespaceName", namespaceName);
        tracingParameters.put("region", region);
        CloudTracing.enter(invocationId, this, "createAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/servicebus/namespaces/";
    url = url + URLEncoder.encode(namespaceName, "UTF-8");
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPut httpRequest = new HttpPut(url);

    // Set Headers
    httpRequest.setHeader("Accept", "application/atom+xml");
    httpRequest.setHeader("Content-Type", "application/atom+xml");
    httpRequest.setHeader("type", "entry");
    httpRequest.setHeader("x-ms-version", "2013-07-01");

    // Serialize Request
    String requestContent = null;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document requestDoc = documentBuilder.newDocument();

    Element entryElement = requestDoc.createElementNS("http://www.w3.org/2005/Atom", "entry");
    requestDoc.appendChild(entryElement);

    Element contentElement = requestDoc.createElementNS("http://www.w3.org/2005/Atom", "content");
    entryElement.appendChild(contentElement);

    Attr typeAttribute = requestDoc.createAttribute("type");
    typeAttribute.setValue("application/xml");
    contentElement.setAttributeNode(typeAttribute);

    Element namespaceDescriptionElement = requestDoc.createElementNS(
            "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "NamespaceDescription");
    contentElement.appendChild(namespaceDescriptionElement);

    if (region != null) {
        Element regionElement = requestDoc.createElementNS(
                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Region");
        regionElement.appendChild(requestDoc.createTextNode(region));
        namespaceDescriptionElement.appendChild(regionElement);
    }

    DOMSource domSource = new DOMSource(requestDoc);
    StringWriter stringWriter = new StringWriter();
    StreamResult streamResult = new StreamResult(stringWriter);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(domSource, streamResult);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/atom+xml");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        ServiceBusNamespaceResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new ServiceBusNamespaceResponse();
            DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance();
            documentBuilderFactory2.setNamespaceAware(true);
            DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder();
            Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent));

            Element entryElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://www.w3.org/2005/Atom",
                    "entry");
            if (entryElement2 != null) {
                Element contentElement2 = XmlUtility.getElementByTagNameNS(entryElement2,
                        "http://www.w3.org/2005/Atom", "content");
                if (contentElement2 != null) {
                    Element namespaceDescriptionElement2 = XmlUtility.getElementByTagNameNS(contentElement2,
                            "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                            "NamespaceDescription");
                    if (namespaceDescriptionElement2 != null) {
                        ServiceBusNamespace namespaceDescriptionInstance = new ServiceBusNamespace();
                        result.setNamespace(namespaceDescriptionInstance);

                        Element nameElement = XmlUtility.getElementByTagNameNS(namespaceDescriptionElement2,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Name");
                        if (nameElement != null) {
                            String nameInstance;
                            nameInstance = nameElement.getTextContent();
                            namespaceDescriptionInstance.setName(nameInstance);
                        }

                        Element regionElement2 = XmlUtility.getElementByTagNameNS(namespaceDescriptionElement2,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "Region");
                        if (regionElement2 != null) {
                            String regionInstance;
                            regionInstance = regionElement2.getTextContent();
                            namespaceDescriptionInstance.setRegion(regionInstance);
                        }

                        Element statusElement = XmlUtility.getElementByTagNameNS(namespaceDescriptionElement2,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "Status");
                        if (statusElement != null) {
                            String statusInstance;
                            statusInstance = statusElement.getTextContent();
                            namespaceDescriptionInstance.setStatus(statusInstance);
                        }

                        Element createdAtElement = XmlUtility.getElementByTagNameNS(
                                namespaceDescriptionElement2,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "CreatedAt");
                        if (createdAtElement != null) {
                            Calendar createdAtInstance;
                            createdAtInstance = DatatypeConverter
                                    .parseDateTime(createdAtElement.getTextContent());
                            namespaceDescriptionInstance.setCreatedAt(createdAtInstance);
                        }

                        Element acsManagementEndpointElement = XmlUtility.getElementByTagNameNS(
                                namespaceDescriptionElement2,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "AcsManagementEndpoint");
                        if (acsManagementEndpointElement != null) {
                            URI acsManagementEndpointInstance;
                            acsManagementEndpointInstance = new URI(
                                    acsManagementEndpointElement.getTextContent());
                            namespaceDescriptionInstance
                                    .setAcsManagementEndpoint(acsManagementEndpointInstance);
                        }

                        Element serviceBusEndpointElement = XmlUtility.getElementByTagNameNS(
                                namespaceDescriptionElement2,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "ServiceBusEndpoint");
                        if (serviceBusEndpointElement != null) {
                            URI serviceBusEndpointInstance;
                            serviceBusEndpointInstance = new URI(serviceBusEndpointElement.getTextContent());
                            namespaceDescriptionInstance.setServiceBusEndpoint(serviceBusEndpointInstance);
                        }

                        Element subscriptionIdElement = XmlUtility.getElementByTagNameNS(
                                namespaceDescriptionElement2,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "SubscriptionId");
                        if (subscriptionIdElement != null) {
                            String subscriptionIdInstance;
                            subscriptionIdInstance = subscriptionIdElement.getTextContent();
                            namespaceDescriptionInstance.setSubscriptionId(subscriptionIdInstance);
                        }

                        Element enabledElement = XmlUtility.getElementByTagNameNS(namespaceDescriptionElement2,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "Enabled");
                        if (enabledElement != null) {
                            boolean enabledInstance;
                            enabledInstance = DatatypeConverter
                                    .parseBoolean(enabledElement.getTextContent().toLowerCase());
                            namespaceDescriptionInstance.setEnabled(enabledInstance);
                        }

                        Element createACSNamespaceElement = XmlUtility.getElementByTagNameNS(
                                namespaceDescriptionElement2,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "CreateACSNamespace");
                        if (createACSNamespaceElement != null) {
                            boolean createACSNamespaceInstance;
                            createACSNamespaceInstance = DatatypeConverter
                                    .parseBoolean(createACSNamespaceElement.getTextContent().toLowerCase());
                            namespaceDescriptionInstance.setCreateACSNamespace(createACSNamespaceInstance);
                        }

                        Element namespaceTypeElement = XmlUtility.getElementByTagNameNS(
                                namespaceDescriptionElement2,
                                "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
                                "NamespaceType");
                        if (namespaceTypeElement != null && namespaceTypeElement.getTextContent() != null
                                && !namespaceTypeElement.getTextContent().isEmpty()) {
                            NamespaceType namespaceTypeInstance;
                            namespaceTypeInstance = NamespaceType
                                    .valueOf(namespaceTypeElement.getTextContent());
                            namespaceDescriptionInstance.setNamespaceType(namespaceTypeInstance);
                        }
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.azure.management.sql.DatabaseOperationsImpl.java

/**
* Begins creating a new Azure SQL Database or updating an existing Azure
* SQL Database. To determine the status of the operation call
* GetDatabaseOperationStatus./*ww w  .  j  a  v  a  2 s.com*/
*
* @param resourceGroupName Required. The name of the Resource Group to
* which the Azure SQL Database Server belongs.
* @param serverName Required. The name of the Azure SQL Database Server on
* which the database is hosted.
* @param databaseName Required. The name of the Azure SQL Database to be
* operated on (Updated or created).
* @param parameters Required. The required parameters for creating or
* updating a database.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return Response for long running Azure Sql Database operations.
*/
@Override
public DatabaseCreateOrUpdateResponse beginCreateOrUpdate(String resourceGroupName, String serverName,
        String databaseName, DatabaseCreateOrUpdateParameters parameters) throws IOException, ServiceException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (serverName == null) {
        throw new NullPointerException("serverName");
    }
    if (databaseName == null) {
        throw new NullPointerException("databaseName");
    }
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getLocation() == null) {
        throw new NullPointerException("parameters.Location");
    }
    if (parameters.getProperties() == null) {
        throw new NullPointerException("parameters.Properties");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("serverName", serverName);
        tracingParameters.put("databaseName", databaseName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "beginCreateOrUpdateAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourceGroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    url = url + "/providers/";
    url = url + "Microsoft.Sql";
    url = url + "/servers/";
    url = url + URLEncoder.encode(serverName, "UTF-8");
    url = url + "/databases/";
    url = url + URLEncoder.encode(databaseName, "UTF-8");
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2014-04-01");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPut httpRequest = new HttpPut(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json; charset=utf-8");

    // Serialize Request
    String requestContent = null;
    JsonNode requestDoc = null;

    ObjectMapper objectMapper = new ObjectMapper();
    ObjectNode databaseCreateOrUpdateParametersValue = objectMapper.createObjectNode();
    requestDoc = databaseCreateOrUpdateParametersValue;

    ObjectNode propertiesValue = objectMapper.createObjectNode();
    ((ObjectNode) databaseCreateOrUpdateParametersValue).put("properties", propertiesValue);

    if (parameters.getProperties().getEdition() != null) {
        ((ObjectNode) propertiesValue).put("edition", parameters.getProperties().getEdition());
    }

    if (parameters.getProperties().getCollation() != null) {
        ((ObjectNode) propertiesValue).put("collation", parameters.getProperties().getCollation());
    }

    if (parameters.getProperties().getMaxSizeBytes() != null) {
        ((ObjectNode) propertiesValue).put("maxSizeBytes",
                Long.toString(parameters.getProperties().getMaxSizeBytes()));
    }

    if (parameters.getProperties().getRequestedServiceObjectiveId() != null) {
        ((ObjectNode) propertiesValue).put("requestedServiceObjectiveId",
                parameters.getProperties().getRequestedServiceObjectiveId());
    }

    if (parameters.getProperties().getRequestedServiceObjectiveName() != null) {
        ((ObjectNode) propertiesValue).put("requestedServiceObjectiveName",
                parameters.getProperties().getRequestedServiceObjectiveName());
    }

    if (parameters.getProperties().getElasticPoolName() != null) {
        ((ObjectNode) propertiesValue).put("elasticPoolName", parameters.getProperties().getElasticPoolName());
    }

    if (parameters.getProperties().getSourceDatabaseId() != null) {
        ((ObjectNode) propertiesValue).put("sourceDatabaseId",
                parameters.getProperties().getSourceDatabaseId());
    }

    if (parameters.getProperties().getCreateMode() != null) {
        ((ObjectNode) propertiesValue).put("createMode", parameters.getProperties().getCreateMode());
    }

    ((ObjectNode) databaseCreateOrUpdateParametersValue).put("location", parameters.getLocation());

    if (parameters.getTags() != null) {
        ObjectNode tagsDictionary = objectMapper.createObjectNode();
        for (Map.Entry<String, String> entry : parameters.getTags().entrySet()) {
            String tagsKey = entry.getKey();
            String tagsValue = entry.getValue();
            ((ObjectNode) tagsDictionary).put(tagsKey, tagsValue);
        }
        ((ObjectNode) databaseCreateOrUpdateParametersValue).put("tags", tagsDictionary);
    }

    StringWriter stringWriter = new StringWriter();
    objectMapper.writeValue(stringWriter, requestDoc);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/json; charset=utf-8");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED
                && statusCode != HttpStatus.SC_ACCEPTED) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        DatabaseCreateOrUpdateResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED
                || statusCode == HttpStatus.SC_ACCEPTED) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new DatabaseCreateOrUpdateResponse();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                ErrorResponse errorInstance = new ErrorResponse();
                result.setError(errorInstance);

                JsonNode codeValue = responseDoc.get("code");
                if (codeValue != null && codeValue instanceof NullNode == false) {
                    String codeInstance;
                    codeInstance = codeValue.getTextValue();
                    errorInstance.setCode(codeInstance);
                }

                JsonNode messageValue = responseDoc.get("message");
                if (messageValue != null && messageValue instanceof NullNode == false) {
                    String messageInstance;
                    messageInstance = messageValue.getTextValue();
                    errorInstance.setMessage(messageInstance);
                }

                JsonNode targetValue = responseDoc.get("target");
                if (targetValue != null && targetValue instanceof NullNode == false) {
                    String targetInstance;
                    targetInstance = targetValue.getTextValue();
                    errorInstance.setTarget(targetInstance);
                }

                Database databaseInstance = new Database();
                result.setDatabase(databaseInstance);

                JsonNode propertiesValue2 = responseDoc.get("properties");
                if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) {
                    DatabaseProperties propertiesInstance = new DatabaseProperties();
                    databaseInstance.setProperties(propertiesInstance);

                    JsonNode collationValue = propertiesValue2.get("collation");
                    if (collationValue != null && collationValue instanceof NullNode == false) {
                        String collationInstance;
                        collationInstance = collationValue.getTextValue();
                        propertiesInstance.setCollation(collationInstance);
                    }

                    JsonNode creationDateValue = propertiesValue2.get("creationDate");
                    if (creationDateValue != null && creationDateValue instanceof NullNode == false) {
                        Calendar creationDateInstance;
                        creationDateInstance = DatatypeConverter
                                .parseDateTime(creationDateValue.getTextValue());
                        propertiesInstance.setCreationDate(creationDateInstance);
                    }

                    JsonNode currentServiceObjectiveIdValue = propertiesValue2.get("currentServiceObjectiveId");
                    if (currentServiceObjectiveIdValue != null
                            && currentServiceObjectiveIdValue instanceof NullNode == false) {
                        String currentServiceObjectiveIdInstance;
                        currentServiceObjectiveIdInstance = currentServiceObjectiveIdValue.getTextValue();
                        propertiesInstance.setCurrentServiceObjectiveId(currentServiceObjectiveIdInstance);
                    }

                    JsonNode databaseIdValue = propertiesValue2.get("databaseId");
                    if (databaseIdValue != null && databaseIdValue instanceof NullNode == false) {
                        String databaseIdInstance;
                        databaseIdInstance = databaseIdValue.getTextValue();
                        propertiesInstance.setDatabaseId(databaseIdInstance);
                    }

                    JsonNode earliestRestoreDateValue = propertiesValue2.get("earliestRestoreDate");
                    if (earliestRestoreDateValue != null
                            && earliestRestoreDateValue instanceof NullNode == false) {
                        Calendar earliestRestoreDateInstance;
                        earliestRestoreDateInstance = DatatypeConverter
                                .parseDateTime(earliestRestoreDateValue.getTextValue());
                        propertiesInstance.setEarliestRestoreDate(earliestRestoreDateInstance);
                    }

                    JsonNode editionValue = propertiesValue2.get("edition");
                    if (editionValue != null && editionValue instanceof NullNode == false) {
                        String editionInstance;
                        editionInstance = editionValue.getTextValue();
                        propertiesInstance.setEdition(editionInstance);
                    }

                    JsonNode maxSizeBytesValue = propertiesValue2.get("maxSizeBytes");
                    if (maxSizeBytesValue != null && maxSizeBytesValue instanceof NullNode == false) {
                        long maxSizeBytesInstance;
                        maxSizeBytesInstance = maxSizeBytesValue.getLongValue();
                        propertiesInstance.setMaxSizeBytes(maxSizeBytesInstance);
                    }

                    JsonNode requestedServiceObjectiveIdValue = propertiesValue2
                            .get("requestedServiceObjectiveId");
                    if (requestedServiceObjectiveIdValue != null
                            && requestedServiceObjectiveIdValue instanceof NullNode == false) {
                        String requestedServiceObjectiveIdInstance;
                        requestedServiceObjectiveIdInstance = requestedServiceObjectiveIdValue.getTextValue();
                        propertiesInstance.setRequestedServiceObjectiveId(requestedServiceObjectiveIdInstance);
                    }

                    JsonNode requestedServiceObjectiveNameValue = propertiesValue2
                            .get("requestedServiceObjectiveName");
                    if (requestedServiceObjectiveNameValue != null
                            && requestedServiceObjectiveNameValue instanceof NullNode == false) {
                        String requestedServiceObjectiveNameInstance;
                        requestedServiceObjectiveNameInstance = requestedServiceObjectiveNameValue
                                .getTextValue();
                        propertiesInstance
                                .setRequestedServiceObjectiveName(requestedServiceObjectiveNameInstance);
                    }

                    JsonNode serviceLevelObjectiveValue = propertiesValue2.get("serviceLevelObjective");
                    if (serviceLevelObjectiveValue != null
                            && serviceLevelObjectiveValue instanceof NullNode == false) {
                        String serviceLevelObjectiveInstance;
                        serviceLevelObjectiveInstance = serviceLevelObjectiveValue.getTextValue();
                        propertiesInstance.setServiceObjective(serviceLevelObjectiveInstance);
                    }

                    JsonNode statusValue = propertiesValue2.get("status");
                    if (statusValue != null && statusValue instanceof NullNode == false) {
                        String statusInstance;
                        statusInstance = statusValue.getTextValue();
                        propertiesInstance.setStatus(statusInstance);
                    }

                    JsonNode elasticPoolNameValue = propertiesValue2.get("elasticPoolName");
                    if (elasticPoolNameValue != null && elasticPoolNameValue instanceof NullNode == false) {
                        String elasticPoolNameInstance;
                        elasticPoolNameInstance = elasticPoolNameValue.getTextValue();
                        propertiesInstance.setElasticPoolName(elasticPoolNameInstance);
                    }

                    JsonNode serviceTierAdvisorsArray = propertiesValue2.get("serviceTierAdvisors");
                    if (serviceTierAdvisorsArray != null
                            && serviceTierAdvisorsArray instanceof NullNode == false) {
                        for (JsonNode serviceTierAdvisorsValue : ((ArrayNode) serviceTierAdvisorsArray)) {
                            ServiceTierAdvisor serviceTierAdvisorInstance = new ServiceTierAdvisor();
                            propertiesInstance.getServiceTierAdvisors().add(serviceTierAdvisorInstance);

                            JsonNode propertiesValue3 = serviceTierAdvisorsValue.get("properties");
                            if (propertiesValue3 != null && propertiesValue3 instanceof NullNode == false) {
                                ServiceTierAdvisorProperties propertiesInstance2 = new ServiceTierAdvisorProperties();
                                serviceTierAdvisorInstance.setProperties(propertiesInstance2);

                                JsonNode observationPeriodStartValue = propertiesValue3
                                        .get("observationPeriodStart");
                                if (observationPeriodStartValue != null
                                        && observationPeriodStartValue instanceof NullNode == false) {
                                    Calendar observationPeriodStartInstance;
                                    observationPeriodStartInstance = DatatypeConverter
                                            .parseDateTime(observationPeriodStartValue.getTextValue());
                                    propertiesInstance2
                                            .setObservationPeriodStart(observationPeriodStartInstance);
                                }

                                JsonNode observationPeriodEndValue = propertiesValue3
                                        .get("observationPeriodEnd");
                                if (observationPeriodEndValue != null
                                        && observationPeriodEndValue instanceof NullNode == false) {
                                    Calendar observationPeriodEndInstance;
                                    observationPeriodEndInstance = DatatypeConverter
                                            .parseDateTime(observationPeriodEndValue.getTextValue());
                                    propertiesInstance2.setObservationPeriodEnd(observationPeriodEndInstance);
                                }

                                JsonNode activeTimeRatioValue = propertiesValue3.get("activeTimeRatio");
                                if (activeTimeRatioValue != null
                                        && activeTimeRatioValue instanceof NullNode == false) {
                                    double activeTimeRatioInstance;
                                    activeTimeRatioInstance = activeTimeRatioValue.getDoubleValue();
                                    propertiesInstance2.setActiveTimeRatio(activeTimeRatioInstance);
                                }

                                JsonNode minDtuValue = propertiesValue3.get("minDtu");
                                if (minDtuValue != null && minDtuValue instanceof NullNode == false) {
                                    double minDtuInstance;
                                    minDtuInstance = minDtuValue.getDoubleValue();
                                    propertiesInstance2.setMinDtu(minDtuInstance);
                                }

                                JsonNode avgDtuValue = propertiesValue3.get("avgDtu");
                                if (avgDtuValue != null && avgDtuValue instanceof NullNode == false) {
                                    double avgDtuInstance;
                                    avgDtuInstance = avgDtuValue.getDoubleValue();
                                    propertiesInstance2.setAvgDtu(avgDtuInstance);
                                }

                                JsonNode maxDtuValue = propertiesValue3.get("maxDtu");
                                if (maxDtuValue != null && maxDtuValue instanceof NullNode == false) {
                                    double maxDtuInstance;
                                    maxDtuInstance = maxDtuValue.getDoubleValue();
                                    propertiesInstance2.setMaxDtu(maxDtuInstance);
                                }

                                JsonNode maxSizeInGBValue = propertiesValue3.get("maxSizeInGB");
                                if (maxSizeInGBValue != null && maxSizeInGBValue instanceof NullNode == false) {
                                    double maxSizeInGBInstance;
                                    maxSizeInGBInstance = maxSizeInGBValue.getDoubleValue();
                                    propertiesInstance2.setMaxSizeInGB(maxSizeInGBInstance);
                                }

                                JsonNode serviceLevelObjectiveUsageMetricsArray = propertiesValue3
                                        .get("serviceLevelObjectiveUsageMetrics");
                                if (serviceLevelObjectiveUsageMetricsArray != null
                                        && serviceLevelObjectiveUsageMetricsArray instanceof NullNode == false) {
                                    for (JsonNode serviceLevelObjectiveUsageMetricsValue : ((ArrayNode) serviceLevelObjectiveUsageMetricsArray)) {
                                        SloUsageMetric sloUsageMetricInstance = new SloUsageMetric();
                                        propertiesInstance2.getServiceLevelObjectiveUsageMetrics()
                                                .add(sloUsageMetricInstance);

                                        JsonNode serviceLevelObjectiveValue2 = serviceLevelObjectiveUsageMetricsValue
                                                .get("serviceLevelObjective");
                                        if (serviceLevelObjectiveValue2 != null
                                                && serviceLevelObjectiveValue2 instanceof NullNode == false) {
                                            String serviceLevelObjectiveInstance2;
                                            serviceLevelObjectiveInstance2 = serviceLevelObjectiveValue2
                                                    .getTextValue();
                                            sloUsageMetricInstance
                                                    .setServiceLevelObjective(serviceLevelObjectiveInstance2);
                                        }

                                        JsonNode serviceLevelObjectiveIdValue = serviceLevelObjectiveUsageMetricsValue
                                                .get("serviceLevelObjectiveId");
                                        if (serviceLevelObjectiveIdValue != null
                                                && serviceLevelObjectiveIdValue instanceof NullNode == false) {
                                            String serviceLevelObjectiveIdInstance;
                                            serviceLevelObjectiveIdInstance = serviceLevelObjectiveIdValue
                                                    .getTextValue();
                                            sloUsageMetricInstance.setServiceLevelObjectiveId(
                                                    serviceLevelObjectiveIdInstance);
                                        }

                                        JsonNode inRangeTimeRatioValue = serviceLevelObjectiveUsageMetricsValue
                                                .get("inRangeTimeRatio");
                                        if (inRangeTimeRatioValue != null
                                                && inRangeTimeRatioValue instanceof NullNode == false) {
                                            double inRangeTimeRatioInstance;
                                            inRangeTimeRatioInstance = inRangeTimeRatioValue.getDoubleValue();
                                            sloUsageMetricInstance
                                                    .setInRangeTimeRatio(inRangeTimeRatioInstance);
                                        }

                                        JsonNode idValue = serviceLevelObjectiveUsageMetricsValue.get("id");
                                        if (idValue != null && idValue instanceof NullNode == false) {
                                            String idInstance;
                                            idInstance = idValue.getTextValue();
                                            sloUsageMetricInstance.setId(idInstance);
                                        }

                                        JsonNode nameValue = serviceLevelObjectiveUsageMetricsValue.get("name");
                                        if (nameValue != null && nameValue instanceof NullNode == false) {
                                            String nameInstance;
                                            nameInstance = nameValue.getTextValue();
                                            sloUsageMetricInstance.setName(nameInstance);
                                        }

                                        JsonNode typeValue = serviceLevelObjectiveUsageMetricsValue.get("type");
                                        if (typeValue != null && typeValue instanceof NullNode == false) {
                                            String typeInstance;
                                            typeInstance = typeValue.getTextValue();
                                            sloUsageMetricInstance.setType(typeInstance);
                                        }

                                        JsonNode locationValue = serviceLevelObjectiveUsageMetricsValue
                                                .get("location");
                                        if (locationValue != null
                                                && locationValue instanceof NullNode == false) {
                                            String locationInstance;
                                            locationInstance = locationValue.getTextValue();
                                            sloUsageMetricInstance.setLocation(locationInstance);
                                        }

                                        JsonNode tagsSequenceElement = ((JsonNode) serviceLevelObjectiveUsageMetricsValue
                                                .get("tags"));
                                        if (tagsSequenceElement != null
                                                && tagsSequenceElement instanceof NullNode == false) {
                                            Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement
                                                    .getFields();
                                            while (itr.hasNext()) {
                                                Map.Entry<String, JsonNode> property = itr.next();
                                                String tagsKey2 = property.getKey();
                                                String tagsValue2 = property.getValue().getTextValue();
                                                sloUsageMetricInstance.getTags().put(tagsKey2, tagsValue2);
                                            }
                                        }
                                    }
                                }

                                JsonNode currentServiceLevelObjectiveValue = propertiesValue3
                                        .get("currentServiceLevelObjective");
                                if (currentServiceLevelObjectiveValue != null
                                        && currentServiceLevelObjectiveValue instanceof NullNode == false) {
                                    String currentServiceLevelObjectiveInstance;
                                    currentServiceLevelObjectiveInstance = currentServiceLevelObjectiveValue
                                            .getTextValue();
                                    propertiesInstance2.setCurrentServiceLevelObjective(
                                            currentServiceLevelObjectiveInstance);
                                }

                                JsonNode currentServiceLevelObjectiveIdValue = propertiesValue3
                                        .get("currentServiceLevelObjectiveId");
                                if (currentServiceLevelObjectiveIdValue != null
                                        && currentServiceLevelObjectiveIdValue instanceof NullNode == false) {
                                    String currentServiceLevelObjectiveIdInstance;
                                    currentServiceLevelObjectiveIdInstance = currentServiceLevelObjectiveIdValue
                                            .getTextValue();
                                    propertiesInstance2.setCurrentServiceLevelObjectiveId(
                                            currentServiceLevelObjectiveIdInstance);
                                }

                                JsonNode usageBasedRecommendationServiceLevelObjectiveValue = propertiesValue3
                                        .get("usageBasedRecommendationServiceLevelObjective");
                                if (usageBasedRecommendationServiceLevelObjectiveValue != null
                                        && usageBasedRecommendationServiceLevelObjectiveValue instanceof NullNode == false) {
                                    String usageBasedRecommendationServiceLevelObjectiveInstance;
                                    usageBasedRecommendationServiceLevelObjectiveInstance = usageBasedRecommendationServiceLevelObjectiveValue
                                            .getTextValue();
                                    propertiesInstance2.setUsageBasedRecommendationServiceLevelObjective(
                                            usageBasedRecommendationServiceLevelObjectiveInstance);
                                }

                                JsonNode usageBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue3
                                        .get("usageBasedRecommendationServiceLevelObjectiveId");
                                if (usageBasedRecommendationServiceLevelObjectiveIdValue != null
                                        && usageBasedRecommendationServiceLevelObjectiveIdValue instanceof NullNode == false) {
                                    String usageBasedRecommendationServiceLevelObjectiveIdInstance;
                                    usageBasedRecommendationServiceLevelObjectiveIdInstance = usageBasedRecommendationServiceLevelObjectiveIdValue
                                            .getTextValue();
                                    propertiesInstance2.setUsageBasedRecommendationServiceLevelObjectiveId(
                                            usageBasedRecommendationServiceLevelObjectiveIdInstance);
                                }

                                JsonNode databaseSizeBasedRecommendationServiceLevelObjectiveValue = propertiesValue3
                                        .get("databaseSizeBasedRecommendationServiceLevelObjective");
                                if (databaseSizeBasedRecommendationServiceLevelObjectiveValue != null
                                        && databaseSizeBasedRecommendationServiceLevelObjectiveValue instanceof NullNode == false) {
                                    String databaseSizeBasedRecommendationServiceLevelObjectiveInstance;
                                    databaseSizeBasedRecommendationServiceLevelObjectiveInstance = databaseSizeBasedRecommendationServiceLevelObjectiveValue
                                            .getTextValue();
                                    propertiesInstance2.setDatabaseSizeBasedRecommendationServiceLevelObjective(
                                            databaseSizeBasedRecommendationServiceLevelObjectiveInstance);
                                }

                                JsonNode databaseSizeBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue3
                                        .get("databaseSizeBasedRecommendationServiceLevelObjectiveId");
                                if (databaseSizeBasedRecommendationServiceLevelObjectiveIdValue != null
                                        && databaseSizeBasedRecommendationServiceLevelObjectiveIdValue instanceof NullNode == false) {
                                    String databaseSizeBasedRecommendationServiceLevelObjectiveIdInstance;
                                    databaseSizeBasedRecommendationServiceLevelObjectiveIdInstance = databaseSizeBasedRecommendationServiceLevelObjectiveIdValue
                                            .getTextValue();
                                    propertiesInstance2
                                            .setDatabaseSizeBasedRecommendationServiceLevelObjectiveId(
                                                    databaseSizeBasedRecommendationServiceLevelObjectiveIdInstance);
                                }

                                JsonNode disasterPlanBasedRecommendationServiceLevelObjectiveValue = propertiesValue3
                                        .get("disasterPlanBasedRecommendationServiceLevelObjective");
                                if (disasterPlanBasedRecommendationServiceLevelObjectiveValue != null
                                        && disasterPlanBasedRecommendationServiceLevelObjectiveValue instanceof NullNode == false) {
                                    String disasterPlanBasedRecommendationServiceLevelObjectiveInstance;
                                    disasterPlanBasedRecommendationServiceLevelObjectiveInstance = disasterPlanBasedRecommendationServiceLevelObjectiveValue
                                            .getTextValue();
                                    propertiesInstance2.setDisasterPlanBasedRecommendationServiceLevelObjective(
                                            disasterPlanBasedRecommendationServiceLevelObjectiveInstance);
                                }

                                JsonNode disasterPlanBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue3
                                        .get("disasterPlanBasedRecommendationServiceLevelObjectiveId");
                                if (disasterPlanBasedRecommendationServiceLevelObjectiveIdValue != null
                                        && disasterPlanBasedRecommendationServiceLevelObjectiveIdValue instanceof NullNode == false) {
                                    String disasterPlanBasedRecommendationServiceLevelObjectiveIdInstance;
                                    disasterPlanBasedRecommendationServiceLevelObjectiveIdInstance = disasterPlanBasedRecommendationServiceLevelObjectiveIdValue
                                            .getTextValue();
                                    propertiesInstance2
                                            .setDisasterPlanBasedRecommendationServiceLevelObjectiveId(
                                                    disasterPlanBasedRecommendationServiceLevelObjectiveIdInstance);
                                }

                                JsonNode overallRecommendationServiceLevelObjectiveValue = propertiesValue3
                                        .get("overallRecommendationServiceLevelObjective");
                                if (overallRecommendationServiceLevelObjectiveValue != null
                                        && overallRecommendationServiceLevelObjectiveValue instanceof NullNode == false) {
                                    String overallRecommendationServiceLevelObjectiveInstance;
                                    overallRecommendationServiceLevelObjectiveInstance = overallRecommendationServiceLevelObjectiveValue
                                            .getTextValue();
                                    propertiesInstance2.setOverallRecommendationServiceLevelObjective(
                                            overallRecommendationServiceLevelObjectiveInstance);
                                }

                                JsonNode overallRecommendationServiceLevelObjectiveIdValue = propertiesValue3
                                        .get("overallRecommendationServiceLevelObjectiveId");
                                if (overallRecommendationServiceLevelObjectiveIdValue != null
                                        && overallRecommendationServiceLevelObjectiveIdValue instanceof NullNode == false) {
                                    String overallRecommendationServiceLevelObjectiveIdInstance;
                                    overallRecommendationServiceLevelObjectiveIdInstance = overallRecommendationServiceLevelObjectiveIdValue
                                            .getTextValue();
                                    propertiesInstance2.setOverallRecommendationServiceLevelObjectiveId(
                                            overallRecommendationServiceLevelObjectiveIdInstance);
                                }

                                JsonNode confidenceValue = propertiesValue3.get("confidence");
                                if (confidenceValue != null && confidenceValue instanceof NullNode == false) {
                                    double confidenceInstance;
                                    confidenceInstance = confidenceValue.getDoubleValue();
                                    propertiesInstance2.setConfidence(confidenceInstance);
                                }
                            }

                            JsonNode idValue2 = serviceTierAdvisorsValue.get("id");
                            if (idValue2 != null && idValue2 instanceof NullNode == false) {
                                String idInstance2;
                                idInstance2 = idValue2.getTextValue();
                                serviceTierAdvisorInstance.setId(idInstance2);
                            }

                            JsonNode nameValue2 = serviceTierAdvisorsValue.get("name");
                            if (nameValue2 != null && nameValue2 instanceof NullNode == false) {
                                String nameInstance2;
                                nameInstance2 = nameValue2.getTextValue();
                                serviceTierAdvisorInstance.setName(nameInstance2);
                            }

                            JsonNode typeValue2 = serviceTierAdvisorsValue.get("type");
                            if (typeValue2 != null && typeValue2 instanceof NullNode == false) {
                                String typeInstance2;
                                typeInstance2 = typeValue2.getTextValue();
                                serviceTierAdvisorInstance.setType(typeInstance2);
                            }

                            JsonNode locationValue2 = serviceTierAdvisorsValue.get("location");
                            if (locationValue2 != null && locationValue2 instanceof NullNode == false) {
                                String locationInstance2;
                                locationInstance2 = locationValue2.getTextValue();
                                serviceTierAdvisorInstance.setLocation(locationInstance2);
                            }

                            JsonNode tagsSequenceElement2 = ((JsonNode) serviceTierAdvisorsValue.get("tags"));
                            if (tagsSequenceElement2 != null
                                    && tagsSequenceElement2 instanceof NullNode == false) {
                                Iterator<Map.Entry<String, JsonNode>> itr2 = tagsSequenceElement2.getFields();
                                while (itr2.hasNext()) {
                                    Map.Entry<String, JsonNode> property2 = itr2.next();
                                    String tagsKey3 = property2.getKey();
                                    String tagsValue3 = property2.getValue().getTextValue();
                                    serviceTierAdvisorInstance.getTags().put(tagsKey3, tagsValue3);
                                }
                            }
                        }
                    }

                    JsonNode upgradeHintValue = propertiesValue2.get("upgradeHint");
                    if (upgradeHintValue != null && upgradeHintValue instanceof NullNode == false) {
                        UpgradeHint upgradeHintInstance = new UpgradeHint();
                        propertiesInstance.setUpgradeHint(upgradeHintInstance);

                        JsonNode targetServiceLevelObjectiveValue = upgradeHintValue
                                .get("targetServiceLevelObjective");
                        if (targetServiceLevelObjectiveValue != null
                                && targetServiceLevelObjectiveValue instanceof NullNode == false) {
                            String targetServiceLevelObjectiveInstance;
                            targetServiceLevelObjectiveInstance = targetServiceLevelObjectiveValue
                                    .getTextValue();
                            upgradeHintInstance
                                    .setTargetServiceLevelObjective(targetServiceLevelObjectiveInstance);
                        }

                        JsonNode targetServiceLevelObjectiveIdValue = upgradeHintValue
                                .get("targetServiceLevelObjectiveId");
                        if (targetServiceLevelObjectiveIdValue != null
                                && targetServiceLevelObjectiveIdValue instanceof NullNode == false) {
                            String targetServiceLevelObjectiveIdInstance;
                            targetServiceLevelObjectiveIdInstance = targetServiceLevelObjectiveIdValue
                                    .getTextValue();
                            upgradeHintInstance
                                    .setTargetServiceLevelObjectiveId(targetServiceLevelObjectiveIdInstance);
                        }

                        JsonNode idValue3 = upgradeHintValue.get("id");
                        if (idValue3 != null && idValue3 instanceof NullNode == false) {
                            String idInstance3;
                            idInstance3 = idValue3.getTextValue();
                            upgradeHintInstance.setId(idInstance3);
                        }

                        JsonNode nameValue3 = upgradeHintValue.get("name");
                        if (nameValue3 != null && nameValue3 instanceof NullNode == false) {
                            String nameInstance3;
                            nameInstance3 = nameValue3.getTextValue();
                            upgradeHintInstance.setName(nameInstance3);
                        }

                        JsonNode typeValue3 = upgradeHintValue.get("type");
                        if (typeValue3 != null && typeValue3 instanceof NullNode == false) {
                            String typeInstance3;
                            typeInstance3 = typeValue3.getTextValue();
                            upgradeHintInstance.setType(typeInstance3);
                        }

                        JsonNode locationValue3 = upgradeHintValue.get("location");
                        if (locationValue3 != null && locationValue3 instanceof NullNode == false) {
                            String locationInstance3;
                            locationInstance3 = locationValue3.getTextValue();
                            upgradeHintInstance.setLocation(locationInstance3);
                        }

                        JsonNode tagsSequenceElement3 = ((JsonNode) upgradeHintValue.get("tags"));
                        if (tagsSequenceElement3 != null && tagsSequenceElement3 instanceof NullNode == false) {
                            Iterator<Map.Entry<String, JsonNode>> itr3 = tagsSequenceElement3.getFields();
                            while (itr3.hasNext()) {
                                Map.Entry<String, JsonNode> property3 = itr3.next();
                                String tagsKey4 = property3.getKey();
                                String tagsValue4 = property3.getValue().getTextValue();
                                upgradeHintInstance.getTags().put(tagsKey4, tagsValue4);
                            }
                        }
                    }

                    JsonNode schemasArray = propertiesValue2.get("schemas");
                    if (schemasArray != null && schemasArray instanceof NullNode == false) {
                        for (JsonNode schemasValue : ((ArrayNode) schemasArray)) {
                            Schema schemaInstance = new Schema();
                            propertiesInstance.getSchemas().add(schemaInstance);

                            JsonNode propertiesValue4 = schemasValue.get("properties");
                            if (propertiesValue4 != null && propertiesValue4 instanceof NullNode == false) {
                                SchemaProperties propertiesInstance3 = new SchemaProperties();
                                schemaInstance.setProperties(propertiesInstance3);

                                JsonNode tablesArray = propertiesValue4.get("tables");
                                if (tablesArray != null && tablesArray instanceof NullNode == false) {
                                    for (JsonNode tablesValue : ((ArrayNode) tablesArray)) {
                                        Table tableInstance = new Table();
                                        propertiesInstance3.getTables().add(tableInstance);

                                        JsonNode propertiesValue5 = tablesValue.get("properties");
                                        if (propertiesValue5 != null
                                                && propertiesValue5 instanceof NullNode == false) {
                                            TableProperties propertiesInstance4 = new TableProperties();
                                            tableInstance.setProperties(propertiesInstance4);

                                            JsonNode tableTypeValue = propertiesValue5.get("tableType");
                                            if (tableTypeValue != null
                                                    && tableTypeValue instanceof NullNode == false) {
                                                String tableTypeInstance;
                                                tableTypeInstance = tableTypeValue.getTextValue();
                                                propertiesInstance4.setTableType(tableTypeInstance);
                                            }

                                            JsonNode columnsArray = propertiesValue5.get("columns");
                                            if (columnsArray != null
                                                    && columnsArray instanceof NullNode == false) {
                                                for (JsonNode columnsValue : ((ArrayNode) columnsArray)) {
                                                    Column columnInstance = new Column();
                                                    propertiesInstance4.getColumns().add(columnInstance);

                                                    JsonNode propertiesValue6 = columnsValue.get("properties");
                                                    if (propertiesValue6 != null
                                                            && propertiesValue6 instanceof NullNode == false) {
                                                        ColumnProperties propertiesInstance5 = new ColumnProperties();
                                                        columnInstance.setProperties(propertiesInstance5);

                                                        JsonNode columnTypeValue = propertiesValue6
                                                                .get("columnType");
                                                        if (columnTypeValue != null
                                                                && columnTypeValue instanceof NullNode == false) {
                                                            String columnTypeInstance;
                                                            columnTypeInstance = columnTypeValue.getTextValue();
                                                            propertiesInstance5
                                                                    .setColumnType(columnTypeInstance);
                                                        }
                                                    }

                                                    JsonNode idValue4 = columnsValue.get("id");
                                                    if (idValue4 != null
                                                            && idValue4 instanceof NullNode == false) {
                                                        String idInstance4;
                                                        idInstance4 = idValue4.getTextValue();
                                                        columnInstance.setId(idInstance4);
                                                    }

                                                    JsonNode nameValue4 = columnsValue.get("name");
                                                    if (nameValue4 != null
                                                            && nameValue4 instanceof NullNode == false) {
                                                        String nameInstance4;
                                                        nameInstance4 = nameValue4.getTextValue();
                                                        columnInstance.setName(nameInstance4);
                                                    }

                                                    JsonNode typeValue4 = columnsValue.get("type");
                                                    if (typeValue4 != null
                                                            && typeValue4 instanceof NullNode == false) {
                                                        String typeInstance4;
                                                        typeInstance4 = typeValue4.getTextValue();
                                                        columnInstance.setType(typeInstance4);
                                                    }

                                                    JsonNode locationValue4 = columnsValue.get("location");
                                                    if (locationValue4 != null
                                                            && locationValue4 instanceof NullNode == false) {
                                                        String locationInstance4;
                                                        locationInstance4 = locationValue4.getTextValue();
                                                        columnInstance.setLocation(locationInstance4);
                                                    }

                                                    JsonNode tagsSequenceElement4 = ((JsonNode) columnsValue
                                                            .get("tags"));
                                                    if (tagsSequenceElement4 != null
                                                            && tagsSequenceElement4 instanceof NullNode == false) {
                                                        Iterator<Map.Entry<String, JsonNode>> itr4 = tagsSequenceElement4
                                                                .getFields();
                                                        while (itr4.hasNext()) {
                                                            Map.Entry<String, JsonNode> property4 = itr4.next();
                                                            String tagsKey5 = property4.getKey();
                                                            String tagsValue5 = property4.getValue()
                                                                    .getTextValue();
                                                            columnInstance.getTags().put(tagsKey5, tagsValue5);
                                                        }
                                                    }
                                                }
                                            }

                                            JsonNode recommendedIndexesArray = propertiesValue5
                                                    .get("recommendedIndexes");
                                            if (recommendedIndexesArray != null
                                                    && recommendedIndexesArray instanceof NullNode == false) {
                                                for (JsonNode recommendedIndexesValue : ((ArrayNode) recommendedIndexesArray)) {
                                                    RecommendedIndex recommendedIndexInstance = new RecommendedIndex();
                                                    propertiesInstance4.getRecommendedIndexes()
                                                            .add(recommendedIndexInstance);

                                                    JsonNode propertiesValue7 = recommendedIndexesValue
                                                            .get("properties");
                                                    if (propertiesValue7 != null
                                                            && propertiesValue7 instanceof NullNode == false) {
                                                        RecommendedIndexProperties propertiesInstance6 = new RecommendedIndexProperties();
                                                        recommendedIndexInstance
                                                                .setProperties(propertiesInstance6);

                                                        JsonNode actionValue = propertiesValue7.get("action");
                                                        if (actionValue != null
                                                                && actionValue instanceof NullNode == false) {
                                                            String actionInstance;
                                                            actionInstance = actionValue.getTextValue();
                                                            propertiesInstance6.setAction(actionInstance);
                                                        }

                                                        JsonNode stateValue = propertiesValue7.get("state");
                                                        if (stateValue != null
                                                                && stateValue instanceof NullNode == false) {
                                                            String stateInstance;
                                                            stateInstance = stateValue.getTextValue();
                                                            propertiesInstance6.setState(stateInstance);
                                                        }

                                                        JsonNode createdValue = propertiesValue7.get("created");
                                                        if (createdValue != null
                                                                && createdValue instanceof NullNode == false) {
                                                            Calendar createdInstance;
                                                            createdInstance = DatatypeConverter
                                                                    .parseDateTime(createdValue.getTextValue());
                                                            propertiesInstance6.setCreated(createdInstance);
                                                        }

                                                        JsonNode lastModifiedValue = propertiesValue7
                                                                .get("lastModified");
                                                        if (lastModifiedValue != null
                                                                && lastModifiedValue instanceof NullNode == false) {
                                                            Calendar lastModifiedInstance;
                                                            lastModifiedInstance = DatatypeConverter
                                                                    .parseDateTime(
                                                                            lastModifiedValue.getTextValue());
                                                            propertiesInstance6
                                                                    .setLastModified(lastModifiedInstance);
                                                        }

                                                        JsonNode indexTypeValue = propertiesValue7
                                                                .get("indexType");
                                                        if (indexTypeValue != null
                                                                && indexTypeValue instanceof NullNode == false) {
                                                            String indexTypeInstance;
                                                            indexTypeInstance = indexTypeValue.getTextValue();
                                                            propertiesInstance6.setIndexType(indexTypeInstance);
                                                        }

                                                        JsonNode schemaValue = propertiesValue7.get("schema");
                                                        if (schemaValue != null
                                                                && schemaValue instanceof NullNode == false) {
                                                            String schemaInstance2;
                                                            schemaInstance2 = schemaValue.getTextValue();
                                                            propertiesInstance6.setSchema(schemaInstance2);
                                                        }

                                                        JsonNode tableValue = propertiesValue7.get("table");
                                                        if (tableValue != null
                                                                && tableValue instanceof NullNode == false) {
                                                            String tableInstance2;
                                                            tableInstance2 = tableValue.getTextValue();
                                                            propertiesInstance6.setTable(tableInstance2);
                                                        }

                                                        JsonNode columnsArray2 = propertiesValue7
                                                                .get("columns");
                                                        if (columnsArray2 != null
                                                                && columnsArray2 instanceof NullNode == false) {
                                                            for (JsonNode columnsValue2 : ((ArrayNode) columnsArray2)) {
                                                                propertiesInstance6.getColumns()
                                                                        .add(columnsValue2.getTextValue());
                                                            }
                                                        }

                                                        JsonNode includedColumnsArray = propertiesValue7
                                                                .get("includedColumns");
                                                        if (includedColumnsArray != null
                                                                && includedColumnsArray instanceof NullNode == false) {
                                                            for (JsonNode includedColumnsValue : ((ArrayNode) includedColumnsArray)) {
                                                                propertiesInstance6.getIncludedColumns().add(
                                                                        includedColumnsValue.getTextValue());
                                                            }
                                                        }

                                                        JsonNode indexScriptValue = propertiesValue7
                                                                .get("indexScript");
                                                        if (indexScriptValue != null
                                                                && indexScriptValue instanceof NullNode == false) {
                                                            String indexScriptInstance;
                                                            indexScriptInstance = indexScriptValue
                                                                    .getTextValue();
                                                            propertiesInstance6
                                                                    .setIndexScript(indexScriptInstance);
                                                        }

                                                        JsonNode estimatedImpactArray = propertiesValue7
                                                                .get("estimatedImpact");
                                                        if (estimatedImpactArray != null
                                                                && estimatedImpactArray instanceof NullNode == false) {
                                                            for (JsonNode estimatedImpactValue : ((ArrayNode) estimatedImpactArray)) {
                                                                OperationImpact operationImpactInstance = new OperationImpact();
                                                                propertiesInstance6.getEstimatedImpact()
                                                                        .add(operationImpactInstance);

                                                                JsonNode nameValue5 = estimatedImpactValue
                                                                        .get("name");
                                                                if (nameValue5 != null
                                                                        && nameValue5 instanceof NullNode == false) {
                                                                    String nameInstance5;
                                                                    nameInstance5 = nameValue5.getTextValue();
                                                                    operationImpactInstance
                                                                            .setName(nameInstance5);
                                                                }

                                                                JsonNode unitValue = estimatedImpactValue
                                                                        .get("unit");
                                                                if (unitValue != null
                                                                        && unitValue instanceof NullNode == false) {
                                                                    String unitInstance;
                                                                    unitInstance = unitValue.getTextValue();
                                                                    operationImpactInstance
                                                                            .setUnit(unitInstance);
                                                                }

                                                                JsonNode changeValueAbsoluteValue = estimatedImpactValue
                                                                        .get("changeValueAbsolute");
                                                                if (changeValueAbsoluteValue != null
                                                                        && changeValueAbsoluteValue instanceof NullNode == false) {
                                                                    double changeValueAbsoluteInstance;
                                                                    changeValueAbsoluteInstance = changeValueAbsoluteValue
                                                                            .getDoubleValue();
                                                                    operationImpactInstance
                                                                            .setChangeValueAbsolute(
                                                                                    changeValueAbsoluteInstance);
                                                                }

                                                                JsonNode changeValueRelativeValue = estimatedImpactValue
                                                                        .get("changeValueRelative");
                                                                if (changeValueRelativeValue != null
                                                                        && changeValueRelativeValue instanceof NullNode == false) {
                                                                    double changeValueRelativeInstance;
                                                                    changeValueRelativeInstance = changeValueRelativeValue
                                                                            .getDoubleValue();
                                                                    operationImpactInstance
                                                                            .setChangeValueRelative(
                                                                                    changeValueRelativeInstance);
                                                                }
                                                            }
                                                        }

                                                        JsonNode reportedImpactArray = propertiesValue7
                                                                .get("reportedImpact");
                                                        if (reportedImpactArray != null
                                                                && reportedImpactArray instanceof NullNode == false) {
                                                            for (JsonNode reportedImpactValue : ((ArrayNode) reportedImpactArray)) {
                                                                OperationImpact operationImpactInstance2 = new OperationImpact();
                                                                propertiesInstance6.getReportedImpact()
                                                                        .add(operationImpactInstance2);

                                                                JsonNode nameValue6 = reportedImpactValue
                                                                        .get("name");
                                                                if (nameValue6 != null
                                                                        && nameValue6 instanceof NullNode == false) {
                                                                    String nameInstance6;
                                                                    nameInstance6 = nameValue6.getTextValue();
                                                                    operationImpactInstance2
                                                                            .setName(nameInstance6);
                                                                }

                                                                JsonNode unitValue2 = reportedImpactValue
                                                                        .get("unit");
                                                                if (unitValue2 != null
                                                                        && unitValue2 instanceof NullNode == false) {
                                                                    String unitInstance2;
                                                                    unitInstance2 = unitValue2.getTextValue();
                                                                    operationImpactInstance2
                                                                            .setUnit(unitInstance2);
                                                                }

                                                                JsonNode changeValueAbsoluteValue2 = reportedImpactValue
                                                                        .get("changeValueAbsolute");
                                                                if (changeValueAbsoluteValue2 != null
                                                                        && changeValueAbsoluteValue2 instanceof NullNode == false) {
                                                                    double changeValueAbsoluteInstance2;
                                                                    changeValueAbsoluteInstance2 = changeValueAbsoluteValue2
                                                                            .getDoubleValue();
                                                                    operationImpactInstance2
                                                                            .setChangeValueAbsolute(
                                                                                    changeValueAbsoluteInstance2);
                                                                }

                                                                JsonNode changeValueRelativeValue2 = reportedImpactValue
                                                                        .get("changeValueRelative");
                                                                if (changeValueRelativeValue2 != null
                                                                        && changeValueRelativeValue2 instanceof NullNode == false) {
                                                                    double changeValueRelativeInstance2;
                                                                    changeValueRelativeInstance2 = changeValueRelativeValue2
                                                                            .getDoubleValue();
                                                                    operationImpactInstance2
                                                                            .setChangeValueRelative(
                                                                                    changeValueRelativeInstance2);
                                                                }
                                                            }
                                                        }
                                                    }

                                                    JsonNode idValue5 = recommendedIndexesValue.get("id");
                                                    if (idValue5 != null
                                                            && idValue5 instanceof NullNode == false) {
                                                        String idInstance5;
                                                        idInstance5 = idValue5.getTextValue();
                                                        recommendedIndexInstance.setId(idInstance5);
                                                    }

                                                    JsonNode nameValue7 = recommendedIndexesValue.get("name");
                                                    if (nameValue7 != null
                                                            && nameValue7 instanceof NullNode == false) {
                                                        String nameInstance7;
                                                        nameInstance7 = nameValue7.getTextValue();
                                                        recommendedIndexInstance.setName(nameInstance7);
                                                    }

                                                    JsonNode typeValue5 = recommendedIndexesValue.get("type");
                                                    if (typeValue5 != null
                                                            && typeValue5 instanceof NullNode == false) {
                                                        String typeInstance5;
                                                        typeInstance5 = typeValue5.getTextValue();
                                                        recommendedIndexInstance.setType(typeInstance5);
                                                    }

                                                    JsonNode locationValue5 = recommendedIndexesValue
                                                            .get("location");
                                                    if (locationValue5 != null
                                                            && locationValue5 instanceof NullNode == false) {
                                                        String locationInstance5;
                                                        locationInstance5 = locationValue5.getTextValue();
                                                        recommendedIndexInstance.setLocation(locationInstance5);
                                                    }

                                                    JsonNode tagsSequenceElement5 = ((JsonNode) recommendedIndexesValue
                                                            .get("tags"));
                                                    if (tagsSequenceElement5 != null
                                                            && tagsSequenceElement5 instanceof NullNode == false) {
                                                        Iterator<Map.Entry<String, JsonNode>> itr5 = tagsSequenceElement5
                                                                .getFields();
                                                        while (itr5.hasNext()) {
                                                            Map.Entry<String, JsonNode> property5 = itr5.next();
                                                            String tagsKey6 = property5.getKey();
                                                            String tagsValue6 = property5.getValue()
                                                                    .getTextValue();
                                                            recommendedIndexInstance.getTags().put(tagsKey6,
                                                                    tagsValue6);
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        JsonNode idValue6 = tablesValue.get("id");
                                        if (idValue6 != null && idValue6 instanceof NullNode == false) {
                                            String idInstance6;
                                            idInstance6 = idValue6.getTextValue();
                                            tableInstance.setId(idInstance6);
                                        }

                                        JsonNode nameValue8 = tablesValue.get("name");
                                        if (nameValue8 != null && nameValue8 instanceof NullNode == false) {
                                            String nameInstance8;
                                            nameInstance8 = nameValue8.getTextValue();
                                            tableInstance.setName(nameInstance8);
                                        }

                                        JsonNode typeValue6 = tablesValue.get("type");
                                        if (typeValue6 != null && typeValue6 instanceof NullNode == false) {
                                            String typeInstance6;
                                            typeInstance6 = typeValue6.getTextValue();
                                            tableInstance.setType(typeInstance6);
                                        }

                                        JsonNode locationValue6 = tablesValue.get("location");
                                        if (locationValue6 != null
                                                && locationValue6 instanceof NullNode == false) {
                                            String locationInstance6;
                                            locationInstance6 = locationValue6.getTextValue();
                                            tableInstance.setLocation(locationInstance6);
                                        }

                                        JsonNode tagsSequenceElement6 = ((JsonNode) tablesValue.get("tags"));
                                        if (tagsSequenceElement6 != null
                                                && tagsSequenceElement6 instanceof NullNode == false) {
                                            Iterator<Map.Entry<String, JsonNode>> itr6 = tagsSequenceElement6
                                                    .getFields();
                                            while (itr6.hasNext()) {
                                                Map.Entry<String, JsonNode> property6 = itr6.next();
                                                String tagsKey7 = property6.getKey();
                                                String tagsValue7 = property6.getValue().getTextValue();
                                                tableInstance.getTags().put(tagsKey7, tagsValue7);
                                            }
                                        }
                                    }
                                }
                            }

                            JsonNode idValue7 = schemasValue.get("id");
                            if (idValue7 != null && idValue7 instanceof NullNode == false) {
                                String idInstance7;
                                idInstance7 = idValue7.getTextValue();
                                schemaInstance.setId(idInstance7);
                            }

                            JsonNode nameValue9 = schemasValue.get("name");
                            if (nameValue9 != null && nameValue9 instanceof NullNode == false) {
                                String nameInstance9;
                                nameInstance9 = nameValue9.getTextValue();
                                schemaInstance.setName(nameInstance9);
                            }

                            JsonNode typeValue7 = schemasValue.get("type");
                            if (typeValue7 != null && typeValue7 instanceof NullNode == false) {
                                String typeInstance7;
                                typeInstance7 = typeValue7.getTextValue();
                                schemaInstance.setType(typeInstance7);
                            }

                            JsonNode locationValue7 = schemasValue.get("location");
                            if (locationValue7 != null && locationValue7 instanceof NullNode == false) {
                                String locationInstance7;
                                locationInstance7 = locationValue7.getTextValue();
                                schemaInstance.setLocation(locationInstance7);
                            }

                            JsonNode tagsSequenceElement7 = ((JsonNode) schemasValue.get("tags"));
                            if (tagsSequenceElement7 != null
                                    && tagsSequenceElement7 instanceof NullNode == false) {
                                Iterator<Map.Entry<String, JsonNode>> itr7 = tagsSequenceElement7.getFields();
                                while (itr7.hasNext()) {
                                    Map.Entry<String, JsonNode> property7 = itr7.next();
                                    String tagsKey8 = property7.getKey();
                                    String tagsValue8 = property7.getValue().getTextValue();
                                    schemaInstance.getTags().put(tagsKey8, tagsValue8);
                                }
                            }
                        }
                    }

                    JsonNode defaultSecondaryLocationValue = propertiesValue2.get("defaultSecondaryLocation");
                    if (defaultSecondaryLocationValue != null
                            && defaultSecondaryLocationValue instanceof NullNode == false) {
                        String defaultSecondaryLocationInstance;
                        defaultSecondaryLocationInstance = defaultSecondaryLocationValue.getTextValue();
                        propertiesInstance.setDefaultSecondaryLocation(defaultSecondaryLocationInstance);
                    }
                }

                JsonNode idValue8 = responseDoc.get("id");
                if (idValue8 != null && idValue8 instanceof NullNode == false) {
                    String idInstance8;
                    idInstance8 = idValue8.getTextValue();
                    databaseInstance.setId(idInstance8);
                }

                JsonNode nameValue10 = responseDoc.get("name");
                if (nameValue10 != null && nameValue10 instanceof NullNode == false) {
                    String nameInstance10;
                    nameInstance10 = nameValue10.getTextValue();
                    databaseInstance.setName(nameInstance10);
                }

                JsonNode typeValue8 = responseDoc.get("type");
                if (typeValue8 != null && typeValue8 instanceof NullNode == false) {
                    String typeInstance8;
                    typeInstance8 = typeValue8.getTextValue();
                    databaseInstance.setType(typeInstance8);
                }

                JsonNode locationValue8 = responseDoc.get("location");
                if (locationValue8 != null && locationValue8 instanceof NullNode == false) {
                    String locationInstance8;
                    locationInstance8 = locationValue8.getTextValue();
                    databaseInstance.setLocation(locationInstance8);
                }

                JsonNode tagsSequenceElement8 = ((JsonNode) responseDoc.get("tags"));
                if (tagsSequenceElement8 != null && tagsSequenceElement8 instanceof NullNode == false) {
                    Iterator<Map.Entry<String, JsonNode>> itr8 = tagsSequenceElement8.getFields();
                    while (itr8.hasNext()) {
                        Map.Entry<String, JsonNode> property8 = itr8.next();
                        String tagsKey9 = property8.getKey();
                        String tagsValue9 = property8.getValue().getTextValue();
                        databaseInstance.getTags().put(tagsKey9, tagsValue9);
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("Location").length > 0) {
            result.setOperationStatusLink(httpResponse.getFirstHeader("Location").getValue());
        }
        if (httpResponse.getHeaders("Retry-After").length > 0) {
            result.setRetryAfter(
                    DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue()));
        }
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }
        if (statusCode == HttpStatus.SC_OK) {
            result.setStatus(OperationStatus.Succeeded);
        }
        if (statusCode == HttpStatus.SC_CREATED) {
            result.setStatus(OperationStatus.Succeeded);
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}