#22506 - Re-engineered the common utilities

This commit is contained in:
Francesco Mangiacrapa 2021-12-06 17:24:27 +01:00
parent d19f293930
commit 4120928540
29 changed files with 518 additions and 2032 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
@ -21,7 +22,8 @@
<wb-module deploy-name="geoportal-data-entry-app-2.1.0-SNAPSHOT">
@ -43,7 +45,8 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
@ -65,7 +68,8 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
@ -87,7 +91,11 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<dependent-module archiveName="geoportal-data-common-1.3.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-common/geoportal-data-common">
<dependency-type>uses</dependency-type>
</dependent-module>
@ -109,7 +117,8 @@
<property name="context-root" value="geoportal-data-entry-app"/>
@ -131,7 +140,8 @@
<property name="java-output-path" value="/geoportal-data-entry-app/target/geoportal-data-entry-app-2.0.0-SNAPSHOT/WEB-INF/classes"/>
@ -153,7 +163,8 @@
</wb-module>

View File

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

View File

@ -39,50 +39,50 @@ public class ConstantsGeoPortalDataEntryApp {
UPDATED_PROJECT
}
/**
* The Enum RECORD_FIELD.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Sep 2, 2021
*/
public static enum RECORD_FIELD {
NAME("nome", "Name"), INTRODUCTION("introduction", "Introduction"), AUTHOR("authors", "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;
/**
* Instantiates a new record field.
*
* @param jsonFieldName the json field name
* @param displayName the display name
*/
RECORD_FIELD(String jsonFieldName, String displayName) {
this.jsonFieldName = jsonFieldName;
this.displayName = displayName;
}
/**
* Gets the json field name.
*
* @return the json field name
*/
public String getJsonFieldName() {
return jsonFieldName;
}
/**
* Gets the display name.
*
* @return the display name
*/
public String getDisplayName() {
return displayName;
}
}
// /**
// * The Enum RECORD_FIELD.
// *
// * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
// *
// * Sep 2, 2021
// */
// public static enum RECORD_FIELD {
// NAME("nome", "Name"), INTRODUCTION("introduction", "Introduction"), AUTHOR("authors", "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;
//
// /**
// * Instantiates a new record field.
// *
// * @param jsonFieldName the json field name
// * @param displayName the display name
// */
// RECORD_FIELD(String jsonFieldName, String displayName) {
// this.jsonFieldName = jsonFieldName;
// this.displayName = displayName;
// }
//
// /**
// * Gets the json field name.
// *
// * @return the json field name
// */
// public String getJsonFieldName() {
// return jsonFieldName;
// }
//
// /**
// * Gets the display name.
// *
// * @return the display name
// */
// public String getDisplayName() {
// return displayName;
// }
// }
}

View File

@ -8,11 +8,17 @@ import java.util.List;
import java.util.TreeMap;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER;
import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM;
import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole;
import org.gcube.application.geoportalcommon.shared.config.RoleRights;
import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.model.RecordDV;
import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM;
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.events.ActionOnItemEvent;
import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEventHandler;
@ -38,15 +44,9 @@ 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;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.NewBrowserWindow;
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.GcubeUserRole;
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.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;
@ -107,26 +107,68 @@ public class GeoPortalDataEntryApp implements EntryPoint {
private UserRights myRights = null;
private LoaderIcon loader = new LoaderIcon("Loading Application...");
private List<ItemField> displayFields = new ArrayList<ItemField>();
private List<ItemField> sortByFields = new ArrayList<ItemField>();
private List<ItemField> searchByFields = new ArrayList<ItemField>();
/**
* This is the entry point method.
*/
public void onModuleLoad() {
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 };
SearchingFilter initialSortFilter = new SearchingFilter(RECORD_FIELD.NAME, ORDER.ASC);
RECORD_FIELD[] searchForFields = new RECORD_FIELD[] { RECORD_FIELD.NAME, RECORD_FIELD.AUTHOR};
// 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 };
//
// SearchingFilter initialSortFilter = new SearchingFilter(RECORD_FIELD.NAME, ORDER.ASC);
//
// RECORD_FIELD[] searchForFields = new RECORD_FIELD[] { RECORD_FIELD.NAME, RECORD_FIELD.AUTHOR};
RootPanel.get(DIV_PORTLET_ID).add(loader);
mainTabPanel = new GeonaMainTabPanel(appManagerBus, sortByOptions, searchForFields, initialSortFilter);
mainTabPanel.setLoaderVisible("Loading...", true);
geoNaMainForm = new GeonaDataEntryMainForm(appManagerBus);
mainTabPanel.addFormPanel(geoNaMainForm);
GeoportalDataEntryServiceAsync.Util.getInstance().listDisplayFields(new AsyncCallback<List<ItemField>>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(List<ItemField> result) {
for (ItemField itemField : result) {
if(itemField.isDisplayIntoTable()) {
displayFields.add(itemField);
}
if(itemField.isSearchable()) {
searchByFields.add(itemField);
}
if(itemField.isSortable()) {
sortByFields.add(itemField);
}
}
GWT.log("List display fields: "+result);
SearchingFilter initialSortFilter = new SearchingFilter();
initialSortFilter.setOrder(ORDER.ASC);
initialSortFilter.setOrderByFields(Arrays.asList(new ItemField("Name", Arrays.asList("name"), true, true, true)));
displayFields = result;
mainTabPanel = new GeonaMainTabPanel(appManagerBus, displayFields, sortByFields, searchByFields, initialSortFilter);
mainTabPanel.setLoaderVisible("Loading...", true);
geoNaMainForm = new GeonaDataEntryMainForm(appManagerBus);
mainTabPanel.addFormPanel(geoNaMainForm);
}
});
GeoportalDataEntryServiceAsync.Util.getInstance().getMyRightsInTheContext(new AsyncCallback<UserRights>() {
@ -505,7 +547,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
if (sortFilter == null) {
sortFilter = mainTabPanel.getCurrentSortFilter();
}
grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, null, sortFilter);
grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, displayFields, sortFilter);
mainTabPanel.showListOfConcessioniView(grpw);
}
});

View File

@ -3,6 +3,9 @@ package org.gcube.portlets.user.geoportaldataentry.client;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV;
import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV;
@ -10,8 +13,6 @@ import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataE
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.SearchingFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
@ -139,4 +140,11 @@ public interface GeoportalDataEntryService extends RemoteService {
*/
UserRights getMyRightsInTheContext() throws Exception;
/**
* List display fields.
*
* @return the list
*/
List<ItemField> listDisplayFields();
}

View File

@ -3,6 +3,9 @@ package org.gcube.portlets.user.geoportaldataentry.client;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV;
import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV;
@ -10,8 +13,6 @@ import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataE
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.SearchingFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
@ -78,4 +79,7 @@ public interface GeoportalDataEntryServiceAsync
void getMyRightsInTheContext(AsyncCallback<UserRights> callback);
void listDisplayFields(AsyncCallback<List<ItemField>> callback);
}

View File

@ -2,8 +2,8 @@ package org.gcube.portlets.user.geoportaldataentry.client.events;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM;
import org.gcube.application.geoportalcommon.shared.products.model.RecordDV;
import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM;
import com.google.gwt.event.shared.GwtEvent;

View File

@ -1,8 +1,8 @@
package org.gcube.portlets.user.geoportaldataentry.client.events;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
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.SearchingFilter;
import com.google.gwt.event.shared.GwtEvent;

View File

