summaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/exception/OperationException.java38
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/exception/supplier/DataTypeOperationExceptionSupplier.java37
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/PropertyDefinitionDto.java39
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/mapper/PropertyDefinitionDtoMapper.java67
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java32
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java12
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java52
7 files changed, 269 insertions, 8 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/exception/OperationException.java b/catalog-model/src/main/java/org/openecomp/sdc/be/exception/OperationException.java
new file mode 100644
index 0000000000..6a647b1d44
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/exception/OperationException.java
@@ -0,0 +1,38 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.exception;
+
+public class OperationException extends BusinessException {
+
+ public OperationException(final String message) {
+ super(message);
+ }
+
+ public OperationException(final Throwable cause) {
+ super(cause);
+ }
+
+ public OperationException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/exception/supplier/DataTypeOperationExceptionSupplier.java b/catalog-model/src/main/java/org/openecomp/sdc/be/exception/supplier/DataTypeOperationExceptionSupplier.java
new file mode 100644
index 0000000000..75cacdd7a8
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/exception/supplier/DataTypeOperationExceptionSupplier.java
@@ -0,0 +1,37 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.exception.supplier;
+
+import java.util.function.Supplier;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.openecomp.sdc.be.exception.OperationException;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class DataTypeOperationExceptionSupplier {
+
+ public static Supplier<OperationException> unexpectedErrorWhileFetchingProperties(final String uniqueId) {
+ final String errorMessage = String.format("An unexpected error has occurred while retrieving the data type '%s' properties", uniqueId);
+ return () -> new OperationException(errorMessage);
+ }
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/PropertyDefinitionDto.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/PropertyDefinitionDto.java
new file mode 100644
index 0000000000..bac73d9e1d
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/PropertyDefinitionDto.java
@@ -0,0 +1,39 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.model.dto;
+
+import java.util.List;
+import lombok.Data;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+
+@Data
+public class PropertyDefinitionDto {
+
+ private String uniqueId;
+ private String type;
+ private String name;
+ private Boolean required;
+ private Object value;
+ private Object defaultValue;
+ private List<PropertyConstraint> constraints;
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/mapper/PropertyDefinitionDtoMapper.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/mapper/PropertyDefinitionDtoMapper.java
new file mode 100644
index 0000000000..8566f55339
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/mapper/PropertyDefinitionDtoMapper.java
@@ -0,0 +1,67 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.model.mapper;
+
+import com.google.gson.Gson;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.collections4.CollectionUtils;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.dto.PropertyDefinitionDto;
+
+public class PropertyDefinitionDtoMapper {
+
+ public static PropertyDefinition mapTo(final PropertyDefinitionDto propertyDefinitionDto) {
+ final var propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setUniqueId(propertyDefinitionDto.getUniqueId());
+ propertyDefinition.setType(propertyDefinitionDto.getType());
+ propertyDefinition.setRequired(propertyDefinitionDto.getRequired());
+ propertyDefinition.setName(propertyDefinitionDto.getName());
+ if (CollectionUtils.isNotEmpty(propertyDefinitionDto.getConstraints())) {
+ final List<PropertyConstraint> propertyConstraints = new ArrayList<>();
+ propertyDefinition.setConstraints(propertyConstraints);
+ propertyConstraints.addAll(propertyDefinitionDto.getConstraints());
+ }
+ propertyDefinition.setValue(new Gson().toJson(propertyDefinitionDto.getValue()));
+ propertyDefinition.setDefaultValue(new Gson().toJson(propertyDefinitionDto.getDefaultValue()));
+ return propertyDefinition;
+ }
+
+ public static PropertyDefinitionDto mapFrom(final PropertyDataDefinition propertyDataDefinition) {
+ final var propertyDefinition = new PropertyDefinition(propertyDataDefinition);
+ final var propertyDefinitionDto = new PropertyDefinitionDto();
+ propertyDefinitionDto.setUniqueId(propertyDefinition.getUniqueId());
+ propertyDefinitionDto.setType(propertyDefinition.getType());
+ propertyDefinitionDto.setRequired(propertyDefinition.getRequired());
+ propertyDefinitionDto.setName(propertyDefinition.getName());
+ if (CollectionUtils.isNotEmpty(propertyDefinition.getConstraints())) {
+ final List<PropertyConstraint> propertyConstraints = new ArrayList<>();
+ propertyDefinitionDto.setConstraints(propertyConstraints);
+ propertyConstraints.addAll(propertyDefinition.getConstraints());
+ }
+ propertyDefinitionDto.setValue(new Gson().fromJson(propertyDataDefinition.getValue(), Object.class));
+ propertyDefinitionDto.setDefaultValue(new Gson().fromJson(propertyDataDefinition.getDefaultValue(), Object.class));
+ return propertyDefinitionDto;
+ }
+}
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 f75e3cfb17..4194ab70db 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
@@ -21,11 +21,13 @@ package org.openecomp.sdc.be.model.operations.impl;
import fj.data.Either;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
@@ -38,6 +40,8 @@ import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.exception.supplier.DataTypeOperationExceptionSupplier;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.DataTypeData;
@@ -53,6 +57,7 @@ public class DataTypeOperation extends AbstractOperation {
private static final Logger LOGGER = LoggerFactory.getLogger(DataTypeOperation.class);
private ModelOperation modelOperation;
+ private PropertyOperation propertyOperation;
@Autowired
public DataTypeOperation(final HealingJanusGraphGenericDao janusGraphGenericDao) {
@@ -65,6 +70,11 @@ public class DataTypeOperation extends AbstractOperation {
this.modelOperation = modelOperation;
}
+ @Autowired
+ public void setPropertyOperation(PropertyOperation propertyOperation) {
+ this.propertyOperation = propertyOperation;
+ }
+
public List<DataTypeData> getAllDataTypeNodes() {
final List<DataTypeData> dataTypesFound = new ArrayList<>();
final Either<List<DataTypeData>, JanusGraphOperationStatus> getAllDataTypesWithNullModel =
@@ -172,4 +182,26 @@ public class DataTypeOperation extends AbstractOperation {
}
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);
+ if (propertiesEither.isRight()) {
+ final JanusGraphOperationStatus status = propertiesEither.right().value();
+ if (status == JanusGraphOperationStatus.NOT_FOUND) {
+ return List.of();
+ }
+ LOGGER.error("Could not retrieve data type '{}' properties. JanusGraphOperationStatus: '{}'", uniqueId, status);
+
+ throw DataTypeOperationExceptionSupplier.unexpectedErrorWhileFetchingProperties(uniqueId).get();
+ }
+ final Map<String, PropertyDefinition> propertyMap = propertiesEither.left().value();
+ if (MapUtils.isEmpty(propertyMap)) {
+ return List.of();
+ }
+ final List<PropertyDefinition> propertyDefinitions = new ArrayList<>(propertyMap.values());
+ propertyDefinitions.sort(Comparator.comparing(PropertyDefinition::getName));
+ return propertyDefinitions;
+ }
+
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
index 6b580527c4..9e5c2e49bc 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
@@ -330,13 +330,9 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
List<PropertyConstraint> constraints = propertyDefinition.getConstraints();
propertyDefinition.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(uniqueId, propertyName));
PropertyData propertyData = new PropertyData(propertyDefinition, convertConstraintsToString(constraints));
- if (log.isDebugEnabled()) {
- log.debug(BEFORE_ADDING_PROPERTY_TO_GRAPH, propertyData);
- }
+ log.debug(BEFORE_ADDING_PROPERTY_TO_GRAPH, propertyData);
Either<PropertyData, JanusGraphOperationStatus> createNodeResult = janusGraphGenericDao.createNode(propertyData, PropertyData.class);
- if (log.isDebugEnabled()) {
- log.debug(AFTER_ADDING_PROPERTY_TO_GRAPH, propertyData);
- }
+ log.debug(AFTER_ADDING_PROPERTY_TO_GRAPH, propertyData);
if (createNodeResult.isRight()) {
JanusGraphOperationStatus operationStatus = createNodeResult.right().value();
log.error("Failed to add property {} to graph. status is {}", propertyName, operationStatus);
@@ -346,8 +342,8 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
props.put(GraphPropertiesDictionary.NAME.getProperty(), propertyName);
UniqueIdData uniqueIdData = new UniqueIdData(nodeType, uniqueId);
log.debug("Before associating {} to property {}", uniqueIdData, propertyName);
- Either<GraphRelation, JanusGraphOperationStatus> createRelResult = janusGraphGenericDao
- .createRelation(uniqueIdData, propertyData, GraphEdgeLabels.PROPERTY, props);
+ Either<GraphRelation, JanusGraphOperationStatus> createRelResult =
+ janusGraphGenericDao.createRelation(uniqueIdData, propertyData, GraphEdgeLabels.PROPERTY, props);
if (createRelResult.isRight()) {
JanusGraphOperationStatus operationStatus = createNodeResult.right().value();
log.error(FAILED_TO_ASSOCIATE_RESOURCE_TO_PROPERTY_IN_GRAPH_STATUS_IS, uniqueId, propertyName, operationStatus);
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 0efb751124..1f448fd875 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
@@ -20,6 +20,7 @@ package org.openecomp.sdc.be.model.operations.impl;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@@ -43,8 +44,11 @@ import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.exception.OperationException;
+import org.openecomp.sdc.be.exception.supplier.DataTypeOperationExceptionSupplier;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.Model;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.resources.data.DataTypeData;
import org.springframework.test.context.ContextConfiguration;
@@ -57,6 +61,8 @@ class DataTypeOperationTest {
private ModelOperation modelOperation;
@Mock
private HealingJanusGraphGenericDao janusGraphGenericDao;
+ @Mock
+ private PropertyOperation propertyOperation;
private final String modelName = "ETSI-SDC-MODEL-TEST";
private final List<DataTypeData> dataTypesWithoutModel = new ArrayList<>();
@@ -69,6 +75,7 @@ class DataTypeOperationTest {
void beforeEachInit() {
MockitoAnnotations.openMocks(this);
dataTypeOperation.setModelOperation(modelOperation);
+ dataTypeOperation.setPropertyOperation(propertyOperation);
initTestData();
}
@@ -135,6 +142,51 @@ class DataTypeOperationTest {
assertTrue(result.isEmpty());
}
+ @Test
+ void findAllPropertiesTest_Success() {
+ final PropertyDefinition property1 = new PropertyDefinition();
+ property1.setName("property1");
+ final PropertyDefinition property2 = new PropertyDefinition();
+ property2.setName("property2");
+ final PropertyDefinition property3 = new PropertyDefinition();
+ property3.setName("property3");
+
+ when(propertyOperation.findPropertiesOfNode(NodeTypeEnum.DataType, "uniqueId"))
+ .thenReturn(Either.left(Map.of(property3.getName(), property3, property1.getName(), property1, property2.getName(), property2)));
+ final List<PropertyDefinition> dataTypeProperties = dataTypeOperation.findAllProperties("uniqueId");
+ assertEquals(3, dataTypeProperties.size());
+ assertEquals(property1.getName(), dataTypeProperties.get(0).getName());
+ assertEquals(property2.getName(), dataTypeProperties.get(1).getName());
+ assertEquals(property3.getName(), dataTypeProperties.get(2).getName());
+ }
+
+ @Test
+ void findAllPropertiesTest_propertiesNotFoundSuccess() {
+ when(propertyOperation.findPropertiesOfNode(NodeTypeEnum.DataType, "uniqueId"))
+ .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ final List<PropertyDefinition> dataTypeProperties = dataTypeOperation.findAllProperties("uniqueId");
+ assertTrue(dataTypeProperties.isEmpty());
+ }
+
+ @Test
+ void findAllPropertiesTest_emptyPropertiesSuccess() {
+ when(propertyOperation.findPropertiesOfNode(NodeTypeEnum.DataType, "uniqueId"))
+ .thenReturn(Either.left(Map.of()));
+ final List<PropertyDefinition> dataTypeProperties = dataTypeOperation.findAllProperties("uniqueId");
+ assertTrue(dataTypeProperties.isEmpty());
+ }
+
+ @Test
+ void findAllPropertiesTest_unknownError() {
+ final String uniqueId = "uniqueId";
+ when(propertyOperation.findPropertiesOfNode(NodeTypeEnum.DataType, uniqueId))
+ .thenReturn(Either.right(JanusGraphOperationStatus.GENERAL_ERROR));
+ final OperationException actualException = assertThrows(OperationException.class, () -> dataTypeOperation.findAllProperties(uniqueId));
+ final OperationException expectedException =
+ DataTypeOperationExceptionSupplier.unexpectedErrorWhileFetchingProperties(uniqueId).get();
+ assertEquals(expectedException.getMessage(), actualException.getMessage());
+ }
+
private void initTestData() {
model = new Model(modelName, ModelTypeEnum.NORMATIVE);
final String TEST_DATA_TYPE_001 = "test.data.type001";