fixes for non gui application
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / service / EPAppCommonServiceImpl.java
index 24572fb..8319dab 100644 (file)
@@ -4,6 +4,8 @@
  * ===================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
  *
  * Unless otherwise specified, all software contained herein is licensed
  * under the Apache License, Version 2.0 (the "License");
@@ -48,6 +50,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 import javax.annotation.PostConstruct;
 import javax.servlet.http.HttpServletResponse;
@@ -58,6 +61,8 @@ import org.hibernate.SessionFactory;
 import org.hibernate.Transaction;
 import org.hibernate.criterion.Criterion;
 import org.hibernate.criterion.Restrictions;
+import org.json.JSONArray;
+import org.json.JSONObject;
 import org.onap.portalapp.portal.domain.AdminUserApp;
 import org.onap.portalapp.portal.domain.AdminUserApplications;
 import org.onap.portalapp.portal.domain.AppIdAndNameTransportModel;
@@ -94,6 +99,13 @@ import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
 import org.onap.portalsdk.core.service.DataAccessService;
 import org.onap.portalsdk.core.util.SystemProperties;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.RestTemplate;
 
 import com.att.nsa.apiClient.http.HttpException;
 import com.att.nsa.cambria.client.CambriaClient.CambriaApiException;
@@ -108,7 +120,9 @@ public class EPAppCommonServiceImpl implements EPAppService {
        protected String ACCOUNT_ADMIN_ROLE_ID = "999";
        protected String RESTRICTED_APP_ROLE_ID = "900";
 
-       private static final String urlField = "url";
+       //private static final String urlField = "url";
+       private static final String nameSpaceField = "url";
+
        private static final String nameField = "name";
 
        private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPAppCommonServiceImpl.class);
@@ -119,6 +133,8 @@ public class EPAppCommonServiceImpl implements EPAppService {
        protected SessionFactory sessionFactory;
        @Autowired
        private DataAccessService dataAccessService;    
+       
+       RestTemplate template = new RestTemplate();
 
        @PostConstruct
        private void init() {
@@ -127,6 +143,65 @@ public class EPAppCommonServiceImpl implements EPAppService {
                ECOMP_APP_ID = SystemProperties.getProperty(EPCommonSystemProperties.ECOMP_APP_ID);
                RESTRICTED_APP_ROLE_ID = SystemProperties.getProperty(EPCommonSystemProperties.RESTRICTED_APP_ROLE_ID);
        }
+       
+       public Boolean onboardingAppFieldsValidation(OnboardingApp onboardingApp) {
+               //FieldsValidator fieldsValidator = new FieldsValidator();
+
+               if ((!onboardingApp.getRestrictedApp()) &&( onboardingApp.getAppName() == null || onboardingApp.getAppName().length() == 0 || onboardingApp.getRestrictedApp() == null
+                               || onboardingApp.getLandingPage() == null || onboardingApp.getLandingPage().length() == 0 || onboardingApp.getRestUrl() == null || onboardingApp.getRestUrl().length() == 0
+                           || onboardingApp.getAppBasicAuthUsername() == null || onboardingApp.getAppBasicAuthUsername().length() == 0
+                               || onboardingApp.getIsOpen() == null
+                               || (onboardingApp.getId() != null && onboardingApp.getId().equals(ECOMP_APP_ID)))
+                               // For a normal app (appType == PortalConstants.PortalAppId),
+                               // these fields must be filled
+                               // in.
+                               // For a restricted app (appType==2), they will be empty.
+                               || ((onboardingApp.getRestrictedApp()) && (onboardingApp.getAppName() == null || onboardingApp.getAppName().length() == 0
+                                               || onboardingApp.getLandingPage() == null || onboardingApp.getLandingPage().length() == 0 || onboardingApp.getIsOpen() == null))) {
+                       return false;
+               }
+               return true;
+               
+       }
+       
+       private Boolean onboardingInactiveAppFieldsForValidation(OnboardingApp onboardingApp) {
+               if (onboardingApp.getAppName() == null || onboardingApp.getAppName().length() == 0
+                               || onboardingApp.getIsOpen() == null) {
+                       return false;
+               }
+               return true;
+       }
+
+       protected FieldsValidator onboardingAppFieldsChecker(OnboardingApp onboardingApp) {
+               FieldsValidator fieldsValidator = new FieldsValidator();
+               if (onboardingApp.getRolesInAAF()) {
+                       if (!onboardingApp.getIsEnabled()) {
+                               if (!onboardingInactiveAppFieldsForValidation(onboardingApp)) {
+                                       fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
+                               }
+                       } else if (onboardingApp.getIsEnabled()) {
+                               if (onboardingAppFieldsValidation(onboardingApp) == false || onboardingApp.getNameSpace() == null
+                                               || onboardingApp.getNameSpace().length() == 0) {
+                                       fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
+                               }
+                       }
+               } else {
+                       if (!onboardingApp.getIsEnabled()) {
+                               if (!onboardingInactiveAppFieldsForValidation(onboardingApp)) {
+                                       fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
+                               }
+                       } else if (onboardingApp.getIsEnabled()) {
+                               if(onboardingApp.getRestrictedApp() && onboardingAppFieldsValidation(onboardingApp) == false){
+                                       fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
+                               }
+                               else if (!onboardingApp.getRestrictedApp() && (onboardingAppFieldsValidation(onboardingApp) == false || onboardingApp.getAppBasicAuthPassword() == null
+                                               || onboardingApp.getAppBasicAuthPassword().length() == 0)) {
+                                       fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
+                               }
+                       }
+               }
+               return fieldsValidator;
+       }
 
        @Override
        public List<EPApp> getUserAsAdminApps(EPUser user) {
@@ -143,12 +218,15 @@ public class EPAppCommonServiceImpl implements EPAppService {
                                EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e);
                                return null;
                        }
+                       
                } else {
                        logger.error(EELFLoggerDelegate.errorLogger,
                                        "getUserAsAdminApps: only Account Admin may invoke this function!");
                        return new ArrayList<EPApp>();
                }
        }
