<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Yes. As I said, <a
        href="https://jira.evolveum.com/browse/MID-2373">MID-2373</a>
      causes that the first code snippet - although being simple -
      currently does not work. <br>
      <br>
      Please use the second one (after merging <a
href="https://github.com/Evolveum/midpoint/commit/5ea8c75705e9564baa70e6fa6a2f2a488a676b99">https://github.com/Evolveum/midpoint/commit/5ea8c75705e9564baa70e6fa6a2f2a488a676b99</a>
      to your code), or merge parts of the first code snippet i.e.<br>
      <br>
      <pre wrap="">AssignmentType itemToApprove = event.getProcessInstanceState().asObjectable().getProcessSpecificState().getApprovalRequest().getItemToApprove();
PrismReferenceValue reference = itemToApprove.getTargetRef().asReferenceValue();
</pre>
      with the rest of your code, i.e.<br>
      <br>
      <pre wrap="">                        String oid = reference.getOid();
                        Class clazz = reference.getTargetTypeCompileTimeClass();

                        TaskManager taskManager = SpringApplicationContextHolder.getBean(TaskManager.class);
                        Task task = taskManager.createTaskInstance();
                        OperationResult parentResult = task.getResult();

                        PrismObject obj = SpringApplicationContextHolder.getBean(ModelController.class).getObject(clazz, oid, null, task, parentResult);

                        body = "Выдаваемое полномочие \""+obj.asObjectable().getName() +"\"";                   
</pre>
      Regards,<br>
      Pavol<br>
      <br>
      On 20. 5. 2015 12:56, Алексей Ващенков wrote:<br>
    </div>
    <blockquote
      cite="mid:23F96C83E30B7E4DA253EBD07C550836014C87FE@EX-MB2.solar.local"
      type="cite">
      <pre wrap="">With your solution exception is throws 
Caused by: java.lang.IllegalArgumentException: Operation result must not be null.
        at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[Validate.class:2.6]
        at com.evolveum.midpoint.model.impl.controller.ModelController.getObject_aroundBody0(ModelController.java:264) [ModelController.class:na]
        at com.evolveum.midpoint.model.impl.controller.ModelController$AjcClosure1.run(ModelController.java:1) ~[ModelController$AjcClosure1.class:na]
        at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149) [JoinPointImpl.class:na]
        at com.evolveum.midpoint.util.aspect.MidpointAspect.wrapSubsystem(MidpointAspect.java:178) [MidpointAspect.class:na]
        at com.evolveum.midpoint.util.aspect.MidpointAspect.ajc$inlineAccessMethod$com_evolveum_midpoint_util_aspect_MidpointAspect$com_evolveum_midpoi
nt_util_aspect_MidpointAspect$wrapSubsystem(MidpointAspect.java:1) [MidpointAspect.class:na]
        at com.evolveum.midpoint.util.aspect.MidpointAspect.processModelNdc(MidpointAspect.java:63) [MidpointAspect.class:na]
        at com.evolveum.midpoint.model.impl.controller.ModelController.getObject(ModelController.java:260) [ModelController.class:na]
        at com.evolveum.midpoint.model.impl.expr.MidpointFunctionsImpl.getObject(MidpointFunctionsImpl.java:784) ~[MidpointFunctionsImpl.class:na]
        at com.evolveum.midpoint.model.api.expr.MidpointFunctions$getObject.call(Unknown Source) ~[na:na]
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) ~[CallSiteArray.class:1.8.6]
        at com.evolveum.midpoint.model.api.expr.MidpointFunctions$getObject.call(Unknown Source) ~[na:na]

com.evolveum.midpoint.model.impl.expr.ModelExpressionThreadLocalHolder#getCurrentResult returns always null. 
Deque<OperationResult> stack = currentResultStackTl.get();
if (stack == null) {
        return null;
}
return stack.peek();
stack is not null. But stack.peek() returns null.

________________________________________
От: midPoint [<a class="moz-txt-link-abbreviated" href="mailto:midpoint-bounces@lists.evolveum.com">midpoint-bounces@lists.evolveum.com</a>] от имени Pavol Mederly [<a class="moz-txt-link-abbreviated" href="mailto:mederly@evolveum.com">mederly@evolveum.com</a>]
Отправлено: 20 мая 2015 г. 12:55
Кому: <a class="moz-txt-link-abbreviated" href="mailto:midpoint@lists.evolveum.com">midpoint@lists.evolveum.com</a>
Тема: Re: [midPoint] Access to assignhments in message generation

