revert the changes
[so.git] / so-monitoring / so-monitoring-handler / src / main / java / org / onap / so / monitoring / configuration / camunda / CamundaRestUrlProvider.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.monitoring.configuration.camunda;
21
22 import java.net.URI;
23
24 import org.springframework.stereotype.Service;
25 import org.springframework.web.util.UriComponentsBuilder;
26
27 /**
28  * @author waqas.ikram@ericsson.com
29  */
30 @Service
31 public class CamundaRestUrlProvider {
32
33     private static final String HISTORY_PATH = "history";
34     private final URI baseUri;
35
36     public CamundaRestUrlProvider(final String httpUrl, final String engineName) {
37         this.baseUri = UriComponentsBuilder.fromHttpUrl(httpUrl).path(engineName).build().toUri();
38     }
39
40     /**
41      * see {@link <a href=
42      * "https://docs.camunda.org/manual/7.5/reference/rest/history/process-instance/get-process-instance-query/">Get
43      * Process Instances</a>}.
44      * 
45      * @param requestId the request ID
46      * @return URL
47      */
48     public String getHistoryProcessInstanceUrl(final String requestId) {
49         return UriComponentsBuilder.fromUri(baseUri).pathSegment(HISTORY_PATH).pathSegment("process-instance")
50                 .query("variables=requestId_eq_{requestID}").buildAndExpand(requestId).toString();
51     }
52
53     /**
54      * see {@link <a href=
55      * "https://docs.camunda.org/manual/7.5/reference/rest/history/process-instance/get-process-instance/">Get
56      * Single Process Instance</a>}.
57      * 
58      * @param processInstanceId the process instance id.
59      * @return URL
60      */
61     public String getSingleProcessInstanceUrl(final String processInstanceId) {
62         return UriComponentsBuilder.fromUri(baseUri).pathSegment(HISTORY_PATH).pathSegment("process-instance")
63                 .pathSegment(processInstanceId).build().toString();
64     }
65
66     /**
67      * see {@link <a href=
68      * "https://docs.camunda.org/manual/7.5/reference/rest/process-definition/get-xml/">Get BPMN 2.0
69      * XML</a>}.
70      * 
71      * @param processDefinitionId the process definition id.
72      * @return URL
73      */
74     public String getProcessDefinitionUrl(final String processDefinitionId) {
75         return UriComponentsBuilder.fromUri(baseUri).pathSegment("process-definition").pathSegment(processDefinitionId)
76                 .pathSegment("xml").build().toString();
77     }
78
79     /**
80      * see {@link <a href=
81      * "https://docs.camunda.org/manual/7.5/reference/rest/history/activity-instance/get-activity-instance/">Get
82      * Single Activity Instance (Historic)</a>}.
83      * 
84      * @param processInstanceId the process instance id.
85      * @return URL
86      */
87     public String getActivityInstanceUrl(final String processInstanceId) {
88         return UriComponentsBuilder.fromUri(baseUri).pathSegment(HISTORY_PATH).pathSegment("activity-instance")
89                 .query("processInstanceId={processInstanceId}").queryParam("sortBy", "startTime")
90                 .queryParam("sortOrder", "asc").buildAndExpand(processInstanceId).toString();
91     }
92
93     /**
94      * see {@link <a href=
95      * "https://docs.camunda.org/manual/7.5/reference/rest/history/variable-instance/get-variable-instance/">Get
96      * Single Variable Instance</a>}.
97      * 
98      * @param processInstanceId the process instance id.
99      * @return URL
100      */
101     public String getProcessInstanceVariablesUrl(final String processInstanceId) {
102         return UriComponentsBuilder.fromUri(baseUri).pathSegment(HISTORY_PATH).pathSegment("variable-instance")
103                 .query("processInstanceId={processInstanceId}").buildAndExpand(processInstanceId).toString();
104     }
105
106 }