2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.core.utils
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
22 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString
23 import org.onap.ccsdk.cds.controllerblueprints.core.returnNullIfMissing
24 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
25 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
29 fun prepareRequestPayloadStr(workflowName: String, jsonNode: JsonNode): String {
30 return prepareRequestPayload(workflowName, jsonNode).asJsonString(false)
33 fun prepareRequestPayload(workflowName: String, jsonNode: JsonNode): JsonNode {
34 val objectNode = JacksonUtils.objectMapper.createObjectNode()
35 objectNode.set<JsonNode>("$workflowName-request", jsonNode)
39 fun getResponseDataFromPayload(workflowName: String, responsePayload: JsonNode): JsonNode {
40 return responsePayload.get("$workflowName-response").returnNullIfMissing()
41 ?: throw BluePrintProcessorException("failed to get property($workflowName-response)")
44 fun prepareInputsFromWorkflowPayload(
45 bluePrintRuntimeService: BluePrintRuntimeService<*>,
49 val input = payload.get("$workflowName-request")
50 bluePrintRuntimeService.assignWorkflowInputs(workflowName, input)
53 fun prepareDynamicInputsFromWorkflowPayload(
54 bluePrintRuntimeService: BluePrintRuntimeService<*>,
58 val input = payload.get("$workflowName-request")
59 val propertyFields = input.get("$workflowName-properties")
60 prepareDynamicInputsFromComponentPayload(bluePrintRuntimeService, propertyFields)
63 fun prepareDynamicInputsFromComponentPayload(
64 bluePrintRuntimeService: BluePrintRuntimeService<*>,
67 payload.fields().forEach { property ->
68 val path = StringBuilder(BluePrintConstants.PATH_INPUTS)
69 .append(BluePrintConstants.PATH_DIVIDER).append(property.key).toString()
70 bluePrintRuntimeService.put(path, property.value)