← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6961: Added EquipmentDataValue object

 

------------------------------------------------------------
revno: 6961
committer: Bharath <chbharathk@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-05-16 16:54:58 +0530
message:
  Added EquipmentDataValue object
added:
  local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/inventory/EquipmentDataValue.java
  local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/inventory/EquipmentDataValueService.java
  local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/inventory/EquipmentDataValueStore.java
  local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/inventory/DefaultEquipmentDataValueService.java
  local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/inventory/hibernate/HibernateEquipmentDataValueStore.java
  local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/org/hisp/dhis/coldchain/hibernate/EquipmentDataValue.hbm.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 file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/inventory/EquipmentDataValue.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/inventory/EquipmentDataValue.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/inventory/EquipmentDataValue.java	2012-05-16 11:24:58 +0000
@@ -0,0 +1,142 @@
+package org.hisp.dhis.coldchain.inventory;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.period.Period;
+
+public class EquipmentDataValue  implements Serializable
+{
+    private EquipmentInstance equipmentInstance;
+
+    private DataElement dataElement;
+    
+    private Period period;
+    
+    private String value;
+
+    private String storedBy;
+
+    private Date timestamp;
+
+    // -------------------------------------------------------------------------
+    // Constructors
+    // -------------------------------------------------------------------------
+
+    public EquipmentDataValue()
+    {
+    }
+
+    public EquipmentDataValue( EquipmentInstance equipmentInstance, DataElement dataElement, Period period )
+    {
+        this.dataElement = dataElement;
+        this.period = period;
+        this.equipmentInstance = equipmentInstance;
+    }
+
+    // -------------------------------------------------------------------------
+    // hashCode and equals
+    // -------------------------------------------------------------------------
+
+    @Override
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+
+        if ( o == null )
+        {
+            return false;
+        }
+
+        if ( !(o instanceof EquipmentDataValue) )
+        {
+            return false;
+        }
+
+        final EquipmentDataValue other = (EquipmentDataValue) o;
+
+        return dataElement.equals( other.getDataElement() ) && period.equals( other.getPeriod() ) && equipmentInstance.equals( other.getEquipmentInstance() );
+    }
+
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+
+        result = result * prime + period.hashCode();
+        result = result * prime + dataElement.hashCode();
+        result = result * prime + equipmentInstance.hashCode();
+
+        return result;
+    }
+
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
+    public EquipmentInstance getEquipmentInstance()
+    {
+        return equipmentInstance;
+    }
+
+    public void setEquipmentInstance( EquipmentInstance equipmentInstance )
+    {
+        this.equipmentInstance = equipmentInstance;
+    }
+
+    public DataElement getDataElement()
+    {
+        return dataElement;
+    }
+
+    public void setDataElement( DataElement dataElement )
+    {
+        this.dataElement = dataElement;
+    }
+
+    public Period getPeriod()
+    {
+        return period;
+    }
+
+    public void setPeriod( Period period )
+    {
+        this.period = period;
+    }
+
+    public String getValue()
+    {
+        return value;
+    }
+
+    public void setValue( String value )
+    {
+        this.value = value;
+    }
+
+    public String getStoredBy()
+    {
+        return storedBy;
+    }
+
+    public void setStoredBy( String storedBy )
+    {
+        this.storedBy = storedBy;
+    }
+
+    public Date getTimestamp()
+    {
+        return timestamp;
+    }
+
+    public void setTimestamp( Date timestamp )
+    {
+        this.timestamp = timestamp;
+    }
+
+}

