<commit_before>package gov.nih.nci.cananolab.restful;

import gov.nih.nci.cananolab.dto.common.AccessibilityBean;
import gov.nih.nci.cananolab.dto.common.CollaborationGroupBean;
import gov.nih.nci.cananolab.dto.common.DataReviewStatusBean;
import gov.nih.nci.cananolab.restful.community.CollaborationGroupBO;
import gov.nih.nci.cananolab.restful.community.CollaborationGroupManager;
import gov.nih.nci.cananolab.restful.context.SpringApplicationContext;
import gov.nih.nci.cananolab.restful.util.SecurityUtil;
import gov.nih.nci.cananolab.ui.form.SearchProtocolForm;

import java.util.List;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;

@Path("/community")
public class CommunityServices {
	
	@Inject
	ApplicationContext applicationContext;
	
	private Logger logger = Logger.getLogger(CommunityServices.class);
	
	@GET
	@Path("/getCollaborationGroups")
	@Produces ("application/json")
    public Response getCollaborationGroups(@Context HttpServletRequest httpRequest) {
		logger.info("In getCollaborationGroups");
				
		try { 
			CollaborationGroupBO collGroupBO = 
					 (CollaborationGroupBO) SpringApplicationContext.getBean("collaborationGroupBO");
			
			if (! SecurityUtil.isUserLoggedIn(httpRequest))
				return Response.status(Response.Status.UNAUTHORIZED)
						.entity(SecurityUtil.MSG_SESSION_INVALID).build();
			
			List<CollaborationGroupBean> existingGroups = collGroupBO.getExistingGroups(httpRequest);
			
			return Response.ok(existingGroups).header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
					.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization").build();

		} catch (Exception e) {
			return Response.status(Response.Status.NOT_FOUND)
					.entity("Problem getting the collaboration groups: "+ e.getMessage()).build();
		}
	}

	@POST
	@Path("/addCollaborationGroups")
	@Produces ("application/json")
    public Response addCollaborationGroups(@Context HttpServletRequest httpRequest, CollaborationGroupBean groupBean) {
		logger.info("In getCollaborationGroups");
				
		try { 
			CollaborationGroupBO collGroupBO = 
					 (CollaborationGroupBO) SpringApplicationContext.getBean("collaborationGroupBO");
			
			if (! SecurityUtil.isUserLoggedIn(httpRequest))
				return Response.status(Response.Status.UNAUTHORIZED)
						.entity(SecurityUtil.MSG_SESSION_INVALID).build();
			 
						
			List<CollaborationGroupBean> beans = collGroupBO.create(groupBean, httpRequest);
			
			return Response.ok(beans).header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
					.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization").build();

		} catch (Exception e) {
			return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
					.entity("Problem creating the collaboration groups: "+ e.getMessage()).build();
		}
	}
	
	@POST
	@Path("/deleteCollaborationGroups")
	@Produces ("application/json")
    public Response deleteCollaborationGroups(@Context HttpServletRequest httpRequest, CollaborationGroupBean groupBean) {
		logger.info("In getCollaborationGroups");
				
		try { 
			CollaborationGroupBO collGroupBO = 
					 (CollaborationGroupBO) SpringApplicationContext.getBean("collaborationGroupBO");
			
			if (! SecurityUtil.isUserLoggedIn(httpRequest))
				return Response.status(Response.Status.UNAUTHORIZED)
						.entity(SecurityUtil.MSG_SESSION_INVALID).build();
			 
						
			List<CollaborationGroupBean> beans = collGroupBO.delete(groupBean, httpRequest);
			
			return Response.ok(beans).header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
					.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization").build();

		} catch (Exception e) {
			return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
					.entity("Problem creating the collaboration groups: "+ e.getMessage()).build();
		}
	}
	
	@GET
	@Path("/editCollaborationGroup")
	@Produces ("application/json")
    public Response editCollaborationGroup(@Context HttpServletRequest httpRequest, @DefaultValue("") @QueryParam("groupId") String groupId) {
		logger.info("In editCollaborationGroup");
				
		try { 
			CollaborationGroupManager collGroupManager = 
					 (CollaborationGroupManager) SpringApplicationContext.getBean("collaborationGroupManger");
			
			if (! SecurityUtil.isUserLoggedIn(httpRequest))
				return Response.status(Response.Status.UNAUTHORIZED)
						.entity(SecurityUtil.MSG_SESSION_INVALID).build();
			
			CollaborationGroupBean collaborationBean = collGroupManager.getCollaborationGroupById(httpRequest, groupId);
			
			return Response.ok(collaborationBean).header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
					.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization").build();

		} catch (Exception e) {
			return Response.status(Response.Status.NOT_FOUND)
					.entity("Problem getting the collaboration group by ID: "+ e.getMessage()).build();
		}
	}
	
