forked from apache/incubator-kie-kogito-runtimes
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from rgdoliveira/sync_main
Sync main branch with Apache main branch (OSL 1.35 cut-off)
- Loading branch information
Showing
299 changed files
with
13,949 additions
and
1,711 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.kie</groupId> | ||
<artifactId>kogito-addons-common-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>org.jbpm</groupId> | ||
<artifactId>jbpm-addons-usertask-storage-jpa</artifactId> | ||
|
||
<name>jBPM :: Add-Ons :: User Task Storage JPA :: Common </name> | ||
<description>jBPM Add-Ons User Task Storage JPA Common</description> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.module.name>org.jbpm.usertask.storage.jpa</java.module.name> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>jakarta.persistence</groupId> | ||
<artifactId>jakarta.persistence-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>kogito-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>jbpm-usertask</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
129 changes: 129 additions & 0 deletions
129
...n/jbpm-usertask-storage-jpa/src/main/java/org/jbpm/usertask/jpa/JPAUserTaskInstances.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* 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.jbpm.usertask.jpa; | ||
|
||
import java.util.*; | ||
import java.util.function.Function; | ||
|
||
import org.jbpm.usertask.jpa.mapper.UserTaskInstanceEntityMapper; | ||
import org.jbpm.usertask.jpa.model.UserTaskInstanceEntity; | ||
import org.jbpm.usertask.jpa.repository.UserTaskInstanceRepository; | ||
import org.kie.kogito.auth.IdentityProvider; | ||
import org.kie.kogito.usertask.UserTaskInstance; | ||
import org.kie.kogito.usertask.UserTaskInstances; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class JPAUserTaskInstances implements UserTaskInstances { | ||
public static final Logger LOGGER = LoggerFactory.getLogger(JPAUserTaskInstances.class); | ||
|
||
private final UserTaskInstanceRepository userTaskInstanceRepository; | ||
private final UserTaskInstanceEntityMapper userTaskInstanceEntityMapper; | ||
|
||
private Function<UserTaskInstance, UserTaskInstance> reconnectUserTaskInstance; | ||
private Function<UserTaskInstance, UserTaskInstance> disconnectUserTaskInstance; | ||
|
||
public JPAUserTaskInstances(UserTaskInstanceRepository userTaskInstanceRepository, UserTaskInstanceEntityMapper userTaskInstanceEntityMapper) { | ||
this.userTaskInstanceRepository = userTaskInstanceRepository; | ||
this.userTaskInstanceEntityMapper = userTaskInstanceEntityMapper; | ||
} | ||
|
||
@Override | ||
public Optional<UserTaskInstance> findById(String userTaskInstanceId) { | ||
return this.userTaskInstanceRepository.findById(userTaskInstanceId) | ||
.map(userTaskInstanceEntityMapper::mapTaskEntityToInstance) | ||
.map(reconnectUserTaskInstance); | ||
} | ||
|
||
@Override | ||
public List<UserTaskInstance> findByIdentity(IdentityProvider identityProvider) { | ||
return userTaskInstanceRepository.findByIdentity(identityProvider) | ||
.stream() | ||
.map(userTaskInstanceEntityMapper::mapTaskEntityToInstance) | ||
.map(reconnectUserTaskInstance) | ||
.toList(); | ||
} | ||
|
||
@Override | ||
public boolean exists(String userTaskInstanceId) { | ||
return userTaskInstanceRepository.findById(userTaskInstanceId).isPresent(); | ||
} | ||
|
||
@Override | ||
public UserTaskInstance create(UserTaskInstance userTaskInstance) { | ||
Optional<UserTaskInstanceEntity> optional = userTaskInstanceRepository.findById(userTaskInstance.getId()); | ||
|
||
if (optional.isPresent()) { | ||
LOGGER.error("Cannot create userTaskInstance with id {}. Task Already exists.", userTaskInstance.getId()); | ||
throw new IllegalArgumentException("Cannot create userTaskInstance with id " + userTaskInstance.getId() + ". Task Already exists."); | ||
} | ||
|
||
UserTaskInstanceEntity entity = new UserTaskInstanceEntity(); | ||
entity.setId(userTaskInstance.getId()); | ||
|
||
this.userTaskInstanceRepository.persist(entity); | ||
|
||
userTaskInstanceEntityMapper.mapTaskInstanceToEntity(userTaskInstance, entity); | ||
|
||
return this.reconnectUserTaskInstance.apply(userTaskInstance); | ||
} | ||
|
||
@Override | ||
public UserTaskInstance update(UserTaskInstance userTaskInstance) { | ||
|
||
Optional<UserTaskInstanceEntity> optional = userTaskInstanceRepository.findById(userTaskInstance.getId()); | ||
|
||
if (optional.isEmpty()) { | ||
LOGGER.error("Could not find userTaskInstance with id {}", userTaskInstance.getId()); | ||
throw new RuntimeException("Could not find userTaskInstance with id " + userTaskInstance.getId()); | ||
} | ||
|
||
UserTaskInstanceEntity userTaskInstanceEntity = optional.get(); | ||
|
||
userTaskInstanceEntityMapper.mapTaskInstanceToEntity(userTaskInstance, userTaskInstanceEntity); | ||
|
||
userTaskInstanceRepository.update(userTaskInstanceEntity); | ||
|
||
return userTaskInstance; | ||
} | ||
|
||
@Override | ||
public UserTaskInstance remove(UserTaskInstance userTaskInstance) { | ||
Optional<UserTaskInstanceEntity> optional = userTaskInstanceRepository.findById(userTaskInstance.getId()); | ||
|
||
if (optional.isEmpty()) { | ||
LOGGER.warn("Could not remove userTaskInstance with id {}, task cannot be found", userTaskInstance.getId()); | ||
throw new RuntimeException("Could not remove userTaskInstance with id " + userTaskInstance.getId() + ", userTaskInstance cannot be found"); | ||
} | ||
|
||
this.userTaskInstanceRepository.remove(optional.get()); | ||
return this.disconnectUserTaskInstance.apply(userTaskInstance); | ||
} | ||
|
||
@Override | ||
public void setReconnectUserTaskInstance(Function<UserTaskInstance, UserTaskInstance> reconnectUserTaskInstance) { | ||
this.reconnectUserTaskInstance = reconnectUserTaskInstance; | ||
} | ||
|
||
@Override | ||
public void setDisconnectUserTaskInstance(Function<UserTaskInstance, UserTaskInstance> disconnectUserTaskInstance) { | ||
this.disconnectUserTaskInstance = disconnectUserTaskInstance; | ||
} | ||
} |
Oops, something went wrong.