From 5dd7bf3451168c1701b6c35b29d0db70c218595a Mon Sep 17 00:00:00 2001 From: sebdet Date: Fri, 19 Jun 2020 11:39:50 +0200 Subject: Fix sonar issues Fix sonar/checkstyle issues in sdc code Issue-ID: SDC-3116 Change-Id: I87802cc9edb378bdbe456c3ca4f10d8c6ebe9425 Signed-off-by: sebdet --- .../config/ValidationToolConfiguration.java | 3 +- .../tasks/module/json/ModuleJsonTask.java | 120 +++++++++++++++++++ .../validator/tasks/moduleJson/ModuleJsonTask.java | 128 --------------------- 3 files changed, 121 insertions(+), 130 deletions(-) create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/module/json/ModuleJsonTask.java delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java (limited to 'asdctool/src/main') diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java index 7afb4ed001..b13009fecc 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java @@ -34,8 +34,7 @@ import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask; import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ArtifactValidationUtils; import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ServiceArtifactValidationTask; import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.VfArtifactValidationTask; -import org.openecomp.sdc.asdctool.impl.validator.tasks.moduleJson.ModuleJsonTask; -import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; +import org.openecomp.sdc.asdctool.impl.validator.tasks.module.json.ModuleJsonTask; import org.openecomp.sdc.asdctool.migration.config.mocks.DistributionEngineMock; import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine; import org.openecomp.sdc.be.components.distribution.engine.ServiceDistributionArtifactsBuilder; diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/module/json/ModuleJsonTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/module/json/ModuleJsonTask.java new file mode 100644 index 0000000000..58c2ef031b --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/module/json/ModuleJsonTask.java @@ -0,0 +1,120 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.asdctool.impl.validator.tasks.module.json; + +import fj.data.Either; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; +import org.openecomp.sdc.asdctool.impl.validator.tasks.ServiceValidationTask; +import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; +import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; +import org.openecomp.sdc.be.model.ComponentParametersView; +import org.openecomp.sdc.be.model.LifecycleStateEnum; +import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate; +import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement; +import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.springframework.beans.factory.annotation.Autowired; + +public class ModuleJsonTask extends ServiceValidationTask { + + private TopologyTemplateOperation topologyTemplateOperation; + + @Autowired + public ModuleJsonTask(TopologyTemplateOperation topologyTemplateOperation) { + this.topologyTemplateOperation = topologyTemplateOperation; + this.name = "Service Module json Validation Task"; + } + + @Override + public VertexResult validate(Report report, GraphVertex vertex, String outputFilePath) { + if (!isAfterSubmitForTesting(vertex)) { + return new VertexResult(true); + } + + ComponentParametersView paramView = new ComponentParametersView(); + paramView.disableAll(); + paramView.setIgnoreArtifacts(false); + paramView.setIgnoreGroups(false); + paramView.setIgnoreComponentInstances(false); + Either toscaElementEither = topologyTemplateOperation + .getToscaElement(vertex.getUniqueId(), paramView); + if (toscaElementEither.isRight()) { + return new VertexResult(false); + } + TopologyTemplate element = (TopologyTemplate) toscaElementEither.left().value(); + Map instGroups = element.getInstGroups(); + Map instDeploymentArtifacts = element.getInstDeploymentArtifacts(); + + for (Map.Entry pair : Optional.ofNullable(instGroups) + .orElse(Collections.emptyMap()).entrySet()) { + MapGroupsDataDefinition groups = pair.getValue(); + if (groups != null && !groups.getMapToscaDataDefinition().isEmpty()) { + return new VertexResult( + findCoordinateModuleJson(report, pair, instDeploymentArtifacts, vertex, outputFilePath)); + } + } + return new VertexResult(true); + } + + private boolean findCoordinateModuleJson(Report report, Map.Entry pair, + Map instDeploymentArtifacts, + GraphVertex vertex, String outputFilePath) { + String groupKey = pair.getKey(); + String[] split = groupKey.split("\\."); + String instanceName = split[split.length - 1]; + MapArtifactDataDefinition deploymentsArtifacts = instDeploymentArtifacts.get(groupKey); + if (deploymentsArtifacts != null && !deploymentsArtifacts.getMapToscaDataDefinition().isEmpty()) { + List moduleJsonArtifacts = deploymentsArtifacts.getMapToscaDataDefinition().values() + .stream().filter(artifact -> { + String artifactName = artifact.getArtifactName(); + return (artifactName.startsWith(instanceName) && artifactName.endsWith("modules.json")); + }).collect(Collectors.toList()); + if (!moduleJsonArtifacts.isEmpty()) { + String status = "Instance " + instanceName + " has a corresponding modules.json file: " + + moduleJsonArtifacts.get(0) + .getArtifactName(); + ReportManager.writeReportLineToFile(status, outputFilePath); + return true; + } + } + String status = "Instance " + instanceName + " doesn't have a corresponding modules.json file"; + ReportManager.writeReportLineToFile(status, outputFilePath); + report.addFailure(getTaskName(), vertex.getUniqueId()); + return false; + } + + private boolean isAfterSubmitForTesting(GraphVertex vertex) { + List allowedStates = new ArrayList<>(Arrays.asList(LifecycleStateEnum.CERTIFIED.name())); + return allowedStates.contains(vertex.getMetadataProperty(GraphPropertyEnum.STATE)); + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java deleted file mode 100644 index af4c6dfd55..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java +++ /dev/null @@ -1,128 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.asdctool.impl.validator.tasks.moduleJson; - -import fj.data.Either; -import org.openecomp.sdc.asdctool.impl.validator.report.Report; -import org.openecomp.sdc.asdctool.impl.validator.tasks.ServiceValidationTask; -import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; -import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.be.model.ComponentParametersView; -import org.openecomp.sdc.be.model.LifecycleStateEnum; -import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate; -import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement; -import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation; -import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - -public class ModuleJsonTask extends ServiceValidationTask { - - private TopologyTemplateOperation topologyTemplateOperation; - - @Autowired - public ModuleJsonTask(TopologyTemplateOperation topologyTemplateOperation) { - this.topologyTemplateOperation = topologyTemplateOperation; - this.name = "Service Module json Validation Task"; - } - - @Override - public VertexResult validate(Report report, GraphVertex vertex, String outputFilePath) { - if (!isAfterSubmitForTesting(vertex)) { - return new VertexResult(true); - } - - ComponentParametersView paramView = new ComponentParametersView(); - paramView.disableAll(); - paramView.setIgnoreArtifacts(false); - paramView.setIgnoreGroups(false); - paramView.setIgnoreComponentInstances(false); - Either toscaElementEither = topologyTemplateOperation - .getToscaElement(vertex.getUniqueId(), paramView); - if (toscaElementEither.isRight()) { - return new VertexResult(false); - } - TopologyTemplate element = (TopologyTemplate) toscaElementEither.left().value(); - Map instGroups = element.getInstGroups(); - Map instDeploymentArtifacts = element.getInstDeploymentArtifacts(); - - for (Map.Entry pair : Optional.ofNullable(instGroups) - .orElse(Collections.emptyMap()).entrySet()) { - MapGroupsDataDefinition groups = pair.getValue(); - if (groups != null && !groups.getMapToscaDataDefinition().isEmpty()) { - return new VertexResult( - findCoordinateModuleJson(report, pair, instDeploymentArtifacts, vertex, outputFilePath)); - } - return new VertexResult(true); - } - return new VertexResult(true); - } - - private boolean findCoordinateModuleJson( - Report report, - Map.Entry pair, - Map instDeploymentArtifacts, - GraphVertex vertex, String outputFilePath - ) { - String groupKey = pair.getKey(); - String[] split = groupKey.split("\\."); - String instanceName = split[split.length - 1]; - MapArtifactDataDefinition deploymentsArtifacts = instDeploymentArtifacts.get(groupKey); - if (deploymentsArtifacts != null && !deploymentsArtifacts.getMapToscaDataDefinition().isEmpty()) { - List moduleJsonArtifacts = deploymentsArtifacts.getMapToscaDataDefinition().values() - .stream().filter(artifact -> { - String artifactName = artifact.getArtifactName(); - if (artifactName.startsWith(instanceName) && artifactName.endsWith("modules.json")) { - return true; - } - return false; - }).collect(Collectors.toList()); - if (moduleJsonArtifacts.size() > 0) { - String status = - "Instance " + instanceName + " has a corresponding modules.json file: " + moduleJsonArtifacts.get(0) - .getArtifactName(); - ReportManager.writeReportLineToFile(status, outputFilePath); - return true; - } - } - String status = "Instance " + instanceName + " doesn't have a corresponding modules.json file"; - ReportManager.writeReportLineToFile(status, outputFilePath); - report.addFailure(getTaskName(), vertex.getUniqueId()); - return false; - } - - private boolean isAfterSubmitForTesting(GraphVertex vertex) { - List allowedStates = new ArrayList<>(Arrays.asList(LifecycleStateEnum.CERTIFIED.name())); - return allowedStates.contains(vertex.getMetadataProperty(GraphPropertyEnum.STATE)); - } -} -- cgit 1.2.3-korg