You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by "Haefele, Michael" <Mi...@idexx.com> on 2015/07/22 22:36:02 UTC

Best practices for java DTOs to/from Sling

We have a Sling application that we're using basically as a database/file manager for portions of a java Spring application.

In java we have a bunch of DTOs that we import by converting to json using Jackson and persisting to Sling using the import option on the Sling post servlet.
We then read them using .tidy.infinity.json and convert back to DTOs using Jackson again.
This is working really well.

But we've reached point where we need to modify some of the data in Sling and it seems like I've hit a bit of a conceptual wall.
I was thinking we'd keep the DTO pattern going.
Load the DTO, modify some value, push the updated DTO back to Sling.

But it seems the POST servlet doesn't support json when doing a modify operation.
I basically took that as a hint that I might be barking up the wrong tree here.

We could also do the updates by posting specific properties, but it seems like that's opening the door to writing a lot of custom update code.


Does anyone have any suggestions for best practices for this sort of thing?
Am I trying too hard to apply RDBMS/hibernate style patterns?


Thanks for taking to the time to read a somewhat open ended question.

RE: Best practices for java DTOs to/from Sling

Posted by Jason Bailey <Ja...@sas.com>.
I second Bertrand on this. The whole point of Sling is that it's a REST framework with a straightforward CRUD support. I feel there's a tendency for people to attempt to shoehorn in paradigms from other application frameworks, because it's familiar to them, and they end up with a layer of complexity that isn't needed.

-----Original Message-----
From: Bertrand Delacretaz [mailto:bdelacretaz@apache.org] 
Sent: Tuesday, July 28, 2015 10:28 AM
To: users
Subject: Re: Best practices for java DTOs to/from Sling

On Tue, Jul 28, 2015 at 4:02 PM, Haefele, Michael <Mi...@idexx.com> wrote:
>... If we end up doing a lot more DB-style work (particularly updates), 
>I think I'll push for some budget to switch to one of  the OCM technologies....

Note that the general thinking here is still that OCM is not needed with Sling, in the vast majority of cases - the underlying resource model is sufficiently flexible that OCM looks just like an extra layer that's not really needed. There are some exceptions and YMMV of course.

-Bertrand

Re: Best practices for java DTOs to/from Sling

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Tue, Jul 28, 2015 at 4:02 PM, Haefele, Michael
<Mi...@idexx.com> wrote:
>... If we end up doing a lot more DB-style work (particularly updates), I think I'll push for some budget to switch to one of
> the OCM technologies....

Note that the general thinking here is still that OCM is not needed
with Sling, in the vast majority of cases - the underlying resource
model is sufficiently flexible that OCM looks just like an extra layer
that's not really needed. There are some exceptions and YMMV of
course.

-Bertrand

RE: Best practices for java DTOs to/from Sling

Posted by "Haefele, Michael" <Mi...@idexx.com>.
Thank you.

That looks great.
TBH I'm not sure how far the complexity of this application is going to go.
If we end up doing a lot more DB-style work (particularly updates), I think I'll push for some budget to switch to one of the OCM technologies.

-----Original Message-----
From: Olaf [mailto:olaf@x100.de] 
Sent: Monday, July 27, 2015 5:23 PM
To: users@sling.apache.org
Subject: RE: Best practices for java DTOs to/from Sling

Hello Michael,

Tto complete the picture: Your use case might also be ideal for JCR OCM. There was an interesting talk on this at the connectcon Basel this year: http://www.connectcon.ch/2015/en/speakers/katarzyna-kozlowska.html. Note also the pointers to the examples & docs on the last slide of that presentation.

Kind regards,
Olaf


-----Original Message-----
From: Haefele, Michael [mailto:Michael-Haefele@idexx.com]
Sent: Montag, 27. Juli 2015 22:23
To: users@sling.apache.org
Subject: RE: Best practices for java DTOs to/from Sling

Ah hah!

Yes, :replaceProperties did the trick!
Sorry I missed that the first time around.

Thanks to everyone for your help.

I'm still curious about maybe trying Sling Models or connecting to jcr directly, but I think this will keep me going for a while.


-----Original Message-----
From: Jason Bailey [mailto:Jason.Bailey@sas.com]
Sent: Monday, July 27, 2015 3:32 PM
To: users@sling.apache.org
Subject: RE: Best practices for java DTOs to/from Sling

I'm going to chime in and say that I don't think you need to change your process. 

You mentioned defining the :operation="import" which really threw me off since I associate that with a form posting and you mentioned JSON. I took a second look at the links that Julian sent out and there's a section which specifies updating a node via a post with JSON as the content format.

this is the specific section.

https://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#content-creation-or-modification

There's some additional parameters there for modifying/replacing nodes

:replace and :replaceProperties to be specific. This just might be an issue of adding one of these to the submission that's occurring.

-Jason



-----Original Message-----
From: Henry Saginor [mailto:hsaginor.apache@gmail.com]
Sent: Monday, July 27, 2015 2:13 PM
To: users@sling.apache.org
Subject: Re: Best practices for java DTOs to/from Sling

Are you using just Sling itself or a Sling based product like Adobe CQ/AEM? Which Sling UI are you referring to?

Also how is you application deployed with Sling? Sling models, I think, is tightly coupled with Sling itself and has a dependency on OSGi container. JCR API supports remote access. 
Different protocols are supported - RMI or WebDav for example. At least Jackrabbit supports both. But I have not kept up with remoting support in OAK. 
And since Sling can be backed either by Jackrabbit or OAK you can do this with Sling (Sling Eclipse Tooling connects to the repository this way I believe).

Also, considering what Jason mentioned regarding added support for content modification you might want to check what version of Sling Post servlet you are using.
Check the version of the OSGi bundles in Felix Console and make sure they match versions mentioned in https://issues.apache.org/jira/browse/SLING-1172 <https://issues.apache.org/jira/browse/SLING-1172>.

I do like what Sarwar suggested bellow to extend Sling yourself with custom post servlet(s). Don’t know why I did not think of responding with that myself. I would probably do that in actually.
But as you can see you have several options. It really depends on your use case and preference.

