2  * ============LICENSE_START=======================================================
 
   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
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  20 package org.onap.appc.flow.controller.node;
 
  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;
 
  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;
 
  33  * Helper class for RestServiceNode
 
  35 class TransactionHandler {
 
  37   Transaction buildTransaction(SvcLogicContext ctx, Properties prop, String resourceUri)
 
  40     String inputRequestAction = ctx.getAttribute(INPUT_REQUEST_ACTION);
 
  41     String inputRequestActionType = ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE);
 
  42     String vnfType = ctx.getAttribute(VNF_TYPE);
 
  44     if (StringUtils.isBlank(vnfType)) {
 
  45         throw new Exception("Don't know vnf type to send REST request for  " + INPUT_REQUEST_ACTION + " - " +vnfType);
 
  47     if (StringUtils.isBlank(inputRequestActionType)) {
 
  48       throw new Exception("Don't know REST operation for Action " + inputRequestActionType);
 
  50     if (StringUtils.isBlank(inputRequestAction)) {
 
  51       throw new Exception("Don't know request-action " + INPUT_REQUEST_ACTION);
 
  54     Transaction transaction = new Transaction();
 
  55     transaction.setExecutionEndPoint(resourceUri);
 
  56     transaction.setExecutionRPC(inputRequestActionType);
 
  57     transaction.setAction(INPUT_REQUEST_ACTION);
 
  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 !!!");