aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java224
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java36
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java62
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java11
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java1
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperationTest.java (renamed from catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java)115
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtilsTest.java50
8 files changed, 95 insertions, 406 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java
index f9f2ce9b35..4aec886092 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java
@@ -17,223 +17,75 @@
package org.openecomp.sdc.be.model.jsontitan.operations;
import fj.data.Either;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.UUID;
-import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
-import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
+import java.util.stream.Collectors;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
-import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
-import org.springframework.beans.factory.annotation.Autowired;
@org.springframework.stereotype.Component("interfaces-operation")
public class InterfaceOperation extends BaseOperation {
- @Autowired
- private ArtifactCassandraDao artifactCassandraDao;
-
- public Either<InterfaceDefinition, StorageOperationStatus> addInterface(String componentId,
- InterfaceDefinition interfaceDefinition) {
- return addOrUpdateInterface(false, componentId, interfaceDefinition);
- }
-
- public Either<InterfaceDefinition, StorageOperationStatus> updateInterface(String componentId,
- InterfaceDefinition interfaceDefinition) {
- return addOrUpdateInterface(true, componentId, interfaceDefinition);
- }
-
- private Either<InterfaceDefinition, StorageOperationStatus> addOrUpdateInterface(
- boolean isUpdateAction, String componentId, InterfaceDefinition interfaceDefinition) {
-
- StorageOperationStatus statusRes;
- Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
-
- getToscaElementRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getToscaElementRes.isRight()) {
- TitanOperationStatus status = getToscaElementRes.right().value();
- statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
- return Either.right(statusRes);
- }
- GraphVertex componentVertex = getToscaElementRes.left().value();
- if (!isUpdateAction) {
- interfaceDefinition.setUniqueId(UUID.randomUUID().toString());
- }
- statusRes = performUpdateToscaAction(isUpdateAction, componentVertex,
- Collections.singletonList(interfaceDefinition), EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE);
- if (!statusRes.equals(StorageOperationStatus.OK)) {
- return Either.right(statusRes);
- }
- return Either.left(interfaceDefinition);
- }
-
- public Either<Operation, StorageOperationStatus> addInterfaceOperation(String componentId, InterfaceDefinition interfaceDef, Operation interfaceOperation) {
- return addOrUpdateInterfaceOperation(false, componentId, interfaceDef, interfaceOperation);
- }
-
- public Either<Operation, StorageOperationStatus> updateInterfaceOperation(String componentId, InterfaceDefinition interfaceDef, Operation interfaceOperation) {
- return addOrUpdateInterfaceOperation(true, componentId, interfaceDef, interfaceOperation);
- }
-
- private Either<Operation, StorageOperationStatus> addOrUpdateInterfaceOperation(boolean isUpdateAction, String componentId, InterfaceDefinition interfaceDef, Operation operation) {
-
- StorageOperationStatus statusRes;
- Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
- Either<GraphVertex, TitanOperationStatus> getToscaElementInt;
-
- if(isUpdateAction && operation.getImplementationArtifact() != null){
- String artifactUUID = operation.getImplementationArtifact().getArtifactUUID();
- Either<Long, CassandraOperationStatus> artifactCount = artifactCassandraDao.getCountOfArtifactById(artifactUUID);
- if(artifactCount.isLeft()){
- CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUUID);
- if (cassandraStatus != CassandraOperationStatus.OK) {
- return Either.right(DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraStatus));
- }
- }
- }
-
- getToscaElementRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getToscaElementRes.isRight()) {
- TitanOperationStatus status = getToscaElementRes.right().value();
- statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
- return Either.right(statusRes);
- }
- GraphVertex componentVertex = getToscaElementRes.left().value();
- getToscaElementInt = titanDao.getChildVertex(componentVertex, EdgeLabelEnum.INTERFACE, JsonParseFlagEnum.NoParse);
- if (getToscaElementInt.isRight()) {
- TitanOperationStatus status = getToscaElementInt.right().value();
- statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status);
- return Either.right(statusRes);
- }
- GraphVertex interfaceVertex = getToscaElementInt.left().value();
-
- statusRes = performUpdateToscaAction(isUpdateAction, interfaceVertex,
- Collections.singletonList(operation), EdgeLabelEnum.INTERFACE_OPERATION, VertexTypeEnum.INTERFACE_OPERATION);
- if (!statusRes.equals(StorageOperationStatus.OK)) {
- return Either.right(statusRes);
+ public Either<List<InterfaceDefinition>, StorageOperationStatus> addInterfaces(String componentId, List<InterfaceDefinition> interfaceDefinitions) {
+ return addOrUpdateInterfaces(false, componentId, interfaceDefinitions);
}
- getUpdatedInterfaceDef(interfaceDef, operation, operation.getUniqueId());
- Either<InterfaceDefinition, StorageOperationStatus> intUpdateStatus = updateInterface(componentId, interfaceDef);
- if (intUpdateStatus.isRight() && !intUpdateStatus.right().value().equals(StorageOperationStatus.OK)) {
- return Either.right(statusRes);
+ public Either<List<InterfaceDefinition>, StorageOperationStatus> updateInterfaces(String componentId, List<InterfaceDefinition> interfaceDefinitions) {
+ return addOrUpdateInterfaces(true, componentId, interfaceDefinitions);
}
- return Either.left(operation);
- }
+ private Either<List<InterfaceDefinition>, StorageOperationStatus> addOrUpdateInterfaces(boolean isUpdateAction, String componentId, List<InterfaceDefinition> interfaceDefinitions) {
- public Either<Operation, StorageOperationStatus> deleteInterfaceOperation(String componentId, InterfaceDefinition interfaceDef, String operationToDelete) {
- Either<GraphVertex, TitanOperationStatus> getInterfaceVertex;
- Either<GraphVertex, TitanOperationStatus> getComponentVertex;
- Operation operation = new Operation();
- StorageOperationStatus status;
+ StorageOperationStatus statusRes;
+ Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
- getComponentVertex = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
- if (getComponentVertex.isRight()) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getComponentVertex.right().value()));
- }
+ getToscaElementRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getToscaElementRes.isRight()) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getToscaElementRes.right().value()));
+ }
+ GraphVertex componentVertex = getToscaElementRes.left().value();
- getInterfaceVertex = titanDao.getChildVertex(getComponentVertex.left().value(), EdgeLabelEnum.INTERFACE, JsonParseFlagEnum.NoParse);
- if (getInterfaceVertex.isRight()) {
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getInterfaceVertex.right().value()));
+ List<ToscaDataDefinition> interfaceDataDefinitions = interfaceDefinitions.stream().map(interfaceDefinition -> new InterfaceDataDefinition(interfaceDefinition)).collect(Collectors.toList());
+ statusRes = performUpdateToscaAction(isUpdateAction, componentVertex, interfaceDataDefinitions, EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE);
+ if (!statusRes.equals(StorageOperationStatus.OK)) {
+ return Either.right(statusRes);
+ }
+ return Either.left(interfaceDefinitions);
}
- if (!interfaceDef.getOperationsMap().isEmpty()) {
- Either<GraphVertex, TitanOperationStatus> getInterfaceOpVertex =
- titanDao.getChildVertex(getInterfaceVertex.left().value(), EdgeLabelEnum.INTERFACE_OPERATION,
- JsonParseFlagEnum.NoParse);
- if (getInterfaceOpVertex.isRight()) {
- List<ToscaDataDefinition> toscaDataList = new ArrayList<>(interfaceDef.getOperationsMap().values());
- StorageOperationStatus statusRes =
- addToscaDataToToscaElement(getInterfaceVertex.left().value(), EdgeLabelEnum.INTERFACE_OPERATION,
- VertexTypeEnum.INTERFACE_OPERATION, toscaDataList, JsonPresentationFields.UNIQUE_ID);
- if (!statusRes.equals(StorageOperationStatus.OK)) {
- return Either.right(statusRes);
- }
- }
- }
-
- Optional<Entry<String, Operation>> operationToRemove = interfaceDef.getOperationsMap().entrySet().stream()
- .filter(entry -> entry.getValue().getUniqueId().equals(operationToDelete)).findAny();
- if (operationToRemove.isPresent()){
- Map.Entry<String, Operation> stringOperationEntry = operationToRemove.get();
- operation = stringOperationEntry.getValue();
- ArtifactDefinition implementationArtifact = operation.getImplementationArtifact();
- if(implementationArtifact != null){
- String artifactUUID = implementationArtifact.getArtifactUUID();
- CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUUID);
- if (cassandraStatus != CassandraOperationStatus.OK) {
- return Either.right(DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraStatus));
- }
- }
+ public Either<String, StorageOperationStatus> deleteInterface(String componentId, String interfacesToDelete) {
+ StorageOperationStatus statusRes;
+ Either<GraphVertex, TitanOperationStatus> getToscaElementRes;
- if(interfaceDef.getOperationsMap().size() > 1){
- status = deleteToscaDataElements(getInterfaceVertex.left().value(), EdgeLabelEnum.INTERFACE_OPERATION, Collections.singletonList(operationToDelete));
- if (status != StorageOperationStatus.OK) {
- return Either.right(status);
+ getToscaElementRes = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getToscaElementRes.isRight()) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getToscaElementRes.right().value()));
}
- } else {
- status = removeToscaDataVertex(getInterfaceVertex.left().value(), EdgeLabelEnum.INTERFACE_OPERATION, VertexTypeEnum.INTERFACE_OPERATION);
- if (status != StorageOperationStatus.OK) {
- return Either.right(status);
- }
- }
- getUpdatedInterfaceDef(interfaceDef, null, operationToDelete);
- if (interfaceDef.getOperations().isEmpty()) {
- status = deleteToscaDataElements(getComponentVertex.left().value(), EdgeLabelEnum.INTERFACE, Collections.singletonList(interfaceDef.getUniqueId()));
- if (status != StorageOperationStatus.OK) {
- return Either.right(status);
- }
- status = removeToscaDataVertex(getComponentVertex.left().value(), EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE);
- if (status != StorageOperationStatus.OK) {
- return Either.right(status);
+ statusRes = deleteToscaDataElements(componentId, EdgeLabelEnum.INTERFACE, Collections.singletonList(interfacesToDelete));
+ if (statusRes != StorageOperationStatus.OK) {
+ return Either.right(statusRes);
}
- }
- else {
- Either<InterfaceDefinition, StorageOperationStatus> intUpdateStatus = updateInterface(componentId, interfaceDef);
- if (intUpdateStatus.isRight() && !intUpdateStatus.right().value().equals(StorageOperationStatus.OK)) {
- return Either.right(status);
- }
- }
- }
- return Either.left(operation);
- }
- private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, GraphVertex graphVertex,
- List<ToscaDataDefinition> toscaDataList, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel) {
- if (isUpdate) {
- return updateToscaDataOfToscaElement(graphVertex, edgeLabel, vertexLabel, toscaDataList, JsonPresentationFields.UNIQUE_ID);
- } else {
- return addToscaDataToToscaElement(graphVertex, edgeLabel, vertexLabel, toscaDataList, JsonPresentationFields.UNIQUE_ID);
+ return Either.left(interfacesToDelete);
}
- }
- private void getUpdatedInterfaceDef(InterfaceDefinition interfaceDef, Operation operation, String operationId){
- Map<String, Operation> operationMap = interfaceDef.getOperationsMap();
- if(operation != null){
- operationMap.put(operationId, operation);
- interfaceDef.setOperationsMap(operationMap);
- }
- else {
- operationMap.remove(operationId);
- interfaceDef.setOperationsMap(operationMap);
+ private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, GraphVertex graphVertex,
+ List<ToscaDataDefinition> toscaDataList, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel) {
+ if (isUpdate) {
+ return updateToscaDataOfToscaElement(graphVertex, edgeLabel, vertexLabel, toscaDataList, JsonPresentationFields.UNIQUE_ID);
+ } else {
+ return addToscaDataToToscaElement(graphVertex, edgeLabel, vertexLabel, toscaDataList, JsonPresentationFields.UNIQUE_ID);
+ }
}
- }
-
-}
-
+} \ No newline at end of file
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
index 9a87874b2a..3bdec2a30a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
@@ -44,7 +44,6 @@ import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
-import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum;
import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -729,15 +728,6 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
if (assosiateElementToData.isRight()) {
return assosiateElementToData.right().value();
}
- else {
- Map<String, OperationDataDefinition> operationMap = interfaceMap.values().stream().filter(op -> MapUtils.isNotEmpty(op.getOperations())).flatMap(a -> a.getOperations().entrySet().stream()).collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue()));
- if(MapUtils.isNotEmpty(operationMap)) {
- Either<GraphVertex, StorageOperationStatus> assosiateOpToInterface = associateElementToData(assosiateElementToData.left().value(), VertexTypeEnum.INTERFACE_OPERATION, EdgeLabelEnum.INTERFACE_OPERATION, operationMap);
- if (assosiateOpToInterface.isRight()) {
- return assosiateOpToInterface.right().value();
- }
- }
- }
}
return StorageOperationStatus.OK;
}
@@ -1062,25 +1052,17 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
-
- Either<GraphVertex, TitanOperationStatus> getInterfaceVertex = titanDao.getChildVertex(toscaElementVertex, EdgeLabelEnum.INTERFACE, JsonParseFlagEnum.NoParse);
- if (getInterfaceVertex.isLeft()) {
- status = titanDao.disassociateAndDeleteLast(getInterfaceVertex.left().value(), Direction.OUT, EdgeLabelEnum.INTERFACE_OPERATION);
- if (status != TitanOperationStatus.OK) {
- log.debug("Failed to disassociate interface operations for {} error {}", getInterfaceVertex.left().value().getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- else {
- status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
- if (status != TitanOperationStatus.OK) {
- log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
- Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
- }
-
+ status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
+ Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
}
-
titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
+ if (status != TitanOperationStatus.OK) {
+ log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
+ Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
+
toscaElementVertex.getVertex().remove();
log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java
deleted file mode 100644
index feef31cbc1..0000000000
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openecomp.sdc.be.model.jsontitan.utils;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.openecomp.sdc.be.model.InterfaceDefinition;
-
-import java.util.Collection;
-import java.util.Formatter;
-import java.util.Optional;
-import java.util.stream.Collectors;
-import org.openecomp.sdc.common.util.ValidationUtils;
-
-public class InterfaceUtils {
-
- public static final String INTERFACE_TOSCA_RESOURCE_NAME = "org.openecomp.interfaces.node.lifecycle.%s";
-
- public static final Optional<InterfaceDefinition> getInterfaceDefinitionFromToscaName(
- Collection<InterfaceDefinition> interfaces,
- String componentName) {
- if (CollectionUtils.isEmpty(interfaces)) {
- return Optional.empty();
- }
-
- String toscaName = createInterfaceToscaResourceName(componentName);
- return interfaces.stream().filter(
- interfaceDefinition -> interfaceDefinition.getToscaResourceName() != null && interfaceDefinition
- .getToscaResourceName().equals(toscaName)).findAny();
- }
-
- public static Collection<InterfaceDefinition> getInterfaceDefinitionListFromToscaName(Collection<InterfaceDefinition> interfaces,
- String componentName) {
- if (CollectionUtils.isEmpty(interfaces)) {
- return CollectionUtils.EMPTY_COLLECTION;
- }
-
- String toscaName = createInterfaceToscaResourceName(componentName);
- return interfaces.stream().filter(
- interfaceDefinition -> interfaceDefinition.getToscaResourceName() != null && interfaceDefinition
- .getToscaResourceName().equals(toscaName)).collect(Collectors.toList());
- }
-
- public static String createInterfaceToscaResourceName(String componentName) {
- StringBuilder sb = new StringBuilder();
- try (Formatter formatter = new Formatter(sb)) {
- return formatter.format(INTERFACE_TOSCA_RESOURCE_NAME, ValidationUtils.convertToSystemName(componentName)).toString();
- }
- }
-}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java
index 06622ebba6..2f12226d95 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IInterfaceLifecycleOperation.java
@@ -51,5 +51,5 @@ public interface IInterfaceLifecycleOperation {
public String getShortInterfaceName(InterfaceDataDefinition interfaceDefinition);
- Either<Map<String, InterfaceDefinition>,StorageOperationStatus> getAllInterfaceLifecycleTypes();
+ public Either<Map<String, InterfaceDefinition>,StorageOperationStatus> getAllInterfaceLifecycleTypes();
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java
index 0090f86f0e..43df6da2e6 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java
@@ -20,7 +20,7 @@
package org.openecomp.sdc.be.ui.model;
-import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition;
+
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
@@ -78,17 +78,8 @@ public class UiComponentDataTransfer {
protected List<AdditionalInformationDefinition> additionalInformation;
- private Map<String, InterfaceOperationDataDefinition> interfaceOperations;
private Map<String, InterfaceDefinition> interfaces;
- public Map<String, InterfaceOperationDataDefinition> getInterfaceOperations() {
- return interfaceOperations;
- }
-
- public void setInterfaceOperations(Map<String, InterfaceOperationDataDefinition> interfaceOperations) {
- this.interfaceOperations = interfaceOperations;
- }
-
public Map<String, InterfaceDefinition> getInterfaces() {
return interfaces;
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java
index 2ecb4b444c..0d5614f176 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java
@@ -3,7 +3,6 @@ package org.openecomp.sdc.be.model;
import mockit.Deencapsulation;
import org.junit.Assert;
import org.junit.Test;
-import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.unittests.utils.ModelConfDependentTest;
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperationTest.java
index 375208d24e..f5835b6c4c 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperationTest.java
@@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue;
import fj.data.Either;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -48,7 +49,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:application-context-test.xml")
-public class InterfacesOperationTest extends ModelTestBase {
+public class InterfaceOperationTest extends ModelTestBase {
@Resource
protected TitanDao titanDao;
@@ -102,10 +103,10 @@ public class InterfacesOperationTest extends ModelTestBase {
}
@Test
- public void testAddInterface_Service(){testAddInterface(service);}
+ public void testAddInterface_Service(){testAddSingleInterface(service);}
@Test
- public void testAddInterface_Resource(){testAddInterface(resource);}
+ public void testAddInterface_Resource(){testAddMultipleInterface(resource);}
@Test
public void testUpdateInterface_Service(){testUpdateInterface(service);}
@@ -114,95 +115,71 @@ public class InterfacesOperationTest extends ModelTestBase {
public void testUpdateInterface_Resource(){testUpdateInterface(resource);}
@Test
- public void testAddInterfaceOperation_Service(){testAddInterfaceOperation(service);}
+ public void testDeleteInterface_Service(){testDeleteInterface(service);}
@Test
- public void testAddInterfaceOperation_Resource(){testAddInterfaceOperation(resource);}
-
- @Test
- public void testUpdateInterfaceOperation_Service(){testUpdateInterfaceOperation(service);}
-
- @Test
- public void testUpdateInterfaceOperation_Resource(){testUpdateInterfaceOperation(resource);}
-
- @Test
- public void testDeleteInterfaceOperation_Service(){testDeleteInterfaceOperation(service);}
-
- @Test
- public void testDeleteInterfaceOperation_Resource(){testDeleteInterfaceOperation(resource);}
+ public void testDeleteInterface_Resource(){testDeleteInterface(resource);}
@Test
public void testUpdateInterfaceShouldFailWhenNOtCreatedFirst() {
Component component = createResource();
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
+ InterfaceDefinition interfaceDefinition = buildInterfaceDefinitionWithoutOperation();
interfaceDefinition.setOperationsMap(createMockOperationMap());
- Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.updateInterface(component.getUniqueId(),
- interfaceDefinition);
+ Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation.updateInterfaces(component.getUniqueId(), Collections.singletonList(interfaceDefinition));
Assert.assertTrue(res.isRight());
}
- private void testAddInterface(Component component) {
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
- Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(),
- interfaceDefinition);
+ private void testAddSingleInterface(Component component) {
+ InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1");
+ Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation.addInterfaces(component.getUniqueId(), Collections.singletonList(interfaceDefinition));
Assert.assertTrue(res.isLeft());
+ Assert.assertEquals("1", res.left().value().get(0).getUniqueId());
}
- private void testUpdateInterface(Component component) {
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
- interfaceDefinition.setOperationsMap(createMockOperationMap());
- Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition);
+ private void testAddMultipleInterface(Component component) {
+ InterfaceDefinition interfaceDefinition1 = buildInterfaceDefinition("1");
+ InterfaceDefinition interfaceDefinition2 = buildInterfaceDefinition("2");
+ List<InterfaceDefinition> interfaceDefinitions = new ArrayList<>();
+ interfaceDefinitions.add(interfaceDefinition1);
+ interfaceDefinitions.add(interfaceDefinition2);
+ Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation.addInterfaces(component.getUniqueId(), interfaceDefinitions);
Assert.assertTrue(res.isLeft());
- InterfaceDefinition value = res.left().value();
- String new_description = "New Description";
- value.setDescription(new_description);
- res = interfaceOperation.updateInterface(component.getUniqueId(), interfaceDefinition);
- assertTrue(res.isLeft());
- assertEquals(new_description,res.left().value().getDescription());
+ Assert.assertEquals(2, res.left().value().size());
}
- private void testAddInterfaceOperation(Component component) {
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
- Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition);
+ private void testUpdateInterface(Component component) {
+ InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1");
+ Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation.addInterfaces(component.getUniqueId(), Collections.singletonList(interfaceDefinition));
Assert.assertTrue(res.isLeft());
- InterfaceDefinition value = res.left().value();
- Operation op = createMockOperation();
- Either<Operation, StorageOperationStatus> addInterfaceOperationRes = interfaceOperation.addInterfaceOperation(component.getUniqueId(), value, op);
- assertTrue(addInterfaceOperationRes.isLeft());
+ List<InterfaceDefinition> value = res.left().value();
+ InterfaceDefinition createdInterfaceDef = value.get(0);
+ String new_description = "New Description";
+ createdInterfaceDef.setDescription(new_description);
+ res = interfaceOperation.updateInterfaces(component.getUniqueId(), Collections.singletonList(createdInterfaceDef));
+ assertTrue(res.isLeft());
+ assertEquals(new_description,res.left().value().get(0).getDescription());
}
- private void testUpdateInterfaceOperation(Component component) {
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
- Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition);
+ private void testDeleteInterface(Component component) {
+ InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1");
+ Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation.addInterfaces(component.getUniqueId(), Collections.singletonList(interfaceDefinition));
Assert.assertTrue(res.isLeft());
- InterfaceDefinition value = res.left().value();
- Operation op = createMockOperation();
- Either<Operation, StorageOperationStatus> addInterfaceOperationRes = interfaceOperation.addInterfaceOperation(component.getUniqueId(), value, op);
- Assert.assertTrue(addInterfaceOperationRes.isLeft());
- Operation resultOp = addInterfaceOperationRes.left().value();
- resultOp.setName("New_Create");
- Either<Operation, StorageOperationStatus> updateInterfaceOperationRes = interfaceOperation.updateInterfaceOperation(component.getUniqueId(), value, resultOp);
- assertTrue(updateInterfaceOperationRes.isLeft());
- assertEquals("New_Create", updateInterfaceOperationRes.left().value().getName());
+ List<InterfaceDefinition> value = res.left().value();
+ Either<String, StorageOperationStatus> deleteInterfaceOperationRes = interfaceOperation.deleteInterface(component.getUniqueId(), value.get(0).getUniqueId());
+ assertTrue(deleteInterfaceOperationRes.isLeft());
}
- private void testDeleteInterfaceOperation(Component component) {
- InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
- Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition);
- Assert.assertTrue(res.isLeft());
- InterfaceDefinition value = res.left().value();
- Operation op = createMockOperation();
- Either<Operation, StorageOperationStatus> addInterfaceOperationRes = interfaceOperation.addInterfaceOperation(component.getUniqueId(), value, op);
- Assert.assertTrue(addInterfaceOperationRes.isLeft());
- Operation resultOp = addInterfaceOperationRes.left().value();
- Either<Operation, StorageOperationStatus> deleteInterfaceOperationRes = interfaceOperation.deleteInterfaceOperation(component.getUniqueId(), value, resultOp.getUniqueId());
- assertTrue(deleteInterfaceOperationRes.isLeft());
+ private InterfaceDefinition buildInterfaceDefinition(String uniqueId) {
+ InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setType("tosca.interfaces.standard");
+ interfaceDefinition.setUniqueId(uniqueId);
+ interfaceDefinition.setOperationsMap(createMockOperationMap());
+ return interfaceDefinition;
}
- private InterfaceDefinition buildInterfaceDefinition() {
+ private InterfaceDefinition buildInterfaceDefinitionWithoutOperation() {
InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
interfaceDefinition.setType("tosca.interfaces.standard");
- interfaceDefinition.setCreationDate(101232L);
return interfaceDefinition;
}
@@ -366,21 +343,21 @@ public class InterfacesOperationTest extends ModelTestBase {
addProperties.add(prop22);
StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME);
- assertSame(status, StorageOperationStatus.OK);
+ assertSame(StorageOperationStatus.OK, status);
PropertyDataDefinition prop33 = new PropertyDataDefinition();
prop33.setName("prop33");
prop33.setDefaultValue("def33");
status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, JsonPresentationFields.NAME);
- assertSame(status, StorageOperationStatus.OK);
+ assertSame(StorageOperationStatus.OK, status);
PropertyDataDefinition prop44 = new PropertyDataDefinition();
prop44.setName("prop44");
prop44.setDefaultValue("def44");
status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME);
- assertSame(status, StorageOperationStatus.OK);
+ assertSame(StorageOperationStatus.OK, status);
PropertyDataDefinition capProp = new PropertyDataDefinition();
capProp.setName("capProp");
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtilsTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtilsTest.java
deleted file mode 100644
index fbf01bc91d..0000000000
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtilsTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.openecomp.sdc.be.model.jsontitan.utils;
-
-import org.junit.Test;
-import org.openecomp.sdc.be.model.InterfaceDefinition;
-import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.model.Resource;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
-public class InterfaceUtilsTest {
-
- private InterfaceUtils createTestSubject() {
- return new InterfaceUtils();
- }
-
-
- @Test
- public void testGetInterfaceDefinitionFromToscaName() throws Exception {
- Collection<InterfaceDefinition> interfaces = null;
- String resourceName = "";
- Optional<InterfaceDefinition> result;
-
- // default test
- result = InterfaceUtils.getInterfaceDefinitionFromToscaName(interfaces, resourceName);
- }
-
-
- @Test
- public void testGetInterfaceDefinitionListFromToscaName() throws Exception {
- Collection<InterfaceDefinition> interfaces = null;
- String resourceName = "";
- Collection<InterfaceDefinition> result;
-
- // default test
- result = InterfaceUtils.getInterfaceDefinitionListFromToscaName(interfaces, resourceName);
- }
-
-
- @Test
- public void testCreateInterfaceToscaResourceName() throws Exception {
- String resourceName = "";
- String result;
-
- // default test
- result = InterfaceUtils.createInterfaceToscaResourceName(resourceName);
- }
-} \ No newline at end of file