View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.fit.core.reference;
20  
21  import java.util.Date;
22  import java.util.concurrent.atomic.AtomicInteger;
23  import javax.sql.DataSource;
24  import org.apache.syncope.core.persistence.api.dao.UserDAO;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  import org.springframework.jdbc.core.JdbcTemplate;
28  import org.springframework.transaction.annotation.Transactional;
29  
30  public class EnableFlowableForTestUsers {
31  
32      private static final Logger LOG = LoggerFactory.getLogger(EnableFlowableForTestUsers.class);
33  
34      private final UserDAO userDAO;
35  
36      public EnableFlowableForTestUsers(final UserDAO userDAO) {
37          this.userDAO = userDAO;
38      }
39  
40      @Transactional
41      public void init(final DataSource datasource) {
42          LOG.debug("Enabling Flowable processing for test users");
43  
44          JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
45          String procDef = jdbcTemplate.queryForObject(
46                  "SELECT ID_ FROM ACT_RE_PROCDEF WHERE KEY_=?", String.class, "userWorkflow");
47          LOG.debug("User workflow ID_ found: {}", procDef);
48  
49          AtomicInteger counter = new AtomicInteger(0);
50          userDAO.findAll(0, 1000).forEach(user -> {
51              int value = counter.addAndGet(1);
52              jdbcTemplate.update("INSERT INTO "
53                      + "ACT_RU_EXECUTION(ID_,REV_,PROC_INST_ID_,BUSINESS_KEY_,PROC_DEF_ID_,ACT_ID_,"
54                      + "IS_ACTIVE_,IS_CONCURRENT_,IS_SCOPE_,IS_EVENT_SCOPE_,SUSPENSION_STATE_) "
55                      + "VALUES(?,?,?,?,?,?,?,?,?,?,?)",
56                      value, 2, value, "userWorkflow:" + user.getKey(), procDef, "active",
57                      true, false, true, false, true);
58  
59              value = counter.addAndGet(1);
60              jdbcTemplate.update("INSERT INTO "
61                      + "ACT_RU_TASK(ID_,REV_,EXECUTION_ID_,PROC_INST_ID_,PROC_DEF_ID_,NAME_,TASK_DEF_KEY_,PRIORITY_,"
62                      + "CREATE_TIME_) "
63                      + "VALUES(?,?,?,?,?,?,?,?,?)",
64                      value, 2, value - 1, value - 1, procDef, "Active", "active", 50, new Date());
65          });
66      }
67  }