ported to GNADataEntryConfigProfile

This commit is contained in:
Francesco Mangiacrapa 2021-12-21 16:51:56 +01:00
parent 03779582ad
commit 8dd267730c
6 changed files with 265 additions and 107 deletions

View File

@ -45,6 +45,7 @@ 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.LoaderIcon;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.NewBrowserWindow; 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.CommitReport;
import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile;
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig;
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
@ -119,7 +120,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
RootPanel.get(DIV_PORTLET_ID).add(loader); RootPanel.get(DIV_PORTLET_ID).add(loader);
GeoportalDataEntryServiceAsync.Util.getInstance().listDisplayFields(new AsyncCallback<List<ItemField>>() { /*GeoportalDataEntryServiceAsync.Util.getInstance().listDisplayFields(new AsyncCallback<List<ItemField>>() {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
@ -129,10 +130,9 @@ public class GeoPortalDataEntryApp implements EntryPoint {
@Override @Override
public void onSuccess(List<ItemField> result) { public void onSuccess(List<ItemField> result) {
for (ItemField itemField : result) { for (ItemField itemField : result) {
if(itemField.isDisplayIntoTable()) { if(itemField.isDisplayAsResult()) {
displayFields.add(itemField); displayFields.add(itemField);
} }
@ -159,10 +159,9 @@ public class GeoPortalDataEntryApp implements EntryPoint {
mainTabPanel.addFormPanel(geoNaMainForm); mainTabPanel.addFormPanel(geoNaMainForm);
} }
}); });*/
GeoportalDataEntryServiceAsync.Util.getInstance().readDataViewerConfig(new AsyncCallback<GNADataEntryExtConfigProfile>() {
GeoportalDataEntryServiceAsync.Util.getInstance().getMyRightsInTheContext(new AsyncCallback<UserRights>() {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
@ -176,18 +175,49 @@ public class GeoPortalDataEntryApp implements EntryPoint {
} }
RootPanel.get(DIV_PORTLET_ID).add(alert); RootPanel.get(DIV_PORTLET_ID).add(alert);
Window.alert(errorMsg); Window.alert(errorMsg);
} }
@Override @Override
public void onSuccess(UserRights result) { public void onSuccess(GNADataEntryExtConfigProfile gNADataEntryConfig) {
try { try {
RootPanel.get(DIV_PORTLET_ID).remove(loader); RootPanel.get(DIV_PORTLET_ID).remove(loader);
} catch (Exception e) { } catch (Exception e) {
} }
myRights = result; List<ItemField> 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(); initGUI();
GcubeUserRole userRole = myRights.getRoleRights().getUserRole(); GcubeUserRole userRole = myRights.getRoleRights().getUserRole();
String msg = "Logged in as "; String msg = "Logged in as ";
@ -231,9 +261,84 @@ public class GeoPortalDataEntryApp implements EntryPoint {
} }
}); });
} }
}); });
// GeoportalDataEntryServiceAsync.Util.getInstance().getMyRightsInTheContext(new AsyncCallback<UserRights>() {
//
// @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<GeonaISConfig>() {
//
// @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() { private void initGUI() {

View File

@ -3,7 +3,6 @@ package org.gcube.portlets.user.geoportaldataentry.client;
import java.util.List; import java.util.List;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
@ -11,9 +10,9 @@ import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceCo
import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV; 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.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; 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.GeoNaFormDataObject;
import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig;
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteService;
@ -133,18 +132,11 @@ public interface GeoportalDataEntryService extends RemoteService {
List<WorkspaceContentDV> keepCurrentContent, GenericDatasetBean gDBean) throws Exception; List<WorkspaceContentDV> keepCurrentContent, GenericDatasetBean gDBean) throws Exception;
/** /**
* Gets the my rights in the context. * Read data viewer config.
* *
* @return the my rights in the context * @return the GNA data entry ext config profile
* @throws Exception * @throws Exception the exception
*/ */
UserRights getMyRightsInTheContext() throws Exception; GNADataEntryExtConfigProfile readDataViewerConfig() throws Exception;
/**
* List display fields.
*
* @return the list
*/
List<ItemField> listDisplayFields();
} }

View File

