should be reasy for testing the associations

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/reports@85498 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-11-14 15:26:26 +00:00
parent 87311f7eff
commit 471c399287
8 changed files with 211 additions and 65 deletions

View File

@ -5,9 +5,12 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import org.gcube.portlets.d4sreporting.common.client.uicomponents.richtext.RichTextToolbar; import org.gcube.portlets.d4sreporting.common.client.uicomponents.richtext.RichTextToolbar;
import org.gcube.portlets.d4sreporting.common.shared.BasicSection;
import org.gcube.portlets.d4sreporting.common.shared.ComponentType; import org.gcube.portlets.d4sreporting.common.shared.ComponentType;
import org.gcube.portlets.d4sreporting.common.shared.Metadata; import org.gcube.portlets.d4sreporting.common.shared.Metadata;
import org.gcube.portlets.d4sreporting.common.shared.Model; import org.gcube.portlets.d4sreporting.common.shared.Model;
import org.gcube.portlets.d4sreporting.common.shared.RepeatableSequence;
import org.gcube.portlets.d4sreporting.common.shared.Tuple;
import org.gcube.portlets.user.reportgenerator.client.Headerbar; import org.gcube.portlets.user.reportgenerator.client.Headerbar;
import org.gcube.portlets.user.reportgenerator.client.ReportConstants; import org.gcube.portlets.user.reportgenerator.client.ReportConstants;
import org.gcube.portlets.user.reportgenerator.client.ReportGenerator; import org.gcube.portlets.user.reportgenerator.client.ReportGenerator;
@ -39,6 +42,7 @@ import org.gcube.portlets.user.reportgenerator.client.targets.AttributeSingleSel
import org.gcube.portlets.user.reportgenerator.client.targets.BasicTextArea; import org.gcube.portlets.user.reportgenerator.client.targets.BasicTextArea;
import org.gcube.portlets.user.reportgenerator.client.targets.ClientImage; import org.gcube.portlets.user.reportgenerator.client.targets.ClientImage;
import org.gcube.portlets.user.reportgenerator.client.targets.ClientRepeatableSequence; import org.gcube.portlets.user.reportgenerator.client.targets.ClientRepeatableSequence;
import org.gcube.portlets.user.reportgenerator.client.targets.ClientSequence;
import org.gcube.portlets.user.reportgenerator.client.targets.ClientTuple; import org.gcube.portlets.user.reportgenerator.client.targets.ClientTuple;
import org.gcube.portlets.user.reportgenerator.client.targets.Coords; import org.gcube.portlets.user.reportgenerator.client.targets.Coords;
import org.gcube.portlets.user.reportgenerator.client.targets.D4sRichTextarea; import org.gcube.portlets.user.reportgenerator.client.targets.D4sRichTextarea;
@ -114,6 +118,10 @@ public class Presenter {
private String location; private String location;
private int currFocus; private int currFocus;
/**
* this is needed to know on which client sequence the user is operating
*/
private ClientSequence clientSeqSelected = null;
RichTextToolbar currentSelectedToolbar; RichTextToolbar currentSelectedToolbar;
@ -134,11 +142,11 @@ public class Presenter {
return eventBus; return eventBus;
} }
private UserSelectionDialog itemSelectionDialog; private UserSelectionDialog itemSelectionDialog;
private void handleEvents() { private void handleEvents() {
eventBus.addHandler(SelectedUserEvent.TYPE, new SelectedUserEventHandler() { eventBus.addHandler(SelectedUserEvent.TYPE, new SelectedUserEventHandler() {
@Override @Override
public void onSelectedUser(SelectedUserEvent event) { public void onSelectedUser(SelectedUserEvent event) {
@ -146,7 +154,11 @@ public class Presenter {
if (event.getSelectedUser().getType().equals(VMETypeIdentifier.Vme.toString())) if (event.getSelectedUser().getType().equals(VMETypeIdentifier.Vme.toString()))
importVMEReport(event.getSelectedUser()); importVMEReport(event.getSelectedUser());
else else
associateVMRReportRef(event.getSelectedUser()); try {
associateVMRReportRef(event.getSelectedUser());
} catch (Exception e) {
e.printStackTrace();
}
} }
}); });
@ -286,6 +298,10 @@ public class Presenter {
//importDlg = new FimesFileUploadWindow(eventBus); //importDlg = new FimesFileUploadWindow(eventBus);
} }
public void setClientSequenceSelected(ClientSequence toSet) {
this.clientSeqSelected = toSet;
}
public void showOpenOptions() { public void showOpenOptions() {
wp.showOpenOptions(); wp.showOpenOptions();
} }
@ -1290,7 +1306,7 @@ public class Presenter {
} }
}); });
} }
/** /**
* *
*/ */
@ -1313,13 +1329,13 @@ public class Presenter {
} }
}); });
} }
private void importVMEReport(ItemSelectableBean selectedReport) { private void importVMEReport(ItemSelectableBean selectedReport) {
showLoading(); showLoading();
reportService.importVMEReport(selectedReport.getId(), selectedReport.getName(), new AsyncCallback<Model>() { reportService.importVMEReport(selectedReport.getId(), selectedReport.getName(), new AsyncCallback<Model>() {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
Window.alert("Could not Load template, please try again later: " + caught.getMessage()); Window.alert("Could not Load Report Model, error on server.: " + caught.getMessage());
} }
@Override @Override
@ -1327,13 +1343,55 @@ public class Presenter {
if (toLoad != null) if (toLoad != null)
loadModel(toLoad); loadModel(toLoad);
else else
Window.alert("Could not Load template, error on server."); Window.alert("Could not Load Report Model, error on server.");
} }
}); });
} }
private void associateVMRReportRef (ItemSelectableBean selectedReport) { private void associateVMRReportRef (ItemSelectableBean selectedReport) throws Exception {
Window.alert("You selected " + selectedReport.getName() + " of type " + selectedReport.getType()); reportService.importVMEReportRef(selectedReport.getId(), getTypeIdFromString(selectedReport.getType()), new AsyncCallback<Model>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Could not Load Report Model, error on server.: " + caught.getMessage());
}
@Override
public void onSuccess(Model reportRef) {
if (reportRef != null && reportRef.getSections().size() > 0) {
//the Repeatable Seq must be in the 1st Section, second component. (because ReportsModeler put it that way)
BasicSection firstSection = reportRef.getSections().get(0);
if (firstSection.getComponents() != null && firstSection.getComponents().size()==2) {
@SuppressWarnings("unchecked")
ArrayList<Tuple> toPass = (ArrayList<Tuple>) firstSection.getComponents().get(1).getPossibleContent();
clientSeqSelected.add(toPass.get(0).getKey(), toPass.get(0));
}
else {
Window.alert("Sorry, we could not locate the ReportRef correctly in the model instance");
}
}
else
Window.alert("Could not Load Report Model, error on server.");
}
});
}
/**
* this method translate the VME ReportRef String in an ENUM
* @param theType
* @return
* @throws Exception
*/
public VMETypeIdentifier getTypeIdFromString(String theType) throws Exception {
if (theType.equals("GeneralMeasure"))
return VMETypeIdentifier.GeneralMeasure;
else if (theType.equals("InformationSource"))
return VMETypeIdentifier.InformationSource;
else if (theType.equals("FisheryAreasHistory"))
return VMETypeIdentifier.FisheryAreasHistory;
else if (theType.equals("VmesHistory"))
return VMETypeIdentifier.VmesHistory;
throw new Exception("Could not find any valid Report Ref, got " + theType + " should be any of " + VMETypeIdentifier.values());
} }
} }

