diff options
Diffstat (limited to 'catalog-model/src/main/java/org')
6 files changed, 217 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); |