> On Jul 27, 2015, at 10:37 AM, Sarwar Bhuiyan <sa...@gmail.com> wrote:
> 
> If you are willing to deploy some code to sling (OSGi), you may be 
> able to write sling servlets which do take a JSON payload and do 
> whatever operations are necessary. That way, you can sort out any 
> issues between the client (your spring code) and the server (sling/JCR).
> 
> I brought up Sling Models only as a suggestion to be able to use the 
> POJOs but it may not even be necessary. I find in the Sling world, 
> using the maps works out best when it's flexibility of the data model 
> you want since you can write some generic code for the servlets even 
> if your data model changes slightly.
> 
> I hope this helps a little.
> 
> Sarwar
> 
> On Mon, Jul 27, 2015 at 12:55 PM, Haefele, Michael < 
> Michael-Haefele@idexx.com> wrote:
> 
>> Sarwar and Henry,
>> 
>> Thank you for your help.
>> 
>> I'm not entirely sure why we went with Sling as opposed to using JCR 
>> directly.
>> I think the Sling GUI made a very good impression in the initial demo 
>> (which was before my time).
>> We are primarily using it as an alternative database (with the hopes 
>> that using JCR will make it very easy to eventually mirror some/all 
>> of the data in the cloud).
>> 
>> Is a hybrid system where we utilize JCR directly in some cases, but 
>> Sling in others possible/desirable?
>> 
>> I'll also take a look at Sling Models.  That sounds promising.
>> 
>> -----Original Message-----
>> From: Sarwar Bhuiyan [mailto:sarwar.bhuiyan@gmail.com]
>> Sent: Thursday, July 23, 2015 1:03 AM
>> To: users@sling.apache.org
>> Subject: Re: Best practices for java DTOs to/from Sling
>> 
>> Have a look at Sling Models.
>> 
>> On Thu, Jul 23, 2015 at 12:32 AM, Henry Saginor 
>> <hsaginor.apache@gmail.com
>>> 
>> wrote:
>> 
>>> Hi Michael,
>>> 
>>> Since Sling itself is a framework for building web applications with 
>>> it’s own persistence and services layer it’s a bit unusual to get 
>>> questions on integration with Spring here (I think). But I don’t 
>>> know enough about your application and its use cases to question why 
>>> you are doing this. ButI think you you can use JCR API to persist 
>>> your DTOs. Look up JCR API and Apache Jackrabbit and OAK projects.
>>> 
>>> Technically you could do away with Sling entirelly and use Apache 
>>> Jackrabbit or OAK directly if all you are using Sling for is as 
>>> document/content store.
>>> But again don’t know enough about your application. And I don’t 
>>> really want to discourage you from using Sling since I am a big fan.
>>> :)
>>> 
>>> Henry
>>> 
>>>> On Jul 22, 2015, at 1:36 PM, Haefele, Michael 
>>>> <Mi...@idexx.com>
>>> wrote:
>>>> 
>>>> We have a Sling application that we're using basically as a
>>> database/file manager for portions of a java Spring application.
>>>> 
>>>> In java we have a bunch of DTOs that we import by converting to 
>>>> json
>>> using Jackson and persisting to Sling using the import option on the 
>>> Sling post servlet.
>>>> We then read them using .tidy.infinity.json and convert back to 
>>>> DTOs
>>> using Jackson again.
>>>> This is working really well.
>>>> 
>>>> But we've reached point where we need to modify some of the data in
>>> Sling and it seems like I've hit a bit of a conceptual wall.
>>>> I was thinking we'd keep the DTO pattern going.
>>>> Load the DTO, modify some value, push the updated DTO back to Sling.
>>>> 
>>>> But it seems the POST servlet doesn't support json when doing a 
>>>> modify
>>> operation.
>>>> I basically took that as a hint that I might be barking up the 
>>>> wrong
>>> tree here.
>>>> 
>>>> We could also do the updates by posting specific properties, but it
>>> seems like that's opening the door to writing a lot of custom update
>> code.
>>>> 
>>>> 
>>>> Does anyone have any suggestions for best practices for this sort 
>>>> of
>>> thing?
>>>> Am I trying too hard to apply RDBMS/hibernate style patterns?
>>>> 
>>>> 
>>>> Thanks for taking to the time to read a somewhat open ended question.
>>> 
>>> 
>> 



RE: Best practices for java DTOs to/from Sling

Posted by Olaf <ol...@x100.de>.
Hello Michael,

Tto complete the picture: Your use case might also be ideal for JCR OCM. There was an interesting talk on this at the connectcon Basel this year: http://www.connectcon.ch/2015/en/speakers/katarzyna-kozlowska.html. Note also the pointers to the examples & docs on the last slide of that presentation.

Kind regards,
Olaf


-----Original Message-----
From: Haefele, Michael [mailto:Michael-Haefele@idexx.com] 
Sent: Montag, 27. Juli 2015 22:23
To: users@sling.apache.org
Subject: RE: Best practices for java DTOs to/from Sling

Ah hah!

Yes, :replaceProperties did the trick!
Sorry I missed that the first time around.

Thanks to everyone for your help.

I'm still curious about maybe trying Sling Models or connecting to jcr directly, but I think this will keep me going for a while.


-----Original Message-----
From: Jason Bailey [mailto:Jason.Bailey@sas.com]
Sent: Monday, July 27, 2015 3:32 PM
To: users@sling.apache.org
Subject: RE: Best practices for java DTOs to/from Sling

I'm going to chime in and say that I don't think you need to change your process. 

You mentioned defining the :operation="import" which really threw me off since I associate that with a form posting and you mentioned JSON. I took a second look at the links that Julian sent out and there's a section which specifies updating a node via a post with JSON as the content format.

this is the specific section.

https://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#content-creation-or-modification

There's some additional parameters there for modifying/replacing nodes

:replace and :replaceProperties to be specific. This just might be an issue of adding one of these to the submission that's occurring.

-Jason



-----Original Message-----
From: Henry Saginor [mailto:hsaginor.apache@gmail.com]
Sent: Monday, July 27, 2015 2:13 PM
To: users@sling.apache.org
Subject: Re: Best practices for java DTOs to/from Sling

Are you using just Sling itself or a Sling based product like Adobe CQ/AEM? Which Sling UI are you referring to?

Also how is you application deployed with Sling? Sling models, I think, is tightly coupled with Sling itself and has a dependency on OSGi container. JCR API supports remote access. 
Different protocols are supported - RMI or WebDav for example. At least Jackrabbit supports both. But I have not kept up with remoting support in OAK. 
And since Sling can be backed either by Jackrabbit or OAK you can do this with Sling (Sling Eclipse Tooling connects to the repository this way I believe).

Also, considering what Jason mentioned regarding added support for content modification you might want to check what version of Sling Post servlet you are using.
Check the version of the OSGi bundles in Felix Console and make sure they match versions mentioned in https://issues.apache.org/jira/browse/SLING-1172 <https://issues.apache.org/jira/browse/SLING-1172>.

I do like what Sarwar suggested bellow to extend Sling yourself with custom post servlet(s). Don’t know why I did not think of responding with that myself. I would probably do that in actually.
But as you can see you have several options. It really depends on your use case and preference.

