=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/DocumentXmlAdapter.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/DocumentXmlAdapter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/DocumentXmlAdapter.java 2011-12-10 23:03:56 +0000 @@ -0,0 +1,60 @@ +package org.hisp.dhis.common.adapter; + +/* + * Copyright (c) 2004-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 org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.document.Document; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.util.UUID; + +/** + * @author Morten Olav Hansen + */ +public class DocumentXmlAdapter extends XmlAdapter +{ + private BaseIdentifiableObjectXmlAdapter baseIdentifiableObjectXmlAdapter = new BaseIdentifiableObjectXmlAdapter(); + + @Override + public Document unmarshal( BaseIdentifiableObject identifiableObject ) throws Exception + { + Document document = new Document(); + + document.setUid( identifiableObject.getUid() ); + document.setLastUpdated( identifiableObject.getLastUpdated() ); + document.setName( identifiableObject.getName() == null ? UUID.randomUUID().toString() : identifiableObject.getName() ); + + return document; + } + + @Override + public BaseIdentifiableObject marshal( Document document ) throws Exception + { + return baseIdentifiableObjectXmlAdapter.marshal( document ); + } +} === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/ValidationRuleGroupXmlAdapter.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/ValidationRuleGroupXmlAdapter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/ValidationRuleGroupXmlAdapter.java 2011-12-10 22:36:01 +0000 @@ -0,0 +1,60 @@ +package org.hisp.dhis.common.adapter; + +/* + * Copyright (c) 2004-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 org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.validation.ValidationRuleGroup; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.util.UUID; + +/** + * @author Morten Olav Hansen + */ +public class ValidationRuleGroupXmlAdapter extends XmlAdapter +{ + private BaseIdentifiableObjectXmlAdapter baseIdentifiableObjectXmlAdapter = new BaseIdentifiableObjectXmlAdapter(); + + @Override + public ValidationRuleGroup unmarshal( BaseIdentifiableObject identifiableObject ) throws Exception + { + ValidationRuleGroup validationRuleGroup = new ValidationRuleGroup(); + + validationRuleGroup.setUid( identifiableObject.getUid() ); + validationRuleGroup.setLastUpdated( identifiableObject.getLastUpdated() ); + validationRuleGroup.setName( identifiableObject.getName() == null ? UUID.randomUUID().toString() : identifiableObject.getName() ); + + return validationRuleGroup; + } + + @Override + public BaseIdentifiableObject marshal( ValidationRuleGroup validationRuleGroup ) throws Exception + { + return baseIdentifiableObjectXmlAdapter.marshal( validationRuleGroup ); + } +} === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/ValidationRuleXmlAdapter.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/ValidationRuleXmlAdapter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/ValidationRuleXmlAdapter.java 2011-12-10 22:36:01 +0000 @@ -0,0 +1,60 @@ +package org.hisp.dhis.common.adapter; + +/* + * Copyright (c) 2004-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 org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.validation.ValidationRule; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.util.UUID; + +/** + * @author Morten Olav Hansen + */ +public class ValidationRuleXmlAdapter extends XmlAdapter +{ + private BaseIdentifiableObjectXmlAdapter baseIdentifiableObjectXmlAdapter = new BaseIdentifiableObjectXmlAdapter(); + + @Override + public ValidationRule unmarshal( BaseIdentifiableObject identifiableObject ) throws Exception + { + ValidationRule validationRule = new ValidationRule(); + + validationRule.setUid( identifiableObject.getUid() ); + validationRule.setLastUpdated( identifiableObject.getLastUpdated() ); + validationRule.setName( identifiableObject.getName() == null ? UUID.randomUUID().toString() : identifiableObject.getName() ); + + return validationRule; + } + + @Override + public BaseIdentifiableObject marshal( ValidationRule validationRule ) throws Exception + { + return baseIdentifiableObjectXmlAdapter.marshal( validationRule ); + } +} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/Document.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/Document.java 2011-12-09 20:58:29 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/Document.java 2011-12-10 23:03:56 +0000 @@ -38,7 +38,7 @@ * @author Lars Helge Overland * @version $Id$ */ -@XmlRootElement( name = "dataElement", namespace = Dxf2Namespace.NAMESPACE ) +@XmlRootElement( name = "document", namespace = Dxf2Namespace.NAMESPACE ) @XmlAccessorType( value = XmlAccessType.NONE ) public class Document extends BaseIdentifiableObject === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/DocumentService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/DocumentService.java 2010-12-14 11:36:39 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/DocumentService.java 2011-12-10 23:03:56 +0000 @@ -45,16 +45,24 @@ * @return the generated identifier. */ int saveDocument( Document document ); - + /** * Retrieves the Document with the given identifier. - * + * * @param id the identifier of the Document. * @return the Document. */ Document getDocument( int id ); /** + * Retrieves the Document with the given identifier. + * + * @param uid the identifier of the Document. + * @return the Document. + */ + Document getDocument( String uid ); + + /** * Deletes a Document. * * @param document the Document to delete. === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/Documents.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/Documents.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/Documents.java 2011-12-10 23:22:51 +0000 @@ -0,0 +1,67 @@ +package org.hisp.dhis.document; + +/* + * Copyright (c) 2004-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 org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonSerialize; +import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.BaseLinkableObject; +import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.adapter.DocumentXmlAdapter; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Morten Olav Hansen + */ +@XmlRootElement( name = "documents", namespace = Dxf2Namespace.NAMESPACE ) +@XmlAccessorType( value = XmlAccessType.NONE ) +public class Documents extends BaseLinkableObject +{ + private List documents = new ArrayList(); + + @XmlElement( name = "document" ) + @XmlJavaTypeAdapter( DocumentXmlAdapter.class ) + @JsonProperty( value = "documents" ) + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + public List getDocuments() + { + return documents; + } + + public void setDocuments( List documents ) + { + this.documents = documents; + } +} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/Expression.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/Expression.java 2011-11-22 14:38:08 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/Expression.java 2011-12-10 22:36:01 +0000 @@ -27,9 +27,17 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonSerialize; +import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.adapter.CategoryOptionComboXmlAdapter; +import org.hisp.dhis.common.adapter.DataElementXmlAdapter; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import javax.xml.bind.annotation.*; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.io.Serializable; import java.util.Set; @@ -50,6 +58,8 @@ * @author Margrethe Store * @version $Id: Expression.java 5011 2008-04-24 20:41:28Z larshelg $ */ +@XmlRootElement( name = "expression", namespace = Dxf2Namespace.NAMESPACE ) +@XmlAccessorType( value = XmlAccessType.NONE ) public class Expression implements Serializable { @@ -185,6 +195,33 @@ // Getters and setters // ------------------------------------------------------------------------- + public int getId() + { + return id; + } + + public void setId( int id ) + { + this.id = id; + } + + @XmlElement + @JsonProperty + public String getExpression() + { + return expression; + } + + public void setExpression( String expression ) + { + this.expression = expression; + } + + @XmlElementWrapper( name = "dataElements" ) + @XmlElement( name = "dataElement" ) + @XmlJavaTypeAdapter( DataElementXmlAdapter.class ) + @JsonProperty( value = "dataElements" ) + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public Set getDataElementsInExpression() { return dataElementsInExpression; @@ -195,6 +232,11 @@ this.dataElementsInExpression = dataElementsInExpression; } + @XmlElementWrapper( name = "categoryOptionCombos" ) + @XmlElement( name = "categoryOptionCombo" ) + @XmlJavaTypeAdapter( CategoryOptionComboXmlAdapter.class ) + @JsonProperty( value = "categoryOptionCombos" ) + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public Set getOptionCombosInExpression() { return optionCombosInExpression; @@ -205,6 +247,8 @@ this.optionCombosInExpression = optionCombosInExpression; } + @XmlElement + @JsonProperty public String getDescription() { return description; @@ -214,24 +258,4 @@ { this.description = description; } - - public String getExpression() - { - return expression; - } - - public void setExpression( String expression ) - { - this.expression = expression; - } - - public int getId() - { - return id; - } - - public void setId( int id ) - { - this.id = id; - } } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRule.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRule.java 2011-12-03 10:35:41 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRule.java 2011-12-10 22:36:01 +0000 @@ -27,15 +27,17 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonSerialize; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.adapter.ValidationRuleGroupXmlAdapter; import org.hisp.dhis.expression.Expression; import org.hisp.dhis.expression.Operator; import org.hisp.dhis.period.PeriodType; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.*; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.util.HashSet; import java.util.Set; @@ -133,6 +135,8 @@ // Set and get methods // ------------------------------------------------------------------------- + @XmlElement + @JsonProperty public String getDescription() { return description; @@ -143,11 +147,6 @@ this.description = description; } - public Operator getOperator() - { - return operator; - } - public PeriodType getPeriodType() { return periodType; @@ -158,11 +157,20 @@ this.periodType = periodType; } + @XmlElement + @JsonProperty + public Operator getOperator() + { + return operator; + } + public void setOperator( Operator operator ) { this.operator = operator; } + @XmlElement + @JsonProperty public String getType() { return type; @@ -173,6 +181,8 @@ this.type = type; } + @XmlElement + @JsonProperty public Expression getLeftSide() { return leftSide; @@ -183,6 +193,8 @@ this.leftSide = leftSide; } + @XmlElement + @JsonProperty public Expression getRightSide() { return rightSide; @@ -193,6 +205,11 @@ this.rightSide = rightSide; } + @XmlElementWrapper( name = "validationRuleGroups" ) + @XmlElement( name = "validationRuleGroup" ) + @XmlJavaTypeAdapter( ValidationRuleGroupXmlAdapter.class ) + @JsonProperty( value = "validationRuleGroups" ) + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public Set getGroups() { return groups; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleGroup.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleGroup.java 2011-12-03 10:35:41 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleGroup.java 2011-12-10 22:36:01 +0000 @@ -27,12 +27,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonSerialize; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.adapter.ValidationRuleXmlAdapter; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.*; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.util.HashSet; import java.util.Set; @@ -107,6 +109,8 @@ // Getters and setters // ------------------------------------------------------------------------- + @XmlElement + @JsonProperty public String getDescription() { return description; @@ -117,6 +121,11 @@ this.description = description; } + @XmlElementWrapper( name = "validationRules" ) + @XmlElement( name = "validationRule" ) + @XmlJavaTypeAdapter( ValidationRuleXmlAdapter.class ) + @JsonProperty( value = "validationRules" ) + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public Set getMembers() { return members; === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleGroups.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleGroups.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleGroups.java 2011-12-10 23:22:51 +0000 @@ -0,0 +1,67 @@ +package org.hisp.dhis.validation; + +/* + * Copyright (c) 2004-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 org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonSerialize; +import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.BaseLinkableObject; +import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.adapter.ValidationRuleGroupXmlAdapter; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Morten Olav Hansen + */ +@XmlRootElement( name = "validationRuleGroups", namespace = Dxf2Namespace.NAMESPACE ) +@XmlAccessorType( value = XmlAccessType.NONE ) +public class ValidationRuleGroups extends BaseLinkableObject +{ + private List validationRuleGroups = new ArrayList(); + + @XmlElement( name = "validationRuleGroup" ) + @XmlJavaTypeAdapter( ValidationRuleGroupXmlAdapter.class ) + @JsonProperty( value = "validationRuleGroups" ) + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + public List getValidationRuleGroups() + { + return validationRuleGroups; + } + + public void setValidationRuleGroups( List validationRuleGroups ) + { + this.validationRuleGroups = validationRuleGroups; + } +} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java 2011-09-10 08:40:27 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java 2011-12-10 23:03:56 +0000 @@ -27,16 +27,16 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.Collection; -import java.util.Date; -import java.util.List; - import org.hisp.dhis.common.Grid; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; +import java.util.Collection; +import java.util.Date; +import java.util.List; + /** * @author Margrethe Store * @version $Id: ValidationRuleService.java 5434 2008-06-18 18:57:59Z larshelg $ @@ -46,7 +46,7 @@ String ID = ValidationRuleService.class.getName(); int MAX_VIOLATIONS = 500; - + // ------------------------------------------------------------------------- // ValidationRule business logic // ------------------------------------------------------------------------- @@ -56,66 +56,66 @@ * are listed as columns and Sources are listed as rows. */ Grid getAggregateValidationResult( Collection results, List periods, List sources ); - + /** * Validates AggregatedDataValues. - * + * * @param startDate the start date. - * @param endDate the end date. - * @param sources a collection of Sources. - * @return a collection of ValidationResults for each validation violation. + * @param endDate the end date. + * @param sources a collection of Sources. + * @return a collection of ValidationResults for each validation violation. */ Collection validateAggregate( Date startDate, Date endDate, Collection sources ); /** * Validate AggregatedDataValues. - * + * * @param startDate the start date. - * @param endDate the end date. - * @param sources a collection of Sources. - * @param group a group of ValidationRules. - * @return a collection of ValidationResults for each validation violation. + * @param endDate the end date. + * @param sources a collection of Sources. + * @param group a group of ValidationRules. + * @return a collection of ValidationResults for each validation violation. */ public Collection validateAggregate( Date startDate, Date endDate, Collection sources, ValidationRuleGroup group ); - + /** * Validate DataValues. - * + * * @param startDate the start date. - * @param endDate the end date. - * @param sources a collection of Sources. - * @return a collection of ValidationResults for each validation violation. + * @param endDate the end date. + * @param sources a collection of Sources. + * @return a collection of ValidationResults for each validation violation. */ Collection validate( Date startDate, Date endDate, Collection sources ); - + /** * Validate DataValues. - * + * * @param startDate the start date. - * @param endDate the end date. - * @param sources a collection of Sources. - * @param group a group of ValidationRules. - * @return a collection of ValidationResults for each validation violation. + * @param endDate the end date. + * @param sources a collection of Sources. + * @param group a group of ValidationRules. + * @return a collection of ValidationResults for each validation violation. */ Collection validate( Date startDate, Date endDate, Collection sources, ValidationRuleGroup group ); - + /** * Validate DataValues. - * + * * @param dataSet the DataSet. - * @param period the Period. - * @param source the Source. - * @return a collection of ValidationResults for each validation violation. + * @param period the Period. + * @param source the Source. + * @return a collection of ValidationResults for each validation violation. */ Collection validate( DataSet dataSet, Period period, OrganisationUnit source ); /** * Validate DataValues. - * + * * @param startDate the start date. - * @param endDate the end date. - * @param source the Source. - * @return a collection of ValidationResults for each validation violation. + * @param endDate the end date. + * @param source the Source. + * @return a collection of ValidationResults for each validation violation. */ Collection validate( Date startDate, Date endDate, OrganisationUnit source ); @@ -125,15 +125,15 @@ /** * Save a ValidationRule to the database. - * + * * @param validationRule the ValidationRule to save. * @return the generated unique identifier for the ValidationRule. */ int saveValidationRule( ValidationRule validationRule ); - + /** * Update a ValidationRule to the database. - * + * * @param validationRule the ValidationRule to update. * @return the generated unique identifier for the ValidationRule. */ @@ -141,71 +141,79 @@ /** * Delete a validation rule with the given identifiers from the database. - * + * * @param validationRule the ValidationRule to delete. */ void deleteValidationRule( ValidationRule validationRule ); - + /** * Get ValidationRule with the given identifier. - * + * * @param id the unique identifier of the ValidationRule. * @return the ValidationRule or null if it doesn't exist. */ ValidationRule getValidationRule( int id ); /** + * Get ValidationRule with the given uid. + * + * @param uid the unique identifier of the ValidationRule. + * @return the ValidationRule or null if it doesn't exist. + */ + ValidationRule getValidationRule( String uid ); + + /** * Get the ValidationRules with the corresponding identifiers. - * + * * @param identifiers the collection of identifiers. * @return a collection of validation rules. */ Collection getValidationRules( Collection identifiers ); - + /** * Get all validation rules. - * + * * @return a Collection of ValidationRule or null if it there are no validation rules. - */ + */ Collection getAllValidationRules(); /** * Get a validation rule with the given name. - * + * * @param name the name of the validation rule. */ ValidationRule getValidationRuleByName( String name ); - + /** * Get the validation rules which are associated with the given name key. - * + * * @param name the name key. * @return a collection of validation rules. */ Collection getValidationRulesByName( String name ); - + /** * Get the validation rules which are associated with the given data elements. - * + * * @param dataElements the collection of data elements. * @return a collection of validation rules. */ Collection getValidationRulesByDataElements( Collection dataElements ); - + /** * Get all data elements associated with any validation rule. - * + * * @return a collection of data elements. */ Collection getDataElementsInValidationRules(); - + // ------------------------------------------------------------------------- // ValidationRuleGroup // ------------------------------------------------------------------------- /** * Adds a ValidationRuleGroup to the database. - * + * * @param validationRuleGroup the ValidationRuleGroup to add. * @return the generated unique identifier for the ValidationRuleGroup. */ @@ -213,54 +221,62 @@ /** * Delete a ValidationRuleGroup with the given identifiers from the database. - * - * @param id the ValidationRuleGroup to delete. + * + * @param validationRuleGroup the ValidationRuleGroup to delete. */ void deleteValidationRuleGroup( ValidationRuleGroup validationRuleGroup ); /** * Update a ValidationRuleGroup with the given identifiers. - * - * @param validationRule the ValidationRule to update. + * + * @param validationRuleGroup the ValidationRule to update. */ void updateValidationRuleGroup( ValidationRuleGroup validationRuleGroup ); /** * Get ValidationRuleGroup with the given identifier. - * + * * @param id the unique identifier of the ValidationRuleGroup. - * @return the ValidationRule or null if it doesn't exist. + * @return the ValidationRuleGroup or null if it doesn't exist. */ ValidationRuleGroup getValidationRuleGroup( int id ); /** + * Get ValidationRuleGroup with the given uid. + * + * @param uid the unique identifier of the ValidationRuleGroup. + * @return the ValidationRuleGroup or null if it doesn't exist. + */ + ValidationRuleGroup getValidationRuleGroup( String uid ); + + /** * Get all ValidationRuleGroups. - * + * * @return a Collection of ValidationRuleGroup or null if it there are no ValidationRuleGroups. - */ + */ Collection getAllValidationRuleGroups(); - + /** * Get a ValidationRuleGroup with the given name. - * + * * @param name the name of the ValidationRuleGroup. */ - ValidationRuleGroup getValidationRuleGroupByName( String name ); - + ValidationRuleGroup getValidationRuleGroupByName( String name ); + Collection getValidationRulesBetween( int first, int max ); - + Collection getValidationRulesBetweenByName( String name, int first, int max ); - + int getValidationRuleCount(); - + int getValidationRuleCountByName( String name ); - + Collection getValidationRuleGroupsBetween( int first, int max ); - + Collection getValidationRuleGroupsBetweenByName( String name, int first, int max ); - + int getValidationRuleGroupCount(); - + int getValidationRuleGroupCountByName( String name ); } === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRules.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRules.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRules.java 2011-12-10 23:22:51 +0000 @@ -0,0 +1,67 @@ +package org.hisp.dhis.validation; + +/* + * Copyright (c) 2004-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 org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonSerialize; +import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.BaseLinkableObject; +import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.adapter.ValidationRuleXmlAdapter; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Morten Olav Hansen + */ +@XmlRootElement( name = "validationRules", namespace = Dxf2Namespace.NAMESPACE ) +@XmlAccessorType( value = XmlAccessType.NONE ) +public class ValidationRules extends BaseLinkableObject +{ + private List validationRules = new ArrayList(); + + @XmlElement( name = "validationRule" ) + @XmlJavaTypeAdapter( ValidationRuleXmlAdapter.class ) + @JsonProperty( value = "validationRules" ) + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + public List getValidationRules() + { + return validationRules; + } + + public void setValidationRules( List validationRules ) + { + this.validationRules = validationRules; + } +} === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java 2011-12-05 12:21:38 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java 2011-12-10 23:03:56 +0000 @@ -50,7 +50,7 @@ private static final Log log = LogFactory.getLog( IdentityPopulator.class ); private static String[] tables = { "chart", "constant", "attribute", "indicatortype", "indicatorgroupset", "indicator", - "indicatorgroup", "datadictionary", "validationrulegroup", "validationrule", "dataset", "orgunitlevel", + "indicatorgroup", "datadictionary", "validationrulegroup", "validationrule", "dataset", "orgunitlevel", "document", "organisationunit", "orgunitgroup", "orgunitgroupset", "dataelementcategoryoption", "dataelementgroup", "dataelement", "dataelementgroupset", "dataelementcategory", "categorycombo", "categoryoptioncombo", "mapview" }; === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2011-12-09 19:44:38 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2011-12-10 23:03:56 +0000 @@ -395,6 +395,11 @@ return validationRuleStore.get( id ); } + public ValidationRule getValidationRule( String uid ) + { + return validationRuleStore.getByUid( uid ); + } + public ValidationRule getValidationRuleByName( String name ) { return validationRuleStore.getByName( name ); @@ -452,6 +457,11 @@ return validationRuleGroupStore.get( id ); } + public ValidationRuleGroup getValidationRuleGroup( String uid ) + { + return validationRuleGroupStore.getByUid( uid ); + } + public Collection getAllValidationRuleGroups() { return validationRuleGroupStore.getAll(); === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/document/impl/DefaultDocumentService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/document/impl/DefaultDocumentService.java 2010-12-13 15:18:59 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/document/impl/DefaultDocumentService.java 2011-12-10 23:03:56 +0000 @@ -27,13 +27,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.Collection; - import org.hisp.dhis.common.GenericIdentifiableObjectStore; import org.hisp.dhis.document.Document; import org.hisp.dhis.document.DocumentService; import org.springframework.transaction.annotation.Transactional; +import java.util.Collection; + /** * @author Lars Helge Overland * @version $Id$ @@ -67,11 +67,16 @@ return documentStore.get( id ); } + public Document getDocument( String uid ) + { + return documentStore.getByUid( uid ); + } + public void deleteDocument( Document document ) { documentStore.delete( document ); } - + public Collection getAllDocuments() { return documentStore.getAll(); === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/document/hibernate/Document.hbm.xml' --- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/document/hibernate/Document.hbm.xml 2011-05-28 21:25:46 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/document/hibernate/Document.hbm.xml 2011-12-10 23:03:56 +0000 @@ -1,7 +1,9 @@ + "-//Hibernate/Hibernate Mapping DTD 3.0//EN" + "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" + [] + > @@ -11,8 +13,7 @@ - - + &identifiableProperties; === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java 2011-12-10 23:03:56 +0000 @@ -0,0 +1,145 @@ +package org.hisp.dhis.api.controller; + +/* + * Copyright (c) 2004-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 org.hisp.dhis.api.utils.IdentifiableObjectParams; +import org.hisp.dhis.api.utils.WebLinkPopulator; +import org.hisp.dhis.document.Document; +import org.hisp.dhis.document.DocumentService; +import org.hisp.dhis.document.Documents; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseStatus; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.InputStream; +import java.util.ArrayList; + +/** + * @author Morten Olav Hansen + */ +@Controller +@RequestMapping( value = DocumentController.RESOURCE_PATH ) +public class DocumentController +{ + public static final String RESOURCE_PATH = "/documents"; + + @Autowired + private DocumentService documentService; + + //------------------------------------------------------------------------------------------------------- + // GET + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( method = RequestMethod.GET ) + public String getDocuments( IdentifiableObjectParams params, Model model, HttpServletRequest request ) + { + Documents documents = new Documents(); + documents.setDocuments( new ArrayList( documentService.getAllDocuments() ) ); + + if ( params.hasLinks() ) + { + WebLinkPopulator listener = new WebLinkPopulator( request ); + listener.addLinks( documents ); + } + + model.addAttribute( "model", documents ); + + return "documents"; + } + + @RequestMapping( value = "/{uid}", method = RequestMethod.GET ) + public String getDocument( @PathVariable( "uid" ) String uid, IdentifiableObjectParams params, Model model, HttpServletRequest request ) + { + Document document = documentService.getDocument( uid ); + + if ( params.hasLinks() ) + { + WebLinkPopulator listener = new WebLinkPopulator( request ); + listener.addLinks( document ); + } + + model.addAttribute( "model", document ); + + return "validationRule"; + } + + //------------------------------------------------------------------------------------------------------- + // POST + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/xml, text/xml"} ) + @ResponseStatus( value = HttpStatus.CREATED ) + public void postDocumentXML( HttpServletResponse response, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() ); + } + + @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/json"} ) + @ResponseStatus( value = HttpStatus.CREATED ) + public void postDocumentJSON( HttpServletResponse response, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() ); + } + + //------------------------------------------------------------------------------------------------------- + // PUT + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/xml, text/xml"} ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void putDocumentXML( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() ); + } + + @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/json"} ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void putDocumentJSON( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() ); + } + + //------------------------------------------------------------------------------------------------------- + // DELETE + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void deleteDocument( @PathVariable( "uid" ) String uid ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() ); + } +} === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ValidationRuleController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ValidationRuleController.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ValidationRuleController.java 2011-12-10 23:22:51 +0000 @@ -0,0 +1,145 @@ +package org.hisp.dhis.api.controller; + +/* + * Copyright (c) 2004-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 org.hisp.dhis.api.utils.IdentifiableObjectParams; +import org.hisp.dhis.api.utils.WebLinkPopulator; +import org.hisp.dhis.validation.ValidationRule; +import org.hisp.dhis.validation.ValidationRuleService; +import org.hisp.dhis.validation.ValidationRules; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseStatus; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.InputStream; +import java.util.ArrayList; + +/** + * @author Morten Olav Hansen + */ +@Controller +@RequestMapping( value = ValidationRuleController.RESOURCE_PATH ) +public class ValidationRuleController +{ + public static final String RESOURCE_PATH = "/validationRules"; + + @Autowired + private ValidationRuleService validationRuleService; + + //------------------------------------------------------------------------------------------------------- + // GET + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( method = RequestMethod.GET ) + public String getValidationRules( IdentifiableObjectParams params, Model model, HttpServletRequest request ) + { + ValidationRules validationRules = new ValidationRules(); + validationRules.setValidationRules( new ArrayList( validationRuleService.getAllValidationRules() ) ); + + if ( params.hasLinks() ) + { + WebLinkPopulator listener = new WebLinkPopulator( request ); + listener.addLinks( validationRules ); + } + + model.addAttribute( "model", validationRules ); + + return "validationRules"; + } + + @RequestMapping( value = "/{uid}", method = RequestMethod.GET ) + public String getValidationRule( @PathVariable( "uid" ) String uid, IdentifiableObjectParams params, Model model, HttpServletRequest request ) + { + ValidationRule validationRule = validationRuleService.getValidationRule( uid ); + + if ( params.hasLinks() ) + { + WebLinkPopulator listener = new WebLinkPopulator( request ); + listener.addLinks( validationRule ); + } + + model.addAttribute( "model", validationRule ); + + return "validationRule"; + } + + //------------------------------------------------------------------------------------------------------- + // POST + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/xml, text/xml"} ) + @ResponseStatus( value = HttpStatus.CREATED ) + public void postValidationRuleXML( HttpServletResponse response, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() ); + } + + @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/json"} ) + @ResponseStatus( value = HttpStatus.CREATED ) + public void postValidationRuleJSON( HttpServletResponse response, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() ); + } + + //------------------------------------------------------------------------------------------------------- + // PUT + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/xml, text/xml"} ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void putValidationRuleXML( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() ); + } + + @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/json"} ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void putValidationRuleJSON( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() ); + } + + //------------------------------------------------------------------------------------------------------- + // DELETE + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void deleteValidationRule( @PathVariable( "uid" ) String uid ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() ); + } +} === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ValidationRuleGroupController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ValidationRuleGroupController.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ValidationRuleGroupController.java 2011-12-10 23:03:56 +0000 @@ -0,0 +1,145 @@ +package org.hisp.dhis.api.controller; + +/* + * Copyright (c) 2004-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 org.hisp.dhis.api.utils.IdentifiableObjectParams; +import org.hisp.dhis.api.utils.WebLinkPopulator; +import org.hisp.dhis.validation.ValidationRuleGroup; +import org.hisp.dhis.validation.ValidationRuleGroups; +import org.hisp.dhis.validation.ValidationRuleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseStatus; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.InputStream; +import java.util.ArrayList; + +/** + * @author Morten Olav Hansen + */ +@Controller +@RequestMapping( value = ValidationRuleGroupController.RESOURCE_PATH ) +public class ValidationRuleGroupController +{ + public static final String RESOURCE_PATH = "/validationRuleGroups"; + + @Autowired + private ValidationRuleService validationRuleService; + + //------------------------------------------------------------------------------------------------------- + // GET + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( method = RequestMethod.GET ) + public String getValidationRuleGroups( IdentifiableObjectParams params, Model model, HttpServletRequest request ) + { + ValidationRuleGroups validationRuleGroups = new ValidationRuleGroups(); + validationRuleGroups.setValidationRuleGroups( new ArrayList( validationRuleService.getAllValidationRuleGroups() ) ); + + if ( params.hasLinks() ) + { + WebLinkPopulator listener = new WebLinkPopulator( request ); + listener.addLinks( validationRuleGroups ); + } + + model.addAttribute( "model", validationRuleGroups ); + + return "validationRuleGroups"; + } + + @RequestMapping( value = "/{uid}", method = RequestMethod.GET ) + public String getValidationRuleGroup( @PathVariable( "uid" ) String uid, IdentifiableObjectParams params, Model model, HttpServletRequest request ) + { + ValidationRuleGroup validationRuleGroup = validationRuleService.getValidationRuleGroup( uid ); + + if ( params.hasLinks() ) + { + WebLinkPopulator listener = new WebLinkPopulator( request ); + listener.addLinks( validationRuleGroup ); + } + + model.addAttribute( "model", validationRuleGroup ); + + return "validationRuleGroup"; + } + + //------------------------------------------------------------------------------------------------------- + // POST + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/xml, text/xml"} ) + @ResponseStatus( value = HttpStatus.CREATED ) + public void postValidationRuleGroupXML( HttpServletResponse response, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() ); + } + + @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/json"} ) + @ResponseStatus( value = HttpStatus.CREATED ) + public void postValidationRuleGroupJSON( HttpServletResponse response, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() ); + } + + //------------------------------------------------------------------------------------------------------- + // PUT + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/xml, text/xml"} ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void putValidationRuleGroupXML( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() ); + } + + @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/json"} ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void putValidationRuleGroupJSON( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() ); + } + + //------------------------------------------------------------------------------------------------------- + // DELETE + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void deleteValidationGroupRule( @PathVariable( "uid" ) String uid ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() ); + } +} === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java 2011-12-09 18:08:05 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java 2011-12-10 23:22:51 +0000 @@ -41,10 +41,16 @@ import org.hisp.dhis.dataelement.*; import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.dataset.DataSets; +import org.hisp.dhis.document.Document; +import org.hisp.dhis.document.Documents; import org.hisp.dhis.indicator.*; import org.hisp.dhis.mapping.MapView; import org.hisp.dhis.mapping.Maps; import org.hisp.dhis.organisationunit.*; +import org.hisp.dhis.validation.ValidationRule; +import org.hisp.dhis.validation.ValidationRuleGroup; +import org.hisp.dhis.validation.ValidationRuleGroups; +import org.hisp.dhis.validation.ValidationRules; import javax.servlet.http.HttpServletRequest; import java.util.Collection; @@ -239,7 +245,99 @@ { populateMap( (MapView) source, true ); } - + else if ( source instanceof Documents ) + { + populateDocuments( (Documents) source, true ); + } + else if ( source instanceof Document ) + { + populateDocument( (Document) source, true ); + } + else if ( source instanceof ValidationRules ) + { + populateValidationRules( (ValidationRules) source, true ); + } + else if ( source instanceof ValidationRule ) + { + populateValidationRule( (ValidationRule) source, true ); + } + else if ( source instanceof ValidationRuleGroups ) + { + populateValidationRuleGroups( (ValidationRuleGroups) source, true ); + } + else if ( source instanceof ValidationRuleGroup ) + { + populateValidationRuleGroup( (ValidationRuleGroup) source, true ); + } + } + + private void populateDocuments( Documents documents, boolean root ) + { + documents.setLink( getBasePath( documents.getClass() ) ); + + if ( root ) + { + for ( Document document : documents.getDocuments() ) + { + populateDocument( document, false ); + } + } + } + + private void populateDocument( Document document, boolean root ) + { + populateIdentifiableObject( document ); + + if ( root ) + { + + } + } + + private void populateValidationRules( ValidationRules validationRules, boolean root ) + { + validationRules.setLink( getBasePath( validationRules.getClass() ) ); + + if ( root ) + { + for ( ValidationRule validationRule : validationRules.getValidationRules() ) + { + populateValidationRule( validationRule, false ); + } + } + } + + private void populateValidationRule( ValidationRule validationRule, boolean root ) + { + populateIdentifiableObject( validationRule ); + + if ( root ) + { + handleIdentifiableObjectCollection( validationRule.getGroups() ); + } + } + + private void populateValidationRuleGroups( ValidationRuleGroups validationRuleGroups, boolean root ) + { + validationRuleGroups.setLink( getBasePath( validationRuleGroups.getClass() ) ); + + if ( root ) + { + for ( ValidationRuleGroup validationRuleGroup : validationRuleGroups.getValidationRuleGroups() ) + { + populateValidationRuleGroup( validationRuleGroup, false ); + } + } + } + + private void populateValidationRuleGroup( ValidationRuleGroup validationRuleGroup, boolean root ) + { + populateIdentifiableObject( validationRuleGroup ); + + if ( root ) + { + handleIdentifiableObjectCollection( validationRuleGroup.getMembers() ); + } } private void populateIndicatorTypes( IndicatorTypes indicatorTypes, boolean root )