diff options
author | marcinrzepeckiwroc <marcin.rzepecki@nokia.com> | 2020-07-01 14:16:21 +0200 |
---|---|---|
committer | marcinrzepeckiwroc <marcin.rzepecki@nokia.com> | 2020-07-06 16:20:29 +0200 |
commit | 674e896261f6edf614aa58fd91d9c8dfd4b8425a (patch) | |
tree | 7723a2d43e543e1f98bde41d8262f3712f6a3632 /bpmn/MSOCommonBPMN/src/main | |
parent | e196ac74e9566cebad4cfdc8191024ea251bdf9e (diff) |
BBInputSetup, getServiceInstanceHelper, mapCollection refactoring
Deleted negation of if statements from void methods
Issue-ID: SO-2634
Signed-off-by: marcinrzepeckiwroc <marcin.rzepecki@nokia.com>
Change-Id: I0bb46be8b2d648d721c58008ee133b63b77894d5
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main')
-rw-r--r-- | bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java | 134 |
1 files changed, 63 insertions, 71 deletions
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<ResourceKey, String> 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<Relationships> 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<org.onap.aai.domain.yang.LineOfBusiness> 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<org.onap.aai.domain.yang.Platform> 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<org.onap.aai.domain.yang.Collection> 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<Relationships> relationshipsOp = collectionWrapper.getRelationships(); - Relationships relationships = null; - if (relationshipsOp.isPresent()) { - relationships = relationshipsOp.get(); - } else { - serviceInstance.setCollection(collection); - return; - } - List<InstanceGroup> 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<Relationships> relationshipsOp = collectionWrapper.getRelationships(); + relationshipsOp.ifPresent(relationships -> setInstanceGroupForCollection(collection, relationships)); + serviceInstance.setCollection(collection); + } + + private void setInstanceGroupForCollection(Collection collection, Relationships relationships) { + List<InstanceGroup> 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<AAIResourceUri> list, List<L3Network> 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<org.onap.aai.domain.yang.OwningEntity> 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<org.onap.aai.domain.yang.Project> 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); } } |