Fix use of Optional in ModelOperation 23/126623/3
authorfranciscovila <javier.paradela.vila@est.tech>
Tue, 18 Jan 2022 09:42:50 +0000 (09:42 +0000)
committerMichael Morris <michael.morris@est.tech>
Thu, 20 Jan 2022 14:18:56 +0000 (14:18 +0000)
Checking the Optionals are present before getting
their values in the ModelOperation class

Issue-ID: SDC-3832
Signed-off-by: franciscovila <javier.paradela.vila@est.tech>
Change-Id: I1bf55744a6bd31d1fe423fd0eabf09f0c04a2422

catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java

index b73f40f..8118eb3 100644 (file)
@@ -246,8 +246,11 @@ public class ModelOperation {
     private Model convertToModel(final GraphVertex modelGraphVertex) {
         final String modelName = (String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.NAME);
         final String modelTypeProperty = (String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.MODEL_TYPE);
-        final ModelTypeEnum modelType = StringUtils.isEmpty(modelTypeProperty) ? ModelTypeEnum.NORMATIVE :
-                ModelTypeEnum.findByValue(modelTypeProperty).isPresent() ? ModelTypeEnum.findByValue(modelTypeProperty).get() : ModelTypeEnum.NORMATIVE;
+        ModelTypeEnum modelType = ModelTypeEnum.NORMATIVE;
+        final Optional<ModelTypeEnum> optionalModelTypeEnum = ModelTypeEnum.findByValue(modelTypeProperty);
+        if (optionalModelTypeEnum.isPresent()) {
+            modelType = optionalModelTypeEnum.get();
+        }
         
         final Either<ImmutablePair<ModelData, GraphEdge>, JanusGraphOperationStatus> parentNode =
             janusGraphGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Model), UniqueIdBuilder.buildModelUid(modelName),