Remove mso-oof-adapter from SO
[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 import org.springframework.stereotype.Service;
24 import org.springframework.web.util.UriComponentsBuilder;
25
26 /**
27  * @author waqas.ikram@ericsson.com
28  */
29 @Service
30 public class CamundaRestUrlProvider {
31
32     private static final String HISTORY_PATH = "history";
33     private final URI baseUri;
34
35     public CamundaRestUrlProvider(final String httpUrl, final String engineName) {
36         this.baseUri = UriComponentsBuilder.fromHttpUrl(httpUrl).path(engineName).build().toUri();
37     }
38
39     /**
40      * see {@link <a href=
41      * "https://docs.camunda.org/manual/7.5/reference/rest/history/process-instance/get-process-instance-query/">Get
42      * Process Instances</a>}.
43      * 
44      * @param requestId the request ID
45      * @return URL
46      */
47     public String getHistoryProcessInstanceUrl(final String requestId) {
48         return UriComponentsBuilder.fromUri(baseUri).pathSegment(HISTORY_PATH).pathSegment("process-instance")
49                 .query("variables=requestId_eq_{requestID}").buildAndExpand(requestId).toString();
50     }
51
52     /**
53      * see {@link <a href=
54      * "https://docs.camunda.org/manual/7.5/reference/rest/history/process-instance/get-process-instance/">Get Single
55      * Process Instance</a>}.
56      * 
57      * @param processInstanceId the process instance id.
58      * @return URL
59      */
60     public String getSingleProcessInstanceUrl(final String processInstanceId) {
61         return UriComponentsBuilder.fromUri(baseUri).pathSegment(HISTORY_PATH).pathSegment("process-instance")
62                 .pathSegment(processInstanceId).build().toString();
63     }
64
65     /**
66      * see {@link <a href= "https://docs.camunda.org/manual/7.5/reference/rest/process-definition/get-xml/">Get BPMN 2.0
67      * XML</a>}.
68      * 
69      * @param processDefinitionId the process definition id.
70      * @return URL
71      */
72     public String getProcessDefinitionUrl(final String processDefinitionId) {
73         return UriComponentsBuilder.fromUri(baseUri).pathSegment("process-definition").pathSegment(processDefinitionId)
74                 .pathSegment("xml").build().toString();
75     }
76
77     /**
78      * see {@link <a href=
79      * "https://docs.camunda.org/manual/7.5/reference/rest/history/activity-instance/get-activity-instance/">Get Single
80      * Activity Instance (Historic)</a>}.
81      * 
82      * @param processInstanceId the process instance id.
83      * @return URL
84      */
85     public String getActivityInstanceUrl(final String processInstanceId) {
86         return UriComponentsBuilder.fromUri(baseUri).pathSegment(HISTORY_PATH).pathSegment("activity-instance")
87                 .query("processInstanceId={processInstanceId}").queryParam("sortBy", "startTime")
88                 .queryParam("sortOrder", "asc").buildAndExpand(processInstanceId).toString();
89     }
90
91     /**
92      * see {@link <a href=
93      * "https://docs.camunda.org/manual/7.5/reference/rest/history/variable-instance/get-variable-instance/">Get Single
94      * Variable Instance</a>}.
95      * 
96      * @param processInstanceId the process instance id.
97      * @return URL
98      */
99     public String getProcessInstanceVariablesUrl(final String processInstanceId) {
100         return UriComponentsBuilder.fromUri(baseUri).pathSegment(HISTORY_PATH).pathSegment("variable-instance")
101                 .query("processInstanceId={processInstanceId}").buildAndExpand(processInstanceId).toString();
102     }
103
104 }