@ -3,7 +3,6 @@ package org.gcube.portlets.user.geoportaldataentry.client;
import java.util.List; import java.util.List;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
@ -11,75 +10,57 @@ import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceCo
import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV; 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.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; 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.GeoNaFormDataObject;
import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig;
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback; 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 * Utility class to get the RPC Async interface from client-side code
*/ */
public static final class Util public static final class Util {
{ private static GeoportalDataEntryServiceAsync instance;
private static GeoportalDataEntryServiceAsync instance;
public static final GeoportalDataEntryServiceAsync getInstance() public static final GeoportalDataEntryServiceAsync getInstance() {
{ if (instance == null) {
if ( instance == null ) instance = (GeoportalDataEntryServiceAsync) GWT.create(GeoportalDataEntryService.class);
{ }
instance = (GeoportalDataEntryServiceAsync) GWT.create( GeoportalDataEntryService.class ); return instance;
} }
return instance;
}
private Util()
{
// Utility class should not be instantiated
}
}
private Util() {
// Utility class should not be instantiated
}
}
void saveGeonaDataForms(List<GeoNaFormDataObject> listGeonaFormObjects, AsyncCallback<CommitReport> callback); void saveGeonaDataForms(List<GeoNaFormDataObject> listGeonaFormObjects, AsyncCallback<CommitReport> callback);
void getGeonaInitConfig(AsyncCallback<GeonaISConfig> callback); void getGeonaInitConfig(AsyncCallback<GeonaISConfig> callback);
void getLinksFor(String itemId, RECORD_TYPE recordType, AsyncCallback<GeoNaItemRef> callback); void getLinksFor(String itemId, RECORD_TYPE recordType, AsyncCallback<GeoNaItemRef> callback);
void getListConcessioni(Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService, void getListConcessioni(Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService,
AsyncCallback<ResultSetPaginatedData> callback); AsyncCallback<ResultSetPaginatedData> callback);
void deleteRecord(String itemId, RECORD_TYPE recordType, AsyncCallback<Boolean> callback); void deleteRecord(String itemId, RECORD_TYPE recordType, AsyncCallback<Boolean> callback);
void getJSONRecord(String itemId, RECORD_TYPE recordType, AsyncCallback<String> callback); void getJSONRecord(String itemId, RECORD_TYPE recordType, AsyncCallback<String> callback);
void updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType, AsyncCallback<ConcessioneDV> callback); void updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType, AsyncCallback<ConcessioneDV> callback);
void readFileSetPaths(AsyncCallback<FileSetPathsDV> callback); void readFileSetPaths(AsyncCallback<FileSetPathsDV> callback);
void getRecord(String itemId, RECORD_TYPE recordType, AsyncCallback<ConcessioneDV> callback); void getRecord(String itemId, RECORD_TYPE recordType, AsyncCallback<ConcessioneDV> callback);
void updateSectionForRecord(String itemId, String recordType, String section, int pathIndex, void updateSectionForRecord(String itemId, String recordType, String section, int pathIndex,
List<WorkspaceContentDV> keepCurrentContent, GenericDatasetBean gDBean, List<WorkspaceContentDV> keepCurrentContent, GenericDatasetBean gDBean,
AsyncCallback<ConcessioneDV> callback); AsyncCallback<ConcessioneDV> callback);
void readDataViewerConfig(AsyncCallback<GNADataEntryExtConfigProfile> asyncCallback);
void getMyRightsInTheContext(AsyncCallback<UserRights> callback);
void listDisplayFields(AsyncCallback<List<ItemField>> callback);
} }

View File