+       
+       
 
        @Override
        public List<EPApp> getUserByOrgUserIdAsAdminApps(String orgUserId) {
@@ -190,15 +268,15 @@ public class EPAppCommonServiceImpl implements EPAppService {
                        ecompApp.setId(app.getId());
                        ecompApp.setName(app.getName());
                        ecompApp.setImageUrl(app.getImageUrl());
-                       ecompApp.setDescription(app.getDescription());
-                       ecompApp.setNotes(app.getNotes());
-                       ecompApp.setUrl(app.getUrl());
-                       ecompApp.setAlternateUrl(app.getAlternateUrl());
+                       ecompApp.setDescription(app.getAppDescription());
+                       ecompApp.setNotes(app.getAppNotes());
+                       ecompApp.setUrl(app.getLandingPage());
+                       ecompApp.setAlternateUrl(app.getAlternateLandingPage());
                        ecompApp.setUebTopicName(app.getUebTopicName());
-                       ecompApp.setUebKey(app.getUebKey());
+                       //ecompApp.setUebKey(app.getUebKey());
                        ecompApp.setUebSecret(app.getUebSecret());
                        ecompApp.setEnabled(app.getEnabled());
-                       ecompApp.setCentralAuth(app.getCentralAuth());
+                       ecompApp.setCentralAuth(app.getRolesInAAF());
                        ecompApp.setNameSpace(app.getNameSpace());
                        ecompApp.setRestrictedApp(app.isRestrictedApp());
                        ecompAppList.add(ecompApp);
@@ -216,25 +294,66 @@ public class EPAppCommonServiceImpl implements EPAppService {
                }
        }
 
+       
+       
        @SuppressWarnings("unchecked")
        @Override
        public List<AppIdAndNameTransportModel> getAdminApps(EPUser user) {
-               if (adminRolesService.isAccountAdmin(user)) {
-                       String format = "SELECT app.APP_ID, app.APP_NAME, app.APP_TYPE FROM FN_APP app inner join FN_USER_ROLE userrole ON userrole.APP_ID=app.APP_ID "
-                                       + "where userrole.USER_ID = %d AND userrole.ROLE_ID=" + ACCOUNT_ADMIN_ROLE_ID
-                                       + " AND (app.ENABLED = 'Y' OR app.APP_ID=1)";
-                       String sql = String.format(format, user.getId());
-                       // sql += " AND app.APP_REST_ENDPOINT IS NOT NULL AND
-                       // app.APP_REST_ENDPOINT <> ''";
-                       logQuery(sql);
+
+               if (adminRolesService.isAccountAdmin(user) && adminRolesService.isRoleAdmin(user)) {
+                       final Map<String, Long> params = new HashMap<>();
+                       params.put("userId", user.getId());
+                       List applicationRoleswithAccountandRoleadmin = dataAccessService
+                                       .executeNamedQuery("getApplicationsofTheUserwithAdminAndRoleAdmin", params, null);
                        try {
-                               return dataAccessService.executeSQLQuery(sql, AppIdAndNameTransportModel.class, null);
+                               return applicationRoleswithAccountandRoleadmin;
                        } catch (Exception e) {
                                EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e);
                                logger.error(EELFLoggerDelegate.errorLogger,
-                                               "Exception occurred while fetching the adminApps for user " + user.getLoginId(), e);
+                                               "Exception occurred while fetching the list of user who has type account and role approver "
+                                                               + user.getLoginId(),
+                                               e);
                        }
                }
+
+               else {
+                       if (adminRolesService.isAccountAdmin(user)) {
+                               String format = "SELECT app.APP_ID, app.APP_NAME, app.APP_TYPE FROM FN_APP app inner join FN_USER_ROLE userrole ON userrole.APP_ID=app.APP_ID "
+                                               + "where userrole.USER_ID = %d AND userrole.ROLE_ID=" + ACCOUNT_ADMIN_ROLE_ID
+                                               + " AND (app.ENABLED = 'Y' OR app.APP_ID=1)";
+                               String sql = String.format(format, user.getId());
+                               logQuery(sql);
+                               try {
+                                       return dataAccessService.executeSQLQuery(sql, AppIdAndNameTransportModel.class, null);
+                               } catch (Exception e) {
+                                       EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e);
+                                       logger.error(EELFLoggerDelegate.errorLogger,
+                                                       "Exception occurred while fetching the adminApps for user " + user.getLoginId(), e);
+                               }
+
+                       }
+
+                       if (adminRolesService.isRoleAdmin(user)) {
+                               final Map<String, Long> params = new HashMap<>();
+                               params.put("userId", user.getId());
+                               List applicationRoles = dataAccessService.executeNamedQuery("getApplicationsofTheUserContainsApprover",
+                                               params, null);
+
+                               try {
+                                       return applicationRoles;
+                               } catch (Exception e) {
+                                       EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e);
+                                       logger.error(EELFLoggerDelegate.errorLogger,
+                                                       "Exception occurred while fetching the list of user who has type approver "
+                                                                       + user.getLoginId(),
+                                                       e);
+                               }
+
+                       }
+               }
+               // sql += " AND app.APP_REST_ENDPOINT IS NOT NULL AND
+               // app.APP_REST_ENDPOINT <> ''";
+
                return new ArrayList<AppIdAndNameTransportModel>();
        }
 
