dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17153
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6738: Using velocity template for producing string for messages
------------------------------------------------------------
revno: 6738
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-04-25 14:24:59 +0200
message:
Using velocity template for producing string for messages
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/velocity/VelocityManager.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-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2012-02-14 19:19:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2012-04-25 12:24:59 +0000
@@ -31,6 +31,8 @@
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.configuration.ConfigurationService;
import org.hisp.dhis.dataset.CompleteDataSetRegistration;
+import org.hisp.dhis.system.util.Clock;
+import org.hisp.dhis.system.velocity.VelocityManager;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserGroup;
@@ -49,6 +51,9 @@
implements MessageService
{
private static final Log log = LogFactory.getLog( DefaultMessageService.class );
+
+ private static final String COMPLETE_SUBJECT = "Form registered as complete";
+ private static final String COMPLETE_TEMPLATE = "completeness_message";
// -------------------------------------------------------------------------
// Dependencies
@@ -157,12 +162,9 @@
{
User sender = currentUserService.getCurrentUser();
- //TODO i18n and string externalization
- String subject = "Form registered as complete";
- String text = "The form " + registration.getDataSet() + " was registered as complete for period " +
- registration.getPeriod().getName() + " and organisation unit " + registration.getSource();
+ String text = new VelocityManager().render( registration, COMPLETE_TEMPLATE );
- MessageConversation conversation = new MessageConversation( subject, sender );
+ MessageConversation conversation = new MessageConversation( COMPLETE_SUBJECT, sender );
conversation.addMessage( new Message( text, null, sender ) );
@@ -173,7 +175,7 @@
int id = saveMessageConversation( conversation );
- invokeMessageSenders( subject, text, sender, userGroup.getMembers() );
+ invokeMessageSenders( COMPLETE_SUBJECT, text, sender, userGroup.getMembers() );
return id;
}
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/velocity/VelocityManager.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/velocity/VelocityManager.java 2012-04-25 11:33:50 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/velocity/VelocityManager.java 2012-04-25 12:24:59 +0000
@@ -27,13 +27,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.StringWriter;
+
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
-import java.io.StringWriter;
-
public class VelocityManager
{
public static final String CONTEXT_KEY = "object";
@@ -42,7 +42,7 @@
private static final String VM_SUFFIX = ".vm";
private VelocityEngine velocity;
- public VelocityManager() throws Exception
+ public VelocityManager()
{
velocity = new VelocityEngine();
velocity.setProperty( Velocity.RESOURCE_LOADER, RESOURCE_LOADER_NAME );
@@ -61,7 +61,7 @@
{
return render( null, template );
}
-
+
public String render( Object object, String template )
{
try