=== added file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/inventory/EquipmentDataValueService.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/inventory/EquipmentDataValueService.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/inventory/EquipmentDataValueService.java	2012-05-16 11:24:58 +0000
@@ -0,0 +1,24 @@
+package org.hisp.dhis.coldchain.inventory;
+
+import java.util.Collection;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.period.Period;
+
+public interface EquipmentDataValueService
+{
+    String ID = EquipmentDataValueService.class.getName();
+    
+    // -------------------------------------------------------------------------
+    // EquipmentDataValue
+    // -------------------------------------------------------------------------
+
+    void addEquipmentDataValue( EquipmentDataValue equipmentDataValue );
+    
+    void updateEquipmentDataValue( EquipmentDataValue equipmentDataValue );
+    
+    void deleteEquipmentDataValue( EquipmentDataValue equipmentDataValue );
+    
+    Collection<EquipmentDataValue> getEquipmentDataValues( EquipmentInstance equipmentInstance, Period period, Collection<DataElement> dataElements );
+
+}

=== added file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/inventory/EquipmentDataValueStore.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/inventory/EquipmentDataValueStore.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/coldchain/inventory/EquipmentDataValueStore.java	2012-05-16 11:24:58 +0000
@@ -0,0 +1,24 @@
+package org.hisp.dhis.coldchain.inventory;
+
+import java.util.Collection;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.period.Period;
+
+public interface EquipmentDataValueStore
+{
+    String ID = EquipmentDataValueStore.class.getName();
+    
+    // -------------------------------------------------------------------------
+    // EquipmentDataValue
+    // -------------------------------------------------------------------------
+
+    void addEquipmentDataValue( EquipmentDataValue equipmentDataValue );
+    
+    void updateEquipmentDataValue( EquipmentDataValue equipmentDataValue );
+    
+    void deleteEquipmentDataValue( EquipmentDataValue equipmentDataValue );
+    
+    Collection<EquipmentDataValue> getEquipmentDataValues( EquipmentInstance equipmentInstance, Period period, Collection<DataElement> dataElements );
+    
+}

=== added file 'local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/inventory/DefaultEquipmentDataValueService.java'
--- local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/inventory/DefaultEquipmentDataValueService.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/inventory/DefaultEquipmentDataValueService.java	2012-05-16 11:24:58 +0000
@@ -0,0 +1,50 @@
+package org.hisp.dhis.coldchain.inventory;
+
+import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.period.Period;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class DefaultEquipmentDataValueService implements EquipmentDataValueService
+{
+    private static final Log log = LogFactory.getLog( DefaultEquipmentDataValueService.class );
+    
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private EquipmentDataValueStore equipmentDataValueStore;
+
+    public void setEquipmentDataValueStore( EquipmentDataValueStore equipmentDataValueStore )
+    {
+        this.equipmentDataValueStore = equipmentDataValueStore;
+    }
+    
+    // -------------------------------------------------------------------------
+    // EquipmentDataValue
+    // -------------------------------------------------------------------------
+
+    public void addEquipmentDataValue( EquipmentDataValue equipmentDataValue )
+    {
+        equipmentDataValueStore.addEquipmentDataValue( equipmentDataValue );
+    }
+    
+    public void updateEquipmentDataValue( EquipmentDataValue equipmentDataValue )
+    {
+        equipmentDataValueStore.updateEquipmentDataValue( equipmentDataValue );
+    }
+    
+    public void deleteEquipmentDataValue( EquipmentDataValue equipmentDataValue )
+    {
+        equipmentDataValueStore.deleteEquipmentDataValue( equipmentDataValue );
+    }
+    
+    public Collection<EquipmentDataValue> getEquipmentDataValues( EquipmentInstance equipmentInstance, Period period, Collection<DataElement> dataElements )
+    {
+        return equipmentDataValueStore.getEquipmentDataValues( equipmentInstance, period, dataElements );
+    }
+}

