You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@isis.apache.org by Kevin Meyer - KMZ <ke...@kmz.co.za> on 2011/12/02 18:10:50 UTC

Re: Help with disabled() on object

Hi Dan,

I've (mostly) implemented an equivalent hidden() on object, and I 
discovered that I was missing adding my HiddenMethodFact from the 
metamodel.

Now I got the hidden() method working in the htmlviewer, but it could 
be a bit of a kludge, as this approach would need each viewer to be 
handled specifically.

Anyway - using this knowledge, I went back to the disabled() method, 
and realised that I am probably looking at hooking into the isVetoed 
and equivalent methods in the metamodel, but I can't find where the 
Context is setup and appropriate Facets interrogated.

Where else do I need to add my DisabledObjectFacet so that the 
metamodel picks it up?

Regards,
Kevin


On 30 Nov 2011 at 17:53, Kevin Meyer - KMZ wrote:

> Hi Dan,
> 
> I remember discussing something like this with you at the Knockree 
> retreat - I've implemented the various classes to support a 
> 	String disabled(){..};
> method on an object, to runtime prevent a user from editting any of the 
> properties.
> 
> The problem is, it doesn't work! :)
> 
> Following the examples of the Immutable facet and the "validate" 
> method facet, I have:
> 
> public class DisabledObjectFacetViaDisabledMethod extends DisabledObjectFacetAbstract implements ImperativeFacet 
> 
> where 
> 
> public abstract class DisabledObjectFacetAbstract extends FacetAbstract implements DisabledObjectFacet
> 
> and 
> 
> public interface DisabledObjectFacet extends Facet, DisablingInteractionAdvisor 
> 
> The factory is registered in ProgrammingModelFacetsJava5:
>      addFactory(DisabledObjectViaDisabledMethodFacetFactory.class);
> 
> But when I load an object with the "disabled()" method, I can still edit it. 
> The "disabled" method is not visible, so it's being picked up...
> 
> This tells me that the "DisablingInteractionAdvisor " is not doing what I 
> expect..
> 
> What am I missing?
> 
> 
> Since the unit test passes, I'll check in the code, associated with 
> ISIS-142
> 
> Regards,
> Kevin
> 


--
Kevin Meyer, PhD, Pr.Sci.Nat
KMZ		P.O. Box 9822, Sharon Park, South Africa.
Tel: +27 11 363 2001	Cell: +27 83 346 3045



Re: Help with disabled() on object

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
I went looking for your code this evening to take a closer look, but
couldn't find it in the tripp. Was I just being daft?

Sorry to be brief, sent from my phone
On Dec 2, 2011 5:11 PM, "Kevin Meyer - KMZ" <ke...@kmz.co.za> wrote:

> Hi Dan,
>
> I've (mostly) implemented an equivalent hidden() on object, and I
> discovered that I was missing adding my HiddenMethodFact from the
> metamodel.
>
> Now I got the hidden() method working in the htmlviewer, but it could
> be a bit of a kludge, as this approach would need each viewer to be
> handled specifically.
>
> Anyway - using this knowledge, I went back to the disabled() method,
> and realised that I am probably looking at hooking into the isVetoed
> and equivalent methods in the metamodel, but I can't find where the
> Context is setup and appropriate Facets interrogated.
>
> Where else do I need to add my DisabledObjectFacet so that the
> metamodel picks it up?
>
> Regards,
> Kevin
>
>
> On 30 Nov 2011 at 17:53, Kevin Meyer - KMZ wrote:
>
> > Hi Dan,
> >
> > I remember discussing something like this with you at the Knockree
> > retreat - I've implemented the various classes to support a
> >       String disabled(){..};
> > method on an object, to runtime prevent a user from editting any of the
> > properties.
> >
> > The problem is, it doesn't work! :)
> >
> > Following the examples of the Immutable facet and the "validate"
> > method facet, I have:
> >
> > public class DisabledObjectFacetViaDisabledMethod extends
> DisabledObjectFacetAbstract implements ImperativeFacet
> >
> > where
> >
> > public abstract class DisabledObjectFacetAbstract extends FacetAbstract
> implements DisabledObjectFacet
> >
> > and
> >
> > public interface DisabledObjectFacet extends Facet,
> DisablingInteractionAdvisor
> >
> > The factory is registered in ProgrammingModelFacetsJava5:
> >      addFactory(DisabledObjectViaDisabledMethodFacetFactory.class);
> >
> > But when I load an object with the "disabled()" method, I can still edit
> it.
> > The "disabled" method is not visible, so it's being picked up...
> >
> > This tells me that the "DisablingInteractionAdvisor " is not doing what I
> > expect..
> >
> > What am I missing?
> >
> >
> > Since the unit test passes, I'll check in the code, associated with
> > ISIS-142
> >
> > Regards,
> > Kevin
> >
>
>
> --
> Kevin Meyer, PhD, Pr.Sci.Nat
> KMZ             P.O. Box 9822, Sharon Park, South Africa.
> Tel: +27 11 363 2001   Cell: +27 83 346 3045
>
>
>

