You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@isis.apache.org by Nacho Cánovas Rejón <n....@gesconsultor.com> on 2015/08/20 10:39:45 UTC

ISIS-1044 issue with Collections

Hi Dan.

In order to test new changes on 1.9.0 release, I think I find some bug.

My problem is in "*ISIS-1044: fixing by filtering the 
PropertyAccessorFacet and CollectionAccessorFacet, also the 
ActionInvocationFacet (for contributed collections/properties):*" issue.

You modified "*getProperty*" method on class 
"*CollectionAccessorFacetViaAccessor*". I show you the code:

*OLD Code*

final Object collectionOrArray = 
ObjectAdapter.InvokeUtils.invoke(method, owningAdapter);

*NEW Code*

final Object collectionOrArray = 
ObjectAdapter.InvokeUtils.invoke(method, owningAdapter);

final ObjectAdapter collectionAdapter = 
getAdapterManager().adapterFor(collectionOrArray);

final FacetedMethod facetedMethod = (FacetedMethod) getFacetHolder();
final Class<?> collectionElementType = facetedMethod.getType();

final List<ObjectAdapter> visibleAdapters =
         ObjectAdapter.Util.visibleAdapters(
                 collectionAdapter,
                 authenticationSession, deploymentCategory);
final List<Object> visibleObjects = Lists.newArrayList(
         Iterables.transform(visibleAdapters, 
ObjectAdapter.Functions.getObject()));

return visibleObjects;

Now I explain my problem.

I have for example  this property defined in one of my entities.

private SortedSet<Product> customSelectedProducts = new TreeSet<Product>();

public SortedSet<Product> getCustomSelectedProducts() {
     return this.customSelectedProducts;
}

public void setCustomSelectedProducts(
         final SortedSet<Product> customSelectedProducts) {
     this.customSelectedProducts = customSelectedProducts;
}

And when I try to get his value, I received:

java.lang.ClassCastException: java.util.ArrayList cannot be cast to 
java.util.SortedSet

You will see that you return always an ArrayList when it's a Collection, 
but maybe there is other kind of collections (SortedSet in my case) and 
it will failed on get method.

I did some dirty and not to well modification for performance to work 
with it in order to advance changing next code:

final List<Object> visibleObjects = Lists.newArrayList(
         Iterables.transform(visibleAdapters, 
ObjectAdapter.Functions.getObject()));

return visibleObjects;
*
**to*

((Collection) collectionOrArray).clear();
((Collection) collectionOrArray).addAll(Lists.newArrayList(
         Iterables.transform(visibleAdapters, 
ObjectAdapter.Functions.getObject())));

return collectionOrArray;

I have the same problem in method "*invoke*" from class 
"*ActionInvocationFacetForDomainEventAbstract*" and I fixed it with a 
similar way than last mail:

final List<Object> visibleObjects =
         Lists.newArrayList(Lists.transform(
                 visibleAdapters, ObjectAdapter.Functions.getObject()));
final ObjectAdapter visibleObjectsAsAdapter = 
getAdapterManager().adapterFor(visibleObjects);

*to*

((Collection<Object>) result).clear();
((Collection<Object>) 
result).addAll(Lists.newArrayList(Lists.transform(visibleAdapters, 
ObjectAdapter.Functions.getObject())));

final ObjectAdapter visibleObjectsAsAdapter = 
this.getAdapterManager().adapterFor(result);

I hope you're well.

Best regards and thanks.

-- 
Ignacio Cánovas Rejón
Tel. 902 900 231
Fax  96 353 19 09
n.canovas@gesconsultor.com
www.gesconsultor.com

Este mensaje y los ficheros anexos son confidenciales. Los mismos contienen información reservada que no puede ser difundida. Si usted ha recibido este correo por error, tenga la amabilidad de eliminarlo de su sistema y avisar al remitente mediante reenvío a su dirección electrónica; no deberá copiar el mensaje ni divulgar su contenido a ninguna persona.

Su dirección de correo electrónico junto a sus datos personales constan en un fichero titularidad de GESDATOS SOFTWARE S.L. cuya finalidad es la de mantener el contacto con Ud. Si quiere saber de qué información disponemos de Ud., modificarla, y en su caso, cancelarla, puede hacerlo enviando un escrito al efecto, acompañado de una fotocopia de su D.N.I. a la siguiente dirección: GESDATOS SOFTWARE S.L. Av. Cortes Valencianas 50-1º-C, C.P.  46015 de Valencia. Asimismo, es su responsabilidad comprobar que este mensaje o sus archivos adjuntos no contengan virus informáticos, y en caso que los tuvieran eliminarlos.



---
El software de antivirus Avast ha analizado este correo electrónico en busca de virus.
http://www.avast.com

Re: ISIS-1044 issue with Collections

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
Many thanks, Nacho.

Cheers
Dan

On 25 August 2015 at 07:05, Nacho Cánovas Rejón <n....@gesconsultor.com>
wrote:

