From: Richard Millet Date: Thu, 27 Jun 2019 19:55:25 +0000 (-0700) Subject: CC-584: Adding code to pull list of reporting output MIME types. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=fc78eb15f7ddadec332524398732b6e189a654c1;p=tmp%2Fjakarta-migration.git CC-584: Adding code to pull list of reporting output MIME types. CC-584: Adding 'displayName' field to payload result for endpoint reports/mimetypes. --- diff --git a/.gitignore b/.gitignore index 7eed369d2..d048301e4 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ target .factorypath m2-settings.xml *.log +cspace-app-perflog.csv diff --git a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto-unified.xml b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto-unified.xml index 5d5b70f84..5e31de796 100644 --- a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto-unified.xml +++ b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto-unified.xml @@ -429,12 +429,61 @@ org.collectionspace.services.report.nuxeo.ReportPostInitHandler - - readerRoleName - reader - + + readerRoleName + reader + + + + outputMIME + XML + application/xml + + + outputMIME + HTML + text/html + + + outputMIME + PDF + application/pdf + + + outputMIME + text/csv + + + outputMIME + text/tab-separated-values + + + outputMIME + application/msword + + + outputMIME + application/vnd.openxmlformats-officedocument.wordprocessingml.document + + + outputMIME + application/vnd.ms-excel + + + outputMIME + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + + + outputMIME + application/vnd.ms-powerpoint + + + outputMIME + application/vnd.openxmlformats-officedocument.presentationml.presentation + + getPropertyValueList(ServiceBindingType service, + String propName) { + if (propName == null || propName.trim().isEmpty()) { + throw new IllegalArgumentException("ServiceBindingUtils.getPropertyValues: null property name!"); + } + List servicePropList = service.getProperties(); + return PropertyItemUtils.getPropertyValueListByNameFromNodeList(servicePropList, propName); + } + /** * @param service * @param propName the property to set diff --git a/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java b/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java index be52453bd..73a0997ff 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java +++ b/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java @@ -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: diff --git a/services/config/src/main/java/org/collectionspace/services/common/config/PropertyItemUtils.java b/services/config/src/main/java/org/collectionspace/services/common/config/PropertyItemUtils.java index f09806fb6..d765959e8 100644 --- a/services/config/src/main/java/org/collectionspace/services/common/config/PropertyItemUtils.java +++ b/services/config/src/main/java/org/collectionspace/services/common/config/PropertyItemUtils.java @@ -20,7 +20,22 @@ public class PropertyItemUtils { } return getPropertyValueByName(propNodeList.get(0).getItem(), propName); } - + + public static List getPropertyValueListByNameFromNodeList(List propNodeList, + String propName) { + if (propNodeList == null || propNodeList.isEmpty()) { + return null; + } + + ArrayList result = new ArrayList(); + for (PropertyItemType propItem : propNodeList.get(0).getItem()) { + if (propName.equals(propItem.getKey())) { + result.add(propItem); + } + } + + return result; + } /** * @param propList the list of properties. diff --git a/services/config/src/main/resources/types.xsd b/services/config/src/main/resources/types.xsd index ddf3a6d8e..f486fd40c 100644 --- a/services/config/src/main/resources/types.xsd +++ b/services/config/src/main/resources/types.xsd @@ -30,6 +30,7 @@ + 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 index 000000000..ccf448810 --- /dev/null +++ b/services/report/jaxb/src/main/resources/reports-output-mime.xsd @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java b/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java index c15ad41bf..15228f36f 100644 --- a/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java +++ b/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java @@ -127,6 +127,20 @@ public class ReportResource extends NuxeoBasedResource { } } + @GET + @Path("mimetypes") + public ReportsOuputMimeList getSupportMimeTypes( + @Context UriInfo ui) { + try { + ServiceContext 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) { diff --git a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java index 4e37787ae..adbb38888 100644 --- a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java +++ b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java @@ -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 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 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 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 ctx, String csid,