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:30:52 UTC
[syncope] branch master 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 master
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/master by this push:
new b15ba0b More robust user init for Flowable
b15ba0b is described below
commit b15ba0b6d998ff4db5f918351d75c2dadcd80e2d
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 | 16 ++++++
standalone/pom.xml | 8 +++
5 files changed, 98 insertions(+), 33 deletions(-)
diff --git a/archetype/pom.xml b/archetype/pom.xml
index 252fd99..e4e0d17 100644
--- a/archetype/pom.xml
+++ b/archetype/pom.xml
@@ -185,6 +185,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 764f8ea..5a156c9 100644
--- a/fit/core-reference/pom.xml
+++ b/fit/core-reference/pom.xml
@@ -1451,39 +1451,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>process-resources</phase>
- <goals>
- <goal>transform</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <transformationSets>
- <transformationSet>
- <dir>${project.build.outputDirectory}</dir>
- <includes>
- <include>domains/MasterContent.xml</include>
- </includes>
- <outputDir>${project.build.outputDirectory}</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 2d333a7..5169eb8 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
@@ -42,6 +42,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;
@@ -73,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;
@@ -233,9 +235,15 @@ public class ITImplementationLookup implements ImplementationLookup {
};
@Autowired
+ private UserWorkflowAdapter uwf;
+
+ @Autowired
private AnySearchDAO anySearchDAO;
@Autowired(required = false)
+ private EnableFlowableForTestUsers enableFlowableForTestUsers;
+
+ @Autowired(required = false)
private ElasticsearchInit elasticsearchInit;
@Override
@@ -245,6 +253,14 @@ public class ITImplementationLookup implements ImplementationLookup {
@Override
public void load(final String domain, final DataSource datasource) {
+ // in case the Flowable extension is enabled, enable modifications for test users
+ if (enableFlowableForTestUsers != null && AopUtils.getTargetClass(uwf).getName().contains("Flowable")) {
+ AuthContextUtils.execWithAuthContext(domain, () -> {
+ enableFlowableForTestUsers.init(datasource);
+ return null;
+ });
+ }
+
// in case the Elasticsearch extension is enabled, reinit a clean index for all available domains
if (elasticsearchInit != null && AopUtils.getTargetClass(anySearchDAO).getName().contains("Elasticsearch")) {
AuthContextUtils.execWithAuthContext(domain, () -> {
diff --git a/standalone/pom.xml b/standalone/pom.xml
index a14f585..c0af803 100644
--- a/standalone/pom.xml
+++ b/standalone/pom.xml
@@ -278,6 +278,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>