Fixed getSystemType

This commit is contained in:
Luca Frosini 2024-05-14 14:37:54 +02:00
parent 4acb0d0b76
commit 120e807625
2 changed files with 8 additions and 8 deletions

View File

@ -944,7 +944,7 @@ public class CKANPackage extends CKAN implements Moderated {
public static final String JSON_PATH_EXPRESSION_FIND_SYSTEM_TYPE_METADATA = "$.extras[?(@.key == 'system:type')].value";
public static final String JSON_PATH_EXPRESSION_FIND_MODERATION_SYSTEM_METADATA = "$.extras[?(@.key =~ /system\\:cm_.*?/i)]";
protected static Map<String, String> getExtraFieldsViaJsonPath(String json, String jsonPath){
public static Map<String, String> getExtraFieldsViaJsonPath(String json, String jsonPath){
JSONArray array = JsonPath.read(json, jsonPath);
logger.trace("Found system metadata {} ", array);
@ -958,15 +958,15 @@ public class CKANPackage extends CKAN implements Moderated {
return systemFieldMap;
}
protected static Map<String, String> getSystemMetadata(String json){
public static Map<String, String> getSystemMetadata(String json){
return getExtraFieldsViaJsonPath(json, JSON_PATH_EXPRESSION_FIND_SYSTEM_METADATA);
}
protected static Map<String, String> getSystemTypeMetadataMap(String json){
public static Map<String, String> getSystemTypeMetadataMap(String json){
return getExtraFieldsViaJsonPath(json, JSON_PATH_EXPRESSION_FIND_SYSTEM_TYPE_METADATA);
}
protected static String getSystemTypeMetadata(String json){
public static String getSystemTypeMetadata(String json){
JSONArray array = JsonPath.read(json, JSON_PATH_EXPRESSION_FIND_SYSTEM_TYPE_METADATA);
logger.trace("Found system type metadata {} ", array);
@ -974,12 +974,10 @@ public class CKANPackage extends CKAN implements Moderated {
throw new BadRequestException("System Type must be one. Got " + array.toString());
}
@SuppressWarnings("unchecked")
LinkedHashMap<String, String> element = (LinkedHashMap<String, String>) array.get(0);
return element.get(EXTRAS_VALUE_KEY);
return (String) array.get(0);
}
protected static Map<String, String> getModerationSystemMetadata(String json){
public static Map<String, String> getModerationSystemMetadata(String json){
return getExtraFieldsViaJsonPath(json, JSON_PATH_EXPRESSION_FIND_MODERATION_SYSTEM_METADATA);
}

View File

@ -49,6 +49,8 @@ public class JsonPathTester {
Assert.assertTrue(systemType.size()==1);
logger.trace("System Type : {}", systemType);
String systemTypeString = CKANPackage.getSystemTypeMetadata(json);
logger.trace("System Type String : {}", systemTypeString);
JSONArray systemMetadata = JsonPath.read(json, CKANPackage.JSON_PATH_EXPRESSION_FIND_SYSTEM_METADATA);
logger.trace("System Metadata {} ", systemMetadata);