Fix issue in artifact type update 63/126763/2
authorMichaelMorris <michael.morris@est.tech>
Tue, 25 Jan 2022 19:53:06 +0000 (19:53 +0000)
committerAndr� Schmid <andre.schmid@est.tech>
Fri, 28 Jan 2022 14:49:49 +0000 (14:49 +0000)
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-3860
Change-Id: Idad3cde460f8ce8c88914a2ddde63c1950f9536b

catalog-be/src/main/resources/import/tosca/artifact-types/artifactTypes.yml
catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ArtifactTypeOperation.java

index 97d00e5..0453fb7 100644 (file)
@@ -1,40 +1,41 @@
 tosca.artifacts.Root:
     description: This is the default (root) TOSCA Artifact Type definition that all other TOSCA base Artifact Types derive from.
 
+tosca.artifacts.Deployment:
+    derived_from: tosca.artifacts.Root
+    description: This artifact type represents the parent type for all deployment artifacts in TOSCA. This class of artifacts typically represents a binary packaging of an application or service that is used to install/create or deploy it as part of a node's lifecycle.
+    
 tosca.artifacts.Deployment.Image:
     derived_from: tosca.artifacts.Deployment
     description: This artifact type represents a parent type for any "image" which is an opaque packaging of a TOSCA Node's deployment (whether real or virtual) whose contents are typically already installed and pre-configured (i.e., "stateful") and prepared to be run on a known target container.
 
-tosca.artifacts.Implementation.Bash:
-    derived_from: tosca.artifacts.Implementation
-    description: This artifact type represents a Bash script type that contains Bash commands that can be executed on the Unix Bash shell.
-
 tosca.artifacts.Deployment.Image.VM:
     derived_from: tosca.artifacts.Deployment
     description: This artifact represents the parent type for all Virtual Machine (VM) image and container formatted deployment artifacts. These images contain a stateful capture of a machine (e.g., server) including operating system and installed software along with any configurations and can be run on another machine using a hypervisor which virtualizes typical server (i.e., hardware) resources.
 
-tosca.artifacts.Implementation.Python:
-    derived_from: tosca.artifacts.Implementation
-    description: This artifact type represents a Python file that contains Python language constructs that can be executed within a Python interpreter.
-
-tosca.artifacts.Deployment:
-    derived_from: tosca.artifacts.Root
-    description: This artifact type represents the parent type for all deployment artifacts in TOSCA. This class of artifacts typically represents a binary packaging of an application or service that is used to install/create or deploy it as part of a node's lifecycle.
-
-tosca.artifacts.File:
-    derived_from: tosca.artifacts.Root
-    description: This artifact type is used when an artifact definition needs to have its associated file simply treated as a file and no special handling/handlers are invoked (i.e., it is not treated as either an implementation or deployment artifact type).
+tosca.artifacts.nfv.SwImage:
+    derived_from: tosca.artifacts.Deployment.Image
+    description: describes the software image which is directly loaded on the virtualisation container realizing of the VDU or is to be loaded on a virtual
 
 tosca.artifacts.Implementation:
     derived_from: tosca.artifacts.Root
     description: This artifact type represents the parent type for all implementation artifacts in TOSCA. These artifacts are used to implement operations of TOSCA interfaces either directly (e.g., scripts) or indirectly (e.g., config. files).
+    
+tosca.artifacts.Implementation.Bash:
+    derived_from: tosca.artifacts.Implementation
+    description: This artifact type represents a Bash script type that contains Bash commands that can be executed on the Unix Bash shell.
 
-tosca.artifacts.nfv.SwImage:
-    derived_from: tosca.artifacts.Deployment.Image
-    description: describes the software image which is directly loaded on the virtualisation container realizing of the VDU or is to be loaded on a virtual
+tosca.artifacts.Implementation.Python:
+    derived_from: tosca.artifacts.Implementation
+    description: This artifact type represents a Python file that contains Python language constructs that can be executed within a Python interpreter.
 
 tosca.artifacts.Implementation.nfv.Mistral:
     derived_from: tosca.artifacts.Implementation
     description: artifacts for Mistral workflows
     mime_type: application/x-yaml
     file_ext: [ yaml ]
