dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43813
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22215: Code style, typos
------------------------------------------------------------
revno: 22215
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-03-09 17:58:54 +0100
message:
Code style, typos
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminder.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceReminderService.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminderServiceTest.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/trackedentity/TrackedEntityInstanceReminder.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminder.java 2016-02-11 09:27:02 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminder.java 2016-03-09 16:58:54 +0000
@@ -61,43 +61,27 @@
public static final String INCIDENT_DATE_TO_COMPARE = "incidentdate";
public static final String TEMPLATE_MESSSAGE_PROGRAM_NAME = "{program-name}";
-
public static final String TEMPLATE_MESSSAGE_PROGAM_STAGE_NAME = "{program-stage-name}";
-
public static final String TEMPLATE_MESSSAGE_DUE_DATE = "{due-date}";
-
public static final String TEMPLATE_MESSSAGE_ORGUNIT_NAME = "{orgunit-name}";
-
public static final String TEMPLATE_MESSSAGE_DAYS_SINCE_DUE_DATE = "{days-since-due-date}";
-
public static final String TEMPLATE_MESSSAGE_INCIDENT_DATE = "{incident-date}";
-
public static final String TEMPLATE_MESSSAGE_ENROLLMENT_DATE = "{enrollement-date}";
-
public static final String TEMPLATE_MESSSAGE_DAYS_SINCE_ENROLLMENT_DATE = "{days-since-enrollment-date}";
-
public static final String TEMPLATE_MESSSAGE_DAYS_SINCE_INCIDENT_DATE = "{days-since-incident-date}";
public static final int SEND_TO_TRACKED_ENTITY_INSTANCE = 1;
-
public static final int SEND_TO_ATTRIBUTE_TYPE_USERS = 2;
-
- public static final int SEND_TO_ORGUGNIT_REGISTERED = 3;
-
- public static final int SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED = 4;
-
+ public static final int SEND_TO_REGISTERED_ORGUNIT = 3;
+ public static final int SEND_TO_ALL_USERS_AT_REGISTERED_ORGUNIT = 4;
public static final int SEND_TO_USER_GROUP = 5;
public static final int SEND_WHEN_TO_ENROLLMENT = 1;
-
public static final int SEND_WHEN_TO_C0MPLETED_EVENT = 2;
-
public static final int SEND_WHEN_TO_COMPLETED_PROGRAM = 3;
public static final int MESSAGE_TYPE_DIRECT_SMS = 1;
-
public static final int MESSAGE_TYPE_DHIS_MESSAGE = 2;
-
public static final int MESSAGE_TYPE_BOTH = 3;
private Integer daysAllowedSendMessage;
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java 2016-03-09 16:58:54 +0000
@@ -499,7 +499,7 @@
+ " and prm.templatemessage is not NULL and prm.templatemessage != '' "
+ " and pg.type='" + ProgramType.WITH_REGISTRATION.name() + "' and prm.daysallowedsendmessage is not null " + " and ( DATE(now()) - DATE( pi."
+ dateToCompare + " ) ) = prm.daysallowedsendmessage " + " and prm.dateToCompare='" + dateToCompare
- + "' and prm.whenToSend is null and prm.sendto = " + TrackedEntityInstanceReminder.SEND_TO_ORGUGNIT_REGISTERED;
+ + "' and prm.whenToSend is null and prm.sendto = " + TrackedEntityInstanceReminder.SEND_TO_REGISTERED_ORGUNIT;
}
private String sendMessageToUsersSql( String dateToCompare )
@@ -525,7 +525,7 @@
+ " and prm.dateToCompare='"
+ dateToCompare
+ "' and prm.sendto = "
- + TrackedEntityInstanceReminder.SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED;
+ + TrackedEntityInstanceReminder.SEND_TO_ALL_USERS_AT_REGISTERED_ORGUNIT;
}
private String sendMessageToUserGroupsSql( String dateToCompare )
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java 2016-02-10 14:57:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java 2016-03-09 16:58:54 +0000
@@ -360,7 +360,7 @@
+ " and psi.executiondate is null "
+ " and ( DATE(now()) - DATE(psi.duedate) ) = prm.daysallowedsendmessage "
+ " and prm.whentosend is null and prm.sendto = "
- + +TrackedEntityInstanceReminder.SEND_TO_ORGUGNIT_REGISTERED;
+ + +TrackedEntityInstanceReminder.SEND_TO_REGISTERED_ORGUNIT;
}
private String sendMessageToUsersSql()
@@ -392,7 +392,7 @@
+ " and psi.executiondate is null "
+ " and ( DATE(now()) - DATE(psi.duedate) ) = prm.daysallowedsendmessage "
+ " and prm.whentosend is null and prm.sendto = "
- + TrackedEntityInstanceReminder.SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED;
+ + TrackedEntityInstanceReminder.SEND_TO_ALL_USERS_AT_REGISTERED_ORGUNIT;
}
private String sendMessageToUserGroupsSql()
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceReminderService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceReminderService.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceReminderService.java 2016-03-09 16:58:54 +0000
@@ -1,5 +1,7 @@
package org.hisp.dhis.trackedentity;
+import org.apache.commons.lang.StringUtils;
+
/*
* Copyright (c) 2004-2016, University of Oslo
* All rights reserved.
@@ -46,8 +48,7 @@
import java.util.Set;
import java.util.regex.Matcher;
-import static org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder.ATTRIBUTE;
-import static org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder.ATTRIBUTE_PATTERN;
+import static org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder.*;
/**
* @author Chau Thu Tran
@@ -104,25 +105,19 @@
String incidentDate = format.formatDate( programInstance.getIncidentDate() );
String erollmentDate = format.formatDate( programInstance.getEnrollmentDate() );
- templateMessage = templateMessage.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_PROGRAM_NAME,
- programName );
- templateMessage = templateMessage.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_ORGUNIT_NAME,
- organisationunitName );
- templateMessage = templateMessage.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_INCIDENT_DATE,
- incidentDate );
- templateMessage = templateMessage.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_ENROLLMENT_DATE,
- erollmentDate );
- templateMessage = templateMessage.replace(
- TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_ENROLLMENT_DATE, daysSinceEnrollementDate );
- templateMessage = templateMessage.replace(
- TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_INCIDENT_DATE, daysSinceIncidentDate );
+ templateMessage = templateMessage.replace( TEMPLATE_MESSSAGE_PROGRAM_NAME, programName );
+ templateMessage = templateMessage.replace( TEMPLATE_MESSSAGE_ORGUNIT_NAME, organisationunitName );
+ templateMessage = templateMessage.replace( TEMPLATE_MESSSAGE_INCIDENT_DATE, incidentDate );
+ templateMessage = templateMessage.replace( TEMPLATE_MESSSAGE_ENROLLMENT_DATE, erollmentDate );
+ templateMessage = templateMessage.replace( TEMPLATE_MESSSAGE_DAYS_SINCE_ENROLLMENT_DATE, daysSinceEnrollementDate );
+ templateMessage = templateMessage.replace( TEMPLATE_MESSSAGE_DAYS_SINCE_INCIDENT_DATE, daysSinceIncidentDate );
Matcher matcher = ATTRIBUTE_PATTERN.matcher( template );
while ( matcher.find() )
{
String match = matcher.group();
- String value = "";
+ String value = StringUtils.EMPTY;
if ( matcher.group( 1 ).equals( ATTRIBUTE ) )
{
@@ -155,15 +150,11 @@
String daysSinceDueDate = DateUtils.daysBetween( new Date(), programStageInstance.getDueDate() ) + "";
String dueDate = format.formatDate( programStageInstance.getDueDate() );
- templateMessage = templateMessage.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_PROGRAM_NAME,
- programName );
- templateMessage = templateMessage.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_PROGAM_STAGE_NAME,
- programStageName );
- templateMessage = templateMessage.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_DUE_DATE, dueDate );
- templateMessage = templateMessage.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_ORGUNIT_NAME,
- organisationunitName );
- templateMessage = templateMessage.replace( TrackedEntityInstanceReminder.TEMPLATE_MESSSAGE_DAYS_SINCE_DUE_DATE,
- daysSinceDueDate );
+ templateMessage = templateMessage.replace( TEMPLATE_MESSSAGE_PROGRAM_NAME, programName );
+ templateMessage = templateMessage.replace( TEMPLATE_MESSSAGE_PROGAM_STAGE_NAME, programStageName );
+ templateMessage = templateMessage.replace( TEMPLATE_MESSSAGE_DUE_DATE, dueDate );
+ templateMessage = templateMessage.replace( TEMPLATE_MESSSAGE_ORGUNIT_NAME, organisationunitName );
+ templateMessage = templateMessage.replace( TEMPLATE_MESSSAGE_DAYS_SINCE_DUE_DATE, daysSinceDueDate );
Matcher matcher = ATTRIBUTE_PATTERN.matcher( templateMessage );
@@ -212,64 +203,69 @@
public Set<String> getPhoneNumbers( TrackedEntityInstanceReminder reminder, TrackedEntityInstance entityInstance )
{
Set<String> phoneNumbers = new HashSet<>();
- switch ( reminder.getSendTo() )
- {
- case TrackedEntityInstanceReminder.SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED:
- Collection<User> users = entityInstance.getOrganisationUnit().getUsers();
-
- for ( User user : users )
- {
- if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( user.getPhoneNumber() );
- }
- }
- break;
- case TrackedEntityInstanceReminder.SEND_TO_ATTRIBUTE_TYPE_USERS:
- if ( entityInstance.getTrackedEntityAttributeValues() != null )
- {
- for ( TrackedEntityAttributeValue attributeValue : entityInstance.getTrackedEntityAttributeValues() )
- {
- if ( ValueType.USERNAME == attributeValue.getAttribute().getValueType() )
- {
- User user = userService.getUser( Integer.parseInt( attributeValue.getValue() ) );
-
- if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( user.getPhoneNumber() );
- }
- }
- }
- }
- break;
- case TrackedEntityInstanceReminder.SEND_TO_ORGUGNIT_REGISTERED:
- if ( entityInstance.getOrganisationUnit().getPhoneNumber() != null
- && !entityInstance.getOrganisationUnit().getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( entityInstance.getOrganisationUnit().getPhoneNumber() );
- }
- break;
- case TrackedEntityInstanceReminder.SEND_TO_USER_GROUP:
- for ( User user : reminder.getUserGroup().getMembers() )
- {
- if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
- {
- phoneNumbers.add( user.getPhoneNumber() );
- }
- }
- break;
- default:
- if ( entityInstance.getTrackedEntityAttributeValues() != null )
- {
- for ( TrackedEntityAttributeValue attributeValue : entityInstance.getTrackedEntityAttributeValues() )
- {
- if ( ValueType.PHONE_NUMBER == attributeValue.getAttribute().getValueType() )
- {
- phoneNumbers.add( attributeValue.getValue() );
- }
- }
- }
- break;
+
+ int sendTo = reminder.getSendTo();
+
+ if ( SEND_TO_ALL_USERS_AT_REGISTERED_ORGUNIT == sendTo )
+ {
+ Collection<User> users = entityInstance.getOrganisationUnit().getUsers();
+
+ for ( User user : users )
+ {
+ if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
+ {
+ phoneNumbers.add( user.getPhoneNumber() );
+ }
+ }
+ }
+ else if ( SEND_TO_ATTRIBUTE_TYPE_USERS == sendTo )
+ {
+ if ( entityInstance.getTrackedEntityAttributeValues() != null )
+ {
+ for ( TrackedEntityAttributeValue attributeValue : entityInstance.getTrackedEntityAttributeValues() )
+ {
+ if ( ValueType.USERNAME == attributeValue.getAttribute().getValueType() )
+ {
+ User user = userService.getUser( Integer.parseInt( attributeValue.getValue() ) );
+
+ if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
+ {
+ phoneNumbers.add( user.getPhoneNumber() );
+ }
+ }
+ }
+ }
+ }
+ else if ( SEND_TO_REGISTERED_ORGUNIT == sendTo )
+ {
+ if ( entityInstance.getOrganisationUnit().getPhoneNumber() != null
+ && !entityInstance.getOrganisationUnit().getPhoneNumber().isEmpty() )
+ {
+ phoneNumbers.add( entityInstance.getOrganisationUnit().getPhoneNumber() );
+ }
+ }
+ else if ( SEND_TO_USER_GROUP == sendTo )
+ {
+ for ( User user : reminder.getUserGroup().getMembers() )
+ {
+ if ( user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty() )
+ {
+ phoneNumbers.add( user.getPhoneNumber() );
+ }
+ }
+ }
+ else
+ {
+ if ( entityInstance.getTrackedEntityAttributeValues() != null )
+ {
+ for ( TrackedEntityAttributeValue attributeValue : entityInstance.getTrackedEntityAttributeValues() )
+ {
+ if ( ValueType.PHONE_NUMBER == attributeValue.getAttribute().getValueType() )
+ {
+ phoneNumbers.add( attributeValue.getValue() );
+ }
+ }
+ }
}
return phoneNumbers;
@@ -279,33 +275,34 @@
public Set<User> getUsers( TrackedEntityInstanceReminder reminder, TrackedEntityInstance entityInstance )
{
Set<User> users = new HashSet<>();
+
+ int sendTo = reminder.getSendTo();
- switch ( reminder.getSendTo() )
- {
- case TrackedEntityInstanceReminder.SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED:
- users.addAll( entityInstance.getOrganisationUnit().getUsers() );
- break;
- case TrackedEntityInstanceReminder.SEND_TO_ATTRIBUTE_TYPE_USERS:
- if ( entityInstance.getTrackedEntityAttributeValues() != null )
+ if ( SEND_TO_ALL_USERS_AT_REGISTERED_ORGUNIT == sendTo )
+ {
+ users.addAll( entityInstance.getOrganisationUnit().getUsers() );
+ }
+ else if ( SEND_TO_ATTRIBUTE_TYPE_USERS == sendTo )
+ {
+ if ( entityInstance.getTrackedEntityAttributeValues() != null )
+ {
+ for ( TrackedEntityAttributeValue attributeValue : entityInstance.getTrackedEntityAttributeValues() )
{
- for ( TrackedEntityAttributeValue attributeValue : entityInstance.getTrackedEntityAttributeValues() )
+ if ( ValueType.USERNAME == attributeValue.getAttribute().getValueType() )
{
- if ( ValueType.USERNAME == attributeValue.getAttribute().getValueType() )
- {
- users.add( userService.getUser( Integer.parseInt( attributeValue.getValue() ) ) );
- }
+ users.add( userService.getUser( Integer.parseInt( attributeValue.getValue() ) ) );
}
}
- break;
- case TrackedEntityInstanceReminder.SEND_TO_USER_GROUP:
- if ( reminder.getUserGroup().getMembers().size() > 0 )
- {
- users.addAll( reminder.getUserGroup().getMembers() );
- }
- break;
- default:
- break;
- }
+ }
+ }
+ else if ( SEND_TO_USER_GROUP == sendTo )
+ {
+ if ( reminder.getUserGroup().getMembers().size() > 0 )
+ {
+ users.addAll( reminder.getUserGroup().getMembers() );
+ }
+ }
+
return users;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminderServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminderServiceTest.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceReminderServiceTest.java 2016-03-09 16:58:54 +0000
@@ -156,7 +156,7 @@
ProgramStage stageB = new ProgramStage( "B", program );
reminderC = new TrackedEntityInstanceReminder( "C", 0, "Test event template",
TrackedEntityInstanceReminder.DUE_DATE_TO_COMPARE,
- TrackedEntityInstanceReminder.SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED,
+ TrackedEntityInstanceReminder.SEND_TO_ALL_USERS_AT_REGISTERED_ORGUNIT,
TrackedEntityInstanceReminder.SEND_WHEN_TO_C0MPLETED_EVENT,
TrackedEntityInstanceReminder.MESSAGE_TYPE_DIRECT_SMS );
reminders = new HashSet<>();