Refs #13306: gCat MUST enforce extra field "searchable" in published Items

Task-Url: https://support.d4science.org/issues/13306

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/gcat@177054 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2019-02-08 15:49:30 +00:00
parent 280a41dbad
commit 3e13bbbdde
1 changed files with 15 additions and 34 deletions

View File

@ -80,7 +80,10 @@ public class CKANPackage extends CKAN {
// The 'results' array is included in the 'result' object for package_search
private static final String RESULTS_KEY = "results";
protected static final String PRIVATE_KEY = "private";
protected static final String SEARCHABLE_KEY = "searchable";
// protected static final String INCLUDE_PRIVATE_KEY = "include_private";
// protected static final String INCLUDE_DRAFTS_KEY = "include_drafts";
@ -126,6 +129,16 @@ public class CKANPackage extends CKAN {
itemID = objectNode.get(ID_KEY).asText();
}
// To include private item in search result (e.g. listing) a private package must be searchable
// The package it is jsut included in the search and listing results but remain private and cannot be accessed
// if not authorized
if(objectNode.has(PRIVATE_KEY)) {
boolean privatePackage = objectNode.get(PRIVATE_KEY).asBoolean();
if(privatePackage) {
objectNode.put(SEARCHABLE_KEY, true);
}
}
// check license
String licenseId = null;
if(objectNode.has(LICENSE_KEY)) {
@ -175,38 +188,6 @@ public class CKANPackage extends CKAN {
}
}
ArrayNode extrasObjectNode;
boolean found = false;
if(objectNode.has(EXTRAS_KEY)) {
try {
extrasObjectNode = (ArrayNode) objectNode.get(EXTRAS_KEY);
for(JsonNode jsonNode : extrasObjectNode) {
String key = jsonNode.get(EXTRAS_KEY_KEY).asText();
if(key.compareTo(SEARCHABLE_KEY)==0) {
ObjectNode searchableObjectNode = (ObjectNode) jsonNode;
searchableObjectNode.put(EXTRAS_VALUE_KEY, true);
extrasObjectNode.add(searchableObjectNode);
found = true;
break;
}
}
}catch (Exception e) {
throw new BadRequestException("Invalid '"+EXTRAS_KEY+"' field", e);
}
}else {
extrasObjectNode = mapper.createArrayNode();
}
if(!found) {
ObjectNode searchableObjectNode = mapper.createObjectNode();
searchableObjectNode.put(EXTRAS_KEY_KEY, SEARCHABLE_KEY);
searchableObjectNode.put(EXTRAS_VALUE_KEY, true);
extrasObjectNode.add(searchableObjectNode);
}
objectNode.set(EXTRAS_KEY, extrasObjectNode);
return objectNode;
}
@ -261,8 +242,8 @@ public class CKANPackage extends CKAN {
ArrayNode arrayNode = mapper.createArrayNode();
for(JsonNode node : results) {
try {
String id = node.get(ID_KEY).asText();
arrayNode.add(id);
String name = node.get(NAME_KEY).asText();
arrayNode.add(name);
}catch (Exception e) {
try {
logger.error("Unable to get the ID of {}. the result will not be included in the result", mapper.writeValueAsString(node));