import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.common.api.RefNameUtils;
import org.collectionspace.services.common.context.ServiceBindingUtils;
+import org.collectionspace.services.common.invocable.Field;
import org.collectionspace.services.common.invocable.InvocationContext;
import org.collectionspace.services.config.service.ServiceBindingType;
import org.collectionspace.services.config.service.ServiceObjectType;
// present.
InvocationContext.IncludeFields includeFields = invocationContext.getIncludeFields();
- List<String> fields = (includeFields != null ? includeFields.getField() : new ArrayList<String>());
+ List<Field> fields = (includeFields != null ? includeFields.getField() : new ArrayList<Field>());
if (fields.size() == 0) {
throw new Exception("For CSV output, the fields to export must be specified using includeFields.");
List<String> headers = new ArrayList<>();
- for (String field : fields) {
- Matcher matcher = VALID_FIELD_XPATH_PATTERN.matcher(field);
+ for (Field field : fields) {
+ String fieldSpec = field.getValue();
+ Matcher matcher = VALID_FIELD_XPATH_PATTERN.matcher(fieldSpec);
if (!matcher.matches()) {
- throw new Exception("The includeField XPath expression \"" + field + "\" is not valid for CSV output. For CSV output, all included fields must be individually specified without using wildcards.");
+ throw new Exception("The includeField expression \"" + fieldSpec + "\" is not valid for CSV output. For CSV output, all included fields must be individually specified without using wildcards.");
}
- String fieldName = matcher.group(2);
+ String fieldName = field.getName();
+
+ if (fieldName == null) {
+ fieldName = matcher.group(2);
+ }
headers.add(fieldName);
- if (isFieldWithinAuthItemTermGroup(field)) {
+ if (isFieldWithinAuthItemTermGroup(fieldSpec)) {
headers.add(fieldName + "NonPreferred");
}
}
return;
}
- List<String> fields = includeFields.getField();
+ List<Field> fields = includeFields.getField();
List<String> csvRecord = new ArrayList<>();
- for (String field : fields) {
- if (isFieldWithinAuthItemTermGroup(field)) {
+ for (Field field : fields) {
+ String fieldSpec = field.getValue();
+
+ if (isFieldWithinAuthItemTermGroup(fieldSpec)) {
// Write a column for values within the preferred (primary) term group.
- csvRecord.add(collectValues(document, field.replace(AUTH_ITEM_TERM_GROUP_SUFFIX + "/", AUTH_ITEM_TERM_GROUP_SUFFIX + "[position()=1]/")));
+ csvRecord.add(collectValues(document, fieldSpec.replace(AUTH_ITEM_TERM_GROUP_SUFFIX + "/", AUTH_ITEM_TERM_GROUP_SUFFIX + "[position()=1]/")));
// Write a column for values within non-preferred term groups.
- csvRecord.add(collectValues(document, field.replace(AUTH_ITEM_TERM_GROUP_SUFFIX + "/", AUTH_ITEM_TERM_GROUP_SUFFIX + "[position()>1]/")));
+ csvRecord.add(collectValues(document, fieldSpec.replace(AUTH_ITEM_TERM_GROUP_SUFFIX + "/", AUTH_ITEM_TERM_GROUP_SUFFIX + "[position()>1]/")));
}
else {
- csvRecord.add(collectValues(document, field));
+ csvRecord.add(collectValues(document, fieldSpec));
}
}
csvPrinter.close();
}
- private boolean isFieldWithinAuthItemTermGroup(String field) {
+ private boolean isFieldWithinAuthItemTermGroup(String fieldSpec) {
// FIXME: How to know a NonPreferred column is needed without hardcoding "TermGroup"?
- return field.contains(AUTH_ITEM_TERM_GROUP_SUFFIX + "/");
+ return fieldSpec.contains(AUTH_ITEM_TERM_GROUP_SUFFIX + "/");
}
- private String collectValues(PoxPayloadOut document, String field) {
+ private String collectValues(PoxPayloadOut document, String fieldSpec) {
String delimitedValues = "";
- String[] segments = field.split(":", 2);
+ String[] segments = fieldSpec.split(":", 2);
String partName = segments[0];
String xpath = segments[1];
String delimitedValues = "";
String fieldName = path.get(depth);
String delimiter = (depth / 2 > 0) ? "^^" : ";";
- List<Node> matches = element.createXPath(fieldName).selectNodes(element);
+ List<Node> matches = element.selectNodes(fieldName);
if (matches.size() > 0) {
List<String> values = new ArrayList<>();
import org.collectionspace.services.common.context.MultipartServiceContextFactory;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.context.ServiceContextFactory;
+import org.collectionspace.services.common.invocable.Field;
import org.collectionspace.services.common.invocable.Invocable;
import org.collectionspace.services.common.invocable.InvocationContext;
import org.dom4j.Node;
InvocationContext.ExcludeFields excludeFields = invocationContext.getExcludeFields();
if (excludeFields != null) {
- List<String> fields = excludeFields.getField();
+ List<Field> fields = excludeFields.getField();
- for (String field : fields) {
- String[] segments = field.split(":", 2);
+ for (Field field : fields) {
+ String fieldSpec = field.getValue();
+ String[] segments = fieldSpec.split(":", 2);
String partName = segments[0];
String xpath = segments[1];
if (part != null) {
org.dom4j.Element partElement = part.getElementBody();
- List<Node> matches = (List<Node>) partElement.createXPath(xpath).selectNodes(partElement);
+ List<Node> matches = (List<Node>) partElement.selectNodes(xpath);
for (Node excludeNode : matches) {
if (excludeNode.getNodeType() == Node.ELEMENT_NODE) {
InvocationContext.IncludeFields includeFields = invocationContext.getIncludeFields();
if (includeFields != null) {
- List<String> fields = includeFields.getField();
+ List<Field> fields = includeFields.getField();
- for (String field : fields) {
- String[] segments = field.split(":", 2);
+ for (Field field : fields) {
+ String fieldSpec = field.getValue();
+ String[] segments = fieldSpec.split(":", 2);
String partName = segments[0];
String xpath = segments[1];
if (part != null) {
org.dom4j.Element partElement = part.getElementBody();
- List<Node> matches = (List<Node>) partElement.createXPath(xpath).selectNodes(partElement);
+ List<Node> matches = (List<Node>) partElement.selectNodes(xpath);
for (Node includeNode : matches) {
if (includeNode.getNodeType() == Node.ELEMENT_NODE) {