@Override
  public EnergyDataHistoryQueryResult getHistory(
      Enums.HistoryType historyType, Group group, long startTime, long endTime, int interval) {
    User user = getCurrentUser();
    if (group == null || group.getId() == null) {
      logger.debug("No group specified");
      return new EnergyDataHistoryQueryResult();
    }
    // Check group history
    Group userGroup = groupService.getGroup(user, group.getId());
    if (userGroup == null) logger.error("User group is null");

    if (userGroup != null
        && (userGroup.getRole() == Group.Role.OWNER
            || userGroup.getRole() == Group.Role.READONLY)) {
      if (logger.isInfoEnabled())
        logger.info(
            "retrieving "
                + historyType
                + " history for  "
                + group
                + " "
                + startTime
                + "-"
                + endTime);
      EnergyDataHistoryQueryResult result =
          historyService.getHistory(historyType, user, group, startTime, endTime, interval);
      return result;
    }
    logger.warn("Security violation. " + user + " attempted to retrieve history for  " + group);
    return new EnergyDataHistoryQueryResult();
  }
 @Override
 public void deleteGroup(Group group) {
   User user = getCurrentUser();
   if (user.getId().equals(group.getOwnerUserId())) {
     if (logger.isInfoEnabled()) logger.info("deleting group " + group);
     groupService.deleteGroup(group);
   } else {
     logger.warn("Security violation. " + user + " attempted to delete " + group);
   }
 }
 @Override
 public Group saveGroup(Group group) {
   User user = getCurrentUser();
   if (user.getId().equals(group.getOwnerUserId())) {
     if (logger.isInfoEnabled()) logger.info("saving group " + group);
     return groupService.saveGroup(group);
   }
   logger.warn("Security violation. " + user + " attempted to save " + group);
   return group;
 }
 @Override
 public void addUserToGroup(Group group, User user) {
   User sessionUser = getCurrentUser();
   if (group.getOwnerUserId().equals(sessionUser.getId())) {
     if (logger.isInfoEnabled())
       logger.info(sessionUser + " is adding " + user + "  to  " + group);
     groupService.addUserToGroup(user, group, Group.Role.READONLY);
   } else {
     logger.warn(
         "Security violation. " + sessionUser + " attempted to add " + user + "  to  " + group);
   }
 }
 @Override
 public List<User> getGroupMembers(Group group) {
   User sessionUser = getCurrentUser();
   if (group.getOwnerUserId().equals(sessionUser.getId())) {
     if (logger.isInfoEnabled())
       logger.info(sessionUser + " is retrieving a list of users for group " + group);
     return userService.findUsers(group);
   } else {
     logger.warn(
         "Security violation. "
             + sessionUser
             + " attempted to retrieve a list of users for group "
             + group);
     return null;
   }
 }
 @Override
 public void removeUserFromGroup(Group group, User user) {
   User sessionUser = getCurrentUser();
   if (group.getOwnerUserId().equals(sessionUser.getId())) {
     if (logger.isInfoEnabled())
       logger.info(sessionUser + " is removing " + user + "  from  " + group);
     groupService.removeUserFromGroup(user, group);
   } else {
     logger.warn(
         "Security violation. "
             + sessionUser
             + " attempted to remove "
             + user
             + "  from  "
             + group);
   }
 }