You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Ben Helleman <bh...@adobe.com> on 2013/07/24 20:40:24 UTC

[sling/collection] Properties

Is there any way which to apply properties to members of a sling/collection?

For example I would like to apply properties to the websites node, not the resource which websites references.  Yes, I'm aware that I could get the collection and dig through children until I find the node of interest and then apply properties.  But there must a better way.

[cid:image002.png@01CE887B.BB7E13C0]

Thanks
Ben

Re: [sling/collection] Properties

Posted by Justin Edelson <ju...@justinedelson.com>.
IIUC, what Ben is asking for is a

void setProperties(Map<String, Object> properties);

which will set the properties on all resources in the collection.

Seems like a good idea to me.

Justin


On Wed, Jul 24, 2013 at 9:43 PM, Amit.. Gupta. <am...@adobe.com> wrote:

> ResourceCollection has
>
> /**
>      * Creates a new entry in the collection at the last position and add
> a reference to resource
>      * in the entry.
>      * Changes are transient & have to be saved by calling
> resolver.commit()
>      *
>      * @param resource resource to be added
>      * @param properties The additional properties to be stored with the
> collection entry (can be null).
>      * @return true if addition of resource to collection was successful or
>      *         false if collection already contained the resource or
> resource is null.
>      *
>      * @throws {@link PersistenceException} if the operation fails
>      */
> boolean add(Resource resource, Map<String, Object> properties) throws
> PersistenceException;
>
> And, then to retrieve and update the properties.
> /**
>      * Returns additional properties for a particular resource in
> Collection entry.
>      *
>      * @return properties of the Collection entry as
> <code>ModifiableValueMap</code>, returns null if entry found.
>      */
>     ModifiableValueMap getProperties(Resource resource);
>
> Thanks
> -Amit
> From: Ben Helleman [mailto:bhellema@adobe.com]
> Sent: 25 July 2013 00:10
> To: dev@sling.apache.org
> Subject: [sling/collection] Properties
>
> Is there any way which to apply properties to members of a
> sling/collection?
>
> For example I would like to apply properties to the websites node, not the
> resource which websites references.  Yes, I'm aware that I could get the
> collection and dig through children until I find the node of interest and
> then apply properties.  But there must a better way.
>
> [cid:image002.png@01CE887B.BB7E13C0]
>
> Thanks
> Ben
>

RE: [sling/collection] Properties

Posted by "Amit.. Gupta." <am...@adobe.com>.
> however I find the ResourceCollection API a little inconsistent.  For example there is a mixed concept between the actual resource and the sling:member reference.  Which is why I ended up over looking getProperties.  My initial though was that you would be getting the properties of the _actual_ resource which the collection references.

>  It would be nice to have a getMembers() API that would return you the sling:members which then you could iterate over.  
This was originally discussed in [1] as well and it was decided that it not needed if we already have getProperties(). Still I have logged [0] to open discussion on the this.

> There is a public static ResourceCollectionConstants.MEMBERS_NODE_NAME which gave me the feeling that there should be an API that would return these values.  If this is not the case then I thought it would have been protected or private.
This is in impl package, and not exported.

Thanks,
Amit
[0] https://issues.apache.org/jira/browse/SLING-2982
[1] https://issues.apache.org/jira/browse/SLING-2853


-----Original Message-----
From: Ben Helleman [mailto:bhellema@adobe.com] 
Sent: 26 July 2013 17:20
To: dev@sling.apache.org
Subject: Re: [sling/collection] Properties

Hi Amit

I managed to get things working with the APIs you specified, however I find the ResourceCollection API a little inconsistent.  For example there is a mixed concept between the actual resource and the sling:member reference.  Which is why I ended up over looking getProperties.  My initial though was that you would be getting the properties of the _actual_ resource which the collection references.  I thought this because when you add a resource to the collection it is the actual resource, so having a mix between the sling:member resources vs actual resources is confusing.  

I also have a requirement to iterate through the sling:members in the collection and pull the properties off the nodes to render UI, however this isn't simple enough to do with the current API.  The two apis we have to use are getResources(), and getProperties() are do not reference the same resources which muddies the water.  It would be nice to have a getMembers() API that would return you the sling:members which then you could iterate over.  

There is a public static ResourceCollectionConstants.MEMBERS_NODE_NAME which gave me the feeling that there should be an API that would return these values.  If this is not the case then I thought it would have been protected or private.

Ben

On 2013-07-24, at 9:43 PM, Amit.. Gupta. <am...@adobe.com> wrote:

