2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2019 Bell Canada
 
   6  * ================================================================================
 
   7  * Modifications Copyright (c) 2020 Tech Mahindra
 
   8  * ================================================================================
 
   9  * Licensed under the Apache License, Version 2.0 (the "License");
 
  10  * you may not use this file except in compliance with the License.
 
  11  * You may obtain a copy of the License at
 
  13  *      http://www.apache.org/licenses/LICENSE-2.0
 
  15  * Unless required by applicable law or agreed to in writing, software
 
  16  * distributed under the License is distributed on an "AS IS" BASIS,
 
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  18  * See the License for the specific language governing permissions and
 
  19  * limitations under the License.
 
  20  * ============LICENSE_END=========================================================
 
  23 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
 
  25 import org.onap.so.bpmn.common.BuildingBlockExecution;
 
  26 import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
 
  27 import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerRunnable;
 
  28 import org.onap.so.client.cds.AbstractCDSProcessingBBUtils;
 
  29 import org.onap.so.client.cds.GeneratePayloadForCds;
 
  30 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
 
  31 import org.onap.so.client.exception.ExceptionBuilder;
 
  32 import org.slf4j.Logger;
 
  33 import org.slf4j.LoggerFactory;
 
  34 import org.springframework.beans.factory.annotation.Autowired;
 
  35 import org.springframework.stereotype.Component;
 
  38  * This class is used in context of Building Block flow for configuration of vnf/vfmodule/service.
 
  40  * @param - BuildingBlockExecution
 
  43 public class GenericCDSProcessingBB implements ControllerRunnable<BuildingBlockExecution> {
 
  44     private static final Logger logger = LoggerFactory.getLogger(GenericCDSProcessingBB.class);
 
  45     private static final String EXECUTION_OBJECT = "executionObject";
 
  46     public static final String CDS_ACTOR = "cds";
 
  47     public static final String VNF_SCOPE = "vnf";
 
  48     public static final String VF_MODULE_SCOPE = "vfmodule";
 
  51     private ExceptionBuilder exceptionBuilder;
 
  54     private AbstractCDSProcessingBBUtils cdsDispather;
 
  57     private GeneratePayloadForCds generatePayloadForCds;
 
  60     public Boolean understand(ControllerContext<BuildingBlockExecution> context) {
 
  61         String scope = context.getControllerScope();
 
  62         return CDS_ACTOR.equalsIgnoreCase(context.getControllerActor())
 
  63                 && (VNF_SCOPE.equalsIgnoreCase(scope) || VF_MODULE_SCOPE.equalsIgnoreCase(scope));
 
  67     public Boolean ready(ControllerContext<BuildingBlockExecution> context) {
 
  72     public void prepare(ControllerContext<BuildingBlockExecution> context) {
 
  73         BuildingBlockExecution buildingBlockExecution = context.getExecution();
 
  75             AbstractCDSPropertiesBean abstractCDSPropertiesBean =
 
  76                     generatePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution);
 
  77             buildingBlockExecution.setVariable(EXECUTION_OBJECT, abstractCDSPropertiesBean);
 
  78         } catch (Exception ex) {
 
  79             logger.error("An exception occurred when creating payload for CDS request", ex);
 
  80             exceptionBuilder.buildAndThrowWorkflowException(buildingBlockExecution, 7000, ex);
 
  85     public void run(ControllerContext<BuildingBlockExecution> context) {
 
  86         BuildingBlockExecution obj = context.getExecution();
 
  87         cdsDispather.constructExecutionServiceInputObject(obj);
 
  88         cdsDispather.sendRequestToCDSClient(obj);