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;
	}
}

@@ -1384,16 +1384,27 @@
         
+ groupSet =
  gsContr
@@ -1413,35 +1413,235 @@
 .get
-ChatBuddyPOsFromDB(dbTime);
+SegregatedGroups(dbTime);%0A            for(Set%3CString%3E addGroup: groupSet)%7B%0A                Group newGroup = new Group();%0A                newGroup.setGroupMembers(addGroup);%0A                groupList.add(newGroup);%0A            %7D
 %0A%0A%09%09

Add user group API function