← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5417: Web api: added Document html viwe and data / content response for uploaded documents and redirect...

 

------------------------------------------------------------
revno: 5417
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-12-14 16:28:36 +0100
message:
  Web api: added Document html viwe and data / content response for uploaded documents and redirects for external URLs
added:
  dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/document.xsl
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataElementController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/OrganisationUnitController.java
  dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl
  dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties


--
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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataElementController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataElementController.java	2011-12-13 16:47:13 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataElementController.java	2011-12-14 15:28:36 +0000
@@ -181,8 +181,6 @@
     @PreAuthorize( "hasRole('ALL') or hasRole('F_WEBAPI_DELETE')" )
     public void deleteDataElement( @PathVariable( "uid" ) String uid ) throws Exception
     {
-        // throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() );
-
         DataElement dataElement = dataElementService.getDataElement( uid );
 
         if ( dataElement != null )

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java	2011-12-12 13:03:59 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java	2011-12-14 15:28:36 +0000
@@ -27,11 +27,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.apache.commons.io.IOUtils;
 import org.hisp.dhis.api.utils.IdentifiableObjectParams;
 import org.hisp.dhis.api.utils.WebLinkPopulator;
 import org.hisp.dhis.document.Document;
 import org.hisp.dhis.document.DocumentService;
 import org.hisp.dhis.document.Documents;
+import org.hisp.dhis.external.location.LocationManager;
+import org.hisp.dhis.util.ContextUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Controller;
@@ -58,6 +61,9 @@
 
     @Autowired
     private DocumentService documentService;
+    
+    @Autowired
+    private LocationManager locationManager;
 
     //-------------------------------------------------------------------------------------------------------
     // GET
@@ -95,6 +101,27 @@
 
         return "document";
     }
+    
+    @RequestMapping( value = "/{uid}/data", method = RequestMethod.GET )
+    public void getDocumentContent( @PathVariable( "uid" ) String uid, HttpServletResponse response ) throws Exception
+    {
+        Document document = documentService.getDocument( uid );
+        
+        if ( document.isExternal() )
+        {
+            String redirectUrl = response.encodeRedirectURL( document.getUrl() );
+            
+            response.sendRedirect( redirectUrl );
+        }
+        else
+        {
+            InputStream in = locationManager.getInputStream( document.getUrl(), DocumentService.DIR );
+
+            IOUtils.copy( in, response.getOutputStream() );
+            
+            ContextUtils.configureResponse( response, document.getContentType(), true, document.getUrl(), true );
+        }
+    }
 
     //-------------------------------------------------------------------------------------------------------
     // POST

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/OrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/OrganisationUnitController.java	2011-12-12 15:06:51 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/OrganisationUnitController.java	2011-12-14 15:28:36 +0000
@@ -123,7 +123,8 @@
                     response.setStatus( HttpServletResponse.SC_CREATED );
                     response.setHeader( "Location", DataElementController.RESOURCE_PATH + "/" + organisationUnit.getUid() );
                 }
-            } catch ( Exception e )
+            } 
+            catch ( Exception e )
             {
                 response.setStatus( HttpServletResponse.SC_CONFLICT );
             }

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/document.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/document.xsl	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/document.xsl	2011-12-14 15:28:36 +0000
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"
+                xmlns="http://www.w3.org/1999/xhtml";
+                xmlns:d="http://dhis2.org/schema/dxf/2.0";
+    >
+
+  <xsl:template match="d:document">
+    <div class="document">
+      <h2> <xsl:value-of select="@name" /> </h2>
+      <table border="1">
+        <tr>
+          <td>ID</td>
+          <td> <xsl:value-of select="@id" /> </td>
+        </tr>
+        <tr>
+          <td>Last Updated</td>
+          <td> <xsl:value-of select="@lastUpdated" /> </td>
+        </tr>
+        <tr>
+          <td>URL</td>
+          <td> <xsl:value-of select="d:url" /> </td>
+        </tr>
+        <tr>
+          <td>External</td>
+          <td> <xsl:value-of select="d:external" /> </td>
+        </tr>
+        <tr>
+          <td>Content type</td>
+          <td> <xsl:value-of select="d:contentType" /> </td>
+        </tr>
+      </table>
+    </div>
+  </xsl:template>
+
+</xsl:stylesheet>

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl	2011-12-14 10:03:38 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl	2011-12-14 15:28:36 +0000
@@ -10,7 +10,7 @@
   <xsl:template match="d:maps|d:charts|d:categories|d:categoryCombos|
     d:categoryOptions|d:categoryOptionCombos|d:dataElements|d:indicators|
     d:organisationUnits|d:dataElementGroups|d:dataElementGroupSets|
