From 674e896261f6edf614aa58fd91d9c8dfd4b8425a Mon Sep 17 00:00:00 2001 From: marcinrzepeckiwroc Date: Wed, 1 Jul 2020 14:16:21 +0200 Subject: BBInputSetup, getServiceInstanceHelper, mapCollection refactoring Deleted negation of if statements from void methods Issue-ID: SO-2634 Signed-off-by: marcinrzepeckiwroc Change-Id: I0bb46be8b2d648d721c58008ee133b63b77894d5 --- .../servicedecomposition/tasks/BBInputSetup.java | 134 ++++++++++----------- .../tasks/BBInputSetupTest.java | 20 +++ 2 files changed, 83 insertions(+), 71 deletions(-) (limited to 'bpmn') diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index bfa77212c4..fcc8484385 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -1699,20 +1699,8 @@ public class BBInputSetup implements JavaDelegate { && bbName.equalsIgnoreCase(AssignFlows.SERVICE_INSTANCE.toString())) { throw new Exception("Request invalid missing: RequestInfo:InstanceName"); } else { - org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI = null; - if (aLaCarte && bbName.equalsIgnoreCase(AssignFlows.SERVICE_INSTANCE.toString())) { - serviceInstanceAAI = bbInputSetupUtils - .getAAIServiceInstanceByName(requestDetails.getRequestInfo().getInstanceName(), customer); - } - if (serviceInstanceId != null && serviceInstanceAAI == null) { - if (customer != null && customer.getServiceSubscription() != null) { - serviceInstanceAAI = - bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(customer.getGlobalCustomerId(), - customer.getServiceSubscription().getServiceType(), serviceInstanceId); - } else { - serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId); - } - } + org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI; + serviceInstanceAAI = getServiceInstanceAAI(requestDetails, customer, serviceInstanceId, aLaCarte, bbName); if (serviceInstanceAAI != null) { lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstanceId); return this.getExistingServiceInstance(serviceInstanceAAI); @@ -1722,6 +1710,25 @@ public class BBInputSetup implements JavaDelegate { } } + private org.onap.aai.domain.yang.ServiceInstance getServiceInstanceAAI(RequestDetails requestDetails, + Customer customer, String serviceInstanceId, boolean aLaCarte, String bbName) throws Exception { + org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI = null; + if (aLaCarte && bbName.equalsIgnoreCase(AssignFlows.SERVICE_INSTANCE.toString())) { + serviceInstanceAAI = bbInputSetupUtils + .getAAIServiceInstanceByName(requestDetails.getRequestInfo().getInstanceName(), customer); + } + if (serviceInstanceId != null && serviceInstanceAAI == null) { + if (customer != null && customer.getServiceSubscription() != null) { + serviceInstanceAAI = + bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(customer.getGlobalCustomerId(), + customer.getServiceSubscription().getServiceType(), serviceInstanceId); + } else { + serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId); + } + } + return serviceInstanceAAI; + } + protected ServiceInstance createServiceInstance(RequestDetails requestDetails, Project project, OwningEntity owningEntity, Map lookupKeyMap, String serviceInstanceId) { ServiceInstance serviceInstance = new ServiceInstance(); @@ -1833,13 +1840,12 @@ public class BBInputSetup implements JavaDelegate { AAIResultWrapper serviceInstanceWrapper = new AAIResultWrapper( new AAICommonObjectMapperProvider().getMapper().writeValueAsString(serviceInstanceAAI)); Optional relationshipsOp = serviceInstanceWrapper.getRelationships(); - Relationships relationships = null; if (relationshipsOp.isPresent()) { - relationships = relationshipsOp.get(); - } else { - return; + mapRelationship(serviceInstance, relationshipsOp.get()); } + } + private void mapRelationship(ServiceInstance serviceInstance, Relationships relationships) { this.mapProject(relationships.getByType(AAIObjectType.PROJECT), serviceInstance); this.mapOwningEntity(relationships.getByType(AAIObjectType.OWNING_ENTITY), serviceInstance); this.mapL3Networks(relationships.getRelatedAAIUris(AAIObjectType.L3_NETWORK), serviceInstance.getNetworks()); @@ -1945,14 +1951,10 @@ public class BBInputSetup implements JavaDelegate { AAIResultWrapper lineOfBusinessWrapper = lineOfBusinesses.get(0); Optional aaiLineOfBusinessOp = lineOfBusinessWrapper.asBean(org.onap.aai.domain.yang.LineOfBusiness.class); - org.onap.aai.domain.yang.LineOfBusiness aaiLineOfBusiness = null; - if (!aaiLineOfBusinessOp.isPresent()) { - return; + if (aaiLineOfBusinessOp.isPresent()) { + LineOfBusiness lineOfBusiness = this.mapperLayer.mapAAILineOfBusiness(aaiLineOfBusinessOp.get()); + genericVnf.setLineOfBusiness(lineOfBusiness); } - aaiLineOfBusiness = aaiLineOfBusinessOp.get(); - - LineOfBusiness lineOfBusiness = this.mapperLayer.mapAAILineOfBusiness(aaiLineOfBusiness); - genericVnf.setLineOfBusiness(lineOfBusiness); } } @@ -1961,14 +1963,10 @@ public class BBInputSetup implements JavaDelegate { AAIResultWrapper platformWrapper = platforms.get(0); Optional aaiPlatformOp = platformWrapper.asBean(org.onap.aai.domain.yang.Platform.class); - org.onap.aai.domain.yang.Platform aaiPlatform = null; - if (!aaiPlatformOp.isPresent()) { - return; + if (aaiPlatformOp.isPresent()) { + Platform platform = this.mapperLayer.mapAAIPlatform(aaiPlatformOp.get()); + genericVnf.setPlatform(platform); } - aaiPlatform = aaiPlatformOp.get(); - - Platform platform = this.mapperLayer.mapAAIPlatform(aaiPlatform); - genericVnf.setPlatform(platform); } } @@ -1977,34 +1975,36 @@ public class BBInputSetup implements JavaDelegate { AAIResultWrapper collectionWrapper = collections.get(0); Optional aaiCollectionOp = collectionWrapper.asBean(org.onap.aai.domain.yang.Collection.class); - org.onap.aai.domain.yang.Collection aaiCollection = null; - if (!aaiCollectionOp.isPresent()) { - return; - } - aaiCollection = aaiCollectionOp.get(); - - Collection collection = this.mapperLayer.mapAAICollectionIntoCollection(aaiCollection); - NetworkCollectionResourceCustomization collectionResourceCust = bbInputSetupUtils - .getCatalogNetworkCollectionResourceCustByID(aaiCollection.getCollectionCustomizationId()); - collection.setModelInfoCollection(mapperLayer.mapCatalogCollectionToCollection(collectionResourceCust, - collectionResourceCust.getCollectionResource())); - Optional relationshipsOp = collectionWrapper.getRelationships(); - Relationships relationships = null; - if (relationshipsOp.isPresent()) { - relationships = relationshipsOp.get(); - } else { - serviceInstance.setCollection(collection); - return; - } - List instanceGroupsList = - mapInstanceGroups(relationships.getByType(AAIObjectType.INSTANCE_GROUP)); - if (!instanceGroupsList.isEmpty()) { - collection.setInstanceGroup(instanceGroupsList.get(0)); - } - serviceInstance.setCollection(collection); + aaiCollectionOp.ifPresent( + collection -> serviceInstanceSetCollection(serviceInstance, collectionWrapper, collection)); } } + private void serviceInstanceSetCollection(ServiceInstance serviceInstance, AAIResultWrapper collectionWrapper, + org.onap.aai.domain.yang.Collection aaiCollection) { + Collection collection = getCollection(aaiCollection); + Optional relationshipsOp = collectionWrapper.getRelationships(); + relationshipsOp.ifPresent(relationships -> setInstanceGroupForCollection(collection, relationships)); + serviceInstance.setCollection(collection); + } + + private void setInstanceGroupForCollection(Collection collection, Relationships relationships) { + List instanceGroupsList = + mapInstanceGroups(relationships.getByType(AAIObjectType.INSTANCE_GROUP)); + if (!instanceGroupsList.isEmpty()) { + collection.setInstanceGroup(instanceGroupsList.get(0)); + } + } + + private Collection getCollection(org.onap.aai.domain.yang.Collection aaiCollection) { + Collection collection = this.mapperLayer.mapAAICollectionIntoCollection(aaiCollection); + NetworkCollectionResourceCustomization collectionResourceCust = bbInputSetupUtils + .getCatalogNetworkCollectionResourceCustByID(aaiCollection.getCollectionCustomizationId()); + collection.setModelInfoCollection(mapperLayer.mapCatalogCollectionToCollection(collectionResourceCust, + collectionResourceCust.getCollectionResource())); + return collection; + } + protected void mapL3Networks(List list, List l3Networks) { for (AAIResourceUri aaiResourceUri : list) { l3Networks.add(this.mapL3Network(aaiResourceUri)); @@ -2080,14 +2080,10 @@ public class BBInputSetup implements JavaDelegate { AAIResultWrapper owningEntityWrapper = owningEntities.get(0); Optional aaiOwningEntityOp = owningEntityWrapper.asBean(org.onap.aai.domain.yang.OwningEntity.class); - org.onap.aai.domain.yang.OwningEntity aaiOwningEntity = null; - if (!aaiOwningEntityOp.isPresent()) { - return; + if (aaiOwningEntityOp.isPresent()) { + OwningEntity owningEntity = this.mapperLayer.mapAAIOwningEntity(aaiOwningEntityOp.get()); + serviceInstance.setOwningEntity(owningEntity); } - aaiOwningEntity = aaiOwningEntityOp.get(); - - OwningEntity owningEntity = this.mapperLayer.mapAAIOwningEntity(aaiOwningEntity); - serviceInstance.setOwningEntity(owningEntity); } } @@ -2096,14 +2092,10 @@ public class BBInputSetup implements JavaDelegate { AAIResultWrapper projectWrapper = projects.get(0); Optional aaiProjectOp = projectWrapper.asBean(org.onap.aai.domain.yang.Project.class); - org.onap.aai.domain.yang.Project aaiProject = null; - if (!aaiProjectOp.isPresent()) { - return; + if (aaiProjectOp.isPresent()) { + Project project = this.mapperLayer.mapAAIProject(aaiProjectOp.get()); + serviceInstance.setProject(project); } - aaiProject = aaiProjectOp.get(); - - Project project = this.mapperLayer.mapAAIProject(aaiProject); - serviceInstance.setProject(project); } } diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java index 458919c48e..9e9c6f365f 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java @@ -815,6 +815,26 @@ public class BBInputSetupTest { assertThat(actual, sameBeanAs(expected)); } + @Test + public void testGetServiceInstanceHelperCreateScenarioExistingWithName() throws Exception { + RequestDetails requestDetails = new RequestDetails(); + RequestInfo requestInfo = new RequestInfo(); + requestDetails.setRequestInfo(requestInfo); + ServiceSubscription serviceSub = new ServiceSubscription(); + Customer customer = new Customer(); + customer.setServiceSubscription(serviceSub); + ServiceInstance expected = new ServiceInstance(); + expected.setServiceInstanceId("serviceInstanceId"); + org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI = new org.onap.aai.domain.yang.ServiceInstance(); + serviceInstanceAAI.setServiceInstanceId("serviceInstanceId"); + + doReturn(serviceInstanceAAI).when(SPY_bbInputSetupUtils).getAAIServiceInstanceByIdAndCustomer(Mockito.any(), + Mockito.any(), Mockito.any()); + ServiceInstance actual = SPY_bbInputSetup.getServiceInstanceHelper(requestDetails, customer, null, null, + new HashMap<>(), "SharansInstanceId", false, new Service(), "ActivateServiceInstanceBB"); + assertThat(actual, sameBeanAs(expected)); + } + @Test(expected = Exception.class) public void testGetServiceInstanceHelperCreateScenarioExistingNoNameButWithIdExceptionThrown() throws Exception { RequestDetails requestDetails = new RequestDetails(); -- cgit 1.2.3-korg