<commit_before>package org.mindinformatics.gwt.services.profiles.src;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mindinformatics.gwt.framework.component.agents.model.MAgentPerson;
import org.mindinformatics.gwt.framework.component.profiles.model.IProfile;
import org.mindinformatics.gwt.framework.component.profiles.model.MProfile;

import com.google.gson.JsonElement;
import com.google.gson.JsonParser;

@SuppressWarnings("serial")
public class JsonProfilesServiceImpl extends HttpServlet {

	public static SimpleDateFormat dayTime = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss Z");
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println("POST - URL : " + req.getRequestURL().toString() + "?" + req.getQueryString());
		Enumeration paramNames = req.getParameterNames();
		String paramName, paramValue;
		System.out.println("Params");
		while(paramNames.hasMoreElements()){
			paramName = (String) paramNames.nextElement();
			paramValue = req.getParameter(paramName);
			System.out.println(paramName+"-"+paramValue);
		}
		String content = req.getReader().readLine();
		JsonParser parser = new JsonParser();
		JsonElement el = parser.parse(content);
		System.out.println(el);
		System.out.println(req.getRemoteAddr());
		
		resp.setHeader("Content-type", "application/json");
		PrintWriter out = resp.getWriter();  
		out.println(content);  
		out.flush();
		out.close();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		System.out.println("URL : " + req.getRequestURL().toString() + "?" + req.getQueryString());
		String pathInfo = req.getPathInfo(); 
		System.out.println("PATH: " + pathInfo);
		if(pathInfo.indexOf("/")==0 && pathInfo.lastIndexOf("/")>0 && pathInfo.length()>pathInfo.lastIndexOf("/")+1) {
			String username = pathInfo.substring(1, pathInfo.lastIndexOf("/"));
			System.out.println(":: username: " + username);
			String request = pathInfo.substring(pathInfo.lastIndexOf("/")+1);
			System.out.println(":: request: " + pathInfo.substring(pathInfo.lastIndexOf("/")+1));
		
			MProfile profile = getProfileOne();
			
			String format = req.getParameter("format");
			System.out.println(":: format: " + format);
			if(format.equals("json") && username.equals("admin")) {
				if(request.equals("info")) {
					PrintWriter out = resp.getWriter();
					//out.print("[{\"createdOn\":\"08/19/2013 09:46:12 -0400\",\"createdBy\":[{\"@type\":\"foafx:Person\",\"foafx:name\":\"Dr. <NAME>\",\"@id\":\"8a70347a4096d318014096d369480000\"}],\"plugins\":[{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.annotation.qualifier\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.annotation.nif.antibodies\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.annotation.micropubs\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.resource.pubmed\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.resource.pubmedcentral\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.resource.omim\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.resource.bioportal\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.client.component.clipboard\"}],\"description\":\"All the tools that Domeo has to offer for biomedicine\",\"name\":\"Complete Biomedical Profile\",\"uuid\":\"8a70347a4096d318014096d36a5c0008\"}]");					
					
					out.print('[');
					
					out.print("{");
					out.print("\"uuid\": \"");
					out.print(profile.getUuid());
					out.print("\",");
					out.print("\"name\": \"");
					out.print(profile.getName());
					out.print("\",");
					out.print("\"description\": \""); 
					out.print(profile.getDescription());
					out.print("\",");
					out.print("\"createdOn\": \"");
					out.print(dayTime.format(profile.getLastSavedOn()));
					out.print("\",");
					out.print("\"createdBy\": [");
					out.print("{");
					out.print("\"uuid\": \"");
					out.print(profile.getLastSavedBy().getUuid());
					out.print("\",");
					out.print("\"@type\": \"");
					out.print("foafx:Person");
					out.print("\",");
					out.print("\"name\": \"");
					out.print(profile.getLastSavedBy().getName());
					out.print("\"");
					out.print("}");
					
					
					// FEATURES
					out.print("],");
					out.print("\"features\": [");
					
					out.print("{");
					out.print("\"name\": \"");
					out.print(IProfile.FEATURE_ANALYZE);
					out.print("\",");
					out.print("\"status\": \"");
					out.print("enabled");
					out.print("\"");
					out.print("},");
					
					out.print("{");
					out.print("\"name\": \"");
					out.print(IProfile.FEATURE_PREFERENCES);
					out.print("\",");
					out.print("\"status\": \"");
					out.print("enabled");
					out.print("\"");
					out.print("},");
					
					out.print("{");
					out.print("\"name\": \"");<commit_msg>Improved profiles to support features<commit_after>package org.mindinformatics.gwt.services.profiles.src;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mindinformatics.gwt.framework.component.agents.model.MAgentPerson;
import org.mindinformatics.gwt.framework.component.profiles.model.IProfile;
import org.mindinformatics.gwt.framework.component.profiles.model.MProfile;

import com.google.gson.JsonElement;
import com.google.gson.JsonParser;

@SuppressWarnings("serial")
public class JsonProfilesServiceImpl extends HttpServlet {

	public static SimpleDateFormat dayTime = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss Z");
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println("POST - URL : " + req.getRequestURL().toString() + "?" + req.getQueryString());
		Enumeration paramNames = req.getParameterNames();
		String paramName, paramValue;
		System.out.println("Params");
		while(paramNames.hasMoreElements()){
			paramName = (String) paramNames.nextElement();
			paramValue = req.getParameter(paramName);
			System.out.println(paramName+"-"+paramValue);
		}
		String content = req.getReader().readLine();
		JsonParser parser = new JsonParser();
		JsonElement el = parser.parse(content);
		System.out.println(el);
		System.out.println(req.getRemoteAddr());
		
		resp.setHeader("Content-type", "application/json");
		PrintWriter out = resp.getWriter();  
		out.println(content);  
		out.flush();
		out.close();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		System.out.println("URL : " + req.getRequestURL().toString() + "?" + req.getQueryString());
		String pathInfo = req.getPathInfo(); 
		System.out.println("PATH: " + pathInfo);
		if(pathInfo.indexOf("/")==0 && pathInfo.lastIndexOf("/")>0 && pathInfo.length()>pathInfo.lastIndexOf("/")+1) {
			String username = pathInfo.substring(1, pathInfo.lastIndexOf("/"));
			System.out.println(":: username: " + username);
			String request = pathInfo.substring(pathInfo.lastIndexOf("/")+1);
			System.out.println(":: request: " + pathInfo.substring(pathInfo.lastIndexOf("/")+1));
		
			MProfile profile = getProfileOne();
			
			String format = req.getParameter("format");
			System.out.println(":: format: " + format);
			if(format.equals("json") && username.equals("admin")) {
				if(request.equals("info")) {
					PrintWriter out = resp.getWriter();
					//out.print("[{\"createdOn\":\"08/19/2013 09:46:12 -0400\",\"createdBy\":[{\"@type\":\"foafx:Person\",\"foafx:name\":\"Dr. <NAME>\",\"@id\":\"8a70347a4096d318014096d369480000\"}],\"plugins\":[{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.annotation.qualifier\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.annotation.nif.antibodies\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.annotation.micropubs\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.resource.pubmed\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.resource.pubmedcentral\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.resource.omim\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.plugins.resource.bioportal\"},{\"status\":\"enabled\",\"name\":\"org.mindinformatics.gwt.domeo.client.component.clipboard\"}],\"description\":\"All the tools that Domeo has to offer for biomedicine\",\"name\":\"Complete Biomedical Profile\",\"uuid\":\"8a70347a4096d318014096d36a5c0008\"}]");					
					
					out.print('[');
					
					out.print("{");
					out.print("\"uuid\": \"");
					out.print(profile.getUuid());
					out.print("\",");
					out.print("\"name\": \"");
					out.print(profile.getName());
					out.print("\",");
					out.print("\"description\": \""); 
					out.print(profile.getDescription());
					out.print("\",");
					out.print("\"createdOn\": \"");
					out.print(dayTime.format(profile.getLastSavedOn()));
					out.print("\",");
					out.print("\"createdBy\": [");
					out.print("{");
					out.print("\"uuid\": \"");
					out.print(profile.getLastSavedBy().getUuid());
					out.print("\",");
					out.print("\"@type\": \"");
					out.print("foafx:Person");
					out.print("\",");
					out.print("\"name\": \"");
					out.print(profile.getLastSavedBy().getName());
					out.print("\"");
					out.print("}");
					
					// KEYS
					out.print("{");
					out.print("\"name\": \"");
					out.print("domeo.encoder.elsevier.sciencedirect.api");
					out.print("\",");
					out.print("\"status\": \"");
					out.print("");
					out.print("\"");
					out.print("},");
					
					// FEATURES
					out.print("],");
					out.print("\"features\": [");
					
					out.print("{");
					out.print("\"name\": \"");
					out.print(IProfile.FEATURE_ANALYZE);
					out.print("\",");
					out.print("\"status\": \"");
					out.print("enabled");
					out.print("\"");
					out.print("},");
					
					out.print("{");
					out.print("\"name\": \"");
					out.print(IProfile.FEATURE_PREFERENCES);
					out.print("\",");
					out.print("\"status\": \"");
					out.print("enabled");
					out.print("\"");
					out.print("},");
					
					out.print("{");
					out.print("\"name\": \"");
{'fraction_non_alphanumeric': 0.22108063480414641, 'fraction_numerical': 0.014310613705164664, 'mean_word_length': 3.978082191780822, 'pattern_counts': {'":': 86, '<': 5, '<?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': '4743468', 'n_tokens_mistral': 4251, 'n_tokens_neox': 3477, 'n_words': 419}