Added export encrypted reports

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/reports@71292 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Antonio Gioia 2013-03-13 10:47:15 +00:00
parent e18d28f8e0
commit 1b140d1420
7 changed files with 158 additions and 4 deletions

View File

@ -1,5 +1,4 @@
#Tue Mar 12 17:50:07 CET 2013
eclipse.preferences.version=1
lastWarOutDir=/Users/massi/Documents/workspace/reports/target/reports-4.0.4-SNAPSHOT
lastWarOutDir=/home/gioia/workspace/reports/target/reports-4.0.4-SNAPSHOT
warSrcDir=src/main/webapp
warSrcDirIsOutput=false

View File

@ -8,6 +8,9 @@
<dependent-module archiveName="gcube-docx-generator-1.2.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-docx-generator/gcube-docx-generator">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="report-exporter-widget-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/report-exporter-widget/report-exporter-widget">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="reports"/>
</wb-module>

View File

@ -19,6 +19,11 @@ import org.gcube.portlets.user.workspace.lighttree.client.load.WorkspaceLightTre
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.CellPanel;
@ -48,6 +53,7 @@ public class Headerbar extends Composite{
private static final String EXPORT_OPENXML = "Export to OpenXML (docx)";
private static final String EXPORT_HTML = "Export to HTML";
private static final String EXPORT_FIMES = "Export to FiMES XML";
private static final String EXPORT_ENCRYPTED_REPORT = "Export crypted Reports";
private static final String VIEW_USER_COMMENTS = "View user comments";
@ -83,6 +89,8 @@ public class Headerbar extends Composite{
private MenuItem optionPDF;
private MenuItem optionFimes;
private MenuItem optionEncryptedModel;
private MenuItem viewMetadata;
@ -341,10 +349,13 @@ public class Headerbar extends Composite{
optionPDF = new MenuItem("<font color=\"gray\">Export to PDF</font>", true, getDisabledExportMenuItemCmd());
optionHTML = new MenuItem("<font color=\"gray\">"+ EXPORT_HTML +"</font>", true, getDisabledExportMenuItemCmd());
optionFimes = new MenuItem("<font color=\"gray\">"+ EXPORT_FIMES +"</font>", true, getDisabledExportMenuItemCmd());
optionEncryptedModel = new MenuItem("<font color=\"gray\">"+ EXPORT_ENCRYPTED_REPORT +"</font>", true, getDisabledExportMenuItemCmd());
exportsMenu.addItem(optionDOCX);
exportsMenu.addItem(optionHTML);
exportsMenu.addItem(optionPDF);
exportsMenu.addItem(optionEncryptedModel);
//optionsMenu.addItem(optionPDF);
//exportsMenu.addItem(optionFimes);
@ -397,7 +408,10 @@ public class Headerbar extends Composite{
optionHTML.setCommand(generateHTML);
optionFimes.setHTML(EXPORT_FIMES);
optionFimes.setCommand(generateFimes);
optionFimes.setCommand(generateFimes);
optionEncryptedModel.setHTML(EXPORT_ENCRYPTED_REPORT);
optionEncryptedModel.setCommand(generateEncryptedModel);
//
importModel.setHTML("Import from Template or Report");
importModel.setCommand(importModelOrReport);
@ -616,7 +630,43 @@ public class Headerbar extends Composite{
presenter.generateManifestation(templateModel, ExportManifestationType.HTML);
}
};
Command generateEncryptedModel = new Command() {
@Override
public void execute() {
GWT.runAsync(WorkspaceLightTreeLoadPopup.class, new RunAsyncCallback() {
public void onSuccess() {
WorkspaceLightTreeLoadPopup wpTreepopup = new WorkspaceLightTreeLoadPopup("Open Template", true, true);
wpTreepopup.setShowableTypes(ItemType.REPORT_TEMPLATE);
wpTreepopup.setSelectableTypes(ItemType.REPORT_TEMPLATE);
wpTreepopup.addPopupHandler(new PopupHandler() {
public void onPopup(PopupEvent event) {
if (! event.isCanceled()) {
if (event.getSelectedItem() != null) {
final String itemId = event.getSelectedItem().getId();
final String url = GWT.getModuleBaseURL() + "downloadEncryptedReport?itemId=" + itemId;
Window.open(url, "_blank", "");
}
}
}
});
wpTreepopup.center();
wpTreepopup.show();
}
public void onFailure(Throwable reason) {
Window.alert("There are networks problem, please check your connection.");
}
});
}
};
Command discardSectionCom = new Command() {
public void execute() {

View File

@ -774,6 +774,8 @@ public class Presenter {
// });
// }
}
public void openAddCitationDialog() {
AddBiblioEntryDialog dlg = new AddBiblioEntryDialog(eventBus);

View File

@ -26,6 +26,7 @@ public enum ExportManifestationType {
/**
* FiMES FAO Schema
*/
FIMES;
FIMES;
}

View File

@ -0,0 +1,89 @@
package org.gcube.portlets.user.reportgenerator.server.servlet;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.user.homelibrary.home.HomeLibrary;
import org.gcube.portlets.user.homelibrary.home.workspace.Workspace;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.ReportTemplate;
import org.gcube.portlets.user.homelibrary.util.encryption.EncryptionUtil;
public class DownloadEncryptedReport extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ReportTemplate item = null;
File tmpFile = File.createTempFile("report", "texz");
String fileName = null;
try {
Workspace workspace = HomeLibrary.getUserWorkspace(getASLSession(request));
item = (ReportTemplate)workspace.getItem(request.getParameter("itemId"));
fileName = item.getName() + ".texz";
EncryptionUtil util = new EncryptionUtil();
FileOutputStream out = new FileOutputStream(tmpFile);
util.encrypt(item.getData(), out);
} catch (Exception e) {
throw new ServletException(e);
}
int length = 0;
ServletOutputStream outStream = response.getOutputStream();
String mimetype = "application/octet-stream";
response.setContentType(mimetype);
response.setContentLength((int)tmpFile.length());
// sets HTTP header
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
byte[] byteBuffer = new byte[1024];
DataInputStream in = new DataInputStream(new FileInputStream(tmpFile));
// reads the file's bytes and writes them to the response stream
while ((in != null) && ((length = in.read(byteBuffer)) != -1))
{
outStream.write(byteBuffer,0,length);
}
in.close();
outStream.close();
}
/**
* the current ASLSession
* @return .
*/
private ASLSession getASLSession(HttpServletRequest request) {
String sessionID = request.getSession().getId();
String user = (String) request.getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
if (user == null) {
user = "massimiliano.assante";
request.getSession().setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, user);
SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec");
}
return SessionManager.getInstance().getASLSession(sessionID, user);
}
}

View File

@ -118,6 +118,16 @@
<servlet-name>convertServlet</servlet-name>
<url-pattern>/reports/convert</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>DownloadEncryptedReport</servlet-name>
<servlet-class>org.gcube.portlets.user.reportgenerator.server.servlet.DownloadEncryptedReport</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DownloadEncryptedReport</servlet-name>
<url-pattern>/reports/downloadEncryptedReport</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DownloadService</servlet-name>