> Hi Dan.
>
> I ran my tests and all are going well, so you can close this subject.
>
> Thanks very much.
>
> Best regards.
>
>
> El 25/08/2015 a las 7:21, Dan Haywood escribió:
>
>> Further to this, as an additional "safety measure" I've introduced three
>> new configuration properties that allow this visibilty filtering to be
>> disabled.  They are documented at [1], [2].
>>
>> I've left the feature as enabled by default because I don't believe there
>> are any adverse side-effects from having it enabled.  In particular, the
>> WrapperFactory, as used in integration tests and elsewhere - should still
>> work ok.
>>
>> Thanks
>> Dan
>>
>> [1] http://isis.apache.org/guides/rg.html#_rg_runtime_configuring-core
>> [2]
>>
>> http://isis.apache.org/guides/rg.html#_rg_runtime_configuring-core_filterVisibility
>>
>>
>>
>> On 23 August 2015 at 18:24, Dan Haywood <da...@haywood-associates.co.uk>
>> wrote:
>>
>> Hi Nacho (and Oscar)...
>>>
>>> OK, I've pushed a commit... [1] could you retest?
>>>
>>> You'll see that I didn't got with your design... doing a clear() and
>>> addAll() on the collection returned by DataNucleus (for a regular managed
>>> "parented" collection) might result in unexpected side effects.  So
>>> instead
>>> the code always returns a copy of the collection, with just the visible
>>> objects.  However, it now takes care to ensure that the compile time type
>>> of that collection is compatible with the underlying method's return
>>> type.
>>>
>>> One thing I wasn't completely certain on is what to do if the method's
>>> return type isn't one of the standard ones (List, Set, SortedSet,
>>> ArrayList, Collection etc).  I decided to revert to returning the
>>> unfiltered collection, but an alternative design would be to fail fast.
>>> Opinions welcome.
>>>
>>> If this all works ok, then I'll cut a release.
>>>
>>> Thanks
>>> Dan
>>>
>>>
>>> [1]
>>>
>>> https://github.com/apache/isis/commit/9417a0d01608ba640b881e391be8c8b0529b1321
>>>
>>>
>>> On 20 August 2015 at 10:15, Dan Haywood <da...@haywood-associates.co.uk>
>>> wrote:
>>>
>>> Hi Nacho,
>>>>
>>>> Thanks for checking this out, and you are right, of course... the code
>>>> should take the return type of the getter into account.
>>>>
>>>> I'll tidy up your code by way of a fix.
>>>>
>>>> Thanks again,
>>>> Dan
>>>> On 20 Aug 2015 09:40, "Nacho Cánovas Rejón" <n.canovas@gesconsultor.com
>>>> >
>>>> wrote:
>>>>
>>>> Hi Dan.
>>>>>
>>>>> In order to test new changes on 1.9.0 release, I think I find some bug.
>>>>>
>>>>> My problem is in "*ISIS-1044: fixing by filtering the
>>>>> PropertyAccessorFacet and CollectionAccessorFacet, also the
>>>>> ActionInvocationFacet (for contributed collections/properties):*"
>>>>> issue.
>>>>>
>>>>> You modified "*getProperty*" method on class
>>>>> "*CollectionAccessorFacetViaAccessor*". I show you the code:
>>>>>
>>>>> *OLD Code*
>>>>>
>>>>> final Object collectionOrArray =
>>>>> ObjectAdapter.InvokeUtils.invoke(method, owningAdapter);
>>>>>
>>>>> *NEW Code*
>>>>>
>>>>> final Object collectionOrArray =
>>>>> ObjectAdapter.InvokeUtils.invoke(method, owningAdapter);
>>>>>
>>>>> final ObjectAdapter collectionAdapter =
>>>>> getAdapterManager().adapterFor(collectionOrArray);
>>>>>
>>>>> final FacetedMethod facetedMethod = (FacetedMethod) getFacetHolder();
>>>>> final Class<?> collectionElementType = facetedMethod.getType();
>>>>>
>>>>> final List<ObjectAdapter> visibleAdapters =
>>>>>          ObjectAdapter.Util.visibleAdapters(
>>>>>                  collectionAdapter,
>>>>>                  authenticationSession, deploymentCategory);
>>>>> final List<Object> visibleObjects = Lists.newArrayList(
>>>>>          Iterables.transform(visibleAdapters,
>>>>> ObjectAdapter.Functions.getObject()));
>>>>>
>>>>> return visibleObjects;
>>>>>
>>>>> Now I explain my problem.
>>>>>
>>>>> I have for example  this property defined in one of my entities.
>>>>>
>>>>> private SortedSet<Product> customSelectedProducts = new
>>>>> TreeSet<Product>();
>>>>>
>>>>> public SortedSet<Product> getCustomSelectedProducts() {
>>>>>      return this.customSelectedProducts;
>>>>> }
>>>>>
>>>>> public void setCustomSelectedProducts(
>>>>>          final SortedSet<Product> customSelectedProducts) {
>>>>>      this.customSelectedProducts = customSelectedProducts;
>>>>> }
>>>>>
>>>>> And when I try to get his value, I received:
>>>>>
>>>>> java.lang.ClassCastException: java.util.ArrayList cannot be cast to
>>>>> java.util.SortedSet
>>>>>
>>>>> You will see that you return always an ArrayList when it's a
>>>>> Collection,
>>>>> but maybe there is other kind of collections (SortedSet in my case)
>>>>> and it
>>>>> will failed on get method.
>>>>>
>>>>> I did some dirty and not to well modification for performance to work
>>>>> with it in order to advance changing next code:
>>>>>
>>>>> final List<Object> visibleObjects = Lists.newArrayList(
>>>>>          Iterables.transform(visibleAdapters,
>>>>> ObjectAdapter.Functions.getObject()));
>>>>>
>>>>> return visibleObjects;
>>>>> *
>>>>> **to*
>>>>>
>>>>> ((Collection) collectionOrArray).clear();
>>>>> ((Collection) collectionOrArray).addAll(Lists.newArrayList(
>>>>>          Iterables.transform(visibleAdapters,
>>>>> ObjectAdapter.Functions.getObject())));
>>>>>
>>>>> return collectionOrArray;
>>>>>
>>>>> I have the same problem in method "*invoke*" from class
>>>>> "*ActionInvocationFacetForDomainEventAbstract*" and I fixed it with a
>>>>> similar way than last mail:
>>>>>
>>>>> final List<Object> visibleObjects =
>>>>>          Lists.newArrayList(Lists.transform(
>>>>>                  visibleAdapters,
>>>>> ObjectAdapter.Functions.getObject()));
>>>>> final ObjectAdapter visibleObjectsAsAdapter =
>>>>> getAdapterManager().adapterFor(visibleObjects);
>>>>>
>>>>> *to*
>>>>>
>>>>> ((Collection<Object>) result).clear();
>>>>> ((Collection<Object>)
>>>>> result).addAll(Lists.newArrayList(Lists.transform(visibleAdapters,
>>>>> ObjectAdapter.Functions.getObject())));
>>>>>
>>>>> final ObjectAdapter visibleObjectsAsAdapter =
>>>>> this.getAdapterManager().adapterFor(result);
>>>>>
>>>>> I hope you're well.
>>>>>
>>>>> Best regards and thanks.
>>>>>
>>>>> --
>>>>> Ignacio Cánovas Rejón
>>>>> Tel. 902 900 231
>>>>> Fax  96 353 19 09
>>>>> n.canovas@gesconsultor.com
>>>>> www.gesconsultor.com
>>>>>
>>>>> Este mensaje y los ficheros anexos son confidenciales. Los mismos
>>>>> contienen información reservada que no puede ser difundida. Si usted ha
>>>>> recibido este correo por error, tenga la amabilidad de eliminarlo de su
>>>>> sistema y avisar al remitente mediante reenvío a su dirección
>>>>> electrónica;
>>>>> no deberá copiar el mensaje ni divulgar su contenido a ninguna persona.
>>>>>
>>>>> Su dirección de correo electrónico junto a sus datos personales constan
>>>>> en un fichero titularidad de GESDATOS SOFTWARE S.L. cuya finalidad es
>>>>> la de
>>>>> mantener el contacto con Ud. Si quiere saber de qué información
>>>>> disponemos
>>>>> de Ud., modificarla, y en su caso, cancelarla, puede hacerlo enviando
>>>>> un
>>>>> escrito al efecto, acompañado de una fotocopia de su D.N.I. a la
>>>>> siguiente
>>>>> dirección: GESDATOS SOFTWARE S.L. Av. Cortes Valencianas 50-1º-C, C.P.
>>>>> 46015 de Valencia. Asimismo, es su responsabilidad comprobar que este
>>>>> mensaje o sus archivos adjuntos no contengan virus informáticos, y en
>>>>> caso
>>>>> que los tuvieran eliminarlos.
>>>>>
>>>>>
>>>>>
>>>>> ---
>>>>> El software de antivirus Avast ha analizado este correo electrónico en
>>>>> busca de virus.
>>>>> http://www.avast.com
>>>>>
>>>>>
>
> --
> Ignacio Cánovas Rejón
> Tel. 902 900 231
> Fax  96 353 19 09
> n.canovas@gesconsultor.com
> www.gesconsultor.com
>
> Este mensaje y los ficheros anexos son confidenciales. Los mismos
> contienen información reservada que no puede ser difundida. Si usted ha
> recibido este correo por error, tenga la amabilidad de eliminarlo de su
> sistema y avisar al remitente mediante reenvío a su dirección electrónica;
> no deberá copiar el mensaje ni divulgar su contenido a ninguna persona.
>
> Su dirección de correo electrónico junto a sus datos personales constan en
> un fichero titularidad de GESDATOS SOFTWARE S.L. cuya finalidad es la de
> mantener el contacto con Ud. Si quiere saber de qué información disponemos
> de Ud., modificarla, y en su caso, cancelarla, puede hacerlo enviando un
> escrito al efecto, acompañado de una fotocopia de su D.N.I. a la siguiente
> dirección: GESDATOS SOFTWARE S.L. Av. Cortes Valencianas 50-1º-C, C.P.
> 46015 de Valencia. Asimismo, es su responsabilidad comprobar que este
> mensaje o sus archivos adjuntos no contengan virus informáticos, y en caso
> que los tuvieran eliminarlos.
>
>
> ---
> El software de antivirus Avast ha analizado este correo electrónico en
> busca de virus.
> http://www.avast.com
>
>

