aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java19
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java19
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java359
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java98
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java39
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java131
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java801
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java46
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java109
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/SubstitutionFilterConverter.java50
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java24
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java32
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java3
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/EdgeLabelEnum.java1
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/VertexTypeEnum.java25
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java104
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java31
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java10
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/BaseOperation.java34
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java49
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java139
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java48
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java37
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java3
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/RequirementSubstitutionFilterCapabilityDataDefinition.java50
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/RequirementSubstitutionFilterPropertyDataDefinition.java44
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/SubstitutionFilterDataDefinition.java84
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ComponentFieldsEnum.java1
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/SubstitutionMapping.java40
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionFilter.java57
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionMappingExt.java52
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java13
-rw-r--r--common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionMappingExtTest.java45
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java1
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java4
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java27
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/substitutionMappingWithFilter.yaml (renamed from openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/substitutionMappingExt.yaml)0
40 files changed, 1628 insertions, 1017 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
index 85453e33d2..2616801c42 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
@@ -22,6 +22,8 @@
package org.openecomp.sdc.be.components.impl;
+import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
+
import com.google.gson.JsonElement;
import fj.data.Either;
import java.util.ArrayList;
@@ -33,6 +35,7 @@ import java.util.function.Function;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
@@ -98,7 +101,7 @@ public abstract class BaseBusinessLogic {
private static final String FAILED_TO_LOCK_COMPONENT_ERROR = "Failed to lock component {} error - {}";
- private static final Logger log = Logger.getLogger(BaseBusinessLogic.class.getName());
+ private static final Logger log = Logger.getLogger(BaseBusinessLogic.class);
private static final String EMPTY_VALUE = null;
private static final String SCHEMA_DOESN_T_EXISTS_FOR_PROPERTY_OF_TYPE = "Schema doesn't exists for property of type {}";
private static final String PROPERTY_IN_SCHEMA_DEFINITION_INSIDE_PROPERTY_OF_TYPE_DOESN_T_EXIST = "Property in Schema Definition inside property of type {} doesn't exist";
@@ -820,4 +823,18 @@ public abstract class BaseBusinessLogic {
throw new StorageException(storageOperationStatus);
}
+ protected Component getComponent(final String componentId) throws BusinessLogicException {
+
+ final Either<Component, StorageOperationStatus> result = toscaOperationFacade.getToscaElement(componentId);
+
+ if (result.isRight()) {
+ final StorageOperationStatus errorStatus = result.right().value();
+ log.error(BUSINESS_PROCESS_ERROR, this.getClass().getName(),
+ "Failed to fetch component information by component id, error {}", errorStatus);
+ throw new BusinessLogicException(componentsUtils.getResponseFormat(
+ componentsUtils.convertFromStorageResponse(errorStatus)));
+ }
+ return result.left().value();
+ }
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
index 30cfac225b..e9fc6a04cc 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
@@ -975,7 +975,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
if (containerComponent instanceof Service){
Either<ComponentInstance, ResponseFormat> renameEither =
renameServiceFilter((Service) containerComponent, newInstanceName,
- oldComponentInstance.getName());
+ oldComponentInstance.getName());
if (renameEither.isRight()) {
throw new ByResponseFormatComponentException(renameEither.right().value());
}
@@ -1011,8 +1011,9 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
- public Either<ComponentInstance, ResponseFormat> renameServiceFilter(Service containerComponent,
- String newInstanceName, String oldInstanceName) {
+ public Either<ComponentInstance, ResponseFormat> renameServiceFilter(final Service containerComponent,
+ final String newInstanceName,
+ final String oldInstanceName) {
Map<String, CINodeFilterDataDefinition> renamedNodesFilter =
ServiceFilterUtils.getRenamedNodesFilter((Service) containerComponent,
@@ -1144,10 +1145,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
final ComponentInstance componentInstanceToBeUpdated = componentInstanceById.get();
final List<String> directives = componentInstanceToBeUpdated.getDirectives();
- if (CollectionUtils.isNotEmpty(directives)) {
- directives.removeAll(directives);
- componentInstanceToBeUpdated.setDirectives(Collections.emptyList());
- }
+ componentInstanceToBeUpdated.setDirectives(Collections.emptyList());
final Either<ComponentInstance, ResponseFormat> componentInstanceResponseFormatEither =
updateComponentInstanceMetadata(containerComponentType.getValue(), component.getUniqueId(),
componentInstanceToBeUpdated.getUniqueId(), userId, componentInstanceToBeUpdated, true, false);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java
index 48cb80d11d..de6836d993 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogic.java
@@ -271,7 +271,7 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
final Component component = getComponent(componentId);
final Either<Boolean, ResponseFormat> response = nodeFilterValidator
- .validateNodeFilter(component, componentInstanceId, constraints, NodeFilterConstraintAction.UPDATE);
+ .validateFilter(component, componentInstanceId, constraints, NodeFilterConstraintAction.UPDATE);
if (response.isRight()) {
throw new BusinessLogicException(componentsUtils
.getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND, response.right().value().getFormattedMessage()));
@@ -333,21 +333,6 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
return user;
}
- private Component getComponent(final String componentId) throws BusinessLogicException {
-
- final Either<Component, StorageOperationStatus> result =
- toscaOperationFacade.getToscaElement(componentId);
-
- if (result.isRight()) {
- final StorageOperationStatus errorStatus = result.right().value();
- LOGGER.error(BUSINESS_PROCESS_ERROR, this.getClass().getName(),
- "Failed to fetch component information by component id, error {}", errorStatus);
- throw new BusinessLogicException(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(errorStatus)));
- }
- return result.left().value();
- }
-
private Optional<ComponentInstance> getComponentInstance(final String componentInstanceId,
final Component component) {
return component.getComponentInstanceById(componentInstanceId);
@@ -407,7 +392,7 @@ public class ComponentNodeFilterBusinessLogic extends BaseBusinessLogic {
final NodeFilterConstraintAction action,
final String constraint) throws BusinessLogicException {
final Either<Boolean, ResponseFormat> response = nodeFilterValidator
- .validateNodeFilter(component, componentInstanceId, Collections.singletonList(constraint), action);
+ .validateFilter(component, componentInstanceId, Collections.singletonList(constraint), action);
if (response.isRight()) {
throw new BusinessLogicException(componentsUtils
.getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND, response.right().value().getFormattedMessage()));
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java
new file mode 100644
index 0000000000..55c70ed271
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java
@@ -0,0 +1,359 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import static org.openecomp.sdc.be.dao.api.ActionStatus.SUBSTITUTION_FILTER_NOT_FOUND;
+import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
+
+import fj.data.Either;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
+import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
+import org.openecomp.sdc.be.components.validation.NodeFilterValidator;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.SubstitutionFilterOperation;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
+import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
+import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.beans.factory.annotation.Autowired;
+
+@org.springframework.stereotype.Component("componentSubstitutionFilterBusinessLogic")
+public class ComponentSubstitutionFilterBusinessLogic extends BaseBusinessLogic {
+
+ private static final Logger LOGGER = Logger.getLogger(ComponentSubstitutionFilterBusinessLogic.class);
+
+ private final SubstitutionFilterOperation substitutionFilterOperation;
+ private final NodeFilterValidator nodeFilterValidator;
+
+ @Autowired
+ public ComponentSubstitutionFilterBusinessLogic(final IElementOperation elementDao,
+ final IGroupOperation groupOperation,
+ final IGroupInstanceOperation groupInstanceOperation,
+ final IGroupTypeOperation groupTypeOperation,
+ final InterfaceOperation interfaceOperation,
+ final InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
+ final ArtifactsOperations artifactToscaOperation,
+ final SubstitutionFilterOperation substitutionFilterOperation,
+ final NodeFilterValidator nodeFilterValidator) {
+ super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation,
+ interfaceLifecycleTypeOperation, artifactToscaOperation);
+ this.substitutionFilterOperation = substitutionFilterOperation;
+ this.nodeFilterValidator = nodeFilterValidator;
+ }
+
+ public Optional<SubstitutionFilterDataDefinition> createSubstitutionFilterIfNotExist(final String componentId,
+ final String componentInstanceId,
+ final boolean shouldLock,
+ final ComponentTypeEnum componentTypeEnum)
+ throws BusinessLogicException {
+
+ final Component component = getComponent(componentId);
+ final Optional<ComponentInstance> componentInstanceOptional =
+ getComponentInstance(componentInstanceId, component);
+
+ Optional<SubstitutionFilterDataDefinition> substitutionFilterDataDefinition;
+ if (componentInstanceOptional.isPresent()) {
+ substitutionFilterDataDefinition = getSubstitutionFilterDataDefinition(componentInstanceOptional.get());
+ if (substitutionFilterDataDefinition.isPresent()) {
+ return substitutionFilterDataDefinition;
+ }
+ }
+ boolean wasLocked = false;
+ try {
+ if (shouldLock) {
+ lockComponent(component.getUniqueId(), component, "Create Substitution Filter on component");
+ wasLocked = true;
+ }
+ final Either<SubstitutionFilterDataDefinition, StorageOperationStatus> result = substitutionFilterOperation
+ .createSubstitutionFilter(componentId, componentInstanceId);
+ if (result.isRight()) {
+ janusGraphDao.rollback();
+ LOGGER.error(BUSINESS_PROCESS_ERROR,
+ "Failed to Create Substitution filter on component with id {}", componentId);
+ throw new BusinessLogicException(componentsUtils.getResponseFormatByResource(componentsUtils
+ .convertFromStorageResponse(result.right().value()), component.getSystemName()));
+ }
+ substitutionFilterDataDefinition = Optional.ofNullable(result.left().value());
+ if (componentInstanceOptional.isPresent() && substitutionFilterDataDefinition.isPresent()) {
+ componentInstanceOptional.get().setSubstitutionFilter(substitutionFilterDataDefinition.get());
+ }
+ janusGraphDao.commit();
+ LOGGER.debug("Substitution filter successfully created in component {} . ", component.getSystemName());
+ } catch (final Exception e) {
+ janusGraphDao.rollback();
+ LOGGER.error(BUSINESS_PROCESS_ERROR,
+ "Exception occurred during add Component Substitution filter property values: {}", e.getMessage(), e);
+ throw new BusinessLogicException(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ } finally {
+ if (wasLocked) {
+ unlockComponent(component.getUniqueId(), componentTypeEnum);
+ }
+ }
+
+ return substitutionFilterDataDefinition;
+ }
+
+ public Optional<SubstitutionFilterDataDefinition> addSubstitutionFilter(final String componentId,
+ final String componentInstanceId,
+ final NodeFilterConstraintAction action,
+ final String propertyName,
+ final String constraint,
+ final boolean shouldLock,
+ final ComponentTypeEnum componentTypeEnum)
+ throws BusinessLogicException {
+
+ final Component component = getComponent(componentId);
+ SubstitutionFilterDataDefinition substitutionFilterDataDefinition = validateAndReturnSubstitutionFilterDefinition(
+ componentInstanceId,
+ action, constraint, component);
+ boolean wasLocked = false;
+ try {
+ if (shouldLock) {
+ lockComponent(component.getUniqueId(), component, "Add Substitution Filter on Component");
+ wasLocked = true;
+ }
+ final RequirementSubstitutionFilterPropertyDataDefinition newProperty =
+ new RequirementSubstitutionFilterPropertyDataDefinition();
+ newProperty.setName(propertyName);
+ newProperty.setConstraints(Collections.singletonList(constraint));
+ final Either<SubstitutionFilterDataDefinition, StorageOperationStatus> result = substitutionFilterOperation
+ .addNewProperty(componentId, componentInstanceId, substitutionFilterDataDefinition, newProperty);
+
+ if (result.isRight()) {
+ janusGraphDao.rollback();
+ throw new BusinessLogicException(componentsUtils.getResponseFormatByResource(componentsUtils
+ .convertFromStorageResponse(result.right().value()), component.getSystemName()));
+ } else {
+ substitutionFilterDataDefinition = result.left().value();
+ }
+ janusGraphDao.commit();
+ LOGGER.debug("Substitution filter successfully created in component {} . ", component.getSystemName());
+
+ } catch (final Exception e) {
+ janusGraphDao.rollback();
+ LOGGER.error(BUSINESS_PROCESS_ERROR,
+ "Exception occurred during add component substitution filter property values: {}", e.getMessage(), e);
+ throw new BusinessLogicException(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ } finally {
+ if (wasLocked) {
+ unlockComponent(component.getUniqueId(), componentTypeEnum);
+ }
+ }
+ return Optional.ofNullable(substitutionFilterDataDefinition);
+ }
+
+ public Optional<SubstitutionFilterDataDefinition> updateSubstitutionFilter(final String componentId,
+ final String componentInstanceId,
+ final List<String> constraints,
+ final boolean shouldLock,
+ final ComponentTypeEnum componentTypeEnum)
+ throws BusinessLogicException {
+
+ final Component component = getComponent(componentId);
+
+ final Either<Boolean, ResponseFormat> response = nodeFilterValidator
+ .validateFilter(component, componentInstanceId, constraints, NodeFilterConstraintAction.UPDATE);
+ if (response.isRight()) {
+ throw new BusinessLogicException(componentsUtils
+ .getResponseFormat(SUBSTITUTION_FILTER_NOT_FOUND, response.right().value().getFormattedMessage()));
+ }
+ final Optional<ComponentInstance> componentInstance = getComponentInstance(componentInstanceId,
+ component);
+ if (!componentInstance.isPresent()) {
+ throw new BusinessLogicException(ResponseFormatManager.getInstance()
+ .getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ SubstitutionFilterDataDefinition substitutionFilterDataDefinition = componentInstance.get()
+ .getSubstitutionFilter();
+ if (substitutionFilterDataDefinition == null) {
+ throw new BusinessLogicException(componentsUtils.getResponseFormat(SUBSTITUTION_FILTER_NOT_FOUND));
+ }
+ boolean wasLocked = false;
+ try {
+ if (shouldLock) {
+ lockComponent(component.getUniqueId(), component, "Update Substitution Filter on Component");
+ wasLocked = true;
+ }
+ final List<RequirementSubstitutionFilterPropertyDataDefinition> properties = constraints.stream()
+ .map(this::getRequirementSubstitutionFilterPropertyDataDefinition).collect(Collectors.toList());
+ final Either<SubstitutionFilterDataDefinition, StorageOperationStatus> result = substitutionFilterOperation
+ .updateSubstitutionFilter(componentId, componentInstanceId, substitutionFilterDataDefinition, properties);
+
+ if (result.isRight()) {
+ janusGraphDao.rollback();
+ throw new BusinessLogicException(componentsUtils.getResponseFormatByResource(componentsUtils
+ .convertFromStorageResponse(result.right().value()), component.getSystemName()));
+ } else {
+ substitutionFilterDataDefinition = result.left().value();
+ }
+ janusGraphDao.commit();
+ LOGGER.debug("Substitution filter successfully updated in component {} . ", component.getSystemName());
+
+ } catch (final Exception e) {
+ janusGraphDao.rollback();
+ LOGGER.error(BUSINESS_PROCESS_ERROR, this.getClass().getName(),
+ "Exception occurred during update component substitution filter property values: {}", e);
+ throw new BusinessLogicException(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ } finally {
+ if (wasLocked) {
+ unlockComponent(component.getUniqueId(), componentTypeEnum);
+ }
+ }
+ return Optional.ofNullable(substitutionFilterDataDefinition);
+ }
+
+ public Optional<SubstitutionFilterDataDefinition> deleteSubstitutionFilter(final String componentId,
+ final String componentInstanceId,
+ final NodeFilterConstraintAction action,
+ final String constraint,
+ final int position,
+ final boolean shouldLock,
+ final ComponentTypeEnum componentTypeEnum)
+ throws BusinessLogicException {
+
+ final Component component = getComponent(componentId);
+ SubstitutionFilterDataDefinition substitutionFilterDataDefinition =
+ validateAndReturnSubstitutionFilterDefinition(componentInstanceId, action, constraint, component);
+ boolean wasLocked = false;
+ try {
+ if (shouldLock) {
+ lockComponent(component.getUniqueId(), component,"Add Node Filter on Component");
+ wasLocked = true;
+ }
+ final Either<SubstitutionFilterDataDefinition, StorageOperationStatus> result = substitutionFilterOperation
+ .deleteConstraint(componentId, componentInstanceId, substitutionFilterDataDefinition, position);
+ if (result.isRight()) {
+ janusGraphDao.rollback();
+ throw new BusinessLogicException(componentsUtils.getResponseFormatByResource(componentsUtils
+ .convertFromStorageResponse(result.right().value()), component.getSystemName()));
+ } else {
+ substitutionFilterDataDefinition = result.left().value();
+ }
+ janusGraphDao.commit();
+ LOGGER.debug("Substitution filter successfully deleted in component {} . ", component.getSystemName());
+
+ } catch (final Exception e) {
+ janusGraphDao.rollback();
+ LOGGER.error(BUSINESS_PROCESS_ERROR,
+ "Exception occurred during delete component substitution filter property values: {}",
+ e.getMessage(), e);
+ throw new BusinessLogicException(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ } finally {
+ if (wasLocked) {
+ unlockComponent(component.getUniqueId(), componentTypeEnum);
+ }
+ }
+ return Optional.ofNullable(substitutionFilterDataDefinition);
+ }
+
+ private Optional<SubstitutionFilterDataDefinition> getSubstitutionFilterDataDefinition(
+ final ComponentInstance componentInstance) {
+
+ final SubstitutionFilterDataDefinition substitutionFilterDataDefinition =
+ componentInstance.getSubstitutionFilter();
+ if (componentInstance.getSubstitutionFilter() != null) {
+ return Optional.ofNullable(substitutionFilterDataDefinition);
+ }
+ return Optional.empty();
+ }
+
+ private void unlockComponent(final String componentUniqueId,
+ final ComponentTypeEnum componentType) {
+ graphLockOperation.unlockComponent(componentUniqueId, componentType.getNodeType());
+ }
+
+ public User validateUser(final String userId) {
+ final User user = userValidations.validateUserExists(userId);
+ userValidations.validateUserRole(user, Arrays.asList(Role.DESIGNER, Role.ADMIN));
+ return user;
+ }
+
+ private Optional<ComponentInstance> getComponentInstance(final String componentInstanceId,
+ final Component component) {
+ return component.getComponentInstanceById(componentInstanceId);
+ }
+
+ private Optional<SubstitutionFilterDataDefinition> getComponentInstanceSubstitutionFilterDataDefinition(
+ final String componentInstanceId, final Component component)
+ throws BusinessLogicException {
+
+ if (nodeFilterValidator.validateComponentInstanceExist(component, componentInstanceId).isRight()) {
+ throw new BusinessLogicException(componentsUtils
+ .getResponseFormat(SUBSTITUTION_FILTER_NOT_FOUND));
+ }
+ return getComponentInstance(componentInstanceId, component).map(ComponentInstance::getSubstitutionFilter);
+ }
+
+ private SubstitutionFilterDataDefinition validateAndReturnSubstitutionFilterDefinition(
+ final String componentInstanceId, final NodeFilterConstraintAction action, final String constraint,
+ final Component component) throws BusinessLogicException {
+
+ validateSubstitutionFilter(component, componentInstanceId, action, constraint);
+ final Optional<SubstitutionFilterDataDefinition> substitutionFilterDataDefinition =
+ getComponentInstanceSubstitutionFilterDataDefinition(componentInstanceId, component);
+ if (!substitutionFilterDataDefinition.isPresent()) {
+ throw new BusinessLogicException(componentsUtils.getResponseFormat(SUBSTITUTION_FILTER_NOT_FOUND));
+ }
+ return substitutionFilterDataDefinition.get();
+ }
+
+ private void validateSubstitutionFilter(final Component component,
+ final String componentInstanceId,
+ final NodeFilterConstraintAction action,
+ final String constraint) throws BusinessLogicException {
+ final Either<Boolean, ResponseFormat> response = nodeFilterValidator
+ .validateFilter(component, componentInstanceId, Collections.singletonList(constraint), action);
+ if (response.isRight()) {
+ throw new BusinessLogicException(componentsUtils
+ .getResponseFormat(SUBSTITUTION_FILTER_NOT_FOUND, response.right().value().getFormattedMessage()));
+ }
+ }
+
+ private RequirementSubstitutionFilterPropertyDataDefinition getRequirementSubstitutionFilterPropertyDataDefinition(
+ final String constraint) {
+
+ final RequirementSubstitutionFilterPropertyDataDefinition requirementSubstitutionFilterPropertyDataDefinition =
+ new RequirementSubstitutionFilterPropertyDataDefinition();
+ requirementSubstitutionFilterPropertyDataDefinition.setConstraints(Arrays.asList(constraint));
+ return requirementSubstitutionFilterPropertyDataDefinition;
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
index 30632e9012..9716dfae23 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
@@ -53,11 +53,11 @@ public class NodeFilterValidator {
private static final String SOURCE = "Source";
public static final Set<String> comparableTypes = ImmutableSet.of(ToscaPropertyType.STRING.getType(),
- ToscaPropertyType.INTEGER.getType(), ToscaPropertyType.FLOAT.getType());
+ ToscaPropertyType.INTEGER.getType(), ToscaPropertyType.FLOAT.getType());
public static final Set<String> schemableTypes =
- ImmutableSet.of(ToscaPropertyType.MAP.getType(), ToscaPropertyType.LIST.getType());
+ ImmutableSet.of(ToscaPropertyType.MAP.getType(), ToscaPropertyType.LIST.getType());
public static final Set<String> comparableConstraintsOperators =
- ImmutableSet.of(ConstraintConvertor.GREATER_THAN_OPERATOR, ConstraintConvertor.LESS_THAN_OPERATOR);
+ ImmutableSet.of(ConstraintConvertor.GREATER_THAN_OPERATOR, ConstraintConvertor.LESS_THAN_OPERATOR);
protected final ToscaOperationFacade toscaOperationFacade;
protected final ComponentsUtils componentsUtils;
@@ -75,13 +75,13 @@ public class NodeFilterValidator {
final String componentInstanceId) {
if (component == null || StringUtils.isEmpty(componentInstanceId)) {
LOGGER.error("Input data cannot be empty");
- return getErrorResponse(ActionStatus.NODE_FILTER_NOT_FOUND);
+ return getErrorResponse(ActionStatus.FILTER_NOT_FOUND);
}
if (CollectionUtils.isEmpty(component.getComponentInstances()) ||
component.getComponentInstances().stream()
.noneMatch(ci -> ci.getUniqueId().equals(componentInstanceId))) {
LOGGER.error("Component Instance list is empty");
- return getErrorResponse(ActionStatus.NODE_FILTER_NOT_FOUND);
+ return getErrorResponse(ActionStatus.FILTER_NOT_FOUND);
}
return Either.left(Boolean.TRUE);
}
@@ -91,10 +91,10 @@ public class NodeFilterValidator {
return Either.right(errorResponse);
}
- public Either<Boolean, ResponseFormat> validateNodeFilter(final Component parentComponent,
- final String componentInstanceId,
- final List<String> uiConstraints,
- final NodeFilterConstraintAction action) {
+ public Either<Boolean, ResponseFormat> validateFilter(final Component parentComponent,
+ final String componentInstanceId,
+ final List<String> uiConstraints,
+ final NodeFilterConstraintAction action) {
try {
if (NodeFilterConstraintAction.ADD == action || NodeFilterConstraintAction.UPDATE == action) {
for (final String uiConstraint : uiConstraints) {
@@ -122,44 +122,44 @@ public class NodeFilterValidator {
return Either.left(true);
}
- private Either<Boolean, ResponseFormat> validatePropertyConstraint(
- final Component parentComponent,
- final String componentInstanceId, final UIConstraint uiConstraint) {
+ private Either<Boolean, ResponseFormat> validatePropertyConstraint(final Component parentComponent,
+ final String componentInstanceId,
+ final UIConstraint uiConstraint) {
String source = SOURCE;
- final Optional<ComponentInstance> brotherComponentInstance;
+ final Optional<ComponentInstance> optionalComponentInstance;
+ final List<PropertyDefinition> propertyDefinitions = parentComponent.getProperties();
List<? extends PropertyDefinition> sourcePropertyDefinition =
- parentComponent.getName().equals(uiConstraint.getSourceName()) ? parentComponent.getProperties() :
- Collections.emptyList();
-
+ parentComponent.getName().equals(uiConstraint.getSourceName()) &&
+ propertyDefinitions != null ? propertyDefinitions : Collections.emptyList();
if (sourcePropertyDefinition.isEmpty() && !parentComponent.getName().equals(uiConstraint.getSourceName())) {
- brotherComponentInstance = parentComponent.getComponentInstances().stream()
- .filter(componentInstance -> uiConstraint.getSourceName()
- .equals(componentInstance
- .getName()))
- .findFirst();
+ optionalComponentInstance = parentComponent.getComponentInstances().stream()
+ .filter(componentInstance -> uiConstraint.getSourceName()
+ .equals(componentInstance
+ .getName()))
+ .findFirst();
- if (brotherComponentInstance.isPresent()) {
+ if (optionalComponentInstance.isPresent()) {
final List<ComponentInstanceProperty> componentInstanceProperties =
- parentComponent.getComponentInstancesProperties()
- .get(brotherComponentInstance.get().getUniqueId());
+ parentComponent.getComponentInstancesProperties()
+ .get(optionalComponentInstance.get().getUniqueId());
sourcePropertyDefinition =
- componentInstanceProperties == null ? new ArrayList<>() : componentInstanceProperties;
+ componentInstanceProperties == null ? new ArrayList<>() : componentInstanceProperties;
}
}
if (!CollectionUtils.isEmpty(sourcePropertyDefinition)) {
- Optional<? extends PropertyDefinition> sourceSelectedProperty = sourcePropertyDefinition.stream()
- .filter(property -> uiConstraint
- .getValue()
- .equals(property.getName()))
- .findFirst();
+ final Optional<? extends PropertyDefinition> sourceSelectedProperty = sourcePropertyDefinition.stream()
+ .filter(property -> uiConstraint
+ .getValue()
+ .equals(property.getName()))
+ .findFirst();
- Optional<? extends PropertyDefinition> targetComponentInstanceProperty =
- parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
- .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
- .findFirst();
+ final Optional<? extends PropertyDefinition> targetComponentInstanceProperty =
+ parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
+ .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
+ .findFirst();
source = !targetComponentInstanceProperty.isPresent() ? "Target" : SOURCE;
if (sourceSelectedProperty.isPresent() && targetComponentInstanceProperty.isPresent()) {
@@ -167,16 +167,16 @@ public class NodeFilterValidator {
}
}
- String missingProperty =
- source.equals(SOURCE) ? uiConstraint.getValue().toString() : uiConstraint.getServicePropertyName();
+ final String missingProperty =
+ source.equals(SOURCE) ? uiConstraint.getValue().toString() : uiConstraint.getServicePropertyName();
return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.MAPPED_PROPERTY_NOT_FOUND, source, missingProperty));
+ componentsUtils.getResponseFormat(ActionStatus.MAPPED_PROPERTY_NOT_FOUND, source, missingProperty));
}
private Either<Boolean, ResponseFormat> validatePropertyData(UIConstraint uiConstraint,
- Optional<? extends PropertyDefinition> sourceSelectedProperty,
- Optional<? extends PropertyDefinition> targetComponentInstanceProperty) {
+ Optional<? extends PropertyDefinition> sourceSelectedProperty,
+ Optional<? extends PropertyDefinition> targetComponentInstanceProperty) {
if (sourceSelectedProperty.isPresent() && targetComponentInstanceProperty.isPresent()) {
final PropertyDefinition sourcePropDefinition = sourceSelectedProperty.get();
final String sourceType = sourcePropDefinition.getType();
@@ -208,28 +208,28 @@ public class NodeFilterValidator {
}
private Either<Boolean, ResponseFormat> validateStaticValueAndOperator(
- final Component parentComponent,
+ final Component parentComponent,
final String componentInstanceId, final UIConstraint uiConstraint) {
if (!(Objects.nonNull(uiConstraint) && uiConstraint.getValue() instanceof String)) {
return Either.left(false);
}
final Optional<ComponentInstanceProperty> componentInstanceProperty =
- parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
- .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
- .findFirst();
+ parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
+ .filter(property -> uiConstraint.getServicePropertyName().equals(property.getName()))
+ .findFirst();
if (!componentInstanceProperty.isPresent()) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT,
- uiConstraint.getServicePropertyName()));
+ uiConstraint.getServicePropertyName()));
}
if (comparableConstraintsOperators.contains(uiConstraint.getConstraintOperator()) && !comparableTypes.contains(
- componentInstanceProperty.get().getType())) {
+ componentInstanceProperty.get().getType())) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED,
- uiConstraint.getServicePropertyName(), uiConstraint.getConstraintOperator()));
+ uiConstraint.getServicePropertyName(), uiConstraint.getConstraintOperator()));
}
return isValidValueCheck(componentInstanceProperty.get().getType(), String.valueOf(uiConstraint.getValue()),
- uiConstraint.getServicePropertyName());
+ uiConstraint.getServicePropertyName());
}
private Either<Boolean, ResponseFormat> isValidValueCheck(String type, String value, String propertyName) {
@@ -237,13 +237,13 @@ public class NodeFilterValidator {
ToscaPropertyType toscaPropertyType = ToscaPropertyType.isValidType(type);
if (Objects.isNull(toscaPropertyType)) {
return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_PROPERTY_TYPE, type, propertyName));
+ componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_PROPERTY_TYPE, type, propertyName));
}
if (toscaPropertyType.getValidator().isValid(value, null)) {
return Either.left(Boolean.TRUE);
}
return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, value));
+ componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, value));
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java
index cb9918cf32..29ed858031 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java
@@ -21,6 +21,9 @@
*/
package org.openecomp.sdc.be.components.validation;
+import static org.openecomp.sdc.be.dao.api.ActionStatus.USER_INACTIVE;
+
+import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -29,59 +32,57 @@ import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.stereotype.Component;
-import java.util.List;
-
-import static org.openecomp.sdc.be.dao.api.ActionStatus.USER_INACTIVE;
-
@Component
public class UserValidations {
private static final Logger log = Logger.getLogger(UserValidations.class);
private final UserBusinessLogic userAdmin;
- public UserValidations(UserBusinessLogic userAdmin) {
+ public UserValidations(final UserBusinessLogic userAdmin) {
this.userAdmin = userAdmin;
}
- public void validateUserRole(User user, List<Role> roles) {
- Role userRole = Role.valueOf(user.getRole());
- if (roles != null) {
- if (!roles.contains(userRole)) {
- log.debug("user is not in appropriate role to perform action");
- throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION);
- }
+ public void validateUserRole(final User user, final List<Role> roles) {
+ final Role userRole = Role.valueOf(user.getRole());
+ if (roles != null && !roles.contains(userRole)) {
+ log.error(EcompLoggerErrorCode.PERMISSION_ERROR, this.getClass().getName(),
+ "user is not in appropriate role to perform action");
+ throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION);
}
}
- public ActionStatus validateUserExistsActionStatus(String userId) {
+ public ActionStatus validateUserExistsActionStatus(final String userId) {
if (!userAdmin.hasActiveUser(userId)) {
return ActionStatus.RESTRICTED_OPERATION;
}
return ActionStatus.OK;
}
- public User validateUserNotEmpty(User user, String ecompErrorContext) {
- String userId = user.getUserId();
+ public User validateUserNotEmpty(final User user,
+ final String ecompErrorContext) {
+ final String userId = user.getUserId();
if (StringUtils.isEmpty(userId)) {
- log.debug("User header is missing ");
+ log.error(EcompLoggerErrorCode.PERMISSION_ERROR, this.getClass().getName(),
+ "User header is missing ");
BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, user.getUserId());
throw new ByActionStatusComponentException(ActionStatus.MISSING_USER_ID);
}
return user;
}
- public User validateUserExists(String userId) {
- User user = userAdmin.getUser(userId);
+ public User validateUserExists(final String userId) {
+ final User user = userAdmin.getUser(userId);
if (UserStatusEnum.INACTIVE == user.getStatus()) {
throw new ByActionStatusComponentException(USER_INACTIVE, userId);
}
return user;
}
- public User validateUserExists(User user) {
+ public User validateUserExists(final User user) {
return validateUserExists(user.getUserId());
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java
index 7c3e7b7ebd..5f799211cc 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java
@@ -78,10 +78,12 @@ public class ConstraintConvertor {
if (content3 instanceof String || content3 instanceof Number || content3 instanceof Boolean) {
uiConstraint.setValue(content3);
uiConstraint.setSourceType(STATIC_CONSTRAINT);
+ uiConstraint.setSourceName(STATIC_CONSTRAINT);
return uiConstraint;
} else if (content3 instanceof List) {
List list1 = (List) content3;
uiConstraint.setSourceType(STATIC_CONSTRAINT);
+ uiConstraint.setSourceName(STATIC_CONSTRAINT);
uiConstraint.setValue(list1);
return uiConstraint;
} else if (content3 instanceof Map) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
index 7f9219b85a..b3db99dc47 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
@@ -20,6 +20,17 @@
package org.openecomp.sdc.be.datamodel.utils;
+import static java.util.stream.Collectors.groupingBy;
+import static java.util.stream.Collectors.toList;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
@@ -38,6 +49,7 @@ import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.tosca.utils.NodeFilterConverter;
+import org.openecomp.sdc.be.tosca.utils.SubstitutionFilterConverter;
import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
import org.openecomp.sdc.be.ui.model.UiComponentMetadata;
import org.openecomp.sdc.be.ui.model.UiResourceDataTransfer;
@@ -46,18 +58,6 @@ import org.openecomp.sdc.be.ui.model.UiServiceDataTransfer;
import org.openecomp.sdc.be.ui.model.UiServiceMetadata;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import static java.util.stream.Collectors.groupingBy;
-import static java.util.stream.Collectors.toList;
-
@org.springframework.stereotype.Component("uiComponentDataConverter")
public class UiComponentDataConverter {
@@ -66,12 +66,14 @@ public class UiComponentDataConverter {
private final GroupTypeBusinessLogic groupTypeBusinessLogic;
private final PolicyTypeBusinessLogic policyTypeBusinessLogic;
- public UiComponentDataConverter(GroupTypeBusinessLogic groupTypeBusinessLogic, PolicyTypeBusinessLogic policyTypeBusinessLogic) {
+ public UiComponentDataConverter(GroupTypeBusinessLogic groupTypeBusinessLogic,
+ PolicyTypeBusinessLogic policyTypeBusinessLogic) {
this.groupTypeBusinessLogic = groupTypeBusinessLogic;
this.policyTypeBusinessLogic = policyTypeBusinessLogic;
}
- private void setUiTranferDataByFieldName(UiComponentDataTransfer dataTransfer, Component component, String fieldName) {
+ private void setUiTranferDataByFieldName(UiComponentDataTransfer dataTransfer, Component component,
+ String fieldName) {
ComponentFieldsEnum field = ComponentFieldsEnum.findByValue(fieldName);
if (field == null) {
log.error(INVALID_INPUT_GIVEN_TO_DATA_CONVERTER, fieldName);
@@ -126,6 +128,9 @@ public class UiComponentDataConverter {
case NODE_FILTER:
setNodeFilter(dataTransfer, component);
break;
+ case SUBSTITUTION_FILTER:
+ setSubstitutionFilter(dataTransfer, component);
+ break;
case COMPONENT_INSTANCES_INTERFACES:
setComponentInstanceInterfaces(dataTransfer, component);
break;
@@ -141,34 +146,46 @@ public class UiComponentDataConverter {
}
private void setNodeFilter(UiComponentDataTransfer dataTransfer, Component component) {
- if(component.getNodeFilterComponents() == null) {
- dataTransfer.setNodeFilter(null);
+ if (component.getNodeFilterComponents() == null) {
+ dataTransfer.setNodeFilter(null);
+ } else {
+ dataTransfer.setNodeFilter(component.getNodeFilterComponents());
+ }
+ }
+
+ private void setSubstitutionFilter(final UiComponentDataTransfer dataTransfer,
+ final Component component) {
+ if (component.getSubstitutionFilterComponents() == null) {
+ dataTransfer.setSubstitutionFilter(null);
} else {
- dataTransfer.setNodeFilter(component.getNodeFilterComponents());
+ dataTransfer.setSubstitutionFilter(component.getSubstitutionFilterComponents());
}
}
private void setPolicies(UiComponentDataTransfer dataTransfer, Component component) {
Map<String, PolicyDefinition> policies = component.getPolicies();
Set<PolicyDefinition> policyDefinitions =
- MapUtils.isEmpty(policies) ? new HashSet<>() : new HashSet<>(policies.values());
+ MapUtils.isEmpty(policies) ? new HashSet<>() : new HashSet<>(policies.values());
policyDefinitions.addAll(getDeclaredPolicies(component.getComponentInstancesProperties()));
dataTransfer.setPolicies(new ArrayList<>(policyDefinitions));
}
- private Set<PolicyDefinition> getDeclaredPolicies(Map<String, List<ComponentInstanceProperty>> componentInstanceProperties) {
- if(MapUtils.isEmpty(componentInstanceProperties)) {
+ private Set<PolicyDefinition> getDeclaredPolicies(
+ Map<String, List<ComponentInstanceProperty>> componentInstanceProperties) {
+ if (MapUtils.isEmpty(componentInstanceProperties)) {
return new HashSet<>();
}
Set<PolicyDefinition> declaredPolicies = new HashSet<>();
- for(Map.Entry<String, List<ComponentInstanceProperty>> instancePropertyEntry : componentInstanceProperties.entrySet()) {
+ for (Map.Entry<String, List<ComponentInstanceProperty>> instancePropertyEntry : componentInstanceProperties
+ .entrySet()) {
declaredPolicies.addAll(instancePropertyEntry.getValue().stream()
- .filter(property -> CollectionUtils.isNotEmpty(property.getGetPolicyValues()))
- .map(instanceProperty -> PolicyUtils.getDeclaredPolicyDefinition(instancePropertyEntry.getKey(), instanceProperty))
- .collect(Collectors.toSet()));
+ .filter(property -> CollectionUtils.isNotEmpty(property.getGetPolicyValues()))
+ .map(instanceProperty -> PolicyUtils
+ .getDeclaredPolicyDefinition(instancePropertyEntry.getKey(), instanceProperty))
+ .collect(Collectors.toSet()));
}
return declaredPolicies;
@@ -198,6 +215,7 @@ public class UiComponentDataConverter {
dataTransfer.setComponentInstancesInputs(component.getComponentInstancesInputs());
}
}
+
private void setComponentInstanceAttributes(UiComponentDataTransfer dataTransfer, Component component) {
if (component.getComponentInstancesAttributes() == null) {
dataTransfer.setComponentInstancesAttributes(new HashMap<>());
@@ -205,6 +223,7 @@ public class UiComponentDataConverter {
dataTransfer.setComponentInstancesAttributes(component.getComponentInstancesAttributes());
}
}
+
private void setArtifacts(UiComponentDataTransfer dataTransfer, Component component) {
if (component.getArtifacts() == null) {
dataTransfer.setArtifacts(new HashMap<>());
@@ -212,6 +231,7 @@ public class UiComponentDataConverter {
dataTransfer.setArtifacts(component.getArtifacts());
}
}
+
private void setToscaArtifacts(UiComponentDataTransfer dataTransfer, Component component) {
if (component.getToscaArtifacts() == null) {
dataTransfer.setToscaArtifacts(new HashMap<>());
@@ -244,13 +264,13 @@ public class UiComponentDataConverter {
}
}
- private Map<String,List<CapabilityDefinition>> getFilteredCapabilities(Component component) {
- if(component.getComponentType() != ComponentTypeEnum.SERVICE){
+ private Map<String, List<CapabilityDefinition>> getFilteredCapabilities(Component component) {
+ if (component.getComponentType() != ComponentTypeEnum.SERVICE) {
return component.getCapabilities().values()
- .stream()
- .flatMap(Collection::stream)
- .filter(c -> c.getOwnerType() != CapabilityDataDefinition.OwnerType.GROUP)
- .collect(groupingBy(CapabilityDefinition::getType, toList()));
+ .stream()
+ .flatMap(Collection::stream)
+ .filter(c -> c.getOwnerType() != CapabilityDataDefinition.OwnerType.GROUP)
+ .collect(groupingBy(CapabilityDefinition::getType, toList()));
}
return component.getCapabilities();
}
@@ -308,24 +328,27 @@ public class UiComponentDataConverter {
if (groups == null) {
dataTransfer.setGroups(new ArrayList<>());
} else {
- Set<String> nonExcludedGroupTypes = groupTypeBusinessLogic.getExcludedGroupTypes(component.getActualComponentType());
+ Set<String> nonExcludedGroupTypes = groupTypeBusinessLogic
+ .getExcludedGroupTypes(component.getActualComponentType());
List<GroupDefinition> nonExcludedGroups = groups.stream()
- .filter(gd -> !nonExcludedGroupTypes.contains(gd.getType()))
- .collect(toList());
+ .filter(gd -> !nonExcludedGroupTypes.contains(gd.getType()))
+ .collect(toList());
dataTransfer.setGroups(nonExcludedGroups);
}
}
private void setNonExcludedPolicies(UiComponentDataTransfer dataTransfer, Component component) {
List<PolicyDefinition> policyDefinitions = component.resolvePoliciesList();
- Set<String> nonExcludedPolicyTypes = policyTypeBusinessLogic.getExcludedPolicyTypes(component.getActualComponentType());
+ Set<String> nonExcludedPolicyTypes = policyTypeBusinessLogic
+ .getExcludedPolicyTypes(component.getActualComponentType());
List<PolicyDefinition> nonExcludedPolicies = policyDefinitions.stream()
- .filter(pd -> !nonExcludedPolicyTypes.contains(pd.getPolicyTypeName()))
- .collect(toList());
+ .filter(pd -> !nonExcludedPolicyTypes.contains(pd.getPolicyTypeName()))
+ .collect(toList());
dataTransfer.setPolicies(nonExcludedPolicies);
}
- public UiComponentDataTransfer getUiDataTransferFromResourceByParams(Resource resource, List<String> paramsToReturn) {
+ public UiComponentDataTransfer getUiDataTransferFromResourceByParams(Resource resource,
+ List<String> paramsToReturn) {
UiResourceDataTransfer dataTransfer = new UiResourceDataTransfer();
for (String fieldName : paramsToReturn) {
@@ -348,7 +371,10 @@ public class UiComponentDataConverter {
setAdditionalInfo(resource, dataTransfer);
break;
case METADATA:
- UiResourceMetadata metadata = new UiResourceMetadata(resource.getCategories(), resource.getDerivedFrom(), (ResourceMetadataDataDefinition) resource.getComponentMetadataDefinition().getMetadataDataDefinition());
+ UiResourceMetadata metadata = new UiResourceMetadata(resource.getCategories(),
+ resource.getDerivedFrom(),
+ (ResourceMetadataDataDefinition) resource.getComponentMetadataDefinition()
+ .getMetadataDataDefinition());
dataTransfer.setMetadata(metadata);
break;
@@ -400,17 +426,28 @@ public class UiComponentDataConverter {
setForwardingPaths(service, dataTransfer);
break;
case METADATA:
- UiServiceMetadata metadata = new UiServiceMetadata(service.getCategories(), (ServiceMetadataDataDefinition) service.getComponentMetadataDefinition().getMetadataDataDefinition());
+ UiServiceMetadata metadata = new UiServiceMetadata(service.getCategories(),
+ (ServiceMetadataDataDefinition) service.getComponentMetadataDefinition()
+ .getMetadataDataDefinition());
dataTransfer.setMetadata(metadata);
break;
case NODE_FILTER:
- if(service.getNodeFilterComponents() == null) {
+ if (service.getNodeFilterComponents() == null) {
dataTransfer.setNodeFilterforNode(null);
} else {
- NodeFilterConverter nodeFilterConverter = new NodeFilterConverter();
- dataTransfer.setNodeFilterforNode(nodeFilterConverter.convertDataMapToUI(service.getNodeFilterComponents()));
+ final NodeFilterConverter nodeFilterConverter = new NodeFilterConverter();
+ dataTransfer.setNodeFilterforNode(
+ nodeFilterConverter.convertDataMapToUI(service.getNodeFilterComponents()));
+ }
+ break;
+ case SUBSTITUTION_FILTER:
+ if (service.getSubstitutionFilterComponents() == null) {
+ dataTransfer.setSubstitutionFilterForTopologyTemplate(null);
+ } else {
+ final SubstitutionFilterConverter substitutionFilterConverter = new SubstitutionFilterConverter();
+ dataTransfer.setSubstitutionFilterForTopologyTemplate(substitutionFilterConverter
+ .convertDataMapToUI(service.getSubstitutionFilterComponents()));
}
-
break;
default:
setUiTranferDataByFieldName(dataTransfer, service, fieldName);
@@ -441,10 +478,14 @@ public class UiComponentDataConverter {
switch (component.getComponentType()) {
case RESOURCE:
Resource resource = (Resource) component;
- uiComponentMetadata = new UiResourceMetadata(component.getCategories(), resource.getDerivedFrom(), (ResourceMetadataDataDefinition) resource.getComponentMetadataDefinition().getMetadataDataDefinition());
+ uiComponentMetadata = new UiResourceMetadata(component.getCategories(), resource.getDerivedFrom(),
+ (ResourceMetadataDataDefinition) resource.getComponentMetadataDefinition()
+ .getMetadataDataDefinition());
break;
case SERVICE:
- uiComponentMetadata = new UiServiceMetadata(component.getCategories(), (ServiceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition());
+ uiComponentMetadata = new UiServiceMetadata(component.getCategories(),
+ (ServiceMetadataDataDefinition) component.getComponentMetadataDefinition()
+ .getMetadataDataDefinition());
break;
default:
break;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index aa9cd8ce49..13a90a822f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -1,22 +1,22 @@
/*-
-* ============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
-*
+ * ============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=========================================================
-*/
+ * 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.be.tosca;
@@ -60,6 +60,8 @@ import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
@@ -140,20 +142,22 @@ public class ToscaExportHandler {
@Autowired
public ToscaExportHandler(ApplicationDataTypeCache dataTypeCache, ToscaOperationFacade toscaOperationFacade,
- CapabilityRequirementConverter capabilityRequirementConverter, PolicyExportParser policyExportParser,
- GroupExportParser groupExportParser, PropertyConvertor propertyConvertor, InputConverter inputConverter,
- InterfaceLifecycleOperation interfaceLifecycleOperation,
- InterfacesOperationsConverter interfacesOperationsConverter) {
- this.dataTypeCache = dataTypeCache;
- this.toscaOperationFacade = toscaOperationFacade;
- this.capabilityRequirementConverter = capabilityRequirementConverter;
- this.policyExportParser = policyExportParser;
- this.groupExportParser = groupExportParser;
- this.propertyConvertor = propertyConvertor;
- this.inputConverter = inputConverter;
- this.interfaceLifecycleOperation = interfaceLifecycleOperation;
- this.interfacesOperationsConverter = interfacesOperationsConverter;
- }
+ CapabilityRequirementConverter capabilityRequirementConverter,
+ PolicyExportParser policyExportParser,
+ GroupExportParser groupExportParser, PropertyConvertor propertyConvertor,
+ InputConverter inputConverter,
+ InterfaceLifecycleOperation interfaceLifecycleOperation,
+ InterfacesOperationsConverter interfacesOperationsConverter) {
+ this.dataTypeCache = dataTypeCache;
+ this.toscaOperationFacade = toscaOperationFacade;
+ this.capabilityRequirementConverter = capabilityRequirementConverter;
+ this.policyExportParser = policyExportParser;
+ this.groupExportParser = groupExportParser;
+ this.propertyConvertor = propertyConvertor;
+ this.inputConverter = inputConverter;
+ this.interfaceLifecycleOperation = interfaceLifecycleOperation;
+ this.interfacesOperationsConverter = interfacesOperationsConverter;
+ }
private static final String TOSCA_VERSION = "tosca_simple_yaml_1_1";
private static final String SERVICE_NODE_TYPE_PREFIX = "org.openecomp.service.";
@@ -167,7 +171,8 @@ public class ToscaExportHandler {
private static final String NATIVE_ROOT = "tosca.nodes.Root";
private static YamlUtil yamlUtil = new YamlUtil();
- public ToscaExportHandler(){}
+ public ToscaExportHandler() {
+ }
public Either<ToscaRepresentation, ToscaError> exportComponent(Component component) {
return convertToToscaTemplate(component).left().map(this::createToscaRepresentation);
@@ -225,7 +230,7 @@ public class ToscaExportHandler {
public Either<ToscaTemplate, ToscaError> getDependencies(Component component) {
ToscaTemplate toscaTemplate = new ToscaTemplate(null);
Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> fillImports = fillImports(component,
- toscaTemplate);
+ toscaTemplate);
if (fillImports.isRight()) {
return Either.right(fillImports.right().value());
}
@@ -259,17 +264,17 @@ public class ToscaExportHandler {
private Either<ToscaTemplate, ToscaError> convertToscaTemplate(Component component, ToscaTemplate toscaNode) {
Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> importsRes = fillImports(component,
- toscaNode);
+ toscaNode);
if (importsRes.isRight()) {
return Either.right(importsRes.right().value());
}
toscaNode = importsRes.left().value().left;
Map<String, Component> componentCache = importsRes.left().value().right;
Either<Map<String, ToscaNodeType>, ToscaError> nodeTypesMapEither = createProxyNodeTypes(componentCache,
- component);
+ component);
if (nodeTypesMapEither.isRight()) {
log.debug("Failed to fetch normative service proxy resource by tosca name, error {}",
- nodeTypesMapEither.right().value());
+ nodeTypesMapEither.right().value());
return Either.right(nodeTypesMapEither.right().value());
}
Map<String, ToscaNodeType> nodeTypesMap = nodeTypesMapEither.left().value();
@@ -280,7 +285,7 @@ public class ToscaExportHandler {
Either<Map<String, Object>, ToscaError> proxyInterfaceTypesEither = createProxyInterfaceTypes(component);
if (proxyInterfaceTypesEither.isRight()) {
log.debug("Failed to populate service proxy local interface types in tosca, error {}",
- nodeTypesMapEither.right().value());
+ nodeTypesMapEither.right().value());
return Either.right(proxyInterfaceTypesEither.right().value());
}
Map<String, Object> proxyInterfaceTypes = proxyInterfaceTypesEither.left().value();
@@ -302,61 +307,59 @@ public class ToscaExportHandler {
topologyTemplate.setInputs(inputs);
}
- List<ComponentInstance> componentInstances = component.getComponentInstances();
+ final List<ComponentInstance> componentInstances = component.getComponentInstances();
Map<String, List<ComponentInstanceProperty>> componentInstancesProperties =
- component.getComponentInstancesProperties();
+ component.getComponentInstancesProperties();
Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces =
component.getComponentInstancesInterfaces();
- if (componentInstances != null && !componentInstances.isEmpty()) {
-
- Either<Map<String, ToscaNodeTemplate>, ToscaError> nodeTemplates =
- convertNodeTemplates(component, componentInstances,
- componentInstancesProperties, componentInstanceInterfaces,
- componentCache, dataTypes, topologyTemplate);
+ SubstitutionMapping substitutionMapping = new SubstitutionMapping();
+ if (CollectionUtils.isNotEmpty(componentInstances)) {
+ final Either<Map<String, ToscaNodeTemplate>, ToscaError> nodeTemplates =
+ convertNodeTemplates(component, componentInstances,
+ componentInstancesProperties, componentInstanceInterfaces,
+ componentCache, dataTypes, topologyTemplate);
if (nodeTemplates.isRight()) {
return Either.right(nodeTemplates.right().value());
}
log.debug("node templates converted");
-
topologyTemplate.setNode_templates(nodeTemplates.left().value());
- }
+ convertSubstitutionMappingFilter(componentInstances, substitutionMapping);
+ }
addGroupsToTopologyTemplate(component, topologyTemplate);
try {
addPoliciesToTopologyTemplate(component, topologyTemplate);
} catch (SdcResourceNotFoundException e) {
- log.debug("Fail to add policies to topology template:",e);
+ log.debug("Fail to add policies to topology template:", e);
return Either.right(ToscaError.GENERAL_ERROR);
}
-
- SubstitutionMapping substitutionMapping = new SubstitutionMapping();
String toscaResourceName;
switch (component.getComponentType()) {
- case RESOURCE:
- toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition()
+ case RESOURCE:
+ toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition()
.getMetadataDataDefinition()).getToscaResourceName();
- break;
- case SERVICE:
- toscaResourceName = SERVICE_NODE_TYPE_PREFIX
+ break;
+ case SERVICE:
+ toscaResourceName = SERVICE_NODE_TYPE_PREFIX
+ component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
- break;
- default:
- log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
- return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
+ break;
+ default:
+ log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
+ return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
}
substitutionMapping.setNode_type(toscaResourceName);
-
- Either<SubstitutionMapping, ToscaError> capabilities = convertCapabilities(component, substitutionMapping, componentCache);
+ Either<SubstitutionMapping, ToscaError> capabilities = convertCapabilities(component, substitutionMapping,
+ componentCache);
if (capabilities.isRight()) {
return Either.right(capabilities.right().value());
}
substitutionMapping = capabilities.left().value();
Either<SubstitutionMapping, ToscaError> requirements = capabilityRequirementConverter
- .convertSubstitutionMappingRequirements(componentCache, component, substitutionMapping);
+ .convertSubstitutionMappingRequirements(componentCache, component, substitutionMapping);
if (requirements.isRight()) {
return Either.right(requirements.right().value());
}
@@ -369,27 +372,42 @@ public class ToscaExportHandler {
return Either.left(toscaNode);
}
- private void addGroupsToTopologyTemplate(Component component, ToscaTopolgyTemplate topologyTemplate) {
+ private void convertSubstitutionMappingFilter(final List<ComponentInstance> componentInstances,
+ final SubstitutionMapping substitutionMapping) {
+ componentInstances.stream()
+ .filter(componentInstance -> hasSubstitutionFilterDataDefinition(componentInstance.getSubstitutionFilter()))
+ .forEach(componentInstance -> substitutionMapping
+ .setSubstitution_filter(convertToSubstitutionFilterComponent(componentInstance.getSubstitutionFilter())));
+ }
+
+ private boolean hasSubstitutionFilterDataDefinition(
+ final SubstitutionFilterDataDefinition substitutionFilterDataDefinition) {
+
+ return substitutionFilterDataDefinition != null && substitutionFilterDataDefinition.getProperties() != null
+ && CollectionUtils.isNotEmpty(substitutionFilterDataDefinition.getProperties().getListToscaDataDefinition());
+ }
+
+ private void addGroupsToTopologyTemplate(Component component, ToscaTopolgyTemplate topologyTemplate) {
Map<String, ToscaGroupTemplate> groups = groupExportParser.getGroups(component);
- if(groups!= null) {
+ if (groups != null) {
topologyTemplate.addGroups(groups);
}
}
- private void addPoliciesToTopologyTemplate(Component component, ToscaTopolgyTemplate topologyTemplate)
- throws SdcResourceNotFoundException {
- Map<String, ToscaPolicyTemplate> policies = policyExportParser.getPolicies(component);
- if(policies!= null) {
- topologyTemplate.addPolicies(policies);
- }
- }
+ private void addPoliciesToTopologyTemplate(Component component, ToscaTopolgyTemplate topologyTemplate)
+ throws SdcResourceNotFoundException {
+ Map<String, ToscaPolicyTemplate> policies = policyExportParser.getPolicies(component);
+ if (policies != null) {
+ topologyTemplate.addPolicies(policies);
+ }
+ }
private ToscaMetadata convertMetadata(Component component) {
return convertMetadata(component, false, null);
}
private ToscaMetadata convertMetadata(Component component, boolean isInstance,
- ComponentInstance componentInstance) {
+ ComponentInstance componentInstance) {
ToscaMetadata toscaMetadata = new ToscaMetadata();
toscaMetadata.setInvariantUUID(component.getInvariantUUID());
toscaMetadata.setUUID(component.getUUID());
@@ -404,48 +422,48 @@ public class ToscaExportHandler {
toscaMetadata.setVersion(component.getVersion());
toscaMetadata.setCustomizationUUID(componentInstance.getCustomizationUUID());
if (componentInstance.getSourceModelInvariant() != null
- && !componentInstance.getSourceModelInvariant().isEmpty()) {
+ && !componentInstance.getSourceModelInvariant().isEmpty()) {
toscaMetadata.setVersion(componentInstance.getComponentVersion());
toscaMetadata.setSourceModelInvariant(componentInstance.getSourceModelInvariant());
toscaMetadata.setSourceModelUuid(componentInstance.getSourceModelUuid());
toscaMetadata.setSourceModelName(componentInstance.getSourceModelName());
toscaMetadata.setName(
- componentInstance.getSourceModelName() + " " + OriginTypeEnum.ServiceProxy.getDisplayValue());
+ componentInstance.getSourceModelName() + " " + OriginTypeEnum.ServiceProxy.getDisplayValue());
toscaMetadata.setDescription(componentInstance.getDescription());
}
}
switch (component.getComponentType()) {
- case RESOURCE:
- Resource resource = (Resource) component;
+ case RESOURCE:
+ Resource resource = (Resource) component;
- if (isInstance && componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy) {
- toscaMetadata.setType(componentInstance.getOriginType().getDisplayValue());
- } else {
- toscaMetadata.setType(resource.getResourceType().name());
- }
- toscaMetadata.setSubcategory(categoryDefinition.getSubcategories().get(0).getName());
- toscaMetadata.setResourceVendor(resource.getVendorName());
- toscaMetadata.setResourceVendorRelease(resource.getVendorRelease());
- toscaMetadata.setResourceVendorModelNumber(resource.getResourceVendorModelNumber());
- break;
- case SERVICE:
- Service service = (Service) component;
- toscaMetadata.setType(component.getComponentType().getValue());
- toscaMetadata.setServiceType(service.getServiceType());
- toscaMetadata.setServiceRole(service.getServiceRole());
- toscaMetadata.setServiceFunction(service.getServiceFunction());
- toscaMetadata.setEnvironmentContext(service.getEnvironmentContext());
- resolveInstantiationTypeAndSetItToToscaMetaData(toscaMetadata, service);
- if (!isInstance) {
- // DE268546
- toscaMetadata.setServiceEcompNaming(((Service) component).isEcompGeneratedNaming());
- toscaMetadata.setEcompGeneratedNaming(((Service) component).isEcompGeneratedNaming());
- toscaMetadata.setNamingPolicy(((Service) component).getNamingPolicy());
- }
- break;
- default:
- log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
+ if (isInstance && componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy) {
+ toscaMetadata.setType(componentInstance.getOriginType().getDisplayValue());
+ } else {
+ toscaMetadata.setType(resource.getResourceType().name());
+ }
+ toscaMetadata.setSubcategory(categoryDefinition.getSubcategories().get(0).getName());
+ toscaMetadata.setResourceVendor(resource.getVendorName());
+ toscaMetadata.setResourceVendorRelease(resource.getVendorRelease());
+ toscaMetadata.setResourceVendorModelNumber(resource.getResourceVendorModelNumber());
+ break;
+ case SERVICE:
+ Service service = (Service) component;
+ toscaMetadata.setType(component.getComponentType().getValue());
+ toscaMetadata.setServiceType(service.getServiceType());
+ toscaMetadata.setServiceRole(service.getServiceRole());
+ toscaMetadata.setServiceFunction(service.getServiceFunction());
+ toscaMetadata.setEnvironmentContext(service.getEnvironmentContext());
+ resolveInstantiationTypeAndSetItToToscaMetaData(toscaMetadata, service);
+ if (!isInstance) {
+ // DE268546
+ toscaMetadata.setServiceEcompNaming(((Service) component).isEcompGeneratedNaming());
+ toscaMetadata.setEcompGeneratedNaming(((Service) component).isEcompGeneratedNaming());
+ toscaMetadata.setNamingPolicy(((Service) component).getNamingPolicy());
+ }
+ break;
+ default:
+ log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
}
return toscaMetadata;
}
@@ -453,14 +471,13 @@ public class ToscaExportHandler {
private void resolveInstantiationTypeAndSetItToToscaMetaData(ToscaMetadata toscaMetadata, Service service) {
if (service.getInstantiationType() != null) {
toscaMetadata.setInstantiationType(service.getInstantiationType());
- }
- else {
+ } else {
toscaMetadata.setInstantiationType(StringUtils.EMPTY);
}
}
private Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> fillImports(Component component,
- ToscaTemplate toscaTemplate) {
+ ToscaTemplate toscaTemplate) {
if (null == DEFAULT_IMPORTS) {
log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
@@ -470,20 +487,20 @@ public class ToscaExportHandler {
if (!ModelConverter.isAtomicComponent(component)) {
List<Map<String, Map<String, String>>> additionalImports = toscaTemplate.getImports() == null
- ? new ArrayList<>(DEFAULT_IMPORTS) : new ArrayList<>(toscaTemplate.getImports());
+ ? new ArrayList<>(DEFAULT_IMPORTS) : new ArrayList<>(toscaTemplate.getImports());
List<Triple<String, String, Component>> dependecies = new ArrayList<>();
Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
if (isNotEmpty(toscaArtifacts)) {
ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
- if(artifactDefinition != null) {
+ if (artifactDefinition != null) {
Map<String, Map<String, String>> importsListMember = new HashMap<>();
Map<String, String> interfaceFiles = new HashMap<>();
interfaceFiles.put(IMPORTS_FILE_KEY, getInterfaceFilename(artifactDefinition.getArtifactName()));
StringBuilder keyNameBuilder = new StringBuilder();
keyNameBuilder.append(component.getComponentType().toString().toLowerCase()).append("-")
- .append(component.getName()).append("-interface");
+ .append(component.getName()).append("-interface");
importsListMember.put(keyNameBuilder.toString(), interfaceFiles);
additionalImports.add(importsListMember);
}
@@ -500,11 +517,11 @@ public class ToscaExportHandler {
return Either.left(new ImmutablePair<>(toscaTemplate, componentCache));
}
- private void createDependency(final Map<String, Component> componentCache,
+ private void createDependency(final Map<String, Component> componentCache,
final List<Map<String, Map<String, String>>> imports,
final List<Triple<String, String, Component>> dependencies,
final ComponentInstance componentInstance) {
- log.debug("createDependency componentCache {}",componentCache);
+ log.debug("createDependency componentCache {}", componentCache);
final Component componentRI = componentCache.get(componentInstance.getComponentUid());
if (componentRI == null) {
// all resource must be only once!
@@ -513,7 +530,7 @@ public class ToscaExportHandler {
if ((resource.isRight()) && (log.isDebugEnabled())) {
log.debug("Failed to fetch resource with id {} for instance {}", componentInstance.getComponentUid(),
componentInstance.getUniqueId());
- return ;
+ return;
}
final Component fetchedComponent = resource.left().value();
setComponentCache(componentCache, componentInstance, fetchedComponent);
@@ -548,12 +565,13 @@ public class ToscaExportHandler {
final Component fetchedComponent) {
final Set<Component> componentsList = new LinkedHashSet<>();
if (fetchedComponent instanceof Resource) {
- log.debug("fetchedComponent is a resource {}",fetchedComponent);
+ log.debug("fetchedComponent is a resource {}", fetchedComponent);
- final Optional<Map<String, String>> derivedFromMapOfIdToName = getDerivedFromMapOfIdToName(fetchedComponent, componentsList);
+ final Optional<Map<String, String>> derivedFromMapOfIdToName = getDerivedFromMapOfIdToName(fetchedComponent,
+ componentsList);
if (derivedFromMapOfIdToName.isPresent()) {
derivedFromMapOfIdToName.get().entrySet().forEach(entry -> {
- log.debug("Started entry.getValue() : {}",entry.getValue());
+ log.debug("Started entry.getValue() : {}", entry.getValue());
if (!NATIVE_ROOT.equals(entry.getValue())) {
Either<Resource, StorageOperationStatus> resourcefetched = toscaOperationFacade
.getToscaElement(entry.getKey());
@@ -574,13 +592,14 @@ public class ToscaExportHandler {
final Set<Component> componentsList) {
final Resource parentResource = (Resource) fetchedComponent;
Map<String, String> derivedFromMapOfIdToName = new HashMap<>();
- if(CollectionUtils.isNotEmpty(parentResource.getComponentInstances())) {
+ if (CollectionUtils.isNotEmpty(parentResource.getComponentInstances())) {
componentsList.add(fetchedComponent);
for (final ComponentInstance componentInstance : parentResource.getComponentInstances()) {
final Either<Resource, StorageOperationStatus> resourcefetched = toscaOperationFacade
.getToscaElement(componentInstance.getComponentUid());
if (resourcefetched != null && resourcefetched.isLeft()) {
- final Map<String, String> derivedWithId = resourcefetched.left().value().getDerivedFromMapOfIdToName();
+ final Map<String, String> derivedWithId = resourcefetched.left().value()
+ .getDerivedFromMapOfIdToName();
if (MapUtils.isNotEmpty(derivedWithId)) {
derivedFromMapOfIdToName.putAll(derivedWithId);
}
@@ -643,29 +662,30 @@ public class ToscaExportHandler {
return artifactName.substring(0, artifactName.lastIndexOf('.')) + ToscaExportHandler.TOSCA_INTERFACE_NAME;
}
- private Either<ToscaTemplate, ToscaError> convertNodeType(Map<String, Component> componentsCache, Component component, ToscaTemplate toscaNode,
+ private Either<ToscaTemplate, ToscaError> convertNodeType(Map<String, Component> componentsCache,
+ Component component, ToscaTemplate toscaNode,
Map<String, ToscaNodeType> nodeTypes) {
return convertInterfaceNodeType(componentsCache, component, toscaNode, nodeTypes, false);
}
public Either<ToscaTemplate, ToscaError> convertInterfaceNodeType(Map<String, Component> componentsCache,
- Component component, ToscaTemplate toscaNode,
- Map<String, ToscaNodeType> nodeTypes,
- boolean isAssociatedComponent) {
+ Component component, ToscaTemplate toscaNode,
+ Map<String, ToscaNodeType> nodeTypes,
+ boolean isAssociatedComponent) {
log.debug("start convert node type for {}", component.getUniqueId());
ToscaNodeType toscaNodeType = createNodeType(component);
Either<Map<String, InterfaceDefinition>, StorageOperationStatus> lifecycleTypeEither =
- interfaceLifecycleOperation.getAllInterfaceLifecycleTypes();
- if(lifecycleTypeEither.isRight()){
+ interfaceLifecycleOperation.getAllInterfaceLifecycleTypes();
+ if (lifecycleTypeEither.isRight()) {
log.debug("Failed to fetch all interface types :", lifecycleTypeEither.right().value());
return Either.right(ToscaError.GENERAL_ERROR);
}
List<String> allGlobalInterfaceTypes = lifecycleTypeEither.left().value()
- .values()
- .stream()
- .map(InterfaceDataDefinition::getType)
- .collect(Collectors.toList());
+ .values()
+ .stream()
+ .map(InterfaceDataDefinition::getType)
+ .collect(Collectors.toList());
toscaNode.setInterface_types(addInterfaceTypeElement(component, allGlobalInterfaceTypes));
Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> dataTypesEither = dataTypeCache.getAll();
@@ -678,16 +698,17 @@ public class ToscaExportHandler {
List<InputDefinition> inputDef = component.getInputs();
Map<String, ToscaProperty> mergedProperties = new HashMap<>();
- interfacesOperationsConverter.addInterfaceDefinitionElement(component, toscaNodeType, dataTypes, isAssociatedComponent);
+ interfacesOperationsConverter
+ .addInterfaceDefinitionElement(component, toscaNodeType, dataTypes, isAssociatedComponent);
addInputsToProperties(dataTypes, inputDef, mergedProperties);
- if(CollectionUtils.isNotEmpty(component.getProperties())) {
+ if (CollectionUtils.isNotEmpty(component.getProperties())) {
List<PropertyDefinition> properties = component.getProperties();
Map<String, ToscaProperty> convertedProperties = properties.stream()
- .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition, component.getInputs()))
- .collect(Collectors.toMap(PropertyDataDefinition::getName,
- property -> propertyConvertor.convertProperty(dataTypes, property,
- PropertyConvertor.PropertyType.PROPERTY)));
+ .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition, component.getInputs()))
+ .collect(Collectors.toMap(PropertyDataDefinition::getName,
+ property -> propertyConvertor.convertProperty(dataTypes, property,
+ PropertyConvertor.PropertyType.PROPERTY)));
// merge component properties and inputs properties
mergedProperties.putAll(convertedProperties);
}
@@ -697,21 +718,22 @@ public class ToscaExportHandler {
/* convert private data_types */
List<DataTypeDefinition> privateDataTypes = component.getDataTypes();
- if (CollectionUtils.isNotEmpty(privateDataTypes) ) {
+ if (CollectionUtils.isNotEmpty(privateDataTypes)) {
Map<String, ToscaDataType> toscaDataTypeMap = new HashMap<>();
- for (DataTypeDefinition dataType: privateDataTypes) {
+ for (DataTypeDefinition dataType : privateDataTypes) {
log.debug("Emitting private data type: component.name={} dataType.name={}",
- component.getNormalizedName(), dataType.getName());
+ component.getNormalizedName(), dataType.getName());
ToscaDataType toscaDataType = new ToscaDataType();
toscaDataType.setDerived_from(dataType.getDerivedFromName());
toscaDataType.setDescription(dataType.getDescription());
toscaDataType.setVersion(dataType.getVersion());
if (CollectionUtils.isNotEmpty(dataType.getProperties())) {
toscaDataType.setProperties(dataType.getProperties().stream()
- .collect(Collectors.toMap(
- s -> s.getName(),
- s -> propertyConvertor.convertProperty(dataTypes, s, PropertyConvertor.PropertyType.PROPERTY)
- )));
+ .collect(Collectors.toMap(
+ s -> s.getName(),
+ s -> propertyConvertor
+ .convertProperty(dataTypes, s, PropertyConvertor.PropertyType.PROPERTY)
+ )));
}
toscaDataTypeMap.put(dataType.getName(), toscaDataType);
}
@@ -722,17 +744,21 @@ public class ToscaExportHandler {
return convertReqCapAndTypeName(componentsCache, component, toscaNode, nodeTypes, toscaNodeType, dataTypes);
}
- private Either<ToscaTemplate, ToscaError> convertReqCapAndTypeName(Map<String, Component> componentsCache, Component component, ToscaTemplate toscaNode,
- Map<String, ToscaNodeType> nodeTypes, ToscaNodeType toscaNodeType,
- Map<String, DataTypeDefinition> dataTypes) {
- Either<ToscaNodeType, ToscaError> capabilities = convertCapabilities(componentsCache, component, toscaNodeType, dataTypes);
+ private Either<ToscaTemplate, ToscaError> convertReqCapAndTypeName(Map<String, Component> componentsCache,
+ Component component, ToscaTemplate toscaNode,
+ Map<String, ToscaNodeType> nodeTypes,
+ ToscaNodeType toscaNodeType,
+ Map<String, DataTypeDefinition> dataTypes) {
+ Either<ToscaNodeType, ToscaError> capabilities = convertCapabilities(componentsCache, component, toscaNodeType,
+ dataTypes);
if (capabilities.isRight()) {
return Either.right(capabilities.right().value());
}
toscaNodeType = capabilities.left().value();
log.debug("Capabilities converted for {}", component.getUniqueId());
- Either<ToscaNodeType, ToscaError> requirements = capabilityRequirementConverter.convertRequirements(componentsCache, component,
+ Either<ToscaNodeType, ToscaError> requirements = capabilityRequirementConverter
+ .convertRequirements(componentsCache, component,
toscaNodeType);
if (requirements.isRight()) {
return Either.right(requirements.right().value());
@@ -742,17 +768,17 @@ public class ToscaExportHandler {
String toscaResourceName;
switch (component.getComponentType()) {
- case RESOURCE:
- toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition()
+ case RESOURCE:
+ toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition()
.getMetadataDataDefinition()).getToscaResourceName();
- break;
- case SERVICE:
- toscaResourceName = SERVICE_NODE_TYPE_PREFIX
+ break;
+ case SERVICE:
+ toscaResourceName = SERVICE_NODE_TYPE_PREFIX
+ component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
- break;
- default:
- log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
- return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
+ break;
+ default:
+ log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
+ return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
}
nodeTypes.put(toscaResourceName, toscaNodeType);
@@ -762,16 +788,16 @@ public class ToscaExportHandler {
}
protected Either<Map<String, ToscaNodeTemplate>, ToscaError> convertNodeTemplates(
- Component component,
- List<ComponentInstance> componentInstances,
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties,
- Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces,
- Map<String, Component> componentCache, Map<String, DataTypeDefinition> dataTypes,
- ToscaTopolgyTemplate topologyTemplate) {
+ Component component,
+ List<ComponentInstance> componentInstances,
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties,
+ Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces,
+ Map<String, Component> componentCache, Map<String, DataTypeDefinition> dataTypes,
+ ToscaTopolgyTemplate topologyTemplate) {
Either<Map<String, ToscaNodeTemplate>, ToscaError> convertNodeTemplatesRes = null;
log.debug("start convert topology template for {} for type {}", component.getUniqueId(),
- component.getComponentType());
+ component.getComponentType());
Map<String, ToscaNodeTemplate> nodeTemplates = new HashMap<>();
Map<String, List<ComponentInstanceInput>> componentInstancesInputs = component.getComponentInstancesInputs();
@@ -786,14 +812,14 @@ public class ToscaExportHandler {
nodeTemplate.setNode_filter(convertToNodeTemplateNodeFilterComponent(componentInstance.getNodeFilter()));
Either<Component, Boolean> originComponentRes = capabilityRequirementConverter
- .getOriginComponent(componentCache, componentInstance);
+ .getOriginComponent(componentCache, componentInstance);
if (originComponentRes.isRight()) {
convertNodeTemplatesRes = Either.right(ToscaError.NODE_TYPE_REQUIREMENT_ERROR);
break;
}
Either<ToscaNodeTemplate, ToscaError> requirements = convertComponentInstanceRequirements(component,
- componentInstance, component.getComponentInstancesRelations(), nodeTemplate,
- originComponentRes.left().value(), componentCache);
+ componentInstance, component.getComponentInstancesRelations(), nodeTemplate,
+ originComponentRes.left().value(), componentCache);
if (requirements.isRight()) {
convertNodeTemplatesRes = Either.right(requirements.right().value());
break;
@@ -805,7 +831,7 @@ public class ToscaExportHandler {
Component originalComponent = componentCache.get(componentInstance.getActualComponentUid());
- if (componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy){
+ if (componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy) {
Component componentOfProxy = componentCache.get(componentInstance.getComponentUid());
nodeTemplate.setMetadata(convertMetadata(componentOfProxy, true, componentInstance));
} else {
@@ -813,7 +839,7 @@ public class ToscaExportHandler {
}
Either<ToscaNodeTemplate, ToscaError> capabilities = capabilityRequirementConverter
- .convertComponentInstanceCapabilities(componentInstance, dataTypes, nodeTemplate);
+ .convertComponentInstanceCapabilities(componentInstance, dataTypes, nodeTemplate);
if (capabilities.isRight()) {
convertNodeTemplatesRes = Either.right(capabilities.right().value());
break;
@@ -830,18 +856,18 @@ public class ToscaExportHandler {
if (null != componentInstancesProperties && componentInstancesProperties.containsKey(instanceUniqueId)) {
addPropertiesOfComponentInstance(componentInstancesProperties, dataTypes, instanceUniqueId,
- props);
+ props);
}
if (componentInstancesInputs != null && componentInstancesInputs.containsKey(instanceUniqueId)
- && !isComponentOfTypeServiceProxy(componentInstance)) {
+ && !isComponentOfTypeServiceProxy(componentInstance)) {
//For service proxy the inputs are already handled under instance properties above
addComponentInstanceInputs(dataTypes, componentInstancesInputs, instanceUniqueId,
- props);
+ props);
}
//M3[00001] - NODE TEMPLATE INTERFACES - START
handleInstanceInterfaces(componentInstanceInterfaces, componentInstance, dataTypes, nodeTemplate,
- instanceUniqueId, component);
+ instanceUniqueId, component);
//M3[00001] - NODE TEMPLATE INTERFACES - END
if (props != null && !props.isEmpty()) {
nodeTemplate.setProperties(props);
@@ -861,7 +887,8 @@ public class ToscaExportHandler {
}
if (addToTosca) {
- ToscaGroupTemplate toscaGroup = groupExportParser.getToscaGroupTemplate(groupInst, componentInstance.getInvariantName());
+ ToscaGroupTemplate toscaGroup = groupExportParser
+ .getToscaGroupTemplate(groupInst, componentInstance.getInvariantName());
groupsMap.put(groupInst.getName(), toscaGroup);
}
}
@@ -873,32 +900,35 @@ public class ToscaExportHandler {
log.debug("instance groups added");
topologyTemplate.addGroups(groupsMap);
}
- if (component.getComponentType() == ComponentTypeEnum.SERVICE && isNotEmpty(((Service) component).getForwardingPaths())) {
+ if (component.getComponentType() == ComponentTypeEnum.SERVICE && isNotEmpty(
+ ((Service) component).getForwardingPaths())) {
log.debug("Starting converting paths for component {}, name {}", component.getUniqueId(),
- component.getName());
- ForwardingPathToscaUtil.addForwardingPaths((Service) component, nodeTemplates, capabilityRequirementConverter, componentCache, toscaOperationFacade);
+ component.getName());
+ ForwardingPathToscaUtil
+ .addForwardingPaths((Service) component, nodeTemplates, capabilityRequirementConverter, componentCache,
+ toscaOperationFacade);
log.debug("Finished converting paths for component {}, name {}", component.getUniqueId(),
- component.getName());
+ component.getName());
}
if (convertNodeTemplatesRes == null) {
convertNodeTemplatesRes = Either.left(nodeTemplates);
}
log.debug("finish convert topology template for {} for type {}", component.getUniqueId(),
- component.getComponentType());
+ component.getComponentType());
return convertNodeTemplatesRes;
}
private void handleInstanceInterfaces(
- Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces,
- ComponentInstance componentInstance, Map<String, DataTypeDefinition> dataTypes, ToscaNodeTemplate nodeTemplate,
- String instanceUniqueId,
- Component parentComponent) {
+ Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces,
+ ComponentInstance componentInstance, Map<String, DataTypeDefinition> dataTypes, ToscaNodeTemplate nodeTemplate,
+ String instanceUniqueId,
+ Component parentComponent) {
Map<String, Object> interfaces;
// we need to handle service proxy interfaces
- if(isComponentOfTypeServiceProxy(componentInstance)) {
- if(MapUtils.isEmpty(componentInstanceInterfaces)
+ if (isComponentOfTypeServiceProxy(componentInstance)) {
+ if (MapUtils.isEmpty(componentInstanceInterfaces)
|| !componentInstanceInterfaces.containsKey(instanceUniqueId)) {
interfaces = null;
} else {
@@ -910,7 +940,7 @@ public class ToscaExportHandler {
.getUniqueId(), instInterface));
interfaces = interfacesOperationsConverter
- .getInterfacesMap(parentComponent, componentInstance, tmpInterfaces, dataTypes, true, true);
+ .getInterfacesMap(parentComponent, componentInstance, tmpInterfaces, dataTypes, true, true);
}
} else {
interfaces =
@@ -926,22 +956,23 @@ public class ToscaExportHandler {
}
//M3[00001] - NODE TEMPLATE INTERFACES - START
- private Map<String, Object> getComponentInstanceInterfaceInstances(Map<String, List<ComponentInstanceInterface>> componentInstancesInterfaces,
- ComponentInstance componentInstance,
- String instanceUniqueId) {
- if(MapUtils.isEmpty(componentInstancesInterfaces)) {
+ private Map<String, Object> getComponentInstanceInterfaceInstances(
+ Map<String, List<ComponentInstanceInterface>> componentInstancesInterfaces,
+ ComponentInstance componentInstance,
+ String instanceUniqueId) {
+ if (MapUtils.isEmpty(componentInstancesInterfaces)) {
return null;
}
List<ComponentInstanceInterface> componentInstanceInterfaces =
componentInstancesInterfaces.get(instanceUniqueId);
- if(CollectionUtils.isEmpty(componentInstanceInterfaces)) {
- return null;
+ if (CollectionUtils.isEmpty(componentInstanceInterfaces)) {
+ return null;
}
Map<String, Object> interfaces = new HashMap<>();
- for(ComponentInstanceInterface componentInstanceInterface : componentInstanceInterfaces) {
+ for (ComponentInstanceInterface componentInstanceInterface : componentInstanceInterfaces) {
interfaces.put(componentInstanceInterface.getInterfaceId(),
removeOperationsKeyFromInterface(componentInstanceInterface.getInterfaceInstanceDataDefinition()));
}
@@ -960,22 +991,22 @@ public class ToscaExportHandler {
instanceInputsList.forEach(input -> {
Supplier<String> supplier = () -> input.getValue() != null && !Objects.isNull(input.getValue())
- ? input.getValue() : input.getDefaultValue();
- propertyConvertor.convertAndAddValue(dataTypes, props, input, supplier);
+ ? input.getValue() : input.getDefaultValue();
+ propertyConvertor.convertAndAddValue(dataTypes, props, input, supplier);
});
}
}
private void addPropertiesOfComponentInstance(
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties,
- Map<String, DataTypeDefinition> dataTypes, String instanceUniqueId,
- Map<String, Object> props) {
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties,
+ Map<String, DataTypeDefinition> dataTypes, String instanceUniqueId,
+ Map<String, Object> props) {
if (isNotEmpty(componentInstancesProperties)) {
componentInstancesProperties.get(instanceUniqueId)
- // Converts and adds each value to property map
- .forEach(prop -> propertyConvertor.convertAndAddValue(dataTypes, props, prop,
- prop::getValue));
+ // Converts and adds each value to property map
+ .forEach(prop -> propertyConvertor.convertAndAddValue(dataTypes, props, prop,
+ prop::getValue));
}
}
@@ -985,23 +1016,19 @@ public class ToscaExportHandler {
List<PropertyDefinition> componentProperties = componentOfInstance.getProperties();
if (isNotEmpty(componentProperties)) {
componentProperties.stream()
- // Filters out properties with empty default values
- .filter(prop -> StringUtils.isNotEmpty(prop.getDefaultValue()))
- // Converts and adds each value to property map
- .forEach(prop -> propertyConvertor.convertAndAddValue(dataTypes, props, prop,
- prop::getDefaultValue));
+ // Filters out properties with empty default values
+ .filter(prop -> StringUtils.isNotEmpty(prop.getDefaultValue()))
+ // Converts and adds each value to property map
+ .forEach(prop -> propertyConvertor.convertAndAddValue(dataTypes, props, prop,
+ prop::getDefaultValue));
}
}
/**
- * @param dataTypes
- * @param componentInstance
- * @param props
- * @param prop
- * @param supplier
+ *
*/
private void convertAndAddValue(Map<String, DataTypeDefinition> dataTypes, ComponentInstance componentInstance,
- Map<String, Object> props, PropertyDefinition prop, Supplier<String> supplier) {
+ Map<String, Object> props, PropertyDefinition prop, Supplier<String> supplier) {
Object convertedValue = convertValue(dataTypes, componentInstance, prop, supplier);
if (!ToscaValueBaseConverter.isEmptyObjectValue(convertedValue)) {
props.put(prop.getName(), convertedValue);
@@ -1009,9 +1036,10 @@ public class ToscaExportHandler {
}
private <T extends PropertyDefinition> Object convertValue(Map<String, DataTypeDefinition> dataTypes,
- ComponentInstance componentInstance, T input, Supplier<String> supplier) {
+ ComponentInstance componentInstance, T input,
+ Supplier<String> supplier) {
log.debug("Convert property or input value {} for instance {}", input.getName(),
- componentInstance.getUniqueId());
+ componentInstance.getUniqueId());
String propertyType = input.getType();
String innerType = null;
if (input.getSchema() != null && input.getSchema().getProperty() != null) {
@@ -1029,7 +1057,7 @@ public class ToscaExportHandler {
toscaNodeType.setDescription(component.getDescription());
} else {
String derivedFrom = null != component.getDerivedFromGenericType() ? component.getDerivedFromGenericType()
- : NATIVE_ROOT;
+ : NATIVE_ROOT;
toscaNodeType.setDerived_from(derivedFrom);
}
return toscaNodeType;
@@ -1045,8 +1073,8 @@ public class ToscaExportHandler {
}
Map<String, ComponentInstance> serviceProxyInstanceList = new HashMap<>();
componentInstances.stream()
- .filter(this::isComponentOfTypeServiceProxy)
- .forEach(inst -> serviceProxyInstanceList.put(inst.getToscaComponentName(), inst));
+ .filter(this::isComponentOfTypeServiceProxy)
+ .forEach(inst -> serviceProxyInstanceList.put(inst.getToscaComponentName(), inst));
if (MapUtils.isEmpty(serviceProxyInstanceList)) {
return res;
}
@@ -1056,28 +1084,28 @@ public class ToscaExportHandler {
componentParametersView.disableAll();
componentParametersView.setIgnoreInterfaces(false);
Either<Component, StorageOperationStatus> service = toscaOperationFacade
- .getToscaElement(entryProxy.getValue().getSourceModelUid(), componentParametersView);
+ .getToscaElement(entryProxy.getValue().getSourceModelUid(), componentParametersView);
if (service.isRight()) {
log.debug("Failed to fetch original service component with id {} for instance {}",
- entryProxy.getValue().getSourceModelUid(), entryProxy.getValue().getName());
+ entryProxy.getValue().getSourceModelUid(), entryProxy.getValue().getName());
return Either.right(ToscaError.GENERAL_ERROR);
} else {
serviceComponent = service.left().value();
}
Either<Map<String, InterfaceDefinition>, StorageOperationStatus> lifecycleTypeEither =
- interfaceLifecycleOperation.getAllInterfaceLifecycleTypes();
- if(lifecycleTypeEither.isRight()){
+ interfaceLifecycleOperation.getAllInterfaceLifecycleTypes();
+ if (lifecycleTypeEither.isRight()) {
log.debug("Failed to retrieve global interface types :", lifecycleTypeEither.right().value());
return Either.right(ToscaError.GENERAL_ERROR);
}
List<String> allGlobalInterfaceTypes = lifecycleTypeEither.left().value().values().stream()
- .map(InterfaceDataDefinition::getType)
- .collect(Collectors.toList());
+ .map(InterfaceDataDefinition::getType)
+ .collect(Collectors.toList());
//Add interface types for local interfaces in the original service component for proxy
Map<String, Object> localInterfaceTypes = addInterfaceTypeElement(serviceComponent,
- allGlobalInterfaceTypes);
+ allGlobalInterfaceTypes);
if (MapUtils.isNotEmpty(localInterfaceTypes)) {
proxyInterfaceTypes.putAll(localInterfaceTypes);
}
@@ -1099,8 +1127,8 @@ public class ToscaExportHandler {
}
Map<String, ComponentInstance> serviceProxyInstanceList = new HashMap<>();
List<ComponentInstance> proxyInst = componentInstances.stream()
- .filter(p -> p.getOriginType().name().equals(OriginTypeEnum.ServiceProxy.name()))
- .collect(Collectors.toList());
+ .filter(p -> p.getOriginType().name().equals(OriginTypeEnum.ServiceProxy.name()))
+ .collect(Collectors.toList());
if (proxyInst != null && !proxyInst.isEmpty()) {
for (ComponentInstance inst : proxyInst) {
serviceProxyInstanceList.put(inst.getToscaComponentName(), inst);
@@ -1111,10 +1139,10 @@ public class ToscaExportHandler {
return res;
}
Either<Resource, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade
- .getLatestByName("serviceProxy");
+ .getLatestByName("serviceProxy");
if (serviceProxyOrigin.isRight()) {
log.debug("Failed to fetch normative service proxy resource by tosca name, error {}",
- serviceProxyOrigin.right().value());
+ serviceProxyOrigin.right().value());
return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
}
Component origComponent = serviceProxyOrigin.left().value();
@@ -1129,22 +1157,23 @@ public class ToscaExportHandler {
componentParametersView.setIgnoreInterfaces(false);
componentParametersView.setIgnoreRequirements(false);
Either<Component, StorageOperationStatus> service = toscaOperationFacade
- .getToscaElement(entryProxy.getValue().getSourceModelUid(), componentParametersView);
+ .getToscaElement(entryProxy.getValue().getSourceModelUid(), componentParametersView);
if (service.isRight()) {
- log.debug("Failed to fetch resource with id {} for instance {}", entryProxy.getValue().getSourceModelUid(), entryProxy.getValue().getName());
+ log.debug("Failed to fetch resource with id {} for instance {}",
+ entryProxy.getValue().getSourceModelUid(), entryProxy.getValue().getName());
} else {
serviceComponent = service.left().value();
}
ToscaNodeType toscaNodeType = createProxyNodeType(componentCache, origComponent, serviceComponent,
- entryProxy.getValue());
+ entryProxy.getValue());
nodeTypesMap.put(entryProxy.getKey(), toscaNodeType);
}
return Either.left(nodeTypesMap);
}
- private ToscaNodeType createProxyNodeType(Map<String, Component> componentCache , Component origComponent,
+ private ToscaNodeType createProxyNodeType(Map<String, Component> componentCache, Component origComponent,
Component proxyComponent, ComponentInstance instance) {
ToscaNodeType toscaNodeType = new ToscaNodeType();
String derivedFrom = ((Resource) origComponent).getToscaResourceName();
@@ -1156,13 +1185,13 @@ public class ToscaExportHandler {
}
Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
Map<String, ToscaCapability> capabilities = this.capabilityRequirementConverter
- .convertProxyCapabilities(componentCache, instance, dataTypes);
+ .convertProxyCapabilities(componentCache, instance, dataTypes);
if (MapUtils.isNotEmpty(capabilities)) {
toscaNodeType.setCapabilities(capabilities);
}
List<Map<String, ToscaRequirement>> proxyNodeTypeRequirements = this.capabilityRequirementConverter
- .convertProxyRequirements(componentCache, instance);
+ .convertProxyRequirements(componentCache, instance);
if (CollectionUtils.isNotEmpty(proxyNodeTypeRequirements)) {
toscaNodeType.setRequirements(proxyNodeTypeRequirements);
}
@@ -1176,13 +1205,17 @@ public class ToscaExportHandler {
}
private Either<ToscaNodeTemplate, ToscaError> convertComponentInstanceRequirements(Component component,
- ComponentInstance componentInstance, List<RequirementCapabilityRelDef> relations,
- ToscaNodeTemplate nodeTypeTemplate, Component originComponent, Map<String, Component> componentCache) {
+ ComponentInstance componentInstance,
+ List<RequirementCapabilityRelDef> relations,
+ ToscaNodeTemplate nodeTypeTemplate,
+ Component originComponent,
+ Map<String, Component> componentCache) {
List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
- if (!addRequirements(component, componentInstance, relations, originComponent, toscaRequirements, componentCache)) {
+ if (!addRequirements(component, componentInstance, relations, originComponent, toscaRequirements,
+ componentCache)) {
log.debug("Failed to convert component instance requirements for the component instance {}. ",
- componentInstance.getName());
+ componentInstance.getName());
return Either.right(ToscaError.NODE_TYPE_REQUIREMENT_ERROR);
}
if (!toscaRequirements.isEmpty()) {
@@ -1193,18 +1226,22 @@ public class ToscaExportHandler {
}
private boolean addRequirements(Component component, ComponentInstance componentInstance,
- List<RequirementCapabilityRelDef> relations, Component originComponent,
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements, Map<String, Component> componentCache) {
+ List<RequirementCapabilityRelDef> relations, Component originComponent,
+ List<Map<String, ToscaTemplateRequirement>> toscaRequirements,
+ Map<String, Component> componentCache) {
List<RequirementCapabilityRelDef> filteredRelations = relations.stream()
- .filter(p -> componentInstance.getUniqueId().equals(p.getFromNode())).collect(Collectors.toList());
+ .filter(p -> componentInstance.getUniqueId().equals(p.getFromNode())).collect(Collectors.toList());
return isEmpty(filteredRelations) ||
- filteredRelations.stream()
- .allMatch(rel -> addRequirement(componentInstance, originComponent, component.getComponentInstances(), rel, toscaRequirements, componentCache));
+ filteredRelations.stream()
+ .allMatch(
+ rel -> addRequirement(componentInstance, originComponent, component.getComponentInstances(), rel,
+ toscaRequirements, componentCache));
}
private boolean addRequirement(ComponentInstance fromInstance, Component fromOriginComponent,
- List<ComponentInstance> instancesList, RequirementCapabilityRelDef rel,
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements, Map<String, Component> componentCache) {
+ List<ComponentInstance> instancesList, RequirementCapabilityRelDef rel,
+ List<Map<String, ToscaTemplateRequirement>> toscaRequirements,
+ Map<String, Component> componentCache) {
boolean result = true;
Map<String, List<RequirementDefinition>> reqMap = fromOriginComponent.getRequirements();
@@ -1215,17 +1252,17 @@ public class ToscaExportHandler {
Optional<CapabilityDefinition> capOpt = Optional.empty();
ComponentInstance toInstance = instancesList.stream().filter(i -> rel.getToNode().equals(i.getUniqueId()))
- .findFirst().orElse(null);
+ .findFirst().orElse(null);
if (toInstance == null) {
log.debug("Failed to find a relation from the node {} to the node {}", fromInstance.getName(),
- rel.getToNode());
+ rel.getToNode());
result = false;
}
if (result) {
reqOpt = findRequirement(fromOriginComponent, reqMap, reqAndRelationshipPair, fromInstance.getUniqueId());
if (!reqOpt.isPresent()) {
log.debug("Failed to find a requirement with uniqueId {} on a component with uniqueId {}",
- reqAndRelationshipPair.getRequirementUid(), fromOriginComponent.getUniqueId());
+ reqAndRelationshipPair.getRequirementUid(), fromOriginComponent.getUniqueId());
result = false;
}
}
@@ -1236,62 +1273,75 @@ public class ToscaExportHandler {
filter.setIgnoreGroups(false);
getOriginRes = toscaOperationFacade.getToscaElement(toInstance.getActualComponentUid(), filter);
if (getOriginRes.isRight()) {
- log.debug("Failed to build substituted name for the requirement {}. Failed to get an origin component with uniqueId {}",
- reqOpt.get().getName(), toInstance.getActualComponentUid());
+ log.debug(
+ "Failed to build substituted name for the requirement {}. Failed to get an origin component with uniqueId {}",
+ reqOpt.get().getName(), toInstance.getActualComponentUid());
result = false;
}
}
if (result) {
toOriginComponent = getOriginRes.left().value();
capOpt = toOriginComponent.getCapabilities().get(reqOpt.get().getCapability()).stream()
- .filter(c -> isCapabilityBelongToRelation(reqAndRelationshipPair, c)).findFirst();
+ .filter(c -> isCapabilityBelongToRelation(reqAndRelationshipPair, c)).findFirst();
if (!capOpt.isPresent()) {
capOpt = findCapability(reqAndRelationshipPair, toOriginComponent, fromOriginComponent, reqOpt.get());
- if(!capOpt.isPresent()){
- result = false;
- log.debug("Failed to find a capability with name {} on a component with uniqueId {}",
+ if (!capOpt.isPresent()) {
+ result = false;
+ log.debug("Failed to find a capability with name {} on a component with uniqueId {}",
reqAndRelationshipPair.getCapability(), fromOriginComponent.getUniqueId());
}
}
}
if (result) {
result = buildAndAddRequirement(toscaRequirements, fromOriginComponent, toOriginComponent, capOpt.get(),
- reqOpt.get(), reqAndRelationshipPair, toInstance, componentCache);
+ reqOpt.get(), reqAndRelationshipPair, toInstance, componentCache);
}
return result;
}
- private boolean isCapabilityBelongToRelation(RelationshipInfo reqAndRelationshipPair, CapabilityDefinition capability) {
- return capability.getName().equals(reqAndRelationshipPair.getCapability()) && (capability.getOwnerId() !=null && capability.getOwnerId().equals(reqAndRelationshipPair.getCapabilityOwnerId()));
+ private boolean isCapabilityBelongToRelation(RelationshipInfo reqAndRelationshipPair,
+ CapabilityDefinition capability) {
+ return capability.getName().equals(reqAndRelationshipPair.getCapability()) && (capability.getOwnerId() != null
+ && capability.getOwnerId().equals(reqAndRelationshipPair.getCapabilityOwnerId()));
}
- private Optional<CapabilityDefinition> findCapability(RelationshipInfo reqAndRelationshipPair, Component toOriginComponent, Component fromOriginComponent, RequirementDefinition requirement) {
- Optional<CapabilityDefinition> cap = toOriginComponent.getCapabilities().get(requirement.getCapability()).stream().filter(c -> c.getType().equals(requirement.getCapability())).findFirst();
+ private Optional<CapabilityDefinition> findCapability(RelationshipInfo reqAndRelationshipPair,
+ Component toOriginComponent, Component fromOriginComponent,
+ RequirementDefinition requirement) {
+ Optional<CapabilityDefinition> cap = toOriginComponent.getCapabilities().get(requirement.getCapability())
+ .stream().filter(c -> c.getType().equals(requirement.getCapability())).findFirst();
if (!cap.isPresent()) {
- log.debug("Failed to find a capability with name {} on a component with uniqueId {}", reqAndRelationshipPair.getCapability(), fromOriginComponent.getUniqueId());
+ log.debug("Failed to find a capability with name {} on a component with uniqueId {}",
+ reqAndRelationshipPair.getCapability(), fromOriginComponent.getUniqueId());
}
return cap;
}
- private boolean buildAndAddRequirement(List<Map<String, ToscaTemplateRequirement>> toscaRequirements, Component fromOriginComponent, Component toOriginComponent, CapabilityDefinition capability, RequirementDefinition requirement, RelationshipInfo reqAndRelationshipPair, ComponentInstance toInstance, Map<String, Component> componentCache) {
+ private boolean buildAndAddRequirement(List<Map<String, ToscaTemplateRequirement>> toscaRequirements,
+ Component fromOriginComponent, Component toOriginComponent,
+ CapabilityDefinition capability, RequirementDefinition requirement,
+ RelationshipInfo reqAndRelationshipPair, ComponentInstance toInstance,
+ Map<String, Component> componentCache) {
List<String> reducedPath = capability.getPath();
- if(capability.getOwnerId() !=null){
- reducedPath = capabilityRequirementConverter.getReducedPathByOwner(capability.getPath() , capability.getOwnerId() );
+ if (capability.getOwnerId() != null) {
+ reducedPath = capabilityRequirementConverter
+ .getReducedPathByOwner(capability.getPath(), capability.getOwnerId());
}
Either<String, Boolean> buildCapNameRes = capabilityRequirementConverter.buildSubstitutedName(componentCache,
- toOriginComponent, reducedPath, reqAndRelationshipPair.getCapability(), capability.getPreviousName());
+ toOriginComponent, reducedPath, reqAndRelationshipPair.getCapability(), capability.getPreviousName());
if (buildCapNameRes.isRight()) {
log.debug(
- "Failed to build a substituted capability name for the capability with name {} on a component with uniqueId {}",
- reqAndRelationshipPair.getCapability(), fromOriginComponent.getUniqueId());
+ "Failed to build a substituted capability name for the capability with name {} on a component with uniqueId {}",
+ reqAndRelationshipPair.getCapability(), fromOriginComponent.getUniqueId());
return false;
}
- Either<String, Boolean> buildReqNameRes = capabilityRequirementConverter.buildSubstitutedName(componentCache, fromOriginComponent,
+ Either<String, Boolean> buildReqNameRes = capabilityRequirementConverter
+ .buildSubstitutedName(componentCache, fromOriginComponent,
requirement.getPath(), reqAndRelationshipPair.getRequirement(), requirement.getPreviousName());
if (buildReqNameRes.isRight()) {
log.debug(
- "Failed to build a substituted requirement name for the requirement with name {} on a component with uniqueId {}",
- reqAndRelationshipPair.getRequirement(), fromOriginComponent.getUniqueId());
+ "Failed to build a substituted requirement name for the requirement with name {} on a component with uniqueId {}",
+ reqAndRelationshipPair.getRequirement(), fromOriginComponent.getUniqueId());
return false;
}
ToscaTemplateRequirement toscaRequirement = new ToscaTemplateRequirement();
@@ -1303,10 +1353,15 @@ public class ToscaExportHandler {
return true;
}
- private Optional<RequirementDefinition> findRequirement(Component fromOriginComponent, Map<String, List<RequirementDefinition>> reqMap, RelationshipInfo reqAndRelationshipPair, String fromInstanceId) {
- for(List<RequirementDefinition> reqList: reqMap.values()){
- Optional<RequirementDefinition> reqOpt = reqList.stream().filter(r -> isRequirementBelongToRelation(fromOriginComponent, reqAndRelationshipPair, r, fromInstanceId)).findFirst();
- if(reqOpt.isPresent()){
+ private Optional<RequirementDefinition> findRequirement(Component fromOriginComponent,
+ Map<String, List<RequirementDefinition>> reqMap,
+ RelationshipInfo reqAndRelationshipPair,
+ String fromInstanceId) {
+ for (List<RequirementDefinition> reqList : reqMap.values()) {
+ Optional<RequirementDefinition> reqOpt = reqList.stream().filter(
+ r -> isRequirementBelongToRelation(fromOriginComponent, reqAndRelationshipPair, r, fromInstanceId))
+ .findFirst();
+ if (reqOpt.isPresent()) {
return reqOpt;
}
}
@@ -1314,40 +1369,43 @@ public class ToscaExportHandler {
}
/**
- * Allows detecting the requirement belonging to the received relationship
- * The detection logic is: A requirement belongs to a relationship IF 1.The
- * name of the requirement equals to the "requirement" field of the
- * relation; AND 2. In case of a non-atomic resource, OwnerId of the
- * requirement equals to requirementOwnerId of the relation OR uniqueId of
- * toInstance equals to capabilityOwnerId of the relation
+ * Allows detecting the requirement belonging to the received relationship The detection logic is: A requirement
+ * belongs to a relationship IF 1.The name of the requirement equals to the "requirement" field of the relation; AND
+ * 2. In case of a non-atomic resource, OwnerId of the requirement equals to requirementOwnerId of the relation OR
+ * uniqueId of toInstance equals to capabilityOwnerId of the relation
*/
- private boolean isRequirementBelongToRelation(Component originComponent, RelationshipInfo reqAndRelationshipPair, RequirementDefinition requirement, String fromInstanceId) {
+ private boolean isRequirementBelongToRelation(Component originComponent, RelationshipInfo reqAndRelationshipPair,
+ RequirementDefinition requirement, String fromInstanceId) {
if (!StringUtils.equals(requirement.getName(), reqAndRelationshipPair.getRequirement())) {
log.debug("Failed to find a requirement with name {} and reqAndRelationshipPair {}",
- requirement.getName(), reqAndRelationshipPair.getRequirement());
+ requirement.getName(), reqAndRelationshipPair.getRequirement());
return false;
}
return ModelConverter.isAtomicComponent(originComponent) ||
- isRequirementBelongToOwner(reqAndRelationshipPair, requirement, fromInstanceId, originComponent);
+ isRequirementBelongToOwner(reqAndRelationshipPair, requirement, fromInstanceId, originComponent);
}
- private boolean isRequirementBelongToOwner(RelationshipInfo reqAndRelationshipPair, RequirementDefinition requirement, String fromInstanceId, Component originComponent) {
+ private boolean isRequirementBelongToOwner(RelationshipInfo reqAndRelationshipPair,
+ RequirementDefinition requirement, String fromInstanceId,
+ Component originComponent) {
return StringUtils.equals(requirement.getOwnerId(), reqAndRelationshipPair.getRequirementOwnerId())
- || (isCvfc(originComponent) && StringUtils.equals(fromInstanceId, reqAndRelationshipPair.getRequirementOwnerId())
- || StringUtils.equals(requirement.getOwnerId(), originComponent.getUniqueId()));
+ || (isCvfc(originComponent) && StringUtils
+ .equals(fromInstanceId, reqAndRelationshipPair.getRequirementOwnerId())
+ || StringUtils.equals(requirement.getOwnerId(), originComponent.getUniqueId()));
}
private boolean isCvfc(Component component) {
return component.getComponentType() == ComponentTypeEnum.RESOURCE &&
- ((Resource) component).getResourceType() == ResourceTypeEnum.CVFC;
+ ((Resource) component).getResourceType() == ResourceTypeEnum.CVFC;
}
private Either<SubstitutionMapping, ToscaError> convertCapabilities(Component component,
- SubstitutionMapping substitutionMappings, Map<String, Component> componentCache) {
+ SubstitutionMapping substitutionMappings,
+ Map<String, Component> componentCache) {
Either<SubstitutionMapping, ToscaError> result = Either.left(substitutionMappings);
Either<Map<String, String[]>, ToscaError> toscaCapabilitiesRes = capabilityRequirementConverter
- .convertSubstitutionMappingCapabilities(componentCache, component);
+ .convertSubstitutionMappingCapabilities(componentCache, component);
if (toscaCapabilitiesRes.isRight()) {
result = Either.right(toscaCapabilitiesRes.right().value());
log.debug("Failed convert capabilities for the component {}. ", component.getName());
@@ -1359,9 +1417,11 @@ public class ToscaExportHandler {
return result;
}
- private Either<ToscaNodeType, ToscaError> convertCapabilities(Map<String, Component> componentsCache, Component component, ToscaNodeType nodeType,
- Map<String, DataTypeDefinition> dataTypes) {
- Map<String, ToscaCapability> toscaCapabilities = capabilityRequirementConverter.convertCapabilities(componentsCache, component,
+ private Either<ToscaNodeType, ToscaError> convertCapabilities(Map<String, Component> componentsCache,
+ Component component, ToscaNodeType nodeType,
+ Map<String, DataTypeDefinition> dataTypes) {
+ Map<String, ToscaCapability> toscaCapabilities = capabilityRequirementConverter
+ .convertCapabilities(componentsCache, component,
dataTypes);
if (!toscaCapabilities.isEmpty()) {
nodeType.setCapabilities(toscaCapabilities);
@@ -1371,28 +1431,29 @@ public class ToscaExportHandler {
return Either.left(nodeType);
}
- private Map<String, ToscaTemplateArtifact> convertToNodeTemplateArtifacts(Map<String, ToscaArtifactDataDefinition> artifacts) {
+ private Map<String, ToscaTemplateArtifact> convertToNodeTemplateArtifacts(
+ Map<String, ToscaArtifactDataDefinition> artifacts) {
if (artifacts == null) {
return null;
}
Map<String, ToscaTemplateArtifact> arts = new HashMap<>();
for (Map.Entry<String, ToscaArtifactDataDefinition> entry : artifacts.entrySet()) {
- ToscaTemplateArtifact artifact = new ToscaTemplateArtifact();
- artifact.setFile(entry.getValue().getFile());
- artifact.setType(entry.getValue().getType());
- arts.put(entry.getKey(), artifact);
+ ToscaTemplateArtifact artifact = new ToscaTemplateArtifact();
+ artifact.setFile(entry.getValue().getFile());
+ artifact.setType(entry.getValue().getType());
+ arts.put(entry.getKey(), artifact);
}
return arts;
}
protected NodeFilter convertToNodeTemplateNodeFilterComponent(CINodeFilterDataDefinition inNodeFilter) {
- if (inNodeFilter == null){
+ if (inNodeFilter == null) {
return null;
}
NodeFilter nodeFilter = new NodeFilter();
ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> origCapabilities =
- inNodeFilter.getCapabilities();
+ inNodeFilter.getCapabilities();
ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> origProperties = inNodeFilter.getProperties();
@@ -1402,17 +1463,33 @@ public class ToscaExportHandler {
copyNodeFilterCapabilitiesTemplate(origCapabilities, capabilitiesCopy);
copyNodeFilterProperties(origProperties, propertiesCopy);
- if(CollectionUtils.isNotEmpty(capabilitiesCopy)) {
+ if (CollectionUtils.isNotEmpty(capabilitiesCopy)) {
nodeFilter.setCapabilities(capabilitiesCopy);
}
- if(CollectionUtils.isNotEmpty(propertiesCopy)) {
+ if (CollectionUtils.isNotEmpty(propertiesCopy)) {
nodeFilter.setProperties(propertiesCopy);
}
nodeFilter.setTosca_id(cloneToscaId(inNodeFilter.getTosca_id()));
+ nodeFilter = (NodeFilter) cloneObjectFromYml(nodeFilter, NodeFilter.class);
+
+ return nodeFilter;
+ }
+
+ private NodeFilter convertToSubstitutionFilterComponent(
+ final SubstitutionFilterDataDefinition substitutionFilterDataDefinition) {
+
+ NodeFilter nodeFilter = new NodeFilter();
+ final List<Map<String, List<Object>>> propertiesCopy = new ArrayList<>();
+ copySubstitutionFilterProperties(substitutionFilterDataDefinition.getProperties(), propertiesCopy);
+
+ if (CollectionUtils.isNotEmpty(propertiesCopy)) {
+ nodeFilter.setProperties(propertiesCopy);
+ }
+ nodeFilter.setTosca_id(cloneToscaId(substitutionFilterDataDefinition.getTosca_id()));
nodeFilter = (NodeFilter) cloneObjectFromYml(nodeFilter, NodeFilter.class);
return nodeFilter;
@@ -1420,22 +1497,22 @@ public class ToscaExportHandler {
private Object cloneToscaId(Object toscaId) {
return Objects.isNull(toscaId) ? null
- : cloneObjectFromYml(toscaId, toscaId.getClass());
+ : cloneObjectFromYml(toscaId, toscaId.getClass());
}
-
private Object cloneObjectFromYml(Object objToClone, Class classOfObj) {
String objectAsYml = yamlUtil.objectToYaml(objToClone);
return yamlUtil.yamlToObject(objectAsYml, classOfObj);
}
+
private void copyNodeFilterCapabilitiesTemplate(
- ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> origCapabilities,
- List<Map<String, CapabilityFilter>> capabilitiesCopy) {
- if(origCapabilities == null || origCapabilities.getListToscaDataDefinition() == null ||
- origCapabilities.getListToscaDataDefinition().isEmpty() ) {
+ ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> origCapabilities,
+ List<Map<String, CapabilityFilter>> capabilitiesCopy) {
+ if (origCapabilities == null || origCapabilities.getListToscaDataDefinition() == null ||
+ origCapabilities.getListToscaDataDefinition().isEmpty()) {
return;
}
- for(RequirementNodeFilterCapabilityDataDefinition capability : origCapabilities.getListToscaDataDefinition()) {
+ for (RequirementNodeFilterCapabilityDataDefinition capability : origCapabilities.getListToscaDataDefinition()) {
Map<String, CapabilityFilter> capabilityFilterCopyMap = new HashMap<>();
CapabilityFilter capabilityFilter = new CapabilityFilter();
List<Map<String, List<Object>>> propertiesCopy = new ArrayList<>();
@@ -1446,25 +1523,20 @@ public class ToscaExportHandler {
}
}
- private List<Object> copyNodeFilterProperty(List<Object> propertyList) {
- String listAsString = yamlUtil.objectToYaml(propertyList);
- return yamlUtil.yamlToObject(listAsString, List.class);
- }
-
-
private void copyNodeFilterProperties(
- ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> origProperties,
- List<Map<String, List<Object>>> propertiesCopy) {
- if(origProperties == null || origProperties.getListToscaDataDefinition() == null ||
- origProperties.isEmpty()) {
+ ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> origProperties,
+ List<Map<String, List<Object>>> propertiesCopy) {
+ if (origProperties == null || origProperties.getListToscaDataDefinition() == null ||
+ origProperties.isEmpty()) {
return;
}
Map<String, List<Object>> propertyMapCopy = new HashMap<>();
- for(RequirementNodeFilterPropertyDataDefinition propertyDataDefinition : origProperties.getListToscaDataDefinition()) {
- for(String propertyInfoEntry : propertyDataDefinition.getConstraints()) {
- Map propertyValObj = new YamlUtil().yamlToObject(propertyInfoEntry, Map.class);
+ for (RequirementNodeFilterPropertyDataDefinition propertyDataDefinition : origProperties
+ .getListToscaDataDefinition()) {
+ for (String propertyInfoEntry : propertyDataDefinition.getConstraints()) {
+ Map propertyValObj = new YamlUtil().yamlToObject(propertyInfoEntry, Map.class);
String propertyName = propertyDataDefinition.getName();
- if (propertyMapCopy.containsKey(propertyName)){
+ if (propertyMapCopy.containsKey(propertyName)) {
addPropertyConstraintValueToList(propertyName, propertyValObj, propertyMapCopy.get(propertyName));
} else {
if (propertyName != null) {
@@ -1481,24 +1553,53 @@ public class ToscaExportHandler {
addCalculatedConstraintsIntoPropertiesList(propertiesCopy, entry));
}
+ private void copySubstitutionFilterProperties(
+ final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> origProperties,
+ final List<Map<String, List<Object>>> propertiesCopy) {
+ if (origProperties == null || origProperties.getListToscaDataDefinition() == null ||
+ origProperties.isEmpty()) {
+ return;
+ }
+ final Map<String, List<Object>> propertyMapCopy = new HashMap<>();
+ for (final RequirementSubstitutionFilterPropertyDataDefinition propertyDataDefinition : origProperties
+ .getListToscaDataDefinition()) {
+ for (final String propertyInfoEntry : propertyDataDefinition.getConstraints()) {
+ final Map<String, List<Object>> propertyValObj = new YamlUtil().yamlToObject(propertyInfoEntry, Map.class);
+ final String propertyName = propertyDataDefinition.getName();
+ if (propertyMapCopy.containsKey(propertyName)) {
+ addPropertyConstraintValueToList(propertyName, propertyValObj, propertyMapCopy.get(propertyName));
+ } else {
+ if (propertyName != null) {
+ final List<Object> propsList = new ArrayList();
+ addPropertyConstraintValueToList(propertyName, propertyValObj, propsList);
+ propertyMapCopy.put(propertyName, propsList);
+ } else {
+ propertyMapCopy.putAll(propertyValObj);
+ }
+ }
+ }
+ }
+ propertyMapCopy.entrySet().forEach(entry ->
+ addCalculatedConstraintsIntoPropertiesList(propertiesCopy, entry));
+ }
+
private void addPropertyConstraintValueToList(String propertyName, Map propertyValObj, List propsList) {
- if(propertyValObj.containsKey(propertyName)) {
+ if (propertyValObj.containsKey(propertyName)) {
propsList.add(propertyValObj.get(propertyName));
} else {
propsList.add(propertyValObj);
}
}
-
-
private void addCalculatedConstraintsIntoPropertiesList(List<Map<String, List<Object>>> propertiesCopy,
- Entry<String, List<Object>> entry) {
+ Entry<String, List<Object>> entry) {
Map<String, List<Object>> tempMap = new HashMap<>();
tempMap.put(entry.getKey(), entry.getValue());
propertiesCopy.add(tempMap);
}
private static class CustomRepresenter extends Representer {
+
CustomRepresenter() {
super();
// null representer is exceptional and it is stored as an instance
@@ -1509,7 +1610,7 @@ public class ToscaExportHandler {
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
- Tag customTag) {
+ Tag customTag) {
if (propertyValue == null) {
return null;
}
@@ -1521,7 +1622,7 @@ public class ToscaExportHandler {
NodeTuple defaultNode = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
return "_defaultp_".equals(property.getName())
- ? new NodeTuple(representData("default"), defaultNode.getValueNode()) : defaultNode;
+ ? new NodeTuple(representData("default"), defaultNode.getValueNode()) : defaultNode;
}
private void removeDefaultP(final Object propertyValue) {
@@ -1557,6 +1658,7 @@ public class ToscaExportHandler {
}
private class RepresentNull implements Represent {
+
@Override
public Node representData(Object data) {
// possible values are here http://yaml.org/type/null.html
@@ -1566,9 +1668,10 @@ public class ToscaExportHandler {
}
private static class UnsortedPropertyUtils extends PropertyUtils {
+
@Override
protected Set<Property> createPropertySet(Class type, BeanAccess bAccess)
- throws IntrospectionException {
+ throws IntrospectionException {
Collection<Property> fields = getPropertiesMap(type, BeanAccess.FIELD).values();
return new LinkedHashSet<>(fields);
}
@@ -1578,23 +1681,23 @@ public class ToscaExportHandler {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
- Map<String, Object> interfaceAsMap = ServiceUtils.getObjectAsMap(interfaceInstanceDataDefinition);
- Map<String, Object> operations = (Map<String, Object>) interfaceAsMap.remove("operations");
- interfaceAsMap.remove("empty");
+ Map<String, Object> interfaceAsMap = ServiceUtils.getObjectAsMap(interfaceInstanceDataDefinition);
+ Map<String, Object> operations = (Map<String, Object>) interfaceAsMap.remove("operations");
+ interfaceAsMap.remove("empty");
- if(MapUtils.isNotEmpty(operations)) {
- interfaceAsMap.putAll(operations);
- }
+ if (MapUtils.isNotEmpty(operations)) {
+ interfaceAsMap.putAll(operations);
+ }
- Object interfaceObject = objectMapper.convertValue(interfaceAsMap, Object.class);
+ Object interfaceObject = objectMapper.convertValue(interfaceAsMap, Object.class);
- return interfaceObject;
+ return interfaceObject;
}
Optional<Map<String, ToscaProperty>> getProxyNodeTypeProperties(Component proxyComponent,
- Map<String, DataTypeDefinition>
- dataTypes) {
+ Map<String, DataTypeDefinition>
+ dataTypes) {
if (Objects.isNull(proxyComponent)) {
return Optional.empty();
}
@@ -1602,30 +1705,30 @@ public class ToscaExportHandler {
addInputsToProperties(dataTypes, proxyComponent.getInputs(), proxyProperties);
if (CollectionUtils.isNotEmpty(proxyComponent.getProperties())) {
proxyProperties.putAll(proxyComponent.getProperties().stream()
- .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition,
- proxyComponent.getInputs()))
- .collect(Collectors.toMap(PropertyDataDefinition::getName,
- property -> propertyConvertor.convertProperty(dataTypes, property,
- PropertyConvertor.PropertyType.PROPERTY))));
+ .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition,
+ proxyComponent.getInputs()))
+ .collect(Collectors.toMap(PropertyDataDefinition::getName,
+ property -> propertyConvertor.convertProperty(dataTypes, property,
+ PropertyConvertor.PropertyType.PROPERTY))));
}
return MapUtils.isNotEmpty(proxyProperties) ? Optional.of(proxyProperties) : Optional.empty();
}
void addInputsToProperties(Map<String, DataTypeDefinition> dataTypes,
- List<InputDefinition> componentInputs,
- Map<String, ToscaProperty> mergedProperties) {
+ List<InputDefinition> componentInputs,
+ Map<String, ToscaProperty> mergedProperties) {
if (CollectionUtils.isEmpty(componentInputs)) {
return;
}
- for(InputDefinition input : componentInputs) {
+ for (InputDefinition input : componentInputs) {
ToscaProperty property = propertyConvertor.convertProperty(dataTypes, input,
- PropertyConvertor.PropertyType.INPUT);
+ PropertyConvertor.PropertyType.INPUT);
mergedProperties.put(input.getName(), property);
}
}
Optional<Map<String, Object>> getProxyNodeTypeInterfaces(Component proxyComponent,
- Map<String, DataTypeDefinition> dataTypes) {
+ Map<String, DataTypeDefinition> dataTypes) {
if (Objects.isNull(proxyComponent) || MapUtils.isEmpty(proxyComponent.getInterfaces())) {
return Optional.empty();
}
@@ -1634,17 +1737,17 @@ public class ToscaExportHandler {
// always available in the proxy node template
removeOperationImplementationForProxyNodeType(proxyComponentInterfaces);
return Optional.ofNullable(interfacesOperationsConverter
- .getInterfacesMap(proxyComponent, null, proxyComponentInterfaces, dataTypes,
- false, false));
+ .getInterfacesMap(proxyComponent, null, proxyComponentInterfaces, dataTypes,
+ false, false));
}
private static void removeOperationImplementationForProxyNodeType(
- Map<String, InterfaceDefinition> proxyComponentInterfaces) {
+ Map<String, InterfaceDefinition> proxyComponentInterfaces) {
if (MapUtils.isEmpty(proxyComponentInterfaces)) {
return;
}
proxyComponentInterfaces.values().stream().map(InterfaceDataDefinition::getOperations)
- .filter(MapUtils::isNotEmpty)
- .forEach(operations -> operations.values().forEach(operation -> operation.setImplementation(null)));
+ .filter(MapUtils::isNotEmpty)
+ .forEach(operations -> operations.values().forEach(operation -> operation.setImplementation(null)));
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java
index bbbb303900..376f211b70 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/SubstitutionMapping.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,38 +21,22 @@
package org.openecomp.sdc.be.tosca.model;
import java.util.Map;
-
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
+
+@Getter
+@Setter
+@NoArgsConstructor
+@EqualsAndHashCode
+@ToString
public class SubstitutionMapping {
+
private String node_type;
private Map<String, String[]> capabilities;
private Map<String, String[]> requirements;
+ private NodeFilter substitution_filter;
- public SubstitutionMapping() {
- super();
- // TODO Auto-generated constructor stub
- }
-
- public String getNode_type() {
- return node_type;
- }
-
- public void setNode_type(String node_type) {
- this.node_type = node_type;
- }
-
- public Map<String, String[]> getCapabilities() {
- return capabilities;
- }
-
- public void setCapabilities(Map<String, String[]> capabilities) {
- this.capabilities = capabilities;
- }
-
- public Map<String, String[]> getRequirements() {
- return requirements;
- }
-
- public void setRequirements(Map<String, String[]> requirements) {
- this.requirements = requirements;
- }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java
index 02da1130d6..cab7d53cd7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java
@@ -16,114 +16,17 @@
package org.openecomp.sdc.be.tosca.utils;
-import org.apache.commons.collections.CollectionUtils;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
-import org.openecomp.sdc.be.tosca.model.CapabilityFilter;
-import org.openecomp.sdc.be.tosca.model.NodeFilter;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.ui.model.UINodeFilter;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
public class NodeFilterConverter {
- public NodeFilter convertNodeFilter(CINodeFilterDataDefinition nodeFilterData) {
- NodeFilter retVal = new NodeFilter();
- if (nodeFilterData.getCapabilities() != null) {
- retVal.setCapabilities(convertCapabilities(nodeFilterData.getCapabilities().getListToscaDataDefinition()));
- }
- if (nodeFilterData.getProperties() != null) {
- retVal.setProperties(convertProperties(nodeFilterData.getProperties().getListToscaDataDefinition()));
- }
- return retVal;
- }
-
- private List<Map<String, CapabilityFilter>> convertCapabilities(
- List<RequirementNodeFilterCapabilityDataDefinition> capabilities) {
- if (CollectionUtils.isEmpty(capabilities)) {
- return Collections.emptyList();
- }
- return capabilities.stream().map(this::transformCapability).collect(Collectors.toList());
- }
-
- private Map<String, CapabilityFilter> transformCapability(
- RequirementNodeFilterCapabilityDataDefinition capability) {
- Map<String, CapabilityFilter> retVal = new HashMap<>();
- if (capability.getProperties() == null) {
- return retVal;
- }
- List<RequirementNodeFilterPropertyDataDefinition> propertyDataDefinitionList =
- capability.getProperties().getListToscaDataDefinition();
- for (RequirementNodeFilterPropertyDataDefinition propertyDataDefinition : propertyDataDefinitionList) {
- retVal.put(capability.getName(), convertCapabilityProperty(propertyDataDefinition));
- }
- return retVal;
- }
-
- private List<Map<String, List<Object>>> convertProperties(
- List<RequirementNodeFilterPropertyDataDefinition> properties) {
- if (CollectionUtils.isEmpty(properties)) {
- return Collections.emptyList();
- }
- return properties.stream().map(this::transformProperty).collect(Collectors.toList());
- }
-
- private CapabilityFilter convertCapabilityProperty(RequirementNodeFilterPropertyDataDefinition property) {
- TransformCapabilityData transformCapabilityData = new TransformCapabilityData(property).invoke();
- Map<String, List<Object>> tranformedMap = transformCapabilityData.getRetVal();
- List<Object> constraints = transformCapabilityData.getConstraints();
- tranformedMap.put(property.getName(), constraints);
- CapabilityFilter capabilityFilter = new CapabilityFilter();
- capabilityFilter.setProperties(Collections.singletonList(tranformedMap));
- return capabilityFilter;
- }
-
-
- private Map<String, List<Object>> transformProperty(RequirementNodeFilterPropertyDataDefinition property) {
- TransformCapabilityData transformCapabilityData = new TransformCapabilityData(property).invoke();
- Map<String, List<Object>> retVal = transformCapabilityData.getRetVal();
- List<Object> constraints = transformCapabilityData.getConstraints();
- retVal.put(property.getName(), constraints);
-
- return retVal;
- }
-
- private class TransformCapabilityData {
-
- private RequirementNodeFilterPropertyDataDefinition property;
- private Map<String, List<Object>> retVal;
- private List<Object> constraints;
-
- public TransformCapabilityData(RequirementNodeFilterPropertyDataDefinition property) {
- this.property = property;
- }
-
- public Map<String, List<Object>> getRetVal() {
- return retVal;
- }
-
- public List<Object> getConstraints() {
- return constraints;
- }
-
- public TransformCapabilityData invoke() {
- final List<String> propertyConstraints = property.getConstraints();
- if (CollectionUtils.isEmpty(propertyConstraints)) {
- return this;
- }
- this.constraints = propertyConstraints.stream().map(c -> (Object) c).collect(Collectors.toList());
- return this;
- }
- }
-
public Map<String, UINodeFilter> convertDataMapToUI(Map<String, CINodeFilterDataDefinition> inMap) {
return inMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, o -> convertToUi(o.getValue())));
}
@@ -135,9 +38,9 @@ public class NodeFilterConverter {
return retVal;
}
List<UIConstraint> constraints = inNodeFilter.getProperties().getListToscaDataDefinition().stream()
- .map(property -> property.getConstraints().iterator().next())
- .map(constraintConvertor::convert)
- .collect(Collectors.toList());
+ .map(property -> property.getConstraints().iterator().next())
+ .map(constraintConvertor::convert)
+ .collect(Collectors.toList());
retVal.setProperties(constraints);
return retVal;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/SubstitutionFilterConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/SubstitutionFilterConverter.java
new file mode 100644
index 0000000000..326ebf3709
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/SubstitutionFilterConverter.java
@@ -0,0 +1,50 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.utils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
+import org.openecomp.sdc.be.ui.model.UIConstraint;
+import org.openecomp.sdc.be.ui.model.UINodeFilter;
+
+public class SubstitutionFilterConverter {
+
+ public Map<String, UINodeFilter> convertDataMapToUI(Map<String, SubstitutionFilterDataDefinition> inMap) {
+ return inMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, o -> convertToUi(o.getValue())));
+ }
+
+ public UINodeFilter convertToUi(final SubstitutionFilterDataDefinition inSubstitutionFilter) {
+ final UINodeFilter uiNodeFilter = new UINodeFilter();
+ final ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ if (inSubstitutionFilter.getProperties() == null || inSubstitutionFilter.getProperties().isEmpty()) {
+ return uiNodeFilter;
+ }
+ final List<UIConstraint> constraints = inSubstitutionFilter.getProperties().getListToscaDataDefinition()
+ .stream()
+ .map(property -> property.getConstraints().iterator().next())
+ .map(constraintConvertor::convert)
+ .collect(Collectors.toList());
+ uiNodeFilter.setProperties(constraints);
+ return uiNodeFilter;
+ }
+}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
index d75a731b04..c4a4acecbc 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java
@@ -251,7 +251,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator
- .validateNodeFilter(resource, componentInstanceId,
+ .validateFilter(resource, componentInstanceId,
requirementNodeFilterPropertyDataDefinition.getConstraints(),
NodeFilterConstraintAction.ADD)).thenReturn(Either.left(true));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
@@ -268,7 +268,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource);
- verify(nodeFilterValidator, times(1)).validateNodeFilter(resource, componentInstanceId,
+ verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId,
constraints, NodeFilterConstraintAction.ADD);
verify(nodeFilterOperation, times(0))
.addNewProperty(componentId, componentInstanceId, ciNodeFilterDataDefinition,
@@ -295,7 +295,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
- when(nodeFilterValidator.validateNodeFilter(resource, componentInstanceId, singletonList(constraint),
+ when(nodeFilterValidator.validateFilter(resource, componentInstanceId, singletonList(constraint),
NodeFilterConstraintAction.DELETE)).thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -318,7 +318,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
verify(nodeFilterValidator, times(1))
.validateComponentInstanceExist(resource, componentInstanceId);
verify(nodeFilterValidator, times(1))
- .validateNodeFilter(resource, componentInstanceId, singletonList(constraint),
+ .validateFilter(resource, componentInstanceId, singletonList(constraint),
NodeFilterConstraintAction.DELETE);
verify(nodeFilterOperation, times(1))
.deleteConstraint(componentId, componentInstanceId, ciNodeFilterDataDefinition, 0);
@@ -332,7 +332,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
- when(nodeFilterValidator.validateNodeFilter(resource, componentInstanceId, singletonList(constraint),
+ when(nodeFilterValidator.validateFilter(resource, componentInstanceId, singletonList(constraint),
NodeFilterConstraintAction.DELETE)).thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -351,7 +351,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(graphLockOperation, times(1)).lockComponent(componentId, NodeTypeEnum.Resource);
verify(nodeFilterValidator, times(1))
- .validateNodeFilter(resource, componentInstanceId, singletonList(constraint),
+ .validateFilter(resource, componentInstanceId, singletonList(constraint),
NodeFilterConstraintAction.DELETE);
verify(nodeFilterValidator, times(1))
.validateComponentInstanceExist(resource, componentInstanceId);
@@ -363,7 +363,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
when(nodeFilterValidator.validateComponentInstanceExist(resource, componentInstanceId))
.thenReturn(Either.left(true));
- when(nodeFilterValidator.validateNodeFilter(resource, componentInstanceId, singletonList(constraint),
+ when(nodeFilterValidator.validateFilter(resource, componentInstanceId, singletonList(constraint),
NodeFilterConstraintAction.DELETE)).thenReturn(Either.left(true));
assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
@@ -372,7 +372,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
verify(nodeFilterValidator, times(1))
- .validateNodeFilter(resource, componentInstanceId, singletonList(constraint),
+ .validateFilter(resource, componentInstanceId, singletonList(constraint),
NodeFilterConstraintAction.DELETE);
verify(nodeFilterValidator, times(1))
.validateComponentInstanceExist(resource, componentInstanceId);
@@ -383,7 +383,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
componentInstance.setNodeFilter(ciNodeFilterDataDefinition);
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
- when(nodeFilterValidator.validateNodeFilter(resource, componentInstanceId,
+ when(nodeFilterValidator.validateFilter(resource, componentInstanceId,
Collections.singletonList(constraint), NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
when(graphLockOperation.lockComponent(componentId, NodeTypeEnum.Resource))
.thenReturn(StorageOperationStatus.OK);
@@ -395,7 +395,7 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
.updateNodeFilter(componentId, componentInstanceId, constraints, true, ComponentTypeEnum.RESOURCE));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
- verify(nodeFilterValidator, times(1)).validateNodeFilter(resource, componentInstanceId,
+ verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId,
constraints, NodeFilterConstraintAction.UPDATE);
}
@@ -403,14 +403,14 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock
public void updateNodeFilterFailValidationTest() {
final List<String> constraints = requirementNodeFilterPropertyDataDefinition.getConstraints();
when(toscaOperationFacade.getToscaElement(componentId)).thenReturn(Either.left(resource));
- when(nodeFilterValidator.validateNodeFilter(resource, componentInstanceId,
+ when(nodeFilterValidator.validateFilter(resource, componentInstanceId,
constraints, NodeFilterConstraintAction.UPDATE)).thenReturn(Either.left(true));
assertThrows(BusinessLogicException.class, () -> componentNodeFilterBusinessLogic
.updateNodeFilter(componentId, componentInstanceId, constraints, true, ComponentTypeEnum.RESOURCE));
verify(toscaOperationFacade, times(1)).getToscaElement(componentId);
- verify(nodeFilterValidator, times(1)).validateNodeFilter(resource, componentInstanceId,
+ verify(nodeFilterValidator, times(1)).validateFilter(resource, componentInstanceId,
constraints, NodeFilterConstraintAction.UPDATE);
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java
index 4b254701a7..83a968c756 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java
@@ -72,7 +72,7 @@ public class NodeFilterValidationTest {
public void testValidateNodeFilterStaticIncorrectPropertyTypeProvided() {
Service service = createService("booleanIncorrect");
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE,
Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")),
NodeFilterConstraintAction.ADD);
@@ -83,7 +83,7 @@ public class NodeFilterValidationTest {
public void testValidateNodeFilterStaticIncorrectOperatorProvidedBoolean() {
Service service = createService("boolean");
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE,
Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")
.replace("equal", "greater_than")),
NodeFilterConstraintAction.ADD);
@@ -95,7 +95,7 @@ public class NodeFilterValidationTest {
public void testValidateNodeFilterStaticIncorrectValueProvidedBoolean() {
Service service = createService("boolean");
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE,
Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "trues")),
NodeFilterConstraintAction.ADD);
@@ -106,7 +106,7 @@ public class NodeFilterValidationTest {
public void testValidateNodeFilterStaticIncorrectOperatorProvidedString() {
Service service = createService(STRING_TYPE);
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE,
Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")
.replace("equal", "greater_than")),
NodeFilterConstraintAction.ADD);
@@ -118,7 +118,7 @@ public class NodeFilterValidationTest {
public void testValidateNodeFilterIntegerValueSuccess() {
Service service = createService(INTEGER_TYPE);
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE,
Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1")),
NodeFilterConstraintAction.ADD);
@@ -133,7 +133,7 @@ public class NodeFilterValidationTest {
.thenReturn(new ResponseFormat());
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE,
Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1.0")),
NodeFilterConstraintAction.ADD);
@@ -144,7 +144,7 @@ public class NodeFilterValidationTest {
public void testValidateNodeFilterFloatValueSuccess() {
Service service = createService(FLOAT_TYPE);
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE,
Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "1.0")),
NodeFilterConstraintAction.ADD);
@@ -159,7 +159,7 @@ public class NodeFilterValidationTest {
.thenReturn(new ResponseFormat());
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE,
Collections.singletonList(UI_CONSTRAINT_STATIC), NodeFilterConstraintAction.ADD);
Assert.assertTrue(either.isRight());
@@ -169,7 +169,7 @@ public class NodeFilterValidationTest {
public void testValidateNodeFilterStringValueSuccess() {
Service service = createService(STRING_TYPE);
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, INNER_SERVICE,
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE,
Collections.singletonList(UI_CONSTRAINT_STATIC), NodeFilterConstraintAction.ADD);
Assert.assertTrue(either.isLeft());
@@ -179,7 +179,7 @@ public class NodeFilterValidationTest {
public void testValidatePropertyConstraintBrotherSuccess() {
Service service = createService(STRING_TYPE);
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ " equal: { get_property :[component2, Prop1]}\n"), NodeFilterConstraintAction.ADD);
Assert.assertTrue(either.isLeft());
@@ -189,7 +189,7 @@ public class NodeFilterValidationTest {
public void testValidatePropertyConstraintParentSuccess() {
Service service = createService(STRING_TYPE);
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD);
Assert.assertTrue(either.isLeft());
@@ -201,7 +201,7 @@ public class NodeFilterValidationTest {
service.getComponentInstancesProperties().get(COMPONENT2_ID).get(0).setType(INTEGER_TYPE);
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ " equal: { get_property : [component2, Prop1]}\n"), NodeFilterConstraintAction.ADD);
Assert.assertFalse(either.isLeft());
@@ -213,7 +213,7 @@ public class NodeFilterValidationTest {
service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(INTEGER_TYPE);
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD);
Assert.assertFalse(either.isLeft());
@@ -225,7 +225,7 @@ public class NodeFilterValidationTest {
service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD);
Assert.assertFalse(either.isLeft());
@@ -237,7 +237,7 @@ public class NodeFilterValidationTest {
service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD);
Assert.assertFalse(either.isLeft());
@@ -249,7 +249,7 @@ public class NodeFilterValidationTest {
service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(LIST_TYPE);
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateNodeFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ nodeFilterValidator.validateFilter(service, COMPONENT1_ID, Collections.singletonList("Prop1:\n"
+ " equal: { get_property : [parentservice, Prop1]}\n"), NodeFilterConstraintAction.ADD);
Assert.assertFalse(either.isLeft());
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java
index 09824fc16d..42967224c5 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java
@@ -145,6 +145,9 @@ public enum ActionStatus {
SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
SOURCE_TARGET_SCHEMA_MISMATCH,
UNSUPPORTED_PROPERTY_TYPE,
+ //Filter
+ SUBSTITUTION_FILTER_NOT_FOUND,
+ FILTER_NOT_FOUND,
//InterfaceLifeCycleType
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/EdgeLabelEnum.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/EdgeLabelEnum.java
index d35f00b5f8..dab74441e9 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/EdgeLabelEnum.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/EdgeLabelEnum.java
@@ -66,6 +66,7 @@ public enum EdgeLabelEnum {
INTERFACE_OPERATION,
INST_INTERFACES,
NODE_FILTER_TEMPLATE,
+ SUBSTITUTION_FILTER_TEMPLATE,
DATA_TYPES;
/**
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/VertexTypeEnum.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/VertexTypeEnum.java
index 01d3ac493d..e266a21ce6 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/VertexTypeEnum.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/types/VertexTypeEnum.java
@@ -22,8 +22,28 @@ package org.openecomp.sdc.be.dao.jsongraph.types;
import lombok.AllArgsConstructor;
import lombok.Getter;
-import org.openecomp.sdc.be.datatypes.elements.*;
-import org.openecomp.sdc.be.resources.data.DataTypeData;
+import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
+import org.openecomp.sdc.be.datatypes.elements.MapComponentInstanceExternalRefs;
+import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
@Getter
@AllArgsConstructor
@@ -66,6 +86,7 @@ public enum VertexTypeEnum {
INTERFACE ("interface", InterfaceDataDefinition.class),
INTERFACE_OPERATION ("interfaceOperation", OperationDataDefinition.class),
NODE_FILTER_TEMPLATE ("NodeTemplateFilter", CINodeFilterDataDefinition.class),
+ SUBSTITUTION_FILTER_TEMPLATE ("substitution_mapping", SubstitutionFilterDataDefinition.class),
INST_INTERFACES ("InstInterfaces", MapInterfaceDataDefinition.class),
DATA_TYPES ("data_types", DataTypeDataDefinition.class);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
index 477d903652..dc0fb51d7c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
@@ -48,6 +48,7 @@ import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
@@ -83,6 +84,7 @@ public abstract class Component implements PropertiesOwner {
private String derivedFromGenericVersion;
private String toscaType;
private Map<String, CINodeFilterDataDefinition> nodeFilterComponents;
+ private Map<String, SubstitutionFilterDataDefinition> substitutionFilterComponents;
private Map<String, InterfaceDefinition> interfaces;
private List<DataTypeDefinition> dataTypes;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java
index 3eefcc1505..5b99f99bd2 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java
@@ -20,20 +20,24 @@
package org.openecomp.sdc.be.model;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
import org.apache.commons.collections.MapUtils;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.log.api.ILogConfiguration;
-import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class ComponentInstance extends ComponentInstanceDataDefinition implements PropertiesOwner{
+@Getter
+@Setter
+public class ComponentInstance extends ComponentInstanceDataDefinition implements PropertiesOwner {
private Map<String, List<CapabilityDefinition>> capabilities;
private Map<String, List<RequirementDefinition>> requirements;
@@ -43,6 +47,7 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement
private Map<String, Object> interfaces;
private List<PropertyDefinition> properties;
private CINodeFilterDataDefinition nodeFilter;
+ private SubstitutionFilterDataDefinition substitutionFilter;
private List<InputDefinition> inputs;
public ComponentInstance() {
@@ -53,26 +58,6 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement
super(r);
}
- public Map<String, List<CapabilityDefinition>> getCapabilities() {
- return capabilities;
- }
-
- public void setCapabilities(Map<String, List<CapabilityDefinition>> capabilities) {
- this.capabilities = capabilities;
- }
-
- public Map<String, List<RequirementDefinition>> getRequirements() {
- return requirements;
- }
-
- public void setRequirements(Map<String, List<RequirementDefinition>> requirements) {
- this.requirements = requirements;
- }
-
- public Map<String, ArtifactDefinition> getDeploymentArtifacts() {
- return deploymentArtifacts;
- }
-
public Map<String, ArtifactDefinition> safeGetDeploymentArtifacts() {
return deploymentArtifacts == null ? Collections.emptyMap() : deploymentArtifacts;
}
@@ -81,30 +66,10 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement
return artifacts == null ? Collections.emptyMap() : deploymentArtifacts;
}
- public void setDeploymentArtifacts(Map<String, ArtifactDefinition> deploymentArtifacts) {
- this.deploymentArtifacts = deploymentArtifacts;
- }
-
- public Map<String, ArtifactDefinition> getArtifacts() {
- return artifacts;
- }
-
public Map<String, ArtifactDefinition> safeGetArtifacts() {
return artifacts == null ? Collections.emptyMap() : artifacts;
}
- public void setArtifacts(Map<String, ArtifactDefinition> artifacts) {
- this.artifacts = artifacts;
- }
-
- public List<GroupInstance> getGroupInstances() {
- return groupInstances;
- }
-
- public void setGroupInstances(List<GroupInstance> groupInstances) {
- this.groupInstances = groupInstances;
- }
-
public String getActualComponentUid() {
return getIsProxy() ? getSourceModelUid() : getComponentUid();
}
@@ -116,57 +81,24 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement
return safeGetInformationalArtifacts().get(artifactLabel) != null;
}
- public Map<String, Object> getInterfaces() {
- return interfaces;
- }
-
- public void setInterfaces(Map<String, Object> interfaces) {
- this.interfaces = interfaces;
- }
-
public void addInterface(String interfaceName, Object interfaceDefinition) {
- if(MapUtils.isEmpty(this.interfaces)) {
+ if (MapUtils.isEmpty(this.interfaces)) {
this.interfaces = new HashMap<>();
}
-
this.interfaces.put(interfaceName, interfaceDefinition);
}
- public List<PropertyDefinition> getProperties() {
- return properties;
- }
-
- public void setProperties(List<PropertyDefinition> properties) {
- this.properties = properties;
- }
-
- public CINodeFilterDataDefinition getNodeFilter() {
- return nodeFilter;
- }
-
- public void setNodeFilter(CINodeFilterDataDefinition nodeFilter) {
- this.nodeFilter = nodeFilter;
- }
-
//supportability log method return map of component metadata teddy.h
- public Map<String,String> getComponentMetadataForSupportLog(){
- Map<String,String>componentMetadata=new HashMap<>();
- componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME,getName());
- componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION,getVersion());
+ public Map<String, String> getComponentMetadataForSupportLog() {
+ Map<String, String> componentMetadata = new HashMap<>();
+ componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME, getName());
+ componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION, getVersion());
componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID, getSourceModelUuid());
return componentMetadata;
}
- public boolean isCreatedFromCsar(){
+ public boolean isCreatedFromCsar() {
return CreatedFrom.CSAR.equals(this.getCreatedFrom());
}
- public List<InputDefinition> getInputs() {
- return inputs;
- }
-
- public void setInputs(List<InputDefinition> inputs) {
- this.inputs = inputs;
- }
-
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java
index 4e7903a890..f1785c76f8 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java
@@ -50,7 +50,9 @@ public class ComponentParametersView {
private boolean ignoreServicePath = true;
private boolean ignorePolicies = false;
private boolean ignoreNodeFilterRequirements = false;
+ private boolean ignoreSubstitutionFilterRequirements = false;
private boolean ignoreNodeFilter = false;
+ private boolean ignoreSubstitutionFilter = false;
private boolean ignoreDataType = false;
public ComponentParametersView() {
@@ -95,6 +97,7 @@ public class ComponentParametersView {
this.setIgnoreCapabilities(false);
this.setIgnoreRequirements(false);
this.setIgnoreNodeFilter(false);
+ this.setIgnoreSubstitutionFilter(false);
this.setIgnoreCapabiltyProperties(false);
break;
case COMPONENT_INSTANCES_PROPERTIES:
@@ -153,6 +156,10 @@ public class ComponentParametersView {
this.setIgnoreNodeFilterRequirements(false);
this.setIgnoreNodeFilter(false);
break;
+ case SUBSTITUTION_FILTER:
+ this.setIgnoreSubstitutionFilterRequirements(false);
+ this.setIgnoreSubstitutionFilter(false);
+ break;
case COMPONENT_INSTANCES_INTERFACES:
this.setIgnoreComponentInstances(false);
this.setIgnoreComponentInstancesInterfaces(false);
@@ -216,6 +223,9 @@ public class ComponentParametersView {
if (ignoreNodeFilterRequirements){
component.setNodeFilterComponents(null);
}
+ if (ignoreSubstitutionFilterRequirements){
+ component.setSubstitutionFilterComponents(null);
+ }
if (ignoreInterfaces && ignoreInterfaceInstances &&
componentType == ComponentTypeEnum.RESOURCE) {
component.setInterfaces(null);
@@ -241,6 +251,9 @@ public class ComponentParametersView {
if (ignoreNodeFilter){
component.setNodeFilterComponents(null);
}
+ if (ignoreSubstitutionFilter){
+ component.setSubstitutionFilterComponents(null);
+ }
if (ignoreDataType) {
component.setDataTypes(null);
}
@@ -255,6 +268,14 @@ public class ComponentParametersView {
this.ignoreNodeFilterRequirements = ignoreNodeFilter;
}
+ public boolean isIgnoreSubstitutionFilterRequirements() {
+ return ignoreSubstitutionFilterRequirements;
+ }
+
+ public void setIgnoreSubstitutionFilterRequirements(boolean ignoreSubstitutionFilterRequirements) {
+ this.ignoreSubstitutionFilterRequirements = ignoreSubstitutionFilterRequirements;
+ }
+
public void disableAll() {
ignoreUsers = true;
ignoreGroups = true;
@@ -278,7 +299,9 @@ public class ComponentParametersView {
ignoreCapabiltyProperties = true;
ignoreServicePath = true;
ignoreNodeFilterRequirements = true;
+ ignoreSubstitutionFilterRequirements = true;
ignoreNodeFilter = true;
+ ignoreSubstitutionFilter = true;
ignoreDataType = true;
}
@@ -462,6 +485,14 @@ public class ComponentParametersView {
this.ignoreNodeFilter = ignoreNodeFilter;
}
+ public boolean isIgnoreSubstitutionFilter() {
+ return ignoreSubstitutionFilter;
+ }
+
+ public void setIgnoreSubstitutionFilter(boolean ignoreSubstitutionFilter) {
+ this.ignoreSubstitutionFilter = ignoreSubstitutionFilter;
+ }
+
public boolean isIgnoreDataType() {
return ignoreDataType;
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java
index a02b07df15..db330e9b19 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java
@@ -60,6 +60,7 @@ public class TopologyTemplate extends ToscaElement{
private Map<String, DataTypeDataDefinition> dataTypes;
private Map<String, CINodeFilterDataDefinition> nodeFilterComponents;
+ private Map<String, SubstitutionFilterDataDefinition> substitutionFilterDataDefinitionMap;
//Component Instances External References (instanceId -> ExternalRefsMap)
//-----------------------------------------------------------------------
private Map<String, MapComponentInstanceExternalRefs> mapComponentInstancesExternalRefs;
@@ -240,6 +241,15 @@ public class TopologyTemplate extends ToscaElement{
this.nodeFilterComponents = nodeFilters;
}
+ public Map<String, SubstitutionFilterDataDefinition> getSubstitutionFilterDataDefinitionMap() {
+ return substitutionFilterDataDefinitionMap;
+ }
+
+ public void setSubstitutionFilterDataDefinitionMap(
+ Map<String, SubstitutionFilterDataDefinition> substitutionFilterDataDefinitionMap) {
+ this.substitutionFilterDataDefinitionMap = substitutionFilterDataDefinitionMap;
+ }
+
/**
* Gets data types.
* @return Current data types.
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/BaseOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/BaseOperation.java
index 14ce6be609..9e12e6e67d 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/BaseOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/BaseOperation.java
@@ -882,7 +882,12 @@ public abstract class BaseOperation {
}
@SuppressWarnings("unchecked")
- private <T extends ToscaDataDefinition> StorageOperationStatus updateOrAddToscaData(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List<T> toscaDataList, JsonPresentationFields mapKeyField, boolean isUpdate) {
+ private <T extends ToscaDataDefinition> StorageOperationStatus updateOrAddToscaData(GraphVertex toscaElement,
+ EdgeLabelEnum edgeLabel,
+ VertexTypeEnum vertexLabel,
+ List<T> toscaDataList,
+ JsonPresentationFields mapKeyField,
+ boolean isUpdate) {
StorageOperationStatus result = null;
GraphVertex toscaDataVertex = null;
Map<String, T> existingToscaDataMap = null;
@@ -892,7 +897,9 @@ public abstract class BaseOperation {
.getChildVertex(toscaElement, edgeLabel, JsonParseFlagEnum.ParseJson);
if (toscaDataVertexRes.isRight() && toscaDataVertexRes.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
JanusGraphOperationStatus status = toscaDataVertexRes.right().value();
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_GET_CHILD_VERTEX_OF_THE_TOSCA_ELEMENT_BY_LABEL_STATUS_IS, toscaElement.getUniqueId(), edgeLabel, status);
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG,
+ FAILED_TO_GET_CHILD_VERTEX_OF_THE_TOSCA_ELEMENT_BY_LABEL_STATUS_IS, toscaElement.getUniqueId(),
+ edgeLabel, status);
result = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(toscaDataVertexRes.right().value());
}
if (result == null) {
@@ -1423,14 +1430,6 @@ public abstract class BaseOperation {
return status;
}
-// public StorageOperationStatus updateDataOnGraph(GraphVertex dataVertex) {
-// Either<GraphVertex, JanusGraphOperationStatus> updateVertex = janusGraphDao.updateVertex(dataVertex);
-// if (updateVertex.isRight()) {
-// return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateVertex.right().value());
-// }
-// return StorageOperationStatus.OK;
-// }
-
protected GroupInstanceDataDefinition buildGroupInstanceDataDefinition(GroupDataDefinition group, ComponentInstanceDataDefinition componentInstance, Map<String, ArtifactDataDefinition> instDeplArtifMap) {
String componentInstanceName = componentInstance.getName();
@@ -1449,21 +1448,6 @@ public abstract class BaseOperation {
groupInstance.setUniqueId(UniqueIdBuilder.buildResourceInstanceUniuqeId(componentInstance.getUniqueId(), groupUid, groupInstance.getNormalizedName()));
groupInstance.setArtifacts(group.getArtifacts());
-// List<String> fixedArtifactsUuid;
-// List<String> artifactsUuid = group.getArtifactsUuid();
-// if (instDeplArtifMap != null) {
-// fixedArtifactsUuid = new ArrayList<>();
-// artifactsUuid.forEach(u -> {
-// Optional<ArtifactDataDefinition> findFirst = instDeplArtifMap.values().stream().filter(a -> u.equals(a.getUniqueId())).findFirst();
-// if (findFirst.isPresent()) {
-// fixedArtifactsUuid.add(findFirst.get().getArtifactUUID());
-// } else {
-// fixedArtifactsUuid.add(u);
-// }
-// });
-// } else {
-// fixedArtifactsUuid = artifactsUuid;
-// }
groupInstance.setArtifactsUuid(group.getArtifactsUuid());
groupInstance.setProperties(group.getProperties());
convertPropertiesToInstanceProperties(groupInstance.getProperties());
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java
index 5f0284a159..69c9f4e59d 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java
@@ -41,7 +41,7 @@ import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
import org.openecomp.sdc.common.log.wrappers.Logger;
-@org.springframework.stereotype.Component("service-filter-operations")
+@org.springframework.stereotype.Component("node-filter-operations")
public class NodeFilterOperation extends BaseOperation {
private static Logger logger = Logger.getLogger(NodeFilterOperation.class);
@@ -82,14 +82,16 @@ public class NodeFilterOperation extends BaseOperation {
}
- public Either<CINodeFilterDataDefinition, StorageOperationStatus> createNodeFilter(String serviceId,
- String componentInstanceId) {
+ public Either<CINodeFilterDataDefinition, StorageOperationStatus> createNodeFilter(final String componentId,
+ final String componentInstanceId) {
CINodeFilterDataDefinition nodeFilterDataDefinition = new CINodeFilterDataDefinition();
- return addOrUpdateNodeFilter(false, serviceId, componentInstanceId, nodeFilterDataDefinition);
+ return addOrUpdateNodeFilter(false, componentId, componentInstanceId, nodeFilterDataDefinition);
}
- public Either<CINodeFilterDataDefinition, StorageOperationStatus> deleteConstraint(String serviceId,
- String componentInstanceId, CINodeFilterDataDefinition nodeFilterDataDefinition, int propertyIndex) {
+ public Either<CINodeFilterDataDefinition, StorageOperationStatus> deleteConstraint(final String serviceId,
+ final String componentInstanceId,
+ final CINodeFilterDataDefinition nodeFilterDataDefinition,
+ final int propertyIndex) {
ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> properties =
nodeFilterDataDefinition.getProperties();
properties.getListToscaDataDefinition().remove(propertyIndex);
@@ -113,9 +115,11 @@ public class NodeFilterOperation extends BaseOperation {
return addOrUpdateNodeFilter(true, componentId, componentInstanceId, nodeFilterDataDefinition);
}
- public Either<CINodeFilterDataDefinition, StorageOperationStatus> updateProperties(String serviceId,
- String componentInstanceId, CINodeFilterDataDefinition nodeFilterDataDefinition,
- List<RequirementNodeFilterPropertyDataDefinition> requirementNodeFilterPropertyDataDefinition) {
+ public Either<CINodeFilterDataDefinition, StorageOperationStatus> updateProperties(
+ final String serviceId, final String componentInstanceId,
+ final CINodeFilterDataDefinition nodeFilterDataDefinition,
+ final List<RequirementNodeFilterPropertyDataDefinition> requirementNodeFilterPropertyDataDefinition) {
+
ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> properties =
nodeFilterDataDefinition.getProperties();
properties.getListToscaDataDefinition().clear();
@@ -124,22 +128,24 @@ public class NodeFilterOperation extends BaseOperation {
return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, nodeFilterDataDefinition);
}
- public Either<CINodeFilterDataDefinition, StorageOperationStatus> updateNodeFilter(String serviceId,
- String componentInstanceId, CINodeFilterDataDefinition ciNodeFilterDataDefinition) {
+ public Either<CINodeFilterDataDefinition, StorageOperationStatus> updateNodeFilter(final String serviceId,
+ final String componentInstanceId,
+ final CINodeFilterDataDefinition ciNodeFilterDataDefinition) {
return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, ciNodeFilterDataDefinition);
}
- private Either<CINodeFilterDataDefinition, StorageOperationStatus> addOrUpdateNodeFilter(boolean isUpdateAction,
- String serviceId, String componentInstanceId, CINodeFilterDataDefinition ciNodeFilterDataDefinition) {
+ private Either<CINodeFilterDataDefinition, StorageOperationStatus> addOrUpdateNodeFilter(
+ final boolean isUpdateAction, final String componentId, final String componentInstanceId,
+ final CINodeFilterDataDefinition ciNodeFilterDataDefinition) {
StorageOperationStatus statusRes;
Either<GraphVertex, JanusGraphOperationStatus> getToscaElementRes;
- getToscaElementRes = janusGraphDao.getVertexById(serviceId, JsonParseFlagEnum.NoParse);
+ getToscaElementRes = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
if (getToscaElementRes.isRight()) {
JanusGraphOperationStatus status = getToscaElementRes.right().value();
CommonUtility.addRecordToLog(logger, CommonUtility.LogLevelEnum.DEBUG,
- "Failed to get tosca element {} upon adding the properties. Status is {}. ", serviceId, status);
+ "Failed to get tosca element {} upon adding the properties. Status is {}. ", componentId, status);
statusRes = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status);
return Either.right(statusRes);
}
@@ -150,23 +156,22 @@ public class NodeFilterOperation extends BaseOperation {
janusGraphDao.rollback();
logger.error(
" Failed to perform tosca update for node filter in service {} , component instance {}. status is {}",
- serviceId, componentInstanceId, statusRes);
+ componentId, componentInstanceId, statusRes);
return Either.right(statusRes);
}
janusGraphDao.commit();
return Either.left(ciNodeFilterDataDefinition);
-
}
-
- private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, GraphVertex graphVertex,
- List<CINodeFilterDataDefinition> toscaDataList) {
+ private StorageOperationStatus performUpdateToscaAction(final boolean isUpdate,
+ final GraphVertex graphVertex,
+ final List<CINodeFilterDataDefinition> toscaDataList) {
if (isUpdate) {
return updateToscaDataOfToscaElement(graphVertex, EdgeLabelEnum.NODE_FILTER_TEMPLATE,
- VertexTypeEnum.NODE_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID);
+ VertexTypeEnum.NODE_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID);
} else {
return addToscaDataToToscaElement(graphVertex, EdgeLabelEnum.NODE_FILTER_TEMPLATE,
- VertexTypeEnum.NODE_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID);
+ VertexTypeEnum.NODE_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID);
}
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java
new file mode 100644
index 0000000000..9007e20998
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java
@@ -0,0 +1,139 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
+
+import com.google.common.collect.ImmutableList;
+import fj.data.Either;
+import java.util.List;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
+import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
+import org.openecomp.sdc.common.log.enums.EcompErrorSeverity;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+
+@org.springframework.stereotype.Component("substitution-filter-operations")
+public class SubstitutionFilterOperation extends BaseOperation {
+
+ private static final Logger LOGGER = Logger.getLogger(SubstitutionFilterOperation.class);
+
+ public Either<SubstitutionFilterDataDefinition, StorageOperationStatus> createSubstitutionFilter(
+ final String componentId, final String componentInstanceId) {
+
+ return addOrUpdateSubstitutionFilter(false, componentId, componentInstanceId,
+ new SubstitutionFilterDataDefinition());
+ }
+
+ public Either<SubstitutionFilterDataDefinition, StorageOperationStatus> deleteConstraint(
+ final String serviceId, final String componentInstanceId,
+ final SubstitutionFilterDataDefinition substitutionFilterDataDefinition, final int propertyIndex) {
+
+ final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> properties =
+ substitutionFilterDataDefinition.getProperties();
+ properties.getListToscaDataDefinition().remove(propertyIndex);
+ substitutionFilterDataDefinition.setProperties(properties);
+ return addOrUpdateSubstitutionFilter(true, serviceId, componentInstanceId, substitutionFilterDataDefinition);
+ }
+
+ public Either<SubstitutionFilterDataDefinition, StorageOperationStatus> addNewProperty(
+ final String componentId, final String componentInstanceId,
+ final SubstitutionFilterDataDefinition substitutionFilterDataDefinition,
+ final RequirementSubstitutionFilterPropertyDataDefinition requirementSubstitutionFilterPropertyDataDefinition) {
+
+ ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> properties =
+ substitutionFilterDataDefinition.getProperties();
+ if (properties == null) {
+ properties = new ListDataDefinition<>();
+ substitutionFilterDataDefinition.setProperties(properties);
+ }
+ properties.getListToscaDataDefinition().add(requirementSubstitutionFilterPropertyDataDefinition);
+ substitutionFilterDataDefinition.setProperties(properties);
+ return addOrUpdateSubstitutionFilter(true, componentId, componentInstanceId, substitutionFilterDataDefinition);
+ }
+
+ public Either<SubstitutionFilterDataDefinition, StorageOperationStatus> updateSubstitutionFilter(
+ final String serviceId, final String componentInstanceId,
+ final SubstitutionFilterDataDefinition substitutionFilterDataDefinition,
+ final List<RequirementSubstitutionFilterPropertyDataDefinition> requirementSubstitutionFilterPropertyDataDefinitions) {
+
+ final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> properties =
+ substitutionFilterDataDefinition.getProperties();
+ properties.getListToscaDataDefinition().clear();
+ properties.getListToscaDataDefinition().addAll(requirementSubstitutionFilterPropertyDataDefinitions);
+ substitutionFilterDataDefinition.setProperties(properties);
+ return addOrUpdateSubstitutionFilter(true, serviceId, componentInstanceId,
+ substitutionFilterDataDefinition);
+ }
+
+ private Either<SubstitutionFilterDataDefinition, StorageOperationStatus> addOrUpdateSubstitutionFilter(
+ final boolean isUpdateAction, final String componentId, final String componentInstanceId,
+ final SubstitutionFilterDataDefinition substitutionFilterDataDefinition) {
+
+ StorageOperationStatus statusRes;
+ Either<GraphVertex, JanusGraphOperationStatus> getToscaElementRes;
+
+ getToscaElementRes = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getToscaElementRes.isRight()) {
+ final JanusGraphOperationStatus status = getToscaElementRes.right().value();
+ CommonUtility.addRecordToLog(LOGGER, CommonUtility.LogLevelEnum.DEBUG,
+ "Failed to get tosca element {} upon adding the properties. Status is {}. ", componentId, status);
+ statusRes = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status);
+ return Either.right(statusRes);
+ }
+ final GraphVertex serviceVertex = getToscaElementRes.left().value();
+ substitutionFilterDataDefinition.setID(componentInstanceId);
+ statusRes = performUpdateToscaAction(isUpdateAction, serviceVertex,
+ ImmutableList.of(substitutionFilterDataDefinition));
+ if (!statusRes.equals(StorageOperationStatus.OK)) {
+ janusGraphDao.rollback();
+ LOGGER.error(EcompErrorSeverity.ERROR, EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR,
+ " Failed to perform tosca update for substitution filter in service {} , component instance {}. status is {}",
+ componentId, componentInstanceId, statusRes);
+ return Either.right(statusRes);
+ }
+ janusGraphDao.commit();
+ return Either.left(substitutionFilterDataDefinition);
+ }
+
+ private StorageOperationStatus performUpdateToscaAction(final boolean isUpdate,
+ final GraphVertex graphVertex,
+ final List<SubstitutionFilterDataDefinition> toscaDataList) {
+ if (isUpdate) {
+ return updateToscaDataOfToscaElement(graphVertex, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE,
+ VertexTypeEnum.SUBSTITUTION_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID);
+ } else {
+ return addToscaDataToToscaElement(graphVertex, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE,
+ VertexTypeEnum.SUBSTITUTION_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID);
+ }
+ }
+
+}
+
+
+
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
index 3f28d72ef4..cc6cd1d430 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
@@ -31,15 +31,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.stream.Collectors;
import org.apache.commons.collections.MapUtils;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
@@ -48,8 +39,6 @@ import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
-import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
-import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
@@ -62,13 +51,16 @@ import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
@@ -791,6 +783,14 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
}
+ if (!componentParametersView.isIgnoreSubstitutionFilter()) {
+ status = setSubstitutionFilterComponentFromGraph(componentV, toscaElement);
+ if (status != JanusGraphOperationStatus.OK) {
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
+
+ }
+ }
+
if (!componentParametersView.isIgnoreInterfaces()) {
JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
if (storageStatus != JanusGraphOperationStatus.OK) {
@@ -996,11 +996,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return JanusGraphOperationStatus.OK;
}
- private JanusGraphOperationStatus setNodeFilterComponentFromGraph(GraphVertex componentV,
- TopologyTemplate topologyTemplate) {
- Either<Map<String, CINodeFilterDataDefinition>, JanusGraphOperationStatus> result =
- getDataFromGraph(componentV,
- EdgeLabelEnum.NODE_FILTER_TEMPLATE);
+ private JanusGraphOperationStatus setNodeFilterComponentFromGraph(final GraphVertex componentV,
+ final TopologyTemplate topologyTemplate) {
+
+ final Either<Map<String, CINodeFilterDataDefinition>, JanusGraphOperationStatus> result =
+ getDataFromGraph(componentV, EdgeLabelEnum.NODE_FILTER_TEMPLATE);
if (result.isLeft()) {
topologyTemplate.setNodeFilterComponents(result.left().value());
} else {
@@ -1011,6 +1011,22 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return JanusGraphOperationStatus.OK;
}
+ private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV,
+ final TopologyTemplate topologyTemplate) {
+
+ final Either<Map<String, SubstitutionFilterDataDefinition>, JanusGraphOperationStatus> result =
+ getDataFromGraph(componentV, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE);
+ if (result.isLeft()) {
+ topologyTemplate.setSubstitutionFilterDataDefinitionMap(result.left().value());
+ } else {
+ if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
+ return result.right().value();
+ }
+ }
+ return JanusGraphOperationStatus.OK;
+ }
+
+
@Override
protected <T extends ToscaElement> JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
Either<Map<String, MapListRequirementDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java
index ae854254c2..272d664b8e 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java
@@ -71,6 +71,7 @@ import org.openecomp.sdc.be.datatypes.elements.ProductMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RelationshipInstDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
@@ -217,6 +218,9 @@ public class ModelConverter {
convertDataTypes(topologyTemplate, service);
convertNodeFiltersComponents(topologyTemplate, service);
+
+ convertSubstitutionFiltersComponents(topologyTemplate, service);
+
setCapabilitiesToComponent(topologyTemplate, service);
setRequirementsToComponent(topologyTemplate, service);
return service;
@@ -879,17 +883,33 @@ public class ModelConverter {
component.setDeploymentArtifacts(copy);
}
- private static void convertNodeFiltersComponents(TopologyTemplate topologyTemplate, Component component) {
- Map<String, CINodeFilterDataDefinition> filters = topologyTemplate.getNodeFilterComponents();
- Map<String, CINodeFilterDataDefinition> copy;
- if (filters != null) {
- copy = filters.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new CINodeFilterDataDefinition(e.getValue())));
+ private static void convertNodeFiltersComponents(final TopologyTemplate topologyTemplate,
+ final Component component) {
+ final Map<String, CINodeFilterDataDefinition> filters = topologyTemplate.getNodeFilterComponents();
+ final Map<String, CINodeFilterDataDefinition> copy;
+ if (MapUtils.isNotEmpty(filters)) {
+ copy = filters.entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, e -> new CINodeFilterDataDefinition(e.getValue())));
} else {
copy = new HashMap<>();
}
component.setNodeFilterComponents(copy);
}
+ private static void convertSubstitutionFiltersComponents(final TopologyTemplate topologyTemplate,
+ final Component component) {
+ final Map<String, SubstitutionFilterDataDefinition> filters = topologyTemplate
+ .getSubstitutionFilterDataDefinitionMap();
+ final Map<String, SubstitutionFilterDataDefinition> copy;
+ if (MapUtils.isNotEmpty(filters)) {
+ copy = filters.entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, e -> new SubstitutionFilterDataDefinition(e.getValue())));
+ } else {
+ copy = new HashMap<>();
+ }
+ component.setSubstitutionFilterComponents(copy);
+ }
+
private static void convertServiceApiArtifacts(TopologyTemplate topologyTemplate, Service service) {
Map<String, ArtifactDataDefinition> serviceApiArtifacts = topologyTemplate.getServiceApiArtifacts();
Map<String, ArtifactDefinition> copy;
@@ -1328,6 +1348,8 @@ public class ModelConverter {
List<ComponentInstance> componentInstances = new ArrayList<>();
ComponentInstance currComponentInstance;
Map<String, CINodeFilterDataDefinition> nodeFilterComponents = topologyTemplate.getNodeFilterComponents();
+ Map<String, SubstitutionFilterDataDefinition> substitutionFilterDataDefinitionMap = topologyTemplate
+ .getSubstitutionFilterDataDefinitionMap();
for (Map.Entry<String, ComponentInstanceDataDefinition> entry : topologyTemplate.getComponentInstances().entrySet()) {
String key = entry.getKey();
@@ -1337,9 +1359,12 @@ public class ModelConverter {
currComponentInstance.setGroupInstances(groupInstances);
}
setComponentInstanceSource(currComponentInstance, component);
- if(nodeFilterComponents != null && nodeFilterComponents.containsKey(key)){
+ if(MapUtils.isNotEmpty(nodeFilterComponents) && nodeFilterComponents.containsKey(key)){
currComponentInstance.setNodeFilter(nodeFilterComponents.get(key));
}
+ if(MapUtils.isNotEmpty(substitutionFilterDataDefinitionMap) && substitutionFilterDataDefinitionMap.containsKey(key)) {
+ currComponentInstance.setSubstitutionFilter(substitutionFilterDataDefinitionMap.get(key));
+ }
if(topologyTemplate.getInstProperties() != null && topologyTemplate.getInstProperties().containsKey(key) && topologyTemplate.getInstProperties().get(key) != null ){
List<PropertyDefinition> instanceProps = topologyTemplate.getInstProperties().get(key).getMapToscaDataDefinition().entrySet().stream().map(e -> new PropertyDefinition(e.getValue())).collect(Collectors.toList());
currComponentInstance.setProperties(instanceProps);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java
index 38d5a90742..f03a5e724f 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java
@@ -26,6 +26,7 @@ import java.util.Map;
import lombok.Getter;
import lombok.Setter;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
@@ -71,8 +72,10 @@ public class UiComponentDataTransfer {
private Map<String, InterfaceDefinition> interfaces;
private Map<String, CINodeFilterDataDefinition> nodeFilter;
+ private Map<String, SubstitutionFilterDataDefinition> substitutionFilter;
private Map<String, UINodeFilter> nodeFilterforNode;
+ private Map<String, UINodeFilter> substitutionFilterForTopologyTemplate;
private List<PropertyDefinition> properties;
private Map<String, List<ComponentInstanceInterface>> componentInstancesInterfaces;
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/RequirementSubstitutionFilterCapabilityDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/RequirementSubstitutionFilterCapabilityDataDefinition.java
new file mode 100644
index 0000000000..242eb490ef
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/RequirementSubstitutionFilterCapabilityDataDefinition.java
@@ -0,0 +1,50 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datatypes.elements;
+
+import java.io.Serializable;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
+
+public class RequirementSubstitutionFilterCapabilityDataDefinition extends ToscaDataDefinition implements Serializable {
+
+ /**
+ * Default Constructor
+ */
+ public RequirementSubstitutionFilterCapabilityDataDefinition() {
+ }
+
+ public String getName() {
+ return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
+ }
+
+ public void setName(final String name) {
+ setToscaPresentationValue(JsonPresentationFields.NAME, name);
+ }
+
+ public ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> getProperties() {
+ return (ListDataDefinition<RequirementNodeFilterPropertyDataDefinition>) getToscaPresentationValue(
+ JsonPresentationFields.PROPERTIES);
+ }
+
+ public void setProperties(final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> properties) {
+ setToscaPresentationValue(JsonPresentationFields.PROPERTIES, properties);
+ }
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/RequirementSubstitutionFilterPropertyDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/RequirementSubstitutionFilterPropertyDataDefinition.java
new file mode 100644
index 0000000000..75efd123bc
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/RequirementSubstitutionFilterPropertyDataDefinition.java
@@ -0,0 +1,44 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.datatypes.elements;
+
+import java.io.Serializable;
+import java.util.List;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
+
+public class RequirementSubstitutionFilterPropertyDataDefinition extends ToscaDataDefinition implements Serializable {
+
+
+ public List<String> getConstraints() {
+ return (List<String>) getToscaPresentationValue(JsonPresentationFields.PROPERTY_FILTER_CONSTRAINT);
+ }
+
+ public void setConstraints(final List<String> constraints) {
+ setToscaPresentationValue(JsonPresentationFields.PROPERTY_FILTER_CONSTRAINT, constraints);
+ }
+
+ public String getName() {
+ return (String) getToscaPresentationValue(JsonPresentationFields.PROPERTY_FILTER_NAME);
+ }
+
+ public void setName(final String name) {
+ setToscaPresentationValue(JsonPresentationFields.PROPERTY_FILTER_NAME, name);
+ }
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/SubstitutionFilterDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/SubstitutionFilterDataDefinition.java
new file mode 100644
index 0000000000..beb5aac1d0
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/SubstitutionFilterDataDefinition.java
@@ -0,0 +1,84 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.datatypes.elements;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import java.io.Serializable;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
+
+public class SubstitutionFilterDataDefinition extends ToscaDataDefinition implements Serializable {
+
+ @JsonCreator
+ public SubstitutionFilterDataDefinition() {
+ }
+
+ public SubstitutionFilterDataDefinition(final SubstitutionFilterDataDefinition substitutionFilterDataDefinition) {
+ super();
+ this.setID(substitutionFilterDataDefinition.getID());
+ this.setName(substitutionFilterDataDefinition.getName());
+ this.setTosca_id(substitutionFilterDataDefinition.getTosca_id());
+ this.setProperties(substitutionFilterDataDefinition.getProperties());
+ this.setCapabilities(substitutionFilterDataDefinition.getCapabilities());
+ }
+
+ public void setTosca_id(final Object tosca_id) {
+ setToscaPresentationValue(JsonPresentationFields.TOSCA_ID, tosca_id);
+ }
+
+ public Object getTosca_id() {
+ return getToscaPresentationValue(JsonPresentationFields.TOSCA_ID);
+ }
+
+ public ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> getProperties() {
+ return (ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition>) getToscaPresentationValue(
+ JsonPresentationFields.PROPERTIES);
+ }
+
+ public void setProperties(final ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> properties) {
+ setToscaPresentationValue(JsonPresentationFields.PROPERTIES, properties);
+ }
+
+ public ListDataDefinition<RequirementSubstitutionFilterCapabilityDataDefinition> getCapabilities() {
+ return (ListDataDefinition<RequirementSubstitutionFilterCapabilityDataDefinition>) getToscaPresentationValue(
+ JsonPresentationFields.NODE_FILTER_CAPABILITIES);
+ }
+
+ public void setCapabilities(ListDataDefinition<RequirementSubstitutionFilterCapabilityDataDefinition> capabilities) {
+ setToscaPresentationValue(JsonPresentationFields.NODE_FILTER_CAPABILITIES, capabilities);
+ }
+
+ public String getName() {
+ return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
+ }
+
+ public void setName(final String name) {
+ setToscaPresentationValue(JsonPresentationFields.NAME, name);
+ }
+
+ public String getID() {
+ return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
+ }
+
+ public void setID(final String name) {
+ setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, name);
+ }
+
+
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ComponentFieldsEnum.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ComponentFieldsEnum.java
index a92a711a38..42696e4ac1 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ComponentFieldsEnum.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ComponentFieldsEnum.java
@@ -45,6 +45,7 @@ public enum ComponentFieldsEnum {
POLICIES("policies"),
NON_EXCLUDED_POLICIES("nonExcludedPolicies"),
NODE_FILTER("nodeFilter"),
+ SUBSTITUTION_FILTER("substitutionFilter"),
COMPONENT_INSTANCES_INTERFACES("componentInstancesInterfaces"),
DATA_TYPES("dataTypes");
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/SubstitutionMapping.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/SubstitutionMapping.java
index 3669ae1df4..a8d0718c4e 100644
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/SubstitutionMapping.java
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/SubstitutionMapping.java
@@ -7,9 +7,9 @@
* 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.
@@ -22,33 +22,17 @@ package org.onap.sdc.tosca.datatypes.model;
import java.util.List;
import java.util.Map;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+@Getter
+@Setter
+@EqualsAndHashCode
public class SubstitutionMapping {
- private String node_type;
- private Map<String, List<String>> capabilities;
- private Map<String, List<String>> requirements;
- public String getNode_type() {
- return node_type;
- }
-
- public void setNode_type(String node_type) {
- this.node_type = node_type;
- }
-
- public Map<String, List<String>> getRequirements() {
- return requirements;
- }
-
- public void setRequirements(Map<String, List<String>> requirements) {
- this.requirements = requirements;
- }
-
- public Map<String, List<String>> getCapabilities() {
- return capabilities;
- }
-
- public void setCapabilities(Map<String, List<String>> capabilities) {
- this.capabilities = capabilities;
- }
+ private String node_type;
+ private Map<String, List<String>> capabilities;
+ private Map<String, List<String>> requirements;
+ private NodeFilter substitution_filter;
}
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionFilter.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionFilter.java
deleted file mode 100644
index 8f3aa20a48..0000000000
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionFilter.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.onap.sdc.tosca.datatypes.model.extension;
-
-
-import java.util.List;
-
-import java.util.Map;
-import org.onap.sdc.tosca.datatypes.model.Constraint;
-import org.onap.sdc.tosca.services.DataModelNormalizeUtil;
-
-public class SubstitutionFilter {
-
- private List<Map<String, List<Constraint>>> properties;
-
- public List<Map<String, List<Constraint>>> getProperties() {
- return properties;
- }
-
- public void setProperties(List<Map<String, List<Constraint>>> properties) {
- this.properties = DataModelNormalizeUtil.getNormalizePropertiesFilter(properties);
- }
-
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof SubstitutionFilter)) {
- return false;
- }
-
- SubstitutionFilter that = (SubstitutionFilter) o;
-
- return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null;
- }
-
- @Override
- public int hashCode() {
- return getProperties() != null ? getProperties().hashCode() : 0;
- }
-}
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionMappingExt.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionMappingExt.java
deleted file mode 100644
index d60931d180..0000000000
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionMappingExt.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.onap.sdc.tosca.datatypes.model.extension;
-
-import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
-
-public class SubstitutionMappingExt extends SubstitutionMapping {
-
- private SubstitutionFilter substitution_filter;
-
- public SubstitutionFilter getSubstitution_filter() {
- return substitution_filter;
- }
-
- public void setSubstitution_filter(SubstitutionFilter substitution_filter) {
- this.substitution_filter = substitution_filter;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof SubstitutionMappingExt)) {
- return false;
- }
-
- SubstitutionMappingExt that = (SubstitutionMappingExt) o;
-
- return getSubstitution_filter() != null ? getSubstitution_filter().equals(that.getSubstitution_filter())
- : that.getSubstitution_filter() == null;
- }
-
- @Override
- public int hashCode() {
- return getSubstitution_filter() != null ? getSubstitution_filter().hashCode() : 0;
- }
-}
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java
index a6c079ade0..45499d15f4 100644
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java
@@ -37,8 +37,6 @@ public class ToscaExtensionYamlUtil extends YamlUtil {
"org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignmentExt";
public static final String TOSCA_MODEL_SUBSTITUTION_MAPPING =
"org.onap.sdc.tosca.datatypes.model.SubstitutionMapping";
- public static final String TOSCA_MODEL_EXT_SUBSTITUTION_MAPPING =
- "org.onap.sdc.tosca.datatypes.model.extension.SubstitutionMappingExt";
@Override
public <T> Constructor getConstructor(Class<T> typClass) {
@@ -62,9 +60,6 @@ public class ToscaExtensionYamlUtil extends YamlUtil {
if (type.equals(Class.forName(TOSCA_MODEL_REQUIREMENT_ASSIGNMENT))) {
classType = Class.forName(TOSCA_MODEL_EXT_REQUIREMENT_ASSIGNMENT);
}
- if (type.equals(Class.forName(TOSCA_MODEL_SUBSTITUTION_MAPPING))) {
- classType = Class.forName(TOSCA_MODEL_EXT_SUBSTITUTION_MAPPING);
- }
} catch (ClassNotFoundException ex) {
throw new ToscaRuntimeException(ex);
}
@@ -85,6 +80,7 @@ public class ToscaExtensionYamlUtil extends YamlUtil {
protected Object constructJavaBean2ndStep(MappingNode node, Object object) {
Class type = node.getType();
try {
+ final Class<?> substitutionMappingClass = Class.forName(TOSCA_MODEL_SUBSTITUTION_MAPPING);
if (type.equals(Class.forName(TOSCA_MODEL_PARAMETER_DEFINITION))) {
Class extendHeatClass = Class.forName(TOSCA_MODEL_EXT_PARAMETER_DEFINITION);
Object extendHeatObject = extendHeatClass.newInstance();
@@ -95,11 +91,8 @@ public class ToscaExtensionYamlUtil extends YamlUtil {
Object extendHeatObject = extendHeatClass.newInstance();
// create JavaBean
return super.constructJavaBean2ndStep(node, extendHeatObject);
- } else if (type.equals(Class.forName(TOSCA_MODEL_SUBSTITUTION_MAPPING))) {
- Class extendHeatClass = Class.forName(TOSCA_MODEL_EXT_SUBSTITUTION_MAPPING);
- Object extendHeatObject = extendHeatClass.newInstance();
- // create JavaBean
- return super.constructJavaBean2ndStep(node, extendHeatObject);
+ } else if (type.equals(substitutionMappingClass)) {
+ return super.constructJavaBean2ndStep(node, substitutionMappingClass.newInstance());
} else {
// create JavaBean
return super.constructJavaBean2ndStep(node, object);
diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionMappingExtTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionMappingExtTest.java
deleted file mode 100644
index aa1290b683..0000000000
--- a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionMappingExtTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 Nokia. 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.onap.sdc.tosca.datatypes.model.extension;
-
-import org.junit.Test;
-
-import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding;
-import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanHashCodeExcluding;
-import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
-import static org.junit.Assert.assertThat;
-
-public class SubstitutionMappingExtTest {
- @Test
- public void shouldHaveValidGettersAndSetters() {
- assertThat(SubstitutionMappingExt.class, hasValidGettersAndSetters());
- }
-
- @Test
- public void shouldHaveValidEquals() {
- assertThat(SubstitutionMappingExt.class, hasValidBeanEqualsExcluding("capabilities", "node_type", "requirements"));
- }
-
- @Test
- public void shouldHaveValidHashCode() {
- assertThat(SubstitutionMappingExt.class, hasValidBeanHashCodeExcluding("capabilities", "node_type", "requirements"));
- }
-} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java
index 2dbc19f8cf..a8d29b9c6a 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java
@@ -22,6 +22,7 @@ public final class Constants {
public static final String DEFINITIONS_DIR = "Definitions/";
public static final String TOPOLOGY_TEMPLATE = "topology_template";
public static final String NODE_TYPE = "node_type";
+ public static final String NODE_FILTER = "node_filter";
public static final String NODE_TYPES = "node_types";
public static final String METADATA = "metadata";
public static final String NODE_TEMPLATES = "node_templates";
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java
index f902309c68..fe76ba01fe 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java
@@ -47,6 +47,7 @@ import java.util.Optional;
import static org.openecomp.core.converter.datatypes.Constants.CAPABILITIES;
import static org.openecomp.core.converter.datatypes.Constants.INPUTS;
+import static org.openecomp.core.converter.datatypes.Constants.NODE_FILTER;
import static org.openecomp.core.converter.datatypes.Constants.NODE_TYPE;
import static org.openecomp.core.converter.datatypes.Constants.OUTPUTS;
import static org.openecomp.core.converter.datatypes.Constants.REQUIREMENTS;
@@ -122,7 +123,7 @@ public class VnfTopologyTemplateConverter {
nodeTemplate.setDescription((String) nodeTemplateAsMap.get("description"));
nodeTemplate.setDirectives((List<String>) nodeTemplateAsMap.get("directives"));
nodeTemplate.setInterfaces((Map<String, Object>) nodeTemplateAsMap.get("interfaces"));
- nodeTemplate.setNode_filter((NodeFilter) nodeTemplateAsMap.get("node_filter"));
+ nodeTemplate.setNode_filter((NodeFilter) nodeTemplateAsMap.get(NODE_FILTER));
nodeTemplate.setProperties((Map<String, Object>) nodeTemplateAsMap.get("properties"));
nodeTemplate.setRequirements((List<Map<String, RequirementAssignment>>) nodeTemplateAsMap.get("requirements"));
nodeTemplate.setType((String) nodeTemplateAsMap.get("type"));
@@ -168,6 +169,7 @@ public class VnfTopologyTemplateConverter {
convertSubstitutionMappingsSections(CAPABILITIES, substitutionMappings.get(CAPABILITIES)));
substitutionMapping.setRequirements(
convertSubstitutionMappingsSections(REQUIREMENTS, substitutionMappings.get(REQUIREMENTS)));
+ substitutionMapping.setSubstitution_filter((NodeFilter) substitutionMappings.get(NODE_FILTER));
return substitutionMapping;
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java
index 88e8461299..4ad4d2b53e 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java
@@ -52,8 +52,6 @@ import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
import org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignmentExt;
-import org.onap.sdc.tosca.datatypes.model.extension.SubstitutionFilter;
-import org.onap.sdc.tosca.datatypes.model.extension.SubstitutionMappingExt;
import org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.onap.sdc.tosca.services.YamlUtil;
@@ -89,7 +87,7 @@ public class ToscaModelTest {
private static final String STRING_TYPE = "string";
private static final String ST_WITH_SERVICE_FILTER = "/serviceTemplateWithServiceFilter.yaml";
private static final String SUBSTITUTION_MAPPING = "/serviceTemplateWithSubstitutionMapping.yaml";
- private static final String SUBSTITUTION_MAPPING_EXT = "/substitutionMappingExt.yaml";
+ private static final String SUBSTITUTION_MAPPING_WITH_FILTER = "/substitutionMappingWithFilter.yaml";
@Test
public void testServiceTemplateJavaToYaml() {
@@ -460,40 +458,33 @@ public class ToscaModelTest {
@Test
public void testSubstitutionMapping() throws IOException {
- ServiceTemplate serviceTemplate = getServiceTemplateExt(BASE_DIR + SUBSTITUTION_MAPPING);
-
- SubstitutionMapping substitutionMappings = DataModelUtil.getSubstitutionMappings(serviceTemplate);
+ final ServiceTemplate serviceTemplate = getServiceTemplateExt(BASE_DIR + SUBSTITUTION_MAPPING);
+ final SubstitutionMapping substitutionMappings = DataModelUtil.getSubstitutionMappings(serviceTemplate);
Assert.assertEquals("myNodeType.node", substitutionMappings.getNode_type());
Assert.assertNotNull(substitutionMappings.getCapabilities());
Assert.assertEquals(1,substitutionMappings.getCapabilities().size());
Assert.assertNotNull(substitutionMappings.getRequirements());
Assert.assertEquals(1,substitutionMappings.getRequirements().size());
- Assert.assertEquals(true, substitutionMappings instanceof SubstitutionMappingExt);
- Assert.assertNull(((SubstitutionMappingExt)substitutionMappings).getSubstitution_filter());
-
+ Assert.assertNull(substitutionMappings.getSubstitution_filter());
}
@Test
- public void testSubstitutionMappingExt() throws IOException {
- ServiceTemplate serviceTemplate = getServiceTemplateExt(BASE_DIR + SUBSTITUTION_MAPPING_EXT);
+ public void testSubstitutionMappingWithFilter() throws IOException {
+ final ServiceTemplate serviceTemplate = getServiceTemplateExt(BASE_DIR + SUBSTITUTION_MAPPING_WITH_FILTER);
- SubstitutionMapping substitutionMappings = DataModelUtil.getSubstitutionMappings(serviceTemplate);
+ final SubstitutionMapping substitutionMappings = DataModelUtil.getSubstitutionMappings(serviceTemplate);
Assert.assertEquals("myNodeType.node", substitutionMappings.getNode_type());
Assert.assertNotNull(substitutionMappings.getCapabilities());
Assert.assertEquals(1,substitutionMappings.getCapabilities().size());
Assert.assertNotNull(substitutionMappings.getRequirements());
Assert.assertEquals(1,substitutionMappings.getRequirements().size());
- Assert.assertEquals(true, substitutionMappings instanceof SubstitutionMappingExt);
- SubstitutionFilter substitutionFilter = ((SubstitutionMappingExt) substitutionMappings).getSubstitution_filter();
+ final NodeFilter substitutionFilter = substitutionMappings.getSubstitution_filter();
Assert.assertNotNull(substitutionFilter);
Assert.assertNotNull(substitutionFilter.getProperties());
Assert.assertEquals(2,substitutionFilter.getProperties().size());
- List<Constraint> vendorFilter = substitutionFilter.getProperties().get(0).get("vendor");
+ final List<Constraint> vendorFilter = substitutionFilter.getProperties().get(0).get("vendor");
Assert.assertNotNull(vendorFilter);
Assert.assertNotNull(vendorFilter.get(0).getEqual());
-
-
-
}
private ServiceTemplate getServiceTemplate(String inputPath) throws IOException {
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/substitutionMappingExt.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/substitutionMappingWithFilter.yaml
index ae6a88ea77..ae6a88ea77 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/substitutionMappingExt.yaml
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/substitutionMappingWithFilter.yaml