← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2922: Some more work-in-progress on the not so elegant web api

 

------------------------------------------------------------
revno: 2922
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-02-25 23:38:38 +0530
message:
  Some more work-in-progress on the not so elegant web api
  - can now delete complete registration by setting it to empty string..
  - added hrefs to links
added:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/CategoryOptionCombo.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataElement.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/UrlResourceListener.java
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataSet.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataSetMapper.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetService.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/LinkBuilder.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/LinkBuilderImpl.java
  dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetServiceTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResource.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitsResource.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
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/CategoryOptionCombo.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/CategoryOptionCombo.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/CategoryOptionCombo.java	2011-02-25 18:08:38 +0000
@@ -0,0 +1,6 @@
+package org.hisp.dhis.importexport.dxf2.model;
+
+public class CategoryOptionCombo extends Link
+{
+
+}

=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataElement.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataElement.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataElement.java	2011-02-25 18:08:38 +0000
@@ -0,0 +1,40 @@
+package org.hisp.dhis.importexport.dxf2.model;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+
+public class DataElement extends Link
+{
+
+    @XmlAttribute
+    private String type;
+
+    @XmlElementWrapper(name="categoryOptionCombos")
+    @XmlElement(name="categoryOptionCombo")
+    private List<CategoryOptionCombo> categoryOptionCombos;
+    
+    
+    public String getType()
+    {
+        return type;
+    }
+
+    public void setType( String type )
+    {
+        this.type = type;
+    }
+
+    public List<CategoryOptionCombo> getCategoryOptionCombos()
+    {
+        return categoryOptionCombos;
+    }
+
+    public void setCategoryOptionCombos( List<CategoryOptionCombo> categoryOptionCombos )
+    {
+        this.categoryOptionCombos = categoryOptionCombos;
+    }
+
+}

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataSet.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataSet.java	2011-02-25 04:16:18 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataSet.java	2011-02-25 18:08:38 +0000
@@ -51,7 +51,7 @@
 
     @XmlElementWrapper(name="dataElements")
     @XmlElement(name="dataElement")
-    private List<Link> dataElementLinks;
+    private List<DataElement> dataElements;
 
     @XmlElementWrapper(name="orgUnits")
     @XmlElement(name="orgUnit")
@@ -87,14 +87,14 @@
         this.periodType = periodType;
     }
 
-    public List<Link> getDataElementLinks()
+    public List<DataElement> getDataElements()
     {
-        return dataElementLinks;
+        return dataElements;
     }
 
-    public void setDataElementLinks( List<Link> dataElementLinks )
+    public void setDataElements( List<DataElement> dataElements )
     {
-        this.dataElementLinks = dataElementLinks;
+        this.dataElements = dataElements;
     }
 
     public List<Link> getOrgUnitLinks()

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataSetMapper.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataSetMapper.java	2011-02-25 04:16:18 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataSetMapper.java	2011-02-25 18:08:38 +0000
@@ -1,24 +1,77 @@
 package org.hisp.dhis.importexport.dxf2.service;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.importexport.dxf2.model.CategoryOptionCombo;
