Improve coverage flow/controller/node #2
[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   private TransactionHandler() {}
17
18   static Transaction buildTransaction(SvcLogicContext ctx, Properties prop,
19       String resourceUri) throws Exception {
20
21     String inputRequestAction = ctx.getAttribute(INPUT_REQUEST_ACTION);
22     String inputRequestActionType = ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE);
23
24     if (StringUtils.isBlank(inputRequestActionType)) {
25       throw new IllegalArgumentException(
26           "Don't know REST operation for Action " + inputRequestActionType);
27     }
28     if (StringUtils.isBlank(inputRequestAction)) {
29       throw new IllegalArgumentException("Don't know request-action " + INPUT_REQUEST_ACTION);
30     }
31
32     Transaction transaction = new Transaction();
33     transaction.setExecutionEndPoint(resourceUri);
34     transaction.setExecutionRPC(inputRequestActionType);
35     transaction.setAction(INPUT_REQUEST_ACTION);
36
37     //This code need to get changed to get the UserID and pass from a common place.
38     transaction.setuId(prop.getProperty(inputRequestAction.concat(".default-rest-user")));
39     transaction.setPswd(prop.getProperty(inputRequestAction.concat(".default-rest-pass")));
40
41     return transaction;
42   }
43
44 }