RE: Get field from model in JSON view
hello guillaume. the default json view of sling is 1:1 the content of the repository. normally it makes no sense to store "computed values" in the repository, because it is redundant. the best solution would be to create your own json view for the resource type, e.g. a servlet or a sightly/jsp template. this can use your sling model and output the data (both repository and computed value) as required. stefan >-Original Message- >From: Guillaume Lucazeau [mailto:glucaz...@gmail.com] >Sent: Wednesday, December 09, 2015 3:42 PM >To: users@sling.apache.org >Subject: Get field from model in JSON view > >Hello, > >I have a class model where I generate a value for a property from two other >properties, something like that: > >@Model(adaptables = Resource.class) >public class MyModel extends AbstractResource implements Resource { > > @Inject > private int valueOne; > > @Inject > private int valueTwo; > > private int sum; > > public getSum() { >return sum; > } > > @PostConstruct > public void calculateScore() { >sum = valueOne + valueTwo; > } >} > >I'd like to see this "sum" property when I call the JSON view: >{ > "sling:resourceType": "model/myModel", > "jcr:createdBy": "admin", > "jcr:created": "Mon Dec 07 2015 17:11:31 GMT+0100", > "jcr:primaryType": "sling:Folder", > "valueOne": 10, > "valueTwo": 5, > "sum": 15 > } > >I tried to save it in a ModifiableValueMap properties that I get with >adaptTo() and display it with new JSONObject(properties) but it requires an >administrative authentication, or now a service with a special user. > >I don't mind trying to do that but it seems a bit heavy as a solution, I >was wondering if there would be something easier to do such thing? > >Thank you >Guillaume
Get field from model in JSON view
Hello, I have a class model where I generate a value for a property from two other properties, something like that: @Model(adaptables = Resource.class) public class MyModel extends AbstractResource implements Resource { @Inject private int valueOne; @Inject private int valueTwo; private int sum; public getSum() { return sum; } @PostConstruct public void calculateScore() { sum = valueOne + valueTwo; } } I'd like to see this "sum" property when I call the JSON view: { "sling:resourceType": "model/myModel", "jcr:createdBy": "admin", "jcr:created": "Mon Dec 07 2015 17:11:31 GMT+0100", "jcr:primaryType": "sling:Folder", "valueOne": 10, "valueTwo": 5, "sum": 15 } I tried to save it in a ModifiableValueMap properties that I get with adaptTo() and display it with new JSONObject(properties) but it requires an administrative authentication, or now a service with a special user. I don't mind trying to do that but it seems a bit heavy as a solution, I was wondering if there would be something easier to do such thing? Thank you Guillaume
Re: JobManager.getJob()
Carsten Ziegeler wrote > Roll, Kevin wrote >> JobManager.getJob() claims to find a job, "either scheduled or active". >> However, this method just calls findJobs() internally, which does not claim >> to look at scheduled jobs, and doesn't appear to do so. It seems to be >> necessary to also call JobManager.getScheduledJobs() to ensure that a >> matching job is not scheduled. Is this a bug in the documentation? >> >> > Hi, > > good catch, yes I think this is a bug in the javadoc > and it should actually read "either queued or active" Carsten -- Carsten Ziegeler Adobe Research Switzerland cziege...@apache.org
Re: JobManager.getJob()
Roll, Kevin wrote > JobManager.getJob() claims to find a job, "either scheduled or active". > However, this method just calls findJobs() internally, which does not claim > to look at scheduled jobs, and doesn't appear to do so. It seems to be > necessary to also call JobManager.getScheduledJobs() to ensure that a > matching job is not scheduled. Is this a bug in the documentation? > > Hi, good catch, yes I think this is a bug in the javadoc Regards Carsten -- Carsten Ziegeler Adobe Research Switzerland cziege...@apache.org