@Log private Person createPerson(PersonDTO personDTO) throws DuplicateException, NullArgumentException { Person user = null; if (personDTO != null) { if (personDTO.getEmail() != null && personDTO.getPassword() != null) { try { user = em.createNamedQuery("Person.findByEmail", Person.class) .setParameter("email", personDTO.getEmail()) .getSingleResult(); } catch (NoResultException e) { } if (user == null) { Person persontemp = new Person(personDTO.getEmail()); persontemp.setName(personDTO.getFirstname()); persontemp.setSurname(personDTO.getSurname()); persontemp.setSsn(personDTO.getSsn()); persontemp.setPassword(getEncryptedPassword(personDTO.getPassword())); em.persist(persontemp); return persontemp; } else { throw new DuplicateException("Person already exists"); } } else { throw new NullArgumentException("Null argument for email or password"); } } return user; }
@Override public boolean createOrUpdatePerson( String electronicShopID, String clientID, String name, String family, String addressCity, String addressLine, String phoneNumber, String mail, String IBANNumber, String SWIFTCode) { // check if we know that shop if (!ConfigurationProperties.getElectronicShopID().equals(electronicShopID)) { logger.warning("electronicShopID \"" + electronicShopID + "\" not known!"); return false; } List<Client> cl = Client.queryGetByForeignID(clientID, 0, 1); List<Person> pl = null; Client c; if (cl.size() == 0) { c = new Client(); } else { c = cl.get(0); pl = Person.queryGetAll(0, 1, c.getID()); } Person p; if ((pl == null) || (pl.size() == 0)) { p = new Person(); } else { p = pl.get(0); } try { c.setForeignID(clientID); c.setAddressCity(addressCity); c.setAddressLine(addressLine); c.setMail(mail); c.setPhoneNumber(phoneNumber); c.setIBANNumber(IBANNumber); c.setSWIFTCode(SWIFTCode); p.setName(name); p.setFamily(family); c.setPerson(p); c.writeToDB(); } catch (RuntimeException e) { logger.log(Level.WARNING, "Can't write to DB!", e); return false; } return true; }
@Test public void testMinDistance() { MinDistance md = new MinDistance(); Person ThiagoCassioKrug = null; Person thiago = new Person(); thiago.setName("Thiago Cassio Krug"); thiago.setId(4); int i = persons.indexOf(thiago); if (i >= 0) { ThiagoCassioKrug = persons.get(i); md.computeScore(ThiagoCassioKrug, true); } else { fail("Não encontrou a pessoa da pesquisa!"); } Collections.sort(ThiagoCassioKrug.getRelationships()); List<Relationship> relationships = ThiagoCassioKrug.getRelationships(); int j = 0; assertEquals(relationships.get(j).getPerson2().getName(), "Marcelo Maia Lopes"); assertEquals(relationships.get(j++).getScore(), 0.99998153499579921154432062633294d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Bruno Vicelli"); assertEquals(relationships.get(j++).getScore(), 0.99998153499579921154432062633294d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafael Tavares Amorim"); assertEquals(relationships.get(j++).getScore(), 0.99991690748109645194944281849824d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Helison Reus Teixeira"); assertEquals(relationships.get(j++).getScore(), 0.99990767497899605772160313166471d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Thiago Aquino de Lima"); assertEquals(relationships.get(j++).getScore(), 0.99989844247689566349376344483118d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Mateus Henrique Dal Forno"); assertEquals(relationships.get(j++).getScore(), 0.9998061174558917212153665764959d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafhael Rodrigues Cunha"); assertEquals(relationships.get(j++).getScore(), 0.99959376990758265397505377932473d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Renan Marcel Uchôa"); assertEquals(relationships.get(j++).getScore(), 0.9993260273466712213677028611524d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Juliano Rodovalho Macedo"); assertEquals(relationships.get(j++).getScore(), 0.99711945934467700091401770793903d, delta); }
@Test public void testRelationshipOccurrenceNumber() { RelationshipOccurrenceNumber ron = new RelationshipOccurrenceNumber(); Person ThiagoCassioKrug = null; Person thiago = new Person(); thiago.setName("Thiago Cassio Krug"); thiago.setId(4); int i = persons.indexOf(thiago); if (i >= 0) { ThiagoCassioKrug = persons.get(i); ron.computeScore(ThiagoCassioKrug, true); } else { fail("Não encontrou a pessoa da pesquisa!"); } Collections.sort(ThiagoCassioKrug.getRelationships()); List<Relationship> relationships = ThiagoCassioKrug.getRelationships(); int j = 0; assertEquals(relationships.get(j).getPerson2().getName(), "Rafhael Rodrigues Cunha"); assertEquals(relationships.get(j++).getScore(), 1.0d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Helison Reus Teixeira"); assertEquals(relationships.get(j++).getScore(), 0.9333333333333333d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafael Tavares Amorim"); assertEquals(relationships.get(j++).getScore(), 0.9333333333333333d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Bruno Vicelli"); assertEquals(relationships.get(j++).getScore(), 0.8d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Mateus Henrique Dal Forno"); assertEquals(relationships.get(j++).getScore(), 0.8d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Renan Marcel Uchôa"); assertEquals(relationships.get(j++).getScore(), 0.7333333333333333d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Marcelo Maia Lopes"); assertEquals(relationships.get(j++).getScore(), 0.6666666666666666d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Thiago Aquino de Lima"); assertEquals(relationships.get(j++).getScore(), 0.6666666666666666d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Juliano Rodovalho Macedo"); assertEquals(relationships.get(j++).getScore(), 0.3333333333333333d, delta); }
@Test public void testMaxDistance() { MaxDistance md = new MaxDistance(); Person ThiagoCassioKrug = null; Person thiago = new Person(); thiago.setName("Thiago Cassio Krug"); thiago.setId(4); int i = persons.indexOf(thiago); if (i >= 0) { ThiagoCassioKrug = persons.get(i); md.computeScore(ThiagoCassioKrug, true); } else { fail("Não encontrou a pessoa da pesquisa!"); } Collections.sort(ThiagoCassioKrug.getRelationships()); List<Relationship> relationships = ThiagoCassioKrug.getRelationships(); int j = 0; assertEquals(relationships.get(j).getPerson2().getName(), "Marcelo Maia Lopes"); assertEquals(relationships.get(j++).getScore(), 0.98147960078660917895358821194132d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Bruno Vicelli"); assertEquals(relationships.get(j++).getScore(), 0.98142420577400681358655009094015d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Helison Reus Teixeira"); assertEquals(relationships.get(j++).getScore(), 0.97165621855178972053216142106672d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Renan Marcel Uchôa"); assertEquals(relationships.get(j++).getScore(), 0.87781706720338278876958444508046d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Juliano Rodovalho Macedo"); assertEquals(relationships.get(j++).getScore(), 0.80018095704116772686565786193716d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Mateus Henrique Dal Forno"); assertEquals(relationships.get(j++).getScore(), 0.78367324328566284748829780358775d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafael Tavares Amorim"); assertEquals(relationships.get(j++).getScore(), 0.62412637448875019619066963337734d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Thiago Aquino de Lima"); assertEquals(relationships.get(j++).getScore(), 0.24201157755763389436171096728925d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafhael Rodrigues Cunha"); assertEquals(relationships.get(j++).getScore(), 0.0d, delta); }
@Test public void testAverageDistance() { AverageDistance ad = new AverageDistance(); Person ThiagoCassioKrug = null; Person thiago = new Person(); thiago.setName("Thiago Cassio Krug"); thiago.setId(4); int i = persons.indexOf(thiago); if (i >= 0) { ThiagoCassioKrug = persons.get(i); ad.computeScore(ThiagoCassioKrug, true); } else { fail("Não encontrou a pessoa da pesquisa!"); } Collections.sort(ThiagoCassioKrug.getRelationships()); List<Relationship> relationships = ThiagoCassioKrug.getRelationships(); int j = 0; assertEquals(relationships.get(j).getPerson2().getName(), "Marcelo Maia Lopes"); assertEquals(relationships.get(j++).getScore(), 0.99972302493698817316480939499414d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Bruno Vicelli"); assertEquals(relationships.get(j++).getScore(), 0.99969224992998685907201043888237d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Helison Reus Teixeira"); assertEquals(relationships.get(j++).getScore(), 0.99966455242368567638849137838179d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Mateus Henrique Dal Forno"); assertEquals(relationships.get(j++).getScore(), 0.99941835236767516364609972948769d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Renan Marcel Uchôa"); assertEquals(relationships.get(j++).getScore(), 0.99847355965273482099717177685658d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafhael Rodrigues Cunha"); assertEquals(relationships.get(j++).getScore(), 0.99832583961912851335173678752012d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafael Tavares Amorim"); assertEquals(relationships.get(j++).getScore(), 0.99739643440768882774920831294489d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Thiago Aquino de Lima"); assertEquals(relationships.get(j++).getScore(), 0.98303066113947540923065559997415d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Juliano Rodovalho Macedo"); assertEquals(relationships.get(j++).getScore(), 0.97067295707809773526723477329591d, delta); }