<commit_before>package com.dak.duty.api;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.method.P;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dak.duty.api.util.DutyNode;
import com.dak.duty.api.util.JsonResponse;
import com.dak.duty.api.util.JsonResponse.ResponseStatus;
import com.dak.duty.model.Person;
import com.dak.duty.repository.EventRepository;
import com.dak.duty.repository.PersonRepository;
import com.dak.duty.service.IntervalService;
import com.dak.duty.service.PersonService;

@Controller
@RequestMapping("/api/person")
@PreAuthorize("hasRole('ROLE_USER')")
public class PersonApi {

   private static final Logger logger = LoggerFactory.getLogger(PersonApi.class);

   @Autowired
   PersonRepository personRepos;

   @Autowired
   PersonService personService;

   @Autowired
   EventRepository eventRepos;
   
   @Autowired
   IntervalService intervalService;

   @Autowired
   BCryptPasswordEncoder encoder;

   @PreAuthorize("hasRole('ROLE_ADMIN')")
   @RequestMapping(method = RequestMethod.DELETE)
   public @ResponseBody JsonResponse delete(@RequestBody Person person){
      logger.debug("person.delete({})", person);

      person = personRepos.findOne(person.getId());
      person.setActive(false);
      personService.save(person);

      return new JsonResponse(ResponseStatus.OK, "Person " + person.getId() + " deleted");
   }

   @RequestMapping(value="/{id}", method = RequestMethod.GET)
   @PreAuthorize("#p.emailAddress == authentication.name or hasRole('ROLE_ADMIN')")
   public @ResponseBody Person get(@PathVariable("id") @P("p") Person person){
      logger.debug("person.get({})", person.getId());

      return person;
   }

   @RequestMapping(value="/{id}/upcomingDuties", method = RequestMethod.GET)
   @PreAuthorize("#p.emailAddress == authentication.name or hasRole('ROLE_ADMIN')")
   public @ResponseBody List<DutyNode> getUpcomingDuties(@PathVariable("id") @P("p") Person person){
      return personService.getUpcomingDuties(person);
   }


   @PreAuthorize("hasRole('ROLE_ADMIN')")
   @RequestMapping(method = RequestMethod.POST)
   public @ResponseBody JsonResponse save(@RequestBody Person person){
      logger.debug("person.save({})", person);
      
      person = personService.save(person);

      return new JsonResponse(ResponseStatus.OK, "Person saved with id " + person.getId());
   }

   @PreAuthorize("hasRole('ROLE_ADMIN')")
   @RequestMapping(value = "/password", method = RequestMethod.POST)
   public @ResponseBody JsonResponse setPassword(@RequestBody Person person){
      logger.debug("setPassword.save({})", person.getId());
<commit_msg>no longer outputting whole person to log (could possibly enclude pw in clear text if at some point we add password to add user view)<commit_after>package com.dak.duty.api;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.method.P;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dak.duty.api.util.DutyNode;
import com.dak.duty.api.util.JsonResponse;
import com.dak.duty.api.util.JsonResponse.ResponseStatus;
import com.dak.duty.model.Person;
import com.dak.duty.repository.EventRepository;
import com.dak.duty.repository.PersonRepository;
import com.dak.duty.service.IntervalService;
import com.dak.duty.service.PersonService;

@Controller
@RequestMapping("/api/person")
@PreAuthorize("hasRole('ROLE_USER')")
public class PersonApi {

   private static final Logger logger = LoggerFactory.getLogger(PersonApi.class);

   @Autowired
   PersonRepository personRepos;

   @Autowired
   PersonService personService;

   @Autowired
   EventRepository eventRepos;
   
   @Autowired
   IntervalService intervalService;

   @Autowired
   BCryptPasswordEncoder encoder;

   @PreAuthorize("hasRole('ROLE_ADMIN')")
   @RequestMapping(method = RequestMethod.DELETE)
   public @ResponseBody JsonResponse delete(@RequestBody Person person){
      logger.debug("person.delete({})", person);

      person = personRepos.findOne(person.getId());
      person.setActive(false);
      personService.save(person);

      return new JsonResponse(ResponseStatus.OK, "Person " + person.getId() + " deleted");
   }

   @RequestMapping(value="/{id}", method = RequestMethod.GET)
   @PreAuthorize("#p.emailAddress == authentication.name or hasRole('ROLE_ADMIN')")
   public @ResponseBody Person get(@PathVariable("id") @P("p") Person person){
      logger.debug("person.get({})", person.getId());

      return person;
   }

   @RequestMapping(value="/{id}/upcomingDuties", method = RequestMethod.GET)
   @PreAuthorize("#p.emailAddress == authentication.name or hasRole('ROLE_ADMIN')")
   public @ResponseBody List<DutyNode> getUpcomingDuties(@PathVariable("id") @P("p") Person person){
      return personService.getUpcomingDuties(person);
   }


   @PreAuthorize("hasRole('ROLE_ADMIN')")
   @RequestMapping(method = RequestMethod.POST)
   public @ResponseBody JsonResponse save(@RequestBody Person person){
      logger.debug("person.save({})", person.getEmailAddress());
      
      person = personService.save(person);

      return new JsonResponse(ResponseStatus.OK, "Person saved with id " + person.getId());
   }

   @PreAuthorize("hasRole('ROLE_ADMIN')")
   @RequestMapping(value = "/password", method = RequestMethod.POST)
   public @ResponseBody JsonResponse setPassword(@RequestBody Person person){
      logger.debug("setPassword.save({})", person.getId());

{'fraction_non_alphanumeric': 0.12471378415509082, 'fraction_numerical': 0.000610593802472905, 'mean_word_length': 5.336557059961315, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6430497', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1884, 'n_words': 344}