Added audit log for onboarding page details
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / service / EPAppCommonServiceImpl.java
index 539ada2..53b8518 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;
@@ -855,7 +858,8 @@ public class EPAppCommonServiceImpl implements EPAppService {
        public List<OnboardingApp> getEnabledNonOpenOnboardingApps() {
                @SuppressWarnings("unchecked")
                List<EPApp> apps = dataAccessService.getList(EPApp.class,
-                               " where enabled = true and open = false and id!=" + ECOMP_APP_ID, null, null);
+                               " where enabled = true and open = false and app_type!= 3 and id!=" + ECOMP_APP_ID, null, null);
+       
                List<OnboardingApp> onboardingAppsList = new ArrayList<OnboardingApp>();
                for (EPApp app : apps) {
                        OnboardingApp onboardingApp = new OnboardingApp();
@@ -939,6 +943,8 @@ public class EPAppCommonServiceImpl implements EPAppService {
                if (fieldsValidator.httpStatusCode.intValue() == HttpServletResponse.SC_OK) {
                        if (modifiedOnboardingApp.getId() != null) {
                                updateApp(modifiedOnboardingApp.getId(), modifiedOnboardingApp, fieldsValidator, user);
+                               logger.info(EELFLoggerDelegate.auditLogger, "Updated " + modifiedOnboardingApp.getAppName() + 
+                                               " onboarding application details by user " + user.getLoginId());
                        } else {
                                fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
                        }
@@ -955,6 +961,8 @@ public class EPAppCommonServiceImpl implements EPAppService {
                if (fieldsValidator.httpStatusCode.intValue() == HttpServletResponse.SC_OK) {
                        if (newOnboardingApp.getId() == null) {
                                updateApp(null, newOnboardingApp, fieldsValidator, user);
+                               logger.info(EELFLoggerDelegate.auditLogger, "Added " + newOnboardingApp.getAppName() + 
+                                               " Onboarding application by user " + user.getLoginId());
                        } else {
                                fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
                        }
@@ -972,6 +980,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++)
@@ -1620,7 +1638,11 @@ public class EPAppCommonServiceImpl implements EPAppService {
        }
 
        protected String constructImageName(OnboardingApp onboardingApp) {
-               return "portal_" + String.valueOf(onboardingApp.getLandingPage().hashCode() + "_" + (int) (Math.random() * 100000.0))
+               String appLandingPageURL = onboardingApp.getLandingPage();
+               if(appLandingPageURL == null) {
+                       appLandingPageURL = "";
+               }
+               return "portal_" + String.valueOf(appLandingPageURL.hashCode() + "_" + (int) (Math.random() * 100000.0))
                                + ".png";
        }
 
@@ -1630,7 +1652,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);
                        }
@@ -1643,7 +1665,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);
                        }