=== added file 'local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/inventory/hibernate/HibernateEquipmentDataValueStore.java'
--- local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/inventory/hibernate/HibernateEquipmentDataValueStore.java	1970-01-01 00:00:00 +0000
+++ local/in/dhis-in-services/dhis-in-service-coldchain/src/main/java/org/hisp/dhis/coldchain/inventory/hibernate/HibernateEquipmentDataValueStore.java	2012-05-16 11:24:58 +0000
@@ -0,0 +1,87 @@
+package org.hisp.dhis.coldchain.inventory.hibernate;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.amplecode.quick.StatementManager;
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.coldchain.inventory.EquipmentDataValue;
+import org.hisp.dhis.coldchain.inventory.EquipmentDataValueStore;
+import org.hisp.dhis.coldchain.inventory.EquipmentInstance;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodStore;
+
+public class HibernateEquipmentDataValueStore implements EquipmentDataValueStore
+{
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private SessionFactory sessionFactory;
+
+    public void setSessionFactory( SessionFactory sessionFactory )
+    {
+        this.sessionFactory = sessionFactory;
+    }
+
+    private PeriodStore periodStore;
+
+    public void setPeriodStore( PeriodStore periodStore )
+    {
+        this.periodStore = periodStore;
+    }
+
+    // -------------------------------------------------------------------------
+    // EquipmentDataValue
+    // -------------------------------------------------------------------------
+
+    public void addEquipmentDataValue( EquipmentDataValue equipmentDataValue )
+    {
+        equipmentDataValue.setPeriod( periodStore.reloadForceAddPeriod( equipmentDataValue.getPeriod() ) );
+
+        Session session = sessionFactory.getCurrentSession();
+
+        session.save( equipmentDataValue );
+    }
+
+    public void updateEquipmentDataValue( EquipmentDataValue equipmentDataValue )
+    {
+        equipmentDataValue.setPeriod( periodStore.reloadForceAddPeriod( equipmentDataValue.getPeriod() ) );
+
+        Session session = sessionFactory.getCurrentSession();
+
+        session.update( equipmentDataValue );
+    }
+
+    public void deleteEquipmentDataValue( EquipmentDataValue equipmentDataValue )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.delete( equipmentDataValue );
+    }
+
+    public Collection<EquipmentDataValue> getEquipmentDataValues( EquipmentInstance equipmentInstance, Period period, Collection<DataElement> dataElements )
+    {
+        Period storedPeriod = periodStore.reloadPeriod( period );
+
+        if ( storedPeriod == null || dataElements == null || dataElements.isEmpty() )
+        {
+            return Collections.emptySet();
+        }
+
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( DataValue.class );
+        criteria.add( Restrictions.eq( "equipmentInstance", equipmentInstance ) );
+        criteria.add( Restrictions.eq( "period", storedPeriod ) );
+        criteria.add( Restrictions.in( "dataElement", dataElements ) );
+
+        return criteria.list();
+    }
+}

=== added file 'local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/org/hisp/dhis/coldchain/hibernate/EquipmentDataValue.hbm.xml'
--- local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/org/hisp/dhis/coldchain/hibernate/EquipmentDataValue.hbm.xml	1970-01-01 00:00:00 +0000
+++ local/in/dhis-in-services/dhis-in-service-coldchain/src/main/resources/org/hisp/dhis/coldchain/hibernate/EquipmentDataValue.hbm.xml	2012-05-16 11:24:58 +0000
@@ -0,0 +1,22 @@
+<?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>
+  <class name="org.hisp.dhis.coldchain.inventory.EquipmentDataValue" table="equipmentdatavalue">
+
+    <composite-id>
+	  <key-many-to-one name="equipmentInstance" class="org.hisp.dhis.coldchain.inventory.EquipmentInstance" column="equipmentinstanceid" foreign-key="fk_equipmentdatavalue_equipmentinstanceid" />
+      <key-many-to-one name="dataElement" class="org.hisp.dhis.dataelement.DataElement" column="dataelementid" foreign-key="fk_equipmentdatavalue_dataelementid" />
+      <key-many-to-one name="period" class="org.hisp.dhis.period.Period" column="periodid" foreign-key="fk_equipmentdatavalue_periodid" />      
+    </composite-id>
+
+    <property name="value" />
+
+    <property name="storedBy" column="storedby" length="31" />
+
+    <property name="timestamp" column="lastupdated" type="date" />
+
+  </class>
+</hibernate-mapping>