App Onboarding - Delete app not working
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / service / EPAppCommonServiceImpl.java
index 8319dab..a4463c7 100644 (file)
@@ -75,6 +75,7 @@ import org.onap.portalapp.portal.domain.EPUserAppsManualSortPreference;
 import org.onap.portalapp.portal.domain.EPUserAppsSortPreference;
 import org.onap.portalapp.portal.domain.EPWidgetsManualSortPreference;
 import org.onap.portalapp.portal.domain.EcompApp;
+import org.onap.portalapp.portal.domain.MicroserviceData;
 import org.onap.portalapp.portal.domain.UserRole;
 import org.onap.portalapp.portal.domain.UserRoles;
 import org.onap.portalapp.portal.ecomp.model.AppCatalogItem;
@@ -94,6 +95,8 @@ import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 import org.onap.portalsdk.core.onboarding.ueb.Helper;
 import org.onap.portalsdk.core.onboarding.ueb.TopicManager;
 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.onap.portalsdk.core.onboarding.util.KeyConstants;
+import org.onap.portalsdk.core.onboarding.util.KeyProperties;
 import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
 import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
 import org.onap.portalsdk.core.service.DataAccessService;
@@ -973,6 +976,16 @@ public class EPAppCommonServiceImpl implements EPAppService {
                }
                final Map<String, Long> params = new HashMap<>();
                params.put("app_id", appid);
+               
+               //Checking if App is associated with any exiting microservices- ep_microservice:
+               final Map<String, Long> queryparams = new HashMap<>();
+               queryparams.put("applicationId", appid);
+               List<MicroserviceData> microservicesList  = dataAccessService.executeNamedQuery( "getMicroservicesByAppId", queryparams, null);
+               if(microservicesList!=null && microservicesList.size()>0) {
+                       fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+                       return fieldsValidator;
+               }
+               
                List<EPUserAppRolesRequest> EPUserAppRolesRequestList= new ArrayList<>();
                EPUserAppRolesRequestList = dataAccessService.executeNamedQuery( "getRequestIdsForApp", params, null);
            for(int i=0;i<EPUserAppRolesRequestList.size();i++)
@@ -1631,7 +1644,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
                if (encryptedAppPwd != null && !encryptedAppPwd.isEmpty()) {
                        try {
                                result = CipherUtil.decryptPKC(encryptedAppPwd,
-                                               SystemProperties.getProperty(SystemProperties.Decryption_Key));
+                                               KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY));
                        } catch (Exception e) {
                                logger.error(EELFLoggerDelegate.errorLogger, "decryptedPassword failed for app " + app.getName(), e);
                        }
@@ -1644,7 +1657,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
                if (decryptedAppPwd != null && !decryptedAppPwd.isEmpty()) {
                        try {
                                result = CipherUtil.encryptPKC(decryptedAppPwd,
-                                               SystemProperties.getProperty(SystemProperties.Decryption_Key));
+                                               KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY));
                        } catch (Exception e) {
                                logger.error(EELFLoggerDelegate.errorLogger, "encryptedPassword failed for app " + app.getName(), e);
                        }