Healthcheck bug fixes
[appc.git] / appc-config / appc-flow-controller / provider / src / main / java / org / onap / appc / flow / controller / node / TransactionHandler.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2018 Nokia. All rights reserved.
6  * =============================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.appc.flow.controller.node;
21
22 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
23 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION_TYPE;
24 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_TYPE;
25 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_PROTOCOL;
26
27 import java.util.Properties;
28 import org.apache.commons.lang3.StringUtils;
29 import org.onap.appc.flow.controller.data.Transaction;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
31
32 /**
33  * Helper class for RestServiceNode
34  */
35 class TransactionHandler {
36
37   Transaction buildTransaction(SvcLogicContext ctx, Properties prop, String resourceUri)
38       throws Exception {
39
40     String inputRequestAction = ctx.getAttribute(INPUT_REQUEST_ACTION);
41     String inputRequestActionType = ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE);
42     String vnfType = ctx.getAttribute(VNF_TYPE);
43
44     if (StringUtils.isBlank(vnfType)) {
45         throw new Exception("Don't know vnf type to send REST request for  " + INPUT_REQUEST_ACTION + " - " +vnfType);
46     }
47     if (StringUtils.isBlank(inputRequestActionType)) {
48       throw new Exception("Don't know REST operation for Action " + inputRequestActionType);
49     }
50     if (StringUtils.isBlank(inputRequestAction)) {
51       throw new Exception("Don't know request-action " + INPUT_REQUEST_ACTION);
52     }
53
54     Transaction transaction = new Transaction();
55     transaction.setExecutionEndPoint(resourceUri);
56     transaction.setExecutionRPC(inputRequestActionType);
57     transaction.setAction(INPUT_REQUEST_ACTION);
58
59     String userKey = vnfType + "." + REST_PROTOCOL + "." + inputRequestAction + ".user";
60     String passwordKey = vnfType + "." +  REST_PROTOCOL + "." + inputRequestAction + ".password";
61     transaction.setuId(prop.getProperty(userKey));
62     transaction.setPswd(prop.getProperty(passwordKey));
63     if (StringUtils.isBlank(transaction.getuId()) || StringUtils.isBlank(transaction.getPswd())) {
64         throw new Exception ("User Id or Password is not set !!!");
65     }
66     return transaction;
67   }
68
69 }