Re: ISIS-1044 issue with Collections

Posted by Nacho Cánovas Rejón <n....@gesconsultor.com>.
Hi Dan.

I ran my tests and all are going well, so you can close this subject.

Thanks very much.

Best regards.

El 25/08/2015 a las 7:21, Dan Haywood escribió:
> Further to this, as an additional "safety measure" I've introduced three
> new configuration properties that allow this visibilty filtering to be
> disabled.  They are documented at [1], [2].
>
> I've left the feature as enabled by default because I don't believe there
> are any adverse side-effects from having it enabled.  In particular, the
> WrapperFactory, as used in integration tests and elsewhere - should still
> work ok.
>
> Thanks
> Dan
>
> [1] http://isis.apache.org/guides/rg.html#_rg_runtime_configuring-core
> [2]
> http://isis.apache.org/guides/rg.html#_rg_runtime_configuring-core_filterVisibility
>
>
>
> On 23 August 2015 at 18:24, Dan Haywood <da...@haywood-associates.co.uk>
> wrote:
>
>> Hi Nacho (and Oscar)...
>>
>> OK, I've pushed a commit... [1] could you retest?
>>
>> You'll see that I didn't got with your design... doing a clear() and
>> addAll() on the collection returned by DataNucleus (for a regular managed
>> "parented" collection) might result in unexpected side effects.  So instead
>> the code always returns a copy of the collection, with just the visible
>> objects.  However, it now takes care to ensure that the compile time type
>> of that collection is compatible with the underlying method's return type.
>>
>> One thing I wasn't completely certain on is what to do if the method's
>> return type isn't one of the standard ones (List, Set, SortedSet,
>> ArrayList, Collection etc).  I decided to revert to returning the
>> unfiltered collection, but an alternative design would be to fail fast.
>> Opinions welcome.
>>
>> If this all works ok, then I'll cut a release.
>>
>> Thanks
>> Dan
>>
>>
>> [1]
>> https://github.com/apache/isis/commit/9417a0d01608ba640b881e391be8c8b0529b1321
>>
>>
>> On 20 August 2015 at 10:15, Dan Haywood <da...@haywood-associates.co.uk>
>> wrote:
>>
>>> Hi Nacho,
>>>
>>> Thanks for checking this out, and you are right, of course... the code
>>> should take the return type of the getter into account.
>>>
>>> I'll tidy up your code by way of a fix.
>>>
>>> Thanks again,
>>> Dan
>>> On 20 Aug 2015 09:40, "Nacho Cánovas Rejón" <n....@gesconsultor.com>
>>> wrote:
>>>
>>>> Hi Dan.
>>>>
>>>> In order to test new changes on 1.9.0 release, I think I find some bug.
>>>>
>>>> My problem is in "*ISIS-1044: fixing by filtering the
>>>> PropertyAccessorFacet and CollectionAccessorFacet, also the
>>>> ActionInvocationFacet (for contributed collections/properties):*" issue.
>>>>
>>>> You modified "*getProperty*" method on class
>>>> "*CollectionAccessorFacetViaAccessor*". I show you the code:
>>>>
>>>> *OLD Code*
>>>>
>>>> final Object collectionOrArray =
>>>> ObjectAdapter.InvokeUtils.invoke(method, owningAdapter);
>>>>
>>>> *NEW Code*
>>>>
>>>> final Object collectionOrArray =
>>>> ObjectAdapter.InvokeUtils.invoke(method, owningAdapter);
>>>>
>>>> final ObjectAdapter collectionAdapter =
>>>> getAdapterManager().adapterFor(collectionOrArray);
>>>>
>>>> final FacetedMethod facetedMethod = (FacetedMethod) getFacetHolder();
>>>> final Class<?> collectionElementType = facetedMethod.getType();
>>>>
>>>> final List<ObjectAdapter> visibleAdapters =
>>>>          ObjectAdapter.Util.visibleAdapters(
>>>>                  collectionAdapter,
>>>>                  authenticationSession, deploymentCategory);
>>>> final List<Object> visibleObjects = Lists.newArrayList(
>>>>          Iterables.transform(visibleAdapters,
>>>> ObjectAdapter.Functions.getObject()));
>>>>
>>>> return visibleObjects;
>>>>
>>>> Now I explain my problem.
>>>>
>>>> I have for example  this property defined in one of my entities.
>>>>
>>>> private SortedSet<Product> customSelectedProducts = new
>>>> TreeSet<Product>();
>>>>
>>>> public SortedSet<Product> getCustomSelectedProducts() {
>>>>      return this.customSelectedProducts;
>>>> }
>>>>
>>>> public void setCustomSelectedProducts(
>>>>          final SortedSet<Product> customSelectedProducts) {
>>>>      this.customSelectedProducts = customSelectedProducts;
>>>> }
>>>>
>>>> And when I try to get his value, I received:
>>>>
>>>> java.lang.ClassCastException: java.util.ArrayList cannot be cast to
>>>> java.util.SortedSet
>>>>
>>>> You will see that you return always an ArrayList when it's a Collection,
>>>> but maybe there is other kind of collections (SortedSet in my case) and it
>>>> will failed on get method.
>>>>
>>>> I did some dirty and not to well modification for performance to work
>>>> with it in order to advance changing next code:
>>>>
>>>> final List<Object> visibleObjects = Lists.newArrayList(
>>>>          Iterables.transform(visibleAdapters,
>>>> ObjectAdapter.Functions.getObject()));
>>>>
>>>> return visibleObjects;
>>>> *
>>>> **to*
>>>>
>>>> ((Collection) collectionOrArray).clear();
>>>> ((Collection) collectionOrArray).addAll(Lists.newArrayList(
>>>>          Iterables.transform(visibleAdapters,
>>>> ObjectAdapter.Functions.getObject())));
>>>>
>>>> return collectionOrArray;
>>>>
>>>> I have the same problem in method "*invoke*" from class
>>>> "*ActionInvocationFacetForDomainEventAbstract*" and I fixed it with a
>>>> similar way than last mail:
>>>>
>>>> final List<Object> visibleObjects =
>>>>          Lists.newArrayList(Lists.transform(
>>>>                  visibleAdapters, ObjectAdapter.Functions.getObject()));
>>>> final ObjectAdapter visibleObjectsAsAdapter =
>>>> getAdapterManager().adapterFor(visibleObjects);
>>>>
>>>> *to*
>>>>
>>>> ((Collection<Object>) result).clear();
>>>> ((Collection<Object>)
>>>> result).addAll(Lists.newArrayList(Lists.transform(visibleAdapters,
>>>> ObjectAdapter.Functions.getObject())));
>>>>
>>>> final ObjectAdapter visibleObjectsAsAdapter =
>>>> this.getAdapterManager().adapterFor(result);
>>>>
>>>> I hope you're well.
>>>>
>>>> Best regards and thanks.
>>>>
>>>> --
>>>> Ignacio Cánovas Rejón
>>>> Tel. 902 900 231
>>>> Fax  96 353 19 09
>>>> n.canovas@gesconsultor.com
>>>> www.gesconsultor.com
>>>>
>>>> Este mensaje y los ficheros anexos son confidenciales. Los mismos
>>>> contienen información reservada que no puede ser difundida. Si usted ha
>>>> recibido este correo por error, tenga la amabilidad de eliminarlo de su
>>>> sistema y avisar al remitente mediante reenvío a su dirección electrónica;
>>>> no deberá copiar el mensaje ni divulgar su contenido a ninguna persona.
>>>>
>>>> Su dirección de correo electrónico junto a sus datos personales constan
>>>> en un fichero titularidad de GESDATOS SOFTWARE S.L. cuya finalidad es la de
>>>> mantener el contacto con Ud. Si quiere saber de qué información disponemos
>>>> de Ud., modificarla, y en su caso, cancelarla, puede hacerlo enviando un
>>>> escrito al efecto, acompañado de una fotocopia de su D.N.I. a la siguiente
>>>> dirección: GESDATOS SOFTWARE S.L. Av. Cortes Valencianas 50-1º-C, C.P.
>>>> 46015 de Valencia. Asimismo, es su responsabilidad comprobar que este
>>>> mensaje o sus archivos adjuntos no contengan virus informáticos, y en caso
>>>> que los tuvieran eliminarlos.
>>>>
>>>>
>>>>
>>>> ---
>>>> El software de antivirus Avast ha analizado este correo electrónico en
>>>> busca de virus.
>>>> http://www.avast.com
>>>>


