Merge lp:dhis2 into lp:~tw-msf/dhis2/dhis2

Proposed by Mahendra Kariya
Status: Merged
Merged at revision: 14679
Proposed branch: lp:dhis2
Merge into: lp:~tw-msf/dhis2/dhis2
Diff against target: 118964 lines (has conflicts)
Text conflict in dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
Conflict: can't delete dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api because it is not empty.  Not deleting.
Conflict because dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api is not versioned, but has versioned children.  Versioned directory.
Conflict: can't delete dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller because it is not empty.  Not deleting.
Conflict because dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller is not versioned, but has versioned children.  Versioned directory.
Contents conflict in dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/CompleteDataSetRegistrationController.java
Contents conflict in dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SystemSettingController.java
Contents conflict in dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/UserSettingController.java
To merge this branch: bzr merge lp:dhis2
Reviewer Review Type Date Requested Status
Lars Helge Øverland Pending
Review via email: mp+219164@code.launchpad.net

Description of the change

- Changed Translation to have uid of the translated object rather than the database id.
- Added an API for Translations. (Get all / Post )
- Making pwd validation optional for update user api
- Adding get user preference web api

To post a comment you must log in.
lp:dhis2 updated
15226. By Morten Olav Hansen

use PERIOD_TYPE_MAP instead of creating new instances in PeriodType.getPeriodTypeFromIsoString

15227. By Lars Helge Øverland

Event capture, small margin between table and paging

15228. By Abyot Asalefew Gizaw <email address hidden>

UI for search by program

15229. By Lars Helge Øverland

Made dependency explicit

15230. By Lars Helge Øverland

Removed really weird dependency

15231. By Abyot Asalefew Gizaw <email address hidden>

minor

15232. By Thu Tran

Support aggregate query builder formulas for the number days between visit-date of event and a date-attribute value.

15233. By Lars Helge Øverland

Made explict dependency on javassist. Version must be kept in sync with the one used by hibernate.

15234. By Abyot Asalefew Gizaw <email address hidden>

UI for tracked entity instance registration

15235. By Lars Helge Øverland

Codestyle

15236. By Abyot Asalefew Gizaw <email address hidden>

minor

15237. By Lars Helge Øverland

Encapsulated super user logic

15238. By Morten Olav Hansen

added simple tests for DateUnit, inject CalendarService into PeriodTypes (but not in use yet)

15239. By Morten Olav Hansen

minor bugfixes, and more tests for DateUnit

15240. By Morten Olav Hansen

minor fix

15241. By Lars Helge Øverland

Event capture. Fixed issue with pager sometimes being undefined. Made service more robust by checking whether pager is defined and falling back to default values.

15242. By Lars Helge Øverland

CSS fix

15243. By Lars Helge Øverland

Not null constraint on category option group short name

15244. By Jan Henrik Øverland

ER, count type, with options: events | unique TE instances.

15245. By Jan Henrik Øverland

ER, NaN bug fixed.

15246. By Morten Olav Hansen

remove programInstances from Program json/xml export, this should be considered data, and not exported as meta-data

15247. By Lars Helge Øverland

COG, test fix

15248. By Lars Helge Øverland

Added class to base identifiable tostring

15249. By Morten Olav Hansen

removed restriction on filters, allow for filtering of non-idobjects with exported properties

15250. By Lars Helge Øverland

IdentifiableObjectStore, added property which can be overridden by impls for whether backing object has persisted id properties - some impls do not. Makes it possible to search for an object solely based on uid.

15251. By Abyot Asalefew Gizaw <email address hidden>

UI for relationship

15252. By Lars Helge Øverland

CSS font weight bold fix

15253. By Lars Helge Øverland

CSS fix

15254. By Thu Tran

Use HibernateGenericStore in HibernateProgramStageDataElementStore.

15255. By Morten Olav Hansen

moved calendar settings from general to its own section

15256. By Morten Olav Hansen

in apps-servlet, just do a 404 if file is not found, current 'html5 compatible' solution didn't really work

15257. By Lars Helge Øverland

Reverted r 15254

15258. By Morten Olav Hansen

Added PeriodType.getCalendar, will return system calendar if calendarService is available, if not, default to iso 8601 impl. Added new method to Calendar, toIntervals, allows for generating multiple intervals.

15259. By Lars Helge Øverland

Removed unused method

15260. By Lars Helge Øverland

CSV import, added support for option sets

15261. By Jan Henrik Øverland

PT DV GIS, i18n.

15262. By Morten Olav Hansen

minor javadoc fix

15263. By Lars Helge Øverland

Dashboard tables cleanup

15264. By Lars Helge Øverland

Minor

15265. By Abyot Asalefew Gizaw <email address hidden>

upgrade of select2 and tracked entity search - WIP

15266. By Abyot Asalefew Gizaw <email address hidden>

tracked entity list refactored

15267. By Lars Helge Øverland

Tracker, fixed bug, display in list no program was assuming column value to be false

15268. By Lars Helge Øverland

Attribute no program, minor fix

15269. By Lars Helge Øverland

Attribute no program, minor fix

15270. By Thu Tran

Rewrite methods in tracker to use criteria instead of hql.

15271. By Thu Tran

Fix bug - Exception thrown when downloading program-history report in TEI dashboard

15272. By Thu Tran

Remove the orgunit-groups in Program object.

15273. By Abyot Asalefew Gizaw <email address hidden>

searching tracked entity - wip

15274. By Ngo Thanh Long

[mobile] clean up, remove unused classes

15275. By Bharath

RBF: Minor fixes on MaxScore

15276. By Abyot Asalefew Gizaw <email address hidden>

searching tracked entity - wip

15277. By Jim Grace

User administration restrictions

15278. By Lars Helge Øverland

Merge from ThoughtWorks/MSF team branch. Makes Translation.java an IdentifiableObject. Exposes translations in Web API.

15279. By Lars Helge Øverland

Minor

15280. By Abyot Asalefew Gizaw <email address hidden>

searching tei - wip

15281. By Lars Helge Øverland

Applied patch from TW. Implements post of system settings map.

15282. By Thu Tran

Fixed bug - Error when saving aggregate data values from Manual Aggregate.

15283. By Thu Tran

Exception thrown when clicking on the details icon of Aggregate query result.

15284. By Le Hong Em

[mobile] update send message server side for mobile J2ME agg

15285. By Thu Tran

Rename in HibernateTrackedEntityFormStore from getCommonForm to getFormsWithoutProgram.

15286. By Thu Tran

Move all classes from package org.hisp.dhis.trackedentity.scheduling to project dhis-service-eventreporting.

15287. By Lars Helge Øverland

Fixed various compilatione errors

15288. By Abyot Asalefew Gizaw <email address hidden>

tei grid, show/hide columns and additional column for orgunit

15289. By Lars Helge Øverland

Tracker, cleanup

15290. By Lars Helge Øverland

Codestyle fix

15291. By Lars Helge Øverland

Removed unused method

15292. By Abyot Asalefew Gizaw <email address hidden>

synchronized TEI search and registration UI

15293. By Thu Tran

Remove unused methods in tracker module.

15294. By Thu Tran

Remove unused methods in eventreporting module.

15295. By Thu Tran

Minor fix.

15296. By Thu Tran

Migrate the value from combo to optionSet in database, java and UI.

15297. By Jim Grace

Support attribute categories in validation

15298. By Paul Mark Castillo

Implemented Interpretations for Mobile Lite
https://blueprints.launchpad.net/dhis-mobile/+spec/mla-interpretations

15299. By Abyot Asalefew Gizaw <email address hidden>

tei registration and enrollment

15300. By Lars Helge Øverland

Web light module, cleaned up code style

15301. By Lars Helge Øverland

User role schema descriptor fix

15302. By Jim Grace

Remove unused UserCredentialsCanUpdateFilter.java

15303. By Abyot Asalefew Gizaw <email address hidden>

communication between tei dashboard controller

15304. By Thu Tran

Add statement to update aggregate query builder formulas from 2.13 to 2.15

15305. By Lars Helge Øverland

Deletion of category combination, including check for attributeoptioncombo in datavalues

15306. By Lars Helge Øverland

Category deletion, allowing deletion of categories which are linked to option combos. No good reason to deny that.

15307. By Lars Helge Øverland

Added new web api method at api/dimensions/constraints for potential dimensional constraints

15308. By Lars Helge Øverland

Excluded xerces

15309. By Abyot Asalefew Gizaw <email address hidden>

tei registration and enrollment - wip

15310. By Abyot Asalefew Gizaw <email address hidden>

minor

15311. By Abyot Asalefew Gizaw <email address hidden>

a little timeout to ensure broadcasts are not missed between controllers

15312. By Lars Helge Øverland

Email settings, made the email from address configurable

15313. By Lars Helge Øverland

Override annotations

15314. By Lars Helge Øverland

Mobile, correct interface modifiers

15315. By Lars Helge Øverland

Mobile, correct interface modifiers

15316. By Lars Helge Øverland

Unused method

15317. By Abyot Asalefew Gizaw <email address hidden>

more interaction in tei dashboard widgets such as editing, enrolling, event creation... - WIP

15318. By Lars Helge Øverland

SmsMessageSender, simplified logic

15319. By Lars Helge Øverland

Unused code

15320. By Lars Helge Øverland

Tracker, removed unused methods

15321. By Lars Helge Øverland

Tracker, removed unused code

15322. By Lars Helge Øverland

TrackedEntityInstance, moved method from store to service layer

15323. By Lars Helge Øverland

Typo

15324. By Lars Helge Øverland

Unused imports

15325. By Ngo Thanh Long

[mobile] migrate to TEI new method in line 286, update enrollProgram() to support for register and import Data Value on-the-fly

15326. By Lars Helge Øverland

Tracker, removed method from TrackedEntityStore/Service

15327. By Lars Helge Øverland

Tracker, removed method from TrackedEntityStore/Service for checking representative. We should reconsider the representative implementation or re-implemet in main TEI query.

15328. By Lars Helge Øverland

Minor

15329. By Ngo Thanh Long

remove class scope patient property in ActivityReportingServiceImpl

15330. By sherylyn.marie

https://blueprints.launchpad.net/dhis-mobile/+spec/enhance-tracker-client
#3 VISIT SCHEDULE

15331. By Ngo Thanh Long

remove TrackedEntityMobileSetting and all related services, actions

15332. By Abyot Asalefew Gizaw <email address hidden>

minor

15333. By jason.p.pickering

(Translations) Intermim commit of French

15334. By jason.p.pickering

(Translations) Interim sync of Arabic translations.

15335. By Le Hong Em

[mobile] update message conversations for J2ME Agg

15336. By Abyot Asalefew Gizaw <email address hidden>

stylesheet - spacing between buttons

15337. By Abyot Asalefew Gizaw <email address hidden>

removed searching and filtering from entity grid - these features can now be directly applied during searching

15338. By Abyot Asalefew Gizaw <email address hidden>

list all etinties by default if orgunit is selected

15339. By Abyot Asalefew Gizaw <email address hidden>

cleanup

15340. By Abyot Asalefew Gizaw <email address hidden>

by default display only those attributes marked displayInListNoProgram

15341. By Lars Helge Øverland

Merge branch localized-calendar from Morten. Implements new and more sophisticated calendar solution.

15342. By Thu Tran

Fixed bug - Don't display option-set attribute as combobox in default TEI registration form.

15343. By Thu Tran

Minor fix.

15344. By Thu Tran

Fixed bug - Error when displaying values of TYes-Only attributes in registration form.

15345. By jason.p.pickering

Adding another script for cleaning of translation files.

15346. By jason.p.pickering

Minor fix to translation cleaning script.

15347. By jason.p.pickering

(Translations) French translation cleanup.

15348. By Thu Tran

Fixed bug - Hide orgunit-uid column of TEI list in Tracked entity instance management

15349. By Le Hong Em

[mobile] reply message

15350. By Thu Tran

Fixed bug - Error when to enroll a TEI into a program in TEI Dashboard.

15351. By Ngo Thanh Long

clean up & bug fix for offline tracked entity data entry

15352. By Lars Helge Øverland

CSS fix

15353. By jason.p.pickering

(Translations) Cleaned up Spanish translations.

15354. By Lars Helge Øverland

Event capture, reduced size of headers

15355. By Lars Helge Øverland

Event report, moved show columns on top of register event button to allow for smaller screens

15356. By Lars Helge Øverland

Minor

15357. By Lars Helge Øverland

Autocomplete off in user invite for email and username

15358. By Morten Olav Hansen

made json default rendering for html/text header, removed xslt view rendering

15359. By Morten Olav Hansen

removing xslt files used for rendering html view

15360. By Lars Helge Øverland

Fixed bug with autocomplete in data entry as a result of jquery-ui upgrade

15361. By Morten Olav Hansen

changed main package for dhis-web-api from org.hisp.dhis.api => org.hisp.dhis.webapi, makes it more obvious where classes belong, also makes component scanner be more specific (it does not include files from dhis-api module which had same package)

15362. By Lars Helge Øverland

Autocomplete style

15363. By Morten Olav Hansen

upgrade to spring 3.2.9, and spring security 3.2.4

15364. By Abyot Asalefew Gizaw <email address hidden>

minor ui adjustments in event capture

15365. By Jan Henrik Øverland

PT, column/row totals as separate options.

15366. By Abyot Asalefew Gizaw <email address hidden>

replaced blue tables in tracker capture with grey ones

15367. By Morten Olav Hansen

made explicit dependency on xml-apis 1.4.01

15368. By Thu Tran

Fixed bug - Error when to enroll a TEI into a program in TEI

15369. By Lars Helge Øverland

Cleanup

15370. By Morten Olav Hansen

change to using /api/system/info to get context information in event-reports

15371. By Morten Olav Hansen

remove /api/system/context endpoint (use /system/info instead), add calendar/dateFormat info to SystemInfo (exposed in /api/system/info)

15372. By Morten Olav Hansen

remove unused constants in ProgramStage

15373. By Morten Olav Hansen

expose trackedEntityInstanceReminders on ProgramStage

15374. By Morten Olav Hansen

expose dataElement on progrmaStageDataElement as idObject

15375. By Jan Henrik Øverland

PT DV GIS plugins updated (commons) + EV, gui fixes, work in progress.

15376. By Morten Olav Hansen

minor undefined check in form.js

15377. By Jan Henrik Øverland

ER, period bug fixed.

15378. By Jan Henrik Øverland

DV, axis min/max instead of max/min.

15379. By Bharath

RBF work in progress: QualityBasedPayment

15380. By Morten Olav Hansen

various fixes to tracker classes

15381. By Lars Helge Øverland

Removed TabularEventColumn

15382. By Morten Olav Hansen

remove unused constants in ProgramValidation

15383. By Morten Olav Hansen

javadoc updates to tracker classes

15384. By Morten Olav Hansen

minor import opts + code format

15385. By Morten Olav Hansen

minor fix, unnecessary unboxing

15386. By Morten Olav Hansen

minor fixes to calendar classes

15387. By Morten Olav Hansen

minor javadoc fixes in period package

15388. By Lars Helge Øverland

Unused import

15389. By Lars Helge Øverland

Mapped hibernate identifiable properties for ValidationCriteria

15390. By Lars Helge Øverland

Minor

15391. By Lars Helge Øverland

TrackedEntityInstanceController, changed from patient to tei for authorities

15392. By Mark Polak

Fixes menu in event-capture additionally adds menu scroll buttons

15393. By Thu Tran

Remove the Single event without registration in DataEntry menu.

15394. By Thu Tran

Hide the Add filter button in Advanced search of Lost to follow up; add the datapicker for due-date search field in Lost to follow up.

15395. By Thu Tran

Apply web-api for search relationship of TEI in Find/Add instance.

15396. By Thu Tran

Minor fix for TEI relationship list.

15397. By Thu Tran

Fixed bug - Repeatable program stage not stored.

15398. By Abyot Asalefew Gizaw <email address hidden>

drop down menus for program selection and advanced search - wip

15399. By Morten Olav Hansen

support resources without paging in progressive selected loader

15400. By Morten Olav Hansen

Minor fix

15401. By Morten Olav Hansen

use HttpServletResponse.sendRedirect instead of relying of RedirectView which we don't use in the view-chain anymore, fixes issues with redirecting from /api and /api/ => /api/resources

15402. By Abyot Asalefew Gizaw <email address hidden>

code style, advanced search drop-down menu stays open onclicks, except for the intended buttons

15403. By Paul Mark Castillo

[NEW] Added sharing interpretations
https://blueprints.launchpad.net/dhis-mobile/+spec/mla-interpretations

15404. By Lars Helge Øverland

Approval, added missing states to approval report UI.

15405. By Lars Helge Øverland

ModuleManager, removed service/maintenance methods

15406. By Morten Olav Hansen

minor fixes to CategoryOptionComboSchemaDescriptor, CategoryOptionCombos are not shareable

15407. By Paul Mark Castillo

[IMPROVED] Cleaned up code for Interpretations for Mobile Lite
https://blueprints.launchpad.net/dhis-mobile/+spec/mla-interpretations

15408. By Thu Tran

Fixed bug - Don't display values of Date attribute in the Enrollment program form.

15409. By Morten Olav Hansen

enabled export of certain tracker objects

15410. By Morten Olav Hansen

hashCode/equals fixes to ProgramStageDataElement and ProgramTrackedEntityAttribute

15411. By Morten Olav Hansen

uncommented removal of tracker classes for import (but not working yet, since importer beans have not been added)

15412. By Morten Olav Hansen

minor importer fixes for tracker

15413. By Morten Olav Hansen

use AbstractCrudController which uses importer for CRUD operations on TrackedEntity objects

15414. By Morten Olav Hansen

fixes to tracker classes, adding merging

15415. By Morten Olav Hansen

minor fixes

15416. By Morten Olav Hansen

Added ValidtionCritera importer and property to MetaData

15417. By Morten Olav Hansen

support for ProgramStageSections in importer

15418. By Morten Olav Hansen

Support ProgramValidation for tracker importer

15419. By Morten Olav Hansen

add programValidtionSchemaDescriptor

15420. By Morten Olav Hansen

in expression extracter in IdObjectImporter, make sure that type is Expression (could clash with ProgramExpression etc)

15421. By Jim Grace

Add to webapi: POST /users/invite

15422. By Morten Olav Hansen

minor fix for sharing dialog, create dialog before autocomplete widget

15423. By Jim Grace

Add category dimension constraints, also validation implements dimension constraints.

15424. By Morten Olav Hansen

minor redirect fix in IndexController

15425. By Morten Olav Hansen

minor fixes to tracker import

15426. By Morten Olav Hansen

minor fix in detailed meta-data export, change from AttributeTypes => Attributes

15427. By Morten Olav Hansen

Minor fix

15428. By Morten Olav Hansen

fixes height issue with detailed export, uses new heightStyle property on accordion

15429. By Morten Olav Hansen

minor

15430. By Morten Olav Hansen

minor fix

15431. By Morten Olav Hansen

Add import for EventReport

15432. By Abyot Asalefew Gizaw <email address hidden>

refactored tracker capture into multiple components, updated code for changes in web-api

15433. By Morten Olav Hansen

expose endpoint in schemaDescriptors, wip

15434. By Morten Olav Hansen

finished exposing endpoints in schema-descriptors

15435. By Morten Olav Hansen

Simplified resource view in web-api, removed /api/resources, resource view is served directly on /api/ now. Uses SchemaDescriptors to generate resources based on apiEndpoint property.

15436. By Thu Tran

Translation.

15437. By Abyot Asalefew Gizaw <email address hidden>

tracker capture, more work on refactoring

15438. By Lars Helge Øverland

Fixed compilation/test error in tracker

15439. By Jan Henrik Øverland

GIS, isadmin callback bug fixed + PT, ou hierarchy wip + ER, ou hierarcy bug fixed + EV, gui wip.

15440. By James Chang

PDF data import fix - checkbox uncheck value change to null rather than 'false'.

15441. By Abyot Asalefew Gizaw <email address hidden>

event capture updated for changes in web-api

15442. By Jan Henrik Øverland

PT DV GIS, plugin, context -> info.

15443. By Jan Henrik Øverland

PT DV GIS, embed code updated.

15444. By Morten Olav Hansen

minor fixes to cacheManifest (caseentry), related to jquery-ui update

15445. By Morten Olav Hansen

exposed metadata property on Schema, will be used to find classes that are used for metadata import/export. Updated SchemaDescripors with metadata info.

15446. By Morten Olav Hansen

New class for /api/schemas output, used instead of metadata class. Reworked dxf2 export list in import-export module, now gets the list of types diretly from /api/schemas, so the list will be dynamic and grow/shrink according to SchemaDescriptors.

15447. By sherylyn.marie

https://blueprints.launchpad.net/dhis-mobile/+spec/enhance-tracker-client
Enhance the feature and offline capacity of tracker client
#2 DATAENTRY FOR OFFLINE PATIENT
- Save thru Visit Schedule
- View thru History List

15448. By Morten Olav Hansen

start work to have export service depend on SchemaService, and not ExchangeClasses, minor fix to TEISchemaDescriptor

15449. By Morten Olav Hansen

implement Ordered interface on Schema, using default value for now. Sort SchemaService.getMetadataSchemas() based on this, important to get proper order on metadata import (but will also be used for export)

15450. By Morten Olav Hansen

wip, implement ordering of schemas

15451. By Morten Olav Hansen

wip, use SchemaService to get supported metadata types in importer/exporter

15452. By Abyot Asalefew Gizaw <email address hidden>

tei enrollment and profile edit from dashboard

15453. By Abyot Asalefew Gizaw <email address hidden>

synchronization between program selections and dashboard contents

15454. By Ngo Thanh Long

temporaryiy fix the build fail problem, the missin file should be commit asap

15455. By Abyot Asalefew Gizaw <email address hidden>

display only those attributes matching selected program in tei profile widget

15456. By Abyot Asalefew Gizaw <email address hidden>

minor

15457. By sherylyn.marie

Added PatientList.java

15458. By sherylyn.marie

added PatientList.java and enabled commented out codes

15459. By Jim Grace

When KEY_ONLY_MANAGE_WITHIN_USER_GROUPS, don't allow user group membership changes causing the changer to gain or loose control over another user.

15460. By Morten Olav Hansen

minor fixes

15461. By Morten Olav Hansen

various fixes to importer, should not be used for tracker objects yet

15462. By Morten Olav Hansen

minor fix

15463. By Morten Olav Hansen

more fixes to importer

15464. By Mark Polak

Make up and down scroll buttons for dropdown menu smaller

15465. By Lars Helge Øverland

Fixed bug with GIS/DV download as png, removing unsafe characters from svg text elements

15466. By Abyot Asalefew Gizaw <email address hidden>

event capture - trimmed data feteched from server using include/exclude feature of the web api

15467. By Thu Tran

Fixed bug - The buttons in TEI Advanced search box are disabled when another orgunit is selected.

15468. By Thu Tran

Fixed bug - Some attribute values are deleted after TEI enrolls into a program.

15469. By Thu Tran

Fixed bug - Hide the Remove program button indashboard if the program selected has any active events.

15470. By Thu Tran

Add deletionHandler for deleting program instance.

15471. By Lars Helge Øverland

App object, remove the permissions config property since it does not match the specification and causes trouble when installing apps

15472. By Lars Helge Øverland

Missing licenses

15473. By Thu Tran

Update help content for tracker module.

15474. By Morten Olav Hansen

minor fixes to programStage importer

15475. By Jan Henrik Øverland

GIS, interpretation gui bug fixed.

