AnsweredAssumed Answered

DeclarativeWebScript can't check updated aspect until it runs asynchronously

Question asked by jamilnour on Mar 6, 2018
Latest reply on Mar 12, 2018 by jamilnour

Hello,

 

I have the following case:

 

From inside a DeclarativeWebScript (A) I have to wait (Thread.sleep) until a custom person aspect properties (of the active user) is updated by another DeclarativeWebScript (B). The Thread.sleep of A is terminated when a condition on the aspect properties (IndorsePeopleModel.PROP_INTESITRANSACTION) is successfully evaluated.

 

The problem I have is that even IndorsePeopleModel.PROP_INTESITRANSACTION is updated by B , A is never know and the sleep is never ended

 

It works only if A is called as ActionExecuter and asynchronously from a DeclarativeWebScript .

 

...
Action action = getServiceRegistry().getActionService().createAction("A", params);
action.setExecuteAsynchronously(true);
getServiceRegistry().getActionService().executeAction(action, docNodeRef);
...

But in this case I have a problem to know the status of the ActionExecuter

 

A:

...


long delta = 0;
        long startTime = System.currentTimeMillis();
        while (true)
        {
        try {
        long endTime = System.currentTimeMillis();
        delta = endTime - startTime;

        if (delta > 35000) break;

        JSONObject runJSONObject = (JSONObject) AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
        {
public JSONObject doWork() throws Exception
        {
        NodeRef userNodeRef = m_personService.getPerson(username);
        String transactionString = (String) getNodeService().getProperty(userNodeRef, IndorsePeopleModel.PROP_INTESITRANSACTION);
        logger.debug("transactionString = " + transactionString);
        JSONObject jsonTransaction = new JSONObject(transactionString);
        return jsonTransaction;
        }
        }, Constants.USER_ADMIN);

        approved = runJSONObject.get("approved").toString();
        logger.debug("approved = " + approved);


        if(jsonObject.get("approved").equals("1"))
        {
        setPin(jsonObject.get("pin").toString());
        break;
        }
        else{
        Thread.sleep(2000);
        continue;
        }


        } catch (Exception e) {
              throw new IllegalArgumentException("Error ", e);
           }
        }

...

 

B:

..

if (!getNodeService().hasAspect(userNodeRef, IndorsePeopleModel.ASPECT_PERSON)) {
    getNodeService().addAspect(userNodeRef, IndorsePeopleModel.ASPECT_PERSON, new HashMap<QName, Serializable>());
}
// add/replace the aspect  to person
//getNodeService().removeProperty(userNodeRef, IndorsePeopleModel.PROP_INTESITRANSACTION);
getNodeService().setProperty(userNodeRef, IndorsePeopleModel.PROP_INTESITRANSACTION, transactionString);
..

 

Thank you

 

Jamil

Outcomes