Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finding and filling out a tiny bit of PersonPart
- Loading branch information
Ole Friis Østergaard
committed
May 25, 2011
1 parent
df4e040
commit 68dc604
Showing
24 changed files
with
385 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
subprojects/hibernate-common-test/hibernate-common-test.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// The contents of this file are subject to the Mozilla Public | ||
// License Version 1.1 (the "License"); you may not use this file | ||
// except in compliance with the License. You may obtain a copy of | ||
// the License at http://www.mozilla.org/MPL/ | ||
// | ||
// Software distributed under the License is distributed on an "AS | ||
// IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
// implied. See the License for the specific language governing | ||
// rights and limitations under the License. | ||
// | ||
// Contributor(s): Contributors are attributed in the source code | ||
// where applicable. | ||
// | ||
// The Original Code is "Stamdata". | ||
// | ||
// The Initial Developer of the Original Code is Trifork Public A/S. | ||
// | ||
// Portions created for the Original Code are Copyright 2011, | ||
// Lægemiddelstyrelsen. All Rights Reserved. | ||
// | ||
// Portions created for the FMKi Project are Copyright 2011, | ||
// National Board of e-Health (NSI). All Rights Reserved. | ||
|
||
dependencies { | ||
|
||
compile project(':shared') | ||
|
||
// Guice | ||
|
||
compile libs.guice_servlet | ||
|
||
// Hibernate | ||
|
||
compile libs.hibernate_entitymanager | ||
compile libs.commons_lang | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
subprojects/lookup/src/main/java/com/trifork/stamdata/lookup/dao/CurrentPersonData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.trifork.stamdata.lookup.dao; | ||
|
||
import java.util.Date; | ||
|
||
import com.trifork.stamdata.views.cpr.Person; | ||
|
||
public class CurrentPersonData { | ||
|
||
private final Person person; | ||
|
||
public CurrentPersonData(Person person) { | ||
this.person = person; | ||
} | ||
|
||
public Date getValidFrom() { | ||
return person.validFrom; | ||
} | ||
|
||
public String getCprNumber() { | ||
return person.cpr; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
subprojects/lookup/src/main/java/com/trifork/stamdata/lookup/dao/PersonDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.trifork.stamdata.lookup.dao; | ||
|
||
import java.util.Date; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.criterion.Order; | ||
import org.hibernate.criterion.Restrictions; | ||
|
||
import com.trifork.stamdata.views.cpr.Person; | ||
|
||
public class PersonDao { | ||
|
||
private final Session session; | ||
|
||
@Inject | ||
public PersonDao(Session session) { | ||
this.session = session; | ||
} | ||
|
||
public CurrentPersonData get(String cpr) { | ||
Person person = (Person) session | ||
.createCriteria(Person.class) | ||
.add(Restrictions.eq("cpr", cpr)) | ||
.add(Restrictions.le("validFrom", new Date())) | ||
.addOrder(Order.desc("validFrom")) | ||
.setMaxResults(1) | ||
.uniqueResult(); | ||
return new CurrentPersonData(person); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ects/lookup/src/main/java/com/trifork/stamdata/lookup/personpart/PersonPartConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.trifork.stamdata.lookup.personpart; | ||
|
||
import oio.sagdok.person._1_0.AttributListeType; | ||
import oio.sagdok.person._1_0.CprBorgerType; | ||
import oio.sagdok.person._1_0.PersonType; | ||
import oio.sagdok.person._1_0.RegisterOplysningType; | ||
import oio.sagdok.person._1_0.RegistreringType; | ||
|
||
import com.trifork.stamdata.lookup.dao.CurrentPersonData; | ||
|
||
public class PersonPartConverter { | ||
|
||
public PersonType convert(CurrentPersonData person) { | ||
PersonType result = new PersonType(); | ||
result.getRegistrering().add(createRegistreringType(person)); | ||
return result; | ||
} | ||
|
||
private RegistreringType createRegistreringType(CurrentPersonData person) { | ||
RegistreringType result = new RegistreringType(); | ||
result.setAttributListe(createAttributListeType(person)); | ||
return result; | ||
} | ||
|
||
private AttributListeType createAttributListeType(CurrentPersonData person) { | ||
AttributListeType result = new AttributListeType(); | ||
result.getRegisterOplysning().add(createRegisterOplysningType(person)); | ||
return result; | ||
} | ||
|
||
private RegisterOplysningType createRegisterOplysningType(CurrentPersonData person) { | ||
RegisterOplysningType result = new RegisterOplysningType(); | ||
result.setCprBorger(createCprBorgerType(person)); | ||
return result; | ||
} | ||
|
||
private CprBorgerType createCprBorgerType(CurrentPersonData person) { | ||
CprBorgerType result = new CprBorgerType(); | ||
result.setPersonCivilRegistrationIdentifier(person.getCprNumber()); | ||
return result; | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
subprojects/lookup/src/main/java/com/trifork/stamdata/lookup/rest/HelloWorldResource.java
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
subprojects/lookup/src/main/java/com/trifork/stamdata/lookup/rest/PersonResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.trifork.stamdata.lookup.rest; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.xml.bind.JAXBElement; | ||
|
||
import oio.sagdok.person._1_0.PersonType; | ||
|
||
import com.trifork.stamdata.lookup.dao.CurrentPersonData; | ||
import com.trifork.stamdata.lookup.dao.PersonDao; | ||
import com.trifork.stamdata.lookup.personpart.PersonPartConverter; | ||
|
||
@Path("person/{cpr}") | ||
public class PersonResource { | ||
private final PersonDao personDao; | ||
private final PersonPartConverter personPartConverter; | ||
|
||
@Inject | ||
public PersonResource(PersonDao personDao, PersonPartConverter personPartConverter) { | ||
this.personDao = personDao; | ||
this.personPartConverter = personPartConverter; | ||
} | ||
|
||
@GET | ||
@Produces("text/xml") | ||
public JAXBElement<PersonType> getPerson(@PathParam("cpr") String cpr) { | ||
CurrentPersonData person = personDao.get(cpr); | ||
PersonType personPart = personPartConverter.convert(person); | ||
return new oio.sagdok.person._1_0.ObjectFactory().createPerson(personPart); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
subprojects/lookup/src/test/java/com/trifork/stamdata/lookup/dao/PersonDaoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.trifork.stamdata.lookup.dao; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
import org.hibernate.classic.Session; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import com.trifork.stamdata.replication.DatabaseHelper; | ||
import com.trifork.stamdata.views.cpr.Person; | ||
|
||
public class PersonDaoTest { | ||
private static DatabaseHelper db; | ||
private Session session; | ||
private PersonDao dao; | ||
|
||
@BeforeClass | ||
public static void beforeClass() throws Exception { | ||
db = new DatabaseHelper("lookup", Person.class); | ||
Session session = db.openSession(); | ||
session.createQuery("delete from Person").executeUpdate(); | ||
session.close(); | ||
} | ||
|
||
@Before | ||
public void before() { | ||
session = db.openSession(); | ||
session.getTransaction().begin(); | ||
dao = new PersonDao(session); | ||
} | ||
|
||
@After | ||
public void after() { | ||
session.getTransaction().rollback(); | ||
session.close(); | ||
} | ||
|
||
@Test | ||
public void givesCurrentPersonDataWithContentsFromUnderlyingView() { | ||
session.save(person(at(2005, Calendar.JANUARY, 5))); | ||
|
||
CurrentPersonData person = dao.get("1020304050"); | ||
assertEquals("1020304050", person.getCprNumber()); | ||
assertEquals(at(2005, Calendar.JANUARY, 5), person.getValidFrom()); | ||
} | ||
|
||
@Test | ||
public void getsNewestPersonRecordIfNoRecordIsInTheFuture() { | ||
session.save(person(at(2005, Calendar.JANUARY, 5))); | ||
session.save(person(at(2010, Calendar.FEBRUARY, 10))); | ||
|
||
CurrentPersonData person = dao.get("1020304050"); | ||
assertEquals(at(2010, Calendar.FEBRUARY, 10), person.getValidFrom()); | ||
} | ||
|
||
@Test | ||
public void getsCurrentPersonRecordIfRecordsInTheFuture() { | ||
session.save(person(at(2005, Calendar.JANUARY, 5))); | ||
session.save(person(at(2010, Calendar.FEBRUARY, 10))); | ||
session.save(person(at(2110, Calendar.FEBRUARY, 10))); | ||
|
||
CurrentPersonData person = dao.get("1020304050"); | ||
assertEquals(at(2010, Calendar.FEBRUARY, 10), person.getValidFrom()); | ||
} | ||
|
||
private Person person(Date validFrom) { | ||
Person result = new Person(); | ||
result.cpr = "1020304050"; | ||
result.koen = "M"; | ||
result.foedselsdato = at(1975, Calendar.MAY, 12); | ||
result.modifiedBy = "AHJ"; | ||
result.createdBy = "AHJ"; | ||
result.validFrom = validFrom; | ||
result.modifiedDate = validFrom; | ||
result.createdDate = at(2005, Calendar.JANUARY, 5); | ||
return result; | ||
} | ||
|
||
private Date at(int year, int month, int day) { | ||
Calendar calendar = Calendar.getInstance(); | ||
calendar.clear(); | ||
calendar.set(Calendar.YEAR, year); | ||
calendar.set(Calendar.MONTH, month); | ||
calendar.set(Calendar.DAY_OF_MONTH, day); | ||
return calendar.getTime(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../lookup/src/test/java/com/trifork/stamdata/lookup/personpart/PersonPartConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.trifork.stamdata.lookup.personpart; | ||
|
||
import static org.junit.Assert.*; | ||
import oio.sagdok.person._1_0.PersonType; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.trifork.stamdata.lookup.dao.CurrentPersonData; | ||
import com.trifork.stamdata.views.cpr.Person; | ||
|
||
|
||
public class PersonPartConverterTest { | ||
private PersonPartConverter converter; | ||
|
||
@Before | ||
public void before() { | ||
converter = new PersonPartConverter(); | ||
} | ||
|
||
@Test | ||
public void fillsOutCprNumber() { | ||
Person person = new Person(); | ||
person.cpr = "1020304050"; | ||
CurrentPersonData currentPerson = new CurrentPersonData(person); | ||
|
||
PersonType personType = converter.convert(currentPerson); | ||
assertEquals("1020304050", personType.getRegistrering().get(0).getAttributListe().getRegisterOplysning().get(0).getCprBorger().getPersonCivilRegistrationIdentifier()); | ||
} | ||
} |
Oops, something went wrong.