Improve coverage flow/controller/node #3
[appc.git] / appc-config / appc-flow-controller / provider / src / main / java / org / onap / appc / flow / controller / node / TransactionHandler.java
1 package org.onap.appc.flow.controller.node;
2
3 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
4 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION_TYPE;
5
6 import java.util.Properties;
7 import org.apache.commons.lang3.StringUtils;
8 import org.onap.appc.flow.controller.data.Transaction;
9 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
10
11 /**
12  * Helper class for RestServiceNode
13  */
14 class TransactionHandler {
15
16   Transaction buildTransaction(SvcLogicContext ctx, Properties prop, String resourceUri)
17       throws Exception {
18
19     String inputRequestAction = ctx.getAttribute(INPUT_REQUEST_ACTION);
20     String inputRequestActionType = ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE);
21
22     if (StringUtils.isBlank(inputRequestActionType)) {
23       throw new Exception("Don't know REST operation for Action " + inputRequestActionType);
24     }
25     if (StringUtils.isBlank(inputRequestAction)) {
26       throw new Exception("Don't know request-action " + INPUT_REQUEST_ACTION);
27     }
28
29     Transaction transaction = new Transaction();
30     transaction.setExecutionEndPoint(resourceUri);
31     transaction.setExecutionRPC(inputRequestActionType);
32     transaction.setAction(INPUT_REQUEST_ACTION);
33
34     //This code need to get changed to get the UserID and pass from a common place.
35     transaction.setuId(prop.getProperty(inputRequestAction.concat(".default-rest-user")));
36     transaction.setPswd(prop.getProperty(inputRequestAction.concat(".default-rest-pass")));
37
38     return transaction;
39   }
40
41 }