Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / java / org / openecomp / mso / bpmn / infrastructure / workflow / serviceTask / client / builder / AbstractBuilder.java
index 41fa8f2..2f5bda6 100644 (file)
@@ -22,7 +22,6 @@ package org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.builde
 
 import org.apache.commons.lang3.StringUtils;
 import org.camunda.bpm.engine.delegate.DelegateExecution;
-import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.SdncUnderlayVpnPreprocessTask;
 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.OnapModelInformationEntity;
 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.ParamEntity;
 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.RequestInformationEntity;
@@ -34,13 +33,11 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
-//import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation;
-//import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader;
-
-/**
- * Created by 10112215 on 2017/9/20.
- */
 public abstract class AbstractBuilder<IN, OUT> {
+
+     public static final String OPERATION_TYPE = "operationType";
+     public static final String RESOURCE_TYPE = "resourceType";
+
      public static enum RequestAction {
           CreateNetworkInstance(0, "CreateNetworkInstance"),
           ActivateNetworkInstance(1, "ActivateNetworkInstance"),
@@ -56,7 +53,9 @@ public abstract class AbstractBuilder<IN, OUT> {
           CreateContrailRouteInstance(11, "CreateContrailRouteInstance"),
           DeleteContrailRouteInstance(12, "DeleteContrailRouteInstance"),
           CreateSecurityZoneInstance(13, "CreateSecurityZoneInstance"),
-          DeleteSecurityZoneInstance(14, "DeleteSecurityZoneInstance");
+          DeleteSecurityZoneInstance(14, "DeleteSecurityZoneInstance"),
+          ActivateDCINetworkInstance(15, "ActivateDCINetworkInstance"),
+          DeActivateDCINetworkInstance(16, "DeActivateDCINetworkInstance");
 
           String name;
           int value;
@@ -109,26 +108,60 @@ public abstract class AbstractBuilder<IN, OUT> {
      abstract OUT build(DelegateExecution execution, IN input) throws Exception;
 
      protected String getRequestActoin(DelegateExecution execution) {
-          String action = /*RequestInformation.*/RequestAction.CreateNetworkInstance.name();
-          String operType = getOperType(execution);
+          String action = /*RequestInformation.*/RequestAction.CreateNetworkInstance.getName();
+          String operType = (String) execution.getVariable(OPERATION_TYPE);
+          String resourceType = (String)execution.getVariable(RESOURCE_TYPE);
           if (!StringUtils.isBlank(operType)) {
-               if (RequestsDbConstant.OperationType.DELETE.equals(operType)) {
-                    action = /*RequestInformation.*/RequestAction.DeleteNetworkInstance.name();
-               } else if (RequestsDbConstant.OperationType.CREATE.equals(operType)) {
-                    action = /*RequestInformation.*/RequestAction.CreateNetworkInstance.name();
+               if (RequestsDbConstant.OperationType.DELETE.equalsIgnoreCase(operType)) {
+                    if (isOverlay(resourceType)) {
+                         action = /*RequestInformation.*/RequestAction.DeActivateDCINetworkInstance.getName();
+                    } else if (isUnderlay(resourceType)) {
+                         action = /*RequestInformation.*/RequestAction.DeleteNetworkInstance.getName();
+                    } else {
+                         action = /*RequestInformation.*/RequestAction.DeleteServiceInstance.getName();
+                    }
+               } else if (RequestsDbConstant.OperationType.CREATE.equalsIgnoreCase(operType)) {
+                    if (isOverlay(resourceType)) {
+                         action = /*RequestInformation.*/RequestAction.ActivateDCINetworkInstance.getName();
+                    } else if (isUnderlay(resourceType)) {
+                         action = /*RequestInformation.*/RequestAction.CreateNetworkInstance.getName();
+                    } else {
+                         action = /*RequestInformation.*/RequestAction.CreateServiceInstance.getName();
+                    }
                }
           }
           return action;
      }
 
-     protected String getOperationType(DelegateExecution execution) {
-          String action = /*SdncRequestHeader.*/SvcAction.Create.name();
-          String operType = getOperType(execution);
+     private boolean isOverlay(String resourceType) {
+          return !StringUtils.isBlank(resourceType) && resourceType.toLowerCase().contains("overlay");
+     }
+
+     private boolean isUnderlay(String resourceType) {
+          return !StringUtils.isBlank(resourceType) && resourceType.toLowerCase().contains("underlay");
+     }
+
+     protected String getSvcAction(DelegateExecution execution) {
+          String action = /*SdncRequestHeader.*/SvcAction.Create.getName();
+          String operType = (String) execution.getVariable(OPERATION_TYPE);
+          String resourceType = (String)execution.getVariable(RESOURCE_TYPE);
           if (!StringUtils.isBlank(operType)) {
-               if (RequestsDbConstant.OperationType.DELETE.equals(operType)) {
-                    action = /*SdncRequestHeader.*/SvcAction.Delete.name();
-               } else if (RequestsDbConstant.OperationType.CREATE.equals(operType)) {
-                    action = /*SdncRequestHeader.*/SvcAction.Create.name();
+               if (RequestsDbConstant.OperationType.DELETE.equalsIgnoreCase(operType)) {
+                    if (isOverlay(resourceType)) {
+                         action = /*SdncRequestHeader.*/SvcAction.Deactivate.getName();
+                    } else if (isUnderlay(resourceType)) {
+                         action = /*SdncRequestHeader.*/SvcAction.Delete.getName();
+                    } else {
+                         action = /*SdncRequestHeader.*/SvcAction.Unassign.getName();
+                    }
+               } else if (RequestsDbConstant.OperationType.CREATE.equalsIgnoreCase(operType)) {
+                    if (isOverlay(resourceType)) {
+                         action = /*SdncRequestHeader.*/SvcAction.Activate.getName();
+                    } else if (isUnderlay(resourceType)) {
+                         action = /*SdncRequestHeader.*/SvcAction.Create.getName();
+                    } else {
+                         action = /*SdncRequestHeader.*/SvcAction.Assign.getName();
+                    }
                }
           }
           return action;
@@ -144,17 +177,13 @@ public abstract class AbstractBuilder<IN, OUT> {
           return requestId;
      }
 
-     protected String getOperType(DelegateExecution execution) {
-          return (String) execution.getVariable(SdncUnderlayVpnPreprocessTask.RESOURCE_OPER_TYPE);
-     }
-
-     protected OnapModelInformationEntity getOnapModelInformationEntity(DelegateExecution execution) {
+     protected OnapModelInformationEntity getOnapServiceModelInformationEntity(DelegateExecution execution) {
           OnapModelInformationEntity onapModelInformationEntity = new OnapModelInformationEntity();
           {
                String modelInvariantUuid = (String) execution.getVariable("modelInvariantUuid");
                String modelVersion = (String) execution.getVariable("modelVersion");
                String modelUuid = (String) execution.getVariable("modelUuid");
-               String modelName = (String) execution.getVariable("modelName");
+               String modelName = (String) execution.getVariable("serviceModelName");
                onapModelInformationEntity.setModelInvariantUuid(modelInvariantUuid);
                onapModelInformationEntity.setModelVersion(modelVersion);
                onapModelInformationEntity.setModelUuid(modelUuid);
@@ -162,6 +191,21 @@ public abstract class AbstractBuilder<IN, OUT> {
           }
           return onapModelInformationEntity;
      }
+     
+     protected OnapModelInformationEntity getOnapNetworkModelInformationEntity(DelegateExecution execution) {
+         OnapModelInformationEntity onapModelInformationEntity = new OnapModelInformationEntity();
+         {
+              String modelInvariantUuid = (String) execution.getVariable("resourceInvariantUUID");
+              String modelVersion = (String) execution.getVariable("modelVersion");
+              String modelUuid = (String) execution.getVariable("resourceUUID");
+              String modelName = (String) execution.getVariable("resourceType");
+              onapModelInformationEntity.setModelInvariantUuid(modelInvariantUuid);
+              onapModelInformationEntity.setModelVersion(modelVersion);
+              onapModelInformationEntity.setModelUuid(modelUuid);
+              onapModelInformationEntity.setModelName(modelName);
+         }
+         return onapModelInformationEntity;
+    }
 
      protected List<ParamEntity> getParamEntities(Map<String, String> inputs) {
           List<ParamEntity> paramEntityList = new ArrayList<>();
@@ -187,9 +231,9 @@ public abstract class AbstractBuilder<IN, OUT> {
 
      protected ServiceInformationEntity getServiceInformationEntity(DelegateExecution execution) {
           ServiceInformationEntity serviceInformationEntity = new ServiceInformationEntity();
-          serviceInformationEntity.setServiceId((String) execution.getVariable("productFamilyId"));
-          serviceInformationEntity.setSubscriptionServiceType((String) execution.getVariable("subscriptionServiceType"));
-          serviceInformationEntity.setOnapModelInformation(getOnapModelInformationEntity(execution));
+          serviceInformationEntity.setServiceId((String) execution.getVariable("serviceInstanceId"));
+          serviceInformationEntity.setSubscriptionServiceType((String) execution.getVariable("serviceType"));
+          serviceInformationEntity.setOnapModelInformation(getOnapServiceModelInformationEntity(execution));
           serviceInformationEntity.setServiceInstanceId((String) execution.getVariable("serviceInstanceId"));
           serviceInformationEntity.setGlobalCustomerId((String) execution.getVariable("globalSubscriberId"));
           return serviceInformationEntity;