Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / java / org / openecomp / mso / bpmn / infrastructure / workflow / serviceTask / client / builder / AbstractBuilder.java
index 91b95df..2f5bda6 100644 (file)
@@ -22,9 +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.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;
-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;
@@ -36,35 +33,135 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
-/**
- * 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"),
+          CreateServiceInstance(2, "CreateServiceInstance"),
+          DeleteServiceInstance(3, "DeleteServiceInstance"),
+          DeleteNetworkInstance(4, "DeleteNetworkInstance"),
+          CreateVnfInstance(5, "CreateVnfInstance"),
+          ActivateVnfInstance(6, "ActivateVnfInstance"),
+          DeleteVnfInstance(7, "DeleteVnfInstance"),
+          CreateVfModuleInstance(8, "CreateVfModuleInstance"),
+          ActivateVfModuleInstance(9, "ActivateVfModuleInstance"),
+          DeleteVfModuleInstance(10, "DeleteVfModuleInstance"),
+          CreateContrailRouteInstance(11, "CreateContrailRouteInstance"),
+          DeleteContrailRouteInstance(12, "DeleteContrailRouteInstance"),
+          CreateSecurityZoneInstance(13, "CreateSecurityZoneInstance"),
+          DeleteSecurityZoneInstance(14, "DeleteSecurityZoneInstance"),
+          ActivateDCINetworkInstance(15, "ActivateDCINetworkInstance"),
+          DeActivateDCINetworkInstance(16, "DeActivateDCINetworkInstance");
+
+          String name;
+          int value;
+
+          private RequestAction(int value, String name) {
+               this.value = value;
+               this.name = name;
+          }
+
+          public String getName() {
+               return this.name;
+          }
+
+          public int getIntValue() {
+               return this.value;
+          }
+     }
+
+     public enum SvcAction {
+          Reserve(0, "reserve"),
+          Assign(1, "assign"),
+          Activate(2, "activate"),
+          Delete(3, "delete"),
+          Changeassign(4, "changeassign"),
+          Changedelete(5, "changedelete"),
+          Rollback(6, "rollback"),
+          Deactivate(7, "deactivate"),
+          Unassign(8, "unassign"),
+          Create(9, "create");
+
+          String name;
+          int value;
+
+          private SvcAction(int value, String name) {
+               this.value = value;
+               this.name = name;
+          }
+
+          public String getName() {
+               return this.name;
+          }
+
+          public int getIntValue() {
+               return this.value;
+          }
+     }
+
      protected String requestId = null;
 
      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;
@@ -80,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);
@@ -98,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<>();
@@ -123,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;