diff --git a/src/main/java/org/upsmf/grievance/controller/HelpdeskController.java b/src/main/java/org/upsmf/grievance/controller/HelpdeskController.java index fabb171cea728b338984633612dc309b8a65b6e6..1e4c3c12391b0988dd425f12ce84691b12692af1 100644 --- a/src/main/java/org/upsmf/grievance/controller/HelpdeskController.java +++ b/src/main/java/org/upsmf/grievance/controller/HelpdeskController.java @@ -89,7 +89,7 @@ public class HelpdeskController { if (MasterDataManager.getRoleMap().get(MasterDataManager.getUserRoleMap().get(userId)).getName() .equalsIgnoreCase(Sql.Common.SUPER_ADMIN) || MasterDataManager.getRoleMap().get(MasterDataManager.getUserRoleMap().get(userId)).getName() - .equalsIgnoreCase(Sql.Common.ORGADMIN)) { + .equalsIgnoreCase(Sql.Common.GRIEVANCE_ADMIN)) { return ResponseGenerator.successResponse(helpdesks); } else { return ResponseGenerator.successResponse(checkIfHelpdeskEmpty(user, helpdesks, newHelpdesks)); diff --git a/src/main/java/org/upsmf/grievance/controller/UserController.java b/src/main/java/org/upsmf/grievance/controller/UserController.java index 7529be751e95975e5222630456fb2c967e4eb9be..d88786b1de50fb552258485f4a5a9481f2a101f7 100644 --- a/src/main/java/org/upsmf/grievance/controller/UserController.java +++ b/src/main/java/org/upsmf/grievance/controller/UserController.java @@ -107,7 +107,7 @@ public class UserController { String name = MasterDataManager.getRoleMap().get(MasterDataManager.getUserRoleMap().get(user.getId())) .getName(); if (userId == 0 - && (name.equalsIgnoreCase(Sql.Common.SUPER_ADMIN) || name.equalsIgnoreCase(Sql.Common.ORGADMIN))) { + && (name.equalsIgnoreCase(Sql.Common.SUPER_ADMIN) || name.equalsIgnoreCase(Sql.Common.GRIEVANCE_ADMIN))) { User isAdded = userService.save(file, user.getId(), profile); if (isAdded != null) { MasterDataManager.getAllOrgUsers(); diff --git a/src/main/java/org/upsmf/grievance/dao/impl/ApplicationDaoImpl.java b/src/main/java/org/upsmf/grievance/dao/impl/ApplicationDaoImpl.java index 8639e275f09d7b68cd0961e8eec18bb9388fe38e..595577c8fc91450dd3663015a6199ee9184ae11c 100644 --- a/src/main/java/org/upsmf/grievance/dao/impl/ApplicationDaoImpl.java +++ b/src/main/java/org/upsmf/grievance/dao/impl/ApplicationDaoImpl.java @@ -69,9 +69,9 @@ public class ApplicationDaoImpl implements ApplicationDao { }, keyHolder); id = keyHolder.getKey().longValue(); app.setId(id); - Long orgAppId = jdbcTemplate.queryForObject(Sql.Apps.GET_ID_FROM_ORG_APP, - new Object[] { id, user.getOrgId() }, Long.class); - if (orgAppId < 1) { + Boolean isExists = jdbcTemplate.queryForObject(Sql.Apps.GET_ID_FROM_ORG_APP, + new Object[] { id, user.getOrgId() }, Boolean.class); + if (!isExists) { jdbcTemplate.update(Apps.MAP_APP_TO_ORG, new Object[] { id, user.getOrgId() }); } MasterDataManager.getAppObjectFromAppName(); @@ -195,9 +195,9 @@ public class ApplicationDaoImpl implements ApplicationDao { @Override public boolean mapAppsToHelpdesk(StatusIdMap statusIdMap) { try { - Long id = jdbcTemplate.queryForObject(Apps.GET_HELPDESK_ID, - new Object[] { statusIdMap.getHelpdeskId(), statusIdMap.getAppId() }, Long.class); - if (id == 0) { + Boolean isExists = jdbcTemplate.queryForObject(Apps.GET_HELPDESK_ID, + new Object[] { statusIdMap.getHelpdeskId(), statusIdMap.getAppId() }, Boolean.class); + if (!isExists) { LOGGER.info(QUERY_TO_EXECUTE + Apps.MAP_HELPDESK_APP); jdbcTemplate.update(Apps.MAP_HELPDESK_APP, new Object[] { statusIdMap.getHelpdeskId(), statusIdMap.getAppId() }); diff --git a/src/main/java/org/upsmf/grievance/dao/impl/RoleDaoImpl.java b/src/main/java/org/upsmf/grievance/dao/impl/RoleDaoImpl.java index 03b6583136edd1f6dacc43ebc60bbc6311faae41..44ec130be770d6fcc75eb5b4434958fb9b5d0867 100644 --- a/src/main/java/org/upsmf/grievance/dao/impl/RoleDaoImpl.java +++ b/src/main/java/org/upsmf/grievance/dao/impl/RoleDaoImpl.java @@ -157,11 +157,11 @@ public class RoleDaoImpl implements RoleDao { case Common.SUPER_ADMIN: actions = Constants.getSuperadminactions(); break; - case Common.ORGADMIN: - actions = Constants.getOrgadminactions(); + case Common.GRIEVANCE_ADMIN: + actions = Constants.getGrievanceAdminActions(); break; - case Common.ENDUSER: - actions = Constants.getEnduseractions(); + case Common.NODAL_OFFICER: + actions = Constants.getNodalOfficerActions(); break; default: actions = new ArrayList<>(); diff --git a/src/main/java/org/upsmf/grievance/dao/impl/SuperAdminDaoImpl.java b/src/main/java/org/upsmf/grievance/dao/impl/SuperAdminDaoImpl.java index 1f99fef57d83a4624d1c7bf62ceb8b5a012a4bc8..10cae994ad4f23268a1e2cc1e5089541e80b579a 100644 --- a/src/main/java/org/upsmf/grievance/dao/impl/SuperAdminDaoImpl.java +++ b/src/main/java/org/upsmf/grievance/dao/impl/SuperAdminDaoImpl.java @@ -65,7 +65,7 @@ public class SuperAdminDaoImpl implements SuperAdminDao { MasterDataManager.getUserOrgMap().get(userId); int orgId = getOrganizationByUserId(userId); Long roleId = jdbcTemplate.queryForObject(Sql.UserQueries.GET_ROLE_ID_BY_ORG, - new Object[] { orgId, Sql.Common.ORGADMIN }, Long.class); + new Object[] { orgId, Sql.Common.GRIEVANCE_ADMIN}, Long.class); Integer response = jdbcTemplate.update(Sql.UserQueries.ADD_ADMIN, new Object[] { roleId.intValue(), userId }); @@ -87,7 +87,7 @@ public class SuperAdminDaoImpl implements SuperAdminDao { int orgId = getOrganizationByUserId(userId); MasterDataManager.getUserOrgMap().get(userId); Long roleId = jdbcTemplate.queryForObject(Sql.UserQueries.GET_ROLE_ID_BY_ORG, - new Object[] { orgId, Sql.Common.ENDUSER }, Long.class); + new Object[] { orgId, Sql.Common.NODAL_OFFICER}, Long.class); Integer response = jdbcTemplate.update(Sql.UserQueries.DELETE_ADMIN, new Object[] { roleId.intValue(), userId }); if (response > 0) { @@ -157,7 +157,7 @@ public class SuperAdminDaoImpl implements SuperAdminDao { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { String[] returnValColumn = new String[] { "id" }; - PreparedStatement statement = connection.prepareStatement(Sql.Organization.NEW_ORG_ADMIN_USER, + PreparedStatement statement = connection.prepareStatement(Sql.Organization.NEW_GRIEVANCE_ADMIN_USER, returnValColumn); statement.setString(1, org.getAdminDetails().get(0).getName()); statement.setString(2, org.getAdminDetails().get(0).getUsername()); @@ -177,13 +177,13 @@ public class SuperAdminDaoImpl implements SuperAdminDao { return null; } - public void orgSetup(final Organization org, Long newOrgAdminUserId) { + public void orgSetup(final Organization org, Long newGrievanceAdminUserId) { Long id = org.getId(); if (id > 0) { LOGGER.info("Org Id: {}", id); } - if (newOrgAdminUserId > 0) { - LOGGER.info("User Id : {}", newOrgAdminUserId); + if (newGrievanceAdminUserId > 0) { + LOGGER.info("User Id : {}", newGrievanceAdminUserId); } String password = null; int adminRoleId = 0; @@ -197,27 +197,27 @@ public class SuperAdminDaoImpl implements SuperAdminDao { List<Integer> actions = new ArrayList<>(); Integer roleId = jdbcTemplate.queryForObject(Sql.Organization.GET_ROLE_ID_BY_ORG, new Object[] { id, String.valueOf(roleName) }, Integer.class); - if (String.valueOf(roleName).equals(Common.ORGADMIN)) { + if (String.valueOf(roleName).equals(Common.GRIEVANCE_ADMIN)) { adminRoleId = roleId; - actions = Constants.getOrgadminactions(); + actions = Constants.getGrievanceAdminActions(); } - if (String.valueOf(roleName).equals(Common.ENDUSER)) { - actions = Constants.getEnduseractions(); + if (String.valueOf(roleName).equals(Common.NODAL_OFFICER)) { + actions = Constants.getNodalOfficerActions(); } for (int i = 0; i < actions.size(); i++) { jdbcTemplate.update(Sql.Organization.ADD_ROLE_PERMISSION, new Object[] { roleId, actions.get(i) }); } } - jdbcTemplate.update(Sql.Organization.NEW_ORG_ADMIN_ROLE, new Object[] { newOrgAdminUserId, adminRoleId }); + jdbcTemplate.update(Sql.Organization.NEW_GRIEVANCE_ADMIN_ROLE, new Object[] { newGrievanceAdminUserId, adminRoleId }); MasterDataManager.getAllUserRoles(); - jdbcTemplate.update(Sql.Organization.FIRST_ADMIN_COMP, new Object[] { id, newOrgAdminUserId }); - MasterDataManager.getUserOrgMap().put(newOrgAdminUserId, id); + jdbcTemplate.update(Sql.Organization.FIRST_ADMIN_COMP, new Object[] { id, newGrievanceAdminUserId }); + MasterDataManager.getUserOrgMap().put(newGrievanceAdminUserId, id); password = ProjectUtil.getRandomStringVal().trim(); if (!StringUtils.isBlank(password)) { LOGGER.info("New Admin Password : {}", password); } String encodedPwd = OneWayHashing.encryptVal(password); - jdbcTemplate.update(Sql.Organization.NEW_ORG_ADMIN_PSWRD, new Object[] { encodedPwd, newOrgAdminUserId }); + jdbcTemplate.update(Sql.Organization.NEW_GRIEVANCE_ADMIN_PSWRD, new Object[] { encodedPwd, newGrievanceAdminUserId }); if (!StringUtils.isBlank(password)) { LOGGER.info("Password : {}", password); } @@ -373,7 +373,7 @@ public class SuperAdminDaoImpl implements SuperAdminDao { public Organization getOrganizationByIdV2(Long id) { try { OrgMapper orgMapper = new SqlDataMapper().new OrgMapper(); - jdbcTemplate.query(Sql.Organization.ORG_BY_ID, new Object[] { true, true, id, id, Sql.Common.ORGADMIN }, + jdbcTemplate.query(Sql.Organization.ORG_BY_ID, new Object[] { true, true, id, id, Sql.Common.GRIEVANCE_ADMIN}, orgMapper); String url = getOrgLogo(orgMapper.getOrg()); if (!url.isEmpty()) { diff --git a/src/main/java/org/upsmf/grievance/dao/impl/TicketDaoImpl.java b/src/main/java/org/upsmf/grievance/dao/impl/TicketDaoImpl.java index b030b395d1c9f487971424774d5a59f475ea8a50..8fc1a1574a47d13df7d4e73b41b063faf35af6bc 100644 --- a/src/main/java/org/upsmf/grievance/dao/impl/TicketDaoImpl.java +++ b/src/main/java/org/upsmf/grievance/dao/impl/TicketDaoImpl.java @@ -430,7 +430,6 @@ public class TicketDaoImpl implements TicketDao { jdbcTemplate.update(Sql.Ticket.ADD_TICKET_TO_HELPDESK, new Object[] { ticket.getId(), ticket.getSourceId(), ticket.getHelpdeskId(), ticket.getAppId() }); } - } @Override diff --git a/src/main/java/org/upsmf/grievance/model/mapper/SqlDataMapper.java b/src/main/java/org/upsmf/grievance/model/mapper/SqlDataMapper.java index d8e0ca009b01aacd581b1b4d65e0db2f3e353d6f..69a1eea5638b044b161619d5984066fb9653e78c 100644 --- a/src/main/java/org/upsmf/grievance/model/mapper/SqlDataMapper.java +++ b/src/main/java/org/upsmf/grievance/model/mapper/SqlDataMapper.java @@ -540,7 +540,7 @@ public class SqlDataMapper { @Override public Organization mapRow(ResultSet rs, int rowNum) throws SQLException { - User orgAdmin = new User(); + User grievanceAdmin = new User(); if (rowNum == 0) { getOrg().setId(rs.getLong(SqlConstants.DbAttributes.ID)); getOrg().setOrgName(rs.getString(SqlConstants.DbAttributes.ORGNAME)); @@ -554,11 +554,11 @@ public class SqlDataMapper { getOrg().setOrgDescription(rs.getString(SqlConstants.DbAttributes.DESCRIPTION)); } - orgAdmin.setId(rs.getLong(SqlConstants.DbAttributes.USERID)); - orgAdmin.setName(rs.getString(SqlConstants.DbAttributes.NAME)); - orgAdmin.setUsername(rs.getString(SqlConstants.DbAttributes.USERNAME)); - orgAdmin.setPhone(rs.getString(SqlConstants.DbAttributes.PHONE)); - adminList.add(orgAdmin); + grievanceAdmin.setId(rs.getLong(SqlConstants.DbAttributes.USERID)); + grievanceAdmin.setName(rs.getString(SqlConstants.DbAttributes.NAME)); + grievanceAdmin.setUsername(rs.getString(SqlConstants.DbAttributes.USERNAME)); + grievanceAdmin.setPhone(rs.getString(SqlConstants.DbAttributes.PHONE)); + adminList.add(grievanceAdmin); getOrg().setAdminDetails(adminList); return null; diff --git a/src/main/java/org/upsmf/grievance/util/Constants.java b/src/main/java/org/upsmf/grievance/util/Constants.java index 8a4b84b79469be3eee97c0e2b9d426cd72dc9ec2..1e96c82db378a10852cb1338455bbbaa29550afa 100644 --- a/src/main/java/org/upsmf/grievance/util/Constants.java +++ b/src/main/java/org/upsmf/grievance/util/Constants.java @@ -91,7 +91,7 @@ public class Constants { public static final String PROCESS_FAIL = "Process failed, Please try again."; public enum userRole { - SUPERADMIN, ORGADMIN, ENDUSER; + SUPERADMIN, GRIEVANCEADMIN, NODALOFFICER; } /** @@ -135,10 +135,10 @@ public class Constants { private static final List<Integer> superAdminActions = new ArrayList<>(Arrays.asList(1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61)); - private static final List<Integer> orgAdminActions = new ArrayList<>( + private static final List<Integer> grievanceAdminActions = new ArrayList<>( Arrays.asList(3, 4, 5, 6, 9, 11, 12, 15, 18, 23, 24, 25, 29, 30, 33, 34, 36, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61)); - private static final List<Integer> endUserActions = new ArrayList<>(Arrays.asList(11, 12, 23, 24, 29, 30, 33, 34, + private static final List<Integer> nodalOfficerActions = new ArrayList<>(Arrays.asList(11, 12, 23, 24, 29, 30, 33, 34, 36, 38, 39, 40, 41, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61)); private static Map<Integer, List<String>> actions = createMap(); @@ -211,12 +211,12 @@ public class Constants { return actions; } - public static List<Integer> getOrgadminactions() { - return orgAdminActions; + public static List<Integer> getGrievanceAdminActions() { + return grievanceAdminActions; } - public static List<Integer> getEnduseractions() { - return endUserActions; + public static List<Integer> getNodalOfficerActions() { + return nodalOfficerActions; } public static Map<Integer, List<String>> getActions() { diff --git a/src/main/java/org/upsmf/grievance/util/Sql.java b/src/main/java/org/upsmf/grievance/util/Sql.java index ef71237ea762961f833be94170a825334d19c719..134a47cefb15f203334ef7a9ae7060ca5bdb4466 100644 --- a/src/main/java/org/upsmf/grievance/util/Sql.java +++ b/src/main/java/org/upsmf/grievance/util/Sql.java @@ -25,23 +25,24 @@ public final class Sql { } - public static final String VERIFY_PSWRD = "SELECT id FROM user WHERE password = ? AND name = ? "; + public static final String VERIFY_PSWRD = "SELECT id FROM \"user\" WHERE password = ? AND name = ? "; public static final String WHERE_CLAUSE = " WHERE "; public static final String AND_CONDITION = " AND "; public static final String OR_CONDITION = " OR "; public static final String OPEN_BRACE = "("; public static final String CLOSE_BRACE = ")"; - public static final String CHECK_EMAIL_IN_USE = "SELECT id FROM user WHERE username=? AND is_active IS TRUE"; + public static final String CHECK_EMAIL_IN_USE = "SELECT id FROM \"user\" WHERE username=? AND is_active IS TRUE"; public static final String CHECK_OLD_PSWRD = "SELECT pwd FROM password WHERE user_id=?"; public static final String UPDATE_PSWRD = "UPDATE password SET pwd=?,updated_date=? WHERE user_id=? and pwd=?"; - public static final String CHECK_USER_BY_USERNAME = "SELECT id from user where username=?"; + public static final String CHECK_USER_BY_USERNAME = "SELECT id from \"user\" where username=?"; public static final String SAVE_FORGOT_PSWRD = "UPDATE password SET pwd=? , updated_date=? WHERE user_id= ? "; - public static final String GET_USER_DETAIL_BY_EMAIL = "Select id, name, username, phone, is_active as isActive, created_date as createdDate, updated_date as updatedDate, img_path as imagePath from user where username=?"; - public static final String GET_ORG_ID_BY_USER_ID = "SELECT org_id FROM user JOIN user_org where user.id=user_org.user_id and user.id=?"; - public static final String GET_ALL_USERS_BY_ORG = "Select user.id, name, username, phone, is_active, img_path, created_date, updated_date from user JOIN user_org where user.id=user_org.user_id and user.is_active is true and user_org.org_id=?"; - public static final String GET_IMAGE_PATH = "SELECT img_path from user where id=?;"; - public static final String ORGADMIN = "ORGADMIN"; - public static final String ENDUSER = "ENDUSER"; + public static final String GET_USER_DETAIL_BY_EMAIL = "Select id, name, username, phone, is_active as isActive, created_date as createdDate, updated_date as updatedDate, img_path as imagePath from \"user\" where username=?"; + public static final String GET_ORG_ID_BY_USER_ID = "SELECT org_id FROM \"user\",user_org where \"user\".id=user_org.user_id and \"user\".id=?"; + public static final String GET_ALL_USERS_BY_ORG = "Select \"user\".id, name, username, phone, is_active, img_path, created_date, updated_date from \"user\",user_org where \"user\".id=user_org.user_id \n" + + "and \"user\".is_active is true and user_org.org_id=?"; + public static final String GET_IMAGE_PATH = "SELECT img_path from \"user\" where id=?;"; + public static final String GRIEVANCE_ADMIN = "GRIEVANCEADMIN"; + public static final String NODAL_OFFICER = "NODALOFFICER"; public static final String SUPER_ADMIN = "SUPERADMIN"; } @@ -74,31 +75,31 @@ public final class Sql { public static final String GET_ALL_ORG = "SELECT id, org_name as orgName, url as url, logo as logo, domain as emailDomain, color as orgColor, " + " created_by as createdBy, created_date as createdDate, is_active as isActive, description as orgDescription FROM organization where is_active is TRUE"; - public static final String GET_ORG_BY_NAME = "SELECT id FROM organization where org_name=? and is_active=1"; + public static final String GET_ORG_BY_NAME = "SELECT id FROM organization where org_name=? and is_active is true"; public static final String GET_ORG_BY_ID = "select id, org_name as orgName, url as url, logo as logo, domain as emailDomain, color as orgColor, created_by as createdBy, created_date as createdDate, is_active as isActive, description as orgDescription FROM organization where id = ? and is_active is true"; public static final String AND_CONDITION = " AND "; public static final String OR_CONDITION = " OR "; public static final String OPEN_BRACE = "("; public static final String CLOSE_BRACE = ")"; public static final String ADD_NEW_ORG = "INSERT INTO organization (org_name, url, logo, created_by, updated_by, description, color, domain) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; - public static final String NEW_ORG_ADMIN_USER = "INSERT INTO user (name, username, phone, img_path) VALUES (?,?,?,?)"; + public static final String NEW_GRIEVANCE_ADMIN_USER = "INSERT INTO user (name, username, phone, img_path) VALUES (?,?,?,?)"; public static final String DELETE_ORG = "UPDATE organization SET is_active = FALSE , updated_by = ? , updated_date = ? WHERE id = ?"; - public static final String GET_ADMIN_BY_ORG = "SELECT DISTINCT a.id,a.name,a.username,a.phone FROM user a,organization b,roles c, user_org d, user_role e " + public static final String GET_ADMIN_BY_ORG = "SELECT DISTINCT a.id,a.name,a.username,a.phone FROM \"user\" a,organization b,roles c, user_org d, user_role e " + "WHERE a.id = d.user_id AND a.id = e.user_id " + "AND c.id = ? AND b.id = ? AND a.is_active IS TRUE"; public static final String GET_ROLE_ID_BY_ORG = "SELECT id FROM roles where org_id = ? and role_name = ?"; public static final String ADD_ORG_ROLES = "insert into roles(role_name, org_id) values (?,?)"; public static final String ADD_ROLE_PERMISSION = "insert into role_action(role_id, action_id) values (?,?)"; - public static final String NEW_ORG_ADMIN_ROLE = "INSERT INTO user_role(user_id,role_id) VALUES (?,?)"; - public static final String NEW_ORG_ADMIN_PSWRD = "INSERT INTO password (pwd, user_id) VALUES (?,?)"; + public static final String NEW_GRIEVANCE_ADMIN_ROLE = "INSERT INTO user_role(user_id,role_id) VALUES (?,?)"; + public static final String NEW_GRIEVANCE_ADMIN_PSWRD = "INSERT INTO password (pwd, user_id) VALUES (?,?)"; public static final String FIRST_ADMIN_COMP = "INSERT INTO user_org (org_id,user_id) VALUES (?,?)"; public static final String UPDATE_ORG = "UPDATE organization SET org_name = ?,logo = ?,updated_date = ?,updated_by = ?,url = ?,description = ?,color = ?, domain = ? WHERE id = ?"; - public static final String GET_ORG_BY_USERID = "select user_org.org_id as id, logo from user, user_org, organization where user.id=user_org.user_id and user_org.org_id=organization.id and user.id= ?"; + public static final String GET_ORG_BY_USERID = "select user_org.org_id as id, logo from \"user\", user_org, organization where \"user\".id=user_org.user_id and user_org.org_id=organization.id and \"user\".id= ?"; public static final String CHECK_IF_ROLE_EXISTS = "select exists(select id from roles where role_name = ? and org_id = ?)"; public static final String CHECK_IF_ACTION_EXISTS = "SELECT exists(select id from action where id=?);"; public static final String GET_ROLE_ID_FROM_ORG = "select id from roles where role_name = ? and org_id = ?"; public static final String DELETE_ACTION = "delete from role_action where role_id=?"; - public static final String ORG_BY_ID = "select organization.id as id, organization.org_name as orgName, organization.url, organization.logo, organization.domain as domain, organization.color as color,organization.created_by as createdBy, organization.created_date as createdDate, organization.is_active as isActive, organization.description as description, user.id as userId, user.name, user.username, user.phone from organization, roles, user, user_org, user_role where user.id = user_org.user_id and user.id = user_role.user_id and user_org.org_id = organization.id and organization.id = roles.org_id and organization.is_active = ? and user.is_active = ? and organization.id = ? and roles.id = (select id from roles where org_id = ? and role_name = ?)"; + public static final String ORG_BY_ID = "select organization.id as id, organization.org_name as orgName, organization.url, organization.logo, organization.domain as domain, organization.color as color,organization.created_by as createdBy, organization.created_date as createdDate, organization.is_active as isActive, organization.description as description, \"user\".id as userId, \"user\".name, \"user\".username, \"user\".phone from organization, roles, user, user_org, user_role where \"user\".id = user_org.user_id and \"user\".id = user_role.user_id and user_org.org_id = organization.id and organization.id = roles.org_id and organization.is_active = ? and \"user\".is_active = ? and organization.id = ? and roles.id = (select id from roles where org_id = ? and role_name = ?)"; } public final class Helpdesk { @@ -135,15 +136,15 @@ public final class Sql { public static final String GET_WORKFLOW_FOR_TICKET_LIST = "SELECT t.id, ticket_id as ticketId, workflow_id as workFlowId, name, time, status FROM ticket_workflow t, workflow_stage w where w.id=t.workflow_id and ticket_id IN "; public static final String GET_HELPDESK_BY_USER_ID = "SELECT hlpdsk.id as id, hlpdsk.helpdesk_name as name, hlpdsk.is_active as isActive, hlpdsk.color as color from helpdesk hlpdsk where id IN (SELECT distinct id FROM helpdesk AS h LEFT JOIN helpdesk_admin AS ha ON h.id=ha.helpdesk_id LEFT JOIN helpdesk_users AS hu ON h.id = hu.helpdesk_id where is_active is true and (ha.user_id=? or hu.user_id=?)) or allow_all_users is true and is_active is true and org_id=?"; - public static final String GET_HELPDESK_USER_BY_ID = " SELECT id as id, name as name, username as userName, img_path from user where id IN (select user_id from helpdesk_users where helpdesk_id = ? ) "; + public static final String GET_HELPDESK_USER_BY_ID = " SELECT id as id, name as name, username as userName, img_path from \"user\" where id IN (select user_id from helpdesk_users where helpdesk_id = ? ) "; public static final String DELETE_CHECKLIST_FOR_TICKET = "DELETE from ticket_checklist WHERE ticket_id = ?"; - public static final String GET_HELPDESK_ADMIN_BY_ID = " SELECT id as id, name as name, username as userName, img_path from user where id IN (select user_id from helpdesk_admin where helpdesk_id = ? ) "; + public static final String GET_HELPDESK_ADMIN_BY_ID = " SELECT id as id, name as name, username as userName, img_path from \"user\" where id IN (select user_id from helpdesk_admin where helpdesk_id = ? ) "; public static final String GET_APP_ORG_ID = "SELECT org_id FROM organization_app where app_id=?;"; - public static final String GET_USER_DETAILS_FOR_HELPDESK = "SELECT user_id as id, name as name, username as userName, img_path from user, user_org where is_active is true and user.id=user_org.user_id and org_id=?"; + public static final String GET_USER_DETAILS_FOR_HELPDESK = "SELECT user_id as id, name as name, username as userName, img_path from \"user\", user_org where is_active is true and \"user\".id=user_org.user_id and org_id=?"; - public static final String GET_HELPDESK_ADMIN_USER = "select distinct user.id, name as name, username, img_path as imagePath" - + " from user, helpdesk_admin " + "where user.id = helpdesk_admin.user_id" - + " and helpdesk_admin.helpdesk_id = ? and user.is_active = true"; + public static final String GET_HELPDESK_ADMIN_USER = "select distinct \"user\".id, name as name, username, img_path as imagePath" + + " from \"user\", helpdesk_admin " + "where \"user\".id = helpdesk_admin.user_id" + + " and helpdesk_admin.helpdesk_id = ? and \"user\".is_active = true"; public static final String UPDATE_HELPDESK_CHANNELS = "update helpdesk set direct = ?, playstore = ?, appstore = ?, aurora_sdk = ? where id = ? and org_id = ?"; } @@ -190,8 +191,8 @@ public final class Sql { public static final String GET_HELPDESK_ID = "select exists(select id from helpdesk_app where helpdesk_id=? and app_id = ?)"; public static final String GET_APP_ID_APP_KEY = "select id FROM application where url = ? and is_active is true;"; public static final String CHECK_IF_APP_NAME_EXISTS = "select exists(select id FROM application where url = ? and is_active is true);"; - public static final String CHECK_IF_TICKET_EXIST = "select exists(select id from ticket where description = ? and active is true and requested_by in (select id from user where username=? and is_active is true) LIMIT 1);"; - public static final String CHECK_IF_TICKET_EXISTS = "select exists(select id from ticket where reviewId = ? and active is true and requested_by in (select id from user where username=? and is_active is true) LIMIT 1);"; + public static final String CHECK_IF_TICKET_EXIST = "select exists(select id from ticket where description = ? and active is true and requested_by in (select id from \"user\" where username=? and is_active is true) LIMIT 1);"; + public static final String CHECK_IF_TICKET_EXISTS = "select exists(select id from ticket where reviewId = ? and active is true and requested_by in (select id from \"user\" where username=? and is_active is true) LIMIT 1);"; public static final String GET_APP_ID_FROM_APP_KEY = "select id FROM application where app_key = ? and is_active is true;"; public static final String CHECK_IF_UPDATE_EXISTS = "select exists(select id from ticket_updates where updates = ? and active is true and created_date=? limit 1);"; @@ -209,13 +210,16 @@ public final class Sql { } public static final String SELECT_USER_BY_TOKEN = "SELECT \"user\".id as id FROM \"user\",\"user_authentication\" WHERE auth_token = ? and \"user\".is_active is true and \"user\".id=user_authentication.user_id;"; - public static final String SELECT_USER_ON_USERNAME = "SELECT user.id as id, user.name as name, user.username as username, user_org.org_id as orgId, " - + " user.is_active as isActive, pwd.pwd as password from user, user_org, password pwd where " - + " user.id = user_org.user_id and pwd.user_id = user.id and username = ?"; + public static final String SELECT_USER_ON_USERNAME = "SELECT \"user\".id AS id, \"user\".name AS name, \"user\".username AS username, user_org.org_id AS orgId,\n" + + "\"user\".is_active AS isActive, pwd.pwd AS password\n" + + "FROM \"user\"\n" + + "JOIN user_org ON \"user\".id = user_org.user_id\n" + + "JOIN password pwd ON pwd.user_id = \"user\".id\n" + + "WHERE \"user\".username = ?"; public static final String SELECT_USER_ROLES_ON_USERNAME = "SELECT usr.id as id, usr.name as name, usr.username as username, usr.is_active as isActive, " + " usrorg.org_id as orgId, " + " pwd.pwd as password, " + " role.role_name as roleName, role.id as roleId, role.org_id as roleOrgId " - + " from user usr LEFT JOIN user_org usrorg ON usr.id = usrorg.user_id " + + " from \"user\" usr LEFT JOIN user_org usrorg ON usr.id = usrorg.user_id " + " LEFT JOIN password pwd ON pwd.user_id = usr.id " + " LEFT JOIN user_role usrrole ON usr.id = usrrole.user_id " + " LEFT JOIN roles role ON usrrole.role_id = role.id " + Common.WHERE_CLAUSE @@ -225,7 +229,7 @@ public final class Sql { + " role.role_name as roleName, role.id as roleId, role.org_id as roleOrgId, " + " actn.id as actionId, actn.name as actionName, actn.display_name as actionDisplayName, actn.query_params as actionQueryParams, " + " actn.service_code as actionServiceCode, actn.url as actionUrl " - + " from user usr LEFT JOIN user_org usrorg ON usr.id = usrorg.user_id " + + " from \"user\" usr LEFT JOIN user_org usrorg ON usr.id = usrorg.user_id " + " LEFT JOIN password pwd ON pwd.user_id = usr.id " + " LEFT JOIN user_role usrrole ON usr.id = usrrole.user_id " + " LEFT JOIN roles role ON usrrole.role_id = role.id " @@ -235,15 +239,15 @@ public final class Sql { public static final String MAP_USER_TO_ROLE = "INSERT INTO user_role (user_id, role_id) VALUES (?, ?)"; public static final String REMOVE_USER_ROLE_MAP = "DELETE FROM user_role WHERE user_id = ? "; - public static final String UPDATE_USER_PROFILE_PROFILE_IMAGE = "UPDATE user SET img_path = ? WHERE id = ?"; + public static final String UPDATE_USER_PROFILE_PROFILE_IMAGE = "UPDATE \"user\" SET img_path = ? WHERE id = ?"; public static final String GET_USER_ACTIONS = "Select action.id, action.display_name as displayName, name, url from action inner join role_action on role_action.action_id = action.id where role_action.role_id = ?"; - public static final String USER_PROFILE_FETCH = "select * from user usr where id=? "; - public static final String USER_DATA = "select COUNT(*) from user where username=?"; - public static final String USER = "select * from user where id=?"; + public static final String USER_PROFILE_FETCH = "select * from \"user\" usr where id=? "; + public static final String USER_DATA = "select COUNT(*) from \"user\" where username=?"; + public static final String USER = "select * from \"user\" where id=?"; public static final String GET_USER_AUTH_DETAILS = "SELECT id, user_id as userId, auth_token FROM user_authentication WHERE id=?"; - public static final String SAVE_USER = "INSERT INTO user(name,username,phone,img_path) VALUES (?,?,?,?)"; - public static final String SAVE_ANONYMOUS_USER = "INSERT INTO user(name,username,phone,img_path,is_anonymous) VALUES (?,?,?,?,?)"; + public static final String SAVE_USER = "INSERT INTO \"user\"(name,username,phone,img_path) VALUES (?,?,?,?)"; + public static final String SAVE_ANONYMOUS_USER = "INSERT INTO \"user\"(name,username,phone,img_path,is_anonymous) VALUES (?,?,?,?,?)"; public static final String SAVE_USER_AUTHENTICATION = "INSERT INTO user_authentication(user_id,auth_token) VALUES (?,?)"; public static final String GET_USER_ROLE = "SELECT user_id, role_id FROM retail_user_role WHERE user_id=?"; public static final String GET_ROLES_FOR_USER = "select ur.role_id as roleId, r.role_name as roleName from roles r, user_role ur where r.id = ur.role_id and ur.user_id = ?"; @@ -253,9 +257,9 @@ public final class Sql { public static final String OR_CONDITION = " OR "; public static final String UPDATE_USER = "UPDATE user SET name = ?,username = ?, phone = ?, is_active = ?, img_path = ? where id = ? "; - public static final String GET_USER_COUNT = "SELECT count(*) FROM user usr"; - public static final String GET_USER_COUNT_ON_ACTIVE_STATUS = "SELECT count(*) FROM user usr where usr.is_active = ? "; - public static final String GET_USER_COUNT_FOR_ROLE = "SELECT count(*) FROM user usr LEFT JOIN user_role ur ON usr.id = ur.user_id where ur.role_id = ? and usr.is_active IS TRUE"; + public static final String GET_USER_COUNT = "SELECT count(*) FROM \"user\" usr"; + public static final String GET_USER_COUNT_ON_ACTIVE_STATUS = "SELECT count(*) FROM \"user\" usr where usr.is_active = ? "; + public static final String GET_USER_COUNT_FOR_ROLE = "SELECT count(*) FROM \"user\" usr LEFT JOIN user_role ur ON usr.id = ur.user_id where ur.role_id = ? and usr.is_active IS TRUE"; public static final String GET_ROLE_COUNT = "SELECT count(*) FROM roles"; public static final String INVALIDATE_TOKEN = "DELETE from user_authentication WHERE auth_token = ? "; @@ -383,9 +387,9 @@ public final class Sql { public static final String UPDATE_USER = "UPDATE user SET name = ?, username = ? , is_active = ? where id = ? "; public static final String UPDATE_USER_PROFILE = "UPDATE user_profile SET name = ?, email = ?, phone_number = ?," + " updated_by = ? WHERE user_id = ? "; - public static final String GET_USER_COUNT = "SELECT count(*) FROM user usr"; - public static final String GET_USER_COUNT_ON_ACTIVE_STATUS = "SELECT count(*) FROM user usr where usr.is_active = ? "; - public static final String GET_USER_COUNT_FOR_ROLE = "SELECT count(*) FROM user usr LEFT JOIN retail_user_role usrrole ON usr.id = usrrole.user_id where usrrole.role_id = ? " + public static final String GET_USER_COUNT = "SELECT count(*) FROM \"user\" usr"; + public static final String GET_USER_COUNT_ON_ACTIVE_STATUS = "SELECT count(*) FROM \"user\" usr where usr.is_active = ? "; + public static final String GET_USER_COUNT_FOR_ROLE = "SELECT count(*) FROM \"user\" usr LEFT JOIN retail_user_role usrrole ON usr.id = usrrole.user_id where usrrole.role_id = ? " + "and usr.is_active IS TRUE"; public static final String GET_ROLE_COUNT = "SELECT count(*) FROM retail_role"; @@ -394,8 +398,8 @@ public final class Sql { public static final String CHECK_USER_DEVICE_TOKEN = "SELECT COUNT(*) FROM user_device WHERE user_id = ? AND device_token = ? "; public static final String GET_S3_ACCESS = "SELECT access_key as accessKey,secret_key as secretKey,bucket_name as bucketName FROM s3_config WHERE id = 1"; public static final String GET_CONFIG = "SELECT client_id as clientId,client_secret as clientSecret,refresh_token as refreshToken FROM review_config where org_id=?;"; - public static final String INSERT_PROFILE_PICTURE = "UPDATE user set img_path=? WHERE id=?"; - public static final String GET_DP = "SELECT img_path FROM user WHERE id=?"; + public static final String INSERT_PROFILE_PICTURE = "UPDATE \"user\" set img_path=? WHERE id=?"; + public static final String GET_DP = "SELECT img_path FROM \"user\" WHERE id=?"; public static final String ADD_ATTACHMENT_TO_TICKET = "insert into ticket_attachment(ticket_id, attachment_id) values (?,?);"; public static final String INSERT_ATTACHMENT = "insert into attachment_url(url) values (?);"; } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a10bd9f7684b2179e7540d2bfcb928bfef0596b3..480ffde6f8153626d70fda41f65bff22744c3fe3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,9 +5,9 @@ spring.main.allow-bean-definition-overriding=true spring.http.multipart.max-file-size=10MB spring.http.multipart.max-request-size=10MB -spring.datasource.url=jdbc:postgresql://localhost:5432/postgres -spring.datasource.username=postgres -spring.datasource.password=mysecretpassword +spring.datasource.url=jdbc:postgresql://localhost:5432/aurora_desk?currentSchema=aurora +spring.datasource.username=juhi +spring.datasource.password=juhiagl8 spring.datasource.driver-class-name=org.postgresql.Driver spring.jpa.hibernate.ddl-auto=none spring.datasource.initialization-mode=always