summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/main
diff options
context:
space:
mode:
authorElaine_Han <elaine.hanyulian@huawei.com>2018-08-03 20:04:55 +0800
committerElaine_Han <elaine.hanyulian@huawei.com>2018-08-06 16:15:34 +0800
commit0753a8356806f40f77a7f1444b655efba1a654c9 (patch)
tree9ba67d21b63cedcc5b4b6a58b770e6374f1e4497 /bpmn/MSOCommonBPMN/src/main
parent7bc08300d69bdbd3512be206128b3ee344ca8b7b (diff)
Add SPPaterner resource procss
Change-Id: Idaa55084f5ecb0dd3636c232cebc14fa70000001 Issue-ID: SO-683 Signed-off-by: Yulian Han <elaine.hanyulian@huawei.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy6
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy234
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/recipe/ResourceInput.java20
3 files changed, 260 insertions, 0 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy
index 0bd54ffe64..81e2b40bb2 100644
--- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AaiUtil.groovy
@@ -94,6 +94,12 @@ class AaiUtil {
msoLogger.debug('AaiUtil.getBusinessCustomerUri() - AAI URI: ' + uri)
return uri
}
+
+ public String getBusinessSPPartnerUri(DelegateExecution execution) {
+ def uri = getUri(execution, 'sp-partner')
+ msoLogger.debug('AaiUtil.getBusinessSPPartnerUri() - AAI URI: ' + uri)
+ return uri
+ }
//public String getBusinessCustomerUriv7(DelegateExecution execution) {
// // //def uri = getUri(execution, BUSINESS_CUSTOMERV7)
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy
new file mode 100644
index 0000000000..3646f26fb6
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy
@@ -0,0 +1,234 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.common.scripts
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
+import org.onap.so.rest.APIResponse
+import org.onap.so.rest.RESTClient
+import org.onap.so.rest.RESTConfig
+import org.apache.commons.lang3.StringEscapeUtils
+import java.util.regex.Matcher
+import java.util.regex.Pattern
+
+class ExternalAPIUtil {
+
+ String Prefix="EXTAPI_"
+
+ public MsoUtils utils = new MsoUtils()
+
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+
+ private AbstractServiceTaskProcessor taskProcessor
+
+ public static final String PostServiceOrderRequestsTemplate =
+ "{\n" +
+ "\t\"externalId\": <externalId>,\n" +
+ "\t\"category\": <category>,\n" +
+ "\t\"description\": <description>,\n" +
+ "\t\"requestedStartDate\": <requestedStartDate>,\n" +
+ "\t\"requestedCompletionDate\": <requestedCompletionDate>,\n" +
+ "\t\"priority\": <priority>,\n" +
+ "\t\"@type\": null,\n" +
+ "\t\"@baseType\": null,\n" +
+ "\t\"@schemaLocation\": null,\n" +
+ "\t\"relatedParty\": [{\n" +
+ "\t\t\"id\": <subscriberId>, \n" +
+ "\t\t\"href\": null, \n" +
+ "\t\t\"role\": <customerRole>, \n" +
+ "\t\t\"name\": <subscriberName>, \n" +
+ "\t\t\"@referredType\": <referredType> \n" +
+ "}], \n" +
+ "\t\"orderItem\": [{\n" +
+ "\t\t\"id\": <orderItemId>,\n" +
+ "\t\t\"action\": <action>,\n" +
+ "\t\t\"service\": {\n" +
+ "\t\t\t\"serviceState\": <serviceState>,\n" +
+ "\t\t\t\"name\": <serviceName>,\n" +
+ "\t\t\t\"serviceSpecification\": { \n" +
+ "\t\t\t\t\"id\": <serviceUuId> \n" +
+ "\t\t\t},\n" +
+ "\t\t\t\"serviceCharacteristic\": [ \n" +
+ "<_requestInputs_> \n" +
+ "\t\t\t] \n" +
+ "\t\t}\n" +
+ "\t}]\n" +
+ "}"
+
+ public static final String RequestInputsTemplate =
+ "{ \n" +
+ "\t\"name\": <inputName>, \n" +
+ "\t\"value\": { \n" +
+ "\t\t\"serviceCharacteristicValue\": <inputValue> \n" +
+ "\t} \n" +
+ "}"
+
+ public ExternalAPIUtil(AbstractServiceTaskProcessor taskProcessor) {
+ this.taskProcessor = taskProcessor
+ }
+
+// public String getUri(DelegateExecution execution, resourceName) {
+//
+// def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
+// def uri = execution.getVariable("ExternalAPIURi")
+// if(uri) {
+// taskProcessor.logDebug("ExternalAPIUtil.getUri: " + uri, isDebugLogEnabled)
+// return uri
+// }
+//
+// exceptionUtil.buildAndThrowWorkflowException(execution, 9999, 'ExternalAPI URI not find')
+// }
+
+ public String setTemplate(String template, Map<String, String> valueMap) {
+ taskProcessor.logDebug("ExternalAPIUtil setTemplate", true);
+ StringBuffer result = new StringBuffer();
+
+ String pattern = "<.*>";
+ Pattern r = Pattern.compile(pattern);
+ Matcher m = r.matcher(template);
+
+ taskProcessor.logDebug("ExternalAPIUtil template:" + template, true);
+ while (m.find()) {
+ String key = template.substring(m.start() + 1, m.end() - 1);
+ taskProcessor.logDebug("ExternalAPIUtil key:" + key + " contains key? " + valueMap.containsKey(key), true);
+ m.appendReplacement(result, valueMap.getOrDefault(key, "\"TBD\""));
+ }
+ m.appendTail(result);
+ taskProcessor.logDebug("ExternalAPIUtil return:" + result.toString(), true);
+ return result.toString();
+ }
+
+ /**
+ * This reusable method can be used for making ExternalAPI Get Calls. The url should
+ * be passed as a parameter along with the execution. The method will
+ * return an APIResponse.
+ *
+ * @param execution
+ * @param url
+ *
+ * @return APIResponse
+ *
+ */
+ public APIResponse executeExternalAPIGetCall(DelegateExecution execution, String url){
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+ taskProcessor.logDebug(" ======== STARTED Execute ExternalAPI Get Process ======== ", isDebugEnabled)
+ APIResponse apiResponse = null
+ try{
+ String uuid = utils.getRequestID()
+ taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)
+ taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)
+
+ String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_externalapi_auth"),execution.getVariable("URN_mso_msoKey"))
+
+ RESTConfig config = new RESTConfig(url);
+ RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Accept","application/json");
+
+ if (basicAuthCred != null && !"".equals(basicAuthCred)) {
+ client.addAuthorizationHeader(basicAuthCred)
+ }
+ apiResponse = client.get()
+
+ taskProcessor.logDebug( "======== COMPLETED Execute ExternalAPI Get Process ======== ", isDebugEnabled)
+ }catch(Exception e){
+ taskProcessor.logDebug("Exception occured while executing ExternalAPI Get Call. Exception is: \n" + e, isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 9999, e.getMessage())
+ }
+ return apiResponse
+ }
+
+ /**
+ * This reusable method can be used for making ExternalAPI Post Calls. The url
+ * and payload should be passed as a parameters along with the execution.
+ * The method will return an APIResponse.
+ *
+ * @param execution
+ * @param url
+ * @param payload
+ *
+ * @return APIResponse
+ *
+ */
+ public APIResponse executeExternalAPIPostCall(DelegateExecution execution, String url, String payload){
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+ taskProcessor.logDebug( " ======== Started Execute ExternalAPI Post Process ======== ", isDebugEnabled)
+ APIResponse apiResponse = null
+ try{
+ String uuid = utils.getRequestID()
+ taskProcessor.logDebug( "Generated uuid is: " + uuid, isDebugEnabled)
+ taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)
+
+ String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_externalapi_auth"),execution.getVariable("URN_mso_msoKey"))
+ RESTConfig config = new RESTConfig(url);
+ RESTClient client = new RESTClient(config).addHeader("X-FromAppId", "MSO").addHeader("X-TransactionId", uuid).addHeader("Content-Type", "application/json").addHeader("Accept","application/json");
+
+ if (basicAuthCred != null && !"".equals(basicAuthCred)) {
+ client.addAuthorizationHeader(basicAuthCred)
+ }
+ apiResponse = client.httpPost(payload)
+
+ taskProcessor.logDebug( "======== Completed Execute ExternalAPI Post Process ======== ", isDebugEnabled)
+ }catch(Exception e){
+ taskProcessor.utils.log("ERROR", "Exception occured while executing ExternalAPI Post Call. Exception is: \n" + e, isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 9999, e.getMessage())
+ }
+ return apiResponse
+ }
+
+ /**
+ * This reusable method can be used for making ExternalAPI Post Calls. The url
+ * and payload should be passed as a parameters along with the execution.
+ * The method will return an APIResponse.
+ *
+ * @param execution
+ * @param url
+ * @param payload
+ * @param authenticationHeader - addAuthenticationHeader value
+ * @param headerName - name of header you want to add, i.e. addHeader(headerName, headerValue)
+ * @param headerValue - the header's value, i.e. addHeader(headerName, headerValue)
+ *
+ * @return APIResponse
+ *
+ */
+ public APIResponse executeExternalAPIPostCall(DelegateExecution execution, String url, String payload, String authenticationHeaderValue, String headerName, String headerValue){
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+ taskProcessor.logDebug( " ======== Started Execute ExternalAPI Post Process ======== ", isDebugEnabled)
+ APIResponse apiResponse = null
+ try{
+ taskProcessor.logDebug( "URL to be used is: " + url, isDebugEnabled)
+
+ String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_externalapi_auth"),execution.getVariable("URN_mso_msoKey"))
+
+ RESTConfig config = new RESTConfig(url);
+ RESTClient client = new RESTClient(config).addAuthorizationHeader(authenticationHeaderValue).addHeader(headerName, headerValue)
+ if (basicAuthCred != null && !"".equals(basicAuthCred)) {
+ client.addAuthorizationHeader(basicAuthCred)
+ }
+ apiResponse = client.httpPost(payload)
+
+ taskProcessor.logDebug( "======== Completed Execute ExternalAPI Post Process ======== ", isDebugEnabled)
+ }catch(Exception e){
+ taskProcessor.utils.log("ERROR", "Exception occured while executing ExternalAPI Post Call. Exception is: \n" + e, isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 9999, e.getMessage())
+ }
+ return apiResponse
+ }
+
+} \ No newline at end of file
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/recipe/ResourceInput.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/recipe/ResourceInput.java
index 4c345babc8..f574288a67 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/recipe/ResourceInput.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/recipe/ResourceInput.java
@@ -75,8 +75,28 @@ public class ResourceInput {
@JsonProperty("resourceParameters")
private String resourceParameters;
+ @JsonProperty("requestsInputs")
+ private String requestsInputs;
+
@JsonProperty("operationType")
private String operationType;
+
+ /**
+ * @return Returns the requestsInputs.
+ */
+ @JsonProperty("requestsInputs")
+ public String getRequestsInputs() {
+ return requestsInputs;
+ }
+
+
+ /**
+ * @param requestsInputs The requestsInputs to set.
+ */
+ @JsonProperty("requestsInputs")
+ public void setRequestsInputs(String requestsInputs) {
+ this.requestsInputs = requestsInputs;
+ }
/**