diff --git a/CHANGELOG.md b/CHANGELOG.md
index a9c7851..fe085ce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,7 +3,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for gCube Catalogue (gCat) Service
-## [v2.4.1]
+## [v2.4.1-SNAPSHOT]
- Integrating Sphinx for documentation [#23833]
- Migrated Social service interaction to social-service-client [#23151]
diff --git a/pom.xml b/pom.xml
index 90900c2..1b226f3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
org.gcube.data-catalogue
gcat
war
- 2.4.1
+ 2.4.1-SNAPSHOT
gCube Catalogue (gCat) Service
This service allows any client to publish on the gCube Catalogue.
@@ -142,9 +142,9 @@
provided
- org.projectlombok
- lombok
- provided
+ org.projectlombok
+ lombok
+ provided
@@ -199,22 +199,28 @@
20211205
+
org.apache.tika
tika-core
2.1.0
+
+
org.apache.commons
commons-lang3
3.12.0
+
org.gcube.common
diff --git a/src/main/java/org/gcube/gcat/moderation/thread/zulip/ZulipStream.java b/src/main/java/org/gcube/gcat/moderation/thread/zulip/ZulipStream.java
index a180035..d9f1dc6 100644
--- a/src/main/java/org/gcube/gcat/moderation/thread/zulip/ZulipStream.java
+++ b/src/main/java/org/gcube/gcat/moderation/thread/zulip/ZulipStream.java
@@ -1,29 +1,29 @@
package org.gcube.gcat.moderation.thread.zulip;
-import java.util.Set;
-
-import javax.ws.rs.InternalServerErrorException;
-
-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.ObjectNode;
-import org.gcube.common.authorization.utils.manager.SecretManager;
+//import java.util.Set;
+//
+//import javax.ws.rs.InternalServerErrorException;
+//
+//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.ObjectNode;
+//import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
-import org.gcube.common.authorization.utils.secret.Secret;
+//import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.gcat.api.moderation.CMItemStatus;
-import org.gcube.gcat.api.moderation.Moderated;
+//import org.gcube.gcat.api.moderation.Moderated;
import org.gcube.gcat.moderation.thread.ModerationThread;
-import org.gcube.gcat.moderation.thread.zulip.ZulipResponse.Result;
-import org.gcube.gcat.social.SocialUsers;
-import org.gcube.gcat.utils.Constants;
+//import org.gcube.gcat.moderation.thread.zulip.ZulipResponse.Result;
+//import org.gcube.gcat.social.SocialUsers;
+//import org.gcube.gcat.utils.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import io.taliox.zulip.ZulipRestExecutor;
-import io.taliox.zulip.calls.ZulipRestAPICall;
-import io.taliox.zulip.calls.messages.PostMessage;
-import io.taliox.zulip.calls.streams.GetStreamID;
-import io.taliox.zulip.calls.streams.PostCreateStream;
+//import io.taliox.zulip.ZulipRestExecutor;
+//import io.taliox.zulip.calls.ZulipRestAPICall;
+//import io.taliox.zulip.calls.messages.PostMessage;
+//import io.taliox.zulip.calls.streams.GetStreamID;
+//import io.taliox.zulip.calls.streams.PostCreateStream;
/**
* @author Luca Frosini (ISTI - CNR)
@@ -31,123 +31,141 @@ import io.taliox.zulip.calls.streams.PostCreateStream;
public class ZulipStream extends ModerationThread {
private static final Logger logger = LoggerFactory.getLogger(ZulipStream.class);
-
- public static final String TOPICS_KEY = "topics";
- public static final String NAME_KEY = "name";
- public static final String MAX_ID_KEY = "max_id";
- public static final String INITIAL_TOPIC_NAME = "hello";
-
- protected ZulipRestExecutor gCatZulipRestExecutor;
- protected ZulipRestExecutor userZulipRestExecutor;
-
- protected String streamName;
- protected String streamDescription;
-
- public ZulipStream() {
- super();
+
+ @Override
+ protected void postMessage(String message) throws Exception {
+ logger.info("gCat is sending a message to the {} for item '{}' (id={}). ItemStatus={}, Message=\"{}\"",
+ ZulipStream.class.getSimpleName(), itemName, itemID, cmItemStatus, message);
}
-
- protected ZulipRestExecutor getZulipRestExecutor() {
- ZulipAuth zulipAuth = new ZulipAuth(SecretManagerProvider.instance.get().getUser().getUsername());
- return new ZulipRestExecutor(zulipAuth.getEmail(), zulipAuth.getAPIKey(), zulipAuth.getSite());
- }
-
- public ZulipRestExecutor getGCatZulipRestExecutor() throws Exception {
- if(gCatZulipRestExecutor==null) {
- SecretManager secretManager = SecretManagerProvider.instance.get();
- Secret secret = Constants.getCatalogueSecret();
- secretManager.startSession(secret);
- gCatZulipRestExecutor = getZulipRestExecutor();
- secretManager.endSession();
- }
- return gCatZulipRestExecutor;
- }
-
- public ZulipRestExecutor getUserZulipRestExecutor() {
- if(userZulipRestExecutor==null) {
- userZulipRestExecutor = getZulipRestExecutor();
- }
- return userZulipRestExecutor;
- }
-
- protected String getStreamName() {
- if(streamName==null) {
- streamName = String.format("Item '%s' moderation", itemID);
- }
- return streamName;
- }
-
- protected Integer getStreamID() throws Exception {
- GetStreamID getStreamID = new GetStreamID(getStreamName());
- ZulipResponse zulipResponse = executeZulipCall(gCatZulipRestExecutor, getStreamID);
- JsonNode response = zulipResponse.getResponse();
- return response.get("stream_id").asInt();
- }
-
- protected String getStreamDescription() {
- if(streamDescription==null) {
- streamDescription = String.format("This stream is used to discuss about the moderation of the item '%s' with id '%s'", itemName, itemID);
- }
- return streamDescription;
- }
-
- protected ZulipResponse executeZulipCall(ZulipRestExecutor zulipRestExecutor, ZulipRestAPICall call) throws Exception {
- logger.trace("Going to execute {}", call);
- String responseString = zulipRestExecutor.executeCall(call);
- logger.trace("Response from {} is {}", call.getClass().getSimpleName(), responseString);
- ZulipResponse zulipResponse = new ZulipResponse(responseString);
- if(zulipResponse.getResponseResult()==Result.error) {
- throw new InternalServerErrorException(zulipResponse.getResponseMessage());
- }
- return zulipResponse;
+
+ @Override
+ public void postUserMessage(CMItemStatus cmItemStatus, String userMessage) throws Exception {
+ logger.info("{} is sending a message to the {} for item '{}' (id={}). ItemStatus={}, Message=\"{}\"",
+ SecretManagerProvider.instance.get().getUser().getUsername(),
+ ZulipStream.class.getSimpleName(), itemName, itemID, cmItemStatus, userMessage);
}
@Override
protected void createModerationThread() throws Exception {
- ArrayNode streamsArrayNode = objectMapper.createArrayNode();
- ObjectNode streamobjectNode = objectMapper.createObjectNode();
- streamobjectNode.put("name", getStreamName());
- streamobjectNode.put("description", getStreamDescription());
- streamsArrayNode.add(streamobjectNode);
-
- ArrayNode principalsArrayNode = objectMapper.createArrayNode();
- // Going to add the item creator
- String itemCreatorEmail = ckanUser.getEMail();
- principalsArrayNode.add(itemCreatorEmail);
-
- getGCatZulipRestExecutor();
-
- principalsArrayNode.add(gCatZulipRestExecutor.httpController.getUserName());
-
- // Going to add the catalogue moderators
- Set moderators = SocialUsers.getUsernamesByRole(Moderated.CATALOGUE_MODERATOR);
- for(String moderator : moderators) {
- principalsArrayNode.add(moderator);
- }
-
- PostCreateStream postCreateStream = new PostCreateStream(streamsArrayNode.toString());
- postCreateStream.setPrincipals(principalsArrayNode.toString());
- postCreateStream.setInvite_only(true);
- postCreateStream.setAnnounce(false);
-
- executeZulipCall(gCatZulipRestExecutor, postCreateStream);
+ logger.info("Creating {} for item '{}' (id={})", ZulipStream.class.getSimpleName(), itemName, itemID);
}
- protected void postMessageToStream(ZulipRestExecutor zulipRestExecutor, String message) throws Exception {
- PostMessage postMessage = new PostMessage(getStreamName(), cmItemStatus.getFancyValue(), message);
- logger.debug("Going to send the following message: {}", message);
- executeZulipCall(zulipRestExecutor, postMessage);
- }
-
- @Override
- protected void postMessage(String message) throws Exception {
- postMessageToStream(getGCatZulipRestExecutor(), message);
- }
-
- @Override
- public void postUserMessage(CMItemStatus cmItemStatus, String message) throws Exception {
- this.cmItemStatus = cmItemStatus;
- postMessageToStream(getUserZulipRestExecutor(), message);
- }
+// public static final String TOPICS_KEY = "topics";
+// public static final String NAME_KEY = "name";
+// public static final String MAX_ID_KEY = "max_id";
+// public static final String INITIAL_TOPIC_NAME = "hello";
+//
+// protected ZulipRestExecutor gCatZulipRestExecutor;
+// protected ZulipRestExecutor userZulipRestExecutor;
+//
+// protected String streamName;
+// protected String streamDescription;
+//
+// public ZulipStream() {
+// super();
+// }
+//
+// protected ZulipRestExecutor getZulipRestExecutor() {
+// ZulipAuth zulipAuth = new ZulipAuth(SecretManagerProvider.instance.get().getUser().getUsername());
+// return new ZulipRestExecutor(zulipAuth.getEmail(), zulipAuth.getAPIKey(), zulipAuth.getSite());
+// }
+//
+// public ZulipRestExecutor getGCatZulipRestExecutor() throws Exception {
+// if(gCatZulipRestExecutor==null) {
+// SecretManager secretManager = SecretManagerProvider.instance.get();
+// Secret secret = Constants.getCatalogueSecret();
+// secretManager.startSession(secret);
+// gCatZulipRestExecutor = getZulipRestExecutor();
+// secretManager.endSession();
+// }
+// return gCatZulipRestExecutor;
+// }
+//
+// public ZulipRestExecutor getUserZulipRestExecutor() {
+// if(userZulipRestExecutor==null) {
+// userZulipRestExecutor = getZulipRestExecutor();
+// }
+// return userZulipRestExecutor;
+// }
+//
+// protected String getStreamName() {
+// if(streamName==null) {
+// streamName = String.format("Item '%s' moderation", itemID);
+// }
+// return streamName;
+// }
+//
+// protected Integer getStreamID() throws Exception {
+// GetStreamID getStreamID = new GetStreamID(getStreamName());
+// ZulipResponse zulipResponse = executeZulipCall(gCatZulipRestExecutor, getStreamID);
+// JsonNode response = zulipResponse.getResponse();
+// return response.get("stream_id").asInt();
+// }
+//
+// protected String getStreamDescription() {
+// if(streamDescription==null) {
+// streamDescription = String.format("This stream is used to discuss about the moderation of the item '%s' with id '%s'", itemName, itemID);
+// }
+// return streamDescription;
+// }
+//
+// protected ZulipResponse executeZulipCall(ZulipRestExecutor zulipRestExecutor, ZulipRestAPICall call) throws Exception {
+// logger.trace("Going to execute {}", call);
+// String responseString = zulipRestExecutor.executeCall(call);
+// logger.trace("Response from {} is {}", call.getClass().getSimpleName(), responseString);
+// ZulipResponse zulipResponse = new ZulipResponse(responseString);
+// if(zulipResponse.getResponseResult()==Result.error) {
+// throw new InternalServerErrorException(zulipResponse.getResponseMessage());
+// }
+// return zulipResponse;
+// }
+//
+// @Override
+// protected void createModerationThread() throws Exception {
+// ArrayNode streamsArrayNode = objectMapper.createArrayNode();
+// ObjectNode streamobjectNode = objectMapper.createObjectNode();
+// streamobjectNode.put("name", getStreamName());
+// streamobjectNode.put("description", getStreamDescription());
+// streamsArrayNode.add(streamobjectNode);
+//
+// ArrayNode principalsArrayNode = objectMapper.createArrayNode();
+// // Going to add the item creator
+// String itemCreatorEmail = ckanUser.getEMail();
+// principalsArrayNode.add(itemCreatorEmail);
+//
+// getGCatZulipRestExecutor();
+//
+// principalsArrayNode.add(gCatZulipRestExecutor.httpController.getUserName());
+//
+// // Going to add the catalogue moderators
+// Set moderators = SocialUsers.getUsernamesByRole(Moderated.CATALOGUE_MODERATOR);
+// for(String moderator : moderators) {
+// principalsArrayNode.add(moderator);
+// }
+//
+// PostCreateStream postCreateStream = new PostCreateStream(streamsArrayNode.toString());
+// postCreateStream.setPrincipals(principalsArrayNode.toString());
+// postCreateStream.setInvite_only(true);
+// postCreateStream.setAnnounce(false);
+//
+// executeZulipCall(gCatZulipRestExecutor, postCreateStream);
+// }
+//
+// protected void postMessageToStream(ZulipRestExecutor zulipRestExecutor, String message) throws Exception {
+// PostMessage postMessage = new PostMessage(getStreamName(), cmItemStatus.getFancyValue(), message);
+// logger.debug("Going to send the following message: {}", message);
+// executeZulipCall(zulipRestExecutor, postMessage);
+// }
+//
+// @Override
+// protected void postMessage(String message) throws Exception {
+// postMessageToStream(getGCatZulipRestExecutor(), message);
+// }
+//
+// @Override
+// public void postUserMessage(CMItemStatus cmItemStatus, String message) throws Exception {
+// this.cmItemStatus = cmItemStatus;
+// postMessageToStream(getUserZulipRestExecutor(), message);
+// }
}
diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java
index f12616a..173daa3 100644
--- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java
+++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java
@@ -14,11 +14,10 @@ import java.util.regex.Pattern;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.ForbiddenException;
import javax.ws.rs.InternalServerErrorException;
-import javax.ws.rs.NotAllowedException;
+import javax.ws.rs.NotAuthorizedException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MultivaluedMap;
-import org.apache.http.MethodNotSupportedException;
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.ObjectNode;
@@ -1469,11 +1468,11 @@ public class CKANPackage extends CKAN implements Moderated {
break;
case REJECTED:
- throw new MethodNotSupportedException("You can't approve a rejected item. The item must be updated first. The update will set the item in pending, than it can be approved/rejected.");
+ throw new BadRequestException("You can't approve a rejected item. The item must be updated first. The update will set the item in pending, than it can be approved/rejected.");
case PENDING:
if(!ckanUser.isCatalogueModerator()) {
- throw new MethodNotSupportedException("Only catalogue moderator can approve a pending item.");
+ throw new NotAuthorizedException("Only catalogue moderator can approve a pending item.");
}
setToApproved(result);
@@ -1502,7 +1501,7 @@ public class CKANPackage extends CKAN implements Moderated {
}
return getAsCleanedString(result);
}
- throw new MethodNotSupportedException("The approve operation is available only in moderation mode");
+ throw new BadRequestException("The approve operation is available only in moderation mode");
}catch(WebApplicationException e) {
throw e;
} catch(Exception e) {
@@ -1518,7 +1517,7 @@ public class CKANPackage extends CKAN implements Moderated {
CMItemStatus cmItemStatus = getCMItemStatus();
switch (cmItemStatus) {
case APPROVED:
- throw new MethodNotSupportedException("You can't rejected an approved item. The item must be updated first. The update will set the item in pending, than it can be approved/rejected.");
+ throw new BadRequestException("You can't rejected an approved item. The item must be updated first. The update will set the item in pending, than it can be approved/rejected.");
case REJECTED:
// Nothing TO DO
@@ -1526,7 +1525,7 @@ public class CKANPackage extends CKAN implements Moderated {
case PENDING:
if(!ckanUser.isCatalogueModerator()) {
- throw new MethodNotSupportedException("Only catalogue moderator can reject a pending item.");
+ throw new NotAuthorizedException("Only catalogue moderator can reject a pending item.");
}
setToRejected(result);
@@ -1549,7 +1548,7 @@ public class CKANPackage extends CKAN implements Moderated {
}
return getAsCleanedString(result);
}
- throw new MethodNotSupportedException("The reject operation is available only in moderation mode");
+ throw new BadRequestException("The reject operation is available only in moderation mode");
}catch(WebApplicationException e) {
throw e;
} catch(Exception e) {
@@ -1573,7 +1572,7 @@ public class CKANPackage extends CKAN implements Moderated {
if(!ckanUser.isCatalogueModerator()) {
// Users that are not
if(!isItemCreator()) {
- throw new NotAllowedException("Only item creator and " + Moderated.CATALOGUE_MODERATOR + "s are entitled to partecipate to the moderation discussion thread.");
+ throw new NotAuthorizedException("Only item creator and " + Moderated.CATALOGUE_MODERATOR + "s are entitled to partecipate to the moderation discussion thread.");
}else {
moderationThread.setItemAuthor(true);
}
@@ -1585,7 +1584,7 @@ public class CKANPackage extends CKAN implements Moderated {
moderationThread.postUserMessage(cmItemStatus, message);
return;
}
- throw new MethodNotSupportedException("The message operation is available only in moderation mode");
+ throw new BadRequestException("The message operation is available only in moderation mode");
}catch(WebApplicationException e) {
throw e;
} catch(Exception e) {