dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29839
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15147: Add method DateUnit.toJdkCalendar, convert from system calendar to iso calendar in update/save or...
------------------------------------------------------------
revno: 15147
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-05-05 15:08:38 +0700
message:
Add method DateUnit.toJdkCalendar, convert from system calendar to iso calendar in update/save orgUnit (openingDate, closingDate), wip
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnit.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java
--
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-api/src/main/java/org/hisp/dhis/calendar/DateUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnit.java 2014-04-29 05:05:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnit.java 2014-05-05 08:08:38 +0000
@@ -33,6 +33,7 @@
import org.joda.time.chrono.ISOChronology;
import javax.validation.constraints.NotNull;
+import java.util.GregorianCalendar;
/**
* Class representing a specific calendar date.
@@ -132,6 +133,11 @@
return new DateTime( year, month, day, 0, 0, chronology );
}
+ public java.util.Calendar toJdkCalendar()
+ {
+ return new GregorianCalendar( year, month - 1, day );
+ }
+
public static DateUnit fromDateTime( DateTime dateTime )
{
return new DateUnit( dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getDayOfWeek() );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java 2014-04-28 18:13:09 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/AddOrganisationUnitAction.java 2014-05-05 08:08:38 +0000
@@ -30,6 +30,8 @@
import com.opensymphony.xwork2.Action;
import org.hisp.dhis.attribute.AttributeService;
+import org.hisp.dhis.calendar.CalendarService;
+import org.hisp.dhis.calendar.DateUnit;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.i18n.I18nFormat;
@@ -43,7 +45,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Collection;
-import java.util.Date;
import java.util.HashSet;
import java.util.List;
@@ -109,6 +110,9 @@
this.manager = manager;
}
+ @Autowired
+ private CalendarService calendarService;
+
// -------------------------------------------------------------------------
// Input & Output
// -------------------------------------------------------------------------
@@ -258,8 +262,6 @@
email = nullIfEmpty( email );
phoneNumber = nullIfEmpty( phoneNumber );
- Date date = format.parseDate( openingDate );
-
// ---------------------------------------------------------------------
// Get parent
// ---------------------------------------------------------------------
@@ -279,7 +281,9 @@
// Create organisation unit
// ---------------------------------------------------------------------
- OrganisationUnit organisationUnit = new OrganisationUnit( name, shortName, code, date, null, active, comment );
+ DateUnit isoOpeningDate = calendarService.getSystemCalendar().toIso( openingDate );
+
+ OrganisationUnit organisationUnit = new OrganisationUnit( name, shortName, code, isoOpeningDate.toJdkCalendar().getTime(), null, active, comment );
organisationUnit.setDescription( description );
organisationUnit.setUrl( url );
@@ -340,7 +344,7 @@
}
organisationUnitService.updateOrganisationUnit( organisationUnit );
-
+
organisationUnitService.updateOrganisationUnitVersion();
return SUCCESS;
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java 2014-04-28 18:13:09 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateOrganisationUnitAction.java 2014-05-05 08:08:38 +0000
@@ -30,6 +30,8 @@
import com.opensymphony.xwork2.Action;
import org.hisp.dhis.attribute.AttributeService;
+import org.hisp.dhis.calendar.CalendarService;
+import org.hisp.dhis.calendar.DateUnit;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
@@ -106,6 +108,9 @@
this.manager = manager;
}
+ @Autowired
+ private CalendarService calendarService;
+
// -------------------------------------------------------------------------
// Input & Output
// -------------------------------------------------------------------------
@@ -274,13 +279,15 @@
email = nullIfEmpty( email );
phoneNumber = nullIfEmpty( phoneNumber );
- Date oDate = format.parseDate( openingDate );
+ DateUnit isoOpeningDate = calendarService.getSystemCalendar().toIso( openingDate );
+ Date oDate = isoOpeningDate.toJdkCalendar().getTime();
Date cDate = null;
if ( closedDate != null && closedDate.trim().length() != 0 )
{
- cDate = format.parseDate( closedDate );
+ DateUnit isoClosingDate = calendarService.getSystemCalendar().toIso( closedDate );
+ cDate = isoClosingDate.toJdkCalendar().getTime();
}
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id );
@@ -370,7 +377,7 @@
manager.updateNoAcl( newGroup );
}
}
-
+
organisationUnitService.updateOrganisationUnitVersion();
return SUCCESS;