=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/action/ImportDataValueAction.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/action/ImportDataValueAction.java 2010-09-24 11:12:49 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/action/ImportDataValueAction.java 2011-01-12 09:13:36 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.web.api.action; +/* + * 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.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; @@ -137,10 +164,10 @@ request = ServletActionContext.getRequest(); response = ServletActionContext.getResponse(); this.setInputStream( new ByteArrayInputStream( message.getBytes() ) ); - + InputStream clientInput = request.getInputStream(); DataInputStream dis = new DataInputStream( clientInput ); - + if ( clientInput.available() > -1 ) { int numOfDataValue = dis.readInt(); @@ -162,28 +189,24 @@ return SUCCESS; } - private void saveDataValue( DataInputStream dis, OrganisationUnit orgUnit ) throws IOException + private void saveDataValue( DataInputStream dis, OrganisationUnit orgUnit ) + throws IOException { - DataElement dataElement = dataElementService.getDataElement( dis.readInt() ); - ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( dis - .readInt() ); - DataElementCategoryOptionCombo optionCombo = dataElementCategoryService - .getDataElementCategoryOptionCombo( 1 ); - - PatientDataValue patientDataValue = new PatientDataValue(); - patientDataValue.setDataElement( dataElement ); - patientDataValue.setOptionCombo( optionCombo ); - patientDataValue.setOrganisationUnit( orgUnit ); - patientDataValue.setProgramStageInstance( programStageInstance ); - patientDataValue.setTimestamp( new Date() ); - patientDataValue.setProvidedByAnotherFacility( false ); - patientDataValue.setValue( dis.readUTF() ); - - patientDataValueService.savePatientDataValue( patientDataValue ); - } - - + DataElement dataElement = dataElementService.getDataElement( dis.readInt() ); + ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( dis.readInt() ); + DataElementCategoryOptionCombo optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo( 1 ); + + PatientDataValue patientDataValue = new PatientDataValue(); + patientDataValue.setDataElement( dataElement ); + patientDataValue.setOptionCombo( optionCombo ); + patientDataValue.setOrganisationUnit( orgUnit ); + patientDataValue.setProgramStageInstance( programStageInstance ); + patientDataValue.setTimestamp( new Date() ); + patientDataValue.setProvidedByAnotherFacility( false ); + patientDataValue.setValue( dis.readUTF() ); + + patientDataValueService.savePatientDataValue( patientDataValue ); } - +} === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/mapping/AbstractDataSerializableConsumer.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/mapping/AbstractDataSerializableConsumer.java 2010-12-02 10:53:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/mapping/AbstractDataSerializableConsumer.java 2011-01-12 09:13:36 +0000 @@ -42,13 +42,17 @@ import org.hisp.dhis.web.api.resources.DhisMediaType; /** - * An abstract class mapping from the {@link DhisMediaType.MOBILE_SERIALIZED} to implementations of {@link DataStreamSerializable} - * - *

Implementations only need to define T and specify the relevant annotations - * - * @param The concrete implementation of {@link DataStreamSerializable} this consumer creates and populates + * An abstract class mapping from the {@link DhisMediaType.MOBILE_SERIALIZED} to + * implementations of {@link DataStreamSerializable} + * + *

+ * Implementations only need to define T and specify the relevant annotations + * + * @param The concrete implementation of {@link DataStreamSerializable} this + * consumer creates and populates */ -public abstract class AbstractDataSerializableConsumer implements MessageBodyReader +public abstract class AbstractDataSerializableConsumer + implements MessageBodyReader { @Override public boolean isReadable( Class type, Type genericType, Annotation[] annotations, MediaType mediaType ) @@ -70,11 +74,11 @@ } catch ( InstantiationException e ) { - throw new IOException("Can't instantiate class " + type.getName(), e); + throw new IOException( "Can't instantiate class " + type.getName(), e ); } catch ( IllegalAccessException e ) { - throw new IOException("Not allowed to instantiate class " + type.getName(), e); + throw new IOException( "Not allowed to instantiate class " + type.getName(), e ); } } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Activity.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Activity.java 2010-11-27 04:15:31 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Activity.java 2011-01-12 09:13:36 +0000 @@ -96,19 +96,19 @@ dout.writeBoolean( late ); dout.writeLong( this.getDueDate().getTime() ); } - + @Override public void deSerialize( DataInputStream dataInputStream ) throws IOException { this.task = new Task(); task.deSerialize( dataInputStream ); - + this.beneficiary = new Beneficiary(); beneficiary.deSerialize( dataInputStream ); - + this.late = dataInputStream.readBoolean(); - this.dueDate = new Date(dataInputStream.readLong()); + this.dueDate = new Date( dataInputStream.readLong() ); } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityPlan.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityPlan.java 2010-11-27 04:15:31 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityPlan.java 2011-01-12 09:13:36 +0000 @@ -42,7 +42,7 @@ private List activitiesList; - @XmlElement(name="activity") + @XmlElement( name = "activity" ) public List getActivitiesList() { return activitiesList; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Beneficiary.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Beneficiary.java 2010-11-27 04:15:31 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Beneficiary.java 2011-01-12 09:13:36 +0000 @@ -61,8 +61,8 @@ @XmlAttribute private int age; - @XmlElementWrapper(name="attributes") - @XmlElement(name="attribute") + @XmlElementWrapper( name = "attributes" ) + @XmlElement( name = "attribute" ) private List patientAttValues; private PatientAttribute groupAttribute; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSetList.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSetList.java 2010-12-22 04:05:46 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSetList.java 2011-01-12 09:13:36 +0000 @@ -1,5 +1,32 @@ 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; @@ -7,14 +34,15 @@ import java.util.List; public class DataSetList - extends Model implements DataStreamSerializable + extends Model + implements DataStreamSerializable { private List addedDataSets; private List deletedDataSets; private List modifiedDataSets; - + private List currentDataSets; public DataSetList() @@ -72,7 +100,9 @@ { dataSet.serialize( dout ); } - }else{ + } + else + { dout.writeInt( 0 ); } if ( deletedDataSets != null ) @@ -82,7 +112,9 @@ { dataSet.serialize( dout ); } - }else{ + } + else + { dout.writeInt( 0 ); } if ( modifiedDataSets != null ) @@ -92,7 +124,9 @@ { dataSet.serialize( dout ); } - }else{ + } + else + { dout.writeInt( 0 ); } if ( currentDataSets != null ) @@ -102,47 +136,57 @@ { dataSet.serialize( dout ); } - }else{ + } + else + { dout.writeInt( 0 ); } } - + @Override public void deSerialize( DataInputStream dataInputStream ) throws IOException { int temp = 0; temp = dataInputStream.readInt(); - if(temp > 0){ + if ( temp > 0 ) + { addedDataSets = new ArrayList(); - for(int i = 0; i < temp; i++){ + for ( int i = 0; i < temp; i++ ) + { DataSet dataSet = new DataSet(); dataSet.deSerialize( dataInputStream ); addedDataSets.add( dataSet ); } } temp = dataInputStream.readInt(); - if(temp > 0){ + if ( temp > 0 ) + { deletedDataSets = new ArrayList(); - for(int i = 0; i < temp; i++){ + for ( int i = 0; i < temp; i++ ) + { DataSet dataSet = new DataSet(); dataSet.deSerialize( dataInputStream ); deletedDataSets.add( dataSet ); } } temp = dataInputStream.readInt(); - if(temp > 0){ + if ( temp > 0 ) + { modifiedDataSets = new ArrayList(); - for(int i = 0; i < temp; i++){ + for ( int i = 0; i < temp; i++ ) + { DataSet dataSet = new DataSet(); dataSet.deSerialize( dataInputStream ); modifiedDataSets.add( dataSet ); } } temp = dataInputStream.readInt(); - if(temp > 0){ + if ( temp > 0 ) + { currentDataSets = new ArrayList(); - for(int i = 0; i < temp; i++){ + for ( int i = 0; i < temp; i++ ) + { DataSet dataSet = new DataSet(); dataSet.deSerialize( dataInputStream ); currentDataSets.add( dataSet ); === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSetValue.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSetValue.java 2010-12-02 10:53:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSetValue.java 2011-01-12 09:13:36 +0000 @@ -75,7 +75,7 @@ this.dataValues = dataValues; } - @XmlElement(name="dataValue") + @XmlElement( name = "dataValue" ) public List getDataValues() { return dataValues; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataValue.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataValue.java 2010-12-02 10:53:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataValue.java 2011-01-12 09:13:36 +0000 @@ -81,7 +81,7 @@ throws IOException { // TODO Auto-generated method stub - + } @Override === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileModel.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileModel.java 2010-11-26 11:00:40 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileModel.java 2011-01-12 09:13:36 +0000 @@ -83,7 +83,8 @@ { dout.writeInt( 0 ); } - else { + else + { dout.writeInt( programs.size() ); for ( Program prog : programs ) @@ -102,7 +103,6 @@ this.activityPlan.serialize( dout ); } - // Write DataSets if ( datasets == null ) { === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ModelList.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ModelList.java 2010-11-27 04:15:31 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ModelList.java 2011-01-12 09:13:36 +0000 @@ -41,7 +41,7 @@ private List models; - @XmlElement(name="model") + @XmlElement( name = "model" ) public List getModels() { return models; @@ -56,10 +56,11 @@ public void serialize( DataOutputStream dataOutputStream ) throws IOException { - if (models == null) { - dataOutputStream.writeInt( 0 ); + if ( models == null ) + { + dataOutputStream.writeInt( 0 ); } - + dataOutputStream.writeInt( models.size() ); for ( int i = 0; i < models.size(); i++ ) === modified 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 2010-12-27 03:17:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java 2011-01-12 09:13:36 +0000 @@ -47,12 +47,11 @@ private String uploadFacilityReportUrl; private String uploadActivityReportUrl; - + private String updateProgramUrl; - + private String updateDataSetUrl; - @XmlAttribute public int getId() { @@ -113,7 +112,7 @@ public void setUploadActivityReportUrl( String uploadActivityReportUrl ) { this.uploadActivityReportUrl = uploadActivityReportUrl; - } + } public String getUpdateDataSetUrl() { === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/PatientAttribute.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/PatientAttribute.java 2010-11-27 04:15:31 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/PatientAttribute.java 2011-01-12 09:13:36 +0000 @@ -33,7 +33,8 @@ import javax.xml.bind.annotation.XmlAttribute; -public class PatientAttribute implements DataStreamSerializable +public class PatientAttribute + implements DataStreamSerializable { private String name; @@ -44,11 +45,11 @@ this.name = name; this.value = value; } - + public PatientAttribute() - { + { } - + @XmlAttribute public String getName() { === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/PatientIdentifier.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/PatientIdentifier.java 2010-11-26 11:00:40 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/PatientIdentifier.java 2011-01-12 09:13:36 +0000 @@ -6,13 +6,14 @@ import javax.xml.bind.annotation.XmlAttribute; -public class PatientIdentifier implements DataStreamSerializable +public class PatientIdentifier + implements DataStreamSerializable { private String identifierType; - + private String identifier; - - public PatientIdentifier( ) + + public PatientIdentifier() { } @@ -59,7 +60,5 @@ identifierType = dataInputStream.readUTF(); identifier = dataInputStream.readUTF(); } - - } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Program.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Program.java 2010-12-27 03:17:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Program.java 2011-01-12 09:13:36 +0000 @@ -37,7 +37,7 @@ { private int version; - + public int getVersion() { return version; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ProgramStage.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ProgramStage.java 2010-11-26 11:00:40 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ProgramStage.java 2011-01-12 09:13:36 +0000 @@ -65,7 +65,7 @@ dout.writeUTF( de.getName() ); dout.writeUTF( de.getType() ); dout.writeBoolean( de.isCompulsory() ); - + List cateOptCombos = de.getCategoryOptionCombos().getModels(); if ( cateOptCombos == null || cateOptCombos.size() <= 0 ) { @@ -80,7 +80,7 @@ dout.writeUTF( each.getName() ); } } - + } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java 2010-11-27 04:15:31 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java 2011-01-12 09:13:36 +0000 @@ -39,7 +39,7 @@ private List dataElements; - @XmlElement(name="dataElement") + @XmlElement( name = "dataElement" ) public List getDataElements() { return dataElements; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Task.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Task.java 2010-12-27 03:17:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Task.java 2011-01-12 09:13:36 +0000 @@ -31,14 +31,15 @@ import java.io.DataOutputStream; import java.io.IOException; -public class Task implements DataStreamSerializable +public class Task + implements DataStreamSerializable { - private int id; - + private int id; + private int programStageId; - + private int programId; - + private boolean completed; public int getId() @@ -49,7 +50,7 @@ public void setId( int id ) { this.id = id; - } + } public int getProgramStageId() { @@ -60,7 +61,7 @@ { this.programStageId = programStageId; } - + public int getProgramId() { return programId; @@ -85,10 +86,10 @@ public void serialize( DataOutputStream dout ) throws IOException { - dout.writeInt(this.getId()); - dout.writeInt(this.getProgramStageId()); + dout.writeInt( this.getId() ); + dout.writeInt( this.getProgramStageId() ); dout.writeInt( this.getProgramId() ); - dout.writeBoolean(this.isCompleted()); + dout.writeBoolean( this.isCompleted() ); } @Override @@ -96,6 +97,6 @@ throws IOException { // Fixme - + } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/comparator/ActivityComparator.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/comparator/ActivityComparator.java 2010-11-26 11:00:40 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/comparator/ActivityComparator.java 2011-01-12 09:13:36 +0000 @@ -1,10 +1,38 @@ package org.hisp.dhis.web.api.model.comparator; +/* + * 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.util.Comparator; import org.hisp.dhis.web.api.model.Activity; -public class ActivityComparator implements Comparator +public class ActivityComparator + implements Comparator { @Override === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DhisMediaType.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DhisMediaType.java 2010-11-18 11:32:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DhisMediaType.java 2011-01-12 09:13:36 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.web.api.resources; +/* + * 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. + */ + public class DhisMediaType { public static final String ACTIVITYVALUELIST_SERIALIZED = "application/vnd.org.dhis2.activityvaluelist+serialized"; === 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 2010-12-27 03:17:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java 2011-01-12 09:13:36 +0000 @@ -110,8 +110,8 @@ orgUnit.setId( unit.getId() ); orgUnit.setName( unit.getShortName() ); - orgUnit.setDownloadAllUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "all" ).build( unit.getId() ) - .toString() ); + orgUnit.setDownloadAllUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "all" ) + .build( unit.getId() ).toString() ); orgUnit.setDownloadActivityPlanUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "activitiyplan" ) .build( unit.getId() ).toString() ); orgUnit.setUploadFacilityReportUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "dataSets" ) @@ -121,7 +121,7 @@ orgUnit.setUpdateProgramUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "programs" ) .build( unit.getId() ).toString() ); orgUnit.setUpdateDataSetUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "updateDataSets" ) - .build( unit.getId() ).toString() ); + .build( unit.getId() ).toString() ); return orgUnit; } === 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 2010-12-27 03:17:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2011-01-12 09:13:36 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.web.api.resources; +/* + * 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.util.ArrayList; import java.util.Collections; import java.util.List; @@ -83,45 +110,48 @@ DataSetList updatedDataSetList = new DataSetList(); List dataSets = facilityReportingService.getMobileDataSetsForUnit( unit, locale ); List currentDataSets = dataSetList.getCurrentDataSets(); -// List copyCurrentDataSets = new ArrayList(currentDataSets.size()); -// Collections.copy( copyCurrentDataSets, currentDataSets ); + // List copyCurrentDataSets = new + // ArrayList(currentDataSets.size()); + // Collections.copy( copyCurrentDataSets, currentDataSets ); // check added dataset for ( DataSet dataSet : dataSets ) { if ( !currentDataSets.contains( dataSet ) ) { - if(updatedDataSetList.getAddedDataSets() == null) + if ( updatedDataSetList.getAddedDataSets() == null ) updatedDataSetList.setAddedDataSets( new ArrayList() ); updatedDataSetList.getAddedDataSets().add( dataSet ); currentDataSets.add( dataSet ); } } - + // check deleted dataset for ( DataSet dataSet : currentDataSets ) { if ( !dataSets.contains( dataSet ) ) { - if(updatedDataSetList.getDeletedDataSets() == null) + if ( updatedDataSetList.getDeletedDataSets() == null ) updatedDataSetList.setDeletedDataSets( new ArrayList() ); - updatedDataSetList.getDeletedDataSets().add( new DataSet( dataSet ) ); + updatedDataSetList.getDeletedDataSets().add( new DataSet( dataSet ) ); } } - if(updatedDataSetList.getDeletedDataSets() != null){ - for (DataSet dataSet : updatedDataSetList.getDeletedDataSets()){ + if ( updatedDataSetList.getDeletedDataSets() != null ) + { + for ( DataSet dataSet : updatedDataSetList.getDeletedDataSets() ) + { currentDataSets.remove( dataSet ); } - } - - // check modified dataset + } + + // check modified dataset Collections.sort( dataSets ); Collections.sort( currentDataSets ); - + for ( int i = 0; i < dataSets.size(); i++ ) { if ( dataSets.get( i ).getVersion() != currentDataSets.get( i ).getVersion() ) { - if(updatedDataSetList.getModifiedDataSets() == null) + if ( updatedDataSetList.getModifiedDataSets() == null ) updatedDataSetList.setModifiedDataSets( new ArrayList() ); updatedDataSetList.getModifiedDataSets().add( dataSets.get( i ) ); } @@ -181,7 +211,7 @@ public MobileModel updatePrograms( @HeaderParam( "accept-language" ) String locale, ModelList programsFromClient ) { MobileModel model = new MobileModel(); - model.setPrograms( programService.updateProgram(programsFromClient, locale, unit) ); + model.setPrograms( programService.updateProgram( programsFromClient, locale, unit ) ); return model; } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingService.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingService.java 2010-12-02 10:53:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingService.java 2011-01-12 09:13:36 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.web.api.service; +/* + * 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 org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.web.api.model.ActivityPlan; import org.hisp.dhis.web.api.model.ActivityValue; @@ -9,6 +36,7 @@ public ActivityPlan getCurrentActivityPlan( OrganisationUnit unit, String localeString ); - public void saveActivityReport( OrganisationUnit unit, ActivityValue activityValue ) throws NotAllowedException; + public void saveActivityReport( OrganisationUnit unit, ActivityValue activityValue ) + throws NotAllowedException; } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java 2011-01-12 03:46:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java 2011-01-12 09:13:36 +0000 @@ -52,7 +52,7 @@ private org.hisp.dhis.program.ProgramService programService; private org.hisp.dhis.i18n.I18nService i18nService; - + private org.hisp.dhis.web.api.service.ModelMapping modelMapping; // ------------------------------------------------------------------------- @@ -75,20 +75,20 @@ { List programs = new ArrayList(); boolean isExisted = false; - - //Get all Program belong to this OrgUnit + + // Get all Program belong to this OrgUnit List serverPrograms = this.getPrograms( unit, localeString ); for ( int i = 0; i < serverPrograms.size(); i++ ) { Program program = serverPrograms.get( i ); - - //Loop thought the list of program from client + + // Loop thought the list of program from client for ( int j = 0; j < programsFromClient.getModels().size(); j++ ) { Model model = programsFromClient.getModels().get( j ); if ( program.getId() == model.getId() ) { - //Version is different + // Version is different if ( program.getVersion() != Integer.parseInt( model.getName() ) ) { programs.add( program ); @@ -96,7 +96,7 @@ } } } - //Server has more program than client + // Server has more program than client if ( isExisted == false ) { programs.add( program ); @@ -166,10 +166,10 @@ { this.i18nService = i18nService; } - + @Required - public void setModelMapping( - org.hisp.dhis.web.api.service.ModelMapping modelMapping) { - this.modelMapping = modelMapping; - } + public void setModelMapping( org.hisp.dhis.web.api.service.ModelMapping modelMapping ) + { + this.modelMapping = modelMapping; + } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingService.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingService.java 2010-12-02 10:53:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingService.java 2011-01-12 09:13:36 +0000 @@ -41,6 +41,7 @@ public DataSet getDataSetForLocale( int dataSetId, Locale locale ); - public void saveDataSetValues( OrganisationUnit unit, DataSetValue dataSetValue ) throws NotAllowedException; + public void saveDataSetValues( OrganisationUnit unit, DataSetValue dataSetValue ) + throws NotAllowedException; } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java 2011-01-12 03:46:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java 2011-01-12 09:13:36 +0000 @@ -61,299 +61,314 @@ import org.hisp.dhis.web.api.utils.PeriodUtil; import org.springframework.beans.factory.annotation.Required; -public class FacilityReportingServiceImpl implements FacilityReportingService { - private static Log log = LogFactory - .getLog(FacilityReportingServiceImpl.class); - - private static boolean DEBUG = log.isDebugEnabled(); - - private DataElementSortOrderComparator dataElementComparator = new DataElementSortOrderComparator(); - - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private PeriodService periodService; - - private org.hisp.dhis.dataelement.DataElementCategoryService categoryService; - - private org.hisp.dhis.datavalue.DataValueService dataValueService; - - private org.hisp.dhis.dataset.DataSetService dataSetService; - - private org.hisp.dhis.i18n.I18nService i18nService; - - private org.hisp.dhis.datalock.DataSetLockService dataSetLockService; - - private org.hisp.dhis.web.api.service.ModelMapping modelMapping; - - // ------------------------------------------------------------------------- - // Service methods - // ------------------------------------------------------------------------- - - public List getMobileDataSetsForUnit(OrganisationUnit unit, - String localeString) { - - List datasets = new ArrayList(); - Locale locale = LocaleUtil.getLocale(localeString); - - if (DEBUG) - log.debug("Getting data sets for unit " + unit.getName()); - - for (org.hisp.dhis.dataset.DataSet dataSet : dataSetService - .getDataSetsForMobile(unit)) { - PeriodType periodType = dataSet.getPeriodType(); - if (periodType instanceof DailyPeriodType - || periodType instanceof WeeklyPeriodType - || periodType instanceof MonthlyPeriodType - || periodType instanceof YearlyPeriodType - || periodType instanceof QuarterlyPeriodType) { - if (DEBUG) - log.debug("Found data set " + dataSet.getName()); - - datasets.add(getDataSetForLocale(dataSet.getId(), locale)); - } else { - log.warn("Dataset '" - + dataSet.getName() - + "' set to be reported from mobile, but not of a supported period type: " - + periodType.getName()); - } - } - - return datasets; - } - - public DataSet getDataSetForLocale(int dataSetId, Locale locale) { - org.hisp.dhis.dataset.DataSet dataSet = dataSetService - .getDataSet(dataSetId); - dataSet = i18n(i18nService, locale, dataSet); - Set sections = dataSet.getSections(); - - DataSet ds = new DataSet(); - - ds.setId(dataSet.getId()); - // Name defaults to short name with fallback to name if empty - String name = dataSet.getShortName(); - if (name == null || name.trim().isEmpty()) { - name = dataSet.getName(); - } - - ds.setName(name); - ds.setVersion(dataSet.getVersion()); - ds.setPeriodType(dataSet.getPeriodType().getName()); - - List

sectionList = new ArrayList
(); - ds.setSections(sectionList); - - if (sections == null || sections.size() == 0) { - List dataElements = new ArrayList( - dataSet.getDataElements()); - - Collections.sort(dataElements, dataElementComparator); - - // Fake Section to store Data Elements - Section section = new Section(); - section.setId(0); - section.setName(""); - - section.setDataElements(getDataElements(locale, dataElements)); - sectionList.add(section); - } else { - for (org.hisp.dhis.dataset.Section s : sections) { - Section section = new Section(); - section.setId(s.getId()); - section.setName(s.getName()); - - List dataElementList = getDataElements(locale, - s.getDataElements()); - section.setDataElements(dataElementList); - sectionList.add(section); - } - } - - return ds; - } - - private List getDataElements(Locale locale, - List dataElements) { - List dataElementList = new ArrayList(); - - for (org.hisp.dhis.dataelement.DataElement dataElement : dataElements) { - dataElement = i18n(i18nService, locale, dataElement); - - DataElement de = modelMapping.getDataElement(dataElement); - - // For facility Reporting, no data elements are mandatory - de.setCompulsory(false); - - dataElementList.add(de); - } - return dataElementList; - } - - @Override - public void saveDataSetValues(OrganisationUnit unit, - DataSetValue dataSetValue) throws NotAllowedException { - - org.hisp.dhis.dataset.DataSet dataSet = dataSetService - .getDataSet(dataSetValue.getId()); - - if (!dataSetService.getDataSetsBySource(unit).contains(dataSet)) { - throw new NotAllowedException("INVALID_DATASET_ASSOCIATION"); - } - - Period selectedPeriod = getPeriod(dataSetValue.getPeriodName(), - dataSet.getPeriodType()); - - if (selectedPeriod == null) { - throw new NotAllowedException("INVALID_PERIOD"); - } - - if (isDataSetLocked(unit, dataSet, selectedPeriod)) { - throw new NotAllowedException("DATASET_LOCKED"); - } - - Collection dataElements = dataSet - .getDataElements(); - Collection dataElementIds = new ArrayList( - dataSetValue.getDataValues().size()); - - for (DataValue dv : dataSetValue.getDataValues()) { - dataElementIds.add(dv.getId()); - } - - Map dataElementMap = new HashMap(); - for (org.hisp.dhis.dataelement.DataElement dataElement : dataElements) { - if (!dataElementIds.contains(dataElement.getId())) { - log.info("Dataset '" + dataSet.getName() + "' for org unit '" - + unit.getName() + "' missing data element '" - + dataElement.getName() + "'"); - } - dataElementMap.put(dataElement.getId(), dataElement); - } - - // Everything is fine, hence save - saveDataValues(dataSetValue, dataElementMap, selectedPeriod, unit, - categoryService.getDefaultDataElementCategoryOptionCombo()); - - } - - // ------------------------------------------------------------------------- - // Supportive method - // ------------------------------------------------------------------------- - - private boolean isDataSetLocked(OrganisationUnit unit, - org.hisp.dhis.dataset.DataSet dataSet, Period selectedPeriod) { - if (dataSetLockService.getDataSetLockByDataSetPeriodAndSource(dataSet, - selectedPeriod, unit) != null) - return true; - return false; - } - - private void saveDataValues(DataSetValue dataSetValue, - Map dataElementMap, - Period period, OrganisationUnit orgUnit, - DataElementCategoryOptionCombo optionCombo) { - - org.hisp.dhis.dataelement.DataElement dataElement; - String value; - - for (DataValue dv : dataSetValue.getDataValues()) { - value = dv.getValue(); - DataElementCategoryOptionCombo cateOptCombo = categoryService - .getDataElementCategoryOptionCombo(dv - .getCategoryOptComboID()); - if (value != null && value.trim().length() == 0) { - value = null; - } - - if (value != null) { - value = value.trim(); - } - - dataElement = dataElementMap.get(dv.getId()); - org.hisp.dhis.datavalue.DataValue dataValue = dataValueService - .getDataValue(orgUnit, dataElement, period, cateOptCombo); - - if (dataValue == null) { - if (value != null) { - dataValue = new org.hisp.dhis.datavalue.DataValue( - dataElement, period, orgUnit, value, "", - new Date(), "", cateOptCombo); - dataValueService.addDataValue(dataValue); - } - } else { - if (value != null) { - dataValue.setValue(value); - dataValue.setTimestamp(new Date()); - dataValueService.updateDataValue(dataValue); - } - } - - } - } - - public Period getPeriod(String periodName, PeriodType periodType) { - Period period = PeriodUtil.getPeriod(periodName, periodType); - - if (period == null) { - return null; - } - - Period persistedPeriod = periodService.getPeriod(period.getStartDate(), - period.getEndDate(), periodType); - - if (persistedPeriod == null) { - periodService.addPeriod(period); - persistedPeriod = periodService.getPeriod(period.getStartDate(), - period.getEndDate(), periodType); - } - - return persistedPeriod; - } - - // ------------------------------------------------------------------------- - // Dependency setters - // ------------------------------------------------------------------------- - - @Required - public void setPeriodService(PeriodService periodService) { - this.periodService = periodService; - } - - @Required - public void setCategoryService( - org.hisp.dhis.dataelement.DataElementCategoryService categoryService) { - this.categoryService = categoryService; - } - - @Required - public void setDataValueService( - org.hisp.dhis.datavalue.DataValueService dataValueService) { - this.dataValueService = dataValueService; - } - - @Required - public void setDataSetService( - org.hisp.dhis.dataset.DataSetService dataSetService) { - this.dataSetService = dataSetService; - } - - @Required - public void setI18nService(org.hisp.dhis.i18n.I18nService i18nService) { - this.i18nService = i18nService; - } - - @Required - public void setDataSetLockService( - org.hisp.dhis.datalock.DataSetLockService dataSetLockService) { - this.dataSetLockService = dataSetLockService; - } - - @Required - public void setModelMapping( - org.hisp.dhis.web.api.service.ModelMapping modelMapping) { - this.modelMapping = modelMapping; - } +public class FacilityReportingServiceImpl + implements FacilityReportingService +{ + private static Log log = LogFactory.getLog( FacilityReportingServiceImpl.class ); + + private static boolean DEBUG = log.isDebugEnabled(); + + private DataElementSortOrderComparator dataElementComparator = new DataElementSortOrderComparator(); + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private PeriodService periodService; + + private org.hisp.dhis.dataelement.DataElementCategoryService categoryService; + + private org.hisp.dhis.datavalue.DataValueService dataValueService; + + private org.hisp.dhis.dataset.DataSetService dataSetService; + + private org.hisp.dhis.i18n.I18nService i18nService; + + private org.hisp.dhis.datalock.DataSetLockService dataSetLockService; + + private org.hisp.dhis.web.api.service.ModelMapping modelMapping; + + // ------------------------------------------------------------------------- + // Service methods + // ------------------------------------------------------------------------- + + public List getMobileDataSetsForUnit( OrganisationUnit unit, String localeString ) + { + + List datasets = new ArrayList(); + Locale locale = LocaleUtil.getLocale( localeString ); + + if ( DEBUG ) + log.debug( "Getting data sets for unit " + unit.getName() ); + + for ( org.hisp.dhis.dataset.DataSet dataSet : dataSetService.getDataSetsForMobile( unit ) ) + { + PeriodType periodType = dataSet.getPeriodType(); + if ( periodType instanceof DailyPeriodType || periodType instanceof WeeklyPeriodType + || periodType instanceof MonthlyPeriodType || periodType instanceof YearlyPeriodType + || periodType instanceof QuarterlyPeriodType ) + { + if ( DEBUG ) + log.debug( "Found data set " + dataSet.getName() ); + + datasets.add( getDataSetForLocale( dataSet.getId(), locale ) ); + } + else + { + log.warn( "Dataset '" + dataSet.getName() + + "' set to be reported from mobile, but not of a supported period type: " + periodType.getName() ); + } + } + + return datasets; + } + + public DataSet getDataSetForLocale( int dataSetId, Locale locale ) + { + org.hisp.dhis.dataset.DataSet dataSet = dataSetService.getDataSet( dataSetId ); + dataSet = i18n( i18nService, locale, dataSet ); + Set sections = dataSet.getSections(); + + DataSet ds = new DataSet(); + + ds.setId( dataSet.getId() ); + // Name defaults to short name with fallback to name if empty + String name = dataSet.getShortName(); + if ( name == null || name.trim().isEmpty() ) + { + name = dataSet.getName(); + } + + ds.setName( name ); + ds.setVersion( dataSet.getVersion() ); + ds.setPeriodType( dataSet.getPeriodType().getName() ); + + List
sectionList = new ArrayList
(); + ds.setSections( sectionList ); + + if ( sections == null || sections.size() == 0 ) + { + List dataElements = new ArrayList( + dataSet.getDataElements() ); + + Collections.sort( dataElements, dataElementComparator ); + + // Fake Section to store Data Elements + Section section = new Section(); + section.setId( 0 ); + section.setName( "" ); + + section.setDataElements( getDataElements( locale, dataElements ) ); + sectionList.add( section ); + } + else + { + for ( org.hisp.dhis.dataset.Section s : sections ) + { + Section section = new Section(); + section.setId( s.getId() ); + section.setName( s.getName() ); + + List dataElementList = getDataElements( locale, s.getDataElements() ); + section.setDataElements( dataElementList ); + sectionList.add( section ); + } + } + + return ds; + } + + private List getDataElements( Locale locale, List dataElements ) + { + List dataElementList = new ArrayList(); + + for ( org.hisp.dhis.dataelement.DataElement dataElement : dataElements ) + { + dataElement = i18n( i18nService, locale, dataElement ); + + DataElement de = modelMapping.getDataElement( dataElement ); + + // For facility Reporting, no data elements are mandatory + de.setCompulsory( false ); + + dataElementList.add( de ); + } + return dataElementList; + } + + @Override + public void saveDataSetValues( OrganisationUnit unit, DataSetValue dataSetValue ) + throws NotAllowedException + { + + org.hisp.dhis.dataset.DataSet dataSet = dataSetService.getDataSet( dataSetValue.getId() ); + + if ( !dataSetService.getDataSetsBySource( unit ).contains( dataSet ) ) + { + throw new NotAllowedException( "INVALID_DATASET_ASSOCIATION" ); + } + + Period selectedPeriod = getPeriod( dataSetValue.getPeriodName(), dataSet.getPeriodType() ); + + if ( selectedPeriod == null ) + { + throw new NotAllowedException( "INVALID_PERIOD" ); + } + + if ( isDataSetLocked( unit, dataSet, selectedPeriod ) ) + { + throw new NotAllowedException( "DATASET_LOCKED" ); + } + + Collection dataElements = dataSet.getDataElements(); + Collection dataElementIds = new ArrayList( dataSetValue.getDataValues().size() ); + + for ( DataValue dv : dataSetValue.getDataValues() ) + { + dataElementIds.add( dv.getId() ); + } + + Map dataElementMap = new HashMap(); + for ( org.hisp.dhis.dataelement.DataElement dataElement : dataElements ) + { + if ( !dataElementIds.contains( dataElement.getId() ) ) + { + log.info( "Dataset '" + dataSet.getName() + "' for org unit '" + unit.getName() + + "' missing data element '" + dataElement.getName() + "'" ); + } + dataElementMap.put( dataElement.getId(), dataElement ); + } + + // Everything is fine, hence save + saveDataValues( dataSetValue, dataElementMap, selectedPeriod, unit, + categoryService.getDefaultDataElementCategoryOptionCombo() ); + + } + + // ------------------------------------------------------------------------- + // Supportive method + // ------------------------------------------------------------------------- + + private boolean isDataSetLocked( OrganisationUnit unit, org.hisp.dhis.dataset.DataSet dataSet, Period selectedPeriod ) + { + if ( dataSetLockService.getDataSetLockByDataSetPeriodAndSource( dataSet, selectedPeriod, unit ) != null ) + return true; + return false; + } + + private void saveDataValues( DataSetValue dataSetValue, + Map dataElementMap, Period period, OrganisationUnit orgUnit, + DataElementCategoryOptionCombo optionCombo ) + { + + org.hisp.dhis.dataelement.DataElement dataElement; + String value; + + for ( DataValue dv : dataSetValue.getDataValues() ) + { + value = dv.getValue(); + DataElementCategoryOptionCombo cateOptCombo = categoryService.getDataElementCategoryOptionCombo( dv + .getCategoryOptComboID() ); + if ( value != null && value.trim().length() == 0 ) + { + value = null; + } + + if ( value != null ) + { + value = value.trim(); + } + + dataElement = dataElementMap.get( dv.getId() ); + org.hisp.dhis.datavalue.DataValue dataValue = dataValueService.getDataValue( orgUnit, dataElement, period, + cateOptCombo ); + + if ( dataValue == null ) + { + if ( value != null ) + { + dataValue = new org.hisp.dhis.datavalue.DataValue( dataElement, period, orgUnit, value, "", + new Date(), "", cateOptCombo ); + dataValueService.addDataValue( dataValue ); + } + } + else + { + if ( value != null ) + { + dataValue.setValue( value ); + dataValue.setTimestamp( new Date() ); + dataValueService.updateDataValue( dataValue ); + } + } + + } + } + + public Period getPeriod( String periodName, PeriodType periodType ) + { + Period period = PeriodUtil.getPeriod( periodName, periodType ); + + if ( period == null ) + { + return null; + } + + Period persistedPeriod = periodService.getPeriod( period.getStartDate(), period.getEndDate(), periodType ); + + if ( persistedPeriod == null ) + { + periodService.addPeriod( period ); + persistedPeriod = periodService.getPeriod( period.getStartDate(), period.getEndDate(), periodType ); + } + + return persistedPeriod; + } + + // ------------------------------------------------------------------------- + // Dependency setters + // ------------------------------------------------------------------------- + + @Required + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } + + @Required + public void setCategoryService( org.hisp.dhis.dataelement.DataElementCategoryService categoryService ) + { + this.categoryService = categoryService; + } + + @Required + public void setDataValueService( org.hisp.dhis.datavalue.DataValueService dataValueService ) + { + this.dataValueService = dataValueService; + } + + @Required + public void setDataSetService( org.hisp.dhis.dataset.DataSetService dataSetService ) + { + this.dataSetService = dataSetService; + } + + @Required + public void setI18nService( org.hisp.dhis.i18n.I18nService i18nService ) + { + this.i18nService = i18nService; + } + + @Required + public void setDataSetLockService( org.hisp.dhis.datalock.DataSetLockService dataSetLockService ) + { + this.dataSetLockService = dataSetLockService; + } + + @Required + public void setModelMapping( org.hisp.dhis.web.api.service.ModelMapping modelMapping ) + { + this.modelMapping = modelMapping; + } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IProgramService.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IProgramService.java 2010-12-27 03:17:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IProgramService.java 2011-01-12 09:13:36 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.web.api.service; +/* + * 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.util.List; import org.hisp.dhis.organisationunit.OrganisationUnit; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ModelMapping.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ModelMapping.java 2011-01-12 03:46:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ModelMapping.java 2011-01-12 09:13:36 +0000 @@ -30,67 +30,67 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Set; import org.hisp.dhis.web.api.model.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryCombo; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataelement.DataElementCategoryService; import org.hisp.dhis.web.api.model.Model; import org.hisp.dhis.web.api.model.ModelList; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Required; -public class ModelMapping { - private DataElementCategoryService categoryService; - - @Required - public void setCategoryService( - org.hisp.dhis.dataelement.DataElementCategoryService categoryService) { - this.categoryService = categoryService; - } - - public DataElement getDataElement( - org.hisp.dhis.dataelement.DataElement dataElement) { - DataElement de = new DataElement(); - de.setId(dataElement.getId()); - - // Name defaults to alternative name with fallback to name if empty - String name = dataElement.getAlternativeName(); - if (name == null || name.trim().isEmpty()) { - name = dataElement.getName(); - } - de.setName(name); - de.setType(dataElement.getType()); - - de.setCategoryOptionCombos(getCategoryOptionCombos(dataElement)); - return de; - } - - public ModelList getCategoryOptionCombos( - org.hisp.dhis.dataelement.DataElement dataElement) { - DataElementCategoryCombo categoryCombo = dataElement.getCategoryCombo(); - Collection deCatOptCombs = categoryService - .sortOptionCombos(categoryCombo); - // Set deCatOptCombs = - // dataElement.getCategoryCombo().getOptionCombos(); - - // if ( deCatOptCombs.size() < 2 ) - // { - // return null; - // } - - // Client DataElement - ModelList deCateOptCombo = new ModelList(); - List listCateOptCombo = new ArrayList(); - deCateOptCombo.setModels(listCateOptCombo); - - for (DataElementCategoryOptionCombo oneCatOptCombo : deCatOptCombs) { - Model oneCateOptCombo = new Model(); - oneCateOptCombo.setId(oneCatOptCombo.getId()); - oneCateOptCombo.setName(oneCatOptCombo.getName()); - listCateOptCombo.add(oneCateOptCombo); - } - return deCateOptCombo; - } +public class ModelMapping +{ + private DataElementCategoryService categoryService; + + @Required + public void setCategoryService( org.hisp.dhis.dataelement.DataElementCategoryService categoryService ) + { + this.categoryService = categoryService; + } + + public DataElement getDataElement( org.hisp.dhis.dataelement.DataElement dataElement ) + { + DataElement de = new DataElement(); + de.setId( dataElement.getId() ); + + // Name defaults to alternative name with fallback to name if empty + String name = dataElement.getAlternativeName(); + if ( name == null || name.trim().isEmpty() ) + { + name = dataElement.getName(); + } + de.setName( name ); + de.setType( dataElement.getType() ); + + de.setCategoryOptionCombos( getCategoryOptionCombos( dataElement ) ); + return de; + } + + public ModelList getCategoryOptionCombos( org.hisp.dhis.dataelement.DataElement dataElement ) + { + DataElementCategoryCombo categoryCombo = dataElement.getCategoryCombo(); + Collection deCatOptCombs = categoryService.sortOptionCombos( categoryCombo ); + // Set deCatOptCombs = + // dataElement.getCategoryCombo().getOptionCombos(); + + // if ( deCatOptCombs.size() < 2 ) + // { + // return null; + // } + + // Client DataElement + ModelList deCateOptCombo = new ModelList(); + List listCateOptCombo = new ArrayList(); + deCateOptCombo.setModels( listCateOptCombo ); + + for ( DataElementCategoryOptionCombo oneCatOptCombo : deCatOptCombs ) + { + Model oneCateOptCombo = new Model(); + oneCateOptCombo.setId( oneCatOptCombo.getId() ); + oneCateOptCombo.setName( oneCatOptCombo.getName() ); + listCateOptCombo.add( oneCateOptCombo ); + } + return deCateOptCombo; + } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/NotAllowedException.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/NotAllowedException.java 2010-12-02 10:53:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/NotAllowedException.java 2011-01-12 09:13:36 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.web.api.service; +/* + * 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. + */ + public class NotAllowedException extends Exception { @@ -13,7 +40,7 @@ public NotAllowedException( String reason, String message ) { - super(message); + super( message ); this.reason = reason; } @@ -22,5 +49,4 @@ return reason; } - } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/utils/LocaleUtil.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/utils/LocaleUtil.java 2010-09-24 11:12:49 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/utils/LocaleUtil.java 2011-01-12 09:13:36 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.web.api.utils; +/* + * 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.util.Locale; public class LocaleUtil { === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/utils/PeriodUtil.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/utils/PeriodUtil.java 2010-12-02 10:53:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/utils/PeriodUtil.java 2011-01-12 09:13:36 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.web.api.utils; +/* + * 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.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -15,7 +42,8 @@ public class PeriodUtil { - public static Period getPeriod( String periodName, PeriodType periodType ) throws IllegalArgumentException + public static Period getPeriod( String periodName, PeriodType periodType ) + throws IllegalArgumentException { if ( periodType instanceof DailyPeriodType ) @@ -41,7 +69,8 @@ { int dashIndex = periodName.indexOf( '-' ); - if (dashIndex < 0) { + if ( dashIndex < 0 ) + { return null; } @@ -61,7 +90,8 @@ { int dashIndex = periodName.indexOf( '-' ); - if (dashIndex < 0) { + if ( dashIndex < 0 ) + { return null; } === 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-01-06 06:33:19 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitTest.java 2011-01-12 09:13:36 +0000 @@ -1,5 +1,32 @@ 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 static org.junit.Assert.*; import java.io.ByteArrayInputStream; @@ -26,7 +53,7 @@ unit.setUploadFacilityReportUrl( "uploadFacilityReportUrl" ); unit.setUpdateDataSetUrl( "updateDataSetUrl" ); unit.setUpdateProgramUrl( "updateProgramUrl" ); - + ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream( baos ); unit.serialize( dos ); @@ -36,6 +63,6 @@ assertEquals( unit.getName(), unit2.getName() ); assertEquals( unit.getId(), unit2.getId() ); - + } } === 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-01-06 06:33:19 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitsTest.java 2011-01-12 09:13:36 +0000 @@ -1,5 +1,32 @@ 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 static org.junit.Assert.assertEquals; import java.io.ByteArrayInputStream; @@ -25,12 +52,12 @@ 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 OrgUnit[] { unit } ) ); units.serialize( dos ); dos.flush(); - OrgUnits units2 = new OrgUnits( ); + OrgUnits units2 = new OrgUnits(); units2.deSerialize( new DataInputStream( new ByteArrayInputStream( baos.toByteArray() ) ) ); List unitList = units2.getOrgUnits(); assertEquals( 1, unitList.size() ); @@ -38,7 +65,7 @@ OrgUnit unit2 = unitList.get( 0 ); assertEquals( unit.getName(), unit2.getName() ); assertEquals( unit.getId(), unit2.getId() ); - + } private OrgUnit createOrgUnit() === modified file 'dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/provider/DataStreamSerializableProviderTest.java' --- dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/provider/DataStreamSerializableProviderTest.java 2010-12-02 10:53:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/provider/DataStreamSerializableProviderTest.java 2011-01-12 09:13:36 +0000 @@ -1,5 +1,32 @@ package org.hisp.dhis.web.api.provider; +/* + * 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 static org.junit.Assert.assertTrue; import org.hisp.dhis.web.api.mapping.DataStreamSerializableProvider; @@ -10,7 +37,8 @@ { @Test - public void testAssigning() { + public void testAssigning() + { boolean writeable = new DataStreamSerializableProvider().isWriteable( OrgUnits.class, null, null, null ); assertTrue( writeable ); }