/**
  * @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>User-story, 2 point. User can create group
  *     <p>This method is used to create new group.
  * @param groupName Name of new group.
  * @param groupType Type of new group(0 - open, 1 - pass, 2 - moderate)
  * @param password Password of new group. Only if groupType equals 1.
  * @param creatorId Identifier of requested device.
  * @param coordinateX X coordinate of requested device.
  * @param coordinateY Y coordinate of requested device.
  * @return Long This returns unique identifier of just created group. Null 1. If groupName equals
  *     null; 2. If groupType null or != [0, 1, 2]; 3. If groupType equals 1 but password is null
  *     or empty; 4. If creatorId is null; 5. If requested device doesn't exist. 6. If X or Y
  *     coordinate equals null.
  */
 public Long createGroup(
     String groupName,
     Byte groupType,
     String password,
     String creatorId,
     Double coordinateX,
     Double coordinateY) {
   if (StringUtils.isEmpty(groupName)) return null;
   if (groupType == null || groupType < 0 || groupType > 2) return null;
   if (groupType.equals(new Byte(String.valueOf(1))) && StringUtils.isEmpty(password)) return null;
   if (StringUtils.isEmpty(creatorId)) return null;
   if (devicesDao.read(creatorId) == null) return null;
   if (coordinateX == null || coordinateY == null) return null;
   return groupDao.create(
       new Group(
           groupName,
           groupType,
           password,
           creatorId,
           coordinateX,
           coordinateY,
           new ArrayList<Device>(Arrays.asList(devicesDao.read(creatorId)))));
 }
 /**
  * @author Bogdan Sliptsov
  *     <p>This method is used to add device to requested group if group and device exists.
  * @param groupId Unique group identifier.
  * @param deviceId Unique device identifier.
  */
 public void addDeviceToGroup(Long groupId, String deviceId) {
   if (groupId == null || StringUtils.isEmpty(deviceId)) return;
   if (groupDao.read(groupId) == null) return;
   if (groupDao.read(groupId).getDevices().contains(devicesDao.read(deviceId))) return;
   groupDao.addDeviceToGroup(groupId, devicesDao.read(deviceId));
 }
 /**
  * @author Bogdan Sliptsov
  *     <p>This method is used to delete device from requested group if group exists; device
  *     exists; devices exists in list of devices of requested group.
  * @param groupId Unique group identifier.
  * @param deviceId Unique device identifier.
  */
 public void deleteDeviceFromGroup(Long groupId, String deviceId) {
   if (groupId == null || StringUtils.isEmpty(deviceId)) return;
   if (groupDao.read(groupId) == null) return;
   if (!groupDao.read(groupId).getDevices().contains(devicesDao.read(deviceId))) return;
   groupDao.deleteDeviceFromGroup(groupId, deviceId);
 }