<commit_before>package edu.yu.einstein.wasp.controller;
/**
 * Controller to manage UIField table
 * 
 * @Author: <NAME>
 */
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import edu.yu.einstein.wasp.model.JQuerySearch;
import edu.yu.einstein.wasp.model.UiField;
import edu.yu.einstein.wasp.service.MessageService;
import edu.yu.einstein.wasp.service.UiFieldService;
import edu.yu.einstein.wasp.service.impl.WaspMessageSourceImpl;
import edu.yu.einstein.wasp.taglib.JQFieldTag;

@Controller
@Transactional
@RequestMapping("/uiField")
public class UiFieldController extends WaspController {

	Logger log=Logger.getLogger(UiFieldController.class);
	
	@Autowired
	private UiFieldService uiFieldService;

	@Autowired
	private MessageSource messageSource;
	
	@Autowired
	private MessageService messageService;
	
	//init read-only static structures used ti build dropdown lists
	private static final Map<String, String> MY_LOCALES=new LinkedHashMap<String, String>();
	static { 
		 MY_LOCALES.put("","--select--");
		 MY_LOCALES.putAll(LOCALES);
	 }
	
	  private static final Map<String, String> ATTR_NAMES=new LinkedHashMap<String, String>();
	  static { 

	  ATTR_NAMES.put("","-- select --");	  
	  ATTR_NAMES.put("label","Field Label");
	  ATTR_NAMES.put("constraint","Validation Constraint");
	  ATTR_NAMES.put("error","Validation Constraint Message");	  	  
	  ATTR_NAMES.put("control","Dropdown Options");
	  ATTR_NAMES.put("suffix","Suffix");
	  ATTR_NAMES.put("metaposition","Position");
	  ATTR_NAMES.put("data","Area-specific data");
	  ATTR_NAMES.put("type","Data Type (INTEGER, NUMBER, STRING)");
	  ATTR_NAMES.put("range","Data Range (e.g. 10 or 0:10)");
	  }
	  
	  //init read-only static structures used ti build dropdown lists
	  protected static final Map<String, String> AREA_NAMES=new LinkedHashMap<String, String>();
	  static { 
		  
		  AREA_NAMES.put("","--select--");
	  }

	  /**
	   * prepares data to display JQGrid
	   * @param m
	   * @param response
	   * @return
	   */
	@RequestMapping("/list")
	@PreAuthorize("hasRole('god')")
	public String list(ModelMap m,HttpServletResponse response) {
	
		Map<String, String> areas=new TreeMap<String, String>();
		
		areas.putAll(AREA_NAMES);
		
		for(String area:uiFieldService.getUniqueAreas()) {
			areas.put(area,area);
		}
		
		response.setContentType("text/html;charset=UTF-8");
		
		m.addAttribute(JQFieldTag.AREA_ATTR, "uiField");		
		m.addAttribute("attrNames", ATTR_NAMES);
		m.addAttribute("areaNames", areas);
		m.addAttribute("locales", MY_LOCALES);
		
		return "uifield/list";
	}

	/**
	 * Returns JSON-formatted list of data rows
	 * 
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/listJSON", method=RequestMethod.GET)	
	public String getListJSON(HttpServletResponse response) {<commit_msg>su user<commit_after>package edu.yu.einstein.wasp.controller;
/**
 * Controller to manage UIField table
 * 
 * @Author: <NAME>
 */
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import edu.yu.einstein.wasp.model.JQuerySearch;
import edu.yu.einstein.wasp.model.UiField;
import edu.yu.einstein.wasp.service.MessageService;
import edu.yu.einstein.wasp.service.UiFieldService;
import edu.yu.einstein.wasp.service.impl.WaspMessageSourceImpl;
import edu.yu.einstein.wasp.taglib.JQFieldTag;

@Controller
@Transactional
@RequestMapping("/uiField")
public class UiFieldController extends WaspController {

	Logger log=Logger.getLogger(UiFieldController.class);
	
	@Autowired
	private UiFieldService uiFieldService;

	@Autowired
	private MessageSource messageSource;
	
	@Autowired
	private MessageService messageService;
	
	//init read-only static structures used ti build dropdown lists
	private static final Map<String, String> MY_LOCALES=new LinkedHashMap<String, String>();
	static { 
		 MY_LOCALES.put("","--select--");
		 MY_LOCALES.putAll(LOCALES);
	 }
	
	  private static final Map<String, String> ATTR_NAMES=new LinkedHashMap<String, String>();
	  static { 

	  ATTR_NAMES.put("","-- select --");	  
	  ATTR_NAMES.put("label","Field Label");
	  ATTR_NAMES.put("constraint","Validation Constraint");
	  ATTR_NAMES.put("error","Validation Constraint Message");	  	  
	  ATTR_NAMES.put("control","Dropdown Options");
	  ATTR_NAMES.put("suffix","Suffix");
	  ATTR_NAMES.put("metaposition","Position");
	  ATTR_NAMES.put("data","Area-specific data");
	  ATTR_NAMES.put("type","Data Type (INTEGER, NUMBER, STRING)");
	  ATTR_NAMES.put("range","Data Range (e.g. 10 or 0:10)");
	  }
	  
	  //init read-only static structures used ti build dropdown lists
	  protected static final Map<String, String> AREA_NAMES=new LinkedHashMap<String, String>();
	  static { 
		  
		  AREA_NAMES.put("","--select--");
	  }

	  /**
	   * prepares data to display JQGrid
	   * @param m
	   * @param response
	   * @return
	   */
	@RequestMapping("/list")
	@PreAuthorize("hasRole('su')")
	public String list(ModelMap m,HttpServletResponse response) {
	
		Map<String, String> areas=new TreeMap<String, String>();
		
		areas.putAll(AREA_NAMES);
		
		for(String area:uiFieldService.getUniqueAreas()) {
			areas.put(area,area);
		}
		
		response.setContentType("text/html;charset=UTF-8");
		
		m.addAttribute(JQFieldTag.AREA_ATTR, "uiField");		
		m.addAttribute("attrNames", ATTR_NAMES);
		m.addAttribute("areaNames", areas);
		m.addAttribute("locales", MY_LOCALES);
		
		return "uifield/list";
	}

	/**
	 * Returns JSON-formatted list of data rows
	 * 
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/listJSON", method=RequestMethod.GET)	
	public String getListJSON(HttpServletResponse response) {
{'fraction_non_alphanumeric': 0.12791747259832367, 'fraction_numerical': 0.0018052869116698903, 'mean_word_length': 5.087912087912088, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '6744509', 'n_tokens_mistral': 2616, 'n_tokens_neox': 2425, 'n_words': 455}