From 338f1b3041ab39951f901e9d9186e75fe3a36366 Mon Sep 17 00:00:00 2001 From: JerzySzachniewicz Date: Fri, 3 Jul 2020 09:17:09 +0200 Subject: Sonar improvements in WorkflowAction Issue-ID: SO-1841 Signed-off-by: JerzySzachniewicz Change-Id: I28603335a2039977aa13d347b703b6abc23de6c3 Signed-off-by: JerzySzachniewicz --- .../workflow/tasks/WorkflowAction.java | 119 +++++++++------------ 1 file changed, 51 insertions(+), 68 deletions(-) (limited to 'bpmn/so-bpmn-tasks/src') diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 9200d99fe1..57e81993d2 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -144,6 +144,7 @@ public class WorkflowAction { private static final String VOLUMEGROUP_DELETE_PATTERN = "(Un|De)(.*)Volume(.*)"; private static final String VOLUMEGROUP_CREATE_PATTERN = "(A|C)(.*)Volume(.*)"; private static final String CONTROLLER = "Controller"; + private static final String DEFAULT_CLOUD_OWNER = "org.onap.so.cloud-owner"; @Autowired protected BBInputSetup bbInputSetup; @@ -159,10 +160,8 @@ public class WorkflowAction { private WorkflowActionExtractResourcesAAI workflowActionUtils; @Autowired private VrfValidation vrfValidation; - @Autowired private Environment environment; - private String defaultCloudOwner = "org.onap.so.cloud-owner"; public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) { this.bbInputSetupUtils = bbInputSetupUtils; @@ -235,7 +234,7 @@ public class WorkflowAction { .setRequestDetails(requestDetails).setExecution(execution)); for (OrchestrationFlow orchFlow : orchFlows) { if (orchFlow.getFlowName().contains(CONFIGURATION)) { - List configOrchFlows = new ArrayList(); + List configOrchFlows = new ArrayList<>(); configOrchFlows.add(orchFlow); List configBuildingBlocks = getConfigBuildingBlocks(new ConfigBuildingBlocksDataObject() @@ -287,11 +286,8 @@ public class WorkflowAction { if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { List> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams(); - for (Map params : userParams) { - if (params.containsKey(USERPARAMSERVICE)) { - containsService = true; - } - } + containsService = + userParams.stream().anyMatch(param -> param.containsKey(USERPARAMSERVICE)); if (containsService) { traverseUserParamsService(execution, resourceList, sIRequest, requestAction); } @@ -309,11 +305,8 @@ public class WorkflowAction { if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { List> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams(); - for (Map params : userParams) { - if (params.containsKey(USERPARAMSERVICE)) { - containsService = true; - } - } + containsService = + userParams.stream().anyMatch(param -> param.containsKey(USERPARAMSERVICE)); } if (containsService) { foundRelated = traverseUserParamsService(execution, resourceList, sIRequest, requestAction); @@ -341,13 +334,13 @@ public class WorkflowAction { } else { buildAndThrowException(execution, "Current Macro Request is not supported"); } - String foundObjects = ""; + StringBuilder foundObjects = new StringBuilder(); for (WorkflowType type : WorkflowType.values()) { - foundObjects = foundObjects + type + " - " + resourceList.stream() - .filter(x -> type.equals(x.getResourceType())).collect(Collectors.toList()).size() - + " "; + foundObjects.append(type).append(" - ").append( + (int) resourceList.stream().filter(x -> type.equals(x.getResourceType())).count()) + .append(" "); } - logger.info("Found {}", foundObjects); + logger.info("Found {}", foundObjects.toString()); if (orchFlows == null || orchFlows.isEmpty()) { orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, isALaCarte, @@ -367,8 +360,7 @@ public class WorkflowAction { // By default, enable homing at VNF level for CREATEINSTANCE and ASSIGNINSTANCE if (resourceType == WorkflowType.SERVICE && (requestAction.equals(CREATEINSTANCE) || requestAction.equals(ASSIGNINSTANCE)) - && !resourceList.stream().filter(x -> WorkflowType.VNF.equals(x.getResourceType())) - .collect(Collectors.toList()).isEmpty()) { + && resourceList.stream().anyMatch(x -> WorkflowType.VNF.equals(x.getResourceType()))) { execution.setVariable("homing", true); execution.setVariable("calledHoming", false); } @@ -389,11 +381,7 @@ public class WorkflowAction { sIRequest.getRequestDetails().getRequestParameters().getUserParams(); for (Map params : userParams) { if (params.containsKey(HOMINGSOLUTION)) { - if ("none".equals(params.get(HOMINGSOLUTION))) { - execution.setVariable("homing", false); - } else { - execution.setVariable("homing", true); - } + execution.setVariable("homing", !"none".equals(params.get(HOMINGSOLUTION))); } } } @@ -448,7 +436,7 @@ public class WorkflowAction { return cloudConfiguration.getCloudOwner(); } logger.warn("cloud owner value not found in request details, it will be set as default"); - return environment.getProperty(defaultCloudOwner); + return environment.getProperty(DEFAULT_CLOUD_OWNER); } protected List getRelatedResourcesInVfModule(String vnfId, String vfModuleId, Class resultClass, @@ -514,7 +502,7 @@ public class WorkflowAction { String vfModuleId = dataObj.getWorkflowResourceIds().getVfModuleId(); String vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId(); - String vfModuleCustomizationUUID = ""; + String vfModuleCustomizationUUID; org.onap.aai.domain.yang.VfModule aaiVfModule = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId); if (aaiVfModule == null) { @@ -575,8 +563,7 @@ public class WorkflowAction { boolean rebuildVolumeGroups = false; if (dataObj.getRequestDetails().getRequestParameters() != null && dataObj.getRequestDetails().getRequestParameters().getRebuildVolumeGroups() != null) { - rebuildVolumeGroups = - dataObj.getRequestDetails().getRequestParameters().getRebuildVolumeGroups().booleanValue(); + rebuildVolumeGroups = dataObj.getRequestDetails().getRequestParameters().getRebuildVolumeGroups(); } Optional volumeGroupFromVfModule = @@ -629,7 +616,7 @@ public class WorkflowAction { } Relationships relationships = relationshipsOp.get(); List vnfcResultWrappers = relationships.getByType(AAIObjectType.VNFC); - if (vnfcResultWrappers.size() > 1 || vnfcResultWrappers.isEmpty()) { + if (vnfcResultWrappers.size() != 1) { logger.debug("Too many vnfcs or no vnfc found that are related to configuration"); } Optional vnfcOp = vnfcResultWrappers.get(0).asBean(Vnfc.class); @@ -667,11 +654,10 @@ public class WorkflowAction { logger.debug(pair.getValue0() + ", " + pair.getValue1()); } - Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE)).forEach(type -> { - resourceList.stream().filter(resource -> type.equals(resource.getResourceType())) - .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource.getResourceId(), - retrieveAAIResourceId(aaiResourceIds, type), null, serviceInstanceId)); - }); + Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE)) + .forEach(type -> resourceList.stream().filter(resource -> type.equals(resource.getResourceType())) + .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource.getResourceId(), + retrieveAAIResourceId(aaiResourceIds, type), null, serviceInstanceId))); } private String retrieveAAIResourceId(List> aaiResourceIds, WorkflowType resource) { @@ -688,11 +674,10 @@ public class WorkflowAction { private void generateResourceIds(List flowsToExecute, List resourceList, String serviceInstanceId) { - Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE)).forEach(type -> { - resourceList.stream().filter(resource -> type.equals(resource.getResourceType())) - .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource.getResourceId(), null, - resource.getVirtualLinkKey(), serviceInstanceId)); - }); + Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE)) + .forEach(type -> resourceList.stream().filter(resource -> type.equals(resource.getResourceType())) + .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource.getResourceId(), + null, resource.getVirtualLinkKey(), serviceInstanceId))); } protected void updateWorkflowResourceIds(List flowsToExecute, WorkflowType resourceType, @@ -947,8 +932,7 @@ public class WorkflowAction { } private boolean isNetworkCollectionInTheResourceList(List resourceList) { - return !(resourceList.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()) - .collect(Collectors.toList()).isEmpty()); + return resourceList.stream().anyMatch(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()); } private boolean isVnfCustomizationsInTheService(org.onap.so.db.catalog.beans.Service service) { @@ -1134,12 +1118,9 @@ public class WorkflowAction { foundVfModuleOrVG = true; Resource resource = new Resource(WorkflowType.VFMODULE, vfModuleCustomization.getModelCustomizationUUID(), false); - if (vfModuleCustomization.getVfModule().getIsBase() != null - && vfModuleCustomization.getVfModule().getIsBase()) { - resource.setBaseVfModule(true); - } else { - resource.setBaseVfModule(false); - } + resource.setBaseVfModule( + vfModuleCustomization.getVfModule().getIsBase() != null + && vfModuleCustomization.getVfModule().getIsBase()); resourceList.add(resource); if (vfModule.getModelInfo() != null && vfModule.getModelInfo().getModelCustomizationUuid() != null) { @@ -1429,7 +1410,7 @@ public class WorkflowAction { true, false); } else if (orchFlow.getFlowName().contains(VFMODULE) || (orchFlow.getFlowName().contains(CONTROLLER) && (VFMODULE).equalsIgnoreCase(orchFlow.getBpmnScope()))) { - List vfModuleResourcesSorted = null; + List vfModuleResourcesSorted; if (requestAction.equals(CREATEINSTANCE) || requestAction.equals(ASSIGNINSTANCE) || requestAction.equals("activateInstance")) { vfModuleResourcesSorted = sortVfModulesByBaseFirst(resourceList.stream() @@ -1438,10 +1419,10 @@ public class WorkflowAction { vfModuleResourcesSorted = sortVfModulesByBaseLast(resourceList.stream() .filter(x -> WorkflowType.VFMODULE == x.getResourceType()).collect(Collectors.toList())); } - for (int i = 0; i < vfModuleResourcesSorted.size(); i++) { - flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, vfModuleResourcesSorted.get(i), - apiVersion, resourceId, requestAction, false, vnfType, workflowResourceIds, requestDetails, - false, null, null, false)); + for (Resource resource : vfModuleResourcesSorted) { + flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resource, apiVersion, resourceId, + requestAction, false, vnfType, workflowResourceIds, requestDetails, false, null, null, + false)); } } else if (orchFlow.getFlowName().contains(VOLUMEGROUP)) { if (requestAction.equalsIgnoreCase(REPLACEINSTANCE) @@ -1477,8 +1458,8 @@ public class WorkflowAction { new BuildingBlock().setBpmnFlowName(orchFlow.getFlowName()).setMsoId(UUID.randomUUID().toString()) .setIsVirtualLink(isVirtualLink).setVirtualLinkKey(virtualLinkKey) .setKey(Optional.ofNullable(resource).map(Resource::getResourceId).orElse("")); - Optional.ofNullable(orchFlow.getBpmnAction()).ifPresent(action -> buildingBlock.setBpmnAction(action)); - Optional.ofNullable(orchFlow.getBpmnScope()).ifPresent(scope -> buildingBlock.setBpmnScope(scope)); + Optional.ofNullable(orchFlow.getBpmnAction()).ifPresent(buildingBlock::setBpmnAction); + Optional.ofNullable(orchFlow.getBpmnScope()).ifPresent(buildingBlock::setBpmnScope); if (resource != null && (orchFlow.getFlowName().contains(VOLUMEGROUP) && (requestAction.equalsIgnoreCase(REPLACEINSTANCE) @@ -1493,16 +1474,21 @@ public class WorkflowAction { .setRequestDetails(requestDetails); if (resource != null && (isConfiguration || resource.getResourceType().equals(WorkflowType.CONFIGURATION))) { - ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys(); - Optional.ofNullable(vnfcName).ifPresent(name -> configurationResourceKeys.setVnfcName(name)); - configurationResourceKeys.setCvnfcCustomizationUUID(resource.getCvnfModuleCustomizationId()); - configurationResourceKeys.setVfModuleCustomizationUUID(resource.getVfModuleCustomizationId()); - configurationResourceKeys.setVnfResourceCustomizationUUID(resource.getVnfCustomizationId()); + ConfigurationResourceKeys configurationResourceKeys = getConfigurationResourceKeys(resource, vnfcName); executeBuildingBlock.setConfigurationResourceKeys(configurationResourceKeys); } return executeBuildingBlock; } + private ConfigurationResourceKeys getConfigurationResourceKeys(Resource resource, String vnfcName) { + ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys(); + Optional.ofNullable(vnfcName).ifPresent(configurationResourceKeys::setVnfcName); + configurationResourceKeys.setCvnfcCustomizationUUID(resource.getCvnfModuleCustomizationId()); + configurationResourceKeys.setVfModuleCustomizationUUID(resource.getVfModuleCustomizationId()); + configurationResourceKeys.setVnfResourceCustomizationUUID(resource.getVnfCustomizationId()); + return configurationResourceKeys; + } + protected List queryNorthBoundRequestCatalogDb(DelegateExecution execution, String requestAction, WorkflowType resourceName, boolean aLaCarte, String cloudOwner) { return this.queryNorthBoundRequestCatalogDb(execution, requestAction, resourceName, aLaCarte, cloudOwner, ""); @@ -1511,7 +1497,7 @@ public class WorkflowAction { protected List queryNorthBoundRequestCatalogDb(DelegateExecution execution, String requestAction, WorkflowType resourceName, boolean aLaCarte, String cloudOwner, String serviceType) { List listToExecute = new ArrayList<>(); - NorthBoundRequest northBoundRequest = null; + NorthBoundRequest northBoundRequest; if (serviceType.equalsIgnoreCase(SERVICE_TYPE_TRANSPORT) || serviceType.equalsIgnoreCase(SERVICE_TYPE_BONDING)) { northBoundRequest = @@ -1592,7 +1578,7 @@ public class WorkflowAction { } protected String validateServiceResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails) throws DuplicateNameException, MultipleObjectsFoundException { + RequestDetails reqDetails) throws DuplicateNameException { String globalCustomerId = reqDetails.getSubscriberInfo().getGlobalSubscriberId(); String serviceType = reqDetails.getRequestParameters().getSubscriptionServiceType(); if (instanceName != null) { @@ -1656,8 +1642,7 @@ public class WorkflowAction { } protected String validateVnfResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) - throws DuplicateNameException, MultipleObjectsFoundException { + RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { Optional vnf = bbInputSetupUtils .getRelatedVnfByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName); if (vnf.isPresent()) { @@ -1701,8 +1686,7 @@ public class WorkflowAction { } protected String validateVolumeGroupResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) - throws DuplicateNameException, MultipleObjectsFoundException { + RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { Optional volumeGroup = bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(workflowResourceIds.getVnfId(), instanceName); if (volumeGroup.isPresent()) { @@ -1720,8 +1704,7 @@ public class WorkflowAction { } protected String validateConfigurationResourceIdInAAI(String generatedResourceId, String instanceName, - RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) - throws DuplicateNameException, MultipleObjectsFoundException { + RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException { Optional configuration = bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance( workflowResourceIds.getServiceInstanceId(), instanceName); -- cgit 1.2.3-korg