Package net.petrikainulainen.spring.datajpa.model

Examples of net.petrikainulainen.spring.datajpa.model.Person$Builder


    @RequestMapping(value = "/person/delete/{id}", method = RequestMethod.GET)
    public String delete(@PathVariable("id") Long id, RedirectAttributes attributes) {
        LOGGER.debug("Deleting person with id: " + id);

        try {
            Person deleted = personService.delete(id);
            addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_PERSON_DELETED, deleted.getName());
        } catch (PersonNotFoundException e) {
            LOGGER.debug("No person found with id: " + id);
            addErrorMessage(attributes, ERROR_MESSAGE_KEY_DELETED_PERSON_WAS_NOT_FOUND);
        }
View Full Code Here


        if (bindingResult.hasErrors()) {
            return PERSON_ADD_FORM_VIEW;
        }
               
        Person person = personService.create(created);

        addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_PERSON_CREATED, person.getName());

        return createRedirectViewPath(REQUEST_MAPPING_LIST);
    }
View Full Code Here

     */
    @RequestMapping(value = "/person/edit/{id}", method = RequestMethod.GET)
    public String showEditPersonForm(@PathVariable("id") Long id, Model model, RedirectAttributes attributes) {
        LOGGER.debug("Rendering edit person form for person with id: " + id);
       
        Person person = personService.findById(id);
        if (person == null) {
            LOGGER.debug("No person found with id: " + id);
            addErrorMessage(attributes, ERROR_MESSAGE_KEY_EDITED_PERSON_WAS_NOT_FOUND);
            return createRedirectViewPath(REQUEST_MAPPING_LIST);           
        }
View Full Code Here

            LOGGER.debug("Edit person form contains validation errors. Rendering form view.");
            return PERSON_EDIT_FORM_VIEW;
        }
       
        try {
            Person person = personService.update(updated);
            addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_PERSON_EDITED, person.getName());
        } catch (PersonNotFoundException e) {
            LOGGER.debug("No person was found with id: " + updated.getId());
            addErrorMessage(attributes, ERROR_MESSAGE_KEY_EDITED_PERSON_WAS_NOT_FOUND);
        }
       
View Full Code Here

    @Transactional
    @Override
    public Person create(PersonDTO created) {
        LOGGER.debug("Creating a new person with information: " + created);
       
        Person person = Person.getBuilder(created.getFirstName(), created.getLastName()).build();
       
        return personRepository.save(person);
    }
View Full Code Here

    @Transactional(rollbackFor = PersonNotFoundException.class)
    @Override
    public Person delete(Long personId) throws PersonNotFoundException {
        LOGGER.debug("Deleting person with id: " + personId);
       
        Person deleted = personRepository.findOne(personId);
       
        if (deleted == null) {
            LOGGER.debug("No person found with id: " + personId);
            throw new PersonNotFoundException();
        }
View Full Code Here

    @Transactional(rollbackFor = PersonNotFoundException.class)
    @Override
    public Person update(PersonDTO updated) throws PersonNotFoundException {
        LOGGER.debug("Updating person with information: " + updated);
       
        Person person = personRepository.findOne(updated.getId());
       
        if (person == null) {
            LOGGER.debug("No person found with id: " + updated.getId());
            throw new PersonNotFoundException();
        }
       
        person.update(updated.getFirstName(), updated.getLastName());

        return person;
    }
View Full Code Here

    }

    @Test
    public void create() {
        PersonDTO created = PersonTestUtil.createDTO(null, FIRST_NAME, LAST_NAME);
        Person persisted = PersonTestUtil.createModelObject(PERSON_ID, FIRST_NAME, LAST_NAME);
       
        when(personRepositoryMock.save(any(Person.class))).thenReturn(persisted);
       
        Person returned = personService.create(created);

        ArgumentCaptor<Person> personArgument = ArgumentCaptor.forClass(Person.class);
        verify(personRepositoryMock, times(1)).save(personArgument.capture());
        verifyNoMoreInteractions(personRepositoryMock);
View Full Code Here

        assertEquals(persisted, returned);
    }
   
    @Test
    public void delete() throws PersonNotFoundException {
        Person deleted = PersonTestUtil.createModelObject(PERSON_ID, FIRST_NAME, LAST_NAME);
        when(personRepositoryMock.findOne(PERSON_ID)).thenReturn(deleted);
       
        Person returned = personService.delete(PERSON_ID);
       
        verify(personRepositoryMock, times(1)).findOne(PERSON_ID);
        verify(personRepositoryMock, times(1)).delete(deleted);
        verifyNoMoreInteractions(personRepositoryMock);
       
View Full Code Here

        assertEquals(persons, returned);
    }

    @Test
    public void findById() {
        Person person = PersonTestUtil.createModelObject(PERSON_ID, FIRST_NAME, LAST_NAME);
        when(personRepositoryMock.findOne(PERSON_ID)).thenReturn(person);
       
        Person returned = personService.findById(PERSON_ID);
       
        verify(personRepositoryMock, times(1)).findOne(PERSON_ID);
        verifyNoMoreInteractions(personRepositoryMock);
       
        assertEquals(person, returned);
View Full Code Here

TOP

Related Classes of net.petrikainulainen.spring.datajpa.model.Person$Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.