From fe99ec99f518811607ba563741cfea77402439d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Novotn=C3=BD?= Date: Wed, 21 Feb 2024 12:46:54 +0100 Subject: [PATCH] Revert "RHPAM-4889: using a feature flag to enable/disable strict mode. (#1606)" This reverts commit a5187268293e0e7b18dd1a60210f1ecc4f1c5ff1. --- .../KieServerQueryDefinitionLoader.java | 90 +++++--------- .../default-query-definitions-strict.json | 14 --- ...erQueryDefinitionLoaderStrictModeTest.java | 113 ------------------ .../KieServerQueryDefinitionLoaderTest.java | 13 -- 4 files changed, 32 insertions(+), 198 deletions(-) delete mode 100644 jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/main/resources/default-query-definitions-strict.json delete mode 100644 jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/test/java/org/jbpm/workbench/ks/integration/KieServerQueryDefinitionLoaderStrictModeTest.java diff --git a/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/main/java/org/jbpm/workbench/ks/integration/KieServerQueryDefinitionLoader.java b/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/main/java/org/jbpm/workbench/ks/integration/KieServerQueryDefinitionLoader.java index 154bb28b0c..341aa2806f 100644 --- a/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/main/java/org/jbpm/workbench/ks/integration/KieServerQueryDefinitionLoader.java +++ b/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/main/java/org/jbpm/workbench/ks/integration/KieServerQueryDefinitionLoader.java @@ -19,9 +19,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; import javax.annotation.PostConstruct; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.event.Event; @@ -44,77 +41,54 @@ public class KieServerQueryDefinitionLoader { private static final Logger LOGGER = LoggerFactory.getLogger(KieServerQueryDefinitionLoader.class); - static final String JBPM_WB_QUERY_MODE = "jbpm.wb.querymode"; - enum QueryMode { - DEFAULT, - STRICT; - - static QueryMode convert(final String mode) { - try { - return QueryMode.valueOf(mode.toUpperCase()); - } catch (IllegalArgumentException ignored) { - } - return QueryMode.DEFAULT; - } - } - @Inject Event event; @PostConstruct public void init() { - init(System.getProperties()); + loadDefaultQueryDefinitions(); } - void init(final Properties properties) { - loadDefaultQueryDefinitions(QueryMode.convert(properties.getProperty(JBPM_WB_QUERY_MODE, QueryMode.DEFAULT.toString()))); - } - - protected void loadDefaultQueryDefinitions(final QueryMode queryMode) { - final Map applyStrict = new HashMap<>(); - - if (QueryMode.STRICT.equals(queryMode)) { - QueryDefinition[] queries = loadQueryDefinitions("/default-query-definitions-strict.json"); - for (QueryDefinition q : queries) { - applyStrict.put(q.getName(), q.getTarget()); - } - } - - final QueryDefinition[] queries = loadQueryDefinitions("/default-query-definitions.json"); - for (QueryDefinition q : queries) { - if (applyStrict.containsKey(q.getName())){ - q.setTarget(applyStrict.get(q.getName())); + protected void loadDefaultQueryDefinitions() { + // load any default query definitions + try (InputStream qdStream = this.getClass().getResourceAsStream("/default-query-definitions.json")) { + if (qdStream == null) { + LOGGER.info("Default query definitions file default-query-definitions.json not found"); + return; } - LOGGER.info("Loaded query definition: {}", q); - event.fire(new QueryDefinitionLoaded(q)); + loadQueryDefinitions(qdStream, + MarshallerFactory.getMarshaller(MarshallingFormat.JSON, + this.getClass().getClassLoader())); + } catch (Exception e) { + LOGGER.error("Error when loading default query definitions from default-query-definitions.json", + e); } } - protected QueryDefinition[] loadQueryDefinitions(String resourceName) { - - try (InputStream qdStream = this.getClass().getResourceAsStream(resourceName)) { - if (qdStream == null) { - LOGGER.info("Default query definitions file " + resourceName + " not found"); - return new QueryDefinition[0]; - } - - final String qdString = IOUtils.toString(qdStream, Charset.forName("UTF-8")); + protected void loadQueryDefinitions(final InputStream qdStream, + final Marshaller marshaller) throws IOException { + final String qdString = IOUtils.toString(qdStream, + Charset.forName("UTF-8")); - QueryDefinition[] queries = MarshallerFactory.getMarshaller(MarshallingFormat.JSON, this.getClass().getClassLoader()).unmarshall(qdString, QueryDefinition[].class); + try { + QueryDefinition[] queries = marshaller.unmarshall(qdString, + QueryDefinition[].class); - LOGGER.info("Found {} query definitions", queries == null ? 0 : queries.length); + LOGGER.info("Found {} query definitions", + queries == null ? 0 : queries.length); - if (queries == null){ - return new QueryDefinition[0]; + if (queries == null) { + return; + } + for (QueryDefinition q : + queries) { + LOGGER.info("Loaded query definition: {}", + q); + event.fire(new QueryDefinitionLoaded(q)); } - - return queries; } catch (MarshallingException e) { - LOGGER.error("Error when unmarshalling query definitions from stream.", e); - } catch (Exception e) { - LOGGER.error("Error when loading default query definitions from " + resourceName, e); + LOGGER.error("Error when unmarshalling query definitions from stream.", + e); } - - return new QueryDefinition[0]; } } diff --git a/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/main/resources/default-query-definitions-strict.json b/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/main/resources/default-query-definitions-strict.json deleted file mode 100644 index 5e1d434f3d..0000000000 --- a/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/main/resources/default-query-definitions-strict.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "query-name": "jbpmProcessInstances", - "query-target": "FILTERED_PROCESS" - }, - { - "query-name": "processesMonitoring", - "query-target": "FILTERED_PROCESS" - }, - { - "query-name": "tasksMonitoring", - "query-target": "FILTERED_PROCESS" - } -] \ No newline at end of file diff --git a/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/test/java/org/jbpm/workbench/ks/integration/KieServerQueryDefinitionLoaderStrictModeTest.java b/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/test/java/org/jbpm/workbench/ks/integration/KieServerQueryDefinitionLoaderStrictModeTest.java deleted file mode 100644 index 246a85a669..0000000000 --- a/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/test/java/org/jbpm/workbench/ks/integration/KieServerQueryDefinitionLoaderStrictModeTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2021 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jbpm.workbench.ks.integration; - -import org.jbpm.workbench.ks.integration.event.QueryDefinitionLoaded; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.kie.server.api.model.definition.QueryDefinition; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import javax.enterprise.event.Event; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.MockitoAnnotations.openMocks; - -/** - * This test class has been created to make contributors aware about the importance of the queries defined in the - * "default-query-definitions.json" file. These queries has been tested and optimized due to some important performance - * issues found on a very important and critical customer. - * Please, consider running a performance test when one of them is changed. - * - * @see JBPM-9099 - */ -@RunWith(MockitoJUnitRunner.class) -public class KieServerQueryDefinitionLoaderStrictModeTest { - - private final Map receivedEvents = new HashMap<>(); - - private static final int TOTAL_QUERY_DEFINITIONS_EXPECTED = 12; - - @Mock - private Event event; - - @InjectMocks - private KieServerQueryDefinitionLoader kieServerQueryDefinitionLoader; - - @Before - public void setup() { - openMocks(this); - doAnswer(invocation -> { - QueryDefinitionLoaded queryDefinitionLoaded = invocation.getArgument(0); - receivedEvents.put(queryDefinitionLoaded.getDefinition().getName(), queryDefinitionLoaded.getDefinition()); - return null; - }).when(event).fire(any(QueryDefinitionLoaded.class)); - this.kieServerQueryDefinitionLoader.init(new Properties(){{ - put(KieServerQueryDefinitionLoader.JBPM_WB_QUERY_MODE, "STRICT"); - }}); - } - - @Test - public void testJbpmProcessInstances() { - QueryDefinition expectedQuery = QueryDefinition.builder() - .name("jbpmProcessInstances") - .expression("SELECT LOG.PROCESSINSTANCEID, LOG.PROCESSID, LOG.START_DATE, LOG.END_DATE, LOG.STATUS, LOG.PARENTPROCESSINSTANCEID, LOG.OUTCOME, LOG.DURATION, LOG.USER_IDENTITY, LOG.PROCESSVERSION, LOG.PROCESSNAME, LOG.CORRELATIONKEY, LOG.EXTERNALID, LOG.PROCESSINSTANCEDESCRIPTION, LOG.SLA_DUE_DATE, LOG.SLACOMPLIANCE, COALESCE ( INFO.LASTMODIFICATIONDATE, LOG.END_DATE ) AS LASTMODIFICATIONDATE, COUNT( ERRINFO.ID ) ERRORCOUNT FROM ProcessInstanceLog LOG LEFT JOIN ExecutionErrorInfo ERRINFO ON ERRINFO.PROCESS_INST_ID=LOG.PROCESSINSTANCEID AND ERRINFO.ERROR_ACK=0 LEFT JOIN ProcessInstanceInfo INFO ON INFO.INSTANCEID=LOG.PROCESSINSTANCEID GROUP BY LOG.PROCESSINSTANCEID, LOG.PROCESSID, LOG.START_DATE, LOG.END_DATE, LOG.STATUS, LOG.PARENTPROCESSINSTANCEID, LOG.OUTCOME, LOG.DURATION, LOG.USER_IDENTITY, LOG.PROCESSVERSION, LOG.PROCESSNAME, LOG.CORRELATIONKEY, LOG.EXTERNALID, LOG.PROCESSINSTANCEDESCRIPTION, LOG.SLA_DUE_DATE, LOG.SLACOMPLIANCE, COALESCE ( INFO.LASTMODIFICATIONDATE, LOG.END_DATE )") - .target("FILTERED_PROCESS") - .build(); - testQueryDefinitionLoaded(expectedQuery); - } - - @Test - public void testProcessesMonitoring() { - QueryDefinition expectedQuery = QueryDefinition.builder() - .name("processesMonitoring") - .expression("select log.processInstanceId, log.processId, log.start_date, log.end_date, log.status, " + - "log.duration, log.user_identity, log.processVersion, log.processName, " + - "log.externalId from ProcessInstanceLog log") - .target("FILTERED_PROCESS") - .build(); - testQueryDefinitionLoaded(expectedQuery); - } - - @Test - public void testTasksMonitoring() { - QueryDefinition expectedQuery = QueryDefinition.builder() - .name("tasksMonitoring") - .expression("select p.processName, p.externalId, t.taskId, t.taskName, t.status, t.createdDate, " + - "t.startDate, t.endDate, t.processInstanceId, t.userId, t.duration " + - "from ProcessInstanceLog p inner join BAMTaskSummary t on " + - "(t.processInstanceId = p.processInstanceId) inner join (select min(pk) as pk " + - "from BAMTaskSummary group by taskId) d on t.pk = d.pk") - .target("FILTERED_PROCESS") - .build(); - testQueryDefinitionLoaded(expectedQuery); - } - - private void testQueryDefinitionLoaded(QueryDefinition expectedQueryDefinition) { - assertTrue("No named-queries were found", receivedEvents.size() > 0); - assertNotNull("No query definition found for " + expectedQueryDefinition.getName(), receivedEvents.get(expectedQueryDefinition.getName())); - assertEquals(expectedQueryDefinition.getExpression(), receivedEvents.get(expectedQueryDefinition.getName()).getExpression()); - assertEquals(expectedQueryDefinition.getTarget(), receivedEvents.get(expectedQueryDefinition.getName()).getTarget()); - } -} diff --git a/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/test/java/org/jbpm/workbench/ks/integration/KieServerQueryDefinitionLoaderTest.java b/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/test/java/org/jbpm/workbench/ks/integration/KieServerQueryDefinitionLoaderTest.java index 58d296a172..2899eaba3f 100644 --- a/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/test/java/org/jbpm/workbench/ks/integration/KieServerQueryDefinitionLoaderTest.java +++ b/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/test/java/org/jbpm/workbench/ks/integration/KieServerQueryDefinitionLoaderTest.java @@ -75,7 +75,6 @@ public void testJbpmProcessInstances() { QueryDefinition expectedQuery = QueryDefinition.builder() .name("jbpmProcessInstances") .expression("SELECT LOG.PROCESSINSTANCEID, LOG.PROCESSID, LOG.START_DATE, LOG.END_DATE, LOG.STATUS, LOG.PARENTPROCESSINSTANCEID, LOG.OUTCOME, LOG.DURATION, LOG.USER_IDENTITY, LOG.PROCESSVERSION, LOG.PROCESSNAME, LOG.CORRELATIONKEY, LOG.EXTERNALID, LOG.PROCESSINSTANCEDESCRIPTION, LOG.SLA_DUE_DATE, LOG.SLACOMPLIANCE, COALESCE ( INFO.LASTMODIFICATIONDATE, LOG.END_DATE ) AS LASTMODIFICATIONDATE, COUNT( ERRINFO.ID ) ERRORCOUNT FROM ProcessInstanceLog LOG LEFT JOIN ExecutionErrorInfo ERRINFO ON ERRINFO.PROCESS_INST_ID=LOG.PROCESSINSTANCEID AND ERRINFO.ERROR_ACK=0 LEFT JOIN ProcessInstanceInfo INFO ON INFO.INSTANCEID=LOG.PROCESSINSTANCEID GROUP BY LOG.PROCESSINSTANCEID, LOG.PROCESSID, LOG.START_DATE, LOG.END_DATE, LOG.STATUS, LOG.PARENTPROCESSINSTANCEID, LOG.OUTCOME, LOG.DURATION, LOG.USER_IDENTITY, LOG.PROCESSVERSION, LOG.PROCESSNAME, LOG.CORRELATIONKEY, LOG.EXTERNALID, LOG.PROCESSINSTANCEDESCRIPTION, LOG.SLA_DUE_DATE, LOG.SLACOMPLIANCE, COALESCE ( INFO.LASTMODIFICATIONDATE, LOG.END_DATE )") - .target("CUSTOM") .build(); testQueryDefinitionLoaded(expectedQuery); } @@ -88,7 +87,6 @@ public void testJbpmProcessInstancesWithVariables() { "vil.variableId, vil.value from VariableInstanceLog vil " + "left join VariableInstanceLog vil2 on vil.processInstanceId = vil2.processInstanceId " + "and vil.variableId = vil2.variableId and vil.id < vil2.id where vil2.id is null") - .target("CUSTOM") .build(); testQueryDefinitionLoaded(expectedQuery); } @@ -100,7 +98,6 @@ public void testProcessesMonitoring() { .expression("select log.processInstanceId, log.processId, log.start_date, log.end_date, log.status, " + "log.duration, log.user_identity, log.processVersion, log.processName, " + "log.externalId from ProcessInstanceLog log") - .target("CUSTOM") .build(); testQueryDefinitionLoaded(expectedQuery); } @@ -114,7 +111,6 @@ public void testTasksMonitoring() { "from ProcessInstanceLog p inner join BAMTaskSummary t on " + "(t.processInstanceId = p.processInstanceId) inner join (select min(pk) as pk " + "from BAMTaskSummary group by taskId) d on t.pk = d.pk") - .target("CUSTOM") .build(); testQueryDefinitionLoaded(expectedQuery); } @@ -127,7 +123,6 @@ public void testJbpmRequestList() { "ri.retries, ri.executions, pil.processName, pil.processInstanceId, " + "pil.processInstanceDescription, ri.deploymentId from RequestInfo ri left join " + "ProcessInstanceLog pil on pil.processInstanceId=ri.processInstanceId") - .target("CUSTOM") .build(); testQueryDefinitionLoaded(expectedQuery); } @@ -140,7 +135,6 @@ public void testJbpmExecutionErrorList() { "eri.ACTIVITY_NAME, eri.DEPLOYMENT_ID, eri.ERROR_DATE, eri.ERROR_ID, " + "eri.ERROR_MSG, eri.JOB_ID, eri.PROCESS_ID, eri.PROCESS_INST_ID, eri.ERROR_TYPE " + "from ExecutionErrorInfo eri") - .target("CUSTOM") .build(); testQueryDefinitionLoaded(expectedQuery); } @@ -156,7 +150,6 @@ public void testJbpmHumanTasks() { "nil.sla_due_date, nil.slaCompliance from AuditTaskImpl t left join " + "ProcessInstanceLog pil on pil.processInstanceId=t.processInstanceId left join " + "NodeInstanceLog nil on nil.workItemId=t.workItemId") - .target("CUSTOM") .build(); testQueryDefinitionLoaded(expectedQuery); } @@ -174,7 +167,6 @@ public void testJbpmHumanTasksWithUser() { "OrganizationalEntity oe on po.entity_id=oe.id left join ProcessInstanceLog pil on " + "pil.processInstanceId=t.processInstanceId left join PeopleAssignments_ExclOwners eo " + "on t.taskId=eo.task_id left join NodeInstanceLog nil on nil.workItemId=t.workItemId") - .target("FILTERED_PO_TASK") .build(); testQueryDefinitionLoaded(expectedQuery); } @@ -193,7 +185,6 @@ public void testJbpmHumanTasksWithAdmin() { "left join ProcessInstanceLog pil on pil.processInstanceId = t.processInstanceId " + "left join PeopleAssignments_BAs ba on t.taskId = ba.task_id left join OrganizationalEntity oe " + "on ba.entity_id = oe.id left join NodeInstanceLog nil on nil.workItemId=t.workItemId") - .target("FILTERED_BA_TASK") .build(); testQueryDefinitionLoaded(expectedQuery); } @@ -215,7 +206,6 @@ public void testJbpmHumanTasksWithAdminExtended() { "left join PeopleAssignments_BAs ba on t.taskId = ba.task_id left join OrganizationalEntity oe " + "on ba.entity_id = oe.id left join NodeInstanceLog nil on nil.workItemId=t.workItemId " + "left join Task task on task.id = t.taskId left join I18NText i18n ON i18n.Task_Subjects_Id = t.taskId") - .target("FILTERED_BA_TASK") .build(); testQueryDefinitionLoaded(expectedQuery); } @@ -225,7 +215,6 @@ public void testJbpmHumanTasksWithVariables() { QueryDefinition expectedQuery = QueryDefinition.builder() .name("jbpmHumanTasksWithVariables") .expression("select tvi.taskId, tvi.name, tvi.value from TaskVariableImpl tvi") - .target("CUSTOM") .build(); testQueryDefinitionLoaded(expectedQuery); } @@ -238,7 +227,6 @@ public void testJbpmProcessInstanceLogs() { "log.processInstanceId, log.log_date, log.connection, log.type, log.workItemId, " + "log.referenceId, log.nodeContainerId, log.sla_due_date, log.slaCompliance " + "from NodeInstanceLog log ") - .target("CUSTOM") .build(); testQueryDefinitionLoaded(expectedQuery); } @@ -276,6 +264,5 @@ private void testQueryDefinitionLoaded(QueryDefinition expectedQueryDefinition) assertTrue("No named-queries were found", receivedEvents.size() > 0); assertNotNull("No query definition found for " + expectedQueryDefinition.getName(), receivedEvents.get(expectedQueryDefinition.getName())); assertEquals(expectedQueryDefinition.getExpression(), receivedEvents.get(expectedQueryDefinition.getName()).getExpression()); - assertEquals(expectedQueryDefinition.getTarget(), receivedEvents.get(expectedQueryDefinition.getName()).getTarget()); } }