@ -1,20 +1,21 @@
package org.gcube.portlets.user.geoportaldataentry.client.ui;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER;
import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
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.events.ActionOnItemEvent;
import org.gcube.portlets.user.geoportaldataentry.client.events.CreateNewProjectEvent;
import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecordsEvent;
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.SearchingFilter;
import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter.ORDER;
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.Button;
@ -102,13 +103,13 @@ public class GeonaMainTabPanel extends Composite {
@UiField
Dropdown dropdownSortBy;
@UiField
Dropdown dropdownSearchFor;
@UiField
Alert alertSortBy;
@UiField
Alert alertSearchFor;
@ -132,14 +133,16 @@ public class GeonaMainTabPanel extends Composite {
private HandlerManager appManagerBus;
private RECORD_FIELD[] sortByFields;
private RECORD_FIELD[] searchForFields;
private List<ItemField> sortByFields;
private List<ItemField> searchForFields;
private SearchingFilter currentSortFilter;
private GeonaRecordsPaginatedView grpw = null;
private List<ItemField> displayFields;
/**
* Instantiates a new geona main tab panel.
*
@ -147,22 +150,24 @@ public class GeonaMainTabPanel extends Composite {
* @param sortByFields the sort by fields
* @param initialSortFilter
*/
public GeonaMainTabPanel(HandlerManager appManagerBus, RECORD_FIELD[] sortByFields, RECORD_FIELD[] searchForFields,
SearchingFilter initialSortFilter) {
public GeonaMainTabPanel(HandlerManager appManagerBus, List<ItemField> displayFields, List<ItemField> sortByFields,
List<ItemField> searchForFields, SearchingFilter initialSortFilter) {
initWidget(uiBinder.createAndBindUi(this));
this.appManagerBus = appManagerBus;
this.sortByFields = sortByFields;
this.displayFields = displayFields;
this.currentSortFilter = initialSortFilter;
this.searchForFields = searchForFields;
alertSortBy.setType(AlertType.INFO);
alertSortBy.setClose(false);
alertSearchFor.setType(AlertType.INFO);
alertSearchFor.setClose(false);
alertSearchFor.setText(searchForFields.get(0).getDisplayName());
alertSortBy.setText(toLabelFilter((initialSortFilter.getOrderByFields().get(0)), initialSortFilter.getOrder()));
alertSearchFor.setText(searchForFields[0].getDisplayName());
alertSortBy.setText(toLabelFilter(initialSortFilter.getOrderByField(), initialSortFilter.getOrder()));
bindEvents();
resetSearch.setIconSize(IconSize.TWO_TIMES);
resetSearch.setType(ButtonType.LINK);
@ -205,7 +210,7 @@ public class GeonaMainTabPanel extends Composite {
}
});
for (RECORD_FIELD record_FIELD : sortByFields) {
for (ItemField record_FIELD : sortByFields) {
// if (record_FIELD.equals(RECORD_FIELD.RECORD_STATUS))
// continue;
@ -238,8 +243,8 @@ public class GeonaMainTabPanel extends Composite {
}
});
}
for (RECORD_FIELD record_FIELD : searchForFields) {
for (ItemField record_FIELD : searchForFields) {
NavLink nav = new NavLink(record_FIELD.getDisplayName());
dropdownSearchFor.add(nav);
@ -249,16 +254,15 @@ public class GeonaMainTabPanel extends Composite {
@Override
public void onClick(ClickEvent event) {
alertSearchFor.setText(record_FIELD.getDisplayName());
if(searchField.getText().length() >= MIN_LENGHT_SERCHING_STRING) {
if (searchField.getText().length() >= MIN_LENGHT_SERCHING_STRING) {
doSearchEvent();
}
}
});
}
navShowOnMap.addClickHandler(new ClickHandler() {
@Override
@ -337,11 +341,11 @@ public class GeonaMainTabPanel extends Composite {
});
}
private void doSearchEvent() {
String searchText = searchField.getText();
if (searchText.length() < MIN_LENGHT_SERCHING_STRING) {
Window.alert("Please enter at least "+MIN_LENGHT_SERCHING_STRING+" characters");
Window.alert("Please enter at least " + MIN_LENGHT_SERCHING_STRING + " characters");
return;
}
@ -349,8 +353,8 @@ public class GeonaMainTabPanel extends Composite {
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
}
private String toLabelFilter(RECORD_FIELD orderBy, ORDER direction) {
String labelFilter = orderBy.getDisplayName() + LABEL_FILTER_SEPARATOR + direction.name();
private String toLabelFilter(ItemField itemField, ORDER direction) {
String labelFilter = itemField.getDisplayName() + LABEL_FILTER_SEPARATOR + direction.name();
return labelFilter;
}
@ -394,15 +398,15 @@ public class GeonaMainTabPanel extends Composite {
SearchingFilter sortFilter = null;
try {
RECORD_FIELD recordField = null;
for (RECORD_FIELD value : RECORD_FIELD.values()) {
ItemField recordField = null;
for (ItemField value : sortByFields) {
if (array[0].equalsIgnoreCase(value.getDisplayName())) {
recordField = value;
break;
}
}
ORDER orderField = ORDER.valueOf(array[1]);
sortFilter = new SearchingFilter(recordField, orderField);
sortFilter = new SearchingFilter(Arrays.asList(recordField), orderField);
} catch (Exception e) {
}
@ -416,12 +420,12 @@ public class GeonaMainTabPanel extends Composite {
String searchText = searchField.getText();
if (searchText != null && !searchText.isEmpty()) {
Map<String, Object> searchInto = new HashMap<String, Object>();
String searchForField = RECORD_FIELD.NAME.getJsonFieldName();
for (RECORD_FIELD recordField : searchForFields) {
if(recordField.getDisplayName().equals(alertSearchFor.getText())) {
searchForField = recordField.getJsonFieldName();
String searchForField = "";
for (ItemField recordField : searchForFields) {
if (recordField.getDisplayName().equals(alertSearchFor.getText())) {
searchForField = recordField.getJsonFields().get(0);
continue;
}
}
@ -451,7 +455,7 @@ public class GeonaMainTabPanel extends Composite {
*
*/
public void instanceAndShowListOfConcessioni() {
grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, null, currentSortFilter);
grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, displayFields, currentSortFilter);
showListOfConcessioniView(grpw);
}

View File

@ -2,15 +2,15 @@ package org.gcube.portlets.user.geoportaldataentry.client.ui;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
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.GeoPortalDataEntryApp;
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.SearchingFilter;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager;
@ -61,7 +61,7 @@ public class GeonaRecordsPaginatedView {
* @param currentSortFilter the sort by field
*/
public GeonaRecordsPaginatedView(HandlerManager eventbus, RECORD_TYPE recordType,
RECORD_FIELD[] displayFields, SearchingFilter currentSortFilter) {
List<ItemField> displayFields, SearchingFilter currentSortFilter) {
this.recordType = recordType;
this.currentSortFilter = currentSortFilter;
this.initClassFirstRangeChanged = true;

View File

@ -5,21 +5,18 @@ 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.ItemField;
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 com.github.gwtbootstrap.client.ui.ButtonCell;
import com.github.gwtbootstrap.client.ui.Pagination;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.cell.client.DateCell;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.shared.HandlerManager;
@ -52,21 +49,10 @@ public class ItemsTable<T extends ConcessioneDV> extends AbstractItemsCellTable<
private static final int ITEMS_PER_PAGE = 10;
private static final String NO_DATA = "No data";
private TextColumn<T> name;
private TextColumn<T> introduction;
private TextColumn<T> author;
public static DateTimeFormat dtformat = DateTimeFormat.getFormat(ConvertToDataViewModel.DATE_FORMAT);
private AbstractDataProvider<T> dataProvider;
private List<RECORD_FIELD> displayFields;
private TextColumn<T> startEndProjectColumn;
private TextColumn<T> statusColumn;
// private Column<T, Date> startProjectDateColumn;
// private Column<T, Date> endProjectDateColumn;
private List<ItemField> displayFields;
private boolean isAsyncronusTable;
private TextColumn<T> insertedBy;
private Column<T, Date> createdColumn;
/**
* Instantiates a new items table.
@ -75,9 +61,9 @@ 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) {
public ItemsTable(HandlerManager eventBus, List<ItemField> displayFields) {
this.eventBus = eventBus;
setDisplayFields(displayFields);
this.displayFields = displayFields;
}
/**
@ -106,15 +92,66 @@ public class ItemsTable<T extends ConcessioneDV> extends AbstractItemsCellTable<
this.isAsyncronusTable = dataProvider instanceof ListDataProvider ? false : true;
setEmptyTableMessage(NO_DATA);
if (this.displayFields.contains(RECORD_FIELD.NAME)) {
int i = 0;
for (ItemField itemField : displayFields) {
String displayName = itemField.getDisplayName();
// NAME
name = new TextColumn<T>() {
TextColumn<T> col = new TextColumn<T>() {
@Override
public String getValue(T object) {
if (object == null)
return "";
return ((ConcessioneDV) object).getNome();
if (displayName.equalsIgnoreCase("Name")) {
return ((ConcessioneDV) object).getNome();
} else if (displayName.equalsIgnoreCase("Introduction")) {
return ((ConcessioneDV) object).getIntroduzione();
} else if (displayName.equalsIgnoreCase("Author/s")) {
String toDisplay = "";
if (object.getAuthors() != null) {
toDisplay = toDisplayAuthors(((ConcessioneDV) object).getAuthors());
}
return toDisplay;
} else if (displayName.equalsIgnoreCase("Project Start/End Date")) {
Date dS = null;
Date dE = null;
if (object.getDataInizioProgetto() != null) {
dS = (((ConcessioneDV) object).getDataInizioProgetto());
}
if (object.getDataFineProgetto() != null) {
dE = (((ConcessioneDV) object).getDataFineProgetto());
}
String dateFormat = "";
if (dS != null) {
dateFormat += dtformat.format(dS);
}
dateFormat += " / ";
if (dE != null) {
dateFormat += dtformat.format(dE);
}
return dateFormat;
} else if (displayName.equalsIgnoreCase("Published with")) {
ValidationReportDV vr = ((ConcessioneDV) object).getValidationReport();
if (vr != null && vr.getStatus() != null)
return vr.getStatus().getLabel();
return "";
} else if (displayName.equalsIgnoreCase("Created")) {
Date cd = ((ConcessioneDV) object).getCreationTime();
return dtformat.format(cd);
} else if (displayName.equalsIgnoreCase("Created by")) {
return ((ConcessioneDV) object).getCreationUser();
}
return "";
}
// ADDING TOOLTIP
@ -122,240 +159,224 @@ public class ItemsTable<T extends ConcessioneDV> extends AbstractItemsCellTable<
public void render(com.google.gwt.cell.client.Cell.Context context, T object, SafeHtmlBuilder sb) {
if (object == null)
return;
sb.appendHtmlConstant("<div introduction=\"" + ((ConcessioneDV) object).getNome() + "\">");
super.render(context, object, sb);
sb.appendHtmlConstant("</div>");
if (displayName.equalsIgnoreCase("Published with")) {
String value = getValue(object);
String color = "#000";
if (value.compareTo(ValidationStatus.PASSED.getLabel()) == 0) {
color = "#32CD32";
} else if (value.compareTo(ValidationStatus.WARNING.getLabel()) == 0) {
color = "#FF8000";
} else if (value.compareTo(ValidationStatus.ERROR.getLabel()) == 0) {
color = "red";
}
sb.appendHtmlConstant("<span style=\"color:" + color + "\";>");
super.render(context, object, sb);
sb.appendHtmlConstant("</span>");
} else
super.render(context, object, sb);
};
};
sortedCellTable.addColumn(name, RECORD_FIELD.NAME.getDisplayName(), true);
if (!isAsyncronusTable) {
Comparator<T> c = new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
return ((ConcessioneDV) o1).getNome().compareTo(((ConcessioneDV) o2).getNome());
}
};
sortedCellTable.setComparator(name, c);
if(i==0) {
//name
sortedCellTable.setColumnWidth(col, 20, Unit.PCT);
}else if (i == 1) {
// intro
sortedCellTable.setColumnWidth(col, 30, Unit.PCT);
} else if (i == 2) {
sortedCellTable.setColumnWidth(col, 15, Unit.PCT);
}else if(i==displayFields.size()-1) {
sortedCellTable.setColumnWidth(col, 120, Unit.PX);
}
sortedCellTable.addColumn(col, itemField.getDisplayName(), true);
i++;
}
if (this.displayFields.contains(RECORD_FIELD.INTRODUCTION)) {
introduction = new TextColumn<T>() {
@Override
public String getValue(T object) {
if (object == null)
return "";
return ((ConcessioneDV) object).getIntroduzione() != null
? ((ConcessioneDV) object).getIntroduzione()
: "";
}
};
sortedCellTable.addColumn(introduction, RECORD_FIELD.INTRODUCTION.getDisplayName(), true);
if (!isAsyncronusTable) {
Comparator<T> c = new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
return ((ConcessioneDV) o1).getIntroduzione().compareTo(((ConcessioneDV) o2).getIntroduzione());
}
};
sortedCellTable.setComparator(introduction, c);
}
// sortedCellTable.setColumnWidth(introduction, 100, Unit.PCT);
}
if (this.displayFields.contains(RECORD_FIELD.AUTHOR)) {
author = new TextColumn<T>() {
@Override
public String getValue(T object) {
if (object == null)
return "";
String toDisplay = toDisplayAuthors(((ConcessioneDV) object).getAuthors());
return toDisplay;
}
};
sortedCellTable.addColumn(author, RECORD_FIELD.AUTHOR.getDisplayName(), true);
if (!isAsyncronusTable) {
Comparator<T> c = new Comparator<T>() {
@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);
}
sortedCellTable.setColumnWidth(author, 220, Unit.PX);
}
if (this.displayFields.contains(RECORD_FIELD.PROJECT_START_END_DATE)) {
startEndProjectColumn = new TextColumn<T>() {
@Override
public String getValue(T object) {
if (object == null)
return "";
Date dS = null;
Date dE = null;
if(object.getDataInizioProgetto()!=null) {
dS = (((ConcessioneDV) object).getDataInizioProgetto());
}
if(object.getDataFineProgetto()!=null) {
dE = (((ConcessioneDV) object).getDataFineProgetto());
}
String dateFormat = "";
if(dS!=null) {
dateFormat+=dtformat.format(dS);
}
dateFormat+=" / ";
if(dE!=null) {
dateFormat+=dtformat.format(dE);
}
return dateFormat;
}
};
sortedCellTable.addColumn(startEndProjectColumn, RECORD_FIELD.PROJECT_START_END_DATE.getDisplayName(),
false);
sortedCellTable.setColumnWidth(startEndProjectColumn, 180, Unit.PX);
}
if (this.displayFields.contains(RECORD_FIELD.CREATED)) {
DateCell date = new DateCell(DateTimeFormat.getFormat(ConvertToDataViewModel.DATE_FORMAT+" "+ConvertToDataViewModel.TIME_FORMAT));
createdColumn = new Column<T, Date>(date) {
@Override
public Date getValue(T object) {
if (object == null)
return null;
return (((ConcessioneDV) object).getCreationTime());
}
};
sortedCellTable.addColumn(createdColumn, RECORD_FIELD.CREATED.getDisplayName(), true);
if (!isAsyncronusTable) {
Comparator<T> c = new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
if (o1 == null)
return -1;
if (o2 == null)
return 1;
Date d1 = (((ConcessioneDV) o1).getCreationTime());
Date d2 = (((ConcessioneDV) o2).getCreationTime());
// 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(createdColumn, c);
}
sortedCellTable.setColumnWidth(createdColumn, 150, Unit.PX);
}
if (this.displayFields.contains(RECORD_FIELD.CREATED_BY)) {
// NAME
insertedBy = new TextColumn<T>() {
@Override
public String getValue(T object) {
if (object == null)
return "";
return ((ConcessioneDV) object).getCreationUser();
}
};
sortedCellTable.addColumn(insertedBy, RECORD_FIELD.CREATED_BY.getDisplayName(), true);
if (!isAsyncronusTable) {
Comparator<T> c = new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
return ((ConcessioneDV) o1).getCreationUser().compareTo(((ConcessioneDV) o2).getCreationUser());
}
};
sortedCellTable.setComparator(insertedBy, c);
}
sortedCellTable.setColumnWidth(insertedBy, 220, Unit.PX);
}
if (this.displayFields.contains(RECORD_FIELD.RECORD_STATUS)) {
statusColumn = new TextColumn<T>() {
@Override
public String getValue(T object) {
if (object == null)
return "";
ValidationReportDV vr = ((ConcessioneDV) object).getValidationReport();
if (vr != null && vr.getStatus() != null)
return vr.getStatus().getLabel();
return "";
}
@Override
public void render(Context context, T object, SafeHtmlBuilder sb) {
// TODO Auto-generated method stub
String value = getValue(object);
String color = "#000";
if (value.compareTo(ValidationStatus.PASSED.getLabel()) == 0) {
color = "#32CD32";
} else if (value.compareTo(ValidationStatus.WARNING.getLabel()) == 0) {
color = "#FF8000";
} else if (value.compareTo(ValidationStatus.ERROR.getLabel()) == 0) {
color = "red";
}
sb.appendHtmlConstant("<span style=\"color:" + color + "\";>");
super.render(context, object, sb);
sb.appendHtmlConstant("</span>");
}
};
sortedCellTable.addColumn(statusColumn, RECORD_FIELD.RECORD_STATUS.getDisplayName(), false);
sortedCellTable.setColumnWidth(statusColumn, 120, Unit.PX);
}
/*
* if (this.displayFields.contains(RECORD_FIELD.NAME)) {
*
* // NAME name = new TextColumn<T>() {
*
* @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("<div introduction=\"" + ((ConcessioneDV)
* object).getNome() + "\">"); super.render(context, object, sb);
* sb.appendHtmlConstant("</div>"); }; };
*
* sortedCellTable.addColumn(name, RECORD_FIELD.NAME.getDisplayName(), true);
*
* if (!isAsyncronusTable) { Comparator<T> c = new Comparator<T>() {
*
* @Override public int compare(T o1, T o2) { return ((ConcessioneDV)
* o1).getNome().compareTo(((ConcessioneDV) o2).getNome()); } };
*
* sortedCellTable.setComparator(name, c); }
*
* }
*
* if (this.displayFields.contains(RECORD_FIELD.INTRODUCTION)) {
*
* introduction = new TextColumn<T>() {
*
* @Override public String getValue(T object) { if (object == null) return "";
* return ((ConcessioneDV) object).getIntroduzione() != null ? ((ConcessioneDV)
* object).getIntroduzione() : ""; } };
*
* sortedCellTable.addColumn(introduction,
* RECORD_FIELD.INTRODUCTION.getDisplayName(), true);
*
* if (!isAsyncronusTable) { Comparator<T> c = new Comparator<T>() {
*
* @Override public int compare(T o1, T o2) { return ((ConcessioneDV)
* o1).getIntroduzione().compareTo(((ConcessioneDV) o2).getIntroduzione()); } };
* sortedCellTable.setComparator(introduction, c); }
*
* // sortedCellTable.setColumnWidth(introduction, 100, Unit.PCT);
*
* }
*
* if (this.displayFields.contains(RECORD_FIELD.AUTHOR)) {
*
* author = new TextColumn<T>() {
*
* @Override public String getValue(T object) { if (object == null) return "";
*
* String toDisplay = toDisplayAuthors(((ConcessioneDV) object).getAuthors());
* return toDisplay; } };
*
* sortedCellTable.addColumn(author, RECORD_FIELD.AUTHOR.getDisplayName(),
* true);
*
* if (!isAsyncronusTable) { Comparator<T> c = new Comparator<T>() {
*
* @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); }
*
* sortedCellTable.setColumnWidth(author, 220, Unit.PX);
*
* }
*
* if (this.displayFields.contains(RECORD_FIELD.PROJECT_START_END_DATE)) {
*
* startEndProjectColumn = new TextColumn<T>() {
*
* @Override public String getValue(T object) { if (object == null) return "";
*
* Date dS = null; Date dE = null; if(object.getDataInizioProgetto()!=null) { dS
* = (((ConcessioneDV) object).getDataInizioProgetto()); }
*
* if(object.getDataFineProgetto()!=null) { dE = (((ConcessioneDV)
* object).getDataFineProgetto()); }
*
* String dateFormat = ""; if(dS!=null) { dateFormat+=dtformat.format(dS); }
*
* dateFormat+=" / ";
*
* if(dE!=null) { dateFormat+=dtformat.format(dE); }
*
* return dateFormat; } };
*
* sortedCellTable.addColumn(startEndProjectColumn,
* RECORD_FIELD.PROJECT_START_END_DATE.getDisplayName(), false);
* sortedCellTable.setColumnWidth(startEndProjectColumn, 180, Unit.PX);
*
* }
*
* if (this.displayFields.contains(RECORD_FIELD.CREATED)) {
*
* DateCell date = new
* DateCell(DateTimeFormat.getFormat(ConvertToDataViewModel.DATE_FORMAT+" "
* +ConvertToDataViewModel.TIME_FORMAT)); createdColumn = new Column<T,
* Date>(date) {
*
* @Override public Date getValue(T object) { if (object == null) return null;
*
* return (((ConcessioneDV) object).getCreationTime()); } };
* sortedCellTable.addColumn(createdColumn,
* RECORD_FIELD.CREATED.getDisplayName(), true);
*
* if (!isAsyncronusTable) { Comparator<T> c = new Comparator<T>() {
*
* @Override public int compare(T o1, T o2) { if (o1 == null) return -1;
*
* if (o2 == null) return 1;
*
* Date d1 = (((ConcessioneDV) o1).getCreationTime()); Date d2 =
* (((ConcessioneDV) o2).getCreationTime());
*
* // 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(createdColumn,
* c); }
*
* sortedCellTable.setColumnWidth(createdColumn, 150, Unit.PX);
*
* }
*
* if (this.displayFields.contains(RECORD_FIELD.CREATED_BY)) {
*
* // NAME insertedBy = new TextColumn<T>() {
*
* @Override public String getValue(T object) { if (object == null) return "";
* return ((ConcessioneDV) object).getCreationUser(); } };
*
* sortedCellTable.addColumn(insertedBy,
* RECORD_FIELD.CREATED_BY.getDisplayName(), true);
*
* if (!isAsyncronusTable) { Comparator<T> c = new Comparator<T>() {
*
* @Override public int compare(T o1, T o2) { return ((ConcessioneDV)
* o1).getCreationUser().compareTo(((ConcessioneDV) o2).getCreationUser()); } };
*
* sortedCellTable.setComparator(insertedBy, c); }
* sortedCellTable.setColumnWidth(insertedBy, 220, Unit.PX); }
*
* if (this.displayFields.contains(RECORD_FIELD.RECORD_STATUS)) {
*
* statusColumn = new TextColumn<T>() {
*
* @Override public String getValue(T object) { if (object == null) return "";
*
* ValidationReportDV vr = ((ConcessioneDV) object).getValidationReport(); if
* (vr != null && vr.getStatus() != null) return vr.getStatus().getLabel();
* return ""; }
*
* @Override public void render(Context context, T object, SafeHtmlBuilder sb) {
* // TODO Auto-generated method stub
*
* String value = getValue(object); String color = "#000"; if
* (value.compareTo(ValidationStatus.PASSED.getLabel()) == 0) { color =
* "#32CD32"; } else if (value.compareTo(ValidationStatus.WARNING.getLabel()) ==
* 0) { color = "#FF8000"; } else if
* (value.compareTo(ValidationStatus.ERROR.getLabel()) == 0) { color = "red"; }
* sb.appendHtmlConstant("<span style=\"color:" + color + "\";>");
* super.render(context, object, sb); sb.appendHtmlConstant("</span>");
*
* } };
*
* sortedCellTable.addColumn(statusColumn,
* RECORD_FIELD.RECORD_STATUS.getDisplayName(), false);
* sortedCellTable.setColumnWidth(statusColumn, 120, Unit.PX);
*
* }
*/
}
public void enableWriteOperations() {
}
/**
@ -398,15 +419,15 @@ public class ItemsTable<T extends ConcessioneDV> extends AbstractItemsCellTable<
}
}
/**
* Sets the display fields.
*
* @param fields the new display fields
*/
public void setDisplayFields(RECORD_FIELD[] fields) {
this.displayFields = fields != null && fields.length > 0 ? Arrays.asList(fields)
: Arrays.asList(RECORD_FIELD.values());
}
// /**
// * Sets the display fields.
// *
// * @param fields the new display fields
// */
// public void setDisplayFields(List<ItemField> fields) {
// this.displayFields = fields != null && fields.size() > 0 ? Arrays.asList(fields)
// : Arrays.asList(RECORD_FIELD.values());
// }
/**
* Reset columns table.
@ -424,7 +445,7 @@ public class ItemsTable<T extends ConcessioneDV> extends AbstractItemsCellTable<
*
* @return the displayFields
*/
public List<RECORD_FIELD> getDisplayFields() {
public List<ItemField> getDisplayFields() {
return displayFields;
}

View File

@ -1,13 +1,10 @@
package org.gcube.portlets.user.geoportaldataentry.server;
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.AbstractRelazione;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths;
@ -16,39 +13,34 @@ 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;
import org.gcube.application.geoportalcommon.GeoportalCommon;
import org.gcube.application.geoportalcommon.MongoServiceCommon;
import org.gcube.application.geoportalcommon.config.GNADataConfigProfileReader;
import org.gcube.application.geoportalcommon.shared.GNADataConfigProfile;
import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM;
import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole;
import org.gcube.application.geoportalcommon.shared.config.RoleRights;
import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE;
import org.gcube.application.geoportalcommon.shared.exception.GNAUserRightsConfigException;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV;
import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV;
import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV;
import org.gcube.common.portal.PortalContext;
import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitle;
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.config.GNADataEntryConfigs;
import org.gcube.portlets.user.geoportaldataentry.server.config.GNADataEntryConfigsProfileReader;
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;
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.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;
@ -62,8 +54,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;
/**
* The server side implementation of the RPC service.
@ -416,195 +406,6 @@ 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);
Document query = null;
if(filter.getSearchInto()!=null) {
Map<String, Object> searchFields = filter.getSearchInto();
//List<BasicDBObject> list = new ArrayList<BasicDBObject>();
//Map map = new HashMap<BasicDBObject, BasicDBObject>();
BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
for (String key : searchFields.keySet()) {
// query.put(key, searchFields.get(key));
// query.put(key, new BasicDBObject("$eq", searchFields.get(key)));
BasicDBObject bs = new BasicDBObject();
bs.append("$regex", searchFields.get(key));
bs.append("$options", "i");
builder.append(key, bs);
}
query = new Document(builder.get().toMap());
// BasicDBList list = new BasicDBList();
// list.add(builder.get().toMap());
// query.put("$and", list);
//or(query);
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());
if(query!=null) {
LOG.info("Search query to JSON: " + query.toJson());
}
Iterator<Concessione> concessioni = clientMongo.query(request);
int i = 0;
while (concessioni.hasNext()) {
Concessione concessione = concessioni.next();
ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true);
toReturnList.add(concessioneDV);
i++;
}
LOG.debug("read " + toReturnList +" project/s");
searchedData.setData(toReturnList);
//TODO WORKAROUND MUST BE REMOVE AFTER THE QUERY COUNT
// AND LIST.SIZE WILL BE AVAILABLE IN THE SERVICE
if(filter.getSearchInto()!=null){
searchedData.setTotalItems(toReturnList.size());
}
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.
*
@ -619,7 +420,29 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SearchingFilter filter,
boolean reloadFromService) throws Exception {
LOG.info("getListConcessioni called wit start: " + start + ", limit: " + limit + ", filter: " + filter);
return queryOnMongo(start, limit, filter, "concessione", reloadFromService);
try {
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
MongoServiceCommon serviceCommon = new MongoServiceCommon();
// 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();
ResultSetPaginatedData searchedData = serviceCommon.queryOnMongo(listConcessioniSize, start, limit, filter,
"concessione");
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());
}
}
/**
@ -921,13 +744,13 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
PortalContext pContext = PortalContext.getConfiguration();
user = pContext.getCurrentUser(this.getThreadLocalRequest());
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
GNADataEntryConfigsProfileReader gnaConfigReader = new GNADataEntryConfigsProfileReader();
GNADataEntryConfigs config = gnaConfigReader.readProfileFromInfrastrucure();
List<RoleRights> listUserRightsForRole = config.getPermissionsForRole();
GNADataConfigProfileReader gnaConfigReader = new GNADataConfigProfileReader();
GNADataConfigProfile config = gnaConfigReader.readProfileFromInfrastrucure();
List<RoleRights> listUserRightsForRole = config.getPermissionsForRole();
// DEV MODE
if (!SessionUtil.isIntoPortal()) {
LOG.warn("OUT OF PORTAL - DEV MODE detected");
GcubeUserRole myRole = GcubeUserRole.DATA_EDITOR;
GcubeUserRole myRole = GcubeUserRole.DATA_MEMBER;
for (RoleRights roleRight : listUserRightsForRole) {
if (roleRight.getUserRole().equals(myRole)) {
@ -997,4 +820,16 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
}
// TODO THIS PART REQUIRES THE JSON MAPPING based on keys read from gCube Meta
/**
* List display fields.
*
* @return the list
*/
@Override
public List<ItemField> listDisplayFields() {
GeoportalCommon gc = new GeoportalCommon();
return gc.getGNADataConfig().getListItemFields();
}
}

View File

@ -23,7 +23,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class MongoServiceUtil.
* The Class MongoServiceCommon.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*

View File

@ -1,152 +0,0 @@
/**
*
*/
package org.gcube.portlets.user.geoportaldataentry.server.config;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* The Class CSVFile.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Jan 29, 2019
*/
public class CSVFile implements Serializable{
/**
*
*/
private static final long serialVersionUID = 6408321963787244600L;
private CSVRow headerRow;
private List<CSVRow> valueRows;
private String fileName;
/**
* Instantiates a new CSV file.
*/
public CSVFile(){
}
/**
* Instantiates a new csv file.
*
* @param fileName the file name
* @param headerRow the header row
* @param valueRows the value rows
*/
public CSVFile(String fileName, CSVRow headerRow, List<CSVRow> valueRows) {
this.fileName = fileName;
this.headerRow = headerRow;
this.valueRows = valueRows;
}
/**
* Gets the header row.
*
* @return the headerRow
*/
public CSVRow getHeaderRow() {
return headerRow;
}
/**
* Adds the value row.
*
* @param row the row
*/
public void addValueRow(CSVRow row) {
if(valueRows==null)
valueRows = new ArrayList<CSVRow>();
valueRows.add(row);
}
/**
* Sets the value rows.
*
* @param valueRows the new value rows
*/
public void setValueRows(List<CSVRow> valueRows) {
this.valueRows = valueRows;
}
/**
* Gets the value rows.
*
* @return the valueRows
*/
public List<CSVRow> getValueRows() {
return valueRows;
}
/**
* Sets the header row.
*
* @param headerRow the headerRow to set
*/
public void setHeaderRow(CSVRow headerRow) {
this.headerRow = headerRow;
}
/**
* Gets the file name.
*
* @return the fileName
*/
public String getFileName() {
return fileName;
}
/**
* Sets the file name.
*
* @param fileName the fileName to set
*/
public void setFileName(String fileName) {
this.fileName = fileName;
}
/**
* To string.
*
* @return the string
*/
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("CSVFile [headerRow=");
builder.append(headerRow);
builder.append(", valueRows=");
builder.append(valueRows);
builder.append(", fileName=");
builder.append(fileName);
builder.append("]");
return builder.toString();
}
}

View File

@ -1,192 +0,0 @@
/**
*
*/
package org.gcube.portlets.user.geoportaldataentry.server.config;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* The Class CSVReader.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Jan 29, 2019
*/
public class CSVReader {
public static final char DEFAULT_SEPARATOR = ',';
public static final char DEFAULT_QUOTE = '"';
private File file;
private CSVFile csvFile;
/**
* Instantiates a new CSV reader.
*
* @param file the file
* @throws FileNotFoundException the file not found exception
*/
public CSVReader(File file) throws FileNotFoundException {
this.file = file;
this.csvFile = new CSVFile();
readCSV(file);
}
/**
* Read csv.
*
* @param file the file
* @throws FileNotFoundException the file not found exception
*/
private void readCSV(File file) throws FileNotFoundException {
Scanner scanner = new Scanner(file);
csvFile.setFileName(file.getName());
int i = 0;
while (scanner.hasNext()) {
CSVRow csvRow = new CSVRow();
List<String> line = parseLine(scanner.nextLine());
csvRow.setListValues(line);
if(i==0){
csvFile.setHeaderRow(csvRow);
}else{
csvFile.addValueRow(csvRow);
}
i++;
}
scanner.close();
}
/**
* Parses the line.
*
* @param cvsLine the cvs line
* @return the list
*/
public static List<String> parseLine(String cvsLine) {
return parseLine(cvsLine, DEFAULT_SEPARATOR, DEFAULT_QUOTE);
}
/**
* Parses the line.
*
* @param cvsLine the cvs line
* @param separators the separators
* @return the list
*/
public static List<String> parseLine(String cvsLine, char separators) {
return parseLine(cvsLine, separators, DEFAULT_QUOTE);
}
/**
* Parses the line.
*
* @param cvsLine the cvs line
* @param separators the separators
* @param customQuote the custom quote
* @return the list
*/
private static List<String> parseLine(String cvsLine, char separators, char customQuote) {
List<String> result = new ArrayList<>();
// if empty, return!
if (cvsLine == null || cvsLine.isEmpty()) {
return result;
}
if (customQuote == ' ') {
customQuote = DEFAULT_QUOTE;
}
if (separators == ' ') {
separators = DEFAULT_SEPARATOR;
}
StringBuffer curVal = new StringBuffer();
boolean inQuotes = false;
boolean startCollectChar = false;
boolean doubleQuotesInColumn = false;
char[] chars = cvsLine.toCharArray();
for (char ch : chars) {
if (inQuotes) {
startCollectChar = true;
if (ch == customQuote) {
inQuotes = false;
doubleQuotesInColumn = false;
}
else {
// Fixed : allow "" in custom quote enclosed
if (ch == '\"') {
if (!doubleQuotesInColumn) {
curVal.append(ch);
doubleQuotesInColumn = true;
}
}
else {
curVal.append(ch);
}
}
}
else {
if (ch == customQuote) {
inQuotes = true;
// Fixed : allow "" in empty quote enclosed
if (chars[0] != '"' && customQuote == '\"') {
curVal.append('"');
}
// double quotes in column will hit this!
if (startCollectChar) {
curVal.append('"');
}
}
else if (ch == separators) {
result.add(curVal.toString());
curVal = new StringBuffer();
startCollectChar = false;
}
else if (ch == '\r') {
// ignore LF characters
continue;
}
else if (ch == '\n') {
// the end, break!
break;
}
else {
curVal.append(ch);
}
}
}
result.add(curVal.toString());
return result;
}
/**
* Gets the csv file.
*
* @return the csvFile
*/
public CSVFile getCsvFile() {
return csvFile;
}
/**
* Gets the file.
*
* @return the file
*/
public File getFile() {
return file;
}
}

View File

@ -1,81 +0,0 @@
/**
*
*/
package org.gcube.portlets.user.geoportaldataentry.server.config;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* The Class CSVRow.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Jan 29, 2019
*/
public class CSVRow implements Serializable{
/**
*
*/
private static final long serialVersionUID = 6254861811998867626L;
private List<String> listValues;
/**
* Instantiates a new CSV row.
*/
public CSVRow(){
}
/**
* Gets the list values.
*
* @return the listValues
*/
public List<String> getListValues() {
return listValues;
}
/**
* @param listValues the listValues to set
*/
public void setListValues(List<String> listValues) {
this.listValues = listValues;
}
/**
* Adds the value.
*
* @param value the value
*/
public void addValue(String value) {
if(listValues==null)
listValues = new ArrayList<String>();
listValues.add(value);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("CSVRow [listValues=");
builder.append(listValues);
builder.append("]");
return builder.toString();
}
}

View File

@ -1,100 +0,0 @@
package org.gcube.portlets.user.geoportaldataentry.server.config;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
/**
* The Class FileUtil.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Dec 2, 2021
*/
public class FileUtil {
/**
* Input stream to temp file.
*
* @param inputStream the input stream
* @param fileName the file name
* @return the file
* @throws IOException Signals that an I/O exception has occurred.
*/
// InputStream -> Temp File
public static File inputStreamToTempFile(InputStream inputStream, String fileName) throws IOException {
File tempFile = File.createTempFile(fileName, ".tmp");
// File tempFile = File.createTempFile("MyAppName-", ".tmp");
try (FileOutputStream outputStream = new FileOutputStream(tempFile)) {
int read;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
return tempFile;
} finally {
tempFile.deleteOnExit();
}
}
/**
* Input stream to temp file.
*
* @param copyString the copy string
* @return
* @throws IOException Signals that an I/O exception has occurred.
*/
public static File inputStreamToTempFile(String copyString, String prefixFile) throws IOException {
File targetFile = null;
try {
InputStream initialStream = new ByteArrayInputStream(copyString.getBytes());
targetFile = File.createTempFile(prefixFile, ".tmp");
java.nio.file.Files.copy(initialStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
try {
if (initialStream != null) {
initialStream.close();
}
} catch (IOException ioe) {
// ignore
}
return targetFile;
} finally {
try {
if (targetFile != null)
targetFile.deleteOnExit();
} catch (Exception e) {
}
}
}
/**
* Copy input stream to file.
*
* @param is the is
* @param to the to
* @return the file
* @throws IOException Signals that an I/O exception has occurred.
*/
public static File copyInputStreamToFile(InputStream is, String to) throws IOException {
Path dest = Paths.get(to);
Files.copy(is, dest);
return new File(to);
}
}

View File

@ -1,38 +0,0 @@
package org.gcube.portlets.user.geoportaldataentry.server.config;
import java.util.List;
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights;
public class GNADataEntryConfigs {
List<RoleRights> permissionsForRole = null;
public GNADataEntryConfigs() {
}
public GNADataEntryConfigs(List<RoleRights> permissionsForRole) {
super();
this.permissionsForRole = permissionsForRole;
}
public List<RoleRights> getPermissionsForRole() {
return permissionsForRole;
}
public void setPermissionsForRole(List<RoleRights> permissionsForRole) {
this.permissionsForRole = permissionsForRole;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GNADataEntryConfigs [permissionsForRole=");
builder.append(permissionsForRole);
builder.append("]");
return builder.toString();
}
}

View File

@ -1,282 +0,0 @@
package org.gcube.portlets.user.geoportaldataentry.server.config;
import static org.gcube.resources.discovery.icclient.ICFactory.client;
import java.io.File;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.gcube.application.geoportalcommon.shared.exception.ApplicationProfileNotFoundException;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM;
import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigException;
import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole;
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights;
import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.Query;
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
/**
* The Class GNADataEntryConfigsProfileReader.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Dec 2, 2021
*/
public class GNADataEntryConfigsProfileReader {
private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body";
public static final String SECONDARY_TYPE = "ApplicationProfile";
public static final String GENERIC_RESOURCE_NAME = "GNA-DataEntry-Configs";
private static final String TEMP_ROLE_RIGHTS_CONFIG_FILENAME = "GNA_RoleRights_Configurations";
private String scope;
private static final Logger LOG = LoggerFactory.getLogger(GNADataEntryConfigsProfileReader.class);
/**
* Instantiates a new application profile reader.
*/
public GNADataEntryConfigsProfileReader() {
}
/**
* Read profile from infrastrucure.
*
* @return the map
* @throws Exception the exception
*/
public GNADataEntryConfigs readProfileFromInfrastrucure() throws Exception {
LOG.info("called readProfileFromInfrastrucure");
String queryString = getGcubeGenericQueryString(SECONDARY_TYPE, GENERIC_RESOURCE_NAME);
LOG.info("Scope " + scope + ", trying to perform query: " + queryString);
this.scope = ScopeProvider.instance.get();
if (scope == null)
throw new Exception("Scope is null, set scope into ScopeProvider");
GNADataEntryConfigs gnDEC = new GNADataEntryConfigs();
String permissions_for_role = "";
try {
LOG.info("Trying to fetch GR named: " + GENERIC_RESOURCE_NAME + ", in the scope: " + scope
+ ", SecondaryType: " + SECONDARY_TYPE);
Query q = new QueryBox(queryString);
DiscoveryClient<String> client = client();
List<String> appProfile = client.submit(q);
if (appProfile == null || appProfile.size() == 0)
throw new ApplicationProfileNotFoundException("GR with SecondaryType: " + SECONDARY_TYPE
+ ", and name: " + GENERIC_RESOURCE_NAME + " is not registered in the scope: " + scope);
else {
String elem = appProfile.get(0);
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = docBuilder.parse(new InputSource(new StringReader(elem)));
XPathHelper helper = new XPathHelper(doc.getDocumentElement());
List<String> currValue = null;
String xPathExp = RESOURCE_PROFILE_BODY + "/permssions_for_role/text()";
currValue = helper.evaluate(xPathExp);
if (currValue != null && currValue.size() > 0) {
permissions_for_role = currValue.get(0);
} else
throw new Exception("I'm not able to read the path: " + xPathExp);
//replacing \n with new_line string
LOG.debug("read permissions_for_role: " + permissions_for_role);
String pfr_with_new_lines = permissions_for_role.replaceAll("\\\\n", System.lineSeparator());
LOG.debug("permissions_for_role with new lines: " + pfr_with_new_lines);
List<RoleRights> listRoleRights = readRoleRightsConfig(pfr_with_new_lines);
gnDEC.setPermissionsForRole(listRoleRights);
LOG.info("returning: " + gnDEC);
return gnDEC;
}
} catch (Exception e) {
LOG.error("Error while trying to read the " + SECONDARY_TYPE + " with SecondaryType "
+ GENERIC_RESOURCE_NAME + " from scope " + scope, e);
return null;
} finally {
}
}
/**
* To gcube user role.
*
* @param name the name
* @return the gcube user role
*/
public static GcubeUserRole toGcubeUserRole(String name) {
for (GcubeUserRole gCubeUserRole : GcubeUserRole.values()) {
if (gCubeUserRole.getName().equalsIgnoreCase(name))
return gCubeUserRole;
}
return null;
}
/**
* Read user rights config.
*
* @param permissions_for_role the permissions for role
* @return the list
* @throws GNAUserRightsConfigException the GNA user rights config not found
* exception
*/
public List<RoleRights> readRoleRightsConfig(String permissions_for_role) throws GNAUserRightsConfigException {
LOG.debug("readRoleRightsConfig called");
File configurationFile = null;
List<RoleRights> listUserRights = new ArrayList<RoleRights>();
try {
configurationFile = FileUtil.inputStreamToTempFile(permissions_for_role, TEMP_ROLE_RIGHTS_CONFIG_FILENAME);
CSVReader reader = new CSVReader(configurationFile);
CSVFile csvFile = reader.getCsvFile();
List<String> headerKeys = csvFile.getHeaderRow().getListValues();
List<CSVRow> rows = csvFile.getValueRows();
// MAPPING OPERATION TYPE AS READ, WRITE, etc.
Map<String, OPERATION_TYPE> mapOperationTypes = new HashMap<String, RoleRights.OPERATION_TYPE>();
CSVRow operationTypeRow = rows.get(0);
List<String> rowValues = operationTypeRow.getListValues();
for (int j = 1; j < rowValues.size(); j++) {
String operationType = rowValues.get(j);
RoleRights.OPERATION_TYPE ot = RoleRights.OPERATION_TYPE.UNKNOWN;
if (operationType.equalsIgnoreCase("R")) {
ot = RoleRights.OPERATION_TYPE.READ;
} else if (operationType.equalsIgnoreCase("RW")) {
ot = RoleRights.OPERATION_TYPE.READ_WRITE;
} else if (operationType.equalsIgnoreCase("W")) {
ot = RoleRights.OPERATION_TYPE.WRITE;
}
mapOperationTypes.put(headerKeys.get(j), ot);
}
LOG.debug("Map of operation types: " + mapOperationTypes);
// Starting from index 1 (means the second row in the CSV)
for (int i = 1; i < rows.size(); i++) {
LOG.trace(i + " row");
RoleRights useRights = new RoleRights();
CSVRow row = rows.get(i);
// to map properties
rowValues = row.getListValues();
LOG.debug("rowValues: " + rowValues);
Map<String, String> mapUserRolePermissions = new HashMap<String, String>();
GcubeUserRole gCubeUserRole = toGcubeUserRole(rowValues.get(0));
if (gCubeUserRole == null) {
LOG.warn("The Role " + rowValues.get(0) + " not found into roleName of: " + GcubeUserRole.values());
continue;
}
useRights.setUserRole(gCubeUserRole);
for (int j = 1; j < rowValues.size(); j++) {
mapUserRolePermissions.put(headerKeys.get(j), rowValues.get(j));
}
LOG.debug("Role: " + useRights.getUserRole());
LOG.debug("Permissions read: " + mapUserRolePermissions);
Map<ACTION_ON_ITEM, OPERATION_TYPE> listPermessions = new HashMap<ACTION_ON_ITEM, OPERATION_TYPE>();
for (ACTION_ON_ITEM value : ACTION_ON_ITEM.values()) {
String yesno = mapUserRolePermissions.get(value.name());
if (yesno != null && yesno.equalsIgnoreCase("yes")) {
listPermessions.put(value, mapOperationTypes.get(value.name()));
}
}
useRights.setListPermessions(listPermessions);
// String writeOwn = mapUserRolePermissions.get(WRITE_OWN_CONFIG);
// if (writeOwn != null && writeOwn.equalsIgnoreCase("yes")) {
// useRights.setWriteOwn(true);
// }
//
// String writeAny = mapUserRolePermissions.get(WRITE_ANY_CONFIG);
// if (writeAny != null && writeAny.equalsIgnoreCase("yes")) {
// useRights.setWriteAny(true);
// }
listUserRights.add(useRights);
}
LOG.info("Returning user rights config: " + listUserRights);
return listUserRights;
} catch (Exception e) {
LOG.error("An error occurred on reading the GNA DataEntry config from: " + permissions_for_role, e);
throw new GNAUserRightsConfigException("Error on reading the GNA DataEntry from: " + permissions_for_role);
} finally {
if (configurationFile != null) {
try {
configurationFile.delete();
} catch (Exception e) {
// silent
}
}
}
}
/**
* Gets the gcube generic query string.
*
* @param secondaryType the secondary type
* @param genericResourceName the generic resource name
* @return the gcube generic query string
*/
public static String getGcubeGenericQueryString(String secondaryType, String genericResourceName) {
return "for $profile in collection('/db/Profiles/GenericResource')//Resource "
+ "where $profile/Profile/SecondaryType/string() eq '" + secondaryType
+ "' and $profile/Profile/Name/string() " + " eq '" + genericResourceName + "'" + "return $profile";
}
/**
* Gets the secondary type.
*
* @return the secondary type
*/
public String getSecondaryType() {
return SECONDARY_TYPE;
}
/**
* Gets the scope.
*
* @return the scope
*/
public String getScope() {
return scope;
}
}

View File

@ -1,29 +0,0 @@
package org.gcube.portlets.user.geoportaldataentry.shared;
/**
* The Class ACTION_ON_ITEM.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Nov 24, 2021
*/
public enum ACTION_ON_ITEM {
CREATE_NEW_PROJECT("Create New Project"),
VIEW_ON_MAP("View on Map"),
SHOW_METADATA("Show Metadata"),
VIEW_REPORT("View the Report"),
EDIT_PROJECT("Edit the Project"),
DELETE_PROJECT("Delete the Project");
String label;
ACTION_ON_ITEM(String label){
this.label = label;
}
public String getLabel() {
return label;
}
}

View File

@ -1,66 +0,0 @@
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

@ -1,8 +0,0 @@
package org.gcube.portlets.user.geoportaldataentry.shared;
@SuppressWarnings("serial")
public class GNAUserRightsConfigException extends Exception {
public GNAUserRightsConfigException(String message) {
super(message);
}
}

View File

@ -1,55 +0,0 @@
package org.gcube.portlets.user.geoportaldataentry.shared;
/**
* The Enum GcubeUserRole.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Nov 25, 2021
*/
public enum GcubeUserRole {
DATA_MEMBER("Data-Member", false, false),
DATA_EDITOR("Data-Editor", true, false),
DATA_MANAGER("Data-Manager", true, true);
private String name;
private boolean writeOwn;
private boolean writeAny;
/**
* Instantiates a new gcube user role.
*
* @param name the name
*/
private GcubeUserRole(String name, boolean writeOwn, boolean writeAny) {
this.name = name;
this.writeOwn = writeOwn;
this.writeAny = writeAny;
}
public String getName() {
return name;
}
public boolean isWriteOwn() {
return writeOwn;
}
public boolean isWriteAny() {
return writeAny;
}
public void setName(String name) {
this.name = name;
}
public void setWriteOwn(boolean writeOwn) {
this.writeOwn = writeOwn;
}
public void setWriteAny(boolean writeAny) {
this.writeAny = writeAny;
}
}

View File

@ -1,184 +0,0 @@
/**
*
*/
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 ResultSetPaginatedData.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Aug 6, 2021
*/
public class ResultSetPaginatedData implements Serializable {
/**
*
*/
private static final long serialVersionUID = 6800997954077785719L;
private List<ConcessioneDV> data;
private int offset = 0;
private int limit;
private boolean isServerSearchFinished = false;
private long totalItems;
/**
* Instantiates a new searched folder.
*/
public ResultSetPaginatedData() {
}
/**
* Instantiates a new result set paginated data.
*
* @param offset the offset
* @param limit the limit
* @param isServerSearchFinished the is server search finished
*/
public ResultSetPaginatedData(int offset, int limit, boolean isServerSearchFinished) {
this.offset = offset;
this.limit = limit;
this.isServerSearchFinished = isServerSearchFinished;
}
/**
* Gets the data.
*
* @return the data
*/
public List<ConcessioneDV> getData() {
return data;
}
/**
* Gets the client start index.
*
* @return the client start index
*/
public int getClientStartIndex() {
return offset;
}
/**
* Gets the limit.
*
* @return the limit
*/
public int getLimit() {
return limit;
}
/**
* 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<ConcessioneDV> data) {
this.data = data;
}
/**
* Sets the client start index.
*
* @param clientStartIndex the new client start index
*/
public void setClientStartIndex(int clientStartIndex) {
this.offset = clientStartIndex;
}
/**
* Sets the limit.
*
* @param limit the new limit
*/
public void setLimit(int limit) {
this.limit = limit;
}
/**
* 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;
}
/**
* Gets the serialversionuid.
*
* @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(", offset=");
builder.append(offset);
builder.append(", limit=");
builder.append(limit);
builder.append(", isServerSearchFinished=");
builder.append(isServerSearchFinished);
builder.append(", totalItems=");
builder.append(totalItems);
builder.append("]");
return builder.toString();
}
}

View File

@ -4,6 +4,7 @@ import java.io.Serializable;
import java.util.List;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
public class ResultSetSorted implements Serializable {

View File

@ -1,100 +0,0 @@
package org.gcube.portlets.user.geoportaldataentry.shared;
import java.io.Serializable;
import java.util.Map;
/**
* The Class RoleRights.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Nov 26, 2021
*/
public class RoleRights implements Serializable {
/**
*
*/
private static final long serialVersionUID = -304157165851633221L;
/**
* The Enum OPERATION_TYPE.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Nov 26, 2021
*/
public static enum OPERATION_TYPE {
READ, WRITE, READ_WRITE, UNKNOWN
}
private Map<ACTION_ON_ITEM, OPERATION_TYPE> listPermessions;
private GcubeUserRole userRole;
/**
* Instantiates a new user rights.
*/
public RoleRights() {
super();
}
/**
* Instantiates a new role rights.
*
* @param myUsername the my username
* @param listPermessions the list permessions
* @param userRole the user role
*/
public RoleRights(Map<ACTION_ON_ITEM, OPERATION_TYPE> listPermessions, GcubeUserRole userRole) {
this.listPermessions = listPermessions;
this.userRole = userRole;
}
/**
* Gets the list permessions.
*
* @return the list permessions
*/
public Map<ACTION_ON_ITEM, OPERATION_TYPE> getListPermessions() {
return listPermessions;
}
/**
* Gets the user role.
*
* @return the user role
*/
public GcubeUserRole getUserRole() {
return userRole;
}
/**
* Sets the list permessions.
*
* @param listPermessions the list permessions
*/
public void setListPermessions(Map<ACTION_ON_ITEM, OPERATION_TYPE> listPermessions) {
this.listPermessions = listPermessions;
}
/**
* Sets the user role.
*
* @param userRole the new user role
*/
public void setUserRole(GcubeUserRole userRole) {
this.userRole = userRole;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("RoleRights [listPermessions=");
builder.append(listPermessions);
builder.append(", userRole=");
builder.append(userRole);
builder.append("]");
return builder.toString();
}
}

View File

@ -1,146 +0,0 @@
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 SearchingFilter.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Nov 30, 2021
*/
public class SearchingFilter implements Serializable {
/**
* The Enum ORDER.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* 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;
}
}
/**
*
*/
private static final long serialVersionUID = -4004094263090373626L;
private RECORD_FIELD orderByField;
private ORDER order;
private Map<String, Object> searchInto;
/**
* Instantiates a new sort filter.
*/
public SearchingFilter() {
}
/**
* Instantiates a new sort filter.
*
* @param orderByField the order by field
* @param order the 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.
*
* @return the order by field
*/
public RECORD_FIELD getOrderByField() {
return orderByField;
}
/**
* Gets the order.
*
* @return the order
*/
public ORDER getOrder() {
return order;
}
/**
* Sets the order by field.
*
* @param orderByField the new order by field
*/
public void setOrderByField(RECORD_FIELD orderByField) {
this.orderByField = orderByField;
}
/**
* Sets the order.
*
* @param order the new order
*/
public void setOrder(ORDER order) {
this.order = order;
}
public Map<String, Object> getSearchInto() {
return searchInto;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
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

@ -2,6 +2,8 @@ package org.gcube.portlets.user.geoportaldataentry.shared;
import java.io.Serializable;
import org.gcube.application.geoportalcommon.shared.config.RoleRights;
/**
* The Class UserRights.
*

View File

@ -16,11 +16,10 @@ import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedReq
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.geoportalcommon.config.GNADataConfigProfileReader;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.geoportaldataentry.server.config.GNADataEntryConfigsProfileReader;
import org.junit.Before;
import org.junit.Test;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
@ -179,15 +178,6 @@ public class TestClass {
// System.out.println(listUserRights);
// }
@Test
public void readUserRights() throws Exception {
GNADataEntryConfigsProfileReader r = new GNADataEntryConfigsProfileReader();
try {
r.readProfileFromInfrastrucure();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}