Commented zulip interaction

This commit is contained in:
Luca Frosini 2021-11-25 14:20:08 +01:00
parent 0f3c5e38e0
commit 04ae243f1d
1 changed files with 14 additions and 36 deletions

View File

@ -3,8 +3,6 @@ package org.gcube.gcat.zulip;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.InternalServerErrorException;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
@ -12,8 +10,6 @@ import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.gcat.api.CMItemStatus;
import org.gcube.gcat.persistence.ckan.CKANUser;
import org.gcube.gcat.utils.Constants;
import org.gcube.gcat.utils.ContextUtility;
import org.gcube.gcat.zulip.ZulipResponse.Result;
import org.gcube.storagehub.ApplicationMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -50,8 +46,9 @@ public class ZulipStream {
protected ObjectMapper objectMapper;
protected ZulipRestExecutor getZulipRestExecutor() {
ZulipAuth zulipAuth = new ZulipAuth(ContextUtility.getUsername());
return new ZulipRestExecutor(zulipAuth.getEmail(), zulipAuth.getAPIKey(), zulipAuth.getSite());
// ZulipAuth zulipAuth = new ZulipAuth(ContextUtility.getUsername());
// return new ZulipRestExecutor(zulipAuth.getEmail(), zulipAuth.getAPIKey(), zulipAuth.getSite());
return null;
}
public ZulipStream() {
@ -107,33 +104,16 @@ public class ZulipStream {
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;
// 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;
return null;
}
protected void renameInitialHelloTopic() throws Exception {
// TODO check if it is possible
/*
Integer streamID = getStreamID();
GetAllTopicsOfAStream getAllTopicsOfAStream = new GetAllTopicsOfAStream(streamID.toString());
ZulipResponse zulipResponse = executeZulipCall(gCatZulipRestExecutor, getAllTopicsOfAStream);
JsonNode jsonNode = zulipResponse.getResponse();
ArrayNode arrayNode = (ArrayNode) jsonNode.get(TOPICS_KEY);
String initialTopicID = null;
for(JsonNode node : arrayNode) {
if(node.get(NAME_KEY).asText().compareTo(INITIAL_TOPIC_NAME)==0) {
initialTopicID = node.get(MAX_ID_KEY).asText();
}
}
*/
}
public void create() throws Exception {
ArrayNode streamsArrayNode = objectMapper.createArrayNode();
ObjectNode streamobjectNode = objectMapper.createObjectNode();
@ -162,15 +142,13 @@ public class ZulipStream {
executeZulipCall(gCatZulipRestExecutor, postCreateStream);
renameInitialHelloTopic();
postItemCreated();
}
private Set<String> getCatalogueModerators() {
Set<String> moderators = new HashSet<>();
moderators.add("pasquale.pagano@isti.cnr.it");
moderators.add("leonardo.candela@isti.cnr.it");
// moderators.add("pasquale.pagano@isti.cnr.it");
// moderators.add("leonardo.candela@isti.cnr.it");
return moderators;
}