summaryrefslogtreecommitdiffstats
path: root/catalog-model/src
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2023-01-19 14:43:33 +0000
committerMichael Morris <michael.morris@est.tech>2023-01-23 15:44:25 +0000
commit7457ecefb624682f6dddc558111b1d38f2a2ca83 (patch)
tree52cbc05f95c23ac2c8d2b9be97a8ac19eec38ad3 /catalog-model/src
parent3da7d9867ab91b58f2a765d24731b45a3f43841c (diff)
Fix ability to add property to data type of different model
Issue-ID: SDC-4339 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: Ibc5b57a042ffc4e7f914d46ad264a0e16081b863
Diffstat (limited to 'catalog-model/src')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java16
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java33
2 files changed, 49 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 d75302fc5d..36dcaf44ba 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
@@ -189,6 +189,22 @@ public class DataTypeOperation extends AbstractOperation {
return Optional.of(dataTypeEither.left().value().getDataTypeDataDefinition());
}
+ public Optional<DataTypeDataDefinition> getDataTypeByNameAndModel(final String name, String model) {
+ final Either<DataTypeData, JanusGraphOperationStatus> dataTypeEither = janusGraphGenericDao
+ .getNode("name", name, DataTypeData.class, model);
+ if (dataTypeEither.isRight()) {
+ if (JanusGraphOperationStatus.NOT_FOUND.equals(dataTypeEither.right().value())) {
+ return Optional.empty();
+ }
+ final StorageOperationStatus storageOperationStatus
+ = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(dataTypeEither.right().value());
+ LOGGER.warn("Failed to fetch data type '{}' from JanusGraph. Status is: {}", name, storageOperationStatus);
+ throw new OperationException(ActionStatus.GENERAL_ERROR,
+ String.format("Failed to fetch data type '%s' from JanusGraph. Status is: %s", name, storageOperationStatus));
+ }
+ return Optional.of(dataTypeEither.left().value().getDataTypeDataDefinition());
+ }
+
public List<PropertyDefinition> findAllProperties(final String uniqueId) {
final Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> propertiesEither =
propertyOperation.findPropertiesOfNode(NodeTypeEnum.DataType, uniqueId);
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 034269b715..5d68bf9bd9 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
@@ -114,6 +114,39 @@ class DataTypeOperationTest {
}
@Test
+ void getDataTypeByNameAndModelEtsiTest() {
+ final DataTypeData dataType = dataTypesWithModel.get(0);
+ final String dataTypeName = dataType.getDataTypeDataDefinition().getName();
+ final String dataTypeUid = dataType.getDataTypeDataDefinition().getUniqueId();
+ when(janusGraphGenericDao.getNode("name", dataTypeName, DataTypeData.class, modelName))
+ .thenReturn(Either.left(dataType));
+ final var dataTypeFound = dataTypeOperation.getDataTypeByNameAndModel(dataTypeName, model.getName());
+ assertTrue(dataTypeFound.isPresent());
+ DataTypeDataDefinition foundDataType = dataTypeFound.get();
+ assertEquals(modelName ,foundDataType.getModel());
+ assertEquals(dataTypeUid ,foundDataType.getUniqueId());
+ }
+
+ @Test
+ void getDataTypeByNameAndModelNotFoundTest() {
+ when(janusGraphGenericDao.getNode("name", "notReal", DataTypeData.class, modelName))
+ .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ final var dataTypesFound = dataTypeOperation.getDataTypeByNameAndModel("notReal", modelName);
+ assertTrue(dataTypesFound.isEmpty());
+ }
+
+ @Test
+ void getDataTypeByNameAndModelGeneralErrorTest() {
+ when(janusGraphGenericDao.getNode("name", "notReal", DataTypeData.class, modelName))
+ .thenReturn(Either.right(JanusGraphOperationStatus.GENERAL_ERROR));
+ final OperationException actualException =
+ assertThrows(OperationException.class, () -> dataTypeOperation.getDataTypeByNameAndModel("notReal", modelName));
+ final OperationException expectedException =
+ DataTypeOperationExceptionSupplier.unexpectedErrorWhileFetchingProperties("notReal").get();
+ assertEquals(expectedException.getMessage(), actualException.getMessage());
+ }
+
+ @Test
void getAllDataTypeNodesWithValidationErrorTest() {
when(janusGraphGenericDao.getByCriteria(NodeTypeEnum.DataType, null, DataTypeData.class))
.thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));