> On Jul 27, 2015, at 10:37 AM, Sarwar Bhuiyan <sa...@gmail.com> wrote:
> 
> If you are willing to deploy some code to sling (OSGi), you may be 
> able to write sling servlets which do take a JSON payload and do 
> whatever operations are necessary. That way, you can sort out any 
> issues between the client (your spring code) and the server (sling/JCR).
> 
> I brought up Sling Models only as a suggestion to be able to use the 
> POJOs but it may not even be necessary. I find in the Sling world, 
> using the maps works out best when it's flexibility of the data model 
> you want since you can write some generic code for the servlets even 
> if your data model changes slightly.
> 
> I hope this helps a little.
> 
> Sarwar
> 
> On Mon, Jul 27, 2015 at 12:55 PM, Haefele, Michael < 
> Michael-Haefele@idexx.com> wrote:
> 
>> Sarwar and Henry,
>> 
>> Thank you for your help.
>> 
>> I'm not entirely sure why we went with Sling as opposed to using JCR 
>> directly.
>> I think the Sling GUI made a very good impression in the initial demo 
>> (which was before my time).
>> We are primarily using it as an alternative database (with the hopes 
>> that using JCR will make it very easy to eventually mirror some/all 
>> of the data in the cloud).
>> 
>> Is a hybrid system where we utilize JCR directly in some cases, but 
>> Sling in others possible/desirable?
>> 
>> I'll also take a look at Sling Models.  That sounds promising.
>> 
>> -----Original Message-----
>> From: Sarwar Bhuiyan [mailto:sarwar.bhuiyan@gmail.com]
>> Sent: Thursday, July 23, 2015 1:03 AM
>> To: users@sling.apache.org
>> Subject: Re: Best practices for java DTOs to/from Sling
>> 
>> Have a look at Sling Models.
>> 
>> On Thu, Jul 23, 2015 at 12:32 AM, Henry Saginor 
>> <hsaginor.apache@gmail.com
>>> 
>> wrote:
>> 
>>> Hi Michael,
>>> 
>>> Since Sling itself is a framework for building web applications with 
>>> it’s own persistence and services layer it’s a bit unusual to get 
>>> questions on integration with Spring here (I think). But I don’t 
>>> know enough about your application and its use cases to question why 
>>> you are doing this. ButI think you you can use JCR API to persist 
>>> your DTOs. Look up JCR API and Apache Jackrabbit and OAK projects.
>>> 
>>> Technically you could do away with Sling entirelly and use Apache 
>>> Jackrabbit or OAK directly if all you are using Sling for is as 
>>> document/content store.
>>> But again don’t know enough about your application. And I don’t 
>>> really want to discourage you from using Sling since I am a big fan.
>>> :)
>>> 
>>> Henry
>>> 
>>>> On Jul 22, 2015, at 1:36 PM, Haefele, Michael 
>>>> <Mi...@idexx.com>
>>> wrote:
>>>> 
>>>> We have a Sling application that we're using basically as a
>>> database/file manager for portions of a java Spring application.
>>>> 
>>>> In java we have a bunch of DTOs that we import by converting to 
>>>> json
>>> using Jackson and persisting to Sling using the import option on the 
>>> Sling post servlet.
>>>> We then read them using .tidy.infinity.json and convert back to 
>>>> DTOs
>>> using Jackson again.
>>>> This is working really well.
>>>> 
>>>> But we've reached point where we need to modify some of the data in
>>> Sling and it seems like I've hit a bit of a conceptual wall.
>>>> I was thinking we'd keep the DTO pattern going.
>>>> Load the DTO, modify some value, push the updated DTO back to Sling.
>>>> 
>>>> But it seems the POST servlet doesn't support json when doing a 
>>>> modify
>>> operation.
>>>> I basically took that as a hint that I might be barking up the 
>>>> wrong
>>> tree here.
>>>> 
>>>> We could also do the updates by posting specific properties, but it
>>> seems like that's opening the door to writing a lot of custom update
>> code.
>>>> 
>>>> 
>>>> Does anyone have any suggestions for best practices for this sort 
>>>> of
>>> thing?
>>>> Am I trying too hard to apply RDBMS/hibernate style patterns?
>>>> 
>>>> 
>>>> Thanks for taking to the time to read a somewhat open ended question.
>>> 
>>> 
>> 



RE: Best practices for java DTOs to/from Sling

Posted by "Haefele, Michael" <Mi...@idexx.com>.
Ah hah!

Yes, :replaceProperties did the trick!
Sorry I missed that the first time around.

Thanks to everyone for your help.

I'm still curious about maybe trying Sling Models or connecting to jcr directly, but I think this will keep me going for a while.


-----Original Message-----
From: Jason Bailey [mailto:Jason.Bailey@sas.com] 
Sent: Monday, July 27, 2015 3:32 PM
To: users@sling.apache.org
Subject: RE: Best practices for java DTOs to/from Sling

I'm going to chime in and say that I don't think you need to change your process. 

You mentioned defining the :operation="import" which really threw me off since I associate that with a form posting and you mentioned JSON. I took a second look at the links that Julian sent out and there's a section which specifies updating a node via a post with JSON as the content format.

this is the specific section.

https://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#content-creation-or-modification

There's some additional parameters there for modifying/replacing nodes

:replace and :replaceProperties to be specific. This just might be an issue of adding one of these to the submission that's occurring.

-Jason



-----Original Message-----
From: Henry Saginor [mailto:hsaginor.apache@gmail.com]
Sent: Monday, July 27, 2015 2:13 PM
To: users@sling.apache.org
Subject: Re: Best practices for java DTOs to/from Sling

Are you using just Sling itself or a Sling based product like Adobe CQ/AEM? Which Sling UI are you referring to?

Also how is you application deployed with Sling? Sling models, I think, is tightly coupled with Sling itself and has a dependency on OSGi container. JCR API supports remote access. 
Different protocols are supported - RMI or WebDav for example. At least Jackrabbit supports both. But I have not kept up with remoting support in OAK. 
And since Sling can be backed either by Jackrabbit or OAK you can do this with Sling (Sling Eclipse Tooling connects to the repository this way I believe).

Also, considering what Jason mentioned regarding added support for content modification you might want to check what version of Sling Post servlet you are using.
Check the version of the OSGi bundles in Felix Console and make sure they match versions mentioned in https://issues.apache.org/jira/browse/SLING-1172 <https://issues.apache.org/jira/browse/SLING-1172>.

I do like what Sarwar suggested bellow to extend Sling yourself with custom post servlet(s). Don’t know why I did not think of responding with that myself. I would probably do that in actually.
But as you can see you have several options. It really depends on your use case and preference.

