← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12997: add new option to document, 'attachment', used to force a save dialog in browser

 

------------------------------------------------------------
revno: 12997
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-11-21 11:14:59 +0100
message:
  add new option to document, 'attachment', used to force a save dialog in browser
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/Document.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/document/hibernate/Document.hbm.xml
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/document/action/SaveDocumentAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addDocumentForm.vm


--
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/document/Document.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/Document.java	2013-08-29 10:30:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/document/Document.java	2013-11-21 10:14:59 +0000
@@ -51,6 +51,8 @@
 
     private String contentType;
 
+    private Boolean attachment = false;
+
     public Document()
     {
     }
@@ -108,6 +110,19 @@
         this.contentType = contentType;
     }
 
+    @JsonProperty
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public Boolean getAttachment()
+    {
+        return attachment;
+    }
+
+    public void setAttachment( Boolean attachment )
+    {
+        this.attachment = attachment;
+    }
+
     @Override
     public void mergeWith( IdentifiableObject other )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/document/hibernate/Document.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/document/hibernate/Document.hbm.xml	2013-08-23 20:59:09 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/document/hibernate/Document.hbm.xml	2013-11-21 10:14:59 +0000
@@ -23,6 +23,8 @@
 
     <property name="contentType" />
 
+    <property name="attachment" />
+
     <!-- Access properties -->
     <property name="externalAccess" />
 

=== 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	2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java	2013-11-21 10:14:59 +0000
@@ -28,14 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_JPG;
-import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_PDF;
-import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_PNG;
-
-import java.io.InputStream;
-
-import javax.servlet.http.HttpServletResponse;
-
 import org.apache.commons.io.IOUtils;
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
@@ -49,12 +41,15 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.InputStream;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  * @author Lars Helge Overland
  */
 @Controller
-@RequestMapping( value = DocumentController.RESOURCE_PATH )
+@RequestMapping(value = DocumentController.RESOURCE_PATH)
 public class DocumentController
     extends AbstractCrudController<Document>
 {
@@ -69,31 +64,28 @@
     @Autowired
     private ContextUtils contextUtils;
 
-    @RequestMapping( value = "/{uid}/data", method = RequestMethod.GET )
-    public void getDocumentContent( @PathVariable( "uid" ) String uid, HttpServletResponse response ) throws Exception
+    @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 == null )
         {
             ContextUtils.notFoundResponse( response, "Resource not found for identifier: " + uid );
             return;
         }
-        
+
         if ( document.isExternal() )
         {
             response.sendRedirect( response.encodeRedirectURL( document.getUrl() ) );
         }
         else
         {
-            String ct = document.getContentType();
-
-            boolean attachment = !(CONTENT_TYPE_PDF.equals( ct ) || CONTENT_TYPE_JPG.equals( ct ) || CONTENT_TYPE_PNG.equals( ct ));
-
-            contextUtils.configureResponse( response, document.getContentType(), CacheStrategy.CACHE_TWO_WEEKS, document.getUrl(), attachment );
+            contextUtils.configureResponse( response, document.getContentType(), CacheStrategy.CACHE_TWO_WEEKS, document.getUrl(),
+                document.getAttachment() );
 
             InputStream in = null;
-            
+
             try
             {
                 in = locationManager.getInputStream( document.getUrl(), DocumentService.DIR );
@@ -103,13 +95,13 @@
             catch ( LocationManagerException ex )
             {
                 ContextUtils.conflictResponse( response, "Document could not be found: " + document.getUrl() );
-                
+
                 return;
             }
             finally
             {
                 IOUtils.closeQuietly( in );
-            }            
+            }
         }
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/document/action/SaveDocumentAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/document/action/SaveDocumentAction.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/document/action/SaveDocumentAction.java	2013-11-21 10:14:59 +0000
@@ -104,6 +104,13 @@
         this.external = external;
     }
 
+    private Boolean attachment = false;
+
+    public void setAttachment( Boolean attachment )
+    {
+        this.attachment = attachment;
+    }
+
     private File file;
 
     public void setUpload( File file )
@@ -146,7 +153,7 @@
             File destination = locationManager.getFileForWriting( fileName, DocumentService.DIR );
 
             log.info( "Destination: '" + destination.getAbsolutePath() + "'" );
-            
+
             boolean fileMoved = file.renameTo( destination );
 
             if ( !fileMoved )
@@ -171,6 +178,8 @@
             document.setUrl( url );
         }
 
+        document.setAttachment( attachment );
+
         document.setExternal( external );
 
         document.setName( name );

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2013-03-17 14:52:32 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2013-11-21 10:14:59 +0000
@@ -125,6 +125,7 @@
 external_url=External URL
 upload_file=Upload file
 file=File
+attachment=Attachment
 url=URL
 display=Display
 visible=Visible

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addDocumentForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addDocumentForm.vm	2013-03-16 05:57:01 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addDocumentForm.vm	2013-11-21 10:14:59 +0000
@@ -47,6 +47,10 @@
 <div id="fileDiv">
 <table>
     <tr>
+      <td style="width:70px"><label for="attachment">$i18n.getString( "attachment" )</label></td>
+      <td><input type="checkbox" id="attachment" name="attachment" value="true" #if($!document.attachment) checked="checked" #end size="30" ></td>
+    </tr>
+    <tr>
         <td style="width:70px"><label for="upload">$i18n.getString( "file" )<em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
         <td><input type="file" id="upload" name="upload" size="30" ></td>
     </tr>