+++ /dev/null
-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;
- }
-
-}
*/
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;
}
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
*
<!-- 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"/>
<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>
: 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;
}
// 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();
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;
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 {
// 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) {
}
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
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) {
}
}
+
@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];
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;
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);
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);
}
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);
+ }
+ }
+
}
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;
: 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;
}
}
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;
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";
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);
}
}
}
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);
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) {
}
}
- 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);
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);
}
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;
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;
}
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,
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();
: 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;
}
}
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;
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);
*/
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
* $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> { }
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.");
-
}
}
<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>
<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>