integrated CLARIN Switchboard with service endpoint query for Switchboard service discovery

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@171466 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2018-09-14 13:38:41 +00:00
parent 94df00cc01
commit 21b00a6f9c
5 changed files with 91 additions and 46 deletions

View File

@ -15,8 +15,12 @@ import com.google.gwt.i18n.client.NumberFormat;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
*/
public class ConstantsExplorer {
public static final String CLARIN_SWITCHBOARD_ENDPOINT = "https://weblicht.sfs.uni-tuebingen.de/clrs/#/d4science/";
public static final String CLARIN_SWITCHBOARD_ENDPOINT_FALLBACK = "https://weblicht.sfs.uni-tuebingen.de/clrs/#/d4science/";
public static final String CLARIN_SWITCHBOARD_ENDPOINT_NAME = "CLARIN Switchboard";
public static final String CLARIN_SWITCHBOARD_ENDPOINT_CATEGORY = "OnlineService";
public static final String PARTHENOS_GATEWAY_HOST_NAME = "parthenos.d4science.org";
//public static final String PARTHENOS_GATEWAY_HOST_NAME = "127.0.0.1"; //for trying in dev
// public static final String FILE_SERVICE = GWT.getModuleBaseURL() + "fileservice";
public static final String RPC_WORKSPACE_SERVICE = GWT.getModuleBaseURL() + "rpcWorkspace";

View File

@ -41,11 +41,10 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
* The Interface GWTWorkspaceService.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 14, 2015
*/
@RemoteServiceRelativePath("WorkspaceService")
public interface GWTWorkspaceService extends RemoteService{
String getLinkForSendToSwitchBoard(String itemId) throws Exception ;
/**
* Gets the servlet context path.
*

View File

@ -42,7 +42,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
* The Interface GWTWorkspaceServiceAsync.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 14, 2015
*/
public interface GWTWorkspaceServiceAsync {
@ -796,4 +795,6 @@ public interface GWTWorkspaceServiceAsync {
*/
void isItemUnderSync(String itemId, AsyncCallback<Boolean> callback);
void getLinkForSendToSwitchBoard(String itemId, AsyncCallback<String> callback);
}

View File

@ -40,7 +40,6 @@ import org.gcube.portlets.user.workspace.client.event.WebDavUrlEvent;
import org.gcube.portlets.user.workspace.client.model.FileModel;
import org.gcube.portlets.user.workspace.client.resources.Resources;
import org.gcube.portlets.user.workspace.client.util.FileModelUtils;
import org.gcube.portlets.user.workspace.client.util.RequestBuilderWorkspaceValidateItem;
import org.gcube.portlets.user.workspace.client.view.tree.CutCopyAndPaste.OperationType;
import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxAlert;
import org.gcube.portlets.user.workspace.shared.PublicLink;
@ -55,7 +54,6 @@ import com.extjs.gxt.ui.client.widget.menu.MenuItem;
import com.extjs.gxt.ui.client.widget.menu.SeparatorMenuItem;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -422,12 +420,10 @@ public class ContextMenuTree {
FileModel sourceFileModel = listSelectedItems.get(0);
if (sourceFileModel != null) {
final MyWindow window = MyWindow.open(null, "_blank", null);
AppControllerExplorer.rpcWorkspaceService.getPublicLinkForFolderItemId(sourceFileModel.getIdentifier(), true, new AsyncCallback<PublicLink>() {
AppControllerExplorer.rpcWorkspaceService.getLinkForSendToSwitchBoard(sourceFileModel.getIdentifier(), new AsyncCallback<String>() {
@Override
public void onSuccess(PublicLink publicLink) {
String encodedURI = com.google.gwt.http.client.URL.encodeQueryString(publicLink.getCompleteURL());
//Window.open(ConstantsExplorer.CLARIN_SWITCHBOARD_ENDPOINT+encodedURI,"_blank","");
window.setUrl(ConstantsExplorer.CLARIN_SWITCHBOARD_ENDPOINT+encodedURI);
public void onSuccess(String link) {
window.setUrl(link);
}
@Override
public void onFailure(Throwable caught) {

View File

@ -1,6 +1,10 @@
package org.gcube.portlets.user.workspace.server;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.io.File;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
@ -44,6 +48,8 @@ import org.gcube.common.homelibrary.home.workspace.search.SearchItem;
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashFolder;
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashItem;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
@ -93,6 +99,8 @@ import org.gcube.portlets.user.workspace.shared.WorkspaceUserQuote;
import org.gcube.portlets.user.workspace.shared.WorkspaceVersioningOperation;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingEntryType;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
@ -2653,7 +2661,23 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
return null;
}
}
@Override
public String getLinkForSendToSwitchBoard(String itemId) throws Exception {
String fallbackValue = ConstantsExplorer.CLARIN_SWITCHBOARD_ENDPOINT_FALLBACK;
String sbEndpoint = "";
try {
sbEndpoint = getCLARINSwitchBoardEndpoint();
}
catch (Exception e) {
workspaceLogger.error("Could not find CLARINSwitchBoardEndpoint on IS, returning fallback value: " + fallbackValue);
sbEndpoint = fallbackValue;
}
String URI = getPublicLinkForFolderItemId(itemId, false).getCompleteURL();
workspaceLogger.debug("Got LinkForSendToSwitchBoard: " + URI + " encoding ...");
String encodedURI = URLEncoder.encode(getPublicLinkForFolderItemId(itemId, false).getCompleteURL(), "UTF-8");
workspaceLogger.debug("LinkForSendToSwitchBoard: " + encodedURI + " encoded ...");
return new StringBuilder(sbEndpoint).append(encodedURI).toString();
}
/**
* Gets the public link for folder item id.
*
@ -4068,8 +4092,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
*/
@Override
public List<FileVersionModel> performOperationOnVersionedFile(
String fileId, List<String> olderVersionIDs,
WorkspaceVersioningOperation operation) throws Exception {
String fileId, List<String> olderVersionIDs,
WorkspaceVersioningOperation operation) throws Exception {
if(fileId == null || olderVersionIDs==null || olderVersionIDs.size()==0)
throw new Exception("File Versioned is null");
@ -4085,45 +4109,45 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
switch (operation) {
case DOWNLOAD: {
//IMPLEMENTED CLIENT-SIDE
break;
case DOWNLOAD: {
//IMPLEMENTED CLIENT-SIDE
break;
}
case DELETE_ALL_OLDER_VERSIONS:{
//MUST BE OPTIMIZED HL-SIDE
for (String olderVersionId : olderVersionIDs) {
extFile.removeVersion(olderVersionId);
workspaceLogger.info("Version "+olderVersionId +" of file id: "+fileId+" removed");
}
return getVersionHistory(fileId);
}
case DELETE_ALL_OLDER_VERSIONS:{
//MUST BE OPTIMIZED HL-SIDE
for (String olderVersionId : olderVersionIDs) {
extFile.removeVersion(olderVersionId);
workspaceLogger.info("Version "+olderVersionId +" of file id: "+fileId+" removed");
}
return getVersionHistory(fileId);
case RESTORE: {
for (String olderVersionId : olderVersionIDs) {
extFile.restoreVersion(olderVersionId);
workspaceLogger.info("Version "+olderVersionId +" of file id: "+fileId+" restored");
}
return getVersionHistory(fileId);
case RESTORE: {
for (String olderVersionId : olderVersionIDs) {
extFile.restoreVersion(olderVersionId);
workspaceLogger.info("Version "+olderVersionId +" of file id: "+fileId+" restored");
}
return getVersionHistory(fileId);
}
case REFRESH: {
return getVersionHistory(fileId);
}
case DELETE_PERMANENTLY: {
for (String olderVersionId : olderVersionIDs) {
extFile.removeVersion(olderVersionId);
workspaceLogger.info("Version "+olderVersionId +" of file id: "+fileId+" removed");
}
return getVersionHistory(fileId);
}
case REFRESH: {
return getVersionHistory(fileId);
}
default:{
case DELETE_PERMANENTLY: {
for (String olderVersionId : olderVersionIDs) {
extFile.removeVersion(olderVersionId);
workspaceLogger.info("Version "+olderVersionId +" of file id: "+fileId+" removed");
}
return getVersionHistory(fileId);
}
default:{
break;
}
break;
}
}
return getVersionHistory(fileId);
@ -4256,7 +4280,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
}
catch (UserRetrievalFault | UserManagementSystemException
| GroupRetrievalFault e) {
| GroupRetrievalFault e) {
workspaceLogger.error("Error occurred server-side getting VRE folders: ", e);
throw new Exception("Sorry, an error occurred server-side getting VRE folders, try again later");
}
@ -4397,4 +4421,25 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
}
}
private String getCLARINSwitchBoardEndpoint() {
//save the context for this resource
String currContext = ScopeProvider.instance.get();
//set the context for this resource
ScopeProvider.instance.set("/"+PortalContext.getConfiguration().getInfrastructureName());
//construct the xquery
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Name/text() eq '"+ ConstantsExplorer.CLARIN_SWITCHBOARD_ENDPOINT_NAME +"'");
query.addCondition("$resource/Profile/Category/text() eq '"+ ConstantsExplorer.CLARIN_SWITCHBOARD_ENDPOINT_CATEGORY +"'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> conf = client.submit(query);
if (conf == null || conf.isEmpty())
return null;
ServiceEndpoint res = conf.get(0);
//reset the context
ScopeProvider.instance.set(currContext);
return res.profile().runtime().hostedOn();
}
}