View File

@ -26,6 +26,8 @@ public interface ReportService extends RemoteService{
ArrayList<ItemSelectableBean> listVMEReportRefByType(VMETypeIdentifier refType); ArrayList<ItemSelectableBean> listVMEReportRefByType(VMETypeIdentifier refType);
Model importVMEReport(String id, String name); Model importVMEReport(String id, String name);
Model importVMEReportRef(String id, VMETypeIdentifier refType);
String save(String filePath, String workspaceFolderId, String ItemName, String save(String filePath, String workspaceFolderId, String ItemName,
TypeExporter type, boolean overwrite) TypeExporter type, boolean overwrite)

View File

@ -78,4 +78,6 @@ public interface ReportServiceAsync {
void importVMEReport(String id, String name, AsyncCallback<Model> callback); void importVMEReport(String id, String name, AsyncCallback<Model> callback);
void listVMEReportRefByType(VMETypeIdentifier refType, void listVMEReportRefByType(VMETypeIdentifier refType,
AsyncCallback<ArrayList<ItemSelectableBean>> callback); AsyncCallback<ArrayList<ItemSelectableBean>> callback);
void importVMEReportRef(String id, VMETypeIdentifier refType,
AsyncCallback<Model> callback);
} }

View File

@ -134,7 +134,7 @@ public class ClientRepeatableSequence extends Composite implements ClientSequenc
} }
@Override @Override
public boolean add(RepeatableSequence sequence) { public boolean add(String id, RepeatableSequence sequence) {
SequenceWidget seqW = new SequenceWidget(p, this, sequence, false, true); SequenceWidget seqW = new SequenceWidget(p, this, sequence, false, true);
myPanel.add(seqW); myPanel.add(seqW);
return true; return true;
@ -147,5 +147,10 @@ public class ClientRepeatableSequence extends Composite implements ClientSequenc
groupedComponents.remove(tc); groupedComponents.remove(tc);
} }
return toRemove; return toRemove;
}
@Override
public void AddButtonClicked(RepeatableSequence sequence) {
add("not needed", sequence);
} }
} }

