@Before
  public void setUp() {

    repository.deleteAll();

    dave = repository.save(new Person("Dave", "Matthews"));
    oliver = repository.save(new Person("Oliver August", "Matthews"));
    carter = repository.save(new Person("Carter", "Beauford"));
  }
コード例 #2
0
 @Test
 public void shouldSavePerson() {
   Person person = new Person();
   person.setName("Foo Bar");
   person.setEmail("*****@*****.**");
   person.setGender(new Gender(Value.MALE));
   person = personRespository.save(person);
   Person expectedPerson = personRespository.getPersonById(person.getId());
   assertEquals(expectedPerson.getName(), person.getName());
   assertEquals(expectedPerson.getGender(), person.getGender());
   assertEquals(expectedPerson.getEmail(), person.getEmail());
 }
コード例 #3
0
 @Test(expected = ValidationException.class)
 public void shouldCheckNameLength() {
   Person person = new Person();
   person.setEmail("*****@*****.**");
   person.setName("f");
   person = personRespository.save(person);
 }
コード例 #4
0
 @Test(expected = ValidationException.class)
 public void shouldCheckValidCharacters_InEmail() {
   Person person = new Person();
   person.setEmail("foo@bar");
   person.setName("Ff hhh");
   person = personRespository.save(person);
 }
  /**
   * Note that the object conversions are performed during stream processing as one can see from the
   * {@link LoggingEventListener} output that is printed to the console.
   */
  @Test
  public void shouldPerformConversionDuringJava8StreamProcessing() {

    // TODO: 01 - Support for Streams

    try (Stream<Person> result = repository.findAllByCustomQueryWithStream()) {
      result.forEach(System.out::println);
    }
  }
コード例 #6
0
  @Override
  public void run(String... strings) throws Exception {

    Person greg = new Person("Greg");
    Person roy = new Person("Roy");
    Person craig = new Person("Craig");

    System.out.println("Before linking up with Neo4j...");
    for (Person person : new Person[] {greg, roy, craig}) {
      System.out.println(person);
    }

    Transaction tx = graphDatabase.beginTx();
    try {
      personRepository.save(greg);
      personRepository.save(roy);
      personRepository.save(craig);

      greg = personRepository.findByName(greg.name);
      greg.worksWith(roy);
      greg.worksWith(craig);
      personRepository.save(greg);

      roy = personRepository.findByName(roy.name);
      roy.worksWith(craig);
      // We already know that roy works with greg
      personRepository.save(roy);

      // We already know craig works with roy and greg

      System.out.println("Lookup each person by name...");
      for (String name : new String[] {greg.name, roy.name, craig.name}) {
        System.out.println(personRepository.findByName(name));
      }

      System.out.println("Looking up who works with Greg...");
      for (Person person : personRepository.findByTeammatesName("Greg")) {
        System.out.println(person.name + " works with Greg.");
      }

      tx.success();
    } finally {

      // tx.close();
    }
  }
コード例 #7
0
  /**
   * Move All Sor Records from one person to another.
   *
   * @param fromPerson person losing sor records.
   * @param toPerson person receiving sor records.
   * @return Result of move. Validation errors if they occurred or the Person receiving sor records.
   */
  public boolean moveAllSystemOfRecordPerson(Person fromPerson, Person toPerson) {
    // get the list of sor person records that will be moving.
    List<SorPerson> sorPersonList = personRepository.getSoRRecordsForPerson(fromPerson);

    // move each sorRecord
    for (final SorPerson sorPerson : sorPersonList) {
      moveSystemOfRecordPerson(fromPerson, toPerson, sorPerson);
    }

    Set<? extends Identifier> oldIdentifiers = fromPerson.getIdentifiers();
    Set<? extends IdCard> oldIdCards = fromPerson.getIdCards();

    this.personRepository.deletePerson(fromPerson);
    logger.info("moveAllSystemOfRecordPerson: Deleted From Person");
    for (Identifier identifier : oldIdentifiers) {

      if (toPerson.getIdentifiersByType().get(identifier.getType().getName()) == null) {
        Identifier oldIdentifierAttachedTotoPerson =
            toPerson.addIdentifier(identifier.getType(), identifier.getValue());
        /// if type of this identifier don't exist then add this identifier as primary and not
        // deleted

        oldIdentifierAttachedTotoPerson.setDeleted(false);
        oldIdentifierAttachedTotoPerson.setPrimary(true);
      }
      // and if this exist then add this identifier as deleted and no primary
      else {
        Identifier oldIdentifierAttachedTotoPerson =
            toPerson.addIdentifier(identifier.getType(), identifier.getValue());
        /// if type of this identifier don't exist then add this identifier as primary and not
        // deleted

        oldIdentifierAttachedTotoPerson.setDeleted(true);
        oldIdentifierAttachedTotoPerson.setPrimary(false);
        ;
      }
    }
    for (IdCard oldIdCard : oldIdCards) {
      if (toPerson.getPrimaryIdCard() == null) {
        toPerson.addIDCard(oldIdCard);
      } else {
        if (oldIdCard.isPrimary()) oldIdCard.setPrimary(false);
        toPerson.addIDCard(oldIdCard);
      }
    }

    this.personRepository.savePerson(toPerson);

    return true;
  }
