Skip to content

Commit

Permalink
Support UUID value type in flowable-rest API (flowable#3856)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Vojtěchovský committed Apr 22, 2024
1 parent 7c1e23b commit 57733fe
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* 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.flowable.common.rest.variable;

import java.util.UUID;

import org.flowable.common.engine.api.FlowableIllegalArgumentException;

public class UUIDRestVariableConverter implements RestVariableConverter {

@Override
public String getRestTypeName() {
return "uuid";
}

@Override
public Class<?> getVariableType() {
return UUID.class;
}

@Override
public Object getVariableValue(EngineRestVariable result) {
if (result.getValue() != null) {
if (!(result.getValue() instanceof String)) {
throw new FlowableIllegalArgumentException("Converter can only convert Strings");
}
return UUID.fromString((String) result.getValue());
}
return null;
}

@Override
public void convertVariableValue(Object variableValue, EngineRestVariable result) {
if (variableValue != null) {
if (!(variableValue instanceof UUID)) {
throw new FlowableIllegalArgumentException("Converter can only convert UUIDs");
}
result.setValue(((UUID)variableValue).toString());
} else {
result.setValue(null);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* 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.
Expand Down Expand Up @@ -38,6 +38,7 @@
import org.flowable.common.rest.variable.RestVariableConverter;
import org.flowable.common.rest.variable.ShortRestVariableConverter;
import org.flowable.common.rest.variable.StringRestVariableConverter;
import org.flowable.common.rest.variable.UUIDRestVariableConverter;
import org.flowable.dmn.api.DmnDecision;
import org.flowable.engine.form.FormData;
import org.flowable.engine.form.FormProperty;
Expand Down Expand Up @@ -116,11 +117,11 @@

/**
* Default implementation of a {@link RestResponseFactory}.
*
*
* Added a new "createProcessInstanceResponse" method (with a different signature) to conditionally return the process variables that exist within the process instance when the first wait state is
* encountered (or when the process instance completes). Also added the population of a "completed" flag - within both the original "createProcessInstanceResponse" method and the new one with the
* different signature - to let the caller know whether the process instance has completed or not.
*
*
* @author Frederik Heremans
* @author Ryan Johnston (@rjfsu)
*/
Expand Down Expand Up @@ -276,7 +277,7 @@ public ProcessDefinitionResponse createProcessDefinitionResponse(ProcessDefiniti
}
return response;
}

public String getFormModelString(FormModelResponse formModelResponse) {
try {
return objectMapper.writeValueAsString(formModelResponse);
Expand Down Expand Up @@ -684,7 +685,7 @@ public ExecutionResponse createExecutionResponse(Execution execution, RestUrlBui
}
return result;
}

public List<ActivityInstanceResponse> createActivityInstanceResponseList(List<ActivityInstance> activityInstances) {
RestUrlBuilder urlBuilder = createUrlBuilder();
List<ActivityInstanceResponse> responseList = new ArrayList<>(activityInstances.size());
Expand Down Expand Up @@ -718,7 +719,7 @@ public ActivityInstanceResponse createActivityInstanceResponse(ActivityInstance
result.setTenantId(activityInstance.getTenantId());
return result;
}

public List<VariableInstanceResponse> createVariableInstanceResponseList(List<VariableInstance> variableInstances) {
RestUrlBuilder urlBuilder = createUrlBuilder();
List<VariableInstanceResponse> responseList = new ArrayList<>(variableInstances.size());
Expand Down Expand Up @@ -1219,7 +1220,7 @@ public HistoryJobResponse createHistoryJobResponse(HistoryJob job, RestUrlBuilde

return response;
}

public List<BatchResponse> createBatchResponse(List<Batch> batches) {
RestUrlBuilder urlBuilder = createUrlBuilder();
List<BatchResponse> responseList = new ArrayList<>(batches.size());
Expand Down Expand Up @@ -1248,7 +1249,7 @@ public BatchResponse createBatchResponse(Batch batch, RestUrlBuilder urlBuilder)

return response;
}

public List<BatchPartResponse> createBatchPartResponse(List<BatchPart> batchParts) {
RestUrlBuilder urlBuilder = createUrlBuilder();
List<BatchPartResponse> responseList = new ArrayList<>(batchParts.size());
Expand Down Expand Up @@ -1356,7 +1357,7 @@ public UserResponse createUserResponse(User user, boolean incudePassword, RestUr
response.setEmail(user.getEmail());
response.setUrl(urlBuilder.buildUrl(RestUrls.URL_USER, user.getId()));
response.setTenantId(user.getTenantId());

if (incudePassword) {
response.setPassword(user.getPassword());
}
Expand Down Expand Up @@ -1528,6 +1529,7 @@ protected void initializeVariableConverters() {
variableConverters.add(new LocalDateRestVariableConverter());
variableConverters.add(new LocalDateTimeRestVariableConverter());
variableConverters.add(new JsonObjectRestVariableConverter(objectMapper));
variableConverters.add(new UUIDRestVariableConverter());
}

protected String formatUrl(String serverRootUrl, String[] fragments, Object... arguments) {
Expand Down

0 comments on commit 57733fe

Please sign in to comment.