]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-654: Allow filtering reports and batch jobs by more than one mode.
authorRay Lee <ray.lee@lyrasis.org>
Tue, 18 Jun 2019 19:54:39 +0000 (12:54 -0700)
committerRay Lee <ray.lee@lyrasis.org>
Tue, 18 Jun 2019 19:54:39 +0000 (12:54 -0700)
services/batch/service/src/main/java/org/collectionspace/services/batch/BatchResource.java
services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java
services/common/src/main/java/org/collectionspace/services/common/query/QueryManager.java
services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java
services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java

index d4433426b84e473b3d129f378132e7329212de9d..fb3c912dac2740a1eebd7c9410a25c7c33f93e70 100644 (file)
@@ -43,6 +43,8 @@ import org.collectionspace.services.common.invocable.InvocationResults;
 import org.collectionspace.services.common.query.QueryManager;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 
+import java.util.List;
+
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
@@ -58,7 +60,7 @@ import javax.ws.rs.core.UriInfo;
 @Produces({"application/xml"})
 @Consumes({"application/xml"})
 public class BatchResource extends NuxeoBasedResource {
-       
+
        protected final String COMMON_SCHEMA = "batch_common";
 
     @Override
@@ -77,7 +79,7 @@ public class BatchResource extends NuxeoBasedResource {
     public Class getCommonPartClass() {
        return BatchCommon.class;
     }
-    
+
        // other resource methods and use the getRepositoryClient() methods.
        @Override
     protected AbstractCommonList getCommonList(UriInfo ui) {
@@ -86,29 +88,29 @@ public class BatchResource extends NuxeoBasedResource {
             MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
             DocumentHandler handler = createDocumentHandler(ctx);
             String docType = queryParams.getFirst(IQueryManager.SEARCH_TYPE_DOCTYPE);
-            String mode = queryParams.getFirst(IQueryManager.SEARCH_TYPE_INVOCATION_MODE);
+            List<String> modes = queryParams.get(IQueryManager.SEARCH_TYPE_INVOCATION_MODE);
             String whereClause = null;
             DocumentFilter documentFilter = null;
             String common_part = ctx.getCommonPartLabel();
-                       
+
             if (docType != null && !docType.isEmpty()) {
                 whereClause = QueryManager.createWhereClauseForInvocableByDocType(
                                common_part, docType);
                 documentFilter = handler.getDocumentFilter();
                 documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
             }
-                       
-            if (mode != null && !mode.isEmpty()) {
+
+            if (modes != null && !modes.isEmpty()) {
                 whereClause = QueryManager.createWhereClauseForInvocableByMode(
-                               common_part, mode);
+                               common_part, modes);
                 documentFilter = handler.getDocumentFilter();
                 documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
             }
-                       
+
             if (whereClause !=null && logger.isDebugEnabled()) {
                 logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
             }
-                       
+
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             AbstractCommonList list = (AbstractCommonList) handler.getCommonPartList();
             return list;
@@ -116,16 +118,16 @@ public class BatchResource extends NuxeoBasedResource {
             throw bigReThrow(e, ServiceMessages.LIST_FAILED);
         }
     }
-       
+
        /**
         * Gets the authorityItem list for the specified authority
         * If partialPerm is specified, keywords will be ignored.
-        * 
+        *
         * @param specifier either a CSID or one of the urn forms
         * @param partialTerm if non-null, matches partial terms
         * @param keywords if non-null, matches terms in the keyword index for items
         * @param ui passed to include additional parameters, like pagination controls
-        * 
+        *
         * @return the authorityItem list
         */
        @GET
@@ -166,9 +168,9 @@ public class BatchResource extends NuxeoBasedResource {
             throw bigReThrow(e, ServiceMessages.SEARCH_FAILED);
         }
     }
-    
+
        private String createWhereClauseForDocType(String docType) {
-               String trimmed = (docType == null)?"":docType.trim(); 
+               String trimmed = (docType == null)?"":docType.trim();
                if (trimmed.isEmpty()) {
                        throw new RuntimeException("No docType specified.");
                }
@@ -179,7 +181,7 @@ public class BatchResource extends NuxeoBasedResource {
        }
 
        private String createWhereClauseForMode(String mode) throws BadRequestException {
-               String trimmed = (mode == null)?"":mode.trim(); 
+               String trimmed = (mode == null)?"":mode.trim();
                if (trimmed.isEmpty()) {
                        throw new RuntimeException("No mode specified.");
                }
@@ -195,18 +197,18 @@ public class BatchResource extends NuxeoBasedResource {
                }
                return ptClause;
        }
-    
+
        private BatchCommon getBatchCommon(String csid) throws Exception {
                BatchCommon result = null;
-       
+
        ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
                PoxPayloadOut ppo = get(csid, ctx);
                PayloadPart batchCommonPart = ppo.getPart(BatchClient.SERVICE_COMMON_PART_NAME);
                result = (BatchCommon)batchCommonPart.getBody();
-               
+
        return result;
     }
-       
+
     @POST
     @Path("{csid}")
     public InvocationResults invokeBatchJob(
@@ -220,7 +222,7 @@ public class BatchResource extends NuxeoBasedResource {
             BatchDocumentModelHandler handler = (BatchDocumentModelHandler)createDocumentHandler(ctx);
             return handler.invokeBatchJob(ctx, csid, resourceMap, invContext, getBatchCommon(csid));
         } catch (Exception e) {
-               String msg = String.format("%s Could not invoke batch job with CSID='%s'.", 
+               String msg = String.format("%s Could not invoke batch job with CSID='%s'.",
                                ServiceMessages.POST_FAILED, csid);
             throw bigReThrow(e, msg);
         }
index e4133a6f1dbfb811faa1098e67d8c400e4088a36..f287539c4ca23212467262e04097bf8746d29665 100644 (file)
@@ -1,4 +1,4 @@
-/**    
+/**
  * IQueryManager.java
  *
  * {Purpose of This Class}
  */
 package org.collectionspace.services.client;
 
+import java.util.List;
+
 public interface IQueryManager {
-       
+
        final static String SEARCH_GROUP_OPEN = "(";
        final static String SEARCH_GROUP_CLOSE = ")";
        final static String SEARCH_TERM_SEPARATOR = " ";
@@ -44,7 +46,7 @@ public interface IQueryManager {
        final static String SEARCH_QUALIFIER_OR = SEARCH_TERM_SEPARATOR + "OR" + SEARCH_TERM_SEPARATOR;
     final static String DEFAULT_SELECT_CLAUSE = "SELECT * FROM ";
     final static String CSID_QUERY_PARAM = "csid";
-       
+
 
        //
        // Nuxeo pseudo-values (and filters) for special document properties.
@@ -57,7 +59,7 @@ public interface IQueryManager {
        // In the CMIS context, the prefix is nuxeo, not ecm
        final static String NUXEO_CMIS_IS_VERSION = "nuxeo:isVersion";
        final static String NUXEO_CMIS_IS_VERSION_FILTER = NUXEO_CMIS_IS_VERSION + " = false";
-       
+
        //
        // Query params for CMIS queries on the relationship (Relation) table.
        //
@@ -68,10 +70,10 @@ public interface IQueryManager {
        final static String SEARCH_RELATED_TO_CSID_AS_EITHER = "rtSbjOrObj";
        final static String SEARCH_RELATED_MATCH_OBJ_DOCTYPES = "rtObjDocTypes";
        final static String SELECT_DOC_TYPE_FIELD = "selectDocType";
-       
+
        final static String MARK_RELATED_TO_CSID_AS_SUBJECT = "mkRtSbj";
        final static String MARK_RELATED_TO_CSID_AS_EITHER = "mkRtSbjOrObj";
-       
+
        //
        // Generic CMIS property mapping constants
        //
@@ -84,14 +86,14 @@ public interface IQueryManager {
        final static String CMIS_NUXEO_TITLE = "dc:title";
        final static String CMIS_CS_UPDATED_AT = CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA + ":" +
                        CollectionSpaceClient.COLLECTIONSPACE_CORE_UPDATED_AT;
-       
+
        // CollectionSpace CMIS property mapping constants
        final static String CMIS_TARGET_PREFIX = "DOC";
        final static String CMIS_CORESCHEMA_PREFIX = "CORE";
        // Relations CMIS property mapping constants
        final static String CMIS_RELATIONS_PREFIX = "REL";
-       
-       final static String CMIS_JOIN_NUXEO_IS_VERSION_FILTER = 
+
+       final static String CMIS_JOIN_NUXEO_IS_VERSION_FILTER =
                        IQueryManager.CMIS_TARGET_PREFIX + "." + IQueryManager.NUXEO_CMIS_IS_VERSION_FILTER;
        final static String CMIS_JOIN_TENANT_ID_FILTER =
                        IQueryManager.CMIS_RELATIONS_PREFIX + "." + CollectionSpaceClient.CORE_TENANTID;
@@ -101,31 +103,31 @@ public interface IQueryManager {
        final static String CMIS_TARGET_TITLE = CMIS_TARGET_PREFIX + "." + CMIS_NUXEO_TITLE;
        final static String CMIS_TARGET_NAME = CMIS_TARGET_PREFIX + "." + CMIS_NUXEO_NAME;
        final static String CMIS_TARGET_UPDATED_AT = CMIS_TARGET_PREFIX + "." + CMIS_CS_UPDATED_AT;
-       
+
        final static String TENANT_USES_STARTING_WILDCARD_FOR_PARTIAL_TERM = "ptStartingWildcard";
         final static String MAX_LIST_ITEMS_RETURNED_LIMIT_ON_JDBC_QUERIES = "maxListItemsReturnedLimitOnJdbcQueries";
         final static String JDBC_QUERIES_ARE_TENANT_ID_RESTRICTED = "jdbcQueriesAreTenantIdRestricted";
 
        public void execQuery(String queryString);
-       
+
        public String getDatasourceName();
-       
+
        /**
         * Creates the where clause from keywords.
-        * 
+        *
         * @param keywords the keywords
-        * 
+        *
         * @return the string
         */
        public String createWhereClauseFromKeywords(String keywords);
-       
+
        public String createWhereClauseFromAdvancedSearch(String advancedSearch);
 
        final static boolean FILTER_EXCLUDE = true;
        final static boolean FILTER_INCLUDE = false;
-       
+
        /**
-        * Creates a query to filter a qualified (string) field according to a list of string values. 
+        * Creates a query to filter a qualified (string) field according to a list of string values.
         * @param qualifiedField The schema-qualified field to filter on
         * @param filterTerms the list of one or more strings to filter on
         * @param fExclude If true, will require qualifiedField NOT match the filters strings.
@@ -133,13 +135,13 @@ public interface IQueryManager {
         * @return queryString
         */
        public String createWhereClauseToFilterFromStringList(String qualifiedField, String[] filterTerms, boolean fExclude);
-       
+
        /**
         * Creates the where clause for partial term match.
-        * 
+        *
         * @param field the qualified field to match on
         * @param partialTerm the term to match against
-        * 
+        *
         * @return the string
         */
        public String createWhereClauseForPartialMatch(String dataSourceName,
@@ -151,27 +153,29 @@ public interface IQueryManager {
 
        /**
         * Creates a filtering where clause from docType, for invocables.
-        * 
+        *
         * @param schema the schema name for this invocable type
         * @param docType the docType
-        * 
+        *
         * @return the string
         */
        public String createWhereClauseForInvocableByDocType(String schema, String docType);
-       
+
        /**
         * Creates a filtering where clause from invocation mode, for invocables.
-        * 
+        *
         * @param schema the schema name for this invocable type
         * @param mode the mode
-        * 
+        *
         * @return the string
         */
        public String createWhereClauseForInvocableByMode(String schema, String mode);
 
+       public String createWhereClauseForInvocableByMode(String schema, List<String> modes);
+
        /*
-        * 
+        *
         */
        public String createWhereClauseFromCsid(String csid);
-       
+
 }
index 5790575c6d63d984970c23631e36bdb5d94e91f5..f53394013d2cc66e9de1a3b57073313ffc840c80 100644 (file)
@@ -1,4 +1,4 @@
-/**    
+/**
  * QueryManager.java
  *
  * {Purpose of This Class}
@@ -26,6 +26,8 @@
  */
 package org.collectionspace.services.common.query;
 
+import java.util.List;
+
 import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
@@ -36,32 +38,32 @@ import org.collectionspace.services.config.tenant.TenantBindingType;
 
 public class QueryManager {
        static private final IQueryManager queryManager = new QueryManagerNuxeoImpl();
-       
+
        /**
         * Creates the where clause from keywords.
-        * 
+        *
         * @param keywords the keywords
-        * 
+        *
         * @return the string
         */
        static public String createWhereClauseFromKeywords(String keywords) {
                return queryManager.createWhereClauseFromKeywords(keywords);
        }
-       
+
        static public String createWhereClauseFromAdvancedSearch(String keywords) {
                return queryManager.createWhereClauseFromAdvancedSearch(keywords);
        }
-       
+
        static public String createWhereClauseFromCsid(String csid) {
                return queryManager.createWhereClauseFromCsid(csid);
-       }       
-       
+       }
+
        /**
         * Creates the where clause for partial term match.
-        * 
+        *
         * @param field the qualified field to match on
         * @param partialTerm the term to match against
-        * 
+        *
         * @return the string
         */
        static public String createWhereClauseForPartialMatch(ServiceContext ctx,
@@ -75,15 +77,15 @@ public class QueryManager {
         TenantBindingType tenantBinding = tReader.getTenantBinding(ctx.getTenantId());
         String ptStartingWildcardValue = TenantBindingUtils.getPropertyValue(tenantBinding,
                        IQueryManager.TENANT_USES_STARTING_WILDCARD_FOR_PARTIAL_TERM);
-        boolean ptStartingWildcard = (ptStartingWildcardValue==null) 
+        boolean ptStartingWildcard = (ptStartingWildcardValue==null)
                                || Boolean.parseBoolean(ptStartingWildcardValue);
 
                return queryManager.createWhereClauseForPartialMatch(queryManager.getDatasourceName(),
                                repositoryName, cspaceInstanceId, field, ptStartingWildcard, partialTerm);
        }
-       
+
        /**
-        * Creates a query to filter a qualified (string) field according to a list of string values. 
+        * Creates a query to filter a qualified (string) field according to a list of string values.
         * @param qualifiedField The schema-qualified field to filter on
         * @param filterTerms the list of one or more strings to filter on
         * @param fExclude If true, will require qualifiedField NOT match the filters strings.
@@ -94,29 +96,32 @@ public class QueryManager {
                return queryManager.createWhereClauseToFilterFromStringList(qualifiedField, filterTerms, fExclude);
        }
 
-       
+
        /**
         * Creates a filtering where clause from docType, for invocables.
-        * 
+        *
         * @param schema the schema name for this invocable type
         * @param docType the docType
-        * 
+        *
         * @return the string
         */
        static public String createWhereClauseForInvocableByDocType(String schema, String docType) {
                return queryManager.createWhereClauseForInvocableByDocType(schema, docType);
        }
-       
+
        /**
         * Creates a filtering where clause from invocation mode, for invocables.
-        * 
+        *
         * @param schema the schema name for this invocable type
         * @param mode the mode
-        * 
+        *
         * @return the string
         */
        static public String createWhereClauseForInvocableByMode(String schema, String mode) {
                return queryManager.createWhereClauseForInvocableByMode(schema, mode);
        }
-       
+
+       static public String createWhereClauseForInvocableByMode(String schema, List<String> modes) {
+               return queryManager.createWhereClauseForInvocableByMode(schema, modes);
+       }
 }
index c947fedfc57540e8c80d40300a3dd92245f9b672..65fa50e7cea14902761cf5e8d9439b520bcefd32 100644 (file)
@@ -1,4 +1,4 @@
-/**    
+/**
  * QueryManagerNuxeoImpl.java
  *
  * {Purpose of This Class}
  */
 package org.collectionspace.services.common.query.nuxeo;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-//import org.nuxeo.ecm.core.client.NuxeoClient;
-
-
-
+import org.apache.commons.lang3.StringUtils;
 
 import org.collectionspace.services.jaxb.InvocableJAXBSchema;
-//import org.collectionspace.services.nuxeo.client.java.NuxeoConnector;
-//import org.collectionspace.services.nuxeo.client.java.NxConnect;
-
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.common.invocable.InvocableUtils;
 import org.collectionspace.services.common.storage.DatabaseProductType;
 import org.collectionspace.services.common.storage.JDBCTools;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 public class QueryManagerNuxeoImpl implements IQueryManager {
 
        private static String ECM_FULLTEXT_LIKE = "ecm:fulltext"
@@ -64,7 +61,7 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
        private static Pattern unescapedDblQuotes = Pattern.compile("(?<!\\\\)\"");
        private static Pattern unescapedSingleQuote = Pattern.compile("(?<!\\\\)'");
        //private static Pattern kwdSearchProblemChars = Pattern.compile("[\\:\\(\\)\\*\\%]");
-       // HACK to work around Nuxeo regression that tokenizes on '.'. 
+       // HACK to work around Nuxeo regression that tokenizes on '.'.
        private static Pattern kwdSearchProblemChars = Pattern.compile("[\\:\\(\\)\\*\\%\\.]");
        private static Pattern kwdSearchHyphen = Pattern.compile(" - ");
        private static Pattern advSearchSqlWildcard = Pattern.compile(".*?[I]*LIKE\\s*\\\"\\%\\\".*?");
@@ -93,13 +90,13 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
        public String getDatasourceName() {
                return JDBCTools.NUXEO_DATASOURCE_NAME;
        }
-       
+
        // TODO: This is currently just an example fixed query. This should
        // eventually be
        // removed or replaced with a more generic method.
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see
         * org.collectionspace.services.common.query.IQueryManager#execQuery(java
         * .lang.String)
@@ -126,13 +123,13 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
                                        advancedSearch);
                        result = advancedSearchWhereClause.toString();
                }
-               
+
                return result;
        }
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.collectionspace.services.common.query.IQueryManager#
         * createWhereClauseFromKeywords(java.lang.String)
         */
@@ -154,7 +151,7 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
                boolean newWordSet = true;
                while (regexMatcher.find()) {
                        String phrase = regexMatcher.group();
-                       // Not needed - already trimmed by split: 
+                       // Not needed - already trimmed by split:
                        // String trimmed = phrase.trim();
                        // Ignore empty strings from match, or goofy input
                        if (phrase.isEmpty())
@@ -167,7 +164,7 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
                                continue;
                        }
                        // Next comment block of questionable value...
-                       
+
                        // ignore the special chars except single quote here - can't hurt
                        // TODO this should become a special function that strips things the
                        // fulltext will ignore, including non-word chars and too-short
@@ -207,7 +204,7 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
                                addNOT = false;
                        }
                        fullTextWhereClause.append(escapedAndTrimmed);
-                       
+
                        if (logger.isTraceEnabled() == true) {
                                logger.trace("Current built whereClause is: "
                                                + fullTextWhereClause.toString());
@@ -231,7 +228,7 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.collectionspace.services.common.query.IQueryManager#
         * createWhereClauseFromKeywords(java.lang.String)
         */
@@ -264,7 +261,7 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
                if (field == null || field.isEmpty()) {
                        throw new RuntimeException("No match field specified.");
                }
-                       
+
                StringBuilder ptClause = new StringBuilder(trimmed.length()+field.length()+20);
                ptClause.append(field);
                ptClause.append(getLikeForm(dataSourceName, repositoryName, cspaceInstanceId));
@@ -276,10 +273,10 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
 
        /**
         * Creates a filtering where clause from docType, for invocables.
-        * 
+        *
         * @param docType
         *            the docType
-        * 
+        *
         * @return the string
         */
        @Override
@@ -299,24 +296,46 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
 
        /**
         * Creates a filtering where clause from invocation mode, for invocables.
-        * 
+        *
         * @param mode
         *            the mode
-        * 
+        *
         * @return the string
         */
        @Override
        public String createWhereClauseForInvocableByMode(String schema, String mode) {
-               String trimmed = (mode == null) ? "" : mode.trim();
-               if (trimmed.isEmpty()) {
-                       throw new RuntimeException("No docType specified.");
-               }
+               return createWhereClauseForInvocableByMode(schema, Arrays.asList(mode));
+       }
+
+       @Override
+       public String createWhereClauseForInvocableByMode(String schema, List<String> modes) {
                if (schema == null || schema.isEmpty()) {
                        throw new RuntimeException("No match schema specified.");
                }
-               String wClause = InvocableUtils.getPropertyNameForInvocationMode(
-                               schema, trimmed) + " != 0";
-               return wClause;
+
+               if (modes == null || modes.isEmpty()) {
+                       throw new RuntimeException("No mode specified.");
+               }
+
+               List<String> whereClauses = new ArrayList<String>();
+
+               for (String mode : modes) {
+                       String propName = InvocableUtils.getPropertyNameForInvocationMode(schema, mode.trim());
+
+                       if (propName != null && !propName.isEmpty()) {
+                               whereClauses.add(propName + " != 0");
+                       }
+               }
+
+               if (whereClauses.size() > 1) {
+                       return ("(" + StringUtils.join(whereClauses, " OR ") + ")");
+               }
+
+               if (whereClauses.size() > 0) {
+                       return whereClauses.get(0);
+               }
+
+               return "";
        }
 
        /**
@@ -329,9 +348,9 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
 
                return fFilteredChars;
        }
-       
+
        /**
-        * Creates a query to filter a qualified (string) field according to a list of string values. 
+        * Creates a query to filter a qualified (string) field according to a list of string values.
         * @param qualifiedField The schema-qualified field to filter on
         * @param filterTerms the list of one or more strings to filter on
         * @param fExclude If true, will require qualifiedField NOT match the filters strings.
@@ -345,18 +364,18 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
        if (filterTerms.length == 1) {
                filterClause.append(fExclude?" <> '":" = '");
                filterClause.append(filterTerms[0]);
-               filterClause.append('\'');  
+               filterClause.append('\'');
        } else {
                filterClause.append(fExclude?" NOT IN (":" IN (");
                for(int i=0; i<filterTerms.length; i++) {
                        if(i>0) {
                                filterClause.append(',');
                        }
-                       filterClause.append('\'');  
+                       filterClause.append('\'');
                        filterClause.append(filterTerms[i]);
-                       filterClause.append('\'');  
+                       filterClause.append('\'');
                }
-               filterClause.append(')');  
+               filterClause.append(')');
        }
        return filterClause.toString();
        }
index c9526b603db08246507325b214f4bf2fb6d3d651..c15ad41bf6e52e217f0a329a5983905a1a6105f7 100644 (file)
@@ -24,6 +24,7 @@
 package org.collectionspace.services.report;
 
 import java.io.InputStream;
+import java.util.List;
 
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.report.nuxeo.ReportDocumentModelHandler;
@@ -70,7 +71,7 @@ public class ReportResource extends NuxeoBasedResource {
     private static String REPORTS_FOLDER = "reports";
     private static String CSID_LIST_SEPARATOR = ",";
     final Logger logger = LoggerFactory.getLogger(ReportResource.class);
-    
+
     private static String REPORTS_STD_CSID_PARAM = "csid";
     private static String REPORTS_STD_GROUPCSID_PARAM = "groupcsid";
     private static String REPORTS_STD_CSIDLIST_PARAM = "csidlist";
@@ -81,7 +82,7 @@ public class ReportResource extends NuxeoBasedResource {
        final String lastChangeRevision = "$LastChangedRevision: 1982 $";
        return lastChangeRevision;
     }
-    
+
     @Override
     public String getServiceName() {
         return ReportClient.SERVICE_NAME;
@@ -91,7 +92,7 @@ public class ReportResource extends NuxeoBasedResource {
     public Class<ReportsCommon> getCommonPartClass() {
        return ReportsCommon.class;
     }
-    
+
     @Override
     protected AbstractCommonList getCommonList(UriInfo ui) {
         try {
@@ -99,19 +100,19 @@ public class ReportResource extends NuxeoBasedResource {
             MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
             DocumentHandler handler = createDocumentHandler(ctx);
             String docType = queryParams.getFirst(IQueryManager.SEARCH_TYPE_DOCTYPE);
-            String mode = queryParams.getFirst(IQueryManager.SEARCH_TYPE_INVOCATION_MODE);
+            List<String> modes = queryParams.get(IQueryManager.SEARCH_TYPE_INVOCATION_MODE);
             String whereClause = null;
             DocumentFilter documentFilter = null;
-            String common_part =ctx.getCommonPartLabel(); 
+            String common_part =ctx.getCommonPartLabel();
             if (docType != null && !docType.isEmpty()) {
                 whereClause = QueryManager.createWhereClauseForInvocableByDocType(
                                common_part, docType);
                 documentFilter = handler.getDocumentFilter();
                 documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
             }
-            if (mode != null && !mode.isEmpty()) {
+            if (modes != null && !modes.isEmpty()) {
                 whereClause = QueryManager.createWhereClauseForInvocableByMode(
-                               common_part, mode);
+                               common_part, modes);
                 documentFilter = handler.getDocumentFilter();
                 documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
             }
@@ -131,9 +132,9 @@ public class ReportResource extends NuxeoBasedResource {
      * for information about the properties, and return that information.
      * See: http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JasperManager.html#loadReport%28java.lang.String%29
      * to get the report from the file.
-     * Use: http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/base/JRBaseReport.html#getParameters%28%29 
+     * Use: http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/base/JRBaseReport.html#getParameters%28%29
      *  to get an array of http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JRParameter.html
-     *  Cast each to JRBaseParameter and use isSystemDefined to filter out 
+     *  Cast each to JRBaseParameter and use isSystemDefined to filter out
      *    the system defined parameters.
      */
 
@@ -146,13 +147,13 @@ public class ReportResource extends NuxeoBasedResource {
     @Path("{csid}/output")
     @Produces("application/pdf")
     public Response invokeReport(
-               @Context UriInfo ui,                    
+               @Context UriInfo ui,
             @PathParam("csid") String csid) {
        InvocationContext invContext = new InvocationContext();
        invContext.setMode(Invocable.INVOCATION_MODE_NO_CONTEXT);
        return invokeReport(ui, csid, invContext);
     }
-    
+
     /*
      * Publishes the report to the PublicItem service.  The response is a URI to the corresponding PublicItem resource instance in
      * the form of /publicitems/{csid}.
@@ -162,32 +163,32 @@ public class ReportResource extends NuxeoBasedResource {
     @POST
     @Path("{csid}/publish")
     public Response invokeReportAndPublish(
-               @Context ResourceMap resourceMap,               
+               @Context ResourceMap resourceMap,
                @Context UriInfo uriInfo,
                @PathParam("csid") String csid,
                InvocationContext invContext) {
        Response response = null;
-       
+
         try {
             StringBuffer outMimeType = new StringBuffer();
             StringBuffer outReportFileName = new StringBuffer();
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
-            InputStream reportInputStream = invokeReport(ctx, csid, invContext, outMimeType, outReportFileName);            
+            InputStream reportInputStream = invokeReport(ctx, csid, invContext, outMimeType, outReportFileName);
             response = PublicItemUtil.publishToRepository(
-                       (PublicitemsCommon)null, 
-                       resourceMap, 
-                       uriInfo, 
-                       getRepositoryClient(ctx), 
-                       ctx, 
-                       reportInputStream, 
+                       (PublicitemsCommon)null,
+                       resourceMap,
+                       uriInfo,
+                       getRepositoryClient(ctx),
+                       ctx,
+                       reportInputStream,
                        outReportFileName.toString());
         } catch (Exception e) {
             throw bigReThrow(e, ServiceMessages.POST_FAILED);
         }
-        
+
         return response;
     }
-    
+
     @POST
     @Path("{csid}")
     public Response invokeReport(
@@ -195,24 +196,24 @@ public class ReportResource extends NuxeoBasedResource {
                @PathParam("csid") String csid,
                InvocationContext invContext) {
        Response response = null;
-       
+
         try {
             StringBuffer outMimeType = new StringBuffer();
             StringBuffer outFileName = new StringBuffer();
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
             InputStream reportInputStream = invokeReport(ctx, csid, invContext, outMimeType, outFileName);
-            
+
                        // Need to set response type for what is requested...
                        ResponseBuilder builder = Response.ok(reportInputStream, outMimeType.toString());
                        builder = builder.header("Content-Disposition","inline;filename=\""+ outFileName.toString() +"\"");
-               response = builder.build();                                    
+               response = builder.build();
         } catch (Exception e) {
             throw bigReThrow(e, ServiceMessages.POST_FAILED);
         }
-        
+
         return response;
     }
-    
+
     /*
      * Does the actual report generation and returns an InputStream with the results.
      */
@@ -223,7 +224,7 @@ public class ReportResource extends NuxeoBasedResource {
                StringBuffer outMimeType,
                StringBuffer outReportFileName) throws Exception {
        InputStream result = null;
-       
+
         if (csid == null || "".equals(csid)) {
             logger.error("invokeReport: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
@@ -231,15 +232,15 @@ public class ReportResource extends NuxeoBasedResource {
                     "text/plain").build();
             throw new CSWebApplicationException(response);
         }
-        
+
         if (logger.isTraceEnabled()) {
             logger.trace("invokeReport with csid=" + csid);
         }
-       
+
         ReportDocumentModelHandler handler = (ReportDocumentModelHandler)createDocumentHandler(ctx);
         result = handler.invokeReport(ctx, csid, invContext, outMimeType, outReportFileName);
-        
+
         return result;
     }
-    
+
 }