Your code is OK. Just as you expected, it can be written in a little bit more compact way:

AssignmentType itemToApprove = event.getProcessInstanceState().asObjectable().getProcessSpecificState().getApprovalRequest().getItemToApprove();
PrismReferenceValue reference = itemToApprove.getTargetRef().asReferenceValue();
String oid = reference.getOid();
Class clazz = reference.getTargetTypeCompileTimeClass();

PrismObject obj = midpoint.getObject(clazz, oid, null);

body = "Выдаваемое полномочие \""+obj.asObjectable().getName() +"\"";

Especially note the midpoint object that points to MidpointFunctionsImpl containing a lot of useful methods. Unfortunately, there seems to be a fault in the notifications module preventing the getObject method from working correctly (some threadlocal variables are not set up) when called from the notification scripts. I'll fix that (MID-2373<a class="moz-txt-link-rfc2396E" href="https://jira.evolveum.com/browse/MID-2373"><https://jira.evolveum.com/browse/MID-2373></a>). Until that, it seems to be necessary to use your solution based on calling model API directly.

BTW, your requirements seem very reasonable to me, so I've added a couple of convenience methods to WorkflowEvent class (see last commit). So your code can be reduced to this one:

            <bodyExpression>
               <script>
                  <code>
                        import com.evolveum.midpoint.wf.impl.processes.common.*;
                        import com.evolveum.midpoint.prism.*;
                        import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
                        import com.evolveum.midpoint.xml.ns.model.workflow.process_instance_state_3.*;
                        import com.evolveum.midpoint.prism.path.*;
                        import com.evolveum.midpoint.model.impl.controller.ModelController;
                        import com.evolveum.midpoint.task.api.Task;
                        import com.evolveum.midpoint.task.api.TaskManager;
                        import com.evolveum.midpoint.schema.result.OperationResult;

                        AssignmentType itemToApprove = event.getItemToApprove();
                        PrismReferenceValue reference = itemToApprove.getTargetRef().asReferenceValue();
                        String oid = reference.getOid();
                        Class clazz = reference.getTargetTypeCompileTimeClass();

                        TaskManager taskManager = SpringApplicationContextHolder.getBean(TaskManager.class);
                        Task task = taskManager.createTaskInstance();
                        OperationResult parentResult = task.getResult();

                        PrismObject obj = SpringApplicationContextHolder.getBean(ModelController.class).getObject(clazz, oid, null, task, parentResult);

                        body = "Выдаваемое полномочие \""+obj.asObjectable().getName() +"\"";                    </code>
               </script>
            </bodyExpression>

Regards,
Pavol

On 20. 5. 2015 10:12, Алексей Ващенков wrote:

I need to get assignment name. I found next decision:
            <bodyExpression>
               <script>
                  <code>
                                import com.evolveum.midpoint.wf.impl.processes.common.*;
                                import com.evolveum.midpoint.prism.*;
                                import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
                                import com.evolveum.midpoint.xml.ns.model.workflow.process_instance_state_3.*;
                                import com.evolveum.midpoint.prism.path.*;
                                import com.evolveum.midpoint.model.impl.controller.ModelController;
                                import com.evolveum.midpoint.task.api.Task;
                                import com.evolveum.midpoint.task.api.TaskManager;
                                import com.evolveum.midpoint.schema.result.OperationResult;

                                List segments = new ArrayList();
                                segments.add(new NameItemPathSegment(ProcessInstanceState.F_PROCESS_SPECIFIC_STATE));
                                segments.add(new NameItemPathSegment(ItemApprovalProcessState.F_APPROVAL_REQUEST));
                                segments.add(new NameItemPathSegment(ItemApprovalRequestType.F_ITEM_TO_APPROVE));
                                PrismPropertyValue value = (PrismPropertyValue)((PrismProperty)event.getProcessInstanceState().find(new ItemPath(segments))).getValues().get(0);

                                PrismReferenceValue reference = ((PrismReference) ((AssignmentType) value.getValue()).asPrismContainerValue().getItems().get(0)).getValue();
                                String oid = reference.getOid();
                                Class clazz = reference.getTargetTypeCompileTimeClass();

                                TaskManager taskManager = SpringApplicationContextHolder.getBean(TaskManager.class);
                                Task task = taskManager.createTaskInstance();
                                OperationResult parentResult = task.getResult();

                                PrismObject obj = SpringApplicationContextHolder.getBean(ModelController.class).getObject(clazz, oid, null, task, parentResult);

                                body = "Выдаваемое полномочие \""+obj.asObjectable().getName() +"\"";
                        </code>
               </script>
            </bodyExpression>