-    d:indicatorGroups|d:indicatorGroupSets|d:organisationUnitGroups|
+    d:documents|d:indicatorGroups|d:indicatorGroupSets|d:organisationUnitGroups|
     d:organisationUnitGroupSets|d:indicatorTypes|d:attributeTypes|d:reports|
     d:sqlViews|d:validationRules|d:validationRuleGroups|d:users|d:reportTables">
     <h3> <xsl:value-of select="local-name()"/> </h3>

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl	2011-12-14 14:40:02 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl	2011-12-14 15:28:36 +0000
@@ -26,6 +26,7 @@
     <xsl:include href="dataElement.xsl"/>
     <xsl:include href="dataElementGroup.xsl"/>
     <xsl:include href="dataElementGroupSet.xsl"/>
+    <xsl:include href="document.xsl"/>
     <xsl:include href="indicator.xsl"/>
     <xsl:include href="indicatorType.xsl"/>
     <xsl:include href="indicatorGroup.xsl"/>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2011-12-14 11:15:54 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2011-12-14 15:28:36 +0000
@@ -266,7 +266,7 @@
 specify_dataelememt=Please specify a data element
 processing=Processing
 done=Done
-optioncombo=Option Combo
+optioncombo=Option combo
 view_as=View as
 dataelement_of_orther_program_stage=Data element of other program stage
 short_name=Short name
@@ -299,7 +299,7 @@
 upload_file_null=Upload file is missing
 file_type_not_supported=File type is not supported
 dataelement_group=Data Element Group
-option_combo=Option Combo
+option_combo=Option combo
 case_aggregation_condition=Beneficiary Aggregation Query Builder
 case_aggregation_condition_detail=Beneficiary aggregation query builder details
 create_new_case_aggregation_condition=Create new beneficiary aggregation query builder
@@ -312,9 +312,9 @@
 not_enough_mandatory_identifier=Not enough data for the mandatory identifier(s)
 not_enough_madatory_attribute=Not enough data for the mandatory attribute(s)
 get_data_error=Get data error
-hierachy_orgunit=Hierarchy Organisation Unit
+hierachy_orgunit=Hierarchy organisation unit
 similar_patients=Similar patients
-orgunit=Organisation Unit
+orgunit=Organisation unit
 validation_criteria_details=Validation criteria details
 program_attribute_details=Program attribute details
 patient_registration=Beneficiary Registration
@@ -343,7 +343,7 @@
 aggregation_data_element_in_use=Aggregation data element is in use
 add_more_option_to_search=Add more option to search
 delete_program_data_entry_confirm=Do you want to delete program data entry ?
-patient_chart_management=Bneneficiary chart management
+patient_chart_management=Beneficiary chart management
 create_new_patient_chart=Create new beneficiary Chart
 edit_patient_chart=Edit beneficiary chart
 chart_type=Chart type
@@ -351,7 +351,7 @@
 save=Save
 title=Title
 include_regression_line=Include regression line
-must_select_one_dataelement=Please select one dataelement
+must_select_one_dataelement=Please select one data element
 value_x_dataelements=Value (X) - Data elements
 bar_chart= Bar chart
 bar3d_chart= Bar 3D chart