/modules/dxp/apps/portal-workflow/portal-workflow-metrics-rest-client/src/main/java/com/liferay/portal/workflow/metrics/rest/client/resource/v1_0/SLAResource.java
http://github.com/liferay/liferay-portal · Java · 821 lines · 605 code · 199 blank · 17 comment · 69 complexity · c1aac337d159ac76569067e93d4d9438 MD5 · raw file
- /**
- * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
- *
- * The contents of this file are subject to the terms of the Liferay Enterprise
- * Subscription License ("License"). You may not use this file except in
- * compliance with the License. You can obtain a copy of the License by
- * contacting Liferay, Inc. See the License for the specific language governing
- * permissions and limitations under the License, including but not limited to
- * distribution rights of the Software.
- *
- *
- *
- */
- package com.liferay.portal.workflow.metrics.rest.client.resource.v1_0;
- import com.liferay.portal.workflow.metrics.rest.client.dto.v1_0.SLA;
- import com.liferay.portal.workflow.metrics.rest.client.http.HttpInvoker;
- import com.liferay.portal.workflow.metrics.rest.client.pagination.Page;
- import com.liferay.portal.workflow.metrics.rest.client.pagination.Pagination;
- import com.liferay.portal.workflow.metrics.rest.client.problem.Problem;
- import com.liferay.portal.workflow.metrics.rest.client.serdes.v1_0.SLASerDes;
- import java.util.LinkedHashMap;
- import java.util.Locale;
- import java.util.Map;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.annotation.Generated;
- /**
- * @author Rafael Praxedes
- * @generated
- */
- @Generated("")
- public interface SLAResource {
- public static Builder builder() {
- return new Builder();
- }
- public Page<SLA> getProcessSLAsPage(
- Long processId, Integer status, Pagination pagination)
- throws Exception;
- public HttpInvoker.HttpResponse getProcessSLAsPageHttpResponse(
- Long processId, Integer status, Pagination pagination)
- throws Exception;
- public SLA postProcessSLA(Long processId, SLA sla) throws Exception;
- public HttpInvoker.HttpResponse postProcessSLAHttpResponse(
- Long processId, SLA sla)
- throws Exception;
- public void postProcessSLABatch(
- Long processId, SLA sla, String callbackURL, Object object)
- throws Exception;
- public HttpInvoker.HttpResponse postProcessSLABatchHttpResponse(
- Long processId, SLA sla, String callbackURL, Object object)
- throws Exception;
- public void deleteSLA(Long slaId) throws Exception;
- public HttpInvoker.HttpResponse deleteSLAHttpResponse(Long slaId)
- throws Exception;
- public void deleteSLABatch(Long slaId, String callbackURL, Object object)
- throws Exception;
- public HttpInvoker.HttpResponse deleteSLABatchHttpResponse(
- Long slaId, String callbackURL, Object object)
- throws Exception;
- public SLA getSLA(Long slaId) throws Exception;
- public HttpInvoker.HttpResponse getSLAHttpResponse(Long slaId)
- throws Exception;
- public SLA putSLA(Long slaId, SLA sla) throws Exception;
- public HttpInvoker.HttpResponse putSLAHttpResponse(Long slaId, SLA sla)
- throws Exception;
- public void putSLABatch(
- Long slaId, SLA sla, String callbackURL, Object object)
- throws Exception;
- public HttpInvoker.HttpResponse putSLABatchHttpResponse(
- Long slaId, SLA sla, String callbackURL, Object object)
- throws Exception;
- public static class Builder {
- public Builder authentication(String login, String password) {
- _login = login;
- _password = password;
- return this;
- }
- public SLAResource build() {
- return new SLAResourceImpl(this);
- }
- public Builder endpoint(String host, int port, String scheme) {
- _host = host;
- _port = port;
- _scheme = scheme;
- return this;
- }
- public Builder header(String key, String value) {
- _headers.put(key, value);
- return this;
- }
- public Builder locale(Locale locale) {
- _locale = locale;
- return this;
- }
- public Builder parameter(String key, String value) {
- _parameters.put(key, value);
- return this;
- }
- public Builder parameters(String... parameters) {
- if ((parameters.length % 2) != 0) {
- throw new IllegalArgumentException(
- "Parameters length is not an even number");
- }
- for (int i = 0; i < parameters.length; i += 2) {
- String parameterName = String.valueOf(parameters[i]);
- String parameterValue = String.valueOf(parameters[i + 1]);
- _parameters.put(parameterName, parameterValue);
- }
- return this;
- }
- private Builder() {
- }
- private Map<String, String> _headers = new LinkedHashMap<>();
- private String _host = "localhost";
- private Locale _locale;
- private String _login = "";
- private String _password = "";
- private Map<String, String> _parameters = new LinkedHashMap<>();
- private int _port = 8080;
- private String _scheme = "http";
- }
- public static class SLAResourceImpl implements SLAResource {
- public Page<SLA> getProcessSLAsPage(
- Long processId, Integer status, Pagination pagination)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse =
- getProcessSLAsPageHttpResponse(processId, status, pagination);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- try {
- return Page.of(content, SLASerDes::toDTO);
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- }
- public HttpInvoker.HttpResponse getProcessSLAsPageHttpResponse(
- Long processId, Integer status, Pagination pagination)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
- if (status != null) {
- httpInvoker.parameter("status", String.valueOf(status));
- }
- if (pagination != null) {
- httpInvoker.parameter(
- "page", String.valueOf(pagination.getPage()));
- httpInvoker.parameter(
- "pageSize", String.valueOf(pagination.getPageSize()));
- }
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port +
- "/o/portal-workflow-metrics/v1.0/processes/{processId}/slas");
- httpInvoker.path("processId", processId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public SLA postProcessSLA(Long processId, SLA sla) throws Exception {
- HttpInvoker.HttpResponse httpResponse = postProcessSLAHttpResponse(
- processId, sla);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- try {
- return SLASerDes.toDTO(content);
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- }
- public HttpInvoker.HttpResponse postProcessSLAHttpResponse(
- Long processId, SLA sla)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- httpInvoker.body(sla.toString(), "application/json");
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port +
- "/o/portal-workflow-metrics/v1.0/processes/{processId}/slas");
- httpInvoker.path("processId", processId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public void postProcessSLABatch(
- Long processId, SLA sla, String callbackURL, Object object)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse =
- postProcessSLABatchHttpResponse(
- processId, sla, callbackURL, object);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- }
- public HttpInvoker.HttpResponse postProcessSLABatchHttpResponse(
- Long processId, SLA sla, String callbackURL, Object object)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- httpInvoker.body(object.toString(), "application/json");
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.POST);
- if (callbackURL != null) {
- httpInvoker.parameter(
- "callbackURL", String.valueOf(callbackURL));
- }
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port +
- "/o/portal-workflow-metrics/v1.0/processes/{processId}/slas/batch");
- httpInvoker.path("processId", processId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public void deleteSLA(Long slaId) throws Exception {
- HttpInvoker.HttpResponse httpResponse = deleteSLAHttpResponse(
- slaId);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- try {
- return;
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- }
- public HttpInvoker.HttpResponse deleteSLAHttpResponse(Long slaId)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port +
- "/o/portal-workflow-metrics/v1.0/slas/{slaId}");
- httpInvoker.path("slaId", slaId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public void deleteSLABatch(
- Long slaId, String callbackURL, Object object)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse = deleteSLABatchHttpResponse(
- slaId, callbackURL, object);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- }
- public HttpInvoker.HttpResponse deleteSLABatchHttpResponse(
- Long slaId, String callbackURL, Object object)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- httpInvoker.body(object.toString(), "application/json");
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.DELETE);
- if (callbackURL != null) {
- httpInvoker.parameter(
- "callbackURL", String.valueOf(callbackURL));
- }
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port +
- "/o/portal-workflow-metrics/v1.0/slas/{slaId}/batch");
- httpInvoker.path("slaId", slaId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public SLA getSLA(Long slaId) throws Exception {
- HttpInvoker.HttpResponse httpResponse = getSLAHttpResponse(slaId);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- try {
- return SLASerDes.toDTO(content);
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- }
- public HttpInvoker.HttpResponse getSLAHttpResponse(Long slaId)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.GET);
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port +
- "/o/portal-workflow-metrics/v1.0/slas/{slaId}");
- httpInvoker.path("slaId", slaId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public SLA putSLA(Long slaId, SLA sla) throws Exception {
- HttpInvoker.HttpResponse httpResponse = putSLAHttpResponse(
- slaId, sla);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- try {
- return SLASerDes.toDTO(content);
- }
- catch (Exception e) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response: " + content, e);
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- }
- public HttpInvoker.HttpResponse putSLAHttpResponse(Long slaId, SLA sla)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- httpInvoker.body(sla.toString(), "application/json");
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.PUT);
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port +
- "/o/portal-workflow-metrics/v1.0/slas/{slaId}");
- httpInvoker.path("slaId", slaId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public void putSLABatch(
- Long slaId, SLA sla, String callbackURL, Object object)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse = putSLABatchHttpResponse(
- slaId, sla, callbackURL, object);
- String content = httpResponse.getContent();
- if ((httpResponse.getStatusCode() / 100) != 2) {
- _logger.log(
- Level.WARNING,
- "Unable to process HTTP response content: " + content);
- _logger.log(
- Level.WARNING,
- "HTTP response message: " + httpResponse.getMessage());
- _logger.log(
- Level.WARNING,
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- throw new Problem.ProblemException(Problem.toDTO(content));
- }
- else {
- _logger.fine("HTTP response content: " + content);
- _logger.fine(
- "HTTP response message: " + httpResponse.getMessage());
- _logger.fine(
- "HTTP response status code: " +
- httpResponse.getStatusCode());
- }
- }
- public HttpInvoker.HttpResponse putSLABatchHttpResponse(
- Long slaId, SLA sla, String callbackURL, Object object)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- httpInvoker.body(object.toString(), "application/json");
- if (_builder._locale != null) {
- httpInvoker.header(
- "Accept-Language", _builder._locale.toLanguageTag());
- }
- for (Map.Entry<String, String> entry :
- _builder._headers.entrySet()) {
- httpInvoker.header(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry :
- _builder._parameters.entrySet()) {
- httpInvoker.parameter(entry.getKey(), entry.getValue());
- }
- httpInvoker.httpMethod(HttpInvoker.HttpMethod.PUT);
- if (callbackURL != null) {
- httpInvoker.parameter(
- "callbackURL", String.valueOf(callbackURL));
- }
- httpInvoker.path(
- _builder._scheme + "://" + _builder._host + ":" +
- _builder._port +
- "/o/portal-workflow-metrics/v1.0/slas/{slaId}/batch");
- httpInvoker.path("slaId", slaId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- private SLAResourceImpl(Builder builder) {
- _builder = builder;
- }
- private static final Logger _logger = Logger.getLogger(
- SLAResource.class.getName());
- private Builder _builder;
- }
- }