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@177053 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2019-02-08 14:39:09 +00:00
parent d1a7a9c16b
commit 280a41dbad
1 changed files with 11 additions and 4 deletions

View File

@ -175,31 +175,38 @@ public class CKANPackage extends CKAN {
} }
} }
ArrayNode extrasObjectNode;
boolean found = false;
if(objectNode.has(EXTRAS_KEY)) { if(objectNode.has(EXTRAS_KEY)) {
try { try {
ArrayNode extrasObjectNode = (ArrayNode) objectNode.get(EXTRAS_KEY); extrasObjectNode = (ArrayNode) objectNode.get(EXTRAS_KEY);
for(JsonNode jsonNode : extrasObjectNode) { for(JsonNode jsonNode : extrasObjectNode) {
String key = jsonNode.get(EXTRAS_KEY_KEY).asText(); String key = jsonNode.get(EXTRAS_KEY_KEY).asText();
if(key.compareTo(SEARCHABLE_KEY)==0) { if(key.compareTo(SEARCHABLE_KEY)==0) {
ObjectNode searchableObjectNode = (ObjectNode) jsonNode; ObjectNode searchableObjectNode = (ObjectNode) jsonNode;
searchableObjectNode.put(EXTRAS_VALUE_KEY, true); searchableObjectNode.put(EXTRAS_VALUE_KEY, true);
extrasObjectNode.add(searchableObjectNode); extrasObjectNode.add(searchableObjectNode);
found = true;
break; break;
} }
} }
}catch (Exception e) { }catch (Exception e) {
throw new BadRequestException("Invalid '"+EXTRAS_KEY+"' field", e); throw new BadRequestException("Invalid '"+EXTRAS_KEY+"' field", e);
} }
}else { }else {
ArrayNode extrasObjectNode = mapper.createArrayNode(); extrasObjectNode = mapper.createArrayNode();
}
if(!found) {
ObjectNode searchableObjectNode = mapper.createObjectNode(); ObjectNode searchableObjectNode = mapper.createObjectNode();
searchableObjectNode.put(EXTRAS_KEY_KEY, SEARCHABLE_KEY); searchableObjectNode.put(EXTRAS_KEY_KEY, SEARCHABLE_KEY);
searchableObjectNode.put(EXTRAS_VALUE_KEY, true); searchableObjectNode.put(EXTRAS_VALUE_KEY, true);
extrasObjectNode.add(searchableObjectNode); extrasObjectNode.add(searchableObjectNode);
objectNode.set(EXTRAS_KEY, extrasObjectNode);
} }
objectNode.set(EXTRAS_KEY, extrasObjectNode);
return objectNode; return objectNode;
} }