Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-26696

Fix LogEntryProvider#queryLogs(AuditQueryBuilder) when using Predicates#in

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 9.10, 10.10
    • Fix Version/s: 9.10-HF27, 10.10-HF01, 11.1
    • Component/s: Audit
    • Release Notes Summary:
      The predicate IN is a valid operator for Audit queries.
    • Backlog priority:
      800
    • Sprint:
      nxFG 11.1.1
    • Story Points:
      2

      Description

      When using Predicates#in in a AuditQueryBuilder instance, it throws an org.hibernate.hql.ast.QuerySyntaxException.

      The following unit test demonstrates the problem:

      package org.nuxeo.ecm.core.test;
      
      import static org.junit.Assert.assertTrue;
      import static org.nuxeo.ecm.platform.audit.api.BuiltinLogEntryData.LOG_DOC_UUID;
      import static org.nuxeo.ecm.platform.audit.api.BuiltinLogEntryData.LOG_EVENT_ID;
      
      import java.util.Collections;
      
      import org.junit.Test;
      import org.junit.runner.RunWith;
      import org.nuxeo.ecm.platform.audit.AuditFeature;
      import org.nuxeo.ecm.platform.audit.api.AuditQueryBuilder;
      import org.nuxeo.ecm.platform.audit.api.AuditReader;
      import org.nuxeo.ecm.platform.audit.api.Predicates;
      import org.nuxeo.runtime.api.Framework;
      import org.nuxeo.runtime.test.runner.Features;
      import org.nuxeo.runtime.test.runner.FeaturesRunner;
      import org.nuxeo.runtime.test.runner.RuntimeFeature;
      
      @RunWith(FeaturesRunner.class)
      @Features({RuntimeFeature.class, AuditFeature.class})
      public class AuditReaderTest {
      
          /**
           * This test passes if the audit reader fails
           */
          @Test
          public void doTest() {
              AuditQueryBuilder builder = new AuditQueryBuilder()
                      .addAndPredicate(Predicates.in(LOG_DOC_UUID, Collections.singletonList("11111111-1111-1111-1111-111111111111")))
                      .addAndPredicate(Predicates.in(LOG_EVENT_ID, Collections.singletonList("download")))
                      ;
              AuditReader auditReader = Framework.getService(AuditReader.class);
              try {
                  auditReader.queryLogs(builder);
              } catch (Exception e) {
                  e.printStackTrace();
                  assertTrue(e instanceof IllegalArgumentException && e.getMessage().contains("org.hiberbate.hql.ast.QuerySyntaxException"));
              }
          }
      
      }
      

      It produces the following output:

      ...
      
      ***** This Nuxeo instance is not registered *****
      This Nuxeo instance can only be used for development and will be stopped if used in production
      
      18:11:13,486 INFO  [MetricsServiceImpl] Setting up metrics configuration
      18:11:13,502 INFO  [WorkManagerImpl] Activated work queue default WorkQueueDescriptor(id=default categories=[] queuing=true processing=true maxThreads=4 capacity=-1 clearCompletedAfterSeconds=)
      18:11:13,504 INFO  [WorkManagerImpl] Activated work queue updateACEStatus WorkQueueDescriptor(id=updateACEStatus categories=[updateACEStatus] queuing=true processing=true maxThreads=1 capacity=-1 clearCompletedAfterSeconds=)
      18:11:13,505 INFO  [WorkManagerImpl] Activated work queue fulltextUpdater WorkQueueDescriptor(id=fulltextUpdater categories=[fulltextUpdater] queuing=true processing=true maxThreads=1 capacity=-1 clearCompletedAfterSeconds=)
      18:11:13,783 DEBUG [DefaultAuditBulker] offered org.nuxeo.ecm.platform.audit.impl.LogEntryImpl@be21bc9[entityType=<null>,id=0,principalName=system,eventId=documentCreated,eventDate=Wed Jan 23 18:11:13 PST 2019,logDate=<null>,docUUID=bafdf22f-0548-452c-88d7-213b76754761,docType=WorkspaceRoot,docPath=/default-domain/workspaces,category=eventDocumentCategory,comment=<null>,docLifeCycle=project,repositoryId=test,extendedInfos={}]
      18:11:13,783 DEBUG [DefaultAuditBulker] offered org.nuxeo.ecm.platform.audit.impl.LogEntryImpl@4cbf4e0[entityType=<null>,id=0,principalName=system,eventId=documentSecurityUpdated,eventDate=Wed Jan 23 18:11:13 PST 2019,logDate=<null>,docUUID=9fcc0ad2-702a-474a-816d-e40cb67a1db5,docType=SectionRoot,docPath=/default-domain/sections,category=eventDocumentCategory,comment=<null>,docLifeCycle=project,repositoryId=test,extendedInfos={}]
      18:11:13,783 DEBUG [DefaultAuditBulker] offered org.nuxeo.ecm.platform.audit.impl.LogEntryImpl@17eb7e06[entityType=<null>,id=0,principalName=system,eventId=documentCreated,eventDate=Wed Jan 23 18:11:13 PST 2019,logDate=<null>,docUUID=9fcc0ad2-702a-474a-816d-e40cb67a1db5,docType=SectionRoot,docPath=/default-domain/sections,category=eventDocumentCategory,comment=<null>,docLifeCycle=project,repositoryId=test,extendedInfos={}]
      18:11:13,784 DEBUG [DefaultAuditBulker] offered org.nuxeo.ecm.platform.audit.impl.LogEntryImpl@ccc1361[entityType=<null>,id=0,principalName=system,eventId=documentCreated,eventDate=Wed Jan 23 18:11:13 PST 2019,logDate=<null>,docUUID=6cf61ccd-24a0-491e-9535-7b3ddddc36d1,docType=TemplateRoot,docPath=/default-domain/templates,category=eventDocumentCategory,comment=<null>,docLifeCycle=project,repositoryId=test,extendedInfos={}]
      18:11:13,784 DEBUG [DefaultAuditBulker] offered org.nuxeo.ecm.platform.audit.impl.LogEntryImpl@2e107d43[entityType=<null>,id=0,principalName=system,eventId=documentCreated,eventDate=Wed Jan 23 18:11:13 PST 2019,logDate=<null>,docUUID=0682bb0c-d6a8-4882-9eb3-5a79167576b4,docType=Domain,docPath=/default-domain,category=eventDocumentCategory,comment=<null>,docLifeCycle=project,repositoryId=test,extendedInfos={}]
      18:11:13,784 DEBUG [DefaultAuditBulker] offered org.nuxeo.ecm.platform.audit.impl.LogEntryImpl@75a7f095[entityType=<null>,id=0,principalName=system,eventId=documentSecurityUpdated,eventDate=Wed Jan 23 18:11:13 PST 2019,logDate=<null>,docUUID=8eeb174c-00e0-43bf-9db9-cfe2543ae653,docType=Root,docPath=/,category=eventDocumentCategory,comment=<null>,docLifeCycle=<null>,repositoryId=test,extendedInfos={}]
      18:11:13,795 INFO  [ComponentManagerImpl] Components started in 2.712 sec.
      18:11:13,798 INFO  [OSGiRuntimeService] Nuxeo Platform Started
      ======================================================================
      = Component Loading Status: Pending: 0 / Missing: 0 / Unstarted: 0 / Total: 127
      ======================================================================
      18:11:13,867 DEBUG [DefaultAuditBulker$Consumer] flushed 6 events
      18:11:13,912 INFO  [CacheServiceImpl] Cache registered: cache-userDirectory
      18:11:13,939 INFO  [CacheServiceImpl] Cache registered: cacheWithoutReference-userDirectory
      18:11:13,940 INFO  [CacheServiceImpl] Cache registered: cache-groupDirectory
      18:11:13,941 INFO  [CacheServiceImpl] Cache registered: cacheWithoutReference-groupDirectory
      18:11:13,995 DEBUG [LogEntryProvider] queryLogs() builder=org.nuxeo.ecm.platform.audit.api.AuditQueryBuilder@6598caab[filter=AND(docUUID IN '11111111-1111-1111-1111-111111111111', eventId IN 'download'),orders=,offset=0,limit=0]
      18:11:14,001 ERROR [ErrorCounter] line 1:79: unexpected token: :
      18:11:14,002 ERROR [ErrorCounter] line 1:107: unexpected token: :
      java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: : near line 1, column 79 [ FROM org.nuxeo.ecm.platform.audit.impl.LogEntryImpl log WHERE log.docUUID IN :docUUID AND log.eventId IN :eventId]
      	at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:601)
      	at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:96)
      	at org.nuxeo.ecm.platform.audit.service.LogEntryProvider.queryLogs(LogEntryProvider.java:324)
      	at org.nuxeo.ecm.platform.audit.service.DefaultAuditBackend.lambda$queryLogs$12(DefaultAuditBackend.java:191)
      	at org.nuxeo.ecm.platform.audit.service.DefaultAuditBackend.lambda$apply$1(DefaultAuditBackend.java:134)
      	at org.nuxeo.ecm.core.persistence.PersistenceProvider.run(PersistenceProvider.java:166)
      	at org.nuxeo.ecm.platform.audit.service.DefaultAuditBackend.apply(DefaultAuditBackend.java:133)
      	at org.nuxeo.ecm.platform.audit.service.DefaultAuditBackend.queryLogs(DefaultAuditBackend.java:191)
      	at org.nuxeo.ecm.core.test.AuditReaderTest.doTest(AuditReaderTest.java:37)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      	at org.nuxeo.runtime.test.runner.FeaturesRunner$BeforeMethodRunStatement.evaluate(FeaturesRunner.java:285)
      	at org.nuxeo.runtime.test.runner.FeaturesRunner$BeforeSetupStatement.evaluate(FeaturesRunner.java:301)
      	at org.nuxeo.runtime.test.runner.FeaturesRunner$AfterMethodRunStatement.evaluate(FeaturesRunner.java:332)
      	at org.nuxeo.runtime.test.runner.FeaturesRunner$AfterTeardownStatement.evaluate(FeaturesRunner.java:351)
      	at org.nuxeo.runtime.test.runner.FeaturesRunner$RulesFactory$1.evaluate(FeaturesRunner.java:429)
      	at org.nuxeo.runtime.test.runner.RuntimeDeployment$DeploymentStatement.evaluate(RuntimeDeployment.java:299)
      	at org.nuxeo.runtime.test.runner.RuntimeFeature$2$1.evaluate(RuntimeFeature.java:137)
      	at org.nuxeo.runtime.test.runner.FeaturesRunner$RulesFactory$1.evaluate(FeaturesRunner.java:429)
      	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      	at org.nuxeo.runtime.test.runner.FeaturesRunner$AfterClassStatement.evaluate(FeaturesRunner.java:235)
      	at org.nuxeo.runtime.test.runner.FeaturesRunner$RulesFactory$1.evaluate(FeaturesRunner.java:429)
      	at org.nuxeo.runtime.test.runner.FeaturesRunner$BeforeClassStatement.evaluate(FeaturesRunner.java:218)
      	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
      Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: : near line 1, column 79 [ FROM org.nuxeo.ecm.platform.audit.impl.LogEntryImpl log WHERE log.docUUID IN :docUUID AND log.eventId IN :eventId]
      	at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
      	at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
      	at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
      	at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284)
      	at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
      	at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
      	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
      	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
      	at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
      	at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
      	at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
      	at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651)
      	at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:93)
      	... 43 more
      18:11:14,040 DEBUG [DefaultAuditBulker] offered org.nuxeo.ecm.platform.audit.impl.LogEntryImpl@e624fb8[entityType=<null>,id=0,principalName=Administrator,eventId=documentRemoved,eventDate=Wed Jan 23 18:11:14 PST 2019,logDate=<null>,docUUID=0682bb0c-d6a8-4882-9eb3-5a79167576b4,docType=Domain,docPath=/default-domain,category=eventDocumentCategory,comment=Document does not exist anymore!,docLifeCycle=<null>,repositoryId=test,extendedInfos={}]
      18:11:14,041 DEBUG [DefaultAuditBulker] offered org.nuxeo.ecm.platform.audit.impl.LogEntryImpl@4a21cd1[entityType=<null>,id=0,principalName=Administrator,eventId=documentSecurityUpdated,eventDate=Wed Jan 23 18:11:14 PST 2019,logDate=<null>,docUUID=8eeb174c-00e0-43bf-9db9-cfe2543ae653,docType=Root,docPath=/,category=eventDocumentCategory,comment=<null>,docLifeCycle=<null>,repositoryId=test,extendedInfos={}]
      18:11:14,047 DEBUG [DefaultAuditBulker$Consumer] flushed 2 events
      18:11:14,182 INFO  [AbstractRuntimeService] Stopping Nuxeo Runtime service OSGi NXRuntime; version: 1.4.0
      18:11:14,182 INFO  [ComponentManagerImpl] Stopping Nuxeo Components
      18:11:14,184 INFO  [WorkManagerImpl] Deactivated work queue default
      18:11:14,184 INFO  [WorkManagerImpl] Deactivated work queue updateACEStatus
      18:11:14,184 INFO  [WorkManagerImpl] Deactivated work queue fulltextUpdater
      18:11:14,190 INFO  [GCTask] GCThread bruttaly interupted
      18:11:14,191 INFO  [RepositoryService] Shutting down repository manager
      18:11:14,193 INFO  [DataSourceComponent] Unregistering DataSourceLink: java:comp/env/jdbc/repository_test
      18:11:14,193 INFO  [DataSourceComponent] Unregistering datasource: jdbc/nxaudit-logs
      18:11:14,193 INFO  [DataSourceComponent] Unregistering datasource: jdbc/nxsqldirectory
      18:11:14,194 INFO  [DataSourceComponent] Unregistering datasource: jdbc/nuxeojunittests
      18:11:14,194 INFO  [ComponentManagerImpl] Components stopped in 0.012 sec.
      18:11:14,195 INFO  [UserService] UserService deactivated
      18:11:14,199 INFO  [ComponentManagerImpl] Components deactivated in 0.005 sec.
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 hour
                  1h

                    PagerDuty

                    Error rendering 'com.pagerduty.jira-server-plugin:PagerDuty'. Please contact your Jira administrators.