Contributed Action methods can not depend on the object state

May 24, 2013 at 10:41 AM
Hi Guys,
           Methods in one of my contributed action services only apply to specific object states.
I would like I way to disable contributed action methods just as you can disable object actions as you say in the doco.
I have a fix for this to just say that when the user attempts an action and the object is not in the correct state then a warning message will be displayed and the user informed that they have to use the contributed action method.
The reason why the contributed action method can not be used is that it returns an IQueryable and the user has to select which object to set.
So this is what I am doing now in my action method.
[MemberOrder(1)]
        public void SetPractitioner()
        {
            switch (MethodOfOfferValue)
            {
                case MethodOfOffer.NextPractitioner:
                    Practitioner = PractitionerRepository.GetNextPractitioner(this);

                    break;
                case MethodOfOffer.SkipPractitioner:
                    Practitioner = PractitionerRepository.GetNextPractitionerAndSkip(this);

                    break;
                case MethodOfOffer.SpecificPractitioner:

                    Container.InformUser("Use the 'Get Specific Practitioners' function on the Practitioner drop down menu to find and select the Practitioner you want.");

                    break;
            }
        }
And my Contributed Action repository has
public Practitioner GetNextPractitioner(WorkOffer workOffer)
        {
            Practitioner practitioner = null;
            if (workOffer.WorkItem == null)
            {
                Container.InformUser("A work Item must be specified.");
            }
            else
            {
                practitioner = (Practitioner)PractitionerService.GetNextPractitionerByCourt(workOffer.WorkItem.Court);               
            }

            return (practitioner);
        }
        
        public Practitioner GetNextPractitionerAndSkip(WorkOffer workOffer)
        {
            Practitioner practitioner = null;
            if (workOffer.WorkItem == null)
            {
                Container.InformUser("A work Item must be specified.");
            }
            else
            {
                practitioner = (Practitioner)PractitionerService.GetNextPractitionerByCourtAndSkip(workOffer.WorkItem.Court);                
            }

            return (practitioner);
        }

        public IQueryable<Practitioner> GetSpecificPractitioners(WorkOffer workOffer, [Optionally] string specificPractitionerLastNameFilter)
        {            
            IQueryable<Practitioner> practitioners = null;
            if (workOffer.WorkItem == null)
            {
                Container.InformUser("A work Item must be specified.");
            }
            else
            {            
                practitioners = PractitionerService.GetSpecificPractitionersByCourt(workOffer.WorkItem.Court, specificPractitionerLastNameFilter).OfType<Practitioner>();                
            }           

            return (practitioners);
        }
Its not a big issue, just thought you might be interested.

Regards,
            Alistair
Coordinator
May 24, 2013 at 11:18 AM
The ability to disable/hide contributed actions is an existing ticket. See: https://nakedobjects.codeplex.com/workitem/61

But I don't understand why GetSpecificPractitioners is a contributed action at all. Why not make it an action on the WorkItem? Then it can be enabled/disabled easily.

Further:
  • If the MethodOfOffer is NextPractitioner or SkipPractitioner, figure out how to set the Practitioner property directly (using your existing underlying methods), without the user having to invoke a SetPractitioner action at all.
  • If the MethodOfOffer is SpecificPractitioner then the user can invoke the action (on the object) SpecifyPractitioner(Practitioner p), with a corresponding AutoComplete action that returns the IQueryable<Practitioner> for the user to select from.
This action would only be hidden for the previous case, and would be disabled if WorkItem == null.

In other words, with some careful re-design you could eliminate several user steps from this process.