summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionDataExtractor.java386
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionEntityDataManager.java257
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGenerator.java70
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGeneratorConfig.java184
4 files changed, 0 insertions, 897 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionDataExtractor.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionDataExtractor.java
deleted file mode 100644
index f92b83532e..0000000000
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionDataExtractor.java
+++ /dev/null
@@ -1,386 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 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.vendorsoftwareproduct.services;
-
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.MapUtils;
-import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
-import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
-import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
-import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
-import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
-import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition;
-import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment;
-import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.openecomp.sdc.tosca.errors.ToscaInvalidEntryNotFoundErrorBuilder;
-import org.openecomp.sdc.tosca.errors.ToscaInvalidSubstituteNodeTemplateErrorBuilder;
-import org.openecomp.sdc.tosca.errors.ToscaMissingSubstitutionMappingForReqCapErrorBuilder;
-import org.openecomp.sdc.tosca.services.ToscaAnalyzerService;
-import org.openecomp.sdc.tosca.services.ToscaConstants;
-import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
-import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil;
-import org.openecomp.sdc.vendorsoftwareproduct.types.ExtractCompositionDataContext;
-import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Component;
-import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
-import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData;
-import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network;
-import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
-/**
- * The type Composition data extractor.
- */
-public class CompositionDataExtractor {
-
- /**
- * The constant logger.
- */
- protected static Logger logger;
- private static ToscaAnalyzerService toscaAnalyzerService;
-
- static {
- logger = LoggerFactory.getLogger(CompositionDataExtractor.class);
- toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- }
-
- /**
- * Extract service composition data composition data.
- *
- * @param toscaServiceModel the tosca service model
- * @return the composition data
- */
- public static CompositionData extractServiceCompositionData(ToscaServiceModel toscaServiceModel) {
- ExtractCompositionDataContext context = new ExtractCompositionDataContext();
- String entryDefinitionServiceTemplateFileName =
- toscaServiceModel.getEntryDefinitionServiceTemplate();
- ServiceTemplate entryDefinitionServiceTemplate =
- toscaServiceModel.getServiceTemplates().get(entryDefinitionServiceTemplateFileName);
- extractServiceCompositionData(entryDefinitionServiceTemplateFileName,
- entryDefinitionServiceTemplate, toscaServiceModel, context);
-
- CompositionData compositionData = new CompositionData();
- compositionData.setNetworks(context.getNetworks());
- compositionData.setComponents(context.getComponents());
- return compositionData;
- }
-
- private static void extractServiceCompositionData(String serviceTemplateFileName,
- ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel,
- ExtractCompositionDataContext context) {
- if (context.getHandledServiceTemplates().contains(serviceTemplateFileName)) {
- return;
- }
- context.addNetworks(extractNetworks(serviceTemplate, toscaServiceModel));
- extractComponents(serviceTemplate, toscaServiceModel, context);
- handleSubstitution(serviceTemplate, toscaServiceModel, context);
- context.addHandledServiceTemplates(serviceTemplateFileName);
- }
-
- private static void handleSubstitution(ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel,
- ExtractCompositionDataContext context) {
- Map<String, NodeTemplate> substitutableNodeTemplates =
- toscaAnalyzerService.getSubstitutableNodeTemplates(serviceTemplate);
-
- if (substitutableNodeTemplates != null) {
- for (String substitutableNodeTemplateId : substitutableNodeTemplates.keySet()) {
- handleSubstitutableNodeTemplate(serviceTemplate, toscaServiceModel,
- substitutableNodeTemplateId,
- substitutableNodeTemplates.get(substitutableNodeTemplateId), context);
- }
- }
- }
-
- private static void handleSubstitutableNodeTemplate(ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel,
- String substitutableNodeTemplateId,
- NodeTemplate substitutableNodeTemplate,
- ExtractCompositionDataContext context) {
- ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
- Optional<String> substituteServiceTemplateFileName = toscaAnalyzerService
- .getSubstituteServiceTemplateName(substitutableNodeTemplateId, substitutableNodeTemplate);
- if (!substituteServiceTemplateFileName.isPresent()) {
- throw new CoreException(
- new ToscaInvalidSubstituteNodeTemplateErrorBuilder(substitutableNodeTemplateId).build());
- }
- if (context.getHandledServiceTemplates().contains(substituteServiceTemplateFileName.get())) {
- return;
- }
-
- ServiceTemplate substituteServiceTemplate =
- toscaServiceModel.getServiceTemplates().get(substituteServiceTemplateFileName.get());
- extractServiceCompositionData(substituteServiceTemplateFileName.get(),
- substituteServiceTemplate, toscaServiceModel, context);
-
- List<Map<String, RequirementAssignment>> substitutableRequirements =
- substitutableNodeTemplate.getRequirements();
-
- if (CollectionUtils.isEmpty(substitutableRequirements)) {
- return;
- }
-
- for (Map<String, RequirementAssignment> substitutableReq : substitutableRequirements) {
- substitutableReq.keySet().stream().filter(reqId -> {
- RequirementAssignment reqAssignment = toscaExtensionYamlUtil
- .yamlToObject(toscaExtensionYamlUtil.objectToYaml(substitutableReq.get(reqId)),
- RequirementAssignment.class);
- return isLinkToNetworkRequirementAssignment(reqAssignment);
- }).forEach(reqId -> {
- RequirementAssignment linkToNetworkRequirement = toscaExtensionYamlUtil
- .yamlToObject(toscaExtensionYamlUtil.objectToYaml(substitutableReq.get(reqId)),
- RequirementAssignment.class);
- String connectedNodeId = linkToNetworkRequirement.getNode();
- Optional<NodeTemplate> connectedNodeTemplate =
- toscaAnalyzerService.getNodeTemplateById(serviceTemplate, connectedNodeId);
-
- if (connectedNodeTemplate.isPresent() && toscaAnalyzerService
- .isTypeOf(connectedNodeTemplate.get(), ToscaNodeType.NETWORK.getDisplayName(),
- serviceTemplate, toscaServiceModel)) {
- Optional<Map.Entry<String, NodeTemplate>> mappedNodeTemplate = toscaAnalyzerService
- .getSubstitutionMappedNodeTemplateByExposedReq(
- substituteServiceTemplateFileName.get(), substituteServiceTemplate, reqId);
- if (!mappedNodeTemplate.isPresent()) {
- throw new CoreException(new ToscaMissingSubstitutionMappingForReqCapErrorBuilder(
- ToscaMissingSubstitutionMappingForReqCapErrorBuilder.MappingExposedEntry
- .REQUIREMENT, connectedNodeId).build());
- }
-
- if (toscaAnalyzerService.isTypeOf(mappedNodeTemplate.get().getValue(),
- ToscaNodeType.NETWORK_PORT.getDisplayName(), serviceTemplate, toscaServiceModel)) {
- Nic port = context.getNics().get(mappedNodeTemplate.get().getKey());
- if (port != null) {
- port.setNetworkName(connectedNodeId);
- } else {
- logger.warn(
- "Different ports define for the same component which is used in different "
- + "substitution service templates.");
- }
- }
- } else if (!connectedNodeTemplate.isPresent()) {
- throw new CoreException(
- new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", connectedNodeId).build());
- }
- });
- }
- }
-
- private static boolean isLinkToNetworkRequirementAssignment(RequirementAssignment requirement) {
- return toscaAnalyzerService.isDesiredRequirementAssignment(requirement,
- ToscaCapabilityType.NETWORK_LINKABLE.getDisplayName(), null,
- ToscaRelationshipType.NETWORK_LINK_TO.getDisplayName());
- }
-
-
- private static void connectPortToNetwork(Nic port, NodeTemplate portNodeTemplate) {
- List<RequirementAssignment> linkRequirementsToNetwork =
- toscaAnalyzerService.getRequirements(portNodeTemplate, ToscaConstants.LINK_REQUIREMENT_ID);
-
- //port is connected to one network
- for (RequirementAssignment linkRequirementToNetwork : linkRequirementsToNetwork) {
- port.setNetworkName(linkRequirementToNetwork.getNode());
- }
-
- }
-
- /*
- return Map with key - compute node template id, value - list of connected port node template id
- */
- private static Map<String, List<String>> getComputeToPortsConnection(
- Map<String, NodeTemplate> portNodeTemplates) {
- Map<String, List<String>> computeToPortConnection = new HashMap<>();
- if (MapUtils.isEmpty(portNodeTemplates)) {
- return computeToPortConnection;
- }
- for (String portId : portNodeTemplates.keySet()) {
- List<RequirementAssignment> bindingRequirementsToCompute = toscaAnalyzerService
- .getRequirements(portNodeTemplates.get(portId), ToscaConstants.BINDING_REQUIREMENT_ID);
- for (RequirementAssignment bindingRequirementToCompute : bindingRequirementsToCompute) {
- computeToPortConnection
- .putIfAbsent(bindingRequirementToCompute.getNode(), new ArrayList<>());
- computeToPortConnection.get(bindingRequirementToCompute.getNode()).add(portId);
- }
-
- }
-
- return computeToPortConnection;
- }
-
- private static void extractComponents(ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel,
- ExtractCompositionDataContext context) {
- Map<String, NodeTemplate> computeNodeTemplates = toscaAnalyzerService
- .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.COMPUTE.getDisplayName(),
- toscaServiceModel);
- if (MapUtils.isEmpty(computeNodeTemplates)) {
- return;
- }
- Map<String, NodeTemplate> portNodeTemplates = toscaAnalyzerService
- .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.NETWORK_PORT.getDisplayName(),
- toscaServiceModel);
- Map<String, List<String>> computeToPortsConnection =
- getComputeToPortsConnection(portNodeTemplates);
- Map<String, List<String>> computesGroupedByType =
- getNodeTemplatesGroupedByType(computeNodeTemplates);
-
- computesGroupedByType.keySet()
- .stream()
- .filter(nodeType ->
- !context.getCreatedComponents().contains(nodeType))
- .forEach(nodeType -> extractComponent(serviceTemplate, computeToPortsConnection,
- computesGroupedByType, nodeType, context));
- }
-
- private static void extractComponent(ServiceTemplate serviceTemplate,
- Map<String, List<String>> computeToPortsConnection,
- Map<String, List<String>> computesGroupedByType,
- String computeNodeType,
- ExtractCompositionDataContext context) {
- ComponentData component = new ComponentData();
- component.setName(computeNodeType);
- component.setDisplayName(getComponentDisplayName(component.getName()));
- Component componentModel = new Component();
- componentModel.setData(component);
-
- String computeId = computesGroupedByType.get(computeNodeType).get(0);
- List<String> connectedPortIds = computeToPortsConnection.get(computeId);
-
- if (connectedPortIds != null) {
- componentModel.setNics(new ArrayList<>());
- for (String portId : connectedPortIds) {
- Nic port = extractPort(serviceTemplate, portId);
- componentModel.getNics().add(port);
- context.addNic(portId, port);
- }
- }
- context.addComponent(componentModel);
- context.getCreatedComponents().add(computeNodeType);
- }
-
- private static Nic extractPort(ServiceTemplate serviceTemplate, String portNodeTemplateId) {
- Optional<NodeTemplate> portNodeTemplate =
- toscaAnalyzerService.getNodeTemplateById(serviceTemplate, portNodeTemplateId);
- if (portNodeTemplate.isPresent()) {
- Nic port = new Nic();
- port.setName(portNodeTemplateId);
- connectPortToNetwork(port, portNodeTemplate.get());
- return port;
- } else {
- throw new CoreException(
- new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", portNodeTemplateId).build());
- }
- }
-
-
- private static Map<String, List<String>> getNodeTemplatesGroupedByType(
- Map<String, NodeTemplate> nodeTemplates) {
- Map<String, List<String>> nodeTemplatesGrouped =
- new HashMap<>(); //key - node type, value - list of node ids with this type
- for (String nodeId : nodeTemplates.keySet()) {
- String nodeType = nodeTemplates.get(nodeId).getType();
- nodeTemplatesGrouped.putIfAbsent(nodeType, new ArrayList<>());
- nodeTemplatesGrouped.get(nodeType).add(nodeId);
- }
- return nodeTemplatesGrouped;
- }
-
- private static List<Network> extractNetworks(ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel) {
- List<Network> networks = new ArrayList<>();
- Map<String, NodeTemplate> networkNodeTemplates = toscaAnalyzerService
- .getNodeTemplatesByType(serviceTemplate, ToscaNodeType.NETWORK.getDisplayName(),
- toscaServiceModel);
- if (MapUtils.isEmpty(networkNodeTemplates)) {
- return networks;
- }
- for (String networkId : networkNodeTemplates.keySet()) {
- Network network = new Network();
- network.setName(networkId);
- Optional<Boolean> networkDhcpValue =
- getNetworkDhcpValue(serviceTemplate, networkNodeTemplates.get(networkId));
- network.setDhcp(networkDhcpValue.isPresent() ? networkDhcpValue.get() : true);
- networks.add(network);
- }
-
- return networks;
- }
-
- //dhcp default value is true
- private static Optional<Boolean> getNetworkDhcpValue(ServiceTemplate serviceTemplate,
- NodeTemplate networkNodeTemplate) {
- if (networkNodeTemplate == null) {
- return Optional.empty();
- }
- if (networkNodeTemplate.getProperties() == null
- || networkNodeTemplate.getProperties().get(ToscaConstants.DHCP_ENABLED_PROPERTY_NAME)
- == null) {
- return Optional.of(true);
- }
-
- Object dhcp =
- networkNodeTemplate.getProperties().get(ToscaConstants.DHCP_ENABLED_PROPERTY_NAME);
- if (dhcp instanceof String) {
- return Optional.of(Boolean.valueOf((String) dhcp));
- } else if (dhcp instanceof Boolean) {
- return Optional.of((Boolean) dhcp);
- } else if (dhcp instanceof Map) {
- String inputParameterName =
- (String) ((Map) dhcp).get(ToscaFunctions.GET_INPUT.getDisplayName());
- if (inputParameterName != null) {
- ParameterDefinition inputParameterDefinition =
- serviceTemplate.getTopology_template().getInputs().get(inputParameterName);
- if (inputParameterDefinition != null) {
- if (inputParameterDefinition.get_default() != null) {
- return Optional.of(Boolean.valueOf(inputParameterDefinition.get_default().toString()));
- }
- } else {
- throw new CoreException(
- new ToscaInvalidEntryNotFoundErrorBuilder("Input Parameter", inputParameterName)
- .build());
- }
- }
- }
-
- return Optional.of(true);
- }
-
- private static String getComponentDisplayName(String componentName) {
- if (componentName == null) {
- return null;
- }
- String delimiterChar = ".";
- if (componentName.contains(delimiterChar)) {
- return componentName.substring(componentName.lastIndexOf(delimiterChar) + 1);
- }
- return componentName;
-
- }
-
-}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionEntityDataManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionEntityDataManager.java
deleted file mode 100644
index e3f56a6578..0000000000
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/CompositionEntityDataManager.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 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.vendorsoftwareproduct.services;
-
-import org.openecomp.core.utilities.json.JsonUtil;
-import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.errors.ErrorCategory;
-import org.openecomp.sdc.common.errors.ErrorCode;
-import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityValidationData;
-import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
-import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * The type Composition entity data manager.
- */
-public class CompositionEntityDataManager {
-
- private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR =
- "COMPOSITION_ENTITY_DATA_MANAGER_ERR";
- private static final String COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG =
- "Invalid input: %s may not be null";
-
- private Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
- CompositionEntityData> entities = new HashMap<>();
- private Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType,
- String> nonDynamicSchemas = new HashMap<>();
- private List<CompositionEntityValidationData> roots = new ArrayList<>();
-
- /**
- * Validate entity composition entity validation data.
- *
- * @param entity the entity
- * @param schemaTemplateContext the schema template context
- * @param schemaTemplateInput the schema template input
- * @return the composition entity validation data
- */
- public static CompositionEntityValidationData validateEntity(
- org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity entity,
- SchemaTemplateContext schemaTemplateContext,
- SchemaTemplateInput schemaTemplateInput) {
- if (entity == null) {
- throw new CoreException(
- new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
- .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage(
- String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity"))
- .build());
- }
- if (schemaTemplateContext == null) {
- throw new CoreException(
- new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
- .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage(
- String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "schema template context"))
- .build());
- }
-
- CompositionEntityValidationData validationData =
- new CompositionEntityValidationData(entity.getType(), entity.getId());
- String json =
- schemaTemplateContext == SchemaTemplateContext.composition ? entity.getCompositionData()
- : entity.getQuestionnaireData();
- validationData.setErrors(JsonUtil.validate(
- json == null ? JsonUtil.object2Json(new Object()) : json,
- SchemaGenerator.generate(schemaTemplateContext, entity.getType(), schemaTemplateInput)));
-
- return validationData;
- }
-
- /**
- * Add entity.
- *
- * @param entity the entity
- * @param schemaTemplateInput the schema template input
- */
- public void addEntity(org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity entity,
- SchemaTemplateInput schemaTemplateInput) {
- if (entity == null) {
- throw new CoreException(
- new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
- .withId(COMPOSITION_ENTITY_DATA_MANAGER_ERR).withMessage(
- String.format(COMPOSITION_ENTITY_DATA_MANAGER_ERR_MSG, "composition entity"))
- .build());
- }
- entities.put(entity.getCompositionEntityId(),
- new CompositionEntityData(entity, schemaTemplateInput));
- }
-
- /**
- * Validate entities questionnaire map.
- *
- * @return the map
- */
- public Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
- Collection<String>> validateEntitiesQuestionnaire() {
- Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
- Collection<String>>
- errorsByEntityId = new HashMap<>();
-
- entities.entrySet().stream().forEach(entry -> {
- Collection<String> errors = validateQuestionnaire(entry.getValue());
- if (errors != null) {
- errorsByEntityId.put(entry.getKey(), errors);
- }
- });
-
- return errorsByEntityId;
- }
-
- /**
- * Build trees.
- */
- public void buildTrees() {
- Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
- CompositionEntityValidationData>
- entitiesValidationData =
- new HashMap<>();
- entities.entrySet().stream().forEach(
- entry -> addValidationDataEntity(entitiesValidationData, entry.getKey(),
- entry.getValue().entity));
- }
-
- /**
- * Gets trees.
- *
- * @return the trees
- */
- public Collection<CompositionEntityValidationData> getTrees() {
- return roots;
- }
-
- /**
- * Add errors to trees.
- *
- * @param errors the errors
- */
- public void addErrorsToTrees(
- Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
- Collection<String>> errors) {
- roots.stream().forEach(root -> addErrorsToTree(root, null, errors));
- }
-
- private void addValidationDataEntity(
- Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
- CompositionEntityValidationData> entitiesValidationData,
- org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId entityId,
- org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity entity) {
- if (entitiesValidationData.containsKey(entityId)) {
- return;
- }
-
- CompositionEntityValidationData validationData =
- new CompositionEntityValidationData(entity.getType(), entity.getId());
- entitiesValidationData.put(entityId, validationData);
-
- org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId parentEntityId =
- entityId.getParentId();
- if (parentEntityId == null) {
- roots.add(validationData);
- } else {
- CompositionEntityData parentEntity = entities.get(parentEntityId);
- if (parentEntity == null) {
- roots.add(validationData);
- } else {
- addValidationDataEntity(entitiesValidationData, parentEntityId, parentEntity.entity);
- entitiesValidationData.get(parentEntityId).addSubEntityValidationData(validationData);
- }
- }
- }
-
- private void addErrorsToTree(CompositionEntityValidationData node,
- org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId parentNodeId,
- Map<org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId,
- Collection<String>> errors) {
- if (node == null) {
- return;
- }
- org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId
- nodeId = new org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId(
- node.getEntityId(), parentNodeId);
- node.setErrors(errors.get(nodeId));
-
- if (node.getSubEntitiesValidationData() != null) {
- node.getSubEntitiesValidationData().stream()
- .forEach(subNode -> addErrorsToTree(subNode, nodeId, errors));
- }
- }
-
- private Collection<String> validateQuestionnaire(CompositionEntityData compositionEntityData) {
- return JsonUtil.validate(
- compositionEntityData.entity.getQuestionnaireData() == null ? JsonUtil
- .object2Json(new Object()) : compositionEntityData.entity.getQuestionnaireData(),
- getSchema(compositionEntityData.entity.getType(), SchemaTemplateContext.questionnaire,
- compositionEntityData.schemaTemplateInput));
- }
-
- private String getSchema(
- org.openecomp.sdc.vendorsoftwareproduct.types
- .composition.CompositionEntityType compositionEntityType,
- SchemaTemplateContext schemaTemplateContext,
- SchemaTemplateInput schemaTemplateInput) {
- return schemaTemplateInput == null ? getNonDynamicSchema(schemaTemplateContext,
- compositionEntityType) : SchemaGenerator
- .generate(schemaTemplateContext, compositionEntityType, schemaTemplateInput);
- }
-
- private String getNonDynamicSchema(SchemaTemplateContext schemaTemplateContext,
- org.openecomp.sdc.vendorsoftwareproduct.types.composition
- .CompositionEntityType compositionEntityType) {
- String schema = nonDynamicSchemas.get(compositionEntityType);
- if (schema == null) {
- schema = SchemaGenerator.generate(schemaTemplateContext, compositionEntityType, null);
- nonDynamicSchemas.put(compositionEntityType, schema);
- }
- return schema;
- }
-
- private static class CompositionEntityData {
- private org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity entity;
- private SchemaTemplateInput schemaTemplateInput;
-
- /**
- * Instantiates a new Composition entity data.
- *
- * @param entity the entity
- * @param schemaTemplateInput the schema template input
- */
- public CompositionEntityData(
- org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity entity,
- SchemaTemplateInput schemaTemplateInput) {
- this.entity = entity;
- this.schemaTemplateInput = schemaTemplateInput;
- }
- }
-}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGenerator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGenerator.java
deleted file mode 100644
index 53fe5455fb..0000000000
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGenerator.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 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.vendorsoftwareproduct.services;
-
-import freemarker.template.Template;
-import freemarker.template.TemplateException;
-import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.errors.ErrorCategory;
-import org.openecomp.sdc.common.errors.ErrorCode;
-import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
-import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-
-/**
- * The type Schema generator.
- */
-public class SchemaGenerator {
- /**
- * The constant SCHEMA_GENERATION_ERROR.
- */
- public static final String SCHEMA_GENERATION_ERROR = "SCHEMA_GENERATION_ERROR";
-
- /**
- * Generate string.
- *
- * @param schemaTemplateContext the schema template context
- * @param entityType the entity type
- * @param input the input
- * @return the string
- */
- public static String generate(SchemaTemplateContext schemaTemplateContext,
- org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType entityType,
- SchemaTemplateInput input) {
- Template schemaTemplate =
- SchemaGeneratorConfig.getSchemaTemplate(schemaTemplateContext, entityType);
- return processTemplate(input, schemaTemplate);
- }
-
- private static String processTemplate(SchemaTemplateInput input, Template schemaTemplate) {
- try (Writer writer = new StringWriter(1024)) {
- schemaTemplate.process(input, writer);
- return writer.toString();
- } catch (IOException | TemplateException exception) {
- throw new CoreException(
- new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
- .withId(SCHEMA_GENERATION_ERROR).withMessage(exception.getMessage()).build());
- }
- }
-}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGeneratorConfig.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGeneratorConfig.java
deleted file mode 100644
index 034d8520fb..0000000000
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/SchemaGeneratorConfig.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 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.vendorsoftwareproduct.services;
-
-import freemarker.cache.StringTemplateLoader;
-import freemarker.template.Configuration;
-import freemarker.template.Template;
-import freemarker.template.TemplateExceptionHandler;
-import org.openecomp.core.utilities.applicationconfig.ApplicationConfig;
-import org.openecomp.core.utilities.applicationconfig.ApplicationConfigFactory;
-import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
-import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.errors.ErrorCategory;
-import org.openecomp.sdc.common.errors.ErrorCode;
-import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * The type Schema generator config.
- */
-public class SchemaGeneratorConfig {
- /**
- * The constant SCHEMA_GENERATOR_INITIALIZATION_ERROR.
- */
- public static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR =
- "SCHEMA_GENERATOR_INITIALIZATION_ERROR";
- /**
- * The constant SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG.
- */
- public static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG =
- "Error occurred while loading questionnaire schema schemaTemplates";
- private static final String CONFIGURATION_NAMESPACE = "vsp.schemaTemplates";
- private static Map<SchemaTemplateId, SchemaTemplate> schemaTemplates = new HashMap<>();
- private static ApplicationConfig applicationConfig =
- ApplicationConfigFactory.getInstance().createInterface();
-
- private static Configuration configuration = new Configuration(Configuration.VERSION_2_3_23);
- private static StringTemplateLoader stringLoader = new StringTemplateLoader();
-
- static {
- configuration.setClassLoaderForTemplateLoading(SchemaGenerator.class.getClassLoader(),
- File.pathSeparator);
- configuration.setDefaultEncoding("UTF-8");
- configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
- configuration.setLogTemplateExceptions(true);
- configuration.setTemplateLoader(stringLoader);
- }
-
- /**
- * Insert schema template.
- *
- * @param schemaTemplateContext the schema template context
- * @param entityType the entity type
- * @param schemaTemplateString the schema template string
- */
- public static void insertSchemaTemplate(SchemaTemplateContext schemaTemplateContext,
- org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType entityType,
- String schemaTemplateString) {
- applicationConfig.insertValue(CONFIGURATION_NAMESPACE,
- new SchemaTemplateId(schemaTemplateContext, entityType).toString(), schemaTemplateString);
- }
-
- /**
- * Gets schema template.
- *
- * @param schemaTemplateContext the schema template context
- * @param entityType the entity type
- * @return the schema template
- */
- public static Template getSchemaTemplate(SchemaTemplateContext schemaTemplateContext,
- org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType entityType) {
- SchemaTemplateId id = new SchemaTemplateId(schemaTemplateContext, entityType);
- ConfigurationData configurationData =
- applicationConfig.getConfigurationData(CONFIGURATION_NAMESPACE, id.toString());
-
- SchemaTemplate schemaTemplate = schemaTemplates.get(id);
- if (schemaTemplate == null || schemaTemplate.timestamp != configurationData.getTimeStamp()) {
- stringLoader.putTemplate(id.toString(), configurationData.getValue());
- Template template;
- try {
- template = configuration.getTemplate(id.toString());
- } catch (IOException exception) {
- throw new CoreException(
- new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
- .withId(SCHEMA_GENERATOR_INITIALIZATION_ERROR)
- .withMessage(SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG).build(), exception);
- }
- schemaTemplate = new SchemaTemplate(template, configurationData.getTimeStamp());
- schemaTemplates.put(id, schemaTemplate);
- }
- return schemaTemplate.template;
- }
-
- private static class SchemaTemplateId {
- private SchemaTemplateContext context;
- private org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType
- entityType;
-
- /**
- * Instantiates a new Schema template id.
- *
- * @param context the context
- * @param entityType the entity type
- */
- public SchemaTemplateId(SchemaTemplateContext context,
- org.openecomp.sdc.vendorsoftwareproduct.types.composition
- .CompositionEntityType entityType) {
- this.context = context;
- this.entityType = entityType;
- }
-
- @Override
- public String toString() {
- return context + "." + entityType;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null || getClass() != obj.getClass()) {
- return false;
- }
-
- SchemaTemplateId that = (SchemaTemplateId) obj;
-
- if (entityType != that.entityType) {
- return false;
- }
- if (context != that.context) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = entityType != null ? entityType.hashCode() : 0;
- result = 31 * result + (context != null ? context.hashCode() : 0);
- return result;
- }
- }
-
- private static class SchemaTemplate {
- private Template template;
- private long timestamp;
-
- /**
- * Instantiates a new Schema template.
- *
- * @param template the template
- * @param timestamp the timestamp
- */
- public SchemaTemplate(Template template, long timestamp) {
- this.template = template;
- this.timestamp = timestamp;
- }
- }
-
-}