Skip to content
Snippets Groups Projects
Commit e39331e1 authored by Stefan E. Funk's avatar Stefan E. Funk
Browse files

fix: add title again to fieldLoader

parent 8981148a
No related branches found
No related tags found
No related merge requests found
Pipeline #340695 passed
...@@ -395,7 +395,7 @@ public class OaipmhUtilities { ...@@ -395,7 +395,7 @@ public class OaipmhUtilities {
* *
* @param resultFromGetRequestInES * @param resultFromGetRequestInES
* @param fields * @param fields
* @return Returns MORE params as a list! * @return Returns ONE or MORE params as a list!
*/ */
public static List<String> fieldLoader(JSONObject resultFromGetRequestInES, String[] fields) { public static List<String> fieldLoader(JSONObject resultFromGetRequestInES, String[] fields) {
...@@ -404,30 +404,61 @@ public class OaipmhUtilities { ...@@ -404,30 +404,61 @@ public class OaipmhUtilities {
List<String> fieldResults = new ArrayList<String>(); List<String> fieldResults = new ArrayList<String>();
// Loop fields.
int count = 0; int count = 0;
for (String field : fields) { for (String field : fields) {
// Check if field has got "." in it, such as
// "edition.source.bibliographicCitation.placeOfPublication".
String[] fieldPathForESIndex = field.split(ES_DIVIDER_REGEXP); String[] fieldPathForESIndex = field.split(ES_DIVIDER_REGEXP);
log.fine("field[" + count++ + "]: " + field); log.fine("field[" + count++ + "]: " + field);
JSONObject singlePath = resultFromGetRequestInES; JSONObject singlePath = resultFromGetRequestInES;
try { try {
// Loop the splitted field components, such as "edition", "source", etcpp.
for (int i = 0; i < fieldPathForESIndex.length; i++) { for (int i = 0; i < fieldPathForESIndex.length; i++) {
// Case 1: We have only one field component.
if (i < fieldPathForESIndex.length - 1) { if (i < fieldPathForESIndex.length - 1) {
String singleFieldComponent = fieldPathForESIndex[i];
log.fine("case 1: we have only one field component: " + singleFieldComponent);
singlePath = singlePath.getJSONObject(fieldPathForESIndex[i]); singlePath = singlePath.getJSONObject(fieldPathForESIndex[i]);
} else if (fieldPathForESIndex.length == 1) { fieldResults.add(singlePath.toString());
}
// Case 2: We have only one field component??
else if (fieldPathForESIndex.length == 1) {
String singleFieldComponent = fieldPathForESIndex[i];
log.fine("case 2: we have only one field component: " + singleFieldComponent);
JSONObject resultiDingsda = JSONObject resultiDingsda =
resultFromGetRequestInES.getJSONObject(fieldPathForESIndex[i]); resultFromGetRequestInES.getJSONObject(singleFieldComponent);
fieldResults.add(resultiDingsda.toString()); fieldResults.add(resultiDingsda.toString());
} else { }
// Case 3: We have got more field components.
else {
String res = singlePath.get(fieldPathForESIndex[i]).toString(); String res = singlePath.get(fieldPathForESIndex[i]).toString();
log.fine("case 3: we have " + fieldPathForESIndex.length + " components in " + field);
// Examine JSONArray.
if (res.startsWith("[")) { if (res.startsWith("[")) {
log.fine("json array found: " + res);
JSONArray array = new JSONArray(res); JSONArray array = new JSONArray(res);
for (int j = 0; j < array.length(); j++) { for (int j = 0; j < array.length(); j++) {
String find = array.getString(j).toString(); String find = array.getString(j).toString();
fieldResults.add(find); fieldResults.add(find);
} }
} else { }
// Examine
else {
log.fine("no array found: " + res);
fieldResults.add(singlePath.get(fieldPathForESIndex[i]).toString()); fieldResults.add(singlePath.get(fieldPathForESIndex[i]).toString());
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment