@Test @Sql(scripts = { "/sql/clearRole.sql", "/sql/clearAction.sql", "/sql/insertRoleData.sql", "/sql/insertActionData.sql" }) public void testAddUniqueValidationForTenantAndRoleAndAction() { RoleActionsRequest roleActionRequest = new RoleActionsRequest(); Role role = Role.builder().code("PGR").build(); Action action1 = Action.builder().name("Get all ReceivingMode").build(); Action action2 = Action.builder().name("Get all CompaintTypeCategory").build(); List<Action> list = new ArrayList<Action>(); list.add(action1); list.add(action2); roleActionRequest.setActions(list); roleActionRequest.setRole(role); boolean exist = roleActionRepository.addUniqueValidationForTenantAndRoleAndAction(roleActionRequest); assertThat(exist == true); }
public boolean addUniqueValidationForTenantAndRoleAndAction(final RoleActionsRequest actionRequest) { List<Integer> actionList = getActionsBasedOnIds(actionRequest); if (actionList.size() > 0) { final Map<String, Object> parametersMap = new HashMap<String, Object>(); parametersMap.put("rolecode", actionRequest.getRole().getCode()); parametersMap.put("tenantid", actionRequest.getTenantId()); parametersMap.put("actionid", actionList); SqlRowSet sqlrowset = namedParameterJdbcTemplate.queryForRowSet(CHECK_UNIQUE_VALIDATION_FOR_ROLEACTIONS, parametersMap); if (sqlrowset != null && sqlrowset.next()) { String rolecode = sqlrowset.getString("rolecode"); if (rolecode != null && rolecode != "") { return false; } } } return true; }
RoleActionRepository { public boolean addUniqueValidationForTenantAndRoleAndAction(final RoleActionsRequest actionRequest) { List<Integer> actionList = getActionsBasedOnIds(actionRequest); if (actionList.size() > 0) { final Map<String, Object> parametersMap = new HashMap<String, Object>(); parametersMap.put("rolecode", actionRequest.getRole().getCode()); parametersMap.put("tenantid", actionRequest.getTenantId()); parametersMap.put("actionid", actionList); SqlRowSet sqlrowset = namedParameterJdbcTemplate.queryForRowSet(CHECK_UNIQUE_VALIDATION_FOR_ROLEACTIONS, parametersMap); if (sqlrowset != null && sqlrowset.next()) { String rolecode = sqlrowset.getString("rolecode"); if (rolecode != null && rolecode != "") { return false; } } } return true; } }
RoleActionRepository { public boolean addUniqueValidationForTenantAndRoleAndAction(final RoleActionsRequest actionRequest) { List<Integer> actionList = getActionsBasedOnIds(actionRequest); if (actionList.size() > 0) { final Map<String, Object> parametersMap = new HashMap<String, Object>(); parametersMap.put("rolecode", actionRequest.getRole().getCode()); parametersMap.put("tenantid", actionRequest.getTenantId()); parametersMap.put("actionid", actionList); SqlRowSet sqlrowset = namedParameterJdbcTemplate.queryForRowSet(CHECK_UNIQUE_VALIDATION_FOR_ROLEACTIONS, parametersMap); if (sqlrowset != null && sqlrowset.next()) { String rolecode = sqlrowset.getString("rolecode"); if (rolecode != null && rolecode != "") { return false; } } } return true; }  }
RoleActionRepository { public boolean addUniqueValidationForTenantAndRoleAndAction(final RoleActionsRequest actionRequest) { List<Integer> actionList = getActionsBasedOnIds(actionRequest); if (actionList.size() > 0) { final Map<String, Object> parametersMap = new HashMap<String, Object>(); parametersMap.put("rolecode", actionRequest.getRole().getCode()); parametersMap.put("tenantid", actionRequest.getTenantId()); parametersMap.put("actionid", actionList); SqlRowSet sqlrowset = namedParameterJdbcTemplate.queryForRowSet(CHECK_UNIQUE_VALIDATION_FOR_ROLEACTIONS, parametersMap); if (sqlrowset != null && sqlrowset.next()) { String rolecode = sqlrowset.getString("rolecode"); if (rolecode != null && rolecode != "") { return false; } } } return true; }  List<RoleAction> createRoleActions(final RoleActionsRequest actionRequest); boolean checkActionNamesAreExistOrNot(final RoleActionsRequest actionRequest); boolean addUniqueValidationForTenantAndRoleAndAction(final RoleActionsRequest actionRequest); }
RoleActionRepository { public boolean addUniqueValidationForTenantAndRoleAndAction(final RoleActionsRequest actionRequest) { List<Integer> actionList = getActionsBasedOnIds(actionRequest); if (actionList.size() > 0) { final Map<String, Object> parametersMap = new HashMap<String, Object>(); parametersMap.put("rolecode", actionRequest.getRole().getCode()); parametersMap.put("tenantid", actionRequest.getTenantId()); parametersMap.put("actionid", actionList); SqlRowSet sqlrowset = namedParameterJdbcTemplate.queryForRowSet(CHECK_UNIQUE_VALIDATION_FOR_ROLEACTIONS, parametersMap); if (sqlrowset != null && sqlrowset.next()) { String rolecode = sqlrowset.getString("rolecode"); if (rolecode != null && rolecode != "") { return false; } } } return true; }  List<RoleAction> createRoleActions(final RoleActionsRequest actionRequest); boolean checkActionNamesAreExistOrNot(final RoleActionsRequest actionRequest); boolean addUniqueValidationForTenantAndRoleAndAction(final RoleActionsRequest actionRequest); static final Logger LOGGER; }