From: Michael Ritter Date: Tue, 4 Nov 2025 17:43:13 +0000 (-0700) Subject: DRYD-1837: New Authority CSV Export Format (#485) X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=7bc5ef0039b7e28730a31d3abae672979ffa0348;p=tmp%2Fjakarta-migration.git DRYD-1837: New Authority CSV Export Format (#485) * Add new parameter includeauthority to csv export service * Update CSV Export to export authorities for fields when requested * Add displayName to service binding xsd --- diff --git a/services/client/src/main/java/org/collectionspace/services/client/GenericAuthorityClientImpl.java b/services/client/src/main/java/org/collectionspace/services/client/GenericAuthorityClientImpl.java deleted file mode 100644 index fc5ec3557..000000000 --- a/services/client/src/main/java/org/collectionspace/services/client/GenericAuthorityClientImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.collectionspace.services.client; - -public class GenericAuthorityClientImpl extends - AuthorityClientImpl { - - public GenericAuthorityClientImpl() throws Exception { - super(); - } - - @Override - public String getItemCommonPartName() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getInAuthority(Object item) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void setInAuthority(Object item, String inAuthorityCsid) { - // TODO Auto-generated method stub - - } - - @Override - public Class getProxyClass() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getServiceName() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getServicePathComponent() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String createAuthorityInstance(String shortIdentifier, String displayName) { - // TODO Auto-generated method stub - return null; - } - - @Override - public String createAuthorityItemInstance(String shortIdentifier, String displayName) { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/RefNameUtils.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/RefNameUtils.java index add4ae303..e2482c770 100644 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/RefNameUtils.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/RefNameUtils.java @@ -285,13 +285,13 @@ public class RefNameUtils { */ public static String getDisplayName(String refName) throws IllegalArgumentException { String displayName = null; - + try { AuthorityTermInfo authorityTermInfo = parseAuthorityTermInfo(refName); displayName = authorityTermInfo.displayName; } catch(IllegalArgumentException invalidAuthorityTermRefNameException) { - try { + try { AuthorityInfo authorityInfo = parseAuthorityInfo(refName); displayName = authorityInfo.displayName; } @@ -299,10 +299,23 @@ public class RefNameUtils { throw new IllegalArgumentException("Invalid refName"); } } - + return displayName; } + /** + * @param refName A string representation of the CollectionSpace {@link RefName} to parse + * @return The {@link AuthorityInfo for the refname} + * @throws IllegalArgumentException if the refName cannot be parsed + */ + public static AuthorityTermInfo getAuthorityTermInfo(String refName) throws IllegalArgumentException { + try { + return parseAuthorityTermInfo(refName); + } catch(IllegalArgumentException invalidAuthorityTermRefNameException) { + throw new IllegalArgumentException("Invalid refName"); + } + } + /** * Compare two refname strings. They're considered equal if the short IDs match * diff --git a/services/config/src/main/resources/service.xsd b/services/config/src/main/resources/service.xsd index bc4c786d1..32faa9e06 100644 --- a/services/config/src/main/resources/service.xsd +++ b/services/config/src/main/resources/service.xsd @@ -76,6 +76,7 @@ + diff --git a/services/export/service/pom.xml b/services/export/service/pom.xml index 2cd3e7114..ae5d39314 100644 --- a/services/export/service/pom.xml +++ b/services/export/service/pom.xml @@ -13,18 +13,6 @@ jar - - org.collectionspace.services - org.collectionspace.services.authentication.service - ${project.version} - provided - - - org.collectionspace.services - org.collectionspace.services.account.service - ${project.version} - provided - org.collectionspace.services org.collectionspace.services.authority.service @@ -36,12 +24,6 @@ org.collectionspace.services.config ${project.version} - - org.collectionspace.services - org.collectionspace.services.authority.jaxb - true - ${project.version} - org.collectionspace.services org.collectionspace.services.common @@ -56,53 +38,20 @@ org.collectionspace.services.export.client ${project.version} - - org.collectionspace.services - org.collectionspace.services.collectionobject.jaxb - ${project.version} - - - junit - junit - test - - - org.testng - testng - org.apache.commons commons-csv 1.8 - - - - javax.security - jaas - 1.0.01 - provided - - - org.jboss.resteasy resteasy-jaxrs - - org.jboss.resteasy - resteasy-jaxb-provider - - - org.jboss.resteasy - resteasy-multipart-provider - - org.nuxeo.ecm.core nuxeo-core-api diff --git a/services/export/service/src/main/java/org/collectionspace/services/export/AbstractDocumentsByQueryIterator.java b/services/export/service/src/main/java/org/collectionspace/services/export/AbstractDocumentsByQueryIterator.java index 9a6ad7027..7d3b79114 100644 --- a/services/export/service/src/main/java/org/collectionspace/services/export/AbstractDocumentsByQueryIterator.java +++ b/services/export/service/src/main/java/org/collectionspace/services/export/AbstractDocumentsByQueryIterator.java @@ -148,7 +148,7 @@ public abstract class AbstractDocumentsByQueryIterator implements : resource.getWithParentCtx(serviceContext, csid)); } catch (Exception e) { - logger.warn("Could not get document with csid " + csid, e); + logger.warn("Could not get document with csid {}", csid, e); return null; } @@ -163,7 +163,7 @@ public abstract class AbstractDocumentsByQueryIterator implements // Some code in services assumes pathSegments will have at least one element, so add an // empty one. - List pathSegments = Arrays.asList((PathSegment) new PathSegmentImpl("", false)); + List pathSegments = Arrays.asList(new PathSegmentImpl("", false)); URIBuilder uriBuilder = new URIBuilder(); diff --git a/services/export/service/src/main/java/org/collectionspace/services/export/AbstractExportWriter.java b/services/export/service/src/main/java/org/collectionspace/services/export/AbstractExportWriter.java index 80d1fd02a..a2ecbe330 100644 --- a/services/export/service/src/main/java/org/collectionspace/services/export/AbstractExportWriter.java +++ b/services/export/service/src/main/java/org/collectionspace/services/export/AbstractExportWriter.java @@ -1,11 +1,8 @@ package org.collectionspace.services.export; -import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; -import java.util.HashSet; -import java.util.Set; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; diff --git a/services/export/service/src/main/java/org/collectionspace/services/export/CsvExportWriter.java b/services/export/service/src/main/java/org/collectionspace/services/export/CsvExportWriter.java index 6c00082dc..6d84cca45 100644 --- a/services/export/service/src/main/java/org/collectionspace/services/export/CsvExportWriter.java +++ b/services/export/service/src/main/java/org/collectionspace/services/export/CsvExportWriter.java @@ -7,30 +7,44 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeMap; +import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVPrinter; import org.apache.commons.lang.StringUtils; +import org.apache.logging.log4j.util.Strings; import org.collectionspace.services.client.PayloadOutputPart; 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.AuthorityInstanceType; import org.collectionspace.services.config.service.ServiceBindingType; +import org.collectionspace.services.config.tenant.TenantBindingType; import org.dom4j.Element; import org.dom4j.Node; public class CsvExportWriter extends AbstractExportWriter { - private static final Pattern VALID_FIELD_XPATH_PATTERN = Pattern.compile("^\\w+:(\\w+\\/)*(\\w+)(\\[.*\\])?$"); + private static final Pattern VALID_FIELD_XPATH_PATTERN = Pattern.compile("^\\w+:(\\w+/)*(\\w+)(\\[.*])?$"); private static final String VALUE_DELIMITER_PARAM_NAME = "valuedelimiter"; + private static final String INCLUDE_AUTHORITY_PARAM = "includeauthority"; + private static final String AUTHORITY_SUFFIX = "AuthorityVocabulary"; private CSVPrinter csvPrinter; private Map>> refFieldsByDocType = new HashMap<>(); private String valueDelimiter = "|"; private String nestedValueDelimiter = "^^"; + private boolean includeAuthority = false; + + /** + * Authority names in the service bindings start with a single capital letter, e.g. Personauthorities, but in + * refnames they are all lowercase. Instead of using toLower just set case-insensitive. + */ + private Map authorityDisplayNames = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); @Override public void start() throws Exception { @@ -40,12 +54,25 @@ public class CsvExportWriter extends AbstractExportWriter { // present. InvocationContext.IncludeFields includeFields = invocationContext.getIncludeFields(); - List fields = (includeFields != null ? includeFields.getField() : new ArrayList()); + List fields = (includeFields != null ? includeFields.getField() : new ArrayList<>()); if (fields.size() == 0) { throw new Exception("For CSV output, the fields to export must be specified using includeFields."); } + // Set the export parameters. + InvocationContext.Params params = invocationContext.getParams(); + if (params != null) { + for (InvocationContext.Params.Param param : params.getParam()) { + if (param.getKey().equals(VALUE_DELIMITER_PARAM_NAME)) { + this.valueDelimiter = param.getValue(); + } else if (param.getKey().equals(INCLUDE_AUTHORITY_PARAM)) { + this.includeAuthority = Boolean.parseBoolean(param.getValue()); + collectAuthorityVocabs(); + } + } + } + List headers = new ArrayList<>(); for (Field field : fields) { @@ -63,25 +90,20 @@ public class CsvExportWriter extends AbstractExportWriter { } headers.add(fieldName); + + // Create additional authority vocabulary column if requested + if (includeAuthority) { + String partName = fieldSpec.split(":", 2)[0]; + String docType = partName.substring(0, partName.indexOf("_")); + if (isRefField(docType, partName, fieldName)) { + // make constant + headers.add(fieldName + AUTHORITY_SUFFIX); + } + } } String[] headersArray = new String[headers.size()]; - this.csvPrinter = new CSVPrinter(writer, CSVFormat.DEFAULT.withHeader(headers.toArray(headersArray))); - - // Set the delimiter. - - InvocationContext.Params params = invocationContext.getParams(); - - if (params != null) { - for (InvocationContext.Params.Param param : params.getParam()) { - if (param.getKey().equals(VALUE_DELIMITER_PARAM_NAME)) { - this.valueDelimiter = param.getValue(); - - break; - } - }; - } } @Override @@ -96,7 +118,12 @@ public class CsvExportWriter extends AbstractExportWriter { List csvRecord = new ArrayList<>(); for (Field field : fields) { - csvRecord.add(collectValues(document, field.getValue())); + boolean isRefField = isRefField(document, field); + + csvRecord.add(collectValues(document, field.getValue(), isRefField, ColumnType.FIELD)); + if (isRefField && includeAuthority) { + csvRecord.add(collectValues(document, field.getValue(), isRefField, ColumnType.AUTHORITY)); + } } if (csvRecord.size() > 0) { @@ -104,12 +131,13 @@ public class CsvExportWriter extends AbstractExportWriter { } } + @Override public void close() throws Exception { - csvPrinter.close(); + csvPrinter.close(); } - private String collectValues(PoxPayloadOut document, String fieldSpec) { + private String collectValues(PoxPayloadOut document, String fieldSpec, boolean isRefField, ColumnType columnType) { String delimitedValues = ""; String[] segments = fieldSpec.split(":", 2); String partName = segments[0]; @@ -118,13 +146,15 @@ public class CsvExportWriter extends AbstractExportWriter { PayloadOutputPart part = document.getPart(partName); if (part != null) { - delimitedValues = collectValues(document.getName(), partName, part.getElementBody(), Arrays.asList(xpath.split("/")), 0); + delimitedValues = collectValues(part.getElementBody(), Arrays.asList(xpath.split("/")), 0, isRefField, + columnType); } return delimitedValues; } - private String collectValues(String docType, String partName, Element element, List path, int depth) { + private String collectValues(Element element, List path, int depth, boolean isRefName, + ColumnType columnType) { String delimitedValues = ""; String fieldName = path.get(depth); String delimiter = (depth / 2 > 0) ? this.nestedValueDelimiter : this.valueDelimiter; @@ -135,15 +165,30 @@ public class CsvExportWriter extends AbstractExportWriter { boolean hasValue = false; for (Node node : matches) { - String textValue = ""; + String textValue; if (depth < path.size() - 1) { - textValue = collectValues(docType, partName, (Element) node, path, depth + 1); - } - else { + textValue = collectValues((Element) node, path, depth + 1, isRefName, columnType); + } else if (columnType == ColumnType.AUTHORITY) { textValue = node.getText(); - boolean isRefName = isRefField(docType, partName, fieldName.replaceFirst("\\[.*\\]", "")); + if (Strings.isNotEmpty(textValue)) { + final RefNameUtils.AuthorityTermInfo termInfo = RefNameUtils.getAuthorityTermInfo(textValue); + final String authority = termInfo.inAuthority.resource; + final String shortId = termInfo.inAuthority.name; + + String authorityDisplayName = authority; + String vocabDisplayName = shortId; + final AuthorityDisplayMapping mapping = authorityDisplayNames.get(authority); + if (mapping != null) { + authorityDisplayName = mapping.getAuthorityDisplayName(); + vocabDisplayName = mapping.getVocabDisplayName(shortId); + } + + textValue = authorityDisplayName + "/" + vocabDisplayName; + } + } else { + textValue = node.getText(); if (isRefName && StringUtils.isNotEmpty(textValue)) { textValue = RefNameUtils.getDisplayName(textValue); @@ -165,6 +210,25 @@ public class CsvExportWriter extends AbstractExportWriter { return delimitedValues; } + /** + * Check if a {@link Field} is for a TermRef or an AuthRef. We expect {@link Field#getValue} to return + * something which matches our Field Spec, i.e. "namespace:path/to/field". We allow for some xpath operations, + * such as contains, so we also need to be mindful of that and filter them out appropriately. + * + * @param document the document we're searching in + * @param field the field being searched for + * @return true if the field is a TermRef or an AuthRef + */ + private boolean isRefField(PoxPayloadOut document, Field field) { + final String fieldSpec = field.getValue(); + final String[] segments = fieldSpec.split(":", 2); + final String partName = segments[0]; + final List xpath = Arrays.asList(segments[1].split("/")); + final String fieldName = xpath.get(xpath.size() - 1); + + return isRefField(document.getName(), partName, fieldName.replaceFirst("\\[.*]", "")); + } + private boolean isRefField(String docType, String partName, String fieldName) { return getRefFields(docType, partName).contains(fieldName); } @@ -183,25 +247,84 @@ public class CsvExportWriter extends AbstractExportWriter { ServiceBindingType serviceBinding = tenantBindingConfigReader.getServiceBinding(serviceContext.getTenantId(), docType); for (String termRefField : ServiceBindingUtils.getPropertyValuesForPart(serviceBinding, partName, ServiceBindingUtils.TERM_REF_PROP, false)) { - String[] segments = termRefField.split("[\\/\\|]"); + String[] segments = termRefField.split("[/|]"); String fieldName = segments[segments.length - 1]; refFields.add(fieldName); } for (String authRefField : ServiceBindingUtils.getPropertyValuesForPart(serviceBinding, partName, ServiceBindingUtils.AUTH_REF_PROP, false)) { - String[] segments = authRefField.split("[\\/\\|]"); + String[] segments = authRefField.split("[/|]"); String fieldName = segments[segments.length - 1]; refFields.add(fieldName); } if (!refFieldsByDocType.containsKey(docType)) { - refFieldsByDocType.put(docType, new HashMap>()); + refFieldsByDocType.put(docType, new HashMap<>()); } refFieldsByDocType.get(docType).put(partName, refFields); return refFields; } + + /** + * Create the mapping of Authority name to Authority displayName and Authority Vocabularies shortId to Authority + * Vocabulary displayName (title) + */ + private void collectAuthorityVocabs() { + if (!includeAuthority) { + return; + } + + TenantBindingType tenantBinding = tenantBindingConfigReader.getTenantBinding(serviceContext.getTenantId()); + + Predicate hasAuthorityInstances = (binding) -> + binding.getAuthorityInstanceList() != null && + binding.getAuthorityInstanceList().getAuthorityInstance() != null; + + Predicate hasAuthorityDisplayName = (binding) -> + binding.getDisplayName() != null && !binding.getDisplayName().isEmpty(); + + tenantBinding.getServiceBindings().stream() + .filter(hasAuthorityInstances.and(hasAuthorityDisplayName)) + .map(AuthorityDisplayMapping::new) + .forEach((mapping) -> authorityDisplayNames.put(mapping.authority, mapping)); + } + + /** + * The type of column which we want to collect data for. + * Field - the text value or display name if a refname is present + * Authority - The aggregate of the Authority display name and Authority Vocabulary display name + */ + private enum ColumnType { + FIELD, AUTHORITY + } + + private static class AuthorityDisplayMapping { + final String authority; + final String displayName; + final Map vocabDisplayNames; + + public AuthorityDisplayMapping(ServiceBindingType binding) { + this.authority = binding.getName(); + this.displayName = binding.getDisplayName(); + this.vocabDisplayNames = new HashMap<>(); + binding.getAuthorityInstanceList().getAuthorityInstance().forEach(this::addVocabMapping); + } + + private void addVocabMapping(AuthorityInstanceType instance) { + vocabDisplayNames.put(instance.getTitleRef(), instance.getTitle()); + } + + public String getAuthorityDisplayName() { + return displayName; + } + + public String getVocabDisplayName(String shortId) { + return vocabDisplayNames.getOrDefault(shortId, shortId); + } + } + } diff --git a/services/export/service/src/main/java/org/collectionspace/services/export/DocumentsByCsidIterator.java b/services/export/service/src/main/java/org/collectionspace/services/export/DocumentsByCsidIterator.java index 787065b75..d3dece2e4 100644 --- a/services/export/service/src/main/java/org/collectionspace/services/export/DocumentsByCsidIterator.java +++ b/services/export/service/src/main/java/org/collectionspace/services/export/DocumentsByCsidIterator.java @@ -16,7 +16,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class DocumentsByCsidIterator implements Iterator { - private final Logger logger = LoggerFactory.getLogger(DocumentsByCsidIterator.class); + private final Logger logger = LoggerFactory.getLogger(DocumentsByCsidIterator.class); private NuxeoBasedResource resource; private String vocabulary; @@ -60,8 +60,7 @@ public class DocumentsByCsidIterator implements Iterator { : resource.getWithParentCtx(serviceContext, csid)); } catch (Exception e) { - logger.warn("Could not get document with csid " + csid, e); - + logger.warn("Could not get document with csid {}", csid, e); return null; } } diff --git a/services/export/service/src/main/java/org/collectionspace/services/export/ExportResource.java b/services/export/service/src/main/java/org/collectionspace/services/export/ExportResource.java index dcdc5a8fc..a4449f537 100644 --- a/services/export/service/src/main/java/org/collectionspace/services/export/ExportResource.java +++ b/services/export/service/src/main/java/org/collectionspace/services/export/ExportResource.java @@ -33,6 +33,14 @@ import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; import com.google.common.collect.ImmutableMap; import org.apache.commons.lang3.StringUtils; @@ -51,30 +59,18 @@ import org.collectionspace.services.common.invocable.Invocable; import org.collectionspace.services.common.invocable.InvocationContext; import org.dom4j.Element; import org.dom4j.Node; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; @Path(ExportClient.SERVICE_PATH) @Consumes("application/xml") @Produces("application/xml") public class ExportResource extends AbstractCollectionSpaceResourceImpl { - private final Logger logger = LoggerFactory.getLogger(ExportResource.class); // There is no way to tell from config that collectionspace_core should not be exported, so it // has to be hardcoded here. At that point we might as well also hardcode account_permission, // so we don't need to look at config at all. private static final ImmutableMap> EXCLUDE_PARTS = ImmutableMap.of( "collectionspace_core", Arrays.asList("workflowState", "tenantId", "refName"), - "account_permission", Collections.emptyList()); + "account_permission", Collections.emptyList()); private static final String MIME_TYPE_CSV = "text/csv"; private static final String MIME_TYPE_XML = "application/xml"; @@ -229,12 +225,12 @@ public class ExportResource extends AbstractCollectionSpaceResourceImpl matches = (List) partElement.selectNodes(xpath); + Element partElement = part.getElementBody(); + List matches = partElement.selectNodes(xpath); for (Node includeNode : matches) { if (includeNode.getNodeType() == Node.ELEMENT_NODE) { - markIncluded((org.dom4j.Element) includeNode); + markIncluded((Element) includeNode); } } } @@ -243,7 +239,7 @@ public class ExportResource extends AbstractCollectionSpaceResourceImpl includedParts = new ArrayList<>(); for (PayloadOutputPart part : document.getParts()) { - org.dom4j.Element partElement = part.getElementBody(); + Element partElement = part.getElementBody(); if (partElement.attributeValue(INCLUDE_ATTRIBUTE_NAME) != null) { includedParts.add(part); @@ -257,7 +253,7 @@ public class ExportResource extends AbstractCollectionSpaceResourceImpl matches = (List) element.selectNodes(xpath); + List matches = element.selectNodes(xpath); for (Node excludeNode : matches) { if (excludeNode.getNodeType() == Node.ELEMENT_NODE) { @@ -267,8 +263,8 @@ public class ExportResource extends AbstractCollectionSpaceResourceImpl childIterator = element.elementIterator(); while (childIterator.hasNext()) { - org.dom4j.Element childElement = (org.dom4j.Element) childIterator.next(); + Element childElement = childIterator.next(); removeUnincluded(childElement); } diff --git a/services/export/service/src/main/java/org/collectionspace/services/export/ExportWriter.java b/services/export/service/src/main/java/org/collectionspace/services/export/ExportWriter.java index fc8f71963..279edd7d0 100644 --- a/services/export/service/src/main/java/org/collectionspace/services/export/ExportWriter.java +++ b/services/export/service/src/main/java/org/collectionspace/services/export/ExportWriter.java @@ -1,8 +1,6 @@ package org.collectionspace.services.export; -import java.io.IOException; import java.io.OutputStream; -import java.util.Set; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; @@ -11,13 +9,13 @@ import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.invocable.InvocationContext; public interface ExportWriter { - public void setInvocationContext(InvocationContext invocationContext); - public void setOutputStream(OutputStream outputStream); - public void setServiceContext(ServiceContext serviceContext); - public void setTenantBindingConfigReader(TenantBindingConfigReaderImpl tenantBindingConfigReader); + void setInvocationContext(InvocationContext invocationContext); + void setOutputStream(OutputStream outputStream); + void setServiceContext(ServiceContext serviceContext); + void setTenantBindingConfigReader(TenantBindingConfigReaderImpl tenantBindingConfigReader); - public void start() throws Exception; - public void writeDocument(PoxPayloadOut document) throws Exception; - public void finish() throws Exception; - public void close() throws Exception; + void start() throws Exception; + void writeDocument(PoxPayloadOut document) throws Exception; + void finish() throws Exception; + void close() throws Exception; } diff --git a/services/export/service/src/main/java/org/collectionspace/services/export/RelationObjectsByQueryIterator.java b/services/export/service/src/main/java/org/collectionspace/services/export/RelationObjectsByQueryIterator.java index 857bb2426..6ea7d1e31 100644 --- a/services/export/service/src/main/java/org/collectionspace/services/export/RelationObjectsByQueryIterator.java +++ b/services/export/service/src/main/java/org/collectionspace/services/export/RelationObjectsByQueryIterator.java @@ -18,7 +18,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class RelationObjectsByQueryIterator extends RelationsByQueryIterator implements Iterator { - private final Logger logger = LoggerFactory.getLogger(RelationObjectsByQueryIterator.class); + private final Logger logger = LoggerFactory.getLogger(RelationObjectsByQueryIterator.class); RelationObjectsByQueryIterator( ServiceContext serviceContext, @@ -36,7 +36,7 @@ public class RelationObjectsByQueryIterator extends RelationsByQueryIterator imp String relationObjectCsid = relationObject.getCsid(); String relationObjectDocType = relationObject.getDocumentType(); - TenantBindingConfigReaderImpl tenantBindingConfigReader = ServiceMain.getInstance().getTenantBindingConfigReader(); + TenantBindingConfigReaderImpl tenantBindingConfigReader = ServiceMain.getInstance().getTenantBindingConfigReader(); ServiceBindingType relationObjectServiceBinding = tenantBindingConfigReader.getServiceBindingForDocType(serviceContext.getTenantId(), relationObjectDocType); String relationObjectServiceType = relationObjectServiceBinding.getType(); String relationObjectServiceName = relationObjectServiceBinding.getName(); @@ -53,8 +53,7 @@ public class RelationObjectsByQueryIterator extends RelationsByQueryIterator imp : relationObjectResource.getWithParentCtx(serviceContext, relationObjectCsid)); } catch (Exception e) { - logger.warn("Could not get document with csid " + relationObjectCsid, e); - + logger.warn("Could not get document with csid {}", relationObjectCsid, e); return null; } } diff --git a/services/export/service/src/main/java/org/collectionspace/services/export/XmlExportWriter.java b/services/export/service/src/main/java/org/collectionspace/services/export/XmlExportWriter.java index 35ffa549f..5b996ec58 100644 --- a/services/export/service/src/main/java/org/collectionspace/services/export/XmlExportWriter.java +++ b/services/export/service/src/main/java/org/collectionspace/services/export/XmlExportWriter.java @@ -1,9 +1,5 @@ package org.collectionspace.services.export; -import java.io.IOException; -import java.util.Arrays; -import java.util.List; - import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.config.service.ServiceBindingType; @@ -40,8 +36,8 @@ public class XmlExportWriter extends AbstractExportWriter { Namespace partNamespace = element.getNamespaceForPrefix("ns2"); String partNamespaceUri = partNamespace.getURI(); - for (Object namespace : element.additionalNamespaces()) { - element.remove((Namespace) namespace); + for (Namespace namespace : element.additionalNamespaces()) { + element.remove(namespace); } element.remove(partNamespace); diff --git a/services/export/service/src/main/java/org/collectionspace/services/export/nuxeo/ExportDocumentModelHandler.java b/services/export/service/src/main/java/org/collectionspace/services/export/nuxeo/ExportDocumentModelHandler.java index 719734c6c..c0f282f94 100644 --- a/services/export/service/src/main/java/org/collectionspace/services/export/nuxeo/ExportDocumentModelHandler.java +++ b/services/export/service/src/main/java/org/collectionspace/services/export/nuxeo/ExportDocumentModelHandler.java @@ -23,29 +23,8 @@ */ package org.collectionspace.services.export.nuxeo; -import java.io.InputStream; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.collectionspace.services.client.PoxPayloadIn; -import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.common.NuxeoBasedResource; -import org.collectionspace.services.common.ResourceMap; -import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl; -import org.collectionspace.services.common.context.ServiceContext; -import org.collectionspace.services.common.invocable.Invocable; -import org.collectionspace.services.common.invocable.InvocationContext; -import org.collectionspace.services.config.service.ServiceBindingType; import org.collectionspace.services.export.ExportsCommon; import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler; -import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface; -import org.collectionspace.services.nuxeo.client.java.NuxeoRepositoryClientImpl; - -import org.nuxeo.ecm.core.api.DocumentModel; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * ExportDocumentModelHandler @@ -53,157 +32,4 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: $ * $LastChangedDate: $ */ -public class ExportDocumentModelHandler extends NuxeoDocumentModelHandler { - private final Logger logger = LoggerFactory.getLogger(ExportDocumentModelHandler.class); - - public InputStream invokeExport( - TenantBindingConfigReaderImpl tenantBindingReader, - ResourceMap resourceMap, - ServiceContext serviceContext, - InvocationContext invocationContext, - StringBuffer outputMimeType, - StringBuffer outputFileName) throws Exception { - - NuxeoRepositoryClientImpl repoClient = (NuxeoRepositoryClientImpl) this.getRepositoryClient(serviceContext); - boolean releaseRepoSession = false; - CoreSessionInterface repoSession = this.getRepositorySession(); - - if (repoSession == null) { - repoSession = repoClient.getRepositorySession(serviceContext); - releaseRepoSession = true; - } - - try { - Iterator documents = findDocuments(tenantBindingReader, resourceMap, serviceContext, repoSession, invocationContext); - - } - finally { - if (releaseRepoSession && repoSession != null) { - repoClient.releaseRepositorySession(serviceContext, repoSession); - } - } - - return null; - // return buildExportResult(csid, params, exportFileNameProperty, outMimeType.toString(), outExportFileName); - } - - private Iterator findDocuments( - TenantBindingConfigReaderImpl tenantBindingReader, - ResourceMap resourceMap, - ServiceContext serviceContext, - CoreSessionInterface repoSession, - InvocationContext invocationContext) throws Exception { - - String docType = invocationContext.getDocType(); - ServiceBindingType binding = tenantBindingReader.getServiceBindingForDocType(serviceContext.getTenantId(), docType); - String serviceName = binding.getName(); - - switch (invocationContext.getMode().toLowerCase()) { - case Invocable.INVOCATION_MODE_SINGLE: - return findDocumentByCsid(resourceMap, serviceContext, repoSession, serviceName, invocationContext.getSingleCSID()); - case Invocable.INVOCATION_MODE_LIST: - return findDocumentsByCsid(resourceMap, serviceContext, repoSession, serviceName, invocationContext.getListCSIDs().getCsid()); - case Invocable.INVOCATION_MODE_GROUP: - return findDocumentsByGroup(resourceMap, serviceContext, repoSession, invocationContext.getGroupCSID()); - case Invocable.INVOCATION_MODE_NO_CONTEXT: - return findDocumentsByType(resourceMap, serviceContext, repoSession, invocationContext.getDocType()); - default: - return null; - } - } - - private Iterator findDocumentByCsid( - ResourceMap resourceMap, - ServiceContext serviceContext, - CoreSessionInterface repoSession, - String serviceName, - String csid) throws Exception { - - return findDocumentsByCsid(resourceMap, serviceContext, repoSession, serviceName, Arrays.asList(csid)); - } - - private Iterator findDocumentsByCsid( - ResourceMap resourceMap, - ServiceContext serviceContext, - CoreSessionInterface repoSession, - String serviceName, - List csids) throws Exception { - - return new DocumentsByCsidIterator(resourceMap, serviceContext, repoSession, serviceName, csids); - } - - private Iterator findDocumentsByType( - ResourceMap resourceMap, - ServiceContext serviceContext, - CoreSessionInterface repoSession, - String docType) { - - return null; - } - - private Iterator findDocumentsByGroup( - ResourceMap resourceMap, - ServiceContext serviceContext, - CoreSessionInterface repoSession, - String docType) { - - return null; - } - - // private InputStream buildExportResult(String exportCSID, - // HashMap params, - // String exportFileName, - // String outputMimeType, - // StringBuffer outExportFileName) throws Exception { - // Connection conn = null; - // InputStream result = null; - - // return result; - // } - - private class DocumentsByCsidIterator implements Iterator { - private NuxeoBasedResource resource; - private ServiceContext serviceContext; - private CoreSessionInterface repoSession; - private Iterator csidIterator; - - DocumentsByCsidIterator( - ResourceMap resourceMap, - ServiceContext serviceContext, - CoreSessionInterface repoSession, - String serviceName, - List csids) throws Exception { - - NuxeoBasedResource resource = (NuxeoBasedResource) resourceMap.get(serviceName.toLowerCase()); - - if (resource == null) { - throw new Exception("Resource not found for service name " + serviceName); - } - - this.resource = resource; - this.serviceContext = serviceContext; - this.repoSession = repoSession; - this.csidIterator = csids.iterator(); - } - - @Override - public boolean hasNext() { - return csidIterator.hasNext(); - } - - @Override - public DocumentModel next() { - String csid = csidIterator.next(); - - try { - // PoxPayloadOut payload = resource.getWithParentCtx(serviceContext, csid); - return null; - } - catch (Exception e) { - logger.warn("Could not get document with csid " + csid, e); - - return null; - } - } - } -} +public class ExportDocumentModelHandler extends NuxeoDocumentModelHandler { } diff --git a/services/export/service/src/main/java/org/collectionspace/services/export/nuxeo/ExportValidatorHandler.java b/services/export/service/src/main/java/org/collectionspace/services/export/nuxeo/ExportValidatorHandler.java index e184902ae..bc94e74c3 100644 --- a/services/export/service/src/main/java/org/collectionspace/services/export/nuxeo/ExportValidatorHandler.java +++ b/services/export/service/src/main/java/org/collectionspace/services/export/nuxeo/ExportValidatorHandler.java @@ -1,18 +1,15 @@ package org.collectionspace.services.export.nuxeo; import org.collectionspace.services.common.context.ServiceContext; -import org.collectionspace.services.common.document.InvalidDocumentException; import org.collectionspace.services.common.document.ValidatorHandler; import org.collectionspace.services.common.document.DocumentHandler.Action; public class ExportValidatorHandler implements ValidatorHandler { @Override - public void validate(Action action, ServiceContext ctx) - throws InvalidDocumentException { + public void validate(Action action, ServiceContext ctx) { // TODO Auto-generated method stub System.out.println("ExportValidatorHandler executed."); - } } diff --git a/services/jaxb/src/main/resources/invocationContext.xsd b/services/jaxb/src/main/resources/invocationContext.xsd index 39624e993..3f7a85bc0 100644 --- a/services/jaxb/src/main/resources/invocationContext.xsd +++ b/services/jaxb/src/main/resources/invocationContext.xsd @@ -13,50 +13,50 @@ - - - - - - - + + + + + + + - + - - - - - + + + + + - - - - - - + + + + + + - + - + @@ -66,8 +66,8 @@ - - + +