1 package org.openecomp.sdc.asdctool.impl.validator.tasks.moduleJson;
4 import org.openecomp.sdc.asdctool.impl.validator.tasks.ServiceValidationTask;
5 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
6 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
7 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
8 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
9 import org.openecomp.sdc.be.model.ComponentParametersView;
10 import org.openecomp.sdc.be.model.LifecycleStateEnum;
11 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
12 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
13 import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
14 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
15 import org.springframework.beans.factory.annotation.Autowired;
17 import java.util.ArrayList;
18 import java.util.Arrays;
19 import java.util.List;
21 import java.util.stream.Collectors;
24 * Created by chaya on 7/18/2017.
26 public class ModuleJsonTask extends ServiceValidationTask {
29 private TopologyTemplateOperation topologyTemplateOperation;
32 public boolean validate(GraphVertex vertex) {
33 ComponentParametersView paramView = new ComponentParametersView();
34 paramView.disableAll();
35 paramView.setIgnoreArtifacts(false);
36 paramView.setIgnoreGroups(false);
37 paramView.setIgnoreComponentInstances(false);
38 Either<ToscaElement, StorageOperationStatus> toscaElementEither = topologyTemplateOperation.getToscaElement(vertex.getUniqueId(), paramView);
39 if (toscaElementEither.isRight()) {
42 TopologyTemplate element = (TopologyTemplate) toscaElementEither.left().value();
43 if (!isAfterSubmitForTesting(element)) {
46 Map<String, MapGroupsDataDefinition> instGroups = element.getInstGroups();
47 Map<String, MapArtifactDataDefinition> instDeploymentArtifacts = element.getInstDeploymentArtifacts();
49 for (Map.Entry<String, MapGroupsDataDefinition> pair : instGroups.entrySet()) {
50 String groupKey = pair.getKey();
51 MapGroupsDataDefinition groups = pair.getValue();
52 if (groups != null && !groups.getMapToscaDataDefinition().isEmpty()) {
53 MapArtifactDataDefinition deploymentsArtifacts = instDeploymentArtifacts.get(groupKey);
54 if (deploymentsArtifacts != null && !deploymentsArtifacts.getMapToscaDataDefinition().isEmpty()) {
55 List<ArtifactDataDefinition> moduleJsonArtifacts = deploymentsArtifacts.getMapToscaDataDefinition().values().stream().filter(artifact -> {
56 String artifactName = artifact.getArtifactName();
57 if (artifactName.startsWith(groupKey) && artifactName.endsWith("module.json")) {
61 }).collect(Collectors.toList());
62 if (moduleJsonArtifacts.size() > 0) {
71 private boolean isAfterSubmitForTesting(TopologyTemplate element){
72 List allowedStates = new ArrayList<>(Arrays.asList(LifecycleStateEnum.READY_FOR_CERTIFICATION,
73 LifecycleStateEnum.CERTIFICATION_IN_PROGRESS, LifecycleStateEnum.CERTIFIED));
74 return allowedStates.contains(element.getLifecycleState());