[midPoint] HA: Access to assignhments in message generation

Pavol Mederly mederly at evolveum.com
Wed May 20 13:43:54 CEST 2015


Yes. As I said, MID-2373 <https://jira.evolveum.com/browse/MID-2373> 
causes that the first code snippet - although being simple - currently 
does not work.

Please use the second one (after merging 
https://github.com/Evolveum/midpoint/commit/5ea8c75705e9564baa70e6fa6a2f2a488a676b99 
to your code), or merge parts of the first code snippet i.e.

AssignmentType itemToApprove = event.getProcessInstanceState().asObjectable().getProcessSpecificState().getApprovalRequest().getItemToApprove();
PrismReferenceValue reference = itemToApprove.getTargetRef().asReferenceValue();

with the rest of your code, i.e.

                         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() +"\"";

Regards,
Pavol

On 20. 5. 2015 12:56, Алексей Ващенков wrote:
> 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 [midpoint-bounces at lists.evolveum.com] от имени Pavol Mederly [mederly at evolveum.com]
> Отправлено: 20 мая 2015 г. 12:55
> Кому: midpoint at lists.evolveum.com
> Тема: 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<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<mailto:midpoint-bounces at lists.evolveum.com>] от имени Pavol Mederly [mederly at evolveum.com<mailto: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><mailto:a.vashchenkov at solarsecurity.ru>
> To: midpoint at lists.evolveum.com<mailto: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<mailto:midPoint at lists.evolveum.com>
> http://lists.evolveum.com/mailman/listinfo/midpoint
> _______________________________________________
> midPoint mailing list
> midPoint at lists.evolveum.com<mailto:midPoint at lists.evolveum.com>
> http://lists.evolveum.com/mailman/listinfo/midpoint
> _______________________________________________
> midPoint mailing list
> midPoint at lists.evolveum.com<mailto: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/77951c00/attachment.htm>


More information about the midPoint mailing list