aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src
diff options
context:
space:
mode:
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>2022-07-05 18:43:07 +0100
committerKrupa Nagabhushan <krupa.nagabhushan@est.tech>2022-08-02 21:10:26 +0000
commit7c7680d767bce8625c9c7ad69009fb73ae849809 (patch)
treefc3cb8f1482ac8c6dfcb22feb085757ea180cfa0 /catalog-model/src
parenta9d0bcd206b7a677b82e5e9b497a8b52b38e3a43 (diff)
Service Import - Node Template Relationship Template
Issue-ID: SDC-4083 Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech> Signed-off-by: andre.schmid <andre.schmid@est.tech> Change-Id: Ia0f3635df969c44de5aba2d672fad34f0855e4e2
Diffstat (limited to 'catalog-model/src')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadComponentInstanceInfo.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadReqInfo.java23
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java1
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java47
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadReqInfoTest.java33
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverterTest.java48
6 files changed, 105 insertions, 49 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadComponentInstanceInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadComponentInstanceInfo.java
index 57652ee162..ef9f1f17e8 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadComponentInstanceInfo.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadComponentInstanceInfo.java
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
+import org.openecomp.sdc.be.ui.model.OperationUi;
@Getter
@Setter
@@ -40,4 +41,5 @@ public class UploadComponentInstanceInfo {
private Map<String, String> requirementsNamesToUpdate;
private Collection<String> directives;
private UploadNodeFilterInfo uploadNodeFilterInfo;
+ private Map<String, List<OperationUi>> operations;
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadReqInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadReqInfo.java
index a3f927925f..b18a8e47a5 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadReqInfo.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadReqInfo.java
@@ -19,6 +19,13 @@
*/
package org.openecomp.sdc.be.model;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Getter
+@Setter
+@NoArgsConstructor
public class UploadReqInfo extends UploadInfo {
/**
@@ -26,20 +33,6 @@ public class UploadReqInfo extends UploadInfo {
*/
private String capabilityName;
private String node;
+ private String relationshipTemplate;
- public String getCapabilityName() {
- return capabilityName;
- }
-
- public void setCapabilityName(String capabilityName) {
- this.capabilityName = capabilityName;
- }
-
- public String getNode() {
- return node;
- }
-
- public void setNode(String node) {
- this.node = node;
- }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
index 02fda3c51b..8c08a3d040 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
@@ -2082,6 +2082,7 @@ public class ToscaOperationFacade {
Component updatedComponent = componentEither.left().value();
component.setCapabilities(updatedComponent.getCapabilities());
component.setRequirements(updatedComponent.getRequirements());
+ component.setComponentInstancesRelations(updatedComponent.getComponentInstancesRelations());
component.setComponentInstances(updatedComponent.getComponentInstances());
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java
index 6dfaebc947..cfc58671e4 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java
@@ -32,6 +32,7 @@ import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
@@ -118,6 +119,7 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
import org.openecomp.sdc.be.model.jsonjanusgraph.enums.JsonConstantKeysEnum;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTemplateOperation;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
import org.openecomp.sdc.be.resources.data.ProductMetadataData;
@@ -481,11 +483,56 @@ public class ModelConverter {
requirementCapabilityRelDef.setType(p.getRelation().getRelationship().getType());
requirementCapabilityRelDef.setCapability(p.getRelation().getCapability());
requirementCapabilityRelDef.setOriginUI(relation.isOriginUI());
+ createRelationshipInterfaces(p.getOperations()).ifPresent(requirementCapabilityRelDef::setInterfaces);
relationsList.add(requirementCapabilityRelDef);
});
return relationsList;
}
+ private static Optional<ListDataDefinition<InterfaceDataDefinition>> createRelationshipInterfaces(final List<OperationUi> operationList) {
+ if (CollectionUtils.isEmpty(operationList)) {
+ return Optional.empty();
+ }
+ final ListDataDefinition<InterfaceDataDefinition> interfaceList = new ListDataDefinition<>();
+ final Map<String, List<OperationUi>> operationByInterfaceType = operationList.stream()
+ .collect(Collectors.groupingBy(OperationUi::getInterfaceType));
+ for (final Entry<String, List<OperationUi>> interfaceEntry : operationByInterfaceType.entrySet()) {
+ interfaceList.add(createInterface(interfaceEntry.getKey(), interfaceEntry.getValue()));
+ }
+ return Optional.of(interfaceList);
+ }
+
+ private static InterfaceDataDefinition createInterface(final String interfaceType, final List<OperationUi> operationList) {
+ final InterfaceDataDefinition interfaceDataDefinition = new InterfaceDataDefinition();
+ interfaceDataDefinition.setType(interfaceType);
+ if (CollectionUtils.isNotEmpty(operationList)) {
+ final Map<String, OperationDataDefinition> operationMap = operationList.stream()
+ .collect(Collectors.toMap(OperationUi::getOperationType, ModelConverter::createOperation));
+ interfaceDataDefinition.setOperations(operationMap);
+ }
+ return interfaceDataDefinition;
+ }
+
+ private static OperationDataDefinition createOperation(final OperationUi operation) {
+ final OperationDataDefinition operationDataDefinition = new OperationDataDefinition();
+ operationDataDefinition.setName(operation.getOperationType());
+ operationDataDefinition.setUniqueId(UUID.randomUUID().toString());
+ final ArtifactDataDefinition artifactDataDefinition = (ArtifactDataDefinition) operation.getImplementation();
+ operationDataDefinition.setImplementation(artifactDataDefinition);
+ if (CollectionUtils.isNotEmpty(operation.getInputs())) {
+ final ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>();
+ operation.getInputs().forEach(input -> {
+ final OperationInputDefinition operationInputDefinition = new OperationInputDefinition();
+ operationInputDefinition.setLabel(input.getName());
+ operationInputDefinition.setType(input.getType());
+ operationInputDefinition.setValue(input.getValue());
+ inputs.add(operationInputDefinition);
+ });
+ operationDataDefinition.setInputs(inputs);
+ }
+ return operationDataDefinition;
+ }
+
private static void convertCapabilities(Component component, TopologyTemplate topologyTemplate) {
convertTopologyTemplateCapabilities(component, topologyTemplate);
if (componentInstancesCapabilitiesExist(component) || groupsCapabilitiesExist(component)) {
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadReqInfoTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadReqInfoTest.java
deleted file mode 100644
index 8ce7d8db57..0000000000
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadReqInfoTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.openecomp.sdc.be.model;
-
-import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-import org.junit.Test;
-
-public class UploadReqInfoTest {
-
- @Test
- public void shouldHaveValidGettersAndSetters() {
- assertThat(UploadReqInfo.class, hasValidGettersAndSetters());
- }
-}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverterTest.java
index 5aa742a540..871a43016f 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverterTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverterTest.java
@@ -29,7 +29,6 @@
*/
package org.openecomp.sdc.be.model.jsonjanusgraph.utils;
-
import java.util.HashMap;
import org.junit.jupiter.api.Test;
@@ -38,6 +37,7 @@ import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
@@ -72,6 +72,9 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import org.openecomp.sdc.be.model.tosca.ToscaType;
+import org.openecomp.sdc.be.ui.model.OperationUi;
+import org.openecomp.sdc.be.ui.model.PropertyAssignmentUi;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -277,6 +280,49 @@ public class ModelConverterTest {
}
@Test
+ void testConvertRelationTemplateToToscaRelation()
+ {
+ RequirementCapabilityRelDef reqCap = new RequirementCapabilityRelDef();
+ reqCap.setOriginUI(true);
+ reqCap.setFromNode("fromNode");
+ reqCap.setToNode("toNode");
+ List<CapabilityRequirementRelationship> list = new LinkedList<>();
+ CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
+ RelationshipInfo info = new RelationshipInfo();
+ info.setCapabilityOwnerId("capOwnerId");
+ info.setId("id");
+ info.setCapabilityUid("capUid");
+ info.setRequirementOwnerId("reqOwnerId");
+ info.setRequirementUid("reqUid");
+ info.setRequirement("req");
+ info.setCapability("cap");
+ RelationshipImpl relationshipImpl = new RelationshipImpl();
+ relationshipImpl.setType("type");
+ info.setRelationships(relationshipImpl);
+ relationship.setRelation(info);
+ OperationUi operationUi = new OperationUi();
+ operationUi.setInterfaceType("tosca.interfaces.relationship.Configure");
+ operationUi.setOperationType("add_source");
+ final ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition();
+ artifactDataDefinition.setArtifactName("impl");
+ operationUi.setImplementation(artifactDataDefinition);
+ PropertyAssignmentUi propertyAssignmentUi = new PropertyAssignmentUi();
+ propertyAssignmentUi.setName("strInput1");
+ propertyAssignmentUi.setType(ToscaType.STRING.getType());
+ propertyAssignmentUi.setValue("inputValue");
+ operationUi.setInputs(List.of(propertyAssignmentUi));
+ relationship.setOperations(List.of(operationUi));
+ list.add(relationship);
+ reqCap.setRelationships(list);
+
+ List<RelationshipInstDataDefinition> result = ModelConverter.convertRelationToToscaRelation(reqCap);
+ assertEquals(1, result.size());
+ assertEquals(false, result.get(0).getInterfaces().isEmpty());
+ assertEquals(false, result.get(0).getInterfaces().getListToscaDataDefinition().get(0).getOperations().isEmpty());
+ assertEquals(false, result.get(0).getInterfaces().getListToscaDataDefinition().get(0).getOperations().get("add_source").getInputs().isEmpty());
+ }
+
+ @Test
public void testConvertToMapOfMapCapabilityPropertiesonvertRelation()
{
Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();