<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Your code is OK. Just as you expected,
it can be written in a little bit more compact way:<br>
<br>
<tt>AssignmentType itemToApprove =
event.getProcessInstanceState().asObjectable().getProcessSpecificState().getApprovalRequest().getItemToApprove();<br>
</tt><tt>PrismReferenceValue reference =
itemToApprove.getTargetRef().asReferenceValue();</tt><tt><br>
</tt><tt>String oid = reference.getOid();</tt><tt><br>
</tt><tt>Class clazz = reference.getTargetTypeCompileTimeClass();</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt>PrismObject obj = <b><font color="#006600">midpoint.getObject</font></b>(clazz,
oid, null);</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt>body = "Выдаваемое полномочие
\""+obj.asObjectable().getName() +"\"";</tt><tt><br>
</tt><br>
Especially note the <tt>midpoint</tt> object that points to <tt>MidpointFunctionsImpl</tt>
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 (<a
href="https://jira.evolveum.com/browse/MID-2373">MID-2373</a>).
Until that, it seems to be necessary to use your solution based on
calling model API directly.<br>
<br>
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:<br>
<br>
<tt> <bodyExpression></tt><tt><br>
</tt><tt> <script></tt><tt><br>
</tt><tt> <code></tt><tt><br>
</tt><tt> import
com.evolveum.midpoint.wf.impl.processes.common.*;</tt><tt><br>
</tt><tt> import
com.evolveum.midpoint.prism.*;</tt><tt><br>
</tt><tt> import
com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;</tt><tt><br>
</tt><tt> import
com.evolveum.midpoint.xml.ns.model.workflow.process_instance_state_3.*;</tt><tt><br>
</tt><tt> import
com.evolveum.midpoint.prism.path.*;</tt><tt><br>
</tt><tt> import
com.evolveum.midpoint.model.impl.controller.ModelController;</tt><tt><br>
</tt><tt> import
com.evolveum.midpoint.task.api.Task;</tt><tt><br>
</tt><tt> import
com.evolveum.midpoint.task.api.TaskManager;</tt><tt><br>
</tt><tt> import
com.evolveum.midpoint.schema.result.OperationResult;</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><b><font color="#006600"><tt>
AssignmentType itemToApprove = event.getItemToApprove();</tt></font></b><tt><br>
</tt><tt> PrismReferenceValue reference =
itemToApprove.getTargetRef().asReferenceValue();</tt><tt><br>
</tt><tt> String oid = reference.getOid();</tt><tt><br>
</tt><tt> Class clazz =
reference.getTargetTypeCompileTimeClass();</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt> TaskManager taskManager =
SpringApplicationContextHolder.getBean(TaskManager.class);</tt><tt><br>
</tt><tt> Task task =
taskManager.createTaskInstance();</tt><tt><br>
</tt><tt> OperationResult parentResult =
task.getResult();</tt><tt><br>
</tt><tt><br>
</tt><tt> PrismObject obj =
SpringApplicationContextHolder.getBean(ModelController.class).getObject(clazz,
oid, null, task, parentResult);</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt> body = "Выдаваемое полномочие
\""+obj.asObjectable().getName() +"\"";
</code></tt><tt><br>
</tt><tt> </script></tt><tt><br>
</tt><tt> </bodyExpression></tt><tt><br>
</tt><br>
Regards,<br>
Pavol<br>
<br>
On 20. 5. 2015 10:12, Алексей Ващенков wrote:<br>
</div>
<blockquote
cite="mid:23F96C83E30B7E4DA253EBD07C550836014C879C@EX-MB2.solar.local"
type="cite">
<pre wrap="">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>] от имени Pavol Mederly [<a class="moz-txt-link-abbreviated" href="mailto:mederly@evolveum.com">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>
To: <a class="moz-txt-link-abbreviated" href="mailto:midpoint@lists.evolveum.com">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-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>
_______________________________________________
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>