Esempio n. 1
0
 @RequestMapping(
     value = "deletePerson",
     method = RequestMethod.POST,
     produces = "application/json")
 public @ResponseBody String deletePerson(@RequestBody Person person) {
   PersonDao personDao = (PersonDao) appContext.getBean("personDao");
   person.setEndDate(new Date());
   // personDao.delete(person);
   personDao.merge(person);
   return "OK";
 }
Esempio n. 2
0
  @RequestMapping(
      value = "inserisciBen",
      method = RequestMethod.POST,
      produces = "application/json")
  public @ResponseBody String inserisciBen(@RequestBody GlobalPerson globalPerson) {

    ProjectPerson projectPerson = globalPerson.getProjectPerson();
    Person person = globalPerson.getPerson();
    PersonDao personDao = (PersonDao) appContext.getBean("personDao");
    if (globalPerson != null && person != null && person.getPersonId() != null) {
      // sono in update
      List<Person> beneficiarioPresente =
          personDao.findById(globalPerson.getPerson().getPersonId());
      if (beneficiarioPresente.size() > 0) {
        addSibling(globalPerson, person);
        personDao.merge(person);
      }
    } else { // insert
      // sto aggiungendo un nominativo ma devo controllare se esiste gia a db. In tal caso introduco
      // solo ProjectPerson
      if (person.getFirstName() != null
          && person.getLastName() != null
          && person.getThirdName() != null) {
        String isNamePresent = personDao.checkNames(globalPerson);
        if (isNamePresent != null && "-1".equals(isNamePresent)) return "threeNamesError";
        if (isNamePresent != null && Integer.valueOf(isNamePresent) > 0) {
          person.setPersonId(Integer.valueOf(isNamePresent));
          ProjectPerson pp = new ProjectPerson();
          pp.setPersonId(Integer.valueOf(isNamePresent));
          pp.setProjectCode(globalPerson.getProjectPerson().getProjectCode());
          pp.setPersonCode(globalPerson.getProjectPerson().getPersonCode());
          Set<ProjectPerson> prS = new HashSet<ProjectPerson>();
          prS.add(pp);
          person.setProjectPersons(prS);
          personDao.merge(person);
          return "threeNamesAnotherProgram";
        }
      }
      if (person.getFirstName() != null
          && person.getLastName() != null
          && person.getVillage() != null) {
        String isNamePresent = personDao.checkNames(globalPerson);
        if (isNamePresent != null && "-3".equals(isNamePresent)) return "twoNamesVillagesError";
      }

      if (person.getFileNumber() != null) {
        String isFileNumberPresent = personDao.checkFileNumber(globalPerson);
        if (isFileNumberPresent != null) return "fileNumberError";
      }
      projectPerson.setPersonCode(projectPerson.getPersonCode());
      projectPerson.setProjectCode(projectPerson.getProjectCode());
      Set<ProjectPerson> prSet = new HashSet<ProjectPerson>();
      prSet.add(projectPerson);
      person.setProjectPersons(prSet);
      person.setPersonId(100);
      person.setInsertDate(new Date());

      addSibling(globalPerson, person);
      personDao.save(person);
    }

    return null;
  }