]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-1837: New Authority CSV Export Format (#485)
authorMichael Ritter <mikejritter@users.noreply.github.com>
Tue, 4 Nov 2025 17:43:13 +0000 (10:43 -0700)
committerGitHub <noreply@github.com>
Tue, 4 Nov 2025 17:43:13 +0000 (10:43 -0700)
* Add new parameter includeauthority to csv export service
* Update CSV Export to export authorities for fields when requested
* Add displayName to service binding xsd

15 files changed:
services/client/src/main/java/org/collectionspace/services/client/GenericAuthorityClientImpl.java [deleted file]
services/common-api/src/main/java/org/collectionspace/services/common/api/RefNameUtils.java
services/config/src/main/resources/service.xsd
services/export/service/pom.xml
services/export/service/src/main/java/org/collectionspace/services/export/AbstractDocumentsByQueryIterator.java
services/export/service/src/main/java/org/collectionspace/services/export/AbstractExportWriter.java
services/export/service/src/main/java/org/collectionspace/services/export/CsvExportWriter.java
services/export/service/src/main/java/org/collectionspace/services/export/DocumentsByCsidIterator.java
services/export/service/src/main/java/org/collectionspace/services/export/ExportResource.java
services/export/service/src/main/java/org/collectionspace/services/export/ExportWriter.java
services/export/service/src/main/java/org/collectionspace/services/export/RelationObjectsByQueryIterator.java
services/export/service/src/main/java/org/collectionspace/services/export/XmlExportWriter.java
services/export/service/src/main/java/org/collectionspace/services/export/nuxeo/ExportDocumentModelHandler.java
services/export/service/src/main/java/org/collectionspace/services/export/nuxeo/ExportValidatorHandler.java
services/jaxb/src/main/resources/invocationContext.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 (file)
index fc5ec35..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-package org.collectionspace.services.client;
-
-public class GenericAuthorityClientImpl extends
-               AuthorityClientImpl<Object, Object, AuthorityProxy> {
-
-       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<AuthorityProxy> 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;
-       }
-
-}
index add4ae3038bd2e5945e1fbed230d221089bfb743..e2482c7701f44412b02bb534f4135a346e71bdb5 100644 (file)
@@ -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
      *
index bc4c786d1bdecd192354850f04b073b370cfd088..32faa9e066965bbe83fc8342cefd6d83ab0781be 100644 (file)
@@ -76,6 +76,7 @@
 
         <!-- name of the service, this is also the default URI path to access this service binding -->
         <xs:attribute name="name" type="xs:string" use="required"/>
+        <xs:attribute name="displayName" type="xs:string"/>
         <xs:attribute name="type" type="xs:string" use="optional"/>
         <xs:attribute name="version" type="types:VersionType" use="required"/>
         <xs:attribute name="elasticsearchIndexed" type="xs:boolean" default="false"/>
index 2cd3e7114baf080f70bbaecf5d93ab5b0ad66174..ae5d39314b4b4437959622d798ee849222ad89cd 100644 (file)
        <packaging>jar</packaging>
 
        <dependencies>
-               <dependency>
-                       <groupId>org.collectionspace.services</groupId>
-                       <artifactId>org.collectionspace.services.authentication.service</artifactId>
-                       <version>${project.version}</version>
-                       <scope>provided</scope>
-               </dependency>
-               <dependency>
-                       <groupId>org.collectionspace.services</groupId>
-                       <artifactId>org.collectionspace.services.account.service</artifactId>
-                       <version>${project.version}</version>
-                       <scope>provided</scope>
-               </dependency>
                <dependency>
                        <groupId>org.collectionspace.services</groupId>
                        <artifactId>org.collectionspace.services.authority.service</artifactId>
                        <artifactId>org.collectionspace.services.config</artifactId>
                        <version>${project.version}</version>
                </dependency>