> On Jul 27, 2015, at 10:37 AM, Sarwar Bhuiyan <sa...@gmail.com> wrote:
> 
> If you are willing to deploy some code to sling (OSGi), you may be 
> able to write sling servlets which do take a JSON payload and do 
> whatever operations are necessary. That way, you can sort out any 
> issues between the client (your spring code) and the server (sling/JCR).
> 
> I brought up Sling Models only as a suggestion to be able to use the 
> POJOs but it may not even be necessary. I find in the Sling world, 
> using the maps works out best when it's flexibility of the data model 
> you want since you can write some generic code for the servlets even 
> if your data model changes slightly.
> 
> I hope this helps a little.
> 
> Sarwar
> 
> On Mon, Jul 27, 2015 at 12:55 PM, Haefele, Michael < 
> Michael-Haefele@idexx.com> wrote:
> 
>> Sarwar and Henry,
>> 
>> Thank you for your help.
>> 
>> I'm not entirely sure why we went with Sling as opposed to using JCR 
>> directly.
>> I think the Sling GUI made a very good impression in the initial demo 
>> (which was before my time).
>> We are primarily using it as an alternative database (with the hopes 
>> that using JCR will make it very easy to eventually mirror some/all 
>> of the data in the cloud).
>> 
>> Is a hybrid system where we utilize JCR directly in some cases, but 
>> Sling in others possible/desirable?
>> 
>> I'll also take a look at Sling Models.  That sounds promising.
>> 
>> -----Original Message-----
>> From: Sarwar Bhuiyan [mailto:sarwar.bhuiyan@gmail.com]
>> Sent: Thursday, July 23, 2015 1:03 AM
>> To: users@sling.apache.org
>> Subject: Re: Best practices for java DTOs to/from Sling
>> 
>> Have a look at Sling Models.
>> 
>> On Thu, Jul 23, 2015 at 12:32 AM, Henry Saginor 
>> <hsaginor.apache@gmail.com
>>> 
>> wrote:
>> 
>>> Hi Michael,
>>> 
>>> Since Sling itself is a framework for building web applications with 
>>> it’s own persistence and services layer it’s a bit unusual to get 
>>> questions on integration with Spring here (I think). But I don’t 
>>> know enough about your application and its use cases to question why 
>>> you are doing this. ButI think you you can use JCR API to persist 
>>> your DTOs. Look up JCR API and Apache Jackrabbit and OAK projects.
>>> 
>>> Technically you could do away with Sling entirelly and use Apache 
>>> Jackrabbit or OAK directly if all you are using Sling for is as 
>>> document/content store.
>>> But again don’t know enough about your application. And I don’t 
>>> really want to discourage you from using Sling since I am a big fan.
>>> :)
>>> 
>>> Henry
>>> 
>>>> On Jul 22, 2015, at 1:36 PM, Haefele, Michael 
>>>> <Mi...@idexx.com>
>>> wrote:
>>>> 
>>>> We have a Sling application that we're using basically as a
>>> database/file manager for portions of a java Spring application.
>>>> 
>>>> In java we have a bunch of DTOs that we import by converting to 
>>>> json
>>> using Jackson and persisting to Sling using the import option on the 
>>> Sling post servlet.
>>>> We then read them using .tidy.infinity.json and convert back to 
>>>> DTOs
>>> using Jackson again.
>>>> This is working really well.
>>>> 
>>>> But we've reached point where we need to modify some of the data in
>>> Sling and it seems like I've hit a bit of a conceptual wall.
>>>> I was thinking we'd keep the DTO pattern going.
>>>> Load the DTO, modify some value, push the updated DTO back to Sling.
>>>> 
>>>> But it seems the POST servlet doesn't support json when doing a 
>>>> modify
>>> operation.
>>>> I basically took that as a hint that I might be barking up the 
>>>> wrong
>>> tree here.
>>>> 
>>>> We could also do the updates by posting specific properties, but it
>>> seems like that's opening the door to writing a lot of custom update
>> code.
>>>> 
>>>> 
>>>> Does anyone have any suggestions for best practices for this sort 
>>>> of
>>> thing?
>>>> Am I trying too hard to apply RDBMS/hibernate style patterns?
>>>> 
>>>> 
>>>> Thanks for taking to the time to read a somewhat open ended question.
>>> 
>>> 
>> 


RE: Best practices for java DTOs to/from Sling

Posted by Jason Bailey <Ja...@sas.com>.
I'm going to chime in and say that I don't think you need to change your process. 

You mentioned defining the :operation="import" which really threw me off since I associate that with a form posting and you mentioned JSON. I took a second look at the links that Julian sent out and there's a section which specifies updating a node via a post with JSON as the content format.

this is the specific section.

https://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#content-creation-or-modification

There's some additional parameters there for modifying/replacing nodes

:replace and :replaceProperties to be specific. This just might be an issue of adding one of these to the submission that's occurring.

-Jason



-----Original Message-----
From: Henry Saginor [mailto:hsaginor.apache@gmail.com] 
Sent: Monday, July 27, 2015 2:13 PM
To: users@sling.apache.org
Subject: Re: Best practices for java DTOs to/from Sling

Are you using just Sling itself or a Sling based product like Adobe CQ/AEM? Which Sling UI are you referring to?

Also how is you application deployed with Sling? Sling models, I think, is tightly coupled with Sling itself and has a dependency on OSGi container. JCR API supports remote access. 
Different protocols are supported - RMI or WebDav for example. At least Jackrabbit supports both. But I have not kept up with remoting support in OAK. 
And since Sling can be backed either by Jackrabbit or OAK you can do this with Sling (Sling Eclipse Tooling connects to the repository this way I believe).

Also, considering what Jason mentioned regarding added support for content modification you might want to check what version of Sling Post servlet you are using.
Check the version of the OSGi bundles in Felix Console and make sure they match versions mentioned in https://issues.apache.org/jira/browse/SLING-1172 <https://issues.apache.org/jira/browse/SLING-1172>.

I do like what Sarwar suggested bellow to extend Sling yourself with custom post servlet(s). Don’t know why I did not think of responding with that myself. I would probably do that in actually.
But as you can see you have several options. It really depends on your use case and preference.