@@ -262,7 +381,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
                        if (apps.size() > 0) {
                                EPApp app = apps.get(0);
                                if (!EcompPortalUtils.checkIfRemoteCentralAccessAllowed()) {
-                                       app.setCentralAuth(false);
+                                       app.setRolesInAAF(false);
                                }
                                return app;
                        } else{
@@ -360,6 +479,23 @@ public class EPAppCommonServiceImpl implements EPAppService {
                return appsModified;
        }
 
+       
+       @Override
+       public List<AppsResponse> getAllApplications(Boolean all) {
+               // If all is true, return both active and inactive apps. Otherwise, just
+               // active apps.
+               @SuppressWarnings("unchecked")
+               // Sort the list by application name so the drop-down looks pretty.
+               List<EPApp> apps = all
+                               ? (List<EPApp>) dataAccessService.getList(EPApp.class, " where id != " + ECOMP_APP_ID, "name", null)
+                                               :dataAccessService.getList(EPApp.class, null);
+
+               List<AppsResponse> appsModified = new ArrayList<AppsResponse>();
+               for (EPApp app : apps) {
+                       appsModified.add(new AppsResponse(app.getId(), app.getName(), app.isRestrictedApp(), app.getEnabled()));
+               }
+               return appsModified;
+       }
        @Override
        public UserRoles getUserProfile(String loginId) {
                final Map<String, String> params = new HashMap<>();
@@ -442,22 +578,45 @@ public class EPAppCommonServiceImpl implements EPAppService {
                return query.toString();
        }
 
-       protected FieldsValidator onboardingAppFieldsChecker(OnboardingApp onboardingApp) {
+       /*protected FieldsValidator onboardingAppFieldsChecker(OnboardingApp onboardingApp) {
                FieldsValidator fieldsValidator = new FieldsValidator();
+               if(onboardingApp.isCentralAuth){
                if (onboardingApp.name == null || onboardingApp.name.length() == 0 || onboardingApp.url == null
-                               || onboardingApp.url.length() == 0 || onboardingApp.restrictedApp == null
-                               || onboardingApp.isOpen == null || onboardingApp.isEnabled == null
-                               || (onboardingApp.id != null && onboardingApp.id.equals(ECOMP_APP_ID))
-                               // For a normal app (appType==1), these fields must be filled
+                               || onboardingApp.url.length() == 0 || onboardingApp.getRestrictedApp() == null
+                               || onboardingApp.getIsOpen() == null || onboardingApp.getIsEnabled() == null
+                               || (onboardingApp.getId() != null && ECOMP_APP_ID.equals(onboardingApp.getId().toString()))
+                               // For a normal app (appType == PortalConstants.PortalAppId),
+                               // these fields must be filled
                                // in.
                                // For a restricted app (appType==2), they will be empty.
-                               || ((!onboardingApp.restrictedApp)
-                                               && (onboardingApp.username == null || onboardingApp.username.length() == 0
-                                                               || onboardingApp.appPassword == null || onboardingApp.appPassword.length() == 0))) {
+                               || ((!onboardingApp.getRestrictedApp()) && (onboardingApp.myLoginsAppName == null
+                                               || onboardingApp.myLoginsAppName.length() == 0 || onboardingApp.myLoginsAppOwner == null
+                                               || onboardingApp.myLoginsAppOwner.length() == 0 || onboardingApp.username == null
+                                               || onboardingApp.username.length() == 0 ))) {
                        fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
+               }
+               }else{
+
+                       if (onboardingApp.name == null || onboardingApp.name.length() == 0 || onboardingApp.url == null
+                                       || onboardingApp.url.length() == 0 || onboardingApp.getRestrictedApp() == null
+                                       || onboardingApp.getIsOpen() == null || onboardingApp.getIsEnabled() == null
+                                       || (onboardingApp.getId() != null && ECOMP_APP_ID.equals(onboardingApp.getId().toString()))
+                                       // For a normal app (appType == PortalConstants.PortalAppId),
+                                       // these fields must be filled
+                                       // in.
+                                       // For a restricted app (appType==2), they will be empty.
+                                       || ((!onboardingApp.getRestrictedApp()) && (onboardingApp.myLoginsAppName == null
+                                                       || onboardingApp.myLoginsAppName.length() == 0 || onboardingApp.myLoginsAppOwner == null
+                                                       || onboardingApp.myLoginsAppOwner.length() == 0 || onboardingApp.username == null
+                                                       || onboardingApp.username.length() == 0 || onboardingApp.appPassword == null
+                                                       || onboardingApp.appPassword.length() == 0))) {
+                               fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
+                       }
+                       
+                       
                }
                return fieldsValidator;
-       }
+       }*/
 
        @Override
        public List<EPApp> getUserApps(EPUser user) {
@@ -656,7 +815,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
                }
                return finalsortedAppsByManual;
        }
-
+       
        @Override
        public List<OnboardingApp> getOnboardingApps() {
                @SuppressWarnings("unchecked")
@@ -664,22 +823,43 @@ public class EPAppCommonServiceImpl implements EPAppService {
                List<OnboardingApp> onboardingAppsList = new ArrayList<OnboardingApp>();
                for (EPApp app : apps) {
                        OnboardingApp onboardingApp = new OnboardingApp();
-                       app.setAppPassword(EPCommonSystemProperties.APP_DISPLAY_PASSWORD);//to hide password from get request
+                       app.setAppBasicAuthPassword(EPCommonSystemProperties.APP_DISPLAY_PASSWORD);//to hide password from get request
                        createOnboardingFromApp(app, onboardingApp);
                        onboardingAppsList.add(onboardingApp);
                }
                return onboardingAppsList;
        }
+       
+       @SuppressWarnings("unchecked")
+       @Override
+       public List<OnboardingApp> getAdminAppsOfUser(EPUser user) {
+               
+               List<OnboardingApp> onboardingAppsList = new ArrayList<OnboardingApp>();
+               List<Integer> userAdminApps = new ArrayList<>();
+               final Map<String, Long> userParams = new HashMap<>();
+               userParams.put("userId", user.getId()); 
+               userAdminApps =  dataAccessService.executeNamedQuery("getAllAdminAppsofTheUser", userParams, null);
+               
+//             userAdminApps.removeIf(x -> x == Integer.valueOf(ECOMP_APP_ID));
+               
+               logger.debug(EELFLoggerDelegate.debugLogger, "Is account admin for userAdminApps() - for user {}, found userAdminAppsSize {}", user.getOrgUserId(), userAdminApps.size());
+               onboardingAppsList = getOnboardingApps();
+               
+               final List<Integer> userAdminApps1 = userAdminApps;
+               List<OnboardingApp> userApplicationAdmins = onboardingAppsList.stream().filter(x -> userAdminApps1.contains((int) (long)x.getId())).collect(Collectors.toList());
+               
+        return userApplicationAdmins;
+       }
 
        @Override
        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();
-                       app.setAppPassword(EPCommonSystemProperties.APP_DISPLAY_PASSWORD); //to hide password from get request
                        createOnboardingFromApp(app, onboardingApp);
                        onboardingAppsList.add(onboardingApp);
                }
@@ -688,50 +868,59 @@ public class EPAppCommonServiceImpl implements EPAppService {
 
        @SuppressWarnings("unchecked")
        private void validateOnboardingApp(OnboardingApp onboardingApp, FieldsValidator fieldsValidator) {
-               boolean duplicatedUrl = false;
+               boolean duplicatedNameSpace = false;
                boolean duplicatedName = false;
                List<EPApp> apps;
-               if (onboardingApp.id == null) {
+               if (onboardingApp.getId() == null) {
                        List<Criterion> restrictionsList = new ArrayList<Criterion>();
-                       Criterion urlCrit =Restrictions.eq("url", onboardingApp.url);
-                       Criterion nameCrit = Restrictions.eq("name",onboardingApp.name);                        
-                       Criterion orCrit = Restrictions.or(urlCrit, nameCrit);
-                       
+                       Criterion nameCrit = Restrictions.eq("name",onboardingApp.getAppName());
+                       Criterion nameSpaceCrit = null;
+                       Criterion       orCrit = null;
+                       if (onboardingApp.getRolesInAAF()) {
+                               nameSpaceCrit = Restrictions.eq("nameSpace", onboardingApp.getNameSpace());
+                               orCrit = Restrictions.or(nameCrit, nameSpaceCrit);
+                       } else
+                               orCrit = Restrictions.or(nameCrit);
                        restrictionsList.add(orCrit);
                        apps = (List<EPApp>) dataAccessService.getList(EPApp.class, null, restrictionsList, null);
-                       
-                       
                } else {
                        List<Criterion> restrictionsList = new ArrayList<Criterion>();
-                       Criterion idCrit =Restrictions.eq("id", onboardingApp.id);
-                       Criterion urlCrit =Restrictions.eq("url", onboardingApp.url);
-                       Criterion nameCrit = Restrictions.eq("name",onboardingApp.name);                        
-                       Criterion orCrit = Restrictions.or(idCrit, urlCrit, nameCrit);
+                       Criterion idCrit =Restrictions.eq("id", onboardingApp.getId());
+                       Criterion nameCrit = Restrictions.eq("name",onboardingApp.getAppName());
+                       Criterion nameSpaceCrit = null;
+                       Criterion orCrit= null;
+                       if (onboardingApp.getRolesInAAF()) {
+                               nameSpaceCrit = Restrictions.eq("nameSpace",onboardingApp.getNameSpace());
+                               orCrit = Restrictions.or(idCrit, nameSpaceCrit, nameCrit);
+                       }
+                       else
+                        orCrit = Restrictions.or(idCrit, nameCrit);
                        
                        restrictionsList.add(orCrit);
                        apps = (List<EPApp>) dataAccessService.getList(EPApp.class, null, restrictionsList, null);
                        
                }
                for (EPApp app : apps) {
-                       if (onboardingApp.id != null && onboardingApp.id.equals(app.getId())) {
+                       if (onboardingApp.getId() != null && onboardingApp.getId().equals(app.getId())) {
                                continue;
                        }
-                       if (!duplicatedUrl && app.getUrl().equalsIgnoreCase(onboardingApp.url)) {
-                               duplicatedUrl = true;
+                       if (!duplicatedName && app.getName().equalsIgnoreCase(onboardingApp.getAppName())) {
+                               duplicatedName = true;
                                if (duplicatedName) {
                                        break;
                                }
                        }
-                       if (!duplicatedName && app.getName().equalsIgnoreCase(onboardingApp.name)) {
-                               duplicatedName = true;
-                               if (duplicatedUrl) {
+                       if (!duplicatedNameSpace && app.getNameSpace().equalsIgnoreCase(onboardingApp.getNameSpace())) {
+                               duplicatedNameSpace = true;
+                               if (duplicatedNameSpace) {
                                        break;
                                }
                        }
+                       
                }
-               if (duplicatedUrl || duplicatedName) {
-                       if (duplicatedUrl) {
-                               fieldsValidator.addProblematicFieldName(urlField);
+               if (duplicatedNameSpace || duplicatedName) {
+                       if (duplicatedNameSpace) {
+                               fieldsValidator.addProblematicFieldName(nameSpaceField);
                        }
                        if (duplicatedName) {
                                fieldsValidator.addProblematicFieldName(nameField);
@@ -749,8 +938,8 @@ public class EPAppCommonServiceImpl implements EPAppService {
                        validateOnboardingApp(modifiedOnboardingApp, fieldsValidator);
                }
                if (fieldsValidator.httpStatusCode.intValue() == HttpServletResponse.SC_OK) {
-                       if (modifiedOnboardingApp.id != null) {
-                               updateApp(modifiedOnboardingApp.id, modifiedOnboardingApp, fieldsValidator, user);
+                       if (modifiedOnboardingApp.getId() != null) {
+                               updateApp(modifiedOnboardingApp.getId(), modifiedOnboardingApp, fieldsValidator, user);
                        } else {
                                fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
                        }
@@ -765,7 +954,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
                        validateOnboardingApp(newOnboardingApp, fieldsValidator);
                }
                if (fieldsValidator.httpStatusCode.intValue() == HttpServletResponse.SC_OK) {
-                       if (newOnboardingApp.id == null) {
+                       if (newOnboardingApp.getId() == null) {
                                updateApp(null, newOnboardingApp, fieldsValidator, user);
                        } else {
                                fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_BAD_REQUEST);
@@ -1023,7 +1212,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
                logger.debug(EELFLoggerDelegate.debugLogger, "LR: entering updateApp");
                // Separate out the code for a restricted app, since it doesn't need any
                // of the UEB code.
-               if (onboardingApp.restrictedApp) {
+               if (Boolean.TRUE.equals(onboardingApp.getRestrictedApp())) {
                        boolean result = false;
                        Session localSession = null;
                        Transaction transaction = null;
@@ -1046,7 +1235,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
                                createAppFromOnboarding(app, onboardingApp, localSession);
                                localSession.saveOrUpdate(app);
                                // Enable or disable all menu items associated with this app
-                               setFunctionalMenuItemsEnabled(localSession, onboardingApp.isEnabled, appId);
+                               setFunctionalMenuItemsEnabled(localSession, onboardingApp.getIsEnabled(), appId);
                                transaction.commit();
                                result = true;
                        } catch (Exception e) {
@@ -1112,7 +1301,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
                                logger.debug(EELFLoggerDelegate.debugLogger,
                                                "updateRestrictedApp: finished calling localSession.saveOrUpdate");
                                // Enable or disable all menu items associated with this app
-                               setFunctionalMenuItemsEnabled(localSession, onboardingApp.isEnabled, appId);
+                               setFunctionalMenuItemsEnabled(localSession, onboardingApp.getIsEnabled(), appId);
                                logger.debug(EELFLoggerDelegate.debugLogger,
                                                "updateRestrictedApp: finished calling setFunctionalMenuItemsEnabled");
                                transaction.commit();
@@ -1217,10 +1406,10 @@ public class EPAppCommonServiceImpl implements EPAppService {
                                                        topicManager.createTopic(
                                                                        PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY),
                                                                        PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_SECRET),
-                                                                       appMailboxName, "ECOMP outbox for app" + onboardingApp.name);
+                                                                       appMailboxName, "ECOMP outbox for app" + onboardingApp.getAppName());
                                                        successfullyCreatedMailbox = true;
                                                        logger.debug(EELFLoggerDelegate.debugLogger,
-                                                                       "Successfully created " + appMailboxName + " for App " + onboardingApp.name);
+                                                                       "Successfully created " + appMailboxName + " for App " + onboardingApp.getAppName());
                                                        logger.debug(EELFLoggerDelegate.debugLogger, "    Key = " + appKey + " Secret = "
                                                                        + appSecret + " generated using = " + user.getEmail());
                                                        break;
@@ -1299,7 +1488,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
                                logger.debug(EELFLoggerDelegate.debugLogger,
                                                "LR: updateApp: finished calling localSession.saveOrUpdate");
                                // Enable or disable all menu items associated with this app
-                               setFunctionalMenuItemsEnabled(localSession, onboardingApp.isEnabled, appId);
+                               setFunctionalMenuItemsEnabled(localSession, onboardingApp.getIsEnabled(), appId);
                                logger.debug(EELFLoggerDelegate.debugLogger,
                                                "LR: updateApp: finished calling setFunctionalMenuItemsEnabled");
                                transaction.commit();
@@ -1340,27 +1529,35 @@ public class EPAppCommonServiceImpl implements EPAppService {
         */
        @Override
        public void createOnboardingFromApp(EPApp app, OnboardingApp onboardingApp) {
-               onboardingApp.id = app.getId();
-               onboardingApp.name = app.getName();
-               onboardingApp.imageUrl = app.getImageUrl();
-               onboardingApp.description = app.getDescription();
-               onboardingApp.notes = app.getNotes();
-               onboardingApp.url = app.getUrl();
-               onboardingApp.alternateUrl = app.getAlternateUrl();
-               onboardingApp.restUrl = app.getAppRestEndpoint();
-               onboardingApp.isOpen = app.getOpen();
-               onboardingApp.isEnabled = app.getEnabled();
-               onboardingApp.username = app.getUsername();
-               onboardingApp.appPassword = (app.getAppPassword().equals(EPCommonSystemProperties.APP_DISPLAY_PASSWORD)) ? EPCommonSystemProperties.APP_DISPLAY_PASSWORD :decryptedPassword(app.getAppPassword(), app);
-               onboardingApp.uebTopicName = app.getUebTopicName();
-               onboardingApp.uebKey = app.getUebKey();
-               onboardingApp.uebSecret = app.getUebSecret();
-               onboardingApp.isCentralAuth = app.getCentralAuth();
-               onboardingApp.nameSpace = app.getNameSpace();
+               onboardingApp.setId(app.getId());
+               onboardingApp.setAppName(app.getName());
+               onboardingApp.setImageUrl(app.getImageUrl());
+               onboardingApp.setAppDescription(app.getAppDescription());
+               onboardingApp.setAppNotes(app.getAppNotes());
+               onboardingApp.setLandingPage(app.getLandingPage());
+               onboardingApp.setAlternateLandingPage(app.getAlternateLandingPage());
+               onboardingApp.setRestUrl(app.getAppRestEndpoint());
+               onboardingApp.setIsOpen(app.getOpen());
+               onboardingApp.setIsEnabled(app.getEnabled());
+               onboardingApp.setAppBasicAuthUsername(app.getAppBasicAuthUsername());
+               
+               String effectivePwd = null;
+               if (app.getAppBasicAuthPassword().equals(EPCommonSystemProperties.APP_DISPLAY_PASSWORD))
+                       effectivePwd = EPCommonSystemProperties.APP_DISPLAY_PASSWORD;
+               else
+                       effectivePwd = decryptedPassword(app.getAppBasicAuthPassword(), app);
+               
+               onboardingApp.setAppBasicAuthPassword(effectivePwd);
+               onboardingApp.setUebTopicName(app.getUebTopicName());
+               onboardingApp.setUebKey(app.getUebKey());
+               onboardingApp.setUebSecret(app.getUebSecret());
+               onboardingApp.setRolesInAAF(app.getRolesInAAF());
+               onboardingApp.setNameSpace(app.getNameSpace());
                onboardingApp.setRestrictedApp(app.isRestrictedApp());
-               // if (app.getThumbnail() != null)
-               // onboardingApp.thumbnail = new
-               // String(Base64.getEncoder().encode(app.getThumbnail()));
+               onboardingApp.setModeOfIntegration(app.getModeOfIntegration());
+               onboardingApp.setAppAck(app.getAppAck());
+               onboardingApp.setUsesCadi(app.getUsesCadi());
+               onboardingApp.setApplicationType(app.getAppType().toString());
        }
 
        /**
@@ -1373,26 +1570,31 @@ public class EPAppCommonServiceImpl implements EPAppService {
         * @return The first argument.
         */
        protected EPApp createAppFromOnboarding(EPApp app, OnboardingApp onboardingApp, Session localSession) {
-               app.setName(onboardingApp.name);
-               app.setDescription(onboardingApp.description);
-               app.setNotes(onboardingApp.notes);
-               app.setUrl(onboardingApp.url);
-               app.setAlternateUrl(onboardingApp.alternateUrl);
-               app.setAppRestEndpoint(onboardingApp.restUrl);
-               app.setOpen(onboardingApp.isOpen);
-               app.setEnabled(onboardingApp.isEnabled);
-               app.setUsername(onboardingApp.username);
-               if(!onboardingApp.appPassword.equals(EPCommonSystemProperties.APP_DISPLAY_PASSWORD))
-               app.setAppPassword(this.encryptedPassword(onboardingApp.appPassword, app));
+               app.setName(onboardingApp.getAppName());
+               app.setAppDescription(onboardingApp.getAppDescription());
+               app.setAppNotes(onboardingApp.getAppNotes());
+               app.setLandingPage(onboardingApp.getLandingPage());
+               app.setAlternateLandingPage(onboardingApp.getAlternateLandingPage());
+               app.setAppRestEndpoint(onboardingApp.getRestUrl());
+               app.setOpen(onboardingApp.getIsOpen());
+               app.setEnabled(onboardingApp.getIsEnabled());
+               app.setAppBasicAuthUsername(onboardingApp.getAppBasicAuthUsername());
+               if(!onboardingApp.getAppBasicAuthPassword().equals(EPCommonSystemProperties.APP_DISPLAY_PASSWORD))
+               app.setAppBasicAuthPassword(this.encryptedPassword(onboardingApp.getAppBasicAuthPassword(), app));
                //app.setUebTopicName(onboardingApp.uebTopicName);
-               app.setUebKey(onboardingApp.uebKey);
-               app.setUebSecret(onboardingApp.uebSecret);
-               app.setCentralAuth(onboardingApp.isCentralAuth);
-               app.setNameSpace(onboardingApp.nameSpace);
-               app.setRestrictedApp(onboardingApp.restrictedApp);
-               if (!StringUtils.isEmpty(onboardingApp.thumbnail)) {
+               app.setUebKey(onboardingApp.getUebKey());
+               app.setUebSecret(onboardingApp.getUebSecret());
+               app.setRolesInAAF(onboardingApp.getRolesInAAF());
+               app.setNameSpace(onboardingApp.getNameSpace());
+               app.setAppType(new Integer(onboardingApp.getApplicationType()));                
+               app.setModeOfIntegration(onboardingApp.getModeOfIntegration());
+               app.setAppAck(onboardingApp.getAppAck());
+               app.setUsesCadi(onboardingApp.getUsesCadi());
+               
+               
+               if (!StringUtils.isEmpty(onboardingApp.getThumbnail())) {
                        logger.debug(EELFLoggerDelegate.debugLogger, "createAppFromOnboarding: onboarding thumbnail is NOT empty");
-                       String[] splitBase64Thumbnail = onboardingApp.thumbnail.split("base64,");
+                       String[] splitBase64Thumbnail = onboardingApp.getThumbnail().split("base64,");
                        logger.debug(EELFLoggerDelegate.debugLogger,
                                        "createAppFromOnboarding: length of splitBase64Thumbnail: " + splitBase64Thumbnail.length);
                        if (splitBase64Thumbnail.length > 1) {
@@ -1404,7 +1606,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
                                app.setImageUrl(constructImageName(onboardingApp));
                                app.setThumbnail(decodedImage);
                        }
-               } else if (app.getThumbnail() != null && onboardingApp.imageLink == null) {
+               } else if (app.getThumbnail() != null && onboardingApp.getImageLink() == null) {
                        // The thumbnail that came in from the json is empty; the previous
                        // thumbnail is NOT empty. Must delete it.
                        logger.debug(EELFLoggerDelegate.debugLogger,
@@ -1419,14 +1621,14 @@ public class EPAppCommonServiceImpl implements EPAppService {
        }
 
        protected String constructImageName(OnboardingApp onboardingApp) {
-               return "portal_" + String.valueOf(onboardingApp.url.hashCode() + "_" + (int) (Math.random() * 100000.0))
+               return "portal_" + String.valueOf(onboardingApp.getLandingPage().hashCode() + "_" + (int) (Math.random() * 100000.0))
                                + ".png";
        }
 
        // Don't encrypt or decrypt the password if it is null or the empty string
        private String decryptedPassword(String encryptedAppPwd, EPApp app) {
                String result = "";
-               if (encryptedAppPwd != null & encryptedAppPwd.length() > 0) {
+               if (encryptedAppPwd != null && !encryptedAppPwd.isEmpty()) {
                        try {
                                result = CipherUtil.decryptPKC(encryptedAppPwd,
                                                SystemProperties.getProperty(SystemProperties.Decryption_Key));
@@ -1439,7 +1641,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
 
        protected String encryptedPassword(String decryptedAppPwd, EPApp app) {
                String result = "";
-               if (decryptedAppPwd != null & decryptedAppPwd.length() > 0) {
+               if (decryptedAppPwd != null && !decryptedAppPwd.isEmpty()) {
                        try {
                                result = CipherUtil.encryptPKC(decryptedAppPwd,
                                                SystemProperties.getProperty(SystemProperties.Decryption_Key));
@@ -1732,4 +1934,60 @@ public class EPAppCommonServiceImpl implements EPAppService {
                return userAndRoles;
                
        }
-}
\ No newline at end of file
+
+       @SuppressWarnings("unused")
+       @Override
+       public ResponseEntity<String> checkIfNameSpaceIsValid(String namespace) throws Exception {
+               HttpHeaders headers = EcompPortalUtils.base64encodeKeyForAAFBasicAuth();
+               HttpEntity<String> entity = new HttpEntity<>(headers);
+               logger.debug(EELFLoggerDelegate.debugLogger, "checkIfNameSpaceExists: Connecting to External Auth system for : "+namespace);
+               ResponseEntity<String> response = null;
+               try {
+                       
+                       String namespaceUrl = SystemProperties.
+                                       getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL) + "nss/" + namespace;
+                       
+                       response = template.exchange(namespaceUrl, HttpMethod.GET, entity, String.class);
+                       logger.debug(EELFLoggerDelegate.debugLogger, "checkIfNameSpaceExists for"+ namespace ,
+                                       response.getStatusCode().value());
+                       if (response.getStatusCode().value() == 200) {
+                               String res = response.getBody();
+                               JSONObject jsonObj = new JSONObject(res);
+                               JSONArray namespaceArray = jsonObj.getJSONArray("ns");
+                               if(!namespaceArray.getJSONObject(0).has("admin")){
+                                       logger.error(EELFLoggerDelegate.errorLogger,
+                                                       "No admins are available for requested namespace:" + namespace);                
+                                       throw new HttpClientErrorException(HttpStatus.UNAUTHORIZED,
+                                                       "Portal Mechid is not an admin of" + namespace);
+                               }
+                               
+                               JSONArray namespaceAdminArray = namespaceArray.getJSONObject(0).getJSONArray("admin");
+                               ArrayList<String> list = new ArrayList<String>();
+                               if (namespaceAdminArray != null) {
+                                       int len = namespaceAdminArray.length();
+                                       for (int i = 0; i < len; i++) {
+                                               list.add(namespaceAdminArray.get(i).toString());
+                                       }
+                               }
+                               logger.debug(EELFLoggerDelegate.debugLogger, "List of Admins of requested namespace" + list);
+                               final String userName = SystemProperties
+                                               .getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_AUTH_USER_NAME);
+                               boolean idExists = list.stream().anyMatch(t -> userName.equals(t));
+                               if (false) {
+                                       logger.error(EELFLoggerDelegate.errorLogger,
+                                                       "Portal mechid is not admin of requested namespace:" + namespace);
+                                       throw new HttpClientErrorException(HttpStatus.UNAUTHORIZED,
+                                                       "Portal Mechid is not an admin of" + namespace);
+                               }
+                       }
+                       
+               } catch (HttpClientErrorException e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "checkIfNameSpaceExists failed", e);
+                       EPLogUtil.logExternalAuthAccessAlarm(logger, e.getStatusCode());
+                               throw e;
+               }
+               return response;
+
+       }
+}
+