Re: Help with disabled() on object

Posted by Kevin Meyer - KMZ <ke...@kmz.co.za>.
I'm trying out:

        final Method methods[] = cls.getMethods();
        for (Method method : methods) {
            FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(method, facetHolder));
        }

Is a bit overkill, as it'll effectively be annotating all the Isis methods as 
well! (validateXXX, etc).

On 5 Dec 2011 at 12:06, Kevin Meyer - KMZ wrote:

> Hi Dan,
> 
> I'm trying to implement your alternate suggestion, but I'm having 
> issues.
> 
> On 3 Dec 2011 at 7:03, Dan Haywood wrote:
> 
> > final Method method =
> >     MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, DISABLED_PREFIX,
> > String.class, NO_PARAMETERS_TYPES);
> > 
> > for(ObjectMember member: objectSpec.getMembers()) {
> 
> No such method as getMembers() on ObjectSpecification.
> 
> >   FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(method,
> > member);
> > }
> 
> In fact, there is no such method anywhere except in the json applib.
> 
> I'm trying to fetch ObjectMember based on Method... but that's not 
> looking good either! :)
> 
> I understand what you're suggesting, I'm just having difficulties making 
> it so!
> 
> Regards,
> Kevin
> 


--
Kevin Meyer, PhD, Pr.Sci.Nat
KMZ		P.O. Box 9822, Sharon Park, South Africa.
Tel: +27 11 363 2001	Cell: +27 83 346 3045



Re: Help with disabled() on object

Posted by Kevin Meyer - KMZ <ke...@kmz.co.za>.
> Anyway, looking at your code, the reason it isn't working is that you are
> installing the facet onto the object, rather than each of the members.

That is the purpose of it - an object-level disable() (and eventual 
hide(), possibly). 

My reasons for the disable are obvious: Certain objects in my domain 
must only be interacted with via actions (promoteMember() to set the 
member level and log the action, etc) for certain roles, and it's a bit 
tedious putting: String DisableXXX() on every method to runtime 
checking.

As for Hide() - how secure is the HTMLviewer against hacking? Can 
you probe the entity space by spoofing / loading URLs?  I want certain 
objects to be completely invisible to certain roles.