> On Jul 27, 2015, at 10:37 AM, Sarwar Bhuiyan <sa...@gmail.com> wrote:
> 
> If you are willing to deploy some code to sling (OSGi), you may be 
> able to write sling servlets which do take a JSON payload and do 
> whatever operations are necessary. That way, you can sort out any 
> issues between the client (your spring code) and the server (sling/JCR).
> 
> I brought up Sling Models only as a suggestion to be able to use the 
> POJOs but it may not even be necessary. I find in the Sling world, 
> using the maps works out best when it's flexibility of the data model 
> you want since you can write some generic code for the servlets even 
> if your data model changes slightly.
> 
> I hope this helps a little.
> 
> Sarwar
> 
> On Mon, Jul 27, 2015 at 12:55 PM, Haefele, Michael < 
> Michael-Haefele@idexx.com> wrote:
> 
>> Sarwar and Henry,
>> 
>> Thank you for your help.
>> 
>> I'm not entirely sure why we went with Sling as opposed to using JCR 
>> directly.
>> I think the Sling GUI made a very good impression in the initial demo 
>> (which was before my time).
>> We are primarily using it as an alternative database (with the hopes 
>> that using JCR will make it very easy to eventually mirror some/all 
>> of the data in the cloud).
>> 
>> Is a hybrid system where we utilize JCR directly in some cases, but 
>> Sling in others possible/desirable?
>> 
>> I'll also take a look at Sling Models.  That sounds promising.
>> 
>> -----Original Message-----
>> From: Sarwar Bhuiyan [mailto:sarwar.bhuiyan@gmail.com]
>> Sent: Thursday, July 23, 2015 1:03 AM
>> To: users@sling.apache.org
>> Subject: Re: Best practices for java DTOs to/from Sling
>> 
>> Have a look at Sling Models.
>> 
>> On Thu, Jul 23, 2015 at 12:32 AM, Henry Saginor 
>> <hsaginor.apache@gmail.com
>>> 
>> wrote:
>> 
>>> Hi Michael,
>>> 
>>> Since Sling itself is a framework for building web applications with 
>>> it’s own persistence and services layer it’s a bit unusual to get 
>>> questions on integration with Spring here (I think). But I don’t 
>>> know enough about your application and its use cases to question why 
>>> you are doing this. ButI think you you can use JCR API to persist 
>>> your DTOs. Look up JCR API and Apache Jackrabbit and OAK projects.
>>> 
>>> Technically you could do away with Sling entirelly and use Apache 
>>> Jackrabbit or OAK directly if all you are using Sling for is as 
>>> document/content store.
>>> But again don’t know enough about your application. And I don’t 
>>> really want to discourage you from using Sling since I am a big fan. 
>>> :)
>>> 
>>> Henry
>>> 
>>>> On Jul 22, 2015, at 1:36 PM, Haefele, Michael 
>>>> <Mi...@idexx.com>
>>> wrote:
>>>> 
>>>> We have a Sling application that we're using basically as a
>>> database/file manager for portions of a java Spring application.
>>>> 
>>>> In java we have a bunch of DTOs that we import by converting to 
>>>> json
>>> using Jackson and persisting to Sling using the import option on the 
>>> Sling post servlet.
>>>> We then read them using .tidy.infinity.json and convert back to 
>>>> DTOs
>>> using Jackson again.
>>>> This is working really well.
>>>> 
>>>> But we've reached point where we need to modify some of the data in
>>> Sling and it seems like I've hit a bit of a conceptual wall.
>>>> I was thinking we'd keep the DTO pattern going.
>>>> Load the DTO, modify some value, push the updated DTO back to Sling.
>>>> 
>>>> But it seems the POST servlet doesn't support json when doing a 
>>>> modify
>>> operation.
>>>> I basically took that as a hint that I might be barking up the 
>>>> wrong
>>> tree here.
>>>> 
>>>> We could also do the updates by posting specific properties, but it
>>> seems like that's opening the door to writing a lot of custom update
>> code.
>>>> 
>>>> 
>>>> Does anyone have any suggestions for best practices for this sort 
>>>> of
>>> thing?
>>>> Am I trying too hard to apply RDBMS/hibernate style patterns?
>>>> 
>>>> 
>>>> Thanks for taking to the time to read a somewhat open ended question.
>>> 
>>> 
>> 


Re: Best practices for java DTOs to/from Sling

Posted by Henry Saginor <hs...@gmail.com>.
Are you using just Sling itself or a Sling based product like Adobe CQ/AEM? Which Sling UI are you referring to?

Also how is you application deployed with Sling? Sling models, I think, is tightly coupled with Sling itself and has a dependency on OSGi container. JCR API supports remote access. 
Different protocols are supported - RMI or WebDav for example. At least Jackrabbit supports both. But I have not kept up with remoting support in OAK. 
And since Sling can be backed either by Jackrabbit or OAK you can do this with Sling (Sling Eclipse Tooling connects to the repository this way I believe).

Also, considering what Jason mentioned regarding added support for content modification you might want to check what version of Sling Post servlet you are using.
Check the version of the OSGi bundles in Felix Console and make sure they match versions mentioned in https://issues.apache.org/jira/browse/SLING-1172 <https://issues.apache.org/jira/browse/SLING-1172>.

I do like what Sarwar suggested bellow to extend Sling yourself with custom post servlet(s). Don’t know why I did not think of responding with that myself. I would probably do that in actually.
But as you can see you have several options. It really depends on your use case and preference.

> On Jul 27, 2015, at 10:37 AM, Sarwar Bhuiyan <sa...@gmail.com> wrote:
> 
> If you are willing to deploy some code to sling (OSGi), you may be able to
> write sling servlets which do take a JSON payload and do whatever
> operations are necessary. That way, you can sort out any issues between the
> client (your spring code) and the server (sling/JCR).
> 
> I brought up Sling Models only as a suggestion to be able to use the POJOs
> but it may not even be necessary. I find in the Sling world, using the maps
> works out best when it's flexibility of the data model you want since you
> can write some generic code for the servlets even if your data model
> changes slightly.
> 
> I hope this helps a little.
> 
> Sarwar
> 
> On Mon, Jul 27, 2015 at 12:55 PM, Haefele, Michael <
> Michael-Haefele@idexx.com> wrote:
> 
>> Sarwar and Henry,
>> 
>> Thank you for your help.
>> 
>> I'm not entirely sure why we went with Sling as opposed to using JCR
>> directly.
>> I think the Sling GUI made a very good impression in the initial demo
>> (which was before my time).
>> We are primarily using it as an alternative database (with the hopes that
>> using JCR will make it very easy to eventually mirror some/all of the data
>> in the cloud).
>> 
>> Is a hybrid system where we utilize JCR directly in some cases, but Sling
>> in others possible/desirable?
>> 
>> I'll also take a look at Sling Models.  That sounds promising.
>> 
>> -----Original Message-----
>> From: Sarwar Bhuiyan [mailto:sarwar.bhuiyan@gmail.com]
>> Sent: Thursday, July 23, 2015 1:03 AM
>> To: users@sling.apache.org
>> Subject: Re: Best practices for java DTOs to/from Sling
>> 
>> Have a look at Sling Models.
>> 
>> On Thu, Jul 23, 2015 at 12:32 AM, Henry Saginor <hsaginor.apache@gmail.com
>>> 
>> wrote:
>> 
>>> Hi Michael,
>>> 
>>> Since Sling itself is a framework for building web applications with
>>> it’s own persistence and services layer it’s a bit unusual to get
>>> questions on integration with Spring here (I think). But I don’t know
>>> enough about your application and its use cases to question why you
>>> are doing this. ButI think you you can use JCR API to persist your
>>> DTOs. Look up JCR API and Apache Jackrabbit and OAK projects.
>>> 
>>> Technically you could do away with Sling entirelly and use Apache
>>> Jackrabbit or OAK directly if all you are using Sling for is as
>>> document/content store.
>>> But again don’t know enough about your application. And I don’t really
>>> want to discourage you from using Sling since I am a big fan. :)
>>> 
>>> Henry
>>> 
>>>> On Jul 22, 2015, at 1:36 PM, Haefele, Michael
>>>> <Mi...@idexx.com>
>>> wrote:
>>>> 
>>>> We have a Sling application that we're using basically as a
>>> database/file manager for portions of a java Spring application.
>>>> 
>>>> In java we have a bunch of DTOs that we import by converting to json
>>> using Jackson and persisting to Sling using the import option on the
>>> Sling post servlet.
>>>> We then read them using .tidy.infinity.json and convert back to DTOs
>>> using Jackson again.
>>>> This is working really well.
>>>> 
>>>> But we've reached point where we need to modify some of the data in
>>> Sling and it seems like I've hit a bit of a conceptual wall.
>>>> I was thinking we'd keep the DTO pattern going.
>>>> Load the DTO, modify some value, push the updated DTO back to Sling.
>>>> 
>>>> But it seems the POST servlet doesn't support json when doing a
>>>> modify
>>> operation.
>>>> I basically took that as a hint that I might be barking up the wrong
>>> tree here.
>>>> 
>>>> We could also do the updates by posting specific properties, but it
>>> seems like that's opening the door to writing a lot of custom update
>> code.
>>>> 
>>>> 
>>>> Does anyone have any suggestions for best practices for this sort of
>>> thing?
>>>> Am I trying too hard to apply RDBMS/hibernate style patterns?
>>>> 
>>>> 
>>>> Thanks for taking to the time to read a somewhat open ended question.
>>> 
>>> 
>> 