-               <dependency>
-                       <groupId>org.collectionspace.services</groupId>
-                       <artifactId>org.collectionspace.services.authority.jaxb</artifactId>
-                       <optional>true</optional>
-                       <version>${project.version}</version>
-               </dependency>
                <dependency>
                        <groupId>org.collectionspace.services</groupId>
                        <artifactId>org.collectionspace.services.common</artifactId>
                        <artifactId>org.collectionspace.services.export.client</artifactId>
                        <version>${project.version}</version>
                </dependency>
-               <dependency>
-                       <groupId>org.collectionspace.services</groupId>
-                       <artifactId>org.collectionspace.services.collectionobject.jaxb</artifactId>
-                       <version>${project.version}</version>
-               </dependency>
                <!-- External dependencies -->
-               <dependency>
-                       <groupId>junit</groupId>
-                       <artifactId>junit</artifactId>
-                       <scope>test</scope>
-               </dependency>
-               <dependency>
-                       <groupId>org.testng</groupId>
-                       <artifactId>testng</artifactId>
-               </dependency>
                <dependency>
                        <groupId>org.apache.commons</groupId>
                        <artifactId>commons-csv</artifactId>
                        <version>1.8</version>
                </dependency>
 
-               <!-- javax -->
-
-               <dependency>
-                       <groupId>javax.security</groupId>
-                       <artifactId>jaas</artifactId>
-                       <version>1.0.01</version>
-                       <scope>provided</scope>
-               </dependency>
-
                <!-- jboss -->
-
                <dependency>
                        <groupId>org.jboss.resteasy</groupId>
                        <artifactId>resteasy-jaxrs</artifactId>
                </dependency>
-               <dependency>
-                       <groupId>org.jboss.resteasy</groupId>
-                       <artifactId>resteasy-jaxb-provider</artifactId>
-               </dependency>
-               <dependency>
-                       <groupId>org.jboss.resteasy</groupId>
-                       <artifactId>resteasy-multipart-provider</artifactId>
-               </dependency>
 
                <!-- nuxeo -->
-
                <dependency>
                        <groupId>org.nuxeo.ecm.core</groupId>
                        <artifactId>nuxeo-core-api</artifactId>
index 9a6ad7027585e5fa8398675e99e2833a53a18fa5..7d3b79114c91be4a6e30b5871eabeba8d96055d1 100644 (file)
@@ -148,7 +148,7 @@ public abstract class AbstractDocumentsByQueryIterator<ListItemType> 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<ListItemType> implements
 
                // Some code in services assumes pathSegments will have at least one element, so add an
                // empty one.
-               List<PathSegment> pathSegments = Arrays.asList((PathSegment) new PathSegmentImpl("", false));
+               List<PathSegment> pathSegments = Arrays.asList(new PathSegmentImpl("", false));
 
                URIBuilder uriBuilder = new URIBuilder();
 
index 80d1fd02a08767719b92f3d61567220a8c886bf8..a2ecbe330162f8887bdb79d0136fdf3e7e319182 100644 (file)
@@ -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;
index 6c00082dcb6d43793c55f9162850f7ef806d1734..6d84cca4545319638fe1b9e5493e44b1fe039cfd 100644 (file)
@@ -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<String, Map<String, Set<String>>> 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<String, AuthorityDisplayMapping> 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<Field> fields = (includeFields != null ? includeFields.getField() : new ArrayList<Field>());
+               List<Field> 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<String> 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<String> 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<String> path, int depth) {
+       private String collectValues(Element element, List<String> 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<String> 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<String, Set<String>>());
+                       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<ServiceBindingType> hasAuthorityInstances = (binding) ->
+                       binding.getAuthorityInstanceList() != null &&
+                       binding.getAuthorityInstanceList().getAuthorityInstance() != null;
+
+               Predicate<ServiceBindingType> 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<String, String> 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);
+               }
+       }
+
 }
index 787065b750e6fbfb9ae140cfaf5581ef65606040..d3dece2e44c68655ecd8aa2f61384ae9026b9f54 100644 (file)
@@ -16,7 +16,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class DocumentsByCsidIterator implements Iterator<PoxPayloadOut> {
-       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<PoxPayloadOut> {
         : 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;
     }
   }
index dcdc5a8fc977d1a7029ba932656790b86b56998b..a4449f537e0570ccfdfc737a9a0cb73465a14fd4 100644 (file)
@@ -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<PoxPayloadIn, PoxPayloadOut> {
-       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<String, List<String>> EXCLUDE_PARTS = ImmutableMap.of(
                "collectionspace_core", Arrays.asList("workflowState", "tenantId", "refName"),
-               "account_permission", Collections.<String>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<PoxPaylo
                                PayloadOutputPart part = document.getPart(partName);
 
                                if (part != null) {
-                                       org.dom4j.Element partElement = part.getElementBody();
-                                       List<Node> matches = (List<Node>) partElement.selectNodes(xpath);
+                                       Element partElement = part.getElementBody();
+                                       List<Node> 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<PoxPaylo
                        ArrayList<PayloadOutputPart> 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<PoxPaylo
 
        private void detach(final String xpath, final Element element) {
                if (element != null) {
-                       List<Node> matches = (List<Node>) element.selectNodes(xpath);
+                       List<Node> matches = element.selectNodes(xpath);
 
                        for (Node excludeNode : matches) {
                                if (excludeNode.getNodeType() == Node.ELEMENT_NODE) {
@@ -267,8 +263,8 @@ public class ExportResource extends AbstractCollectionSpaceResourceImpl<PoxPaylo
                }
        }
 
-       private void markIncluded(org.dom4j.Element element) {
-               org.dom4j.Element parentElement = element.getParent();
+       private void markIncluded(Element element) {
+               Element parentElement = element.getParent();
 
                if (parentElement != null) {
                        markIncluded(parentElement);
@@ -277,17 +273,17 @@ public class ExportResource extends AbstractCollectionSpaceResourceImpl<PoxPaylo
                element.addAttribute(INCLUDE_ATTRIBUTE_NAME, "1");
        }
 
-       private void removeUnincluded(org.dom4j.Element element) {
+       private void removeUnincluded(Element element) {
                if (element.attributeValue(INCLUDE_ATTRIBUTE_NAME) == null) {
                        element.detach();
                }
                else {
                        element.addAttribute(INCLUDE_ATTRIBUTE_NAME, null);
 
-                       Iterator childIterator = element.elementIterator();
+                       Iterator<Element> childIterator = element.elementIterator();
 
                        while (childIterator.hasNext()) {
-                               org.dom4j.Element childElement = (org.dom4j.Element) childIterator.next();
+                               Element childElement = childIterator.next();
 
                                removeUnincluded(childElement);
                        }
index fc8f719633405ef51f74fcbcc3514d91e0b2dcc6..279edd7d081ad4e7ff80910ac63ac8a685969d40 100644 (file)
@@ -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<PoxPayloadIn, PoxPayloadOut> serviceContext);
-       public void setTenantBindingConfigReader(TenantBindingConfigReaderImpl tenantBindingConfigReader);
+       void setInvocationContext(InvocationContext invocationContext);
+       void setOutputStream(OutputStream outputStream);
+       void setServiceContext(ServiceContext<PoxPayloadIn, PoxPayloadOut> 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;
 }
index 857bb2426ecf61f5c6978da7c4cc089f227bd245..6ea7d1e313d6fd831e423b8a7155f77c85c4b4b9 100644 (file)
@@ -18,7 +18,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class RelationObjectsByQueryIterator extends RelationsByQueryIterator implements Iterator<PoxPayloadOut> {
-       private final Logger logger = LoggerFactory.getLogger(RelationObjectsByQueryIterator.class);
+  private final Logger logger = LoggerFactory.getLogger(RelationObjectsByQueryIterator.class);
 
   RelationObjectsByQueryIterator(
     ServiceContext<PoxPayloadIn, PoxPayloadOut> 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;
     }
   }
index 35ffa549f9ae0bc79737c1bdc9d0d8a162ddb007..5b996ec58b9e3b42fff2ec84fdee39f0b9d77b03 100644 (file)
@@ -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);
index 719734c6c8764fe6c0fd324039937293f3e9d5a8..c0f282f94c4374a89534396bbe212005c69087a4 100644 (file)
  */
 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<ExportsCommon> {
-       private final Logger logger = LoggerFactory.getLogger(ExportDocumentModelHandler.class);
-
-       public InputStream invokeExport(
-                       TenantBindingConfigReaderImpl tenantBindingReader,
-                       ResourceMap resourceMap,
-                       ServiceContext<PoxPayloadIn, PoxPayloadOut> 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<DocumentModel> 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<DocumentModel> findDocuments(
-                       TenantBindingConfigReaderImpl tenantBindingReader,
-                       ResourceMap resourceMap,
-                       ServiceContext<PoxPayloadIn, PoxPayloadOut> 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<DocumentModel> findDocumentByCsid(
-                       ResourceMap resourceMap,
-                       ServiceContext<PoxPayloadIn, PoxPayloadOut> serviceContext,
-                       CoreSessionInterface repoSession,
-                       String serviceName,
-                       String csid) throws Exception {
-
-               return findDocumentsByCsid(resourceMap, serviceContext, repoSession, serviceName, Arrays.asList(csid));
-       }
-
-       private Iterator<DocumentModel> findDocumentsByCsid(
-                       ResourceMap resourceMap,
-                       ServiceContext<PoxPayloadIn, PoxPayloadOut> serviceContext,
-                       CoreSessionInterface repoSession,
-                       String serviceName,
-                       List<String> csids) throws Exception {
-
-               return new DocumentsByCsidIterator(resourceMap, serviceContext, repoSession, serviceName, csids);
-       }
-
-       private Iterator<DocumentModel> findDocumentsByType(
-                       ResourceMap resourceMap,
-                       ServiceContext<PoxPayloadIn, PoxPayloadOut> serviceContext,
-                       CoreSessionInterface repoSession,
-                       String docType) {
-
-               return null;
-       }
-
-       private Iterator<DocumentModel> findDocumentsByGroup(
-                       ResourceMap resourceMap,
-                       ServiceContext<PoxPayloadIn, PoxPayloadOut> serviceContext,
-                       CoreSessionInterface repoSession,
-                       String docType) {
-
-               return null;
-       }
-
-       // private InputStream buildExportResult(String exportCSID,
-       //              HashMap<String, Object> params,
-       //              String exportFileName,
-       //              String outputMimeType,
-       //              StringBuffer outExportFileName) throws Exception {
-       //      Connection conn = null;
-       //      InputStream result = null;
-
-       //      return result;
-       // }
-
-       private class DocumentsByCsidIterator implements Iterator<DocumentModel> {
-               private NuxeoBasedResource resource;
-               private ServiceContext<PoxPayloadIn, PoxPayloadOut> serviceContext;
-               private CoreSessionInterface repoSession;
-               private Iterator<String> csidIterator;
-
-               DocumentsByCsidIterator(
-                               ResourceMap resourceMap,
-                               ServiceContext<PoxPayloadIn, PoxPayloadOut> serviceContext,
-                               CoreSessionInterface repoSession,
-                               String serviceName,
-                               List<String> 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<ExportsCommon> { }
index e184902ae128dcd313b2b93304e88ca3e13df134..bc94e74c385bcf526a2a92735b62e36c5914fb74 100644 (file)
@@ -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.");
-
        }
 
 }
index 39624e99332fab7699129ed429af057670d1a622..3f7a85bc0e7001609e12576ed616953ad7899664 100644 (file)
     <xs:element name="invocationContext">
         <xs:complexType>
             <xs:sequence>
-                <xs:element name="outputMIME" type="xs:string"></xs:element>
-                <xs:element name="mode" type="xs:string"></xs:element>
-                <xs:element name="updateCoreValues" type="xs:string"></xs:element>
-                <xs:element name="docType" type="xs:string"></xs:element>
-                <xs:element name="vocabulary" type="xs:string"></xs:element>
-                <xs:element name="singleCSID" type="xs:string"></xs:element>
-                <xs:element name="groupCSID" type="xs:string"></xs:element>
+                <xs:element name="outputMIME" type="xs:string"/>
+                <xs:element name="mode" type="xs:string"/>
+                <xs:element name="updateCoreValues" type="xs:string"/>
+                <xs:element name="docType" type="xs:string"/>
+                <xs:element name="vocabulary" type="xs:string"/>
+                <xs:element name="singleCSID" type="xs:string"/>
+                <xs:element name="groupCSID" type="xs:string"/>
                 <xs:element name="listCSIDs">
                     <xs:complexType>
                         <xs:sequence>
-                            <xs:element name="csid" type="xs:string" minOccurs="0" maxOccurs="unbounded"></xs:element>
+                            <xs:element name="csid" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
                         </xs:sequence>
                     </xs:complexType>
                 </xs:element>
                 <xs:element name="query">
                     <xs:complexType>
                         <xs:sequence>
-                            <xs:element name="kw" type="xs:string"></xs:element>
-                            <xs:element name="as" type="xs:string"></xs:element>
-                            <xs:element name="pgSz" type="xs:integer"></xs:element>
-                            <xs:element name="pgNum" type="xs:integer"></xs:element>
-                            <xs:element name="wf_deleted" type="xs:boolean" minOccurs="0"></xs:element>
+                            <xs:element name="kw" type="xs:string"/>
+                            <xs:element name="as" type="xs:string"/>
+                            <xs:element name="pgSz" type="xs:integer"/>
+                            <xs:element name="pgNum" type="xs:integer"/>
+                            <xs:element name="wf_deleted" type="xs:boolean" minOccurs="0"/>
 
                             <!-- Relation query parameters -->
-                            <xs:element name="sbj" type="xs:string"></xs:element>
-                            <xs:element name="sbjType" type="xs:string"></xs:element>
-                            <xs:element name="prd" type="xs:string"></xs:element>
-                            <xs:element name="obj" type="xs:string"></xs:element>
-                            <xs:element name="objType" type="xs:string"></xs:element>
-                            <xs:element name="andReciprocal" type="xs:boolean" minOccurs="0"></xs:element>
+                            <xs:element name="sbj" type="xs:string"/>
+                            <xs:element name="sbjType" type="xs:string"/>
+                            <xs:element name="prd" type="xs:string"/>
+                            <xs:element name="obj" type="xs:string"/>
+                            <xs:element name="objType" type="xs:string"/>
+                            <xs:element name="andReciprocal" type="xs:boolean" minOccurs="0"/>
                         </xs:sequence>
                     </xs:complexType>
                 </xs:element>
                 <xs:element name="includeFields">
                     <xs:complexType>
                         <xs:sequence>
-                            <xs:element name="field" type="field" minOccurs="0" maxOccurs="unbounded"></xs:element>
+                            <xs:element name="field" type="field" minOccurs="0" maxOccurs="unbounded"/>
                         </xs:sequence>
                     </xs:complexType>
                 </xs:element>
                 <xs:element name="excludeFields">
                     <xs:complexType>
                         <xs:sequence>
-                            <xs:element name="field" type="field" minOccurs="0" maxOccurs="unbounded"></xs:element>
+                            <xs:element name="field" type="field" minOccurs="0" maxOccurs="unbounded"/>
                         </xs:sequence>
                     </xs:complexType>
                 </xs:element>
@@ -66,8 +66,8 @@
                             <xs:element name="param" minOccurs="0" maxOccurs="unbounded">
                                 <xs:complexType>
                                     <xs:sequence>
-                                        <xs:element name="key" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
-                                        <xs:element name="value" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
+                                        <xs:element name="key" type="xs:string" minOccurs="0" maxOccurs="1"/>
+                                        <xs:element name="value" type="xs:string" minOccurs="0" maxOccurs="1"/>
                                     </xs:sequence>
                                 </xs:complexType>
                             </xs:element>