From aa72781388f3e6408bb43f1b024d88ec1c9d2c10 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Tue, 4 Oct 2022 20:29:28 +0100 Subject: Add data type properties workspace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements the properties workspace for a data type, with the list and filter feature. Change-Id: I2ec337a0481bddd5fe32e45644abdc88e197fa49 Issue-ID: SDC-4214 Signed-off-by: André Schmid --- .../sdc/be/exception/OperationException.java | 38 ++++++++++++ .../DataTypeOperationExceptionSupplier.java | 37 ++++++++++++ .../sdc/be/model/dto/PropertyDefinitionDto.java | 39 +++++++++++++ .../model/mapper/PropertyDefinitionDtoMapper.java | 67 ++++++++++++++++++++++ .../model/operations/impl/DataTypeOperation.java | 32 +++++++++++ .../model/operations/impl/PropertyOperation.java | 12 ++-- 6 files changed, 217 insertions(+), 8 deletions(-) create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/exception/OperationException.java create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/exception/supplier/DataTypeOperationExceptionSupplier.java create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/dto/PropertyDefinitionDto.java create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/mapper/PropertyDefinitionDtoMapper.java (limited to 'catalog-model/src/main/java/org') 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 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 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 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 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 getAllDataTypeNodes() { final List dataTypesFound = new ArrayList<>(); final Either, JanusGraphOperationStatus> getAllDataTypesWithNullModel = @@ -172,4 +182,26 @@ public class DataTypeOperation extends AbstractOperation { } return Optional.of(dataTypeEither.left().value().getDataTypeDataDefinition()); } + + public List findAllProperties(final String uniqueId) { + final Either, 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 propertyMap = propertiesEither.left().value(); + if (MapUtils.isEmpty(propertyMap)) { + return List.of(); + } + final List 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 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 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 createRelResult = janusGraphGenericDao - .createRelation(uniqueIdData, propertyData, GraphEdgeLabels.PROPERTY, props); + Either 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); -- cgit 1.2.3-korg