diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index d1324d9..3af9f7e 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,29 +1,39 @@ - + + + - + + + - + + + - + + + - + + + @@ -32,25 +42,33 @@ uses - + + + - + + + - + + + - + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 734f6c7..f9b5eb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm Moved to maven-portal-bom 3.6.3 [#21856] Implementing new user feedback [#21890] Passed to mongoID +[#20599] Get List of Records ## [v1.2.0] - 2020-12-18 diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java index def5f97..7076afb 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java @@ -12,4 +12,10 @@ public class ConstantsGeoPortalDataEntryApp { public static final String ERROR_ON_INIZIALITAION_STAGE_PLEASE_CONTACT_THE_SUPPORT = "Error on inizialization stage, please contact the support!"; + + public enum RECORD_TYPE { + CONCESSIONE + } + + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index 7d8448e..815d042 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -8,14 +8,19 @@ import java.util.List; import java.util.TreeMap; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.events.CreateNewProjectEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.CreateNewProjectEventHandler; +import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecordsEvent; +import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecordsEventHandler; import org.gcube.portlets.user.geoportaldataentry.client.events.SaveGeonaDataFormsEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.SaveGeonaDataFormsHandler; -import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaDataEntryMainForm; import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaMainPanel; +import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaRecordsPaginatedView; import org.gcube.portlets.user.geoportaldataentry.client.ui.card.GeoNaFormCardModel; +import org.gcube.portlets.user.geoportaldataentry.client.ui.form.GeonaDataEntryMainForm; import org.gcube.portlets.user.geoportaldataentry.client.ui.report.ReportTemplateToHTML; +import org.gcube.portlets.user.geoportaldataentry.client.ui.table.ItemsTable.DISPLAY_FIELD; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil.HTML_TAG; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; @@ -57,7 +62,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { /** * Create a remote service proxy to talk to the server-side Greeting service. */ - private final GeoportalDataEntryServiceAsync greetingService = GWT.create(GeoportalDataEntryService.class); + public static final GeoportalDataEntryServiceAsync greetingService = GWT.create(GeoportalDataEntryService.class); private final HandlerManager appManagerBus = new HandlerManager(null); @@ -350,6 +355,21 @@ public class GeoPortalDataEntryApp implements EntryPoint { } }); + + appManagerBus.addHandler(GetListOfRecordsEvent.TYPE, new GetListOfRecordsEventHandler() { + + @Override + public void onGetList(GetListOfRecordsEvent getListOfRecordsEvent) { + + + Modal modal = new Modal(true); + modal.setCloseVisible(true); + GeonaRecordsPaginatedView grpw = new GeonaRecordsPaginatedView(appManagerBus,RECORD_TYPE.CONCESSIONE,null, DISPLAY_FIELD.NAME); + modal.add(grpw.getCellPanel()); + modal.add(grpw.getPagerPanel()); + modal.show(); + } + }); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java index 32fc1c1..8b6fba5 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java @@ -6,19 +6,55 @@ import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; +import org.gcube.portlets.user.geoportaldataentry.shared.SearchedData; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; /** * The client side stub for the RPC service. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Aug 4, 2021 */ @RemoteServiceRelativePath("geoportaldataentryservice") public interface GeoportalDataEntryService extends RemoteService { + /** + * Save geona data forms. + * + * @param listGeonaFormObjects the list geona form objects + * @return the commit report + * @throws Exception the exception + */ CommitReport saveGeonaDataForms(List listGeonaFormObjects) throws Exception; + /** + * Gets the geona init config. + * + * @return the geona init config + */ GeonaISConfig getGeonaInitConfig(); + /** + * Gets the links for. + * + * @param itemId the item id + * @param recordType the record type + * @return the links for + * @throws Exception the exception + */ GeoNaItemRef getLinksFor(String itemId, String recordType) throws Exception; + + + /** + * Gets the list concessioni. + * + * @param start the start + * @param offset the offset + * @return the list concessioni + * @throws Exception the exception + */ + SearchedData getListConcessioni(Integer start, Integer offset) throws Exception; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java index 0a01544..902f1c4 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java @@ -6,6 +6,7 @@ import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; +import org.gcube.portlets.user.geoportaldataentry.shared.SearchedData; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -43,4 +44,7 @@ public interface GeoportalDataEntryServiceAsync void getLinksFor(String itemId, String recordType, AsyncCallback callback); + + + void getListConcessioni(Integer start, Integer offset, AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ClickItemEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ClickItemEvent.java new file mode 100644 index 0000000..6578f7a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ClickItemEvent.java @@ -0,0 +1,68 @@ +package org.gcube.portlets.user.geoportaldataentry.client.events; + +import java.util.List; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * The Class ClickItemEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 22, 2021 + * @param the generic type + */ +public class ClickItemEvent extends GwtEvent { + public static Type TYPE = new Type(); + private List selectItems; + + /** + * Instantiates a new click item event. + * + * @param selectItems the select items + */ + public ClickItemEvent(List selectItems) { + this.selectItems = selectItems; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + /* + * (non-Javadoc) + * + * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType() + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared. + * EventHandler) + */ + @Override + protected void dispatch(ClickItemEventHandler handler) { + handler.onClick(this); + } + + /** + * Gets the select items. + * + * @return the select items + */ + public List getSelectItems() { + return selectItems; + } +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ClickItemEventHandler.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ClickItemEventHandler.java new file mode 100644 index 0000000..9b9097e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ClickItemEventHandler.java @@ -0,0 +1,21 @@ +package org.gcube.portlets.user.geoportaldataentry.client.events; + +import com.google.gwt.event.shared.EventHandler; + + +/** + * The Interface ClickItemEventHandler. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jul 6, 2015 + */ +public interface ClickItemEventHandler extends EventHandler { + + /** + * On click. + * + * @param the generic type + * @param moreInfoShowEvent the more info show event + */ + void onClick(ClickItemEvent moreInfoShowEvent); +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java new file mode 100644 index 0000000..9fb313f --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java @@ -0,0 +1,65 @@ +package org.gcube.portlets.user.geoportaldataentry.client.events; + +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * The Class CreateNewProjectEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Oct 13, 2020 + */ +public class GetListOfRecordsEvent extends GwtEvent { + + /** The type. */ + public static Type TYPE = new Type(); + private RECORD_TYPE recordType; + + + /** + * Instantiates a new cancel upload event. + */ + public GetListOfRecordsEvent(ConstantsGeoPortalDataEntryApp.RECORD_TYPE recordType) { + this.recordType = recordType; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + /* + * (non-Javadoc) + * + * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType() + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared. + * EventHandler) + */ + @Override + protected void dispatch(GetListOfRecordsEventHandler handler) { + handler.onGetList(this); + } + + public RECORD_TYPE getRecordType() { + return recordType; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEventHandler.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEventHandler.java new file mode 100644 index 0000000..7933d78 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEventHandler.java @@ -0,0 +1,22 @@ +package org.gcube.portlets.user.geoportaldataentry.client.events; + +import com.google.gwt.event.shared.EventHandler; + + +/** + * The Interface GetListOfRecordsEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Aug 4, 2021 + */ +public interface GetListOfRecordsEventHandler extends EventHandler { + + + /** + * On get list. + * + * @param getListOfRecordsEvent the get list of records event + */ + void onGetList(GetListOfRecordsEvent getListOfRecordsEvent); +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ShowItemEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ShowItemEvent.java new file mode 100644 index 0000000..fe6afc3 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ShowItemEvent.java @@ -0,0 +1,68 @@ +package org.gcube.portlets.user.geoportaldataentry.client.events; + +import java.util.List; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * The Class ShowItemEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 22, 2021 + * @param the generic type + */ +public class ShowItemEvent extends GwtEvent { + public static Type TYPE = new Type(); + private List selectItems; + + /** + * Instantiates a new click item event. + * + * @param selectItems the select items + */ + public ShowItemEvent(List selectItems) { + this.selectItems = selectItems; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + /* + * (non-Javadoc) + * + * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType() + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared. + * EventHandler) + */ + @Override + protected void dispatch(ShowItemEventHandler handler) { + handler.onShowItemClicked(this); + } + + /** + * Gets the select items. + * + * @return the select items + */ + public List getSelectItems() { + return selectItems; + } +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ShowItemEventHandler.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ShowItemEventHandler.java new file mode 100644 index 0000000..7713908 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ShowItemEventHandler.java @@ -0,0 +1,23 @@ +package org.gcube.portlets.user.geoportaldataentry.client.events; + +import com.google.gwt.event.shared.EventHandler; + + +// TODO: Auto-generated Javadoc +/** + * The Interface ShowItemEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 22, 2021 + */ +public interface ShowItemEventHandler extends EventHandler { + + /** + * On show item clicked. + * + * @param the generic type + * @param showItemEvent the show item event + */ + void onShowItemClicked(ShowItemEvent showItemEvent); +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/resource/CellTable.css b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/resource/CellTable.css new file mode 100644 index 0000000..c0939d4 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/resource/CellTable.css @@ -0,0 +1,110 @@ +@def selectionBorderWidth 1px ; .cellTableWidget { + +} + +.cellTableFirstColumn { + +} + +.cellTableLastColumn { + +} + +.cellTableFooter { + +} + +.cellTableHeader { +} + +.cellTableCell { + +} + +.cellTableFirstColumnFooter { + +} + +.cellTableFirstColumnHeader { + +} + +.cellTableLastColumnFooter { + +} + +.cellTableLastColumnHeader { + +} + +.cellTableSortableHeader { + +} + +.cellTableSortableHeader:hover { + +} + +.cellTableSortedHeaderAscending { + +} + +.cellTableSortedHeaderDescending { + +} + +.cellTableEvenRow { + +} + +.cellTableEvenRowCell { + +} + +.cellTableOddRow { + +} + +.cellTableOddRowCell { + +} + +.cellTableHoveredRow { + background: #D9EDF7 !important; + cursor: pointer; +} + +.cellTableHoveredRowCell { + background: #D9EDF7 !important; + cursor: pointer; +} + +.cellTableKeyboardSelectedRow, .cellTableKeyboardSelectedRow td, .cellTableKeyboardSelectedRow th { + background: #3A87AD !important; +} + +.cellTableSelectedRow, .cellTableSelectedRow td, .cellTableSelectedRow th + { + /* background: #D9EDF7 !important; */ + /* color: white !important; */ + /* height: auto; */ + /* overflow: auto; */ + +} + +.cellTableSelectedRowCell, .cellTableSelectedRow td.cellTableSelectedRowCell { + background: #3A87AD !important; +} + +.cellTableKeyboardSelectedRowCell, .cellTableKeyboardSelectedRow td.cellTableKeyboardSelectedRowCell{ + background: #3A87AD !important; +} + +.cellTableKeyboardSelectedCell, .cellTableKeyboardSelectedRow td.cellTableKeyboardSelectedCell{ + background: #3A87AD !important; + color: white !important; +} + +.cellTableLoading { + margin: 30px; +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/resource/CellTableResources.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/resource/CellTableResources.java new file mode 100644 index 0000000..ade9aae --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/resource/CellTableResources.java @@ -0,0 +1,23 @@ +/** + * + */ +package org.gcube.portlets.user.geoportaldataentry.client.resource; + +import com.github.gwtbootstrap.client.ui.CellTable; +import com.github.gwtbootstrap.client.ui.CellTable.Resources; +import com.google.gwt.core.shared.GWT; + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jun 23, 2015 + */ +public interface CellTableResources extends Resources { + + public CellTableResources INSTANCE = GWT.create(CellTableResources.class); + + // The styles used in this widget. + @Override + @Source("CellTable.css") + CellTable.Style cellTableStyle(); +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainPanel.java index 77790f5..c3b1db6 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainPanel.java @@ -1,5 +1,6 @@ package org.gcube.portlets.user.geoportaldataentry.client.ui; +import org.gcube.portlets.user.geoportaldataentry.client.ui.form.GeonaDataEntryMainForm; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; import com.google.gwt.core.client.GWT; @@ -10,7 +11,6 @@ import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Widget; -// TODO: Auto-generated Javadoc /** * The Class GeonaMainPanel. * diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaNavigationBar.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaNavigationBar.java index 86d3ab3..53b2b01 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaNavigationBar.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaNavigationBar.java @@ -1,15 +1,17 @@ package org.gcube.portlets.user.geoportaldataentry.client.ui; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.events.CreateNewProjectEvent; +import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecordsEvent; import com.github.gwtbootstrap.client.ui.NavLink; 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.event.shared.EventBus; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; -import com.google.gwt.uibinder.client.UiHandler; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Widget; @@ -24,28 +26,42 @@ public class GeonaNavigationBar extends Composite { public GeonaNavigationBar() { initWidget(uiBinder.createAndBindUi(this)); + bindEvents(); } private void bindEvents() { - // TODO Auto-generated method stub + linkCreateNewProject.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + appManagerBus.fireEvent(new CreateNewProjectEvent()); + + } + }); + + linkGetListOfRecords.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE)); + + } + }); } @UiField NavLink linkCreateNewProject; + @UiField + NavLink linkGetListOfRecords; + private HandlerManager appManagerBus; public GeonaNavigationBar(String firstName) { initWidget(uiBinder.createAndBindUi(this)); } - @UiHandler("linkCreateNewProject") - void onClick(ClickEvent e) { - appManagerBus.fireEvent(new CreateNewProjectEvent()); - } - - /** * Sets the app manager bus. * diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaNavigationBar.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaNavigationBar.ui.xml index 8d8abea..6a54199 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaNavigationBar.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaNavigationBar.ui.xml @@ -12,6 +12,8 @@ Create new Project + Get List of Concessioni diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java new file mode 100644 index 0000000..010307d --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java @@ -0,0 +1,310 @@ +package org.gcube.portlets.user.geoportaldataentry.client.ui; + +import java.util.List; + +import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; +import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp; +import org.gcube.portlets.user.geoportaldataentry.client.ui.table.ItemsTable; +import org.gcube.portlets.user.geoportaldataentry.client.ui.table.ItemsTable.DISPLAY_FIELD; +import org.gcube.portlets.user.geoportaldataentry.client.ui.table.SortedCellTable; +import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; +import org.gcube.portlets.user.geoportaldataentry.shared.SearchedData; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.user.cellview.client.SimplePager; +import com.google.gwt.user.cellview.client.SimplePager.TextLocation; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; +import com.google.gwt.view.client.AsyncDataProvider; +import com.google.gwt.view.client.HasData; +import com.google.gwt.view.client.MultiSelectionModel; +import com.google.gwt.view.client.Range; +import com.google.gwt.view.client.SelectionModel; +import com.google.gwt.view.client.SingleSelectionModel; + + +/** + * The Class GeonaRecordsPaginatedView. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Aug 4, 2021 + */ +public class GeonaRecordsPaginatedView { + + private static final int ITEM_START_INDEX = 0; + private static final int ITEMS_PER_PAGE = 30; + private VerticalPanel vPanel = new VerticalPanel(); + private FlowPanel pagerPanel = new FlowPanel(); + private Boolean initClassFirstRangeChanged = false; + private ItemsTable itemsTable; + private MyCustomDataProvider dataProvider = new MyCustomDataProvider(); + protected Widget orginalLoadingIndicator = null; + private LoaderIcon loadingPanel = new LoaderIcon("Loading data..."); + private int serverStartIndex; + private HandlerManager eventBus; + private RECORD_TYPE recordType; + + + /** + * Instantiates a new geona records paginated view. + * + * @param eventbus the eventbus + * @param recordType the record type + * @param displayFields the display fields + * @param sortByField the sort by field + */ + public GeonaRecordsPaginatedView(HandlerManager eventbus, RECORD_TYPE recordType, DISPLAY_FIELD[] displayFields, + DISPLAY_FIELD sortByField) { + this.recordType = recordType; + this.initClassFirstRangeChanged = true; + this.eventBus = eventbus; + itemsTable = new ItemsTable(eventbus, displayFields, sortByField); + itemsTable.initTable(null, null, dataProvider); + + orginalLoadingIndicator = itemsTable.getCellTable().getLoadingIndicator(); + initPagination(ITEMS_PER_PAGE); + // loadNewPage(ITEM_START_INDEX, ITEMS_PER_PAGE, false); + loadItemsForStatus(recordType); + } + + /** + * Gets the asycn data provider. + * + * @return the asycn data provider + */ + public AsyncDataProvider getAsycnDataProvider() { + return (AsyncDataProvider) getCellTable().getDataProvider(); + } + + /** + * Gets the cell tale. + * + * @return the cell tale + */ + private SortedCellTable getCellTable() { + return itemsTable.getCellTable(); + } + + /** + * Inits the pagination. + * + * @param itemsPerPage the items per page + */ + public void initPagination(int itemsPerPage) { + + SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class); + SimplePager pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true); + pager.setDisplay(getCellTable()); + pager.setPageSize(itemsPerPage); + pager.getElement().getStyle().setProperty("margin", "auto"); + vPanel.add(loadingPanel); + vPanel.add(getCellTable()); + vPanel.getElement().addClassName("vPanel"); + pagerPanel.add(pager); + } + + /** + * Gets the pager panel. + * + * @return the pager panel + */ + public VerticalPanel getCellPanel() { + return vPanel; + } + + /** + * Set the panel in loading mode. + * + * @param show the show + */ + protected void showLoading(boolean show) { + loadingPanel.setVisible(show); + } + + /** + * Gets the pager panel. + * + * @return the pager panel + */ + public FlowPanel getPagerPanel() { + return pagerPanel; + } + + /** + * Load new page. + * + * @param startIdx the start idx + * @param limit the limit + * @param resetStore the reset store + */ + private void loadNewPage(final int startIdx, final int limit, final boolean resetStore) { + // initFirstRangeChanged = resetStore; + GWT.log("loadNewPage with parameters [startIdx: " + startIdx + ", limit: " + limit + ", resetStore:" + + resetStore + "]"); + // showLoading(true); + + int newStartIndex = startIdx; + + if (resetStore) { + GWT.log("Cleaning all data..."); + newStartIndex = 0; + serverStartIndex = 0; + GWT.log("Store reset performed start index is: " + newStartIndex); + getAsycnDataProvider().updateRowCount(ITEMS_PER_PAGE, false); + } + + loadItemsForStatus(newStartIndex, limit, serverStartIndex); + + } + + /** + * Load items for status. + * + * @param recordType the record type + */ + public void loadItemsForStatus(RECORD_TYPE recordType) { + this.recordType = recordType; + getCellTable().setVisibleRangeAndClearData(new Range(ITEM_START_INDEX, ITEMS_PER_PAGE), false); + loadNewPage(ITEM_START_INDEX, ITEMS_PER_PAGE, true); + } + + /** + * Sets the new page result. + * + * @param result the new new page result + */ + private void setNewPageResult(SearchedData result) { + GWT.log("setNewPageResult: " + result); + serverStartIndex = result.getServerEndIndex(); + SelectionModel sm = getCellTable().getSelectionModel(); + + if (sm instanceof SingleSelectionModel) { + SingleSelectionModel ssm = (SingleSelectionModel) sm; + ssm.clear(); + } else if (sm instanceof MultiSelectionModel) { + MultiSelectionModel msm = (MultiSelectionModel) sm; + msm.clear(); + } + + getAsycnDataProvider().updateRowCount((int) result.getTotalItems(), true); + getAsycnDataProvider().updateRowData(result.getClientStartIndex(), result.getData()); + + if (result.getData().size() == 0) { + getCellTable().setLoadingIndicator(new Label("No data")); + } else { + getCellTable().setLoadingIndicator(orginalLoadingIndicator); + } + + GWT.log("Updating row data startIndex: " + result.getClientStartIndex() + " children size: " + + result.getData().size()); + GWT.log("getAsycnDataProvider().getDataDisplays().size(): " + getCellTable().getRowCount()); + + if (result.isServerSearchFinished()) { + GWT.log("Search finished!!!"); + getAsycnDataProvider().updateRowCount(getCellTable().getRowCount(), true); + } + // initFirstRangeChanged = false; + + } + + /** + * Load items for status. + * + * @param the generic type + * @param offset the offset + * @param limit the limit + * @param serverIndex the server index + */ + private void loadItemsForStatus(int newStartIndex, int limit, int serverIndex) { + showLoading(true); + + GWT.log("calling getDataForStatus with parameters [startIndex: " + newStartIndex + ", limit: " + limit + + ", serverIndex:" + serverIndex + "]"); + + GeoPortalDataEntryApp.greetingService.getListConcessioni(newStartIndex, limit, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + showLoading(false); + + } + + @Override + public void onSuccess(SearchedData result) { + showLoading(false); + setNewPageResult(result); + + } + }); + + } + + /** + * Select items. + * + * @param select the select + * @param limitToPage the limit to page + */ + public void selectItems(boolean select, boolean limitToPage) { + SortedCellTable table = getCellTable(); + int rowSize = table.getVisibleItemCount(); + + for (int i = 0; i < rowSize; i++) { + ConcessioneDV item = table.getVisibleItem(i); + itemsTable.getSelectionModel().setSelected(item, select); + } + } + + /** + * Gets the select items. + * + * @return the select items + */ + public List getSelectItems() { + return itemsTable.getSelectedItems(); + } + + /** + * A custom {@link AsyncDataProvider}. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jul 5, 2017 + * @param the generic type + */ + public class MyCustomDataProvider extends AsyncDataProvider { + + /** + * {@link #onRangeChanged(HasData)} is called when the table requests a new + * range of data. You can push data back to the displays using + * {@link #updateRowData(int, List)}. + * + * @param display the display + */ + @Override + public void onRangeChanged(HasData display) { + + // Get the new range. + final Range range = display.getVisibleRange(); + + int start = range.getStart(); + int length = range.getLength(); + + if (initClassFirstRangeChanged) { + GWT.log("initClassFirstRangeChanged is true.. returning"); + initClassFirstRangeChanged = false; + return; + } + GWT.log("Range changed: " + start + " " + length + " visible count: " + display.getVisibleItemCount()); + loadNewPage(start, length, false); + //eventBus.fireEvent(new TableRangeViewChangedEvent(start, length)); + + } + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaDataEntryMainForm.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/form/GeonaDataEntryMainForm.java similarity index 98% rename from src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaDataEntryMainForm.java rename to src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/form/GeonaDataEntryMainForm.java index 43427af..033575d 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaDataEntryMainForm.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/form/GeonaDataEntryMainForm.java @@ -1,4 +1,4 @@ -package org.gcube.portlets.user.geoportaldataentry.client.ui; +package org.gcube.portlets.user.geoportaldataentry.client.ui.form; import java.util.ArrayList; import java.util.LinkedHashMap; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaDataEntryMainForm.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/form/GeonaDataEntryMainForm.ui.xml similarity index 100% rename from src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaDataEntryMainForm.ui.xml rename to src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/form/GeonaDataEntryMainForm.ui.xml diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/AbstractItemsCellTable.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/AbstractItemsCellTable.java new file mode 100644 index 0000000..37d50b5 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/AbstractItemsCellTable.java @@ -0,0 +1,204 @@ +package org.gcube.portlets.user.geoportaldataentry.client.ui.table; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +import org.gcube.portlets.user.geoportaldataentry.client.events.ClickItemEvent; + +import com.github.gwtbootstrap.client.ui.Pagination; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.core.shared.GWT; +import com.google.gwt.dom.client.Style.BorderStyle; +import com.google.gwt.event.dom.client.ContextMenuEvent; +import com.google.gwt.event.dom.client.ContextMenuHandler; +import com.google.gwt.event.dom.client.DoubleClickEvent; +import com.google.gwt.event.dom.client.DoubleClickHandler; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.user.cellview.client.SimplePager; +import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.ui.DialogBox; +import com.google.gwt.user.client.ui.MenuBar; +import com.google.gwt.user.client.ui.MenuItem; +import com.google.gwt.view.client.AbstractDataProvider; +import com.google.gwt.view.client.AsyncDataProvider; +import com.google.gwt.view.client.DefaultSelectionEventManager; +import com.google.gwt.view.client.ListDataProvider; +import com.google.gwt.view.client.MultiSelectionModel; +import com.google.gwt.view.client.SelectionChangeEvent; +import com.google.gwt.view.client.SelectionChangeEvent.Handler; +import com.google.gwt.view.client.SelectionModel; +import com.google.gwt.view.client.SingleSelectionModel; + + +/** + * The Class AbstractItemsCellTable. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jul 11, 2017 + * @param the generic type + */ +public abstract class AbstractItemsCellTable { + + protected SortedCellTable sortedCellTable; + protected T itemContextMenu = null; + protected boolean fireEventOnClick = true; + protected SelectionModel theSelectionModel; + protected HandlerManager eventBus; + + /** + * Inits the table. + * + * @param pager the pager + * @param pagination the pagination + * @param dataProvider the data provider + */ + public abstract void initTable(final SimplePager pager, final Pagination pagination, + AbstractDataProvider dataProvider); + + /** + * Inits the abstract table. + * + * @param eventBus the event bus + * @param fireOnClick the fire on click + * @param dataProvider the data provider + * @param selectionModel the selection model + * @param pageSize the page size + */ + protected void initAbstractTable(HandlerManager eventBus, boolean fireOnClick, AbstractDataProvider dataProvider, + SelectionModel selectionModel, int pageSize) { + this.eventBus = eventBus; + this.fireEventOnClick = fireOnClick; + this.theSelectionModel = selectionModel; + sortedCellTable = new SortedCellTable(pageSize, dataProvider); +// sortedCellTable.addStyleName("table-cms-widget"); +// sortedCellTable.addStyleName("table-cms-widget-vertical-middle"); + sortedCellTable.setStriped(true); + sortedCellTable.setCondensed(true); + sortedCellTable.setWidth("100%", true); +// dataProvider.addDataDisplay(sortedCellTable); +// initTable(cellTable, null, null); + //sortedCellTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); + + DefaultSelectionEventManager checkBoxManager = DefaultSelectionEventManager. createCheckboxManager(); + sortedCellTable.setSelectionModel(theSelectionModel,checkBoxManager); + + theSelectionModel.addSelectionChangeHandler(new Handler() { + @Override + public void onSelectionChange(final SelectionChangeEvent event) { + + if (theSelectionModel instanceof SingleSelectionModel) { + SingleSelectionModel ssm = (SingleSelectionModel) theSelectionModel; + final T selectedObject = ssm.getSelectedObject(); + if (selectedObject != null) { + GWT.log("Clicked: " + selectedObject); +// selectedItem(selectedObject); + if (fireEventOnClick) + AbstractItemsCellTable.this.eventBus.fireEvent(new ClickItemEvent(Arrays.asList(selectedObject))); + } + }else if (theSelectionModel instanceof MultiSelectionModel) { + Set selected = ((MultiSelectionModel) theSelectionModel).getSelectedSet(); + GWT.log("Selected are:" +selected); + if (fireEventOnClick) + AbstractItemsCellTable.this.eventBus.fireEvent(new ClickItemEvent(new ArrayList(selected))); + } + } + }); + + sortedCellTable.addDomHandler(new DoubleClickHandler() { + + @Override + public void onDoubleClick(final DoubleClickEvent event) { + if (theSelectionModel instanceof SingleSelectionModel) { + SingleSelectionModel ssm = (SingleSelectionModel) theSelectionModel; + T selected = ssm.getSelectedObject(); + if (selected != null) { + GWT.log("Double Click: " + selected); + // AbstractItemsCellTable.this.eventBus.fireEvent(new + // org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent(selected)); + } + } + + } + }, DoubleClickEvent.getType()); + + MenuBar options = new MenuBar(true); + ScheduledCommand openCommand = new ScheduledCommand() { + + @Override + public void execute() { + GWT.log("Context menu shown: " + itemContextMenu); + // AbstractItemsCellTable.this.eventBus.fireEvent(new + // org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent(itemContextMenu)); + } + }; + + MenuItem openItem = new MenuItem("Open", openCommand); + options.addItem(openItem); + final DialogBox menuWrapper = new DialogBox(true); + menuWrapper.getElement().getStyle().setBorderStyle(BorderStyle.NONE); + menuWrapper.getElement().getStyle().setZIndex(10000); + menuWrapper.add(options); + sortedCellTable.sinkEvents(Event.ONCONTEXTMENU); + + sortedCellTable.addHandler(new ContextMenuHandler() { + @Override + public void onContextMenu(ContextMenuEvent event) { + } + }, ContextMenuEvent.getType()); + + } + + /** + * Gets the cell tables. + * + * @return the cell tables + */ + public SortedCellTable getCellTable() { + return sortedCellTable; + } + + /** + * Checks if is fire event on click. + * + * @return the fireEventOnClick + */ + public boolean isFireEventOnClick() { + + return fireEventOnClick; + } + + /** + * Sets the fire event on click. + * + * @param fireEventOnClick the fireEventOnClick to set + */ + public void setFireEventOnClick(boolean fireEventOnClick) { + + this.fireEventOnClick = fireEventOnClick; + } + + /** + * Adds the items. + * + * @param items the items + */ + public void addItems(List items) { + + AbstractDataProvider dataProvider = sortedCellTable.getDataProvider(); + + if (dataProvider instanceof ListDataProvider) { + List ldp = ((ListDataProvider) dataProvider).getList(); + for (int i = 0; i < items.size(); i++) { + ldp.add(i, items.get(i)); + } + + sortedCellTable.setPageSize(items.size() + 1); + sortedCellTable.redraw(); + } else if (dataProvider instanceof AsyncDataProvider) { + + // TODO ??? + + } + } +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java new file mode 100644 index 0000000..4b8f96c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java @@ -0,0 +1,516 @@ +/** + * + */ +package org.gcube.portlets.user.geoportaldataentry.client.ui.table; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import org.gcube.application.geoportalcommon.ConvertToDataViewModel; +import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; +import org.gcube.portlets.user.geoportaldataentry.client.events.ShowItemEvent; + +import com.github.gwtbootstrap.client.ui.Pagination; +import com.google.gwt.cell.client.ButtonCell; +import com.google.gwt.cell.client.DateCell; +import com.google.gwt.cell.client.FieldUpdater; +import com.google.gwt.core.shared.GWT; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.safehtml.shared.SafeHtml; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.google.gwt.safehtml.shared.SafeHtmlUtils; +import com.google.gwt.user.cellview.client.Column; +import com.google.gwt.user.cellview.client.ColumnSortEvent; +import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo; +import com.google.gwt.user.cellview.client.SimplePager; +import com.google.gwt.user.cellview.client.TextColumn; +import com.google.gwt.user.client.ui.Image; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.view.client.AbstractDataProvider; +import com.google.gwt.view.client.ListDataProvider; +import com.google.gwt.view.client.MultiSelectionModel; +import com.google.gwt.view.client.SelectionModel; +import com.google.gwt.view.client.SingleSelectionModel; + +/** + * The Class ItemsTable. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 15, 2021 + * @param the generic type + */ +public class ItemsTable extends AbstractItemsCellTable { + + private static final int ITEMS_PER_PAGE = 10; + private static final String NO_DATA = "No data"; + private TextColumn name; + private TextColumn introduction; + private TextColumn author; + public static DateTimeFormat dtformat = DateTimeFormat.getFormat(ConvertToDataViewModel.DATE_FORMAT); + + private AbstractDataProvider dataProvider; + + /** + * The Enum DISPLAY_FIELD. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 1, 2016 + */ + public static enum DISPLAY_FIELD { + NAME, INTRO, AUTHOR, PROJECT_START_DATE, PROJECT_END_DATE + }; + + private List displayFields; + private Column startProjectDateColumn; + private Column endProjectDateColumn; + private DISPLAY_FIELD startSortByColumn; + private boolean isAsyncronusTable; + + /** + * Instantiates a new items table. + * + * @param eventBus the event bus + * @param fields the fields + * @param startSortByColumn the start sort by column + */ + public ItemsTable(HandlerManager eventBus, DISPLAY_FIELD[] fields, DISPLAY_FIELD startSortByColumn) { + this.eventBus = eventBus; + this.startSortByColumn = startSortByColumn; + setDisplayFields(fields); + } + + /** + * Adds the items. + * + * @param items the items + */ + public void addItems(List items) { + super.addItems(items); + } + + /** + * Inits the table. + * + * @param pager the pager + * @param pagination the pagination + * @param dataProvider the data provider + */ + @Override + public void initTable(final SimplePager pager, final Pagination pagination, AbstractDataProvider dataProvider) { + this.dataProvider = dataProvider; + this.theSelectionModel = new SingleSelectionModel(); + initAbstractTable(eventBus, fireEventOnClick, dataProvider, theSelectionModel, ITEMS_PER_PAGE); + this.dataProvider.addDataDisplay(sortedCellTable); + + this.isAsyncronusTable = dataProvider instanceof ListDataProvider ? false : true; + setEmptyTableMessage(NO_DATA); + +// final CheckboxCell cellCheckBox = new CheckboxCell(true, false); +// Column checkColumn = new Column(cellCheckBox) { +// @Override +// public Boolean getValue(T object) { +// // Get the value from the selection model. +// return theSelectionModel.isSelected(object); +// } +// +// @Override +// public void render(Context context, T object, SafeHtmlBuilder sb) { +// super.render(context, object, sb); +// GWT.log("added checkbox: " + cellCheckBox + " to object: " + object); +// } +// +// }; +// +// sortedCellTable.addColumn(checkColumn, "", false); +// sortedCellTable.setColumnWidth(checkColumn, 40, Unit.PX); + + ButtonCell previewButton = new ButtonCell(); + Column showdItemColumn = new Column(previewButton) { + public String getValue(T object) { + return "Show"; + } + }; + + showdItemColumn.setFieldUpdater(new FieldUpdater() { + @Override + public void update(int index, T object, String value) { + GWT.log("clicked show"); + eventBus.fireEvent(new ShowItemEvent(Arrays.asList(object))); + } + }); + sortedCellTable.addColumn(showdItemColumn); + sortedCellTable.setColumnWidth(showdItemColumn, 80, Unit.PX); + + if (this.displayFields.contains(DISPLAY_FIELD.NAME)) { + + // NAME + name = new TextColumn() { + @Override + public String getValue(T object) { + if (object == null) + return ""; + return ((ConcessioneDV) object).getNome(); + } + + // ADDING TOOLTIP + @Override + public void render(com.google.gwt.cell.client.Cell.Context context, T object, SafeHtmlBuilder sb) { + if (object == null) + return; + sb.appendHtmlConstant("
"); + super.render(context, object, sb); + sb.appendHtmlConstant("
"); + }; + }; + + sortedCellTable.addColumn(name, "Name", true); + + if (!isAsyncronusTable) { + Comparator c = new Comparator() { + @Override + public int compare(T o1, T o2) { + return ((ConcessioneDV) o1).getNome().compareTo(((ConcessioneDV) o2).getNome()); + } + }; + + sortedCellTable.setComparator(name, c); + } + + } + + if (this.displayFields.contains(DISPLAY_FIELD.INTRO)) { + + introduction = new TextColumn() { + @Override + public String getValue(T object) { + if (object == null) + return ""; + return ((ConcessioneDV) object).getIntroduzione() != null + ? ((ConcessioneDV) object).getIntroduzione() + : ""; + } + }; + + sortedCellTable.addColumn(introduction, "Intro", true); + + if (!isAsyncronusTable) { + Comparator c = new Comparator() { + @Override + public int compare(T o1, T o2) { + return ((ConcessioneDV) o1).getIntroduzione().compareTo(((ConcessioneDV) o2).getIntroduzione()); + } + }; + sortedCellTable.setComparator(introduction, c); + } + + } + + if (this.displayFields.contains(DISPLAY_FIELD.AUTHOR)) { + + author = new TextColumn() { + @Override + public String getValue(T object) { + if (object == null) + return ""; + + String toDisplay = toDisplayAuthors(((ConcessioneDV) object).getAuthors()); + return toDisplay; + } + }; + + sortedCellTable.addColumn(author, "Author/s", true); + + if (!isAsyncronusTable) { + Comparator c = new Comparator() { + @Override + public int compare(T o1, T o2) { + String toDisplay1 = toDisplayAuthors(((ConcessioneDV) o1).getAuthors()); + String toDisplay2 = toDisplayAuthors(((ConcessioneDV) o2).getAuthors()); + return toDisplay1.compareTo(toDisplay2); + } + }; + sortedCellTable.setComparator(author, c); + } + + } + + if (this.displayFields.contains(DISPLAY_FIELD.PROJECT_START_DATE)) { + + DateCell date = new DateCell(dtformat); + startProjectDateColumn = new Column(date) { + + @Override + public Date getValue(T object) { + if (object == null) + return null; + + return (((ConcessioneDV) object).getDataInizioProgetto()); + } + }; + sortedCellTable.addColumn(startProjectDateColumn, "Project Start Date", true); + + if (!isAsyncronusTable) { + Comparator c = new Comparator() { + @Override + public int compare(T o1, T o2) { + if (o1 == null) + return -1; + + if (o2 == null) + return 1; + + Date d1 = (((ConcessioneDV) o1).getDataInizioProgetto()); + Date d2 = (((ConcessioneDV) o2).getDataInizioProgetto()); + + // GWT.log(d1.toString() + "is after "+d2.toString() +" ? "+d2.after(d1)); + + if (d1.after(d2)) + return 1; + else + return -1; + } + }; + GWT.log("date colum sortable"); + sortedCellTable.setComparator(startProjectDateColumn, c); + } + + } + + if (this.displayFields.contains(DISPLAY_FIELD.PROJECT_END_DATE)) { + + DateCell date = new DateCell(dtformat); + endProjectDateColumn = new Column(date) { + + @Override + public Date getValue(T object) { + if (object == null) + return null; + + return (((ConcessioneDV) object).getDataFineProgetto()); + } + }; + sortedCellTable.addColumn(startProjectDateColumn, "Project End Date", true); + + if (!isAsyncronusTable) { + Comparator c = new Comparator() { + @Override + public int compare(T o1, T o2) { + if (o1 == null) + return -1; + + if (o2 == null) + return 1; + + Date d1 = (((ConcessioneDV) o1).getDataFineProgetto()); + Date d2 = (((ConcessioneDV) o2).getDataFineProgetto()); + + // GWT.log(d1.toString() + "is after "+d2.toString() +" ? "+d2.after(d1)); + + if (d1.after(d2)) + return 1; + else + return -1; + } + }; + GWT.log("date colum sortable"); + sortedCellTable.setComparator(endProjectDateColumn, c); + } + + } + + GWT.log("startSortByColumn: " + startSortByColumn); + + if (startSortByColumn != null) + switch (startSortByColumn) { + case NAME: + if (this.displayFields.contains(DISPLAY_FIELD.NAME)) { + sortedCellTable.setInitialSortColumn(name); + } + break; + case INTRO: + if (this.displayFields.contains(DISPLAY_FIELD.INTRO)) { + sortedCellTable.setInitialSortColumn(introduction); + } + break; + case AUTHOR: + if (this.displayFields.contains(DISPLAY_FIELD.AUTHOR)) { + sortedCellTable.setInitialSortColumn(author); + } + break; + case PROJECT_START_DATE: + if (this.displayFields.contains(DISPLAY_FIELD.PROJECT_START_DATE)) { + sortedCellTable.setDefaultSortOrder(startProjectDateColumn, false); // sorts ascending on first + // click + sortedCellTable.setInitialSortColumn(startProjectDateColumn); + GWT.log("sortedCellTable: " + sortedCellTable); + } + break; + case PROJECT_END_DATE: + if (this.displayFields.contains(DISPLAY_FIELD.PROJECT_START_DATE)) { + sortedCellTable.setDefaultSortOrder(endProjectDateColumn, false); // sorts ascending on first click + sortedCellTable.setInitialSortColumn(endProjectDateColumn); + GWT.log("sortedCellTable: " + sortedCellTable); + } + break; + default: + break; + } + + } + +// /** +// * To date format string. +// * +// * @param dateTime the date time +// * @return the string +// */ +// public static Date toDisplayDate(Date dateTime) { +// +// if(dateTime==null) +// return null; +// +// return new Date(dtformat.format(dateTime)); +// } + + private String toDisplayAuthors(List authors) { + String toDisplay = ""; + if (authors == null) + return toDisplay; + + for (String author : authors) { + toDisplay += author + "; "; + } + return toDisplay; + } + + /** + * Displays the appropriate sorted icon in the header of the column for the + * given index. + * + * @param columnIndex of the column to mark as sorted + * @param ascending true for ascending icon, false + * for descending icon + */ + public void setSortedColumn(int columnIndex, boolean ascending) { + GWT.log("Column index: " + columnIndex); + GWT.log("ascending: " + ascending); + Column column = sortedCellTable.getColumn(columnIndex); + if (column != null && column.isSortable()) { + ColumnSortInfo info = sortedCellTable.getColumnSortList().push(column); +// ColumnSortEvent.fire(cellTable, cellTable.getColumnSortList()); + GWT.log("info.isAscending(): " + info.isAscending()); + if (info.isAscending() != ascending) { + sortedCellTable.getColumnSortList().push(column); + ColumnSortEvent.fire(sortedCellTable, sortedCellTable.getColumnSortList()); + } + } + } + + /** + * Sets the display fields. + * + * @param fields the new display fields + */ + public void setDisplayFields(DISPLAY_FIELD[] fields) { + this.displayFields = fields != null && fields.length > 0 ? Arrays.asList(fields) + : Arrays.asList(DISPLAY_FIELD.values()); + } + + /** + * Reset columns table. + */ + public void reInitColumnsTable() { + int count = sortedCellTable.getColumnCount(); + for (int i = 0; i < count; i++) { + sortedCellTable.removeColumn(0); + } + initTable(null, null, dataProvider); + } + + /** + * Gets the display fields. + * + * @return the displayFields + */ + public List getDisplayFields() { + return displayFields; + } + + /** + * The Class ButtonImageCell. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 1, 2016 + */ + public class ButtonImageCell extends ButtonCell { + + /** + * Render. + * + * @param context the context + * @param value the value + * @param sb the sb + */ + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.cell.client.AbstractSafeHtmlCell#render(com.google.gwt.cell. + * client.Cell.Context, java.lang.Object, + * com.google.gwt.safehtml.shared.SafeHtmlBuilder) + */ + @Override + public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) { + SafeHtml html = SafeHtmlUtils.fromTrustedString(new Image(value).toString()); + sb.append(html); + } + } + + /** + * Gets the selected item. + * + * @return the selected item + */ + public List getSelectedItems() { + if (theSelectionModel instanceof SingleSelectionModel) { + T selected = ((SingleSelectionModel) theSelectionModel).getSelectedObject(); + if (selected != null) { + return Arrays.asList(selected); + } + + } else if (theSelectionModel instanceof MultiSelectionModel) { + Set selected = ((MultiSelectionModel) theSelectionModel).getSelectedSet(); + if (selected != null) { + return new ArrayList(selected); + } + } + + return null; + } + + /** + * Sets the empty table message. + * + * @param msg the new empty table message + */ + public void setEmptyTableMessage(String msg) { + msg = msg != null ? msg : NO_DATA; + if (sortedCellTable != null) + sortedCellTable.setEmptyTableWidget(new Label(msg)); + } + + /** + * Gets the selection model. + * + * @return the selection model + */ + public SelectionModel getSelectionModel() { + return theSelectionModel; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/MyToolTipColumn.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/MyToolTipColumn.java new file mode 100644 index 0000000..1de211f --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/MyToolTipColumn.java @@ -0,0 +1,83 @@ +/** + * + */ + +package org.gcube.portlets.user.geoportaldataentry.client.ui.table; + +import com.google.gwt.cell.client.Cell; +import com.google.gwt.cell.client.Cell.Context; +import com.google.gwt.core.client.GWT; +import com.google.gwt.safehtml.client.SafeHtmlTemplates; +import com.google.gwt.safehtml.shared.SafeHtml; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.google.gwt.user.cellview.client.Column; + + +/** + * The Class MyToolTipColumn. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 15, 2021 + * @param the generic type + * @param the generic type + */ +public abstract class MyToolTipColumn extends Column { + + /** + * The Interface Templates. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 15, 2021 + */ + interface Templates extends SafeHtmlTemplates { + + /** + * Start tool tip. + * + * @param toolTipText the tool tip text + * @return the safe html + */ + @Template("
") + SafeHtml startToolTip(String toolTipText); + + /** + * End tool tip. + * + * @return the safe html + */ + @Template("
") + SafeHtml endToolTip(); + } + + private static final Templates TEMPLATES = GWT.create(Templates.class); + private final String toolTipText; + + /** + * Instantiates a new my tool tip column. + * + * @param cell the cell + * @param toolTipText the tool tip text + */ + public MyToolTipColumn(final Cell cell, final String toolTipText) { + + super(cell); + this.toolTipText = toolTipText; + } + + /** + * Render. + * + * @param context the context + * @param object the object + * @param sb the sb + */ + @Override + public void render(final Context context, final T object, final SafeHtmlBuilder sb) { + + sb.append(TEMPLATES.startToolTip(toolTipText)); + super.render(context, object, sb); + sb.append(TEMPLATES.endToolTip()); + } +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/SortedCellTable.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/SortedCellTable.java new file mode 100644 index 0000000..66f82d1 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/SortedCellTable.java @@ -0,0 +1,302 @@ +/** + * + */ + +package org.gcube.portlets.user.geoportaldataentry.client.ui.table; + +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.gcube.portlets.user.geoportaldataentry.client.resource.CellTableResources; + +import com.github.gwtbootstrap.client.ui.CellTable; +import com.google.gwt.user.cellview.client.Column; +import com.google.gwt.user.cellview.client.ColumnSortEvent; +import com.google.gwt.user.cellview.client.ColumnSortEvent.AsyncHandler; +import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler; +import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo; +import com.google.gwt.user.cellview.client.Header; +import com.google.gwt.view.client.AbstractDataProvider; +import com.google.gwt.view.client.AsyncDataProvider; +import com.google.gwt.view.client.ListDataProvider; + +/** + * The Class SortedCellTable. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 15, 2021 + * @param the generic type + */ +public class SortedCellTable extends CellTable { + + /** + * To keep track of the currently sorted column + */ + private Column currentlySortedColumn; + /** + * Tells us which way to sort a column initially + */ + private Map, Boolean> defaultSortOrderMap = new HashMap, Boolean>(); + /** + * Comparators associated with their columns + */ + private Map, Comparator> comparators = new HashMap, Comparator>(); + /** + * Column to sort when the data provider's list is refreshed using + * {@link SortedCellTable#setList(List)} + */ + private Column initialSortColumn; + /** + * Data provider we will attach to this table + */ + private AbstractDataProvider dataProvider; + + /** + * Special column sorting handler that will allow us to do more controlled + * sorting + */ + private ColumnSortEvent.Handler columnSortHandler; + + /** + * Instantiates a new sorted cell table. + * + * @param pageSize the page size + * @param dataProv the data prov + */ + public SortedCellTable(int pageSize, AbstractDataProvider dataProv) { + super(pageSize, CellTableResources.INSTANCE); + this.dataProvider = dataProv; + + if (this.dataProvider instanceof ListDataProvider) { + ListDataProvider listDataProvider = (ListDataProvider) this.dataProvider; + ListHandler listSortHandler = new ListHandler((listDataProvider).getList()) { + + @Override + public void onColumnSort(ColumnSortEvent event) { + + @SuppressWarnings("unchecked") + Column column = (Column) event.getColumn(); + if (column == null) { + return; + } + if (column.equals(currentlySortedColumn)) { + // Default behavior + super.onColumnSort(event); + } else { + // Initial sort; look up which direction we need + final Comparator comparator = comparators.get(column); + if (comparator == null) { + return; + } + Boolean ascending = defaultSortOrderMap.get(column); + if (ascending == null || ascending) { + // Default behavior + super.onColumnSort(event); + } else { + // Sort the column descending + Collections.sort(getList(), new Comparator() { + + public int compare(T o1, T o2) { + + return -comparator.compare(o1, o2); + } + }); + // Set the proper arrow in the header + getColumnSortList().push(new ColumnSortInfo(column, false)); + } + currentlySortedColumn = column; + } + } + + @Override + public void setComparator(Column column, Comparator comparator) { + + comparators.put(column, comparator); + super.setComparator(column, comparator); + } + }; + addColumnSortHandler(listSortHandler); + columnSortHandler = listSortHandler; + } else if (this.dataProvider instanceof AsyncDataProvider) { + //AsyncDataProvider asyncDataProvider = ((AsyncDataProvider) this.dataProvider); + //asyncDataProvider.get + AsyncHandler asyncSortHandler = new AsyncHandler(this) { + @Override + public void onColumnSort(ColumnSortEvent event) { + + @SuppressWarnings("unchecked") + Column column = (Column) event.getColumn(); + if (column == null) { + return; + } + if (column.equals(currentlySortedColumn)) { + // Default behavior + super.onColumnSort(event); + } else { + // Initial sort; look up which direction we need + final Comparator comparator = comparators.get(column); + if (comparator == null) { + return; + } + Boolean ascending = defaultSortOrderMap.get(column); + if (ascending == null || ascending) { + // Default behavior + super.onColumnSort(event); + } else { + // Sort the column descending + Collections.sort(getVisibleItems(), new Comparator() { + + public int compare(T o1, T o2) { + + return -comparator.compare(o1, o2); + } + }); + // Set the proper arrow in the header + getColumnSortList().push(new ColumnSortInfo(column, false)); + } + currentlySortedColumn = column; + } + } + }; + +// addColumnSortHandler(asyncSortHandler); +// columnSortHandler = asyncSortHandler; + } + + } + + /** + * Adds a column to the table and sets its sortable state. + * + * @param column the column + * @param headerName the header name + * @param sortable the sortable + */ + public void addColumn(Column column, String headerName, boolean sortable) { + + addColumn(column, headerName); + column.setSortable(sortable); + if (sortable) { + defaultSortOrderMap.put(column, true); + } + } + + /** + * Adds the column. + * + * @param column the column + * @param headerName the header name + */ + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.user.cellview.client.AbstractCellTable#addColumn(com.google. + * gwt.user.cellview.client.Column, java.lang.String) + */ + public void addColumn(Column column, String headerName) { + + super.addColumn(column, headerName); + } + + /** + * Adds a column to the table and sets its sortable state. + * + * @param column the column + * @param header the header + * @param sortable the sortable + */ + public void addColumn(Column column, Header header, boolean sortable) { + + addColumn(column, header); + column.setSortable(sortable); + if (sortable) { + defaultSortOrderMap.put(column, true); + } + } + + /** + * Sets the column to sort when the data list is reset using + * {@link SortedCellTable#setList(List)}. + * + * @param column the column + */ + public void setInitialSortColumn(Column column) { + + initialSortColumn = column; + } + + /** + * Set the comparator used to sort the specified column in ascending order. + * + * @param column the {@link Column} + * @param comparator the {@link Comparator} to use for the {@link Column} + */ + public void setComparator(Column column, Comparator comparator) { + comparators.put(column, comparator); + } + + /** + * Sets the sort order to use when this column is clicked and it was not + * previously sorted. + * + * @param column the column + * @param ascending the ascending + */ + public void setDefaultSortOrder(Column column, boolean ascending) { + + defaultSortOrderMap.put(column, ascending); + } + + /** + * Sets the table's data provider list and sorts the table based on the column + * given in {@link SortedCellTable#setInitialSortColumn(Column)}. + * + * @param list the new list + */ + public void setList(List list) { + + if (dataProvider instanceof ListDataProvider) { + List myData = ((ListDataProvider) dataProvider).getList(); + myData.clear(); + if (list != null) { + /* + * for (T t : list) { dataProvider.getList().add(t); } + */ + myData.addAll(list); + } + // Do a first-time sort based on which column was set in + // setInitialSortColumn() + if (initialSortColumn != null) { + Collections.sort(myData, new Comparator() { + + @Override + public int compare(T o1, T o2) { + + return (defaultSortOrderMap.get(initialSortColumn) ? 1 : -1) + * comparators.get(initialSortColumn).compare(o1, o2); + } + }); + // Might as well get the little arrow on the header to make it + // official + getColumnSortList().push(new ColumnSortInfo(initialSortColumn, defaultSortOrderMap.get(initialSortColumn))); + + currentlySortedColumn = initialSortColumn; + } + } + } + + /** + * Gets the data provider. + * + * @return the data provider + */ + public AbstractDataProvider getDataProvider() { + + return dataProvider; + } +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index 5cbd991..d5c9342 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -14,14 +14,17 @@ import org.gcube.application.geoportal.common.model.legacy.report.ValidationRepo import org.gcube.application.geoportal.common.rest.AddSectionToConcessioneRequest; import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.application.geoportal.common.rest.TempFile; +import org.gcube.application.geoportalcommon.ConvertToDataViewModel; import org.gcube.application.geoportalcommon.GeoportalCommon; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; +import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitle; import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport.STATE; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; +import org.gcube.portlets.user.geoportaldataentry.shared.SearchedData; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded; import org.gcube.vomanagement.usermanagement.model.GCubeUser; @@ -393,50 +396,83 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); GeoportalCommon gc = new GeoportalCommon(); - GeoNaItemRef item = new GeoNaItemRef(itemId, recordType); + GeoNaItemRef item = new GeoNaItemRef(itemId, recordType.toLowerCase()); item = gc.getPublicLinksFor(item); LOG.info("Returning: " + item); return item; } /** - * Gets the links for. + * Gets the list concessioni. * - * @param itemId the item id - * @param recordType the record type - * @return the links for + * @param start the start + * @param offset the offset + * @return the list concessioni * @throws Exception the exception */ - // @Override - public void getListConcessioni(Integer start, Integer offset) throws Exception { - LOG.info("getListConcessioni called"); + @Override + public SearchedData getListConcessioni(Integer start, Integer limit) throws Exception { + LOG.info("getListConcessioni called wit start: "+start + ", limit: "+limit); try { List listOfConcessioni = SessionUtil.getListOfConcessioni(getThreadLocalRequest()); - int maxOffset = listOfConcessioni.size(); + int listConcessioniSize = listOfConcessioni.size(); + List toReturn = new ArrayList(); - if(start==null && offset==null) { + int startIndex; + int limitIndex = 0; + if (start == null && limit == null) { toReturn.addAll(listOfConcessioni); - } - if(start<0) - start=0; - - if(offset>maxOffset) - offset = maxOffset; - - toReturn.subList(start, offset); - - for (Concessione concessione : toReturn) { + startIndex = 0; + limitIndex = listConcessioniSize; + }else { +// if (start < 0) +// start = 0; +// +// if (start > listConcessioniSize) +// start = listConcessioniSize; +// +// if (limit > listConcessioniSize) +// limit = listConcessioniSize; + startIndex = start; + limitIndex = start + limit; + if(limitIndex>listConcessioniSize) { + limitIndex = listConcessioniSize; + } } - // TODO - //LOG.info("Returning: " + concessioni); - }catch (Exception e) { + + SearchedData searchedData = new SearchedData(start, limit, startIndex, false); + searchedData.setTotalItems(listConcessioniSize); + + + toReturn = listOfConcessioni.subList(startIndex, limitIndex); + + List toReturnList = new ArrayList(toReturn.size()); + + for (Concessione concessione : toReturn) { + ConcessioneDV concessioneDV = ConvertToDataViewModel.toBaseConcessione(concessione); + toReturnList.add(concessioneDV); + } + + searchedData.setData(toReturnList); + + if (listConcessioniSize == limit || listConcessioniSize == 0) { + LOG.debug("Page completed returning " + listConcessioniSize + " items"); + int newOffset = startIndex + start; + searchedData.setServerSearchFinished(newOffset > listConcessioniSize || listConcessioniSize == 0); + LOG.debug("is Search finished: " + searchedData.isServerSearchFinished()); + return searchedData; + } + + LOG.debug("Returning: " + toReturnList); + LOG.info("Returning list of concessioni with size: " + toReturnList.size()); + return searchedData; + } catch (Exception e) { LOG.error("Error on loading list of concessioni: ", e); throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage()); } - } /** diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java index 97f065b..3a06bde 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java @@ -4,6 +4,7 @@ package org.gcube.portlets.user.geoportaldataentry.server; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -130,24 +131,27 @@ public class SessionUtil { public static List getListOfConcessioni(HttpServletRequest httpServletRequest) throws Exception { HttpSession session = httpServletRequest.getSession(); List listOfConcessioni = (List) session.getAttribute(LIST_OF_CONCESSIONI); - List result = new ArrayList(); - if (listOfConcessioni == null) { + listOfConcessioni = new ArrayList(); LOG.info("Loading list of concessione from client mongo"); SessionUtil.getCurrentContext(httpServletRequest, true); ServiceUtil serviceUtil = new ServiceUtil(); MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); - Iterable concessioni = clientMongo.getList(); + Iterator concessioni = clientMongo.getList(); if (concessioni != null) { - for (Concessione conc : concessioni) { - result.add(conc); + while (concessioni.hasNext()) { + Concessione concessione = (Concessione) concessioni.next(); + listOfConcessioni.add(concessione); + } } - LOG.debug("Got list of concessione from client mongo: "+result); - session.setAttribute(LIST_OF_CONCESSIONI, result); - LOG.info("Saved in session list of concessione from client mongo with size: "+result.size()); - } - LOG.info("returning list of concessioni with size: "+result.size()); - return result; + LOG.debug("Got list of concessioni from client mongo: "+listOfConcessioni); + session.setAttribute(LIST_OF_CONCESSIONI, listOfConcessioni); + LOG.info("Saved in session list of concessioni from client mongo with size: "+listOfConcessioni.size()); + }else + LOG.info("list of concessioni presents in session"); + + LOG.info("read list of concessioni with size: "+listOfConcessioni.size()); + return listOfConcessioni; } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SearchedData.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SearchedData.java new file mode 100644 index 0000000..f9bb70c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SearchedData.java @@ -0,0 +1,183 @@ +/** + * + */ +package org.gcube.portlets.user.geoportaldataentry.shared; + +import java.io.Serializable; +import java.util.List; + +import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; + + +/** + * The Class SearchedFolder. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 16, 2021 + */ +public class SearchedData implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 6800997954077785719L; + private List data; + private int clientStartIndex = 0; + private int limit; + private int serverEndIndex = 0; + private boolean isServerSearchFinished = false; + private long totalItems; + + /** + * Instantiates a new searched folder. + */ + public SearchedData() { + } + + /** + * Instantiates a new searched data. + * + * @param clientStartIndex the client start index + * @param limit the limit + * @param serverEndIndex the server end index + * @param isServerSearchFinished the is server search finished + */ + public SearchedData(int clientStartIndex, int limit, int serverEndIndex, boolean isServerSearchFinished) { + + this.clientStartIndex = clientStartIndex; + this.limit = limit; + this.serverEndIndex = serverEndIndex; + this.isServerSearchFinished = isServerSearchFinished; + } + + /** + * Gets the data. + * + * @return the data + */ + public List getData() { + return data; + } + + /** + * Gets the client start index. + * + * @return the client start index + */ + public int getClientStartIndex() { + return clientStartIndex; + } + + /** + * Gets the limit. + * + * @return the limit + */ + public int getLimit() { + return limit; + } + + /** + * Gets the server end index. + * + * @return the server end index + */ + public int getServerEndIndex() { + return serverEndIndex; + } + + /** + * Checks if is server search finished. + * + * @return true, if is server search finished + */ + public boolean isServerSearchFinished() { + return isServerSearchFinished; + } + + /** + * Sets the data. + * + * @param data the new data + */ + public void setData(List data) { + this.data = data; + } + + /** + * Sets the client start index. + * + * @param clientStartIndex the new client start index + */ + public void setClientStartIndex(int clientStartIndex) { + this.clientStartIndex = clientStartIndex; + } + + /** + * Sets the limit. + * + * @param limit the new limit + */ + public void setLimit(int limit) { + this.limit = limit; + } + + /** + * Sets the server end index. + * + * @param serverEndIndex the new server end index + */ + public void setServerEndIndex(int serverEndIndex) { + this.serverEndIndex = serverEndIndex; + } + + /** + * Sets the server search finished. + * + * @param isServerSearchFinished the new server search finished + */ + public void setServerSearchFinished(boolean isServerSearchFinished) { + this.isServerSearchFinished = isServerSearchFinished; + } + + /** + * Gets the total items. + * + * @return the total items + */ + public long getTotalItems() { + return totalItems; + } + + /** + * Sets the total items. + * + * @param totalItems the new total items + */ + public void setTotalItems(long totalItems) { + this.totalItems = totalItems; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SearchedData [data="); + builder.append(data); + builder.append(", clientStartIndex="); + builder.append(clientStartIndex); + builder.append(", limit="); + builder.append(limit); + builder.append(", serverEndIndex="); + builder.append(serverEndIndex); + builder.append(", isServerSearchFinished="); + builder.append(isServerSearchFinished); + builder.append(", totalItems="); + builder.append(totalItems); + builder.append("]"); + return builder.toString(); + } + + + +} diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java index 3fefedf..b3d9e17 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java @@ -1,31 +1,58 @@ package org.gcube.portlets.user.geoportaldataentry.client; -import java.time.LocalDateTime; +import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.mongoConcessioni; -import org.gcube.portlets.user.geoportaldataentry.server.ConvertToServiceModel; -import org.gcube.portlets.user.geoportaldataentry.server.GeoportalDataEntryServiceImpl; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.gcube.application.geoportal.common.model.legacy.Concessione; +import org.gcube.application.geoportal.common.rest.MongoConcessioni; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.scope.api.ScopeProvider; public class TestClass { + + + private static String TOKEN = ""; + private static String CONTEXT ="/gcube/devsec/devVRE"; public static void main(String[] args) throws Exception { + ScopeProvider.instance.set(CONTEXT); + SecurityTokenProvider.instance.set(TOKEN); - LocalDateTime ldt = ConvertToServiceModel.toLocalDateTime("2020-10-01 10:20"); - System.out.println(ldt.toString()); - - String latitudine = "-899.2986"; - //System.out.println(latitudine.matches("^[-]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$")); - - - String longitude = "0"; - System.out.println(longitude.matches("\\s*[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$")); - +// LocalDateTime ldt = ConvertToServiceModel.toLocalDateTime("2020-10-01 10:20"); +// System.out.println(ldt.toString()); +// +// String latitudine = "-899.2986"; +// // System.out.println(latitudine.matches("^[-]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$")); +// +// String longitude = "0"; +// System.out.println(longitude.matches("\\s*[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$")); +// +// GeoportalDataEntryServiceImpl g = new GeoportalDataEntryServiceImpl(); +// g.getLinksFor("", ConstantsGeoPortalDataEntryApp.RECORD_TYPE.CONCESSIONE.toString()); + getListOfConcessioni(); - GeoportalDataEntryServiceImpl g = new GeoportalDataEntryServiceImpl(); - g.getLinksFor("", "concessione"); - } - - + + public static void getListOfConcessioni() throws Exception { + MongoConcessioni clientMongo = mongoConcessioni().build(); + Iterator concessioni = clientMongo.getList(); + List listOfConcessioni = new ArrayList(); + if (concessioni != null) { + while (concessioni.hasNext()) { + Concessione concessione = (Concessione) concessioni.next(); + listOfConcessioni.add(concessione); + + } + } + int i = 0; + for (Concessione concessione : listOfConcessioni) { + System.out.println(++i+" "+concessione); + } + } + }