You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2020/11/17 15:15:44 UTC
[syncope] branch 2_1_X updated: [SYNCOPE-1601] Looking up
HistoricVariableInstances in case the process ends with form submit
This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/2_1_X by this push:
new ae75377 [SYNCOPE-1601] Looking up HistoricVariableInstances in case the process ends with form submit
ae75377 is described below
commit ae753776b67642fcc9b5dd287b660d44aa28f7e0
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Tue Nov 17 16:04:45 2020 +0100
[SYNCOPE-1601] Looking up HistoricVariableInstances in case the process ends with form submit
---
.../flowable/impl/FlowableUserRequestHandler.java | 74 +++++++++++++++-------
1 file changed, 50 insertions(+), 24 deletions(-)
diff --git a/ext/flowable/flowable-bpmn/src/main/java/org/apache/syncope/core/flowable/impl/FlowableUserRequestHandler.java b/ext/flowable/flowable-bpmn/src/main/java/org/apache/syncope/core/flowable/impl/FlowableUserRequestHandler.java
index 2b267ab..0925eb2 100644
--- a/ext/flowable/flowable-bpmn/src/main/java/org/apache/syncope/core/flowable/impl/FlowableUserRequestHandler.java
+++ b/ext/flowable/flowable-bpmn/src/main/java/org/apache/syncope/core/flowable/impl/FlowableUserRequestHandler.java
@@ -18,9 +18,10 @@
*/
package org.apache.syncope.core.flowable.impl;
-import org.apache.syncope.core.flowable.api.UserRequestHandler;
import java.util.Collections;
+import org.apache.syncope.core.flowable.api.UserRequestHandler;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -66,6 +67,7 @@ import org.flowable.identitylink.api.IdentityLinkType;
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;
import org.flowable.task.api.history.HistoricTaskInstance;
+import org.flowable.variable.api.history.HistoricVariableInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
@@ -295,7 +297,7 @@ public class FlowableUserRequestHandler implements UserRequestHandler {
case "dropdown":
result = UserRequestFormPropertyType.Dropdown;
break;
-
+
case "password":
result = UserRequestFormPropertyType.Password;
break;
@@ -625,16 +627,21 @@ public class FlowableUserRequestHandler implements UserRequestHandler {
return FlowableUserRequestHandler.this.getForm(task, parsed.getRight());
}
- private Map<String, String> getPropertiesForSubmit(final UserRequestForm form) {
+ protected Map<String, String> getPropertiesForSubmit(final UserRequestForm form) {
Map<String, String> props = new HashMap<>();
form.getProperties().stream().
filter(UserRequestFormProperty::isWritable).
- forEach(prop -> {
- props.put(prop.getId(), prop.getValue());
- });
+ forEach(prop -> props.put(prop.getId(), prop.getValue()));
return Collections.unmodifiableMap(props);
}
+ protected <T> T getHistoricVariable(
+ final List<HistoricVariableInstance> historicVariables, final String name, final Class<T> valueRef) {
+
+ return historicVariables.stream().filter(v -> name.equals(v.getVariableName())).
+ findFirst().map(v -> valueRef.cast(v.getValue())).orElse(null);
+ }
+
@Override
@SuppressWarnings("unchecked")
public UserWorkflowResult<UserPatch> submitForm(final UserRequestForm form) {
@@ -672,37 +679,54 @@ public class FlowableUserRequestHandler implements UserRequestHandler {
user = userDAO.save(user);
- UserPatch userPatch = null;
+ PropagationByResource<String> propByRes;
+ PropagationByResource<Pair<String, String>> propByLinkedAccount;
String clearPassword = null;
- PropagationByResource<String> propByRes = null;
- PropagationByResource<Pair<String, String>> propByLinkedAccount = null;
+ UserPatch userPatch;
+ if (engine.getRuntimeService().
+ createProcessInstanceQuery().processInstanceId(procInstID).singleResult() == null) {
- ProcessInstance afterSubmitPI = engine.getRuntimeService().
- createProcessInstanceQuery().processInstanceId(procInstID).singleResult();
- if (afterSubmitPI != null) {
+ List<HistoricVariableInstance> historicVariables = engine.getHistoryService().
+ createHistoricVariableInstanceQuery().processInstanceId(procInstID).list();
+
+ // see if there is any propagation to be done
+ propByRes = getHistoricVariable(
+ historicVariables, FlowableRuntimeUtils.PROP_BY_RESOURCE, PropagationByResource.class);
+ propByLinkedAccount = getHistoricVariable(
+ historicVariables, FlowableRuntimeUtils.PROP_BY_LINKEDACCOUNT, PropagationByResource.class);
+
+ // fetch - if available - the encrypted password
+ String encryptedPwd = getHistoricVariable(
+ historicVariables, FlowableRuntimeUtils.ENCRYPTED_PWD, String.class);
+ if (StringUtils.isNotBlank(encryptedPwd)) {
+ clearPassword = FlowableRuntimeUtils.decrypt(encryptedPwd);
+ }
+
+ userPatch = getHistoricVariable(historicVariables, FlowableRuntimeUtils.USER_PATCH, UserPatch.class);
+ } else {
engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.TASK);
engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.FORM_SUBMITTER);
engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.USER);
engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.USER_TO);
// see if there is any propagation to be done
- propByRes = engine.getRuntimeService().
- getVariable(procInstID, FlowableRuntimeUtils.PROP_BY_RESOURCE, PropagationByResource.class);
+ propByRes = engine.getRuntimeService().getVariable(
+ procInstID, FlowableRuntimeUtils.PROP_BY_RESOURCE, PropagationByResource.class);
engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.PROP_BY_RESOURCE);
propByLinkedAccount = engine.getRuntimeService().getVariable(
procInstID, FlowableRuntimeUtils.PROP_BY_LINKEDACCOUNT, PropagationByResource.class);
engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.PROP_BY_LINKEDACCOUNT);
// fetch - if available - the encrypted password
- String encryptedPwd = engine.getRuntimeService().
- getVariable(procInstID, FlowableRuntimeUtils.ENCRYPTED_PWD, String.class);
+ String encryptedPwd = engine.getRuntimeService().getVariable(
+ procInstID, FlowableRuntimeUtils.ENCRYPTED_PWD, String.class);
engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.ENCRYPTED_PWD);
if (StringUtils.isNotBlank(encryptedPwd)) {
clearPassword = FlowableRuntimeUtils.decrypt(encryptedPwd);
}
- Boolean enabled = engine.getRuntimeService().
- getVariable(procInstID, FlowableRuntimeUtils.ENABLED, Boolean.class);
+ Boolean enabled = engine.getRuntimeService().getVariable(
+ procInstID, FlowableRuntimeUtils.ENABLED, Boolean.class);
engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.ENABLED);
// supports approval chains
@@ -716,23 +740,25 @@ public class FlowableUserRequestHandler implements UserRequestHandler {
propByRes,
propByLinkedAccount);
- userPatch = engine.getRuntimeService().
- getVariable(procInstID, FlowableRuntimeUtils.USER_PATCH, UserPatch.class);
+ userPatch = engine.getRuntimeService().getVariable(
+ procInstID, FlowableRuntimeUtils.USER_PATCH, UserPatch.class);
engine.getRuntimeService().removeVariable(procInstID, FlowableRuntimeUtils.USER_PATCH);
}
+
if (userPatch == null) {
userPatch = new UserPatch();
userPatch.setKey(user.getKey());
userPatch.setPassword(new PasswordPatch.Builder().onSyncope(true).value(clearPassword).build());
+ Set<String> pwdResources = new HashSet<>();
if (propByRes != null) {
- userPatch.getPassword().getResources().addAll(propByRes.get(ResourceOperation.CREATE));
+ pwdResources.addAll(propByRes.get(ResourceOperation.CREATE));
}
if (propByLinkedAccount != null) {
- for (Pair<String, String> account : propByLinkedAccount.get(ResourceOperation.CREATE)) {
- userPatch.getPassword().getResources().add(account.getLeft());
- }
+ pwdResources.addAll(propByLinkedAccount.get(ResourceOperation.CREATE).stream().
+ map(Pair::getLeft).collect(Collectors.toList()));
}
+ userPatch.getPassword().getResources().addAll(pwdResources);
}
return new UserWorkflowResult<>(userPatch, propByRes, propByLinkedAccount, postTasks);