Several fixes due to changed ckan utils library

Added support for multiselection in metadata listboxes

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@131118 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-09-05 16:18:57 +00:00
parent 69fd3467c1
commit 1822ee8c06
7 changed files with 145 additions and 134 deletions

View File

@ -4,6 +4,9 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="ckan-util-library-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ckan-util-library/ckan-util-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="gcube-ckan-datacatalog"/>
<property name="java-output-path" value="/gcube-ckan-datacatalog/target/gcube-ckan-datacatalog-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</wb-module>

View File

@ -71,107 +71,107 @@ public class CkanEventHandlerManager {
// bind on insert metadata
eventBus.addHandler(InsertMetadataEvent.TYPE, new InsertMetadataEventHandler() {
@Override
public void onInsertMetadata(
@Override
public void onInsertMetadata(
InsertMetadataEvent loadSelecteReleaseEvent) {
final Modal modal = new Modal(true, true);
// request who's doing the insert
GCubeCkanDataCatalog.service.getUser(new AsyncCallback<String>() {
final Modal modal = new Modal(true, true);
// request who's doing the insert
GCubeCkanDataCatalog.service.getUser(new AsyncCallback<String>() {
@Override
public void onSuccess(String username) {
@Override
public void onSuccess(String username) {
if (username != null) {
modal.setTitle("Publish Product");
modal.addStyleName("insert-metadata-modal-style");
modal.add(new CreateDatasetForm(username, eventBus));
modal.setCloseVisible(true);
modal.show();
// hide any popup panel opened
modal.addHideHandler(new HideHandler() {
@Override
public void onHide(HideEvent hideEvent) {
eventBus.fireEvent(new CloseCreationFormEvent());
}
});
}
else
Window.alert("Please, logout and login again then retry.");
if (username != null) {
modal.setTitle("Publish Product");
modal.addStyleName("insert-metadata-modal-style");
modal.add(new CreateDatasetForm(username, eventBus));
modal.setCloseVisible(true);
modal.show();
// hide any popup panel opened
modal.addHideHandler(new HideHandler() {
@Override
public void onHide(HideEvent hideEvent) {
eventBus.fireEvent(new CloseCreationFormEvent());
}
});
}
@Override
public void onFailure(Throwable caught) {
else
Window.alert("Please, logout and login again then retry.");
}
});
}
});
}
@Override
public void onFailure(Throwable caught) {
Window.alert("Please, logout and login again then retry.");
}
});
}
});
// bind on edit (TODO)
eventBus.addHandler(
EditMetadataEvent.TYPE, new EditMetadataEventHandler() {
EditMetadataEvent.TYPE, new EditMetadataEventHandler() {
@Override
public void onEditMetadata(EditMetadataEvent editMetadataEvent) {
@Override
public void onEditMetadata(EditMetadataEvent editMetadataEvent) {
// TODO Auto-generated method stub
}
});
// TODO Auto-generated method stub
}
});
// show datasets event
eventBus.addHandler(
ShowUserDatasetsEvent.TYPE, new ShowUserDatasetsEventHandler() {
ShowUserDatasetsEvent.TYPE, new ShowUserDatasetsEventHandler() {
@Override
public void onShowDatasets(
ShowUserDatasetsEvent showUserDatasetsEvent) {
String request = getCkanRequest("/dashboard/datasets", null);
panel.instanceCkanFrame(request);
}
});
@Override
public void onShowDatasets(
ShowUserDatasetsEvent showUserDatasetsEvent) {
String request = getCkanRequest("/dashboard/datasets", null);
panel.instanceCkanFrame(request);
}
});
eventBus.addHandler(
ShowUserOrganizationsEvent.TYPE,
new ShowUserOrganizationsEventHandler() {
ShowUserOrganizationsEvent.TYPE,
new ShowUserOrganizationsEventHandler() {
@Override
public void onShowOrganizations(
ShowUserOrganizationsEvent showUserDatasetsEvent) {
@Override
public void onShowOrganizations(
ShowUserOrganizationsEvent showUserDatasetsEvent) {
panel.showOrganizations();
panel.showOrganizations();
}
});
}
});
eventBus.addHandler(
ShowUserGroupsEvent.TYPE, new ShowUserGroupsEventHandler() {
ShowUserGroupsEvent.TYPE, new ShowUserGroupsEventHandler() {
@Override
public void onShowGroups(ShowUserGroupsEvent showUserDatasetsEvent) {
String request = getCkanRequest("/dashboard/groups", null);
panel.instanceCkanFrame(request);
}
});
@Override
public void onShowGroups(ShowUserGroupsEvent showUserDatasetsEvent) {
String request = getCkanRequest("/dashboard/groups", null);
panel.instanceCkanFrame(request);
}
});
// show statistics event
eventBus.addHandler(
ShowStatisticsEvent.TYPE, new ShowStatisticsEventHandler() {
ShowStatisticsEvent.TYPE, new ShowStatisticsEventHandler() {
@Override
public void onShowStatistics(
ShowStatisticsEvent showStatisticsEvent) {
String request = getCkanRequest("/stats", null);
panel.instanceCkanFrame(request);
}
});
@Override
public void onShowStatistics(
ShowStatisticsEvent showStatisticsEvent) {
String request = getCkanRequest("/stats", null);
panel.instanceCkanFrame(request);
}
});
eventBus.addHandler(NotifyLogoutEvent.TYPE, new NotifyLogoutEventHandler() {
@Override
public void onLogout(NotifyLogoutEvent editMetadataEvent) {
// CKanLeaveFrame frame = new CKanLeaveFrame(GCubeCkanDataCatalog.CKAN_LOGUT_SERVICE);
// DOM.appendChild(RootPanel.getBodyElement(), frame.getElement());
// CKanLeaveFrame frame = new CKanLeaveFrame(GCubeCkanDataCatalog.CKAN_LOGUT_SERVICE);
// DOM.appendChild(RootPanel.getBodyElement(), frame.getElement());
}
});

