Adding feature: Replace vfmodule
[vid.git] / vid-app-common / src / main / java / org / onap / vid / job / command / CommandUtils.java
index 0fe7255..2b6b57a 100644 (file)
 package org.onap.vid.job.command;
 
 import org.apache.commons.lang3.StringUtils;
+import org.onap.vid.aai.model.ModelVer;
 import org.onap.vid.asdc.AsdcCatalogException;
 import org.onap.vid.model.ServiceModel;
+import org.onap.vid.services.AaiService;
 import org.onap.vid.services.VidService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -31,18 +33,16 @@ import org.springframework.stereotype.Component;
 public class CommandUtils {
 
     private final VidService vidService;
+    private final AaiService aaiService;
 
     @Autowired
-    public CommandUtils(VidService vidService) {
+    public CommandUtils(VidService vidService, AaiService aaiService) {
         this.vidService = vidService;
+        this.aaiService = aaiService;
     }
 
     public boolean isVfModuleBaseModule(String serviceModelUuid, String vfModuleModelUUID) throws AsdcCatalogException{
-        ServiceModel serviceModel =  vidService.getService(serviceModelUuid);
-
-        if (serviceModel==null) {
-            throw new AsdcCatalogException("Failed to retrieve model with uuid "+serviceModelUuid +" from SDC");
-        }
+        ServiceModel serviceModel =  getServiceModel(serviceModelUuid);
 
         if (serviceModel.getVfModules() == null) {
             throw createAsdcCatalogVfModuleModelUUIDNotFoundException(serviceModelUuid, vfModuleModelUUID);
@@ -58,6 +58,23 @@ public class CommandUtils {
                 .getBaseModule();
     }
 
+    public ServiceModel getServiceModel(String serviceModelUuid) throws AsdcCatalogException{
+        ServiceModel serviceModel =  vidService.getService(serviceModelUuid);
+
+        if (serviceModel==null) {
+            throw new AsdcCatalogException("Failed to retrieve model with uuid "+serviceModelUuid +" from SDC");
+        }
+
+        return serviceModel;
+    }
+
+    public String getNewestModelUuid(String serviceModelInvariantId)
+    {
+        ModelVer serviceModelLatestVersion = aaiService.getNewestModelVersionByInvariantId(serviceModelInvariantId);
+
+        return serviceModelLatestVersion.getModelVersionId();
+    }
+
     private AsdcCatalogException createAsdcCatalogVfModuleModelUUIDNotFoundException(String serviceModelUuid, String vfModuleModelUUID) {
         return new AsdcCatalogException("Failed to find vfModuleModelUUID: " + vfModuleModelUUID +
                 "in model with uuid: " + serviceModelUuid);