Re: Best practices for java DTOs to/from Sling

Posted by Sarwar Bhuiyan <sa...@gmail.com>.
If you are willing to deploy some code to sling (OSGi), you may be able to
write sling servlets which do take a JSON payload and do whatever
operations are necessary. That way, you can sort out any issues between the
client (your spring code) and the server (sling/JCR).

I brought up Sling Models only as a suggestion to be able to use the POJOs
but it may not even be necessary. I find in the Sling world, using the maps
works out best when it's flexibility of the data model you want since you
can write some generic code for the servlets even if your data model
changes slightly.

I hope this helps a little.

Sarwar

On Mon, Jul 27, 2015 at 12:55 PM, Haefele, Michael <
Michael-Haefele@idexx.com> wrote:

> Sarwar and Henry,
>
> Thank you for your help.
>
> I'm not entirely sure why we went with Sling as opposed to using JCR
> directly.
> I think the Sling GUI made a very good impression in the initial demo
> (which was before my time).
> We are primarily using it as an alternative database (with the hopes that
> using JCR will make it very easy to eventually mirror some/all of the data
> in the cloud).
>
> Is a hybrid system where we utilize JCR directly in some cases, but Sling
> in others possible/desirable?
>
> I'll also take a look at Sling Models.  That sounds promising.
>
> -----Original Message-----
> From: Sarwar Bhuiyan [mailto:sarwar.bhuiyan@gmail.com]
> Sent: Thursday, July 23, 2015 1:03 AM
> To: users@sling.apache.org
> Subject: Re: Best practices for java DTOs to/from Sling
>
> Have a look at Sling Models.
>
> On Thu, Jul 23, 2015 at 12:32 AM, Henry Saginor <hsaginor.apache@gmail.com
> >
> wrote:
>
> > Hi Michael,
> >
> > Since Sling itself is a framework for building web applications with
> > it’s own persistence and services layer it’s a bit unusual to get
> > questions on integration with Spring here (I think). But I don’t know
> > enough about your application and its use cases to question why you
> > are doing this. ButI think you you can use JCR API to persist your
> > DTOs. Look up JCR API and Apache Jackrabbit and OAK projects.
> >
> > Technically you could do away with Sling entirelly and use Apache
> > Jackrabbit or OAK directly if all you are using Sling for is as
> > document/content store.
> > But again don’t know enough about your application. And I don’t really
> > want to discourage you from using Sling since I am a big fan. :)
> >
> > Henry
> >
> > > On Jul 22, 2015, at 1:36 PM, Haefele, Michael
> > > <Mi...@idexx.com>
> > wrote:
> > >
> > > We have a Sling application that we're using basically as a
> > database/file manager for portions of a java Spring application.
> > >
> > > In java we have a bunch of DTOs that we import by converting to json
> > using Jackson and persisting to Sling using the import option on the
> > Sling post servlet.
> > > We then read them using .tidy.infinity.json and convert back to DTOs
> > using Jackson again.
> > > This is working really well.
> > >
> > > But we've reached point where we need to modify some of the data in
> > Sling and it seems like I've hit a bit of a conceptual wall.
> > > I was thinking we'd keep the DTO pattern going.
> > > Load the DTO, modify some value, push the updated DTO back to Sling.
> > >
> > > But it seems the POST servlet doesn't support json when doing a
> > > modify
> > operation.
> > > I basically took that as a hint that I might be barking up the wrong
> > tree here.
> > >
> > > We could also do the updates by posting specific properties, but it
> > seems like that's opening the door to writing a lot of custom update
> code.
> > >
> > >
> > > Does anyone have any suggestions for best practices for this sort of
> > thing?
> > > Am I trying too hard to apply RDBMS/hibernate style patterns?
> > >
> > >
> > > Thanks for taking to the time to read a somewhat open ended question.
> >
> >
>

RE: Best practices for java DTOs to/from Sling

Posted by "Haefele, Michael" <Mi...@idexx.com>.
Sarwar and Henry,

Thank you for your help.

I'm not entirely sure why we went with Sling as opposed to using JCR directly.
I think the Sling GUI made a very good impression in the initial demo (which was before my time).
We are primarily using it as an alternative database (with the hopes that using JCR will make it very easy to eventually mirror some/all of the data in the cloud).

Is a hybrid system where we utilize JCR directly in some cases, but Sling in others possible/desirable?

I'll also take a look at Sling Models.  That sounds promising.

-----Original Message-----
From: Sarwar Bhuiyan [mailto:sarwar.bhuiyan@gmail.com] 
Sent: Thursday, July 23, 2015 1:03 AM
To: users@sling.apache.org
Subject: Re: Best practices for java DTOs to/from Sling

Have a look at Sling Models.

On Thu, Jul 23, 2015 at 12:32 AM, Henry Saginor <hs...@gmail.com>
wrote:

> Hi Michael,
>
> Since Sling itself is a framework for building web applications with 
> it’s own persistence and services layer it’s a bit unusual to get 
> questions on integration with Spring here (I think). But I don’t know 
> enough about your application and its use cases to question why you 
> are doing this. ButI think you you can use JCR API to persist your 
> DTOs. Look up JCR API and Apache Jackrabbit and OAK projects.
>
> Technically you could do away with Sling entirelly and use Apache 
> Jackrabbit or OAK directly if all you are using Sling for is as 
> document/content store.
> But again don’t know enough about your application. And I don’t really 
> want to discourage you from using Sling since I am a big fan. :)
>
> Henry
>
> > On Jul 22, 2015, at 1:36 PM, Haefele, Michael 
> > <Mi...@idexx.com>
> wrote:
> >
> > We have a Sling application that we're using basically as a
> database/file manager for portions of a java Spring application.
> >
> > In java we have a bunch of DTOs that we import by converting to json
> using Jackson and persisting to Sling using the import option on the 
> Sling post servlet.
> > We then read them using .tidy.infinity.json and convert back to DTOs
> using Jackson again.
> > This is working really well.
> >
> > But we've reached point where we need to modify some of the data in
> Sling and it seems like I've hit a bit of a conceptual wall.
> > I was thinking we'd keep the DTO pattern going.
> > Load the DTO, modify some value, push the updated DTO back to Sling.
> >
> > But it seems the POST servlet doesn't support json when doing a 
> > modify
> operation.
> > I basically took that as a hint that I might be barking up the wrong
> tree here.
> >
> > We could also do the updates by posting specific properties, but it
> seems like that's opening the door to writing a lot of custom update code.
> >
> >
> > Does anyone have any suggestions for best practices for this sort of
> thing?
> > Am I trying too hard to apply RDBMS/hibernate style patterns?
> >
> >
> > Thanks for taking to the time to read a somewhat open ended question.
>
>

