dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31569
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16107: Event analytics, unit testing
------------------------------------------------------------
revno: 16107
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-07-12 20:15:50 +0200
message:
Event analytics, unit testing
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java
dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java
dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java
dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml
dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.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/Program.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java 2014-06-17 15:55:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/Program.java 2014-07-12 18:15:50 +0000
@@ -65,34 +65,24 @@
{
public static final List<String> TYPE_LOOKUP = Arrays.asList( "", "MULTIPLE_EVENTS_WITH_REGISTRATION",
"SINGLE_EVENT_WITH_REGISTRATION", "SINGLE_EVENT_WITHOUT_REGISTRATION" );
+
public static final int MULTIPLE_EVENTS_WITH_REGISTRATION = 1;
public static final int SINGLE_EVENT_WITH_REGISTRATION = 2;
public static final int SINGLE_EVENT_WITHOUT_REGISTRATION = 3;
- /**
- * Determines if a de-serialized file is compatible with this class.
- */
- private static final long serialVersionUID = -2581751965520009382L;
+
private String description;
private Integer version;
- /**
- * Description of Date of Enrollment This description is differ from each
- * program
- */
private String dateOfEnrollmentDescription;
- /**
- * Description of Date of Incident This description is differ from each
- * program
- */
private String dateOfIncidentDescription;
@Scanned
private Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
@Scanned
- private Set<ProgramStage> programStages = new HashSet<ProgramStage>();
+ private Set<ProgramStage> programStages = new HashSet<ProgramStage>(); //TODO use List?
@Scanned
private Set<ValidationCriteria> validationCriteria = new HashSet<ValidationCriteria>();
@@ -103,7 +93,7 @@
private Boolean ignoreOverdueEvents = false;
- private Set<ProgramTrackedEntityAttribute> attributes = new HashSet<ProgramTrackedEntityAttribute>();
+ private Set<ProgramTrackedEntityAttribute> attributes = new HashSet<ProgramTrackedEntityAttribute>(); //TODO use List?
@Scanned
private Set<UserAuthorityGroup> userRoles = new HashSet<UserAuthorityGroup>();
@@ -114,8 +104,8 @@
private Set<TrackedEntityInstanceReminder> instanceReminders = new HashSet<TrackedEntityInstanceReminder>();
/**
- * Allow enrolling trackedEntity to all orgunit no matter what the program
- * is assigned for the orgunit or not
+ * Allow enrolling tracked entity to all org units disregarding whether the
+ * program is assigned for the org unit or not.
*/
private Boolean displayOnAllOrgunit = true;
@@ -146,7 +136,7 @@
public Program( String name, String description )
{
- this();
+ setAutoFields();
this.name = name;
this.description = description;
}
@@ -191,7 +181,8 @@
}
/**
- * Returns TrackedEntityAttributes from ProgramTrackedEntityAttributes.
+ * Returns TrackedEntityAttributes from ProgramTrackedEntityAttributes. Use
+ * getAttributes() to access the persisted attribute list.
*/
public List<TrackedEntityAttribute> getTrackedEntityAttributes()
{
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java 2014-07-12 18:15:50 +0000
@@ -76,7 +76,7 @@
private OrganisationUnitGroup ouGroupC;
private OrganisationUnitGroupSet ouGroupSetA;
-
+
@Autowired
private AnalyticsService analyticsService;
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java 2014-07-12 18:15:50 +0000
@@ -28,15 +28,21 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.system.util.CollectionUtils.asSet;
+import static org.junit.Assert.assertEquals;
+
import java.util.HashSet;
+import java.util.Set;
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.analytics.event.EventAnalyticsService;
+import org.hisp.dhis.analytics.event.EventQueryParams;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramService;
-import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
import org.junit.Test;
@@ -48,34 +54,72 @@
public class EventAnalyticsServiceTest
extends DhisSpringTest
{
- @Autowired
- private EventAnalyticsService analyticsService;
-
- @Autowired
- private ProgramService programService;
-
- @Autowired
- private DataElementService dataElementService;
-
- @Autowired
- private TrackedEntityAttributeService attributeService;
-
private Program prA;
+
+ private OrganisationUnit ouA;
+ private OrganisationUnit ouB;
+
private DataElement deA;
private DataElement deB;
+
private TrackedEntityAttribute atA;
private TrackedEntityAttribute atB;
+ @Autowired
+ private EventAnalyticsService analyticsService;
+
+ @Autowired
+ private ProgramService programService;
+
+ @Autowired
+ private DataElementService dataElementService;
+
+ @Autowired
+ private OrganisationUnitService organisationUnitService;
+
+ @Autowired
+ private TrackedEntityAttributeService attributeService;
+
@Override
public void setUpTest()
{
- prA = createProgram( 'A', new HashSet<ProgramStage>(), null );
-
+ ouA = createOrganisationUnit( 'A' );
+ ouB = createOrganisationUnit( 'B' );
+
+ organisationUnitService.addOrganisationUnit( ouA );
+ organisationUnitService.addOrganisationUnit( ouB );
+
+ deA = createDataElement( 'A' );
+ deB = createDataElement( 'B' );
+
+ dataElementService.addDataElement( deA );
+ dataElementService.addDataElement( deB );
+
+ atA = createTrackedEntityAttribute( 'A' );
+ atB = createTrackedEntityAttribute( 'B' );
+
+ attributeService.addTrackedEntityAttribute( atA );
+ attributeService.addTrackedEntityAttribute( atB );
+
+ prA = createProgram( 'A', null, asSet( atA, atB ), asSet( ouA, ouB ) );
+ programService.addProgram( prA );
}
@Test
- public void testGetFromUrl()
+ public void testGetFromUrlA()
{
-
+ Set<String> dimensionParams = new HashSet<String>();
+ dimensionParams.add( "ou:" + ouA.getUid() + ";" + ouB.getId() );
+ dimensionParams.add( atA.getUid() + ":LE:5" );
+
+ Set<String> filterParams = new HashSet<String>();
+ filterParams.add( "pe:201401;201402" );
+
+ EventQueryParams params = analyticsService.getFromUrl( prA.getUid(), null,
+ null, null, dimensionParams, filterParams, false, false, null, null, false, null );
+
+ assertEquals( prA, params.getProgram() );
+ assertEquals( 1, params.getOrganisationUnits().size() );
+ assertEquals( 2, params.getFilterPeriods().size() );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml 2014-05-14 15:14:18 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/Program.hbm.xml 2014-07-12 18:15:50 +0000
@@ -13,7 +13,7 @@
<id name="id" column="programid">
<generator class="native" />
</id>
- &identifiableProperties;
+ &identifiableProperties;
<property name="name" column="name" not-null="true" length="230" />
=== 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 2014-07-08 17:16:48 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java 2014-07-12 18:15:50 +0000
@@ -108,6 +108,7 @@
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageService;
+import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
import org.hisp.dhis.relationship.RelationshipType;
import org.hisp.dhis.resourcetable.ResourceTableService;
import org.hisp.dhis.sqlview.SqlView;
@@ -1162,11 +1163,19 @@
}
protected static Program createProgram( char uniqueCharacter, Set<ProgramStage> programStages,
- OrganisationUnit organisationUnit )
+ OrganisationUnit unit )
+ {
+ Set<OrganisationUnit> units = new HashSet<>();
+ units.add( unit );
+
+ return createProgram( uniqueCharacter, programStages, null, units );
+ }
+
+ protected static Program createProgram( char uniqueCharacter, Set<ProgramStage> programStages,
+ Set<TrackedEntityAttribute> attributes, Set<OrganisationUnit> organisationUnits )
{
Program program = new Program();
- program.setAutoFields();
-
+
program.setName( "Program" + uniqueCharacter );
program.setDescription( "Description" + uniqueCharacter );
program.setDateOfEnrollmentDescription( "DateOfEnrollmentDescription" );
@@ -1179,11 +1188,25 @@
for ( ProgramStage programStage : programStages )
{
programStage.setProgram( program );
- }
- }
-
- program.getOrganisationUnits().add( organisationUnit );
-
+ program.getProgramStages().add( programStage );
+ }
+ }
+
+ if ( attributes != null )
+ {
+ int i = 0;
+
+ for ( TrackedEntityAttribute attribute : attributes )
+ {
+ program.getAttributes().add( new ProgramTrackedEntityAttribute( attribute, i++, false ) );
+ }
+ }
+
+ if ( organisationUnits != null )
+ {
+ program.getOrganisationUnits().addAll( organisationUnits );
+ }
+
return program;
}