> In the processClassContext(), the problem is that facetHolder is going to
> relate to the ObjectSpecification:
> 
>         if (method != null) {
>             FacetUtil.addFacet(new
> DisabledObjectFacetViaDisabledMethod(method, *facetHolder*));    <<<<<<<
> HERE'S THE PROBLEM

> 
> Instead, you're going to have to hack it a little, by looping through the
> members and installing the facet on each.  It'll be something like:
> 
> for(ObjectMember member: objectSpec.getMembers()) {
>   FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(method,
> member);
> }
> 
> processClassContext.removeMethod(method);

Ah - I understand. Spoof object disabling by installing the same facet 
on all members. Ugly - the object's disabled() method will be called for 
every method in the object.


> As for your hidden() facet, you'll probably need to do something similar.
>  It shouldn't be necessary to hack individual viewers. 
>  A good place to put a break point in order to see the stacktrace is in the
> InteractionUtils class.

Thanks - I realised this morning where a breakpoint would be a good 
idea - create a disabledXXX() method, and see when *IT* is called, 
working upstream of the stacktrace until a suitable loop is found.

BTW: My gut feeling is that hooking into the ObjectMember's 
isUsable()/isVisible() Consent in the metamodel makes more sense? 
Find where the members are iterated through, and don't bother 
checking all members, if the Object-level facet is present?

I'll decide further when I next fire up the IDE - probably tomorrow 
evening or Monday.

Thanks for your help.

Regards,
Kevin



Re: Help with disabled() on object

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
OK, I committed the fix last night.

I did give you a bad steer there... the getAssociations() is empty when
FacetFactory#processClassContext(...) is called because of an ordering
issue.

The fix I chose was to install the DisabledObjectFacet on the ObjectSpec,
and then to additionally have the FacetFactory process the method contexts.
 Here I copy the facet down onto the member.

I did this for HiddenObjectFacet, and also (since I noticed a todo) did
something similar for ImmutableFacet.  Note that I didn't change your
modification for ImmutableFacet only applying to properties/collections;
seemed reasonable to me.

Cheers
Dan

On 6 December 2011 10:01, Dan Haywood <da...@haywood-associates.co.uk> wrote:

> Hi Kevin,
> Had a look at this this morning... and have a fix.  At client site at the
> mo so can't commit, will do this eve with more detail.
> Dan
>
>
> On 5 December 2011 18:23, Kevin Meyer - KMZ <ke...@kmz.co.za> wrote:
>
>> Hi Dan,
>>
>> Thanks for the update. But I still can't get it to work:
>> If you load DisabledObjectViaDisabledMethodFacetFactory, you'll see
>> various attempts in "process" and "addFacetToFacetHolder" (likewise
>> for HiddenObjectViaHiddenMethodFacetFactory).
>>
>> With
>>        ObjectSpecification spec =
>> getSpecificationLookup().loadSpecification(cls);
>>        List<ObjectAssociation> members = spec.getAssociations();
>>
>> members turns out to be empty every time!
>>
>> With
>>         Method methods[] = cls.getMethods();
>>        for (Method method : methods)
>>                 FacetUtil.addFacet(new
>> DisabledObjectFacetViaDisabledMethod(method, member));
>>
>> it doesn't matter which facet I install, its never called.
>>
>> So I have gone back to hacking the HTML viewer to manually looking
>> for DisabledObjectFacet in ObjectView. Naturally, it means the other
>> viewers are oblivious.
>>
>> Regards,
>> Kevin
>>
>>
>> On 5 Dec 2011 at 11:06, Dan Haywood wrote:
>>
>> > Hi Kevin,
>> >
>> > bit rushed to reply in more detail, but the method you need is
>> > getAssociations() (which is inherited by ObjectSpecification from the
>> > superinterface, ObjectAssociationContainer).
>> >
>> > HTH
>> > Dan
>> >
>> >
>> >
>> > Sorry to give you the wrong steer there.
>> >
>> > On 5 December 2011 10:06, Kevin Meyer - KMZ <ke...@kmz.co.za> wrote:
>> >
>> > > Hi Dan,
>> > >
>> > > I'm trying to implement your alternate suggestion, but I'm having
>> > > issues.
>> > >
>> > > On 3 Dec 2011 at 7:03, Dan Haywood wrote:
>> > >
>> > > > final Method method =
>> > > >     MethodFinderUtils.findMethod(cls, MethodScope.OBJECT,
>> > > DISABLED_PREFIX,
>> > > > String.class, NO_PARAMETERS_TYPES);
>> > > >
>> > > > for(ObjectMember member: objectSpec.getMembers()) {
>> > >
>> > > No such method as getMembers() on ObjectSpecification.
>> > >
>> > > >   FacetUtil.addFacet(new
>> DisabledObjectFacetViaDisabledMethod(method,
>> > > > member);
>> > > > }
>> > >
>> > > In fact, there is no such method anywhere except in the json applib.
>> > >
>> > > I'm trying to fetch ObjectMember based on Method... but that's not
>> > > looking good either! :)
>> > >
>> > > I understand what you're suggesting, I'm just having difficulties
>> making
>> > > it so!
>> > >
>> > > Regards,
>> > > Kevin
>>
>>
>

Re: Help with disabled() on object

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
Hi Kevin,
Had a look at this this morning... and have a fix.  At client site at the
mo so can't commit, will do this eve with more detail.
Dan


On 5 December 2011 18:23, Kevin Meyer - KMZ <ke...@kmz.co.za> wrote:

> Hi Dan,
>
> Thanks for the update. But I still can't get it to work:
> If you load DisabledObjectViaDisabledMethodFacetFactory, you'll see
> various attempts in "process" and "addFacetToFacetHolder" (likewise
> for HiddenObjectViaHiddenMethodFacetFactory).
>
> With
>        ObjectSpecification spec =
> getSpecificationLookup().loadSpecification(cls);
>        List<ObjectAssociation> members = spec.getAssociations();
>
> members turns out to be empty every time!
>
> With
>         Method methods[] = cls.getMethods();
>        for (Method method : methods)
>                 FacetUtil.addFacet(new
> DisabledObjectFacetViaDisabledMethod(method, member));
>
> it doesn't matter which facet I install, its never called.
>
> So I have gone back to hacking the HTML viewer to manually looking
> for DisabledObjectFacet in ObjectView. Naturally, it means the other
> viewers are oblivious.
>
> Regards,
> Kevin
>
>
> On 5 Dec 2011 at 11:06, Dan Haywood wrote:
>
> > Hi Kevin,
> >
> > bit rushed to reply in more detail, but the method you need is
> > getAssociations() (which is inherited by ObjectSpecification from the
> > superinterface, ObjectAssociationContainer).
> >
> > HTH
> > Dan
> >
> >
> >
> > Sorry to give you the wrong steer there.
> >
> > On 5 December 2011 10:06, Kevin Meyer - KMZ <ke...@kmz.co.za> wrote:
> >
> > > Hi Dan,
> > >
> > > I'm trying to implement your alternate suggestion, but I'm having
> > > issues.
> > >
> > > On 3 Dec 2011 at 7:03, Dan Haywood wrote:
> > >
> > > > final Method method =
> > > >     MethodFinderUtils.findMethod(cls, MethodScope.OBJECT,
> > > DISABLED_PREFIX,
> > > > String.class, NO_PARAMETERS_TYPES);
> > > >
> > > > for(ObjectMember member: objectSpec.getMembers()) {
> > >
> > > No such method as getMembers() on ObjectSpecification.
> > >
> > > >   FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(method,
> > > > member);
> > > > }
> > >
> > > In fact, there is no such method anywhere except in the json applib.
> > >
> > > I'm trying to fetch ObjectMember based on Method... but that's not
> > > looking good either! :)
> > >
> > > I understand what you're suggesting, I'm just having difficulties
> making
> > > it so!
> > >
> > > Regards,
> > > Kevin
>
>

