added upload image integrated with upload popup

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/reports@95187 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-04-28 16:26:53 +00:00
parent 5645ceafab
commit fd610b29bc
20 changed files with 440 additions and 976 deletions

View File

@ -1,7 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning

View File

@ -4,6 +4,9 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<dependent-module archiveName="fileupload-progress-bar-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/fileupload-progress-bar/fileupload-progress-bar">
<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

@ -170,9 +170,9 @@
<scope>${setScope}</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>workspace-tree-widget</artifactId>
<scope>${setScope}</scope>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>fileupload-progress-bar</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>

View File

@ -50,10 +50,10 @@ import org.gcube.portlets.user.reportgenerator.client.targets.GenericTable;
import org.gcube.portlets.user.reportgenerator.client.targets.GroupingDelimiterArea;
import org.gcube.portlets.user.reportgenerator.client.targets.HeadingTextArea;
import org.gcube.portlets.user.reportgenerator.client.targets.ReportTextArea;
import org.gcube.portlets.user.reportgenerator.client.targets.TSArea;
import org.gcube.portlets.user.reportgenerator.client.targets.TextTableImage;
import org.gcube.portlets.user.reportgenerator.client.toolbar.RichTextToolbar;
import org.gcube.portlets.user.reportgenerator.client.uibinder.ExportOptions;
import org.gcube.portlets.user.reportgenerator.shared.ReportImage;
import org.gcube.portlets.user.reportgenerator.shared.SessionInfo;
import org.gcube.portlets.user.reportgenerator.shared.UserBean;
import org.gcube.portlets.user.reportgenerator.shared.VMETypeIdentifier;
@ -65,6 +65,9 @@ import org.gcube.portlets.widgets.exporter.client.event.ExportingCompletedEventH
import org.gcube.portlets.widgets.exporter.client.event.ReportExporterEvent;
import org.gcube.portlets.widgets.exporter.client.event.ReportExporterEventHandler;
import org.gcube.portlets.widgets.exporter.shared.TypeExporter;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEvent;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEventHandler;
import org.gcube.portlets.widgets.fileupload.client.view.UploadProgressDialog;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.core.client.GWT;
@ -105,8 +108,15 @@ public class Presenter {
private final WaitingOperationDialog dlg = new WaitingOperationDialog();
private UploadProgressDialog uploadDlg;
private UserBean currentUser;
private String currentScope;
private ClientImage selectedImage;
/**
* Model
*/
@ -141,15 +151,42 @@ public class Presenter {
/**
* eventbus events handler
*/
HandlerManager eventBus = new HandlerManager(null);
static HandlerManager eventBus = new HandlerManager(null);
public HandlerManager getEventBus() {
public static HandlerManager getEventBus() {
return eventBus;
}
private void handleEvents() {
/**
* get the uploaded file result
*/
eventBus.addHandler(FileUploadCompleteEvent.TYPE, new FileUploadCompleteEventHandler() {
@Override
public void onUploadComplete(FileUploadCompleteEvent event) {
//the filename and its path on server are returned to the client
String fileName = event.getUploadedFileInfo().getFilename();
String absolutePathOnServer = event.getUploadedFileInfo().getAbsolutePath();
GWT.log(fileName + " uploaded on Server here: " + absolutePathOnServer);
reportService.getUploadedImageUrlById(fileName, absolutePathOnServer, new AsyncCallback<ReportImage>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("An error occurred in the server: " + caught.getMessage());
}
@Override
public void onSuccess(ReportImage result) {
uploadDlg.showRegisteringResult(true); //or false if an error occurred
selectedImage.dropImage(result.getUrl(), result.getId(), result.getWidth(), result.getHeight());
}
});
}
});
eventBus.addHandler(SelectedReportEvent.TYPE, new SelectedReportEventHandler() {
@Override
public void onReportSelected(SelectedReportEvent event) {
@ -954,9 +991,6 @@ public class Presenter {
setCurrCursorPos(uiY);
break;
case TIME_SERIES:
TSArea dp5 = (TSArea) component.getContent();
wp.addComponentToLayout(dp5, component.isDoubleColLayout());
setCurrCursorPos(uiY);
break;
case FLEX_TABLE:
GenericTable gt = (GenericTable) component.getContent();
@ -1118,8 +1152,11 @@ public class Presenter {
/**
* show the upload file popup
*/
public void showUploadFilePopup() {
toolBoxPanel.showUploadFile();
public void showUploadFilePopup(ClientImage selectedImage) {
uploadDlg = new UploadProgressDialog("Upload Image", eventBus);
uploadDlg.center();
uploadDlg.show();
this.selectedImage = selectedImage;
}
/**
*

View File

@ -1,8 +1,6 @@
package org.gcube.portlets.user.reportgenerator.client;
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceServiceAsync;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.logical.shared.ResizeEvent;
@ -82,8 +80,6 @@ public class ReportGenerator implements EntryPoint {
private ScrollPanel bottomScrollerPanel = new ScrollPanel();
private AppControllerExplorer treeController;
private HTML divHidden = new HTML();
/**
* This is the entry point method.
@ -91,14 +87,13 @@ public class ReportGenerator implements EntryPoint {
public void onModuleLoad() {
singleton = this;
presenter = new Presenter();
treeController = new AppControllerExplorer();
mainLayout.setWidth("100%");
mainLayout.setHeight("100%");
//
workSpacePanel = new WorkspacePanel(presenter);
titlebar = new TitleBar(presenter);
header = new Headerbar(presenter);
toolBoxPanel = new ToolboxPanel(treeController);
toolBoxPanel = new ToolboxPanel();
presenter.setHeader(header);
presenter.setTitleBar(titlebar);
@ -197,12 +192,6 @@ public class ReportGenerator implements EntryPoint {
public ToolboxPanel getToolBoxPanel() {
return toolBoxPanel;
}
public GWTWorkspaceServiceAsync getWSTreeService() {
return treeController.getRpcWorkspaceService();
}
/**
*
* @return .

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import org.gcube.portlets.d4sreporting.common.shared.Model;
import org.gcube.portlets.d4sreporting.common.shared.RepTimeSeries;
import org.gcube.portlets.d4sreporting.common.shared.Table;
import org.gcube.portlets.user.reportgenerator.shared.ReportImage;
import org.gcube.portlets.user.reportgenerator.shared.SessionInfo;
import org.gcube.portlets.user.reportgenerator.shared.VMEReportBean;
import org.gcube.portlets.user.reportgenerator.shared.VMETypeIdentifier;
@ -22,6 +23,8 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("ReportServiceImpl")
public interface ReportService extends RemoteService{
ReportImage getUploadedImageUrlById(String fileName, String absolutePath);
ArrayList<VMEReportBean> listVMEReports();
ArrayList<VMEReportBean> listVMEReportRefByType(VMETypeIdentifier refType);
@ -35,6 +38,8 @@ public interface ReportService extends RemoteService{
String save(String filePath, String workspaceFolderId, String ItemName,
TypeExporter type, boolean overwrite)
throws SaveReportFileException, SaveReportFileExistException;
ReportImage getImageUrlById(String identifier);
/**
* return the first ten records of the timeseries having id as param
* @param sTS .

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import org.gcube.portlets.d4sreporting.common.shared.Model;
import org.gcube.portlets.d4sreporting.common.shared.RepTimeSeries;
import org.gcube.portlets.d4sreporting.common.shared.Table;
import org.gcube.portlets.user.reportgenerator.shared.ReportImage;
import org.gcube.portlets.user.reportgenerator.shared.SessionInfo;
import org.gcube.portlets.user.reportgenerator.shared.VMEReportBean;
import org.gcube.portlets.user.reportgenerator.shared.VMETypeIdentifier;
@ -91,4 +92,7 @@ public interface ReportServiceAsync {
AsyncCallback<VmeExportResponse> callback);
void deleteReportFromRSG(VMETypeIdentifier refType, String idToDelete,
AsyncCallback<VmeExportResponse> callback);
void getImageUrlById(String identifier, AsyncCallback<ReportImage> callback);
void getUploadedImageUrlById(String fileName, String absolutePath,
AsyncCallback<ReportImage> callback);
}

View File

@ -1,14 +1,9 @@
package org.gcube.portlets.user.reportgenerator.client;
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent;
import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent.DownloadType;
import org.gcube.portlets.user.workspace.client.event.FileUploadEvent;
import org.gcube.portlets.user.workspace.client.event.FileUploadEvent.UploadType;
import org.gcube.portlets.user.workspace.client.view.tree.AsyncTreePanel;
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
import org.gcube.portlets.widgets.fileupload.client.view.UploadProgressDialog;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
@ -17,8 +12,6 @@ import com.google.gwt.user.client.ui.VerticalPanel;
*/
public class ToolboxPanel extends VerticalPanel {
private AppControllerExplorer appController;
private AsyncTreePanel tp;
/**
*
*/
@ -28,12 +21,7 @@ public class ToolboxPanel extends VerticalPanel {
*/
public static final int TOOLBOX_HEIGHT= 800;
public ToolboxPanel(AppControllerExplorer appController) {
this.appController = appController;
// AsyncTreePanel tp = appController.getTree(TOOLBOX_WIDTH, TOOLBOX_HEIGHT);
// this.tp = tp;
// add(tp);
// this.appController.hideSharingFacilities(); //sharing disabled we have problems from Reports
public ToolboxPanel() {
}
public void showStructure(ReportStructurePanel panel) {
@ -50,7 +38,7 @@ public class ToolboxPanel extends VerticalPanel {
public void showExportedVersion(String id, String fileName) {
GWT.log("showExportedVersion");
AppControllerExplorer.getEventBus().fireEvent(new FileDownloadEvent(id, fileName, DownloadType.SHOW));
//AppControllerExplorer.getEventBus().fireEvent(new FileDownloadEvent(id, fileName, DownloadType.SHOW));
}
/**
* refresh the root
@ -58,12 +46,6 @@ public class ToolboxPanel extends VerticalPanel {
public void refreshRoot() {
//appController.refreshRoot();
}
/**
* show upload file popup
*/
public void showUploadFile() {
AppControllerExplorer.getEventBus().fireEvent(new FileUploadEvent(tp.getRootItem(), UploadType.FILE));
}
/**
* lalala
* @return the toolbox height

View File

@ -1,112 +0,0 @@
package org.gcube.portlets.user.reportgenerator.client.dialog;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
*
* @author massi
*
*/
public class TSHeader extends HorizontalPanel {
private CheckBox myCB;
private HTML myHeader;
private int myColNo;
private FlexTable myTable;
TimeSeriesFilterDialog caller;
TSHeader myinstance;
/**
* @param tsf -
* @param myTable .
* @param cb .
* @param myColNo .
* @param myHeader .
*/
public TSHeader(TimeSeriesFilterDialog tsf, FlexTable myTable, CheckBox cb, int myColNo, HTML myHeader) {
super();
myinstance = this;
caller = tsf;
this.myTable = myTable;
this.myCB = cb;
this.myColNo = myColNo;
this.myHeader = myHeader;
setVerticalAlignment(ALIGN_MIDDLE);
myHeader.setStyleName("timeSeries_header_font");
add(myHeader);
add(myCB);
myCB.addClickListener(cbListener);
}
private void removeEmptyHeaders( FlexTable myTable) {
for (int i = 0; i < myTable.getCellCount(0); i++) {
if (myTable.getWidget(0, i) == null) {
myTable.removeCell(0, i);
myTable.removeCell(1, i);
}
}
}
ClickListener cbListener = new ClickListener() {
public void onClick(Widget sender) {
caller.removeHeader(myinstance);
myTable.remove(sender.getParent());
removeEmptyHeaders(myTable);
}
};
/**
*
* @return .
*/
public CheckBox getMyCB() {
return myCB;
}
/**
*
* @param myCB .
*/
public void setMyCB(CheckBox myCB) {
this.myCB = myCB;
}
/**
*
* @return .
* */
public HTML getMyHeader() {
return myHeader;
}
/**
*
* @param myHeader .
*/
public void setMyHeader(HTML myHeader) {
this.myHeader = myHeader;
}
/**
*
* @return .
*/
public int getMyColNo() {
return myColNo;
}
/**
*
* @param myColNo .
*/
public void setMyColNo(int myColNo) {
this.myColNo = myColNo;
}
}

View File

@ -1,212 +0,0 @@
package org.gcube.portlets.user.reportgenerator.client.dialog;
import java.util.LinkedList;
import java.util.List;
import org.gcube.portlets.d4sreporting.common.client.CommonConstants;
import org.gcube.portlets.d4sreporting.common.shared.TimeSeriesFilter;
import org.gcube.portlets.d4sreporting.common.shared.TimeSeriesinfo;
import org.gcube.portlets.d4sreporting.common.shared.RepTimeSeries;
import org.gcube.portlets.user.reportgenerator.client.targets.TSArea;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
*
* @author massi
*
*/
public class TimeSeriesFilterDialog extends DialogBox {
ScrollPanel scroller = new ScrollPanel();
TextBox from = new TextBox();
TextBox to = new TextBox();
FlexTable flexTable = new FlexTable();
List<TSHeader> compoundHeaders = new LinkedList<TSHeader>();
/**
*
* @param sts a ts
* @param caller .
*/
public TimeSeriesFilterDialog(final TSArea caller, final RepTimeSeries sts) {
final TimeSeriesinfo droppedTS = sts.getTsMetadata();
setText(droppedTS.getTitle() + " Filter");
String name = droppedTS.getTitle();
long rowsNo = droppedTS.getDimension();
Grid metadata = new Grid(2, 2);
metadata.setWidget(0, 0, new HTML("Name:", true));
metadata.setWidget(0, 1, new HTML(name));
metadata.setWidget(1, 0, new HTML("Total rows : ", true));
metadata.setWidget(1, 1, new HTML(""+rowsNo));
final VerticalPanel main_panel = new VerticalPanel();
main_panel.addStyleName("bgBlank p8 font_family font_12");
main_panel.add(metadata);
List<String> headersString = droppedTS.getHeaderLabels();
/**
*/
for (int i = 0; i < headersString.size(); i++) {
CheckBox toAdd = new CheckBox();
toAdd.setChecked(true);
compoundHeaders.add(new TSHeader(this, flexTable, toAdd, i, new HTML(headersString.get(i) )));
}
main_panel.add(new HTML("Selected fields: (click to remove)"));
flexTable = getTableHeader(compoundHeaders);
main_panel.add(flexTable);
main_panel.add(new HTML("Select rows interval:"));
from.setText("1");
to.setText("10");
to.setMaxLength(6);
from.setMaxLength(6);
from.addChangeListener(textBoxListener);
to.addChangeListener(textBoxListener);
Grid rowsInterval = new Grid(1, 4);
rowsInterval.setWidget(0, 0, new HTML("From row:"));
rowsInterval.setWidget(0, 1, from);
rowsInterval.setWidget(0, 2, new HTML("&nbsp;&nbsp;To row:"));
rowsInterval.setWidget(0, 3, to);
main_panel.add(rowsInterval);
main_panel.add(new HTML("<hr align=\"left\" size=\"1\" width=\"100%\" color=\"gray\" noshade>"));
HorizontalPanel buttonspanel = new HorizontalPanel();
buttonspanel.setHeight("50");
buttonspanel.setSpacing(3);
// PopupPanel is a SimplePanel, so you have to set it's widget property to
// whatever you want its contents to be.
Button close = new Button("Close");
close.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
hide();
}
});
Button apply = new Button("Apply");
apply.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
List<TSHeader> selectedCols = compoundHeaders;
List<Integer> colsToShow = new LinkedList<Integer>();
for (TSHeader head : selectedCols) {
colsToShow.add(new Integer(head.getMyColNo()));
}
int fromInt = Integer.parseInt(from.getText());
int toInt = Integer.parseInt(to.getText());
TimeSeriesFilter toSet = new TimeSeriesFilter(colsToShow, null, null, fromInt, toInt);
caller.setNewFilter(toSet);
caller.refreshHeaders();
hide();
}
});
buttonspanel.add(close);
buttonspanel.add(apply);
main_panel.add(buttonspanel);
scroller.setPixelSize(550, 280);
main_panel.setPixelSize(550, 260);
scroller.add(main_panel);
setWidget(scroller);
}
/**
*
* @param toRemove .
* @return .
*/
public boolean removeHeader(TSHeader toRemove) {
return compoundHeaders.remove(toRemove);
}
/**
* display the header of the ts
* @param droppedTS
* @return
*/
private FlexTable getTableHeader(List<TSHeader> headers) {
flexTable.clear();
int n = headers.size();
for (int i = 0; i < n ; i++) {
flexTable.getCellFormatter().setStyleName(0, i, "timeSeries_header");
flexTable.setWidget(0, i, headers.get(i));
flexTable.getCellFormatter().setStyleName(1, i, "timeSeries_td");
flexTable.setWidget(1, i, new HTML("..."));
}
return flexTable;
}
ChangeListener textBoxListener = new ChangeListener() {
public void onChange(Widget sender) {
TextBox tb = (TextBox) sender;
String text = tb.getText();
String checkedText = text;
text = text.replaceAll(CommonConstants.ACCEPTED_CHARS_JUST_NUM, "");
if (! text.equals(checkedText) ) {
Window.alert("Only numbers are accepted");
tb.setText(text);
}
int start = Integer.parseInt(from.getText());
int end = Integer.parseInt(to.getText());
if (start >= end) {
Window.alert("From must be greater than to");
to.setText(""+(start+10));
}
}
};
/**
*
*/
public void show() {
super.show();
center();
}
}

View File

@ -23,14 +23,12 @@ import org.gcube.portlets.user.reportgenerator.client.targets.ClientRepeatableSe
import org.gcube.portlets.user.reportgenerator.client.targets.ClientReportReference;
import org.gcube.portlets.user.reportgenerator.client.targets.ClientSequence;
import org.gcube.portlets.user.reportgenerator.client.targets.D4sRichTextarea;
import org.gcube.portlets.user.reportgenerator.client.targets.DropTSListener;
import org.gcube.portlets.user.reportgenerator.client.targets.ExtHidden;
import org.gcube.portlets.user.reportgenerator.client.targets.GenericTable;
import org.gcube.portlets.user.reportgenerator.client.targets.GroupingDelimiterArea;
import org.gcube.portlets.user.reportgenerator.client.targets.GroupingInnerArea;
import org.gcube.portlets.user.reportgenerator.client.targets.HeadingTextArea;
import org.gcube.portlets.user.reportgenerator.client.targets.ReportTextArea;
import org.gcube.portlets.user.reportgenerator.client.targets.TSArea;
import org.gcube.portlets.user.reportgenerator.client.targets.TextTableImage;
import com.google.gwt.core.client.GWT;
@ -338,24 +336,6 @@ public class TemplateComponent {
this.content = hiddenField;
break;
case TIME_SERIES:
TSArea tsa;
RepTimeSeries sts = null;
try {
sts = ((RepTimeSeries) sc.getPossibleContent());
} catch (ClassCastException e) {
}
//need to reset the filter when loading a TS
sts.setFilter(null);
tsa = new TSArea(presenter, width, 155, sts);
tsa.setPixelSize(width, 155);
@SuppressWarnings("unused")
DropTSListener dropTSListener = new DropTSListener(tsa);
this.content = tsa;
break;
case REPEAT_SEQUENCE_DELIMITER:
GroupingDelimiterArea gp = new GroupingDelimiterArea(width, height);
@ -490,9 +470,7 @@ public class TemplateComponent {
}
break;
case TIME_SERIES:
GWT.log("Found Time Series", null);
TSArea tsa = (TSArea) this.content;
content = tsa.getSts();
GWT.log("Found Time Series, not supported anymore", null);
break;
case FLEX_TABLE:
GenericTable gt = (GenericTable) this.content;

View File

@ -5,13 +5,12 @@ import java.util.List;
import org.gcube.portlets.d4sreporting.common.shared.BasicComponent;
import org.gcube.portlets.d4sreporting.common.shared.Metadata;
import org.gcube.portlets.user.reportgenerator.client.ReportGenerator;
import org.gcube.portlets.user.reportgenerator.client.ReportService;
import org.gcube.portlets.user.reportgenerator.client.ReportServiceAsync;
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
import org.gcube.portlets.user.reportgenerator.client.model.TemplateComponent;
import org.gcube.portlets.user.reportgenerator.client.model.TemplateModel;
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem;
import org.gcube.portlets.user.workspace.client.workspace.folder.item.GWTExternalImage;
import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTImageDocument;
import org.gcube.portlets.user.reportgenerator.shared.ReportImage;
import org.gcube.portlets.widgets.lighttree.client.ItemType;
import org.gcube.portlets.widgets.lighttree.client.event.PopupEvent;
import org.gcube.portlets.widgets.lighttree.client.event.PopupHandler;
@ -43,7 +42,7 @@ import com.google.gwt.user.client.ui.Widget;
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
*/
public class ClientImage extends Composite {
private ReportServiceAsync reportService = (ReportServiceAsync) GWT.create(ReportService.class);
private String expectedContent = "";
private final String METADATA_TITLE_KEY = "title";
@ -72,10 +71,11 @@ public class ClientImage extends Composite {
private TextBox sourceTB = new TextBox();
private Button resetB = new Button("Clear");
private Button addImageB = new Button("Select Image");
private Button addImageB = new Button("Select from Workspace");
private Button uploadImageB = new Button("Upload Image");
private Button removeB = new Button("Remove Image");
private BasicComponent basicComponent;
/**
*
* @param presenter
@ -174,7 +174,7 @@ public class ClientImage extends Composite {
uploadImageB.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
presenter.showUploadFilePopup();
showUploadPopup();
}
});
@ -188,6 +188,10 @@ public class ClientImage extends Composite {
return toReturn;
}
private void showUploadPopup() {
presenter.showUploadFilePopup(this);
}
private VerticalPanel getAttributesPanel(BasicComponent co) {
VerticalPanel toReturn = new VerticalPanel();
@ -214,7 +218,7 @@ public class ClientImage extends Composite {
hp1.add(desc);
hp1.add(descTB);
descTB.setWidth("435px");
descTB.setWidth("400px");
toReturn.add(hp1);
toReturn.add(source);
@ -286,23 +290,22 @@ public class ClientImage extends Composite {
}
public void fetchImage(String identifier, final boolean isInteralImage, boolean fullDetails) {
ReportGenerator.get().getWSTreeService().getImageById(identifier, isInteralImage, fullDetails, new AsyncCallback<GWTWorkspaceItem>() {
GWT.log("fetchImage:" + identifier);
reportService.getImageUrlById(identifier, new AsyncCallback<ReportImage>() {
public void onSuccess(GWTWorkspaceItem result) {
if (isInteralImage) {
GWTImageDocument image = (GWTImageDocument) result;
@Override
public void onSuccess(ReportImage image) {
int width = image.getWidth();
int height = image.getHeight();
dropImage(image.getImageUrl(), image.getId(), width, height);
} else {
GWTExternalImage image = (GWTExternalImage) result;
int width = image.getWidth();
int height = image.getHeight();
dropImage(image.getImageUrl(), image.getId(), width, height);
}
GWT.log("image.getUrl():" + image.getUrl());
dropImage(image.getUrl(), image.getId(), width, height);
}
@Override
public void onFailure(Throwable caught) {
Window.alert("Could not fetch image from infrastructure " + caught.getCause());
}
});
}
@ -316,36 +319,6 @@ public class ClientImage extends Composite {
return new Image();
return currImage;
}
//
// /**
// * return a URL which is lookable for on the web
// * @param imageName .
// * @param templateName .
// * @return .
// */
// public String getImageURL(String imageName, String templateName) {
// currentUser = presenter.getCurrentUser().getUsername();
// currentScope = presenter.getCurrentScope();
// /**
// * Images will be stored under webapps/usersArea...
// * GWT.getModuleBaseURL() returns * e.g. http://dlib28.isti.cnr.it/templatecreator/html/
// * need to get just http://dlib28.isti.cnr.it/
// */
// //remove "/html/" and get e.g. http://dlib28.isti.cnr.it/templatecreator
// String host = GWT.getModuleBaseURL().substring(0, GWT.getModuleBaseURL().length()-6);
//
// //loog for last slash
// int lastSlash = host.lastIndexOf("/");
//
// //get what i need : e.g. http://dlib28.isti.cnr.it/ or host = "http://localhost:8080/";
// host = host.substring(0, lastSlash +1 );
// //host = "http://localhost:8080/";
//
// String imgURL = host + "usersArea/" + currentScope + "/templates/"
// + currentUser + "/CURRENT_OPEN/images/" + imageName;
//
// return imgURL;
// }
/**
*

View File

@ -1,115 +0,0 @@
/**
*
*/
package org.gcube.portlets.user.reportgenerator.client.targets;
import java.util.List;
import org.gcube.portlets.user.workspace.client.interfaces.GXTFolderItemTypeEnum;
import org.gcube.portlets.user.workspace.client.model.FileModel;
import com.extjs.gxt.ui.client.dnd.DND.Operation;
import com.extjs.gxt.ui.client.dnd.DropTarget;
import com.extjs.gxt.ui.client.dnd.Insert;
import com.extjs.gxt.ui.client.event.DNDEvent;
import com.extjs.gxt.ui.client.store.TreeStoreModel;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.google.gwt.core.client.GWT;
/**
* @author Federico De Faveri defaveri@isti.cnr.it
*
*/
public class DropTSListener extends DropTarget {
/**
*
*/
public static final String NO_DROP = "x-dd-drop-nodrop";
/**
*
*/
public static final String OK_DROP = "x-dd-drop-ok";
/**
*
*/
public static final String OK_DROP_ADD = "x-dd-drop-ok-add";
protected TSArea panel;
/**
*
* @param panel .
* @param config .
*/
public DropTSListener(TSArea panel) {
super(panel);
this.panel = panel;
//IMPORTANT
setOperation(Operation.COPY);
}
@Override
protected void showFeedback(DNDEvent event) {
if (!isValidDropTarget(event)) {
Insert.get().hide();
event.getStatus().setStatus(false);
return;
}
super.showFeedback(event);
}
@SuppressWarnings("unchecked")
private boolean isValidDropTarget(DNDEvent event) {
GWT.log("isValidDropTarget");
TreePanel<FileModel> source = (TreePanel<FileModel>) event.getDragSource().getComponent();
List<FileModel> selection = source.getSelectionModel().getSelection();
for (FileModel model : selection) {
GWT.log("selection: " + model.getGXTFolderItemType());
if(model.getGXTFolderItemType()!=null){
if (model.getGXTFolderItemType().equals(GXTFolderItemTypeEnum.TIME_SERIES))
return true;
}
}
return false;
}
/**
* @param source .
* @param e .
* @param data .
* @return .
*/
protected void onDragDrop(DNDEvent event) {
super.onDragDrop(event);
if(event.getData() != null){
List<TreeStoreModel> listItemsSource = event.getData();
GWT.log("Number of move " + listItemsSource.size());
FileModel sourceFileModel = null; //for print
for(TreeStoreModel itemSource : listItemsSource){
sourceFileModel = (FileModel) itemSource.getModel();
if(sourceFileModel.getParentFileModel()!=null)
GWT.log("Source Name " + sourceFileModel.getName() + " id " + sourceFileModel.getIdentifier() + " end drag " + " Parent Name: " + sourceFileModel.getParentFileModel().getName() + "id " + sourceFileModel.getParentFileModel().getIdentifier());
else
GWT.log("Source Name " + sourceFileModel.getName() + " id " + sourceFileModel.getIdentifier() + " end drag ");
GWT.log("Child count: " + itemSource.getChildCount());
panel.fetchTS(sourceFileModel.getIdentifier(), false , true);
}
}
}
}

View File

@ -1,312 +0,0 @@
package org.gcube.portlets.user.reportgenerator.client.targets;
import java.util.LinkedList;
import java.util.List;
import org.gcube.portlets.d4sreporting.common.shared.TimeSeriesFilter;
import org.gcube.portlets.d4sreporting.common.shared.TimeSeriesinfo;
import org.gcube.portlets.d4sreporting.common.shared.Table;
import org.gcube.portlets.d4sreporting.common.shared.RepTimeSeries;
import org.gcube.portlets.user.reportgenerator.client.ReportGenerator;
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
import org.gcube.portlets.user.reportgenerator.client.dialog.TimeSeriesDialog;
import org.gcube.portlets.user.reportgenerator.client.dialog.TimeSeriesFilterDialog;
import org.gcube.portlets.user.reportgenerator.client.dialog.TimeSeriesSampleDialog;
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem;
import org.gcube.portlets.user.workspace.client.workspace.folder.item.GWTTimeSeries;
import com.extjs.gxt.ui.client.widget.Composite;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
/**
* <code> TSArea </code> class is a Widget you can drop a Workspace Time Series on
*
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
* @version July 2011 (3.0)
*/
public class TSArea extends Composite {
private VerticalPanel mainPanel;
private RepTimeSeries sts = new RepTimeSeries();
private String idInBasket;
private Presenter presenter;
private FlexTable flexTable;
private TSArea singleton;
VerticalPanel tableContainer = new VerticalPanel();
Grid metadata = new Grid(3, 2);
Label label;
/**
* @param presenter .
* @param width .
* @param height .
* @param sts the time series
*/
public TSArea(Presenter presenter, int width, int height, RepTimeSeries sts) {
singleton = this;
this.presenter = presenter;
mainPanel = new VerticalPanel();
//setElement(mainPanel.getElement());
mainPanel.setStyleName("timeseriesArea");
mainPanel.addStyleName("timeseriesArea_bg");
mainPanel.setWidth(width);
mainPanel.setHeight(height);
mainPanel.add(new HTML("&nbsp;", true));
this.sts = sts;
if (sts != null) {
if (sts.getTsMetadata() != null) {
showTS(sts.getTsMetadata());
}
}
initComponent(mainPanel);
mainPanel.layout(true);
}
/**
* called when dropped a TS on the area
* @param toShow the TS to show
*/
public void showTS(TimeSeriesinfo toShow) {
mainPanel.removeAll();
mainPanel.removeStyleName("timeseriesArea_bg");
tableContainer.removeAll();
metadata.setWidget(0, 0, new HTML("<b>TS name:</b>", true));
metadata.setWidget(0, 1, new HTML(toShow.getTitle()));
metadata.setWidget(1, 0, new HTML("<b>Creation Date:</b> ", true));
metadata.setWidget(1, 1, new HTML(toShow.getTimeSeriesCreationDate()));
metadata.setWidget(2, 0, new HTML("<b>Total rows:</b>", true));
metadata.setWidget(2, 1, new HTML(""+toShow.getDimension()));
List<String> headers = toShow.getHeaderLabels();
flexTable = new FlexTable();
int n = (headers.size() > 10) ? 10 : headers.size();
for (int i = 0; i < n ; i++) {
flexTable.getCellFormatter().setStyleName(0, i, "timeSeries_header");
flexTable.setWidget(0, i, new HTML(headers.get(i)));
flexTable.setWidget(1, i, new HTML(".."));
flexTable.getCellFormatter().setStyleName(1, i, "timeSeries_td");
}
if (headers.size() > 10) {
flexTable.setWidget(0, 11, new HTML(" more .."));
flexTable.setWidget(1, 11, new HTML(".."));
flexTable.getCellFormatter().setStyleName(0, 11, "timeSeries_header");
flexTable.getCellFormatter().setStyleName(1, 11, "timeSeries_td");
}
tableContainer.add(flexTable);
mainPanel.add(metadata);
mainPanel.add(tableContainer);
Button moreDetails = new Button("View Timeseries Metadata");
Button filter = new Button("Filter Table");
Button showSample = new Button("Show Sample");
HorizontalPanel buttonsPanel = new HorizontalPanel();
buttonsPanel.setSpacing(5);
buttonsPanel.add(moreDetails);
buttonsPanel.add(filter);
buttonsPanel.add(showSample);
mainPanel.add(buttonsPanel);
moreDetails.addClickHandler(viewMetadataTS);
showSample.addClickHandler(showTSSample);
filter.addClickHandler(applyFilterTs);
mainPanel.layout(true);
}
ClickHandler viewMetadataTS = new ClickHandler() {
public void onClick(ClickEvent event) {
TimeSeriesDialog dlg = new TimeSeriesDialog(sts.getTsMetadata());
dlg.setAnimationEnabled(true);
dlg.show();
}
};
ClickHandler applyFilterTs = new ClickHandler() {
public void onClick(ClickEvent event) {
TimeSeriesFilterDialog dlg = new TimeSeriesFilterDialog(singleton, sts);
//dlg.setPopupPosition(sender.getAbsoluteLeft(), sender.getAbsoluteTop());
dlg.setAnimationEnabled(true);
dlg.show();
}
};
ClickHandler showTSSample = new ClickHandler() {
public void onClick(ClickEvent event) {
presenter.getModel().getModelService().getSampleTimeSeries(sts, new AsyncCallback<Table>() {
public void onFailure(Throwable caught) { Window.alert("There were Problem contacting Server, please try later");}
public void onSuccess(Table result) {
Table toPass = result;
TimeSeriesSampleDialog dlg = new TimeSeriesSampleDialog(toPass);
dlg.setAnimationEnabled(true);
dlg.show();
}
});
}
};
/**
*
* @param droppedTS the dropped timeseries
*/
public void dropTS(GWTTimeSeries droppedTS) {
idInBasket = droppedTS.getId();
TimeSeriesinfo tsMetadata = convertWSTS2SerialazableTS(droppedTS);
sts = new RepTimeSeries(null, tsMetadata);
GWT.log("showTS TS");
showTS(tsMetadata);
}
public void fetchTS(String identifier, boolean isInteralImage, boolean fullDetails) {
GWT.log("FETCH TS");
this.mask("fetching TimeSeries, pleas wait", "loading-indicator");
ReportGenerator.get().getWSTreeService().getTimeSeriesById(identifier, new AsyncCallback<GWTWorkspaceItem>() {
public void onSuccess(GWTWorkspaceItem result) {
unmask();
GWTTimeSeries ts = (GWTTimeSeries) result;
dropTS(ts);
}
public void onFailure(Throwable caught) {
unmask();
Window.alert("Could not fetch Time Series from infrastructure " + caught.getCause());
}
});
}
/**
* converts the WorkSpace TS Object into a Report TS Object
* @param md the TS metadata to convert
* @return
*/
private TimeSeriesinfo convertWSTS2SerialazableTS(GWTTimeSeries md) {
TimeSeriesinfo tsMetadata = new TimeSeriesinfo(md.getId(), md.getName(), md.getDescription(), md.getOwner(),
md.getCreationTime(), md.getLastModificationTime(), md.getTimeSeriesId(), md.getTitle(), md.getCreator(),
md.getTimeSeriesDescription(), md.getTimeSeriesCreationDate(),
md.getPublisher(), md.getSourceId(), md.getSourceName(), md.getRights(), md.getDimension(), md.getHeaderLabels());
return tsMetadata;
}
/**
* refresh the headers once the TS has been filtered
*/
public void refreshHeaders() {
tableContainer.removeAll();
flexTable = new FlexTable();
List<String> filteredHeaders = new LinkedList<String>();
TimeSeriesFilter tf = sts.getFilter();
for (Integer colNo : tf.getColsNumberToShow()) {
String toAdd = sts.getTsMetadata().getHeaderLabels().get(colNo);
filteredHeaders.add(toAdd);
}
int n = (filteredHeaders.size() > 10) ? 10 : filteredHeaders.size();
for (int i = 0; i < n ; i++) {
flexTable.getCellFormatter().setStyleName(0, i, "timeSeries_header");
flexTable.setWidget(0, i, new HTML(filteredHeaders.get(i)));
flexTable.setWidget(1, i, new HTML(".."));
flexTable.getCellFormatter().setStyleName(1, i, "timeSeries_td");
}
if (filteredHeaders.size() > 10) {
flexTable.setWidget(0, 11, new HTML(" more .."));
flexTable.setWidget(1, 11, new HTML(".."));
flexTable.getCellFormatter().setStyleName(0, 11, "timeSeries_header");
flexTable.getCellFormatter().setStyleName(1, 11, "timeSeries_td");
}
tableContainer.add(flexTable);
Grid newGrid = new Grid(1, 2);
newGrid.setWidget(0, 0, new HTML("<b>Selected Interval:</b> ", true));
newGrid.setWidget(0, 1, new HTML(tf.getFrom() + " - " + tf.getTo() ));
tableContainer.add(newGrid);
}
/**
*
* @return the possible content
*/
public Label getLabel() {
return label;
}
/**
*
* @param label set the label
*/
public void setLabel(Label label) {
this.label = label;
}
/**
*
* @return .
*/
public String getIdInBasket() {
return idInBasket;
}
/**
*
* @param idInBasket .
*/
public void setIdInBasket(String idInBasket) {
this.idInBasket = idInBasket;
}
/**
*
* @return .
*/
public RepTimeSeries getSts() {
return sts;
}
/**
*
* @param sts .
*/
public void setSts(RepTimeSeries sts) {
this.sts = sts;
}
/**
*
* @param tsf the new ts filter
*/
public void setNewFilter(TimeSeriesFilter tsf) {
this.sts.setFilter(tsf);
}
}

View File

@ -67,7 +67,7 @@ public class OpenOptions extends Composite {
cmd.openTemplate.execute();
break;
case UPLOAD:
p.showUploadFilePopup();
p.showUploadFilePopup(null); //TODO: fix this
break;
default:
break;

View File

@ -0,0 +1,120 @@
package org.gcube.portlets.user.reportgenerator.server.servlet;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalImage;
import org.gcube.common.homelibrary.util.MimeTypeUtil;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
/**
* Servlet implementation class DownloadImageServlet
*/
public class DownloadImageServlet extends HttpServlet {
protected static Logger _log = Logger.getLogger(DownloadImageServlet.class);
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public DownloadImageServlet() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String itemId = req.getParameter("id");
if(itemId==null || itemId.isEmpty()){
sendError(resp,HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Item id is null");
return;
}
Workspace wa;
WorkspaceItem item;
try{
wa = getWorkspaceArea(req.getSession());
item = wa.getItem(itemId);
ExternalImage externalImage = (ExternalImage) item;
String mimeType = externalImage.getMimeType();
String itemName = MimeTypeUtil.getNameWithExtension(item.getName(), mimeType);
resp.setHeader( "Content-Disposition", "inline; filename=\"" + itemName + "\"" );
resp.setContentType(externalImage.getMimeType());
resp.setContentLength((int) externalImage.getLength());
OutputStream out = resp.getOutputStream();
InputStream is = externalImage.getData();
IOUtils.copy(is, out);
is.close();
out.close();
return;
} catch (Exception e) {
_log.error("Error during item retrieving "+itemId,e);
sendError(resp,HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Error during image retrieving: "+e.getMessage());
return;
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { }
/**
*
* @return
* @throws WorkspaceFolderNotFoundException
* @throws InternalErrorException
* @throws HomeNotFoundException
*/
protected Workspace getWorkspaceArea(HttpSession session) throws WorkspaceFolderNotFoundException, InternalErrorException, HomeNotFoundException {
String user = (String) session.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
String currScope = ScopeProvider.instance.get();
if (currScope == null) {
String scope2Set = "/"+PortalContext.getConfiguration().getInfrastructureName();
ScopeProvider.instance.set(scope2Set);
_log.warn("Found scope null, setting infrastructure scope="+scope2Set);
}
if (user == null) {
user = ReportServiceImpl.getDevUser();
ScopeProvider.instance.set(ReportServiceImpl.TEST_SCOPE);
_log.warn("User is null in session, setting dev user = " + user);
}
Workspace toReturn = HomeLibrary.getUserWorkspace(user);
return toReturn;
}
protected void sendError(HttpServletResponse response, String resultMessage) throws IOException {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
_log.trace("error message: "+resultMessage);
_log.trace("writing response...");
StringReader sr = new StringReader(resultMessage);
IOUtils.copy(sr, response.getOutputStream());
_log.trace("response wrote");
response.flushBuffer();
}
}

View File

@ -30,6 +30,11 @@ import net.sf.csv4j.ParseException;
import net.sf.csv4j.ProcessingException;
import org.apache.commons.io.IOUtils;
import org.apache.tika.config.TikaConfig;
import org.apache.tika.detect.Detector;
import org.apache.tika.io.TikaInputStream;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MediaType;
import org.gcube.application.framework.accesslogger.library.impl.AccessLogger;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
@ -85,6 +90,7 @@ import org.gcube.portlets.user.reportgenerator.server.servlet.loggers.CreateRepo
import org.gcube.portlets.user.reportgenerator.server.servlet.loggers.OpenReportLogEntry;
import org.gcube.portlets.user.reportgenerator.server.servlet.loggers.OpenWorkflowLogEntry;
import org.gcube.portlets.user.reportgenerator.server.servlet.loggers.SaveWorkflowLogEntry;
import org.gcube.portlets.user.reportgenerator.shared.ReportImage;
import org.gcube.portlets.user.reportgenerator.shared.SessionInfo;
import org.gcube.portlets.user.reportgenerator.shared.UserBean;
import org.gcube.portlets.user.reportgenerator.shared.VMEReportBean;
@ -107,6 +113,7 @@ import com.liferay.portlet.documentlibrary.model.DLFileEntry;
/**
*
* class implementing services
@ -122,9 +129,9 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
private boolean withinPortal = true;
//private static final String TEST_SCOPE = "/gcube/devsec/devVRE";
private static final String TEST_SCOPE = "/gcube/devNext/NextNext";
public static final String TEST_SCOPE = "/gcube/devNext/NextNext";
protected static final String IMAGE_SERVICE_URL = "reports/DownloadService";
/**
*
*/
@ -142,6 +149,8 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
*/
public static final String RSG_WS_ADDRESS = "RSG_WS_ADDRESS";
private static final String REPORT_IMAGES_FOLDER = "Report Images";
/**
* the WF DB Store
@ -169,7 +178,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
if (user == null) {
user = "massimiliano.assante";
user = getDevUser();
this.getThreadLocalRequest().getSession().setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, user);
SessionManager.getInstance().getASLSession(sessionID, user).setScope(TEST_SCOPE);
String email = user+"@isti.cnr.it";
@ -187,6 +196,9 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
return SessionManager.getInstance().getASLSession(sessionID, user);
}
public static String getDevUser() {
return "massimiliano.assante";
}
/**
* Retrieve the user saved template names
*
@ -382,8 +394,12 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
log.logEntry(getASLSession().getUsername(), getASLSession().getScopeName(), logEntry);
if (! isTemplate) {
try {
ModelReader reader = new ModelReader(toReturn);
System.out.println(reader);
} catch (Exception e) {
_log.warn("ModelReader fails to read this report, continue...");
}
}
return toReturn;
@ -398,6 +414,94 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
}
/**
* used when an image is uploaded
*/
@Override
public ReportImage getUploadedImageUrlById(String fileName, String absolutePathOnServer) {
if (absolutePathOnServer == null)
return null;
try {
_log.trace("trying read: "+absolutePathOnServer);
WorkspaceFolder imagesFolder = getImagesFolder();
// Read from an input stream
InputStream imageData = new BufferedInputStream(new FileInputStream(absolutePathOnServer));
ExternalImage image = imagesFolder.createExternalImageItem(fileName, "automatically uploaded by Reports Manager", getMimeType(imageData, fileName), imageData);
_log.trace("Created external image with name " + image.getName());
return new ReportImage(image.getId(), buildImageServiceUrl(image.getId()), image.getWidth(), image.getHeight());
} catch (Exception e) {
_log.error("Error in server get image by id", e);
e.printStackTrace();
}
return null;
}
private WorkspaceFolder getImagesFolder() {
Workspace ws = null;
WorkspaceFolder reportFolder = null;
try {
ws = getWorkspaceArea();
if (! ws.getRoot().exists(REPORT_IMAGES_FOLDER)) {
reportFolder = ws.getRoot().createFolder(REPORT_IMAGES_FOLDER, "This folder hosts the images uploaded by the Reports Manager");
} else {
reportFolder = (WorkspaceFolder) ws.getRoot().find(REPORT_IMAGES_FOLDER);
}
} catch (Exception e) {
e.printStackTrace();
}
return reportFolder;
}
/**
*
* @param is
* @return
* @throws IOException
* @throws MagicParseException
* @throws MagicMatchNotFoundException
* @throws MagicException
*/
protected static String getMimeType(InputStream is, String filenameWithExtension) throws IOException {
TikaConfig config = TikaConfig.getDefaultConfig();
Detector detector = config.getDetector();
TikaInputStream stream = TikaInputStream.get(is);
Metadata metadata = new Metadata();
metadata.add(Metadata.RESOURCE_NAME_KEY, filenameWithExtension);
MediaType mediaType = detector.detect(stream, metadata);
return mediaType.getBaseType().toString();
}
/**
* used to actually display images in reports (when reading reports)
*/
@Override
public ReportImage getImageUrlById(String identifier) {
if (identifier == null)
return null;
try {
Workspace workspace = getWorkspaceArea();
_log.trace("get image URL by id: "+identifier);
WorkspaceItem item = workspace.getItem(identifier); //get item from workspace
//ACCOUNTING READ
item.markAsRead(true);
_log.trace("item name " + item.getName());
ExternalImage image = (ExternalImage) item; //Cast External Document
return new ReportImage(image.getId(), buildImageServiceUrl(image.getId()), image.getWidth(), image.getHeight());
} catch (Exception e) {
_log.error("Error in server get image by id", e);
e.printStackTrace();
}
return null;
}
protected String buildImageServiceUrl(String id) {
StringBuilder sb = new StringBuilder();
sb.append(IMAGE_SERVICE_URL).append("?id=").append(id).append("&type=IMAGE");
return sb.toString();
}
/**
@ -836,8 +940,13 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
ServiceUtil myUtil = new ServiceUtil(getASLSession());
boolean result = myUtil.writeModel(model, "CURRENT_OPEN", getVreName(), getUsername());
try {
ModelReader reader = new ModelReader(model);
System.out.println(reader);
} catch (Exception e) {
_log.warn("ModelReader fails to read this report, continue...");
}
if (!result) {
_log.debug("Could not save report, serializing failed");

View File

@ -0,0 +1,46 @@
package org.gcube.portlets.user.reportgenerator.shared;
import java.io.Serializable;
@SuppressWarnings("serial")
public class ReportImage implements Serializable {
private String id;
private String url;
private int width;
private int height;
public ReportImage() {
super();
}
public ReportImage(String id, String url, int width, int height) {
super();
this.id = id;
this.url = url;
this.width = width;
this.height = height;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
}

View File

@ -11,7 +11,7 @@
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />
<inherits name='org.gcube.portlets.d4sreporting.common.Reporting' />
<inherits name='com.extjs.gxt.ui.GXT' />
<inherits name='org.gcube.portlets.user.workspace.WorkspaceTree' />
<inherits name='org.gcube.portlets.widgets.fileupload.FileUpload' />
<inherits name='org.gcube.portlets.widgets.exporter.Report_exporter_widget' />
<!-- Specify the app entry point class. -->
<entry-point

View File

@ -1,7 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="WebApp_ID" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>ReportGenerator-portlet</display-name>
<!-- Servlets -->
<servlet>
@ -36,6 +33,39 @@
</servlet-mapping>
<servlet>
<servlet-name>uploadprogress</servlet-name>
<servlet-class>org.gcube.portlets.widgets.fileupload.server.UploadProgressServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>uploadprogress</servlet-name>
<url-pattern>/reports/uploadprogress</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>DownloadService</servlet-name>
<servlet-class>org.gcube.portlets.user.reportgenerator.server.servlet.DownloadImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DownloadService</servlet-name>
<url-pattern>/reports/DownloadService</url-pattern>
</servlet-mapping>
<!-- DO NOT CHANGE - DO NOT Replace URL PATTERN HERE -->
<servlet>
<servlet-name>upload</servlet-name>
<servlet-class>org.gcube.portlets.widgets.fileupload.server.UploadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>upload</servlet-name>
<url-pattern>/FileUpload/upload</url-pattern>
</servlet-mapping>
<!-- END DO NOT CHANGE -->
<servlet>
<servlet-name>remoteLoggerServiceImpl</servlet-name>
@ -47,55 +77,6 @@
<url-pattern>/reports/gwt-log</url-pattern>
</servlet-mapping>
<!-- Workspace Tree import part -->
<servlet>
<servlet-name>WorkspaceService</servlet-name>
<servlet-class>org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WorkspaceService</servlet-name>
<url-pattern>/reports/WorkspaceService</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>UploadService</servlet-name>
<servlet-class>org.gcube.portlets.user.workspace.server.UploadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UploadService</servlet-name>
<url-pattern>/reports/UploadService</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>localUploadServlet</servlet-name>
<servlet-class>org.gcube.portlets.user.workspace.server.LocalUploadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>localUploadServlet</servlet-name>
<url-pattern>/reports/LocalUploadService</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>DownloadService</servlet-name>
<servlet-class>org.gcube.portlets.user.workspace.server.DownloadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DownloadService</servlet-name>
<url-pattern>/reports/DownloadService</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ImageService</servlet-name>
<servlet-class>org.gcube.portlets.user.workspace.server.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ImageService</servlet-name>
<url-pattern>/reports/ImageService</url-pattern>
</servlet-mapping>
<!-- Fimes import expot part -->
@ -127,23 +108,7 @@
<url-pattern>/reports/downloadEncryptedReport</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DownloadService</servlet-name>
<url-pattern>/org.gcube.portlets.user.reportgenerator.ReportGeneratorJUnit/DownloadService</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>WorkspaceService</servlet-name>
<url-pattern>/org.gcube.portlets.user.reportgenerator.ReportGeneratorJUnit/WorkspaceService</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ImageService</servlet-name>
<url-pattern>/org.gcube.portlets.user.reportgenerator.ReportGeneratorJUnit/ImageService</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>UploadService</servlet-name>
<url-pattern>/org.gcube.portlets.user.reportgenerator.ReportGeneratorJUnit/UploadService</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>ReportGenerator.html</welcome-file>