[midPoint] Access to assignhments in message generation

Pavol Mederly mederly at evolveum.com
Wed May 20 11:55:26 CEST 2015


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 
<https://jira.evolveum.com/browse/MID-2373>). 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 [midpoint-bounces at lists.evolveum.com] от имени Pavol Mederly [mederly at evolveum.com]
> Отправлено: 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.vashchenkov at solarsecurity.ru>
> To: midpoint at lists.evolveum.com
> 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
> midPoint at lists.evolveum.com
> http://lists.evolveum.com/mailman/listinfo/midpoint
> _______________________________________________
> midPoint mailing list
> midPoint at lists.evolveum.com
> http://lists.evolveum.com/mailman/listinfo/midpoint
> _______________________________________________
> midPoint mailing list
> midPoint at lists.evolveum.com
> http://lists.evolveum.com/mailman/listinfo/midpoint

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.evolveum.com/pipermail/midpoint/attachments/20150520/2a042b15/attachment.htm>


More information about the midPoint mailing list