diff --git a/.classpath b/.classpath index e619cfc..d8296e1 100644 --- a/.classpath +++ b/.classpath @@ -1,16 +1,11 @@ - + - - - - - @@ -35,5 +30,5 @@ - + diff --git a/.settings/com.gwtplugins.gdt.eclipse.core.prefs b/.settings/com.gwtplugins.gdt.eclipse.core.prefs index 384836d..876328d 100644 --- a/.settings/com.gwtplugins.gdt.eclipse.core.prefs +++ b/.settings/com.gwtplugins.gdt.eclipse.core.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 jarsExcludedFromWebInfLib= -lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-entry-app/target/geoportal-data-entry-app-2.0.1-SNAPSHOT +lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-entry-app/target/geoportal-data-entry-app-2.1.0-SNAPSHOT warSrcDir=src/main/webapp warSrcDirIsOutput=false diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index b922d7e..71eda66 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,5 @@ - + @@ -17,8 +17,16 @@ - - + + + + + + + + + + @@ -37,7 +45,11 @@ - + + + + + @@ -56,7 +68,11 @@ - + + + + + @@ -75,7 +91,10 @@ - + + uses + + @@ -93,27 +112,16 @@ - - - - - - - - - - - - - - - - + + + + + @@ -132,7 +140,11 @@ - + + + + + @@ -151,7 +163,11 @@ - + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index f94c8f7..9286d3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v2.1.0-SNAPSHOT] - 2021-11-24 + +#### 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 +- [#22506] Re-engineered the common utilities + + ## [v2.0.1] - 2021-11-17 - [#22369] Just to include the bug fix for Policy and LicenseID in the geoportal-common diff --git a/pom.xml b/pom.xml index a2c34bf..1b9b368 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.gcube.portlets.user geoportal-data-entry-app war - 2.0.1 + 2.1.0-SNAPSHOT GeoPortal Data Entry App The GeoPortal Data Entry App is an application to build the web forms for data entries needed to GeoNa project @@ -209,6 +209,22 @@ update them in DevMode --> ${webappDirectory}/WEB-INF/classes + + + src/main/java + + **/*.csv + + + + + + + + + + + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java index dea88f1..4475190 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java @@ -17,8 +17,6 @@ public class ConstantsGeoPortalDataEntryApp { public static final String HOURS_MINUTES_SEPARATOR = ConstantsMPFormBuilder.HOURS_MINUTES_SEPARATOR; - public static final String ERROR_ON_INIZIALITAION_STAGE_PLEASE_CONTACT_THE_SUPPORT = "Error on inizialization stage, please contact the support!"; - /** * The Enum RECORD_TYPE. * @@ -31,49 +29,13 @@ public class ConstantsGeoPortalDataEntryApp { } /** - * The Enum ACTION_ON_ITEM. + * The Enum ACTION_PERFORMED_ON_ITEM. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Aug 6, 2021 + * Nov 25, 2021 */ - public enum ACTION_ON_ITEM { - SHOW_ON_MAP, SHOW_METADATA, SHOW_REPORT, SHOW_EDIT_MODE, DELETE_RECORD, UPDATED_RECORD + public enum ACTION_PERFORMED_ON_ITEM { + 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("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"); - - 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; - } - - public String getJsonFieldName() { - return jsonFieldName; - } - - public String getDisplayName() { - return displayName; - } - } - } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index d4430bd..6afcf8c 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -8,22 +8,32 @@ 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_ON_ITEM; -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM; 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; +import org.gcube.portlets.user.geoportaldataentry.client.events.ActionPerformedOnItemEvent; +import org.gcube.portlets.user.geoportaldataentry.client.events.ActionPerformedOnItemEventHandler; import org.gcube.portlets.user.geoportaldataentry.client.events.CreateNewProjectEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.CreateNewProjectEventHandler; import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecordsEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecordsEventHandler; import org.gcube.portlets.user.geoportaldataentry.client.events.SaveGeonaDataFormsEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.SaveGeonaDataFormsHandler; +import org.gcube.portlets.user.geoportaldataentry.client.resource.Images; import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaMainTabPanel; import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaRecordsPaginatedView; +import org.gcube.portlets.user.geoportaldataentry.client.ui.ModalWindow; import org.gcube.portlets.user.geoportaldataentry.client.ui.card.GeoNaFormCardModel; import org.gcube.portlets.user.geoportaldataentry.client.ui.edit.EditModeRecord; import org.gcube.portlets.user.geoportaldataentry.client.ui.form.GeonaDataEntryMainForm; @@ -35,10 +45,10 @@ import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil.HTML_ 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.CommitReport; +import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; -import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; -import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter.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; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; @@ -58,6 +68,7 @@ import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.VerticalPanel; @@ -82,7 +93,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { private LinkedHashMap mapForms = new LinkedHashMap(); - private GeonaDataEntryMainForm geoNaMainForm; + private GeonaDataEntryMainForm geoNaMainForm = null; private Collection orderedCards; @@ -94,44 +105,245 @@ public class GeoPortalDataEntryApp implements EntryPoint { private GeonaRecordsPaginatedView grpw = null; + private UserRights myRights = null; + + private LoaderIcon loader = new LoaderIcon("Loading Application..."); + + private List displayFields = new ArrayList(); + private List sortByFields = new ArrayList(); + private List searchByFields = new ArrayList(); + /** * 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 }; + RootPanel.get(DIV_PORTLET_ID).add(loader); - SortFilter initialSortFilter = new SortFilter(RECORD_FIELD.NAME, ORDER.ASC); - - mainTabPanel = new GeonaMainTabPanel(appManagerBus, sortByOptions, initialSortFilter); - mainTabPanel.setLoaderVisible("Loading...", true); - - geoNaMainForm = new GeonaDataEntryMainForm(appManagerBus); - - GeoportalDataEntryServiceAsync.Util.getInstance().getGeonaInitConfig(new AsyncCallback() { + /*GeoportalDataEntryServiceAsync.Util.getInstance().listDisplayFields(new AsyncCallback>() { @Override public void onFailure(Throwable caught) { - Window.alert(ConstantsGeoPortalDataEntryApp.ERROR_ON_INIZIALITAION_STAGE_PLEASE_CONTACT_THE_SUPPORT); + Window.alert(caught.getMessage()); + } @Override - public void onSuccess(GeonaISConfig result) { + public void onSuccess(List result) { - if (result != null && result.getgRSecondaryType() != null && result.getScope() != null) { - callGetMetadataProfiles(result.getScope(), result.getgRSecondaryType()); - } else - Window.alert( - ConstantsGeoPortalDataEntryApp.ERROR_ON_INIZIALITAION_STAGE_PLEASE_CONTACT_THE_SUPPORT); + for (ItemField itemField : result) { + if(itemField.isDisplayAsResult()) { + 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().readDataViewerConfig(new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + String errorMsg = "Sorry, an error occurrend on istancing the application. Please, contact the support"; + Alert alert = new Alert(errorMsg, AlertType.ERROR); + alert.setClose(false); + try { + RootPanel.get(DIV_PORTLET_ID).remove(loader); + } catch (Exception e) { + + } + RootPanel.get(DIV_PORTLET_ID).add(alert); + Window.alert(errorMsg); + + } + + @Override + public void onSuccess(GNADataEntryExtConfigProfile gNADataEntryConfig) { + + try { + RootPanel.get(DIV_PORTLET_ID).remove(loader); + } catch (Exception e) { + + } + + List itemFields = gNADataEntryConfig.getListItemFields(); + + for (ItemField itemField : itemFields) { + if(itemField.isDisplayAsResult()) { + displayFields.add(itemField); + } + + if(itemField.isSearchable()) { + searchByFields.add(itemField); + } + + if(itemField.isSortable()) { + sortByFields.add(itemField); + } + } + + + GWT.log("List display fields: "+itemFields); + SearchingFilter initialSortFilter = new SearchingFilter(); + initialSortFilter.setOrder(ORDER.ASC); + initialSortFilter.setOrderByFields(Arrays.asList(new ItemField("Name", Arrays.asList("name"), true, true, true))); + + displayFields = itemFields; + mainTabPanel = new GeonaMainTabPanel(appManagerBus, displayFields, sortByFields, searchByFields, initialSortFilter); + mainTabPanel.setLoaderVisible("Loading...", true); + + geoNaMainForm = new GeonaDataEntryMainForm(appManagerBus); + mainTabPanel.addFormPanel(geoNaMainForm); + + //PERMISSIONS + myRights = gNADataEntryConfig.getUserRights(); + initGUI(); + GcubeUserRole userRole = myRights.getRoleRights().getUserRole(); + String msg = "Logged in as "; + if(userRole != null && userRole.getName()!=null) { + msg+= userRole.getName().substring(userRole.getName().indexOf("-")+1, userRole.getName().length()); + }else + msg+="Member"; + + mainTabPanel.setRoleLabel(msg); + + + RoleRights roleRights = myRights.getRoleRights(); + boolean canCreateNewItem = roleRights.getListPermessions().keySet().contains(ACTION_ON_ITEM.CREATE_NEW_PROJECT); + + if (!canCreateNewItem) { + // removing Tab "Create New Project" + mainTabPanel.removeTab(0); + // activating Tab "List of Project" + mainTabPanel.setTabActive(0); + mainTabPanel.instanceAndShowListOfConcessioni(); + return; + } + + GeoportalDataEntryServiceAsync.Util.getInstance().getGeonaInitConfig(new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + Window.alert( + "Sorry, an error occurrend when loading configurations. Please, contact the support"); + } + + @Override + public void onSuccess(GeonaISConfig result) { + + if (result != null && result.getGenericResourceSecondaryType() != null + && result.getScope() != null) { + callGetMetadataProfiles(result.getScope(), result.getGenericResourceSecondaryType()); + } else + Window.alert( + "Sorry, no configuration found in the context. Please, contact the support"); + + } + }); + } }); - bindEvents(); - mainTabPanel.addFormPanel(geoNaMainForm); - RootPanel.get(DIV_PORTLET_ID).add(mainTabPanel); + +// GeoportalDataEntryServiceAsync.Util.getInstance().getMyRightsInTheContext(new AsyncCallback() { +// +// @Override +// public void onFailure(Throwable caught) { +// String errorMsg = "Sorry, an error occurrend on istancing the application. Please, contact the support"; +// Alert alert = new Alert(errorMsg, AlertType.ERROR); +// alert.setClose(false); +// try { +// RootPanel.get(DIV_PORTLET_ID).remove(loader); +// } catch (Exception e) { +// +// } +// RootPanel.get(DIV_PORTLET_ID).add(alert); +// Window.alert(errorMsg); +// +// } +// +// @Override +// public void onSuccess(UserRights result) { +// try { +// RootPanel.get(DIV_PORTLET_ID).remove(loader); +// } catch (Exception e) { +// +// } +// +// myRights = result; +// initGUI(); +// GcubeUserRole userRole = myRights.getRoleRights().getUserRole(); +// String msg = "Logged in as "; +// if(userRole != null && userRole.getName()!=null) { +// msg+= userRole.getName().substring(userRole.getName().indexOf("-")+1, userRole.getName().length()); +// }else +// msg+="Member"; +// +// mainTabPanel.setRoleLabel(msg); +// +// +// RoleRights roleRights = myRights.getRoleRights(); +// boolean canCreateNewItem = roleRights.getListPermessions().keySet().contains(ACTION_ON_ITEM.CREATE_NEW_PROJECT); +// +// if (!canCreateNewItem) { +// // removing Tab "Create New Project" +// mainTabPanel.removeTab(0); +// // activating Tab "List of Project" +// mainTabPanel.setTabActive(0); +// mainTabPanel.instanceAndShowListOfConcessioni(); +// return; +// } +// +// GeoportalDataEntryServiceAsync.Util.getInstance().getGeonaInitConfig(new AsyncCallback() { +// +// @Override +// public void onFailure(Throwable caught) { +// Window.alert( +// "Sorry, an error occurrend when loading configurations. Please, contact the support"); +// } +// +// @Override +// public void onSuccess(GeonaISConfig result) { +// +// if (result != null && result.getgRSecondaryType() != null +// && result.getScope() != null) { +// callGetMetadataProfiles(result.getScope(), result.getgRSecondaryType()); +// } else +// Window.alert( +// "Sorry, no configuration found in the context. Please, contact the support"); +// +// } +// }); +// +// } +// }); + } + + private void initGUI() { + bindEvents(); + RootPanel.get(DIV_PORTLET_ID).add(mainTabPanel); Window.addResizeHandler(new ResizeHandler() { @Override public void onResize(ResizeEvent event) { @@ -143,21 +355,29 @@ public class GeoPortalDataEntryApp implements EntryPoint { updateSize(); } + private static native void click(Element element)/*-{ + element.click(); + }-*/; + /** * Update window size */ public void updateSize() { - RootPanel workspace = RootPanel.get(DIV_PORTLET_ID); - int topBorder = workspace.getAbsoluteTop(); - int footer = 85; // footer is bottombar + sponsor - int headerSize = 90; - // int headerSize = 30; - int rootHeight = Window.getClientHeight() - topBorder - headerSize - footer;// - ((footer == - // null)?0:(footer.getOffsetHeight()-15)); + try { + RootPanel workspace = RootPanel.get(DIV_PORTLET_ID); + int topBorder = workspace.getAbsoluteTop(); + int footer = 85; // footer is bottombar + sponsor + int headerSize = 90; + // int headerSize = 30; + int rootHeight = Window.getClientHeight() - topBorder - headerSize - footer;// - ((footer == + // null)?0:(footer.getOffsetHeight()-15)); - GWT.log("New workspace dimension Height: " + rootHeight); - mainTabPanel.setInternalHeight(rootHeight); + GWT.log("New workspace dimension Height: " + rootHeight); + mainTabPanel.setInternalHeight(rootHeight); + } catch (Exception e) { + // TODO: handle exception + } // appController.getMainPanel().setHeight(rootHeight); // appController.getMainPanel().setWidth(rootWidth); @@ -429,15 +649,55 @@ public class GeoPortalDataEntryApp implements EntryPoint { @Override public void onGetList(GetListOfRecordsEvent getListOfRecordsEvent) { - SortFilter sortFilter = getListOfRecordsEvent.getSortFilter(); - if(sortFilter==null){ + SearchingFilter sortFilter = getListOfRecordsEvent.getSortFilter(); + 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); } }); + + appManagerBus.addHandler(ActionPerformedOnItemEvent.TYPE, new ActionPerformedOnItemEventHandler() { + + @Override + public void onDoActionPerformedFired( + ActionPerformedOnItemEvent actionPerformedOnItemEvent) { + if (actionPerformedOnItemEvent != null) { + + ACTION_PERFORMED_ON_ITEM action = actionPerformedOnItemEvent.getAction(); + List items = actionPerformedOnItemEvent.getSelectItems(); + + if (items == null) { + if (grpw != null) { + items = (List) grpw.getSelectItems(); + } + } + + if (items == null || items.size() == 0) { + Window.alert("No item selected"); + return; + } + + T item = items.get(0); + + if (item == null) + return; + + if (item instanceof ConcessioneDV) { + final ConcessioneDV concessione = (ConcessioneDV) item; + GWT.log("onDoActionPerformedFired item: " + concessione); + switch (action) { + case UPDATED_PROJECT: + appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, + mainTabPanel.getCurrentSortFilter())); + break; + } + } + } + + } + }); appManagerBus.addHandler(ActionOnItemEvent.TYPE, new ActionOnItemEventHandler() { @@ -470,10 +730,41 @@ public class GeoPortalDataEntryApp implements EntryPoint { if (item instanceof ConcessioneDV) { final ConcessioneDV concessione = (ConcessioneDV) item; - GWT.log("ActionOnItemEvente item: " + concessione); + GWT.log("onDoActionFired item: " + concessione); + + // Checking if the user is NOT authorized to perform this action in two ways: + // 1. the map of actions allowed for the user does not contain the action; + RoleRights roleRights = myRights.getRoleRights(); + OPERATION_TYPE operationType = roleRights.getListPermessions().get(action); + boolean allowedOperationForUser = operationType != null? true:false; + if (!allowedOperationForUser) { + + String msg = "You are not authorized to perform the action: "+ action.getLabel(); + ModalWindow modalW = new ModalWindow(new Image(Images.ICONS.accessDenied()), "Forbidden: "+action, msg, AlertType.WARNING); + modalW.show(); + return; + } + // 2. the user cannot access to action (e.g. the user cannot write an item of another user) + // if so an error is shown + GcubeUserRole userRole = myRights.getRoleRights().getUserRole(); + boolean allowedWriteActionOnItem = checkAccessToOperationType(userRole, operationType, concessione); + if (!allowedWriteActionOnItem) { + String title = "Forbidden: missing write access"; + String msg = "You do not have write access to item: "+ concessione.getNome(); + if(!userRole.isWriteOwn()) { + msg = "You do not have write access to item: "+ concessione.getNome(); + }else if (!userRole.isWriteAny()){ + title = "Forbidden: missing ownership"; + msg = "You are not the creator of: "+ concessione.getNome() +". You cannot access to it"; + } + ModalWindow modalW = new ModalWindow(new Image(Images.ICONS.accessDenied()), title, msg, AlertType.WARNING); + modalW.show(); + return; + } + switch (action) { - case SHOW_ON_MAP: + case VIEW_ON_MAP: final Modal modal = new Modal(true, true); modal.setCloseVisible(true); final HorizontalPanel hpGetLink = new HorizontalPanel(); @@ -508,10 +799,12 @@ public class GeoPortalDataEntryApp implements EntryPoint { break; - case SHOW_REPORT: + case VIEW_REPORT: + final Modal modal2 = new Modal(true, true); - modal2.setTitle("Report: " + concessione.getNome() - + ""); + modal2.setTitle( + "Report: " + + concessione.getNome() + ""); modal2.setWidth(800); modal2.setCloseVisible(true); if (concessione.getValidationReport() == null) { @@ -525,10 +818,11 @@ public class GeoPortalDataEntryApp implements EntryPoint { break; - case SHOW_EDIT_MODE: + case EDIT_PROJECT: final Modal modal3 = new Modal(true, true); - modal3.setTitle("Edit: " + concessione.getNome() - + ""); + modal3.setTitle( + "Edit: " + + concessione.getNome() + ""); modal3.setWidth(950); modal3.setHeight("700px"); modal3.setCloseVisible(true); @@ -540,12 +834,11 @@ public class GeoPortalDataEntryApp implements EntryPoint { modal3.show(); break; - case UPDATED_RECORD: - appManagerBus.fireEvent( - new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, - mainTabPanel.getCurrentSortFilter())); - break; - case DELETE_RECORD: +// case UPDATED_PROJECT: +// appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, +// mainTabPanel.getCurrentSortFilter())); +// break; + case DELETE_PROJECT: String htmlMsg = "Going to delete the project with:"; htmlMsg += "
    "; @@ -614,6 +907,56 @@ public class GeoPortalDataEntryApp implements EntryPoint { }); } + + private boolean checkAccessToOperationType(GcubeUserRole userRole, OPERATION_TYPE allowedAction, ConcessioneDV concessione) { + + boolean writeAnyAPassed = false; + boolean writeOwnPassed = false; + + // Case ADMIN + if (userRole.isWriteAny()) { + writeAnyAPassed = true; + } + + // Case EDITOR + // Going to check if the user can RW the record is owner of. + if (userRole.isWriteOwn()) { + String ownerUser = concessione.getCreationUser(); + if (ownerUser == null || ownerUser.isEmpty()) { + writeOwnPassed = false; + }else if (ownerUser.compareTo(myRights.getMyUsername()) == 0) { + // if my username is equal the owner of the concessione + writeOwnPassed = true; + } + } + + boolean operationAllowed = false; + switch (allowedAction) { + case READ: + //Access to READ operation is allowed to everyone + operationAllowed = true; + GWT.log(OPERATION_TYPE.READ+ " ALLOWED? "+operationAllowed); + break; + case READ_WRITE: + //Access to READ_WRITE operation + operationAllowed = writeAnyAPassed || writeOwnPassed; + GWT.log(OPERATION_TYPE.READ_WRITE+ " ALLOWED? "+operationAllowed); + break; + case WRITE: + //Access to WRITE operation + operationAllowed = writeAnyAPassed || writeOwnPassed; + GWT.log(OPERATION_TYPE.WRITE+ " ALLOWED? "+operationAllowed); + break; + case UNKNOWN: + operationAllowed = false; + GWT.log(OPERATION_TYPE.UNKNOWN+ " ALLOWED? "+operationAllowed); + break; + default: + break; + } + + return operationAllowed; + } private void purgeFileUploaded() { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java index e85bd00..d2d8bb0 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java @@ -3,15 +3,16 @@ package org.gcube.portlets.user.geoportaldataentry.client; import java.util.List; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; +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; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; +import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile; 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.widgets.mpformbuilder.shared.GenericDatasetBean; import com.google.gwt.user.client.rpc.RemoteService; @@ -63,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; /** @@ -118,13 +119,24 @@ public interface GeoportalDataEntryService extends RemoteService { /** * Update record. * - * @param itemId the item id - * @param jsonUpdate the json update - * @param recordType the record type + * @param itemId the item id + * @param recordType the record type + * @param section the section + * @param pathIndex the path index + * @param keepCurrentContent the keep current content + * @param gDBean the g D bean * @return the updated JSON string representing the itemId * @throws Exception the exception */ ConcessioneDV updateSectionForRecord(String itemId, String recordType, String section, int pathIndex, List keepCurrentContent, GenericDatasetBean gDBean) throws Exception; + /** + * Read data viewer config. + * + * @return the GNA data entry ext config profile + * @throws Exception the exception + */ + GNADataEntryExtConfigProfile readDataViewerConfig() throws Exception; + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java index 0dc4486..c3593de 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java @@ -3,75 +3,64 @@ package org.gcube.portlets.user.geoportaldataentry.client; import java.util.List; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; +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; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; +import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile; 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.widgets.mpformbuilder.shared.GenericDatasetBean; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; -public interface GeoportalDataEntryServiceAsync -{ +public interface GeoportalDataEntryServiceAsync { - /** - * Utility class to get the RPC Async interface from client-side code - */ - public static final class Util - { - private static GeoportalDataEntryServiceAsync instance; + /** + * Utility class to get the RPC Async interface from client-side code + */ + public static final class Util { + private static GeoportalDataEntryServiceAsync instance; - public static final GeoportalDataEntryServiceAsync getInstance() - { - if ( instance == null ) - { - instance = (GeoportalDataEntryServiceAsync) GWT.create( GeoportalDataEntryService.class ); - } - return instance; - } - - private Util() - { - // Utility class should not be instantiated - } - } + public static final GeoportalDataEntryServiceAsync getInstance() { + if (instance == null) { + instance = (GeoportalDataEntryServiceAsync) GWT.create(GeoportalDataEntryService.class); + } + return instance; + } + private Util() { + // Utility class should not be instantiated + } + } void saveGeonaDataForms(List listGeonaFormObjects, AsyncCallback callback); - void getGeonaInitConfig(AsyncCallback callback); - void getLinksFor(String itemId, RECORD_TYPE recordType, AsyncCallback callback); - - void getListConcessioni(Integer start, Integer limit, SortFilter filter, boolean reloadFromService, + void getListConcessioni(Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService, AsyncCallback callback); - void deleteRecord(String itemId, RECORD_TYPE recordType, AsyncCallback callback); - void getJSONRecord(String itemId, RECORD_TYPE recordType, AsyncCallback callback); - void updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType, AsyncCallback callback); - void readFileSetPaths(AsyncCallback callback); - void getRecord(String itemId, RECORD_TYPE recordType, AsyncCallback callback); - void updateSectionForRecord(String itemId, String recordType, String section, int pathIndex, List keepCurrentContent, GenericDatasetBean gDBean, AsyncCallback callback); + + void readDataViewerConfig(AsyncCallback asyncCallback); + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java index 11386db..1def9fc 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java @@ -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.client.ConstantsGeoPortalDataEntryApp.ACTION_ON_ITEM; import com.google.gwt.event.shared.GwtEvent; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEvent.java new file mode 100644 index 0000000..54857af --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEvent.java @@ -0,0 +1,84 @@ +package org.gcube.portlets.user.geoportaldataentry.client.events; + +import java.util.List; + +import org.gcube.application.geoportalcommon.shared.products.model.RecordDV; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * The Class ActionOnItemEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Sep 15, 2021 + * @param the generic type + */ +public class ActionPerformedOnItemEvent extends GwtEvent { + public static Type TYPE = new Type(); + private List selectItems; + private ACTION_PERFORMED_ON_ITEM action; + + /** + * Instantiates a new action performed on item event. + * + * @param selectItems the select items + * @param doAction the do action + */ + public ActionPerformedOnItemEvent(List selectItems, ACTION_PERFORMED_ON_ITEM doAction) { + this.selectItems = selectItems; + this.action = doAction; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + /* + * (non-Javadoc) + * + * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType() + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared. + * EventHandler) + */ + @Override + protected void dispatch(ActionPerformedOnItemEventHandler handler) { + handler.onDoActionPerformedFired(this); + } + + /** + * Gets the select items. + * + * @return the select items + */ + public List getSelectItems() { + return selectItems; + } + + /** + * Gets the action. + * + * @return the action + */ + public ACTION_PERFORMED_ON_ITEM getAction() { + return action; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEventHandler.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEventHandler.java new file mode 100644 index 0000000..0d6ec7b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEventHandler.java @@ -0,0 +1,24 @@ +package org.gcube.portlets.user.geoportaldataentry.client.events; + +import org.gcube.application.geoportalcommon.shared.products.model.RecordDV; + +import com.google.gwt.event.shared.EventHandler; + + +/** + * The Interface ActionPerformedOnItemEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 25, 2021 + */ +public interface ActionPerformedOnItemEventHandler extends EventHandler { + + /** + * On do action performed fired. + * @param + * + * @param actionPerformedOnItemEvent the action performed on item event + */ + void onDoActionPerformedFired(ActionPerformedOnItemEvent actionPerformedOnItemEvent); +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java index cbea945..bd62d1e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java @@ -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.SortFilter; import com.google.gwt.event.shared.GwtEvent; @@ -18,12 +18,12 @@ public class GetListOfRecordsEvent extends GwtEvent TYPE = new Type(); 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 sortByFields; - private SortFilter currentSortFilter; + private List searchForFields; + + private SearchingFilter currentSortFilter; private GeonaRecordsPaginatedView grpw = null; + private List displayFields; + /** * Instantiates a new geona main tab panel. * @@ -117,13 +156,27 @@ 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, List displayFields, List sortByFields, + List searchForFields, SearchingFilter initialSortFilter) { initWidget(uiBinder.createAndBindUi(this)); this.appManagerBus = appManagerBus; this.sortByFields = sortByFields; - setCurrentSortFilter(initialSortFilter); - bindEvents(); + 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())); + + bindEvents(); + resetSearch.setIconSize(IconSize.TWO_TIMES); + resetSearch.setType(ButtonType.LINK); } public void setInternalHeight(int height) { @@ -159,17 +212,17 @@ public class GeonaMainTabPanel extends Composite { @Override public void onClick(ClickEvent event) { - grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, null, currentSortFilter); - showListOfConcessioniView(grpw); - + instanceAndShowListOfConcessioni(); } }); - for (RECORD_FIELD record_FIELD : sortByFields) { + for (ItemField 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); @@ -177,29 +230,45 @@ public class GeonaMainTabPanel extends Composite { @Override public void onClick(ClickEvent event) { - GWT.log("Sort by: " + sortFilter); - setCurrentSortFilter(sortFilter); + alertSortBy.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); + alertSortBy.setText(labelDESC); appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter())); } }); } + for (ItemField record_FIELD : searchForFields) { + + NavLink nav = new NavLink(record_FIELD.getDisplayName()); + dropdownSearchFor.add(nav); + + nav.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + alertSearchFor.setText(record_FIELD.getDisplayName()); + + if (searchField.getText().length() >= MIN_LENGHT_SERCHING_STRING) { + doSearchEvent(); + } + + } + }); + } + navShowOnMap.addClickHandler(new ClickHandler() { @Override @@ -209,7 +278,7 @@ public class GeonaMainTabPanel extends Composite { listConcessioni = grpw.getSelectItems(); } appManagerBus - .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.SHOW_ON_MAP)); + .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.VIEW_ON_MAP)); } }); @@ -223,7 +292,7 @@ public class GeonaMainTabPanel extends Composite { listConcessioni = grpw.getSelectItems(); } appManagerBus - .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.SHOW_REPORT)); + .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.VIEW_REPORT)); } }); @@ -237,7 +306,7 @@ public class GeonaMainTabPanel extends Composite { listConcessioni = grpw.getSelectItems(); } appManagerBus - .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.SHOW_EDIT_MODE)); + .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.EDIT_PROJECT)); } }); @@ -249,11 +318,54 @@ public class GeonaMainTabPanel extends Composite { if (grpw != null && grpw.getSelectItems() != null) { listConcessioni = grpw.getSelectItems(); } - appManagerBus - .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.DELETE_RECORD)); + appManagerBus.fireEvent( + new ActionOnItemEvent(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()); + doSearchEvent(); + } + + } + }); + + resetSearch.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + searchField.setText(""); + appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter())); + resetSearch.setVisible(false); + } + }); + + } + + public void setRoleLabel(String msg) { + roleLabel.setText(msg); + } + + 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"); + return; + } + + resetSearch.setVisible(true); + appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter())); + } + + private String toLabelFilter(ItemField itemField, ORDER direction) { + String labelFilter = itemField.getDisplayName() + LABEL_FILTER_SEPARATOR + direction.name(); + return labelFilter; } /** @@ -290,49 +402,74 @@ 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 { + 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(Arrays.asList(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) { + private SearchingFilter builtSearchingFilter() { + SearchingFilter searchingFilter = toSortFilter(alertSortBy.getText()); + String searchText = searchField.getText(); + if (searchText != null && !searchText.isEmpty()) { + Map searchInto = new HashMap(); - String labelFilter = sortFilter.getOrderByField().getDisplayName() + LABEL_FILTER_SEPARATOR - + sortFilter.getOrder().name(); - GWT.log("Got " + sortFilter); - return labelFilter; + String searchForField = ""; + + for (ItemField recordField : searchForFields) { + if (recordField.getDisplayName().equals(alertSearchFor.getText())) { + searchForField = recordField.getJsonFields().get(0); + continue; + } + } + searchInto.put(searchForField, searchText); + WhereClause where = new WhereClause(); + where.setSearchInto(searchInto); + where.setOperator(LOGICAL_OP.OR); + searchingFilter.setConditions(Arrays.asList(where)); + } + 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; } + public void removeTab(int index) { + tabPanel.remove(index); + } + + 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 + * + */ + public void instanceAndShowListOfConcessioni() { + grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, displayFields, currentSortFilter); + showListOfConcessioniView(grpw); + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml index 346c494..7f5e5ec 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml @@ -32,23 +32,34 @@ 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; + } GeoNa + styleName="{style.custom-page-header}">GNA + - + New Project - - List of Projects + + List of Projects - + Reload Projects + + + + + + + + + + + + + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java index ca84a21..dabccca 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java @@ -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.SortFilter; import com.google.gwt.core.client.GWT; import com.google.gwt.event.shared.HandlerManager; @@ -47,10 +47,10 @@ public class GeonaRecordsPaginatedView { private MyCustomDataProvider dataProvider = new MyCustomDataProvider(); 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) { + List displayFields, SearchingFilter currentSortFilter) { this.recordType = recordType; this.currentSortFilter = currentSortFilter; this.initClassFirstRangeChanged = true; this.eventBus = eventbus; - itemsTable = new ItemsTable(eventbus, displayFields, currentSortFilter); + itemsTable = new ItemsTable(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 sm = getCellTable().getSelectionModel(); if (sm instanceof SingleSelectionModel) { @@ -197,12 +197,11 @@ public class GeonaRecordsPaginatedView { * @param limit the limit * @param serverIndex the server index */ - private void loadConcessioni(int newStartIndex, int limit, int serverIndex, SortFilter sortFilter, + private 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() { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/ModalWindow.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/ModalWindow.java new file mode 100644 index 0000000..f52934b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/ModalWindow.java @@ -0,0 +1,58 @@ +package org.gcube.portlets.user.geoportaldataentry.client.ui; + +import com.github.gwtbootstrap.client.ui.Alert; +import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.Modal; +import com.github.gwtbootstrap.client.ui.ModalFooter; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Image; + +public class ModalWindow { + + private HorizontalPanel hp = new HorizontalPanel(); + private Modal modal; + + public ModalWindow(Image icon, String title, String msg, AlertType alertType) { + + modal = new Modal(true,true); + modal.hide(false); + modal.setTitle(title); + modal.setCloseVisible(true); + + + Alert alert = new Alert(); + alert.setType(alertType); + alert.setClose(false); + alert.setText(msg); + alert.getElement().getStyle().setMarginLeft(10, Unit.PX); + + + if (icon != null) + hp.add(icon); + hp.add(alert); + + ModalFooter modalFooter = new ModalFooter(); + final Button buttClose = new Button("Close"); + modalFooter.add(buttClose); + + buttClose.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + modal.hide(); + } + }); + + modal.add(hp); + modal.add(modalFooter); + } + + public void show() { + modal.show(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java index f7a0330..79ca301 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java @@ -7,11 +7,11 @@ import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.RecordDV; import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV; -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_ON_ITEM; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM; 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.events.ActionOnItemEvent; -import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEventHandler; +import org.gcube.portlets.user.geoportaldataentry.client.events.ActionPerformedOnItemEvent; +import org.gcube.portlets.user.geoportaldataentry.client.events.ActionPerformedOnItemEventHandler; import org.gcube.portlets.user.geoportaldataentry.client.ui.edit.jseditor.JSONEditorWrapper; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; @@ -66,7 +66,7 @@ public class EditModeRecord extends Composite { private JSONEditorWrapper jsEditor; private HandlerManager appManagerBus; - + private final HandlerManager editorManagerBus = new HandlerManager(null); /** @@ -159,7 +159,7 @@ public class EditModeRecord extends Composite { * Bind events. */ private void bindEvents() { - + buttonJSONUpdate.addClickHandler(new ClickHandler() { @Override @@ -181,8 +181,8 @@ public class EditModeRecord extends Composite { // TODO: handle exception } - editorManagerBus.fireEvent( - new ActionOnItemEvent(null, ACTION_ON_ITEM.UPDATED_RECORD)); + editorManagerBus.fireEvent(new ActionPerformedOnItemEvent(null, + ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); } @@ -195,38 +195,38 @@ public class EditModeRecord extends Composite { } catch (Exception e) { // TODO: handle exception } - - DialogInform di = new DialogInform(null, "Project updated!", "Project '" + result.getNome() + "' updated correctly"); + + DialogInform di = new DialogInform(null, "Project updated!", + "Project '" + result.getNome() + "' updated correctly"); di.setZIndex(100000); di.center(); - editorManagerBus.fireEvent( - new ActionOnItemEvent(Arrays.asList(result), ACTION_ON_ITEM.UPDATED_RECORD)); + editorManagerBus.fireEvent(new ActionPerformedOnItemEvent( + Arrays.asList(result), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); } }); } }); - - editorManagerBus.addHandler(ActionOnItemEvent.TYPE, new ActionOnItemEventHandler() { + + editorManagerBus.addHandler(ActionPerformedOnItemEvent.TYPE, new ActionPerformedOnItemEventHandler() { @Override - public void onDoActionFired(ActionOnItemEvent showItemEvent) { - - ACTION_ON_ITEM action = showItemEvent.getAction(); - List items = showItemEvent.getSelectItems(); - - if(items!=null) { + public void onDoActionPerformedFired( + ActionPerformedOnItemEvent actionPerformedOnItemEvent) { + ACTION_PERFORMED_ON_ITEM action = actionPerformedOnItemEvent.getAction(); + List items = actionPerformedOnItemEvent.getSelectItems(); + + if (items != null) { selectedConcessione = (BaseConcessioneDV) items.get(0); instanceJSONEditor(); - - if(action.equals(ACTION_ON_ITEM.UPDATED_RECORD)) { - appManagerBus.fireEvent( - new ActionOnItemEvent((List) items, ACTION_ON_ITEM.UPDATED_RECORD)); + + if (action.equals(ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)) { + appManagerBus.fireEvent(new ActionPerformedOnItemEvent( + (List) items, ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); } } - + } }); - } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.java index 51036f8..ddfbaf5 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.java @@ -14,11 +14,11 @@ import org.gcube.application.geoportalcommon.shared.products.model.AbstractRelaz import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.RelazioneScavoDV; import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV; -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_ON_ITEM; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM; 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.GeoportalDataEntryServiceAsync; -import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEvent; +import org.gcube.portlets.user.geoportaldataentry.client.events.ActionPerformedOnItemEvent; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogConfirm; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.StringUtil; @@ -262,7 +262,7 @@ public class UpdateFileset extends Composite { buttonUpdate.setEnabled(true); showUploadFileGUI(); editorManagerBus.fireEvent( - new ActionOnItemEvent(Arrays.asList(fullConcessione), ACTION_ON_ITEM.UPDATED_RECORD)); + new ActionPerformedOnItemEvent(Arrays.asList(fullConcessione), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); } }); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java index f801244..f938fc3 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java @@ -5,22 +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 org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; 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; @@ -53,22 +49,10 @@ public class ItemsTable extends AbstractItemsCellTable< private static final int ITEMS_PER_PAGE = 10; private static final String NO_DATA = "No data"; - private TextColumn name; - private TextColumn introduction; - private TextColumn author; public static DateTimeFormat dtformat = DateTimeFormat.getFormat(ConvertToDataViewModel.DATE_FORMAT); - private AbstractDataProvider dataProvider; - - private List displayFields; - private TextColumn startEndProjectColumn; - private TextColumn statusColumn; - // private Column startProjectDateColumn; - // private Column endProjectDateColumn; + private List displayFields; private boolean isAsyncronusTable; - private TextColumn insertedBy; - private Column createdColumn; - private SortFilter currentSortFilter; /** * Instantiates a new items table. @@ -77,10 +61,9 @@ public class ItemsTable 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, List displayFields) { this.eventBus = eventBus; - this.currentSortFilter = currentSortFilter; - setDisplayFields(displayFields); + this.displayFields = displayFields; } /** @@ -109,15 +92,66 @@ public class ItemsTable 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() { + TextColumn col = new TextColumn() { @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 @@ -125,304 +159,224 @@ public class ItemsTable extends AbstractItemsCellTable< public void render(com.google.gwt.cell.client.Cell.Context context, T object, SafeHtmlBuilder sb) { if (object == null) return; - sb.appendHtmlConstant("
    "); - super.render(context, object, sb); - sb.appendHtmlConstant("
    "); + + 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(""); + super.render(context, object, sb); + sb.appendHtmlConstant(""); + } else + super.render(context, object, sb); + }; }; - sortedCellTable.addColumn(name, RECORD_FIELD.NAME.getDisplayName(), true); - - if (!isAsyncronusTable) { - Comparator c = new Comparator() { - @Override - public int compare(T o1, T o2) { - return ((ConcessioneDV) o1).getNome().compareTo(((ConcessioneDV) o2).getNome()); - } - }; - - sortedCellTable.setComparator(name, c); + if(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() { - @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 c = new Comparator() { - @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() { - @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 c = new Comparator() { - @Override - public int compare(T o1, T o2) { - String toDisplay1 = toDisplayAuthors(((ConcessioneDV) o1).getAuthors()); - String toDisplay2 = toDisplayAuthors(((ConcessioneDV) o2).getAuthors()); - return toDisplay1.compareTo(toDisplay2); - } - }; - sortedCellTable.setComparator(author, c); - } - - sortedCellTable.setColumnWidth(author, 220, Unit.PX); - - } - - if (this.displayFields.contains(RECORD_FIELD.PROJECT_START_END_DATE)) { - - startEndProjectColumn = new TextColumn() { - @Override - public String getValue(T object) { - if (object == null) - return ""; - - Date dS = (((ConcessioneDV) object).getDataInizioProgetto()); - Date dE = (((ConcessioneDV) object).getDataFineProgetto()); - return dtformat.format(dS) + " / " + dtformat.format(dE); - } - }; - - 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(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 c = new Comparator() { - @Override - public int compare(T o1, T o2) { - if (o1 == null) - return -1; - - if (o2 == null) - return 1; - - Date d1 = (((ConcessioneDV) o1).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() { - @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 c = new Comparator() { - @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() { - @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(""); - super.render(context, object, sb); - sb.appendHtmlConstant(""); - - } - }; - - sortedCellTable.addColumn(statusColumn, RECORD_FIELD.RECORD_STATUS.getDisplayName(), false); - sortedCellTable.setColumnWidth(statusColumn, 120, Unit.PX); - - } - -// ButtonCell showOnMapButton = new ButtonCell(); -// showOnMapButton.setIcon(IconType.MAP_MARKER); -// -// MyToolTipColumn showOnMapColumn = new MyToolTipColumn(showOnMapButton, "Show on Map") { -// -// @Override -// public String getValue(T object) { -// return ""; -// } -// }; -// -// showOnMapColumn.setFieldUpdater(new FieldUpdater() { -// @Override -// public void update(int index, T object, String value) { -// GWT.log("clicked show"); -// eventBus.fireEvent(new ActionOnItemEvent(Arrays.asList(object), ACTION_ON_ITEM.SHOW_ON_MAP)); -// } -// }); -// sortedCellTable.addColumn(showOnMapColumn); -// sortedCellTable.setColumnWidth(showOnMapColumn, 50, Unit.PX); -// -// ButtonCell showReportRecordButton = new ButtonCell(); -// showReportRecordButton.setIcon(IconType.FILE_TEXT_ALT); -// MyToolTipColumn showReportRecordColumn = new MyToolTipColumn(showReportRecordButton, -// "Show Publication Report") { -// public String getValue(T object) { -// return ""; -// } -// }; -// -// showReportRecordColumn.setFieldUpdater(new FieldUpdater() { -// @Override -// public void update(int index, T object, String value) { -// -// eventBus.fireEvent(new ActionOnItemEvent(Arrays.asList(object), ACTION_ON_ITEM.SHOW_REPORT)); -// } -// }); -// sortedCellTable.addColumn(showReportRecordColumn); -// sortedCellTable.setColumnWidth(showReportRecordColumn, 50, Unit.PX); -// -// ButtonCell deleteRecordButton = new ButtonCell(); -// deleteRecordButton.setIcon(IconType.TRASH); -// MyToolTipColumn deleteRecordColumn = new MyToolTipColumn(deleteRecordButton, -// "Delete Project") { -// public String getValue(T object) { -// return ""; -// } -// }; -// -// deleteRecordColumn.setFieldUpdater(new FieldUpdater() { -// @Override -// public void update(int index, T object, String value) { -// -// eventBus.fireEvent(new ActionOnItemEvent(Arrays.asList(object), ACTION_ON_ITEM.DELETE_RECORD)); -// } -// }); -// 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; - } - + /* + * if (this.displayFields.contains(RECORD_FIELD.NAME)) { + * + * // NAME name = new TextColumn() { + * + * @Override public String getValue(T object) { if (object == null) return ""; + * return ((ConcessioneDV) object).getNome(); } + * + * // ADDING TOOLTIP + * + * @Override public void render(com.google.gwt.cell.client.Cell.Context context, + * T object, SafeHtmlBuilder sb) { if (object == null) return; + * sb.appendHtmlConstant("
    "); super.render(context, object, sb); + * sb.appendHtmlConstant("
    "); }; }; + * + * sortedCellTable.addColumn(name, RECORD_FIELD.NAME.getDisplayName(), true); + * + * if (!isAsyncronusTable) { Comparator c = new Comparator() { + * + * @Override public int compare(T o1, T o2) { return ((ConcessioneDV) + * o1).getNome().compareTo(((ConcessioneDV) o2).getNome()); } }; + * + * sortedCellTable.setComparator(name, c); } + * + * } + * + * if (this.displayFields.contains(RECORD_FIELD.INTRODUCTION)) { + * + * introduction = new TextColumn() { + * + * @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 c = new Comparator() { + * + * @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() { + * + * @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 c = new Comparator() { + * + * @Override public int compare(T o1, T o2) { String toDisplay1 = + * toDisplayAuthors(((ConcessioneDV) o1).getAuthors()); String toDisplay2 = + * toDisplayAuthors(((ConcessioneDV) o2).getAuthors()); return + * toDisplay1.compareTo(toDisplay2); } }; sortedCellTable.setComparator(author, + * c); } + * + * sortedCellTable.setColumnWidth(author, 220, Unit.PX); + * + * } + * + * if (this.displayFields.contains(RECORD_FIELD.PROJECT_START_END_DATE)) { + * + * startEndProjectColumn = new TextColumn() { + * + * @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(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 c = new Comparator() { + * + * @Override public int compare(T o1, T o2) { if (o1 == null) return -1; + * + * if (o2 == null) return 1; + * + * Date d1 = (((ConcessioneDV) o1).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() { + * + * @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 c = new Comparator() { + * + * @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() { + * + * @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(""); + * super.render(context, object, sb); sb.appendHtmlConstant(""); + * + * } }; + * + * sortedCellTable.addColumn(statusColumn, + * RECORD_FIELD.RECORD_STATUS.getDisplayName(), false); + * sortedCellTable.setColumnWidth(statusColumn, 120, Unit.PX); + * + * } + */ } - - + public void enableWriteOperations() { - + } /** @@ -465,15 +419,15 @@ public class ItemsTable 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 fields) { +// this.displayFields = fields != null && fields.size() > 0 ? Arrays.asList(fields) +// : Arrays.asList(RECORD_FIELD.values()); +// } /** * Reset columns table. @@ -491,7 +445,7 @@ public class ItemsTable extends AbstractItemsCellTable< * * @return the displayFields */ - public List getDisplayFields() { + public List getDisplayFields() { return displayFields; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index aae3fa7..d6187d5 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -1,8 +1,6 @@ package org.gcube.portlets.user.geoportaldataentry.server; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -19,25 +17,37 @@ import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.application.geoportal.common.rest.TempFile; import org.gcube.application.geoportalcommon.ConvertToDataViewModel; import org.gcube.application.geoportalcommon.GeoportalCommon; -import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; +import org.gcube.application.geoportalcommon.MongoServiceCommon; +import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile; +import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; +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.GNAConfigException; 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.MongoServiceUtil.ConcessioneValidationReportStatusComparator; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; +import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile; 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.SortFilter.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; +import org.gcube.vomanagement.usermanagement.RoleManager; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; +import org.gcube.vomanagement.usermanagement.model.GCubeRole; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,6 +67,29 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen public static final String GEONA_GENERIC_RESOURCE_SECONDARY_TYPE = "GEONA_GENERIC_RESOURCE_SECONDARY_TYPE"; private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataEntryServiceImpl.class); + /** + * Gets the GNA data entry config profile. + * + * @return the GNA data entry config profile + * @throws Exception the exception + */ + private GNADataEntryConfigProfile getGNADataEntryConfigProfile() throws Exception { + + GNADataEntryConfigProfile profile = SessionUtil.getGNADataEntryConfigProfile(getThreadLocalRequest()); + if (profile == null) { + LOG.info(GNADataEntryConfigProfile.class.getSimpleName() + " is null, loading configurations from IS"); + //to be sure + SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + GeoportalCommon gCommon = new GeoportalCommon(); + profile = gCommon.readGNADataEntryConfig(); + SessionUtil.setGNADataEntryConfigProfile(getThreadLocalRequest(), profile); + } else { + LOG.info(GNADataEntryConfigProfile.class.getSimpleName() + " read from session"); + } + + return profile; + } + /** * Save geona data forms. * @@ -362,8 +395,9 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen try { theSecondaryType = this.getServletContext().getInitParameter(GEONA_GENERIC_RESOURCE_SECONDARY_TYPE); } catch (Exception e) { - LOG.error("I cannot read the init parameter for: " + GEONA_GENERIC_RESOURCE_SECONDARY_TYPE, e); + LOG.warn("I cannot read the init parameter for: " + GEONA_GENERIC_RESOURCE_SECONDARY_TYPE, e); theSecondaryType = "GeoNaMetadata"; + LOG.warn("Using default SecondaryType: " + theSecondaryType); } // LOG.warn("\n\n\nHARD-CABLING THE SCOPE, PLEASE REMOTE IT!!!!\n\n\n"); @@ -387,7 +421,8 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen LOG.info("getLinksFor called"); SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); - GeoNaDataViewerProfile grViewerProfile = SessionUtil.getGeportalViewerResourceProfile(getThreadLocalRequest()); + GNADataViewerConfigProfile grViewerProfile = SessionUtil + .getGeportalViewerResourceProfile(getThreadLocalRequest()); GeoportalCommon gc = new GeoportalCommon(grViewerProfile); GeoNaItemRef item = new GeoNaItemRef(itemId, recordType.toString().toLowerCase()); item = gc.getPublicLinksFor(item, false); @@ -406,147 +441,26 @@ 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 { + + SessionUtil.getCurrentContext(getThreadLocalRequest(), true); + MongoServiceCommon serviceCommon = new MongoServiceCommon(); + + // TODO MUST BE REPLACED BY COUNT List listOfConcessioni = SessionUtil.getListOfConcessioni(getThreadLocalRequest(), reloadFromService); int listConcessioniSize = listOfConcessioni.size(); - List toReturn = new ArrayList(); - 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 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 toReturnList = new ArrayList(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()); + ResultSetPaginatedData searchedData = serviceCommon.queryOnMongo(listConcessioniSize, start, limit, filter, + "concessione"); return searchedData; + } catch (Exception e) { - LOG.error("Error on loading list of concessioni: ", 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()); } @@ -760,19 +674,19 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen String toEditPath = null; AddSectionToConcessioneRequest request = null; List files = new ArrayList(); - + // Managing files already present as current content and kept by user List keepFiles = serviceUtil.toTemFilesFromWSC(keepCurrentContent); if (keepFiles != null) { files.addAll(keepFiles); - LOG.debug(keepFiles.size() +" current corrent file/s has/have been added to list of files"); + LOG.debug(keepFiles.size() + " current corrent file/s has/have been added to list of files"); } // Managing new files uploaded by user List newFiles = serviceUtil.toTemFiles(gDBean.getFilesUploaded()); if (newFiles != null) { files.addAll(newFiles); - LOG.debug(newFiles.size() +" new file/s has/have been added to list of files"); + LOG.debug(newFiles.size() + " new file/s has/have been added to list of files"); } // if (files == null || files.isEmpty()) @@ -808,21 +722,21 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen Concessione concessione = clientMongo.cleanFileSet(itemId, toEditPath); LOG.debug("Sending new Fileset .."); - if(files.size()>0) { + if (files.size() > 0) { // StorageUtils storage=new StorageUtils(); // Building TempFile SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); - LOG.info("Registering FileSet into recordId " + itemId + " with request path: " + toEditPath + " and: " - + files.size() + " file/s"); + LOG.info("Registering FileSet into recordId " + itemId + " with request path: " + toEditPath + + " and: " + files.size() + " file/s"); concessione = clientMongo.registerFileSet(itemId, request); - }else { + } else { LOG.info("Fileset is empty, skipping registerFileSet"); } - - LOG.info("Publishings itemId: "+itemId); + + LOG.info("Publishings itemId: " + itemId); concessione = clientMongo.publish(itemId); - - LOG.debug("returning concessione: "+concessione); + + LOG.debug("returning concessione: " + concessione); return ConvertToDataViewModel.toConcessione(concessione); } @@ -834,5 +748,94 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen "Error occurred on updating the project with id: " + itemId + ". Error: " + e.getMessage()); } } + + @Override + public GNADataEntryExtConfigProfile readDataViewerConfig() throws Exception { + LOG.info("readDataViewerConfig called"); + GCubeUser user = null; + GNADataEntryExtConfigProfile gnaDEExtConfig = new GNADataEntryExtConfigProfile(); + try { + PortalContext pContext = PortalContext.getConfiguration(); + user = pContext.getCurrentUser(this.getThreadLocalRequest()); + String scope = SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + + GNADataEntryConfigProfile config = getGNADataEntryConfigProfile(); + List listUserRightsForRole = config.getPermissionsForRole(); + gnaDEExtConfig.setListItemFields(config.getListItemFields()); + gnaDEExtConfig.setPermissionsForRole(listUserRightsForRole); + + // DEV MODE + if (!SessionUtil.isIntoPortal()) { + LOG.warn("OUT OF PORTAL - DEV MODE detected"); + GcubeUserRole myRole = GcubeUserRole.DATA_EDITOR; + + for (RoleRights roleRight : listUserRightsForRole) { + if (roleRight.getUserRole().equals(myRole)) { + UserRights userRights = new UserRights(user.getUsername(), roleRight); + LOG.warn("DEV MODE returning: " + userRights); + gnaDEExtConfig.setUserRights(userRights); + return gnaDEExtConfig; + } + } + } + + long groupId = pContext.getCurrentGroupId(this.getThreadLocalRequest()); + + if (user == null || scope == null) { + LOG.warn("called getMyRightsInTheContext with invalid parameter user: " + user + ", in the scope: " + + scope, ", returning null"); + return null; + } + + LOG.info("reading GcubeUserRole for user: " + user.getUsername() + ", in the scope: " + scope); + // The following snippet should pass in the service-side + RoleManager roleManager = new LiferayRoleManager(); + List roles = roleManager.listRolesByUserAndGroup(user.getUserId(), groupId); + List listMyRoles = new ArrayList(); + for (GCubeRole gCubeRole : roles) { + if (gCubeRole.getRoleName().equalsIgnoreCase(GcubeUserRole.DATA_EDITOR.getName())) { + listMyRoles.add(GcubeUserRole.DATA_EDITOR); + } + if (gCubeRole.getRoleName().equalsIgnoreCase(GcubeUserRole.DATA_MANAGER.getName())) { + listMyRoles.add(GcubeUserRole.DATA_MANAGER); + } + } + + // Mapping to roles "known" + LOG.info( + "For user: " + user.getUsername() + " in the scope: " + scope + " read the role/s: " + listMyRoles); + + GcubeUserRole myRole = null; + if (listMyRoles.contains(GcubeUserRole.DATA_MANAGER)) + myRole = GcubeUserRole.DATA_MANAGER; + else if (listMyRoles.contains(GcubeUserRole.DATA_EDITOR)) + myRole = GcubeUserRole.DATA_EDITOR; + else + myRole = GcubeUserRole.DATA_MEMBER; + + LOG.info("using highest role: " + myRole); + + RoleRights toRoleRight = null; + for (RoleRights roleRight : listUserRightsForRole) { + if (roleRight.getUserRole().equals(myRole)) { + toRoleRight = roleRight; + break; + } + } + UserRights userRights = new UserRights(user.getUsername(), toRoleRight); + LOG.info("returning: " + userRights); + gnaDEExtConfig.setUserRights(userRights); + return gnaDEExtConfig; + } catch (UserRetrievalFault | GroupRetrievalFault | GNAConfigException e) { + LOG.error("An error occurred during getMyRightsInTheContext: " + user, e); + + Map permissions = new HashMap(); + RoleRights roleRights = new RoleRights(permissions, GcubeUserRole.DATA_MEMBER); + UserRights ur = new UserRights(user.getUsername(), roleRights); + LOG.warn("Returning default user rights: " + ur); + gnaDEExtConfig.setUserRights(ur); + return gnaDEExtConfig; + } + } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java index 42bad84..a092374 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java @@ -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 * diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java index 0b6e5eb..80e1177 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java @@ -13,7 +13,8 @@ import javax.servlet.http.HttpSession; import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.application.geoportalcommon.GeoportalCommon; -import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; +import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile; +import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.portal.PortalContext; import org.gcube.common.scope.api.ScopeProvider; @@ -38,6 +39,8 @@ import com.liferay.portal.service.UserLocalServiceUtil; */ public class SessionUtil { + private static final String GNA_DATAENTRY_CONFIG_PROFILE = "GNA_DATAENTRY_CONFIG_PROFILE"; + private static final String LATEST_RESULT_SET_SORTED = "LATEST_RESULT_SET_SORTED"; private static final String GEONA_DATAVIEWER_PROFILE = "GEONA_DATAVIEWER_PROFILE"; private static final String LIST_OF_CONCESSIONI = "LIST_OF_CONCESSIONI"; /** The log. */ @@ -173,15 +176,15 @@ public class SessionUtil { * @return the geportal viewer resource profile * @throws Exception the exception */ - public static GeoNaDataViewerProfile getGeportalViewerResourceProfile(HttpServletRequest httpServletRequest) + public static GNADataViewerConfigProfile getGeportalViewerResourceProfile(HttpServletRequest httpServletRequest) throws Exception { HttpSession session = httpServletRequest.getSession(); - GeoNaDataViewerProfile geoNaDataViewerProfile = (GeoNaDataViewerProfile) session + GNADataViewerConfigProfile geoNaDataViewerProfile = (GNADataViewerConfigProfile) session .getAttribute(GEONA_DATAVIEWER_PROFILE); if (geoNaDataViewerProfile == null) { GeoportalCommon gc = new GeoportalCommon(); - geoNaDataViewerProfile = gc.getGeoNaDataViewProfile(null); + geoNaDataViewerProfile = gc.readGNADataViewerConfig(null); session.setAttribute(GEONA_DATAVIEWER_PROFILE, geoNaDataViewerProfile); } @@ -197,18 +200,41 @@ public class SessionUtil { */ public static ResultSetSorted getLatestResultSetSorted(HttpServletRequest httpServletRequest) { HttpSession session = httpServletRequest.getSession(); - return (ResultSetSorted) session.getAttribute("LATEST_RESULT_SET_SORTED"); + return (ResultSetSorted) session.getAttribute(LATEST_RESULT_SET_SORTED); } /** * Gets the latest sort filter. * * @param httpServletRequest the http servlet request + * @param rsSorted the rs sorted * @return the latest sort filter */ public static void setLatestResultSetSorted(HttpServletRequest httpServletRequest, ResultSetSorted rsSorted) { HttpSession session = httpServletRequest.getSession(); - session.setAttribute("LATEST_RESULT_SET_SORTED", rsSorted); + session.setAttribute(LATEST_RESULT_SET_SORTED, rsSorted); } + /** + * Gets the GNA data entry config profile. + * + * @param httpServletRequest the http servlet request + * @return the GNA data entry config profile + */ + public static GNADataEntryConfigProfile getGNADataEntryConfigProfile(HttpServletRequest httpServletRequest) { + HttpSession session = httpServletRequest.getSession(); + return (GNADataEntryConfigProfile) session.getAttribute(GNA_DATAENTRY_CONFIG_PROFILE); + } + + /** + * Sets the GNA data entry config profile. + * + * @param httpServletRequest the http servlet request + * @param gNADEConfigProfile the g NADE config profile + */ + public static void setGNADataEntryConfigProfile(HttpServletRequest httpServletRequest, + GNADataEntryConfigProfile gNADEConfigProfile) { + HttpSession session = httpServletRequest.getSession(); + session.setAttribute(GNA_DATAENTRY_CONFIG_PROFILE, gNADEConfigProfile); + } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNADataEntryExtConfigProfile.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNADataEntryExtConfigProfile.java new file mode 100644 index 0000000..944d3b7 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNADataEntryExtConfigProfile.java @@ -0,0 +1,46 @@ +package org.gcube.portlets.user.geoportaldataentry.shared; + +import java.io.Serializable; + +import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile; + +/** + * The Class GNADataEntryExtConfigProfile. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 21, 2021 + */ +public class GNADataEntryExtConfigProfile extends GNADataEntryConfigProfile implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3185317083819447952L; + private UserRights userRights = null; + + /** + * Instantiates a new GNA data entry config profile. + */ + public GNADataEntryExtConfigProfile() { + + } + + public UserRights getUserRights() { + return userRights; + } + + public void setUserRights(UserRights userRights) { + this.userRights = userRights; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GNADataEntryExtConfigProfile [userRights="); + builder.append(userRights); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GeonaISConfig.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GeonaISConfig.java index 4e35d33..1ec007e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GeonaISConfig.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GeonaISConfig.java @@ -2,39 +2,73 @@ package org.gcube.portlets.user.geoportaldataentry.shared; import java.io.Serializable; -public class GeonaISConfig implements Serializable{ - - +/** + * The Class GeonaISConfig. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 22, 2021 + */ +public class GeonaISConfig implements Serializable { + + /** * */ - private static final long serialVersionUID = -6700506811708315617L; - - String gRSecondaryType; - String scope; - + private static final long serialVersionUID = 4187839053354198268L; + private String genericResSecondaryType; + private String scope; + + /** + * Instantiates a new geona IS config. + */ public GeonaISConfig() { } + /** + * Instantiates a new geona IS config. + * + * @param gRSecondaryType the g R secondary type + * @param scope the scope + */ public GeonaISConfig(String gRSecondaryType, String scope) { super(); - this.gRSecondaryType = gRSecondaryType; + this.genericResSecondaryType = gRSecondaryType; this.scope = scope; } - - public String getgRSecondaryType() { - return gRSecondaryType; + /** + * Gets the generic resource secondary type. + * + * @return the generic resource secondary type + */ + public String getGenericResourceSecondaryType() { + return genericResSecondaryType; } - public void setgRSecondaryType(String gRSecondaryType) { - this.gRSecondaryType = gRSecondaryType; + /** + * Sets the generic resource secondary type. + * + * @param gRSecondaryType the new generic resource secondary type + */ + public void setGenericResourceSecondaryType(String gRSecondaryType) { + this.genericResSecondaryType = gRSecondaryType; } + /** + * Gets the scope. + * + * @return the scope + */ public String getScope() { return scope; } + /** + * Sets the scope. + * + * @param scope the new scope + */ public void setScope(String scope) { this.scope = scope; } @@ -42,14 +76,12 @@ public class GeonaISConfig implements Serializable{ @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("GeonaISConfig [gRSecondaryType="); - builder.append(gRSecondaryType); + builder.append("GeonaISConfig [genericResSecondaryType="); + builder.append(genericResSecondaryType); builder.append(", scope="); builder.append(scope); builder.append("]"); return builder.toString(); } - - } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetPaginatedData.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetPaginatedData.java deleted file mode 100644 index d838915..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetPaginatedData.java +++ /dev/null @@ -1,189 +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 data; - private int clientStartIndex = 0; - private int limit; - private int serverEndIndex = 0; - private boolean isServerSearchFinished = false; - private long totalItems; - - /** - * Instantiates a new searched folder. - */ - public 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 isServerSearchFinished the is server search finished - */ - public ResultSetPaginatedData(int clientStartIndex, int limit, int serverEndIndex, boolean isServerSearchFinished) { - - this.clientStartIndex = clientStartIndex; - this.limit = limit; - this.serverEndIndex = serverEndIndex; - this.isServerSearchFinished = isServerSearchFinished; - } - - /** - * Gets the data. - * - * @return the data - */ - public List getData() { - return data; - } - - /** - * Gets the client start index. - * - * @return the client start index - */ - public int getClientStartIndex() { - return clientStartIndex; - } - - /** - * Gets the limit. - * - * @return the limit - */ - public int getLimit() { - return limit; - } - - /** - * Gets the server end index. - * - * @return the server end index - */ - public int getServerEndIndex() { - return serverEndIndex; - } - - /** - * Checks if is server search finished. - * - * @return true, if is server search finished - */ - public boolean isServerSearchFinished() { - return isServerSearchFinished; - } - - /** - * Sets the data. - * - * @param data the new data - */ - public void setData(List data) { - this.data = data; - } - - /** - * Sets the client start index. - * - * @param clientStartIndex the new client start index - */ - public void setClientStartIndex(int clientStartIndex) { - this.clientStartIndex = clientStartIndex; - } - - /** - * Sets the limit. - * - * @param limit the new limit - */ - public void setLimit(int limit) { - this.limit = limit; - } - - /** - * Sets the server end index. - * - * @param serverEndIndex the new server end index - */ - public void setServerEndIndex(int serverEndIndex) { - this.serverEndIndex = serverEndIndex; - } - - /** - * Sets the server search finished. - * - * @param isServerSearchFinished the new server search finished - */ - public void setServerSearchFinished(boolean isServerSearchFinished) { - this.isServerSearchFinished = isServerSearchFinished; - } - - /** - * Gets the total items. - * - * @return the total items - */ - public long getTotalItems() { - return totalItems; - } - - /** - * Sets the total items. - * - * @param totalItems the new total items - */ - public void setTotalItems(long totalItems) { - this.totalItems = totalItems; - } - - /** - * To string. - * - * @return the string - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("ResultSetPaginatedData [data="); - builder.append(data); - builder.append(", clientStartIndex="); - builder.append(clientStartIndex); - builder.append(", limit="); - builder.append(limit); - builder.append(", serverEndIndex="); - builder.append(serverEndIndex); - builder.append(", isServerSearchFinished="); - builder.append(isServerSearchFinished); - builder.append(", totalItems="); - builder.append(totalItems); - builder.append("]"); - return builder.toString(); - } - - - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetSorted.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetSorted.java index 412d1a0..7cc44dc 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetSorted.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetSorted.java @@ -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 { @@ -12,7 +13,7 @@ public class ResultSetSorted implements Serializable { */ private static final long serialVersionUID = 889420364685643758L; - private SortFilter searchFilter; + private SearchingFilter searchFilter; private List data; @@ -20,13 +21,13 @@ public class ResultSetSorted implements Serializable { } - public ResultSetSorted(SortFilter searchFilter, List data) { + public ResultSetSorted(SearchingFilter searchFilter, List data) { super(); this.searchFilter = searchFilter; this.data = data; } - public SortFilter getSearchFilter() { + public SearchingFilter getSearchFilter() { return searchFilter; } @@ -34,7 +35,7 @@ public class ResultSetSorted implements Serializable { return data; } - public void setSearchFilter(SortFilter searchFilter) { + public void setSearchFilter(SearchingFilter searchFilter) { this.searchFilter = searchFilter; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SortFilter.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SortFilter.java deleted file mode 100644 index 5226711..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SortFilter.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.shared; - -import java.io.Serializable; - -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; - -/** - * The Class SortFilter. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Aug 6, 2021 - */ -public class SortFilter implements Serializable { - - /** - * The Enum ORDER. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Aug 6, 2021 - */ - public static enum ORDER { - ASC("ASCENDING"), DESC("DESCENDING"); - - String label; - - ORDER(String label) { - this.label = label; - } - - public String getLabel() { - return label; - } - } - - /** - * - */ - private static final long serialVersionUID = -4004094263090373626L; - - private RECORD_FIELD orderByField; - - private ORDER order; - - /** - * Instantiates a new sort filter. - */ - public SortFilter() { - - } - - /** - * Instantiates a new sort filter. - * - * @param orderByField the order by field - * @param order the order - */ - public SortFilter(RECORD_FIELD orderByField, ORDER order) { - this.orderByField = orderByField; - this.order = order; - } - - /** - * 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; - } - - /** - * To string. - * - * @return the string - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("SortFilter [orderByField="); - builder.append(orderByField); - builder.append(", order="); - builder.append(order); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/UserRights.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/UserRights.java new file mode 100644 index 0000000..2b25960 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/UserRights.java @@ -0,0 +1,65 @@ +package org.gcube.portlets.user.geoportaldataentry.shared; + +import java.io.Serializable; + +import org.gcube.application.geoportalcommon.shared.config.RoleRights; + +/** + * The Class UserRights. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 24, 2021 + */ +public class UserRights implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -304157165851633221L; + + private String myUsername; + + private RoleRights roleRights; + + /** + * Instantiates a new user rights. + */ + public UserRights() { + super(); + } + + public UserRights(String myUsername, RoleRights roleRights) { + super(); + this.myUsername = myUsername; + this.roleRights = roleRights; + } + + public String getMyUsername() { + return myUsername; + } + + public RoleRights getRoleRights() { + return roleRights; + } + + public void setMyUsername(String myUsername) { + this.myUsername = myUsername; + } + + public void setRoleRights(RoleRights roleRights) { + this.roleRights = roleRights; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("UserRights [myUsername="); + builder.append(myUsername); + builder.append(", roleRights="); + builder.append(roleRights); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/webapp/GeoPortalDataEntryApp.css b/src/main/webapp/GeoPortalDataEntryApp.css index 3965771..0f43430 100644 --- a/src/main/webapp/GeoPortalDataEntryApp.css +++ b/src/main/webapp/GeoPortalDataEntryApp.css @@ -119,3 +119,30 @@ 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; + width: 250px !important; + margin-top: 8px !important; +} + +.alert_box_nav { + padding: 4px 10px !important; + margin-top: 8px !important; + margin-bottom: 10px !important; +} diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java index b3d9e17..4119769 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java @@ -3,42 +3,40 @@ 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; +import com.mongodb.BasicDBList; +import com.mongodb.BasicDBObject; +import com.mongodb.BasicDBObjectBuilder; + public class TestClass { - private static String TOKEN = ""; - private static String CONTEXT ="/gcube/devsec/devVRE"; - - - public static void main(String[] args) throws Exception { + private static String CONTEXT = "/gcube/devsec/devVRE"; + private static String USERNAME = "francesco.mangiacrapa"; + + //@Before + public void init() { ScopeProvider.instance.set(CONTEXT); SecurityTokenProvider.instance.set(TOKEN); - -// LocalDateTime ldt = ConvertToServiceModel.toLocalDateTime("2020-10-01 10:20"); -// System.out.println(ldt.toString()); -// -// String latitudine = "-899.2986"; -// // System.out.println(latitudine.matches("^[-]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$")); -// -// String longitude = "0"; -// System.out.println(longitude.matches("\\s*[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$")); -// -// GeoportalDataEntryServiceImpl g = new GeoportalDataEntryServiceImpl(); -// g.getLinksFor("", ConstantsGeoPortalDataEntryApp.RECORD_TYPE.CONCESSIONE.toString()); - - getListOfConcessioni(); - } - public static void getListOfConcessioni() throws Exception { + // @Test + public void getListConcessioniTest() throws Exception { MongoConcessioni clientMongo = mongoConcessioni().build(); Iterator concessioni = clientMongo.getList(); List listOfConcessioni = new ArrayList(); @@ -46,13 +44,138 @@ public class TestClass { while (concessioni.hasNext()) { Concessione concessione = (Concessione) concessioni.next(); listOfConcessioni.add(concessione); - + } } int i = 0; for (Concessione concessione : listOfConcessioni) { - System.out.println(++i+" "+concessione); + 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 orderByFields = Arrays.asList("nome"); + + Map searchFields = new HashMap(); + searchFields.put("nome", "test"); + searchFields.put("authors", "fra"); + + 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(); + + query = new Document(); + + for (String key : searchFields.keySet()) { + // builder.append(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.put(key, new BasicDBObject("$eq", searchFields.get(key))); + // query = new Document(key, searchFields.get(key)); + } + +// query.putAll(builder.get().toMap()); +// request.setFilter(query); + + BasicDBList list = new BasicDBList(); + list.add(builder.get().toMap()); + query.put("$or", list); + // or(query); + request.setFilter(query); + + // ************************************************ AND +// query = new Document(); +// for (String key : searchFields.keySet()) { +// //AND +// BasicDBObject bs = new BasicDBObject(); +// bs.append("$regex", searchFields.get(key)); +// bs.append("$options", "i"); +// query.put(key, bs); +// +// } +// request.setFilter(query); + // ******************************************** END AND + } + + // OR + /* + * query = new Document(); BasicDBObject container = new BasicDBObject(); + * BsonArray bArray = new BsonArray(); for (String key : searchFields.keySet()) + * { //AND BasicDBObject bs = new BasicDBObject(); bs.append("$regex", + * searchFields.get(key)); bs.append("$options", "i"); query.put(key, bs); + * + * //container.put(key, bs); + * + * + * // BasicDBObject bs2 = new BasicDBObject(); // bs2.append("$regex", + * searchFields.get(key)); // bs2.append("$options", "i"); // BsonDocument bsK = + * new BsonDocument(); // bsK.append(key, new BsonString(bs2.toJson())); // + * bArray.add(bsK); + * + * } // query.put("$or", bArray); + * + * BasicDBList list = new BasicDBList(); list.add(query); + * + * Document orDocument = new Document(); orDocument.put("$or", list); // query = + * orDocument; 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 concessioni = clientMongo.query(request); + + if (concessioni.hasNext()) { + System.out.println("Found concessioni, printing them..."); + } else + System.out.println("No concessione found"); + + 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 { +// new GNARoleRitghtsConfigReader(); +// List listUserRights = GNARoleRitghtsConfigReader.readRoleRightsConfig(); +// System.out.println(listUserRights); +// } + + + }