Skip to content

Commit

Permalink
Merge pull request #16667 from camunda/16663-client-user-task-assign
Browse files Browse the repository at this point in the history
Support `Assign task` user task action
  • Loading branch information
ana-vinogradova-camunda committed Mar 1, 2024
2 parents 1e0319c + 01d8233 commit ced94e0
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 0 deletions.
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;
}
}

0 comments on commit ced94e0

Please sign in to comment.