dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24560
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12063: person-controller, wip
------------------------------------------------------------
revno: 12063
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-09-12 13:20:41 +0200
message:
person-controller, wip
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/AbstractPersonService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Contact.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/DateOfBirth.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Identifier.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/JacksonPersonService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Person.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/PersonService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java 2013-09-12 08:43:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java 2013-09-12 11:20:41 +0000
@@ -50,7 +50,7 @@
/**
* @author Abyot Asalefew Gizaw
*/
-@JacksonXmlRootElement( localName = "person", namespace = DxfNamespaces.DXF_2_0 )
+@JacksonXmlRootElement(localName = "person", namespace = DxfNamespaces.DXF_2_0)
public class Patient
extends BaseIdentifiableObject
{
@@ -141,9 +141,9 @@
}
@JsonProperty
- @JsonSerialize( as = BaseIdentifiableObject.class )
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JsonSerialize(as = BaseIdentifiableObject.class)
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public OrganisationUnit getOrganisationUnit()
{
return organisationUnit;
@@ -155,8 +155,8 @@
}
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public String getGender()
{
return gender;
@@ -168,8 +168,8 @@
}
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Date getBirthDate()
{
return birthDate;
@@ -181,8 +181,8 @@
}
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Date getDeathDate()
{
return deathDate;
@@ -194,8 +194,8 @@
}
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Boolean getIsDead()
{
return isDead;
@@ -217,9 +217,9 @@
}
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlElementWrapper( localName = "programs", namespace = DxfNamespaces.DXF_2_0 )
- @JacksonXmlProperty( localName = "program", namespace = DxfNamespaces.DXF_2_0 )
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlElementWrapper(localName = "programs", namespace = DxfNamespaces.DXF_2_0)
+ @JacksonXmlProperty(localName = "program", namespace = DxfNamespaces.DXF_2_0)
public Set<Program> getPrograms()
{
return programs;
@@ -231,9 +231,9 @@
}
@JsonProperty
- @JsonSerialize( as = BaseIdentifiableObject.class )
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JsonSerialize(as = BaseIdentifiableObject.class)
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public User getHealthWorker()
{
return healthWorker;
@@ -245,8 +245,8 @@
}
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Date getRegistrationDate()
{
return registrationDate;
@@ -258,9 +258,9 @@
}
@JsonProperty
- @JsonSerialize( as = BaseIdentifiableObject.class )
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JsonSerialize(as = BaseIdentifiableObject.class)
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Patient getRepresentative()
{
return representative;
@@ -309,6 +309,11 @@
public int getIntegerValueOfAge()
{
+ return getIntegerValueOfAge( birthDate );
+ }
+
+ public static int getIntegerValueOfAge( Date birthDate )
+ {
if ( birthDate == null )
{
return 0;
@@ -334,7 +339,7 @@
return age;
}
- public void setBirthDateFromAge( int age, char ageType )
+ public static Date getBirthFromAge( int age, char ageType )
{
Calendar todayCalendar = Calendar.getInstance();
todayCalendar.clear( Calendar.MILLISECOND );
@@ -359,7 +364,13 @@
todayCalendar.add( Calendar.DATE, -1 * age );
}
- setBirthDate( todayCalendar.getTime() );
+ return todayCalendar.getTime();
+ }
+
+ public void setBirthDateFromAge( int age, char ageType )
+ {
+ Date fromAge = getBirthFromAge( age, ageType );
+ setBirthDate( fromAge );
}
public char getAgeType()
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/AbstractPersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/AbstractPersonService.java 2013-09-12 07:19:15 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/AbstractPersonService.java 2013-09-12 11:20:41 +0000
@@ -28,8 +28,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.i18n.I18nManager;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.patient.PatientIdentifier;
@@ -57,15 +55,14 @@
@Autowired
private PatientService patientService;
- @Autowired
- private I18nManager i18nManager;
-
- private I18nFormat format;
-
// -------------------------------------------------------------------------
// Implementation
// -------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
+ // READ
+ // -------------------------------------------------------------------------
+
@Override
public Persons getPersons()
{
@@ -162,8 +159,19 @@
person.setContact( contact );
}
- DateOfBirth dateOfBirth = new DateOfBirth( patient.getBirthDate(),
- DateOfBirthType.fromString( String.valueOf( patient.getDobType() ) ) );
+ DateOfBirth dateOfBirth;
+
+ if ( patient.getDobType().equals( Patient.DOB_TYPE_VERIFIED ) || patient.getDobType().equals( Patient.DOB_TYPE_DECLARED ) )
+ {
+ dateOfBirth = new DateOfBirth( patient.getBirthDate(),
+ DateOfBirthType.fromString( String.valueOf( patient.getDobType() ) ) );
+ }
+ else
+ {
+ // assume APPROXIMATE
+ dateOfBirth = new DateOfBirth( patient.getIntegerValueOfAge() );
+ }
+
person.setDateOfBirth( dateOfBirth );
person.setDateOfRegistration( patient.getRegistrationDate() );
@@ -184,25 +192,35 @@
Patient patient = new Patient();
-
return patient;
}
+ // -------------------------------------------------------------------------
+ // UPDATE
+ // -------------------------------------------------------------------------
+
@Override
public void savePerson( Person person )
{
+ System.err.println( "SAVE: " + person );
Patient patient = getPatient( person );
}
@Override
public void updatePerson( Person person )
{
+ System.err.println( "UPDATE: " + person );
Patient patient = getPatient( person );
}
+ // -------------------------------------------------------------------------
+ // DELETE
+ // -------------------------------------------------------------------------
+
@Override
public void deletePerson( Person person )
{
+ System.err.println( "DELETE:" + person );
Patient patient = patientService.getPatient( person.getPerson() );
if ( patient != null )
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Contact.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Contact.java 2013-09-10 14:11:48 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Contact.java 2013-09-12 11:20:41 +0000
@@ -56,4 +56,31 @@
{
this.phoneNumber = phoneNumber;
}
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o ) return true;
+ if ( o == null || getClass() != o.getClass() ) return false;
+
+ Contact contact = (Contact) o;
+
+ if ( phoneNumber != null ? !phoneNumber.equals( contact.phoneNumber ) : contact.phoneNumber != null ) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return phoneNumber != null ? phoneNumber.hashCode() : 0;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Contact{" +
+ "phoneNumber='" + phoneNumber + '\'' +
+ '}';
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/DateOfBirth.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/DateOfBirth.java 2013-09-10 14:11:48 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/DateOfBirth.java 2013-09-12 11:20:41 +0000
@@ -32,19 +32,22 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.patient.Patient;
import java.util.Date;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@JacksonXmlRootElement( localName = "dateOfBirth", namespace = DxfNamespaces.DXF_2_0 )
+@JacksonXmlRootElement(localName = "dateOfBirth", namespace = DxfNamespaces.DXF_2_0)
public class DateOfBirth
{
private Date date;
private DateOfBirthType type;
+ private Integer age;
+
public DateOfBirth()
{
}
@@ -52,17 +55,26 @@
public DateOfBirth( Date date )
{
this.date = date;
+ this.age = Patient.getIntegerValueOfAge( date );
this.type = DateOfBirthType.VERIFIED;
}
public DateOfBirth( Date date, DateOfBirthType type )
{
this.date = date;
+ this.age = Patient.getIntegerValueOfAge( date );
this.type = type;
}
- @JsonProperty( required = true )
- @JacksonXmlProperty( isAttribute = true )
+ public DateOfBirth( Integer age )
+ {
+ this.age = age;
+ this.date = Patient.getBirthFromAge( age, Patient.AGE_TYPE_YEAR );
+ this.type = DateOfBirthType.APPROXIMATE;
+ }
+
+ @JsonProperty(required = true)
+ @JacksonXmlProperty(isAttribute = true)
public Date getDate()
{
return date;
@@ -74,4 +86,42 @@
{
return type;
}
+
+ @JsonProperty( required = true )
+ @JacksonXmlProperty( isAttribute = true )
+ public Integer getAge()
+ {
+ return age;
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o ) return true;
+ if ( o == null || getClass() != o.getClass() ) return false;
+
+ DateOfBirth that = (DateOfBirth) o;
+
+ if ( date != null ? !date.equals( that.date ) : that.date != null ) return false;
+ if ( type != that.type ) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = date != null ? date.hashCode() : 0;
+ result = 31 * result + (type != null ? type.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "DateOfBirth{" +
+ "date=" + date +
+ ", type=" + type +
+ '}';
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Identifier.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Identifier.java 2013-09-10 15:36:21 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Identifier.java 2013-09-12 11:20:41 +0000
@@ -81,4 +81,35 @@
{
this.value = value;
}
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o ) return true;
+ if ( o == null || getClass() != o.getClass() ) return false;
+
+ Identifier that = (Identifier) o;
+
+ if ( type != null ? !type.equals( that.type ) : that.type != null ) return false;
+ if ( value != null ? !value.equals( that.value ) : that.value != null ) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = type != null ? type.hashCode() : 0;
+ result = 31 * result + (value != null ? value.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Identifier{" +
+ "type='" + type + '\'' +
+ ", value='" + value + '\'' +
+ '}';
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/JacksonPersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/JacksonPersonService.java 2013-09-11 12:12:22 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/JacksonPersonService.java 2013-09-12 11:20:41 +0000
@@ -54,25 +54,25 @@
private static ObjectMapper xmlMapper = new XmlMapper();
private static ObjectMapper jsonMapper = new ObjectMapper();
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
private static <T> T fromXml( InputStream inputStream, Class<?> clazz ) throws IOException
{
return (T) xmlMapper.readValue( inputStream, clazz );
}
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
private static <T> T fromXml( String input, Class<?> clazz ) throws IOException
{
return (T) xmlMapper.readValue( input, clazz );
}
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
private static <T> T fromJson( InputStream inputStream, Class<?> clazz ) throws IOException
{
return (T) jsonMapper.readValue( inputStream, clazz );
}
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
private static <T> T fromJson( String input, Class<?> clazz ) throws IOException
{
return (T) jsonMapper.readValue( input, clazz );
@@ -88,6 +88,10 @@
jsonMapper.configure( DeserializationFeature.WRAP_EXCEPTIONS, true );
}
+ // -------------------------------------------------------------------------
+ // CREATE
+ // -------------------------------------------------------------------------
+
@Override
public void savePersonXml( InputStream inputStream ) throws IOException
{
@@ -129,4 +133,26 @@
savePerson( person );
}
}
+
+ // -------------------------------------------------------------------------
+ // UPDATE
+ // -------------------------------------------------------------------------
+
+ @Override
+ public void updatePersonXml( String id, InputStream inputStream ) throws IOException
+ {
+ Person person = fromXml( inputStream, Person.class );
+ person.setPerson( id );
+
+ updatePerson( person );
+ }
+
+ @Override
+ public void updatePersonJson( String id, InputStream inputStream ) throws IOException
+ {
+ Person person = fromJson( inputStream, Person.class );
+ person.setPerson( id );
+
+ updatePerson( person );
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Person.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Person.java 2013-09-10 15:36:21 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/Person.java 2013-09-12 11:20:41 +0000
@@ -193,9 +193,19 @@
if ( this == o ) return true;
if ( o == null || getClass() != o.getClass() ) return false;
- Person person = (Person) o;
+ Person person1 = (Person) o;
- if ( person != null ? !person.equals( person.person ) : person.person != null ) return false;
+ if ( deceased != person1.deceased ) return false;
+ if ( contact != null ? !contact.equals( person1.contact ) : person1.contact != null ) return false;
+ if ( dateOfBirth != null ? !dateOfBirth.equals( person1.dateOfBirth ) : person1.dateOfBirth != null ) return false;
+ if ( dateOfDeath != null ? !dateOfDeath.equals( person1.dateOfDeath ) : person1.dateOfDeath != null ) return false;
+ if ( dateOfRegistration != null ? !dateOfRegistration.equals( person1.dateOfRegistration ) : person1.dateOfRegistration != null )
+ return false;
+ if ( gender != person1.gender ) return false;
+ if ( identifiers != null ? !identifiers.equals( person1.identifiers ) : person1.identifiers != null ) return false;
+ if ( name != null ? !name.equals( person1.name ) : person1.name != null ) return false;
+ if ( orgUnit != null ? !orgUnit.equals( person1.orgUnit ) : person1.orgUnit != null ) return false;
+ if ( person != null ? !person.equals( person1.person ) : person1.person != null ) return false;
return true;
}
@@ -203,7 +213,17 @@
@Override
public int hashCode()
{
- return person != null ? person.hashCode() : 0;
+ int result = person != null ? person.hashCode() : 0;
+ result = 31 * result + (orgUnit != null ? orgUnit.hashCode() : 0);
+ result = 31 * result + (name != null ? name.hashCode() : 0);
+ result = 31 * result + (gender != null ? gender.hashCode() : 0);
+ result = 31 * result + (dateOfBirth != null ? dateOfBirth.hashCode() : 0);
+ result = 31 * result + (deceased ? 1 : 0);
+ result = 31 * result + (dateOfDeath != null ? dateOfDeath.hashCode() : 0);
+ result = 31 * result + (dateOfRegistration != null ? dateOfRegistration.hashCode() : 0);
+ result = 31 * result + (contact != null ? contact.hashCode() : 0);
+ result = 31 * result + (identifiers != null ? identifiers.hashCode() : 0);
+ return result;
}
@Override
@@ -211,6 +231,15 @@
{
return "Person{" +
"person='" + person + '\'' +
+ ", orgUnit='" + orgUnit + '\'' +
+ ", name='" + name + '\'' +
+ ", gender=" + gender +
+ ", dateOfBirth=" + dateOfBirth +
+ ", deceased=" + deceased +
+ ", dateOfDeath=" + dateOfDeath +
+ ", dateOfRegistration=" + dateOfRegistration +
+ ", contact=" + contact +
+ ", identifiers=" + identifiers +
'}';
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/PersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/PersonService.java 2013-09-11 12:12:22 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/person/PersonService.java 2013-09-12 11:20:41 +0000
@@ -41,6 +41,10 @@
*/
public interface PersonService
{
+ // -------------------------------------------------------------------------
+ // READ
+ // -------------------------------------------------------------------------
+
Persons getPersons();
Persons getPersons( OrganisationUnit organisationUnit );
@@ -63,13 +67,29 @@
Person getPerson( Patient patient );
+ // -------------------------------------------------------------------------
+ // CREATE
+ // -------------------------------------------------------------------------
+
void savePersonXml( InputStream inputStream ) throws IOException;
void savePersonJson( InputStream inputStream ) throws IOException;
void savePerson( Person person );
+ // -------------------------------------------------------------------------
+ // UPDATE
+ // -------------------------------------------------------------------------
+
+ void updatePersonXml( String id, InputStream inputStream ) throws IOException;
+
+ void updatePersonJson( String id, InputStream inputStream ) throws IOException;
+
void updatePerson( Person person );
+ // -------------------------------------------------------------------------
+ // DELETE
+ // -------------------------------------------------------------------------
+
void deletePerson( Person person );
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java 2013-09-10 14:11:48 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java 2013-09-12 11:20:41 +0000
@@ -38,15 +38,19 @@
import org.hisp.dhis.program.Program;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.client.HttpClientErrorException;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
import java.util.Map;
/**
@@ -64,11 +68,15 @@
@Autowired
private IdentifiableObjectManager manager;
- @RequestMapping( value = "", method = RequestMethod.GET )
+ // -------------------------------------------------------------------------
+ // READ
+ // -------------------------------------------------------------------------
+
+ @RequestMapping(value = "", method = RequestMethod.GET)
public String getPersons(
- @RequestParam( value = "orgUnit", required = false ) String orgUnitUid,
- @RequestParam( required = false ) Gender gender,
- @RequestParam( value = "program", required = false ) String programUid,
+ @RequestParam(value = "orgUnit", required = false) String orgUnitUid,
+ @RequestParam(required = false) Gender gender,
+ @RequestParam(value = "program", required = false) String programUid,
@RequestParam Map<String, String> parameters, Model model, HttpServletRequest request ) throws Exception
{
WebOptions options = new WebOptions( parameters );
@@ -147,8 +155,8 @@
return organisationUnit;
}
- @RequestMapping( value = "/{id}", method = RequestMethod.GET )
- public String getPerson( @PathVariable String id, @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request )
+ @RequestMapping(value = "/{id}", method = RequestMethod.GET)
+ public String getPerson( @PathVariable String id, @RequestParam Map<String, String> parameters, Model model )
{
WebOptions options = new WebOptions( parameters );
Person person = personService.getPerson( id );
@@ -158,4 +166,52 @@
return "person";
}
+
+ // -------------------------------------------------------------------------
+ // CREATE
+ // -------------------------------------------------------------------------
+
+ @RequestMapping( value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_XML_VALUE )
+ @ResponseStatus( value = HttpStatus.CREATED )
+ public void postPersonXml( HttpServletRequest request, HttpServletResponse response ) throws IOException
+ {
+ personService.savePersonXml( request.getInputStream() );
+ }
+
+ @RequestMapping( value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE )
+ @ResponseStatus( value = HttpStatus.CREATED )
+ public void postPersonJson( HttpServletRequest request, HttpServletResponse response ) throws IOException
+ {
+ personService.savePersonJson( request.getInputStream() );
+ }
+
+ // -------------------------------------------------------------------------
+ // UPDATE
+ // -------------------------------------------------------------------------
+
+ @RequestMapping( value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_XML_VALUE )
+ @ResponseStatus( value = HttpStatus.NO_CONTENT )
+ public void updatePersonXml( @PathVariable String id, HttpServletRequest request ) throws IOException
+ {
+ personService.updatePersonXml( id, request.getInputStream() );
+ }
+
+ @RequestMapping( value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE )
+ @ResponseStatus( value = HttpStatus.NO_CONTENT )
+ public void updatePersonJson( @PathVariable String id, HttpServletRequest request ) throws IOException
+ {
+ personService.updatePersonJson( id, request.getInputStream() );
+ }
+
+ // -------------------------------------------------------------------------
+ // DELETE
+ // -------------------------------------------------------------------------
+
+ @RequestMapping( value = "/{id}", method = RequestMethod.DELETE )
+ @ResponseStatus( value = HttpStatus.NO_CONTENT )
+ public void deletePerson( @PathVariable String id )
+ {
+ Person person = personService.getPerson( id );
+ personService.deletePerson( person );
+ }
}