dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #15572
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5669: basic documentation for dataValueSet
------------------------------------------------------------
revno: 5669
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-01-06 10:25:10 +0100
message:
basic documentation for dataValueSet
modified:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/velocity/VelocityManager.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.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-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 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/velocity/VelocityManager.java 2012-01-06 09:25:10 +0000
@@ -27,17 +27,17 @@
* 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";
-
+
private static final String RESOURCE_LOADER_NAME = "class";
private static final String VM_SUFFIX = ".vm";
private VelocityEngine velocity;
@@ -56,27 +56,31 @@
{
return velocity;
}
-
+
+ public String render( String template )
+ {
+ return render( null, template );
+ }
+
public String render( Object object, String template )
{
try
{
StringWriter writer = new StringWriter();
-
+
VelocityContext context = new VelocityContext();
-
+
if ( object != null )
{
context.put( CONTEXT_KEY, object );
}
-
+
velocity.getTemplate( template + VM_SUFFIX ).merge( context, writer );
-
+
return writer.toString();
-
+
// TODO include encoder in context
- }
- catch ( Exception ex )
+ } catch ( Exception ex )
{
throw new RuntimeException( "Failed to merge velocity template", ex );
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java 2012-01-05 21:51:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java 2012-01-06 09:25:10 +0000
@@ -27,25 +27,22 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.io.IOException;
-import java.util.Collection;
-
-import javax.servlet.http.HttpServletResponse;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.importexport.dxf2.model.DataValueSet;
import org.hisp.dhis.importexport.dxf2.service.DataValueSetService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.system.velocity.VelocityManager;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collection;
@Controller
@RequestMapping( value = DataValueSetController.RESOURCE_PATH )
@@ -61,6 +58,14 @@
@Autowired
private UserService userService;
+ @RequestMapping( method = RequestMethod.GET )
+ public void getDataValueSet( Writer writer ) throws Exception
+ {
+ VelocityManager velocityManager = new VelocityManager();
+ String str = velocityManager.render( "/templates/html/dataValueSet" );
+ writer.write( str );
+ }
+
@RequestMapping( method = RequestMethod.POST )
public void storeDataValueSet( @RequestBody DataValueSet dataValueSet, @RequestParam( required = false ) String phoneNumber )
{
@@ -96,11 +101,12 @@
* @param phoneNumber The phone number to look up
* @return the organisation unit uid
* @throws IllegalArgumentException if
- * <ul>
- * <li>No user has phone number
- * <li>More than one user has phone number
- * <li>User not associated with org unit
- * <li>User associated with multiple org units
+ * <ul>
+ * <li>No user has phone number
+ * <li>More than one user has phone number
+ * <li>User not associated with org unit
+ * <li>User associated with multiple org units
+ * </ul>
*/
private String findOrgUnit( String phoneNumber )
throws IllegalArgumentException
@@ -134,5 +140,4 @@
return organisationUnits.iterator().next().getUid();
}
-
}