← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 932: Import data from Excel File - Work in process

 

------------------------------------------------------------
revno: 932
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2009-10-30 17:01:26 +0700
message:
  Import data from Excel File - Work in process
modified:
  dhis-2/dhis-services/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/excelitem/hibernate/HibernateExcelItemStore.java
  dhis-2/dhis-services/dhis-service-excel-reporting/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/excelitem/hibernate/ExcelItemGroup.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.
=== modified file 'dhis-2/dhis-services/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/excelitem/hibernate/HibernateExcelItemStore.java'
--- dhis-2/dhis-services/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/excelitem/hibernate/HibernateExcelItemStore.java	2009-10-29 05:21:01 +0000
+++ dhis-2/dhis-services/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/excelitem/hibernate/HibernateExcelItemStore.java	2009-10-30 10:01:26 +0000
@@ -7,6 +7,8 @@
 import org.hibernate.SessionFactory;
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.PeriodStore;
+import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.reportexcel.DataElementGroupOrder;
 import org.hisp.dhis.reportexcel.excelitem.ExcelItem;
 import org.hisp.dhis.reportexcel.excelitem.ExcelItemGroup;
@@ -56,6 +58,13 @@
 		this.sessionFactory = sessionFactory;
 	}
 
+	private PeriodStore periodStore;
+
+    public void setPeriodStore( PeriodStore periodStore )
+    {
+        this.periodStore = periodStore;
+    }
+
 	// ----------------------------------------------------------------------
 	// ExcelItemStore implementation
 	// ----------------------------------------------------------------------
@@ -102,7 +111,13 @@
 
 	public void addExcelItemGroup(ExcelItemGroup excelItemGroup) {
 
-		sessionFactory.getCurrentSession().save(excelItemGroup);
+		PeriodType periodType = periodStore.getPeriodType( excelItemGroup.getPeriodType().getClass() );
+
+		excelItemGroup.setPeriodType( periodType );
+
+        Session session = sessionFactory.getCurrentSession();
+
+        session.save( excelItemGroup );
 	}
 
 	public void deleteExcelItemGroup(int id) {
@@ -135,10 +150,13 @@
 
 	public void updateExcelItemGroup(ExcelItemGroup excelItemGroup) {
 
-		Session session = sessionFactory.getCurrentSession();
-
-		session.saveOrUpdate(excelItemGroup);
-
+		PeriodType periodType = periodStore.getPeriodType( excelItemGroup.getPeriodType().getClass() );
+
+		excelItemGroup.setPeriodType( periodType );
+
+        Session session = sessionFactory.getCurrentSession();
+
+        session.update( excelItemGroup );
 	}
 
 	@SuppressWarnings("unchecked")
@@ -157,9 +175,14 @@
 	}
 
 	public DataElementGroupOrder getDataElementGroupOrder(Integer id) {
+		
 		Session session = sessionFactory.getCurrentSession();
-		return (DataElementGroupOrder) session.get(DataElementGroupOrder.class,
-				id);
+		
+		Criteria criteria = session.createCriteria(DataElementGroupOrder.class);
+
+		criteria.add(Restrictions.eq("id", id.intValue()));
+
+		return (DataElementGroupOrder) criteria.uniqueResult();
 	}
 
 	public void updateDataElementGroupOrder(
@@ -169,7 +192,9 @@
 	}
 
 	public void deleteDataElementGroupOrder(Integer id) {
+		
 		Session session = sessionFactory.getCurrentSession();
-		session.delete(this.getDataElementGroupOrder(id));
+		
+		session.delete(getDataElementGroupOrder(id));
 	}
 }

=== modified file 'dhis-2/dhis-services/dhis-service-excel-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-excel-reporting/src/main/resources/META-INF/dhis/beans.xml	2009-10-27 06:05:22 +0000
+++ dhis-2/dhis-services/dhis-service-excel-reporting/src/main/resources/META-INF/dhis/beans.xml	2009-10-30 10:01:26 +0000
@@ -17,7 +17,6 @@
 	</bean>
 
 
-
 	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
 	<!-- EXCELITEM STORE                                               -->
 	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
@@ -25,6 +24,7 @@
 	<bean id="org.hisp.dhis.reportexcel.excelitem.ExcelItemStore"
 		class="org.hisp.dhis.reportexcel.excelitem.hibernate.HibernateExcelItemStore">
 		<property name="sessionFactory" ref="sessionFactory" />
+		<property name="periodStore" ref="org.hisp.dhis.period.PeriodStore" />
 	</bean>
 
 	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

=== modified file 'dhis-2/dhis-services/dhis-service-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/excelitem/hibernate/ExcelItemGroup.hbm.xml'
--- dhis-2/dhis-services/dhis-service-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/excelitem/hibernate/ExcelItemGroup.hbm.xml	2009-10-29 05:21:01 +0000
+++ dhis-2/dhis-services/dhis-service-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/excelitem/hibernate/ExcelItemGroup.hbm.xml	2009-10-30 10:01:26 +0000
@@ -16,6 +16,9 @@
 
 		<property name="excelTemplateFile" column="exceltemplate" />
 
+		<many-to-one name="periodType" class="org.hisp.dhis.period.PeriodType"
+			lazy="false" column="periodtypeid" not-null="true" foreign-key="fk_excelitemgroup_periodtypeid" />
+
 		<set name="excelItems" lazy="false" cascade="delete">
 			<key column="excelitemgroupid" />
 			<one-to-many class="org.hisp.dhis.reportexcel.excelitem.ExcelItem" />