You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@syncope.apache.org by pcrowder <pc...@hotmail.com> on 2019/01/22 21:21:03 UTC

Flowable Java Service

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/

Re: Flowable Java Service

Posted by pcrowder <pc...@hotmail.com>.
They are both schema fields assigned to the BaseUser AnyType. Birthdate is
set in the EndUser UI. It is set fine and visible in the Admin Console.
email_verified is set using a patch in the workflow process and displays
correctly in the Admin Console.


BaseUser
[accountExpiryDate, accountReviewDate, birthdate, email, email_verified,
family_name, given_name, middle_name, ssn]

--
Sent from: http://syncope-user.1051894.n5.nabble.com/

Re: Flowable Java Service

Posted by Francesco Chicchiriccò <il...@apache.org>.
On 24/01/19 18:30, pcrowder wrote:
> Ok. What about the values not showing in the console when you edit a user?

Here the question is: to which AnyTypeClass [1] do the 
'accountExpiryDate' and 'accountReviewDate' plain schemas belong to? Is 
such AnyTypeClass assigned to the user (either directly or indirectly)?

Even though you can circumvent the typing mechanism by acting at 
low-level via DAOs, this is anyway enforced at high-level by REST APIs - 
and Admin Console behaves accordingly.

Regards.

[1] 
https://ci.apache.org/projects/syncope/2_1_X/reference-guide.html#anytypeclass

-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Member at The Apache Software Foundation
Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
http://home.apache.org/~ilgrosso/


Re: Flowable Java Service

Posted by pcrowder <pc...@hotmail.com>.
Ok. What about the values not showing in the console when you edit a user?

--
Sent from: http://syncope-user.1051894.n5.nabble.com/

Re: Flowable Java Service

Posted by Francesco Chicchiriccò <il...@apache.org>.
Yep, value(s) for read-only schemas are modifiable only via internal 
code [1], e.g. via DAO.

[1] https://ci.apache.org/projects/syncope/2_1_X/reference-guide.html#plain

On 24/01/19 16:58, pcrowder wrote:
> I found nothing in the logs. Set everything to debug. No warnings or errors.
> Using version 2.1.2 of Syncope.
>
> Did some experimenting and this is what I found:
>
> 1. Using the patch method.
>    - The accountReviewDate was read only and a patch will not set a read only
> value. If the read only flag is reviewed then the value is written to the
> database.
>    - Neither value will display in the console (accountExpiryDate or
> accountReviewDate) when editing a user.
>    - If you edit the blank field in the console (accountExpiryDate), a second
> entry is written to the database (uplainattr and uplainaatrvalue). These
> values now show up in the console.
>   
> 2. Using UserDAO to save the values (no patch).
>    - Both values are written to the database even the read only field.
>    - Two values are written for the read only field (accountReviewDate).
>    - The read field displays in the console (accountReviewDate) but the other
> field does not (accountExpiryDate).
>    - Editing and saving a new value for accountExpiryDate writes a new value
> to the database and that value if visible in the console.

-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Member at The Apache Software Foundation
Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
http://home.apache.org/~ilgrosso/


Re: Flowable Java Service

Posted by pcrowder <pc...@hotmail.com>.
I found nothing in the logs. Set everything to debug. No warnings or errors.
Using version 2.1.2 of Syncope.

Did some experimenting and this is what I found:

1. Using the patch method.
  - The accountReviewDate was read only and a patch will not set a read only
value. If the read only flag is reviewed then the value is written to the
database.
  - Neither value will display in the console (accountExpiryDate or
accountReviewDate) when editing a user.
  - If you edit the blank field in the console (accountExpiryDate), a second
entry is written to the database (uplainattr and uplainaatrvalue). These
values now show up in the console.
 
2. Using UserDAO to save the values (no patch).
  - Both values are written to the database even the read only field.
  - Two values are written for the read only field (accountReviewDate).
  - The read field displays in the console (accountReviewDate) but the other
field does not (accountExpiryDate).
  - Editing and saving a new value for accountExpiryDate writes a new value
to the database and that value if visible in the console.



--
Sent from: http://syncope-user.1051894.n5.nabble.com/

Re: Flowable Java Service

Posted by Francesco Chicchiriccò <il...@apache.org>.
Hi,
before moving into Sherlock Holmes mode, are you able to assign a value 
for the "accountReviewDate" attribute from Admin Console?
There might be chance that such attribute is simply not assignable to 
the given user, thus Syncope silently discards it from update request.

In any case: can you derive something relevant by watching the logs 
during the execution of the class below?

Regards.

On 22/01/19 22:21, pcrowder wrote:
> 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();
>      }
> }

-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Member at The Apache Software Foundation
Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
http://home.apache.org/~ilgrosso/