Update Logic 43/71643/2
authorSmokowski, Steve (ss835w) <ss835w@us.att.com>
Thu, 1 Nov 2018 15:23:04 +0000 (11:23 -0400)
committerSmokowski, Steve (ss835w) <ss835w@us.att.com>
Thu, 1 Nov 2018 15:27:01 +0000 (11:27 -0400)
Update Regex Logic to take into account new scale out URI and generate
the UUID, Fix whitespace

Issue-ID: SO-117
Change-Id: I1a3c3b31e18701fce3d622d501dd68efc7ab6969

Change-Id: I1a3c3b31e18701fce3d622d501dd68efc7ab6969
Signed-off-by: Smokowski, Steve (ss835w) <ss835w@us.att.com>
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java

index 2424627..3fbdbba 100644 (file)
@@ -81,6 +81,7 @@ public class WorkflowAction {
 
        private static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage";
        private static final String SERVICE_INSTANCES = "serviceInstances";
+       private static final String VF_MODULES = "vfModules";
        private static final String WORKFLOW_ACTION_WAS_UNABLE_TO_VERIFY_IF_THE_INSTANCE_NAME_ALREADY_EXIST_IN_AAI = "WorkflowAction was unable to verify if the instance name already exist in AAI.";
        private static final String G_ORCHESTRATION_FLOW = "gOrchestrationFlow";
        private static final String G_ACTION = "requestAction";
@@ -664,35 +665,38 @@ public class WorkflowAction {
        }
 
        protected Resource extractResourceIdAndTypeFromUri(String uri) {
-               Pattern patt = Pattern.compile(
-                               "[vV]\\d+.*?(?:(?:/(?<type>" + supportedTypes + ")(?:/(?<id>[^/]+))?)(?:/(?<action>[^/]+))?)?$");
-               Matcher m = patt.matcher(uri);
-               Boolean generated = false;
-
-               if (m.find()) {
-                       logger.debug("found match on {} : {} " , uri ,  m);
-                       String type = m.group("type");
-                       String id = m.group("id");
-                       String action = m.group("action");
-                       if (type == null) {
-                               throw new IllegalArgumentException("Uri could not be parsed. No type found. " + uri);
-                       }
-                       if (action == null) {
-                               if (type.equals(SERVICE_INSTANCES) && (id == null || id.equals("assign"))) {
-                                       id = UUID.randomUUID().toString();
-                                       generated = true;
-                               }
-                       } else {
-                               if (action.matches(supportedTypes)) {
-                                       id = UUID.randomUUID().toString();
-                                       generated = true;
-                                       type = action;
-                               }
-                       }
-                       return new Resource(WorkflowType.fromString(convertTypeFromPlural(type)), id, generated);
-               } else {
-                       throw new IllegalArgumentException("Uri could not be parsed: " + uri);
-               }
+           Pattern patt = Pattern.compile(
+                   "[vV]\\d+.*?(?:(?:/(?<type>" + supportedTypes + ")(?:/(?<id>[^/]+))?)(?:/(?<action>[^/]+))?)?$");
+           Matcher m = patt.matcher(uri);
+           Boolean generated = false;
+
+           if (m.find()) {
+               logger.debug("found match on {} : {} " , uri ,  m);
+               String type = m.group("type");
+               String id = m.group("id");
+               String action = m.group("action");
+               if (type == null) {
+                   throw new IllegalArgumentException("Uri could not be parsed. No type found. " + uri);
+               }
+               if (action == null) {
+                   if (type.equals(SERVICE_INSTANCES) && (id == null || id.equals("assign"))) {
+                       id = UUID.randomUUID().toString();
+                       generated = true;
+                   }else if (type.equals(VF_MODULES) && id.equals("scaleOut")) {
+                       id = UUID.randomUUID().toString();
+                       generated = true;
+                   }
+               } else {
+                   if (action.matches(supportedTypes)) {
+                       id = UUID.randomUUID().toString();
+                       generated = true;
+                       type = action;
+                   }
+               }
+               return new Resource(WorkflowType.fromString(convertTypeFromPlural(type)), id, generated);
+           } else {
+               throw new IllegalArgumentException("Uri could not be parsed: " + uri);
+           }
        }
 
        protected String validateResourceIdInAAI(String generatedResourceId, WorkflowType type, String instanceName,
index 65d16ad..c27b5dd 100644 (file)
@@ -1318,7 +1318,7 @@ public class WorkflowActionTest extends BaseTaskTest {
                String uri5 = "'/v6/serviceInstances/123/vnfs";
                String uri6 = "/v6/serviceInstances/123/vnfs/1234/someAction";
                String uri7 = "/v6/serviceInstances/123/vnfs/1234/vfModules/5678/replace";
-               
+               String uri8 = "/v6/serviceInstances/123/vnfs/1234/vfModules/scaleOut";
                Resource expected1 = new Resource(WorkflowType.SERVICE, "123", true);
                Resource expected2 = new Resource(WorkflowType.VNF, "1234", false);
                Resource expected3 = new Resource(WorkflowType.VNF, "1234", false);
@@ -1344,6 +1344,10 @@ public class WorkflowActionTest extends BaseTaskTest {
                result = workflowAction.extractResourceIdAndTypeFromUri(uri7);
                assertEquals(expected4.getResourceId(),result.getResourceId());
                assertEquals(expected4.getResourceType(),result.getResourceType());
+               result = workflowAction.extractResourceIdAndTypeFromUri(uri8);
+        assertEquals(UUID.randomUUID().toString().length(),result.getResourceId().length());    
+        assertEquals("VfModule", result.getResourceType().toString());
+               
        }
        
        @Test