-- 
Ignacio Cánovas Rejón
Tel. 902 900 231
Fax  96 353 19 09
n.canovas@gesconsultor.com
www.gesconsultor.com

Este mensaje y los ficheros anexos son confidenciales. Los mismos contienen información reservada que no puede ser difundida. Si usted ha recibido este correo por error, tenga la amabilidad de eliminarlo de su sistema y avisar al remitente mediante reenvío a su dirección electrónica; no deberá copiar el mensaje ni divulgar su contenido a ninguna persona.

Su dirección de correo electrónico junto a sus datos personales constan en un fichero titularidad de GESDATOS SOFTWARE S.L. cuya finalidad es la de mantener el contacto con Ud. Si quiere saber de qué información disponemos de Ud., modificarla, y en su caso, cancelarla, puede hacerlo enviando un escrito al efecto, acompañado de una fotocopia de su D.N.I. a la siguiente dirección: GESDATOS SOFTWARE S.L. Av. Cortes Valencianas 50-1º-C, C.P.  46015 de Valencia. Asimismo, es su responsabilidad comprobar que este mensaje o sus archivos adjuntos no contengan virus informáticos, y en caso que los tuvieran eliminarlos.


---
El software de antivirus Avast ha analizado este correo electrónico en busca de virus.
http://www.avast.com