View File

@ -19,7 +19,7 @@ public interface GcubeCkanDataCatalogService extends RemoteService {
CkanConnectorAccessPoint getCKanConnector(
String pathInfoParameters, String queryStringParameters) throws Exception;
String pathInfoParameters, String queryStringParameters, String currentUrl) throws Exception;
CkanRole getMyRole() throws Exception;

View File

@ -19,30 +19,21 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
*/
public interface GcubeCkanDataCatalogServiceAsync {
void getMyRole(AsyncCallback<CkanRole> callback);
void getUser(AsyncCallback<String> callback);
void getCKanConnector(
String pathInfoParameters, String queryStringParameters,
String pathInfoParameters, String queryStringParameters, String currentUrl,
AsyncCallback<CkanConnectorAccessPoint> callback);
/**
*
*/
void logoutFromCkan(AsyncCallback<Void> callback);
void logoutURIFromCkan(AsyncCallback<String> callback);
void getCkanOrganizationsNamesAndUrlsForUser(
AsyncCallback<Map<String, String>> callback);
void outsidePortal(AsyncCallback<Boolean> callback);
}

View File

@ -14,7 +14,7 @@ public class CKanLeaveFrame extends Frame{
try{
// GCubeCkanDataCatalogPanel.print("Instancing new IFRAME with uri: "+ url);
// GCubeCkanDataCatalogPanel.print("Instancing new IFRAME with uri: "+ url);
getElement().setId("i-frame-logout");
// make it smaller

View File

@ -65,7 +65,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
Window.Location.getParameter(GCubeCkanDataCatalog.GET_QUERY_PARAMETER);
GCubeCkanDataCatalog.service.getCKanConnector(
pathParameter, queryParameter,
pathParameter, queryParameter, Window.Location.getHref(),
new AsyncCallback<CkanConnectorAccessPoint>() {
@Override
@ -138,9 +138,6 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
@Override
public void onFailure(Throwable caught) {
// the portlet is outside the portal and no user is logged in
// show only home and statistics
managementPanel.doNotShowUserRelatedInfo();
}
});

View File

@ -21,13 +21,15 @@ import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.ckanutillibrary.CKanUtils;
import org.gcube.datacatalogue.ckanutillibrary.CKanUtilsImpl;
import org.gcube.datacatalogue.ckanutillibrary.CkanUtilsFactory;
import org.gcube.datacatalogue.ckanutillibrary.utils.ApplicationProfileScopePerUrlReader;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -39,6 +41,7 @@ import eu.trentorise.opendata.traceprov.internal.org.apache.commons.io.IOUtils;
* The server side implementation of the RPC service.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @author Costantino Perciante costantino.perciante@isti.cnr.it
* Jun 10, 2016
*/
@SuppressWarnings("serial")
@ -65,6 +68,9 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
private static final String CKAN_HIGHEST_ROLE = "ckanHighestRole"; // editor, member, admin (this information is retrieved according the scope)
private static final String CKAN_ORGANIZATIONS_PUBLISH_KEY = "ckanOrganizationsPublish"; // here he can publish (admin role)
// THIS IS NEEDED TO HANDLE SPECIAL CASES (e.g. for a certain portlet url we want to discover in another scope)
private final static String CLIENT_PORTLET_URL = "currentClientUrlPortlet";
/**
* Instanciate the ckan util library.
* Since it needs the scope, we need to check if it is null or not
@ -80,16 +86,9 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
CKanUtils instance = null;
try{
if(user.equals(TEST_USER)){
// session expired or, maybe, outside the portal
logger.warn("User is "+TEST_USER +" are we out from portal?");
logger.warn("I'm using root scope "+ CKanUtilsImpl.PRODUCTION_SCOPE_ROOT);
instance = CkanUtilsFactory.getFactory().getUtilsPerScope(CKanUtilsImpl.PRODUCTION_SCOPE_ROOT);
}else{
String scopeInWhichDiscover = (discoverScope != null && !discoverScope.isEmpty()) ? discoverScope : currentScope;
logger.debug("Discovering ckan utils library into scope " + scopeInWhichDiscover);
instance = CkanUtilsFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
}
String scopeInWhichDiscover = (discoverScope != null && !discoverScope.isEmpty()) ? discoverScope : currentScope;
logger.debug("Discovering ckan utils library into scope " + scopeInWhichDiscover);
instance = CkanUtilsFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
}catch(Exception e){
logger.error("Unable to retrieve ckan utils", e);
}
@ -100,23 +99,30 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
* @see org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService#getCKanConnector(java.lang.String, java.lang.String)
*/
@Override
public CkanConnectorAccessPoint getCKanConnector(String pathInfoParameter, String queryStringParameters) throws Exception {
logger.info("getCKanConnector [pathInfo: "+pathInfoParameter + ", query: "+queryStringParameters+"]");
public CkanConnectorAccessPoint getCKanConnector(String pathInfoParameter, String queryStringParameters, String currentUrl) throws Exception {
logger.info("getCKanConnector [pathInfo: "+pathInfoParameter + ", query: "+queryStringParameters+"], current url is " + currentUrl);
try{
// call asl session otherwise ScopeProvider.instance.get(); returns null
ASLSession aslSession = getASLSession(this.getThreadLocalRequest().getSession());
// retrieve scope per current portlet url
String scopePerCurrentUrl = new ApplicationProfileScopePerUrlReader().getScopePerUrl(currentUrl);
// save it
this.getThreadLocalRequest().getSession().setAttribute(CLIENT_PORTLET_URL, currentUrl);
if(queryStringParameters!=null && Base64.isBase64(queryStringParameters.getBytes())){
byte[] valueDecoded=Base64.decodeBase64(queryStringParameters.getBytes());
queryStringParameters = new String(valueDecoded);
logger.info("queryStringParameters detected like Base64 and decoded like: "+queryStringParameters);
}
CkanConnectorAccessPoint ckAP = getCkanConnectorAccessPoint(pathInfoParameter, queryStringParameters);
ASLSession aslSession = getASLSession(this.getThreadLocalRequest().getSession());
SessionUtil.saveCkanAccessPoint(this.getThreadLocalRequest().getSession(), aslSession.getScope(), ckAP);
CkanConnectorAccessPoint ckAP = getCkanConnectorAccessPoint(pathInfoParameter, queryStringParameters, scopePerCurrentUrl);
SessionUtil.saveCkanAccessPoint(this.getThreadLocalRequest().getSession(), scopePerCurrentUrl, ckAP);
logger.info("Builded URI to CKAN Connector: "+ckAP.buildURI());
logger.debug("returning ckanConnectorUri: "+ckAP);
return ckAP;
// return "http://ckan-d-d4s.d4science.org";
}catch(Exception e ){
String message = "Sorry an error occurred during contacting gCube Ckan Data Catalogue";
logger.error(message, e);
@ -133,10 +139,10 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
* @return the ckan connector access point
* @throws Exception
*/
private CkanConnectorAccessPoint getCkanConnectorAccessPoint(String pathInfoParameter, String queryStringParameters) throws Exception {
private CkanConnectorAccessPoint getCkanConnectorAccessPoint(String pathInfoParameter, String queryStringParameters, String scopePerCurrentUrl) throws Exception {
if(outsidePortal()){
CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(getCkanUtilsObj(null).getCatalogueUrl(),"");
CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(getCkanUtilsObj(scopePerCurrentUrl).getCatalogueUrl(),"");
return ckan;
}
@ -144,7 +150,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
ASLSession session = getASLSession(this.getThreadLocalRequest().getSession());
GcoreEndpointReader ckanEndPoint = null;
try{
ckanEndPoint = SessionUtil.getCkanEndPoint(this.getThreadLocalRequest().getSession(), session.getScope());
ckanEndPoint = SessionUtil.getCkanEndPoint(this.getThreadLocalRequest().getSession(), scopePerCurrentUrl);
}catch(Exception e){
logger.error("CkanConnectorAccessPoint error: "+e.getMessage());
throw new Exception("Sorry, an error occurred during contacting d4Science Data Catalogue, try again later");
@ -154,7 +160,6 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
ckanConnectorBaseUrl = ckanConnectorBaseUrl.contains(PORT_HTTP)?ckanConnectorBaseUrl.replace(PORT_HTTP, PORT_HTTPS):ckanConnectorBaseUrl;
logger.debug("Base URL is: "+ckanConnectorBaseUrl);
//GET CONTEXT
String ckanContext = getServletContext().getInitParameter(CKANCONNECTORCONTEXT);
logger.debug(CKANCONNECTORCONTEXT + " is: "+ckanContext);
@ -241,17 +246,16 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
if (user == null) {
logger.warn("****** STARTING IN TEST MODE - NO USER FOUND *******");
//for test only
user = TEST_USER;
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user);
session.setScope(TEST_SCOPE);
//session.setUserEmailAddress(TEST_MAIL);
return session;
} else logger.trace("user found in session "+user);
}
else
logger.trace("user found in session "+user);
return SessionManager.getInstance().getASLSession(sessionID, user);
}
@ -272,12 +276,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
HttpSession httpSession = this.getThreadLocalRequest().getSession();
ASLSession session = getASLSession(httpSession);
String currentScope = session.getScope();
String username = session.getUsername();
String groupName = session.getGroupName(); // e.g. devVRE
// get key per scope
String keyPerScope = UserUtil.concatenateSessionKeyScope(CKAN_HIGHEST_ROLE, session.getScope());
// check if session expired
if(username.equals(TEST_USER)){
@ -285,6 +284,16 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
logger.warn("Session expired, returning " + toReturn);
}else{
// save it
String currentUrl = (String)this.getThreadLocalRequest().getSession().getAttribute(CLIENT_PORTLET_URL);
// retrieve scope per current portlet url
String scopePerCurrentUrl = new ApplicationProfileScopePerUrlReader().getScopePerUrl(currentUrl);
// get key per scope
String keyPerScope = UserUtil.concatenateSessionKeyScope(CKAN_HIGHEST_ROLE, scopePerCurrentUrl);
// check into session
if(httpSession.getAttribute(keyPerScope) != null){
@ -293,18 +302,25 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
}else{
// we build up also a list that keeps track of the scopes (orgs) in which the user has role ADMIN
List<OrganizationBean> orgsInWhichAdminRole = new ArrayList<OrganizationBean>();
toReturn = UserUtil.getHighestRole(currentScope, username, groupName, this, orgsInWhichAdminRole);
httpSession.setAttribute(keyPerScope, toReturn);
try{
GroupManager gm = new LiferayGroupManager();
String groupName = gm.getGroup(gm.getGroupIdFromInfrastructureScope(scopePerCurrentUrl)).getGroupName();
logger.info("Set role " + toReturn + " into session for user " + username);
// we build up also a list that keeps track of the scopes (orgs) in which the user has role ADMIN
List<OrganizationBean> orgsInWhichAdminRole = new ArrayList<OrganizationBean>();
toReturn = UserUtil.getHighestRole(scopePerCurrentUrl, username, groupName, this, orgsInWhichAdminRole);
httpSession.setAttribute(keyPerScope, toReturn);
// if he is an admin preload:
// 1) organizations in which he can publish (the widget will find these info in session)
if(toReturn.equals(CkanRole.ADMIN)){
httpSession.setAttribute(UserUtil.concatenateSessionKeyScope(CKAN_ORGANIZATIONS_PUBLISH_KEY, currentScope), orgsInWhichAdminRole);
logger.info("Set organizations in which he can publish to " + orgsInWhichAdminRole + " into session for user " + username);
logger.info("Set role " + toReturn + " into session for user " + username);
// if he is an admin preload:
// 1) organizations in which he can publish (the widget will find these info in session)
if(toReturn.equals(CkanRole.ADMIN)){
httpSession.setAttribute(UserUtil.concatenateSessionKeyScope(CKAN_ORGANIZATIONS_PUBLISH_KEY, scopePerCurrentUrl), orgsInWhichAdminRole);
logger.info("Set organizations in which he can publish to " + orgsInWhichAdminRole + " into session for user " + username);
}
}catch(Exception e){
logger.error("Error while retreving roles... returning MEMBER", e);
}
}
}
@ -412,8 +428,6 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
@Override
public Map<String, String> getCkanOrganizationsNamesAndUrlsForUser() {
// TODO generate this list dynamically taking into account the current scope
Map<String, String> toReturn = new HashMap<>();
if(!SessionUtil.isIntoPortal()){
@ -427,7 +441,13 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
ASLSession session = getASLSession(httpSession);
String username = session.getUsername();
String keyPerScope = UserUtil.concatenateSessionKeyScope(CKAN_ORGS_USER_KEY, session.getScope());
// get it
String currentUrl = (String)this.getThreadLocalRequest().getSession().getAttribute(CLIENT_PORTLET_URL);
// retrieve scope per current portlet url
String scopePerCurrentUrl = new ApplicationProfileScopePerUrlReader().getScopePerUrl(currentUrl);
String keyPerScope = UserUtil.concatenateSessionKeyScope(CKAN_ORGS_USER_KEY, scopePerCurrentUrl);
if(!username.equals(TEST_USER)){
@ -437,7 +457,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
logger.debug("List of organizations was into the session " + toReturn);
}else{
logger.debug("Organizations list wasn't into session, retrieving them");
List<CkanOrganization> organizations = getCkanUtilsObj(null).getOrganizationsByUser(username);
List<CkanOrganization> organizations = getCkanUtilsObj(scopePerCurrentUrl).getOrganizationsByUser(username);
for (CkanOrganization ckanOrganization : organizations) {
toReturn.put(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName());
}