dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24764
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12191: more testing of EventService
------------------------------------------------------------
revno: 12191
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-09-20 17:12:37 +0200
message:
more testing of EventService
removed:
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EventServiceTest.java
added:
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/JacksonEnrollmentService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/DataValue.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/DefaultEventStore.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JacksonEventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/JacksonPersonService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/PersonService.java
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EnrollmentServiceTest.java
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/PersonServiceTest.java
dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java
dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/hibernate-default.properties
dhis-2/dhis-support/dhis-support-test/pom.xml
dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java
dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java 2013-09-18 02:45:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java 2013-09-20 15:12:37 +0000
@@ -91,10 +91,12 @@
public ProgramStageInstance()
{
+ setAutoFields();
}
public ProgramStageInstance( ProgramInstance programInstance, ProgramStage programStage )
{
+ this();
this.programInstance = programInstance;
this.programStage = programStage;
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java 2013-09-20 08:14:40 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java 2013-09-20 15:12:37 +0000
@@ -74,6 +74,7 @@
private I18nFormat _format;
+ @Override
public void setFormat( I18nFormat format )
{
this._format = format;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java 2013-09-18 14:03:19 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java 2013-09-20 15:12:37 +0000
@@ -31,6 +31,7 @@
import org.hisp.dhis.dxf2.events.person.Person;
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.program.Program;
@@ -45,6 +46,8 @@
*/
public interface EnrollmentService
{
+ public void setFormat(I18nFormat format);
+
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/JacksonEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/JacksonEnrollmentService.java 2013-09-18 13:42:06 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/JacksonEnrollmentService.java 2013-09-20 15:12:37 +0000
@@ -33,7 +33,7 @@
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
-import org.hisp.dhis.patient.Patient;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StreamUtils;
import java.io.IOException;
@@ -43,6 +43,7 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
+@Transactional
public class JacksonEnrollmentService extends AbstractEnrollmentService
{
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2013-09-20 08:14:40 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2013-09-20 15:12:37 +0000
@@ -69,7 +69,6 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@Transactional
public abstract class AbstractEventService implements EventService
{
// -------------------------------------------------------------------------
@@ -117,6 +116,7 @@
private I18nFormat _format;
+ @Override
public void setFormat( I18nFormat format )
{
this._format = format;
@@ -144,7 +144,14 @@
// CREATE
// -------------------------------------------------------------------------
- protected ImportSummary saveEvent( Event event, ImportOptions importOptions )
+ @Override
+ public ImportSummary saveEvent( Event event )
+ {
+ return saveEvent( event, null );
+ }
+
+ @Override
+ public ImportSummary saveEvent( Event event, ImportOptions importOptions )
{
Program program = programService.getProgram( event.getProgram() );
ProgramInstance programInstance = null;
@@ -165,6 +172,7 @@
programStage = program.getProgramStageByStage( 1 );
}
+ Assert.notNull( program );
Assert.notNull( programStage );
if ( verifyProgramAccess( program ) )
@@ -209,18 +217,36 @@
if ( programStageInstances.isEmpty() )
{
- return new ImportSummary( ImportStatus.ERROR, "No active event exists for single event program " + program.getUid()
+ return new ImportSummary( ImportStatus.ERROR, "No active event exists for single event registration program " + program.getUid()
+ ", please check and correct your database." );
}
else if ( programStageInstances.size() > 1 )
{
- return new ImportSummary( ImportStatus.ERROR, "Multiple active events exists for single event program " + program.getUid()
+ return new ImportSummary( ImportStatus.ERROR, "Multiple active events exists for single event registration program " + program.getUid()
+ ", please check and correct your database." );
}
programStageInstance = programStageInstances.get( 0 );
}
}
+ else
+ {
+ List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>(
+ programInstanceService.getProgramInstances( program, ProgramInstance.STATUS_ACTIVE ) );
+
+ if ( programInstances.isEmpty() )
+ {
+ return new ImportSummary( ImportStatus.ERROR, "No active event exists for single event no registration program " + program.getUid()
+ + ", please check and correct your database." );
+ }
+ else if ( programInstances.size() > 1 )
+ {
+ return new ImportSummary( ImportStatus.ERROR, "Multiple active events exists for single event no registration program " + program.getUid()
+ + ", please check and correct your database." );
+ }
+
+ programInstance = programInstances.get( 0 );
+ }
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( event.getOrgUnit() );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/DataValue.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/DataValue.java 2013-09-17 12:15:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/DataValue.java 2013-09-20 15:12:37 +0000
@@ -48,6 +48,12 @@
{
}
+ public DataValue( String dataElement, String value )
+ {
+ this.dataElement = dataElement;
+ this.value = value;
+ }
+
@JsonProperty
@JacksonXmlProperty( isAttribute = true )
public String getValue()
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/DefaultEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/DefaultEventStore.java 2013-09-17 12:15:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/DefaultEventStore.java 2013-09-20 15:12:37 +0000
@@ -28,13 +28,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.common.IdentifiableObjectUtils.getIdList;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramStage;
@@ -43,6 +36,15 @@
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getIdList;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java 2013-09-17 15:26:14 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java 2013-09-20 15:12:37 +0000
@@ -31,6 +31,7 @@
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.dxf2.metadata.ImportOptions;
+import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramStage;
@@ -47,6 +48,8 @@
*/
public interface EventService
{
+ public void setFormat(I18nFormat format);
+
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@@ -73,6 +76,10 @@
// CREATE
// -------------------------------------------------------------------------
+ ImportSummary saveEvent( Event event );
+
+ ImportSummary saveEvent( Event event, ImportOptions importOptions );
+
ImportSummary saveEventXml( InputStream inputStream ) throws IOException;
ImportSummary saveEventXml( InputStream inputStream, ImportOptions importOptions ) throws IOException;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JacksonEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JacksonEventService.java 2013-09-17 12:15:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JacksonEventService.java 2013-09-20 15:12:37 +0000
@@ -38,6 +38,7 @@
import org.hisp.dhis.system.notification.NotificationLevel;
import org.hisp.dhis.system.notification.Notifier;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StreamUtils;
import java.io.IOException;
@@ -49,6 +50,7 @@
*
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
+@Transactional
public class JacksonEventService extends AbstractEventService
{
@Autowired
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java 2013-09-19 10:07:24 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java 2013-09-20 15:12:37 +0000
@@ -32,6 +32,9 @@
import org.hisp.dhis.dxf2.importsummary.ImportConflict;
import org.hisp.dhis.dxf2.importsummary.ImportStatus;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.i18n.I18nManager;
+import org.hisp.dhis.i18n.I18nManagerException;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.patient.PatientAttribute;
@@ -48,7 +51,6 @@
import org.hisp.dhis.relationship.RelationshipType;
import org.hisp.dhis.relationship.RelationshipTypeService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.ArrayList;
@@ -66,7 +68,6 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@Transactional
public abstract class AbstractPersonService implements PersonService
{
// -------------------------------------------------------------------------
@@ -91,9 +92,35 @@
@Autowired
private IdentifiableObjectManager manager;
- // -------------------------------------------------------------------------
- // Implementation
- // -------------------------------------------------------------------------
+ @Autowired
+ private I18nManager i18nManager;
+
+ private I18nFormat _format;
+
+ @Override
+ public void setFormat( I18nFormat format )
+ {
+ this._format = format;
+ }
+
+ public I18nFormat getFormat()
+ {
+ if ( _format != null )
+ {
+ return _format;
+ }
+
+ try
+ {
+ _format = i18nManager.getI18nFormat();
+ }
+ catch ( I18nManagerException ignored )
+ {
+ }
+
+ return _format;
+ }
+
// -------------------------------------------------------------------------
// READ
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/JacksonPersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/JacksonPersonService.java 2013-09-17 12:15:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/JacksonPersonService.java 2013-09-20 15:12:37 +0000
@@ -35,6 +35,7 @@
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.system.notification.Notifier;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StreamUtils;
import java.io.IOException;
@@ -44,6 +45,7 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
+@Transactional
public class JacksonPersonService extends AbstractPersonService
{
@Autowired
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/PersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/PersonService.java 2013-09-17 12:15:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/PersonService.java 2013-09-20 15:12:37 +0000
@@ -30,6 +30,7 @@
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.program.Program;
@@ -43,6 +44,8 @@
*/
public interface PersonService
{
+ public void setFormat(I18nFormat format);
+
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EnrollmentServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EnrollmentServiceTest.java 2013-09-20 09:17:59 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EnrollmentServiceTest.java 2013-09-20 15:12:37 +0000
@@ -30,7 +30,6 @@
import org.hisp.dhis.DhisTest;
import org.hisp.dhis.common.IdentifiableObjectManager;
-import org.hisp.dhis.dxf2.events.enrollment.AbstractEnrollmentService;
import org.hisp.dhis.dxf2.events.enrollment.Enrollment;
import org.hisp.dhis.dxf2.events.enrollment.EnrollmentService;
import org.hisp.dhis.dxf2.events.enrollment.EnrollmentStatus;
@@ -120,7 +119,7 @@
// mocked format
I18nFormat mockFormat = mock( I18nFormat.class );
- ((AbstractEnrollmentService) enrollmentService).setFormat( mockFormat );
+ enrollmentService.setFormat( mockFormat );
}
@Override
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EventServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EventServiceTest.java 2013-09-19 17:42:17 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EventServiceTest.java 1970-01-01 00:00:00 +0000
@@ -1,65 +0,0 @@
-package org.hisp.dhis.dxf2.events;
-
-/*
- * Copyright (c) 2004-2013, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import org.hisp.dhis.DhisTest;
-import org.hisp.dhis.common.IdentifiableObjectManager;
-import org.hisp.dhis.dxf2.events.event.EventService;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class EventServiceTest
- extends DhisTest
-{
- @Autowired
- private EventService eventService;
-
- @Autowired
- private IdentifiableObjectManager manager;
-
- @Override
- protected void setUpTest() throws Exception
- {
- }
-
- @Override
- public boolean emptyDatabaseAfterTest()
- {
- return true;
- }
-
- @Test
- public void noTest()
- {
-
- }
-}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java 2013-09-20 15:12:37 +0000
@@ -0,0 +1,171 @@
+package org.hisp.dhis.dxf2.events;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.DhisTest;
+import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dxf2.events.event.DataValue;
+import org.hisp.dhis.dxf2.events.event.Event;
+import org.hisp.dhis.dxf2.events.event.EventService;
+import org.hisp.dhis.dxf2.importsummary.ImportStatus;
+import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramInstanceService;
+import org.hisp.dhis.program.ProgramStage;
+import org.hisp.dhis.program.ProgramStageDataElement;
+import org.hisp.dhis.program.ProgramStageDataElementService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserAuthorityGroup;
+import org.hisp.dhis.user.UserService;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.UserDetails;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class NoRegistrationSingleEventServiceTest
+ extends DhisTest
+{
+ @Autowired
+ private EventService eventService;
+
+ @Autowired
+ private ProgramStageDataElementService programStageDataElementService;
+
+ @Autowired
+ private ProgramInstanceService programInstanceService;
+
+ @Autowired
+ private IdentifiableObjectManager manager;
+
+ @Autowired
+ private UserService userService;
+
+ private OrganisationUnit organisationUnitA;
+ private DataElement dataElementA;
+ private Program programA;
+ private ProgramStage programStageA;
+
+ @Override
+ protected void setUpTest() throws Exception
+ {
+ organisationUnitA = createOrganisationUnit( 'A' );
+ manager.save( organisationUnitA );
+
+ dataElementA = createDataElement( 'A' );
+ dataElementA.setType( DataElement.VALUE_TYPE_INT );
+ manager.save( dataElementA );
+
+ programStageA = createProgramStage( 'A', 0 );
+ manager.save( programStageA );
+
+ programA = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnitA );
+ programA.setType( Program.SINGLE_EVENT_WITHOUT_REGISTRATION );
+ manager.save( programA );
+
+ ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
+ programStageDataElement.setDataElement( dataElementA );
+ programStageDataElement.setProgramStage( programStageA );
+ programStageDataElementService.addProgramStageDataElement( programStageDataElement );
+
+ programStageA.getProgramStageDataElements().add( programStageDataElement );
+ programStageA.setProgram( programA );
+ programA.getProgramStages().add( programStageA );
+
+ manager.update( programStageA );
+ manager.update( programA );
+
+ ProgramInstance programInstance = new ProgramInstance();
+ programInstance.setProgram( programA );
+ programInstance.setDateOfIncident( new Date() );
+ programInstance.setEnrollmentDate( new Date() );
+
+ programInstanceService.addProgramInstance( programInstance );
+ programA.getProgramInstances().add( programInstance );
+ manager.update( programA );
+
+ createSuperuserAndInjectSecurityContext( 'A' );
+
+ // mocked format
+ I18nFormat mockFormat = mock( I18nFormat.class );
+ when( mockFormat.parseDate( anyString() ) ).thenReturn( new Date() );
+ eventService.setFormat( mockFormat );
+ }
+
+ @Override
+ public boolean emptyDatabaseAfterTest()
+ {
+ return true;
+ }
+
+ @Test
+ public void testSaveEvent()
+ {
+ Event event = createEvent( programA.getUid(), organisationUnitA.getUid() );
+
+ ImportSummary importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+ assertNotNull( importSummary.getReference() );
+
+ assertEquals( 1, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+ }
+
+ private Event createEvent( String program, String orgUnit )
+ {
+ Event event = new Event();
+ event.setProgram( program );
+ event.setOrgUnit( orgUnit );
+
+ event.getDataValues().add( new DataValue( dataElementA.getUid(), "10" ) );
+
+ return event;
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/PersonServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/PersonServiceTest.java 2013-09-20 07:29:46 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/PersonServiceTest.java 2013-09-20 15:12:37 +0000
@@ -42,7 +42,6 @@
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramInstanceService;
import org.hisp.dhis.program.ProgramStage;
-import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java 2013-09-19 14:00:03 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java 2013-09-20 15:12:37 +0000
@@ -97,6 +97,15 @@
emptyTable( "reporttable_filters" );
emptyTable( "reporttable" );
+ emptyTable( "userrolemembers" );
+ emptyTable( "userroledataset" );
+ emptyTable( "userroleauthorities" );
+ emptyTable( "usergroupmembers" );
+ emptyTable( "usergroup" );
+ emptyTable( "users" );
+ emptyTable( "userinfo" );
+ emptyTable( "userrole" );
+
emptyTable( "orgunitgroupsetmembers" );
emptyTable( "orgunitgroupset" );
emptyTable( "orgunitgroupmembers" );
@@ -116,6 +125,16 @@
emptyTable( "datasetoperands" );
emptyTable( "dataset" );
+ emptyTable( "programstageinstance" );
+ emptyTable( "programinstance" );
+ emptyTable( "programstage_dataelements" );
+ emptyTable( "programstage" );
+ emptyTable( "program_organisationunits" );
+ emptyTable( "program" );
+ emptyTable( "patientidentifier" );
+ emptyTable( "patientidentifier_patient" );
+ emptyTable( "patient" );
+
emptyTable( "minmaxdataelement" );
emptyTable( "expressiondataelement" );
emptyTable( "expressionoptioncombo" );
@@ -132,15 +151,6 @@
emptyTable( "categorycombos_categories" );
emptyTable( "categories_categoryoptions" );
- emptyTable( "programstageinstance" );
- emptyTable( "programinstance" );
- emptyTable( "programstage" );
- emptyTable( "program_organisationunits" );
- emptyTable( "program" );
- emptyTable( "patientidentifier" );
- emptyTable( "patientidentifier_patient" );
- emptyTable( "patient" );
-
emptyTable( "organisationunit" );
emptyTable( "version" );
emptyTable( "mocksource" );
@@ -158,14 +168,14 @@
emptyTable( "categorycombo" );
emptyTable( "dataelementcategory" );
emptyTable( "dataelementcategoryoption" );
-
+
emptyTable( "optionsetmembers" );
emptyTable( "optionset" );
dropTable( "aggregateddatavalue" );
dropTable( "aggregatedindicatorvalue" );
dropTable( "aggregateddatasetcompleteness" );
-
+
dropTable( "aggregatedorgunitdatavalue" );
dropTable( "aggregatedorgunitindicatorvalue" );
dropTable( "aggregatedorgunitdatasetcompleteness" );
=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/hibernate-default.properties'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/hibernate-default.properties 2012-03-12 20:25:54 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/hibernate-default.properties 2013-09-20 15:12:37 +0000
@@ -12,7 +12,7 @@
hibernate.dialect = org.hibernate.dialect.H2Dialect
hibernate.connection.driver_class = org.h2.Driver
-hibernate.connection.url = jdbc:h2:mem:dhis2;DB_CLOSE_DELAY=-1;MVCC=TRUE
+hibernate.connection.url = jdbc:h2:mem:dhis2;DB_CLOSE_DELAY=-1;MVCC=TRUE;ALIAS_COLUMN_NAME=TRUE
hibernate.connection.username = sa
hibernate.connection.password =
hibernate.hbm2ddl.auto = create-drop
@@ -50,4 +50,4 @@
# hibernate.show_sql = true
# hibernate.format_sql = true
-# hibernate.use_sql_comments = true
\ No newline at end of file
+# hibernate.use_sql_comments = true
=== modified file 'dhis-2/dhis-support/dhis-support-test/pom.xml'
--- dhis-2/dhis-support/dhis-support-test/pom.xml 2013-05-31 08:27:38 +0000
+++ dhis-2/dhis-support/dhis-support-test/pom.xml 2013-09-20 15:12:37 +0000
@@ -36,6 +36,10 @@
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-core</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java 2013-09-20 09:56:36 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java 2013-09-20 15:12:37 +0000
@@ -34,6 +34,7 @@
import org.hisp.dhis.aggregation.AggregatedOrgUnitDataValueService;
import org.hisp.dhis.chart.Chart;
import org.hisp.dhis.common.DimensionalObject;
+import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.concept.Concept;
import org.hisp.dhis.constant.Constant;
import org.hisp.dhis.constant.ConstantService;
@@ -85,6 +86,7 @@
import org.hisp.dhis.resourcetable.ResourceTableService;
import org.hisp.dhis.sqlview.SqlView;
import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserAuthorityGroup;
import org.hisp.dhis.user.UserCredentials;
import org.hisp.dhis.user.UserGroup;
import org.hisp.dhis.user.UserService;
@@ -95,6 +97,13 @@
import org.hisp.dhis.validation.ValidationRuleService;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.UserDetails;
import org.xml.sax.InputSource;
import javax.xml.XMLConstants;
@@ -105,8 +114,10 @@
import java.io.File;
import java.io.StringReader;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
@@ -246,10 +257,7 @@
{
final Collection<Object> collection = new HashSet<Object>();
- for ( Object object : reference )
- {
- collection.add( object );
- }
+ Collections.addAll( collection, reference );
if ( actual == collection )
{
@@ -415,7 +423,7 @@
/**
* @param uniqueCharacter A unique character to identify the object.
- * @param valueType The value type.
+ * @param type The value type.
* @param aggregationOperator The aggregation operator.
*/
public static DataElement createDataElement( char uniqueCharacter, String type, String aggregationOperator )
@@ -430,7 +438,7 @@
/**
* @param uniqueCharacter A unique character to identify the object.
- * @param valueType The value type.
+ * @param type The value type.
* @param aggregationOperator The aggregation operator.
* @param categoryCombo The category combo.
*/
@@ -452,7 +460,7 @@
* @param categoryOptionUniqueIdentifiers
* Unique characters to identify the
* category options.
- * @return
+ * @return DataElementCategoryOptionCombo
*/
public static DataElementCategoryOptionCombo createCategoryOptionCombo( char categoryComboUniqueIdentifier,
char... categoryOptionUniqueIdentifiers )
@@ -474,7 +482,7 @@
/**
* @param categoryCombo the category combo.
* @param categoryOptions the category options.
- * @return
+ * @return DataElementCategoryOptionCombo
*/
public static DataElementCategoryOptionCombo createCategoryOptionCombo( DataElementCategoryCombo categoryCombo, DataElementCategoryOption... categoryOptions )
{
@@ -787,7 +795,7 @@
/**
* @param uniqueCharacter A unique character to identify the object.
- * @return
+ * @return ValidationRuleGroup
*/
public static ValidationRuleGroup createValidationRuleGroup( char uniqueCharacter )
{
@@ -890,6 +898,7 @@
UserCredentials credentials = new UserCredentials();
credentials.setUsername( "username" );
+ credentials.setPassword( "password" );
user.setUserCredentials( credentials );
@@ -976,7 +985,7 @@
/**
* @param uniqueCharacter A unique character to identify the object.
- * @return
+ * @return ValidationCriteria
*/
public static ValidationCriteria createValidationCriteria( char uniqueCharacter, String property, int operator,
Object value )
=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisTest.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisTest.java 2013-09-20 15:12:37 +0000
@@ -29,10 +29,16 @@
*/
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
+import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dbms.DbmsManager;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserAuthorityGroup;
+import org.hisp.dhis.user.UserService;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
@@ -41,6 +47,12 @@
import org.springframework.context.ApplicationContextAware;
import org.springframework.orm.hibernate4.SessionFactoryUtils;
import org.springframework.orm.hibernate4.SessionHolder;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -173,4 +185,36 @@
SessionFactoryUtils.closeSession( sessionHolder.getSession() );
}
+
+ private UserService _userService;
+
+ private IdentifiableObjectManager _manager;
+
+ public User createSuperuserAndInjectSecurityContext( char uniqueCharacter )
+ {
+ _userService = (UserService) getBean( "org.hisp.dhis.user.UserService" );
+ _manager = (IdentifiableObjectManager) getBean( "org.hisp.dhis.common.IdentifiableObjectManager" );
+
+ UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
+ userAuthorityGroup.setName( "Superuser" );
+ userAuthorityGroup.getAuthorities().add( "ALL" );
+ _manager.save( userAuthorityGroup );
+
+ User user = createUser( 'A' );
+ user.getUserCredentials().getUserAuthorityGroups().add( userAuthorityGroup );
+ _userService.addUser( user );
+ user.getUserCredentials().setUser( user );
+ _userService.addUserCredentials( user.getUserCredentials() );
+
+ List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
+ authorities.add( new SimpleGrantedAuthority( "ALL" ) );
+
+ UserDetails userDetails = new org.springframework.security.core.userdetails.User( "username", "password", authorities );
+
+ Authentication authentication = new UsernamePasswordAuthenticationToken( userDetails, "", authorities );
+ SecurityContextHolder.getContext().setAuthentication( authentication );
+
+ return user;
+ }
+
}