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

Support Assign task user task action #16667

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.camunda.zeebe.client;

import io.camunda.zeebe.client.api.ExperimentalApi;
import io.camunda.zeebe.client.api.command.AssignUserTaskCommandStep1;
import io.camunda.zeebe.client.api.command.BroadcastSignalCommandStep1;
import io.camunda.zeebe.client.api.command.CancelProcessInstanceCommandStep1;
import io.camunda.zeebe.client.api.command.CompleteUserTaskCommandStep1;
Expand Down Expand Up @@ -486,4 +487,30 @@ static ZeebeClientCloudBuilderStep1 newCloudClientBuilder() {
*/
@ExperimentalApi("https://github.com/camunda/zeebe/issues/16166")
CompleteUserTaskCommandStep1 newUserTaskCompleteCommand(long userTaskKey);

/**
* Command to assign a user task.
*
* <pre>
* long userTaskKey = ..;
*
* zeebeClient
* .newUserTaskAssignCommand(userTaskKey)
* .assignee(newAssignee)
* .send();
* </pre>
*
* <p>This command is only sent via REST over HTTP, not via gRPC <br>
* <br>
*
* <p><strong>Experimental: This method is under development, and as such using it may have no
* effect on the client builder when called. Until this warning is removed, anything described
* below may not yet have taken effect, and the interface and its description are subject to
* change.</strong>
*
* @param userTaskKey the key of the user tasks
* @return a builder for the command
*/
@ExperimentalApi("https://github.com/camunda/zeebe/issues/16166")
AssignUserTaskCommandStep1 newUserTaskAssignCommand(long userTaskKey);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright © 2017 camunda services GmbH (info@camunda.com)
*
* 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 io.camunda.zeebe.client.api.command;

import io.camunda.zeebe.client.api.response.AssignUserTaskResponse;

public interface AssignUserTaskCommandStep1 extends FinalCommandStep<AssignUserTaskResponse> {

/**
* Set the custom action to assign the user task with.
*
* @param action the action value
* @return the builder for this command. Call {@link #send()} to complete the command and send it
* to the broker.
*/
AssignUserTaskCommandStep1 action(String action);

/**
* Set the assignee to set for the user task.
*
* @param assignee the assignee to set
* @return the builder for this command. Call {@link #send()} to complete the command and send it
* to the broker.
*/
AssignUserTaskCommandStep1 assignee(String assignee);

/**
* Flag to allow overriding an existing assignee for the user task without unassigning it first.
*
* @param allowOverride allow overriding an existing assignee
* @return the builder for this command. Call {@link #send()} to complete the command and send it
* to the broker.
*/
AssignUserTaskCommandStep1 allowOverride(boolean allowOverride);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright © 2017 camunda services GmbH (info@camunda.com)
*
* 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 io.camunda.zeebe.client.api.response;

public interface AssignUserTaskResponse {}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.camunda.zeebe.client.ZeebeClientConfiguration;
import io.camunda.zeebe.client.api.JsonMapper;
import io.camunda.zeebe.client.api.command.ActivateJobsCommandStep1;
import io.camunda.zeebe.client.api.command.AssignUserTaskCommandStep1;
import io.camunda.zeebe.client.api.command.BroadcastSignalCommandStep1;
import io.camunda.zeebe.client.api.command.CancelProcessInstanceCommandStep1;
import io.camunda.zeebe.client.api.command.ClientException;
Expand All @@ -47,6 +48,7 @@
import io.camunda.zeebe.client.api.response.ActivatedJob;
import io.camunda.zeebe.client.api.worker.JobClient;
import io.camunda.zeebe.client.api.worker.JobWorkerBuilderStep1;
import io.camunda.zeebe.client.impl.command.AssignUserTaskCommandImpl;
import io.camunda.zeebe.client.impl.command.BroadcastSignalCommandImpl;
import io.camunda.zeebe.client.impl.command.CancelProcessInstanceCommandImpl;
import io.camunda.zeebe.client.impl.command.CompleteUserTaskCommandImpl;
Expand Down Expand Up @@ -451,6 +453,11 @@ public CompleteUserTaskCommandStep1 newUserTaskCompleteCommand(final long userTa
return new CompleteUserTaskCommandImpl(httpClient, jsonMapper, userTaskKey);
}

@Override
public AssignUserTaskCommandStep1 newUserTaskAssignCommand(final long userTaskKey) {
return new AssignUserTaskCommandImpl(httpClient, jsonMapper, userTaskKey);
}

private JobClient newJobClient() {
return new JobClientImpl(
asyncStub, config, jsonMapper, credentialsProvider::shouldRetryRequest);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright © 2017 camunda services GmbH (info@camunda.com)
*
* 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 io.camunda.zeebe.client.impl.command;

import io.camunda.zeebe.client.api.JsonMapper;
import io.camunda.zeebe.client.api.ZeebeFuture;
import io.camunda.zeebe.client.api.command.AssignUserTaskCommandStep1;
import io.camunda.zeebe.client.api.command.FinalCommandStep;
import io.camunda.zeebe.client.api.response.AssignUserTaskResponse;
import io.camunda.zeebe.client.impl.http.HttpClient;
import io.camunda.zeebe.client.impl.http.HttpZeebeFuture;
import io.camunda.zeebe.gateway.protocol.rest.UserTaskAssignmentRequest;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.apache.hc.client5.http.config.RequestConfig;

public final class AssignUserTaskCommandImpl implements AssignUserTaskCommandStep1 {

private final long userTaskKey;
private final UserTaskAssignmentRequest request;
private final JsonMapper jsonMapper;
private final HttpClient httpClient;
private final RequestConfig.Builder httpRequestConfig;

public AssignUserTaskCommandImpl(
final HttpClient httpClient, final JsonMapper jsonMapper, final long userTaskKey) {
this.jsonMapper = jsonMapper;
this.userTaskKey = userTaskKey;
this.httpClient = httpClient;
httpRequestConfig = httpClient.newRequestConfig();
request = new UserTaskAssignmentRequest();
}

@Override
public FinalCommandStep<AssignUserTaskResponse> requestTimeout(final Duration requestTimeout) {
httpRequestConfig.setResponseTimeout(requestTimeout.toMillis(), TimeUnit.MILLISECONDS);
return this;
}

@Override
public ZeebeFuture<AssignUserTaskResponse> send() {
final HttpZeebeFuture<AssignUserTaskResponse> result = new HttpZeebeFuture<>();
httpClient.post(
"/user-tasks/" + userTaskKey + "/assignment",
jsonMapper.toJson(request),
httpRequestConfig.build(),
result);
return result;
}

@Override
public AssignUserTaskCommandStep1 action(final String action) {
request.setAction(action);
return this;
}

@Override
public AssignUserTaskCommandStep1 assignee(final String assignee) {
ArgumentUtil.ensureNotNull("assignee", assignee);
request.setAssignee(assignee);
return this;
}

@Override
public AssignUserTaskCommandStep1 allowOverride(final boolean allowOverride) {
request.setAllowOverride(allowOverride);
return this;
}
}