@ -17,19 +17,18 @@ import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.application.geoportal.common.rest.TempFile; import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportalcommon.ConvertToDataViewModel; import org.gcube.application.geoportalcommon.ConvertToDataViewModel;
import org.gcube.application.geoportalcommon.GeoportalCommon; import org.gcube.application.geoportalcommon.GeoportalCommon;
//import org.gcube.application.geoportalcommon.GeoportalCommon;
import org.gcube.application.geoportalcommon.MongoServiceCommon; import org.gcube.application.geoportalcommon.MongoServiceCommon;
import org.gcube.application.geoportalcommon.config.GNADataConfigProfileReader; import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile;
import org.gcube.application.geoportalcommon.shared.GNADataConfigProfile; import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile;
import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM; 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.GcubeUserRole;
import org.gcube.application.geoportalcommon.shared.config.RoleRights; import org.gcube.application.geoportalcommon.shared.config.RoleRights;
import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE; import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE;
import org.gcube.application.geoportalcommon.shared.exception.GNAUserRightsConfigException; import org.gcube.application.geoportalcommon.shared.exception.GNAConfigException;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; 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.model.ValidationReportDV;
@ -39,6 +38,7 @@ import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitl
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService; import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService;
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; 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.GeoNaFormDataObject;
import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig;
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
@ -68,6 +68,29 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
public static final String GEONA_GENERIC_RESOURCE_SECONDARY_TYPE = "GEONA_GENERIC_RESOURCE_SECONDARY_TYPE"; public static final String GEONA_GENERIC_RESOURCE_SECONDARY_TYPE = "GEONA_GENERIC_RESOURCE_SECONDARY_TYPE";
private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataEntryServiceImpl.class); 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. * Save geona data forms.
* *
@ -398,7 +421,8 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
LOG.info("getLinksFor called"); LOG.info("getLinksFor called");
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
GeoNaDataViewerProfile grViewerProfile = SessionUtil.getGeportalViewerResourceProfile(getThreadLocalRequest()); GNADataViewerConfigProfile grViewerProfile = SessionUtil
.getGeportalViewerResourceProfile(getThreadLocalRequest());
GeoportalCommon gc = new GeoportalCommon(grViewerProfile); GeoportalCommon gc = new GeoportalCommon(grViewerProfile);
GeoNaItemRef item = new GeoNaItemRef(itemId, recordType.toString().toLowerCase()); GeoNaItemRef item = new GeoNaItemRef(itemId, recordType.toString().toLowerCase());
item = gc.getPublicLinksFor(item, false); item = gc.getPublicLinksFor(item, false);
@ -424,7 +448,6 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
try { try {
SessionUtil.getCurrentContext(getThreadLocalRequest(), true); SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
MongoServiceCommon serviceCommon = new MongoServiceCommon(); MongoServiceCommon serviceCommon = new MongoServiceCommon();
// TODO MUST BE REPLACED BY COUNT // TODO MUST BE REPLACED BY COUNT
@ -725,41 +748,38 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
"Error occurred on updating the project with id: " + itemId + ". Error: " + e.getMessage()); "Error occurred on updating the project with id: " + itemId + ". Error: " + e.getMessage());
} }
} }
/**
* Gets the my rights in the context.
*
* @return the my rights in the context
* @throws Exception the exception
*/
@Override @Override
public UserRights getMyRightsInTheContext() throws Exception { public GNADataEntryExtConfigProfile readDataViewerConfig() throws Exception {
LOG.info("getMyRightsInTheContext called"); LOG.info("readDataViewerConfig called");
GCubeUser user = null; GCubeUser user = null;
GNADataEntryExtConfigProfile gnaDEExtConfig = new GNADataEntryExtConfigProfile();
try { try {
PortalContext pContext = PortalContext.getConfiguration(); PortalContext pContext = PortalContext.getConfiguration();
user = pContext.getCurrentUser(this.getThreadLocalRequest()); user = pContext.getCurrentUser(this.getThreadLocalRequest());
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); String scope = SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
GNADataConfigProfileReader gnaConfigReader = new GNADataConfigProfileReader();
GNADataConfigProfile config = gnaConfigReader.readProfileFromInfrastrucure(); GNADataEntryConfigProfile config = getGNADataEntryConfigProfile();
List<RoleRights> listUserRightsForRole = config.getPermissionsForRole(); List<RoleRights> listUserRightsForRole = config.getPermissionsForRole();
gnaDEExtConfig.setListItemFields(config.getListItemFields());
gnaDEExtConfig.setPermissionsForRole(listUserRightsForRole);
// DEV MODE // DEV MODE
if (!SessionUtil.isIntoPortal()) { if (!SessionUtil.isIntoPortal()) {
LOG.warn("OUT OF PORTAL - DEV MODE detected"); LOG.warn("OUT OF PORTAL - DEV MODE detected");
GcubeUserRole myRole = GcubeUserRole.DATA_MEMBER; GcubeUserRole myRole = GcubeUserRole.DATA_EDITOR;
for (RoleRights roleRight : listUserRightsForRole) { for (RoleRights roleRight : listUserRightsForRole) {
if (roleRight.getUserRole().equals(myRole)) { if (roleRight.getUserRole().equals(myRole)) {
UserRights userRights = new UserRights(user.getUsername(), roleRight); UserRights userRights = new UserRights(user.getUsername(), roleRight);
LOG.warn("DEV MODE returning: " + userRights); LOG.warn("DEV MODE returning: " + userRights);
return userRights; gnaDEExtConfig.setUserRights(userRights);
return gnaDEExtConfig;
} }
} }
} }
String scope = pContext.getCurrentScope(this.getThreadLocalRequest());
long groupId = pContext.getCurrentGroupId(this.getThreadLocalRequest()); long groupId = pContext.getCurrentGroupId(this.getThreadLocalRequest());
if (user == null || scope == null) { if (user == null || scope == null) {
@ -805,29 +825,17 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
} }
UserRights userRights = new UserRights(user.getUsername(), toRoleRight); UserRights userRights = new UserRights(user.getUsername(), toRoleRight);
LOG.info("returning: " + userRights); LOG.info("returning: " + userRights);
return userRights; gnaDEExtConfig.setUserRights(userRights);
} catch (UserRetrievalFault | GroupRetrievalFault | GNAUserRightsConfigException e) { return gnaDEExtConfig;
} catch (UserRetrievalFault | GroupRetrievalFault | GNAConfigException e) {
LOG.error("An error occurred during getMyRightsInTheContext: " + user, e); LOG.error("An error occurred during getMyRightsInTheContext: " + user, e);
Map<ACTION_ON_ITEM, OPERATION_TYPE> permissions = new HashMap<ACTION_ON_ITEM, RoleRights.OPERATION_TYPE>(); Map<ACTION_ON_ITEM, OPERATION_TYPE> permissions = new HashMap<ACTION_ON_ITEM, RoleRights.OPERATION_TYPE>();
RoleRights roleRights = new RoleRights(permissions, GcubeUserRole.DATA_MEMBER); RoleRights roleRights = new RoleRights(permissions, GcubeUserRole.DATA_MEMBER);
UserRights ur = new UserRights(user.getUsername(), roleRights); UserRights ur = new UserRights(user.getUsername(), roleRights);
LOG.warn("Returning default user rights: " + ur); LOG.warn("Returning default user rights: " + ur);
return ur; gnaDEExtConfig.setUserRights(ur);
return gnaDEExtConfig;
} }
} }
// TODO THIS PART REQUIRES THE JSON MAPPING based on keys read from gCube Meta
/**
* List display fields.
*
* @return the list
*/
@Override
public List<ItemField> listDisplayFields() {
GeoportalCommon gc = new GeoportalCommon();
return gc.getGNADataConfig().getListItemFields();
}
} }

