/modules/dxp/apps/portal-workflow/portal-workflow-metrics-rest-client/src/main/java/com/liferay/portal/workflow/metrics/rest/client/resource/v1_0/ProcessResource.java
http://github.com/liferay/liferay-portal · Java · 793 lines · 583 code · 193 blank · 17 comment · 65 complexity · e542b7e3aec3a2f87de78619674bfb4d 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.Process;
- import com.liferay.portal.workflow.metrics.rest.client.http.HttpInvoker;
- import com.liferay.portal.workflow.metrics.rest.client.problem.Problem;
- 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 ProcessResource {
- public static Builder builder() {
- return new Builder();
- }
- public Process postProcess(Process process) throws Exception;
- public HttpInvoker.HttpResponse postProcessHttpResponse(Process process)
- throws Exception;
- public void postProcessBatch(String callbackURL, Object object)
- throws Exception;
- public HttpInvoker.HttpResponse postProcessBatchHttpResponse(
- String callbackURL, Object object)
- throws Exception;
- public void deleteProcess(Long processId) throws Exception;
- public HttpInvoker.HttpResponse deleteProcessHttpResponse(Long processId)
- throws Exception;
- public void deleteProcessBatch(String callbackURL, Object object)
- throws Exception;
- public HttpInvoker.HttpResponse deleteProcessBatchHttpResponse(
- String callbackURL, Object object)
- throws Exception;
- public Process getProcess(Long processId) throws Exception;
- public HttpInvoker.HttpResponse getProcessHttpResponse(Long processId)
- throws Exception;
- public void putProcess(Long processId, Process process) throws Exception;
- public HttpInvoker.HttpResponse putProcessHttpResponse(
- Long processId, Process process)
- throws Exception;
- public void putProcessBatch(String callbackURL, Object object)
- throws Exception;
- public HttpInvoker.HttpResponse putProcessBatchHttpResponse(
- String callbackURL, Object object)
- throws Exception;
- public String getProcessTitle(Long processId) throws Exception;
- public HttpInvoker.HttpResponse getProcessTitleHttpResponse(Long processId)
- throws Exception;
- public static class Builder {
- public Builder authentication(String login, String password) {
- _login = login;
- _password = password;
- return this;
- }
- public ProcessResource build() {
- return new ProcessResourceImpl(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 ProcessResourceImpl implements ProcessResource {
- public Process postProcess(Process process) throws Exception {
- HttpInvoker.HttpResponse httpResponse = postProcessHttpResponse(
- process);
- 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 com.liferay.portal.workflow.metrics.rest.client.serdes.
- v1_0.ProcessSerDes.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 postProcessHttpResponse(Process process)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- httpInvoker.body(process.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");
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public void postProcessBatch(String callbackURL, Object object)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse =
- postProcessBatchHttpResponse(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 postProcessBatchHttpResponse(
- 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/batch");
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public void deleteProcess(Long processId) throws Exception {
- HttpInvoker.HttpResponse httpResponse = deleteProcessHttpResponse(
- processId);
- 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 deleteProcessHttpResponse(
- Long processId)
- 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/processes/{processId}");
- httpInvoker.path("processId", processId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public void deleteProcessBatch(String callbackURL, Object object)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse =
- deleteProcessBatchHttpResponse(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 deleteProcessBatchHttpResponse(
- 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/processes/batch");
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public Process getProcess(Long processId) throws Exception {
- HttpInvoker.HttpResponse httpResponse = getProcessHttpResponse(
- processId);
- 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 com.liferay.portal.workflow.metrics.rest.client.serdes.
- v1_0.ProcessSerDes.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 getProcessHttpResponse(Long processId)
- 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/processes/{processId}");
- httpInvoker.path("processId", processId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public void putProcess(Long processId, Process process)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse = putProcessHttpResponse(
- processId, process);
- 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 putProcessHttpResponse(
- Long processId, Process process)
- throws Exception {
- HttpInvoker httpInvoker = HttpInvoker.newHttpInvoker();
- httpInvoker.body(process.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/processes/{processId}");
- httpInvoker.path("processId", processId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public void putProcessBatch(String callbackURL, Object object)
- throws Exception {
- HttpInvoker.HttpResponse httpResponse = putProcessBatchHttpResponse(
- 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 putProcessBatchHttpResponse(
- 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/processes/batch");
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- public String getProcessTitle(Long processId) throws Exception {
- HttpInvoker.HttpResponse httpResponse = getProcessTitleHttpResponse(
- processId);
- 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 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 getProcessTitleHttpResponse(
- Long processId)
- 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/processes/{processId}/title");
- httpInvoker.path("processId", processId);
- httpInvoker.userNameAndPassword(
- _builder._login + ":" + _builder._password);
- return httpInvoker.invoke();
- }
- private ProcessResourceImpl(Builder builder) {
- _builder = builder;
- }
- private static final Logger _logger = Logger.getLogger(
- ProcessResource.class.getName());
- private Builder _builder;
- }
- }