This commit is contained in:
Francesco Mangiacrapa 2022-03-18 15:40:39 +01:00
parent 6ea950a627
commit fdc6f22ca0
1 changed files with 12 additions and 6 deletions

View File

@ -19,6 +19,7 @@ import org.gcube.gcat.client.Group;
import org.gcube.gcat.client.Item;
import org.gcube.gcat.client.Resource;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -33,6 +34,8 @@ public class GCatCaller {
private GCatCatalogueConfiguration catalogueConfiguration;
private static final Logger LOG = LoggerFactory.getLogger(GCatCaller.class);
public final static String MODERATOR_FIELD_NAME = Moderated.SYSTEM_CM_ITEM_STATUS.replaceAll(":", "");
/**
* Instantiates a new g cat caller.
@ -232,7 +235,7 @@ public class GCatCaller {
Map<String, String> queryParams = new HashMap<String, String>();
// queryParams.put(Moderated.SYSTEM_CM_ITEM_STATUS, status.getValue());
String modStatusField = Moderated.SYSTEM_CM_ITEM_STATUS.replaceAll(":", "");
String modStatusField = GCatCaller.MODERATOR_FIELD_NAME;
queryParams.put("q", "extras_" + modStatusField + ":" + status.getValue());
if (limit < 0)
@ -256,20 +259,23 @@ public class GCatCaller {
*/
public int countListItemsForCMStatus(CMItemStatus status) throws WebServiceException, MalformedURLException {
LOG.trace("countListItemsForCMStatus called");
LOG.info("Calling coun list items for status: " + status);
LOG.info("Calling count list items for status: " + status);
Map<String, String> queryParams = new HashMap<String, String>();
// queryParams.put(Moderated.SYSTEM_CM_ITEM_STATUS, status.getValue());
String modStatusField = Moderated.SYSTEM_CM_ITEM_STATUS.replaceAll(":", "_");
String modStatusField = GCatCaller.MODERATOR_FIELD_NAME;
queryParams.put("q", "extras_" + modStatusField + ":" + status.getValue());
queryParams.put("count", "true");
String theSize = getListItemsForQuery(queryParams);
String theCount = getListItemsForQuery(queryParams);
int count = 0;
try {
count = Integer.parseInt(theSize);
JSONParser parser = new JSONParser();
JSONObject jsonCount = (JSONObject) parser.parse(theCount);
Long total = (Long) jsonCount.get("count");
count = total.intValue();
} catch (Exception e) {
LOG.warn("Size retured by gCat is not an integer, returning: " + count);
LOG.warn("Size retured by gCat is not an integer, returning: " + count, e);
}
return count;
}