Re: ISIS-1044 issue with Collections

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
Further to this, as an additional "safety measure" I've introduced three
new configuration properties that allow this visibilty filtering to be
disabled.  They are documented at [1], [2].

I've left the feature as enabled by default because I don't believe there
are any adverse side-effects from having it enabled.  In particular, the
WrapperFactory, as used in integration tests and elsewhere - should still
work ok.

Thanks
Dan

[1] http://isis.apache.org/guides/rg.html#_rg_runtime_configuring-core
[2]
http://isis.apache.org/guides/rg.html#_rg_runtime_configuring-core_filterVisibility



On 23 August 2015 at 18:24, Dan Haywood <da...@haywood-associates.co.uk>
wrote:

> Hi Nacho (and Oscar)...
>
> OK, I've pushed a commit... [1] could you retest?
>
> You'll see that I didn't got with your design... doing a clear() and
> addAll() on the collection returned by DataNucleus (for a regular managed
> "parented" collection) might result in unexpected side effects.  So instead
> the code always returns a copy of the collection, with just the visible
> objects.  However, it now takes care to ensure that the compile time type
> of that collection is compatible with the underlying method's return type.
>
> One thing I wasn't completely certain on is what to do if the method's
> return type isn't one of the standard ones (List, Set, SortedSet,
> ArrayList, Collection etc).  I decided to revert to returning the
> unfiltered collection, but an alternative design would be to fail fast.
> Opinions welcome.
>
> If this all works ok, then I'll cut a release.
>
> Thanks
> Dan
>
>
> [1]
> https://github.com/apache/isis/commit/9417a0d01608ba640b881e391be8c8b0529b1321
>
>
> On 20 August 2015 at 10:15, Dan Haywood <da...@haywood-associates.co.uk>
> wrote:
>
>> Hi Nacho,
>>
>> Thanks for checking this out, and you are right, of course... the code
>> should take the return type of the getter into account.
>>
>> I'll tidy up your code by way of a fix.
>>
>> Thanks again,
>> Dan
>> On 20 Aug 2015 09:40, "Nacho Cánovas Rejón" <n....@gesconsultor.com>
>> wrote:
>>
>>> Hi Dan.
>>>
>>> In order to test new changes on 1.9.0 release, I think I find some bug.
>>>
>>> My problem is in "*ISIS-1044: fixing by filtering the
>>> PropertyAccessorFacet and CollectionAccessorFacet, also the
>>> ActionInvocationFacet (for contributed collections/properties):*" issue.
>>>
>>> You modified "*getProperty*" method on class
>>> "*CollectionAccessorFacetViaAccessor*". I show you the code:
>>>
>>> *OLD Code*
>>>
>>> final Object collectionOrArray =
>>> ObjectAdapter.InvokeUtils.invoke(method, owningAdapter);
>>>
>>> *NEW Code*
>>>
>>> final Object collectionOrArray =
>>> ObjectAdapter.InvokeUtils.invoke(method, owningAdapter);
>>>
>>> final ObjectAdapter collectionAdapter =
>>> getAdapterManager().adapterFor(collectionOrArray);
>>>
>>> final FacetedMethod facetedMethod = (FacetedMethod) getFacetHolder();
>>> final Class<?> collectionElementType = facetedMethod.getType();
>>>
>>> final List<ObjectAdapter> visibleAdapters =
>>>         ObjectAdapter.Util.visibleAdapters(
>>>                 collectionAdapter,
>>>                 authenticationSession, deploymentCategory);
>>> final List<Object> visibleObjects = Lists.newArrayList(
>>>         Iterables.transform(visibleAdapters,
>>> ObjectAdapter.Functions.getObject()));
>>>
>>> return visibleObjects;
>>>
>>> Now I explain my problem.
>>>
>>> I have for example  this property defined in one of my entities.
>>>
>>> private SortedSet<Product> customSelectedProducts = new
>>> TreeSet<Product>();
>>>
>>> public SortedSet<Product> getCustomSelectedProducts() {
>>>     return this.customSelectedProducts;
>>> }
>>>
>>> public void setCustomSelectedProducts(
>>>         final SortedSet<Product> customSelectedProducts) {
>>>     this.customSelectedProducts = customSelectedProducts;
>>> }
>>>
>>> And when I try to get his value, I received:
>>>
>>> java.lang.ClassCastException: java.util.ArrayList cannot be cast to
>>> java.util.SortedSet
>>>
>>> You will see that you return always an ArrayList when it's a Collection,
>>> but maybe there is other kind of collections (SortedSet in my case) and it
>>> will failed on get method.
>>>
>>> I did some dirty and not to well modification for performance to work
>>> with it in order to advance changing next code:
>>>
>>> final List<Object> visibleObjects = Lists.newArrayList(
>>>         Iterables.transform(visibleAdapters,
>>> ObjectAdapter.Functions.getObject()));
>>>
>>> return visibleObjects;
>>> *
>>> **to*
>>>
>>> ((Collection) collectionOrArray).clear();
>>> ((Collection) collectionOrArray).addAll(Lists.newArrayList(
>>>         Iterables.transform(visibleAdapters,
>>> ObjectAdapter.Functions.getObject())));
>>>
>>> return collectionOrArray;
>>>
>>> I have the same problem in method "*invoke*" from class
>>> "*ActionInvocationFacetForDomainEventAbstract*" and I fixed it with a
>>> similar way than last mail:
>>>
>>> final List<Object> visibleObjects =
>>>         Lists.newArrayList(Lists.transform(
>>>                 visibleAdapters, ObjectAdapter.Functions.getObject()));
>>> final ObjectAdapter visibleObjectsAsAdapter =
>>> getAdapterManager().adapterFor(visibleObjects);
>>>
>>> *to*
>>>
>>> ((Collection<Object>) result).clear();
>>> ((Collection<Object>)
>>> result).addAll(Lists.newArrayList(Lists.transform(visibleAdapters,
>>> ObjectAdapter.Functions.getObject())));
>>>
>>> final ObjectAdapter visibleObjectsAsAdapter =
>>> this.getAdapterManager().adapterFor(result);
>>>
>>> I hope you're well.
>>>
>>> Best regards and thanks.
>>>
>>> --
>>> Ignacio Cánovas Rejón
>>> Tel. 902 900 231
>>> Fax  96 353 19 09
>>> n.canovas@gesconsultor.com
>>> www.gesconsultor.com
>>>
>>> Este mensaje y los ficheros anexos son confidenciales. Los mismos
>>> contienen información reservada que no puede ser difundida. Si usted ha
>>> recibido este correo por error, tenga la amabilidad de eliminarlo de su
>>> sistema y avisar al remitente mediante reenvío a su dirección electrónica;
>>> no deberá copiar el mensaje ni divulgar su contenido a ninguna persona.
>>>
>>> Su dirección de correo electrónico junto a sus datos personales constan
>>> en un fichero titularidad de GESDATOS SOFTWARE S.L. cuya finalidad es la de
>>> mantener el contacto con Ud. Si quiere saber de qué información disponemos
>>> de Ud., modificarla, y en su caso, cancelarla, puede hacerlo enviando un
>>> escrito al efecto, acompañado de una fotocopia de su D.N.I. a la siguiente
>>> dirección: GESDATOS SOFTWARE S.L. Av. Cortes Valencianas 50-1º-C, C.P.
>>> 46015 de Valencia. Asimismo, es su responsabilidad comprobar que este
>>> mensaje o sus archivos adjuntos no contengan virus informáticos, y en caso
>>> que los tuvieran eliminarlos.
>>>
>>>
>>>
>>> ---
>>> El software de antivirus Avast ha analizado este correo electrónico en
>>> busca de virus.
>>> http://www.avast.com
>>>
>>
>

