Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync main branch with Apache main branch (OSL 1.35 cut-off) #69

Merged
merged 16 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .mvn/maven.config

This file was deleted.

117 changes: 0 additions & 117 deletions .mvn/wrapper/MavenWrapperDownloader.java

This file was deleted.

Binary file removed .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
73 changes: 73 additions & 0 deletions addons/common/jbpm-usertask-storage-jpa/pom.xml
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>
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;
}
}
Loading
Loading