Re: Help with disabled() on object

Posted by Kevin Meyer - KMZ <ke...@kmz.co.za>.
Hi Dan,

Thanks for the update. But I still can't get it to work:
If you load DisabledObjectViaDisabledMethodFacetFactory, you'll see 
various attempts in "process" and "addFacetToFacetHolder" (likewise 
for HiddenObjectViaHiddenMethodFacetFactory).

With
	ObjectSpecification spec = getSpecificationLookup().loadSpecification(cls);
	List<ObjectAssociation> members = spec.getAssociations();

members turns out to be empty every time!

With 
	Method methods[] = cls.getMethods();
	for (Method method : methods)
		FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(method, member));

it doesn't matter which facet I install, its never called.

So I have gone back to hacking the HTML viewer to manually looking 
for DisabledObjectFacet in ObjectView. Naturally, it means the other 
viewers are oblivious.

Regards,
Kevin


On 5 Dec 2011 at 11:06, Dan Haywood wrote:

> Hi Kevin,
> 
> bit rushed to reply in more detail, but the method you need is
> getAssociations() (which is inherited by ObjectSpecification from the
> superinterface, ObjectAssociationContainer).
> 
> HTH
> Dan
> 
> 
> 
> Sorry to give you the wrong steer there.
> 
> On 5 December 2011 10:06, Kevin Meyer - KMZ <ke...@kmz.co.za> wrote:
> 
> > Hi Dan,
> >
> > I'm trying to implement your alternate suggestion, but I'm having
> > issues.
> >
> > On 3 Dec 2011 at 7:03, Dan Haywood wrote:
> >
> > > final Method method =
> > >     MethodFinderUtils.findMethod(cls, MethodScope.OBJECT,
> > DISABLED_PREFIX,
> > > String.class, NO_PARAMETERS_TYPES);
> > >
> > > for(ObjectMember member: objectSpec.getMembers()) {
> >
> > No such method as getMembers() on ObjectSpecification.
> >
> > >   FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(method,
> > > member);
> > > }
> >
> > In fact, there is no such method anywhere except in the json applib.
> >
> > I'm trying to fetch ObjectMember based on Method... but that's not
> > looking good either! :)
> >
> > I understand what you're suggesting, I'm just having difficulties making
> > it so!
> >
> > Regards,
> > Kevin


