/** * @author Bogdan Sliptsov * <p>This method is used to find all groups in DB by group-name or group-id. * @param searchValue String search value which can be group-name or group-id * @return Null 1. If searchValue reference is null; 2. If searchValue is empty; 3. If there are * no groups with such name or id. * @exception NumberFormatException On parsing searchValue to Long (searching by group id) */ public List<Group> getAllGroupsByNameOrID(String searchValue) { if (StringUtils.isEmpty(searchValue)) return null; List<Group> allGroups = getAllGroups(); List<Group> resultList = new ArrayList<>(); for (Group g : allGroups) { if (g.getName().equals(searchValue)) { resultList.add(g); continue; } try { Long id = Long.parseLong(searchValue); if (g.getId().equals(id)) { resultList.add(g); } } catch (NumberFormatException ex) { /*NOP*/ } } if (resultList.isEmpty()) return null; return resultList; }
/** * @author Bogdan Sliptsov * <p>This method is used to update group in DB. * @param group Group object to update. * @return 1. Null If group doesn't exist. 2. Group object of updated group. */ public Group updateGroup(Group group) { if (group == null) return null; if (groupDao.read(group.getId()) == null) return null; return groupDao.update(group); }