/**
  * @author Bogdan Sliptsov
  *     <p>Returns true if group is open. False if group is closed. //TODO moderate
  */
 public boolean groupIsOpen(Long groupId) {
   if (groupId == null) return false;
   Group group = groupDao.read(groupId);
   if (group == null) return false;
   if (group.getType().equals(new Byte(String.valueOf(1)))) return false;
   return true;
 }
 /**
  * @author Bogdan Sliptsov
  *     <p>This method returns true if user is a group-creator and has rights to modify group and
  *     returns false if user doesn't have admin rights.
  */
 public boolean isCreator(Long groupId, String deviceId) {
   if (groupId == null) return false;
   if (StringUtils.isEmpty(deviceId)) return false;
   Group group = findById(groupId);
   if (group == null) return false;
   Device device = devicesDao.read(deviceId);
   if (device == null) return false;
   if (!group.getIdCreator().equals(deviceId)) return false;
   return true;
 }
 /**
  * @author Bogdan Sliptsov
  *     <p>This method is used to find all groups within a radius of 1000 meters.
  * @param latitude Latitude of requested device
  * @param longitude Longitude of requested device
  * @return Null 1. If latitude or longitude is null; 2. If there are no groups wihin radius of 1
  *     km List of groups within radius of 1 km.
  */
 public List<Group> getAllGroupsByGPS(Double latitude, Double longitude) {
   if (latitude == null || longitude == null) return null;
   List<Group> groups = getAllGroups();
   List<Group> resultList = new ArrayList<>();
   for (Group g : groups) {
     System.out.println(distanceGPS(latitude, longitude, g.getLatitude(), g.getLongitude()));
     if (distanceGPS(latitude, longitude, g.getLatitude(), g.getLongitude()) <= 1.0) {
       resultList.add(g);
     }
   }
   if (resultList.isEmpty()) return null;
   return resultList;
 }
 /**
  * @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);
 }