You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Guillaume Lucazeau <gl...@gmail.com> on 2016/02/23 11:51:58 UTC

Ordering nodes after initial import

Hello,

I'm loading content through a JSON file. I would like then to sort nodes
(mostly page nodes under document nodes) with the JCR API.

I'm calling my service in my bundle's activator, but i'm facing two issues.

The first one is that no changes seems to be applied to the content tree.
While my logs show that actions are executed (calls to Node.orderBefore()
and then Session.save()), when I look at the tree with Composum, pages are
still in a random order. Even though my parent node is an ordered folder
(jcr:primaryType : sling:OrderedFolder). if I try to manually move a node
in Composum, it works. There is no Exception thrown by my code.

Am I missing something there? I used the JCR API to set permissions and had
no such issue, changes were appliued. This operation is to be made only
once, for migration purpose, and I would like it to be automatic each time
this bundle is deployed to the server during development. For further
ordering actions I will use the REST API.

The second issue is that my service needs access to an administrative
session for this ordering. I mapped it to the admin user with
ServiceUserMapperImpl.amended in sling:OsgiConfig nodes, however this
configuration is fired after the bundle has started. Which means that my
service fails because no mapping is found at the time it's started, and I
have to manually restart it to execute this code.

Is there a possibility to fire this configuration before the bundle start?
I've looked at priorities but didn't manage to make it work.

Thank you,
Guillaume

Re: Ordering nodes after initial import

Posted by Guillaume Lucazeau <gl...@gmail.com>.
Thank Marius, I didn't know this interface and it works well (event though
my bundle seems to start twice by itself but the second time it works so
it's ok).

Regarding the changes not save, I used ResourceResolver.commit instead of
Session.save() and it works.

Thank you!

Best regards,
Guillaume

On Tue, Feb 23, 2016 at 12:17 PM, Marius Petria <mp...@adobe.com> wrote:

>
>
>
>
>
> On 2/23/16, 12:51 PM, "Guillaume Lucazeau" <gl...@gmail.com> wrote:
>
> >The second issue is that my service needs access to an administrative
> >session for this ordering. I mapped it to the admin user with
> >ServiceUserMapperImpl.amended in sling:OsgiConfig nodes, however this
> >configuration is fired after the bundle has started. Which means that my
> >service fails because no mapping is found at the time it's started, and I
> >have to manually restart it to execute this code.
> >
> >Is there a possibility to fire this configuration before the bundle start?
> >I've looked at priorities but didn't manage to make it work.
>
> You can use the ServiceUserMapped interface to wait until your
> configuration is registered. An OSGI service is registered for each mapping.
>
> @Reference(target="(subServiceName=mySubService)”)
> ServiceUserMapped serviceUserMapped;
>
>
>
> [1]
> https://github.com/apache/sling/blob/7c4a53755aed1211c9af313a3973cd2543a7bbe0/bundles/extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapped.java
>

Re: Ordering nodes after initial import

Posted by Marius Petria <mp...@adobe.com>.




On 2/23/16, 12:51 PM, "Guillaume Lucazeau" <gl...@gmail.com> wrote:

>The second issue is that my service needs access to an administrative
>session for this ordering. I mapped it to the admin user with
>ServiceUserMapperImpl.amended in sling:OsgiConfig nodes, however this
>configuration is fired after the bundle has started. Which means that my
>service fails because no mapping is found at the time it's started, and I
>have to manually restart it to execute this code.
>
>Is there a possibility to fire this configuration before the bundle start?
>I've looked at priorities but didn't manage to make it work.

You can use the ServiceUserMapped interface to wait until your configuration is registered. An OSGI service is registered for each mapping.

@Reference(target="(subServiceName=mySubService)”)
ServiceUserMapped serviceUserMapped;



[1] https://github.com/apache/sling/blob/7c4a53755aed1211c9af313a3973cd2543a7bbe0/bundles/extensions/serviceusermapper/src/main/java/org/apache/sling/serviceusermapping/ServiceUserMapped.java