Is it easier way to take it?
________________________________________
От: midPoint [<a class="moz-txt-link-abbreviated" href="mailto:midpoint-bounces@lists.evolveum.com">midpoint-bounces@lists.evolveum.com</a><a class="moz-txt-link-rfc2396E" href="mailto:midpoint-bounces@lists.evolveum.com"><mailto:midpoint-bounces@lists.evolveum.com></a>] от имени Pavol Mederly [<a class="moz-txt-link-abbreviated" href="mailto:mederly@evolveum.com">mederly@evolveum.com</a><a class="moz-txt-link-rfc2396E" href="mailto:mederly@evolveum.com"><mailto:mederly@evolveum.com></a>]
Отправлено: 19 мая 2015 г. 16:06
Кому: midPoint General Discussion
Тема: Re: [midPoint] Access to assignhments in message generation

It should be possible. Let event be an instance of WorkItemEvent. Then:

- event.getProcessInstanceState() is an instance of ProcessInstanceState (it maybe will be renamed to ProcessInstanceStateType in later versions of midPoint)
- in its "processorSpecificState" attribute there is an instance of PrimaryChangeProcessorState, which in turn has the attribute "delta"
- delta contains the delta that is being approved

In your case, the delta should contain the assignment that is to be added.

I'm not sure that I've actually tested this, but it should work. If not, just let me know.

Pavol

----- Original Message -----
From: "Алексей Ващенков" <a class="moz-txt-link-rfc2396E" href="mailto:a.vashchenkov@solarsecurity.ru"><a.vashchenkov@solarsecurity.ru></a><a class="moz-txt-link-rfc2396E" href="mailto:a.vashchenkov@solarsecurity.ru"><mailto:a.vashchenkov@solarsecurity.ru></a>
To: <a class="moz-txt-link-abbreviated" href="mailto:midpoint@lists.evolveum.com">midpoint@lists.evolveum.com</a><a class="moz-txt-link-rfc2396E" href="mailto:midpoint@lists.evolveum.com"><mailto:midpoint@lists.evolveum.com></a>
Sent: Tuesday, May 19, 2015 1:48:04 PM
Subject: [midPoint] Access to assignhments in message generation

Is it possible access to requested assignments while message generation?
_______________________________________________
midPoint mailing list
<a class="moz-txt-link-abbreviated" href="mailto:midPoint@lists.evolveum.com">midPoint@lists.evolveum.com</a><a class="moz-txt-link-rfc2396E" href="mailto:midPoint@lists.evolveum.com"><mailto:midPoint@lists.evolveum.com></a>
<a class="moz-txt-link-freetext" href="http://lists.evolveum.com/mailman/listinfo/midpoint">http://lists.evolveum.com/mailman/listinfo/midpoint</a>
_______________________________________________
midPoint mailing list
<a class="moz-txt-link-abbreviated" href="mailto:midPoint@lists.evolveum.com">midPoint@lists.evolveum.com</a><a class="moz-txt-link-rfc2396E" href="mailto:midPoint@lists.evolveum.com"><mailto:midPoint@lists.evolveum.com></a>
<a class="moz-txt-link-freetext" href="http://lists.evolveum.com/mailman/listinfo/midpoint">http://lists.evolveum.com/mailman/listinfo/midpoint</a>
_______________________________________________
midPoint mailing list
<a class="moz-txt-link-abbreviated" href="mailto:midPoint@lists.evolveum.com">midPoint@lists.evolveum.com</a><a class="moz-txt-link-rfc2396E" href="mailto:midPoint@lists.evolveum.com"><mailto:midPoint@lists.evolveum.com></a>
<a class="moz-txt-link-freetext" href="http://lists.evolveum.com/mailman/listinfo/midpoint">http://lists.evolveum.com/mailman/listinfo/midpoint</a>
_______________________________________________
midPoint mailing list
<a class="moz-txt-link-abbreviated" href="mailto:midPoint@lists.evolveum.com">midPoint@lists.evolveum.com</a>
<a class="moz-txt-link-freetext" href="http://lists.evolveum.com/mailman/listinfo/midpoint">http://lists.evolveum.com/mailman/listinfo/midpoint</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>