org.acme.travels.ApprovalsResource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of process-usertasks-custom-lifecycle-springboot
Show all versions of process-usertasks-custom-lifecycle-springboot
Kogito usertasks orchestration with custom life cycle - Spring Boot
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates.
*
* Licensed 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.acme.travels;
import java.net.URI;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.jsonschema.JsonSchema;
import org.jbpm.util.JsonSchemaUtil;
import org.kie.kogito.Application;
import org.kie.kogito.process.Process;
import org.kie.kogito.process.ProcessInstance;
import org.kie.kogito.process.ProcessInstanceReadMode;
import org.kie.kogito.process.impl.Sig;
import org.kie.kogito.process.ProcessInstanceExecutionException;
import org.kie.kogito.process.WorkItem;
import org.kie.kogito.process.workitem.Attachment;
import org.kie.kogito.process.workitem.AttachmentInfo;
import org.kie.kogito.process.workitem.Comment;
import org.kie.kogito.process.workitem.Policies;
import org.kie.kogito.services.uow.UnitOfWorkExecutor;
import org.jbpm.process.instance.impl.humantask.HumanTaskHelper;
import org.jbpm.process.instance.impl.humantask.HumanTaskTransition;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import org.acme.travels.ApprovalsModelOutput;
@RestController
@RequestMapping("/approvals")
@org.springframework.stereotype.Component()
public class ApprovalsResource {
@org.springframework.beans.factory.annotation.Autowired()
@org.springframework.beans.factory.annotation.Qualifier("approvals")
Process process;
@org.springframework.beans.factory.annotation.Autowired()
Application application;
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity createResource_approvals(@RequestHeader HttpHeaders httpHeaders, @RequestParam(value = "businessKey", required = false) String businessKey, @RequestBody(required = false) @javax.validation.Valid() @javax.validation.constraints.NotNull() ApprovalsModelInput resource, UriComponentsBuilder uriComponentsBuilder) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
ApprovalsModelInput inputModel = resource != null ? resource : new ApprovalsModelInput();
ProcessInstance pi = process.createInstance(businessKey, inputModel.toModel());
List startFromNode = httpHeaders.get("X-KOGITO-StartFromNode");
if (startFromNode != null && !startFromNode.isEmpty()) {
pi.startFrom(startFromNode.get(0));
} else {
pi.start();
}
UriComponents uriComponents = uriComponentsBuilder.path("/approvals/{id}").buildAndExpand(pi.id());
URI location = uriComponents.toUri();
return ResponseEntity.created(location).body(pi.checkError().variables().toOutput());
});
}
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public List getResources_approvals() {
return process.instances().values().stream().map(pi -> pi.variables().toOutput()).collect(Collectors.toList());
}
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getResource_approvals(@PathVariable("id") String id) {
return process.instances().findById(id, ProcessInstanceReadMode.READ_ONLY).map(m -> ResponseEntity.ok(m.variables().toOutput())).orElseGet(() -> ResponseEntity.notFound().build());
}
@DeleteMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity deleteResource_approvals(@PathVariable("id") final String id) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
pi.abort();
return pi.checkError().variables().toOutput();
}).map(m -> ResponseEntity.ok(m))).orElseGet(() -> ResponseEntity.notFound().build());
}
@PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity updateModel_approvals(@PathVariable("id") String id, @RequestBody(required = false) ApprovalsModel resource) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> pi.updateVariables(resource).toOutput()).map(m -> ResponseEntity.ok(m))).orElseGet(() -> ResponseEntity.notFound().build());
}
@GetMapping(value = "/{id}/tasks", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity> getTasks_approvals(@PathVariable("id") String id, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
return process.instances().findById(id, ProcessInstanceReadMode.READ_ONLY).map(pi -> pi.workItems(Policies.of(user, groups))).map(m -> ResponseEntity.ok(m)).orElseGet(() -> ResponseEntity.notFound().build());
}
@PostMapping(value = "/{id}/firstLineApproval/{taskId}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity taskTransition_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "phase", required = false, defaultValue = "complete") final String phase, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups, @RequestBody(required = false) final Approvals_1_TaskOutput model) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
pi.transitionWorkItem(taskId, HumanTaskTransition.withModel(phase, model, Policies.of(user, groups)));
return ResponseEntity.ok(pi.checkError().variables().toOutput());
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
@PutMapping(value = "/{id}/firstLineApproval/{taskId}", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity saveTask_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups, @RequestBody(required = false) final Approvals_1_TaskOutput model) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> ResponseEntity.ok(Approvals_1_TaskOutput.fromMap(pi.updateWorkItem(taskId, wi -> HumanTaskHelper.updateContent(wi, model), Policies.of(user, groups))))).orElseGet(() -> ResponseEntity.notFound().build()));
}
@PostMapping(value = "/{id}/firstLineApproval/{taskId}/phases/{phase}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity completeTask_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("phase") final String phase, @RequestParam("user") final String user, @RequestParam("group") final List groups, @RequestBody(required = false) final Approvals_1_TaskOutput model) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
pi.transitionWorkItem(taskId, HumanTaskTransition.withModel(phase, model, Policies.of(user, groups)));
return ResponseEntity.ok(pi.checkError().variables().toOutput());
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
@PostMapping(value = "/{id}/firstLineApproval/{taskId}/comments", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity addComment_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups, @RequestBody String commentInfo, UriComponentsBuilder uriComponentsBuilder) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
Comment comment = pi.updateWorkItem(taskId, wi -> HumanTaskHelper.addComment(wi, commentInfo, user), Policies.of(user, groups));
return ResponseEntity.created(uriComponentsBuilder.path("/approvals/{id}/firstLineApproval/{taskId}/comments/{commentId}").buildAndExpand(id, taskId, comment.getId()).toUri()).body(comment);
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
@PutMapping(value = "/{id}/firstLineApproval/{taskId}/comments/{commentId}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity updateComment_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("commentId") final String commentId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups, @RequestBody String comment) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> ResponseEntity.ok(pi.updateWorkItem(taskId, wi -> HumanTaskHelper.updateComment(wi, commentId, comment, user), Policies.of(user, groups)))).orElseGet(() -> ResponseEntity.notFound().build()));
}
@DeleteMapping(value = "/{id}/firstLineApproval/{taskId}/comments/{commentId}")
public ResponseEntity deleteComment_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("commentId") final String commentId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
boolean removed = pi.updateWorkItem(taskId, wi -> HumanTaskHelper.deleteComment(wi, commentId, user), Policies.of(user, groups));
return removed ? ResponseEntity.ok().build() : ResponseEntity.notFound().build();
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
@PostMapping(value = "/{id}/firstLineApproval/{taskId}/attachments", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity addAttachment_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups, @RequestBody AttachmentInfo attachmentInfo, UriComponentsBuilder uriComponentsBuilder) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
Attachment attachment = pi.updateWorkItem(taskId, wi -> HumanTaskHelper.addAttachment(wi, attachmentInfo, user), Policies.of(user, groups));
return ResponseEntity.created(uriComponentsBuilder.path("/approvals/{id}/firstLineApproval/{taskId}/attachments/{attachmentId}").buildAndExpand(id, taskId, attachment.getId()).toUri()).body(attachment);
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
@PutMapping(value = "/{id}/firstLineApproval/{taskId}/attachments/{attachmentId}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity updateAttachment_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("attachmentId") final String attachmentId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups, @RequestBody AttachmentInfo attachment) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> ResponseEntity.ok(pi.updateWorkItem(taskId, wi -> HumanTaskHelper.updateAttachment(wi, attachmentId, attachment, user), Policies.of(user, groups)))).orElseGet(() -> ResponseEntity.notFound().build()));
}
@DeleteMapping(value = "/{id}/firstLineApproval/{taskId}/attachments/{attachmentId}")
public ResponseEntity deleteAttachment_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("attachmentId") final String attachmentId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
boolean removed = pi.updateWorkItem(taskId, wi -> HumanTaskHelper.deleteAttachment(wi, attachmentId, user), Policies.of(user, groups));
return (removed ? ResponseEntity.ok() : ResponseEntity.notFound()).build();
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
@GetMapping(value = "/{id}/firstLineApproval/{taskId}/attachments/{attachmentId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getAttachment_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("attachmentId") final String attachmentId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
Optional> pi = process.instances().findById(id);
if (pi.isPresent()) {
Attachment attachment = HumanTaskHelper.findTask(pi.get(), taskId, Policies.of(user, groups)).getAttachments().get(attachmentId);
if (attachment != null) {
return ResponseEntity.ok(attachment);
}
}
return ResponseEntity.notFound().build();
}
@GetMapping(value = "/{id}/firstLineApproval/{taskId}/attachments", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity> getAttachments_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "user") final String user, @RequestParam(value = "group") final List groups) {
Optional> pi = process.instances().findById(id);
return pi.isPresent() ? ResponseEntity.ok(HumanTaskHelper.findTask(pi.get(), taskId, Policies.of(user, groups)).getAttachments().values()) : ResponseEntity.notFound().build();
}
@GetMapping(value = "/{id}/firstLineApproval/{taskId}/comments/{commentId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getComment_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("commentId") final String commentId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
Optional> pi = process.instances().findById(id);
if (pi.isPresent()) {
Comment comment = HumanTaskHelper.findTask(pi.get(), taskId, Policies.of(user, groups)).getComments().get(commentId);
if (comment != null) {
return ResponseEntity.ok(comment);
}
}
return ResponseEntity.notFound().build();
}
@GetMapping(value = "/{id}/firstLineApproval/{taskId}/comments", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity> getComments_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
Optional> pi = process.instances().findById(id);
return pi.isPresent() ? ResponseEntity.ok(HumanTaskHelper.findTask(pi.get(), taskId, Policies.of(user, groups)).getComments().values()) : ResponseEntity.notFound().build();
}
@GetMapping(value = "/{id}/firstLineApproval/{taskId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getTask_firstLineApproval_0(@PathVariable("id") String id, @PathVariable("taskId") String taskId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
return process.instances().findById(id).map(pi -> Approvals_1_TaskInput.from(pi.workItem(taskId, Policies.of(user, groups)))).map(m -> ResponseEntity.ok(m)).orElseGet(() -> ResponseEntity.notFound().build());
}
@GetMapping(value = "firstLineApproval/schema", produces = MediaType.APPLICATION_JSON_VALUE)
public Map getSchema_firstLineApproval_0() {
return JsonSchemaUtil.load(this.getClass().getClassLoader(), process.id(), "firstLineApproval");
}
@GetMapping(value = "/{id}/firstLineApproval/{taskId}/schema", produces = MediaType.APPLICATION_JSON_VALUE)
public Map getSchemaAndPhases_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
return JsonSchemaUtil.addPhases(process, application, id, taskId, Policies.of(user, groups), JsonSchemaUtil.load(this.getClass().getClassLoader(), process.id(), "firstLineApproval"));
}
@DeleteMapping(value = "/{id}/firstLineApproval/{taskId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity abortTask_firstLineApproval_0(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "phase", required = false, defaultValue = "abort") final String phase, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
pi.transitionWorkItem(taskId, HumanTaskTransition.withoutModel(phase, Policies.of(user, groups)));
return ResponseEntity.ok(pi.checkError().variables().toOutput());
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
@PostMapping(value = "/{id}/secondLineApproval/{taskId}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity taskTransition_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "phase", required = false, defaultValue = "complete") final String phase, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups, @RequestBody(required = false) final Approvals_2_TaskOutput model) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
pi.transitionWorkItem(taskId, HumanTaskTransition.withModel(phase, model, Policies.of(user, groups)));
return ResponseEntity.ok(pi.checkError().variables().toOutput());
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
@PutMapping(value = "/{id}/secondLineApproval/{taskId}", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity saveTask_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups, @RequestBody(required = false) final Approvals_2_TaskOutput model) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> ResponseEntity.ok(Approvals_2_TaskOutput.fromMap(pi.updateWorkItem(taskId, wi -> HumanTaskHelper.updateContent(wi, model), Policies.of(user, groups))))).orElseGet(() -> ResponseEntity.notFound().build()));
}
@PostMapping(value = "/{id}/secondLineApproval/{taskId}/phases/{phase}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity completeTask_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("phase") final String phase, @RequestParam("user") final String user, @RequestParam("group") final List groups, @RequestBody(required = false) final Approvals_2_TaskOutput model) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
pi.transitionWorkItem(taskId, HumanTaskTransition.withModel(phase, model, Policies.of(user, groups)));
return ResponseEntity.ok(pi.checkError().variables().toOutput());
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
@PostMapping(value = "/{id}/secondLineApproval/{taskId}/comments", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity addComment_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups, @RequestBody String commentInfo, UriComponentsBuilder uriComponentsBuilder) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
Comment comment = pi.updateWorkItem(taskId, wi -> HumanTaskHelper.addComment(wi, commentInfo, user), Policies.of(user, groups));
return ResponseEntity.created(uriComponentsBuilder.path("/approvals/{id}/secondLineApproval/{taskId}/comments/{commentId}").buildAndExpand(id, taskId, comment.getId()).toUri()).body(comment);
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
@PutMapping(value = "/{id}/secondLineApproval/{taskId}/comments/{commentId}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity updateComment_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("commentId") final String commentId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups, @RequestBody String comment) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> ResponseEntity.ok(pi.updateWorkItem(taskId, wi -> HumanTaskHelper.updateComment(wi, commentId, comment, user), Policies.of(user, groups)))).orElseGet(() -> ResponseEntity.notFound().build()));
}
@DeleteMapping(value = "/{id}/secondLineApproval/{taskId}/comments/{commentId}")
public ResponseEntity deleteComment_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("commentId") final String commentId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
boolean removed = pi.updateWorkItem(taskId, wi -> HumanTaskHelper.deleteComment(wi, commentId, user), Policies.of(user, groups));
return removed ? ResponseEntity.ok().build() : ResponseEntity.notFound().build();
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
@PostMapping(value = "/{id}/secondLineApproval/{taskId}/attachments", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity addAttachment_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups, @RequestBody AttachmentInfo attachmentInfo, UriComponentsBuilder uriComponentsBuilder) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
Attachment attachment = pi.updateWorkItem(taskId, wi -> HumanTaskHelper.addAttachment(wi, attachmentInfo, user), Policies.of(user, groups));
return ResponseEntity.created(uriComponentsBuilder.path("/approvals/{id}/secondLineApproval/{taskId}/attachments/{attachmentId}").buildAndExpand(id, taskId, attachment.getId()).toUri()).body(attachment);
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
@PutMapping(value = "/{id}/secondLineApproval/{taskId}/attachments/{attachmentId}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity updateAttachment_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("attachmentId") final String attachmentId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups, @RequestBody AttachmentInfo attachment) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> ResponseEntity.ok(pi.updateWorkItem(taskId, wi -> HumanTaskHelper.updateAttachment(wi, attachmentId, attachment, user), Policies.of(user, groups)))).orElseGet(() -> ResponseEntity.notFound().build()));
}
@DeleteMapping(value = "/{id}/secondLineApproval/{taskId}/attachments/{attachmentId}")
public ResponseEntity deleteAttachment_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("attachmentId") final String attachmentId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
boolean removed = pi.updateWorkItem(taskId, wi -> HumanTaskHelper.deleteAttachment(wi, attachmentId, user), Policies.of(user, groups));
return (removed ? ResponseEntity.ok() : ResponseEntity.notFound()).build();
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
@GetMapping(value = "/{id}/secondLineApproval/{taskId}/attachments/{attachmentId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getAttachment_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("attachmentId") final String attachmentId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
Optional> pi = process.instances().findById(id);
if (pi.isPresent()) {
Attachment attachment = HumanTaskHelper.findTask(pi.get(), taskId, Policies.of(user, groups)).getAttachments().get(attachmentId);
if (attachment != null) {
return ResponseEntity.ok(attachment);
}
}
return ResponseEntity.notFound().build();
}
@GetMapping(value = "/{id}/secondLineApproval/{taskId}/attachments", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity> getAttachments_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "user") final String user, @RequestParam(value = "group") final List groups) {
Optional> pi = process.instances().findById(id);
return pi.isPresent() ? ResponseEntity.ok(HumanTaskHelper.findTask(pi.get(), taskId, Policies.of(user, groups)).getAttachments().values()) : ResponseEntity.notFound().build();
}
@GetMapping(value = "/{id}/secondLineApproval/{taskId}/comments/{commentId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getComment_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @PathVariable("commentId") final String commentId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
Optional> pi = process.instances().findById(id);
if (pi.isPresent()) {
Comment comment = HumanTaskHelper.findTask(pi.get(), taskId, Policies.of(user, groups)).getComments().get(commentId);
if (comment != null) {
return ResponseEntity.ok(comment);
}
}
return ResponseEntity.notFound().build();
}
@GetMapping(value = "/{id}/secondLineApproval/{taskId}/comments", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity> getComments_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
Optional> pi = process.instances().findById(id);
return pi.isPresent() ? ResponseEntity.ok(HumanTaskHelper.findTask(pi.get(), taskId, Policies.of(user, groups)).getComments().values()) : ResponseEntity.notFound().build();
}
@GetMapping(value = "/{id}/secondLineApproval/{taskId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getTask_secondLineApproval_1(@PathVariable("id") String id, @PathVariable("taskId") String taskId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
return process.instances().findById(id).map(pi -> Approvals_2_TaskInput.from(pi.workItem(taskId, Policies.of(user, groups)))).map(m -> ResponseEntity.ok(m)).orElseGet(() -> ResponseEntity.notFound().build());
}
@GetMapping(value = "secondLineApproval/schema", produces = MediaType.APPLICATION_JSON_VALUE)
public Map getSchema_secondLineApproval_1() {
return JsonSchemaUtil.load(this.getClass().getClassLoader(), process.id(), "secondLineApproval");
}
@GetMapping(value = "/{id}/secondLineApproval/{taskId}/schema", produces = MediaType.APPLICATION_JSON_VALUE)
public Map getSchemaAndPhases_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
return JsonSchemaUtil.addPhases(process, application, id, taskId, Policies.of(user, groups), JsonSchemaUtil.load(this.getClass().getClassLoader(), process.id(), "secondLineApproval"));
}
@DeleteMapping(value = "/{id}/secondLineApproval/{taskId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity abortTask_secondLineApproval_1(@PathVariable("id") final String id, @PathVariable("taskId") final String taskId, @RequestParam(value = "phase", required = false, defaultValue = "abort") final String phase, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "group", required = false) final List groups) {
return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> process.instances().findById(id).map(pi -> {
pi.transitionWorkItem(taskId, HumanTaskTransition.withoutModel(phase, Policies.of(user, groups)));
return ResponseEntity.ok(pi.checkError().variables().toOutput());
}).orElseGet(() -> ResponseEntity.notFound().build()));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy