All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationParser Maven / Gradle / Ivy

Go to download

Implementation of the Cloud platform abstraction for general-purpose connectivity on the SAP Cloud Platform (Cloud Foundry).

The newest version!
/*
 * Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
 */

package com.sap.cloud.sdk.cloudplatform.connectivity;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Nullable;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException;

import lombok.AccessLevel;
import lombok.Getter;

class ScpCfDestinationParser extends AbstractDestinationParser
{
    private static final String PROPERTY_CLOUD_CONNECTOR_LOCATION_ID = "CloudConnectorLocationId";

    @Getter( AccessLevel.PACKAGE )
    private final JsonObject destinationAsJson;

    ScpCfDestinationParser( final JsonObject destinationAsJson )
    {
        this.destinationAsJson = destinationAsJson;
    }

    @Nullable
    String getCloudConnectorLocationId()
    {
        return getPropertyIfExists(PROPERTY_CLOUD_CONNECTOR_LOCATION_ID);
    }

    @Override
    Map getProperties()
        throws DestinationAccessException
    {
        final Map properties = new HashMap<>();

        for( final Map.Entry entry : destinationAsJson.entrySet() ) {
            final String key = entry.getKey();
            final JsonElement value = entry.getValue();

            if( value != null && value.isJsonPrimitive() ) {
                properties.put(key, value.getAsString());
            } else {
                throw new DestinationAccessException(
                    "No valid JSON primitive defined for destination property '" + key + "'.");
            }
        }

        return properties;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy