CC-584: Adding 'displayName' field to payload result for endpoint reports/mimetypes.
.factorypath
m2-settings.xml
*.log
+cspace-app-perflog.csv
<service:initHandler xmlns:service="http://collectionspace.org/services/config/service">
<service:classname>org.collectionspace.services.report.nuxeo.ReportPostInitHandler</service:classname>
<service:params>
- <service:property>
- <service:key>readerRoleName</service:key>
- <service:value>reader</service:value>
- </service:property>
+ <service:property>
+ <service:key>readerRoleName</service:key>
+ <service:value>reader</service:value>
+ </service:property>
</service:params>
</service:initHandler>
+ <service:properties xmlns:service="http://collectionspace.org/services/config/service">
+ <types:item xmlns:types="http://collectionspace.org/services/config/types">
+ <types:key>outputMIME</types:key>
+ <types:displayName>XML</types:displayName>
+ <types:value>application/xml</types:value>
+ </types:item>
+ <types:item xmlns:types="http://collectionspace.org/services/config/types">
+ <types:key>outputMIME</types:key>
+ <types:displayName>HTML</types:displayName>
+ <types:value>text/html</types:value>
+ </types:item>
+ <types:item xmlns:types="http://collectionspace.org/services/config/types">
+ <types:key>outputMIME</types:key>
+ <types:displayName>PDF</types:displayName>
+ <types:value>application/pdf</types:value>
+ </types:item>
+ <types:item xmlns:types="http://collectionspace.org/services/config/types">
+ <types:key>outputMIME</types:key>
+ <types:value>text/csv</types:value>
+ </types:item>
+ <types:item xmlns:types="http://collectionspace.org/services/config/types">
+ <types:key>outputMIME</types:key>
+ <types:value>text/tab-separated-values</types:value>
+ </types:item>
+ <types:item xmlns:types="http://collectionspace.org/services/config/types">
+ <types:key>outputMIME</types:key>
+ <types:value>application/msword</types:value>
+ </types:item>
+ <types:item xmlns:types="http://collectionspace.org/services/config/types">
+ <types:key>outputMIME</types:key>
+ <types:value>application/vnd.openxmlformats-officedocument.wordprocessingml.document</types:value>
+ </types:item>
+ <types:item xmlns:types="http://collectionspace.org/services/config/types">
+ <types:key>outputMIME</types:key>
+ <types:value>application/vnd.ms-excel</types:value>
+ </types:item>
+ <types:item xmlns:types="http://collectionspace.org/services/config/types">
+ <types:key>outputMIME</types:key>
+ <types:value>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</types:value>
+ </types:item>
+ <types:item xmlns:types="http://collectionspace.org/services/config/types">
+ <types:key>outputMIME</types:key>
+ <types:value>application/vnd.ms-powerpoint</types:value>
+ </types:item>
+ <types:item xmlns:types="http://collectionspace.org/services/config/types">
+ <types:key>outputMIME</types:key>
+ <types:value>application/vnd.openxmlformats-officedocument.presentationml.presentation</types:value>
+ </types:item>
+ </service:properties>
<service:object xmlns:service="http://collectionspace.org/services/config/service" name="Report"
version="1.0">
<service:part id="0" control_group="Managed" versionable="true" auditable="false" label="reports-system"
public static final String LIST_FAILED = "List request" + FAILED;
public static final String SEARCH_FAILED = "Search request" + FAILED;
public static final String AUTH_REFS_FAILED = "Authority references request" + FAILED;
+ public static final String LIST_MIMETYPES_FAILED = "Could not get list of support MIME types for report outputs.";
public static final String PASSWORD_RESET_REQUEST_FAILED = "Password reset request" + FAILED;
public static final String UNKNOWN_ERROR_MSG = "Unknown error ";
public class ServiceBindingUtils {
public static final boolean QUALIFIED_PROP_NAMES = true;
public static final boolean UNQUALIFIED_PROP_NAMES = false;
+ public static final String OUTPUT_MIME_PROP = "outputMIME";
public static final String AUTH_REF_PROP = "authRef";
public static final String TERM_REF_PROP = "termRef";
public static final String OBJ_NUMBER_PROP = "objectNumberProperty";
return PropertyItemUtils.getPropertyValueByNameFromNodeList(servicePropList, propName );
}
+ public static List<PropertyItemType> getPropertyValueList(ServiceBindingType service,
+ String propName) {
+ if (propName == null || propName.trim().isEmpty()) {
+ throw new IllegalArgumentException("ServiceBindingUtils.getPropertyValues: null property name!");
+ }
+ List<PropertyType> servicePropList = service.getProperties();
+ return PropertyItemUtils.getPropertyValueListByNameFromNodeList(servicePropList, propName);
+ }
+
/**
* @param service
* @param propName the property to set
/** The Constant logger. */
private static final Logger logger = LoggerFactory.getLogger(SecurityInterceptor.class);
+ private static final String REPORTS_MIME_OUTPUTS = "reports/mimetypes";
private static final String ACCOUNT_PERMISSIONS = "accounts/*/accountperms";
private static final String STRUCTURED_DATE_REQUEST = "structureddate";
private static final String PASSWORD_RESET = "accounts/requestpasswordreset";
switch (resName) {
case STRUCTURED_DATE_REQUEST:
case ACCOUNT_PERMISSIONS:
+ case REPORTS_MIME_OUTPUTS:
result = false;
break;
default:
}
return getPropertyValueByName(propNodeList.get(0).getItem(), propName);
}
-
+
+ public static List<PropertyItemType> getPropertyValueListByNameFromNodeList(List<PropertyType> propNodeList,
+ String propName) {
+ if (propNodeList == null || propNodeList.isEmpty()) {
+ return null;
+ }
+
+ ArrayList<PropertyItemType> result = new ArrayList<PropertyItemType>();
+ for (PropertyItemType propItem : propNodeList.get(0).getItem()) {
+ if (propName.equals(propItem.getKey())) {
+ result.add(propItem);
+ }
+ }
+
+ return result;
+ }
/**
* @param propList the list of properties.
<xs:complexType name="PropertyItemType">
<xs:sequence>
<xs:element name="key" type="xs:string"/>
+ <xs:element name="displayName" minOccurs="0" type="xs:string"/>
<xs:element name="value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+
+<!--
+ SystemInfo schema (XSD)
+
+ Entity : Reports Ouput MIME types
+ Used for: JAXB binding between XML and Java objects
+
+-->
+
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
+ jaxb:version="1.0" elementFormDefault="unqualified"
+ xmlns:ns="http://collectionspace.org/services/report"
+ xmlns="http://collectionspace.org/services/report"
+ targetNamespace="http://collectionspace.org/services/report"
+ version="0.1"
+>
+
+<!--
+ Avoid XmlRootElement nightmare:
+ See http://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html
+-->
+
+ <xs:element name="reports_ouput_mime_list">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="MIMETypeList" type="MIMEType" minOccurs="0" maxOccurs="1"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:complexType name="MIMEType">
+ <xs:sequence>
+ <xs:element name="MIMEType" type="MIMETypeItemType" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="MIMETypeItemType">
+ <xs:sequence>
+ <xs:element name="key" type="xs:string"/>
+ <xs:element name="value" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+
+</xs:schema>
}
}
+ @GET
+ @Path("mimetypes")
+ public ReportsOuputMimeList getSupportMimeTypes(
+ @Context UriInfo ui) {
+ try {
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
+ ReportDocumentModelHandler handler = (ReportDocumentModelHandler)createDocumentHandler(ctx);
+
+ return handler.getSupportMIMETypes(ctx);
+ } catch (Exception e) {
+ throw bigReThrow(e, ServiceMessages.LIST_MIMETYPES_FAILED);
+ }
+ }
+
/*
* TODO: provide a static utility that will load a report, interrogate it
* for information about the properties, and return that information.
* @param csid the csid
* @return the report
*/
- @GET
- @Path("{csid}/output")
- @Produces("application/pdf")
+// @GET
+// @Path("{csid}/output")
+// @Produces("application/pdf")
public Response invokeReport(
@Context UriInfo ui,
@PathParam("csid") String csid) {
import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter;
import org.collectionspace.services.ReportJAXBSchema;
+import org.collectionspace.services.report.MIMEType;
+import org.collectionspace.services.report.MIMETypeItemType;
import org.collectionspace.services.report.ReportsCommon;
+import org.collectionspace.services.report.ReportsOuputMimeList;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.client.ReportClient;
import org.collectionspace.services.common.api.JEEServerDeployment;
import org.collectionspace.services.common.api.FileTools;
import org.collectionspace.services.common.api.Tools;
+import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
+import org.collectionspace.services.common.context.ServiceBindingUtils;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.BadRequestException;
import org.collectionspace.services.common.document.DocumentException;
import org.collectionspace.services.common.invocable.Invocable;
import org.collectionspace.services.common.invocable.InvocationContext;
import org.collectionspace.services.common.storage.JDBCTools;
+import org.collectionspace.services.config.service.ServiceBindingType;
+import org.collectionspace.services.config.types.PropertyItemType;
import org.collectionspace.services.jaxb.InvocableJAXBSchema;
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.collectionspace.services.nuxeo.util.NuxeoUtils;
+
import org.jfree.util.Log;
-import org.nuxeo.ecm.core.api.DocumentModel;
+
import org.nuxeo.ecm.core.api.model.PropertyException;
+import org.nuxeo.ecm.core.api.DocumentModel;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static String REPORTS_STD_CSIDLIST_PARAM = "csidlist";
private static String REPORTS_STD_TENANTID_PARAM = "tenantid";
+ //
+ // Map the MIME types from the service bindings to our payload output
+ //
+ public ReportsOuputMimeList getSupportMIMETypes(
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) {
+ //
+ // Create a new payload response instance and initialize it
+ //
+ ReportsOuputMimeList result = new ReportsOuputMimeList();
+ MIMEType resultMIMEType = result.getMIMETypeList();
+ if (resultMIMEType == null) {
+ result.setMIMETypeList(resultMIMEType = new MIMEType());
+ }
+ List<MIMETypeItemType> resultMIMETypeItemList = resultMIMEType.getMIMEType();
+
+ //
+ // Read the MIME type values from the service bindings and put into our response payload
+ //
+ TenantBindingConfigReaderImpl tReader =
+ ServiceMain.getInstance().getTenantBindingConfigReader();
+ ServiceBindingType reportServiceBinding = tReader.getServiceBinding(ctx.getTenantId(), ctx.getServiceName());
+ List<PropertyItemType> bindingsMIMETypeList = ServiceBindingUtils.getPropertyValueList(reportServiceBinding, ServiceBindingUtils.OUTPUT_MIME_PROP);
+
+ if (bindingsMIMETypeList != null) {
+ for (PropertyItemType bindingItemMimeType : bindingsMIMETypeList) {
+ MIMETypeItemType resultMimeTypeItem = new MIMETypeItemType();
+ String displayName = bindingItemMimeType.getDisplayName();
+ if (displayName != null && displayName.trim().isEmpty() == false) {
+ resultMimeTypeItem.setKey(displayName);
+ } else {
+ resultMimeTypeItem.setKey(bindingItemMimeType.getValue());
+ }
+ resultMimeTypeItem.setValue(bindingItemMimeType.getValue());
+ resultMIMETypeItemList.add(resultMimeTypeItem);
+ }
+ }
+
+ return result;
+ }
+
public InputStream invokeReport(
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
String csid,