<commit_before>package org.openregistry.core.web;

import org.openregistry.core.domain.Role;
import org.openregistry.core.domain.Person;
import org.openregistry.core.domain.RoleInfo;

import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.propertyeditors.CustomDateEditor;

import javax.servlet.http.HttpServletRequest;
import javax.annotation.Resource;

import org.javalid.core.AnnotationValidator;
import org.javalid.core.AnnotationValidatorImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.List;
import java.util.Collection;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import org.openregistry.core.web.propertyeditors.PhoneEditor;
import org.openregistry.core.web.propertyeditors.CountryEditor;
import org.openregistry.core.web.propertyeditors.RegionEditor;
import org.openregistry.core.service.PersonService;
import org.openregistry.core.service.ServiceExecutionResult;
import org.openregistry.core.repository.PersonRepository;
import org.openregistry.core.repository.ReferenceRepository;
import com.sun.xml.internal.bind.v2.TODO;

/**
 * @author <NAME>
 * @version $Revision$ $Date$
 * @since 1.0.0
 */
@Controller
@RequestMapping("/addRole.htm")

public class PersonRegistryController {

	protected final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private PersonService personService;

    @Autowired(required=true)
    private ReferenceRepository referenceRepository;

	@RequestMapping(method = RequestMethod.GET)
    public String addRoleSetUpForm(ModelMap model) {
    	logger.info("Populating: setUpForm: ");

        //fudge personKey
        Long personKey = new Long(5);
        Person person = personService.findPersonById(personKey);
        model.addAttribute("person",person);

        //fudge roleInfoKey
        Long roleInfoKey = new Long(2);
        RoleInfo roleInfo = referenceRepository.getRoleInfo(roleInfoKey);
        Role role = person.addRole(roleInfo);
        role.setSponsor(personService.findPersonById(new Long(6)));
        role.addEmailAddress();
        role.addPhone();
        role.addAddress();

        //add reference data
        readReferenceData(model);

        model.addAttribute("personid", getPersonDisplayName(person));
        model.addAttribute("affiliationTypeDescription", role.getAffiliationType().getDescription());
        model.addAttribute("title", role.getTitle());
        model.addAttribute("role",role);
    	return "addRole";
    }

	@RequestMapping(method = RequestMethod.POST)
	public String addRoleProcessSubmit(ModelMap model, @ModelAttribute("role") Role role, @ModelAttribute("person") Person person, BindingResult result, SessionStatus status) {
        logger.info("processSubmit in add role");

        ServiceExecutionResult res = personService.validateAndSaveRoleForPerson(person,role);
        if (res.getErrorList().size() == 0){
            model.addAttribute("infoModel", "Role has been added.");
        } else {
            //show errors
        }

        model.addAttribute("person",person);
        
		return "addRole";
	}

    @InitBinder
    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
        DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
        binder.registerCustomEditor(Date.class, null, new CustomDateEditor(df, true));
        binder.registerCustomEditor(String.class,"phone.number", new PhoneEditor());
        binder.registerCustomEditor(String.class,"country", new CountryEditor());
        binder.registerCustomEditor(String.class,"region", new RegionEditor());
    }

    protected void readReferenceData(ModelMap model){
        model.put("countryLookup", referenceRepository.getCountries());
        model.put("campusLookup", referenceRepository.getCampuses());
        model.put("departmentLookup", referenceRepository.getDepartments());
        model.put("sponsorLookup", referenceRepository.getPeople());
    }

    protected String getPersonDisplayName(Person person){
        String name = person.getOfficialName().toString()  + " (ID: " + person.getId() + ")";
        return name;
    }

}<commit_msg>NOJIRA<commit_after>package org.openregistry.core.web;

import org.openregistry.core.domain.*;

import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.propertyeditors.CustomDateEditor;

import javax.servlet.http.HttpServletRequest;
import javax.annotation.Resource;

