modified generated xml according to new mapping

This commit is contained in:
Enrico Ottonello 2020-02-14 16:56:34 +01:00
parent c5945c386b
commit a6b5a80984
1 changed files with 3 additions and 24 deletions

View File

@ -35,13 +35,11 @@ public class FileJSONCollectorPlugin extends FileCollectorPlugin {
public Iterable<String> collect(final InterfaceDescriptor interfaceDescriptor, final String fromDate, final String untilDate) public Iterable<String> collect(final InterfaceDescriptor interfaceDescriptor, final String fromDate, final String untilDate)
throws CollectorServiceException { throws CollectorServiceException {
log.info("FileJSONCollectorPlugin"); log.info("FileJSONCollectorPlugin");
System.out.println("FileJSONCollectorPlugin");
final String identifierFieldKey = interfaceDescriptor.getParams().get("identifierFieldKey"); final String identifierFieldKey = interfaceDescriptor.getParams().get("identifierFieldKey");
URL u = null; URL u = null;
try { try {
u = new URL(interfaceDescriptor.getBaseUrl()); u = new URL(interfaceDescriptor.getBaseUrl());
System.out.println(u.toString());
} catch (MalformedURLException e1) { } catch (MalformedURLException e1) {
e1.printStackTrace(); e1.printStackTrace();
throw new CollectorServiceException(e1); throw new CollectorServiceException(e1);
@ -75,10 +73,8 @@ public class FileJSONCollectorPlugin extends FileCollectorPlugin {
public FileJSONIterator(final FileReader fileReader, final String identifierFieldKey) { public FileJSONIterator(final FileReader fileReader, final String identifierFieldKey) {
this.identifierFieldKey = identifierFieldKey; this.identifierFieldKey = identifierFieldKey;
jsonReader = new JsonReader(fileReader); jsonReader = new JsonReader(fileReader);
System.out.println("parsing ...");
JsonElement jsonElement = new JsonParser().parse(jsonReader); JsonElement jsonElement = new JsonParser().parse(jsonReader);
JsonArray jsonArrays = jsonElement.getAsJsonArray(); JsonArray jsonArrays = jsonElement.getAsJsonArray();
System.out.println("size: "+ jsonArrays.size());
aatInfosIterator = jsonArrays.iterator(); aatInfosIterator = jsonArrays.iterator();
next = calculateNext(); next = calculateNext();
} }
@ -97,25 +93,19 @@ public class FileJSONCollectorPlugin extends FileCollectorPlugin {
private String calculateNext() { private String calculateNext() {
try { try {
System.out.println("calculateNext()");
Document document = DocumentHelper.createDocument(); Document document = DocumentHelper.createDocument();
Element root = document.addElement("jsonRecord"); Element root = document.addElement("Entry");
if (!aatInfosIterator.hasNext()) { if (!aatInfosIterator.hasNext()) {
System.out.println("son entries finished");
log.info("json entries finished, closing RESULT SET"); log.info("json entries finished, closing RESULT SET");
jsonReader.close(); jsonReader.close();
return null; return null;
} }
System.out.println("parsing next entry");
JsonElement aatInfos = aatInfosIterator.next(); JsonElement aatInfos = aatInfosIterator.next();
JsonObject aatInfoJsonObj = aatInfos.getAsJsonObject(); JsonObject aatInfoJsonObj = aatInfos.getAsJsonObject();
Set<Entry<String, JsonElement>> keys = aatInfoJsonObj.entrySet(); Set<Entry<String, JsonElement>> keys = aatInfoJsonObj.entrySet();
for(Map.Entry<String,JsonElement> entry : keys) { for(Map.Entry<String,JsonElement> entry : keys) {
String key = entry.getKey(); String key = entry.getKey();
// if (key.equals("updated")) {
// continue;
// }
JsonElement jsonElement = aatInfoJsonObj.get(key); JsonElement jsonElement = aatInfoJsonObj.get(key);
if (jsonElement.isJsonNull()) { if (jsonElement.isJsonNull()) {
continue; continue;
@ -124,21 +114,10 @@ public class FileJSONCollectorPlugin extends FileCollectorPlugin {
if (StringUtils.isEmpty(value)) { if (StringUtils.isEmpty(value)) {
continue; continue;
} }
System.out.println("key: "+key+" value: "+value);
Element element = root.addElement("Entry");
String name = new String(key); String name = new String(key);
if (name.equals("sourceURI")) { Element element = root.addElement(name);
name = new String("Source_ID");
} else if (name.equals("targetURI")) {
name = new String("Target_URI");
}
value = StringEscapeUtils.escapeXml11(value.replace('\r',' ').replace('\t',' ')); value = StringEscapeUtils.escapeXml11(value.replace('\r',' ').replace('\t',' '));
if (name.equals(identifierFieldKey)) { element.addText(value);
element.addAttribute("isID", "true");
element.addAttribute("name", name).addText(value);
} else {
element.addAttribute("name", name).addText(value);
}
} }
String xmlRecord = new String(document.asXML()); String xmlRecord = new String(document.asXML());
log.debug(xmlRecord); log.debug(xmlRecord);