15476. By Lars Helge Øverland

Added academy server index file

15477. By Morten Olav Hansen

minor indent fix

15478. By Morten Olav Hansen

fixes to tracker import, basic import should now work (although dry-run is disabled for certain types)

15479. By Morten Olav Hansen

remove dependency on ExchangeClasses in DefaultIdentifiableObjectImporter and AbstractCrudController

15480. By Lars Helge Øverland

SQL view, download as json

15481. By Morten Olav Hansen

removed dependency of ExchangeClasses in DefaultObjectBridge

15482. By Morten Olav Hansen

minor update to schema order, add a bit more room between each schema, makes it easier to plug in other schemas later

15483. By Morten Olav Hansen

removed usage of ExchangeClasses in DefaultMetaDataDependencyService

15484. By Morten Olav Hansen

minor cleanup

15485. By Lars Helge Øverland

DimensionService, fixed bug, lists of dimensions of type org unit group set and data element group set did not respect sharing

15486. By Bharath <email address hidden>

RBF: QualityPaymentScore calculation

15487. By Morten Olav Hansen

introduces two new services: ContextServices and LinkService. LinkService will generate links automatic based on presence of getUid and setHepref. Also extends SchemaService with new method getDynamicSchema, auto-generates schema based on class, useful for classes that have Jackson exposed properties but have no SchemaDescriptor.

15488. By Morten Olav Hansen

wip, node based object graph with json/xml renderers

15489. By Morten Olav Hansen

minor fix

15490. By Morten Olav Hansen

minor change, double check that value is true if XML_ATTRIBUTE hint is set

15491. By Lars Helge Øverland

Notificating in org unit level screen when no levels have been saved yet

15492. By Lars Helge Øverland

Web API, MaintenanceController, added function for clearing application cache

15493. By Lars Helge Øverland

Minor

15494. By Morten Olav Hansen

minor refactor to node render system

15495. By Morten Olav Hansen

support unwrapped collections in xml writer, minor bugfixes to JacksonJson writer, use Node based rendering system in SystemController/UID (only json output for now, will be both xml/json soon)

15496. By Morten Olav Hansen

removed unused package

15497. By Morten Olav Hansen

add RootNodeMessageConverter (write only), allow usage of @ResponseBody in controllers (and return type RootNode), being used in SystemController/UID to support both xml/json automatic

15498. By Thu Tran

Minor fix

15499. By Morten Olav Hansen

minor changes

15500. By Lars Helge Øverland

Removed file

15501. By Lars Helge Øverland

Data value import, trimming meta data objects before looking up in maps

15502. By Morten Olav Hansen

minor change, add helper method for adding new NodeHint

15503. By Lars Helge Øverland

Data value error code translations

15504. By Thu Tran

Fixed bug - The dropdown list of options of dataelements does not show up in Add function of single event with registration.

15505. By Thu Tran

Small change UI of Tracked entity attributes displayed in list form.

15506. By Thu Tran

Add filter for attributes in available Attribute box of Tracked entity attributes displayed in list.

15507. By Thu Tran

Use ajax to load available attributes in Tracked entity attribute visit schedule form and Tracked entity attributes displayed in list form.

15508. By Thu Tran

Remove unused translation in UI ( tracker module )

15509. By Thu Tran

Add a link to show/hide advanced options into Add/Update program form.

15510. By jason.p.pickering

(Translations) Interim commit of Myanmar translations including clean-up.

15511. By Morten Olav Hansen

minor api update

15512. By Morten Olav Hansen

add RenderServiceMessageConverter, uses renderService to render out objects (based on annotations), don't support viewClasses, but useful for simplifying controllers where we just use JacksonUtils.toX or renderService.toX directly

15513. By Morten Olav Hansen

minor rename in SchemaController

15514. By Jan Henrik Øverland

PT DV GIS ER, startup validation.

15515. By Abyot Asalefew Gizaw <email address hidden>

custom form for event capture

15516. By Mithilesh Kumar Thakur

local/in RBF work in progress

15517. By Jan Henrik Øverland

ER, N/A sorting bug fixed.

15518. By Lars Helge Øverland

Improved logging in module manager

15519. By Lars Helge Øverland

Std dev outlier analysis, paging org units in order to avoid very large sql criteria

15520. By Jim Grace

Added category option start and end dates, blueprint category-start-end-dates

15521. By Morten Olav Hansen

minor indent fix

15522. By Morten Olav Hansen

expose propertyMap on Schema

15523. By Morten Olav Hansen

use SchemaService instead of PropertyIntrospectorService in DefaultFilterService

15524. By Morten Olav Hansen

simplifications to DefaultFilterService code

15525. By Abyot Asalefew Gizaw <email address hidden>

turned-off localestorage for event capture, soon to be replaced with dhis2.storage

15526. By Morten Olav Hansen

rewrote filter functionality to use node rendrer system, only supports json for now (but xml is coming soon)

15527. By Thu Tran

Fixed bug - Exception thrown when to delete a program

15528. By Thu Tran

Small change in Assign program to user roles form.

15529. By Abyot Asalefew Gizaw <email address hidden>

replaced localstorage with indexedDB storage for event capture

15530. By Lars Helge Øverland

Module tostring

15531. By Morten Olav Hansen

minor changes to schema/property classes

15532. By Morten Olav Hansen

expose class-level name/namespaceURI in Schema with data from @JacksonXmlRootElement

15533. By Morten Olav Hansen

support COMMENTs in Nodes (will only be output in XML at the moment, since valid JSON does not support comments)

15534. By Morten Olav Hansen

use nodes to write out DVS template (now supports json and xml)

15535. By Morten Olav Hansen

Minor fix

15536. By Abyot Asalefew Gizaw <email address hidden>

minor

15537. By Thu Tran

Add validation for attribute field with letter value type on TEI registration form.

15538. By Thu Tran

Minor fix.

15539. By Thu Tran

Fixed bug - Display value-field according to the value type of attribute selected in Add/Update Validation Criteria.

15540. By Le Hong Em

[mobile] add feedback for J2ME tracker

15541. By Thu Tran

Add filter field for Validation criteria list form.

15542. By Morten Olav Hansen

minor changes to web-api filter

15543. By Morten Olav Hansen

added class information to ComplexNode, useful in cases where the ComplexNode represents a class, and you want that information for later purposes (like getting the schema, link-generator etc)

15544. By Morten Olav Hansen

minor compilation fix

15545. By Thu Tran

Add filter field for Program Validation rule list form.

15546. By Morten Olav Hansen

minor change to ComplexNode

15547. By Thu Tran

Remove unused classes in tracker module.

15548. By Le Hong Em

[mobile] update org unit controller for J2ME tracker

15549. By Morten Olav Hansen

simplifications to Nodes, removed 'hinting' for now

15550. By Thu Tran

Fixed bug - The Days when to send message isn't save if this values is nagetive

15551. By Morten Olav Hansen

minor fixes to serializers

15552. By Thu Tran

Fixed bug - The Days when to send message isn't save if this values is nagetive in program reminder message template.

15553. By Lars Helge Øverland

Analytics, more descriptive feedback in analytics when tables cannot be updated

15554. By Morten Olav Hansen

minor api changes to NodeService

15555. By Morten Olav Hansen

use map internally in AbstractNode, speeds up lookup based on name, also enforces name uniqueness (might be name+namespace in the future)

15556. By Morten Olav Hansen

remove duplicate license

15557. By Le Hong Em

[mobile] update org unit controller for J2ME tracker

15558. By Morten Olav Hansen

Minor fix

15559. By Morten Olav Hansen

revert to using list instead of map for children list

15560. By Morten Olav Hansen

changed parameter parsing in inclusion/exclusion filter

15561. By Morten Olav Hansen

Minor javadoc update

15562. By Morten Olav Hansen

minor fixes to nodeService

15563. By Morten Olav Hansen

