package edu.cmu.sv.ws.ssnoc.rest;

import edu.cmu.sv.ws.ssnoc.common.logging.Log;
import edu.cmu.sv.ws.ssnoc.control.GroupSegregate;
import edu.cmu.sv.ws.ssnoc.data.dao.DAOFactory;
import edu.cmu.sv.ws.ssnoc.data.po.ChatBuddyPO;
import edu.cmu.sv.ws.ssnoc.data.po.UserListPO;
import edu.cmu.sv.ws.ssnoc.data.po.UserPO;
import edu.cmu.sv.ws.ssnoc.dto.DBTime;
import edu.cmu.sv.ws.ssnoc.dto.Group;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.bind.annotation.XmlElementWrapper;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


@Path("/usergroups")
public class UserGroups extends BaseService {

	/**
	 * This method loads all active users in the system.
	 * 
	 * @return - List of all active users.
	 */
    @POST
    @Path("/unconnected")
    @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	@XmlElementWrapper(name = "groups")
	public Set<Group> loadGroups(DBTime dbTime) {
		Log.enter();

        Set<Group> groupList = new HashSet<Group>();
		try {
            Set<Set<String>> groupSet = new HashSet<Set<String>>();
            //add full list to each users
            //get chat buddies from database
            GroupSegregate gsControl = GroupSegregate.getInstance();
            gsControl.getChatBuddyPOsFromDB(dbTime);

		} catch (Exception e) {
			handleException(e);
		} finally {
			Log.exit(groupList);
		}
        return groupList;
	}
}

package edu.cmu.sv.ws.ssnoc.rest;

import edu.cmu.sv.ws.ssnoc.common.logging.Log;
import edu.cmu.sv.ws.ssnoc.control.GroupSegregate;
import edu.cmu.sv.ws.ssnoc.data.dao.DAOFactory;
import edu.cmu.sv.ws.ssnoc.data.po.ChatBuddyPO;
import edu.cmu.sv.ws.ssnoc.data.po.UserListPO;
import edu.cmu.sv.ws.ssnoc.data.po.UserPO;
import edu.cmu.sv.ws.ssnoc.dto.DBTime;
import edu.cmu.sv.ws.ssnoc.dto.Group;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.bind.annotation.XmlElementWrapper;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


@Path("/usergroups")
public class UserGroups extends BaseService {

	/**
	 * This method loads all active users in the system.
	 * 
	 * @return - List of all active users.
	 */
    @POST
    @Path("/unconnected")
    @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	@XmlElementWrapper(name = "groups")
	public Set<Group> loadGroups(DBTime dbTime) {
		Log.enter();

        Set<Group> groupList = new HashSet<Group>();
		try {
            Set<Set<String>> groupSet = new HashSet<Set<String>>();
            //add full list to each users
            //get chat buddies from database
            GroupSegregate gsControl = GroupSegregate.getInstance();
            groupSet = gsControl.getSegregatedGroups(dbTime);
            for(Set<String> addGroup: groupSet){
                Group newGroup = new Group();
                newGroup.setGroupMembers(addGroup);
                groupList.add(newGroup);
            }

		} catch (Exception e) {
			handleException(e);
		} finally {
			Log.exit(groupList);
		}
        return groupList;
	}
}

Add user group API function