Re: Help with disabled() on object

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
Hi Kevin,

bit rushed to reply in more detail, but the method you need is
getAssociations() (which is inherited by ObjectSpecification from the
superinterface, ObjectAssociationContainer).

HTH
Dan



Sorry to give you the wrong steer there.

On 5 December 2011 10:06, Kevin Meyer - KMZ <ke...@kmz.co.za> wrote:

> Hi Dan,
>
> I'm trying to implement your alternate suggestion, but I'm having
> issues.
>
> On 3 Dec 2011 at 7:03, Dan Haywood wrote:
>
> > final Method method =
> >     MethodFinderUtils.findMethod(cls, MethodScope.OBJECT,
> DISABLED_PREFIX,
> > String.class, NO_PARAMETERS_TYPES);
> >
> > for(ObjectMember member: objectSpec.getMembers()) {
>
> No such method as getMembers() on ObjectSpecification.
>
> >   FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(method,
> > member);
> > }
>
> In fact, there is no such method anywhere except in the json applib.
>
> I'm trying to fetch ObjectMember based on Method... but that's not
> looking good either! :)
>
> I understand what you're suggesting, I'm just having difficulties making
> it so!
>
> Regards,
> Kevin
>
>

Re: Help with disabled() on object

Posted by Kevin Meyer - KMZ <ke...@kmz.co.za>.
Hi Dan,

I'm trying to implement your alternate suggestion, but I'm having 
issues.

On 3 Dec 2011 at 7:03, Dan Haywood wrote:

> final Method method =
>     MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, DISABLED_PREFIX,
> String.class, NO_PARAMETERS_TYPES);
> 
> for(ObjectMember member: objectSpec.getMembers()) {

No such method as getMembers() on ObjectSpecification.

>   FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(method,
> member);
> }

In fact, there is no such method anywhere except in the json applib.

I'm trying to fetch ObjectMember based on Method... but that's not 
looking good either! :)

I understand what you're suggesting, I'm just having difficulties making 
it so!

Regards,
Kevin


Re: Help with disabled() on object

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
OK, silly me... I didn't "svn up" properly.

Anyway, looking at your code, the reason it isn't working is that you are
installing the facet onto the object, rather than each of the members.

