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

com.ocadotechnology.newrelic.apiclient.internal.DefaultApplicationsApi Maven / Gradle / Ivy

Go to download

NewRelic Alerts Configurator can be used to configure NewRelic alerts for your application. Instead of defining alerts through UI you can define them in code. It allows you to automatize alerts configuration, easily recover them in case of wipe out and have full history of changes in your version control system.

There is a newer version: 5.0.1
Show newest version
package com.ocadotechnology.newrelic.apiclient.internal;

import com.ocadotechnology.newrelic.apiclient.ApplicationsApi;
import com.ocadotechnology.newrelic.apiclient.internal.client.NewRelicClient;
import com.ocadotechnology.newrelic.apiclient.internal.model.ApplicationList;
import com.ocadotechnology.newrelic.apiclient.internal.model.ApplicationWrapper;
import com.ocadotechnology.newrelic.apiclient.model.applications.Application;

import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import java.util.Optional;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;

class DefaultApplicationsApi extends ApiBase implements ApplicationsApi {

    private static final String APPLICATIONS_URL = "/v2/applications.json";
    private static final String APPLICATION_URL = "/v2/applications/{application_id}.json";

    DefaultApplicationsApi(NewRelicClient client) {
        super(client);
    }

    @Override
    public Optional getByName(String applicationName) {
        Invocation.Builder builder = client
                .target(APPLICATIONS_URL)
                .queryParam("filter[name]", applicationName)
                .request(APPLICATION_JSON_TYPE);
        return getPageable(builder, ApplicationList.class)
                .filter(application -> application.getName().equals(applicationName))
                .getSingle();
    }

    @Override
    public Application update(int applicationId, Application application) {
        return client
                .target(APPLICATION_URL)
                .resolveTemplate("application_id", applicationId)
                .request(APPLICATION_JSON_TYPE)
                .put(Entity.entity(new ApplicationWrapper(application), APPLICATION_JSON_TYPE), ApplicationWrapper.class)
                .getApplication();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy