You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2019/03/25 16:11:04 UTC

[syncope] branch 2_1_X updated: More robust user init for Flowable

This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/2_1_X by this push:
     new ea5321d  More robust user init for Flowable
ea5321d is described below

commit ea5321da284e618eeb60d836def960e4b6cc7d74
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Mon Mar 25 17:10:49 2019 +0100

    More robust user init for Flowable
---
 archetype/pom.xml                                  |  7 +++
 fit/core-reference/pom.xml                         | 33 -----------
 .../logic/init/EnableFlowableForTestUsers.java     | 67 ++++++++++++++++++++++
 .../fit/core/reference/ITImplementationLookup.java | 25 ++++++--
 standalone/pom.xml                                 | 41 +++----------
 5 files changed, 103 insertions(+), 70 deletions(-)

diff --git a/archetype/pom.xml b/archetype/pom.xml
index fda5369..3f56550 100644
--- a/archetype/pom.xml
+++ b/archetype/pom.xml
@@ -183,6 +183,13 @@ under the License.
         </includes>
       </resource>      
       <resource>
+        <directory>../fit/core-reference/src/test/resources</directory>
+        <targetPath>${project.build.outputDirectory}/archetype-resources/core/src/test/resources</targetPath>
+        <includes>
+          <include>mail.properties</include>
+        </includes>
+      </resource>
+      <resource>
         <directory>../fit/core-reference/src/test/resources/scriptedsql</directory>
         <targetPath>${project.build.outputDirectory}/archetype-resources/core/src/test/resources/scriptedsql</targetPath>
       </resource>
diff --git a/fit/core-reference/pom.xml b/fit/core-reference/pom.xml
index 17f86e0..b9aa1bd 100644
--- a/fit/core-reference/pom.xml
+++ b/fit/core-reference/pom.xml
@@ -1708,39 +1708,6 @@ under the License.
                 </configuration>
               </execution>
             </executions>
-          </plugin>
-
-          <!-- Adds Flowable test content -->
-          <plugin>
-            <groupId>org.codehaus.mojo</groupId>
-            <artifactId>xml-maven-plugin</artifactId>
-            <inherited>true</inherited>
-            <executions>
-              <execution>
-                <phase>prepare-package</phase>
-                <goals>
-                  <goal>transform</goal>
-                </goals>
-              </execution>
-            </executions>
-            <configuration>
-              <transformationSets>
-                <transformationSet>
-                  <dir>${project.build.directory}/classes</dir>
-                  <includes>
-                    <include>domains/MasterContent.xml</include>
-                  </includes>
-                  <outputDir>${project.build.directory}/classes</outputDir>
-                  <stylesheet>${basedir}/src/test/resources/addFlowableToContent.xsl</stylesheet>
-                  <outputProperties>
-                    <outputProperty>
-                      <name>indent</name>
-                      <value>yes</value>
-                    </outputProperty>
-                  </outputProperties>
-                </transformationSet>
-              </transformationSets>
-            </configuration>
           </plugin>                    
         </plugins>
         
diff --git a/fit/core-reference/src/main/java/org/apache/syncope/core/logic/init/EnableFlowableForTestUsers.java b/fit/core-reference/src/main/java/org/apache/syncope/core/logic/init/EnableFlowableForTestUsers.java
new file mode 100644
index 0000000..7014292
--- /dev/null
+++ b/fit/core-reference/src/main/java/org/apache/syncope/core/logic/init/EnableFlowableForTestUsers.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.syncope.core.logic.init;
+
+import java.util.Date;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.sql.DataSource;
+import org.apache.syncope.core.persistence.api.dao.UserDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+@Component
+public class EnableFlowableForTestUsers {
+
+    private static final Logger LOG = LoggerFactory.getLogger(EnableFlowableForTestUsers.class);
+
+    @Autowired
+    private UserDAO userDAO;
+
+    @Transactional
+    public void init(final DataSource datasource) {
+        LOG.debug("Enabling Flowable processing for test users");
+
+        JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
+        String procDef = jdbcTemplate.queryForObject(
+                "SELECT ID_ FROM ACT_RE_PROCDEF WHERE KEY_=?", String.class, "userWorkflow");
+        LOG.debug("User workflow ID_ found: {}", procDef);
+
+        AtomicInteger counter = new AtomicInteger(0);
+        userDAO.findAll(0, 1000).forEach(user -> {
+            int value = counter.addAndGet(1);
+            jdbcTemplate.update("INSERT INTO "
+                    + "ACT_RU_EXECUTION(ID_,REV_,PROC_INST_ID_,BUSINESS_KEY_,PROC_DEF_ID_,ACT_ID_,"
+                    + "IS_ACTIVE_,IS_CONCURRENT_,IS_SCOPE_,IS_EVENT_SCOPE_,SUSPENSION_STATE_) "
+                    + "VALUES(?,?,?,?,?,?,?,?,?,?,?)",
+                    value, 2, value, "userWorkflow:" + user.getKey(), procDef, "active",
+                    true, false, true, false, true);
+
+            value = counter.addAndGet(1);
+            jdbcTemplate.update("INSERT INTO "
+                    + "ACT_RU_TASK(ID_,REV_,EXECUTION_ID_,PROC_INST_ID_,PROC_DEF_ID_,NAME_,TASK_DEF_KEY_,PRIORITY_,"
+                    + "CREATE_TIME_) "
+                    + "VALUES(?,?,?,?,?,?,?,?,?)",
+                    value, 2, value - 1, value - 1, procDef, "Active", "active", 50, new Date());
+        });
+    }
+}
diff --git a/fit/core-reference/src/main/java/org/apache/syncope/fit/core/reference/ITImplementationLookup.java b/fit/core-reference/src/main/java/org/apache/syncope/fit/core/reference/ITImplementationLookup.java
index ce71a55..f1d8628 100644
--- a/fit/core-reference/src/main/java/org/apache/syncope/fit/core/reference/ITImplementationLookup.java
+++ b/fit/core-reference/src/main/java/org/apache/syncope/fit/core/reference/ITImplementationLookup.java
@@ -24,7 +24,6 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
-import javax.sql.DataSource;
 import org.apache.syncope.common.lib.policy.AccountRuleConf;
 import org.apache.syncope.common.lib.policy.DefaultAccountRuleConf;
 import org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf;