import org.javalid.core.AnnotationValidator;
import org.javalid.core.AnnotationValidatorImpl;
import org.javalid.core.ValidationMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import org.openregistry.core.web.propertyeditors.*;
import org.openregistry.core.service.PersonService;
import org.openregistry.core.service.ServiceExecutionResult;
import org.openregistry.core.repository.PersonRepository;
import org.openregistry.core.repository.ReferenceRepository;
import com.sun.xml.internal.bind.v2.TODO;

/**
 * @author <NAME>
 * @version $Revision$ $Date$
 * @since 1.0.0
 */
@Controller
@RequestMapping("/addRole.htm")
@SessionAttributes("role")
public class PersonRegistryController {

	protected final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private PersonService personService;

    @Autowired(required=true)
    private ReferenceRepository referenceRepository;

	@RequestMapping(method = RequestMethod.GET)
    public String addRoleSetUpForm(ModelMap model) {
    	logger.info("Populating: setUpForm: ");

        //fudge personKey
        Long personKey = new Long(5);
        Person person = personService.findPersonById(personKey);
        model.addAttribute("person",person);

        //fudge roleInfoKey
        Long roleInfoKey = new Long(2);
        RoleInfo roleInfo = referenceRepository.getRoleInfo(roleInfoKey);
        Role role = person.addRole(roleInfo);
        role.addEmailAddress();
        role.addPhone();
        role.addAddress();
        Calendar cal = Calendar.getInstance();
        role.setStart(cal.getTime());
        cal.add(Calendar.MONTH, 6);
        role.setEnd(cal.getTime());

        //add reference data
        readReferenceData(model);

        
        model.addAttribute("personDescription", getPersonDisplayName(person));
        model.addAttribute("affiliationTypeDescription", role.getAffiliationType().getDescription());
        model.addAttribute("title", role.getTitle());
        model.addAttribute("role",role);
        model.addAttribute("personKey", personKey.toString());
    	return "addRole";
    }

	@RequestMapping(method = RequestMethod.POST)
	public String addRoleProcessSubmit(ModelMap model, @ModelAttribute("role") Role role, BindingResult result, SessionStatus status ) {
        logger.info("processSubmit in add role");

        //fudge personKey
        Long pKey = new Long(5);
        Person person = personService.findPersonById(pKey);

        ServiceExecutionResult res = personService.validateAndSaveRoleForPerson(person,role);
        List errorList = res.getErrorList();
        if (errorList.size() == 0 && !result.hasErrors()){
            model.addAttribute("infoModel", "Role has been added.");
            //status.setComplete();
        } else {
            //show errors
            for (int i=0; i < errorList.size(); i++){
                ValidationMessage message = (ValidationMessage)errorList.get(i);
                result.reject(message.getMessage());
            }
        }

        model.addAttribute("role",role);
		return "addRole";
	}

    @InitBinder
    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
        DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
        binder.registerCustomEditor(Date.class, null, new CustomDateEditor(df, true));
        binder.registerCustomEditor(String.class,"phone.number", new PhoneEditor());
        binder.registerCustomEditor(Country.class,"addresses.country", new CountryEditor(referenceRepository));
        binder.registerCustomEditor(Region.class,"addresses.region", new RegionEditor(referenceRepository));
        binder.registerCustomEditor(Person.class,"sponsor", new SponsorEditor(referenceRepository));
        binder.registerCustomEditor(Department.class,"department", new DepartmentEditor(referenceRepository));
    }

    protected void readReferenceData(ModelMap model){
        model.put("countryLookup", referenceRepository.getCountries());
        model.put("campusLookup", referenceRepository.getCampuses());
        model.put("departmentLookup", referenceRepository.getDepartments());
        model.put("sponsorLookup", referenceRepository.getPeople());
    }

    protected String getPersonDisplayName(Person person){
        String name = person.getOfficialName().toString()  + " (ID: " + person.getId() + ")";
        return name;
    }

}
{'fraction_non_alphanumeric': 0.10942809981551607, 'fraction_numerical': 0.002136129721332168, 'mean_word_length': 3.748732134624251, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7155170', 'n_tokens_mistral': 2761, 'n_tokens_neox': 2696, 'n_words': 479}