+    
+tosca.artifacts.File:
+    derived_from: tosca.artifacts.Root
+    description: This artifact type is used when an artifact definition needs to have its associated file simply treated as a file and no special handling/handlers are invoked (i.e., it is not treated as either an implementation or deployment artifact type).
+
index d16a735..8dfea30 100644 (file)
@@ -105,7 +105,7 @@ public class ArtifactTypeOperation extends AbstractOperation implements IArtifac
                 createNodeResult = janusGraphGenericDao.updateNode(artifactTypeData, ArtifactTypeData.class).right()
                         .map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus).left()
                         .bind(updatedNode -> updateArtifactProperties(artifactType.getUniqueId(), artifactType.getProperties())).left()
-                        .bind(updatedProperties -> updateArtifactDerivedFrom(artifactType, artifactType.getDerivedFrom())).left()
+                        .bind(updatedProperties -> updateArtifactDerivedFrom(artifactType)).left()
                         .map(updatedDerivedFrom -> artifactType);
             }
             if (createNodeResult.isRight()) {
@@ -165,15 +165,18 @@ public class ArtifactTypeOperation extends AbstractOperation implements IArtifac
                 .bind(deleteProps -> addPropertiesToArtifact(artifactId, properties));
     }
 
-    private Either<GraphRelation, StorageOperationStatus> updateArtifactDerivedFrom(ArtifactTypeDefinition updatedArtifactType,
-                                                                                  String currDerivedFromArtifactType) {
+    private Either<GraphRelation, StorageOperationStatus> updateArtifactDerivedFrom(ArtifactTypeDefinition updatedArtifactType) {
         String artifactTypeId = updatedArtifactType.getUniqueId();
+        
+        Either<ArtifactTypeData, StorageOperationStatus> currentDerivedFrom = derivedFromOperation.getDerivedFromChild(updatedArtifactType.getUniqueId(), NodeTypeEnum.ArtifactType, ArtifactTypeData.class);
         LOGGER.debug(
                 "#updateArtifactDerivedFrom - updating artifact derived from relation for artifact type with id {}. old derived type {}. new derived type {}",
-                artifactTypeId, currDerivedFromArtifactType, updatedArtifactType.getDerivedFrom());
-        StorageOperationStatus deleteDerivedRelationStatus = deleteDerivedFromArtifactType(artifactTypeId, currDerivedFromArtifactType, updatedArtifactType.getModel());
-        if (deleteDerivedRelationStatus != StorageOperationStatus.OK) {
-            return Either.right(deleteDerivedRelationStatus);
+                artifactTypeId, currentDerivedFrom.isLeft() ? currentDerivedFrom: "", updatedArtifactType.getDerivedFrom());
+        if (currentDerivedFrom.isLeft()) {
+            StorageOperationStatus deleteDerivedRelationStatus = deleteDerivedFromArtifactType(artifactTypeId, currentDerivedFrom.left().value().getArtifactTypeDataDefinition().getType(), updatedArtifactType.getModel());
+            if (deleteDerivedRelationStatus != StorageOperationStatus.OK) {
+                return Either.right(deleteDerivedRelationStatus);
+            }
         }
         return addDerivedFromRelation(updatedArtifactType, artifactTypeId);
     }
@@ -240,7 +243,6 @@ public class ArtifactTypeOperation extends AbstractOperation implements IArtifac
     private Either<ArtifactTypeDefinition, StorageOperationStatus> getProjectionLatestArtifactTypeByType(String type, String model) {
         Map<String, Object> mapCriteria = new HashMap<>();
         mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type);
-        mapCriteria.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true);
         return getArtifactTypeByCriteria(type, mapCriteria, model);
     }