...
Code Block |
---|
<script> <![CDATA[ import com.searchtechnologies.aspire.services.AspireObject; import java.text.SimpleDateFormat; import java.text.ParseException; Map<String, String> avroFieldsMap = new HashMap<String, String>(); avroFieldsMap.put("url", "filepath"); avroFieldsMap.put("modificationDate", "filemodificationtime"); avroFieldsMap.put("content", "contenttext"); if (doc.url != null && doc.url.text() != null && !doc.url.text().trim().isEmpty()) { if (avroFieldsMap.get("url") != null) { doc.add(avroFieldsMap.get("url"), doc.url.text()); } } if (doc.content != null && doc.content.text() != null && !doc.content.text().trim().isEmpty()) { if (avroFieldsMap.get("content") != null) { doc.add(avroFieldsMap.get("content"), doc.content.text()); doc.removeChildren("content"); } } if (doc.extension != null) { List<AspireObject> extensions = doc.getAll("extension"); for (AspireObject extension : extensions) { List<AspireObject> extensionFields = extension.getChildren(); for (AspireObject aspireObj: extensionFields) { String fieldName = aspireObj.getAttribute("name"); if (fieldName != null && !fieldName.trim().isEmpty() && avroFieldsMap.get(fieldName) != null) { String fieldValue = aspireObj.getText(); if (fieldValue != null && !fieldValue.trim().isEmpty()) { if (fieldName.equals("modificationDate")) { try { long dateMillis = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse(fieldValue).getTime(); doc.add(avroFieldsMap.get(fieldName), dateMillis); } catch (ParseException pe) { component.error(pe.toString()); } } else { doc.add(avroFieldsMap.get(fieldName), fieldValue); } } } } } } ]]> </script> |
Useful Avro manipulation tools