Skip to main content
added 149 characters in body; edited tags; edited title
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

Get valuesapplication credentials from linked array obtained from Cloud Foundry API

I am new to Java and I use the following code to retrieve parameters from a linked hash map from the Cloud Foundry API. My question is if there is a better way to do it in Java?

The following code is working

public HashMap<String, String> getUserData(String Url, String org, String space, String app) throws MalformedURLException { 
        URL endpoint = new URL(Url);
        CloudFoundryOperations ops = sm.getCurrentUserCfClient(endpoint, org, space);

        GetApplicationEnvironmentsRequest request = GetApplicationEnvironmentsRequest.builder()
                .name(app)
                .build();

        ApplicationEnvironments environments = ops.applications()
                .getEnvironments(request)
                .block();

Map<String, Object> mapSystemProvided =  environments.getSystemProvided();

    LinkedHashMap<String, Object> SERVICES = (LinkedHashMap<String, Object>) mapSystemProvided.get("SERVICES");
    ArrayList<Object> apps = (ArrayList<Object>) SERVICES.get("apps");
    LinkedHashMap<String, Object> appsList = (LinkedHashMap<String, Object>) apps.get(0);
    LinkedHashMap<String, Object> credentials = (LinkedHashMap<String, Object>) appsList.get("credentials");
    
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put(ID, credentials.get(ID).toString());
    parameters.put(DEFAULTS, credentials.get(DEFAULTST).toString());
    
    return parameters; 

Get values from linked array

I am new to Java and I use the following code to retrieve parameters from a linked hash map. My question is if there is a better way to do it in Java?

The following code is working

public HashMap<String, String> getUserData(String Url, String org, String space, String app) throws MalformedURLException { 
        URL endpoint = new URL(Url);
        CloudFoundryOperations ops = sm.getCurrentUserCfClient(endpoint, org, space);

        GetApplicationEnvironmentsRequest request = GetApplicationEnvironmentsRequest.builder()
                .name(app)
                .build();

        ApplicationEnvironments environments = ops.applications()
                .getEnvironments(request)
                .block();

Map<String, Object> mapSystemProvided =  environments.getSystemProvided();

    LinkedHashMap<String, Object> SERVICES = (LinkedHashMap<String, Object>) mapSystemProvided.get("SERVICES");
    ArrayList<Object> apps = (ArrayList<Object>) SERVICES.get("apps");
    LinkedHashMap<String, Object> appsList = (LinkedHashMap<String, Object>) apps.get(0);
    LinkedHashMap<String, Object> credentials = (LinkedHashMap<String, Object>) appsList.get("credentials");
    
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put(ID, credentials.get(ID).toString());
    parameters.put(DEFAULTS, credentials.get(DEFAULTST).toString());
    
    return parameters; 

Get application credentials from linked array obtained from Cloud Foundry API

I am new to Java and I use the following code to retrieve parameters from a linked hash map from the Cloud Foundry API. My question is if there is a better way to do it in Java?

public HashMap<String, String> getUserData(String Url, String org, String space, String app) throws MalformedURLException { 
        URL endpoint = new URL(Url);
        CloudFoundryOperations ops = sm.getCurrentUserCfClient(endpoint, org, space);

        GetApplicationEnvironmentsRequest request = GetApplicationEnvironmentsRequest.builder()
                .name(app)
                .build();

        ApplicationEnvironments environments = ops.applications()
                .getEnvironments(request)
                .block();

Map<String, Object> mapSystemProvided =  environments.getSystemProvided();

    LinkedHashMap<String, Object> SERVICES = (LinkedHashMap<String, Object>) mapSystemProvided.get("SERVICES");
    ArrayList<Object> apps = (ArrayList<Object>) SERVICES.get("apps");
    LinkedHashMap<String, Object> appsList = (LinkedHashMap<String, Object>) apps.get(0);
    LinkedHashMap<String, Object> credentials = (LinkedHashMap<String, Object>) appsList.get("credentials");
    
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put(ID, credentials.get(ID).toString());
    parameters.put(DEFAULTS, credentials.get(DEFAULTST).toString());
    
    return parameters; 
added 76 characters in body
Source Link
Rayn D
  • 227
  • 3
  • 8

I am new to Java and I use the following code to retrieve parameters from a linked hash map. My question is if there is a better way to do it in Java?

The following code is working

public HashMap<String, String> getUserData(String Url, String org, String space, String app) throws MalformedURLException { 
        URL endpoint = new URL(Url);
        CloudFoundryOperations ops = sm.getCurrentUserCfClient(endpoint, org, space);

        GetApplicationEnvironmentsRequest request = GetApplicationEnvironmentsRequest.builder()
                .name(app)
                .build();

        ApplicationEnvironments environments = ops.applications()
                .getEnvironments(request)
                .block();

Map<String, Object> mapSystemProvided =  environments.getSystemProvided();

    LinkedHashMap<String, Object> SERVICES = (LinkedHashMap<String, Object>) mapSystemProvided.get("SERVICES");
    ArrayList<Object> apps = (ArrayList<Object>) SERVICES.get("apps");
    LinkedHashMap<String, Object> appsList = (LinkedHashMap<String, Object>) apps.get(0);
    LinkedHashMap<String, Object> credentials = (LinkedHashMap<String, Object>) appsList.get("credentials");
    
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put(ID, credentials.get(ID).toString());
    parameters.put(DEFAULTS, credentials.get(DEFAULTST).toString());
    
    return parameters; 

I am new to Java and I use the following code to retrieve parameters from a linked hash map. My question is if there is a better way to do it in Java?

The following code is working

public HashMap<String, String> getUserData(String Url, String org, String space, String app) throws MalformedURLException { 
        URL endpoint = new URL(Url);
        CloudFoundryOperations ops = sm.getCurrentUserCfClient(endpoint, org, space);

        GetApplicationEnvironmentsRequest request = GetApplicationEnvironmentsRequest.builder()
                .name(app)
                .build();

        ApplicationEnvironments environments = ops.applications()
                .getEnvironments(request)
                .block();


    LinkedHashMap<String, Object> SERVICES = (LinkedHashMap<String, Object>) mapSystemProvided.get("SERVICES");
    ArrayList<Object> apps = (ArrayList<Object>) SERVICES.get("apps");
    LinkedHashMap<String, Object> appsList = (LinkedHashMap<String, Object>) apps.get(0);
    LinkedHashMap<String, Object> credentials = (LinkedHashMap<String, Object>) appsList.get("credentials");
    
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put(ID, credentials.get(ID).toString());
    parameters.put(DEFAULTS, credentials.get(DEFAULTST).toString());
    
    return parameters; 

I am new to Java and I use the following code to retrieve parameters from a linked hash map. My question is if there is a better way to do it in Java?

The following code is working

public HashMap<String, String> getUserData(String Url, String org, String space, String app) throws MalformedURLException { 
        URL endpoint = new URL(Url);
        CloudFoundryOperations ops = sm.getCurrentUserCfClient(endpoint, org, space);

        GetApplicationEnvironmentsRequest request = GetApplicationEnvironmentsRequest.builder()
                .name(app)
                .build();

        ApplicationEnvironments environments = ops.applications()
                .getEnvironments(request)
                .block();

Map<String, Object> mapSystemProvided =  environments.getSystemProvided();

    LinkedHashMap<String, Object> SERVICES = (LinkedHashMap<String, Object>) mapSystemProvided.get("SERVICES");
    ArrayList<Object> apps = (ArrayList<Object>) SERVICES.get("apps");
    LinkedHashMap<String, Object> appsList = (LinkedHashMap<String, Object>) apps.get(0);
    LinkedHashMap<String, Object> credentials = (LinkedHashMap<String, Object>) appsList.get("credentials");
    
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put(ID, credentials.get(ID).toString());
    parameters.put(DEFAULTS, credentials.get(DEFAULTST).toString());
    
    return parameters; 
added 555 characters in body
Source Link
Rayn D
  • 227
  • 3
  • 8

I am new to Java and I use the following code to retrieve parameters from a linked hash map. My question is if there is a better way to do it in Java?

The following code is working

Map<Stringpublic HashMap<String, Object>String> mapSystemProvidedgetUserData(String Url, String org, String space, String app) throws MalformedURLException { 
        URL endpoint = new URL(Url);
        CloudFoundryOperations ops = sm.getCurrentUserCfClient(endpoint, org, space);

        GetApplicationEnvironmentsRequest request = GetApplicationEnvironmentsRequest.builder()
                .name(app)
                .build();

        ApplicationEnvironments environments = ops.getSystemProvidedapplications()
                .getEnvironments(request)
                .block(); 


    LinkedHashMap<String, Object> SERVICES = (LinkedHashMap<String, Object>) mapSystemProvided.get("SERVICES");
    ArrayList<Object> apps = (ArrayList<Object>) SERVICES.get("apps");
    LinkedHashMap<String, Object> appsList = (LinkedHashMap<String, Object>) apps.get(0);
    LinkedHashMap<String, Object> credentials = (LinkedHashMap<String, Object>) appsList.get("credentials");
    
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put(ID, credentials.get(ID).toString());
    parameters.put(DEFAULTS, credentials.get(DEFAULTST).toString());
    
    return parameters; 

I am new to Java and I use the following code to retrieve parameters from a linked hash map. My question is if there is a better way to do it in Java?

The following code is working

Map<String, Object> mapSystemProvided =  environments.getSystemProvided();

LinkedHashMap<String, Object> SERVICES = (LinkedHashMap<String, Object>) mapSystemProvided.get("SERVICES");
ArrayList<Object> apps = (ArrayList<Object>) SERVICES.get("apps");
LinkedHashMap<String, Object> appsList = (LinkedHashMap<String, Object>) apps.get(0);
LinkedHashMap<String, Object> credentials = (LinkedHashMap<String, Object>) appsList.get("credentials");

HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put(ID, credentials.get(ID).toString());
parameters.put(DEFAULTS, credentials.get(DEFAULTST).toString());

return parameters; 

I am new to Java and I use the following code to retrieve parameters from a linked hash map. My question is if there is a better way to do it in Java?

The following code is working

public HashMap<String, String> getUserData(String Url, String org, String space, String app) throws MalformedURLException { 
        URL endpoint = new URL(Url);
        CloudFoundryOperations ops = sm.getCurrentUserCfClient(endpoint, org, space);

        GetApplicationEnvironmentsRequest request = GetApplicationEnvironmentsRequest.builder()
                .name(app)
                .build();

        ApplicationEnvironments environments = ops.applications()
                .getEnvironments(request)
                .block(); 


    LinkedHashMap<String, Object> SERVICES = (LinkedHashMap<String, Object>) mapSystemProvided.get("SERVICES");
    ArrayList<Object> apps = (ArrayList<Object>) SERVICES.get("apps");
    LinkedHashMap<String, Object> appsList = (LinkedHashMap<String, Object>) apps.get(0);
    LinkedHashMap<String, Object> credentials = (LinkedHashMap<String, Object>) appsList.get("credentials");
    
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put(ID, credentials.get(ID).toString());
    parameters.put(DEFAULTS, credentials.get(DEFAULTST).toString());
    
    return parameters; 
added 82 characters in body
Source Link
Rayn D
  • 227
  • 3
  • 8
Loading
deleted 2 characters in body; edited title
Source Link
Mast
  • 13.5k
  • 12
  • 54
  • 119
Loading
Source Link
Rayn D
  • 227
  • 3
  • 8
Loading