+import org.hisp.dhis.importexport.dxf2.model.DataElement;
 import org.hisp.dhis.importexport.dxf2.model.DataSet;
 
 public class DataSetMapper
 {
     private LinkBuilder linkBuilder = new LinkBuilderImpl();
-    
-    public DataSet convert(org.hisp.dhis.dataset.DataSet dataSet) {
+
+    public DataSet convert( org.hisp.dhis.dataset.DataSet dataSet )
+    {
         DataSet dxfDataSet = new DataSet();
-        
+
         dxfDataSet.setCode( dataSet.getCode() );
         dxfDataSet.setName( dataSet.getName() );
         dxfDataSet.setPeriodType( dataSet.getPeriodType().getName() );
         dxfDataSet.setShortName( dataSet.getShortName() );
         dxfDataSet.setId( dataSet.getUuid() );
 
-        dxfDataSet.setDataElementLinks( linkBuilder.getLinks( dataSet.getDataElements()) );
-        dxfDataSet.setOrgUnitLinks( linkBuilder.getLinks(dataSet.getOrganisationUnits()) );
-        
+        dxfDataSet.setDataElements( getDataElements( dataSet.getDataElements() ) );
+        dxfDataSet.setOrgUnitLinks( linkBuilder.getLinks( dataSet.getOrganisationUnits() ) );
+
         return dxfDataSet;
     }
 
+    private List<DataElement> getDataElements( Collection<org.hisp.dhis.dataelement.DataElement> dataElements )
+    {
+        List<DataElement> dxfElements = new ArrayList<DataElement>();
+
+        for ( org.hisp.dhis.dataelement.DataElement dataElement : dataElements )
+        {
+            dxfElements.add( getDataElement( dataElement ) );
+        }
+        return dxfElements;
+    }
+
+    private DataElement getDataElement( org.hisp.dhis.dataelement.DataElement dataElement )
+    {
+        DataElement dxfElement = new DataElement();
+
+        dxfElement.setId( dataElement.getUuid() );
+        dxfElement.setName( dataElement.getName() );
+        dxfElement.setType( dataElement.getType() );
+
+        Set<DataElementCategoryOptionCombo> optionCombos = dataElement.getCategoryCombo().getOptionCombos();
+
+        if ( optionCombos.size() > 1 )
+        {
+            List<CategoryOptionCombo> categoryOptionCombos = getOptionCombos( optionCombos );
+
+            dxfElement.setCategoryOptionCombos( categoryOptionCombos );
+        }
+
+        return dxfElement;
+    }
+
+    private List<CategoryOptionCombo> getOptionCombos( Set<DataElementCategoryOptionCombo> optionCombos )
+    {
+        List<CategoryOptionCombo> dxfCombos = new ArrayList<CategoryOptionCombo>();
+        for ( DataElementCategoryOptionCombo optionCombo : optionCombos )
+        {
+            CategoryOptionCombo dxfCombo = new CategoryOptionCombo();
+            dxfCombo.setId( optionCombo.getUuid() );
+            dxfCombo.setName( optionCombo.getName() );
+            dxfCombos.add( dxfCombo );
+        }
+        return dxfCombos;
+    }
+
 }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetService.java	2011-02-21 10:32:35 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetService.java	2011-02-25 18:08:38 +0000
@@ -75,21 +75,23 @@
      * <p>
      * Handles the content in the following way
      * <ul>
-     * <li>if data set is not specified, will resolve it through data elements if not ambigous.
+     * <li>if data set is not specified, will resolve it through data elements if not ambiguous.
      * <li>optionCombo defaults to 'default' if not specified
      * <li>storedBy defaults to currently logged in user's name
+     * <li>if value is empty not present -> delete value
      * </ul>
      * <ul>
      * Validates the following:
      * <p>
      * First checks that:
      * <ul>
-     * <li>dataSet exists (tries to resolve it through the data elements if not specified)
+     * <li>dataSet exists (tries to resolve it through the data elements if not
+     * specified)
      * <li>orgUnit exists
      * <li>orgunit reports dataSet
      * <li>period is a valid period
-     * <li>the dataValueSet is not registered as complete or that if it is a
-     * complete date is present
+     * <li>the dataValueSet is not registered as complete or that if it is a complete date is present
+     * <li>if complete date is empty string - delete completion
      * <li>if complete date present checks validity
      * </ul>
      * For all dataValues check that:
@@ -105,8 +107,9 @@
      * </ul>
      * Concerns:
      * <ul>
-     * <li>deletion through sending "empty string" value dependant on semantics of add/update in data value store
-     * <li>completed semantics: can't uncomplete but can complete and "recomplete"
+     * <li>deletion through sending "empty string" value dependent on semantics of add/update in data value store
+     * <li>completed semantics: can't uncomplete but can complete and
+     * "recomplete"
      * <li>what is 'comment' good for really?
      * 
      * @param dataValueSet
@@ -143,7 +146,7 @@
     private DataSet getDataSet( DataValueSet dataValueSet )
     {
         DataSet dataSet = null;
-        
+
         String uuid = dataValueSet.getDataSetUuid();
         if ( uuid != null )
         {
@@ -178,8 +181,7 @@
 
             if ( dataSets == null || dataSets.isEmpty() )
             {
-                throw new IllegalArgumentException( "Data element '" + dataElement.getUuid()
-                    + "' isn't in a data set." );
+                throw new IllegalArgumentException( "Data element '" + dataElement.getUuid() + "' isn't in a data set." );
             }
             else if ( dataSets.size() == 1 )
             {
@@ -273,11 +275,10 @@
 
         CompleteDataSetRegistration complete = null;
 
-        if ( completeDateString != null )
+        if ( completeDateString != null && !completeDateString.trim().isEmpty())
         {
             complete = getComplete( dataSet, unit, period, completeDateString, complete );
         }
-
         if ( complete != null )
         {
             registrationService.saveCompleteDataSetRegistration( complete );

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/LinkBuilder.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/LinkBuilder.java	2011-02-25 04:16:18 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/LinkBuilder.java	2011-02-25 18:08:38 +0000
@@ -9,8 +9,8 @@
 public interface LinkBuilder
 {
     
-    public List<Link> getLinks( Collection<? extends IdentifiableObject> targets );
+    public List<Link> getLinks( Collection<? extends IdentifiableObject> targets  );
 
-    public Link get( IdentifiableObject target );
+    public Link get( IdentifiableObject target  );
 
 }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/LinkBuilderImpl.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/LinkBuilderImpl.java	2011-02-25 04:16:18 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/LinkBuilderImpl.java	2011-02-25 18:08:38 +0000
@@ -9,7 +9,7 @@
 
 public class LinkBuilderImpl implements LinkBuilder
 {
-    public List<Link> getLinks( Collection<? extends IdentifiableObject> targets )
+    public List<Link> getLinks( Collection<? extends IdentifiableObject> targets  )
     {
         List<Link> links = new ArrayList<Link>();
 
@@ -23,6 +23,7 @@
     public Link get( IdentifiableObject target )
     {
         Link link = new Link();
+
         link.setName( target.getName() );
         link.setId( target.getUuid() );
 

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetServiceTest.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetServiceTest.java	2011-02-21 10:32:35 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetServiceTest.java	2011-02-25 18:08:38 +0000
@@ -43,6 +43,8 @@
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.CompleteDataSetRegistration;
+import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueService;
@@ -57,13 +59,6 @@
 import org.junit.Ignore;
 import org.junit.Test;
 
-/**
- * Messy test class checking that jaxb produces the expected java
- * 
- * @link{DataValueSet data value set} structure, that the set is converted,
- *                    validated and stored into a correct set of
- *                    {@link DataValue data values} .
- */
 public class DataValueSetServiceTest
     extends DhisTest
 {
@@ -104,7 +99,8 @@
         dataElementService = (DataElementService) getBean( DataElementService.ID );
         dataSetService = (DataSetService) getBean( DataSetService.ID );
         dataValueService = (DataValueService) getBean( DataValueService.ID );
-
+        completeDataSetRegistrationService = (CompleteDataSetRegistrationService) getBean( CompleteDataSetRegistrationService.ID );
+        
         service = (DataValueSetService) getBean( "org.hisp.dhis.importexport.dxf2.service.DataValueSetService" );
 
         classLoader = Thread.currentThread().getContextClassLoader();
@@ -301,9 +297,21 @@
 
         service.saveDataValueSet( dataValueSet );
 
+        Collection<CompleteDataSetRegistration> registrations = 
+            completeDataSetRegistrationService.getAllCompleteDataSetRegistrations();
+
+        assertTrue( registrations.isEmpty() );
+
+        
         dataValueSet.setCompleteDate( "20110101" );
         service.saveDataValueSet( dataValueSet );
 
+        registrations = 
+            completeDataSetRegistrationService.getAllCompleteDataSetRegistrations();
+
+        assertEquals( 1, registrations.size() );
+        assertEquals( 2011 - 1900, registrations.iterator().next().getDate().getYear() );
+        
         dataValueSet.setCompleteDate( null );
 
         try
@@ -316,6 +324,12 @@
             // TODO: Expected
         }
 
+        registrations = 
+            completeDataSetRegistrationService.getAllCompleteDataSetRegistrations();
+
+        assertEquals( 1, registrations.size() );
+        assertEquals( 2011 - 1900, registrations.iterator().next().getDate().getYear() );
+
         dataValueSet.setCompleteDate( "201lala" );
 
         try
@@ -327,9 +341,28 @@
             // Expected
         }
 
-        dataValueSet.setCompleteDate( "20101010" );
-        service.saveDataValueSet( dataValueSet );
-
+        registrations = 
+            completeDataSetRegistrationService.getAllCompleteDataSetRegistrations();
+
+        assertEquals( 1, registrations.size() );
+        assertEquals( 2011 - 1900, registrations.iterator().next().getDate().getYear() );
+
+        dataValueSet.setCompleteDate( "20071010" );
+        service.saveDataValueSet( dataValueSet );
+
+        registrations = 
+            completeDataSetRegistrationService.getAllCompleteDataSetRegistrations();
+
+        assertEquals( 1, registrations.size() );
+        assertEquals( 2007 - 1900, registrations.iterator().next().getDate().getYear() );
+
+        dataValueSet.setCompleteDate( "" );
+        service.saveDataValueSet( dataValueSet );
+
+        registrations = 
+            completeDataSetRegistrationService.getAllCompleteDataSetRegistrations();
+
+        assertTrue( registrations.isEmpty() );
     }
 
     @Test

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/UrlResourceListener.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/UrlResourceListener.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/UrlResourceListener.java	2011-02-25 18:08:38 +0000
@@ -0,0 +1,83 @@
+package org.hisp.dhis.web.api;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.UriInfo;
+import javax.xml.bind.Marshaller.Listener;
+
+import org.hisp.dhis.importexport.dxf2.model.DataSet;
+import org.hisp.dhis.importexport.dxf2.model.DataSetLinks;
+import org.hisp.dhis.importexport.dxf2.model.Link;
+import org.hisp.dhis.importexport.dxf2.model.OrgUnit;
+import org.hisp.dhis.importexport.dxf2.model.OrgUnitLinks;
+
+public class UrlResourceListener
+    extends Listener
+{
+
+    private UriInfo uriInfo;
+
+    private Map<Class<?>, String> mapping;
+
+    public UrlResourceListener( UriInfo uriInfo )
+    {
+        super();
+        this.uriInfo = uriInfo;
+
+        mapping = new HashMap<Class<?>, String>();
+        mapping.put( OrgUnit.class, "orgUnits/{id}" );
+        mapping.put( DataSet.class, "dataSets/{id}" );
+    }
+
+    @Override
+    public void beforeMarshal( Object source )
+    {
+        if ( source instanceof DataSet )
+        {
+            addUrls( ((DataSet) source).getOrgUnitLinks(), OrgUnit.class );
+        }
+        else if ( source instanceof DataSetLinks )
+        {
+            addUrls( ((DataSetLinks) source).getDataSet(), DataSet.class );
+        }
+        else if ( source instanceof OrgUnit )
+        {
+            OrgUnit unit = (OrgUnit) source;
+            addUrls( unit.getChildren(), OrgUnit.class );
+            addUrl( unit.getParent(), OrgUnit.class );
+            addUrls( unit.getDataSets(), DataSet.class );
+
+        }
+        else if ( source instanceof OrgUnitLinks )
+        {
+            addUrls( ((OrgUnitLinks) source).getOrgUnit(), OrgUnit.class );
+        }
+    }
+
+    private void addUrls( List<Link> links, Class<?> clazz )
+    {
+        if ( links == null )
+            return;
+
+        for ( Link link : links )
+        {
+            addUrl( link, clazz );
+        }
+
+    }
+
+    private void addUrl( Link link, Class<?> clazz )
+    {
+        if ( link == null )
+            return;
+
+        String id = link.getId();
+        String path = mapping.get( clazz );
+        String url = uriInfo.getBaseUriBuilder().path( path ).build( id ).toString();
+
+        link.setHref( url );
+    }
+
+}

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java	2011-02-25 04:16:18 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java	2011-02-25 18:08:38 +0000
@@ -16,6 +16,8 @@
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.importexport.dxf2.service.DataSetMapper;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.web.api.UrlResourceListener;
 import org.springframework.beans.factory.annotation.Required;
 
 @Path( "dataSets/{uuid}" )
@@ -37,7 +39,9 @@
         {
             throw new IllegalArgumentException( "No dataset with uuid " + uuid );
         }
-        return new DataSetMapper().convert( dataSet );
+        org.hisp.dhis.importexport.dxf2.model.DataSet dxfDataSet = new DataSetMapper().convert( dataSet );
+        new UrlResourceListener( uriInfo ).beforeMarshal( dxfDataSet );
+        return dxfDataSet;
     }
 
     @GET
@@ -55,8 +59,9 @@
         StringBuilder t = Html.head( "Data set " + dataSet.getName() );
         t.append( "<p>See the <a href=\"" + uuid + ".xml\">xml version</a></p>\n" );
         t.append( "<p>Uuid: " ).append( dataSet.getUuid() ).append( "<br>\n" );
+        PeriodType periodType = dataSet.getPeriodType();
         t.append( "Period type: " ).append( dataSet.getPeriodType().getName() ).append( " - " )
-            .append( dataSet.getPeriodType().getIsoFormat() );
+            .append( periodType.getIsoFormat() );
         t.append( "</p>\n" );
 
         t.append( "<h2>Org units reporting data set</h2>\n<ul>" );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResource.java	2011-02-25 04:16:18 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResource.java	2011-02-25 18:08:38 +0000
@@ -19,6 +19,7 @@
 import org.hisp.dhis.importexport.dxf2.model.OrgUnitLinks;
 import org.hisp.dhis.importexport.dxf2.service.LinkBuilder;
 import org.hisp.dhis.importexport.dxf2.service.LinkBuilderImpl;
+import org.hisp.dhis.web.api.UrlResourceListener;
 import org.springframework.beans.factory.annotation.Required;
 
 @Path( "dataSets" )
@@ -35,7 +36,9 @@
     @GET
     @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } )
     public DataSetLinks getDataSetLinks() {
-        return new DataSetLinks( linkBuilder.getLinks( dataSetService.getAllDataSets() ) );
+        DataSetLinks dataSetLinks = new DataSetLinks( linkBuilder.getLinks( dataSetService.getAllDataSets() ) );
+        new UrlResourceListener( uriInfo ).beforeMarshal( dataSetLinks );
+        return dataSetLinks;
     }
     
     @GET

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java	2011-02-25 07:08:59 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java	2011-02-25 18:08:38 +0000
@@ -27,10 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.HeaderParam;
@@ -49,13 +45,13 @@
 import org.hisp.dhis.importexport.dxf2.service.OrgUnitMapper;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.web.api.UrlResourceListener;
 import org.hisp.dhis.web.api.model.ActivityValue;
-import org.hisp.dhis.web.api.model.DataSet;
 import org.hisp.dhis.web.api.model.DataSetList;
 import org.hisp.dhis.web.api.model.DataSetValue;
 import org.hisp.dhis.web.api.model.MobileModel;
+import org.hisp.dhis.web.api.model.MobileOrgUnitLinks;
 import org.hisp.dhis.web.api.model.ModelList;
-import org.hisp.dhis.web.api.model.MobileOrgUnitLinks;
 import org.hisp.dhis.web.api.service.ActivityReportingService;
 import org.hisp.dhis.web.api.service.ActivityReportingServiceImpl;
 import org.hisp.dhis.web.api.service.FacilityReportingService;
@@ -107,7 +103,9 @@
         if (unit == null)
             return null;
         
-        return new OrgUnitMapper().get( unit );
+        OrgUnit orgUnit = new OrgUnitMapper().get( unit );
+        new UrlResourceListener( uriInfo ).beforeMarshal( orgUnit );
+        return orgUnit;
     }
 
     /**

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitsResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitsResource.java	2011-02-25 04:16:18 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitsResource.java	2011-02-25 18:08:38 +0000
@@ -3,13 +3,16 @@
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
 
 import org.hisp.dhis.importexport.dxf2.model.OrgUnitLinks;
 import org.hisp.dhis.importexport.dxf2.service.LinkBuilder;
 import org.hisp.dhis.importexport.dxf2.service.LinkBuilderImpl;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.web.api.UrlResourceListener;
 import org.springframework.web.util.HtmlUtils;
 
 @Path( "orgUnits" )
@@ -19,11 +22,15 @@
 
     private LinkBuilder linkBuilder = new LinkBuilderImpl();
 
+    @Context UriInfo uriInfo;
+    
     @GET
     @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } )
     public OrgUnitLinks getOrgUnits()
     {
-        return new OrgUnitLinks( linkBuilder.getLinks( organisationUnitService.getAllOrganisationUnits() ) );
+        OrgUnitLinks orgUnitLinks = new OrgUnitLinks( linkBuilder.getLinks( organisationUnitService.getAllOrganisationUnits() ) );
+        new UrlResourceListener( uriInfo ).beforeMarshal( orgUnitLinks );
+        return orgUnitLinks;
     }
 
     @GET