minor fix to contextService

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'dhis-2/dhis-api/pom.xml'
--- dhis-2/dhis-api/pom.xml 2014-04-25 10:44:39 +0000
+++ dhis-2/dhis-api/pom.xml 2014-06-05 17:39:07 +0000
@@ -83,6 +83,10 @@
83 <groupId>org.hibernate</groupId>83 <groupId>org.hibernate</groupId>
84 <artifactId>hibernate-validator</artifactId>84 <artifactId>hibernate-validator</artifactId>
85 </dependency>85 </dependency>
86 <dependency>
87 <groupId>org.javassist</groupId>
88 <artifactId>javassist</artifactId>
89 </dependency>
8690
87 </dependencies>91 </dependencies>
8892
8993
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/App.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/App.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/App.java 2014-06-05 17:39:07 +0000
@@ -78,9 +78,6 @@
78 private String locales;78 private String locales;
7979
80 @JsonProperty80 @JsonProperty
81 private String permissions;
82
83 @JsonProperty
84 private AppActivities activities;81 private AppActivities activities;
85 82
86 @JsonProperty83 @JsonProperty
@@ -194,16 +191,6 @@
194 this.locales = locales;191 this.locales = locales;
195 }192 }
196193
197 public String getPermissions()
198 {
199 return permissions;
200 }
201
202 public void setPermissions( String permissions )
203 {
204 this.permissions = permissions;
205 }
206
207 public AppActivities getActivities()194 public AppActivities getActivities()
208 {195 {
209 return activities;196 return activities;
210197
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/AbstractCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/AbstractCalendar.java 2014-05-13 16:00:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/AbstractCalendar.java 2014-06-05 17:39:07 +0000
@@ -143,7 +143,7 @@
143 @Override143 @Override
144 public DateUnit fromIso( int year, int month, int day )144 public DateUnit fromIso( int year, int month, int day )
145 {145 {
146 return fromIso( new DateUnit( year, month, day ) );146 return fromIso( new DateUnit( year, month, day, true ) );
147 }147 }
148148
149 @Override149 @Override
150150
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java 2014-05-13 16:00:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java 2014-06-05 17:39:07 +0000
@@ -32,6 +32,7 @@
3232
33/**33/**
34 * Generic interface for representing a Calendar.34 * Generic interface for representing a Calendar.
35 *
35 * @author Morten Olav Hansen <mortenoh@gmail.com>36 * @author Morten Olav Hansen <mortenoh@gmail.com>
36 * @see DateUnit37 * @see DateUnit
37 * @see DateInterval38 * @see DateInterval
@@ -41,24 +42,28 @@
41{42{
42 /**43 /**
43 * Name of this calendar.44 * Name of this calendar.
45 *
44 * @return Name of calendar.46 * @return Name of calendar.
45 */47 */
46 String name();48 String name();
4749
48 /**50 /**
49 * Date format for this calendar51 * Date format for this calendar
52 *
50 * @return Default date format53 * @return Default date format
51 */54 */
52 String getDateFormat();55 String getDateFormat();
5356
54 /**57 /**
55 * Set date format for this calendar58 * Set date format for this calendar
59 *
56 * @param dateFormat Date format to use for this calendar60 * @param dateFormat Date format to use for this calendar
57 */61 */
58 void setDateFormat( String dateFormat );62 void setDateFormat( String dateFormat );
5963
60 /**64 /**
61 * Formats dateUnit using dateFormat65 * Formats dateUnit using dateFormat
66 *
62 * @param dateUnit DateUnit representing local year, month, day67 * @param dateUnit DateUnit representing local year, month, day
63 * @return Default date format68 * @return Default date format
64 * @see #getDateFormat()69 * @see #getDateFormat()
@@ -67,6 +72,7 @@
6772
68 /**73 /**
69 * Formats dateUnit using dateFormat and ISO 860174 * Formats dateUnit using dateFormat and ISO 8601
75 *
70 * @param dateUnit DateUnit representing local year, month, day76 * @param dateUnit DateUnit representing local year, month, day
71 * @return Default date format77 * @return Default date format
72 * @see #getDateFormat()78 * @see #getDateFormat()
@@ -75,6 +81,7 @@
7581
76 /**82 /**
77 * Convert local calendar to an ISO 8601 DateUnit.83 * Convert local calendar to an ISO 8601 DateUnit.
84 *
78 * @param year Local year85 * @param year Local year
79 * @param month Local month86 * @param month Local month
80 * @param day Local day87 * @param day Local day
@@ -85,6 +92,7 @@
8592
86 /**93 /**
87 * Convert local calendar to an ISO 8601 DateUnit.94 * Convert local calendar to an ISO 8601 DateUnit.
95 *
88 * @param date Date formatted using default date format96 * @param date Date formatted using default date format
89 * @return DateUnit representing local date in ISO 860197 * @return DateUnit representing local date in ISO 8601
90 * @see <a href="http://en.wikipedia.org/wiki/ISO_8601">http://en.wikipedia.org/wiki/ISO_8601</a>98 * @see <a href="http://en.wikipedia.org/wiki/ISO_8601">http://en.wikipedia.org/wiki/ISO_8601</a>
@@ -93,6 +101,7 @@
93101
94 /**102 /**
95 * Convert local calendar to an ISO 8601 DateUnit.103 * Convert local calendar to an ISO 8601 DateUnit.
104 *
96 * @param dateUnit DateUnit representing local year, month, day105 * @param dateUnit DateUnit representing local year, month, day
97 * @return DateUnit representing local date in ISO 8601106 * @return DateUnit representing local date in ISO 8601
98 * @see <a href="http://en.wikipedia.org/wiki/ISO_8601">http://en.wikipedia.org/wiki/ISO_8601</a>107 * @see <a href="http://en.wikipedia.org/wiki/ISO_8601">http://en.wikipedia.org/wiki/ISO_8601</a>
@@ -101,6 +110,7 @@
101110
102 /**111 /**
103 * Convert from local to ISO 8601 DateUnit.112 * Convert from local to ISO 8601 DateUnit.
113 *
104 * @param year ISO 8601 year114 * @param year ISO 8601 year
105 * @param month ISO 8601 month115 * @param month ISO 8601 month
106 * @param day ISO 8601 day116 * @param day ISO 8601 day
@@ -111,6 +121,7 @@
111121
112 /**122 /**
113 * Convert from local to ISO 8601 DateUnit.123 * Convert from local to ISO 8601 DateUnit.
124 *
114 * @param dateUnit DateUnit representing ISO 8601 year, month, day125 * @param dateUnit DateUnit representing ISO 8601 year, month, day
115 * @return DateUnit representing ISO 8601 in local126 * @return DateUnit representing ISO 8601 in local
116 * @see <a href="http://en.wikipedia.org/wiki/ISO_8601">http://en.wikipedia.org/wiki/ISO_8601</a>127 * @see <a href="http://en.wikipedia.org/wiki/ISO_8601">http://en.wikipedia.org/wiki/ISO_8601</a>
@@ -119,6 +130,7 @@
119130
120 /**131 /**
121 * Gets interval of type based on DateUnit132 * Gets interval of type based on DateUnit
133 *
122 * @param dateUnit DateUnit representing local year, month, day134 * @param dateUnit DateUnit representing local year, month, day
123 * @param type Interval type to get135 * @param type Interval type to get
124 * @param offset Offset to start at, can be negative of positive136 * @param offset Offset to start at, can be negative of positive
@@ -130,6 +142,7 @@
130142
131 /**143 /**
132 * Gets interval of type based on DateUnit using default options, 0 for offset, 1 for length144 * Gets interval of type based on DateUnit using default options, 0 for offset, 1 for length
145 *
133 * @param dateUnit DateUnit representing local year, month, day146 * @param dateUnit DateUnit representing local year, month, day
134 * @param type Interval type to get147 * @param type Interval type to get
135 * @return Interval for interval type based on dateUnit148 * @return Interval for interval type based on dateUnit
@@ -139,6 +152,7 @@
139152
140 /**153 /**
141 * Gets interval of type based on today's date154 * Gets interval of type based on today's date
155 *
142 * @param type Interval type to get156 * @param type Interval type to get
143 * @return Interval for interval type based on dateUnit157 * @return Interval for interval type based on dateUnit
144 * @see DateIntervalType158 * @see DateIntervalType
@@ -147,6 +161,7 @@
147161
148 /**162 /**
149 * Gets interval of type based on today's date163 * Gets interval of type based on today's date
164 *
150 * @param type Interval type to get165 * @param type Interval type to get
151 * @param offset Offset to start at, can be negative of positive166 * @param offset Offset to start at, can be negative of positive
152 * @param length How many periods to asks for, i.e. type = MONTH, length = 2, two months167 * @param length How many periods to asks for, i.e. type = MONTH, length = 2, two months
@@ -157,6 +172,7 @@
157172
158 /**173 /**
159 * Gets interval of type based on DateUnit174 * Gets interval of type based on DateUnit
175 *
160 * @param dateUnit DateUnit representing local year, month, day176 * @param dateUnit DateUnit representing local year, month, day
161 * @param type Interval type to get177 * @param type Interval type to get
162 * @param offset Offset to start at, can be negative of positive178 * @param offset Offset to start at, can be negative of positive
@@ -169,37 +185,50 @@
169185
170 /**186 /**
171 * Gets current date as local DateUnit187 * Gets current date as local DateUnit
188 *
172 * @return Today date as local DateUnit189 * @return Today date as local DateUnit
173 */190 */
174 DateUnit today();191 DateUnit today();
175192
176 /**193 /**
177 * Gets the number of months in a calendar year.194 * Gets the number of months in a calendar year.
195 *
178 * @return Number of months in a year196 * @return Number of months in a year
179 */197 */
180 int monthsInYear();198 int monthsInYear();
181199
182 /**200 /**
183 * Gets the number of days in a calendar week.201 * Gets the number of days in a calendar week.
202 *
184 * @return Number of days in a week203 * @return Number of days in a week
185 */204 */
186 int daysInWeek();205 int daysInWeek();
187206
188 /**207 /**
189 * Gets the number of days in a calendar year.208 * Gets the number of days in a calendar year.
209 *
190 * @return Number of days in this calendar year210 * @return Number of days in this calendar year
191 */211 */
192 int daysInYear( int year );212 int daysInYear( int year );
193213
194 /**214 /**
195 * Gets the number of days in a calendar year/month.215 * Gets the number of days in a calendar year/month.
216 *
196 * @return Number of days in this calendar year/month217 * @return Number of days in this calendar year/month
197 */218 */
198 int daysInMonth( int year, int month );219 int daysInMonth( int year, int month );
199220
200 /**221 /**
222 * Gets the number of weeks in a calendar year.
223 *
224 * @return Number of weeks in this calendar year
225 */
226 int weeksInYear( int year );
227
228 /**
201 * Gets week number using local DateUnit, week number is calculated based on229 * Gets week number using local DateUnit, week number is calculated based on
202 * ISO 8601 week numbers230 * ISO 8601 week numbers
231 *
203 * @param dateUnit DateUnit representing local year, month, day232 * @param dateUnit DateUnit representing local year, month, day
204 * @return Week number233 * @return Week number
205 * @see <a href="http://en.wikipedia.org/wiki/ISO_8601">http://en.wikipedia.org/wiki/ISO_8601</a>234 * @see <a href="http://en.wikipedia.org/wiki/ISO_8601">http://en.wikipedia.org/wiki/ISO_8601</a>
@@ -209,6 +238,7 @@
209238
210 /**239 /**
211 * Returns week number using local DateUnit, week number is calculated based on local calendar.240 * Returns week number using local DateUnit, week number is calculated based on local calendar.
241 *
212 * @param dateUnit DateUnit representing local year, month, day242 * @param dateUnit DateUnit representing local year, month, day
213 * @return Week number243 * @return Week number
214 */244 */
@@ -217,6 +247,7 @@
217 /**247 /**
218 * Gets the ISO 8601 weekday for this local DateUnit, using ISO 8601 day numbering,248 * Gets the ISO 8601 weekday for this local DateUnit, using ISO 8601 day numbering,
219 * 1=Monday => 7=Sunday.249 * 1=Monday => 7=Sunday.
250 *
220 * @param dateUnit DateUnit representing local year, month, day251 * @param dateUnit DateUnit representing local year, month, day
221 * @return Weekday number252 * @return Weekday number
222 * @see <a href="http://en.wikipedia.org/wiki/ISO_8601">http://en.wikipedia.org/wiki/ISO_8601</a>253 * @see <a href="http://en.wikipedia.org/wiki/ISO_8601">http://en.wikipedia.org/wiki/ISO_8601</a>
@@ -227,6 +258,7 @@
227 /**258 /**
228 * Gets the local weekday for this local DateUnit, using ISO 8601 day numbering,259 * Gets the local weekday for this local DateUnit, using ISO 8601 day numbering,
229 * 1=Monday => 7=Sunday.260 * 1=Monday => 7=Sunday.
261 *
230 * @param dateUnit DateUnit representing local year, month, day262 * @param dateUnit DateUnit representing local year, month, day
231 * @return Weekday number263 * @return Weekday number
232 * @see <a href="http://en.wikipedia.org/wiki/ISO_8601">http://en.wikipedia.org/wiki/ISO_8601</a>264 * @see <a href="http://en.wikipedia.org/wiki/ISO_8601">http://en.wikipedia.org/wiki/ISO_8601</a>
@@ -236,6 +268,7 @@
236268
237 /**269 /**
238 * Gets the (untranslated) I18n key for local month270 * Gets the (untranslated) I18n key for local month
271 *
239 * @param month Month to fetch key for272 * @param month Month to fetch key for
240 * @return I18n Key for this month273 * @return I18n Key for this month
241 * @see <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">http://en.wikipedia.org/wiki/Internationalization_and_localization</a>274 * @see <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">http://en.wikipedia.org/wiki/Internationalization_and_localization</a>
@@ -244,6 +277,7 @@
244277
245 /**278 /**
246 * Gets the (untranslated) I18n short key for local month279 * Gets the (untranslated) I18n short key for local month
280 *
247 * @param month Month to fetch key for281 * @param month Month to fetch key for
248 * @return I18n Key for this month282 * @return I18n Key for this month
249 * @see <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">http://en.wikipedia.org/wiki/Internationalization_and_localization</a>283 * @see <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">http://en.wikipedia.org/wiki/Internationalization_and_localization</a>
@@ -252,6 +286,7 @@
252286
253 /**287 /**
254 * Gets the (untranslated) I18n key for local day288 * Gets the (untranslated) I18n key for local day
289 *
255 * @param day Day to fetch key for290 * @param day Day to fetch key for
256 * @return I18n Key for this day291 * @return I18n Key for this day
257 * @see <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">http://en.wikipedia.org/wiki/Internationalization_and_localization</a>292 * @see <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">http://en.wikipedia.org/wiki/Internationalization_and_localization</a>
@@ -260,6 +295,7 @@
260295
261 /**296 /**
262 * Gets the (untranslated) I18n short key for local day297 * Gets the (untranslated) I18n short key for local day
298 *
263 * @param day Day to fetch key for299 * @param day Day to fetch key for
264 * @return I18n Key for this day300 * @return I18n Key for this day
265 * @see <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">http://en.wikipedia.org/wiki/Internationalization_and_localization</a>301 * @see <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization">http://en.wikipedia.org/wiki/Internationalization_and_localization</a>
@@ -268,6 +304,7 @@
268304
269 /**305 /**
270 * Returns a new dateUnit with specified number of days added306 * Returns a new dateUnit with specified number of days added
307 *
271 * @param dateUnit DateUnit representing local year, month, day308 * @param dateUnit DateUnit representing local year, month, day
272 * @param days Days to add309 * @param days Days to add
273 * @return dateUnit + days310 * @return dateUnit + days
@@ -276,6 +313,7 @@
276313
277 /**314 /**
278 * Returns a new dateUnit with specified number of days subtracted315 * Returns a new dateUnit with specified number of days subtracted
316 *
279 * @param dateUnit DateUnit representing local year, month, day317 * @param dateUnit DateUnit representing local year, month, day
280 * @param days Days to subtract318 * @param days Days to subtract
281 * @return dateUnit - days319 * @return dateUnit - days
@@ -284,6 +322,7 @@
284322
285 /**323 /**
286 * Returns a new dateUnit with specified number of weeks added324 * Returns a new dateUnit with specified number of weeks added
325 *
287 * @param dateUnit DateUnit representing local year, month, day326 * @param dateUnit DateUnit representing local year, month, day
288 * @param weeks Weeks to add327 * @param weeks Weeks to add
289 * @return dateUnit + weeks328 * @return dateUnit + weeks
@@ -292,6 +331,7 @@
292331
293 /**332 /**
294 * Returns a new dateUnit with specified number of weeks subtracted333 * Returns a new dateUnit with specified number of weeks subtracted
334 *
295 * @param dateUnit DateUnit representing local year, month, day335 * @param dateUnit DateUnit representing local year, month, day
296 * @param weeks Weeks to subtract336 * @param weeks Weeks to subtract
297 * @return dateUnit - weeks337 * @return dateUnit - weeks
@@ -300,6 +340,7 @@
300340
301 /**341 /**
302 * Returns a new dateUnit with specified number of months added342 * Returns a new dateUnit with specified number of months added
343 *
303 * @param dateUnit DateUnit representing local year, month, day344 * @param dateUnit DateUnit representing local year, month, day
304 * @param months Months to add345 * @param months Months to add
305 * @return dateUnit + months346 * @return dateUnit + months
@@ -308,6 +349,7 @@
308349
309 /**350 /**
310 * Returns a new dateUnit with specified number of months subtracted351 * Returns a new dateUnit with specified number of months subtracted
352 *
311 * @param dateUnit DateUnit representing local year, month, day353 * @param dateUnit DateUnit representing local year, month, day
312 * @param months Months to subtract354 * @param months Months to subtract
313 * @return dateUnit - months355 * @return dateUnit - months
@@ -316,6 +358,7 @@
316358
317 /**359 /**
318 * Returns a new dateUnit with specified number of years added360 * Returns a new dateUnit with specified number of years added
361 *
319 * @param dateUnit DateUnit representing local year, month, day362 * @param dateUnit DateUnit representing local year, month, day
320 * @param years Years to add363 * @param years Years to add
321 * @return dateUnit + years364 * @return dateUnit + years
@@ -324,6 +367,7 @@
324367
325 /**368 /**
326 * Returns a new dateUnit with specified number of years subtracted369 * Returns a new dateUnit with specified number of years subtracted
370 *
327 * @param dateUnit DateUnit representing local year, month, day371 * @param dateUnit DateUnit representing local year, month, day
328 * @param years Years to subtract372 * @param years Years to subtract
329 * @return dateUnit - years373 * @return dateUnit - years
330374
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java 2014-05-12 07:52:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java 2014-06-05 17:39:07 +0000
@@ -47,15 +47,25 @@
47 @Override47 @Override
48 public DateUnit toIso( DateUnit dateUnit )48 public DateUnit toIso( DateUnit dateUnit )
49 {49 {
50 if ( dateUnit.isIso8601() )
51 {
52 return dateUnit;
53 }
54
50 DateTime dateTime = dateUnit.toDateTime( chronology );55 DateTime dateTime = dateUnit.toDateTime( chronology );
51 dateTime = dateTime.withChronology( ISOChronology.getInstance() );56 dateTime = dateTime.withChronology( ISOChronology.getInstance() );
5257
53 return DateUnit.fromDateTime( dateTime );58 return new DateUnit( DateUnit.fromDateTime( dateTime ), true );
54 }59 }
5560
56 @Override61 @Override
57 public DateUnit fromIso( DateUnit dateUnit )62 public DateUnit fromIso( DateUnit dateUnit )
58 {63 {
64 if ( !dateUnit.isIso8601() )
65 {
66 return dateUnit;
67 }
68
59 DateTime dateTime = dateUnit.toDateTime( ISOChronology.getInstance() );69 DateTime dateTime = dateUnit.toDateTime( ISOChronology.getInstance() );
60 dateTime = dateTime.withChronology( chronology );70 dateTime = dateTime.withChronology( chronology );
61 return DateUnit.fromDateTime( dateTime );71 return DateUnit.fromDateTime( dateTime );
@@ -204,7 +214,14 @@
204 public int daysInMonth( int year, int month )214 public int daysInMonth( int year, int month )
205 {215 {
206 DateTime dateTime = new DateTime( year, month, 1, 0, 0, chronology );216 DateTime dateTime = new DateTime( year, month, 1, 0, 0, chronology );
207 return (int) dateTime.monthOfYear().toInterval().toDuration().getStandardDays();217 return dateTime.dayOfMonth().getMaximumValue();
218 }
219
220 @Override
221 public int weeksInYear( int year )
222 {
223 DateTime dateTime = new DateTime( year, 1, 1, 0, 0, chronology );
224 return dateTime.weekOfWeekyear().getMaximumValue();
208 }225 }
209226
210 @Override227 @Override
211228
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateInterval.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateInterval.java 2014-04-27 02:45:02 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateInterval.java 2014-06-05 17:39:07 +0000
@@ -84,6 +84,30 @@
84 }84 }
8585
86 @Override86 @Override
87 public boolean equals( Object o )
88 {
89 if ( this == o ) return true;
90 if ( o == null || getClass() != o.getClass() ) return false;
91
92 DateInterval that = (DateInterval) o;
93
94 if ( from != null ? !from.equals( that.from ) : that.from != null ) return false;
95 if ( to != null ? !to.equals( that.to ) : that.to != null ) return false;
96 if ( type != that.type ) return false;
97
98 return true;
99 }
100
101 @Override
102 public int hashCode()
103 {
104 int result = from != null ? from.hashCode() : 0;
105 result = 31 * result + (to != null ? to.hashCode() : 0);
106 result = 31 * result + (type != null ? type.hashCode() : 0);
107 return result;
108 }
109
110 @Override
87 public String toString()111 public String toString()
88 {112 {
89 return "DateInterval{" +113 return "DateInterval{" +
90114
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateTimeUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateTimeUnit.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateTimeUnit.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,134 @@
1package org.hisp.dhis.calendar;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31import org.joda.time.DateTime;
32
33import java.util.Date;
34
35/**
36 * Simple class that can hold both a TimeUnit and DateUnit which is useful in cases
37 * where we are converting from a DateTime, Jdk Calendar or Jdk Date and don't want to
38 * loose either date or time dimension.
39 *
40 * @author Morten Olav Hansen <mortenoh@gmail.com>
41 * @see DateUnit
42 * @see TimeUnit
43 * @see org.joda.time.DateTime
44 * @see java.util.Calendar
45 * @see java.util.Date
46 */
47public class DateTimeUnit
48{
49 private DateUnit dateUnit;
50
51 private TimeUnit timeUnit;
52
53 public DateTimeUnit()
54 {
55 }
56
57 public DateTimeUnit( DateUnit dateUnit, TimeUnit timeUnit )
58 {
59 this.dateUnit = dateUnit;
60 this.timeUnit = timeUnit;
61 }
62
63 public DateUnit getDateUnit()
64 {
65 return dateUnit;
66 }
67
68 public void setDateUnit( DateUnit dateUnit )
69 {
70 this.dateUnit = dateUnit;
71 }
72
73 public TimeUnit getTimeUnit()
74 {
75 return timeUnit;
76 }
77
78 public void setTimeUnit( TimeUnit timeUnit )
79 {
80 this.timeUnit = timeUnit;
81 }
82
83 public static DateTimeUnit fromDateTime( DateTime dateTime )
84 {
85 DateUnit dateUnit = DateUnit.fromDateTime( dateTime );
86 TimeUnit timeUnit = TimeUnit.fromDateTime( dateTime );
87
88 return new DateTimeUnit( dateUnit, timeUnit );
89 }
90
91 public static DateTimeUnit fromJdkCalendar( java.util.Calendar calendar )
92 {
93 DateUnit dateUnit = DateUnit.fromJdkCalendar( calendar );
94 TimeUnit timeUnit = TimeUnit.fromJdkCalendar( calendar );
95
96 return new DateTimeUnit( dateUnit, timeUnit );
97 }
98
99 public static DateTimeUnit fromJdkDate( Date date )
100 {
101 return fromDateTime( new DateTime( date.getTime() ) );
102 }
103
104 @Override
105 public boolean equals( Object o )
106 {
107 if ( this == o ) return true;
108 if ( o == null || getClass() != o.getClass() ) return false;
109
110 DateTimeUnit that = (DateTimeUnit) o;
111
112 if ( dateUnit != null ? !dateUnit.equals( that.dateUnit ) : that.dateUnit != null ) return false;
113 if ( timeUnit != null ? !timeUnit.equals( that.timeUnit ) : that.timeUnit != null ) return false;
114
115 return true;
116 }
117
118 @Override
119 public int hashCode()
120 {
121 int result = dateUnit != null ? dateUnit.hashCode() : 0;
122 result = 31 * result + (timeUnit != null ? timeUnit.hashCode() : 0);
123 return result;
124 }
125
126 @Override
127 public String toString()
128 {
129 return "DateTimeUnit{" +
130 "dateUnit=" + dateUnit +
131 ", timeUnit=" + timeUnit +
132 '}';
133 }
134}
0135
=== 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-05-12 16:57:48 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnit.java 2014-06-05 17:39:07 +0000
@@ -38,9 +38,12 @@
3838
39/**39/**
40 * Class representing a specific calendar date.40 * Class representing a specific calendar date.
41 *
41 * @author Morten Olav Hansen <mortenoh@gmail.com>42 * @author Morten Olav Hansen <mortenoh@gmail.com>
42 * @see DateInterval43 * @see DateInterval
43 * @see Calendar44 * @see Calendar
45 * @see TimeUnit
46 * @see DateTimeUnit
44 */47 */
45public class DateUnit48public class DateUnit
46{49{
@@ -67,29 +70,61 @@
67 */70 */
68 int dayOfWeek;71 int dayOfWeek;
6972
73 /**
74 * Does dateUnit represent ISO 8601.
75 */
76 final boolean iso8601;
77
78 public DateUnit( boolean iso8601 )
79 {
80 this.iso8601 = iso8601;
81 }
82
70 public DateUnit()83 public DateUnit()
71 {84 {
85 this( false );
72 }86 }
7387
74 public DateUnit( DateUnit dateUnit )88 public DateUnit( DateUnit dateUnit )
75 {89 {
76 this.year = dateUnit.getYear();90 this( dateUnit.isIso8601() );
77 this.month = dateUnit.getMonth();91 this.year = dateUnit.getYear();
78 this.day = dateUnit.getDay();92 this.month = dateUnit.getMonth();
79 this.dayOfWeek = dateUnit.getDayOfWeek();93 this.day = dateUnit.getDay();
94 this.dayOfWeek = dateUnit.getDayOfWeek();
95 }
96
97 public DateUnit( DateUnit dateUnit, boolean iso8601 )
98 {
99 this( iso8601 );
100 this.year = dateUnit.getYear();
101 this.month = dateUnit.getMonth();
102 this.day = dateUnit.getDay();
103 this.dayOfWeek = dateUnit.getDayOfWeek();
104 }
105
106 public DateUnit( int year, int month, int day, boolean iso8601 )
107 {
108 this.year = year;
109 this.month = month;
110 this.day = day;
111 this.iso8601 = iso8601;
80 }112 }
81113
82 public DateUnit( int year, int month, int day )114 public DateUnit( int year, int month, int day )
83 {115 {
84 this.year = year;116 this( year, month, day, false );
85 this.month = month;117 }
86 this.day = day;118
119 public DateUnit( int year, int month, int day, int dayOfWeek, boolean iso8601 )
120 {
121 this( year, month, day, iso8601 );
122 this.dayOfWeek = dayOfWeek;
87 }123 }
88124
89 public DateUnit( int year, int month, int day, int dayOfWeek )125 public DateUnit( int year, int month, int day, int dayOfWeek )
90 {126 {
91 this( year, month, day );127 this( year, month, day, dayOfWeek, false );
92 this.dayOfWeek = dayOfWeek;
93 }128 }
94129
95 public int getYear()130 public int getYear()
@@ -132,8 +167,18 @@
132 this.dayOfWeek = dayOfWeek;167 this.dayOfWeek = dayOfWeek;
133 }168 }
134169
170 public boolean isIso8601()
171 {
172 return iso8601;
173 }
174
135 public DateTime toDateTime()175 public DateTime toDateTime()
136 {176 {
177 if ( !iso8601 )
178 {
179 throw new RuntimeException( "Cannot convert non-ISO8601 DateUnit to DateTime." );
180 }
181
137 return new DateTime( year, month, day, 0, 0, ISOChronology.getInstance() );182 return new DateTime( year, month, day, 0, 0, ISOChronology.getInstance() );
138 }183 }
139184
@@ -144,7 +189,15 @@
144189
145 public java.util.Calendar toJdkCalendar()190 public java.util.Calendar toJdkCalendar()
146 {191 {
147 return new GregorianCalendar( year, month - 1, day );192 if ( !iso8601 )
193 {
194 throw new RuntimeException( "Cannot convert non-ISO8601 DateUnit to JDK Calendar." );
195 }
196
197 java.util.Calendar calendar = new GregorianCalendar( year, month - 1, day );
198 calendar.setTime( calendar.getTime() );
199
200 return calendar;
148 }201 }
149202
150 public Date toJdkDate()203 public Date toJdkDate()
@@ -160,12 +213,39 @@
160 public static DateUnit fromJdkCalendar( java.util.Calendar calendar )213 public static DateUnit fromJdkCalendar( java.util.Calendar calendar )
161 {214 {
162 return new DateUnit( calendar.get( java.util.Calendar.YEAR ), calendar.get( java.util.Calendar.MONTH ) + 1,215 return new DateUnit( calendar.get( java.util.Calendar.YEAR ), calendar.get( java.util.Calendar.MONTH ) + 1,
163 calendar.get( java.util.Calendar.DAY_OF_MONTH ), calendar.get( java.util.Calendar.DAY_OF_WEEK ) );216 calendar.get( java.util.Calendar.DAY_OF_MONTH ), calendar.get( java.util.Calendar.DAY_OF_WEEK ), true );
164 }217 }
165218
166 public static DateUnit fromJdkDate( Date date )219 public static DateUnit fromJdkDate( Date date )
167 {220 {
168 return fromDateTime( new DateTime( date.getTime() ) );221 DateUnit dateUnit = fromDateTime( new DateTime( date.getTime() ) );
222 return new DateUnit( dateUnit, true );
223 }
224
225 @Override
226 public boolean equals( Object o )
227 {
228 if ( this == o ) return true;
229 if ( o == null || getClass() != o.getClass() ) return false;
230
231 DateUnit dateUnit = (DateUnit) o;
232
233 if ( day != dateUnit.day ) return false;
234 if ( iso8601 != dateUnit.iso8601 ) return false;
235 if ( month != dateUnit.month ) return false;
236 if ( year != dateUnit.year ) return false;
237
238 return true;
239 }
240
241 @Override
242 public int hashCode()
243 {
244 int result = year;
245 result = 31 * result + month;
246 result = 31 * result + day;
247 result = 31 * result + (iso8601 ? 1 : 0);
248 return result;
169 }249 }
170250
171 @Override251 @Override
@@ -175,7 +255,7 @@
175 "year=" + year +255 "year=" + year +
176 ", month=" + month +256 ", month=" + month +
177 ", day=" + day +257 ", day=" + day +
178 ", dayOfWeek=" + dayOfWeek +258 ", iso8601=" + iso8601 +
179 '}';259 '}';
180 }260 }
181}261}
182262
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnitPeriodTypeParser.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnitPeriodTypeParser.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnitPeriodTypeParser.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,289 @@
1package org.hisp.dhis.calendar;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31import com.google.common.collect.Maps;
32import org.hisp.dhis.calendar.impl.Iso8601Calendar;
33
34import java.util.Map;
35import java.util.regex.Matcher;
36import java.util.regex.Pattern;
37import java.util.regex.PatternSyntaxException;
38
39/**
40 * @author Morten Olav Hansen <mortenoh@gmail.com>
41 */
42public class DateUnitPeriodTypeParser implements PeriodTypeParser
43{
44 private final Map<String, Pattern> compileCache = Maps.newHashMap();
45
46 private static CalendarService calendarService;
47
48 public static void setCalendarService( CalendarService calendarService )
49 {
50 DateUnitPeriodTypeParser.calendarService = calendarService;
51 }
52
53 public static CalendarService getCalendarService()
54 {
55 return calendarService;
56 }
57
58 public static org.hisp.dhis.calendar.Calendar getCalendar()
59 {
60 if ( calendarService != null )
61 {
62 return calendarService.getSystemCalendar();
63 }
64
65 return Iso8601Calendar.getInstance();
66 }
67
68 @Override
69 public DateInterval parse( String period )
70 {
71 DateUnitType type = DateUnitType.find( period );
72
73 if ( type == null )
74 {
75 return null;
76 }
77
78 if ( compileCache.get( type.getType() ) == null )
79 {
80 try
81 {
82 Pattern pattern = Pattern.compile( type.getFormat() );
83 compileCache.put( type.getType(), pattern );
84 }
85 catch ( PatternSyntaxException ex )
86 {
87 return null;
88 }
89 }
90
91 Pattern pattern = compileCache.get( type.getType() );
92 Matcher matcher = pattern.matcher( period );
93 boolean match = matcher.find();
94
95 if ( !match )
96 {
97 return null;
98 }
99
100 if ( DateUnitType.DAILY.equals( type ) )
101 {
102 int year = Integer.parseInt( matcher.group( 1 ) );
103 int month = Integer.parseInt( matcher.group( 2 ) );
104 int day = Integer.parseInt( matcher.group( 3 ) );
105
106 DateUnit dateUnit = new DateUnit( year, month, day );
107 dateUnit.setDayOfWeek( getCalendar().weekday( dateUnit ) );
108
109 return new DateInterval( dateUnit, dateUnit );
110 }
111 else if ( DateUnitType.WEEKLY.equals( type ) )
112 {
113 int year = Integer.parseInt( matcher.group( 1 ) );
114 int week = Integer.parseInt( matcher.group( 2 ) );
115
116 if ( week < 1 || week > getCalendar().weeksInYear( year ) )
117 {
118 return null;
119 }
120
121 DateUnit start = new DateUnit( year, 1, 1 );
122 start = getCalendar().minusDays( start, getCalendar().weekday( start ) - 1 ); // rewind to start of week
123
124 // since we rewind to start of week, we might end up in the previous years weeks, so we check and forward if needed
125 if ( getCalendar().isoWeek( start ) == getCalendar().weeksInYear( year ) )
126 {
127 start = getCalendar().plusWeeks( start, 1 );
128 }
129
130 start = getCalendar().plusWeeks( start, week - 1 );
131 DateUnit end = new DateUnit( start );
132 end = getCalendar().plusWeeks( end, 1 );
133 end = getCalendar().minusDays( end, 1 );
134
135 start.setDayOfWeek( getCalendar().weekday( start ) );
136 end.setDayOfWeek( getCalendar().weekday( end ) );
137
138 return new DateInterval( start, end );
139 }
140 else if ( DateUnitType.MONTHLY.equals( type ) )
141 {
142 int year = Integer.parseInt( matcher.group( 1 ) );
143 int month = Integer.parseInt( matcher.group( 2 ) );
144
145 DateUnit start = new DateUnit( year, month, 1 );
146 DateUnit end = new DateUnit( year, month, getCalendar().daysInMonth( start.getYear(), start.getMonth() ) );
147
148 start.setDayOfWeek( getCalendar().weekday( start ) );
149 end.setDayOfWeek( getCalendar().weekday( end ) );
150
151 return new DateInterval( start, end );
152 }
153 else if ( DateUnitType.BI_MONTHLY.equals( type ) )
154 {
155 int year = Integer.parseInt( matcher.group( 1 ) );
156 int month = Integer.parseInt( matcher.group( 2 ) );
157
158 DateUnit start = new DateUnit( year, month, 1 );
159 DateUnit end = new DateUnit( start );
160 end = getCalendar().plusMonths( end, 2 );
161 end = getCalendar().minusDays( end, 1 );
162
163 start.setDayOfWeek( getCalendar().weekday( start ) );
164 end.setDayOfWeek( getCalendar().weekday( end ) );
165
166 return new DateInterval( start, end );
167 }
168 else if ( DateUnitType.QUARTERLY.equals( type ) )
169 {
170 int year = Integer.parseInt( matcher.group( 1 ) );
171 int quarter = Integer.parseInt( matcher.group( 2 ) );
172
173 // valid quarters are from 1 - 4
174 if ( quarter < 1 || quarter > 4 )
175 {
176 return null;
177 }
178
179 DateUnit start = new DateUnit( year, ((quarter - 1) * 3) + 1, 1 );
180 DateUnit end = new DateUnit( start );
181 end = getCalendar().plusMonths( end, 3 );
182 end = getCalendar().minusDays( end, 1 );
183
184 start.setDayOfWeek( getCalendar().weekday( start ) );
185 end.setDayOfWeek( getCalendar().weekday( end ) );
186
187 return new DateInterval( start, end );
188 }
189 else if ( DateUnitType.SIX_MONTHLY.equals( type ) )
190 {
191 int year = Integer.parseInt( matcher.group( 1 ) );
192 int semester = Integer.parseInt( matcher.group( 2 ) );
193
194 // valid six-monthly are from 1 - 2
195 if ( semester < 1 || semester > 2 )
196 {
197 return null;
198 }
199
200 DateUnit start = new DateUnit( year, semester == 1 ? 1 : 7, 1 );
201 DateUnit end = new DateUnit( start );
202 end = getCalendar().plusMonths( end, 6 );
203 end = getCalendar().minusDays( end, 1 );
204
205 start.setDayOfWeek( getCalendar().weekday( start ) );
206 end.setDayOfWeek( getCalendar().weekday( end ) );
207
208 return new DateInterval( start, end );
209 }
210 else if ( DateUnitType.SIX_MONTHLY_APRIL.equals( type ) )
211 {
212 int year = Integer.parseInt( matcher.group( 1 ) );
213 int semester = Integer.parseInt( matcher.group( 2 ) );
214
215 // valid six-monthly are from 1 - 2
216 if ( semester < 1 || semester > 2 )
217 {
218 return null;
219 }
220
221 DateUnit start = new DateUnit( year, semester == 1 ? 4 : 10, 1 );
222 DateUnit end = new DateUnit( start );
223 end = getCalendar().plusMonths( end, 6 );
224 end = getCalendar().minusDays( end, 1 );
225
226 start.setDayOfWeek( getCalendar().weekday( start ) );
227 end.setDayOfWeek( getCalendar().weekday( end ) );
228
229 return new DateInterval( start, end );
230 }
231 else if ( DateUnitType.YEARLY.equals( type ) )
232 {
233 int year = Integer.parseInt( matcher.group( 1 ) );
234
235 DateUnit start = new DateUnit( year, 1, 1 );
236 DateUnit end = new DateUnit( year, getCalendar().monthsInYear(),
237 getCalendar().daysInMonth( start.getYear(), getCalendar().monthsInYear() ) );
238
239 start.setDayOfWeek( getCalendar().weekday( start ) );
240 end.setDayOfWeek( getCalendar().weekday( end ) );
241
242 return new DateInterval( start, end );
243 }
244 else if ( DateUnitType.FINANCIAL_APRIL.equals( type ) )
245 {
246 int year = Integer.parseInt( matcher.group( 1 ) );
247
248 DateUnit start = new DateUnit( year, 4, 1 );
249 DateUnit end = new DateUnit( start );
250 end = getCalendar().plusYears( end, 1 );
251 end = getCalendar().minusDays( end, 1 );
252
253 start.setDayOfWeek( getCalendar().weekday( start ) );
254 end.setDayOfWeek( getCalendar().weekday( end ) );
255
256 return new DateInterval( start, end );
257 }
258 else if ( DateUnitType.FINANCIAL_JULY.equals( type ) )
259 {
260 int year = Integer.parseInt( matcher.group( 1 ) );
261
262 DateUnit start = new DateUnit( year, 7, 1 );
263 DateUnit end = new DateUnit( start );
264 end = getCalendar().plusYears( end, 1 );
265 end = getCalendar().minusDays( end, 1 );
266
267 start.setDayOfWeek( getCalendar().weekday( start ) );
268 end.setDayOfWeek( getCalendar().weekday( end ) );
269
270 return new DateInterval( start, end );
271 }
272 else if ( DateUnitType.FINANCIAL_OCTOBER.equals( type ) )
273 {
274 int year = Integer.parseInt( matcher.group( 1 ) );
275
276 DateUnit start = new DateUnit( year, 10, 1 );
277 DateUnit end = new DateUnit( start );
278 end = getCalendar().plusYears( end, 1 );
279 end = getCalendar().minusDays( end, 1 );
280
281 start.setDayOfWeek( getCalendar().weekday( start ) );
282 end.setDayOfWeek( getCalendar().weekday( end ) );
283
284 return new DateInterval( start, end );
285 }
286
287 return null;
288 }
289}
0290
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnitType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnitType.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnitType.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,92 @@
1package org.hisp.dhis.calendar;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31import org.hisp.dhis.period.BiMonthlyPeriodType;
32import org.hisp.dhis.period.DailyPeriodType;
33import org.hisp.dhis.period.FinancialAprilPeriodType;
34import org.hisp.dhis.period.FinancialJulyPeriodType;
35import org.hisp.dhis.period.FinancialOctoberPeriodType;
36import org.hisp.dhis.period.MonthlyPeriodType;
37import org.hisp.dhis.period.QuarterlyPeriodType;
38import org.hisp.dhis.period.SixMonthlyAprilPeriodType;
39import org.hisp.dhis.period.SixMonthlyPeriodType;
40import org.hisp.dhis.period.WeeklyPeriodType;
41import org.hisp.dhis.period.YearlyPeriodType;
42
43/**
44 * @author Morten Olav Hansen <mortenoh@gmail.com>
45 */
46public enum DateUnitType
47{
48 DAILY( DailyPeriodType.NAME, "\\b(\\d{4})(\\d{2})(\\d{2})\\b" ),
49 WEEKLY( WeeklyPeriodType.NAME, "\\b(\\d{4})W(\\d[\\d]?)\\b" ),
50 MONTHLY( MonthlyPeriodType.NAME, "\\b(\\d{4})[-]?(\\d{2})\\b" ),
51 BI_MONTHLY( BiMonthlyPeriodType.NAME, "\\b(\\d{4})(\\d{2})B\\b" ),
52 QUARTERLY( QuarterlyPeriodType.NAME, "\\b(\\d{4})Q(\\d)\\b" ),
53 SIX_MONTHLY( SixMonthlyPeriodType.NAME, "\\b(\\d{4})S(\\d)\\b" ),
54 SIX_MONTHLY_APRIL( SixMonthlyAprilPeriodType.NAME, "\\b(\\d{4})AprilS(\\d)\\b" ),
55 YEARLY( YearlyPeriodType.NAME, "\\b(\\d{4})\\b" ),
56 FINANCIAL_APRIL( FinancialAprilPeriodType.NAME, "\\b(\\d{4})April\\b" ),
57 FINANCIAL_JULY( FinancialJulyPeriodType.NAME, "\\b(\\d{4})July\\b" ),
58 FINANCIAL_OCTOBER( FinancialOctoberPeriodType.NAME, "\\b(\\d{4})Oct\\b" );
59
60 private final String type;
61
62 private final String format;
63
64 public String getType()
65 {
66 return type;
67 }
68
69 public String getFormat()
70 {
71 return format;
72 }
73
74 DateUnitType( String type, String format )
75 {
76 this.type = type;
77 this.format = format;
78 }
79
80 public static DateUnitType find( String format )
81 {
82 for ( DateUnitType type : DateUnitType.values() )
83 {
84 if ( format.matches( type.format ) )
85 {
86 return type;
87 }
88 }
89
90 return null;
91 }
92}
093
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/PeriodTypeParser.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/PeriodTypeParser.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/PeriodTypeParser.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,37 @@
1package org.hisp.dhis.calendar;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * @author Morten Olav Hansen <mortenoh@gmail.com>
33 */
34public interface PeriodTypeParser
35{
36 public DateInterval parse( String period );
37}
038
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/TimeUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/TimeUnit.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/TimeUnit.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,154 @@
1package org.hisp.dhis.calendar;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31import org.joda.time.DateTime;
32
33import java.util.Calendar;
34import java.util.Date;
35
36/**
37 * Simple class to hold information about time, can be used together with DateUnit to form
38 * a DateTimeUnit which holds both date and time information. Useful in cases where converting
39 * from a JDK Date/Calendar and you don't want to loose the time dimension.
40 *
41 * @author Morten Olav Hansen <mortenoh@gmail.com>
42 * @see DateUnit
43 * @see DateTimeUnit
44 */
45public class TimeUnit
46{
47 /**
48 * Hour of day, range is 1 - 24.
49 */
50 private int hour;
51
52 /**
53 * Minute of day, range is 0 - 59.
54 */
55 private int minute;
56
57 /**
58 * Second of day, range is 0 - 59.
59 */
60 private int second;
61
62 public TimeUnit()
63 {
64 }
65
66 public TimeUnit( int hour, int minute, int second )
67 {
68 this.hour = hour;
69 this.minute = minute;
70 this.second = second;
71 }
72
73 public int getHour()
74 {
75 return hour;
76 }
77
78 public void setHour( int hour )
79 {
80 this.hour = hour;
81 }
82
83 public int getMinute()
84 {
85 return minute;
86 }
87
88 public void setMinute( int minute )
89 {
90 this.minute = minute;
91 }
92
93 public int getSecond()
94 {
95 return second;
96 }
97
98 public void setSecond( int second )
99 {
100 this.second = second;
101 }
102
103 public static TimeUnit fromDateTime( DateTime dateTime )
104 {
105 return new TimeUnit( dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute() );
106 }
107
108 public static TimeUnit fromJdkCalendar( Calendar calendar )
109 {
110 int amPm = calendar.get( Calendar.AM_PM );
111
112 return new TimeUnit( calendar.get( Calendar.HOUR ) + (amPm * 12), calendar.get( Calendar.MINUTE ),
113 calendar.get( Calendar.SECOND ) );
114 }
115
116 public static TimeUnit fromJdkDate( Date date )
117 {
118 return fromDateTime( new DateTime( date.getTime() ) );
119 }
120
121 @Override
122 public boolean equals( Object o )
123 {
124 if ( this == o ) return true;
125 if ( o == null || getClass() != o.getClass() ) return false;
126
127 TimeUnit timeUnit = (TimeUnit) o;
128
129 if ( hour != timeUnit.hour ) return false;
130 if ( minute != timeUnit.minute ) return false;
131 if ( second != timeUnit.second ) return false;
132
133 return true;
134 }
135
136 @Override
137 public int hashCode()
138 {
139 int result = hour;
140 result = 31 * result + minute;
141 result = 31 * result + second;
142 return result;
143 }
144
145 @Override
146 public String toString()
147 {
148 return "TimeUnit{" +
149 "hour=" + hour +
150 ", minute=" + minute +
151 ", second=" + second +
152 '}';
153 }
154}
0155
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java 2014-05-12 07:52:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java 2014-06-05 17:39:07 +0000
@@ -49,7 +49,7 @@
49{49{
50 private static final DateUnit startNepal = new DateUnit( 2000, 1, 1, java.util.Calendar.WEDNESDAY );50 private static final DateUnit startNepal = new DateUnit( 2000, 1, 1, java.util.Calendar.WEDNESDAY );
5151
52 private static final DateUnit startIso = new DateUnit( 1943, 4, 14, java.util.Calendar.WEDNESDAY );52 private static final DateUnit startIso = new DateUnit( 1943, 4, 14, java.util.Calendar.WEDNESDAY, true );
5353
54 private static final Calendar self = new NepaliCalendar();54 private static final Calendar self = new NepaliCalendar();
5555
@@ -85,7 +85,7 @@
8585
86 dateTime = dateTime.plusDays( totalDays );86 dateTime = dateTime.plusDays( totalDays );
8787
88 return DateUnit.fromDateTime( dateTime );88 return new DateUnit( DateUnit.fromDateTime( dateTime ), true );
89 }89 }
9090
91 @Override91 @Override
@@ -219,6 +219,13 @@
219 }219 }
220220
221 @Override221 @Override
222 public int weeksInYear( int year )
223 {
224 DateTime dateTime = new DateTime( year, 1, 1, 0, 0, ISOChronology.getInstance() );
225 return dateTime.weekOfWeekyear().getMaximumValue();
226 }
227
228 @Override
222 public int isoWeek( DateUnit dateUnit )229 public int isoWeek( DateUnit dateUnit )
223 {230 {
224 DateTime dateTime = toIso( dateUnit ).toDateTime( ISOChronology.getInstance() );231 DateTime dateTime = toIso( dateUnit ).toDateTime( ISOChronology.getInstance() );
225232
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AuditLogUtil.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AuditLogUtil.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AuditLogUtil.java 2014-06-05 17:39:07 +0000
@@ -28,6 +28,7 @@
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */29 */
3030
31import javassist.util.proxy.ProxyFactory;
31import org.apache.commons.logging.Log;32import org.apache.commons.logging.Log;
3233
33public class AuditLogUtil34public class AuditLogUtil
@@ -52,7 +53,15 @@
52 StringBuilder builder = new StringBuilder();53 StringBuilder builder = new StringBuilder();
5354
54 builder.append( "'" ).append( username ).append( "' " ).append( action );55 builder.append( "'" ).append( username ).append( "' " ).append( action );
55 builder.append( " " ).append( object.getClass().getName() );56
57 if ( !ProxyFactory.isProxyClass( object.getClass() ) )
58 {
59 builder.append( " " ).append( object.getClass().getName() );
60 }
61 else
62 {
63 builder.append( " " ).append( object.getClass().getSuperclass().getName() );
64 }
5665
57 if ( idObject.getName() != null && !idObject.getName().isEmpty() )66 if ( idObject.getName() != null && !idObject.getName().isEmpty() )
58 {67 {
5968
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java 2014-06-05 17:39:07 +0000
@@ -30,6 +30,8 @@
3030
31import java.util.List;31import java.util.List;
3232
33import org.hisp.dhis.user.User;
34
33/**35/**
34 * @author Lars Helge Overland36 * @author Lars Helge Overland
35 */37 */
@@ -39,9 +41,13 @@
39 41
40 List<NameableObject> getCanReadDimensionItems( String uid );42 List<NameableObject> getCanReadDimensionItems( String uid );
41 43
44 <T extends IdentifiableObject> List<T> filterCanRead( User user, List<T> objects );
45
42 DimensionType getDimensionType( String uid );46 DimensionType getDimensionType( String uid );
43 47
44 List<DimensionalObject> getAllDimensions();48 List<DimensionalObject> getAllDimensions();
45 49
50 List<DimensionalObject> getDimensionConstraints();
51
46 void mergeAnalyticalObject( BaseAnalyticalObject object );52 void mergeAnalyticalObject( BaseAnalyticalObject object );
47}53}
4854
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ListMap.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ListMap.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ListMap.java 2014-06-05 17:39:07 +0000
@@ -31,6 +31,7 @@
31import java.util.ArrayList;31import java.util.ArrayList;
32import java.util.HashMap;32import java.util.HashMap;
33import java.util.List;33import java.util.List;
34import java.util.Map;
3435
35/**36/**
36 * @author Lars Helge Overland37 * @author Lars Helge Overland
@@ -38,6 +39,11 @@
38public class ListMap<T, V>39public class ListMap<T, V>
39 extends HashMap<T, List<V>>40 extends HashMap<T, List<V>>
40{41{
42 /**
43 * Determines if a de-serialized file is compatible with this class.
44 */
45 private static final long serialVersionUID = 4880664228933342003L;
46
41 public ListMap()47 public ListMap()
42 {48 {
43 super();49 super();
@@ -56,4 +62,12 @@
56 super.put( key, list ); 62 super.put( key, list );
57 return null;63 return null;
58 }64 }
65
66 public void putValueMap( Map<T, V> map )
67 {
68 for ( Map.Entry<T, V> entry : map.entrySet() )
69 {
70 putValue( entry.getKey(), entry.getValue() );
71 }
72 }
59}73}
6074
=== renamed file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MapMap.java' => 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/MapMap.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MapMap.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/MapMap.java 2014-06-05 17:39:07 +0000
@@ -1,4 +1,4 @@
1package org.hisp.dhis.system.util;1package org.hisp.dhis.common;
22
3/*3/*
4 * Copyright (c) 2004-2014, University of Oslo4 * Copyright (c) 2004-2014, University of Oslo
@@ -52,4 +52,9 @@
52 map.putAll( m );52 map.putAll( m );
53 this.put( key, map );53 this.put( key, map );
54 }54 }
55
56 public V getValue( T key, U valueKey )
57 {
58 return this.get( key ) == null ? null : this.get( key ).get( valueKey );
59 }
55}60}
5661
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SetMap.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SetMap.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SetMap.java 2014-06-05 17:39:07 +0000
@@ -55,4 +55,11 @@
55 set.add( value );55 set.add( value );
56 return super.put( key, set );56 return super.put( key, set );
57 }57 }
58
59 public Set<V> getSet( T key )
60 {
61 Set<V> set = this.get( key );
62 set = set == null ? new HashSet<V>() : set;
63 return super.put( key, set );
64 }
58}65}
5966
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java 2014-04-25 11:22:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java 2014-06-05 17:39:07 +0000
@@ -28,6 +28,7 @@
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */29 */
3030
31import java.util.Date;
31import java.util.HashSet;32import java.util.HashSet;
32import java.util.Set;33import java.util.Set;
3334
@@ -59,6 +60,10 @@
5960
60 public static final String DEFAULT_NAME = "default";61 public static final String DEFAULT_NAME = "default";
6162
63 private Date startDate;
64
65 private Date endDate;
66
62 private Set<DataElementCategory> categories = new HashSet<DataElementCategory>();67 private Set<DataElementCategory> categories = new HashSet<DataElementCategory>();
6368
64 @Scanned69 @Scanned
@@ -152,6 +157,30 @@
152 }157 }
153158
154 @JsonProperty159 @JsonProperty
160 @JsonView( {DetailedView.class } )
161 public Date getStartDate()
162 {
163 return startDate;
164 }
165
166 public void setStartDate( Date startDate )
167 {
168 this.startDate = startDate;
169 }
170
171 @JsonProperty
172 @JsonView( {DetailedView.class } )
173 public Date getEndDate()
174 {
175 return endDate;
176 }
177
178 public void setEndDate( Date endDate )
179 {
180 this.endDate = endDate;
181 }
182
183 @JsonProperty
155 @JsonSerialize(contentAs = BaseIdentifiableObject.class)184 @JsonSerialize(contentAs = BaseIdentifiableObject.class)
156 @JsonView({ DetailedView.class })185 @JsonView({ DetailedView.class })
157 @JacksonXmlElementWrapper(localName = "categories", namespace = DxfNamespaces.DXF_2_0)186 @JacksonXmlElementWrapper(localName = "categories", namespace = DxfNamespaces.DXF_2_0)
158187
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java 2014-04-17 14:19:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java 2014-06-05 17:39:07 +0000
@@ -30,9 +30,12 @@
3030
31import java.util.Collection;31import java.util.Collection;
32import java.util.Date;32import java.util.Date;
33import java.util.Map;33import java.util.Set;
3434
35import org.hisp.dhis.common.MapMap;
36import org.hisp.dhis.dataelement.CategoryOptionGroup;
35import org.hisp.dhis.dataelement.DataElement;37import org.hisp.dhis.dataelement.DataElement;
38import org.hisp.dhis.dataelement.DataElementCategoryOption;
36import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;39import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
37import org.hisp.dhis.dataelement.DataElementOperand;40import org.hisp.dhis.dataelement.DataElementOperand;
38import org.hisp.dhis.organisationunit.OrganisationUnit;41import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -296,33 +299,26 @@
296 * @return the number of DataValues.299 * @return the number of DataValues.
297 */300 */
298 int getDataValueCount( int days );301 int getDataValueCount( int days );
299
300 /**
301 * Returns a map of values indexed by DataElementOperand.
302 *
303 * @param dataElements collection of DataElements to fetch for
304 * @param period period for which to fetch the values
305 * @param unit OrganisationUnit for which to fetch the values
306 * @return
307 */
308 Map<DataElementOperand, Double> getDataValueMap( Collection<DataElement> dataElements, Period period, OrganisationUnit source );
309302
310 /**303 /**
311 * Returns a map of values indexed by DataElementOperand.304 * Returns a map of values for each attribute option combo found.
312 * 305 * <p>
313 * In the (unlikely) event that the same dataElement/optionCombo is found in306 * In the (unlikely) event that the same dataElement/optionCombo is found in
314 * more than one period for the same organisationUnit and date, the value307 * more than one period for the same organisationUnit, date, and attribute
315 * is returned from the period with the shortest duration.308 * combo, the value is returned from the period with the shortest duration.
316 * 309 *
317 * @param dataElements collection of DataElements to fetch for310 * @param dataElements collection of DataElements to fetch for
318 * @param date date which must be present in the period311 * @param date date which must be present in the period
319 * @param unit OrganisationUnit for which to fetch the values312 * @param source OrganisationUnit for which to fetch the values
320 * @param periodTypes allowable period types in which to find the data313 * @param periodTypes allowable period types in which to find the data
314 * @param attributeCombo the attribute combo to check (if restricted)
321 * @param lastUpdatedMap map in which to return the lastUpdated date for each value315 * @param lastUpdatedMap map in which to return the lastUpdated date for each value
322 * @return316 * @return map of values by attribute option combo id, then DataElementOperand
323 */317 */
324 Map<DataElementOperand, Double> getDataValueMap( Collection<DataElement> dataElements, Date date, OrganisationUnit source,318 MapMap<Integer, DataElementOperand, Double> getDataValueMapByAttributeCombo( Collection<DataElement> dataElements, Date date,
325 Collection<PeriodType> periodTypes, Map<DataElementOperand, Date> lastUpdatedMap );319 OrganisationUnit source, Collection<PeriodType> periodTypes, DataElementCategoryOptionCombo attributeCombo,
320 Set<CategoryOptionGroup> cogDimensionConstraints, Set<DataElementCategoryOption> coDimensionConstraints,
321 MapMap<Integer, DataElementOperand, Date> lastUpdatedMap );
326322
327 /**323 /**
328 * Gets a Collection of DeflatedDataValues.324 * Gets a Collection of DeflatedDataValues.
329325
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java 2014-06-05 17:39:07 +0000
@@ -30,9 +30,12 @@
3030
31import java.util.Collection;31import java.util.Collection;
32import java.util.Date;32import java.util.Date;
33import java.util.Map;33import java.util.Set;
3434
35import org.hisp.dhis.common.MapMap;
36import org.hisp.dhis.dataelement.CategoryOptionGroup;
35import org.hisp.dhis.dataelement.DataElement;37import org.hisp.dhis.dataelement.DataElement;
38import org.hisp.dhis.dataelement.DataElementCategoryOption;
36import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;39import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
37import org.hisp.dhis.dataelement.DataElementOperand;40import org.hisp.dhis.dataelement.DataElementOperand;
38import org.hisp.dhis.organisationunit.OrganisationUnit;41import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -229,19 +232,19 @@
229 * collection of Periods, and collection of Sources.232 * collection of Periods, and collection of Sources.
230 * 233 *
231 * @param dataElement the DataElements of the DataValues.234 * @param dataElement the DataElements of the DataValues.
232 * @param optionCombo the DataElementCategoryOptionCombo of the DataValues.235 * @param categoryOptionCombo the DataElementCategoryOptionCombo of the DataValues.
233 * @param periods the Periods of the DataValues.236 * @param periods the Periods of the DataValues.
234 * @param sources the Sources of the DataValues.237 * @param sources the Sources of the DataValues.
235 * @return a collection of all DataValues which match the given DataElement,238 * @return a collection of all DataValues which match the given DataElement,
236 * Periods, and Sources.239 * Periods, and Sources.
237 */240 */
238 Collection<DataValue> getDataValues( DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombos, 241 Collection<DataValue> getDataValues( DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo,
239 Collection<Period> periods, Collection<OrganisationUnit> sources );242 Collection<Period> periods, Collection<OrganisationUnit> sources );
240 243
241 /**244 /**
242 * Returns all DataValues for a given collection of DataElementCategoryOptionCombos.245 * Returns all DataValues for a given collection of DataElementCategoryOptionCombos.
243 * 246 *
244 * @param optionCombos the DataElementCategoryOptionCombos of the DataValue.247 * @param categoryOptionCombos the DataElementCategoryOptionCombos of the DataValue.
245 * @return a collection of all DataValues which match the given collection of248 * @return a collection of all DataValues which match the given collection of
246 * DataElementCategoryOptionCombos.249 * DataElementCategoryOptionCombos.
247 */250 */
@@ -273,34 +276,26 @@
273 * @return the number of DataValues.276 * @return the number of DataValues.
274 */277 */
275 int getDataValueCount( Date date );278 int getDataValueCount( Date date );
276
277 /**
278 * Returns a map of values indexed by DataElementOperand.
279 *
280 * @param dataElements collection of DataElements to fetch for
281 * @param period period for which to fetch the values
282 * @param unit OrganisationUnit for which to fetch the values
283 * @param lastUpdatedMap optional map in which to return the lastUpdated date for each value
284 * @return
285 */
286 Map<DataElementOperand, Double> getDataValueMap( Collection<DataElement> dataElements, Period period, OrganisationUnit source );
287279
288 /**280 /**
289 * Returns a map of values indexed by DataElementOperand.281 * Returns a map of values for each attribute option combo found.
290 * 282 * <p>
291 * In the (unlikely) event that the same dataElement/optionCombo is found in283 * In the (unlikely) event that the same dataElement/optionCombo is found in
292 * more than one period for the same organisationUnit and date, the value284 * more than one period for the same organisationUnit, date, and attribute
293 * is returned from the period with the shortest duration.285 * combo, the value is returned from the period with the shortest duration.
294 * 286 *
295 * @param dataElements collection of DataElements to fetch for287 * @param dataElements collection of DataElements to fetch for
296 * @param date date which must be present in the period288 * @param date date which must be present in the period
297 * @param unit OrganisationUnit for which to fetch the values289 * @param source OrganisationUnit for which to fetch the values
298 * @param periodTypes allowable period types in which to find the data290 * @param periodTypes allowable period types in which to find the data
291 * @param attributeCombo the attribute combo to check (if restricted)
299 * @param lastUpdatedMap map in which to return the lastUpdated date for each value292 * @param lastUpdatedMap map in which to return the lastUpdated date for each value
300 * @return293 * @return map of values by attribute option combo id, then DataElementOperand
301 */294 */
302 Map<DataElementOperand, Double> getDataValueMap( Collection<DataElement> dataElements, Date date, OrganisationUnit source,295 public MapMap<Integer, DataElementOperand, Double> getDataValueMapByAttributeCombo( Collection<DataElement> dataElements, Date date,
303 Collection<PeriodType> periodTypes, Map<DataElementOperand, Date> lastUpdatedMap );296 OrganisationUnit source, Collection<PeriodType> periodTypes, DataElementCategoryOptionCombo attributeCombo,
297 Set<CategoryOptionGroup> cogDimensionConstraints, Set<DataElementCategoryOption> coDimensionConstraints,
298 MapMap<Integer, DataElementOperand, Date> lastUpdatedMap );
304 299
305 /**300 /**
306 * Gets a Collection of DeflatedDataValues.301 * Gets a Collection of DeflatedDataValues.
307302
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventreport/EventReport.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventreport/EventReport.java 2014-05-12 23:03:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventreport/EventReport.java 2014-06-05 17:39:07 +0000
@@ -28,10 +28,11 @@
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */29 */
3030
31import java.util.ArrayList;31import com.fasterxml.jackson.annotation.JsonProperty;
32import java.util.Date;32import com.fasterxml.jackson.annotation.JsonView;
33import java.util.List;33import com.fasterxml.jackson.databind.annotation.JsonSerialize;
3434import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
35import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
35import org.hisp.dhis.common.BaseAnalyticalObject;36import org.hisp.dhis.common.BaseAnalyticalObject;
36import org.hisp.dhis.common.BaseIdentifiableObject;37import org.hisp.dhis.common.BaseIdentifiableObject;
37import org.hisp.dhis.common.DxfNamespaces;38import org.hisp.dhis.common.DxfNamespaces;
@@ -45,11 +46,9 @@
45import org.hisp.dhis.program.ProgramStage;46import org.hisp.dhis.program.ProgramStage;
46import org.hisp.dhis.user.User;47import org.hisp.dhis.user.User;
4748
48import com.fasterxml.jackson.annotation.JsonProperty;49import java.util.ArrayList;
49import com.fasterxml.jackson.annotation.JsonView;50import java.util.Date;
50import com.fasterxml.jackson.databind.annotation.JsonSerialize;51import java.util.List;
51import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
52import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
5352
54/**53/**
55 * @author Lars Helge Overland54 * @author Lars Helge Overland
@@ -183,39 +182,6 @@
183 }182 }
184 }183 }
185184
186 @Override
187 public void mergeWith( IdentifiableObject other )
188 {
189 super.mergeWith( other );
190
191 if ( other.getClass().isInstance( this ) )
192 {
193 EventReport report = (EventReport) other;
194
195 dataType = report.getDataType();
196 program = report.getProgram();
197 programStage = report.getProgramStage();
198 startDate = report.getStartDate();
199 endDate = report.getEndDate();
200 totals = report.isTotals();
201 subtotals = report.isSubtotals();
202 hideEmptyRows = report.isHideEmptyRows();
203 countType = report.getCountType();
204 showHierarchy = report.isShowHierarchy();
205 displayDensity = report.getDisplayDensity();
206 fontSize = report.getFontSize();
207
208 columnDimensions.clear();
209 columnDimensions.addAll( report.getColumnDimensions() );
210
211 rowDimensions.clear();
212 rowDimensions.addAll( report.getRowDimensions() );
213
214 filterDimensions.clear();
215 filterDimensions.addAll( report.getFilterDimensions() );
216 }
217 }
218
219 // -------------------------------------------------------------------------185 // -------------------------------------------------------------------------
220 // Getters and setters186 // Getters and setters
221 // -------------------------------------------------------------------------187 // -------------------------------------------------------------------------
@@ -419,4 +385,37 @@
419 {385 {
420 this.fontSize = fontSize;386 this.fontSize = fontSize;
421 }387 }
388
389 @Override
390 public void mergeWith( IdentifiableObject other )
391 {
392 super.mergeWith( other );
393
394 if ( other.getClass().isInstance( this ) )
395 {
396 EventReport eventReport = (EventReport) other;
397
398 dataType = eventReport.getDataType();
399 program = eventReport.getProgram();
400 programStage = eventReport.getProgramStage();
401 startDate = eventReport.getStartDate();
402 endDate = eventReport.getEndDate();
403 totals = eventReport.isTotals();
404 subtotals = eventReport.isSubtotals();
405 hideEmptyRows = eventReport.isHideEmptyRows();
406 countType = eventReport.getCountType();
407 showHierarchy = eventReport.isShowHierarchy();
408 displayDensity = eventReport.getDisplayDensity();
409 fontSize = eventReport.getFontSize();
410
411 columnDimensions.clear();
412 columnDimensions.addAll( eventReport.getColumnDimensions() );
413
414 rowDimensions.clear();
415 rowDimensions.addAll( eventReport.getRowDimensions() );
416
417 filterDimensions.clear();
418 filterDimensions.addAll( eventReport.getFilterDimensions() );
419 }
420 }
422}421}
423422
=== added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node'
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,178 @@
1package org.hisp.dhis.node;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import com.google.common.collect.ImmutableList;
32import com.google.common.collect.Lists;
33import org.hisp.dhis.node.exception.InvalidTypeException;
34
35import java.util.List;
36
37/**
38 * @author Morten Olav Hansen <mortenoh@gmail.com>
39 */
40public abstract class AbstractNode implements Node
41{
42 private String name;
43
44 private final NodeType nodeType;
45
46 private String namespace;
47
48 private String comment;
49
50 private List<Node> children = Lists.newArrayList();
51
52 protected AbstractNode( String name, NodeType nodeType )
53 {
54 this.name = name;
55 this.nodeType = nodeType;
56 }
57
58 @Override
59 public String getName()
60 {
61 return name;
62 }
63
64 public void setName( String name )
65 {
66 this.name = name;
67 }
68
69 @Override
70 public NodeType getType()
71 {
72 return nodeType;
73 }
74
75 @Override
76 public boolean is( NodeType type )
77 {
78 return type.equals( nodeType );
79 }
80
81 @Override
82 public boolean isSimple()
83 {
84 return is( NodeType.SIMPLE );
85 }
86
87 @Override
88 public boolean isComplex()
89 {
90 return is( NodeType.COMPLEX );
91 }
92
93 @Override
94 public boolean isCollection()
95 {
96 return is( NodeType.COLLECTION );
97 }
98
99 @Override
100 public String getNamespace()
101 {
102 return namespace;
103 }
104
105 public void setNamespace( String namespace )
106 {
107 this.namespace = namespace;
108 }
109
110 @Override
111 public String getComment()
112 {
113 return comment;
114 }
115
116 public void setComment( String comment )
117 {
118 this.comment = comment;
119 }
120
121 @Override
122 public <T extends Node> T addChild( T child ) throws InvalidTypeException
123 {
124 if ( child == null || child.getName() == null )
125 {
126 return null;
127 }
128
129 children.add( child );
130 return child;
131 }
132
133 @Override
134 public <T extends Node> void addChildren( Iterable<T> children )
135 {
136 for ( Node child : children )
137 {
138 addChild( child );
139 }
140 }
141
142 @Override
143 public List<Node> getChildren()
144 {
145 return ImmutableList.copyOf( children );
146 }
147
148 @Override
149 public boolean equals( Object o )
150 {
151 if ( this == o ) return true;
152 if ( o == null || getClass() != o.getClass() ) return false;
153
154 AbstractNode that = (AbstractNode) o;
155
156 if ( name != null ? !name.equals( that.name ) : that.name != null ) return false;
157
158 return true;
159 }
160
161 @Override
162 public int hashCode()
163 {
164 return name != null ? name.hashCode() : 0;
165 }
166
167 @Override
168 public String toString()
169 {
170 return "Node{" +
171 "name='" + name + '\'' +
172 ", nodeType=" + nodeType +
173 ", namespace='" + namespace + '\'' +
174 ", comment='" + comment + '\'' +
175 ", children=" + children +
176 '}';
177 }
178}
0179
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Node.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Node.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Node.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,124 @@
1package org.hisp.dhis.node;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import java.util.List;
32
33/**
34 * @author Morten Olav Hansen <mortenoh@gmail.com>
35 */
36public interface Node
37{
38 /**
39 * Name of this node.
40 *
41 * @return current name of node
42 */
43 String getName();
44
45 /**
46 * Type specifier for this node.
47 *
48 * @return Node type
49 * @see org.hisp.dhis.node.NodeType
50 */
51 NodeType getType();
52
53 /**
54 * @param type Type to check for
55 * @return True if node is of this type
56 */
57 boolean is( NodeType type );
58
59 /**
60 * Helper that checks if node is of simple type, useful to checking if
61 * you are allowed to add children to this node.
62 *
63 * @return true if type is simple
64 * @see org.hisp.dhis.node.NodeType
65 */
66 boolean isSimple();
67
68 /**
69 * Helper that checks if node is of complex type.
70 *
71 * @return true if type is complex
72 * @see org.hisp.dhis.node.NodeType
73 */
74 boolean isComplex();
75
76 /**
77 * Helper that checks if node is of collection type.
78 *
79 * @return true if type is collection
80 * @see org.hisp.dhis.node.NodeType
81 */
82 boolean isCollection();
83
84 /**
85 * Namespace for this node. Not all serializers support this, and its up to the
86 * NodeSerializer implementation to decide what to do with this.
87 *
88 * @return namespace
89 * @see org.hisp.dhis.node.NodeSerializer
90 */
91 String getNamespace();
92
93 /**
94 * Comment for this node. Not all serializers support this, and its up to the
95 * NodeSerializer implementation to decide what to do with this.
96 *
97 * @return namespace
98 * @see org.hisp.dhis.node.NodeSerializer
99 */
100 String getComment();
101
102 /**
103 * Adds a child to this node.
104 *
105 * @param child Child node to add
106 * @return Child node that was added
107 */
108 <T extends Node> T addChild( T child );
109
110 /**
111 * Adds a collection of children to this node.
112 *
113 * @param children Child nodes to add
114 */
115 <T extends Node> void addChildren( Iterable<T> children );
116
117 /**
118 * Get all child notes associated with this node. Please note that the returned list is a copy
119 * of the internal list, and changes to the list will not be reflected in the node.
120 *
121 * @return List of child nodes associated with this node
122 */
123 List<Node> getChildren();
124}
0125
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeDeserializer.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeDeserializer.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeDeserializer.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,45 @@
1package org.hisp.dhis.node;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import org.hisp.dhis.node.types.RootNode;
32
33import java.io.IOException;
34import java.io.InputStream;
35import java.util.List;
36
37/**
38 * @author Morten Olav Hansen <mortenoh@gmail.com>
39 */
40public interface NodeDeserializer
41{
42 List<String> contentTypes();
43
44 RootNode deserialize( InputStream inputStream ) throws IOException;
45}
046
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeSerializer.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeSerializer.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeSerializer.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,45 @@
1package org.hisp.dhis.node;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import org.hisp.dhis.node.types.RootNode;
32
33import java.io.IOException;
34import java.io.OutputStream;
35import java.util.List;
36
37/**
38 * @author Morten Olav Hansen <mortenoh@gmail.com>
39 */
40public interface NodeSerializer
41{
42 List<String> contentTypes();
43
44 void serialize( RootNode rootNode, OutputStream outputStream ) throws IOException;
45}
046
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeService.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,75 @@
1package org.hisp.dhis.node;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import org.hisp.dhis.node.types.RootNode;
32
33import java.io.IOException;
34import java.io.InputStream;
35import java.io.OutputStream;
36
37/**
38 * @author Morten Olav Hansen <mortenoh@gmail.com>
39 */
40public interface NodeService
41{
42 /**
43 * Find a nodeSerializer that supports contentType or return null.
44 *
45 * @param contentType NodeSerializer contentType
46 * @return NodeSerializer that support contentType, or null if not match was found
47 * @see org.hisp.dhis.node.NodeSerializer
48 */
49 NodeSerializer getNodeSerializer( String contentType );
50
51 /**
52 * Write out rootNode to a nodeSerializer that matches the contentType.
53 *
54 * @param rootNode RootNode to write
55 * @param contentType NodeSerializer contentType
56 * @param outputStream Write to this outputStream
57 */
58 void serialize( RootNode rootNode, String contentType, OutputStream outputStream ) throws IOException;
59
60 /**
61 * Find a nodeDeserializer that supports contentType or return null.
62 *
63 * @param contentType NodeDeserializer contentType
64 * @return NodeDeserializer that support contentType, or null if not match was found
65 * @see org.hisp.dhis.node.NodeDeserializer
66 */
67 NodeDeserializer getNodeDeserializer( String contentType );
68
69 /**
70 * @param contentType NodeDeserializer contentType
71 * @param inputStream Read RootNode from this stream
72 * @return RootNode deserialized from inputStream
73 */
74 RootNode deserialize( String contentType, InputStream inputStream ) throws IOException;
75}
076
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeType.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeType.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,39 @@
1package org.hisp.dhis.node;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31/**
32 * @author Morten Olav Hansen <mortenoh@gmail.com>
33 */
34public enum NodeType
35{
36 SIMPLE,
37 COMPLEX,
38 COLLECTION
39}
040
=== added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation'
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/ExportCollection.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/ExportCollection.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/ExportCollection.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,54 @@
1package org.hisp.dhis.node.annotation;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import java.lang.annotation.ElementType;
32import java.lang.annotation.Retention;
33import java.lang.annotation.RetentionPolicy;
34import java.lang.annotation.Target;
35
36/**
37 * @author Morten Olav Hansen <mortenoh@gmail.com>
38 */
39@Target( { ElementType.FIELD, ElementType.METHOD } )
40@Retention( RetentionPolicy.RUNTIME )
41public @interface ExportCollection
42{
43 String value() default "";
44
45 String namespace() default "";
46
47 String itemName() default "";
48
49 String itemNamespace() default "";
50
51 boolean owner() default false;
52
53 boolean useWrapping() default true;
54}
055
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/ExportComplex.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/ExportComplex.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/ExportComplex.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,46 @@
1package org.hisp.dhis.node.annotation;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import java.lang.annotation.ElementType;
32import java.lang.annotation.Retention;
33import java.lang.annotation.RetentionPolicy;
34import java.lang.annotation.Target;
35
36/**
37 * @author Morten Olav Hansen <mortenoh@gmail.com>
38 */
39@Target( { ElementType.FIELD, ElementType.METHOD } )
40@Retention( RetentionPolicy.RUNTIME )
41public @interface ExportComplex
42{
43 String value() default "";
44
45 String namespace() default "";
46}
047
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/ExportRoot.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/ExportRoot.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/ExportRoot.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,46 @@
1package org.hisp.dhis.node.annotation;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import java.lang.annotation.ElementType;
32import java.lang.annotation.Retention;
33import java.lang.annotation.RetentionPolicy;
34import java.lang.annotation.Target;
35
36/**
37 * @author Morten Olav Hansen <mortenoh@gmail.com>
38 */
39@Target( { ElementType.TYPE } )
40@Retention( RetentionPolicy.RUNTIME )
41public @interface ExportRoot
42{
43 String value() default "";
44
45 String namespace() default "";
46}
047
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/ExportSimple.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/ExportSimple.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/annotation/ExportSimple.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,48 @@
1package org.hisp.dhis.node.annotation;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import java.lang.annotation.ElementType;
32import java.lang.annotation.Retention;
33import java.lang.annotation.RetentionPolicy;
34import java.lang.annotation.Target;
35
36/**
37 * @author Morten Olav Hansen <mortenoh@gmail.com>
38 */
39@Target( { ElementType.FIELD, ElementType.METHOD } )
40@Retention( RetentionPolicy.RUNTIME )
41public @interface ExportSimple
42{
43 String value() default "";
44
45 boolean isAttribute() default false;
46
47 String namespace() default "";
48}
049
=== added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/exception'
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/exception/DuplicateNodeException.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/exception/DuplicateNodeException.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/exception/DuplicateNodeException.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,40 @@
1package org.hisp.dhis.node.exception;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31/**
32 * @author Morten Olav Hansen <mortenoh@gmail.com>
33 */
34public class DuplicateNodeException extends RuntimeException
35{
36 public DuplicateNodeException()
37 {
38 super( "A node with that name already exists in the child list." );
39 }
40}
041
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/exception/InvalidTypeException.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/exception/InvalidTypeException.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/exception/InvalidTypeException.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,40 @@
1package org.hisp.dhis.node.exception;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31/**
32 * @author Morten Olav Hansen <mortenoh@gmail.com>
33 */
34public class InvalidTypeException extends RuntimeException
35{
36 public InvalidTypeException()
37 {
38 super( "Adding children to a node of type simple is not allowed." );
39 }
40}
041
=== added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers'
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/JacksonJsonNodeSerializer.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/JacksonJsonNodeSerializer.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/JacksonJsonNodeSerializer.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,165 @@
1package org.hisp.dhis.node.serializers;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import com.fasterxml.jackson.annotation.JsonInclude;
32import com.fasterxml.jackson.core.JsonGenerator;
33import com.fasterxml.jackson.databind.ObjectMapper;
34import com.fasterxml.jackson.databind.SerializationFeature;
35import com.google.common.collect.Lists;
36import org.hisp.dhis.node.Node;
37import org.hisp.dhis.node.NodeSerializer;
38import org.hisp.dhis.node.types.CollectionNode;
39import org.hisp.dhis.node.types.ComplexNode;
40import org.hisp.dhis.node.types.RootNode;
41import org.hisp.dhis.node.types.SimpleNode;
42import org.springframework.stereotype.Component;
43
44import java.io.IOException;
45import java.io.OutputStream;
46import java.util.List;
47
48/**
49 * @author Morten Olav Hansen <mortenoh@gmail.com>
50 */
51@Component
52public class JacksonJsonNodeSerializer implements NodeSerializer
53{
54 public static final String CONTENT_TYPE = "application/json";
55
56 private final ObjectMapper objectMapper = new ObjectMapper();
57
58 @Override
59 public List<String> contentTypes()
60 {
61 return Lists.newArrayList( CONTENT_TYPE );
62 }
63
64 public JacksonJsonNodeSerializer()
65 {
66 objectMapper.setSerializationInclusion( JsonInclude.Include.NON_NULL );
67 objectMapper.configure( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false );
68 objectMapper.configure( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false );
69 objectMapper.configure( SerializationFeature.WRAP_EXCEPTIONS, true );
70 objectMapper.getFactory().enable( JsonGenerator.Feature.QUOTE_FIELD_NAMES );
71 }
72
73 @Override
74 public void serialize( RootNode rootNode, OutputStream outputStream ) throws IOException
75 {
76 JsonGenerator generator = objectMapper.getFactory().createGenerator( outputStream );
77
78 writeRootNode( rootNode, generator );
79 generator.flush();
80 }
81
82 private void writeRootNode( RootNode rootNode, JsonGenerator generator ) throws IOException
83 {
84 generator.writeStartObject();
85
86 for ( Node node : rootNode.getChildren() )
87 {
88 dispatcher( node, generator, true );
89 generator.flush();
90 }
91
92 generator.writeEndObject();
93 }
94
95 private void writeSimpleNode( SimpleNode simpleNode, JsonGenerator generator, boolean writeKey ) throws IOException
96 {
97 if ( simpleNode.getValue() == null ) // add hint for this, exclude if null
98 {
99 return;
100 }
101
102 if ( writeKey )
103 {
104 generator.writeObjectField( simpleNode.getName(), simpleNode.getValue() );
105 }
106 else
107 {
108 generator.writeObject( simpleNode.getValue() );
109 }
110 }
111
112 private void writeComplexNode( ComplexNode complexNode, JsonGenerator generator, boolean writeKey ) throws IOException
113 {
114 if ( writeKey )
115 {
116 generator.writeObjectFieldStart( complexNode.getName() );
117 }
118 else
119 {
120 generator.writeStartObject();
121 }
122
123 for ( Node node : complexNode.getChildren() )
124 {
125 dispatcher( node, generator, true );
126 }
127
128 generator.writeEndObject();
129 }
130
131 private void writeCollectionNode( CollectionNode collectionNode, JsonGenerator generator, boolean writeKey ) throws IOException
132 {
133 if ( writeKey )
134 {
135 generator.writeArrayFieldStart( collectionNode.getName() );
136 }
137 else
138 {
139 generator.writeStartArray();
140 }
141
142 for ( Node node : collectionNode.getChildren() )
143 {
144 dispatcher( node, generator, false );
145 }
146
147 generator.writeEndArray();
148 }
149
150 private void dispatcher( Node node, JsonGenerator generator, boolean writeKey ) throws IOException
151 {
152 switch ( node.getType() )
153 {
154 case SIMPLE:
155 writeSimpleNode( (SimpleNode) node, generator, writeKey );
156 break;
157 case COMPLEX:
158 writeComplexNode( (ComplexNode) node, generator, writeKey );
159 break;
160 case COLLECTION:
161 writeCollectionNode( (CollectionNode) node, generator, writeKey );
162 break;
163 }
164 }
165}
0166
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,197 @@
1package org.hisp.dhis.node.serializers;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import com.google.common.collect.Lists;
32import org.hisp.dhis.node.Node;
33import org.hisp.dhis.node.NodeSerializer;
34import org.hisp.dhis.node.types.CollectionNode;
35import org.hisp.dhis.node.types.ComplexNode;
36import org.hisp.dhis.node.types.RootNode;
37import org.hisp.dhis.node.types.SimpleNode;
38import org.springframework.stereotype.Component;
39import org.springframework.util.StringUtils;
40
41import javax.xml.stream.XMLOutputFactory;
42import javax.xml.stream.XMLStreamException;
43import javax.xml.stream.XMLStreamWriter;
44import java.io.IOException;
45import java.io.OutputStream;
46import java.util.List;
47
48/**
49 * @author Morten Olav Hansen <mortenoh@gmail.com>
50 */
51@Component
52public class StAXNodeSerializer implements NodeSerializer
53{
54 public static final String CONTENT_TYPE = "application/xml";
55
56 private final XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance();
57
58 @Override
59 public List<String> contentTypes()
60 {
61 return Lists.newArrayList( CONTENT_TYPE );
62 }
63
64 @Override
65 public void serialize( RootNode rootNode, OutputStream outputStream ) throws IOException
66 {
67 XMLStreamWriter writer;
68
69 try
70 {
71 writer = xmlFactory.createXMLStreamWriter( outputStream );
72 writeRootNode( rootNode, writer );
73 writer.flush();
74 }
75 catch ( XMLStreamException e )
76 {
77 throw new IOException( e.getMessage(), e.getCause() );
78 }
79 }
80
81 private void writeRootNode( RootNode rootNode, XMLStreamWriter writer ) throws IOException, XMLStreamException
82 {
83 writer.writeStartDocument( "UTF-8", "1.0" );
84
85 if ( !StringUtils.isEmpty( rootNode.getComment() ) )
86 {
87 writer.writeComment( rootNode.getComment() );
88 }
89
90 writeStartElement( rootNode, writer );
91
92 for ( Node node : rootNode.getChildren() )
93 {
94 dispatcher( node, writer );
95 writer.flush();
96 }
97
98 writeEndElement( writer );
99 writer.writeEndDocument();
100 }
101
102 private void writeSimpleNode( SimpleNode simpleNode, XMLStreamWriter writer ) throws XMLStreamException
103 {
104 if ( simpleNode.getValue() == null ) // TODO include null or not?
105 {
106 return;
107 }
108
109 String value = String.format( "%s", simpleNode.getValue() );
110
111 if ( simpleNode.isAttribute() )
112 {
113 if ( !StringUtils.isEmpty( simpleNode.getNamespace() ) )
114 {
115 writer.writeAttribute( "", simpleNode.getNamespace(), simpleNode.getName(), value );
116 }
117 else
118 {
119 writer.writeAttribute( simpleNode.getName(), value );
120 }
121 }
122 else
123 {
124 writeStartElement( simpleNode, writer );
125 writer.writeCharacters( value );
126 writeEndElement( writer );
127 }
128 }
129
130 private void writeComplexNode( ComplexNode complexNode, XMLStreamWriter writer ) throws XMLStreamException, IOException
131 {
132 writeStartElement( complexNode, writer );
133
134 for ( Node node : complexNode.getChildren() )
135 {
136 dispatcher( node, writer );
137 }
138
139 writeEndElement( writer );
140 }
141
142 private void writeCollectionNode( CollectionNode collectionNode, XMLStreamWriter writer ) throws XMLStreamException, IOException
143 {
144 if ( collectionNode.isWrapping() )
145 {
146 writeStartElement( collectionNode, writer );
147 }
148
149 for ( Node node : collectionNode.getChildren() )
150 {
151 dispatcher( node, writer );
152 }
153
154 if ( collectionNode.isWrapping() )
155 {
156 writeEndElement( writer );
157 }
158 }
159
160 private void dispatcher( Node node, XMLStreamWriter writer ) throws IOException, XMLStreamException
161 {
162 if ( !StringUtils.isEmpty( node.getComment() ) )
163 {
164 writer.writeComment( node.getComment() );
165 }
166
167 switch ( node.getType() )
168 {
169 case SIMPLE:
170 writeSimpleNode( (SimpleNode) node, writer );
171 break;
172 case COMPLEX:
173 writeComplexNode( (ComplexNode) node, writer );
174 break;
175 case COLLECTION:
176 writeCollectionNode( (CollectionNode) node, writer );
177 break;
178 }
179 }
180
181 private void writeStartElement( Node node, XMLStreamWriter writer ) throws XMLStreamException
182 {
183 if ( !StringUtils.isEmpty( node.getNamespace() ) )
184 {
185 writer.writeStartElement( "", node.getName(), node.getNamespace() );
186 }
187 else
188 {
189 writer.writeStartElement( node.getName() );
190 }
191 }
192
193 private void writeEndElement( XMLStreamWriter writer ) throws XMLStreamException
194 {
195 writer.writeEndElement();
196 }
197}
0198
=== added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types'
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/CollectionNode.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/CollectionNode.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/CollectionNode.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,58 @@
1package org.hisp.dhis.node.types;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import org.hisp.dhis.node.AbstractNode;
32import org.hisp.dhis.node.NodeType;
33
34/**
35 * @author Morten Olav Hansen <mortenoh@gmail.com>
36 */
37public class CollectionNode extends AbstractNode
38{
39 /**
40 * Should this collection act as a wrapper around its children.
41 */
42 boolean wrapping = true;
43
44 public CollectionNode( String name )
45 {
46 super( name, NodeType.COLLECTION );
47 }
48
49 public boolean isWrapping()
50 {
51 return wrapping;
52 }
53
54 public void setWrapping( boolean wrapping )
55 {
56 this.wrapping = wrapping;
57 }
58}
059
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/ComplexNode.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/ComplexNode.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/ComplexNode.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,43 @@
1package org.hisp.dhis.node.types;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import org.hisp.dhis.node.AbstractNode;
32import org.hisp.dhis.node.NodeType;
33
34/**
35 * @author Morten Olav Hansen <mortenoh@gmail.com>
36 */
37public class ComplexNode extends AbstractNode
38{
39 public ComplexNode( String name )
40 {
41 super( name, NodeType.COMPLEX );
42 }
43}
044
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/RootNode.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/RootNode.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/RootNode.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,40 @@
1package org.hisp.dhis.node.types;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31/**
32 * @author Morten Olav Hansen <mortenoh@gmail.com>
33 */
34public class RootNode extends ComplexNode
35{
36 public RootNode( String name )
37 {
38 super( name );
39 }
40}
041
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/SimpleNode.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/SimpleNode.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/SimpleNode.java 2014-06-05 17:39:07 +0000
@@ -0,0 +1,78 @@
1package org.hisp.dhis.node.types;
2
3/*
4 * Copyright (c) 2004-2014, University of Oslo
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the HISP project nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30
31import org.hisp.dhis.node.AbstractNode;
32import org.hisp.dhis.node.Node;
33import org.hisp.dhis.node.NodeType;
34import org.hisp.dhis.node.exception.InvalidTypeException;
35
36/**
37 * @author Morten Olav Hansen <mortenoh@gmail.com>
38 */
39public class SimpleNode extends AbstractNode
40{
41 private final Object value;
42
43 private boolean attribute;
44
45 public SimpleNode( String name, Object value )
46 {
47 super( name, NodeType.SIMPLE );
48 this.value = value;
49 this.attribute = false;
50 }
51
52 public Object getValue()
53 {
54 return value;
55 }
56
57 public boolean isAttribute()
58 {
59 return attribute;
60 }
61
62 public void setAttribute( boolean attribute )
63 {
64 this.attribute = attribute;
65 }
66
67 @Override
68 public <T extends Node> T addChild( T child ) throws InvalidTypeException
69 {
70 throw new InvalidTypeException();
71 }
72
73 @Override
74 public <T extends Node> void addChildren( Iterable<T> children )
75 {
76 throw new InvalidTypeException();
77 }
78}
079
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java 2014-06-05 17:39:07 +0000
@@ -28,10 +28,9 @@
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */29 */
3030
31import java.text.ParseException;31import com.google.common.collect.Lists;
32import java.text.SimpleDateFormat;32import org.hisp.dhis.calendar.DateUnit;
33import java.util.ArrayList;33
34import java.util.Calendar;
35import java.util.Date;34import java.util.Date;
36import java.util.List;35import java.util.List;
3736
@@ -61,29 +60,18 @@
61 }60 }
6261
63 @Override62 @Override
64 public Period createPeriod()63 public Period createPeriod( DateUnit dateUnit )
65 {64 {
66 return createPeriod( createCalendarInstance() );65 DateUnit start = new DateUnit( dateUnit );
67 }66 start.setMonth( ((start.getMonth() - 1) - (start.getMonth() - 1) % 2) + 1 );
6867 start.setDay( 1 );
69 @Override68
70 public Period createPeriod( Date date )69 DateUnit end = new DateUnit( start );
71 {70
72 return createPeriod( createCalendarInstance( date ) );71 end = getCalendar().plusMonths( end, 1 );
73 }72 end.setDay( getCalendar().daysInMonth( end.getYear(), end.getMonth() ) );
7473
75 @Override74 return toIsoPeriod( start, end );
76 public Period createPeriod( Calendar cal )
77 {
78 cal.set( Calendar.MONTH, cal.get( Calendar.MONTH ) - cal.get( Calendar.MONTH ) % 2 );
79 cal.set( Calendar.DAY_OF_MONTH, 1 );
80
81 Date startDate = cal.getTime();
82
83 cal.add( Calendar.MONTH, 1 );
84 cal.set( Calendar.DAY_OF_MONTH, cal.getActualMaximum( Calendar.DAY_OF_MONTH ) );
85
86 return new Period( this, startDate, cal.getTime() );
87 }75 }
8876
89 @Override77 @Override
@@ -99,17 +87,19 @@
99 @Override87 @Override
100 public Period getNextPeriod( Period period )88 public Period getNextPeriod( Period period )
101 {89 {
102 Calendar cal = createCalendarInstance( period.getStartDate() );90 DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
103 cal.add( Calendar.MONTH, 2 );91 dateUnit = getCalendar().plusMonths( dateUnit, 2 );
104 return createPeriod( cal );92
93 return createPeriod( getCalendar().toIso( dateUnit ) );
105 }94 }
10695
107 @Override96 @Override
108 public Period getPreviousPeriod( Period period )97 public Period getPreviousPeriod( Period period )
109 {98 {
110 Calendar cal = createCalendarInstance( period.getStartDate() );99 DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
111 cal.add( Calendar.MONTH, -2 );100 dateUnit = getCalendar().minusMonths( dateUnit, 2 );
112 return createPeriod( cal );101
102 return createPeriod( getCalendar().toIso( dateUnit ) );
113 }103 }
114104
115 /**105 /**
@@ -117,18 +107,19 @@
117 * the given Period exists.107 * the given Period exists.
118 */108 */
119 @Override109 @Override
120 public List<Period> generatePeriods( Date date )110 public List<Period> generatePeriods( DateUnit dateUnit )
121 {111 {
122 Calendar cal = createCalendarInstance( date );112 dateUnit.setMonth( 1 );
123 cal.set( Calendar.DAY_OF_YEAR, 1 );113 dateUnit.setDay( 1 );
124114
125 int year = cal.get( Calendar.YEAR );115 List<Period> periods = Lists.newArrayList();
126 ArrayList<Period> periods = new ArrayList<Period>();116
127117 int year = dateUnit.getYear();
128 while ( cal.get( Calendar.YEAR ) == year )118
119 while ( dateUnit.getYear() == year )
129 {120 {
130 periods.add( createPeriod( cal ) );121 periods.add( createPeriod( dateUnit ) );
131 cal.add( Calendar.MONTH, 2 );122 dateUnit = getCalendar().plusMonths( dateUnit, 2 );
132 }123 }
133124
134 return periods;125 return periods;
@@ -139,41 +130,26 @@
139 * which the given date is inside.130 * which the given date is inside.
140 */131 */
141 @Override132 @Override
142 public List<Period> generateRollingPeriods( Date date )133 public List<Period> generateRollingPeriods( DateUnit dateUnit )
143 {134 {
144 Calendar cal = createCalendarInstance( date );135 dateUnit.setDay( 1 );
145 cal.set( Calendar.DAY_OF_MONTH, 1 );136 dateUnit = getCalendar().minusMonths( dateUnit, (dateUnit.getMonth() % 2) + 10 );
146 cal.add( Calendar.MONTH, ( ( cal.get( Calendar.MONTH ) % 2 ) * -1 ) - 10 ); 137
147138 List<Period> periods = Lists.newArrayList();
148 ArrayList<Period> periods = new ArrayList<Period>();139
149
150 for ( int i = 0; i < 6; i++ )140 for ( int i = 0; i < 6; i++ )
151 {141 {
152 periods.add( createPeriod( cal ) );142 periods.add( createPeriod( dateUnit ) );
153 cal.add( Calendar.MONTH, 2 );143 dateUnit = getCalendar().plusMonths( dateUnit, 2 );
154 }144 }
155 145
156 return periods;146 return periods;
157 }147 }
158148
159 @Override149 @Override
160 public String getIsoDate( Period period )150 public String getIsoDate( DateUnit dateUnit )
161 {
162 return new SimpleDateFormat( "yyyyMM" ).format( period.getStartDate() ) + "B";
163 }
164
165 @Override
166 public Period createPeriod( String isoDate )
167 {151 {
168 try152 return String.format( "%d%02dB", dateUnit.getYear(), dateUnit.getMonth() );
169 {
170 Date date = new SimpleDateFormat( "yyyyMM" ).parse( isoDate.substring( 0, 6 ) );
171 return createPeriod( date );
172 }
173 catch ( ParseException ex )
174 {
175 throw new RuntimeException( ex );
176 }
177 }153 }
178154
179 @Override155 @Override
@@ -181,16 +157,16 @@
181 {157 {
182 return ISO_FORMAT;158 return ISO_FORMAT;
183 }159 }
184 160
185 @Override161 @Override
186 public Date getRewindedDate( Date date, Integer rewindedPeriods )162 public Date getRewindedDate( Date date, Integer rewindedPeriods )
187 {163 {
188 date = date != null ? date : new Date(); 164 date = date != null ? date : new Date();
189 rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;165 rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
190166
191 Calendar cal = createCalendarInstance( date ); 167 DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( date ) );
192 cal.add( Calendar.MONTH, (rewindedPeriods * -2) );168 dateUnit = getCalendar().minusMonths( dateUnit, rewindedPeriods );
193169
194 return cal.getTime();170 return getCalendar().toIso( dateUnit ).toJdkDate();
195 }171 }
196}172}
197173
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Cal.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Cal.java 2014-05-14 07:18:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Cal.java 2014-06-05 17:39:07 +0000
@@ -28,43 +28,62 @@
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */29 */
3030
31import org.hisp.dhis.calendar.CalendarService;
32import org.hisp.dhis.calendar.DateUnit;
33import org.hisp.dhis.calendar.impl.Iso8601Calendar;
34
31import java.util.Calendar;35import java.util.Calendar;
32import java.util.Date;36import java.util.Date;
33import java.util.GregorianCalendar;
3437
35/**38/**
39 * An abstraction over a calendar implementation, expects input to be in whatever the current
40 * system calendar is using, and all output will be in ISO 8601.
41 *
36 * @author Lars Helge Overland42 * @author Lars Helge Overland
43 * @author Morten Olav Hansen <mortenoh@gmail.com>
37 */44 */
38public class Cal45public class Cal
39{46{
40 private Calendar calendar;47 private static CalendarService calendarService;
41 48
49 public static void setCalendarService( CalendarService calendarService )
50 {
51 Cal.calendarService = calendarService;
52 }
53
54 public static org.hisp.dhis.calendar.Calendar getCalendar()
55 {
56 if ( calendarService != null )
57 {
58 return calendarService.getSystemCalendar();
59 }
60
61 return Iso8601Calendar.getInstance();
62 }
63
64 private DateUnit dateUnit = new DateUnit( 1, 1, 1 );
65
42 public Cal()66 public Cal()
43 {67 {
44 calendar = new GregorianCalendar();68 dateUnit = getCalendar().today();
45 calendar.clear();
46 }69 }
4770
48 /**71 /**
49 * @param year the year starting at AD 1.72 * @param year the year starting at AD 1.
50 * @param month the month starting at 1.73 * @param month the month starting at 1.
51 * @param day the day of the month starting at 1.74 * @param day the day of the month starting at 1.
52 */75 */
53 public Cal( int year, int month, int day )76 public Cal( int year, int month, int day )
54 {77 {
55 calendar = new GregorianCalendar();78 dateUnit = new DateUnit( year, month, day );
56 calendar.clear();
57 set( year, month, day );
58 }79 }
59 80
60 /**81 /**
61 * @param date the date.82 * @param date the date.
62 */83 */
63 public Cal( Date date )84 public Cal( Date date )
64 {85 {
65 calendar = new GregorianCalendar();86 dateUnit = DateUnit.fromJdkDate( date );
66 calendar.clear();
67 calendar.setTime( date );
68 }87 }
6988
70 /**89 /**
@@ -72,95 +91,107 @@
72 */91 */
73 public Cal now()92 public Cal now()
74 {93 {
75 calendar.setTime( new Date() );94 dateUnit = getCalendar().today();
76 return this;95 return this;
77 }96 }
78 97
79 /**98 /**
80 * Adds the given amount of time to the given calendar field.99 * Adds the given amount of time to the given calendar field.
81 * 100 * @param field the calendar field.
82 * @param field the calendar field.
83 * @param amount the amount of time.101 * @param amount the amount of time.
84 */102 */
85 public Cal add( int field, int amount )103 public Cal add( int field, int amount )
86 {104 {
87 calendar.add( field, amount );105 switch ( field )
106 {
107 case Calendar.YEAR:
108 getCalendar().plusYears( dateUnit, amount );
109 case Calendar.MONTH:
110 getCalendar().plusMonths( dateUnit, amount );
111 case Calendar.DAY_OF_MONTH:
112 getCalendar().plusDays( dateUnit, amount );
113 }
114
88 return this;115 return this;
89 }116 }
90117
91 /**118 /**
92 * Subtracts the given amount of time to the given calendar field.119 * Subtracts the given amount of time to the given calendar field.
93 * 120 * @param field the calendar field.
94 * @param field the calendar field.
95 * @param amount the amount of time.121 * @param amount the amount of time.
96 */122 */
97 public Cal subtract( int field, int amount )123 public Cal subtract( int field, int amount )
98 {124 {
99 calendar.add( field, amount * -1 );125 switch ( field )
126 {
127 case Calendar.YEAR:
128 getCalendar().minusYears( dateUnit, amount );
129 case Calendar.MONTH:
130 getCalendar().minusMonths( dateUnit, amount );
131 case Calendar.DAY_OF_MONTH:
132 getCalendar().minusDays( dateUnit, amount );
133 }
134
100 return this;135 return this;
101 }136 }
102137
103 /**138 /**
104 * Returns the value of the given calendar field.139 * Returns the value of the given calendar field.
105 *
106 * @param field the field.140 * @param field the field.
107 */141 */
108 public int get( int field )142 public int get( int field )
109 {143 {
110 return calendar.get( field );144 return getCalendar().toIso( dateUnit ).toJdkCalendar().get( field );
111 }145 }
112 146
113 /**147 /**
114 * Returns the current year.148 * Returns the current year.
115 * @return current year149 * @return current year
116 */150 */
117 public int getYear()151 public int getYear()
118 {152 {
119 return calendar.get( Calendar.YEAR );153 return getCalendar().toIso( dateUnit ).toJdkCalendar().get( Calendar.YEAR );
120 }154 }
121 155
122 /**156 /**
123 * Sets the current time.157 * Sets the current time.
124 * 158 * @param year the year starting at AD 1.
125 * @param year the year starting at AD 1.
126 * @param month the month starting at 1.159 * @param month the month starting at 1.
127 * @param day the day of the month starting at 1.160 * @param day the day of the month starting at 1.
128 */161 */
129 public Cal set( int year, int month, int day )162 public Cal set( int year, int month, int day )
130 {163 {
131 calendar.set( year, month - 1, day );164 dateUnit = new DateUnit( year, month, day );
132 return this;165 return this;
133 }166 }
134167
135 /**168 /**
136 * Sets the current month and day.169 * Sets the current month and day.
137 *
138 * @param month the month starting at 1.170 * @param month the month starting at 1.
139 * @param day the day of the month starting at 1.171 * @param day the day of the month starting at 1.
140 */172 */
141 public Cal set( int month, int day )173 public Cal set( int month, int day )
142 {174 {
143 calendar.set( Calendar.MONTH, month - 1 );175 dateUnit.setMonth( month );
144 calendar.set( Calendar.DAY_OF_MONTH, day );176 dateUnit.setDay( day );
145 return this;177 return this;
146 } 178 }
147 179
148 /**180 /**
149 * Sets the current time.181 * Sets the current time.
150 *
151 * @param date the date to base time on.182 * @param date the date to base time on.
152 */183 */
153 public Cal set( Date date )184 public Cal set( Date date )
154 {185 {
155 calendar.setTime( date );186 dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( date ) );
156 return this;187 return this;
157 }188 }
158 189
159 /**190 /**
160 * Returns the current date the cal.191 * Returns the current date the cal.
161 */192 */
162 public Date time()193 public Date time()
163 {194 {
164 return calendar.getTime();195 return getCalendar().toIso( dateUnit ).toJdkDate();
165 }196 }
166}197}
167198
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/CalendarPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/CalendarPeriodType.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/CalendarPeriodType.java 2014-06-05 17:39:07 +0000
@@ -28,15 +28,17 @@
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */29 */
3030
31import com.google.common.collect.Lists;
32import org.hisp.dhis.calendar.DateUnit;
33
31import java.util.ArrayList;34import java.util.ArrayList;
32import java.util.Calendar;
33import java.util.Date;35import java.util.Date;
34import java.util.List;36import java.util.List;
3537
36/**38/**
37 * The superclass of all PeriodTypes which represent typical calendar periods39 * The superclass of all PeriodTypes which represent typical calendar periods
38 * like days, weeks, months, etc.40 * like days, weeks, months, etc.
39 * 41 *
40 * @author Torgeir Lorange Ostby42 * @author Torgeir Lorange Ostby
41 * @version $Id: CalendarPeriodType.java 2952 2007-03-01 23:40:10Z torgeilo $43 * @version $Id: CalendarPeriodType.java 2952 2007-03-01 23:40:10Z torgeilo $
42 */44 */
@@ -57,7 +59,7 @@
57 * Periods are returned. If the given Period is of different PeriodType than59 * Periods are returned. If the given Period is of different PeriodType than
58 * the executing PeriodType, or the given Period is invalid, the returned60 * the executing PeriodType, or the given Period is invalid, the returned
59 * Period might overlap the given Period.61 * Period might overlap the given Period.
60 * 62 *
61 * @param period the Period to base the next Period on.63 * @param period the Period to base the next Period on.
62 * @return a Period which is the next of the given Period.64 * @return a Period which is the next of the given Period.
63 */65 */
@@ -68,7 +70,7 @@
68 * Periods are returned. If the given Period is of different PeriodType than70 * Periods are returned. If the given Period is of different PeriodType than
69 * the executing PeriodType, or the given Period is invalid, the returned71 * the executing PeriodType, or the given Period is invalid, the returned
70 * Period might overlap the given Period.72 * Period might overlap the given Period.
71 * 73 *
72 * @param period the Period to base the previous Period on.74 * @param period the Period to base the previous Period on.
73 * @return a Period which is the previous of the given Period.75 * @return a Period which is the previous of the given Period.
74 */76 */
@@ -79,73 +81,83 @@
79 * Period. E.g. if the given Period is March 2007, and a monthly PeriodType81 * Period. E.g. if the given Period is March 2007, and a monthly PeriodType
80 * generates for a year, all months in 2007 should be generated and returned82 * generates for a year, all months in 2007 should be generated and returned
81 * in order.83 * in order.
82 * 84 *
83 * @param period the Period which touches the time span to generate Periods85 * @param period the Period which touches the time span to generate Periods
84 * for.86 * for.
85 * @return a list of Periods for a defined time span.87 * @return a list of Periods for a defined time span.
86 */88 */
87 public List<Period> generatePeriods( Period period )89 public List<Period> generatePeriods( Period period )
88 {90 {
89 return generatePeriods( period.getStartDate() );91 return generatePeriods( period.getStartDate() );
90 } 92 }
91 93
92 /**94 /**
93 * Generates a list of Periods for a defined time span containing the given95 * Generates a list of Periods for a defined time span containing the given
94 * date. E.g. if the given date is March 2007, and a monthly PeriodType96 * date. E.g. if the given date is March 2007, and a monthly PeriodType
95 * generates for a year, all months in 2007 should be generated and returned97 * generates for a year, all months in 2007 should be generated and returned
96 * in order.98 * in order.
97 * 99 *
98 * @param date the date which touches the time span to generate Periods for.100 * @param date the date which touches the time span to generate Periods for.
99 * @return a list of Periods for a defined time span.101 * @return a list of Periods for a defined time span.
100 */102 */
101 public abstract List<Period> generatePeriods( Date date );103 public List<Period> generatePeriods( Date date )
102 104 {
103 public abstract List<Period> generateRollingPeriods( Date date );105 return generatePeriods( createLocalDateUnitInstance( date ) );
104 106 }
107
108 public abstract List<Period> generatePeriods( DateUnit dateUnit );
109
110 public List<Period> generateRollingPeriods( Date date )
111 {
112 return generateRollingPeriods( createLocalDateUnitInstance( date ) );
113 }
114
115 public abstract List<Period> generateRollingPeriods( DateUnit dateUnit );
116
105 /**117 /**
106 * Generates a list of Periods for the last 5 years. Must be overridden by118 * Generates a list of Periods for the last 5 years. Must be overridden by
107 * CalendarPeriodTypes which do not generate periods for the current year119 * CalendarPeriodTypes which do not generate periods for the current year
108 * only in their implementation of generatePeriods( Date ).120 * only in their implementation of generatePeriods( Date ).
109 * 121 *
110 * @param date the date which touches the time span to generate Periods for.122 * @param date the date which touches the time span to generate Periods for.
111 * @return a list of Periods for a defined time span.123 * @return a list of Periods for a defined time span.
112 */124 */
113 public List<Period> generateLast5Years( Date date )125 public List<Period> generateLast5Years( Date date )
114 {126 {
115 ArrayList<Period> periods = new ArrayList<Period>();127 DateUnit dateUnit = createLocalDateUnitInstance( date );
116 Calendar cal = createCalendarInstance( date );128 dateUnit = getCalendar().minusYears( dateUnit, 4 );
117 cal.add( Calendar.YEAR, -4 );129 List<Period> periods = Lists.newArrayList();
118 130
119 for ( int i = 0; i < 5; i++ )131 for ( int i = 0; i < 5; i++ )
120 {132 {
121 periods.addAll( generatePeriods( cal.getTime() ) );133 periods.addAll( generatePeriods( dateUnit ) );
122 cal.add( Calendar.YEAR, 1 );134 dateUnit = getCalendar().plusYears( dateUnit, 1 );
123 }135 }
124 136
125 return periods;137 return periods;
126 }138 }
127 139
128 /**140 /**
129 * Generates a list of all Periods between the given start and end date. The141 * Generates a list of all Periods between the given start and end date. The
130 * first period will span the start date. The last period will span the end142 * first period will span the start date. The last period will span the end
131 * date.143 * date.
132 * 144 *
133 * @param startDate the start date.145 * @param startDate the start date.
134 * @param endDate the end date.146 * @param endDate the end date.
135 * @return a list of Periods for the defined time span.147 * @return a list of Periods for the defined time span.
136 */148 */
137 public List<Period> generatePeriods( Date startDate, Date endDate )149 public List<Period> generatePeriods( Date startDate, Date endDate )
138 {150 {
139 List<Period> periods = new ArrayList<Period>();151 List<Period> periods = new ArrayList<Period>();
140 152
141 Period period = createPeriod( startDate );153 Period period = createPeriod( startDate );
142 154
143 while ( period.getStartDate().before( endDate ) )155 while ( period.getStartDate().before( endDate ) )
144 {156 {
145 periods.add( period );157 periods.add( period );
146 period = getNextPeriod( period );158 period = getNextPeriod( period );
147 }159 }
148 160
149 return periods;161 return periods;
150 }162 }
151}163}
152164
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java 2014-06-05 17:39:07 +0000
@@ -28,19 +28,17 @@
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */29 */
3030
31import java.text.ParseException;31import com.google.common.collect.Lists;
32import java.text.SimpleDateFormat;32import org.hisp.dhis.calendar.DateUnit;
33import java.util.ArrayList;33
34import java.util.Calendar;
35import java.util.Date;34import java.util.Date;
36import java.util.List;35import java.util.List;
3736
38/**37/**
39 * PeriodType for daily Periods. A valid daily Period has equal startDate and38 * PeriodType for daily Periods. A valid daily Period has equal startDate and
40 * endDate.39 * endDate.
41 * 40 *
42 * @author Torgeir Lorange Ostby41 * @author Torgeir Lorange Ostby
43 * @version $Id: DailyPeriodType.java 2971 2007-03-03 18:54:56Z torgeilo $
44 */42 */
45public class DailyPeriodType43public class DailyPeriodType
46 extends CalendarPeriodType44 extends CalendarPeriodType
@@ -70,31 +68,17 @@
70 }68 }
7169
72 @Override70 @Override
73 public Period createPeriod()71 public Period createPeriod( DateUnit dateUnit )
74 {72 {
75 return createPeriod( createCalendarInstance() );73 return toIsoPeriod( dateUnit );
76 }74 }
7775
78 @Override
79 public Period createPeriod( Date date )
80 {
81 return createPeriod( createCalendarInstance( date ) );
82 }
83
84 @Override
85 public Period createPeriod( Calendar cal )
86 {
87 Date date = cal.getTime();
88
89 return new Period( this, date, date );
90 }
91
92 @Override76 @Override
93 public int getFrequencyOrder()77 public int getFrequencyOrder()
94 {78 {
95 return FREQUENCY_ORDER;79 return FREQUENCY_ORDER;
96 }80 }
97 81
98 // -------------------------------------------------------------------------82 // -------------------------------------------------------------------------
99 // CalendarPeriodType functionality83 // CalendarPeriodType functionality
100 // -------------------------------------------------------------------------84 // -------------------------------------------------------------------------
@@ -102,10 +86,10 @@
102 @Override86 @Override
103 public Period getNextPeriod( Period period )87 public Period getNextPeriod( Period period )
104 {88 {
105 Calendar cal = createCalendarInstance( period.getStartDate() );89 DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
106 cal.add( Calendar.DAY_OF_YEAR, 1 );90 dateUnit = getCalendar().plusDays( dateUnit, 1 );
10791
108 Date date = cal.getTime();92 Date date = getCalendar().toIso( dateUnit ).toJdkDate();
10993
110 return new Period( this, date, date );94 return new Period( this, date, date );
111 }95 }
@@ -113,75 +97,61 @@
113 @Override97 @Override
114 public Period getPreviousPeriod( Period period )98 public Period getPreviousPeriod( Period period )
115 {99 {
116 Calendar cal = createCalendarInstance( period.getStartDate() );100 DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
117 cal.add( Calendar.DAY_OF_YEAR, -1 );101 dateUnit = getCalendar().minusDays( dateUnit, 1 );
118102
119 Date date = cal.getTime();103 Date date = getCalendar().toIso( dateUnit ).toJdkDate();
120104
121 return new Period( this, date, date );105 return new Period( this, date, date );
122 }106 }
123 107
124 /**108 /**
125 * Generates daily Periods for the whole year in which the given Period's109 * Generates daily Periods for the whole year in which the given Period's
126 * startDate exists.110 * startDate exists.
127 */111 */
128 @Override112 @Override
129 public List<Period> generatePeriods( Date date )113 public List<Period> generatePeriods( DateUnit dateUnit )
130 {114 {
131 Calendar cal = createCalendarInstance( date );115 dateUnit.setMonth( 1 );
132 cal.set( Calendar.DAY_OF_YEAR, 1 );116 dateUnit.setDay( 1 );
133117
134 int year = cal.get( Calendar.YEAR );118 List<Period> periods = Lists.newArrayList();
135 ArrayList<Period> periods = new ArrayList<Period>();119
136120 int year = dateUnit.getYear();
137 while ( cal.get( Calendar.YEAR ) == year )121
122 while ( year == dateUnit.getYear() )
138 {123 {
139 periods.add( createPeriod( cal.getTime() ) );124 periods.add( createPeriod( dateUnit ) );
140 cal.add( Calendar.DAY_OF_YEAR, 1 );125 dateUnit = getCalendar().plusDays( dateUnit, 1 );
141 }126 }
142127
143 return periods;128 return periods;
144 }129 }
145130
146 /**131 /**
147 * Generates the last 365 days where the last one is the day of the given 132 * Generates the last 365 days where the last one is the day of the given
148 * date.133 * date.
149 */134 */
150 @Override135 @Override
151 public List<Period> generateRollingPeriods( Date date )136 public List<Period> generateRollingPeriods( DateUnit dateUnit )
152 {137 {
153 Calendar cal = createCalendarInstance( date );138 dateUnit = getCalendar().minusDays( dateUnit, 364 );
154 cal.set( Calendar.DAY_OF_MONTH, -364 ); 139
155140 List<Period> periods = Lists.newArrayList();
156 ArrayList<Period> periods = new ArrayList<Period>();141
157
158 for ( int i = 0; i < 365; i++ )142 for ( int i = 0; i < 365; i++ )
159 {143 {
160 periods.add( createPeriod( cal ) );144 periods.add( createPeriod( dateUnit ) );
161 cal.add( Calendar.MONTH, 1 );145 dateUnit = getCalendar().plusDays( dateUnit, 1 );
162 }146 }
163 147
164 return periods; 148 return periods;
165 }149 }
166150
167 @Override151 @Override
168 public String getIsoDate( Period period )152 public String getIsoDate( DateUnit dateUnit )
169 {153 {
170 return new SimpleDateFormat( ISO_FORMAT ).format( period.getStartDate() );154 return String.format( "%d%02d%02d", dateUnit.getYear(), dateUnit.getMonth(), dateUnit.getDay() );
171 }
172
173 @Override
174 public Period createPeriod( String isoDate )
175 {
176 try
177 {
178 Date date = new SimpleDateFormat( ISO_FORMAT ).parse( isoDate );
179 return createPeriod( date );
180 }
181 catch ( ParseException e )
182 {
183 throw new RuntimeException( e );
184 }
185 }155 }
186156
187 @Override157 @Override
@@ -189,16 +159,16 @@
189 {159 {
190 return ISO_FORMAT;160 return ISO_FORMAT;
191 }161 }
192 162
193 @Override163 @Override
194 public Date getRewindedDate( Date date, Integer rewindedPeriods )164 public Date getRewindedDate( Date date, Integer rewindedPeriods )
195 {165 {
196 date = date != null ? date : new Date(); 166 date = date != null ? date : new Date();
197 rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;167 rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
198168
199 Calendar cal = createCalendarInstance( date ); 169 DateUnit dateUnit = createLocalDateUnitInstance( date );
200 cal.add( Calendar.DAY_OF_YEAR, (rewindedPeriods * -1) );170 dateUnit = getCalendar().minusDays( dateUnit, rewindedPeriods );
201171
202 return cal.getTime();172 return getCalendar().toIso( dateUnit ).toJdkDate();
203 }173 }
204}174}
205175
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java 2014-06-05 17:39:07 +0000
@@ -28,6 +28,8 @@
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */29 */
3030
31import org.hisp.dhis.calendar.DateUnit;
32
31import java.util.Calendar;33import java.util.Calendar;
3234
33/**35/**
@@ -58,11 +60,9 @@
58 }60 }
5961
60 @Override62 @Override
61 public String getIsoDate( Period period )63 public String getIsoDate( DateUnit dateUnit )
62 {64 {
63 Calendar cal = createCalendarInstance( period.getStartDate() );65 return String.format( "%dApril", dateUnit.getYear() );
64 int year = cal.get( Calendar.YEAR );
65 return String.valueOf( year ) + "April";
66 }66 }
6767
68 @Override68 @Override
6969
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialJulyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialJulyPeriodType.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialJulyPeriodType.java 2014-06-05 17:39:07 +0000
@@ -28,6 +28,8 @@
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */29 */
3030
31import org.hisp.dhis.calendar.DateUnit;
32
31import java.util.Calendar;33import java.util.Calendar;
3234
33/**35/**
@@ -58,11 +60,9 @@
58 }60 }
5961
60 @Override62 @Override
61 public String getIsoDate( Period period )63 public String getIsoDate( DateUnit dateUnit )
62 {64 {
63 Calendar cal = createCalendarInstance( period.getStartDate() );65 return String.format( "%dJuly", dateUnit.getYear() );
64 int year = cal.get( Calendar.YEAR );
65 return String.valueOf( year ) + "July";
66 }66 }
6767
68 @Override68 @Override
6969
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java 2014-06-05 17:39:07 +0000
@@ -28,6 +28,8 @@
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */29 */
3030
31import org.hisp.dhis.calendar.DateUnit;
32
31import java.util.Calendar;33import java.util.Calendar;
3234
33/**35/**
@@ -50,7 +52,7 @@
50 {52 {
51 return Calendar.OCTOBER;53 return Calendar.OCTOBER;
52 }54 }
53 55
54 @Override56 @Override
55 public String getName()57 public String getName()
56 {58 {
@@ -58,11 +60,9 @@
58 }60 }
5961
60 @Override62 @Override
61 public String getIsoDate( Period period )63 public String getIsoDate( DateUnit dateUnit )
62 {64 {
63 Calendar cal = createCalendarInstance( period.getStartDate() );65 return String.format( "%dOct", dateUnit.getYear() );
64 int year = cal.get( Calendar.YEAR );
65 return String.valueOf( year ) + "Oct";
66 }66 }
6767
68 @Override68 @Override
6969
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java 2014-06-05 17:39:07 +0000
@@ -28,8 +28,9 @@
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */29 */
3030
31import java.util.ArrayList;31import com.google.common.collect.Lists;
32import java.util.Calendar;32import org.hisp.dhis.calendar.DateUnit;
33
33import java.util.Date;34import java.util.Date;
34import java.util.List;35import java.util.List;
3536
@@ -45,44 +46,37 @@
45 private static final long serialVersionUID = 2649990007010207631L;46 private static final long serialVersionUID = 2649990007010207631L;
4647
47 public static final int FREQUENCY_ORDER = 365;48 public static final int FREQUENCY_ORDER = 365;
48 49
49 // -------------------------------------------------------------------------50 // -------------------------------------------------------------------------
50 // Abstract methods51 // Abstract methods
51 // -------------------------------------------------------------------------52 // -------------------------------------------------------------------------
5253
53 protected abstract int getBaseMonth();54 protected abstract int getBaseMonth();
54 55
55 // -------------------------------------------------------------------------56 // -------------------------------------------------------------------------
56 // PeriodType functionality57 // PeriodType functionality
57 // -------------------------------------------------------------------------58 // -------------------------------------------------------------------------
5859
59 @Override60 @Override
60 public Period createPeriod()61 public Period createPeriod( DateUnit dateUnit )
61 {62 {
62 return createPeriod( createCalendarInstance() );63 boolean past = dateUnit.getMonth() >= (getBaseMonth() + 1);
63 }64
6465 if ( !past )
65 @Override66 {
66 public Period createPeriod( Date date )67 dateUnit = getCalendar().minusYears( dateUnit, 1 );
67 {68 }
68 return createPeriod( createCalendarInstance( date ) );69
69 }70 dateUnit.setMonth( getBaseMonth() + 1 );
7071 dateUnit.setDay( 1 );
71 @Override72
72 public Period createPeriod( Calendar cal )73 DateUnit start = new DateUnit( dateUnit );
73 {74 DateUnit end = new DateUnit( dateUnit );
74 boolean past = cal.get( Calendar.MONTH ) >= getBaseMonth();75
75 76 end = getCalendar().plusYears( end, 1 );
76 cal.set( Calendar.YEAR, past ? cal.get( Calendar.YEAR ) : cal.get( Calendar.YEAR ) - 1 );77 end = getCalendar().minusDays( end, 1 );
77 cal.set( Calendar.MONTH, getBaseMonth() );78
78 cal.set( Calendar.DATE, 1 );79 return toIsoPeriod( start, end );
79
80 Date startDate = cal.getTime();
81
82 cal.add( Calendar.YEAR, 1 );
83 cal.set( Calendar.DAY_OF_YEAR, cal.get( Calendar.DAY_OF_YEAR ) - 1 );
84
85 return new Period( this, startDate, cal.getTime() );
86 }80 }
8781
88 @Override82 @Override
@@ -98,40 +92,40 @@
98 @Override92 @Override
99 public Period getNextPeriod( Period period )93 public Period getNextPeriod( Period period )
100 {94 {
101 Calendar cal = createCalendarInstance( period.getStartDate() );95 DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
102 cal.add( Calendar.YEAR, 1 );96 dateUnit = getCalendar().plusYears( dateUnit, 1 );
103 return createPeriod( cal );97
98 return createPeriod( dateUnit );
104 }99 }
105100
106 @Override101 @Override
107 public Period getPreviousPeriod( Period period )102 public Period getPreviousPeriod( Period period )
108 {103 {
109 Calendar cal = createCalendarInstance( period.getStartDate() );104 DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
110 cal.add( Calendar.YEAR, -1 );105 dateUnit = getCalendar().minusYears( dateUnit, 1 );
111 return createPeriod( cal );106
107 return createPeriod( dateUnit );
112 }108 }
113109
114 /**110 /**
115 * Generates financial yearly periods for the last 5, current and next 5 111 * Generates financial yearly periods for the last 5, current and next 5
116 * financial years.112 * financial years.
117 */113 */
118 @Override114 @Override
119 public List<Period> generatePeriods( Date date )115 public List<Period> generatePeriods( DateUnit dateUnit )
120 {116 {
121 Calendar cal = createCalendarInstance( date );117 boolean past = dateUnit.getMonth() >= (getBaseMonth() + 1);
122 118
123 boolean past = cal.get( Calendar.MONTH ) >= getBaseMonth();119 List<Period> periods = Lists.newArrayList();
124 120
125 cal.add( Calendar.YEAR, past ? -5 : -6 );121 dateUnit = getCalendar().minusYears( dateUnit, past ? 5 : 6 );
126 cal.set( Calendar.MONTH, getBaseMonth() );122 dateUnit.setMonth( getBaseMonth() + 1 );
127 cal.set( Calendar.DATE, 1 );123 dateUnit.setDay( 1 );
128124
129 ArrayList<Period> periods = new ArrayList<Period>();125 for ( int i = 0; i < 11; i++ )
130
131 for ( int i = 0; i < 11; ++i )
132 {126 {
133 periods.add( createPeriod( cal ) );127 periods.add( createPeriod( dateUnit ) );
134 cal.add( Calendar.YEAR, 1 );128 dateUnit = getCalendar().plusYears( dateUnit, 1 );
135 }129 }
136130
137 return periods;131 return periods;
@@ -146,49 +140,43 @@
146 {140 {
147 return generateLast5Years( date );141 return generateLast5Years( date );
148 }142 }
149 143
144 @Override
145 public List<Period> generateRollingPeriods( DateUnit dateUnit )
146 {
147 return generateLast5Years( getCalendar().toIso( dateUnit ).toJdkDate() );
148 }
149
150 @Override150 @Override
151 public List<Period> generateLast5Years( Date date )151 public List<Period> generateLast5Years( Date date )
152 {152 {
153 Calendar cal = createCalendarInstance( date );153 DateUnit dateUnit = createLocalDateUnitInstance( date );
154 154 boolean past = dateUnit.getMonth() >= (getBaseMonth() + 1);
155 boolean past = cal.get( Calendar.MONTH ) >= getBaseMonth();155
156 156 List<Period> periods = Lists.newArrayList();
157 cal.add( Calendar.YEAR, past ? -4 : -5 );157
158 cal.set( Calendar.MONTH, getBaseMonth() );158 dateUnit = getCalendar().minusYears( dateUnit, past ? 4 : 5 );
159 cal.set( Calendar.DATE, 1 );159 dateUnit.setMonth( getBaseMonth() + 1 );
160160 dateUnit.setDay( 1 );
161 ArrayList<Period> periods = new ArrayList<Period>();161
162162 for ( int i = 0; i < 5; i++ )
163 for ( int i = 0; i < 5; ++i )
164 {163 {
165 periods.add( createPeriod( cal ) );164 periods.add( createPeriod( dateUnit ) );
166 cal.add( Calendar.YEAR, 1 );165 dateUnit = getCalendar().plusYears( dateUnit, 1 );
167 }166 }
168167
169 return periods;168 return periods;
170 }169 }
171170
172 @Override171 @Override
173 public Period createPeriod( String isoDate )
174 {
175 int year = Integer.parseInt( isoDate.substring( 0, 4 ) );
176 Calendar cal = createCalendarInstance();
177 cal.set( Calendar.YEAR, year );
178 cal.set( Calendar.MONTH, 11 );
179 cal.set( Calendar.DAY_OF_MONTH, 31 );
180 return createPeriod( cal );
181 }
182
183 @Override
184 public Date getRewindedDate( Date date, Integer rewindedPeriods )172 public Date getRewindedDate( Date date, Integer rewindedPeriods )
185 {173 {
186 date = date != null ? date : new Date(); 174 date = date != null ? date : new Date();
187 rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;175 rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
188176
189 Calendar cal = createCalendarInstance( date ); 177 DateUnit dateUnit = createLocalDateUnitInstance( date );
190 cal.add( Calendar.YEAR, (rewindedPeriods * -1) );178 dateUnit = getCalendar().minusYears( dateUnit, rewindedPeriods );
191179
192 return cal.getTime();180 return getCalendar().toIso( dateUnit ).toJdkDate();
193 }181 }
194}182}
195183
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java 2014-05-13 16:00:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java 2014-06-05 17:39:07 +0000
@@ -28,10 +28,9 @@
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */29 */
3030
31import java.text.ParseException;31import com.google.common.collect.Lists;
32import java.text.SimpleDateFormat;32import org.hisp.dhis.calendar.DateUnit;
33import java.util.ArrayList;33
34import java.util.Calendar;
35import java.util.Date;34import java.util.Date;
36import java.util.List;35import java.util.List;
3736
@@ -39,6 +38,7 @@
39 * PeriodType for monthly Periods. A valid monthly Period has startDate set to38 * PeriodType for monthly Periods. A valid monthly Period has startDate set to
40 * the first day of a calendar month, and endDate set to the last day of the39 * the first day of a calendar month, and endDate set to the last day of the
41 * same month.40 * same month.
41 *
42 * @author Torgeir Lorange Ostby42 * @author Torgeir Lorange Ostby
43 * @version $Id: MonthlyPeriodType.java 2971 2007-03-03 18:54:56Z torgeilo $43 * @version $Id: MonthlyPeriodType.java 2971 2007-03-03 18:54:56Z torgeilo $
44 */44 */
@@ -52,8 +52,6 @@
5252
53 private static final String ISO_FORMAT = "yyyyMM";53 private static final String ISO_FORMAT = "yyyyMM";
5454
55 private static final String ALTERNATIVE_ISO_FORMAT = "yyyy-MM";
56
57 /**55 /**
58 * The name of the MonthlyPeriodType, which is "Monthly".56 * The name of the MonthlyPeriodType, which is "Monthly".
59 */57 */
@@ -72,25 +70,15 @@
72 }70 }
7371
74 @Override72 @Override
75 public Period createPeriod()73 public Period createPeriod( DateUnit dateUnit )
76 {74 {
77 return createPeriod( createCalendarInstance() );75 DateUnit start = new DateUnit( dateUnit );
78 }76 start.setDay( 1 );
7977
80 @Override78 DateUnit end = new DateUnit( dateUnit );
81 public Period createPeriod( Date date )79 end.setDay( getCalendar().daysInMonth( end.getYear(), end.getMonth() ) );
82 {80
83 return createPeriod( createCalendarInstance( date ) );81 return toIsoPeriod( start, end );
84 }
85
86 @Override
87 public Period createPeriod( Calendar cal )
88 {
89 cal.set( Calendar.DAY_OF_MONTH, 1 );
90 Date startDate = cal.getTime();
91 cal.set( Calendar.DAY_OF_MONTH, cal.getActualMaximum( Calendar.DAY_OF_MONTH ) );
92
93 return new Period( this, startDate, cal.getTime() );
94 }82 }
9583
96 @Override84 @Override
@@ -106,17 +94,19 @@
106 @Override94 @Override
107 public Period getNextPeriod( Period period )95 public Period getNextPeriod( Period period )
108 {96 {
109 Calendar cal = createCalendarInstance( period.getStartDate() );97 DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
110 cal.add( Calendar.MONTH, 1 );98 dateUnit = getCalendar().plusMonths( dateUnit, 1 );
111 return createPeriod( cal );99
100 return createPeriod( getCalendar().toIso( dateUnit ) );
112 }101 }
113102
114 @Override103 @Override
115 public Period getPreviousPeriod( Period period )104 public Period getPreviousPeriod( Period period )
116 {105 {
117 Calendar cal = createCalendarInstance( period.getStartDate() );106 DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
118 cal.add( Calendar.MONTH, -1 );107 dateUnit = getCalendar().minusMonths( dateUnit, 1 );
119 return createPeriod( cal );108
109 return createPeriod( getCalendar().toIso( dateUnit ) );
120 }110 }
121111
122 /**112 /**
@@ -124,18 +114,19 @@
124 * startDate exists.114 * startDate exists.
125 */115 */
126 @Override116 @Override
127 public List<Period> generatePeriods( Date date )117 public List<Period> generatePeriods( DateUnit dateUnit )
128 {118 {
129 Calendar cal = createCalendarInstance( date );119 dateUnit.setMonth( 1 );
130 cal.set( Calendar.DAY_OF_YEAR, 1 );120 dateUnit.setDay( 1 );
131121
132 int year = cal.get( Calendar.YEAR );122 List<Period> periods = Lists.newArrayList();
133 ArrayList<Period> periods = new ArrayList<Period>();123
134124 int year = dateUnit.getYear();
135 while ( cal.get( Calendar.YEAR ) == year )125
126 while ( dateUnit.getYear() == year )
136 {127 {
137 periods.add( createPeriod( cal ) );128 periods.add( createPeriod( dateUnit ) );
138 cal.add( Calendar.MONTH, 1 );129 dateUnit = getCalendar().plusMonths( dateUnit, 1 );
139 }130 }
140131
141 return periods;132 return periods;
@@ -146,51 +137,26 @@
146 * given date is inside.137 * given date is inside.
147 */138 */
148 @Override139 @Override
149 public List<Period> generateRollingPeriods( Date date )140 public List<Period> generateRollingPeriods( DateUnit dateUnit )
150 {141 {
151 Calendar cal = createCalendarInstance( date );142 dateUnit.setDay( 1 );
152 cal.set( Calendar.DAY_OF_MONTH, 1 );143 dateUnit = getCalendar().minusMonths( dateUnit, 11 );
153 cal.add( Calendar.MONTH, -11 );
154144
155 ArrayList<Period> periods = new ArrayList<Period>();145 List<Period> periods = Lists.newArrayList();
156146
157 for ( int i = 0; i < 12; i++ )147 for ( int i = 0; i < 12; i++ )
158 {148 {
159 periods.add( createPeriod( cal ) );149 periods.add( createPeriod( dateUnit ) );
160 cal.add( Calendar.MONTH, 1 );150 dateUnit = getCalendar().plusMonths( dateUnit, 1 );
161 }151 }
162152
163 return periods;153 return periods;
164 }154 }
165155
166 @Override156 @Override
167 public String getIsoDate( Period period )157 public String getIsoDate( DateUnit dateUnit )
168 {158 {
169 return new SimpleDateFormat( ISO_FORMAT ).format( period.getStartDate() );159 return String.format( "%d%02d", dateUnit.getYear(), dateUnit.getMonth() );
170 }
171
172 @Override
173 public Period createPeriod( String isoDate )
174 {
175 try
176 {
177 Date date = new SimpleDateFormat( ISO_FORMAT ).parse( isoDate );
178 return createPeriod( date );
179 }
180 catch ( ParseException ex )
181 {
182 // Ignore and try alternative format
183 }
184
185 try
186 {
187 Date date = new SimpleDateFormat( ALTERNATIVE_ISO_FORMAT ).parse( isoDate );
188 return createPeriod( date );
189 }
190 catch ( ParseException ex )
191 {
192 throw new RuntimeException( ex );
193 }
194 }160 }
195161
196 @Override162 @Override
@@ -205,9 +171,9 @@
205 date = date != null ? date : new Date();171 date = date != null ? date : new Date();
206 rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;172 rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
207173
208 Calendar cal = createCalendarInstance( date );174 DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( date ) );
209 cal.add( Calendar.MONTH, (rewindedPeriods * -1) );175 dateUnit = getCalendar().minusMonths( dateUnit, rewindedPeriods );
210176
211 return cal.getTime();177 return getCalendar().toIso( dateUnit ).toJdkDate();
212 }178 }
213}179}
214180
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2014-05-13 16:00:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2014-06-05 17:39:07 +0000
@@ -30,13 +30,15 @@
3030
31import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;31import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
32import org.hisp.dhis.calendar.CalendarService;32import org.hisp.dhis.calendar.CalendarService;
33import org.hisp.dhis.calendar.DateInterval;
34import org.hisp.dhis.calendar.DateUnit;
35import org.hisp.dhis.calendar.DateUnitPeriodTypeParser;
36import org.hisp.dhis.calendar.DateUnitType;
37import org.hisp.dhis.calendar.PeriodTypeParser;
33import org.hisp.dhis.calendar.impl.Iso8601Calendar;38import org.hisp.dhis.calendar.impl.Iso8601Calendar;
34import org.hisp.dhis.common.DxfNamespaces;39import org.hisp.dhis.common.DxfNamespaces;
35import org.springframework.beans.factory.annotation.Autowired;
3640
37import java.io.Serializable;41import java.io.Serializable;
38import java.text.ParseException;
39import java.text.SimpleDateFormat;
40import java.util.ArrayList;42import java.util.ArrayList;
41import java.util.Calendar;43import java.util.Calendar;
42import java.util.Date;44import java.util.Date;
@@ -47,9 +49,10 @@
4749
48/**50/**
49 * The superclass of all PeriodTypes.51 * The superclass of all PeriodTypes.
52 *
50 * @author Kristian Nordal53 * @author Kristian Nordal
51 */54 */
52@JacksonXmlRootElement(localName = "periodType", namespace = DxfNamespaces.DXF_2_0)55@JacksonXmlRootElement( localName = "periodType", namespace = DxfNamespaces.DXF_2_0 )
53public abstract class PeriodType56public abstract class PeriodType
54 implements Serializable57 implements Serializable
55{58{
@@ -58,15 +61,19 @@
58 */61 */
59 private static final long serialVersionUID = 2402122626196305083L;62 private static final long serialVersionUID = 2402122626196305083L;
6063
61 private CalendarService calendarService;64 private static CalendarService calendarService;
6265
63 @Autowired66 public static void setCalendarService( CalendarService calendarService )
64 public void setCalendarService( CalendarService calendarService )67 {
65 {68 PeriodType.calendarService = calendarService;
66 this.calendarService = calendarService;69 }
67 }70
6871 public static CalendarService getCalendarService()
69 public org.hisp.dhis.calendar.Calendar getCalendar()72 {
73 return calendarService;
74 }
75
76 public static org.hisp.dhis.calendar.Calendar getCalendar()
70 {77 {
71 if ( calendarService != null )78 if ( calendarService != null )
72 {79 {
@@ -76,6 +83,8 @@
76 return Iso8601Calendar.getInstance();83 return Iso8601Calendar.getInstance();
77 }84 }
7885
86 protected PeriodTypeParser dateUnitFormat = new DateUnitPeriodTypeParser();
87
79 // -------------------------------------------------------------------------88 // -------------------------------------------------------------------------
80 // Available PeriodTypes89 // Available PeriodTypes
81 // -------------------------------------------------------------------------90 // -------------------------------------------------------------------------
@@ -112,6 +121,7 @@
112121
113 /**122 /**
114 * Returns an immutable list of all available PeriodTypes in their natural order.123 * Returns an immutable list of all available PeriodTypes in their natural order.
124 *
115 * @return all available PeriodTypes in their natural order.125 * @return all available PeriodTypes in their natural order.
116 */126 */
117 public static List<PeriodType> getAvailablePeriodTypes()127 public static List<PeriodType> getAvailablePeriodTypes()
@@ -121,6 +131,7 @@
121131
122 /**132 /**
123 * Returns a PeriodType with a given name.133 * Returns a PeriodType with a given name.
134 *
124 * @param name the name of the PeriodType to return.135 * @param name the name of the PeriodType to return.
125 * @return the PeriodType with the given name or null if no such PeriodType136 * @return the PeriodType with the given name or null if no such PeriodType
126 * exists.137 * exists.
@@ -145,6 +156,7 @@
145156
146 /**157 /**
147 * Get period type according to natural order order.158 * Get period type according to natural order order.
159 *
148 * @param index the index of the period type with base 1160 * @param index the index of the period type with base 1
149 * @return period type according to index order or null if no match161 * @return period type according to index order or null if no match
150 * TODO: Consider manual ordering, since relying on natural order might create problems if new periods are introduced.162 * TODO: Consider manual ordering, since relying on natural order might create problems if new periods are introduced.
@@ -183,6 +195,7 @@
183195
184 /**196 /**
185 * Returns a unique name for the PeriodType.197 * Returns a unique name for the PeriodType.
198 *
186 * @return a unique name for the PeriodType. E.g. "Monthly".199 * @return a unique name for the PeriodType. E.g. "Monthly".
187 */200 */
188 public abstract String getName();201 public abstract String getName();
@@ -190,29 +203,54 @@
190 /**203 /**
191 * Creates a valid Period based on the current date. E.g. if today is204 * Creates a valid Period based on the current date. E.g. if today is
192 * January 5. 2007, a monthly PeriodType should return January 2007.205 * January 5. 2007, a monthly PeriodType should return January 2007.
206 *
193 * @return a valid Period based on the current date.207 * @return a valid Period based on the current date.
194 */208 */
195 public abstract Period createPeriod();209 public Period createPeriod()
210 {
211 return createPeriod( createCalendarInstance() );
212 }
196213
197 /**214 /**
198 * Creates a valid Period based on the given date. E.g. the given date is215 * Creates a valid Period based on the given date. E.g. the given date is
199 * February 10. 2007, a monthly PeriodType should return February 2007.216 * February 10. 2007, a monthly PeriodType should return February 2007.
217 *
200 * @param date the date which is contained by the created period.218 * @param date the date which is contained by the created period.
201 * @return the valid Period based on the given date219 * @return the valid Period based on the given date
202 */220 */
203 public abstract Period createPeriod( Date date );221 public Period createPeriod( Date date )
204222 {
205 public abstract Period createPeriod( Calendar cal );223 return createPeriod( createCalendarInstance( date ) );
224 }
225
226 public Period createPeriod( Calendar cal )
227 {
228 return createPeriod( getCalendar().fromIso( DateUnit.fromJdkCalendar( cal ) ) );
229 }
230
231 public Period toIsoPeriod( DateUnit start, DateUnit end )
232 {
233 return new Period( this, getCalendar().toIso( start ).toJdkDate(), getCalendar().toIso( end ).toJdkDate() );
234 }
235
236 public Period toIsoPeriod( DateUnit dateUnit )
237 {
238 return toIsoPeriod( dateUnit, dateUnit );
239 }
240
241 public abstract Period createPeriod( DateUnit dateUnit );
206242
207 /**243 /**
208 * Returns a comparable value for the frequency length of this PeriodType.244 * Returns a comparable value for the frequency length of this PeriodType.
209 * Shortest is 0.245 * Shortest is 0.
246 *
210 * @return the frequency order.247 * @return the frequency order.
211 */248 */
212 public abstract int getFrequencyOrder();249 public abstract int getFrequencyOrder();
213250
214 /**251 /**
215 * Returns a new date rewinded from now.252 * Returns a new date rewinded from now.
253 *
216 * @return the Date.254 * @return the Date.
217 */255 */
218 public abstract Date getRewindedDate( Date date, Integer rewindedPeriods );256 public abstract Date getRewindedDate( Date date, Integer rewindedPeriods );
@@ -224,20 +262,18 @@
224 /**262 /**
225 * Returns an instance of a Calendar without any time of day, with the263 * Returns an instance of a Calendar without any time of day, with the
226 * current date.264 * current date.
265 *
227 * @return an instance of a Calendar without any time of day.266 * @return an instance of a Calendar without any time of day.
228 */267 */
229 public static Calendar createCalendarInstance()268 public static Calendar createCalendarInstance()
230 {269 {
231 Calendar calendar = new GregorianCalendar();270 return getCalendar().toIso( getCalendar().today() ).toJdkCalendar();
232
233 clearTimeOfDay( calendar );
234
235 return calendar;
236 }271 }
237272
238 /**273 /**
239 * Returns an instance of a Calendar without any time of day, with the given274 * Returns an instance of a Calendar without any time of day, with the given
240 * date.275 * date.
276 *
241 * @param date the date of the Calendar.277 * @param date the date of the Calendar.
242 * @return an instance of a Calendar without any time of day.278 * @return an instance of a Calendar without any time of day.
243 */279 */
@@ -252,7 +288,19 @@
252 }288 }
253289
254 /**290 /**
291 * Returns an instance of a DateUnit.
292 *
293 * @param date date of calendar in local calendar
294 * @return an instance of a Calendar without any time of day.
295 */
296 public static DateUnit createLocalDateUnitInstance( Date date )
297 {
298 return getCalendar().fromIso( DateUnit.fromJdkDate( date ) );
299 }
300
301 /**
255 * Clears the time of day in a Calendar instance.302 * Clears the time of day in a Calendar instance.
303 *
256 * @param calendar the Calendar to fix.304 * @param calendar the Calendar to fix.
257 */305 */
258 public static void clearTimeOfDay( Calendar calendar )306 public static void clearTimeOfDay( Calendar calendar )
@@ -264,85 +312,24 @@
264 }312 }
265313
266 /**314 /**
267 * Parses a date from a String on the format YYYY-MM-DD.
268 * @param dateString the String to parse.
269 * @return a Date based on the given String.
270 */
271 public static Date getMediumDate( String dateString )
272 {
273 try
274 {
275 final SimpleDateFormat format = new SimpleDateFormat();
276 format.applyPattern( "yyyy-MM-dd" );
277 return dateString != null ? format.parse( dateString ) : null;
278 }
279 catch ( ParseException ex )
280 {
281 throw new RuntimeException( "Failed to parse medium date", ex );
282 }
283 }
284
285 /**
286 * Returns a PeriodType corresponding to the provided string The test is315 * Returns a PeriodType corresponding to the provided string The test is
287 * quite rudimentary, testing for string format rather than invalid periods.316 * quite rudimentary, testing for string format rather than invalid periods.
288 * Currently only recognizes the basic subset of common period types.317 * Currently only recognizes the basic subset of common period types.
318 *
289 * @param isoPeriod String formatted period (2011, 201101, 2011W34, 2011Q1319 * @param isoPeriod String formatted period (2011, 201101, 2011W34, 2011Q1
290 * etc320 * etc
291 * @return the PeriodType or null if unrecognized321 * @return the PeriodType or null if unrecognized
292 */322 */
293 public static PeriodType getPeriodTypeFromIsoString( String isoPeriod )323 public static PeriodType getPeriodTypeFromIsoString( String isoPeriod )
294 {324 {
295 if ( isoPeriod.matches( "\\b\\d{4}\\b" ) )325 DateUnitType dateUnitType = DateUnitType.find( isoPeriod );
296 {326 return dateUnitType != null ? PERIOD_TYPE_MAP.get( dateUnitType.getType() ) : null;
297 return PERIOD_TYPE_MAP.get( YearlyPeriodType.NAME );
298 }
299 if ( isoPeriod.matches( "\\b\\d{4}[-]?\\d{2}\\b" ) )
300 {
301 return PERIOD_TYPE_MAP.get( MonthlyPeriodType.NAME );
302 }
303 if ( isoPeriod.matches( "\\b\\d{4}W\\d[\\d]?\\b" ) )
304 {
305 return PERIOD_TYPE_MAP.get( WeeklyPeriodType.NAME );
306 }
307 if ( isoPeriod.matches( "\\b\\d{8}\\b" ) )
308 {
309 return PERIOD_TYPE_MAP.get( DailyPeriodType.NAME );
310 }
311 if ( isoPeriod.matches( "\\b\\d{4}Q\\d\\b" ) )
312 {
313 return PERIOD_TYPE_MAP.get( QuarterlyPeriodType.NAME );
314 }
315 if ( isoPeriod.matches( "\\b\\d{4}S\\d\\b" ) )
316 {
317 return PERIOD_TYPE_MAP.get( SixMonthlyPeriodType.NAME );
318 }
319 if ( isoPeriod.matches( "\\b\\d{4}AprilS\\d\\b" ) )
320 {
321 return PERIOD_TYPE_MAP.get( SixMonthlyAprilPeriodType.NAME );
322 }
323 if ( isoPeriod.matches( "\\b\\d{6}B\\b" ) )
324 {
325 return PERIOD_TYPE_MAP.get( BiMonthlyPeriodType.NAME );
326 }
327 if ( isoPeriod.matches( "\\b\\d{4}April\\b" ) )
328 {
329 return PERIOD_TYPE_MAP.get( FinancialAprilPeriodType.NAME );
330 }
331 if ( isoPeriod.matches( "\\b\\d{4}July\\b" ) )
332 {
333 return PERIOD_TYPE_MAP.get( FinancialJulyPeriodType.NAME );
334 }
335 if ( isoPeriod.matches( "\\b\\d{4}Oct\\b" ) )
336 {
337 return PERIOD_TYPE_MAP.get( FinancialOctoberPeriodType.NAME );
338 }
339
340 return null;
341 }327 }
342328
343 /**329 /**
344 * Returns a period type based on the given date string in ISO format. Returns330 * Returns a period type based on the given date string in ISO format. Returns
345 * null if the date string cannot be parsed to a date.331 * null if the date string cannot be parsed to a date.
332 *
346 * @param isoPeriod the date string in ISO format.333 * @param isoPeriod the date string in ISO format.
347 * @return a period.334 * @return a period.
348 */335 */
@@ -368,6 +355,7 @@
368 /**355 /**
369 * Return the potential number of periods of the given period type which is356 * Return the potential number of periods of the given period type which is
370 * spanned by this period.357 * spanned by this period.
358 *
371 * @param type the period type.359 * @param type the period type.
372 * @return the potential number of periods of the given period type spanned360 * @return the potential number of periods of the given period type spanned
373 * by this period.361 * by this period.
@@ -384,21 +372,55 @@
384 // -------------------------------------------------------------------------372 // -------------------------------------------------------------------------
385373
386 /**374 /**
375 * @param dateInterval DateInterval to create period from
376 * @return the period.
377 */
378 public Period createPeriod( DateInterval dateInterval )
379 {
380 if ( dateInterval == null || dateInterval.getFrom() == null || dateInterval.getTo() == null )
381 {
382 return null;
383 }
384
385 final DateUnit from = getCalendar().toIso( dateInterval.getFrom() );
386 final DateUnit to = getCalendar().toIso( dateInterval.getTo() );
387
388 return new Period( this, from.toJdkDate(), to.toJdkDate() );
389 }
390
391 /**
387 * Returns an iso8601 formatted string representation of the period392 * Returns an iso8601 formatted string representation of the period
393 *
388 * @param period Period394 * @param period Period
389 * @return the period as string395 * @return the period as string
390 */396 */
391 public abstract String getIsoDate( Period period );397 public String getIsoDate( Period period )
398 {
399 return getIsoDate( createLocalDateUnitInstance( period.getStartDate() ) );
400 }
401
402 /**
403 * Returns an iso8601 formatted string representation of the dataUnit
404 *
405 * @param dateUnit Period
406 * @return the period as string
407 */
408 public abstract String getIsoDate( DateUnit dateUnit );
392409
393 /**410 /**
394 * Generates a period based on the given iso8601 formatted string.411 * Generates a period based on the given iso8601 formatted string.
412 *
395 * @param isoDate the iso8601 string.413 * @param isoDate the iso8601 string.
396 * @return the period.414 * @return the period.
397 */415 */
398 public abstract Period createPeriod( String isoDate );416 public Period createPeriod( String isoDate )
417 {
418 return createPeriod( dateUnitFormat.parse( isoDate ) );
419 }
399420
400 /**421 /**
401 * Returns the iso8601 format as a string for this period type.422 * Returns the iso8601 format as a string for this period type.
423 *
402 * @return the iso8601 format.424 * @return the iso8601 format.
403 */425 */
404 public abstract String getIsoFormat();426 public abstract String getIsoFormat();
405427
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java 2014-06-05 17:39:07 +0000
@@ -28,7 +28,9 @@
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */29 */
3030
31import java.util.ArrayList;31import com.google.common.collect.Lists;
32import org.hisp.dhis.calendar.DateUnit;
33
32import java.util.Calendar;34import java.util.Calendar;
33import java.util.Date;35import java.util.Date;
34import java.util.List;36import java.util.List;
@@ -37,7 +39,7 @@
37 * PeriodType for quarterly Periods. A valid quarterly Period has startDate set39 * PeriodType for quarterly Periods. A valid quarterly Period has startDate set
38 * to the first day of a calendar quarter, and endDate set to the last day of40 * to the first day of a calendar quarter, and endDate set to the last day of
39 * the same quarter.41 * the same quarter.
40 * 42 *
41 * @author Torgeir Lorange Ostby43 * @author Torgeir Lorange Ostby
42 * @version $Id: QuarterlyPeriodType.java 2971 2007-03-03 18:54:56Z torgeilo $44 * @version $Id: QuarterlyPeriodType.java 2971 2007-03-03 18:54:56Z torgeilo $
43 */45 */
@@ -69,29 +71,18 @@
69 }71 }
7072
71 @Override73 @Override
72 public Period createPeriod()74 public Period createPeriod( DateUnit dateUnit )
73 {75 {
74 return createPeriod( createCalendarInstance() );76 DateUnit start = new DateUnit( dateUnit );
75 }77
7678 start.setMonth( ((dateUnit.getMonth() - 1) - ((dateUnit.getMonth() - 1) % 3)) + 1 );
77 @Override79 start.setDay( 1 );
78 public Period createPeriod( Date date )80
79 {81 DateUnit end = new DateUnit( start );
80 return createPeriod( createCalendarInstance( date ) );82 end = getCalendar().plusMonths( end, 2 );
81 }83 end.setDay( getCalendar().daysInMonth( end.getYear(), end.getMonth() ) );
8284
83 @Override85 return toIsoPeriod( start, end );
84 public Period createPeriod( Calendar cal )
85 {
86 cal.set( Calendar.MONTH, cal.get( Calendar.MONTH ) - cal.get( Calendar.MONTH ) % 3 );
87 cal.set( Calendar.DAY_OF_MONTH, 1 );
88
89 Date startDate = cal.getTime();
90
91 cal.add( Calendar.MONTH, 2 );
92 cal.set( Calendar.DAY_OF_MONTH, cal.getActualMaximum( Calendar.DAY_OF_MONTH ) );
93
94 return new Period( this, startDate, cal.getTime() );
95 }86 }
9687
97 @Override88 @Override
@@ -107,17 +98,19 @@
107 @Override98 @Override
108 public Period getNextPeriod( Period period )99 public Period getNextPeriod( Period period )
109 {100 {
110 Calendar cal = createCalendarInstance( period.getStartDate() );101 DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
111 cal.add( Calendar.MONTH, 3 );102 dateUnit = getCalendar().plusMonths( dateUnit, 3 );
112 return createPeriod( cal );103
The diff has been truncated for viewing.