Skip to content

Commit

Permalink
[incubator-kie-issues-1484] Create endpoints for user task
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian committed Oct 4, 2024
1 parent 6074289 commit ea13b2a
Show file tree
Hide file tree
Showing 77 changed files with 3,486 additions and 1,580 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface KogitoWorkItemHandlerFactory {

public static List<KogitoWorkItemHandler> findAllKogitoWorkItemHandlersRegistered() {
List<KogitoWorkItemHandler> handlers = new ArrayList<>();
ServiceLoader.load(KogitoWorkItemHandlerFactory.class).stream()
ServiceLoader.load(KogitoWorkItemHandlerFactory.class, Thread.currentThread().getContextClassLoader()).stream()
.map(ServiceLoader.Provider<KogitoWorkItemHandlerFactory>::get)
.map(KogitoWorkItemHandlerFactory::provide)
.flatMap(List::stream)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.kie.kogito.usertask.UserTaskEventListener;
import org.kie.kogito.usertask.UserTaskInstance;
import org.kie.kogito.usertask.lifecycle.UserTaskState;
import org.kie.kogito.usertask.model.Attachment;
import org.kie.kogito.usertask.model.Comment;

Expand All @@ -37,7 +38,7 @@ enum AssignmentType {

void fireOneUserTaskStateChange(
UserTaskInstance instance,
String oldPhaseStatus, String newPhaseStatus);
UserTaskState oldPhaseStatus, UserTaskState newPhaseStatus);

void fireOnUserTaskNotStartedDeadline(
UserTaskInstance instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public String getUpdatedBy() {
return updatedBy;
}

public void setId(K id) {
this.id = id;
}

public K getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ public interface UserTask {

Collection<DeadlineInfo<Reassignment>> getNotCompletedReassigments();

UserTaskAssignmentStrategy getAssignmentStrategy();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.kie.kogito.usertask;

import java.util.Optional;

import org.kie.kogito.auth.IdentityProvider;

public interface UserTaskAssignmentStrategy {

static final String DEFAULT_NAME = "default";

default String getName() {
return getClass().getName();
}

Optional<String> computeAssigment(UserTaskInstance userTaskInstance, IdentityProvider identityProvider);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.kie.kogito.usertask;

import java.util.List;

public interface UserTaskAssignmentStrategyConfig {

List<UserTaskAssignmentStrategy> userTaskAssignmentStrategies();

UserTaskAssignmentStrategy forName(String name);

default UserTaskAssignmentStrategy defaultUserTaskAssignmentStrategy() {
return forName(UserTaskAssignmentStrategy.DEFAULT_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface UserTaskConfig extends KogitoConfig {

UserTaskEventListenerConfig userTaskEventListeners();

UserTaskAssignmentStrategyConfig userTaskAssignmentStrategies();

UserTaskLifeCycle userTaskLifeCycle();

UnitOfWorkManager unitOfWorkManager();
Expand All @@ -36,4 +38,6 @@ public interface UserTaskConfig extends KogitoConfig {

IdentityProvider identityProvider();

UserTaskInstances userTaskInstances();

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.Map;
import java.util.Set;

import org.kie.kogito.auth.IdentityProvider;
import org.kie.kogito.usertask.lifecycle.UserTaskState;
import org.kie.kogito.usertask.lifecycle.UserTaskTransitionToken;
import org.kie.kogito.usertask.model.Attachment;
import org.kie.kogito.usertask.model.Comment;

Expand All @@ -35,19 +35,15 @@ public interface UserTaskInstance {

UserTaskState getStatus();

String getUserTaskId();

boolean hasActualOwner();

void setActuaOwner(String string);
void setActuaOwner(String actualOwner);

String getActualOwner();

UserTaskTransitionToken createTransitionToken(String transitionId, Map<String, Object> data);

void transition(UserTaskTransitionToken token);

void complete();

void abort();
void transition(String transitionId, Map<String, Object> data, IdentityProvider identityProvider);

String getExternalReferenceId();

Expand All @@ -59,6 +55,14 @@ public interface UserTaskInstance {

Map<String, Object> getMetadata();

Map<String, Object> getOutputs();

Map<String, Object> getInputs();

void setInput(String key, Object value);

void setOutput(String key, Object value);

/**
* Returns potential users that can work on this task
*
Expand Down Expand Up @@ -94,23 +98,24 @@ public interface UserTaskInstance {
*/
Set<String> getExcludedUsers();

void addAttachment(Attachment attachment);
Attachment findAttachmentById(String attachmentId);

void updateAttachment(Attachment newAttachment);
Attachment addAttachment(Attachment attachment);

void removeAttachment(Attachment oldAttachment);
Attachment updateAttachment(Attachment newAttachment);

void addComment(Comment comment);
Attachment removeAttachment(Attachment oldAttachment);

void updateComment(Comment newComment);
Collection<Attachment> getAttachments();

void removeComment(Comment comment);
Comment findCommentById(String commentId);

Collection<Comment> getComments();
Comment addComment(Comment comment);

Collection<Attachment> getAttachments();
Comment updateComment(Comment newComment);

Attachment findAttachmentById(String attachmentId);
Comment removeComment(Comment comment);

Collection<Comment> getComments();

Comment findCommentById(String commentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@
*/
package org.kie.kogito.usertask;

import java.util.List;
import java.util.Optional;
import java.util.function.Function;

import org.kie.kogito.auth.IdentityProvider;

public interface UserTaskInstances {

void setReconnectUserTaskInstance(Function<UserTaskInstance, UserTaskInstance> reconnectUserTaskInstance);

void setDisconnectUserTaskInstance(Function<UserTaskInstance, UserTaskInstance> disconnectUserTaskInstance);

List<UserTaskInstance> findByIdentity(IdentityProvider identityProvider);

Optional<UserTaskInstance> findById(String userTaskInstanceId);

boolean exists(String userTaskInstanceId);
Expand All @@ -33,8 +42,4 @@ public interface UserTaskInstances {

UserTaskInstance remove(String userTaskInstanceId);

void setReconnectUserTaskInstance(Function<UserTaskInstance, UserTaskInstance> reconnectUserTaskInstance);

void setDisconnectUserTaskInstance(Function<UserTaskInstance, UserTaskInstance> disconnectUserTaskInstance);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.kie.kogito.usertask;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.kie.kogito.auth.IdentityProvider;
import org.kie.kogito.usertask.model.Attachment;
import org.kie.kogito.usertask.model.Comment;
import org.kie.kogito.usertask.view.UserTaskTransitionView;
import org.kie.kogito.usertask.view.UserTaskView;

public interface UserTaskService {

Optional<UserTaskView> getUserTaskInstance(String taskId, IdentityProvider identity);

List<UserTaskView> list(IdentityProvider identity);

Optional<UserTaskView> transition(String taskId, String transitionId, Map<String, Object> data, IdentityProvider identity);

List<UserTaskTransitionView> allowedTransitions(String taskId, IdentityProvider identity);

Optional<UserTaskView> setOutputs(String taskId, Map<String, Object> data, IdentityProvider identity);

Optional<UserTaskView> setInputs(String taskId, Map<String, Object> data, IdentityProvider identity);

List<Comment> getComments(String taskId, IdentityProvider identity);

Optional<Comment> getComment(String taskId, String commentId, IdentityProvider identity);

Optional<Comment> addComment(String taskId, Comment comment, IdentityProvider identity);

Optional<Comment> updateComment(String taskId, Comment comment, IdentityProvider identity);

Optional<Comment> removeComment(String taskId, String commentId, IdentityProvider identity);

List<Attachment> getAttachments(String taskId, IdentityProvider identity);

Optional<Attachment> getAttachment(String taskId, String commentId, IdentityProvider identity);

Optional<Attachment> addAttachment(String taskId, Attachment comment, IdentityProvider identity);

Optional<Attachment> updateAttachment(String taskId, Attachment comment, IdentityProvider identity);

Optional<Attachment> removeAttachment(String taskId, String commentId, IdentityProvider identity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

public interface UserTasks extends KogitoEngine {

UserTaskInstances instances();

UserTask userTaskById(String userTaskId);

Collection<String> userTaskIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

package org.kie.kogito.usertask.events;

import org.kie.kogito.usertask.lifecycle.UserTaskState;

public interface UserTaskStateEvent extends UserTaskEvent {

String getNewStatus();
UserTaskState getNewStatus();

String getOldStatus();
UserTaskState getOldStatus();

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@

package org.kie.kogito.usertask.lifecycle;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.kie.kogito.auth.IdentityProvider;
import org.kie.kogito.usertask.UserTaskInstance;

public interface UserTaskLifeCycle {

Optional<UserTaskTransitionToken> transition(UserTaskInstance userTaskInstance, UserTaskTransitionToken transition);
Optional<UserTaskTransitionToken> transition(UserTaskInstance userTaskInstance, UserTaskTransitionToken transition, IdentityProvider identity);

UserTaskTransitionToken newTransitionToken(String transitionId, UserTaskInstance userTaskInstance, Map<String, Object> data);

UserTaskTransitionToken newCompleteTransitionToken(UserTaskInstance userTaskInstance, Map<String, Object> emptyMap);

UserTaskTransitionToken newAbortTransitionToken(UserTaskInstance userTaskInstance, Map<String, Object> emptyMap);

List<UserTaskTransition> allowedTransitions(UserTaskInstance ut);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.kie.kogito.usertask.lifecycle;

import java.util.Objects;
import java.util.Optional;

public class UserTaskState {

Expand Down Expand Up @@ -69,8 +68,8 @@ public String getName() {
return name;
}

public Optional<TerminationType> isTerminate() {
return Optional.ofNullable(terminate);
public boolean isTerminate() {
return terminate != null;
}

@Override
Expand All @@ -91,7 +90,7 @@ public boolean equals(Object obj) {
}

public static UserTaskState initalized() {
return of(null);
return of("Created");
}

@Override
Expand Down
Loading

0 comments on commit ea13b2a

Please sign in to comment.