minor fix for support of #11139
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@163125 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c425ed2c92
commit
60d3b61185
|
@ -370,7 +370,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
datasetUrl,
|
datasetUrl,
|
||||||
false, // send notification to other people
|
false, // send notification to other people
|
||||||
toCreate.getTags(),
|
toCreate.getTags(),
|
||||||
GenericUtils.getCurrentUser(getThreadLocalRequest()).getFullname()
|
GenericUtils.getCurrentUser(getThreadLocalRequest()).getFullname(),
|
||||||
|
GenericUtils.getCurrentClientUrl(getThreadLocalRequest())
|
||||||
);
|
);
|
||||||
threadWritePost.start();
|
threadWritePost.start();
|
||||||
|
|
||||||
|
|
|
@ -72,45 +72,6 @@ public class AssociationToGroupAndNotifyThread extends Thread {
|
||||||
|
|
||||||
logger.info("Association thread started to put the dataset with id = "+ datasetId + " into group with title " + groupTitle + " for user " + username);
|
logger.info("Association thread started to put the dataset with id = "+ datasetId + " into group with title " + groupTitle + " for user " + username);
|
||||||
|
|
||||||
// if(groupTitle != null){
|
|
||||||
// try{
|
|
||||||
//
|
|
||||||
// // create the group
|
|
||||||
// CkanGroup group = catalogue.createGroup(groupTitle, groupTitle, "");
|
|
||||||
//
|
|
||||||
// if(group == null){
|
|
||||||
//
|
|
||||||
// logger.warn("The group doesn't exist! Unable to perform such association");
|
|
||||||
//
|
|
||||||
// }else{
|
|
||||||
//
|
|
||||||
// logger.debug("Group exists, going to add the user " + username + " as its admin...");
|
|
||||||
//
|
|
||||||
// // retrieve the role to be assigned according the one the user has into the organization of the dataset
|
|
||||||
// RolesCkanGroupOrOrg role = RolesCkanGroupOrOrg.valueOf(catalogue.getRoleOfUserInOrganization(username, organization, catalogue.getApiKeyFromUsername(username)).toUpperCase());
|
|
||||||
//
|
|
||||||
// if(!role.equals(RolesCkanGroupOrOrg.ADMIN))
|
|
||||||
// role = RolesCkanGroupOrOrg.MEMBER; // decrease the role to member if it is not an admin
|
|
||||||
//
|
|
||||||
// boolean assigned = catalogue.checkRoleIntoGroup(username, groupTitle, role);
|
|
||||||
//
|
|
||||||
// if(assigned){
|
|
||||||
//
|
|
||||||
// logger.debug("Admin/editor role was assigned for this group, going to associate the product to the group");
|
|
||||||
// boolean putIntoGroup = catalogue.assignDatasetToGroup(groupTitle, datasetId, catalogue.getApiKeyFromUsername(username));
|
|
||||||
// logger.info("Was product put into group? " + putIntoGroup);
|
|
||||||
//
|
|
||||||
// if(putIntoGroup)
|
|
||||||
// notifyGroupAdmins(catalogue, group.getName(), group.getTitle(), username);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }catch(Exception e){
|
|
||||||
// logger.warn("Something went wrong when tried to add the group " + groupTitle, e);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// force creation of groups if needed
|
// force creation of groups if needed
|
||||||
if(groupsForceCreation != null){
|
if(groupsForceCreation != null){
|
||||||
logger.info("Groups that must be created before association are " + groupsForceCreation);
|
logger.info("Groups that must be created before association are " + groupsForceCreation);
|
||||||
|
|
|
@ -2,10 +2,13 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.portal.GCubePortalConstants;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.portal.databook.client.GCubeSocialNetworking;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GCoreEndPointReaderSocial;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GCoreEndPointReaderSocial;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GenericUtils;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GenericUtils;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
@ -34,8 +37,8 @@ public class WritePostCatalogueManagerThread extends Thread {
|
||||||
|
|
||||||
private static final String APPLICATION_ID_CATALOGUE_MANAGER = "org.gcube.datacatalogue.ProductCatalogue";
|
private static final String APPLICATION_ID_CATALOGUE_MANAGER = "org.gcube.datacatalogue.ProductCatalogue";
|
||||||
private static final String NOTIFICATION_MESSAGE = "Dear members,<br>The item '$PRODUCT_TITLE' has been just published by $USER_FULLNAME.<br>You can find it here: $PRODUCT_URL <br>";
|
private static final String NOTIFICATION_MESSAGE = "Dear members,<br>The item '$PRODUCT_TITLE' has been just published by $USER_FULLNAME.<br>You can find it here: $PRODUCT_URL <br>";
|
||||||
private static final String SOCIAL_SERVICE_APPLICATION_TOKEN = "/2/tokens/generate-application-token";
|
private static final String SOCIAL_SERVICE_APPLICATION_TOKEN = "2/tokens/generate-application-token";
|
||||||
private static final String SOCIAL_SERVICE_WRITE_APPLICATION_POST = "/2/posts/write-post-app";
|
private static final String SOCIAL_SERVICE_WRITE_APPLICATION_POST = "2/posts/write-post-app";
|
||||||
private static final String MEDIATYPE_JSON = "application/json";
|
private static final String MEDIATYPE_JSON = "application/json";
|
||||||
private static final Log logger = LogFactoryUtil.getLog(WritePostCatalogueManagerThread.class);
|
private static final Log logger = LogFactoryUtil.getLog(WritePostCatalogueManagerThread.class);
|
||||||
// private static Logger logger = LoggerFactory.getLogger(WritePostCatalogueManagerThread.class);
|
// private static Logger logger = LoggerFactory.getLogger(WritePostCatalogueManagerThread.class);
|
||||||
|
@ -46,6 +49,7 @@ public class WritePostCatalogueManagerThread extends Thread {
|
||||||
private boolean enableNotification;
|
private boolean enableNotification;
|
||||||
private List<String> hashtags;
|
private List<String> hashtags;
|
||||||
private String userFullName;
|
private String userFullName;
|
||||||
|
private String userCurrentUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param token
|
* @param token
|
||||||
|
@ -59,7 +63,7 @@ public class WritePostCatalogueManagerThread extends Thread {
|
||||||
public WritePostCatalogueManagerThread(
|
public WritePostCatalogueManagerThread(
|
||||||
String username, String scope,
|
String username, String scope,
|
||||||
String productTitle, String productUrl, boolean enableNotification,
|
String productTitle, String productUrl, boolean enableNotification,
|
||||||
List<String> hashtags, String userFullName) {
|
List<String> hashtags, String userFullName, String userCurrentUrl) {
|
||||||
super();
|
super();
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
|
@ -68,6 +72,7 @@ public class WritePostCatalogueManagerThread extends Thread {
|
||||||
this.enableNotification = enableNotification;
|
this.enableNotification = enableNotification;
|
||||||
this.hashtags = hashtags;
|
this.hashtags = hashtags;
|
||||||
this.userFullName = userFullName;
|
this.userFullName = userFullName;
|
||||||
|
this.userCurrentUrl = userCurrentUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -90,6 +95,13 @@ public class WritePostCatalogueManagerThread extends Thread {
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
SecurityTokenProvider.instance.set(token);
|
SecurityTokenProvider.instance.set(token);
|
||||||
|
|
||||||
|
final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + extractOrgFriendlyURL(userCurrentUrl) + GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
|
||||||
|
|
||||||
|
userFullName = "<a class=\"link\" href=\"" + profilePageURL + "?"+
|
||||||
|
Base64.getEncoder().encodeToString(GCubeSocialNetworking.USER_PROFILE_OID.getBytes())+"="+
|
||||||
|
Base64.getEncoder().encodeToString(username.getBytes())+"\">"+userFullName+
|
||||||
|
"</a> ";
|
||||||
|
|
||||||
// write
|
// write
|
||||||
writeProductPost(
|
writeProductPost(
|
||||||
productTitle,
|
productTitle,
|
||||||
|
@ -107,6 +119,21 @@ public class WritePostCatalogueManagerThread extends Thread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String extractOrgFriendlyURL(String portalURL) {
|
||||||
|
String groupRegEx = "/group/";
|
||||||
|
if (portalURL.contains(groupRegEx)) {
|
||||||
|
String[] splits = portalURL.split(groupRegEx);
|
||||||
|
String friendlyURL = splits[1];
|
||||||
|
if (friendlyURL.contains("/")) {
|
||||||
|
friendlyURL = friendlyURL.split("/")[0];
|
||||||
|
} else {
|
||||||
|
friendlyURL = friendlyURL.split("\\?")[0].split("\\#")[0];
|
||||||
|
}
|
||||||
|
return "/"+friendlyURL;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send notification to vre members about the created product by writing a post.
|
* Send notification to vre members about the created product by writing a post.
|
||||||
* @param productName the title of the product
|
* @param productName the title of the product
|
||||||
|
@ -158,7 +185,9 @@ public class WritePostCatalogueManagerThread extends Thread {
|
||||||
String token = null;
|
String token = null;
|
||||||
try{
|
try{
|
||||||
|
|
||||||
HttpResponse response = performRequest(client, path, "{\"app_id\":\"" + APPLICATION_ID_CATALOGUE_MANAGER + "\"}");
|
JSONObject request = new JSONObject();
|
||||||
|
request.put("app_id", APPLICATION_ID_CATALOGUE_MANAGER);
|
||||||
|
HttpResponse response = performRequest(client, path, request.toJSONString());
|
||||||
|
|
||||||
int statusTokenGenerate = response.getStatusLine().getStatusCode();
|
int statusTokenGenerate = response.getStatusLine().getStatusCode();
|
||||||
|
|
||||||
|
@ -218,9 +247,11 @@ public class WritePostCatalogueManagerThread extends Thread {
|
||||||
message += " #" + modifiedHashtag; // ckan accepts tag with empty spaces, we don't
|
message += " #" + modifiedHashtag; // ckan accepts tag with empty spaces, we don't
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("The post that is going to be written is -> " + message);
|
JSONObject request = new JSONObject();
|
||||||
|
request.put("text", message);
|
||||||
HttpResponse response = performRequest(client, path, "{\"text\":\"" + message + "\", \"enable_notification\" : "+ enablePostNotification+ "}");
|
request.put("enable_notification", enablePostNotification);
|
||||||
|
logger.info("The post that is going to be written is ->\n" + request.toJSONString());
|
||||||
|
HttpResponse response = performRequest(client, path, request.toJSONString());
|
||||||
int statusWritePost = response.getStatusLine().getStatusCode();
|
int statusWritePost = response.getStatusLine().getStatusCode();
|
||||||
|
|
||||||
if(statusWritePost == HttpURLConnection.HTTP_CREATED){
|
if(statusWritePost == HttpURLConnection.HTTP_CREATED){
|
||||||
|
@ -244,14 +275,14 @@ public class WritePostCatalogueManagerThread extends Thread {
|
||||||
writePost(client, realLocation, productName, productUrl, userFullname, hashtags, enablePostNotification);
|
writePost(client, realLocation, productName, productUrl, userFullname, hashtags, enablePostNotification);
|
||||||
|
|
||||||
}else
|
}else
|
||||||
throw new RuntimeException("Failed to write the post");
|
throw new RuntimeException("Failed to write the post ");
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Failed to retrieve application token", e);
|
logger.error("Failed to write the post ", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the json response to a map
|
* Convert the json response to a map
|
||||||
* @param response
|
* @param response
|
||||||
|
|
Loading…
Reference in New Issue