#22287 starting integration with the base search, ordering and filtering

facility provided by MongoDB
This commit is contained in:
Francesco Mangiacrapa 2021-12-01 11:54:39 +01:00
parent acae8dd735
commit 2b98a0849c
21 changed files with 623 additions and 421 deletions

View File

@ -1,16 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/geoportal-data-entry-app-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry including="**/*.java" kind="src" output="target/geoportal-data-entry-app-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/geoportal-data-entry-app-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
@ -20,7 +21,8 @@
<wb-module deploy-name="geoportal-data-entry-app-2.1.0-SNAPSHOT">
@ -41,7 +43,8 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
@ -62,7 +65,8 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
@ -83,7 +87,7 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
@ -103,29 +107,10 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="geoportal-data-entry-app"/>
@ -146,7 +131,8 @@
<property name="java-output-path" value="/geoportal-data-entry-app/target/geoportal-data-entry-app-2.0.0-SNAPSHOT/WEB-INF/classes"/>
@ -167,7 +153,8 @@
</wb-module>

View File

@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
#### Enhancements
- [#22455] Integrated with roles: (Data-Member as default), Data-Manager, Data-Editor
- [#22287] Integrated with base search, ordering and filtering facility provided by MongoDB
## [v2.0.1] - 2021-11-17

View File

@ -47,9 +47,9 @@ public class ConstantsGeoPortalDataEntryApp {
* Sep 2, 2021
*/
public static enum RECORD_FIELD {
NAME("name", "Name"), INTRODUCTION("introduction", "Introduction"), AUTHOR("author", "Author/s"),
PROJECT_START_END_DATE("", "Project Start/End Date"), RECORD_STATUS("recordStatus", "Published with"), CREATED("created", "Created"),
CREATED_BY("createdBy", "Created by");
NAME("nome", "Name"), INTRODUCTION("introduction", "Introduction"), AUTHOR("author", "Author/s"),
PROJECT_START_END_DATE("", "Project Start/End Date"), RECORD_STATUS("recordStatus", "Published with"), CREATED("creationTime", "Created"),
CREATED_BY("creationUser", "Created by");
String jsonFieldName;
String displayName;
@ -83,5 +83,6 @@ public class ConstantsGeoPortalDataEntryApp {
return displayName;
}
}
}

View File

@ -45,8 +45,8 @@ import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig;
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights;
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE;
import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter.ORDER;
import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter.ORDER;
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderServiceAsync;
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm;
@ -116,7 +116,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
RECORD_FIELD[] sortByOptions = new RECORD_FIELD[] { RECORD_FIELD.NAME, RECORD_FIELD.PROJECT_START_END_DATE,
RECORD_FIELD.CREATED, RECORD_FIELD.CREATED_BY, RECORD_FIELD.RECORD_STATUS };
SortFilter initialSortFilter = new SortFilter(RECORD_FIELD.NAME, ORDER.ASC);
SearchingFilter initialSortFilter = new SearchingFilter(RECORD_FIELD.NAME, ORDER.ASC);
RootPanel.get(DIV_PORTLET_ID).add(loader);
@ -499,7 +499,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
@Override
public void onGetList(GetListOfRecordsEvent getListOfRecordsEvent) {
SortFilter sortFilter = getListOfRecordsEvent.getSortFilter();
SearchingFilter sortFilter = getListOfRecordsEvent.getSortFilter();
if (sortFilter == null) {
sortFilter = mainTabPanel.getCurrentSortFilter();
}

View File

@ -11,7 +11,7 @@ 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.ResultSetPaginatedData;
import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
@ -64,7 +64,7 @@ public interface GeoportalDataEntryService extends RemoteService {
* @return the list concessioni
* @throws Exception the exception
*/
public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SortFilter filter,
public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SearchingFilter filter,
boolean reloadFromService) throws Exception;
/**

View File

@ -11,7 +11,7 @@ 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.ResultSetPaginatedData;
import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
@ -53,7 +53,7 @@ public interface GeoportalDataEntryServiceAsync
void getLinksFor(String itemId, RECORD_TYPE recordType, AsyncCallback<GeoNaItemRef> callback);
void getListConcessioni(Integer start, Integer limit, SortFilter filter, boolean reloadFromService,
void getListConcessioni(Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService,
AsyncCallback<ResultSetPaginatedData> callback);

View File

@ -2,7 +2,7 @@ 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 org.gcube.portlets.user.geoportaldataentry.shared.SortFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter;
import com.google.gwt.event.shared.GwtEvent;
@ -18,12 +18,12 @@ public class GetListOfRecordsEvent extends GwtEvent<GetListOfRecordsEventHandler
/** The type. */
public static Type<GetListOfRecordsEventHandler> TYPE = new Type<GetListOfRecordsEventHandler>();
private RECORD_TYPE recordType;
private SortFilter sortFilter;
private SearchingFilter sortFilter;
/**
* Instantiates a new cancel upload event.
*/
public GetListOfRecordsEvent(ConstantsGeoPortalDataEntryApp.RECORD_TYPE recordType, SortFilter sortFilter) {
public GetListOfRecordsEvent(ConstantsGeoPortalDataEntryApp.RECORD_TYPE recordType, SearchingFilter sortFilter) {
this.recordType = recordType;
this.sortFilter = sortFilter;
}
@ -64,7 +64,7 @@ public class GetListOfRecordsEvent extends GwtEvent<GetListOfRecordsEventHandler
return recordType;
}
public SortFilter getSortFilter() {
public SearchingFilter getSortFilter() {
return sortFilter;
}

View File

@ -1,6 +1,8 @@
package org.gcube.portlets.user.geoportaldataentry.client.ui;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD;
@ -11,20 +13,26 @@ import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecords
import org.gcube.portlets.user.geoportaldataentry.client.ui.form.GeonaDataEntryMainForm;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon;
import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM;
import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter.ORDER;
import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter.ORDER;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Dropdown;
import com.github.gwtbootstrap.client.ui.NavLink;
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.TabPanel;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
import com.github.gwtbootstrap.client.ui.constants.IconSize;
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.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
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.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
@ -43,6 +51,8 @@ public class GeonaMainTabPanel extends Composite {
private static final String LABEL_FILTER_SEPARATOR = " - ";
protected static final int MIN_LENGHT_SERCHING_STRING = 3;
private static GeonaMainTabPanelUiBinder uiBinder = GWT.create(GeonaMainTabPanelUiBinder.class);
/**
@ -106,11 +116,17 @@ public class GeonaMainTabPanel extends Composite {
@UiField
NavLink navDelete;
@UiField
TextBox searchField;
@UiField
Button resetSearch;
private HandlerManager appManagerBus;
private RECORD_FIELD[] sortByFields;
private SortFilter currentSortFilter;
private SearchingFilter currentSortFilter;
private GeonaRecordsPaginatedView grpw = null;
@ -121,13 +137,16 @@ public class GeonaMainTabPanel extends Composite {
* @param sortByFields the sort by fields
* @param initialSortFilter
*/
public GeonaMainTabPanel(HandlerManager appManagerBus, RECORD_FIELD[] sortByFields, SortFilter initialSortFilter) {
public GeonaMainTabPanel(HandlerManager appManagerBus, RECORD_FIELD[] sortByFields,
SearchingFilter initialSortFilter) {
initWidget(uiBinder.createAndBindUi(this));
this.appManagerBus = appManagerBus;
this.sortByFields = sortByFields;
setCurrentSortFilter(initialSortFilter);
this.currentSortFilter = initialSortFilter;
textBoxSortBy.setText(toLabelFilter(initialSortFilter.getOrderByField(), initialSortFilter.getOrder()));
bindEvents();
resetSearch.setIconSize(IconSize.TWO_TIMES);
resetSearch.setType(ButtonType.LINK);
}
public void setInternalHeight(int height) {
@ -153,7 +172,7 @@ public class GeonaMainTabPanel extends Composite {
@Override
public void onClick(ClickEvent event) {
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, currentSortFilter));
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
}
});
@ -162,16 +181,18 @@ public class GeonaMainTabPanel extends Composite {
@Override
public void onClick(ClickEvent event) {
instanceAndShowListOfConcessioni();
}
});
for (RECORD_FIELD record_FIELD : sortByFields) {
if (record_FIELD.equals(RECORD_FIELD.RECORD_STATUS))
continue;
// ASC
SortFilter sortFilter = new SortFilter(record_FIELD, ORDER.ASC);
String labelASC = toLabelFilter(sortFilter);
String labelASC = toLabelFilter(record_FIELD, ORDER.ASC);
NavLink nav = new NavLink(labelASC);
dropdownSortBy.add(nav);
@ -179,24 +200,21 @@ public class GeonaMainTabPanel extends Composite {
@Override
public void onClick(ClickEvent event) {
GWT.log("Sort by: " + sortFilter);
setCurrentSortFilter(sortFilter);
textBoxSortBy.setText(labelASC);
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
}
});
// //DESC
SortFilter sortFilter2 = new SortFilter(record_FIELD, ORDER.DESC);
String labelASC2 = toLabelFilter(sortFilter2);
NavLink nav2 = new NavLink(labelASC2);
String labelDESC = toLabelFilter(record_FIELD, ORDER.DESC);
NavLink nav2 = new NavLink(labelDESC);
dropdownSortBy.add(nav2);
nav2.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
GWT.log("Sort by: " + sortFilter2);
setCurrentSortFilter(sortFilter2);
textBoxSortBy.setText(labelDESC);
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
}
});
@ -238,8 +256,8 @@ public class GeonaMainTabPanel extends Composite {
if (grpw != null && grpw.getSelectItems() != null) {
listConcessioni = grpw.getSelectItems();
}
appManagerBus.fireEvent(
new ActionOnItemEvent<ConcessioneDV>(listConcessioni, ACTION_ON_ITEM.EDIT_PROJECT));
appManagerBus
.fireEvent(new ActionOnItemEvent<ConcessioneDV>(listConcessioni, ACTION_ON_ITEM.EDIT_PROJECT));
}
});
@ -251,11 +269,46 @@ public class GeonaMainTabPanel extends Composite {
if (grpw != null && grpw.getSelectItems() != null) {
listConcessioni = grpw.getSelectItems();
}
appManagerBus
.fireEvent(new ActionOnItemEvent<ConcessioneDV>(listConcessioni, ACTION_ON_ITEM.DELETE_PROJECT));
appManagerBus.fireEvent(
new ActionOnItemEvent<ConcessioneDV>(listConcessioni, ACTION_ON_ITEM.DELETE_PROJECT));
}
});
searchField.addKeyPressHandler(new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent event) {
GWT.log("CHAR CODE: " + event.getCharCode());
if (com.google.gwt.event.dom.client.KeyCodes.KEY_ENTER == event.getCharCode()) {
GWT.log(searchField.getText());
String searchText = searchField.getText();
if (searchText.length() < MIN_LENGHT_SERCHING_STRING) {
Window.alert("Please enter at least "+MIN_LENGHT_SERCHING_STRING+" characters");
return;
}
resetSearch.setVisible(true);
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
}
}
});
resetSearch.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
searchField.setText("");
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
resetSearch.setVisible(false);
}
});
}
private String toLabelFilter(RECORD_FIELD orderBy, ORDER direction) {
String labelFilter = orderBy.getDisplayName() + LABEL_FILTER_SEPARATOR + direction.name();
return labelFilter;
}
/**
@ -292,48 +345,43 @@ public class GeonaMainTabPanel extends Composite {
loader.setVisible(visible);
}
private void setCurrentSortFilter(SortFilter sortFilter) {
this.currentSortFilter = sortFilter;
this.textBoxSortBy.setText(toLabelFilter(sortFilter));
public SearchingFilter toSortFilter(String labelFilter) {
GWT.log("toSortFilter for label " + labelFilter);
String[] array = labelFilter.split(LABEL_FILTER_SEPARATOR);
SearchingFilter sortFilter = null;
try {
RECORD_FIELD recordField = null;
for (RECORD_FIELD value : RECORD_FIELD.values()) {
if (array[0].equalsIgnoreCase(value.getDisplayName())) {
recordField = value;
break;
}
}
ORDER orderField = ORDER.valueOf(array[1]);
sortFilter = new SearchingFilter(recordField, orderField);
} catch (Exception e) {
}
GWT.log("toSortFilter Got " + sortFilter);
return sortFilter;
}
/**
* To label filter.
*
* @param sortFilter the sort filter
* @return the string
*/
public String toLabelFilter(SortFilter sortFilter) {
String labelFilter = sortFilter.getOrderByField().getDisplayName() + LABEL_FILTER_SEPARATOR
+ sortFilter.getOrder().name();
GWT.log("Got " + sortFilter);
return labelFilter;
private SearchingFilter builtSearchingFilter() {
SearchingFilter searchingFilter = toSortFilter(this.textBoxSortBy.getText());
String searchText = searchField.getText();
if (searchText != null && !searchText.isEmpty()) {
Map<String, Object> searchInto = new HashMap<String, Object>();
searchInto.put(RECORD_FIELD.NAME.getJsonFieldName(), searchText);
searchingFilter.setSearchInto(searchInto);
}
return searchingFilter;
}
/**
* To sort filter.
*
* @param labelFilter the label filter
* @return the sort filter
*/
/*
* public SortFilter toSortFilter(String labelFilter) {
*
* String[] array = labelFilter.split(LABEL_FILTER_SEPARATOR);
*
* SortFilter sortFilter = null; try { RECORD_FIELD recordField =
* RECORD_FIELD.valueOf(array[0]); ORDER orderField = ORDER.valueOf(array[1]);
* sortFilter = new SortFilter(recordField, orderField); } catch (Exception e) {
*
* }
*
* GWT.log("Got " + sortFilter); return sortFilter;
*
* }
*/
public SortFilter getCurrentSortFilter() {
public SearchingFilter getCurrentSortFilter() {
currentSortFilter = builtSearchingFilter();
GWT.log("currentSortFilter: " + currentSortFilter);
return currentSortFilter;
}
@ -344,13 +392,13 @@ public class GeonaMainTabPanel extends Composite {
public void setTabActive(int index) {
tabPanel.selectTab(index);
}
/**
* Dirty solution.
* I created this one because I had problem on firing click event for Tab element
* Dirty solution. I created this one because I had problem on firing click
* event for Tab element
*
*/
public void instanceAndShowListOfConcessioni(){
public void instanceAndShowListOfConcessioni() {
grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, null, currentSortFilter);
showListOfConcessioniView(grpw);
}

View File

@ -32,13 +32,22 @@
text-align: right;
}
.display-right {
float: right;
}
.max-height-300 {
max-height: auto;
}
.margin-botttom-5 {
.margin-bottom-5 {
margin-bottom: 5px !important;
}
.search-field {
padding-top: 6px;
margin-top: 2px;
}
</ui:style>
<g:HTMLPanel>
<b:PageHeader subtext="data entry facility"
@ -48,7 +57,7 @@
ui:field="tabNewProject">
<g:ScrollPanel>
<g:HTMLPanel ui:field="contTabNewProject">
<b:Navbar addStyleNames="{style.margin-botttom-5}">
<b:Navbar addStyleNames="{style.margin-bottom-5}">
<b:Brand addStyleNames="{style.margin-top-5}">New Project</b:Brand>
<b:Nav>
<b:NavLink ui:field="buttCreateNewProject"
@ -85,8 +94,8 @@
</g:FlowPanel>
<g:ScrollPanel>
<g:HTMLPanel ui:field="contTabGetListOfProjects">
<b:Navbar addStyleNames="{style.margin-botttom-5}">
<b:Brand addStyleNames="{style.margin-top-5}">List of Projects</b:Brand>
<b:Navbar addStyleNames="nav-toolbar-style">
<b:Brand>List of Projects</b:Brand>
<b:Nav>
<b:Dropdown text="Sort by" ui:field="dropdownSortBy">
</b:Dropdown>
@ -99,6 +108,12 @@
<b:NavLink ui:field="buttonReloadConcessioni"
title="Create a new Project" icon="ROTATE_RIGHT">Reload Projects</b:NavLink>
</b:Nav>
<b:TextBox ui:field="searchField"
addStyleNames="search-textbox" placeholder="Search"></b:TextBox>
<b:Button addStyleNames="{style.display-right}"
icon="REMOVE_CIRCLE" ui:field="resetSearch"
title="Reset the search" visible="false"></b:Button>
</b:Navbar>
<g:HTMLPanel addStyleNames="{style.float-right}">

View File

@ -10,7 +10,7 @@ import org.gcube.portlets.user.geoportaldataentry.client.ui.table.ItemsTable;
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.ResultSetPaginatedData;
import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager;
@ -47,10 +47,10 @@ public class GeonaRecordsPaginatedView {
private MyCustomDataProvider<ConcessioneDV> dataProvider = new MyCustomDataProvider<ConcessioneDV>();
protected Widget orginalLoadingIndicator = null;
private LoaderIcon loadingPanel = new LoaderIcon("Loading data...");
private int serverStartIndex;
//private int serverStartIndex;
private HandlerManager eventBus;
private RECORD_TYPE recordType;
private SortFilter currentSortFilter;
private SearchingFilter currentSortFilter;
/**
* Instantiates a new geona records paginated view.
@ -61,12 +61,12 @@ public class GeonaRecordsPaginatedView {
* @param currentSortFilter the sort by field
*/
public GeonaRecordsPaginatedView(HandlerManager eventbus, RECORD_TYPE recordType,
RECORD_FIELD[] displayFields, SortFilter currentSortFilter) {
RECORD_FIELD[] displayFields, SearchingFilter currentSortFilter) {
this.recordType = recordType;
this.currentSortFilter = currentSortFilter;
this.initClassFirstRangeChanged = true;
this.eventBus = eventbus;
itemsTable = new ItemsTable<ConcessioneDV>(eventbus, displayFields, currentSortFilter);
itemsTable = new ItemsTable<ConcessioneDV>(eventbus, displayFields);
itemsTable.initTable(null, null, dataProvider);
orginalLoadingIndicator = itemsTable.getCellTable().getLoadingIndicator();
@ -120,7 +120,7 @@ public class GeonaRecordsPaginatedView {
* @param invalidCache the invalid cache
*/
private void loadNewPage(final int startIdx, final int limit, final boolean resetStore,
final SortFilter currentSortFilter, final boolean invalidCache) {
final SearchingFilter currentSortFilter, final boolean invalidCache) {
// initFirstRangeChanged = resetStore;
GWT.log("loadNewPage with parameters [startIdx: " + startIdx + ", limit: " + limit + ", resetStore:"
+ resetStore + "]");
@ -131,12 +131,12 @@ public class GeonaRecordsPaginatedView {
if (resetStore) {
GWT.log("Cleaning all data...");
newStartIndex = 0;
serverStartIndex = 0;
//serverStartIndex = 0;
GWT.log("Store reset performed start index is: " + newStartIndex);
getTableDataProvider().updateRowCount(ITEMS_PER_PAGE, false);
}
loadConcessioni(newStartIndex, limit, serverStartIndex, currentSortFilter, invalidCache);
loadConcessioni(newStartIndex, limit, currentSortFilter, invalidCache);
}
/**
@ -157,7 +157,7 @@ public class GeonaRecordsPaginatedView {
*/
private void setNewPageResult(ResultSetPaginatedData result) {
GWT.log("setNewPageResult: " + result);
serverStartIndex = result.getServerEndIndex();
//serverStartIndex = result.getServerEndIndex();
SelectionModel<? super ConcessioneDV> sm = getCellTable().getSelectionModel();
if (sm instanceof SingleSelectionModel) {
@ -197,12 +197,11 @@ public class GeonaRecordsPaginatedView {
* @param limit the limit
* @param serverIndex the server index
*/
private <T> void loadConcessioni(int newStartIndex, int limit, int serverIndex, SortFilter sortFilter,
private <T> void loadConcessioni(int newStartIndex, int limit, SearchingFilter sortFilter,
boolean invalidCache) {
showLoading(true);
GWT.log("calling loadItemsForStatus with parameters [startIndex: " + newStartIndex + ", limit: " + limit
+ ", serverIndex:" + serverIndex + ", sortFilter: " + sortFilter + "]");
GWT.log("calling loadItemsForStatus with parameters [startIndex: " + newStartIndex + ", limit: " + limit+ ", sortFilter: " + sortFilter + "]");
GeoPortalDataEntryApp.geoportalDataEntryService.getListConcessioni(newStartIndex, limit, sortFilter, invalidCache,
new AsyncCallback<ResultSetPaginatedData>() {

View File

@ -15,7 +15,6 @@ import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV;
import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV.ValidationStatus;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD;
import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter;
import com.github.gwtbootstrap.client.ui.ButtonCell;
import com.github.gwtbootstrap.client.ui.Pagination;
@ -68,7 +67,6 @@ public class ItemsTable<T extends ConcessioneDV> extends AbstractItemsCellTable<
private boolean isAsyncronusTable;
private TextColumn<T> insertedBy;
private Column<T, Date> createdColumn;
private SortFilter currentSortFilter;
/**
* Instantiates a new items table.
@ -77,9 +75,8 @@ public class ItemsTable<T extends ConcessioneDV> extends AbstractItemsCellTable<
* @param displayFields the display fields
* @param startSortByColumn the start sort by column
*/
public ItemsTable(HandlerManager eventBus, RECORD_FIELD[] displayFields, SortFilter currentSortFilter) {
public ItemsTable(HandlerManager eventBus, RECORD_FIELD[] displayFields) {
this.eventBus = eventBus;
this.currentSortFilter = currentSortFilter;
setDisplayFields(displayFields);
}
@ -335,89 +332,6 @@ public class ItemsTable<T extends ConcessioneDV> extends AbstractItemsCellTable<
sortedCellTable.setColumnWidth(statusColumn, 120, Unit.PX);
}
// ButtonCell showOnMapButton = new ButtonCell();
// showOnMapButton.setIcon(IconType.MAP_MARKER);
//
// MyToolTipColumn<T, String> showOnMapColumn = new MyToolTipColumn<T, String>(showOnMapButton, "Show on Map") {
//
// @Override
// public String getValue(T object) {
// return "";
// }
// };
//
// showOnMapColumn.setFieldUpdater(new FieldUpdater<T, String>() {
// @Override
// public void update(int index, T object, String value) {
// GWT.log("clicked show");
// eventBus.fireEvent(new ActionOnItemEvent<T>(Arrays.asList(object), ACTION_ON_ITEM.VIEW_ON_MAP));
// }
// });
// sortedCellTable.addColumn(showOnMapColumn);
// sortedCellTable.setColumnWidth(showOnMapColumn, 50, Unit.PX);
//
// ButtonCell showReportRecordButton = new ButtonCell();
// showReportRecordButton.setIcon(IconType.FILE_TEXT_ALT);
// MyToolTipColumn<T, String> showReportRecordColumn = new MyToolTipColumn<T, String>(showReportRecordButton,
// "Show Publication Report") {
// public String getValue(T object) {
// return "";
// }
// };
//
// showReportRecordColumn.setFieldUpdater(new FieldUpdater<T, String>() {
// @Override
// public void update(int index, T object, String value) {
//
// eventBus.fireEvent(new ActionOnItemEvent<T>(Arrays.asList(object), ACTION_ON_ITEM.VIEW_REPORT));
// }
// });
// sortedCellTable.addColumn(showReportRecordColumn);
// sortedCellTable.setColumnWidth(showReportRecordColumn, 50, Unit.PX);
//
// ButtonCell deleteRecordButton = new ButtonCell();
// deleteRecordButton.setIcon(IconType.TRASH);
// MyToolTipColumn<T, String> deleteRecordColumn = new MyToolTipColumn<T, String>(deleteRecordButton,
// "Delete Project") {
// public String getValue(T object) {
// return "";
// }
// };
//
// deleteRecordColumn.setFieldUpdater(new FieldUpdater<T, String>() {
// @Override
// public void update(int index, T object, String value) {
//
// eventBus.fireEvent(new ActionOnItemEvent<T>(Arrays.asList(object), ACTION_ON_ITEM.DELETE_PROJECT));
// }
// });
// sortedCellTable.addColumn(deleteRecordColumn);
// sortedCellTable.setColumnWidth(deleteRecordColumn, 50, Unit.PX);
GWT.log("currentSortFilter: " + currentSortFilter);
if (currentSortFilter != null)
switch (currentSortFilter.getOrderByField()) {
case NAME:
if (this.displayFields.contains(RECORD_FIELD.NAME)) {
sortedCellTable.setInitialSortColumn(name);
}
break;
case INTRODUCTION:
if (this.displayFields.contains(RECORD_FIELD.INTRODUCTION)) {
sortedCellTable.setInitialSortColumn(introduction);
}
break;
case AUTHOR:
if (this.displayFields.contains(RECORD_FIELD.AUTHOR)) {
sortedCellTable.setInitialSortColumn(author);
}
break;
default:
break;
}
}

View File

@ -1,12 +1,13 @@
package org.gcube.portlets.user.geoportaldataentry.server;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bson.Document;
import org.gcube.application.geoportal.common.model.legacy.AbstractRelazione;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths;
@ -15,6 +16,10 @@ import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo;
import org.gcube.application.geoportal.common.model.legacy.UploadedImage;
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport;
import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest;
import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction;
import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest;
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportalcommon.ConvertToDataViewModel;
@ -30,10 +35,10 @@ import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitl
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService;
import org.gcube.portlets.user.geoportaldataentry.server.MongoServiceUtil.ConcessioneValidationReportStatusComparator;
import org.gcube.portlets.user.geoportaldataentry.server.config.GNARoleRitghtsConfigReader;
import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM;
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
import org.gcube.portlets.user.geoportaldataentry.shared.DisplayField;
import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigException;
import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole;
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
@ -41,8 +46,8 @@ import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig;
import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData;
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights;
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE;
import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter.ORDER;
import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter.ORDER;
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded;
@ -56,6 +61,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.mongodb.BasicDBObject;
/**
* The server side implementation of the RPC service.
@ -408,6 +414,176 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
return item;
}
/**
* Query on mongo.
*
* @param offset the offset
* @param limit the limit
* @param filter the filter
* @param recordType the record type
* @param reloadFromService the reload from service
* @return the result set paginated data
* @throws Exception the exception
*/
private ResultSetPaginatedData queryOnMongo(Integer offset, Integer limit, SearchingFilter filter, String recordType,
boolean reloadFromService) throws Exception {
try {
if (recordType.equalsIgnoreCase(RECORD_TYPE.CONCESSIONE.name())) {
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
MongoServiceUtil serviceUtil = new MongoServiceUtil();
MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni();
// TODO MUST BE REPLACED BY COUNT
List<Concessione> listOfConcessioni = SessionUtil.getListOfConcessioni(getThreadLocalRequest(),
reloadFromService);
int listConcessioniSize = listOfConcessioni.size();
Integer offsetIndex = offset;
Integer limitIndex = limit;
if (offset == null) {
offsetIndex = 0;
}
if (limit == null) {
limitIndex = listConcessioniSize;
}
ResultSetPaginatedData searchedData = new ResultSetPaginatedData(offsetIndex, limitIndex, false);
searchedData.setTotalItems(listConcessioniSize);
List<ConcessioneDV> toReturnList = new ArrayList<ConcessioneDV>();
Direction sDirection = null;
List<String> fields = new ArrayList<String>();
if (filter == null) {
LOG.info("No filter found, creating empty filter");
filter = new SearchingFilter();
}
ORDER order = filter.getOrder();
if (order == null) {
sDirection = Direction.ASCENDING;
LOG.info("No direction/order found, using default: " + sDirection);
}
switch (order) {
case ASC:
sDirection = Direction.ASCENDING;
break;
case DESC:
sDirection = Direction.DESCENDING;
break;
}
RECORD_FIELD orderByFields = filter.getOrderByField();
if (orderByFields == null) {
orderByFields = RECORD_FIELD.NAME;
LOG.info("No fields for searching found, using default: " + orderByFields);
}
switch (orderByFields) {
case NAME:
fields.add(RECORD_FIELD.NAME.getJsonFieldName());
break;
case CREATED:
fields.add(RECORD_FIELD.CREATED.getJsonFieldName());
break;
case CREATED_BY:
fields.add(RECORD_FIELD.CREATED_BY.getJsonFieldName());
break;
// TODO is buggy must be performed by service
case PROJECT_START_END_DATE:
fields.add("dataInizioProgetto");
fields.add("dataFineProgetto");
break;
case RECORD_STATUS:
fields.add("report:status");
// statusComparator = new ConcessioneValidationReportStatusComparator();
default:
break;
}
QueryRequest request = new QueryRequest();
PagedRequest paging = new PagedRequest();
paging.setOffset(offsetIndex);
paging.setLimit(limitIndex);
request.setPaging(paging);
OrderedRequest ordering = new OrderedRequest();
ordering.setDirection(sDirection);
ordering.setFields(fields);
request.setOrdering(ordering);
if(filter.getSearchInto()!=null) {
Map<String, Object> searchFields = filter.getSearchInto();
//List<BasicDBObject> list = new ArrayList<BasicDBObject>();
//Map map = new HashMap<BasicDBObject, BasicDBObject>();
Document query = new Document();
for (String key : searchFields.keySet()) {
query.put(key, searchFields.get(key));
query.put(key, new BasicDBObject("$eq", searchFields.get(key)));
}
request.setFilter(query);
}
LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
LOG.info("Direction: " + sDirection);
LOG.info("Order by Fields: " + fields);
LOG.info("Search for: " + filter.getSearchInto());
Iterator<Concessione> concessioni = clientMongo.query(request);
while (concessioni.hasNext()) {
Concessione concessione = concessioni.next();
ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true);
toReturnList.add(concessioneDV);
}
searchedData.setData(toReturnList);
if (listConcessioniSize == limit || listConcessioniSize == 0) {
LOG.debug("Page completed returning " + listConcessioniSize + " items");
int newOffset = offsetIndex + limitIndex;
searchedData.setServerSearchFinished(newOffset > listConcessioniSize || listConcessioniSize == 0);
LOG.debug("is Search finished: " + searchedData.isServerSearchFinished());
}
return searchedData;
}
} catch (Exception e) {
LOG.error("Error on loading paginated and filtered list of concessioni: ", e);
throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage());
}
return null;
}
// TODO THIS PART REQUIRES THE JSON MAPPING based on keys read from gCube Meta
/**
* List display fields.
*
* @return the list
*/
// Profile
public List<DisplayField> listDisplayFields() {
List<DisplayField> listDisplayFields = new ArrayList<DisplayField>();
DisplayField df = new DisplayField("Name", Arrays.asList("nome"), true);
// etc
return listDisplayFields;
}
/**
* Gets the list concessioni.
*
@ -419,150 +595,10 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
* @throws Exception the exception
*/
@Override
public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SortFilter filter,
public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SearchingFilter filter,
boolean reloadFromService) throws Exception {
LOG.info("getListConcessioni called wit start: " + start + ", limit: " + limit + ", filter: " + filter);
try {
List<Concessione> listOfConcessioni = SessionUtil.getListOfConcessioni(getThreadLocalRequest(),
reloadFromService);
int listConcessioniSize = listOfConcessioni.size();
List<Concessione> toReturn = new ArrayList<Concessione>();
int startIndex;
int limitIndex = 0;
if (start == null && limit == null) {
startIndex = 0;
limitIndex = listConcessioniSize;
} else {
startIndex = start;
limitIndex = start + limit;
if (limitIndex > listConcessioniSize) {
limitIndex = listConcessioniSize;
}
}
ResultSetPaginatedData searchedData = new ResultSetPaginatedData(start, limit, startIndex, false);
searchedData.setTotalItems(listConcessioniSize);
RECORD_FIELD orderBy = null;
ORDER order = null;
ConcessioneValidationReportStatusComparator statusComparator = null;
if (filter == null) {
// unsorted list of records
toReturn = listOfConcessioni.subList(startIndex, limitIndex);
} else {
orderBy = filter.getOrderByField();
order = filter.getOrder();
if (orderBy == null)
orderBy = RECORD_FIELD.NAME;
if (order == null)
order = ORDER.ASC;
// CASE INSENSITIVE COMPARATOR
Comparator<Concessione> comparator = null;
switch (orderBy) {
case NAME:
if (order.equals(ORDER.ASC)) {
comparator = Comparator.comparing(Concessione::getNome,
Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER));
} else {
comparator = Comparator
.comparing(Concessione::getNome, Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER))
.reversed();
}
break;
case CREATED:
if (order.equals(ORDER.ASC)) {
comparator = Comparator.comparing(Concessione::getCreationTime,
Comparator.nullsLast(Comparator.naturalOrder()));
} else {
comparator = Comparator.comparing(Concessione::getCreationTime,
Comparator.nullsLast(Comparator.naturalOrder())).reversed();
}
break;
case CREATED_BY:
if (order.equals(ORDER.ASC)) {
comparator = Comparator.comparing(Concessione::getCreationUser,
Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER));
} else {
comparator = Comparator.comparing(Concessione::getCreationUser,
Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER)).reversed();
}
break;
// TODO is buggy must be performed by service
case PROJECT_START_END_DATE:
if (order.equals(ORDER.ASC)) {
comparator = Comparator.comparing(Concessione::getDataInizioProgetto,
Comparator.nullsLast(Comparator.naturalOrder()));
} else {
comparator = Comparator.comparing(Concessione::getDataInizioProgetto,
Comparator.nullsLast(Comparator.naturalOrder())).reversed();
}
break;
case RECORD_STATUS:
statusComparator = new ConcessioneValidationReportStatusComparator();
default:
break;
}
// sorting with nullsLast
if (comparator != null)
listOfConcessioni.sort(Comparator.nullsLast(comparator));
// solution quick&dirty
try {
if (statusComparator != null) {
if (order.equals(ORDER.ASC)) {
listOfConcessioni.sort(Comparator.nullsLast(statusComparator));
} else {
Collections.sort(listOfConcessioni, Comparator.nullsLast(
Collections.reverseOrder(new ConcessioneValidationReportStatusComparator())));
}
}
} catch (Exception e) {
LOG.warn("comparator Exception: " + e.getMessage());
}
LOG.trace("sorted list: " + listOfConcessioni);
// pagination
toReturn = listOfConcessioni.subList(startIndex, limitIndex);
}
List<ConcessioneDV> toReturnList = new ArrayList<ConcessioneDV>(toReturn.size());
for (Concessione concessione : toReturn) {
ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true);
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());
}
return queryOnMongo(start, limit, filter, "concessione", reloadFromService);
}
/**
@ -848,6 +884,12 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
}
}
/**
* Gets the my rights in the context.
*
* @return the my rights in the context
* @throws Exception the exception
*/
@Override
public UserRights getMyRightsInTheContext() throws Exception {
LOG.info("getMyRightsInTheContext called");

View File

@ -147,7 +147,7 @@ public class SessionUtil {
SessionUtil.getCurrentContext(httpServletRequest, true);
MongoServiceUtil serviceUtil = new MongoServiceUtil();
MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni();
Iterator<Concessione> concessioni = clientMongo.getList();
if (concessioni != null) {
while (concessioni.hasNext()) {

View File

@ -1,7 +1,6 @@
package org.gcube.portlets.user.geoportaldataentry.server.config;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;

View File

@ -0,0 +1,66 @@
package org.gcube.portlets.user.geoportaldataentry.shared;
import java.io.Serializable;
import java.util.List;
public class DisplayField implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1856714668390438433L;
private String displayName;
private List<String> jsonFields;
private boolean sortable;
public DisplayField(){
}
public DisplayField(String displayName, List<String> jsonFields, boolean sortable) {
super();
this.displayName = displayName;
this.jsonFields = jsonFields;
this.sortable = sortable;
}
public String getDisplayName() {
return displayName;
}
public List<String> getJsonFields() {
return jsonFields;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public void setJsonFields(List<String> jsonFields) {
this.jsonFields = jsonFields;
}
public boolean isSortable() {
return sortable;
}
public void setSortable(boolean sortable) {
this.sortable = sortable;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("DisplayField [displayName=");
builder.append(displayName);
builder.append(", jsonFields=");
builder.append(jsonFields);
builder.append(", sortable=");
builder.append(sortable);
builder.append("]");
return builder.toString();
}
}

View File

@ -8,13 +8,12 @@ import java.util.List;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
/**
* The Class ResultSetPaginatedData.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Aug 6, 2021
* Aug 6, 2021
*/
public class ResultSetPaginatedData implements Serializable {
@ -23,9 +22,8 @@ public class ResultSetPaginatedData implements Serializable {
*/
private static final long serialVersionUID = 6800997954077785719L;
private List<ConcessioneDV> data;
private int clientStartIndex = 0;
private int offset = 0;
private int limit;
private int serverEndIndex = 0;
private boolean isServerSearchFinished = false;
private long totalItems;
@ -35,20 +33,17 @@ public class ResultSetPaginatedData implements Serializable {
public ResultSetPaginatedData() {
}
/**
* Instantiates a new result set paginated data.
*
* @param clientStartIndex the client start index
* @param limit the limit
* @param serverEndIndex the server end index
* @param offset the offset
* @param limit the limit
* @param isServerSearchFinished the is server search finished
*/
public ResultSetPaginatedData(int clientStartIndex, int limit, int serverEndIndex, boolean isServerSearchFinished) {
public ResultSetPaginatedData(int offset, int limit, boolean isServerSearchFinished) {
this.clientStartIndex = clientStartIndex;
this.offset = offset;
this.limit = limit;
this.serverEndIndex = serverEndIndex;
this.isServerSearchFinished = isServerSearchFinished;
}
@ -67,7 +62,7 @@ public class ResultSetPaginatedData implements Serializable {
* @return the client start index
*/
public int getClientStartIndex() {
return clientStartIndex;
return offset;
}
/**
@ -79,15 +74,6 @@ public class ResultSetPaginatedData implements Serializable {
return limit;
}
/**
* Gets the server end index.
*
* @return the server end index
*/
public int getServerEndIndex() {
return serverEndIndex;
}
/**
* Checks if is server search finished.
*
@ -112,7 +98,7 @@ public class ResultSetPaginatedData implements Serializable {
* @param clientStartIndex the new client start index
*/
public void setClientStartIndex(int clientStartIndex) {
this.clientStartIndex = clientStartIndex;
this.offset = clientStartIndex;
}
/**
@ -124,15 +110,6 @@ public class ResultSetPaginatedData implements Serializable {
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.
*
@ -161,21 +138,41 @@ public class ResultSetPaginatedData implements Serializable {
}
/**
* To string.
* Gets the serialversionuid.
*
* @return the string
* @return the serialversionuid
*/
public static long getSerialversionuid() {
return serialVersionUID;
}
/**
* Gets the offset.
*
* @return the offset
*/
public int getOffset() {
return offset;
}
/**
* Sets the offset.
*
* @param offset the new offset
*/
public void setOffset(int offset) {
this.offset = offset;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ResultSetPaginatedData [data=");
builder.append(data);
builder.append(", clientStartIndex=");
builder.append(clientStartIndex);
builder.append(", offset=");
builder.append(offset);
builder.append(", limit=");
builder.append(limit);
builder.append(", serverEndIndex=");
builder.append(serverEndIndex);
builder.append(", isServerSearchFinished=");
builder.append(isServerSearchFinished);
builder.append(", totalItems=");
@ -184,6 +181,4 @@ public class ResultSetPaginatedData implements Serializable {
return builder.toString();
}
}

View File

@ -12,7 +12,7 @@ public class ResultSetSorted implements Serializable {
*/
private static final long serialVersionUID = 889420364685643758L;
private SortFilter searchFilter;
private SearchingFilter searchFilter;
private List<Concessione> data;
@ -20,13 +20,13 @@ public class ResultSetSorted implements Serializable {
}
public ResultSetSorted(SortFilter searchFilter, List<Concessione> data) {
public ResultSetSorted(SearchingFilter searchFilter, List<Concessione> data) {
super();
this.searchFilter = searchFilter;
this.data = data;
}
public SortFilter getSearchFilter() {
public SearchingFilter getSearchFilter() {
return searchFilter;
}
@ -34,7 +34,7 @@ public class ResultSetSorted implements Serializable {
return data;
}
public void setSearchFilter(SortFilter searchFilter) {
public void setSearchFilter(SearchingFilter searchFilter) {
this.searchFilter = searchFilter;
}

View File

@ -1,34 +1,45 @@
package org.gcube.portlets.user.geoportaldataentry.shared;
import java.io.Serializable;
import java.util.Map;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD;
/**
* The Class SortFilter.
* The Class SearchingFilter.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Aug 6, 2021
* Nov 30, 2021
*/
public class SortFilter implements Serializable {
public class SearchingFilter implements Serializable {
/**
* The Enum ORDER.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Aug 6, 2021
* Nov 30, 2021
*/
public static enum ORDER {
ASC("ASCENDING"), DESC("DESCENDING");
String label;
/**
* Instantiates a new order.
*
* @param label the label
*/
ORDER(String label) {
this.label = label;
}
/**
* Gets the label.
*
* @return the label
*/
public String getLabel() {
return label;
}
@ -43,10 +54,12 @@ public class SortFilter implements Serializable {
private ORDER order;
private Map<String, Object> searchInto;
/**
* Instantiates a new sort filter.
*/
public SortFilter() {
public SearchingFilter() {
}
@ -56,11 +69,27 @@ public class SortFilter implements Serializable {
* @param orderByField the order by field
* @param order the order
*/
public SortFilter(RECORD_FIELD orderByField, ORDER order) {
public SearchingFilter(RECORD_FIELD orderByField, ORDER order) {
this.orderByField = orderByField;
this.order = order;
}
/**
* Instantiates a new sort filter.
*
* @param orderByField the order by field
* @param order the order
*/
public SearchingFilter(RECORD_FIELD orderByField, ORDER order, Map<String, Object> searchInto) {
this.orderByField = orderByField;
this.order = order;
this.searchInto = searchInto;
}
public void setSearchInto(Map<String, Object> searchInto) {
this.searchInto = searchInto;
}
/**
* Gets the order by field.
*
@ -97,18 +126,19 @@ public class SortFilter implements Serializable {
this.order = order;
}
/**
* To string.
*
* @return the string
*/
public Map<String, Object> getSearchInto() {
return searchInto;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("SortFilter [orderByField=");
builder.append("SearchingFilter [orderByField=");
builder.append(orderByField);
builder.append(", order=");
builder.append(order);
builder.append(", searchInto=");
builder.append(searchInto);
builder.append("]");
return builder.toString();
}

View File

@ -119,3 +119,25 @@ h1 {
margin-left: 10px;
width: 95%;
}
.nav-toolbar-style {
margin-bottom: 5px;
}
.nav-toolbar-style .container {
padding-top: 5px;
}
.search-textbox {
padding: 4px 14px !important;
margin-bottom: 0 !important;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif !important;
font-size: 13px !important;
font-weight: normal !important;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px !important;
float: right !important;
width: 250px !important;
margin-top: 8px !important;
}

View File

@ -3,10 +3,18 @@ package org.gcube.portlets.user.geoportaldataentry.client;
import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.mongoConcessioni;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bson.Document;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest;
import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction;
import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest;
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
@ -15,13 +23,15 @@ import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights;
import org.junit.Before;
import org.junit.Test;
import com.mongodb.BasicDBObject;
public class TestClass {
private static String TOKEN = "";
private static String TOKEN = "8e74a17c-92f1-405a-b591-3a6090066248-98187548";
private static String CONTEXT = "/gcube/devsec/devVRE";
private static String USERNAME = "francesco.mangiacrapa";
//@Before
@Before
public void init() {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
@ -44,6 +54,84 @@ public class TestClass {
System.out.println(++i + " " + concessione);
}
}
@Test
public void queryConcessioniTest() throws Exception {
try {
MongoConcessioni clientMongo = mongoConcessioni().build();
int offsetIndex = 0;
int limitIndex = 25;
Direction sDirection = Direction.ASCENDING;
List<String> orderByFields = Arrays.asList("nome");
String searchByField = "nome";
String serchValue = "mock";
Map<String, Object> searchFields = new HashMap<String, Object>();
searchFields.put(searchByField, serchValue);
QueryRequest request = new QueryRequest();
PagedRequest paging = new PagedRequest();
paging.setOffset(offsetIndex);
paging.setLimit(limitIndex);
request.setPaging(paging);
OrderedRequest ordering = new OrderedRequest();
ordering.setDirection(sDirection);
ordering.setFields(orderByFields);
request.setOrdering(ordering);
Document query = null;
if(searchFields!=null) {
// BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
// BasicDBObject bs = null;
// query = new Document();
//
// for (String key : searchFields.keySet()) {
// //builder.append(key, new BasicDBObject("$eq", searchFields.get(key)));
// //query.put(key, new BasicDBObject("$eq", searchFields.get(key)));
// query = new Document(key, searchFields.get(key));
// }
//
// request.setFilter(query);
query = new Document();
for (String key : searchFields.keySet()) {
//query.put(key, searchFields.get(key));
query.put(key, new BasicDBObject("$eq", searchFields.get(key)));
}
request.setFilter(query);
}
System.out.println("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
System.out.println("Direction: " + sDirection);
System.out.println("Order by Fields: " + orderByFields);
System.out.println("Search for: " + query);
System.out.println("Search for Query to JSON: "+query.toJson());
Iterator<Concessione> concessioni = clientMongo.query(request);
if (concessioni != null) {
while (concessioni.hasNext()) {
Concessione concessione = (Concessione) concessioni.next();
System.out.println(concessione.getNome());
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
//@Test
public void readUserRights() throws Exception {