Re: Best practices for java DTOs to/from Sling

Posted by Sarwar Bhuiyan <sa...@gmail.com>.
Have a look at Sling Models.

On Thu, Jul 23, 2015 at 12:32 AM, Henry Saginor <hs...@gmail.com>
wrote:

> Hi Michael,
>
> Since Sling itself is a framework for building web applications with it’s
> own persistence and services layer it’s a bit unusual to get questions on
> integration with Spring here (I think). But I don’t know enough about your
> application and its use cases to question why you are doing this. ButI
> think you you can use JCR API to persist your DTOs. Look up JCR API and
> Apache Jackrabbit and OAK projects.
>
> Technically you could do away with Sling entirelly and use Apache
> Jackrabbit or OAK directly if all you are using Sling for is as
> document/content store.
> But again don’t know enough about your application. And I don’t really
> want to discourage you from using Sling since I am a big fan. :)
>
> Henry
>
> > On Jul 22, 2015, at 1:36 PM, Haefele, Michael <Mi...@idexx.com>
> wrote:
> >
> > We have a Sling application that we're using basically as a
> database/file manager for portions of a java Spring application.
> >
> > In java we have a bunch of DTOs that we import by converting to json
> using Jackson and persisting to Sling using the import option on the Sling
> post servlet.
> > We then read them using .tidy.infinity.json and convert back to DTOs
> using Jackson again.
> > This is working really well.
> >
> > But we've reached point where we need to modify some of the data in
> Sling and it seems like I've hit a bit of a conceptual wall.
> > I was thinking we'd keep the DTO pattern going.
> > Load the DTO, modify some value, push the updated DTO back to Sling.
> >
> > But it seems the POST servlet doesn't support json when doing a modify
> operation.
> > I basically took that as a hint that I might be barking up the wrong
> tree here.
> >
> > We could also do the updates by posting specific properties, but it
> seems like that's opening the door to writing a lot of custom update code.
> >
> >
> > Does anyone have any suggestions for best practices for this sort of
> thing?
> > Am I trying too hard to apply RDBMS/hibernate style patterns?
> >
> >
> > Thanks for taking to the time to read a somewhat open ended question.
>
>

Re: Best practices for java DTOs to/from Sling

Posted by Henry Saginor <hs...@gmail.com>.
Hi Michael,

Since Sling itself is a framework for building web applications with it’s own persistence and services layer it’s a bit unusual to get questions on integration with Spring here (I think). But I don’t know enough about your application and its use cases to question why you are doing this. ButI think you you can use JCR API to persist your DTOs. Look up JCR API and Apache Jackrabbit and OAK projects.

Technically you could do away with Sling entirelly and use Apache Jackrabbit or OAK directly if all you are using Sling for is as document/content store.
But again don’t know enough about your application. And I don’t really want to discourage you from using Sling since I am a big fan. :)

Henry
 
> On Jul 22, 2015, at 1:36 PM, Haefele, Michael <Mi...@idexx.com> wrote:
> 
> We have a Sling application that we're using basically as a database/file manager for portions of a java Spring application.
> 
> In java we have a bunch of DTOs that we import by converting to json using Jackson and persisting to Sling using the import option on the Sling post servlet.
> We then read them using .tidy.infinity.json and convert back to DTOs using Jackson again.
> This is working really well.
> 
> But we've reached point where we need to modify some of the data in Sling and it seems like I've hit a bit of a conceptual wall.
> I was thinking we'd keep the DTO pattern going.
> Load the DTO, modify some value, push the updated DTO back to Sling.
> 
> But it seems the POST servlet doesn't support json when doing a modify operation.
> I basically took that as a hint that I might be barking up the wrong tree here.
> 
> We could also do the updates by posting specific properties, but it seems like that's opening the door to writing a lot of custom update code.
> 
> 
> Does anyone have any suggestions for best practices for this sort of thing?
> Am I trying too hard to apply RDBMS/hibernate style patterns?
> 
> 
> Thanks for taking to the time to read a somewhat open ended question.


RE: Best practices for java DTOs to/from Sling

Posted by "Haefele, Michael" <Mi...@idexx.com>.
Apologies for the delayed response.  I was out of town and unexpectedly wasn't able to connect to email.

We actually are using the :operation=import POST using json and it works quite well.
But it doesn't seem like there is a modify/update operation that also takes in json.

I believe using import for nodes that already exist gives an error (which makes sense to me), but I don't see a way to send json with the modify operation.
This would mostly be useful for updating the entire DTO graph with one POST.

We can absolutely write something to convert the DTO graph into properties and POST those out node by node, but it got me thinking maybe I was going down an untrodden path.


Thanks for your help,
Mike

-----Original Message-----
From: Julian Sedding [mailto:jsedding@gmail.com] 
Sent: Friday, July 24, 2015 6:00 AM
To: users@sling.apache.org
Subject: Re: Best practices for java DTOs to/from Sling

Documentation for JSON import via the SLing POST Servlet is available
here: http://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#importing-content-structures

Regards
Julian

On Thu, Jul 23, 2015 at 2:35 PM, Jason Bailey <Ja...@sas.com> wrote:
> The occasional problem with Sling is that the feature set moves faster than the documentation.
>
> Support for modification of content via JSON has been implemented. Here's some relevant links:
> https://cwiki.apache.org/confluence/display/SLING/FAQ#FAQ-HowdoIcreateanodebypostingajsondocumenttoaURL?
> https://issues.apache.org/jira/browse/SLING-1172
>
> As you can tell, this was actually completed a while back. So the problem you're experiencing is either a bug(new or regression) or there's a problem with how you implemented
>
> Can you provide a simple use  case of the problem you're having posting json?
>
> -Jason
>
> -----Original Message-----
> From: Haefele, Michael [mailto:Michael-Haefele@idexx.com]
> Sent: Wednesday, July 22, 2015 4:36 PM
> To: users@sling.apache.org
> Subject: Best practices for java DTOs to/from Sling
>
> We have a Sling application that we're using basically as a database/file manager for portions of a java Spring application.
>
> In java we have a bunch of DTOs that we import by converting to json using Jackson and persisting to Sling using the import option on the Sling post servlet.
> We then read them using .tidy.infinity.json and convert back to DTOs using Jackson again.
> This is working really well.
>
> But we've reached point where we need to modify some of the data in Sling and it seems like I've hit a bit of a conceptual wall.
> I was thinking we'd keep the DTO pattern going.
> Load the DTO, modify some value, push the updated DTO back to Sling.
>
> But it seems the POST servlet doesn't support json when doing a modify operation.
> I basically took that as a hint that I might be barking up the wrong tree here.
>
> We could also do the updates by posting specific properties, but it seems like that's opening the door to writing a lot of custom update code.
>
>
> Does anyone have any suggestions for best practices for this sort of thing?
> Am I trying too hard to apply RDBMS/hibernate style patterns?
>
>
> Thanks for taking to the time to read a somewhat open ended question.

