--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP : APPC\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Copyright (C) 2017 Amdocs\r
+ * =============================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * \r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.appc.provider.lcm.service;\r
+\r
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;\r
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreConfigureInput;\r
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreConfigureOutput;\r
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.PreConfigureOutputBuilder;\r
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;\r
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;\r
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;\r
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;\r
+import org.onap.appc.executor.objects.LCMCommandStatus;\r
+import org.onap.appc.util.JsonUtil;\r
+\r
+import java.io.IOException;\r
+import java.util.Map;\r
+/**\r
+ * Provide LCM command service for PreConfigure VNF\r
+ */\r
+public class PreConfigure extends AbstractBaseService {\r
+\r
+ /**\r
+ * Constructor\r
+ */\r
+ public PreConfigure() {\r
+ super(Action.PreConfigure);\r
+ logger.debug("PreConfigure starts");\r
+ }\r
+\r
+ /**\r
+ * Process the PreConfigure request\r
+ * @param input of PreConfigureInput from the REST API input\r
+ * @return PreConfigureOutputBuilder which has the process results\r
+ */\r
+ public PreConfigureOutputBuilder process(PreConfigureInput input) {\r
+ CommonHeader commonHeader = input.getCommonHeader();\r
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();\r
+ Payload payload = input.getPayload();\r
+\r
+ validate(commonHeader, input.getAction(), actionIdentifiers, payload);\r
+ if (status == null) {\r
+ proceedAction(commonHeader,actionIdentifiers,payload);\r
+ }\r
+\r
+ PreConfigureOutputBuilder outputBuilder = new PreConfigureOutputBuilder();\r
+ outputBuilder.setStatus(status);\r
+ outputBuilder.setCommonHeader(input.getCommonHeader());\r
+ return outputBuilder;\r
+ }\r
+\r
+ /**\r
+ * Validate the input.\r
+ * Set Status if any error occurs.\r
+ *\r
+ * @param input of PreConfigureInput from the REST API input\r
+ */\r
+ void validate(CommonHeader commonHeader,\r
+ Action action,\r
+ ActionIdentifiers actionIdentifiers,\r
+ Payload payload) {\r
+ status = validateVnfId(commonHeader, action, actionIdentifiers);\r
+ if (status != null) {\r
+ return;\r
+ }\r
+\r
+ // validate payload\r
+ String keyName = "payload";\r
+ if (payload == null) {\r
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);\r
+ return;\r
+ }\r
+ String payloadString = payload.getValue();\r
+ status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), "payload");\r
+ if (status != null) {\r
+ return;\r
+ }\r
+\r
+ try {\r
+ Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString);\r
+ validateMustHaveParamValue(payloadMap.get(keyName), keyName);\r
+ } catch (IOException e) {\r
+ logger.error(String.format("PreConfigure (%s) got IOException when converting payload", rpcName), e);\r
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Proceed to action for the PreConfigure VNF traffic.\r
+ *\r
+ * @param input of PreConfigureInput from the REST API input\r
+ */\r
+ void proceedAction(CommonHeader commonHeader,\r
+ ActionIdentifiers actionIdentifiers,\r
+ Payload payload) {\r
+ RequestHandlerInput requestHandlerInput = getRequestHandlerInput(commonHeader, actionIdentifiers, payload,\r
+ this.getClass().getName());\r
+ if (requestHandlerInput != null) {\r
+ executeAction(requestHandlerInput);\r
+ }\r
+ }\r
+}\r