// Path: src/main/java/org/cytoscape/rest/internal/datamapper/GroupMapper.java
// public class GroupMapper {
// 
// 	
// 	/**
// 	 * Create a new group from a list of nodes.
// 	 * 
// 	 * @param rootNode
// 	 * @param factory
// 	 * @param network
// 	 * @return
// 	 */
// 	public CyGroup createGroup(final JsonNode rootNode, final CyGroupFactory factory, final CyNetwork network) {
// 		
// 		// Extract required fields: member nodes and name of new node.
// 		final String groupName = rootNode.get(CyNetwork.NAME).textValue();
// 		final JsonNode memberNodes = rootNode.get("nodes");
// 		
// 		// This is optional.
// 		final JsonNode memberEdges = rootNode.get("edges");
// 		
// 		if(groupName == null || groupName.isEmpty()) {
// 			throw new IllegalArgumentException("Group name is missing.");
// 		}
// 		
// 		if(memberNodes.isArray() == false) {
// 			throw new IllegalArgumentException("Invalid parameter.");
// 		}
// 		
// 		if(memberNodes.size() == 0) {
// 			throw new IllegalArgumentException("Group member list is empty.");
// 		}
// 		
// 		// Phase 1: Create list of member nodes.
// 		final List<CyNode> nodes = new ArrayList<CyNode>();
// 		for (final JsonNode node : memberNodes) {
// 			final CyNode n = network.getNode(node.asLong());
// 			if (n != null) {
// 				nodes.add(n);
// 			}
// 		}
// 	
// 		// Phase 2: Create group from the list of nodes.
// 		final CyGroup group = factory.createGroup(network, nodes, null, true);
// 		final CyRow groupRow = ((CySubNetwork)network).getRootNetwork().getRow(group.getGroupNode(), CyRootNetwork.SHARED_ATTRS);
// 		groupRow.set(CyRootNetwork.SHARED_NAME, groupName);
// 
// 		// Add edges if necessary...
// 		if (memberEdges != null && memberEdges.isArray()) {
// 			final List<CyEdge> edges = new ArrayList<CyEdge>();
// 			for (final JsonNode edge : memberEdges) {
// 				final CyEdge e = network.getEdge(edge.asLong());
// 				if (e != null) {
// 					edges.add(e);
// 				}
// 			}
// 			group.addEdges(edges);
// 		}
// 
// 		return group;
// 	}
// }
// 
// Path: src/main/java/org/cytoscape/rest/internal/serializer/GroupModule.java
// public class GroupModule extends SimpleModule {
// 
// 	private static final long serialVersionUID = -1590853632349015561L;
// 
// 	public GroupModule() {
// 		super("GroupModule", new Version(1, 0, 0, null, null, null));
// 		addSerializer(new GroupSerializer());
// 	}
// }


import java.io.IOException;
import java.io.InputStream;
import java.util.Set;
import javax.inject.Singleton;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.cytoscape.group.CyGroup;
import org.cytoscape.group.CyGroupFactory;
import org.cytoscape.group.CyGroupManager;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
import org.cytoscape.model.subnetwork.CySubNetwork;
import org.cytoscape.rest.internal.datamapper.GroupMapper;
import org.cytoscape.rest.internal.serializer.GroupModule;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
package org.cytoscape.rest.internal.resource;





@Singleton
@Path("/v1/networks/{networkId}/groups")
public class GroupResource extends AbstractResource {

	private final ObjectMapper groupMapper;
// Path: src/main/java/org/cytoscape/rest/internal/datamapper/GroupMapper.java
// public class GroupMapper {
// 
// 	
// 	/**
// 	 * Create a new group from a list of nodes.
// 	 * 
// 	 * @param rootNode
// 	 * @param factory
// 	 * @param network
// 	 * @return
// 	 */
// 	public CyGroup createGroup(final JsonNode rootNode, final CyGroupFactory factory, final CyNetwork network) {
// 		
// 		// Extract required fields: member nodes and name of new node.
// 		final String groupName = rootNode.get(CyNetwork.NAME).textValue();
// 		final JsonNode memberNodes = rootNode.get("nodes");
// 		
// 		// This is optional.
// 		final JsonNode memberEdges = rootNode.get("edges");
// 		
// 		if(groupName == null || groupName.isEmpty()) {
// 			throw new IllegalArgumentException("Group name is missing.");
// 		}
// 		
// 		if(memberNodes.isArray() == false) {
// 			throw new IllegalArgumentException("Invalid parameter.");
// 		}
// 		
// 		if(memberNodes.size() == 0) {
// 			throw new IllegalArgumentException("Group member list is empty.");
// 		}
// 		
// 		// Phase 1: Create list of member nodes.
// 		final List<CyNode> nodes = new ArrayList<CyNode>();
// 		for (final JsonNode node : memberNodes) {
// 			final CyNode n = network.getNode(node.asLong());
// 			if (n != null) {
// 				nodes.add(n);
// 			}
// 		}
// 	
// 		// Phase 2: Create group from the list of nodes.
// 		final CyGroup group = factory.createGroup(network, nodes, null, true);
// 		final CyRow groupRow = ((CySubNetwork)network).getRootNetwork().getRow(group.getGroupNode(), CyRootNetwork.SHARED_ATTRS);
// 		groupRow.set(CyRootNetwork.SHARED_NAME, groupName);
// 
// 		// Add edges if necessary...
// 		if (memberEdges != null && memberEdges.isArray()) {
// 			final List<CyEdge> edges = new ArrayList<CyEdge>();
// 			for (final JsonNode edge : memberEdges) {
// 				final CyEdge e = network.getEdge(edge.asLong());
// 				if (e != null) {
// 					edges.add(e);
// 				}
// 			}
// 			group.addEdges(edges);
// 		}
// 
// 		return group;
// 	}
// }
// 
// Path: src/main/java/org/cytoscape/rest/internal/serializer/GroupModule.java
// public class GroupModule extends SimpleModule {
// 
// 	private static final long serialVersionUID = -1590853632349015561L;
// 
// 	public GroupModule() {
// 		super("GroupModule", new Version(1, 0, 0, null, null, null));
// 		addSerializer(new GroupSerializer());
// 	}
// }


// Path: src/main/java/org/cytoscape/rest/internal/resource/GroupResource.java
import java.io.IOException;
import java.io.InputStream;
import java.util.Set;
import javax.inject.Singleton;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.cytoscape.group.CyGroup;
import org.cytoscape.group.CyGroupFactory;
import org.cytoscape.group.CyGroupManager;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
import org.cytoscape.model.subnetwork.CySubNetwork;
import org.cytoscape.rest.internal.datamapper.GroupMapper;
import org.cytoscape.rest.internal.serializer.GroupModule;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

package org.cytoscape.rest.internal.resource;





@Singleton
@Path("/v1/networks/{networkId}/groups")
public class GroupResource extends AbstractResource {

	private final ObjectMapper groupMapper;
	private final GroupMapper mapper;