	@POST
	@Path("/addUserAccess")
	@Produces ("application/json")
    public Response addUserAccess(@Context HttpServletRequest httpRequest, AccessibilityBean userAccess) {
		logger.info("In addUserAccess for Collaboration group");
				
		try { 
			CollaborationGroupManager collGroupManager = 
					 (CollaborationGroupManager) SpringApplicationContext.getBean("collaborationGroupManger");
			
			if (! SecurityUtil.isUserLoggedIn(httpRequest))
				return Response.status(Response.Status.UNAUTHORIZED)
						.entity(SecurityUtil.MSG_SESSION_INVALID).build();
			
			CollaborationGroupBean collaborationBean = collGroupManager.addUserAccess(httpRequest, userAccess);
			
			return Response.ok(collaborationBean).header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
					.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization").build();

		} catch (Exception e) {
			return Response.status(Response.Status.NOT_FOUND)
					.entity("Problem getting the collaboration group by ID: "+ e.getMessage()).build();
		}
	}
	
	@POST
	@Path("/deleteUserAccess")
	@Produces ("application/json")
    public Response deleteUserAccess(@Context HttpServletRequest httpRequest, AccessibilityBean userAccess) {
		logger.info("In addUserAccess for Collaboration group");
				
		try { 
			CollaborationGroupManager collGroupManager = 
					 (CollaborationGroupManager) SpringApplicationContext.getBean("collaborationGroupManger");
			
			if (! SecurityUtil.isUserLoggedIn(httpRequest))
				return Response.status(Response.Status.UNAUTHORIZED)
						.entity(SecurityUtil.MSG_SESSION_INVALID).build();
			
			CollaborationGroupBean collaborationBean = collGroupManager.deleteUserAccess(httpRequest, userAccess);
			
			return Response.ok(collaborationBean).header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
					.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization").build();

		} catch (Exception e) {
			return Response.status(Response.Status.NOT_FOUND)
					.entity("Problem getting the collaboration group by ID: "+ e.getMessage()).build();
		}
	}

}<commit_msg>Collaboration group changes.<commit_after>package gov.nih.nci.cananolab.restful;

import gov.nih.nci.cananolab.dto.common.AccessibilityBean;
import gov.nih.nci.cananolab.dto.common.CollaborationGroupBean;
import gov.nih.nci.cananolab.dto.common.DataReviewStatusBean;
import gov.nih.nci.cananolab.restful.community.CollaborationGroupBO;
import gov.nih.nci.cananolab.restful.community.CollaborationGroupManager;
import gov.nih.nci.cananolab.restful.context.SpringApplicationContext;
import gov.nih.nci.cananolab.restful.util.SecurityUtil;
import gov.nih.nci.cananolab.ui.form.SearchProtocolForm;

import java.util.List;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;

@Path("/community")
public class CommunityServices {
	
	@Inject
	ApplicationContext applicationContext;
	
	private Logger logger = Logger.getLogger(CommunityServices.class);
	
	@GET
	@Path("/getCollaborationGroups")
	@Produces ("application/json")
    public Response getCollaborationGroups(@Context HttpServletRequest httpRequest) {
		logger.info("In getCollaborationGroups");
				
		try { 
			CollaborationGroupBO collGroupBO = 
					 (CollaborationGroupBO) SpringApplicationContext.getBean("collaborationGroupBO");
			
			if (! SecurityUtil.isUserLoggedIn(httpRequest))
				return Response.status(Response.Status.UNAUTHORIZED)
						.entity(SecurityUtil.MSG_SESSION_INVALID).build();
			
			List<CollaborationGroupBean> existingGroups = collGroupBO.getExistingGroups(httpRequest);
			
			return Response.ok(existingGroups).header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
					.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization").build();

		} catch (Exception e) {
			return Response.status(Response.Status.NOT_FOUND)
					.entity("Problem getting the collaboration groups: "+ e.getMessage()).build();
		}
	}

	@POST
	@Path("/addCollaborationGroups")
	@Produces ("application/json")
    public Response addCollaborationGroups(@Context HttpServletRequest httpRequest, CollaborationGroupBean groupBean) {
		logger.info("In getCollaborationGroups");
				
		try { 
			CollaborationGroupBO collGroupBO = 
					 (CollaborationGroupBO) SpringApplicationContext.getBean("collaborationGroupBO");
			
			if (! SecurityUtil.isUserLoggedIn(httpRequest))
				return Response.status(Response.Status.UNAUTHORIZED)
						.entity(SecurityUtil.MSG_SESSION_INVALID).build();
			 
						
			List<CollaborationGroupBean> beans = collGroupBO.create(groupBean, httpRequest);
			
			return Response.ok(beans).header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
					.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization").build();

		} catch (Exception e) {
			return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
					.entity("Problem creating the collaboration groups: "+ e.getMessage()).build();
		}
	}
	