RE: Best practices for java DTOs to/from Sling

Posted by Jason Bailey <Ja...@sas.com>.
Ok, that's a complaint I have. I actually looked for that knowing that I had seen something like that before and I was unable to find it in the docs.

I'm not a fan of how the website is laid out.  Thanks Julian for finding that.

-----Original Message-----
From: Julian Sedding [mailto:jsedding@gmail.com] 
Sent: Friday, July 24, 2015 6:00 AM
To: users@sling.apache.org
Subject: Re: Best practices for java DTOs to/from Sling

Documentation for JSON import via the SLing POST Servlet is available
here: http://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#importing-content-structures

Regards
Julian

On Thu, Jul 23, 2015 at 2:35 PM, Jason Bailey <Ja...@sas.com> wrote:
> The occasional problem with Sling is that the feature set moves faster than the documentation.
>
> Support for modification of content via JSON has been implemented. Here's some relevant links:
> https://cwiki.apache.org/confluence/display/SLING/FAQ#FAQ-HowdoIcreateanodebypostingajsondocumenttoaURL?
> https://issues.apache.org/jira/browse/SLING-1172
>
> As you can tell, this was actually completed a while back. So the problem you're experiencing is either a bug(new or regression) or there's a problem with how you implemented
>
> Can you provide a simple use  case of the problem you're having posting json?
>
> -Jason
>
> -----Original Message-----
> From: Haefele, Michael [mailto:Michael-Haefele@idexx.com]
> Sent: Wednesday, July 22, 2015 4:36 PM
> To: users@sling.apache.org
> Subject: Best practices for java DTOs to/from Sling
>
> We have a Sling application that we're using basically as a database/file manager for portions of a java Spring application.
>
> In java we have a bunch of DTOs that we import by converting to json using Jackson and persisting to Sling using the import option on the Sling post servlet.
> We then read them using .tidy.infinity.json and convert back to DTOs using Jackson again.
> This is working really well.
>
> But we've reached point where we need to modify some of the data in Sling and it seems like I've hit a bit of a conceptual wall.
> I was thinking we'd keep the DTO pattern going.
> Load the DTO, modify some value, push the updated DTO back to Sling.
>
> But it seems the POST servlet doesn't support json when doing a modify operation.
> I basically took that as a hint that I might be barking up the wrong tree here.
>
> We could also do the updates by posting specific properties, but it seems like that's opening the door to writing a lot of custom update code.
>
>
> Does anyone have any suggestions for best practices for this sort of thing?
> Am I trying too hard to apply RDBMS/hibernate style patterns?
>
>
> Thanks for taking to the time to read a somewhat open ended question.

Re: Best practices for java DTOs to/from Sling

Posted by Julian Sedding <js...@gmail.com>.
Documentation for JSON import via the SLing POST Servlet is available
here: http://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html#importing-content-structures

Regards
Julian

On Thu, Jul 23, 2015 at 2:35 PM, Jason Bailey <Ja...@sas.com> wrote:
> The occasional problem with Sling is that the feature set moves faster than the documentation.
>
> Support for modification of content via JSON has been implemented. Here's some relevant links:
> https://cwiki.apache.org/confluence/display/SLING/FAQ#FAQ-HowdoIcreateanodebypostingajsondocumenttoaURL?
> https://issues.apache.org/jira/browse/SLING-1172
>
> As you can tell, this was actually completed a while back. So the problem you're experiencing is either a bug(new or regression) or there's a problem with how you implemented
>
> Can you provide a simple use  case of the problem you're having posting json?
>
> -Jason
>
> -----Original Message-----
> From: Haefele, Michael [mailto:Michael-Haefele@idexx.com]
> Sent: Wednesday, July 22, 2015 4:36 PM
> To: users@sling.apache.org
> Subject: Best practices for java DTOs to/from Sling
>
> We have a Sling application that we're using basically as a database/file manager for portions of a java Spring application.
>
> In java we have a bunch of DTOs that we import by converting to json using Jackson and persisting to Sling using the import option on the Sling post servlet.
> We then read them using .tidy.infinity.json and convert back to DTOs using Jackson again.
> This is working really well.
>
> But we've reached point where we need to modify some of the data in Sling and it seems like I've hit a bit of a conceptual wall.
> I was thinking we'd keep the DTO pattern going.
> Load the DTO, modify some value, push the updated DTO back to Sling.
>
> But it seems the POST servlet doesn't support json when doing a modify operation.
> I basically took that as a hint that I might be barking up the wrong tree here.
>
> We could also do the updates by posting specific properties, but it seems like that's opening the door to writing a lot of custom update code.
>
>
> Does anyone have any suggestions for best practices for this sort of thing?
> Am I trying too hard to apply RDBMS/hibernate style patterns?
>
>
> Thanks for taking to the time to read a somewhat open ended question.

RE: Best practices for java DTOs to/from Sling

Posted by Jason Bailey <Ja...@sas.com>.
The occasional problem with Sling is that the feature set moves faster than the documentation.

Support for modification of content via JSON has been implemented. Here's some relevant links:
https://cwiki.apache.org/confluence/display/SLING/FAQ#FAQ-HowdoIcreateanodebypostingajsondocumenttoaURL?
https://issues.apache.org/jira/browse/SLING-1172

As you can tell, this was actually completed a while back. So the problem you're experiencing is either a bug(new or regression) or there's a problem with how you implemented

Can you provide a simple use  case of the problem you're having posting json?

-Jason

-----Original Message-----
From: Haefele, Michael [mailto:Michael-Haefele@idexx.com] 
Sent: Wednesday, July 22, 2015 4:36 PM
To: users@sling.apache.org
Subject: Best practices for java DTOs to/from Sling

We have a Sling application that we're using basically as a database/file manager for portions of a java Spring application.

In java we have a bunch of DTOs that we import by converting to json using Jackson and persisting to Sling using the import option on the Sling post servlet.
We then read them using .tidy.infinity.json and convert back to DTOs using Jackson again.
This is working really well.

But we've reached point where we need to modify some of the data in Sling and it seems like I've hit a bit of a conceptual wall.
I was thinking we'd keep the DTO pattern going.
Load the DTO, modify some value, push the updated DTO back to Sling.

But it seems the POST servlet doesn't support json when doing a modify operation.
I basically took that as a hint that I might be barking up the wrong tree here.

We could also do the updates by posting specific properties, but it seems like that's opening the door to writing a lot of custom update code.


Does anyone have any suggestions for best practices for this sort of thing?
Am I trying too hard to apply RDBMS/hibernate style patterns?


Thanks for taking to the time to read a somewhat open ended question.