Hello.
I was wondering if anyone could help with an issue of setting plain
attribute values for a user from a flowable service task. It is behaving in
a strange manner. The relevant code is below. The service is called from
the workflow without error. The accountExpiryDate is saved to the database
but the accountReviewDate is not (both dates are in a valid format). Also,
the accountExpiryDate does not display in the admin console and again the
data is in the database. I hope someone can help me with this mystery.
I have tried both with and without an update service task following this
service call in the workflow and it does not appear to have an effect.
Thank you.
@Component
public class UpdateAccountReviewDate extends FlowableServiceTask {
@Autowired
private UserDAO userDAO;
@Autowired
private PlainSchemaDAO plainSchemaDAO;
@Autowired
protected EntityFactory entityFactory;
@Autowired
protected AnyUtilsFactory anyUtilsFactory;
@Autowired
private UserDataBinder dataBinder;
@Autowired
private ConfDAO confDAO;
//Format defined in schema for fields in question
private static final DateFormat dateFormat = new
SimpleDateFormat("MM/dd/yyyy");
@Override
protected void doExecute(DelegateExecution execution) {
int expiryDays = getExpiryDays().intValue();
Date now = new Date();
Date expiryDate = getFutureDate(now, expiryDays);
String accountReviewDate = dateFormat.format(now);
String accountExpiryDate = dateFormat.format(expiryDate);
User user = execution.getVariable(FlowableRuntimeUtils.USER,
User.class);
userDAO.save(user);
UserPatch userPatch = new UserPatch();
userPatch.setKey(user.getKey());
userPatch.getPlainAttrs().add(createUpdatePatch("accountReviewDate",
accountReviewDate));
userPatch.getPlainAttrs().add(createUpdatePatch("accountExpiryDate",
accountExpiryDate));
PropagationByResource propByRes = dataBinder.update(user,
userPatch);
execution.setVariable(FlowableRuntimeUtils.USER, user);
execution.setVariable(FlowableRuntimeUtils.USER_PATCH, userPatch);
execution.setVariable(FlowableRuntimeUtils.PROP_BY_RESOURCE,
propByRes);
}
private AttrPatch createUpdatePatch(String key, String value) {
return new
AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(createAttribute(key,
value)).build();
}
private AttrTO createAttribute(String key, String value) {
return new AttrTO.Builder().schema(key).value(value).build();
}
}
--
Sent from: http://syncope-user.1051894.n5.nabble.com/