Re: ISIS-1044 issue with Collections

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
Hi Nacho (and Oscar)...

OK, I've pushed a commit... [1] could you retest?

You'll see that I didn't got with your design... doing a clear() and
addAll() on the collection returned by DataNucleus (for a regular managed
"parented" collection) might result in unexpected side effects.  So instead
the code always returns a copy of the collection, with just the visible
objects.  However, it now takes care to ensure that the compile time type
of that collection is compatible with the underlying method's return type.

One thing I wasn't completely certain on is what to do if the method's
return type isn't one of the standard ones (List, Set, SortedSet,
ArrayList, Collection etc).  I decided to revert to returning the
unfiltered collection, but an alternative design would be to fail fast.
Opinions welcome.

If this all works ok, then I'll cut a release.

Thanks
Dan


[1]
https://github.com/apache/isis/commit/9417a0d01608ba640b881e391be8c8b0529b1321


On 20 August 2015 at 10:15, Dan Haywood <da...@haywood-associates.co.uk>
wrote:

> Hi Nacho,
>
> Thanks for checking this out, and you are right, of course... the code
> should take the return type of the getter into account.
>
> I'll tidy up your code by way of a fix.
>
> Thanks again,
> Dan
> On 20 Aug 2015 09:40, "Nacho Cánovas Rejón" <n....@gesconsultor.com>
> wrote:
>
>> Hi Dan.
>>
>> In order to test new changes on 1.9.0 release, I think I find some bug.
>>
>> My problem is in "*ISIS-1044: fixing by filtering the
>> PropertyAccessorFacet and CollectionAccessorFacet, also the
>> ActionInvocationFacet (for contributed collections/properties):*" issue.
>>
>> You modified "*getProperty*" method on class
>> "*CollectionAccessorFacetViaAccessor*". I show you the code:
>>
>> *OLD Code*
>>
>> final Object collectionOrArray = ObjectAdapter.InvokeUtils.invoke(method,
>> owningAdapter);
>>
>> *NEW Code*
>>
>> final Object collectionOrArray = ObjectAdapter.InvokeUtils.invoke(method,
>> owningAdapter);
>>
>> final ObjectAdapter collectionAdapter =
>> getAdapterManager().adapterFor(collectionOrArray);
>>
>> final FacetedMethod facetedMethod = (FacetedMethod) getFacetHolder();
>> final Class<?> collectionElementType = facetedMethod.getType();
>>
>> final List<ObjectAdapter> visibleAdapters =
>>         ObjectAdapter.Util.visibleAdapters(
>>                 collectionAdapter,
>>                 authenticationSession, deploymentCategory);
>> final List<Object> visibleObjects = Lists.newArrayList(
>>         Iterables.transform(visibleAdapters,
>> ObjectAdapter.Functions.getObject()));
>>
>> return visibleObjects;
>>
>> Now I explain my problem.
>>
>> I have for example  this property defined in one of my entities.
>>
>> private SortedSet<Product> customSelectedProducts = new
>> TreeSet<Product>();
>>
>> public SortedSet<Product> getCustomSelectedProducts() {
>>     return this.customSelectedProducts;
>> }
>>
>> public void setCustomSelectedProducts(
>>         final SortedSet<Product> customSelectedProducts) {
>>     this.customSelectedProducts = customSelectedProducts;
>> }
>>
>> And when I try to get his value, I received:
>>
>> java.lang.ClassCastException: java.util.ArrayList cannot be cast to
>> java.util.SortedSet
>>
>> You will see that you return always an ArrayList when it's a Collection,
>> but maybe there is other kind of collections (SortedSet in my case) and it
>> will failed on get method.
>>
>> I did some dirty and not to well modification for performance to work
>> with it in order to advance changing next code:
>>
>> final List<Object> visibleObjects = Lists.newArrayList(
>>         Iterables.transform(visibleAdapters,
>> ObjectAdapter.Functions.getObject()));
>>
>> return visibleObjects;
>> *
>> **to*
>>
>> ((Collection) collectionOrArray).clear();
>> ((Collection) collectionOrArray).addAll(Lists.newArrayList(
>>         Iterables.transform(visibleAdapters,
>> ObjectAdapter.Functions.getObject())));
>>
>> return collectionOrArray;
>>
>> I have the same problem in method "*invoke*" from class
>> "*ActionInvocationFacetForDomainEventAbstract*" and I fixed it with a
>> similar way than last mail:
>>
>> final List<Object> visibleObjects =
>>         Lists.newArrayList(Lists.transform(
>>                 visibleAdapters, ObjectAdapter.Functions.getObject()));
>> final ObjectAdapter visibleObjectsAsAdapter =
>> getAdapterManager().adapterFor(visibleObjects);
>>
>> *to*
>>
>> ((Collection<Object>) result).clear();
>> ((Collection<Object>)
>> result).addAll(Lists.newArrayList(Lists.transform(visibleAdapters,
>> ObjectAdapter.Functions.getObject())));
>>
>> final ObjectAdapter visibleObjectsAsAdapter =
>> this.getAdapterManager().adapterFor(result);
>>
>> I hope you're well.
>>
>> Best regards and thanks.
>>
>> --
>> Ignacio Cánovas Rejón
>> Tel. 902 900 231
>> Fax  96 353 19 09
>> n.canovas@gesconsultor.com
>> www.gesconsultor.com
>>
>> Este mensaje y los ficheros anexos son confidenciales. Los mismos
>> contienen información reservada que no puede ser difundida. Si usted ha
>> recibido este correo por error, tenga la amabilidad de eliminarlo de su
>> sistema y avisar al remitente mediante reenvío a su dirección electrónica;
>> no deberá copiar el mensaje ni divulgar su contenido a ninguna persona.
>>
>> Su dirección de correo electrónico junto a sus datos personales constan
>> en un fichero titularidad de GESDATOS SOFTWARE S.L. cuya finalidad es la de
>> mantener el contacto con Ud. Si quiere saber de qué información disponemos
>> de Ud., modificarla, y en su caso, cancelarla, puede hacerlo enviando un
>> escrito al efecto, acompañado de una fotocopia de su D.N.I. a la siguiente
>> dirección: GESDATOS SOFTWARE S.L. Av. Cortes Valencianas 50-1º-C, C.P.
>> 46015 de Valencia. Asimismo, es su responsabilidad comprobar que este
>> mensaje o sus archivos adjuntos no contengan virus informáticos, y en caso
>> que los tuvieran eliminarlos.
>>
>>
>>
>> ---
>> El software de antivirus Avast ha analizado este correo electrónico en
>> busca de virus.
>> http://www.avast.com
>>
>

