]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CC-584: Adding code to pull list of reporting output MIME types.
authorRichard Millet <remillet@gmail.com>
Thu, 27 Jun 2019 19:55:25 +0000 (12:55 -0700)
committerRichard Millet <remillet@gmail.com>
Fri, 28 Jun 2019 19:48:02 +0000 (12:48 -0700)
CC-584: Adding 'displayName' field to payload result for endpoint reports/mimetypes.

.gitignore
services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto-unified.xml
services/common/src/main/java/org/collectionspace/services/common/ServiceMessages.java
services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java
services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java
services/config/src/main/java/org/collectionspace/services/common/config/PropertyItemUtils.java
services/config/src/main/resources/types.xsd
services/report/jaxb/src/main/resources/reports-output-mime.xsd [new file with mode: 0644]
services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java
services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java

index 7eed369d211752bd330c340bac2bbce29f61b8a3..d048301e4c8c258377ff8c6fe0d294308c19f94b 100644 (file)
@@ -16,3 +16,4 @@ target
 .factorypath
 m2-settings.xml
 *.log
+cspace-app-perflog.csv
index 5d5b70f840d99d6f868ee73f3429b926cd744f5b..5e31de796ecb69019b77e640577c8351cdf6fe97 100644 (file)
                        <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"
index 86770ebdf4a0b88584c8bc36028916b1a30ee4f1..11494f4661b989cce84bc27821538fd8270e6123 100644 (file)
@@ -55,6 +55,7 @@ public class ServiceMessages {
     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 ";
index 0cba4b901337700cbe01c460c1373d6c62f0105f..2acfb5b528eae35f06259f026e18f79f0e78fac6 100644 (file)
@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
 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";
@@ -135,6 +136,15 @@ public class ServiceBindingUtils {
                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
index be52453bd25781965d39a19a2965e06e0a957d96..73a0997ffafb3800a39872d7fb45a8a8f66f3958 100644 (file)
@@ -84,6 +84,7 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn
 
        /** 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";
@@ -140,6 +141,7 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn
        switch (resName) {
                case STRUCTURED_DATE_REQUEST:
                case ACCOUNT_PERMISSIONS:
+               case REPORTS_MIME_OUTPUTS:
                        result = false;
                        break;
                default:
index f09806fb6abfb82dbbac3e5a8d4908575a18562a..d765959e8d5c166155aaf53580dee55fe99a6a9d 100644 (file)
@@ -20,7 +20,22 @@ public class PropertyItemUtils {
                }
                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.
index ddf3a6d8edece2f052b44a797ce579a40d7c626a..f486fd40cb69cb48e3129533febc8765ffa17495 100644 (file)
@@ -30,6 +30,7 @@
     <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>
diff --git a/services/report/jaxb/src/main/resources/reports-output-mime.xsd b/services/report/jaxb/src/main/resources/reports-output-mime.xsd
new file mode 100644 (file)
index 0000000..ccf4488
--- /dev/null
@@ -0,0 +1,46 @@
+<?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>
index c15ad41bf6e52e217f0a329a5983905a1a6105f7..15228f36f38f1ba1a998dc7ecf50d790e730bf2a 100644 (file)
@@ -127,6 +127,20 @@ public class ReportResource extends NuxeoBasedResource {
         }
     }
 
+    @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.
@@ -143,9 +157,9 @@ public class ReportResource extends NuxeoBasedResource {
      * @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) {
index 4e37787ae434ab3127c07cc2f07a872b52ed65d0..adbb388888f798a14887d648ed66f4e53b4261b7 100644 (file)
@@ -56,7 +56,10 @@ import net.sf.jasperreports.engine.export.ooxml.JRPptxExporter;
 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;
@@ -65,6 +68,8 @@ import org.collectionspace.services.common.ServiceMain;
 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;
@@ -72,14 +77,19 @@ import org.collectionspace.services.common.document.DocumentWrapper;
 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;
 
@@ -99,6 +109,46 @@ public class ReportDocumentModelHandler extends NuxeoDocumentModelHandler<Report
     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,