=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.java' --- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.java 2009-06-18 12:45:22 +0000 +++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.java 2011-02-25 04:16:18 +0000 @@ -27,10 +27,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import static org.junit.Assert.assertFalse; + +import static org.junit.Assert.*; import static org.junit.Assert.assertTrue; import java.util.Calendar; +import java.util.Date; import java.util.List; import org.junit.Ignore; @@ -96,4 +98,24 @@ } + @Test + public void isoDates() + { + WeeklyPeriodType weekly = new WeeklyPeriodType(); + Calendar cal = Calendar.getInstance(); + cal.clear(); + + cal.set( 2010, 11, 27 ); + + Period period = weekly.createPeriod( "2011W1" ); + + assertEquals(cal.getTime(), period.getStartDate()); + + period = weekly.createPeriod( "2011W11" ); + + cal.set( 2011, 2, 7 ); + + assertEquals(cal.getTime(), period.getStartDate()); + + } } === removed 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 2011-02-21 10:32:35 +0000 +++ 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 @@ -1,37 +0,0 @@ -package org.hisp.dhis.importexport.dxf2.model; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -@XmlAccessorType(XmlAccessType.FIELD) -public class DataElement -{ - @XmlAttribute(name="id") - private String uuid; - - @XmlAttribute - private String name; - - public String getUuid() - { - return uuid; - } - - public void setUuid( String uuid ) - { - this.uuid = uuid; - } - - public String getName() - { - return name; - } - - public void setName( String name ) - { - this.name = name; - } - - -} === 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-21 10:32:35 +0000 +++ 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 @@ -1,5 +1,32 @@ package org.hisp.dhis.importexport.dxf2.model; +/* + * Copyright (c) 2011, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + import java.util.List; import javax.xml.bind.annotation.XmlAccessType; @@ -11,14 +38,8 @@ @XmlRootElement @XmlAccessorType( XmlAccessType.FIELD ) -public class DataSet +public class DataSet extends Link { - @XmlAttribute(name="id") - private String uuid; - - @XmlAttribute - private String name; - @XmlAttribute private String shortName; @@ -28,29 +49,13 @@ @XmlAttribute private String periodType; - @XmlElementWrapper(name="members") + @XmlElementWrapper(name="dataElements") @XmlElement(name="dataElement") - private List members; - - public String getUuid() - { - return uuid; - } - - public void setUuid( String uuid ) - { - this.uuid = uuid; - } - - public String getName() - { - return name; - } - - public void setName( String name ) - { - this.name = name; - } + private List dataElementLinks; + + @XmlElementWrapper(name="orgUnits") + @XmlElement(name="orgUnit") + private List orgUnitLinks; public String getShortName() { @@ -82,15 +87,25 @@ this.periodType = periodType; } - public List getMembers() - { - return members; - } - - public void setMembers( List members ) - { - this.members = members; - } - - + public List getDataElementLinks() + { + return dataElementLinks; + } + + public void setDataElementLinks( List dataElementLinks ) + { + this.dataElementLinks = dataElementLinks; + } + + public List getOrgUnitLinks() + { + return orgUnitLinks; + } + + public void setOrgUnitLinks( List orgUnitLinks ) + { + this.orgUnitLinks = orgUnitLinks; + } + + } === added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataSetLinks.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataSetLinks.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataSetLinks.java 2011-02-25 04:16:18 +0000 @@ -0,0 +1,33 @@ +package org.hisp.dhis.importexport.dxf2.model; + +import java.util.List; + +import javax.xml.bind.annotation.XmlRootElement; + + +@XmlRootElement +public class DataSetLinks +{ + + List dataSet; + + public DataSetLinks() + { + } + + public DataSetLinks( List dataSet ) + { + this.dataSet = dataSet; + } + + public List getDataSet() + { + return dataSet; + } + + public void setDataSet( List dataSet ) + { + this.dataSet = dataSet; + } + +} === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/Dxf.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/Dxf.java 2011-02-21 10:32:35 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/Dxf.java 2011-02-25 04:16:18 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.importexport.dxf2.model; +/* + * Copyright (c) 2011, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + import java.util.List; import javax.xml.bind.annotation.XmlAccessType; @@ -22,6 +49,10 @@ @XmlElement( name="dataValueSet" ) private List dataValueSets; + @XmlElementWrapper( name="orgUnits" ) + @XmlElement( name="orgUnit" ) + private List orgUnits; + public void setDataValueSets( List dataValueSets ) { this.dataValueSets = dataValueSets; @@ -42,5 +73,15 @@ this.dataSets = dataSets; } + public List getOrgUnits() + { + return orgUnits; + } + + public void setOrgUnits( List orgUnits ) + { + this.orgUnits = orgUnits; + } + } === added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/Link.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/Link.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/Link.java 2011-02-25 04:16:18 +0000 @@ -0,0 +1,50 @@ +package org.hisp.dhis.importexport.dxf2.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +@XmlAccessorType( XmlAccessType.FIELD ) +public class Link +{ + + @XmlAttribute( name = "id", required = true ) + private String id; + + @XmlAttribute + private String href; + + @XmlAttribute + private String name; + + public String getId() + { + return id; + } + + public void setId( String id ) + { + this.id = id; + } + + public String getHref() + { + return href; + } + + public void setHref( String href ) + { + this.href = href; + } + + public String getName() + { + return name; + } + + public void setName( String name ) + { + this.name = name; + } + +} === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/OrgUnit.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/OrgUnit.java 2011-02-21 10:32:35 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/OrgUnit.java 2011-02-25 04:16:18 +0000 @@ -1,37 +1,55 @@ package org.hisp.dhis.importexport.dxf2.model; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -@XmlAccessorType(XmlAccessType.FIELD) -public class OrgUnit +import java.util.List; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class OrgUnit extends Link { - @XmlAttribute(name="id") - private String uuid; - - @XmlAttribute - private String name; - - public String getUuid() - { - return uuid; - } - - public void setUuid( String uuid ) - { - this.uuid = uuid; - } - - public void setName( String name ) - { - this.name = name; - } - - public String getName() - { - return name; - } - + private Link parent; + + @XmlElementWrapper(name="children") + @XmlElement(name="orgUnit") + private List children; + + + @XmlElementWrapper(name="dataSets") + @XmlElement(name="dataSet") + private List dataSets; + + public List getDataSets() + { + return dataSets; + } + + public void setDataSets( List dataSets ) + { + this.dataSets = dataSets; + } + + public List getChildren() + { + return children; + } + + public void setChildren( List children ) + { + this.children = children; + } + + public Link getParent() + { + return parent; + } + + public void setParent( Link parent ) + { + this.parent = parent; + } + + } === added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/OrgUnitLinks.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/OrgUnitLinks.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/OrgUnitLinks.java 2011-02-25 04:16:18 +0000 @@ -0,0 +1,35 @@ +package org.hisp.dhis.importexport.dxf2.model; + +import java.util.List; + +import javax.xml.bind.annotation.XmlRootElement; + + +@XmlRootElement +public class OrgUnitLinks +{ + + List orgUnit; + + public OrgUnitLinks() + { + } + + public OrgUnitLinks( List orgUnit ) + { + this.orgUnit = orgUnit; + } + + public List getOrgUnit() + { + return orgUnit; + } + + public void setOrgUnit( List orgUnit ) + { + this.orgUnit = orgUnit; + } + + + +} === 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-21 10:32:35 +0000 +++ 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 @@ -1,40 +1,24 @@ package org.hisp.dhis.importexport.dxf2.service; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.hisp.dhis.importexport.dxf2.model.DataElement; import org.hisp.dhis.importexport.dxf2.model.DataSet; public class DataSetMapper { - - public static DataSet convert(org.hisp.dhis.dataset.DataSet dataSet) { + private LinkBuilder linkBuilder = new LinkBuilderImpl(); + + public DataSet convert(org.hisp.dhis.dataset.DataSet dataSet) { DataSet dxfDataSet = new DataSet(); dxfDataSet.setCode( dataSet.getCode() ); - dxfDataSet.setMembers( getDataElements(dataSet.getDataElements()) ); dxfDataSet.setName( dataSet.getName() ); dxfDataSet.setPeriodType( dataSet.getPeriodType().getName() ); dxfDataSet.setShortName( dataSet.getShortName() ); - dxfDataSet.setUuid( dataSet.getUuid() ); + dxfDataSet.setId( dataSet.getUuid() ); + + dxfDataSet.setDataElementLinks( linkBuilder.getLinks( dataSet.getDataElements()) ); + dxfDataSet.setOrgUnitLinks( linkBuilder.getLinks(dataSet.getOrganisationUnits()) ); return dxfDataSet; } - public static List getDataElements( Collection dataElements ) - { - List dxfDataElements = new ArrayList(); - - for ( org.hisp.dhis.dataelement.DataElement dataElement : dataElements ) - { - DataElement dxfDataElement = new DataElement(); - dxfDataElement.setName( dataElement.getName() ); - dxfDataElement.setUuid( dataElement.getUuid() ); - - dxfDataElements.add( dxfDataElement ); - } - return dxfDataElements; - } } === added 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 1970-01-01 00:00:00 +0000 +++ 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 @@ -0,0 +1,16 @@ +package org.hisp.dhis.importexport.dxf2.service; + +import java.util.Collection; +import java.util.List; + +import org.hisp.dhis.common.IdentifiableObject; +import org.hisp.dhis.importexport.dxf2.model.Link; + +public interface LinkBuilder +{ + + public List getLinks( Collection targets ); + + public Link get( IdentifiableObject target ); + +} === added 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 1970-01-01 00:00:00 +0000 +++ 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 @@ -0,0 +1,32 @@ +package org.hisp.dhis.importexport.dxf2.service; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.hisp.dhis.common.IdentifiableObject; +import org.hisp.dhis.importexport.dxf2.model.Link; + +public class LinkBuilderImpl implements LinkBuilder +{ + public List getLinks( Collection targets ) + { + List links = new ArrayList(); + + for ( IdentifiableObject target : targets ) + { + links.add( get( target ) ); + } + return links; + } + + public Link get( IdentifiableObject target ) + { + Link link = new Link(); + link.setName( target.getName() ); + link.setId( target.getUuid() ); + + return link; + } + +} === added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/OrgUnitMapper.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/OrgUnitMapper.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/OrgUnitMapper.java 2011-02-25 04:16:18 +0000 @@ -0,0 +1,33 @@ +package org.hisp.dhis.importexport.dxf2.service; + +import java.util.Set; + +import org.hisp.dhis.importexport.dxf2.model.OrgUnit; +import org.hisp.dhis.organisationunit.OrganisationUnit; + +public class OrgUnitMapper +{ + + private LinkBuilder linkBuilder = new LinkBuilderImpl(); + + public OrgUnit get( OrganisationUnit unit ) + { + OrgUnit dxfUnit = new OrgUnit(); + + dxfUnit.setName( unit.getName() ); + dxfUnit.setId( unit.getUuid() ); + + OrganisationUnit parent = unit.getParent(); + if ( parent != null ) + dxfUnit.setParent( linkBuilder.get( parent ) ); + + Set children = unit.getChildren(); + if ( children != null && !children.isEmpty() ) + dxfUnit.setChildren( linkBuilder.getLinks( children ) ); + + dxfUnit.setDataSets( linkBuilder.getLinks( unit.getDataSets() ) ); + + return dxfUnit; + } + +} === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataSetMappingTest.java' --- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataSetMappingTest.java 2011-02-22 23:17:50 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataSetMappingTest.java 2011-02-25 04:16:18 +0000 @@ -97,7 +97,7 @@ StringWriter writer = new StringWriter(); org.hisp.dhis.dataset.DataSet dataSet = dataSetService.getDataSet( DATA_SET_UUID ); - DataSet dxfDataSet = DataSetMapper.convert( dataSet ); + DataSet dxfDataSet = new DataSetMapper().convert( dataSet ); u.marshal( dxfDataSet, writer ); System.out.println( writer.toString() ); === modified file 'dhis-2/dhis-web/dhis-web-api/pom.xml' --- dhis-2/dhis-web/dhis-web-api/pom.xml 2011-01-23 00:12:53 +0000 +++ dhis-2/dhis-web/dhis-web-api/pom.xml 2011-02-25 04:16:18 +0000 @@ -42,17 +42,17 @@ com.sun.jersey jersey-server - 1.4 + 1.5 com.sun.jersey jersey-json - 1.4 + 1.5 com.sun.jersey.contribs jersey-spring - 1.4 + 1.5 org.springframework === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/HtmlPromotingUriConnegFilter.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/HtmlPromotingUriConnegFilter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/HtmlPromotingUriConnegFilter.java 2011-02-25 04:16:18 +0000 @@ -0,0 +1,96 @@ +package org.hisp.dhis.web.api; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +import com.sun.jersey.api.container.filter.UriConnegFilter; +import com.sun.jersey.spi.container.ContainerRequest; + +public class HtmlPromotingUriConnegFilter + extends UriConnegFilter +{ + + private static final String ACCEPT = "Accept"; + + private static Map mediaExtentions; + + static + { + mediaExtentions = new HashMap(); + mediaExtentions.put( "xml", MediaType.APPLICATION_XML_TYPE ); + mediaExtentions.put( "html", MediaType.TEXT_HTML_TYPE ); + mediaExtentions.put( "json", MediaType.APPLICATION_JSON_TYPE ); + } + + public HtmlPromotingUriConnegFilter() + { + super( mediaExtentions ); + } + + @Override + public ContainerRequest filter( ContainerRequest request ) + { + String accept = request.getHeaderValue( ACCEPT ); + + if ( accept == null || accept.trim().isEmpty()) + { + request.getRequestHeaders().putSingle( ACCEPT, MediaType.TEXT_HTML ); + } + else + { + accept = preferHtml(accept); + request.getRequestHeaders().putSingle( ACCEPT, accept ); + } + + request = super.filter( request ); + + return request; + } + + public static String preferHtml( String accept ) + { + int i = accept.indexOf( "text/html" ); + + if ( i == -1 ) + { + if ( accept.trim().equals( "" ) ) + { + return "text/html"; + } + return "text/html," + accept; + } + + int start = accept.substring( 0, i ).lastIndexOf( ',' ); + + String result = ""; + + if ( start != -1 ) + { + result = accept.substring( 0, start ); + } + + int end = accept.indexOf( ',', i ); + if ( end != -1 ) + { + if ( result.equals( "" ) ) + { + result = accept.substring( end + 1 ); + } + else + { + result = result + accept.substring( end ); + } + } + + if ( result.trim().equals( "" ) ) + { + return "text/html"; + } + + return "text/html," + result; + + } + +} === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileOrgUnitLinks.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileOrgUnitLinks.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileOrgUnitLinks.java 2011-02-25 04:16:18 +0000 @@ -0,0 +1,149 @@ +package org.hisp.dhis.web.api.model; + +/* + * Copyright (c) 2004-2010, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name="orgUnit") +public class MobileOrgUnitLinks + implements DataStreamSerializable +{ + private int id; + + private String name; + + private String downloadAllUrl; + + private String updateActivityPlanUrl; + + private String uploadFacilityReportUrl; + + private String uploadActivityReportUrl; + + private String updateDataSetUrl; + + @XmlAttribute + public int getId() + { + return id; + } + + public void setId( int id ) + { + this.id = id; + } + + @XmlAttribute + public String getName() + { + return name; + } + + public void setName( String name ) + { + this.name = name; + } + + public String getDownloadAllUrl() + { + return downloadAllUrl; + } + + public void setDownloadAllUrl( String downloadAllUrl ) + { + this.downloadAllUrl = downloadAllUrl; + } + + public String getUploadFacilityReportUrl() + { + return uploadFacilityReportUrl; + } + + public void setUploadFacilityReportUrl( String uploadFacilityReportUrl ) + { + this.uploadFacilityReportUrl = uploadFacilityReportUrl; + } + + public String getUploadActivityReportUrl() + { + return uploadActivityReportUrl; + } + + public void setUploadActivityReportUrl( String uploadActivityReportUrl ) + { + this.uploadActivityReportUrl = uploadActivityReportUrl; + } + + public String getUpdateDataSetUrl() + { + return updateDataSetUrl; + } + + public void setUpdateDataSetUrl( String updateDataSetUrl ) + { + this.updateDataSetUrl = updateDataSetUrl; + } + + public String getUpdateActivityPlanUrl() { + return updateActivityPlanUrl; + } + + public void setUpdateActivityPlanUrl(String updateActivityPlanUrl) { + this.updateActivityPlanUrl = updateActivityPlanUrl; + } + + public void serialize( DataOutputStream dataOutputStream ) + throws IOException + { + dataOutputStream.writeInt( this.id ); + dataOutputStream.writeUTF( this.name ); + dataOutputStream.writeUTF( this.downloadAllUrl ); + dataOutputStream.writeUTF(this.updateActivityPlanUrl); + dataOutputStream.writeUTF( this.uploadFacilityReportUrl ); + dataOutputStream.writeUTF( this.uploadActivityReportUrl ); + dataOutputStream.writeUTF( this.updateDataSetUrl ); + } + + public void deSerialize( DataInputStream dataInputStream ) + throws IOException + { + this.id = dataInputStream.readInt(); + this.name = dataInputStream.readUTF(); + this.downloadAllUrl = dataInputStream.readUTF(); + this.updateActivityPlanUrl = dataInputStream.readUTF(); + this.uploadFacilityReportUrl = dataInputStream.readUTF(); + this.uploadActivityReportUrl = dataInputStream.readUTF(); + this.updateDataSetUrl = dataInputStream.readUTF(); + } + +} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java 2011-02-21 06:51:20 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java 1970-01-01 00:00:00 +0000 @@ -1,149 +0,0 @@ -package org.hisp.dhis.web.api.model; - -/* - * Copyright (c) 2004-2010, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement -public class OrgUnit - implements DataStreamSerializable -{ - private int id; - - private String name; - - private String downloadAllUrl; - - private String updateActivityPlanUrl; - - private String uploadFacilityReportUrl; - - private String uploadActivityReportUrl; - - private String updateDataSetUrl; - - @XmlAttribute - public int getId() - { - return id; - } - - public void setId( int id ) - { - this.id = id; - } - - @XmlAttribute - public String getName() - { - return name; - } - - public void setName( String name ) - { - this.name = name; - } - - public String getDownloadAllUrl() - { - return downloadAllUrl; - } - - public void setDownloadAllUrl( String downloadAllUrl ) - { - this.downloadAllUrl = downloadAllUrl; - } - - public String getUploadFacilityReportUrl() - { - return uploadFacilityReportUrl; - } - - public void setUploadFacilityReportUrl( String uploadFacilityReportUrl ) - { - this.uploadFacilityReportUrl = uploadFacilityReportUrl; - } - - public String getUploadActivityReportUrl() - { - return uploadActivityReportUrl; - } - - public void setUploadActivityReportUrl( String uploadActivityReportUrl ) - { - this.uploadActivityReportUrl = uploadActivityReportUrl; - } - - public String getUpdateDataSetUrl() - { - return updateDataSetUrl; - } - - public void setUpdateDataSetUrl( String updateDataSetUrl ) - { - this.updateDataSetUrl = updateDataSetUrl; - } - - public String getUpdateActivityPlanUrl() { - return updateActivityPlanUrl; - } - - public void setUpdateActivityPlanUrl(String updateActivityPlanUrl) { - this.updateActivityPlanUrl = updateActivityPlanUrl; - } - - public void serialize( DataOutputStream dataOutputStream ) - throws IOException - { - dataOutputStream.writeInt( this.id ); - dataOutputStream.writeUTF( this.name ); - dataOutputStream.writeUTF( this.downloadAllUrl ); - dataOutputStream.writeUTF(this.updateActivityPlanUrl); - dataOutputStream.writeUTF( this.uploadFacilityReportUrl ); - dataOutputStream.writeUTF( this.uploadActivityReportUrl ); - dataOutputStream.writeUTF( this.updateDataSetUrl ); - } - - public void deSerialize( DataInputStream dataInputStream ) - throws IOException - { - this.id = dataInputStream.readInt(); - this.name = dataInputStream.readUTF(); - this.downloadAllUrl = dataInputStream.readUTF(); - this.updateActivityPlanUrl = dataInputStream.readUTF(); - this.uploadFacilityReportUrl = dataInputStream.readUTF(); - this.uploadActivityReportUrl = dataInputStream.readUTF(); - this.updateDataSetUrl = dataInputStream.readUTF(); - } - -} === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnits.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnits.java 2010-12-08 05:45:56 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnits.java 2011-02-25 04:16:18 +0000 @@ -13,24 +13,24 @@ public class OrgUnits implements DataStreamSerializable { - private List orgUnits = new ArrayList(); + private List orgUnits = new ArrayList(); public OrgUnits() { } - public OrgUnits( List unitList ) + public OrgUnits( List unitList ) { this.orgUnits = unitList; } @XmlElement( name = "orgUnit" ) - public List getOrgUnits() + public List getOrgUnits() { return orgUnits; } - public void setOrgUnits( List orgUnits ) + public void setOrgUnits( List orgUnits ) { this.orgUnits = orgUnits; } @@ -40,7 +40,7 @@ throws IOException { dataOutputStream.writeInt( orgUnits.size() ); - for ( OrgUnit unit : orgUnits ) + for ( MobileOrgUnitLinks unit : orgUnits ) { unit.serialize( dataOutputStream ); } @@ -51,12 +51,12 @@ public void deSerialize( DataInputStream dataInputStream ) throws IOException { - orgUnits = new ArrayList(); + orgUnits = new ArrayList(); int size = dataInputStream.readInt(); for ( int i = 0; i < size; i++ ) { - OrgUnit unit = new OrgUnit(); + MobileOrgUnitLinks unit = new MobileOrgUnitLinks(); unit.deSerialize( dataInputStream ); orgUnits.add( unit ); } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ApiResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ApiResource.java 2011-02-21 10:32:35 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ApiResource.java 2011-02-25 04:16:18 +0000 @@ -20,10 +20,7 @@ @Produces( MediaType.TEXT_HTML ) public String getDescription() { - StringBuilder sb = new StringBuilder(); - - sb.append( " \n" ); - sb.append( "DHIS2 Web API\n\n

DHIS2 Web API

\n" ); + StringBuilder sb = Html.head( null ); sb.append( "

Warning: This API is in no way ready for public consumption. Radical changes must be expected at any time!

\n" ); @@ -31,10 +28,10 @@ sb.append( "

Posting data value sets

" ); sb.append( "

To find the needed information about the data sets you want to post data about, go to " ); - URI uri = uriInfo.getBaseUriBuilder().path( DataSetResource.class ).build(); - sb.append( "the data set list.

" ); - - DataValueSetResource.xmlTemplate( sb, uriInfo ); + sb.append( "the data set list.

" ); + sb.append( "

If you don't want org units listed by data set, there is also the full list of org units

" ); + + Html.xmlTemplate( sb, uriInfo ); sb.append( "

Mobile GPRS API

" ); sb.append( "

The api/mobile path will return a list of the currently logged in user's" ); @@ -43,7 +40,7 @@ sb.append( "

The url's, and their content is quite specifically tailored for the mobile client, and the serialization" ); sb.append( " format for the mobile solution is java's native data serialization, zipped. But it does send xml (and potentially json)" ); sb.append( " if you request that in your Accept header (xml would be chosen by browsers by default), so have a look if you like.

" ); - sb.append( "

If the user you are logged in as are not associated with any org unit, try going directly to one of the org units

" ); + sb.append( "

If the user you are logged in as are not associated with any org unit, try going directly to one of the org units

" ); sb.append( "\n\n" ); return sb.toString(); } === 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-21 10:32:35 +0000 +++ 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 @@ -1,6 +1,5 @@ package org.hisp.dhis.web.api.resources; -import java.net.URI; import java.util.Set; import javax.ws.rs.GET; @@ -19,7 +18,7 @@ import org.hisp.dhis.organisationunit.OrganisationUnit; import org.springframework.beans.factory.annotation.Required; -@Path( "dataSets" ) +@Path( "dataSets/{uuid}" ) public class DataSetResource { @@ -29,29 +28,7 @@ UriInfo uriInfo; @GET - @Produces( MediaType.TEXT_HTML ) - public String getDataSetList() - { - StringBuilder t = new StringBuilder(); - t.append( head( "Data sets available for reporting" ) ); - - t.append( "

Data sets available for reporting

\n
    \n" ); - for ( DataSet dataSet : dataSetService.getAllDataSets() ) - { - URI uri = uriInfo.getAbsolutePathBuilder().path( "{uuid}" ).build( dataSet.getUuid() ); - t.append( "
  • " ).append( "" ).append( dataSet.getName() ) - .append( "
  • \n" ); - } - t.append( "
" ); - DataValueSetResource.xmlTemplate( t, uriInfo ); - t.append( tail() ); - - return t.toString(); - } - - @GET - @Produces( { MediaType.APPLICATION_XML, DhisMediaType.DXF } ) - @Path( "{uuid}/dxf" ) + @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) public org.hisp.dhis.importexport.dxf2.model.DataSet getDataSetXml( @PathParam( "uuid" ) String uuid ) { DataSet dataSet = dataSetService.getDataSet( uuid ); @@ -60,11 +37,10 @@ { throw new IllegalArgumentException( "No dataset with uuid " + uuid ); } - return DataSetMapper.convert( dataSet ); + return new DataSetMapper().convert( dataSet ); } @GET - @Path( "{uuid}" ) @Produces( MediaType.TEXT_HTML ) public String getDataSet( @PathParam( "uuid" ) String uuid ) { @@ -76,12 +52,8 @@ throw new IllegalArgumentException( "No dataset with uuid " + uuid ); } - StringBuilder t = new StringBuilder(); - - t.append( head( "Data set " + dataSet.getName() ) ); - URI url = uriInfo.getAbsolutePathBuilder().path( "/dxf" ).build(); - t.append( "

(There is also a prototype xml version of this data set available)

\n" ); + StringBuilder t = Html.head( "Data set " + dataSet.getName() ); + t.append( "

See the xml version

\n" ); t.append( "

Uuid: " ).append( dataSet.getUuid() ).append( "
\n" ); t.append( "Period type: " ).append( dataSet.getPeriodType().getName() ).append( " - " ) .append( dataSet.getPeriodType().getIsoFormat() ); @@ -117,23 +89,15 @@ t.append( "" ); t.append( "

Xml template

\n" ); - DataValueSetResource.xmlTemplate( t, uriInfo ); - t.append( tail() ); + Html.xmlTemplate( t, uriInfo ); + t.append( Html.tail() ); return t.toString(); } - private String head( String title ) - { - return " \n" - + title + "\n" + "\n

" + title + "

\n"; - } - - private String tail() - { - return "\n\n"; - } - + + + @Required public void setDataSetService( DataSetService dataSetService ) { === added 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 1970-01-01 00:00:00 +0000 +++ 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 @@ -0,0 +1,69 @@ +package org.hisp.dhis.web.api.resources; + +import java.net.URI; +import java.util.Collection; +import java.util.List; + +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.common.IdentifiableObject; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.DataSetService; +import org.hisp.dhis.importexport.dxf2.model.DataSetLinks; +import org.hisp.dhis.importexport.dxf2.model.Link; +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.springframework.beans.factory.annotation.Required; + +@Path( "dataSets" ) +public class DataSetsResource +{ + + private LinkBuilder linkBuilder = new LinkBuilderImpl(); + + private DataSetService dataSetService; + + @Context + UriInfo uriInfo; + + @GET + @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) + public DataSetLinks getDataSetLinks() { + return new DataSetLinks( linkBuilder.getLinks( dataSetService.getAllDataSets() ) ); + } + + @GET + @Produces( MediaType.TEXT_HTML ) + public String getDataSetList() + { + StringBuilder t = Html.head( "Data sets available for reporting" ); + + t.append( "

See the xml version

\n" ); + for ( DataSet dataSet : dataSetService.getAllDataSets() ) + { + URI uri = uriInfo.getAbsolutePathBuilder().path( "{uuid}" ).build( dataSet.getUuid() ); + t.append( "
  • " ).append( "" ).append( dataSet.getName() ) + .append( "
  • \n" ); + } + t.append( "" ); + Html.xmlTemplate( t, uriInfo ); + t.append( Html.tail() ); + + return t.toString(); + } + + + + @Required + public void setDataSetService( DataSetService dataSetService ) + { + this.dataSetService = dataSetService; + } + +} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataValueSetResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataValueSetResource.java 2011-02-18 20:17:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataValueSetResource.java 1970-01-01 00:00:00 +0000 @@ -1,75 +0,0 @@ -package org.hisp.dhis.web.api.resources; - -import java.net.URI; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -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.DataValueSet; -import org.hisp.dhis.importexport.dxf2.service.DataValueSetService; -import org.springframework.beans.factory.annotation.Required; - -@Path( "dataValueSets" ) -public class DataValueSetResource -{ - - private DataValueSetService dataValueSetService; - - @Context UriInfo uriInfo; - - @GET - @Produces( MediaType.TEXT_HTML ) - public String getDescription() { - StringBuilder sb = new StringBuilder(); - - sb.append( " \n"); - sb.append( "DHIS2 Web API: Data value sets\n\n

    Data value sets

    \n"); - URI uri = uriInfo.getBaseUriBuilder().path( DataSetResource.class ).build( ); - sb.append( "

    This resource is the place to post data value sets. Take a look at the data sets to see what to post.." ); - xmlTemplate( sb, null ); - - sb.append( "\n\n" ); - - return sb.toString(); - } - - @POST - @Consumes( MediaType.APPLICATION_XML ) - public void storeDataValueSet( DataValueSet dataValueSet ) - { - dataValueSetService.saveDataValueSet( dataValueSet ); - } - - @Required - public void setDataValueSetService( DataValueSetService dataValueSetService ) - { - this.dataValueSetService = dataValueSetService; - } - - - public static void xmlTemplate( StringBuilder t, UriInfo uriInfo ) - { - - t.append( "

    Post according to the following template" ); - if (uriInfo != null) { - URI uri = uriInfo.getBaseUriBuilder().path( DataValueSetResource.class ).build(); - t.append( " to " ).append( uri ).append( ""); - } - t.append( ":

    " ); - - t.append( "
    " ).append( "<dataValueSet xmlns=\"http://dhis2.org/schema/dxf/2.0-SNAPSHOT\"\n" );
    -        t.append( "    dataSet=\"dataSet UUID\" \n    period=\"periodInIsoFormat\"\n    orgUnit=\"unit UUID\">" );
    -
    -        t.append( "\n  <dataValue dataElement=\"data element UUID\" categoryOptionCombo=\"UUID, only specify if used\" storedBy=\"string\" value=\"value\"/>" );
    -        t.append( "\n</dataValueSet>" );
    -        t.append( "
    " ); - } - -} === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataValueSetsResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataValueSetsResource.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataValueSetsResource.java 2011-02-25 04:16:18 +0000 @@ -0,0 +1,53 @@ +package org.hisp.dhis.web.api.resources; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +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.DataValueSet; +import org.hisp.dhis.importexport.dxf2.service.DataValueSetService; +import org.springframework.beans.factory.annotation.Required; + +@Path( "dataValueSets" ) +public class DataValueSetsResource +{ + + private DataValueSetService dataValueSetService; + + @Context UriInfo uriInfo; + + @GET + @Produces( MediaType.TEXT_HTML ) + public String getDescription() { + StringBuilder sb = Html.head( "Data value sets" ); + URI uri = uriInfo.getBaseUriBuilder().path( DataSetsResource.class ).build( ); + sb.append( "

    This resource is the place to post data value sets. Take a look at the data sets to see what to post.." ); + Html.xmlTemplate( sb, null ); + + sb.append( Html.tail() ); + + return sb.toString(); + } + + @POST + @Consumes( MediaType.APPLICATION_XML ) + public void storeDataValueSet( DataValueSet dataValueSet ) + { + dataValueSetService.saveDataValueSet( dataValueSet ); + } + + @Required + public void setDataValueSetService( DataValueSetService dataValueSetService ) + { + this.dataValueSetService = dataValueSetService; + } + +} === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/Html.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/Html.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/Html.java 2011-02-25 04:16:18 +0000 @@ -0,0 +1,59 @@ +package org.hisp.dhis.web.api.resources; + +import java.net.URI; + +import javax.ws.rs.core.UriInfo; + +public class Html +{ + + public static StringBuilder head( String title ) + { + StringBuilder sb = new StringBuilder( + " \nDHIS2 Web API" ); + + if ( title != null ) + { + sb.append( " - " ).append( title ); + } + + sb.append( "\n\n

    " ); + if ( title == null ) + { + sb.append( "DHIS2 Web API" ); + } + else + { + sb.append( title ); + } + sb.append( "

    \n" ); + + return sb; + + } + + public static String tail() + { + return "\n\n"; + } + + public static void xmlTemplate( StringBuilder t, UriInfo uriInfo ) + { + + t.append( "

    Post according to the following template" ); + if ( uriInfo != null ) + { + URI uri = uriInfo.getBaseUriBuilder().path( DataValueSetsResource.class ).build(); + t.append( " to " ).append( uri ).append( "" ); + } + t.append( ":

    " ); + + t.append( "
    " ).append( "<dataValueSet xmlns=\"http://dhis2.org/schema/dxf/2.0-SNAPSHOT\"\n" );
    +        t.append( "    dataSet=\"dataSet UUID\" \n    period=\"periodInIsoFormat\"\n    orgUnit=\"unit UUID\">" );
    +
    +        t.append( "\n  <dataValue dataElement=\"data element UUID\" categoryOptionCombo=\"UUID, only specify if used\" storedBy=\"string\" value=\"value\"/>" );
    +        t.append( "\n</dataValueSet>" );
    +        t.append( "
    " ); + } + +} === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java 2011-02-18 20:17:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java 2011-02-25 04:16:18 +0000 @@ -41,7 +41,7 @@ import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; -import org.hisp.dhis.web.api.model.OrgUnit; +import org.hisp.dhis.web.api.model.MobileOrgUnitLinks; import org.hisp.dhis.web.api.model.OrgUnits; import org.hisp.dhis.web.api.service.NotAllowedException; import org.springframework.beans.factory.annotation.Required; @@ -76,7 +76,7 @@ Collection units = user.getOrganisationUnits(); - List unitList = new ArrayList(); + List unitList = new ArrayList(); for ( OrganisationUnit unit : units ) { unitList.add( OrgUnitResource.getOrgUnit( unit, uriInfo ) ); === 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-22 23:17:50 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2011-02-25 04:16:18 +0000 @@ -45,6 +45,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.hisp.dhis.importexport.dxf2.model.OrgUnit; +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.model.ActivityValue; @@ -53,7 +55,7 @@ import org.hisp.dhis.web.api.model.DataSetValue; import org.hisp.dhis.web.api.model.MobileModel; import org.hisp.dhis.web.api.model.ModelList; -import org.hisp.dhis.web.api.model.OrgUnit; +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; @@ -67,7 +69,7 @@ public class OrgUnitResource { private OrganisationUnitService organisationUnitService; - + private static Log log = LogFactory.getLog( ActivityReportingServiceImpl.class ); private static final boolean DEBUG = log.isDebugEnabled(); @@ -78,19 +80,36 @@ private FacilityReportingService facilityReportingService; - @PathParam( "id" ) private int id; - - @Context UriInfo uriInfo; - - private OrganisationUnit getUnit() { - return organisationUnitService.getOrganisationUnit( id ); + @PathParam( "id" ) + private String id; + + @Context + UriInfo uriInfo; + + private OrganisationUnit getUnit() + { + try + { + return organisationUnitService.getOrganisationUnit( Integer.parseInt( id ) ); + } + catch ( NumberFormatException e ) + { + return organisationUnitService.getOrganisationUnit( id ); + } } - + @GET - public OrgUnit getOrgUnit() { - return OrgUnitResource.getOrgUnit( getUnit(), uriInfo ); + @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) + public OrgUnit getOrgUnit() + { + OrganisationUnit unit = getUnit(); + + if (unit == null) + return null; + + return new OrgUnitMapper().get( unit ); } - + /** * Get activity plan, program forms and facility forms wrapped in a * {@link MobileModel} @@ -168,7 +187,7 @@ updatedDataSetList.getModifiedDataSets().add( dataSets.get( i ) ); } } - + if ( DEBUG ) log.debug( "Returning updated datasets for org unit " + getUnit().getName() ); @@ -210,37 +229,34 @@ { MobileModel model = new MobileModel(); model.setPrograms( programService.updateProgram( programsFromClient, locale, getUnit() ) ); - model.setActivityPlan(activityReportingService.getCurrentActivityPlan( getUnit(), locale )); + model.setActivityPlan( activityReportingService.getCurrentActivityPlan( getUnit(), locale ) ); return model; } - public static OrgUnit getOrgUnit( OrganisationUnit unit, UriInfo uriInfo ) + public static MobileOrgUnitLinks getOrgUnit( OrganisationUnit unit, UriInfo uriInfo ) { - OrgUnit orgUnit = new OrgUnit(); + MobileOrgUnitLinks orgUnit = new MobileOrgUnitLinks(); orgUnit.setId( unit.getId() ); orgUnit.setName( unit.getShortName() ); - orgUnit.setDownloadAllUrl( getOrgUnitUrlBuilder(uriInfo).path( "all" ) - .build( unit.getId() ).toString() ); - orgUnit.setUpdateActivityPlanUrl( getOrgUnitUrlBuilder(uriInfo).path( "activitiyplan" ) - .build( unit.getId() ).toString() ); - orgUnit.setUploadFacilityReportUrl( getOrgUnitUrlBuilder(uriInfo).path( "dataSets" ) - .build( unit.getId() ).toString() ); - orgUnit.setUploadActivityReportUrl( getOrgUnitUrlBuilder(uriInfo).path( "activities" ) - .build( unit.getId() ).toString() ); - orgUnit.setUpdateDataSetUrl( getOrgUnitUrlBuilder(uriInfo).path( "updateDataSets" ) - .build( unit.getId() ).toString() ); + orgUnit.setDownloadAllUrl( getOrgUnitUrlBuilder( uriInfo ).path( "all" ).build( unit.getId() ).toString() ); + orgUnit.setUpdateActivityPlanUrl( getOrgUnitUrlBuilder( uriInfo ).path( "activitiyplan" ).build( unit.getId() ) + .toString() ); + orgUnit.setUploadFacilityReportUrl( getOrgUnitUrlBuilder( uriInfo ).path( "dataSets" ).build( unit.getId() ) + .toString() ); + orgUnit.setUploadActivityReportUrl( getOrgUnitUrlBuilder( uriInfo ).path( "activities" ).build( unit.getId() ) + .toString() ); + orgUnit.setUpdateDataSetUrl( getOrgUnitUrlBuilder( uriInfo ).path( "updateDataSets" ).build( unit.getId() ) + .toString() ); return orgUnit; } - private static UriBuilder getOrgUnitUrlBuilder(UriInfo uriInfo) + private static UriBuilder getOrgUnitUrlBuilder( UriInfo uriInfo ) { return uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ); } - - @Required public void setProgramService( IProgramService programService ) { === 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-18 20:17:34 +0000 +++ 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 @@ -5,6 +5,9 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +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.springframework.web.util.HtmlUtils; @@ -14,20 +17,29 @@ { private OrganisationUnitService organisationUnitService; + private LinkBuilder linkBuilder = new LinkBuilderImpl(); + + @GET + @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) + public OrgUnitLinks getOrgUnits() + { + return new OrgUnitLinks( linkBuilder.getLinks( organisationUnitService.getAllOrganisationUnits() ) ); + } + @GET @Produces( MediaType.TEXT_HTML ) - public String getOrgUnits() + public String getOrgUnitsHtml() { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = Html.head( "Org units" ); - sb.append( " \n" ); - sb.append( "DHIS2 Web API: Org units\n\n

    Data value sets

    \n
      " ); + sb.append( "

      See the xml version

      \n" ); + sb.append( "\n\n" ); @@ -39,6 +51,5 @@ { this.organisationUnitService = organisationUnitService; } - - + } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2011-02-21 10:32:35 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2011-02-25 04:16:18 +0000 @@ -7,12 +7,17 @@ + + + + - + === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml' --- dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml 2011-02-21 10:32:35 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml 2011-02-25 04:16:18 +0000 @@ -2,102 +2,100 @@ - DHIS Case Entry - - - contextConfigLocation - classpath*:/META-INF/dhis/beans.xml - - - automaticAccessType - ghostAdmin - - - - RedirectFilter - - org.hisp.dhis.servlet.filter.HttpRedirectFilter - - redirectPath - api/ - - - - OpenSessionInViewFilter - - org.springframework.orm.hibernate3.support.OpenSessionInViewFilter - - - filterChainProxy - - org.springframework.web.filter.DelegatingFilterProxy - - - - Struts - - org.apache.struts2.dispatcher.FilterDispatcher - - - - RedirectFilter - / - - - OpenSessionInViewFilter - *.action - - - OpenSessionInViewFilter - /api/* - - - filterChainProxy - /* - - - Struts - *.action - - - - - org.springframework.web.context.ContextLoaderListener - - - - org.hisp.dhis.system.startup.StartupListener - - - - web-api - - com.sun.jersey.spi.spring.container.servlet.SpringServlet - - - com.sun.jersey.spi.container.ContainerRequestFilters - - com.sun.jersey.api.container.filter.LoggingFilter - - - - com.sun.jersey.spi.container.ContainerResponseFilters - - com.sun.jersey.api.container.filter.LoggingFilter - - - com.sun.jersey.config.feature.Trace - true - - 1 - - - web-api - /api/* - + DHIS Case Entry + + + contextConfigLocation + classpath*:/META-INF/dhis/beans.xml + + + automaticAccessType + ghostAdmin + + + + RedirectFilter + + org.hisp.dhis.servlet.filter.HttpRedirectFilter + + redirectPath + api/ + + + + OpenSessionInViewFilter + + org.springframework.orm.hibernate3.support.OpenSessionInViewFilter + + + filterChainProxy + + org.springframework.web.filter.DelegatingFilterProxy + + + + Struts + + org.apache.struts2.dispatcher.FilterDispatcher + + + + RedirectFilter + / + + + OpenSessionInViewFilter + *.action + + + OpenSessionInViewFilter + /api/* + + + filterChainProxy + /* + + + Struts + *.action + + + + + org.springframework.web.context.ContextLoaderListener + + + + org.hisp.dhis.system.startup.StartupListener + + + + web-api + com.sun.jersey.spi.spring.container.servlet.SpringServlet + + com.sun.jersey.config.property.packages + org.hisp.dhis.web.api.resources + + + com.sun.jersey.spi.container.ContainerRequestFilters + + com.sun.jersey.api.container.filter.LoggingFilter, org.hisp.dhis.web.api.HtmlPromotingUriConnegFilter + + + + + + + + 1 + + + web-api + /api/* + web-api /api - + \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitTest.java' --- dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitTest.java 2011-02-21 06:51:20 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitTest.java 2011-02-25 04:16:18 +0000 @@ -44,7 +44,7 @@ public void testSerialization() throws IOException { - OrgUnit unit = new OrgUnit(); + MobileOrgUnitLinks unit = new MobileOrgUnitLinks(); unit.setId( 1 ); unit.setName( "name" ); unit.setUpdateActivityPlanUrl("updateActivityPlanUrl"); @@ -57,7 +57,7 @@ DataOutputStream dos = new DataOutputStream( baos ); unit.serialize( dos ); dos.flush(); - OrgUnit unit2 = new OrgUnit(); + MobileOrgUnitLinks unit2 = new MobileOrgUnitLinks(); unit2.deSerialize( new DataInputStream( new ByteArrayInputStream( baos.toByteArray() ) ) ); assertEquals( unit.getName(), unit2.getName() ); === modified file 'dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitsTest.java' --- dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitsTest.java 2011-02-21 06:51:20 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitsTest.java 2011-02-25 04:16:18 +0000 @@ -37,7 +37,7 @@ import java.util.Arrays; import java.util.List; -import org.hisp.dhis.web.api.model.OrgUnit; +import org.hisp.dhis.web.api.model.MobileOrgUnitLinks; import org.hisp.dhis.web.api.model.OrgUnits; import org.junit.Test; @@ -48,29 +48,29 @@ public void testSerialization() throws IOException { - OrgUnit unit = createOrgUnit(); + MobileOrgUnitLinks unit = createOrgUnit(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream( baos ); OrgUnits units = new OrgUnits(); - units.setOrgUnits( Arrays.asList( new OrgUnit[] { unit } ) ); + units.setOrgUnits( Arrays.asList( new MobileOrgUnitLinks[] { unit } ) ); units.serialize( dos ); dos.flush(); OrgUnits units2 = new OrgUnits(); units2.deSerialize( new DataInputStream( new ByteArrayInputStream( baos.toByteArray() ) ) ); - List unitList = units2.getOrgUnits(); + List unitList = units2.getOrgUnits(); assertEquals( 1, unitList.size() ); - OrgUnit unit2 = unitList.get( 0 ); + MobileOrgUnitLinks unit2 = unitList.get( 0 ); assertEquals( unit.getName(), unit2.getName() ); assertEquals( unit.getId(), unit2.getId() ); } - private OrgUnit createOrgUnit() + private MobileOrgUnitLinks createOrgUnit() { - OrgUnit unit = new OrgUnit(); + MobileOrgUnitLinks unit = new MobileOrgUnitLinks(); unit.setId( 1 ); unit.setName( "name" ); unit.setUpdateActivityPlanUrl("updateActivityPlanUrl"); === modified file 'dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml' --- dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml 2011-02-18 20:17:34 +0000 +++ dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml 2011-02-25 04:16:18 +0000 @@ -67,6 +67,14 @@ web-api com.sun.jersey.spi.spring.container.servlet.SpringServlet + + com.sun.jersey.config.property.packages + org.hisp.dhis.web.api.resources + + + com.sun.jersey.spi.container.ContainerRequestFilters + org.hisp.dhis.web.api.HtmlPromotingUriConnegFilter + 1