コード例 #8
0
ファイル: Application.java プロジェクト: glalit/spring-guides
  @Override
  public void run(String... strings) throws Exception {
    Person greg = new Person("Greg");
    Person craig = new Person("Craig");
    Person roy = new Person("Roy");

    List<Person> people = Arrays.asList(greg, craig, roy);

    System.out.println("Before linking up with Neo4j...");
    people.stream().forEach(System.out::println);

    try (Transaction tx = graphDatabase.beginTx()) {
      personRepository.save(greg);
      personRepository.save(craig);
      personRepository.save(roy);

      greg = personRepository.findByName(greg.name);
      greg.worksWith(roy);
      greg.worksWith(craig);
      personRepository.save(greg);

      roy = personRepository.findByName(roy.name);
      roy.worksWith(craig);
      personRepository.save(roy);

      System.out.println("Lookup each person by name...");
      people
          .stream()
          .map(Person::getName)
          .map(personRepository::findByName)
          .forEach(System.out::println);

      System.out.println("Lookup who works with Greg...");
      StreamSupport.stream(personRepository.findByTeammatesName("Greg").spliterator(), false)
          .map(Person::getName)
          .forEach(name -> System.out.println(name + " works with Greg"));
      tx.success();
    }
  }
コード例 #9
0
 @RequestMapping
 public List<Person> findAll() {
   return personRepository.findAll();
 }
コード例 #10
0
 @Override
 @Transactional(propagation = Propagation.SUPPORTS)
 public Person findPersonById(Long id) {
   Person person = personRepository.findById(id);
   return person;
 }
コード例 #11
0
 @Override
 @Transactional(propagation = Propagation.SUPPORTS)
 public Person findPersonByLastname(String lastname) {
   Person person = personRepository.findByLastname(lastname);
   return person;
 }
コード例 #12
0
 @Override
 @Transactional(propagation = Propagation.SUPPORTS)
 public Integer getAmountOfPerson() {
   Integer amount = personRepository.getAmount();
   return amount;
 }
コード例 #13
0
 @Override
 @Transactional(propagation = Propagation.SUPPORTS)
 public Collection<Person> findAllPersons() {
   Collection<Person> persons = personRepository.findAll();
   return persons;
 }
コード例 #14
0
 @Override
 @Transactional(propagation = Propagation.REQUIRED)
 public Person createPerson(Person person) {
   Person personCreated = personRepository.save(person);
   return personCreated;
 }
コード例 #15
0
 /** This method is secured with annotation */
 @PreAuthorize("#oauth2.hasScope('write') and hasRole('ROLE_KILLER')")
 @ResponseStatus(HttpStatus.OK)
 @RequestMapping(method = RequestMethod.DELETE, value = "/{personId}")
 public void delete(@PathVariable final Long personId) {
   personRepository.delete(personId);
 }
 /**
  * Note that the all object conversions are performed before the results are printed to the
  * console.
  */
 @Test
 public void shouldPerformConversionBeforeResultProcessing() {
   repository.findAll().forEach(System.out::println);
 }
コード例 #17
0
 /** This method is secured in config */
 @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
 public Person create(@RequestBody final Person person) {
   return personRepository.saveAndFlush(person);
 }
コード例 #18
0
 @Test(expected = ValidationException.class)
 public void shouldCheckEmptyEmail() {
   Person person = new Person();
   person.setName("foo bar");
   person = personRespository.save(person);
 }