	@POST
	@Path("/deleteCollaborationGroups")
	@Produces ("application/json")
    public Response deleteCollaborationGroups(@Context HttpServletRequest httpRequest, CollaborationGroupBean groupBean) {
		logger.info("In getCollaborationGroups");
				
		try { 
			CollaborationGroupBO collGroupBO = 
					 (CollaborationGroupBO) SpringApplicationContext.getBean("collaborationGroupBO");
			
			if (! SecurityUtil.isUserLoggedIn(httpRequest))
				return Response.status(Response.Status.UNAUTHORIZED)
						.entity(SecurityUtil.MSG_SESSION_INVALID).build();
			 
						
			List<CollaborationGroupBean> beans = collGroupBO.delete(groupBean, httpRequest);
			
			return Response.ok(beans).header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
					.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization").build();

		} catch (Exception e) {
			return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
					.entity("Problem deleting the collaboration groups: "+ e.getMessage()).build();
		}
	}
	
	@GET
	@Path("/editCollaborationGroup")
	@Produces ("application/json")
    public Response editCollaborationGroup(@Context HttpServletRequest httpRequest, @DefaultValue("") @QueryParam("groupId") String groupId) {
		logger.info("In editCollaborationGroup");
				
		try { 
			CollaborationGroupManager collGroupManager = 
					 (CollaborationGroupManager) SpringApplicationContext.getBean("collaborationGroupManger");
			
			if (! SecurityUtil.isUserLoggedIn(httpRequest))
				return Response.status(Response.Status.UNAUTHORIZED)
						.entity(SecurityUtil.MSG_SESSION_INVALID).build();
			
			CollaborationGroupBean collaborationBean = collGroupManager.getCollaborationGroupById(httpRequest, groupId);
			
			return Response.ok(collaborationBean).header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
					.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization").build();

		} catch (Exception e) {
			return Response.status(Response.Status.NOT_FOUND)
					.entity("Problem getting the collaboration group by ID: "+ e.getMessage()).build();
		}
	}
	
	@POST
	@Path("/addUserAccess")
	@Produces ("application/json")
    public Response addUserAccess(@Context HttpServletRequest httpRequest, AccessibilityBean userAccess) {
		logger.info("In addUserAccess for Collaboration group");
				
		try { 
			CollaborationGroupManager collGroupManager = 
					 (CollaborationGroupManager) SpringApplicationContext.getBean("collaborationGroupManger");
			
			if (! SecurityUtil.isUserLoggedIn(httpRequest))
				return Response.status(Response.Status.UNAUTHORIZED)
						.entity(SecurityUtil.MSG_SESSION_INVALID).build();
			
			CollaborationGroupBean collaborationBean = collGroupManager.addUserAccess(httpRequest, userAccess);
			
			return Response.ok(collaborationBean).header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
					.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization").build();

		} catch (Exception e) {
			return Response.status(Response.Status.NOT_FOUND)
					.entity("Problem adding the user to collaboration group : "+ e.getMessage()).build();
		}
	}
	
	@POST
	@Path("/deleteUserAccess")
	@Produces ("application/json")
    public Response deleteUserAccess(@Context HttpServletRequest httpRequest, AccessibilityBean userAccess) {
		logger.info("In addUserAccess for Collaboration group");
				
		try { 
			CollaborationGroupManager collGroupManager = 
					 (CollaborationGroupManager) SpringApplicationContext.getBean("collaborationGroupManger");
			
			if (! SecurityUtil.isUserLoggedIn(httpRequest))
				return Response.status(Response.Status.UNAUTHORIZED)
						.entity(SecurityUtil.MSG_SESSION_INVALID).build();
			
			CollaborationGroupBean collaborationBean = collGroupManager.deleteUserAccess(httpRequest, userAccess);
			
			return Response.ok(collaborationBean).header("Access-Control-Allow-Credentials", "true")
					.header("Access-Control-Allow-Origin", "*")
					.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
					.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization").build();

		} catch (Exception e) {
			return Response.status(Response.Status.NOT_FOUND)
					.entity("Problem removing user from the collaboration group : "+ e.getMessage()).build();
		}
	}

}
{'fraction_non_alphanumeric': 0.12476496633711409, 'fraction_numerical': 0.00012130769697337296, 'mean_word_length': 5.102146558105107, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2565376', 'n_tokens_mistral': 5562, 'n_tokens_neox': 4797, 'n_words': 782}