Fixing social post creation

This commit is contained in:
Luca Frosini 2022-10-21 14:31:38 +02:00
parent 78b1bb6639
commit 9b1190f359
1 changed files with 9 additions and 2 deletions

View File

@ -8,10 +8,13 @@ import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
import org.gcube.common.authorization.library.provider.AccessTokenProvider; import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider; import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.gcat.api.configuration.CatalogueConfiguration; import org.gcube.gcat.api.configuration.CatalogueConfiguration;
import org.gcube.gcat.configuration.CatalogueConfigurationFactory; import org.gcube.gcat.configuration.CatalogueConfigurationFactory;
import org.gcube.gcat.persistence.ckan.CKANUserCache; import org.gcube.gcat.persistence.ckan.CKANUserCache;
import org.gcube.gcat.utils.Constants;
import org.gcube.portal.databook.shared.Post; import org.gcube.portal.databook.shared.Post;
import org.gcube.social_networking.social_networking_client_library.PostClient; import org.gcube.social_networking.social_networking_client_library.PostClient;
import org.gcube.social_networking.socialnetworking.model.beans.PostInputBean; import org.gcube.social_networking.socialnetworking.model.beans.PostInputBean;
@ -126,7 +129,7 @@ public class SocialPost extends Thread {
} }
public void sendSocialPost(boolean notifyUsers) { public void sendSocialPost(boolean notifyUsers) {
SecretManager secretManager = SecretManagerProvider.instance.get();
try { try {
String fullName = CKANUserCache.getCurrrentCKANUser().getNameSurname(); String fullName = CKANUserCache.getCurrrentCKANUser().getNameSurname();
@ -148,6 +151,9 @@ public class SocialPost extends Thread {
logger.debug("The social post that is going to be written is\n{}", message); logger.debug("The social post that is going to be written is\n{}", message);
Secret secret = Constants.getCatalogueSecret();
secretManager.startSession(secret);
logger.trace("The user is going to send the social post is {}", SecretManagerProvider.instance.get().getUser().getUsername()); logger.trace("The user is going to send the social post is {}", SecretManagerProvider.instance.get().getUser().getUsername());
logger.trace("SecurityTokenProvider : {}", SecurityTokenProvider.instance.get()); logger.trace("SecurityTokenProvider : {}", SecurityTokenProvider.instance.get());
@ -160,9 +166,10 @@ public class SocialPost extends Thread {
Post post = postClient.writeApplicationPost(postInputBean); Post post = postClient.writeApplicationPost(postInputBean);
logger.trace("Sent post {}", post); logger.trace("Sent post {}", post);
} catch(Exception e) { } catch(Exception e) {
logger.error("Unable to send Social Post", e); logger.error("Unable to send Social Post", e);
} finally {
secretManager.endSession();
} }
} }