> ResourceCollection has
> 
> /**
>     * Creates a new entry in the collection at the last position and add a reference to resource
>     * in the entry.
>     * Changes are transient & have to be saved by calling resolver.commit()
>     *
>     * @param resource resource to be added
>     * @param properties The additional properties to be stored with the collection entry (can be null).
>     * @return true if addition of resource to collection was successful or
>     *         false if collection already contained the resource or resource is null.
>     *
>     * @throws {@link PersistenceException} if the operation fails
>     */
> boolean add(Resource resource, Map<String, Object> properties) throws PersistenceException;
> 
> And, then to retrieve and update the properties.
> /**
>     * Returns additional properties for a particular resource in Collection entry.
>     *
>     * @return properties of the Collection entry as <code>ModifiableValueMap</code>, returns null if entry found.
>     */
>    ModifiableValueMap getProperties(Resource resource);
> 
> Thanks
> -Amit
> From: Ben Helleman [mailto:bhellema@adobe.com]
> Sent: 25 July 2013 00:10
> To: dev@sling.apache.org
> Subject: [sling/collection] Properties
> 
> Is there any way which to apply properties to members of a sling/collection?
> 
> For example I would like to apply properties to the websites node, not the resource which websites references.  Yes, I'm aware that I could get the collection and dig through children until I find the node of interest and then apply properties.  But there must a better way.
> 
> [cid:image002.png@01CE887B.BB7E13C0]
> 
> Thanks
> Ben


Re: [sling/collection] Properties

Posted by Ben Helleman <bh...@adobe.com>.
Hi Amit

I managed to get things working with the APIs you specified, however I find the ResourceCollection API a little inconsistent.  For example there is a mixed concept between the actual resource and the sling:member reference.  Which is why I ended up over looking getProperties.  My initial though was that you would be getting the properties of the _actual_ resource which the collection references.  I thought this because when you add a resource to the collection it is the actual resource, so having a mix between the sling:member resources vs actual resources is confusing.  

I also have a requirement to iterate through the sling:members in the collection and pull the properties off the nodes to render UI, however this isn't simple enough to do with the current API.  The two apis we have to use are getResources(), and getProperties() are do not reference the same resources which muddies the water.  It would be nice to have a getMembers() API that would return you the sling:members which then you could iterate over.  

There is a public static ResourceCollectionConstants.MEMBERS_NODE_NAME which gave me the feeling that there should be an API that would return these values.  If this is not the case then I thought it would have been protected or private.

Ben

On 2013-07-24, at 9:43 PM, Amit.. Gupta. <am...@adobe.com> wrote:

> ResourceCollection has
> 
> /**
>     * Creates a new entry in the collection at the last position and add a reference to resource
>     * in the entry.
>     * Changes are transient & have to be saved by calling resolver.commit()
>     *
>     * @param resource resource to be added
>     * @param properties The additional properties to be stored with the collection entry (can be null).
>     * @return true if addition of resource to collection was successful or
>     *         false if collection already contained the resource or resource is null.
>     *
>     * @throws {@link PersistenceException} if the operation fails
>     */
> boolean add(Resource resource, Map<String, Object> properties) throws PersistenceException;
> 
> And, then to retrieve and update the properties.
> /**
>     * Returns additional properties for a particular resource in Collection entry.
>     *
>     * @return properties of the Collection entry as <code>ModifiableValueMap</code>, returns null if entry found.
>     */
>    ModifiableValueMap getProperties(Resource resource);
> 
> Thanks
> -Amit
> From: Ben Helleman [mailto:bhellema@adobe.com]
> Sent: 25 July 2013 00:10
> To: dev@sling.apache.org
> Subject: [sling/collection] Properties
> 
> Is there any way which to apply properties to members of a sling/collection?
> 
> For example I would like to apply properties to the websites node, not the resource which websites references.  Yes, I'm aware that I could get the collection and dig through children until I find the node of interest and then apply properties.  But there must a better way.
> 
> [cid:image002.png@01CE887B.BB7E13C0]
> 
> Thanks
> Ben


RE: [sling/collection] Properties

Posted by "Amit.. Gupta." <am...@adobe.com>.
ResourceCollection has

/**
     * Creates a new entry in the collection at the last position and add a reference to resource
     * in the entry.
     * Changes are transient & have to be saved by calling resolver.commit()
     *
     * @param resource resource to be added
     * @param properties The additional properties to be stored with the collection entry (can be null).
     * @return true if addition of resource to collection was successful or
     *         false if collection already contained the resource or resource is null.
     *
     * @throws {@link PersistenceException} if the operation fails
     */
boolean add(Resource resource, Map<String, Object> properties) throws PersistenceException;

And, then to retrieve and update the properties.
/**
     * Returns additional properties for a particular resource in Collection entry.
     *
     * @return properties of the Collection entry as <code>ModifiableValueMap</code>, returns null if entry found.
     */
    ModifiableValueMap getProperties(Resource resource);

Thanks
-Amit
From: Ben Helleman [mailto:bhellema@adobe.com]
Sent: 25 July 2013 00:10
To: dev@sling.apache.org
Subject: [sling/collection] Properties

Is there any way which to apply properties to members of a sling/collection?

For example I would like to apply properties to the websites node, not the resource which websites references.  Yes, I'm aware that I could get the collection and dig through children until I find the node of interest and then apply properties.  But there must a better way.

[cid:image002.png@01CE887B.BB7E13C0]

Thanks
Ben