@@ -42,6 +41,7 @@ import org.apache.syncope.common.lib.report.StaticReportletConf;
 import org.apache.syncope.common.lib.report.UserReportletConf;
 import org.apache.syncope.common.lib.types.ImplementationType;
 import org.apache.syncope.core.logic.init.ElasticsearchInit;
+import org.apache.syncope.core.logic.init.EnableFlowableForTestUsers;
 import org.apache.syncope.core.provisioning.java.job.report.AuditReportlet;
 import org.apache.syncope.core.provisioning.java.job.report.GroupReportlet;
 import org.apache.syncope.core.provisioning.java.job.report.ReconciliationReportlet;
@@ -74,6 +74,7 @@ import org.apache.syncope.core.provisioning.java.pushpull.LDAPMembershipPullActi
 import org.apache.syncope.core.provisioning.java.pushpull.LDAPPasswordPullActions;
 import org.apache.syncope.core.spring.security.AuthContextUtils;
 import org.apache.syncope.core.spring.security.SyncopeJWTSSOProvider;
+import org.apache.syncope.core.workflow.api.UserWorkflowAdapter;
 import org.springframework.aop.support.AopUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -234,12 +235,18 @@ public class ITImplementationLookup implements ImplementationLookup {
     };
 
     @Autowired
+    private UserWorkflowAdapter uwf;
+
+    @Autowired
     private AnySearchDAO anySearchDAO;
 
     @Autowired
     private DomainsHolder domainsHolder;
 
     @Autowired
+    private EnableFlowableForTestUsers enableFlowableForTestUsers;
+
+    @Autowired
     private ElasticsearchInit elasticsearchInit;
 
     @Override
@@ -249,14 +256,24 @@ public class ITImplementationLookup implements ImplementationLookup {
 
     @Override
     public void load() {
+        // in case the Flowable extension is enabled, enable modifications for test users
+        if (AopUtils.getTargetClass(uwf).getName().contains("Flowable")) {
+            domainsHolder.getDomains().forEach((domain, datasource) -> {
+                AuthContextUtils.execWithAuthContext(domain, () -> {
+                    enableFlowableForTestUsers.init(datasource);
+                    return null;
+                });
+            });
+        }
+
         // in case the Elasticsearch extension is enabled, reinit a clean index for all available domains
         if (AopUtils.getTargetClass(anySearchDAO).getName().contains("Elasticsearch")) {
-            for (Map.Entry<String, DataSource> entry : domainsHolder.getDomains().entrySet()) {
-                AuthContextUtils.execWithAuthContext(entry.getKey(), () -> {
+            domainsHolder.getDomains().forEach((domain, datasource) -> {
+                AuthContextUtils.execWithAuthContext(domain, () -> {
                     elasticsearchInit.init();
                     return null;
                 });
-            }
+            });
         }
     }
 
diff --git a/standalone/pom.xml b/standalone/pom.xml
index 5ff800a..7642a0d 100644
--- a/standalone/pom.xml
+++ b/standalone/pom.xml
@@ -78,39 +78,6 @@ under the License.
   <build>
 
     <plugins>
-      <!-- Adds Flowable test content -->
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>xml-maven-plugin</artifactId>
-        <inherited>true</inherited>
-        <executions>
-          <execution>
-            <phase>prepare-package</phase>
-            <goals>
-              <goal>transform</goal>
-            </goals>
-          </execution>
-        </executions>
-        <configuration>
-          <transformationSets>
-            <transformationSet>
-              <dir>${project.build.directory}/classes/core</dir>
-              <includes>
-                <include>domains/MasterContent.xml</include>
-              </includes>
-              <outputDir>${project.build.directory}/classes/core</outputDir>
-              <stylesheet>${basedir}/../fit/core-reference/src/test/resources/addFlowableToContent.xsl</stylesheet>
-              <outputProperties>
-                <outputProperty>
-                  <name>indent</name>
-                  <value>yes</value>
-                </outputProperty>
-              </outputProperties>
-            </transformationSet>
-          </transformationSets>
-        </configuration>
-      </plugin>
-          
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-antrun-plugin</artifactId>
@@ -252,6 +219,14 @@ under the License.
         <filtering>true</filtering>
       </resource>
       <resource>
+        <directory>../fit/core-reference/src/test/resources</directory>
+        <includes>
+          <include>mail.properties</include>
+        </includes>
+        <targetPath>core</targetPath>
+        <filtering>true</filtering>
+      </resource>
+      <resource>
         <directory>../fit/core-reference/src/test/resources/scriptedsql</directory>
         <targetPath>core/scriptedsql</targetPath>
         <filtering>true</filtering>