Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

provide the ability to get optional and/or nullable param #443

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;

import static java.util.Objects.isNull;

/**
* Base Class for a WorkFlowTask.
* <p>
Expand Down Expand Up @@ -123,4 +125,20 @@ public String getOptionalParameterValue(String parameterName, String defaultValu
.map(Map.Entry::getValue).findFirst().orElse(defaultValue);
}

/**
* Gets non-null and non-empty optional parameter. Returns the defaultValue if not
* found
* @param parameterName parameter name
* @param defaultValue default value
* @param isNullable is nullable
* @return parameter value
* @throws MissingParameterException exception
*/
public String getOptionalParameterValue(String parameterName, String defaultValue, Boolean isNullable) {
Map<String, String> parameters = getAllParameters(workContext);
return parameters.entrySet().stream().filter(entry -> !isNullable && !isNull(entry.getValue()) && !entry.getValue().equalsIgnoreCase("null"))
.filter(entry -> parameterName.equals(entry.getKey()))
.map(Map.Entry::getValue).findFirst().orElse(defaultValue);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public WorkReport execute(WorkContext workContext) {
String role;
try {
username = getRequiredParameterValue(PARAMETER_USERNAME);
role = getOptionalParameterValue(PARAMETER_ROLE, PARAMETER_ROLE_DEFAULT);
role = getOptionalParameterValue(PARAMETER_ROLE, PARAMETER_ROLE_DEFAULT, false);
log.info("Project access request with the following - username: {}, role: {}", username, role);
}
catch (MissingParameterException e) {
Expand Down