aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src')
-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
14 files changed, 1092 insertions, 649 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());