Merge "align MME"
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
index 9e4d3bf..0450244 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
@@ -78,6 +78,7 @@
 import java.util.Collection;
 import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 import static org.openecomp.sdc.logging.messages.AuditMessages.SUBMIT_VSP_ERROR;
 
@@ -403,59 +404,30 @@
     MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Re_Submit_ALL_Final_VSPs.toString());
     logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.RESUBMIT_ALL_FINAL_VSPS);
 
-    List<VersionedVendorSoftwareProductInfo> vspList = Objects.requireNonNull(
-        vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), user));
-    int skippedCounter = 0;
-    final int vspListSizeBefore = vspList.size();
+    List<VersionedVendorSoftwareProductInfo> latestFinalVsps = Objects
+        .requireNonNull(vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), user));
 
-    for (VersionedVendorSoftwareProductInfo versionVspInfo : vspList) {
-      final VspDetails vspDetails = versionVspInfo.getVspDetails();
-      final String vspId = vspDetails.getId();
-      final Version latestFinalVersion =
-          getVersionInfo(vspId, VersionableEntityAction.Read, user).getLatestFinalVersion();
+    List<VersionedVendorSoftwareProductInfo> nonLockedLatestFinalVsps = latestFinalVsps.stream()
+        .filter(vsp ->
+            !isVspLocked(vsp.getVspDetails().getId(), vsp.getVspDetails().getName(), user))
+        .collect(Collectors.toList());
 
-      if (latestFinalVersion.getStatus().equals(VersionStatus.Locked)) {
-        logger.info("Skipping processing VSP name [{}]/id [{}] due to status LOCKED", vspDetails
-                .getName(),
-            vspId);
-        skippedCounter++;
-        vspList.remove(versionVspInfo);
-      }
-    }
-
-    logger.info("Removed {} VSPs out of {} from processing due to status LOCKED", skippedCounter,
-        vspListSizeBefore);
+    logger.info("Removed {} VSPs out of {} from processing due to status LOCKED.\n" +
+            "Total number of VSPs: {}. Performing healing and resubmit for all non-Manual VSPs " +
+            "in submitted status.\n No need to pre-set oldVersion field",
+        latestFinalVsps.size() - nonLockedLatestFinalVsps.size(), latestFinalVsps.size(),
+        nonLockedLatestFinalVsps.size());
 
     int healingCounter = 0;
     int failedCounter = 0;
-    int totalCounter = 0;
-
-
-    final int vspListSize = vspList.size();
-    logger.info("Total number of VSPs: {}. Performing healing and " +
-        "resubmit for all non-Manual VSPs in submitted status.\n No need to pre-set oldVersion " +
-        "field", vspListSize);
-
-    for (VersionedVendorSoftwareProductInfo versionVspInfo : vspList) {
+    for (int counter = 0; counter < nonLockedLatestFinalVsps.size(); counter++) {
+      VersionedVendorSoftwareProductInfo versionVspInfo = nonLockedLatestFinalVsps.get(counter);
       try {
-        totalCounter++;
-        final Version activeVersion = versionVspInfo.getVersionInfo().getActiveVersion();
         final VspDetails vspDetails = versionVspInfo.getVspDetails();
-        final String vspId = vspDetails.getId();
-        final Version latestFinalVersion =
-            getVersionInfo(vspId, VersionableEntityAction.Read, user).getLatestFinalVersion();
-
-        final String vspName = vspDetails.getName();
-        logger.info("VSP Name {}, VSP id [{}], Active Version {} , Active Version Status {}," +
-                "Latest Final Version {} ,  " +
-                "Latest Final Version Status {}", vspName, vspId, activeVersion
-                .toString(),
-            activeVersion.getStatus(), latestFinalVersion.toString(),
-            latestFinalVersion.getStatus());
-
-        if (Objects.nonNull(latestFinalVersion) &&
-            (!OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod()))) {
-          reSubmit(vspDetails, user, totalCounter, vspListSize);
+        if (!OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod())) {
+          logger.info("Starting on healing and resubmit for VSP [{}], #{} out of total {}",
+              vspDetails.getName(), counter + 1, nonLockedLatestFinalVsps.size());
+          reSubmit(vspDetails, user);
           healingCounter++;
         }
       } catch (Exception e) {
@@ -464,42 +436,46 @@
     }
 
     logger.info("Total VSPs processed {}. Completed running healing and resubmit for {} VSPs out" +
-            " " +
-            "of total # of {} submitted VSPs.  Failures count during resubmitAll: {}",
-        totalCounter, healingCounter, vspListSize, failedCounter);
-
+            " of total # of {} submitted VSPs.  Failures count during resubmitAll: {}",
+        nonLockedLatestFinalVsps.size(), healingCounter, latestFinalVsps.size(), failedCounter);
 
     return Response.ok().build();
   }
 