In the processClassContext(), the problem is that facetHolder is going to
relate to the ObjectSpecification:

    @Override
    public void process(final ProcessClassContext processClassContext) {
        final Class<?> cls = processClassContext.getCls();
        final FacetHolder facetHolder =
processClassContext.getFacetHolder();

        final Method method =
            MethodFinderUtils.findMethod(cls, MethodScope.OBJECT,
DISABLED_PREFIX, String.class, NO_PARAMETERS_TYPES);
        if (method != null) {
            FacetUtil.addFacet(new
DisabledObjectFacetViaDisabledMethod(method, *facetHolder*));    <<<<<<<
HERE'S THE PROBLEM
            processClassContext.removeMethod(method);
        }
    }

Instead, you're going to have to hack it a little, by looping through the
members and installing the facet on each.  It'll be something like:

ObjectSpecification objectSpec =
getSpecificationLoader().loadSpecification(processClassContext.getCls());

final Method method =
    MethodFinderUtils.findMethod(cls, MethodScope.OBJECT, DISABLED_PREFIX,
String.class, NO_PARAMETERS_TYPES);

for(ObjectMember member: objectSpec.getMembers()) {
  FacetUtil.addFacet(new DisabledObjectFacetViaDisabledMethod(method,
member);
}

processClassContext.removeMethod(method);


~~~
As for your hidden() facet, you'll probably need to do something similar.
 It shouldn't be necessary to hack individual viewers.  It also isn't
necessary to manually create an InteractionContext; that is done for you.
 A good place to put a break point in order to see the stacktrace is in the
InteractionUtils class.

HTH
Dan




On 2 December 2011 17:10, Kevin Meyer - KMZ <ke...@kmz.co.za> wrote:

> Hi Dan,
>
> I've (mostly) implemented an equivalent hidden() on object, and I
> discovered that I was missing adding my HiddenMethodFact from the
> metamodel.
>
> Now I got the hidden() method working in the htmlviewer, but it could
> be a bit of a kludge, as this approach would need each viewer to be
> handled specifically.
>
> Anyway - using this knowledge, I went back to the disabled() method,
> and realised that I am probably looking at hooking into the isVetoed
> and equivalent methods in the metamodel, but I can't find where the
> Context is setup and appropriate Facets interrogated.
>
> Where else do I need to add my DisabledObjectFacet so that the
> metamodel picks it up?
>
> Regards,
> Kevin
>
>
> On 30 Nov 2011 at 17:53, Kevin Meyer - KMZ wrote:
>
> > Hi Dan,
> >
> > I remember discussing something like this with you at the Knockree
> > retreat - I've implemented the various classes to support a
> >       String disabled(){..};
> > method on an object, to runtime prevent a user from editting any of the
> > properties.
> >
> > The problem is, it doesn't work! :)
> >
> > Following the examples of the Immutable facet and the "validate"
> > method facet, I have:
> >
> > public class DisabledObjectFacetViaDisabledMethod extends
> DisabledObjectFacetAbstract implements ImperativeFacet
> >
> > where
> >
> > public abstract class DisabledObjectFacetAbstract extends FacetAbstract
> implements DisabledObjectFacet
> >
> > and
> >
> > public interface DisabledObjectFacet extends Facet,
> DisablingInteractionAdvisor
> >
> > The factory is registered in ProgrammingModelFacetsJava5:
> >      addFactory(DisabledObjectViaDisabledMethodFacetFactory.class);
> >
> > But when I load an object with the "disabled()" method, I can still edit
> it.
> > The "disabled" method is not visible, so it's being picked up...
> >
> > This tells me that the "DisablingInteractionAdvisor " is not doing what I
> > expect..
> >
> > What am I missing?
> >
> >
> > Since the unit test passes, I'll check in the code, associated with
> > ISIS-142
> >
> > Regards,
> > Kevin
> >
>
>
> --
> Kevin Meyer, PhD, Pr.Sci.Nat
> KMZ             P.O. Box 9822, Sharon Park, South Africa.
> Tel: +27 11 363 2001   Cell: +27 83 346 3045
>
>
>