View File

@ -13,7 +13,8 @@ import javax.servlet.http.HttpSession;
import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.application.geoportalcommon.GeoportalCommon; 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.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.PortalContext; import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
@ -38,6 +39,8 @@ import com.liferay.portal.service.UserLocalServiceUtil;
*/ */
public class SessionUtil { 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 GEONA_DATAVIEWER_PROFILE = "GEONA_DATAVIEWER_PROFILE";
private static final String LIST_OF_CONCESSIONI = "LIST_OF_CONCESSIONI"; private static final String LIST_OF_CONCESSIONI = "LIST_OF_CONCESSIONI";
/** The log. */ /** The log. */
@ -147,7 +150,7 @@ public class SessionUtil {
SessionUtil.getCurrentContext(httpServletRequest, true); SessionUtil.getCurrentContext(httpServletRequest, true);
MongoServiceUtil serviceUtil = new MongoServiceUtil(); MongoServiceUtil serviceUtil = new MongoServiceUtil();
MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni();
Iterator<Concessione> concessioni = clientMongo.getList(); Iterator<Concessione> concessioni = clientMongo.getList();
if (concessioni != null) { if (concessioni != null) {
while (concessioni.hasNext()) { while (concessioni.hasNext()) {
@ -173,15 +176,15 @@ public class SessionUtil {
* @return the geportal viewer resource profile * @return the geportal viewer resource profile
* @throws Exception the exception * @throws Exception the exception
*/ */
public static GeoNaDataViewerProfile getGeportalViewerResourceProfile(HttpServletRequest httpServletRequest) public static GNADataViewerConfigProfile getGeportalViewerResourceProfile(HttpServletRequest httpServletRequest)
throws Exception { throws Exception {
HttpSession session = httpServletRequest.getSession(); HttpSession session = httpServletRequest.getSession();
GeoNaDataViewerProfile geoNaDataViewerProfile = (GeoNaDataViewerProfile) session GNADataViewerConfigProfile geoNaDataViewerProfile = (GNADataViewerConfigProfile) session
.getAttribute(GEONA_DATAVIEWER_PROFILE); .getAttribute(GEONA_DATAVIEWER_PROFILE);
if (geoNaDataViewerProfile == null) { if (geoNaDataViewerProfile == null) {
GeoportalCommon gc = new GeoportalCommon(); GeoportalCommon gc = new GeoportalCommon();
geoNaDataViewerProfile = gc.getGeoNaDataViewProfile(null); geoNaDataViewerProfile = gc.readGNADataViewerConfig(null);
session.setAttribute(GEONA_DATAVIEWER_PROFILE, geoNaDataViewerProfile); session.setAttribute(GEONA_DATAVIEWER_PROFILE, geoNaDataViewerProfile);
} }
@ -197,18 +200,41 @@ public class SessionUtil {
*/ */
public static ResultSetSorted getLatestResultSetSorted(HttpServletRequest httpServletRequest) { public static ResultSetSorted getLatestResultSetSorted(HttpServletRequest httpServletRequest) {
HttpSession session = httpServletRequest.getSession(); 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. * Gets the latest sort filter.
* *
* @param httpServletRequest the http servlet request * @param httpServletRequest the http servlet request
* @param rsSorted the rs sorted
* @return the latest sort filter * @return the latest sort filter
*/ */
public static void setLatestResultSetSorted(HttpServletRequest httpServletRequest, ResultSetSorted rsSorted) { public static void setLatestResultSetSorted(HttpServletRequest httpServletRequest, ResultSetSorted rsSorted) {
HttpSession session = httpServletRequest.getSession(); 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);
}
} }

View File

@ -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();
}
}