+  private boolean isVspLocked(String vspId, String vspName, String user) {
+    final VersionInfo versionInfo = getVersionInfo(vspId, VersionableEntityAction.Read, user);
 
-  private void reSubmit(VspDetails vspDetails, String user, int currentCount, int total) throws
-      Exception {
+    if (versionInfo.getStatus().equals(VersionStatus.Locked)) {
+      logger.info("VSP name [{}]/id [{}] status is LOCKED", vspName, vspId);
+      return true;
+    }
+    logger.info("VSP Name {}, VSP id [{}], Active Version {} , Status {}, Latest Final Version {}",
+        vspName, vspId, versionInfo.getActiveVersion().toString(), versionInfo.getStatus(),
+        versionInfo.getLatestFinalVersion().toString());
+    return false;
+  }
 
-    final String vspId = vspDetails.getId();
-    final String vspName = vspDetails.getName();
+
+  private void reSubmit(VspDetails vspDetails, String user) throws Exception {
     final Version versionBefore = vspDetails.getVersion();
-    Version finalVersion;
-
-    logger.info("Starting on healing and resubmit for VSP [{}], #{} out of total {}", vspName,
-        currentCount, total);
     vspDetails.setOldVersion("true");
 
+    Version finalVersion;
     try {
       finalVersion =
-          vendorSoftwareProductManager.healAndAdvanceFinalVersion(vspId, vspDetails, user);
-
+          vendorSoftwareProductManager
+              .healAndAdvanceFinalVersion(vspDetails.getId(), vspDetails, user);
     } catch (Exception e) {
-
       logger.error("Failed during resubmit, VSP [{}] , version before:{}, version after:{}, " +
               "status after:{}, with exception:{}",
-          vspName, versionBefore.toString(), vspDetails.getVersion().toString(), vspDetails
+          vspDetails.getName(), versionBefore.toString(), vspDetails.getVersion().toString(),
+          vspDetails
               .getVersion().getStatus().name(), e.getMessage());
       throw e;
     }
 
     logger.info("Completed healing and resubmit for VSP [{}], version before:{}, version after:" +
-        " {}", vspName, versionBefore.toString(), finalVersion);
+        " {}", vspDetails.getName(), versionBefore.toString(), finalVersion);
   }
 
   private static void printAuditForErrors(List<ErrorMessage> errorList, String vspId,
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java
index 3f6ffcc..07a3fa7 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java
@@ -30,6 +30,7 @@
 import org.openecomp.sdc.activityLog.ActivityLogManager;
 import org.openecomp.sdc.common.errors.CoreException;
 import org.openecomp.sdc.common.errors.Messages;
+import org.openecomp.sdc.common.utils.CommonUtil;
 import org.openecomp.sdc.common.utils.SdcCommon;
 import org.openecomp.sdc.datatypes.error.ErrorLevel;
 import org.openecomp.sdc.datatypes.error.ErrorMessage;
@@ -258,20 +259,20 @@
     OnboardingTypesEnum type =
         OnboardingTypesEnum.getOnboardingTypesEnum(vspDetails.getOnboardingOrigin());
 
-    if(vspDetails.getOnboardingOrigin().equals(OnboardingTypesEnum.ZIP.toString())) {
+    if(CommonUtil.isFileOriginFromZip(vspDetails.getOnboardingOrigin())) {
       FilesDataStructure structure = JsonUtil
           .json2Object(candidateDataEntity.get().getFilesDataStructure(), FilesDataStructure.class);
       String manifest = candidateService.createManifest(vspDetails, structure);
 
       mdcDataDebugMessage
           .debugExitMessage("VSP id", vspId);
-      return Optional.ofNullable(
+      return Optional.of(
           new ImmutablePair<>(OnboardingTypesEnum.ZIP.toString(),candidateService
               .replaceManifestInZip(candidateDataEntity.get().getContentData(),
               manifest, vspId, type)));
     }
 
-    return Optional.ofNullable(
+    return Optional.of(
         new ImmutablePair<>(vspDetails.getOnboardingOrigin(),candidateDataEntity.get()
             .getContentData().array()));
   }
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
index dde5d61..d4879da 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
@@ -832,21 +832,20 @@
   public Version healAndAdvanceFinalVersion(String vspId, VspDetails vendorSoftwareProductInfo,
                                             String user) throws IOException {
 
-    Version checkoutFinalVersion = checkout(vspId, user);
-    autoHeal(vspId, checkoutFinalVersion, vendorSoftwareProductInfo, user);
-    Version checkinFinalVersion = checkin(vspId, user);
+    Version checkoutVersion = checkout(vspId, user);
+    autoHeal(vspId, checkoutVersion, vendorSoftwareProductInfo, user);
+    Version checkinVersion = checkin(vspId, user);
 
     ValidationResponse response = Objects.requireNonNull(submit(vspId, user),
         "Null response not expected");
 
     if (!response.isValid()) {
-      return checkout(vspId, user);
+      return checkinVersion;
     }
 
-    Version finalVersion = checkinFinalVersion.calculateNextFinal();
+    Version finalVersion = checkinVersion.calculateNextFinal();
     createPackage(vspId, finalVersion, user);
     return finalVersion;
-
   }
 
   @Override
@@ -1103,7 +1102,7 @@
                 (vspDetails.getOnboardingOrigin()),
             uploadData.getContentData().array());
 
-    if (vspDetails.getOnboardingOrigin().equals(OnboardingTypesEnum.ZIP.name().toLowerCase())) {
+    if (CommonUtil.isFileOriginFromZip(vspDetails.getOnboardingOrigin())) {
       ValidationManager validationManager =
           ValidationManagerUtil.initValidationManager(fileContentMap);
       validationErrors.putAll(validationManager.validate());
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java
index db43e00..516d85c 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java
@@ -28,11 +28,11 @@
   }
 
   public static Optional<OrchestrationTemplateProcessHandler> getInstance(String filePrefix) {
-    filePrefix = filePrefix == null ? null : filePrefix.toLowerCase().trim();
     if (filePrefix == null) {
       return Optional.empty();
     }
 
+    filePrefix = filePrefix.toLowerCase().trim();
     OnboardingTypesEnum onboardingTypesEnum = OnboardingTypesEnum.getOnboardingTypesEnum(filePrefix);
     if (onboardingTypesEnum == null) {
       return Optional.empty();
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
index 1c52930..72485d7 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
@@ -42,6 +42,7 @@
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Objects;
 import java.util.Set;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
@@ -67,7 +68,7 @@
       throws IOException {
     Pair<FileContentHandler,List<String> > pair = getFileContentMapFromOrchestrationCandidateZip(uploadFileData);
 
-    if(type.equals(OnboardingTypesEnum.ZIP)) {
+    if(isFileOriginFromZip(type.toString())) {
       validateNoFolders(pair.getRight());
     }
 
@@ -133,7 +134,7 @@
     return -1;
   }
 
-  public static boolean validateFilesExtensions(Set<String> allowedExtensions, FileContentHandler
+  private static boolean validateFilesExtensions(Set<String> allowedExtensions, FileContentHandler
       files) {
     for (String fileName : files.getFileList()) {
       if (!allowedExtensions.contains(FilenameUtils.getExtension(fileName))) {
@@ -147,4 +148,9 @@
     Set<String> allowedExtensions = new HashSet<>(Arrays.asList("yml", "yaml"));
     return validateFilesExtensions(allowedExtensions, files);
   }
+
+  public static boolean isFileOriginFromZip(String fileOrigin){
+   return Objects.nonNull(fileOrigin)
+        && fileOrigin.toLowerCase().equals(OnboardingTypesEnum.ZIP.toString());
+  }
 }
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java
index 04e64c3..85fe305 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java
@@ -20,13 +20,11 @@
         if (inStr == null) {
             return null;
         }
+
         Optional<OnboardingTypesEnum>  onboardingTypesOptional =  asList(OnboardingTypesEnum.values()).stream()
-                .filter(onboardingTypesEnum -> onboardingTypesEnum.toString().equals(inStr)).findAny();
-       if( onboardingTypesOptional.isPresent()){
-          return onboardingTypesOptional.get();
-       }else {
-           return null;
-       }
+                .filter(onboardingTypesEnum -> onboardingTypesEnum.toString().equals(inStr.toLowerCase()))
+            .findAny();
+      return onboardingTypesOptional.orElse(null);
     }
 
 }
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/VspDetails.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/VspDetails.java
index e871ecf..3f9768b 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/VspDetails.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/VspDetails.java
@@ -226,8 +226,7 @@
   }
 
   public void setOnboardingOrigin(String onboardingOrigin) {
-    this.onboardingOrigin = Objects.isNull(onboardingOrigin) ? null
-        : onboardingOrigin.toLowerCase();
+    this.onboardingOrigin = onboardingOrigin;
   }
 
   public String getOnboardingMethod() {