@Test @Sql(scripts = { "/sql/clearRole.sql", "/sql/clearAction.sql", "/sql/insertRoleData.sql", "/sql/insertActionData.sql" }) public void testCheckActionNamesAreNotExist() { RoleActionsRequest roleActionRequest = new RoleActionsRequest(); Action action1 = Action.builder().name("testActionOne").build(); Action action2 = Action.builder().name("testActionTWo").build(); List<Action> list = new ArrayList<Action>(); list.add(action1); list.add(action2); roleActionRequest.setActions(list); boolean exist = roleActionRepository.checkActionNamesAreExistOrNot(roleActionRequest); assertThat(exist == false); }
public boolean checkActionNamesAreExistOrNot(final RoleActionsRequest actionRequest) { LOGGER.info("checkActionNamesAreExistOrNot::" + actionRequest); if (actionRequest.getActions().size() > 0) { List<String> sqlStringifiedCodes = new ArrayList<>(); for (Action actionName : actionRequest.getActions()) sqlStringifiedCodes.add(actionName.getName()); final Map<String, Object> parametersMap = new HashMap<String, Object>(); parametersMap.put("sqlStringifiedCodes", sqlStringifiedCodes); final String getActionIdsBasedOnName = "select id from eg_action where name IN (:sqlStringifiedCodes)"; SqlRowSet sqlrowset = namedParameterJdbcTemplate.queryForRowSet(getActionIdsBasedOnName, parametersMap); List<Integer> actionList = new ArrayList<Integer>(); while (sqlrowset.next()) { actionList.add(sqlrowset.getInt("id")); } if (actionList.size() == actionRequest.getActions().size()) { return true; } } return false; }
RoleActionRepository { public boolean checkActionNamesAreExistOrNot(final RoleActionsRequest actionRequest) { LOGGER.info("checkActionNamesAreExistOrNot::" + actionRequest); if (actionRequest.getActions().size() > 0) { List<String> sqlStringifiedCodes = new ArrayList<>(); for (Action actionName : actionRequest.getActions()) sqlStringifiedCodes.add(actionName.getName()); final Map<String, Object> parametersMap = new HashMap<String, Object>(); parametersMap.put("sqlStringifiedCodes", sqlStringifiedCodes); final String getActionIdsBasedOnName = "select id from eg_action where name IN (:sqlStringifiedCodes)"; SqlRowSet sqlrowset = namedParameterJdbcTemplate.queryForRowSet(getActionIdsBasedOnName, parametersMap); List<Integer> actionList = new ArrayList<Integer>(); while (sqlrowset.next()) { actionList.add(sqlrowset.getInt("id")); } if (actionList.size() == actionRequest.getActions().size()) { return true; } } return false; } }
RoleActionRepository { public boolean checkActionNamesAreExistOrNot(final RoleActionsRequest actionRequest) { LOGGER.info("checkActionNamesAreExistOrNot::" + actionRequest); if (actionRequest.getActions().size() > 0) { List<String> sqlStringifiedCodes = new ArrayList<>(); for (Action actionName : actionRequest.getActions()) sqlStringifiedCodes.add(actionName.getName()); final Map<String, Object> parametersMap = new HashMap<String, Object>(); parametersMap.put("sqlStringifiedCodes", sqlStringifiedCodes); final String getActionIdsBasedOnName = "select id from eg_action where name IN (:sqlStringifiedCodes)"; SqlRowSet sqlrowset = namedParameterJdbcTemplate.queryForRowSet(getActionIdsBasedOnName, parametersMap); List<Integer> actionList = new ArrayList<Integer>(); while (sqlrowset.next()) { actionList.add(sqlrowset.getInt("id")); } if (actionList.size() == actionRequest.getActions().size()) { return true; } } return false; }  }
RoleActionRepository { public boolean checkActionNamesAreExistOrNot(final RoleActionsRequest actionRequest) { LOGGER.info("checkActionNamesAreExistOrNot::" + actionRequest); if (actionRequest.getActions().size() > 0) { List<String> sqlStringifiedCodes = new ArrayList<>(); for (Action actionName : actionRequest.getActions()) sqlStringifiedCodes.add(actionName.getName()); final Map<String, Object> parametersMap = new HashMap<String, Object>(); parametersMap.put("sqlStringifiedCodes", sqlStringifiedCodes); final String getActionIdsBasedOnName = "select id from eg_action where name IN (:sqlStringifiedCodes)"; SqlRowSet sqlrowset = namedParameterJdbcTemplate.queryForRowSet(getActionIdsBasedOnName, parametersMap); List<Integer> actionList = new ArrayList<Integer>(); while (sqlrowset.next()) { actionList.add(sqlrowset.getInt("id")); } if (actionList.size() == actionRequest.getActions().size()) { return true; } } return false; }  List<RoleAction> createRoleActions(final RoleActionsRequest actionRequest); boolean checkActionNamesAreExistOrNot(final RoleActionsRequest actionRequest); boolean addUniqueValidationForTenantAndRoleAndAction(final RoleActionsRequest actionRequest); }
RoleActionRepository { public boolean checkActionNamesAreExistOrNot(final RoleActionsRequest actionRequest) { LOGGER.info("checkActionNamesAreExistOrNot::" + actionRequest); if (actionRequest.getActions().size() > 0) { List<String> sqlStringifiedCodes = new ArrayList<>(); for (Action actionName : actionRequest.getActions()) sqlStringifiedCodes.add(actionName.getName()); final Map<String, Object> parametersMap = new HashMap<String, Object>(); parametersMap.put("sqlStringifiedCodes", sqlStringifiedCodes); final String getActionIdsBasedOnName = "select id from eg_action where name IN (:sqlStringifiedCodes)"; SqlRowSet sqlrowset = namedParameterJdbcTemplate.queryForRowSet(getActionIdsBasedOnName, parametersMap); List<Integer> actionList = new ArrayList<Integer>(); while (sqlrowset.next()) { actionList.add(sqlrowset.getInt("id")); } if (actionList.size() == actionRequest.getActions().size()) { return true; } } return false; }  List<RoleAction> createRoleActions(final RoleActionsRequest actionRequest); boolean checkActionNamesAreExistOrNot(final RoleActionsRequest actionRequest); boolean addUniqueValidationForTenantAndRoleAndAction(final RoleActionsRequest actionRequest); static final Logger LOGGER; }