dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #13805
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4529: added domain, store, service and tests for dynamic attributes
------------------------------------------------------------
revno: 4529
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-09-06 13:52:18 +0200
message:
added domain, store, service and tests for dynamic attributes
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/
dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/Attribute.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeOption.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeOptionService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeOptionStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValue.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValueService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValueStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeOptionService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeValueService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeOptionStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeValueStore.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/Attribute.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/AttributeOption.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/AttributeValue.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeOptionServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeOptionStoreTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeStoreTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueStoreTest.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/indicator/hibernate/Indicator.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml
dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute'
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/Attribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/Attribute.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/Attribute.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,145 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hisp.dhis.common.AbstractIdentifiableObject;
+
+/**
+ * @author mortenoh
+ */
+public class Attribute
+ extends AbstractIdentifiableObject
+{
+ /**
+ * Determines if a de-serialized file is compatible with this class.
+ */
+ private static final long serialVersionUID = 9085246849415991424L;
+
+ private String valueType;
+
+ private boolean mandatory;
+
+ private boolean dataElement;
+
+ private boolean indicator;
+
+ private boolean organisationUnit;
+
+ private Set<AttributeOption> attributeOptions = new HashSet<AttributeOption>();
+
+ private Set<AttributeValue> attributeValues = new HashSet<AttributeValue>();
+
+ public String getValueType()
+ {
+ return valueType;
+ }
+
+ public void setValueType( String valueType )
+ {
+ this.valueType = valueType;
+ }
+
+ public boolean isMandatory()
+ {
+ return mandatory;
+ }
+
+ public void setMandatory( boolean mandatory )
+ {
+ this.mandatory = mandatory;
+ }
+
+ public boolean isDataElement()
+ {
+ return dataElement;
+ }
+
+ public void setDataElement( boolean dataElement )
+ {
+ this.dataElement = dataElement;
+ }
+
+ public boolean isIndicator()
+ {
+ return indicator;
+ }
+
+ public void setIndicator( boolean indicator )
+ {
+ this.indicator = indicator;
+ }
+
+ public boolean isOrganisationUnit()
+ {
+ return organisationUnit;
+ }
+
+ public void setOrganisationUnit( boolean organisationUnit )
+ {
+ this.organisationUnit = organisationUnit;
+ }
+
+ public Set<AttributeOption> getAttributeOptions()
+ {
+ return attributeOptions;
+ }
+
+ public void setAttributeOptions( Set<AttributeOption> attributeOptions )
+ {
+ this.attributeOptions = attributeOptions;
+ }
+
+ public Set<AttributeValue> getAttributeValues()
+ {
+ return attributeValues;
+ }
+
+ public void setAttributeValues( Set<AttributeValue> attributeValues )
+ {
+ this.attributeValues = attributeValues;
+ }
+
+ // -------------------------------------------------------------------------
+ // Helpers
+ // -------------------------------------------------------------------------
+
+ public void addAttributeOption( AttributeOption attributeOption )
+ {
+ attributeOptions.add( attributeOption );
+ attributeOption.getAttributes().add( this );
+ }
+
+ public void removeAttributeOption( AttributeOption attributeOption )
+ {
+ attributeOption.getAttributes().remove( this );
+ attributeOptions.remove( attributeOption );
+ }
+}
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeOption.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeOption.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeOption.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,90 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author mortenoh
+ */
+public class AttributeOption
+ implements Serializable
+{
+ /**
+ * Determines if a de-serialized file is compatible with this class.
+ */
+ private static final long serialVersionUID = -2698940415255819380L;
+
+ private int id;
+
+ private String value;
+
+ private Set<Attribute> attributes = new HashSet<Attribute>();
+
+ public AttributeOption()
+ {
+
+ }
+
+ public AttributeOption( String value )
+ {
+ this.value = value;
+ }
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public void setId( int id )
+ {
+ this.id = id;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue( String value )
+ {
+ this.value = value;
+ }
+
+ public Set<Attribute> getAttributes()
+ {
+ return attributes;
+ }
+
+ public void setAttributes( Set<Attribute> attributes )
+ {
+ this.attributes = attributes;
+ }
+ }
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeOptionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeOptionService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeOptionService.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import java.util.Set;
+
+/**
+ * @author mortenoh
+ */
+public interface AttributeOptionService
+{
+ String ID = AttributeOptionService.class.getName();
+
+ public void addAttributeOption( AttributeOption attributeOption );
+
+ public void updateAttributeOption( AttributeOption attributeOption );
+
+ public void deleteAttributeOption( AttributeOption attributeOption );
+
+ public AttributeOption getAttributeOption( int id );
+
+ public Set<AttributeOption> getAllAttributeOptions();
+}
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeOptionStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeOptionStore.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeOptionStore.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import org.hisp.dhis.common.GenericStore;
+
+/**
+ * @author mortenoh
+ */
+public interface AttributeOptionStore
+ extends GenericStore<AttributeOption>
+{
+ String ID = AttributeOptionStore.class.getName();
+}
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeService.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import java.util.Set;
+
+/**
+ * @author mortenoh
+ */
+public interface AttributeService
+{
+ String ID = AttributeService.class.getName();
+
+ public void addAttribute( Attribute attribute );
+
+ public void updateAttribute( Attribute attribute );
+
+ public void deleteAttribute( Attribute attribute );
+
+ public Attribute getAttribute( int id );
+
+ public Set<Attribute> getAllAttributes();
+}
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeStore.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeStore.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import java.util.Set;
+
+import org.hisp.dhis.common.GenericStore;
+
+/**
+ * @author mortenoh
+ */
+public interface AttributeStore
+ extends GenericStore<Attribute>
+{
+ String ID = AttributeStore.class.getName();
+
+ /**
+ * Get all attributes that are enabled for data elements.
+ *
+ * @return All attributes with attribute.dataElement = true
+ */
+ public Set<Attribute> getDataElementAttributes();
+
+ /**
+ * Get all attributes that are enabled for indicators.
+ *
+ * @return All attributes with attribute.indicator = true
+ */
+ public Set<Attribute> getIndicatorAttributes();
+
+ /**
+ * Get all attributes that are enabled for organisation units.
+ *
+ * @return All attributes with attribute.organisationUnit = true
+ */
+ public Set<Attribute> getOrganisationUnitAttributes();
+}
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValue.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValue.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import java.io.Serializable;
+
+/**
+ * @author mortenoh
+ */
+public class AttributeValue
+ implements Serializable
+{
+ /**
+ * Determines if a de-serialized file is compatible with this class.
+ */
+ private static final long serialVersionUID = -6625127769248931066L;
+
+ private int id;
+
+ private Attribute attribute;
+
+ private String value;
+
+ public AttributeValue()
+ {
+
+ }
+
+ public AttributeValue( String value )
+ {
+ this.value = value;
+ }
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public Attribute getAttribute()
+ {
+ return attribute;
+ }
+
+ public void setAttribute( Attribute attribute )
+ {
+ this.attribute = attribute;
+ }
+
+ public void setId( int id )
+ {
+ this.id = id;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue( String value )
+ {
+ this.value = value;
+ }
+}
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValueService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValueService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValueService.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import java.util.Set;
+
+/**
+ * @author mortenoh
+ */
+public interface AttributeValueService
+{
+ String ID = AttributeValueStore.class.getName();
+
+ public void addAttributeValue( AttributeValue attributeValue );
+
+ public void updateAttributeValue( AttributeValue attributeValue );
+
+ public void deleteAttributeValue( AttributeValue attributeValue );
+
+ public AttributeValue getAttributeValue( int id );
+
+ public Set<AttributeValue> getAllAttributeValues();
+}
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValueStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValueStore.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValueStore.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import org.hisp.dhis.common.GenericStore;
+
+/**
+ * @author mortenoh
+ */
+public interface AttributeValueStore
+ extends GenericStore<AttributeValue>
+{
+ String ID = AttributeValueStore.class.getName();
+}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2011-06-14 16:13:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2011-09-06 11:52:18 +0000
@@ -35,6 +35,7 @@
import java.util.Set;
import org.apache.commons.lang.StringEscapeUtils;
+import org.hisp.dhis.attribute.AttributeValue;
import org.hisp.dhis.common.AbstractNameableObject;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.period.PeriodType;
@@ -65,16 +66,15 @@
private static final long serialVersionUID = -7131541880444446669L;
public static final String VALUE_TYPE_STRING = "string";
-
+
public static final String VALUE_TYPE_INT = "int";
public static final String VALUE_TYPE_NUMBER = "number";
-
+
public static final String VALUE_TYPE_POSITIVE_INT = "positiveNumber";
-
+
public static final String VALUE_TYPE_NEGATIVE_INT = "negativeNumber";
-
-
+
public static final String VALUE_TYPE_BOOL = "bool";
public static final String VALUE_TYPE_DATE = "date";
@@ -110,7 +110,7 @@
* The number type. Is relevant when type is INT.
*/
private String numberType;
-
+
/**
* The aggregation operator of this DataElement; e.g. DataElement.SUM og
* DataElement.AVERAGE.
@@ -168,6 +168,11 @@
*/
private Boolean zeroIsSignificant;
+ /**
+ * Set of the dynamic attributes values that belong to this dataElement.
+ */
+ private Set<AttributeValue> attributeValues = new HashSet<AttributeValue>();
+
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
@@ -223,19 +228,19 @@
// -------------------------------------------------------------------------
// Logic
// -------------------------------------------------------------------------
-
+
public void addDataElementGroup( DataElementGroup group )
{
groups.add( group );
group.getMembers().add( this );
}
-
+
public void removeDataElementGroup( DataElementGroup group )
{
groups.remove( group );
group.getMembers().remove( this );
}
-
+
public void updateDataElementGroups( Set<DataElementGroup> updates )
{
for ( DataElementGroup group : new HashSet<DataElementGroup>( groups ) )
@@ -245,13 +250,13 @@
removeDataElementGroup( group );
}
}
-
+
for ( DataElementGroup group : updates )
{
addDataElementGroup( group );
}
}
-
+
/**
* Returns the value type. If value type is int and the number type exists,
* the number type is returned, if the type is int and the number type does
@@ -259,7 +264,7 @@
*/
public String getDetailedNumberType()
{
- return ( type != null && type.equals( VALUE_TYPE_INT ) && numberType != null ) ? numberType : type;
+ return (type != null && type.equals( VALUE_TYPE_INT ) && numberType != null) ? numberType : type;
}
/**
@@ -267,10 +272,10 @@
*/
public boolean isZeroIsSignificant()
{
- return zeroIsSignificant != null && zeroIsSignificant;
-
+ return zeroIsSignificant != null && zeroIsSignificant;
+
}
-
+
/**
* Returns the PeriodType of the DataElement, based on the PeriodType of the
* DataSet which the DataElement is registered for.
@@ -279,7 +284,7 @@
{
return dataSets != null && dataSets.size() > 0 ? dataSets.iterator().next().getPeriodType() : null;
}
-
+
/**
* Returns the frequency order for the PeriodType of this DataElement. If no
* PeriodType exists, 0 is returned.
@@ -287,7 +292,7 @@
public int getFrequencyOrder()
{
PeriodType periodType = getPeriodType();
-
+
return periodType != null ? periodType.getFrequencyOrder() : YearlyPeriodType.FREQUENCY_ORDER;
}
@@ -353,15 +358,15 @@
}
public String toJSON()
- {
- StringBuffer result = new StringBuffer();
-
+ {
+ StringBuffer result = new StringBuffer();
+
result.append( "{" );
result.append( "\"id\":\"" + this.id + "\"" );
result.append( ",\"name\":\"" + StringEscapeUtils.escapeJavaScript( this.name ) + "\"" );
result.append( ",\"shortName\":\"" + StringEscapeUtils.escapeJavaScript( this.shortName ) + "\"" );
result.append( ",\"type\":\"" + StringEscapeUtils.escapeJavaScript( this.type ) + "\"" );
- result.append( "}" );
+ result.append( "}" );
return result.toString();
}
@@ -518,4 +523,14 @@
{
this.numberType = numberType;
}
+
+ public Set<AttributeValue> getAttributeValues()
+ {
+ return attributeValues;
+ }
+
+ public void setAttributeValues( Set<AttributeValue> attributeValues )
+ {
+ this.attributeValues = attributeValues;
+ }
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java 2011-07-14 10:31:16 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java 2011-09-06 11:52:18 +0000
@@ -31,6 +31,7 @@
import java.util.HashSet;
import java.util.Set;
+import org.hisp.dhis.attribute.AttributeValue;
import org.hisp.dhis.common.AbstractNameableObject;
import org.hisp.dhis.dataset.DataSet;
@@ -57,25 +58,30 @@
private String numeratorAggregationOperator;
private String explodedNumerator;
-
+
private String denominator;
private String denominatorDescription;
private String denominatorAggregationOperator;
-
+
private String explodedDenominator;
-
+
private Integer sortOrder;
private String url;
private Date lastUpdated;
-
+
private Set<IndicatorGroup> groups = new HashSet<IndicatorGroup>();
-
+
private Set<DataSet> dataSets = new HashSet<DataSet>();
-
+
+ /**
+ * Set of the dynamic attributes values that belong to this indicator.
+ */
+ private Set<AttributeValue> attributeValues = new HashSet<AttributeValue>();
+
// -------------------------------------------------------------------------
// Logic
// -------------------------------------------------------------------------
@@ -85,13 +91,13 @@
groups.add( group );
group.getMembers().add( this );
}
-
+
public void removeIndicatorGroup( IndicatorGroup group )
{
groups.remove( group );
group.getMembers().remove( this );
}
-
+
public void updateIndicatorGroups( Set<IndicatorGroup> updates )
{
for ( IndicatorGroup group : new HashSet<IndicatorGroup>( groups ) )
@@ -101,18 +107,18 @@
removeIndicatorGroup( group );
}
}
-
+
for ( IndicatorGroup group : updates )
{
addIndicatorGroup( group );
}
}
-
+
public boolean isAnnualized()
{
return annualized != null && annualized;
}
-
+
// -------------------------------------------------------------------------
// hashCode and equals
// -------------------------------------------------------------------------
@@ -255,7 +261,7 @@
{
this.explodedDenominator = explodedDenominator;
}
-
+
public Integer getSortOrder()
{
return sortOrder;
@@ -305,4 +311,14 @@
{
this.dataSets = dataSets;
}
+
+ public Set<AttributeValue> getAttributeValues()
+ {
+ return attributeValues;
+ }
+
+ public void setAttributeValues( Set<AttributeValue> attributeValues )
+ {
+ this.attributeValues = attributeValues;
+ }
}
=== 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 2011-07-25 08:52:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2011-09-06 11:52:18 +0000
@@ -38,6 +38,7 @@
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
+import org.hisp.dhis.attribute.AttributeValue;
import org.hisp.dhis.common.AbstractNameableObject;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataset.DataSet;
@@ -57,61 +58,73 @@
private static final long serialVersionUID = 1228298379303894619L;
public static final String FEATURETYPE_NONE = "None";
+
public static final String FEATURETYPE_MULTIPOLYGON = "MultiPolygon";
+
public static final String FEATURETYPE_POLYGON = "Polygon";
+
public static final String FEATURETYPE_POINT = "Point";
+
public static final String RESULTTYPE_SYMBOL = "Symbol";
-
+
private static final Comparator<OrganisationUnit> COMPARATOR = new OrganisationUnitNameComparator();
+
private static final Pattern JSON_COORDINATE_PATTERN = Pattern.compile( "(\\[{3}.*?\\]{3})" );
- private static final Pattern COORDINATE_PATTERN = Pattern.compile("([\\-0-9.]+,[\\-0-9.]+)");
-
+
+ private static final Pattern COORDINATE_PATTERN = Pattern.compile( "([\\-0-9.]+,[\\-0-9.]+)" );
+
private static final String NAME_SEPARATOR = " - ";
-
+
private Set<OrganisationUnit> children = new HashSet<OrganisationUnit>();
private OrganisationUnit parent;
-
+
private Date openingDate;
private Date closedDate;
private boolean active;
-
+
private String comment;
-
+
private String geoCode;
private String featureType;
-
+
private String coordinates;
-
+
private String url;
private Date lastUpdated;
private Set<OrganisationUnitGroup> groups = new HashSet<OrganisationUnitGroup>();
-
+
private Set<DataSet> dataSets = new HashSet<DataSet>();
-
+
private Set<User> users = new HashSet<User>();
-
+
private String contactPerson;
-
+
private String address;
-
+
private String email;
-
+
private String phoneNumber;
private Boolean hasPatients;
-
+
private transient int level;
-
+
private transient boolean currentParent;
-
+
private transient String type;
-
+
+ /**
+ * Set of the dynamic attributes values that belong to this
+ * organisationUnit.
+ */
+ private Set<AttributeValue> attributeValues = new HashSet<AttributeValue>();
+
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
@@ -124,42 +137,42 @@
{
this.name = name;
}
-
- /**
- * @param name
- * @param shortName
- * @param organisationUnitCode
- * @param openingDate
- * @param closedDate
- * @param active
- * @param comment
- */
- public OrganisationUnit( String name, String shortName, String code, Date openingDate,
+
+ /**
+ * @param name
+ * @param shortName
+ * @param organisationUnitCode
+ * @param openingDate
+ * @param closedDate
+ * @param active
+ * @param comment
+ */
+ public OrganisationUnit( String name, String shortName, String code, Date openingDate, Date closedDate,
+ boolean active, String comment )
+ {
+ this.name = name;
+ this.shortName = shortName;
+ this.code = code;
+ this.openingDate = openingDate;
+ this.closedDate = closedDate;
+ this.active = active;
+ this.comment = comment;
+ }
+
+ /**
+ * @param name
+ * @param parent
+ * @param shortName
+ * @param organisationUnitCode
+ * @param openingDate
+ * @param closedDate
+ * @param active
+ * @param comment
+ */
+ public OrganisationUnit( String name, OrganisationUnit parent, String shortName, String code, Date openingDate,
Date closedDate, boolean active, String comment )
{
this.name = name;
- this.shortName = shortName;
- this.code = code;
- this.openingDate = openingDate;
- this.closedDate = closedDate;
- this.active = active;
- this.comment = comment;
- }
-
- /**
- * @param name
- * @param parent
- * @param shortName
- * @param organisationUnitCode
- * @param openingDate
- * @param closedDate
- * @param active
- * @param comment
- */
- public OrganisationUnit( String name, OrganisationUnit parent, String shortName, String code,
- Date openingDate, Date closedDate, boolean active, String comment )
- {
- this.name = name;
this.parent = parent;
this.shortName = shortName;
this.code = code;
@@ -172,19 +185,19 @@
// -------------------------------------------------------------------------
// Logic
// -------------------------------------------------------------------------
-
+
public void addDataSet( DataSet dataSet )
{
dataSets.add( dataSet );
dataSet.getSources().add( this );
}
-
+
public void removeDataSet( DataSet dataSet )
{
dataSets.remove( dataSet );
- dataSet.getSources().remove( this );
+ dataSet.getSources().remove( this );
}
-
+
public void updateDataSets( Set<DataSet> updates )
{
for ( DataSet dataSet : new HashSet<DataSet>( dataSets ) )
@@ -194,37 +207,37 @@
removeDataSet( dataSet );
}
}
-
+
for ( DataSet dataSet : updates )
{
addDataSet( dataSet );
}
}
-
+
public List<OrganisationUnit> getSortedChildren()
{
List<OrganisationUnit> sortedChildren = new ArrayList<OrganisationUnit>( children );
-
+
Collections.sort( sortedChildren, COMPARATOR );
-
+
return sortedChildren;
}
-
+
public Set<OrganisationUnit> getGrandChildren()
{
Set<OrganisationUnit> grandChildren = new HashSet<OrganisationUnit>();
-
+
for ( OrganisationUnit child : children )
{
grandChildren.addAll( child.getChildren() );
}
-
+
return grandChildren;
}
-
+
public boolean hasChild()
{
- return !this.children.isEmpty();
+ return !this.children.isEmpty();
}
public boolean hasChildrenWithCoordinates()
@@ -236,19 +249,19 @@
return true;
}
}
-
+
return false;
}
-
+
public boolean hasCoordinates()
{
return coordinates != null && coordinates.trim().length() > 0;
}
-
+
public List<CoordinatesTuple> getCoordinatesAsList()
{
List<CoordinatesTuple> list = new ArrayList<CoordinatesTuple>();
-
+
if ( coordinates != null && !coordinates.trim().isEmpty() )
{
Matcher jsonMatcher = JSON_COORDINATE_PATTERN.matcher( coordinates );
@@ -256,56 +269,56 @@
while ( jsonMatcher.find() )
{
CoordinatesTuple tuple = new CoordinatesTuple();
-
+
Matcher matcher = COORDINATE_PATTERN.matcher( jsonMatcher.group() );
-
+
while ( matcher.find() )
{
tuple.addCoordinates( matcher.group() );
}
-
+
list.add( tuple );
}
}
-
+
return list;
}
-
+
public void setMultiPolygonCoordinatesFromList( List<CoordinatesTuple> list )
{
StringBuilder builder = new StringBuilder();
-
+
if ( CoordinatesTuple.hasCoordinates( list ) )
{
builder.append( "[" );
-
+
for ( CoordinatesTuple tuple : list )
{
if ( tuple.hasCoordinates() )
{
builder.append( "[[" );
-
+
for ( String coordinates : tuple.getCoordinatesTuple() )
{
builder.append( "[" + coordinates + "]," );
}
-
- builder.deleteCharAt( builder.lastIndexOf( "," ) );
+
+ builder.deleteCharAt( builder.lastIndexOf( "," ) );
builder.append( "]]," );
}
}
-
+
builder.deleteCharAt( builder.lastIndexOf( "," ) );
builder.append( "]" );
}
-
+
this.coordinates = StringUtils.trimToNull( builder.toString() );
}
-
+
public void setPointCoordinatesFromList( List<CoordinatesTuple> list )
{
StringBuilder builder = new StringBuilder();
-
+
if ( list != null && list.size() > 0 )
{
for ( CoordinatesTuple tuple : list )
@@ -316,10 +329,10 @@
}
}
}
-
+
this.coordinates = StringUtils.trimToNull( builder.toString() );
}
-
+
public String getChildrenFeatureType()
{
for ( OrganisationUnit child : children )
@@ -329,15 +342,15 @@
return child.getFeatureType();
}
}
-
+
return FEATURETYPE_NONE;
}
-
+
public String getValidCoordinates()
{
return coordinates != null && !coordinates.isEmpty() ? coordinates : "[]";
}
-
+
public OrganisationUnitGroup getGroupInGroupSet( OrganisationUnitGroupSet groupSet )
{
if ( groupSet != null )
@@ -347,75 +360,75 @@
if ( groupSet.getOrganisationUnitGroups().contains( group ) )
{
return group;
- }
+ }
}
}
-
+
return null;
}
-
+
public Integer getGroupIdInGroupSet( OrganisationUnitGroupSet groupSet )
{
final OrganisationUnitGroup group = getGroupInGroupSet( groupSet );
-
+
return group != null ? group.getId() : null;
}
-
+
public String getGroupNameInGroupSet( OrganisationUnitGroupSet groupSet )
{
final OrganisationUnitGroup group = getGroupInGroupSet( groupSet );
-
+
return group != null ? group.getName() : null;
}
-
+
public String getAncestorNames()
{
StringBuilder builder = new StringBuilder( name );
-
+
OrganisationUnit unit = parent;
-
+
while ( unit != null )
{
builder.append( NAME_SEPARATOR ).append( unit.getName() );
unit = unit.getParent();
}
-
+
return builder.toString();
}
-
+
public Set<DataElement> getDataElementsInDataSets()
{
Set<DataElement> dataElements = new HashSet<DataElement>();
-
+
for ( DataSet dataSet : dataSets )
{
dataElements.addAll( dataSet.getDataElements() );
}
-
+
return dataElements;
}
-
+
public boolean isHasPatients()
{
return hasPatients != null && hasPatients;
}
-
+
public void updateParent( OrganisationUnit newParent )
{
if ( this.parent != null && this.parent.getChildren() != null )
{
- this.parent.getChildren().remove( this );
+ this.parent.getChildren().remove( this );
}
-
+
this.parent = newParent;
-
+
newParent.getChildren().add( this );
}
-
+
public Set<OrganisationUnit> getChildrenThisIfEmpty()
{
Set<OrganisationUnit> set = new HashSet<OrganisationUnit>();
-
+
if ( hasChild() )
{
set = children;
@@ -424,10 +437,10 @@
{
set.add( this );
}
-
+
return set;
}
-
+
// -------------------------------------------------------------------------
// hashCode, equals and toString
// -------------------------------------------------------------------------
@@ -510,17 +523,17 @@
{
this.code = code;
}
-
+
public String getAlternativeName()
{
return getShortName();
}
-
+
public void setAlternativeName( String alternativeName )
{
throw new UnsupportedOperationException( "Cannot set alternativename on OrganisationUnit: " + alternativeName );
}
-
+
public Date getOpeningDate()
{
return openingDate;
@@ -680,7 +693,7 @@
{
this.phoneNumber = phoneNumber;
}
-
+
public Boolean getHasPatients()
{
return hasPatients;
@@ -720,4 +733,14 @@
{
this.type = type;
}
+
+ public Set<AttributeValue> getAttributeValues()
+ {
+ return attributeValues;
+ }
+
+ public void setAttributeValues( Set<AttributeValue> attributeValues )
+ {
+ this.attributeValues = attributeValues;
+ }
}
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeOptionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeOptionService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeOptionService.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * @author mortenoh
+ */
+@Transactional
+public class DefaultAttributeOptionService
+ implements AttributeOptionService
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private AttributeOptionStore attributeOptionStore;
+
+ public AttributeOptionStore getAttributeOptionStore()
+ {
+ return attributeOptionStore;
+ }
+
+ public void setAttributeOptionStore( AttributeOptionStore attributeOptionStore )
+ {
+ this.attributeOptionStore = attributeOptionStore;
+ }
+
+ // -------------------------------------------------------------------------
+ // AttributeOptionService implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public void addAttributeOption( AttributeOption attributeOption )
+ {
+ attributeOptionStore.save( attributeOption );
+ }
+
+ @Override
+ public void updateAttributeOption( AttributeOption attributeOption )
+ {
+ attributeOptionStore.update( attributeOption );
+ }
+
+ @Override
+ public void deleteAttributeOption( AttributeOption attributeOption )
+ {
+ attributeOptionStore.delete( attributeOption );
+ }
+
+ @Override
+ public AttributeOption getAttributeOption( int id )
+ {
+ return attributeOptionStore.get( id );
+ }
+
+ @Override
+ public Set<AttributeOption> getAllAttributeOptions()
+ {
+ return new HashSet<AttributeOption>( attributeOptionStore.getAll() );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * @author mortenoh
+ */
+@Transactional
+public class DefaultAttributeService
+ implements AttributeService
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private AttributeStore attributeStore;
+
+ public AttributeStore getAttributeStore()
+ {
+ return attributeStore;
+ }
+
+ public void setAttributeStore( AttributeStore attributeStore )
+ {
+ this.attributeStore = attributeStore;
+ }
+
+ // -------------------------------------------------------------------------
+ // AttributeService implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public void addAttribute( Attribute attribute )
+ {
+ attributeStore.save( attribute );
+ }
+
+ @Override
+ public void updateAttribute( Attribute attribute )
+ {
+ attributeStore.update( attribute );
+ }
+
+ @Override
+ public void deleteAttribute( Attribute attribute )
+ {
+ attributeStore.delete( attribute );
+ }
+
+ @Override
+ public Attribute getAttribute( int id )
+ {
+ return attributeStore.get( id );
+ }
+
+ @Override
+ public Set<Attribute> getAllAttributes()
+ {
+ return new HashSet<Attribute>( attributeStore.getAll() );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeValueService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeValueService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeValueService.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * @author mortenoh
+ */
+@Transactional
+public class DefaultAttributeValueService
+ implements AttributeValueService
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private AttributeValueStore attributeValueStore;
+
+ public AttributeValueStore getAttributeValueStore()
+ {
+ return attributeValueStore;
+ }
+
+ public void setAttributeValueStore( AttributeValueStore attributeValueStore )
+ {
+ this.attributeValueStore = attributeValueStore;
+ }
+
+ // -------------------------------------------------------------------------
+ // AttributeValueService implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public void addAttributeValue( AttributeValue attributeValue )
+ {
+ attributeValueStore.save( attributeValue );
+ }
+
+ @Override
+ public void updateAttributeValue( AttributeValue attributeValue )
+ {
+ attributeValueStore.update( attributeValue );
+ }
+
+ @Override
+ public void deleteAttributeValue( AttributeValue attributeValue )
+ {
+ attributeValueStore.delete( attributeValue );
+ }
+
+ @Override
+ public AttributeValue getAttributeValue( int id )
+ {
+ return attributeValueStore.get( id );
+ }
+
+ @Override
+ public Set<AttributeValue> getAllAttributeValues()
+ {
+ return new HashSet<AttributeValue>( attributeValueStore.getAll() );
+ }
+}
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeOptionStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeOptionStore.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeOptionStore.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute.hibernate;
+
+import org.hisp.dhis.attribute.AttributeOption;
+import org.hisp.dhis.attribute.AttributeOptionStore;
+import org.hisp.dhis.hibernate.HibernateGenericStore;
+
+/**
+ * @author mortenoh
+ */
+public class HibernateAttributeOptionStore
+ extends HibernateGenericStore<AttributeOption>
+ implements AttributeOptionStore
+{
+
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeStore.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeStore.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute.hibernate;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.attribute.Attribute;
+import org.hisp.dhis.attribute.AttributeStore;
+import org.hisp.dhis.hibernate.HibernateGenericStore;
+
+/**
+ * @author mortenoh
+ */
+public class HibernateAttributeStore
+ extends HibernateGenericStore<Attribute>
+ implements AttributeStore
+{
+ @SuppressWarnings( "unchecked" )
+ public Set<Attribute> getDataElementAttributes()
+ {
+ Session session = sessionFactory.getCurrentSession();
+ Criteria criteria = session.createCriteria( Attribute.class );
+ criteria.add( Restrictions.eq( "dataElement", true ) );
+ criteria.setCacheable( true );
+
+ return new HashSet<Attribute>( criteria.list() );
+ }
+
+ @SuppressWarnings( "unchecked" )
+ public Set<Attribute> getIndicatorAttributes()
+ {
+ Session session = sessionFactory.getCurrentSession();
+ Criteria criteria = session.createCriteria( Attribute.class );
+ criteria.add( Restrictions.eq( "indicator", true ) );
+ criteria.setCacheable( true );
+
+ return new HashSet<Attribute>( criteria.list() );
+ }
+
+ @SuppressWarnings( "unchecked" )
+ public Set<Attribute> getOrganisationUnitAttributes()
+ {
+ Session session = sessionFactory.getCurrentSession();
+ Criteria criteria = session.createCriteria( Attribute.class );
+ criteria.add( Restrictions.eq( "organisationUnit", true ) );
+ criteria.setCacheable( true );
+
+ return new HashSet<Attribute>( criteria.list() );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeValueStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeValueStore.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeValueStore.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute.hibernate;
+
+import org.hisp.dhis.attribute.AttributeValue;
+import org.hisp.dhis.attribute.AttributeValueStore;
+import org.hisp.dhis.hibernate.HibernateGenericStore;
+
+/**
+ * @author mortenoh
+ */
+public class HibernateAttributeValueStore
+ extends HibernateGenericStore<AttributeValue>
+ implements AttributeValueStore
+{
+
+}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2011-08-11 11:31:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2011-09-06 11:52:18 +0000
@@ -233,6 +233,21 @@
<property name="clazz" value="org.hisp.dhis.version.Version" />
</bean>
+ <bean id="org.hisp.dhis.attribute.AttributeStore" class="org.hisp.dhis.attribute.hibernate.HibernateAttributeStore">
+ <property name="sessionFactory" ref="sessionFactory" />
+ <property name="clazz" value="org.hisp.dhis.attribute.Attribute" />
+ </bean>
+
+ <bean id="org.hisp.dhis.attribute.AttributeOptionStore" class="org.hisp.dhis.attribute.hibernate.HibernateAttributeOptionStore">
+ <property name="sessionFactory" ref="sessionFactory" />
+ <property name="clazz" value="org.hisp.dhis.attribute.AttributeOption" />
+ </bean>
+
+ <bean id="org.hisp.dhis.attribute.AttributeValueStore" class="org.hisp.dhis.attribute.hibernate.HibernateAttributeValueStore">
+ <property name="sessionFactory" ref="sessionFactory" />
+ <property name="clazz" value="org.hisp.dhis.attribute.AttributeValue" />
+ </bean>
+
<!-- Service definitions -->
<bean id="org.hisp.dhis.dataelement.DataElementOperandService" class="org.hisp.dhis.dataelement.DefaultDataElementOperandService">
@@ -446,6 +461,18 @@
<property name="versionStore" ref="org.hisp.dhis.version.VersionStore" />
</bean>
+ <bean id="org.hisp.dhis.attribute.AttributeService" class="org.hisp.dhis.attribute.DefaultAttributeService">
+ <property name="attributeStore" ref="org.hisp.dhis.attribute.AttributeStore" />
+ </bean>
+
+ <bean id="org.hisp.dhis.attribute.AttributeOptionService" class="org.hisp.dhis.attribute.DefaultAttributeOptionService">
+ <property name="attributeOptionStore" ref="org.hisp.dhis.attribute.AttributeOptionStore" />
+ </bean>
+
+ <bean id="org.hisp.dhis.attribute.AttributeValueService" class="org.hisp.dhis.attribute.DefaultAttributeValueService">
+ <property name="attributeValueStore" ref="org.hisp.dhis.attribute.AttributeValueStore" />
+ </bean>
+
<!-- I18nService -->
<bean id="org.hisp.dhis.i18n.I18nService" class="org.hisp.dhis.i18n.DefaultI18nService">
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute'
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/Attribute.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/Attribute.hbm.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/Attribute.hbm.xml 2011-09-06 11:52:18 +0000
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hisp.dhis.attribute">
+ <class name="Attribute" table="attribute">
+
+ <cache usage="read-write" />
+
+ <id name="id" column="attributeid">
+ <generator class="native" />
+ </id>
+
+ <property name="name" not-null="true" unique="true" />
+
+ <property name="valueType" not-null="true" />
+
+ <property name="mandatory" />
+
+ <property name="dataElement" />
+
+ <property name="indicator" />
+
+ <property name="organisationUnit" />
+
+ <set name="attributeOptions" table="attributeattributeoptions">
+ <key column="attributeid" />
+ <many-to-many column="attributeoptionid" class="AttributeOption" />
+ </set>
+
+ <set name="attributeValues" inverse="true" lazy="true">
+ <cache usage="read-write" />
+ <key column="attributeid" />
+ <one-to-many class="AttributeValue" />
+ </set>
+
+ </class>
+</hibernate-mapping>
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/AttributeOption.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/AttributeOption.hbm.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/AttributeOption.hbm.xml 2011-09-06 11:52:18 +0000
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hisp.dhis.attribute">
+ <class name="AttributeOption" table="attributeoption">
+
+ <cache usage="read-write" />
+
+ <id name="id" column="attributeoptionid">
+ <generator class="native" />
+ </id>
+
+ <property name="value" />
+
+ <set name="attributes" table="attributeattributeoptions">
+ <cache usage="read-write" />
+ <key column="attributeoptionid" />
+ <many-to-many column="attributeid" class="Attribute" />
+ </set>
+
+ </class>
+</hibernate-mapping>
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/AttributeValue.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/AttributeValue.hbm.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/attribute/hibernate/AttributeValue.hbm.xml 2011-09-06 11:52:18 +0000
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hisp.dhis.attribute">
+ <class name="AttributeValue" table="attributevalue">
+
+ <cache usage="read-write" />
+
+ <id name="id" column="attributevalueid">
+ <generator class="native" />
+ </id>
+
+ <property name="value" />
+
+ </class>
+</hibernate-mapping>
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml 2011-07-13 09:35:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml 2011-09-06 11:52:18 +0000
@@ -73,5 +73,13 @@
<property name="zeroIsSignificant" />
+ <!-- Dynamic attribute values -->
+
+ <set name="attributeValues" table="dataelementattributevalues">
+ <cache usage="read-write" />
+ <key column="dataelementid" />
+ <many-to-many class="org.hisp.dhis.attribute.AttributeValue" column="attributevalueid" />
+ </set>
+
</class>
</hibernate-mapping>
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/indicator/hibernate/Indicator.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/indicator/hibernate/Indicator.hbm.xml 2011-07-14 10:31:16 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/indicator/hibernate/Indicator.hbm.xml 2011-09-06 11:52:18 +0000
@@ -68,5 +68,14 @@
<key column="indicatorid" />
<many-to-many class="org.hisp.dhis.dataset.DataSet" column="datasetid" />
</set>
+
+ <!-- Dynamic attribute values -->
+
+ <set name="attributeValues" table="indicatorattributevalues">
+ <cache usage="read-write" />
+ <key column="indicatorid" />
+ <many-to-many class="org.hisp.dhis.attribute.AttributeValue" column="attributevalueid" />
+ </set>
+
</class>
</hibernate-mapping>
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml 2011-07-13 09:35:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml 2011-09-06 11:52:18 +0000
@@ -87,5 +87,13 @@
<property name="hasPatients" />
+ <!-- Dynamic attribute values -->
+
+ <set name="attributeValues" table="organisationunitattributevalues">
+ <cache usage="read-write" />
+ <key column="organisationunitid" />
+ <many-to-many class="org.hisp.dhis.attribute.AttributeValue" column="attributevalueid" />
+ </set>
+
</class>
</hibernate-mapping>
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeOptionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeOptionServiceTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeOptionServiceTest.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,132 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.hisp.dhis.DhisSpringTest;
+
+/**
+ * @author mortenoh
+ */
+public class AttributeOptionServiceTest
+ extends DhisSpringTest
+{
+ private AttributeOptionService attributeOptionService;
+
+ @Override
+ protected void setUpTest()
+ {
+ attributeOptionService = (AttributeOptionService) getBean( "org.hisp.dhis.attribute.AttributeOptionService" );
+ }
+
+ @Test
+ public void testAddAttributeOption()
+ {
+ AttributeOption attributeOption1 = new AttributeOption( "option 1" );
+ AttributeOption attributeOption2 = new AttributeOption( "option 2" );
+
+ attributeOptionService.addAttributeOption( attributeOption1 );
+ attributeOptionService.addAttributeOption( attributeOption2 );
+
+ attributeOption1 = attributeOptionService.getAttributeOption( attributeOption1.getId() );
+ attributeOption2 = attributeOptionService.getAttributeOption( attributeOption2.getId() );
+
+ assertNotNull( attributeOption1 );
+ assertNotNull( attributeOption2 );
+ }
+
+ @Test
+ public void testUpdateAttributeOption()
+ {
+ AttributeOption attributeOption1 = new AttributeOption( "option 1" );
+ AttributeOption attributeOption2 = new AttributeOption( "option 2" );
+
+ attributeOptionService.addAttributeOption( attributeOption1 );
+ attributeOptionService.addAttributeOption( attributeOption2 );
+
+ attributeOption1.setValue( "updated option 1" );
+ attributeOption2.setValue( "updated option 2" );
+
+ attributeOptionService.updateAttributeOption( attributeOption1 );
+ attributeOptionService.updateAttributeOption( attributeOption2 );
+
+ attributeOption1 = attributeOptionService.getAttributeOption( attributeOption1.getId() );
+ attributeOption2 = attributeOptionService.getAttributeOption( attributeOption2.getId() );
+
+ assertNotNull( attributeOption1 );
+ assertNotNull( attributeOption2 );
+
+ assertEquals( "updated option 1", attributeOption1.getValue() );
+ assertEquals( "updated option 2", attributeOption2.getValue() );
+ }
+
+ @Test
+ public void testDeleteAttributeOption()
+ {
+ AttributeOption attributeOption1 = new AttributeOption( "option 1" );
+ AttributeOption attributeOption2 = new AttributeOption( "option 2" );
+
+ attributeOptionService.addAttributeOption( attributeOption1 );
+ attributeOptionService.addAttributeOption( attributeOption2 );
+
+ int attributeOptionId1 = attributeOption1.getId();
+ int attributeOptionId2 = attributeOption2.getId();
+
+ attributeOptionService.deleteAttributeOption( attributeOption1 );
+ attributeOptionService.deleteAttributeOption( attributeOption2 );
+
+ assertNull( attributeOptionService.getAttributeOption( attributeOptionId1 ) );
+ assertNull( attributeOptionService.getAttributeOption( attributeOptionId2 ) );
+ }
+
+ @Test
+ public void testGetAttributeOption()
+ {
+ AttributeOption attributeOption1 = new AttributeOption( "option 1" );
+ AttributeOption attributeOption2 = new AttributeOption( "option 2" );
+
+ attributeOptionService.addAttributeOption( attributeOption1 );
+ attributeOptionService.addAttributeOption( attributeOption2 );
+
+ attributeOption1 = attributeOptionService.getAttributeOption( attributeOption1.getId() );
+ attributeOption2 = attributeOptionService.getAttributeOption( attributeOption2.getId() );
+
+ assertNotNull( attributeOption1 );
+ assertNotNull( attributeOption2 );
+ }
+
+ @Test
+ public void testGetAllAttributeOptions()
+ {
+ AttributeOption attributeOption1 = new AttributeOption( "option 1" );
+ AttributeOption attributeOption2 = new AttributeOption( "option 2" );
+
+ attributeOptionService.addAttributeOption( attributeOption1 );
+ attributeOptionService.addAttributeOption( attributeOption2 );
+
+ assertEquals( 2, attributeOptionService.getAllAttributeOptions().size() );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeOptionStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeOptionStoreTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeOptionStoreTest.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.hisp.dhis.DhisSpringTest;
+
+public class AttributeOptionStoreTest
+ extends DhisSpringTest
+{
+ private AttributeOptionStore attributeOptionStore;
+
+ private AttributeOption option1;
+
+ private AttributeOption option2;
+
+ @Override
+ protected void setUpTest()
+ {
+ attributeOptionStore = (AttributeOptionStore) getBean( "org.hisp.dhis.attribute.AttributeOptionStore" );
+
+ Attribute attribute1 = new Attribute();
+ attribute1.setName( "attribute_simple1" );
+ attribute1.setValueType( "string" );
+
+ Attribute attribute2 = new Attribute();
+ attribute2.setName( "attribute_simple2" );
+ attribute2.setValueType( "string" );
+
+ option1 = new AttributeOption( "option 1" );
+ option1.getAttributes().add( attribute1 );
+ option1.getAttributes().add( attribute2 );
+
+ option2 = new AttributeOption( "option 2" );
+ option2.getAttributes().add( attribute2 );
+
+ attributeOptionStore.save( option1 );
+ attributeOptionStore.save( option2 );
+ }
+
+ @Test
+ public void testGetAttributes()
+ {
+ AttributeOption ao1 = attributeOptionStore.get( option1.getId() );
+ AttributeOption ao2 = attributeOptionStore.get( option2.getId() );
+
+ assertNotNull( ao1 );
+ assertNotNull( ao2 );
+
+ assertEquals( 2, ao1.getAttributes().size() );
+ assertEquals( 1, ao2.getAttributes().size() );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeServiceTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeServiceTest.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,128 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.hisp.dhis.DhisSpringTest;
+
+/**
+ * @author mortenoh
+ */
+public class AttributeServiceTest
+ extends DhisSpringTest
+{
+ private AttributeService attributeService;
+
+ @Override
+ protected void setUpTest()
+ {
+ attributeService = (AttributeService) getBean( "org.hisp.dhis.attribute.AttributeService" );
+ }
+
+ @Test
+ public void testAddAttribute()
+ {
+ Attribute attribute = new Attribute();
+ attribute.setValueType( "string" );
+ attribute.setName( "attribute1" );
+
+ attributeService.addAttribute( attribute );
+ attribute = attributeService.getAttribute( attribute.getId() );
+
+ assertNotNull( attribute );
+ assertEquals( "attribute1", attribute.getName() );
+ assertEquals( "string", attribute.getValueType() );
+ }
+
+ @Test
+ public void testUpdateAttribute()
+ {
+ Attribute attribute = new Attribute();
+ attribute.setValueType( "string" );
+ attribute.setName( "attribute1" );
+
+ attributeService.addAttribute( attribute );
+
+ attribute.setValueType( "int" );
+ attribute.setName( "attribute2" );
+
+ attributeService.updateAttribute( attribute );
+ attribute = attributeService.getAttribute( attribute.getId() );
+
+ assertEquals( "int", attribute.getValueType() );
+ assertEquals( "attribute2", attribute.getName() );
+ }
+
+ @Test
+ public void testDeleteAttribute()
+ {
+ Attribute attribute = new Attribute();
+ attribute.setValueType( "string" );
+ attribute.setName( "attribute1" );
+
+ attributeService.addAttribute( attribute );
+ attribute = attributeService.getAttribute( attribute.getId() );
+
+ assertNotNull( attribute );
+
+ int attributeId = attribute.getId();
+
+ attributeService.deleteAttribute( attribute );
+ attribute = attributeService.getAttribute( attributeId );
+
+ assertNull( attribute );
+ }
+
+ @Test
+ public void testGetAttribute()
+ {
+ Attribute attribute = new Attribute();
+ attribute.setValueType( "string" );
+ attribute.setName( "attribute1" );
+
+ attributeService.addAttribute( attribute );
+ attribute = attributeService.getAttribute( attribute.getId() );
+
+ assertNotNull( attribute );
+ }
+
+ @Test
+ public void testGetAllAttributes()
+ {
+ Attribute attribute1 = new Attribute();
+ attribute1.setValueType( "string" );
+ attribute1.setName( "attribute1" );
+
+ Attribute attribute2 = new Attribute();
+ attribute2.setValueType( "string" );
+ attribute2.setName( "attribute2" );
+
+ attributeService.addAttribute( attribute1 );
+ attributeService.addAttribute( attribute2 );
+
+ assertEquals( 2, attributeService.getAllAttributes().size() );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeStoreTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeStoreTest.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.hisp.dhis.DhisSpringTest;
+
+public class AttributeStoreTest
+ extends DhisSpringTest
+{
+ private AttributeStore attributeStore;
+
+ private Attribute attribute1;
+
+ private Attribute attribute2;
+
+ @Override
+ protected void setUpTest()
+ {
+ attributeStore = (AttributeStore) getBean( "org.hisp.dhis.attribute.AttributeStore" );
+
+ attribute1 = new Attribute();
+ attribute1.setName( "attribute_simple" );
+ attribute1.setValueType( "string" );
+ attribute1.setIndicator( true );
+ attribute1.setDataElement( true );
+
+ attribute2 = new Attribute();
+ attribute2.setName( "attribute_with_options" );
+ attribute2.setValueType( "string" );
+ attribute2.setOrganisationUnit( true );
+ attribute2.setDataElement( true );
+
+ attribute2.addAttributeOption( new AttributeOption( "option 1" ) );
+ attribute2.addAttributeOption( new AttributeOption( "option 2" ) );
+
+ attributeStore.save( attribute1 );
+ attributeStore.save( attribute2 );
+ }
+
+ @Test
+ public void testGetDataElementAttributes()
+ {
+ assertEquals( 2, attributeStore.getDataElementAttributes().size() );
+ }
+
+ @Test
+ public void testGetIndicatorAttributes()
+ {
+ assertEquals( 1, attributeStore.getIndicatorAttributes().size() );
+ }
+
+ @Test
+ public void testGetOrganisationUnitAttributes()
+ {
+ assertEquals( 1, attributeStore.getOrganisationUnitAttributes().size() );
+ }
+
+ @Test
+ public void testGetAttributeOptions()
+ {
+ Attribute attr = attributeStore.get( attribute2.getId() );
+ assertNotNull( attr );
+ assertEquals( 2, attr.getAttributeOptions().size() );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueServiceTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueServiceTest.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,135 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.hisp.dhis.DhisSpringTest;
+
+/**
+ * @author mortenoh
+ */
+public class AttributeValueServiceTest
+ extends DhisSpringTest
+{
+ private AttributeValueService attributeValueService;
+
+ @Override
+ protected void setUpTest()
+ {
+ attributeValueService = (AttributeValueService) getBean( "org.hisp.dhis.attribute.AttributeValueService" );
+ }
+
+ @Test
+ public void testAddAttributeValue()
+ {
+ AttributeValue attributeValue1 = new AttributeValue( "value 1" );
+ AttributeValue attributeValue2 = new AttributeValue( "value 2" );
+
+ attributeValueService.addAttributeValue( attributeValue1 );
+ attributeValueService.addAttributeValue( attributeValue2 );
+
+ attributeValue1 = attributeValueService.getAttributeValue( attributeValue1.getId() );
+ attributeValue2 = attributeValueService.getAttributeValue( attributeValue2.getId() );
+
+ assertNotNull( attributeValue1 );
+ assertNotNull( attributeValue2 );
+ }
+
+ @Test
+ public void testUpdateAttributeValue()
+ {
+ AttributeValue attributeValue1 = new AttributeValue( "value 1" );
+ AttributeValue attributeValue2 = new AttributeValue( "value 2" );
+
+ attributeValueService.addAttributeValue( attributeValue1 );
+ attributeValueService.addAttributeValue( attributeValue2 );
+
+ attributeValue1.setValue( "updated value 1" );
+ attributeValue2.setValue( "updated value 2" );
+
+ attributeValueService.updateAttributeValue( attributeValue1 );
+ attributeValueService.updateAttributeValue( attributeValue2 );
+
+ attributeValue1 = attributeValueService.getAttributeValue( attributeValue1.getId() );
+ attributeValue2 = attributeValueService.getAttributeValue( attributeValue2.getId() );
+
+ assertNotNull( attributeValue1 );
+ assertNotNull( attributeValue2 );
+
+ assertEquals( "updated value 1", attributeValue1.getValue() );
+ assertEquals( "updated value 2", attributeValue2.getValue() );
+ }
+
+ @Test
+ public void testDeleteAttributeValue()
+ {
+ AttributeValue attributeValue1 = new AttributeValue( "value 1" );
+ AttributeValue attributeValue2 = new AttributeValue( "value 2" );
+
+ attributeValueService.addAttributeValue( attributeValue1 );
+ attributeValueService.addAttributeValue( attributeValue2 );
+
+ int attributeValueId1 = attributeValue1.getId();
+ int attributeValueId2 = attributeValue2.getId();
+
+ attributeValueService.deleteAttributeValue( attributeValue1 );
+ attributeValueService.deleteAttributeValue( attributeValue2 );
+
+ attributeValue1 = attributeValueService.getAttributeValue( attributeValueId1 );
+ attributeValue2 = attributeValueService.getAttributeValue( attributeValueId2 );
+
+ assertNull( attributeValue1 );
+ assertNull( attributeValue2 );
+ }
+
+ @Test
+ public void testGetAttributeValue()
+ {
+ AttributeValue attributeValue1 = new AttributeValue( "value 1" );
+ AttributeValue attributeValue2 = new AttributeValue( "value 2" );
+
+ attributeValueService.addAttributeValue( attributeValue1 );
+ attributeValueService.addAttributeValue( attributeValue2 );
+
+ attributeValue1 = attributeValueService.getAttributeValue( attributeValue1.getId() );
+ attributeValue2 = attributeValueService.getAttributeValue( attributeValue2.getId() );
+
+ assertNotNull( attributeValue1 );
+ assertNotNull( attributeValue2 );
+ }
+
+ @Test
+ public void testGetAllAttributeValues()
+ {
+ AttributeValue attributeValue1 = new AttributeValue( "value 1" );
+ AttributeValue attributeValue2 = new AttributeValue( "value 2" );
+
+ attributeValueService.addAttributeValue( attributeValue1 );
+ attributeValueService.addAttributeValue( attributeValue2 );
+
+ assertEquals( 2, attributeValueService.getAllAttributeValues().size() );
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueStoreTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueStoreTest.java 2011-09-06 11:52:18 +0000
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.attribute;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.hisp.dhis.DhisSpringTest;
+
+public class AttributeValueStoreTest
+ extends DhisSpringTest
+{
+ private AttributeValueStore attributeValueStore;
+
+ private AttributeValue attributeValue1;
+
+ private AttributeValue attributeValue2;
+
+ @Override
+ protected void setUpTest()
+ {
+ attributeValueStore = (AttributeValueStore) getBean( "org.hisp.dhis.attribute.AttributeValueStore" );
+
+ Attribute attribute1 = new Attribute();
+ attribute1.setName( "attribute_simple" );
+ attribute1.setValueType( "string" );
+
+ attributeValue1 = new AttributeValue("value 1");
+ attributeValue1.setAttribute( attribute1 );
+
+ attributeValue2 = new AttributeValue("value 2");
+ attributeValue2.setAttribute( attribute1 );
+
+ attributeValueStore.save( attributeValue1 );
+ attributeValueStore.save( attributeValue2 );
+ }
+
+ @Test
+ public void testGetAttribute()
+ {
+ AttributeValue av = attributeValueStore.get( attributeValue1.getId() );
+
+ assertNotNull( av );
+ assertNotNull( av.getAttribute() );
+ }
+
+ @Test
+ public void testGetValue()
+ {
+ AttributeValue av = attributeValueStore.get( attributeValue1.getId() );
+
+ assertNotNull( av );
+ assertEquals( "value 1", av.getValue() );
+ }
+}
=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml 2011-08-17 10:57:08 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml 2011-09-06 11:52:18 +0000
@@ -92,6 +92,12 @@
<cache name="org.hisp.dhis.version.Version" maxElementsInMemory="100" />
+ <cache name="org.hisp.dhis.attribute.Attribute" maxElementsInMemory="100" />
+
+ <cache name="org.hisp.dhis.attribute.AttributeOption" maxElementsInMemory="100" />
+
+ <cache name="org.hisp.dhis.attribute.AttributeValue" maxElementsInMemory="100" />
+
<!-- Hibernate Associations -->
<cache name="org.hisp.dhis.dataelement.DataElementCategoryCombo.categories" maxElementsInMemory="300" />
@@ -101,7 +107,7 @@
<cache name="org.hisp.dhis.dataelement.DataElementCategory.categoryOptions" maxElementsInMemory="300" />
<cache name="org.hisp.dhis.dataelement.DataElementCategoryOption.categoryOptionCombos" maxElementsInMemory="500" />
-
+
<cache name="org.hisp.dhis.dataelement.DataElementCategoryOptionCombo.categoryOptions" maxElementsInMemory="500" />
<cache name="org.hisp.dhis.dataset.DataSet.dataElements" maxElementsInMemory="3000" />
@@ -114,6 +120,8 @@
<cache name="org.hisp.dhis.dataelement.DataElement.dataSets" maxElementsInMemory="3000" />
+ <cache name="org.hisp.dhis.dataelement.DataElement.attributeValues" maxElementsInMemory="100" />
+
<cache name="org.hisp.dhis.dataelement.DataElementGroup.members" maxElementsInMemory="3000" />
<cache name="org.hisp.dhis.dataelement.DataElementGroupSet.members" maxElementsInMemory="400" />
@@ -122,6 +130,8 @@
<cache name="org.hisp.dhis.indicator.Indicator.dataSets" maxElementsInMemory="400" />
+ <cache name="org.hisp.dhis.indicator.Indicator.attributeValues" maxElementsInMemory="100" />
+
<cache name="org.hisp.dhis.indicator.IndicatorGroup.members" maxElementsInMemory="400" />
<cache name="org.hisp.dhis.indicator.IndicatorGroupSet.members" maxElementsInMemory="400" />
@@ -140,6 +150,8 @@
<cache name="org.hisp.dhis.organisationunit.OrganisationUnit.users" maxElementsInMemory="400" />
+ <cache name="org.hisp.dhis.organisationunit.OrganisationUnit.attributeValues" maxElementsInMemory="100" />
+
<cache name="org.hisp.dhis.organisationunit.OrganisationUnitGroup.members" maxElementsInMemory="10000" />
<cache name="org.hisp.dhis.organisationunit.OrganisationUnitGroupSet.organisationUnitGroups"
@@ -177,6 +189,12 @@
<cache name="org.hisp.dhis.user.User.organisationUnits" maxElementsInMemory="20000" />
+ <cache name="org.hisp.dhis.attribute.Attribute.attributeOptions" maxElementsInMemory="100" />
+
+ <cache name="org.hisp.dhis.attribute.Attribute.attributeValues" maxElementsInMemory="100" />
+
+ <cache name="org.hisp.dhis.attribute.AttributeOption.attributes" maxElementsInMemory="100" />
+
<!-- Hibernate Query Cache -->
<cache name="org.hibernate.cache.StandardQueryCache" maxElementsInMemory="200000" />