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

fix: add reducing singleField again.... had to understand it first

parent e39331e1
No related branches found
No related tags found
No related merge requests found
Pipeline #340705 passed
......@@ -396,8 +396,11 @@ public class OaipmhUtilities {
* @param resultFromGetRequestInES
* @param fields
* @return Returns ONE or MORE params as a list!
* @deprecated
*/
public static List<String> fieldLoader(JSONObject resultFromGetRequestInES, String[] fields) {
@Deprecated
public static List<String> fieldLoader(final JSONObject resultFromGetRequestInES,
final String[] fields) {
log.fine("JSON: " + (resultFromGetRequestInES == null ? "NULL" : resultFromGetRequestInES));
log.fine("FIELDS: " + fields);
......@@ -418,32 +421,63 @@ public class OaipmhUtilities {
try {
// Loop the splitted field components, such as "edition", "source", etcpp.
for (int i = 0; i < fieldPathForESIndex.length; i++) {
// Case 1: We have only one field component.
String fieldComponent = fieldPathForESIndex[i];
log.fine("i=" + i);
log.fine("fieldPathLength=" + fieldPathForESIndex.length);
// Case 1: Reduce JSON object.
if (i < fieldPathForESIndex.length - 1) {
String singleFieldComponent = fieldPathForESIndex[i];
log.fine("case 1: we have only one field component: " + singleFieldComponent);
log.fine(
"case 1: " + i + "<" + (fieldPathForESIndex.length - 1) + " : reduce singlePath");
singlePath = singlePath.getJSONObject(fieldPathForESIndex[i]);
fieldResults.add(singlePath.toString());
}
// Case 2: We have only one field component??
// Case 2: We have one field component.
else if (fieldPathForESIndex.length == 1) {
String singleFieldComponent = fieldPathForESIndex[i];
log.fine("case 2: we have only one field component: " + singleFieldComponent);
log.fine("case 2: we have only one field component in field " + field);
// Examine JSONArray, take String if not applicable.
try {
JSONArray singlePathArray = singlePath.getJSONArray(fieldComponent);
log.fine("get json array: " + singlePathArray.toString(2));
for (int j = 0; j < singlePathArray.length(); j++) {
fieldResults.add(singlePathArray.getString(j));
}
} catch (JSONException e) {
String singlePathValue = singlePath.getString(fieldComponent);
log.fine("get string: " + singlePathValue);
JSONObject resultiDingsda =
resultFromGetRequestInES.getJSONObject(singleFieldComponent);
fieldResults.add(resultiDingsda.toString());
fieldResults.add(singlePathValue);
}
}
// Case 3: We have got more field components.
// // 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 =
// resultFromGetRequestInES.getJSONObject(singleFieldComponent);
// fieldResults.add(resultiDingsda.toString());
// }
// Case 2: We have got more field components.
else {
String res = singlePath.get(fieldPathForESIndex[i]).toString();
log.fine("case 3: we have " + fieldPathForESIndex.length + " components in " + field);
log.fine("case 2: we have " + fieldPathForESIndex.length + " components in " + field);
// JSONArray pathArray = resultFromGetRequestInES.getJSONArray(fieldComponent);
String res = singlePath.get(fieldPathForESIndex[i]).toString();
// Examine JSONArray.
// Examine JSONArray, take String if not applicable.
if (res.startsWith("[")) {
log.fine("json array found: " + res);
......@@ -489,19 +523,39 @@ public class OaipmhUtilities {
String[] fieldPathForESIndex = field.split(ES_DIVIDER_REGEXP);
JSONObject singlePath = resultFromGetRequestInES;
try {
log.fine("kakki 1");
for (int i = 0; i < fieldPathForESIndex.length; i++) {
log.fine("kakki 2");
if (i < fieldPathForESIndex.length - 1) {
log.fine(i + "<" + (fieldPathForESIndex.length - 1) + " : reduce singlePath");
singlePath = singlePath.getJSONObject(fieldPathForESIndex[i]);
log.fine("kakki 3");
} else if (fieldPathForESIndex.length == 1) {
fieldResults = resultFromGetRequestInES.get(fieldPathForESIndex[i]).toString();
log.fine("kakki 4");
} else {
fieldResults = singlePath.get(fieldPathForESIndex[i]).toString();
log.fine("kakki 5");
}
}
} catch (JSONException e) {
log.fine("IGNORING JSON ERROR: " + e.getMessage());
}
log.fine("kakki 6");
return fieldResults;
}
......
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