View File

@ -9,7 +9,9 @@ public interface ClientSequence {
ArrayList<TemplateComponent> getGroupedComponents(); ArrayList<TemplateComponent> getGroupedComponents();
boolean add(RepeatableSequence sequence); boolean add(String id, RepeatableSequence sequence);
SequenceWidget remove(SequenceWidget toRemove); SequenceWidget remove(SequenceWidget toRemove);
void AddButtonClicked(RepeatableSequence sequence);
} }

View File

@ -8,6 +8,8 @@ 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.TemplateComponent;
import org.gcube.portlets.user.reportgenerator.shared.VMETypeIdentifier; import org.gcube.portlets.user.reportgenerator.shared.VMETypeIdentifier;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.VerticalPanel;
@ -35,22 +37,26 @@ public class ClientTuple extends Composite implements ClientSequence {
this.tupleList = tupleList; this.tupleList = tupleList;
for (Tuple seq : tupleList) { for (Tuple seq : tupleList) {
if (myPanel.getWidgetCount()==0) { // if is the first one if (myPanel.getWidgetCount()==0) { // if is the first one
first = new SequenceWidget(p, this, seq, true, false); first = getMasterSequence(seq);
if (tupleList.size() == 1) {
first.enableClear();
}
myPanel.add(first); myPanel.add(first);
} else { } else {
SequenceWidget seqW = new SequenceWidget(p, this, seq, false, false); SequenceWidget seqW = new SequenceWidget(p, this, seq, false, false);
myPanel.add(seqW); myPanel.add(seqW);
} }
} }
initWidget(myPanel); initWidget(myPanel);
} }
/**
* the first seq has to behave differently
*/
private SequenceWidget getMasterSequence(RepeatableSequence seq) {
SequenceWidget toReturn = new SequenceWidget(p, this, seq, true, false);
if (tupleList.size() == 1) {
toReturn.enableClear();
}
return toReturn;
}
public ArrayList<Tuple> getTupleList() { public ArrayList<Tuple> getTupleList() {
@ -69,22 +75,20 @@ public class ClientTuple extends Composite implements ClientSequence {
} }
@Override @Override
public boolean add(RepeatableSequence sequence) { public boolean add(String id, RepeatableSequence sequence) {
Tuple tuple = (Tuple) sequence; if (first.isSelectNewEnabled()) {
VMETypeIdentifier type2Pass = null; first = getMasterSequence(sequence);
if (tuple.getKey().equals("GENERAL_MEASURE")) myPanel.clear();
type2Pass = VMETypeIdentifier.GeneralMeasure; myPanel.add(first);
else if (tuple.getKey().equals("INFORMATION_SOURCE")) tupleList.clear();
type2Pass = VMETypeIdentifier.InformationSource; } else {
else if (tuple.getKey().equals("FISHERY_AREA_HISTORY")) SequenceWidget seqW = new SequenceWidget(p, this, sequence, false, true);
type2Pass = VMETypeIdentifier.FisheryAreasHistory; myPanel.add(seqW);
else if (tuple.getKey().equals("VMES_HISTORY")) first.hideClearAssociationButton();
type2Pass = VMETypeIdentifier.VmesHistory;
else {
Window.alert("Could not find any valid Report Ref, got " + tuple.getKey());
return false;
} }
p.showVMERefAssociateDialog(type2Pass); //needed for the model //TODO: preserve the id!!
Tuple toAdd = new Tuple(id, sequence.getGroupedComponents());
tupleList.add(toAdd);
return true; return true;
} }
@ -98,7 +102,25 @@ public class ClientTuple extends Composite implements ClientSequence {
tupleList.remove(toRemove.getSequence()); tupleList.remove(toRemove.getSequence());
if (tupleList.size() == 1) if (tupleList.size() == 1)
first.enableClear(); first.enableClear();
GWT.log("List Tuple Size = "+tupleList.size());
return toRemove; return toRemove;
} }
@Override
public void AddButtonClicked(RepeatableSequence sequence) {
Tuple tuple = (Tuple) sequence;
VMETypeIdentifier type2Pass = null;
try {
type2Pass = p.getTypeIdFromString(tuple.getKey());
} catch (Exception e) {
e.printStackTrace();
}
p.showVMERefAssociateDialog(type2Pass);
p.setClientSequenceSelected(this); //important!
}
} }

View File

@ -13,7 +13,6 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; 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.Button;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTML;
@ -27,16 +26,18 @@ public class SequenceWidget extends Composite {
private Button addAnotherB = new Button("Add another Entry"); private Button addAnotherB = new Button("Add another Entry");
private Button removeThisB = new Button("Remove Entry"); private Button removeThisB = new Button("Remove Entry");
private Button selectEntryB = new Button("Select New"); private Button selectNewB = new Button("Select New");
private Presenter p; private Button clearB = new Button("Clear Association");
private HorizontalPanel buttonPanel = new HorizontalPanel(); private HorizontalPanel buttonPanel = new HorizontalPanel();
HorizontalPanel buttonsWrapperPanel = new HorizontalPanel(); HorizontalPanel buttonsWrapperPanel = new HorizontalPanel();
private ClientSequence owner; private ClientSequence owner;
private RepeatableSequence repSequence; private RepeatableSequence repSequence;
private ArrayList<TemplateComponent> seqGroupedComponents = new ArrayList<TemplateComponent>(); private ArrayList<TemplateComponent> seqGroupedComponents = new ArrayList<TemplateComponent>();
private boolean isSelectingNew = false;
public SequenceWidget(Presenter p, ClientSequence owner, RepeatableSequence repSequence, boolean notRemovable, boolean isNew) { public SequenceWidget(Presenter p, ClientSequence owner, RepeatableSequence repSequence, boolean notRemovable, boolean isNew) {
this.p = p;
this.owner = owner; this.owner = owner;
this.repSequence = repSequence; this.repSequence = repSequence;
addAnotherB.getElement().getStyle().setMargin(10, Unit.PX); addAnotherB.getElement().getStyle().setMargin(10, Unit.PX);
@ -78,7 +79,7 @@ public class SequenceWidget extends Composite {
}); });
} }
else { else {
removeThisB.getElement().getStyle().setWidth(130, Unit.PX); removeThisB.getElement().getStyle().setWidth(130, Unit.PX);
removeThisB.getElement().getStyle().setMargin(10, Unit.PX); removeThisB.getElement().getStyle().setMargin(10, Unit.PX);
removeThisB.addStyleName("deleteEntryButton"); removeThisB.addStyleName("deleteEntryButton");
@ -90,25 +91,33 @@ public class SequenceWidget extends Composite {
removeMe(); removeMe();
} }
}); });
buttonsWrapperPanel.add(addAnotherB); buttonsWrapperPanel.add(addAnotherB);
addAnotherB.addClickHandler(new ClickHandler() { addAnotherB.addClickHandler(new ClickHandler() {
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
addAnother(); addAnother();
} }
}); });
} }
} }
private void selectNew() { protected boolean hideClearAssociationButton() {
owner.add(repSequence); return buttonsWrapperPanel.remove(clearB);
} }
private void addAnother() {
owner.AddButtonClicked(repSequence);
}
private void selectNew() {
owner.AddButtonClicked(repSequence);
}
public void enableClear() { public void enableClear() {
Button clearB = new Button("Clear Association");
clearB.getElement().getStyle().setWidth(130, Unit.PX); clearB.getElement().getStyle().setWidth(130, Unit.PX);
clearB.getElement().getStyle().setMargin(10, Unit.PX); clearB.getElement().getStyle().setMargin(10, Unit.PX);
clearB.addStyleName("deleteAssociationButton"); clearB.addStyleName("deleteAssociationButton");
@ -119,13 +128,13 @@ public class SequenceWidget extends Composite {
clearAssociation(); clearAssociation();
} }
}); });
buttonsWrapperPanel.insert(clearB, 0); buttonsWrapperPanel.insert(clearB, 0);
} }
public void clearAssociation() { public void clearAssociation() {
GWT.log("Clearing Association"); GWT.log("Clearing Association");
//in the MODEL //in the MODEL
for (BasicComponent bc : repSequence.getGroupedComponents()) { for (BasicComponent bc : repSequence.getGroupedComponents()) {
@ -141,20 +150,25 @@ public class SequenceWidget extends Composite {
} }
} }
buttonsWrapperPanel.clear(); buttonsWrapperPanel.clear();
selectEntryB.getElement().getStyle().setWidth(130, Unit.PX); selectNewB.getElement().getStyle().setWidth(130, Unit.PX);
selectEntryB.getElement().getStyle().setMargin(10, Unit.PX); selectNewB.getElement().getStyle().setMargin(10, Unit.PX);
selectEntryB.addStyleName("deleteAssociationButton"); selectNewB.addStyleName("deleteAssociationButton");
selectEntryB.addClickHandler(new ClickHandler() { selectNewB.addClickHandler(new ClickHandler() {
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
selectNew(); selectNew();
} }
}); });
buttonsWrapperPanel.add(selectEntryB); buttonsWrapperPanel.add(selectNewB);
isSelectingNew = true;
} }
protected boolean isSelectNewEnabled() {
return isSelectingNew;
}
public void add(TemplateComponent toAdd) { public void add(TemplateComponent toAdd) {
if (toAdd.getType() != ComponentType.REPEAT_SEQUENCE_INNER) { if (toAdd.getType() != ComponentType.REPEAT_SEQUENCE_INNER) {
owner.getGroupedComponents().add(toAdd); owner.getGroupedComponents().add(toAdd);
@ -172,14 +186,12 @@ public class SequenceWidget extends Composite {
buttonsWrapperPanel.remove(addAnotherB); buttonsWrapperPanel.remove(addAnotherB);
} }
private void addAnother() {
owner.add(repSequence);
}
private void removeMe() { private void removeMe() {
owner.remove(this); owner.remove(this);
} }
public RepeatableSequence getSequence() { public RepeatableSequence getSequence() {
return repSequence; return repSequence;
} }

View File

@ -32,6 +32,8 @@ import org.gcube.application.framework.accesslogger.library.impl.AccessLogger;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager; import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.application.reporting.ReportsModeler; import org.gcube.application.reporting.ReportsModeler;
import org.gcube.application.reporting.reference.DBTableRow;
import org.gcube.application.reporting.reference.ReferenceReportType;
import org.gcube.application.rsg.service.dto.ReportEntry; import org.gcube.application.rsg.service.dto.ReportEntry;
import org.gcube.application.rsg.service.dto.ReportType; import org.gcube.application.rsg.service.dto.ReportType;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager; import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
@ -63,6 +65,7 @@ import org.gcube.portlets.d4sreporting.common.server.ServiceUtil;
import org.gcube.portlets.d4sreporting.common.shared.BasicComponent; import org.gcube.portlets.d4sreporting.common.shared.BasicComponent;
import org.gcube.portlets.d4sreporting.common.shared.BasicSection; import org.gcube.portlets.d4sreporting.common.shared.BasicSection;
import org.gcube.portlets.d4sreporting.common.shared.ComponentType; import org.gcube.portlets.d4sreporting.common.shared.ComponentType;
import org.gcube.portlets.d4sreporting.common.shared.Metadata;
import org.gcube.portlets.d4sreporting.common.shared.Model; import org.gcube.portlets.d4sreporting.common.shared.Model;
import org.gcube.portlets.d4sreporting.common.shared.RepTimeSeries; import org.gcube.portlets.d4sreporting.common.shared.RepTimeSeries;
import org.gcube.portlets.d4sreporting.common.shared.RepeatableSequence; import org.gcube.portlets.d4sreporting.common.shared.RepeatableSequence;
@ -1539,4 +1542,44 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
} }
public Model importVMEReportRef(String id, VMETypeIdentifier refType) {
String reportName = "Sample VME Report imported with id: " + id;
ReportsModeler rm = new ReportsModeler(
UUID.randomUUID().toString(),
reportName,
getASLSession().getUsername(),
new Date(),
new Date(),
getASLSession().getUsername()
);
//construct the options (the references)
ArrayList<DBTableRow> dBTableRows = new ArrayList<DBTableRow>();
ArrayList<Metadata> md = new ArrayList<Metadata>();
Random generator = new Random();
int year = generator.nextInt(15) + 2000;
md.add(new Metadata("Year", ""+year));
year = generator.nextInt(15) + 2000;
md.add(new Metadata("Validity Period - Start", ""+year));
year = generator.nextInt(15) + 2000;
md.add(new Metadata("Validity Period - End", ""+year));
md.add(new Metadata("VME Specific Measure Summary",
"2011 Roll over of existing measures until 31 Dec 2014. " + UUID.randomUUID().toString()
+ "Closed to demersal fishing with possibilities of an exploratory fishing not exceed-ing 20% "
+ "of the fishable area of each seamount. (CEM 2011, Art. 15)"));
md.add(new Metadata("Link Bookmarked", "http://archive.nafo.int/open/fc/2012/fcdoc12-01.pdf"));
md.add(new Metadata("Link Source URL", "http://archive.nafo.int/open/fc/2012/fcdoc12-01.pdf"));
dBTableRows.add(new DBTableRow(md));
rm.addReference(ReferenceReportType.GeneralMeasure, dBTableRows);
try {
return rm.getReportInstance();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
} }