Re: ISIS-1044 issue with Collections

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

Thanks for checking this out, and you are right, of course... the code
should take the return type of the getter into account.

I'll tidy up your code by way of a fix.

Thanks again,
Dan
On 20 Aug 2015 09:40, "Nacho Cánovas Rejón" <n....@gesconsultor.com>
wrote:

> Hi Dan.
>
> In order to test new changes on 1.9.0 release, I think I find some bug.
>
> My problem is in "*ISIS-1044: fixing by filtering the
> PropertyAccessorFacet and CollectionAccessorFacet, also the
> ActionInvocationFacet (for contributed collections/properties):*" issue.
>
> You modified "*getProperty*" method on class
> "*CollectionAccessorFacetViaAccessor*". I show you the code:
>
> *OLD Code*
>
> final Object collectionOrArray = ObjectAdapter.InvokeUtils.invoke(method,
> owningAdapter);
>
> *NEW Code*
>
> final Object collectionOrArray = ObjectAdapter.InvokeUtils.invoke(method,
> owningAdapter);
>
> final ObjectAdapter collectionAdapter =
> getAdapterManager().adapterFor(collectionOrArray);
>
> final FacetedMethod facetedMethod = (FacetedMethod) getFacetHolder();
> final Class<?> collectionElementType = facetedMethod.getType();
>
> final List<ObjectAdapter> visibleAdapters =
>         ObjectAdapter.Util.visibleAdapters(
>                 collectionAdapter,
>                 authenticationSession, deploymentCategory);
> final List<Object> visibleObjects = Lists.newArrayList(
>         Iterables.transform(visibleAdapters,
> ObjectAdapter.Functions.getObject()));
>
> return visibleObjects;
>
> Now I explain my problem.
>
> I have for example  this property defined in one of my entities.
>
> private SortedSet<Product> customSelectedProducts = new TreeSet<Product>();
>
> public SortedSet<Product> getCustomSelectedProducts() {
>     return this.customSelectedProducts;
> }
>
> public void setCustomSelectedProducts(
>         final SortedSet<Product> customSelectedProducts) {
>     this.customSelectedProducts = customSelectedProducts;
> }
>
> And when I try to get his value, I received:
>
> java.lang.ClassCastException: java.util.ArrayList cannot be cast to
> java.util.SortedSet
>
> You will see that you return always an ArrayList when it's a Collection,
> but maybe there is other kind of collections (SortedSet in my case) and it
> will failed on get method.
>
> I did some dirty and not to well modification for performance to work with
> it in order to advance changing next code:
>
> final List<Object> visibleObjects = Lists.newArrayList(
>         Iterables.transform(visibleAdapters,
> ObjectAdapter.Functions.getObject()));
>
> return visibleObjects;
> *
> **to*
>
> ((Collection) collectionOrArray).clear();
> ((Collection) collectionOrArray).addAll(Lists.newArrayList(
>         Iterables.transform(visibleAdapters,
> ObjectAdapter.Functions.getObject())));
>
> return collectionOrArray;
>
> I have the same problem in method "*invoke*" from class
> "*ActionInvocationFacetForDomainEventAbstract*" and I fixed it with a
> similar way than last mail:
>
> final List<Object> visibleObjects =
>         Lists.newArrayList(Lists.transform(
>                 visibleAdapters, ObjectAdapter.Functions.getObject()));
> final ObjectAdapter visibleObjectsAsAdapter =
> getAdapterManager().adapterFor(visibleObjects);
>
> *to*
>
> ((Collection<Object>) result).clear();
> ((Collection<Object>)
> result).addAll(Lists.newArrayList(Lists.transform(visibleAdapters,
> ObjectAdapter.Functions.getObject())));
>
> final ObjectAdapter visibleObjectsAsAdapter =
> this.getAdapterManager().adapterFor(result);
>
> I hope you're well.
>
> Best regards and thanks.
>
> --
> Ignacio Cánovas Rejón
> Tel. 902 900 231
> Fax  96 353 19 09
> n.canovas@gesconsultor.com
> www.gesconsultor.com
>
> Este mensaje y los ficheros anexos son confidenciales. Los mismos
> contienen información reservada que no puede ser difundida. Si usted ha
> recibido este correo por error, tenga la amabilidad de eliminarlo de su
> sistema y avisar al remitente mediante reenvío a su dirección electrónica;
> no deberá copiar el mensaje ni divulgar su contenido a ninguna persona.
>
> Su dirección de correo electrónico junto a sus datos personales constan en
> un fichero titularidad de GESDATOS SOFTWARE S.L. cuya finalidad es la de
> mantener el contacto con Ud. Si quiere saber de qué información disponemos
> de Ud., modificarla, y en su caso, cancelarla, puede hacerlo enviando un
> escrito al efecto, acompañado de una fotocopia de su D.N.I. a la siguiente
> dirección: GESDATOS SOFTWARE S.L. Av. Cortes Valencianas 50-1º-C, C.P.
> 46015 de Valencia. Asimismo, es su responsabilidad comprobar que este
> mensaje o sus archivos adjuntos no contengan virus informáticos, y en caso
> que los tuvieran eliminarlos.
>
>
>
> ---
> El software de antivirus Avast ha analizado este correo electrónico en
> busca de virus.
> http://www.avast.com
>