aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>2022-10-26 17:26:54 +0100
committerKrupaNagabhushan <krupa.nagabhushan@est.tech>2023-01-19 15:23:12 +0000
commit3943534cd3409c0cca6588f36527df34345d74f2 (patch)
treefc10c05a93fe853f21f1f3beddf5d0557d7bad1d /catalog-model
parent8edfa4dee9fed9be5b38133847c60136294eba80 (diff)
Download data type from UI
Issue-ID: SDC-4332 Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech> Change-Id: If31f7a95eb2d568e716760a33ef2641bad09cf68
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java14
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java28
2 files changed, 42 insertions, 0 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
index 7cd042a27d..d75302fc5d 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
@@ -28,6 +28,7 @@ import java.util.Map;
import java.util.Optional;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
@@ -42,6 +43,7 @@ import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.exception.supplier.DataTypeOperationExceptionSupplier;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.dto.PropertyDefinitionDto;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
@@ -208,6 +210,18 @@ public class DataTypeOperation extends AbstractOperation {
return propertyDefinitions;
}
+ public Optional<DataTypeDefinition> handleDataTypeDownloadRequestById(final String dataTypeId) {
+ if (StringUtils.isNotEmpty(dataTypeId)) {
+ Optional<DataTypeDataDefinition> dataTypeDataDefinition = getDataTypeByUid(dataTypeId);
+ if (dataTypeDataDefinition.isPresent()) {
+ DataTypeDefinition dataTypeDefinition = new DataTypeDefinition(dataTypeDataDefinition.get());
+ dataTypeDefinition.setProperties(findAllProperties(dataTypeId));
+ return Optional.of(dataTypeDefinition);
+ }
+ }
+ return Optional.empty();
+ }
+
public PropertyDefinitionDto createProperty(final String dataTypeId, final PropertyDefinitionDto propertyDefinitionDto) {
final String propertyName = propertyDefinitionDto.getName();
LOGGER.debug("Adding property '{}' to data type '{}'.", propertyName, dataTypeId);
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java
index 26fb7658f1..034269b715 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java
@@ -268,6 +268,34 @@ class DataTypeOperationTest {
assertArrayEquals(expectedException.getParams(), actualException.getParams());
}
+ @Test
+ void handleDataTypeDownloadRequestById_Success() {
+ final PropertyDefinition property1 = new PropertyDefinition();
+ property1.setName("property1");
+ final PropertyDefinition property2 = new PropertyDefinition();
+ property2.setName("property2");
+
+ when(janusGraphGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.DataType), "test.data.type00099", DataTypeData.class))
+ .thenReturn(Either.left(createDataTypeData("test.data.type99", "test.data.type00099", 888L, 999L, modelName)));
+ when(propertyOperation.findPropertiesOfNode(NodeTypeEnum.DataType, "test.data.type00099"))
+ .thenReturn(Either.left(Map.of(property1.getName(), property1, property2.getName(), property2)));
+
+ final Optional<DataTypeDefinition> dataType = dataTypeOperation.handleDataTypeDownloadRequestById("test.data.type00099");
+ assertTrue(dataType.isPresent());
+ assertEquals("test.data.type99", dataType.get().getName());
+ assertEquals("test.data.type00099", dataType.get().getUniqueId());
+ assertEquals(modelName, dataType.get().getModel());
+ assertEquals(2, dataType.get().getProperties().size());
+ assertEquals(property1.getName(), dataType.get().getProperties().get(0).getName());
+ assertEquals(property2.getName(), dataType.get().getProperties().get(1).getName());
+ }
+
+ @Test
+ void handleDataTypeDownloadRequestById_Fail() {
+ final Optional<DataTypeDefinition> dataType = dataTypeOperation.handleDataTypeDownloadRequestById("");
+ assertTrue(dataType.isEmpty());
+ }
+
private void initTestData() {
model = new Model(modelName, ModelTypeEnum.NORMATIVE);
final String TEST_DATA_TYPE_001 = "test.data.type001";