=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java 2014-12-01 05:36:11 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java 2014-12-19 12:31:55 +0000 @@ -42,6 +42,8 @@ import org.hisp.dhis.common.view.SharingBasicView; import org.hisp.dhis.common.view.SharingDetailedView; import org.hisp.dhis.common.view.SharingExportView; +import org.hisp.dhis.schema.PropertyType; +import org.hisp.dhis.schema.annotation.Property; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserGroupAccess; @@ -186,6 +188,7 @@ @JsonProperty( value = "id" ) @JacksonXmlProperty( localName = "id", isAttribute = true ) @Description( "The Unique Identifier for this Object." ) + @Property( PropertyType.IDENTIFIER ) public String getUid() { return uid; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2014-12-15 10:57:23 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2014-12-19 12:31:55 +0000 @@ -34,7 +34,6 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; - import org.apache.commons.lang.StringUtils; import org.hisp.dhis.attribute.AttributeValue; import org.hisp.dhis.common.BaseIdentifiableObject; @@ -49,6 +48,8 @@ import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.period.PeriodType; +import org.hisp.dhis.schema.PropertyType; +import org.hisp.dhis.schema.annotation.Property; import org.hisp.dhis.user.User; import java.util.ArrayList; @@ -332,7 +333,7 @@ { return !this.children.isEmpty(); } - + public boolean isLeaf() { return children == null || children.isEmpty(); @@ -366,20 +367,20 @@ { return true; } - + unit = unit.getParent(); } - + return false; } - + public boolean isDescendant( Set ancestors ) { if ( ancestors == null || ancestors.isEmpty() ) { return false; } - + OrganisationUnit unit = this; while ( unit != null ) @@ -388,11 +389,11 @@ { return true; } - + unit = unit.getParent(); } - - return false; + + return false; } public boolean hasCoordinatesUp() @@ -404,7 +405,7 @@ return parent.getParent().hasChildrenWithCoordinates(); } } - + return false; } @@ -579,9 +580,9 @@ /** * Returns the list of ancestor organisation units up the any of the given roots - * for this organisation unit. Does not include itself. The list is ordered - * by root first. - * + * for this organisation unit. Does not include itself. The list is ordered + * by root first. + * * @param roots the root organisation units, if null using real roots. */ public List getAncestors( Collection roots ) @@ -593,19 +594,19 @@ while ( unit != null ) { units.add( unit ); - + if ( roots != null && roots.contains( unit ) ) { break; } - + unit = unit.getParent(); } Collections.reverse( units ); return units; } - + public Set getDataElementsInDataSets() { Set dataElements = new HashSet<>(); @@ -620,21 +621,21 @@ public Map> getDataElementsInDataSetsByPeriodType() { - Map> map = new HashMap<>(); - + Map> map = new HashMap<>(); + for ( DataSet dataSet : dataSets ) { Set dataElements = map.get( dataSet.getPeriodType() ); - + if ( dataElements == null ) { dataElements = new HashSet<>(); map.put( dataSet.getPeriodType(), dataElements ); } - + dataElements.addAll( dataSet.getDataElements() ); } - + return map; } @@ -699,7 +700,7 @@ /** * Returns a string representing the graph of ancestors. The string is delimited * by "/". The ancestors are ordered by root first and represented by UIDs. - * + * * @param roots the root organisation units, if null using real roots. */ public String getParentGraph( Collection roots ) @@ -731,7 +732,7 @@ { builder.append( "/" ).append( name ); } - + return builder.toString(); } @@ -742,7 +743,7 @@ public static Map getParentGraphMap( List organisationUnits, Collection roots ) { Map map = new HashMap<>(); - + if ( organisationUnits != null ) { for ( OrganisationUnit unit : organisationUnits ) @@ -750,7 +751,7 @@ map.put( unit.getUid(), unit.getParentGraph( roots ) ); } } - + return map; } @@ -761,7 +762,7 @@ public static Map getParentNameGraphMap( List organisationUnits, Collection roots, boolean includeThis ) { Map map = new HashMap<>(); - + if ( organisationUnits != null ) { for ( OrganisationUnit unit : organisationUnits ) @@ -769,7 +770,7 @@ map.put( unit.getName(), unit.getParentNameGraph( roots, includeThis ) ); } } - + return map; } @@ -777,7 +778,7 @@ { return level > 0; } - + @Override public boolean haveUniqueNames() { @@ -788,7 +789,7 @@ { return parent == null; } - + // ------------------------------------------------------------------------- // Getters and setters // ------------------------------------------------------------------------- @@ -821,7 +822,7 @@ } @JsonProperty - @JsonSerialize( contentUsing = JacksonOrganisationUnitChildrenSerializer.class) + @JsonSerialize( contentUsing = JacksonOrganisationUnitChildrenSerializer.class ) @JsonView( { DetailedView.class } ) @JacksonXmlElementWrapper( localName = "children", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "child", namespace = DxfNamespaces.DXF_2_0 ) @@ -912,6 +913,7 @@ @JsonProperty @JsonView( { DetailedView.class, ExportView.class } ) @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + @Property( PropertyType.GEOLOCATION ) public String getCoordinates() { return coordinates; @@ -925,6 +927,7 @@ @JsonProperty @JsonView( { DetailedView.class, ExportView.class } ) @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + @Property( PropertyType.URL ) public String getUrl() { return url; @@ -964,6 +967,7 @@ @JsonProperty @JsonView( { DetailedView.class, ExportView.class } ) @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + @Property( PropertyType.EMAIL ) public String getEmail() { return email; @@ -977,6 +981,7 @@ @JsonProperty @JsonView( { DetailedView.class, ExportView.class } ) @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + @Property( PropertyType.PHONENUMBER ) public String getPhoneNumber() { return phoneNumber; @@ -1047,8 +1052,8 @@ @JsonProperty( value = "attributeValues" ) @JsonView( { DetailedView.class, ExportView.class } ) - @JacksonXmlElementWrapper( localName = "attributeValues", namespace = DxfNamespaces.DXF_2_0) - @JacksonXmlProperty( localName = "attributeValue", namespace = DxfNamespaces.DXF_2_0) + @JacksonXmlElementWrapper( localName = "attributeValues", namespace = DxfNamespaces.DXF_2_0 ) + @JacksonXmlProperty( localName = "attributeValue", namespace = DxfNamespaces.DXF_2_0 ) public Set getAttributeValues() { return attributeValues; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyType.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyType.java 2014-12-19 11:18:40 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyType.java 2014-12-19 12:31:55 +0000 @@ -37,6 +37,7 @@ @JacksonXmlRootElement( localName = "propertyType", namespace = DxfNamespaces.DXF_2_0 ) public enum PropertyType { + IDENTIFIER, TEXT, NUMBER, INTEGER, === added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/annotation' === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/annotation/Property.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/annotation/Property.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/annotation/Property.java 2014-12-19 12:31:55 +0000 @@ -0,0 +1,44 @@ +package org.hisp.dhis.schema.annotation; + +/* + * Copyright (c) 2004-2014, 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.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Morten Olav Hansen + */ +@Target( { ElementType.FIELD, ElementType.METHOD } ) +@Retention( RetentionPolicy.RUNTIME ) +public @interface Property +{ + org.hisp.dhis.schema.PropertyType value() default org.hisp.dhis.schema.PropertyType.TEXT; +} === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/annotation/PropertyRange.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/annotation/PropertyRange.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/annotation/PropertyRange.java 2014-12-19 12:31:55 +0000 @@ -0,0 +1,57 @@ +package org.hisp.dhis.schema.annotation; + +/* + * Copyright (c) 2004-2014, 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.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Property annotation for setting min/max range. + *

+ * Behavior changes according to type: + *

    + *
      PropertyType.TEXT: min/max length of TEXT + *
        PropertyType.COLLECTION: min/max size of collection + *
          PropertyType.NUMBER: min/max values (only integer min/max currently allowed) + *
            PropertyType.INTEGER: min/max values + *
+ * + * @author Morten Olav Hansen + * @see Property + */ +@Target( { ElementType.FIELD, ElementType.METHOD } ) +@Retention( RetentionPolicy.RUNTIME ) +public @interface PropertyRange +{ + int min() default 0; + + int max() default Integer.MAX_VALUE; +} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java 2014-12-18 19:55:42 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java 2014-12-19 12:31:55 +0000 @@ -46,6 +46,9 @@ import org.hisp.dhis.dataelement.CategoryOptionGroupSet; import org.hisp.dhis.dataelement.DataElementCategory; import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.schema.PropertyType; +import org.hisp.dhis.schema.annotation.Property; +import org.hisp.dhis.schema.annotation.PropertyRange; import org.springframework.util.StringUtils; import java.util.Collection; @@ -451,6 +454,8 @@ @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + @Property( PropertyType.PASSWORD ) + @PropertyRange( min = 8, max = 35 ) public void setPassword( String password ) { this.password = password;