Discussion:
How to design Magnolia to retrieve/set external data
Paul Shuttlewood (via Magnolia Forums)
2012-07-30 16:12:54 UTC
Permalink
Hello,

I'm new to CMS in general and have been tasked with developing a proof of concept that gets Magnolia talking to an existing self service system (the data consists of a person's user/personal/contact details). The user will need to login then can view/edit their personal/contact details.

I'm after some design guidance on how best to achieve this. Looking through the Magnolia documentation, there doesn't appear to be any clear example of how to retrieve or set data from an external system.

Any guidance or suggestions and the direction I should follow?
--
Context is everything: http://forum.magnolia-cms.com/forum/thread.html?threadId=2e16ec5c-2be3-4d9a-b79d-f6df9f2bc0bd


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Gavan Stockdale (via Magnolia Forums)
2012-07-30 16:19:59 UTC
Permalink
Hi Paul,

Can you provide us with more information on the self service system? Are you referring to Central Authentication Service/single sign on process?

Thanks,

Gavan
--
Context is everything: http://forum.magnolia-cms.com/forum/thread.html?threadId=2e16ec5c-2be3-4d9a-b79d-f6df9f2bc0bd


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Paul Shuttlewood (via Magnolia Forums)
2012-07-31 06:50:46 UTC
Permalink
Hi Gavan,

Our self service system has an existing set of web services that cover the whole the range of login/register/retrieve/set of person details.

I'm half expecting to define a new set of interfaces for the person data so that the CMS is not tighly coupled to the existing web services. Then develop a middle man module that would be able to call the web services and translate the returned objects into the objects CMS is aware of then. Then the display of the objects is done within CMS.

Paul
--
Context is everything: http://forum.magnolia-cms.com/forum/thread.html?threadId=2e16ec5c-2be3-4d9a-b79d-f6df9f2bc0bd


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Unger, Richard
2012-07-31 08:44:31 UTC
Permalink
Hi Paul,

We've integrated several backend services that sound similar to what you are describing.

We have the following general pattern:

- We generate a AXIS2 SOAP client from the WSDL description of the web-services. We insist on a clean WSDL + Schema, so there are no issues with client generation.
- The generated client provides a set of POJOs that will be very convenient, more on that later, as well as the Bindings and Stub classes that can be used to call the service
- We then create one or more magnolia "Model-Classes". Model-Classes are linked to a template, area or component, and provide additional processing capabilities for the template. Normally, we use the "execute()" method of the model to call the web-service methods. We keep the response object in the model for later use by the template.
- The model has "rendering" scope, i.e. each time your template/area/component is rendered, a new model is instantiated and its execute method is called. The model will automagically receive the values from GET or POST parameters in the request, which you can then use when calling the web-service.
- When rendering, we provide getXXX() getter methods in our model that provide access to the POJOs from the web-service as needed. Thanks to Freemarker's BeanWrapper, you can access your data fairly easily from the template, e.g.: ${model.personData.officeLocation.doorNumber}

So it's not hard to do, in the end. The Axis-generated POJOs make it very quick to work with the web-services from the template. The model is really just a thin layer to call the web-service and pass back the data.

Some points to watch for:
- If your web-service exposes sensitive information, or provides much more functionality than needed for the task, it might be better to implement a wrapper-layer at some level, to prevent any "leakage" of sensitive information. While in theory of course you only get to see what you ask for in the template, programmers make mistakes and it's safer if magnolia never gets the information it doesn't need.
- Since you are calling the web-service synchronously from the model during rendering, the web-service should be sufficiently speedy, and you should structure the web-service so that all the information for a given page-render can be retrieved in one SOAP call. If you need 6 SOAP calls for one page-render, the latencies will add up, and the page will be slooow...

For you, the "login" will be one of the points you need to think about. Will you perform a login in magnolia, using, for example, the PUR module? I think it depends a bit on where you plan to keep your "state" - will you need a session for the user in magnolia? One solution that could work stateless in magnolia would be to set a cookie with an authorization token for the web-service, and use this cookie value whenever web-service calls are made, or something like that...

Regards from Vienna,

Richard





-----Ursprüngliche Nachricht-----
Von: user-list-***@magnolia-cms.com [mailto:user-list-***@magnolia-cms.com] Im Auftrag von Paul Shuttlewood (via Magnolia Forums)
Gesendet: Dienstag, 31. Juli 2012 08:51
An: Magnolia User List
Betreff: [magnolia-user] Re: How to design Magnolia to retrieve/set external data

Hi Gavan,

Our self service system has an existing set of web services that cover the whole the range of login/register/retrieve/set of person details.

I'm half expecting to define a new set of interfaces for the person data so that the CMS is not tighly coupled to the existing web services. Then develop a middle man module that would be able to call the web services and translate the returned objects into the objects CMS is aware of then. Then the display of the objects is done within CMS.

Paul
--
Context is everything: http://forum.magnolia-cms.com/forum/thread.html?threadId=2e16ec5c-2be3-4d9a-b79d-f6df9f2bc0bd


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------





----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Paul Shuttlewood (via Magnolia Forums)
2012-07-31 10:18:37 UTC
Permalink
Hi Richard,

Thanks for the detailed reply, it's certainly given me some pointers to look into.

Can I ask what you mean by "We then create one or more magnolia "Model-Classes""? I'm expecting to develop a magnolia module which will contain a new basic POJO model, an interface wrapper layer to my web services and of course my template definitions (in Freemarker as opposed to JSP is my preference). I'm looking at the Magnolia Blossom samples and this I think will give me that. What module/API are you developing to?

Ideally I want to deliver components and area definitions in my module, and allow content definers to create their pages and choose where they place my components/areas on their page. I also need to consider how different clients may want to render the POJO model differently.

My initial idea is that upon login, I will retrieve the complete POJO model for that person (i.e. make all retrieve web service calls). So as the user nagivates the different pages, I just access the different sections of the POJO model. I will only make a web service call if the user updates some part of the model or I need to refresh.

Regards,

Paul
--
Context is everything: http://forum.magnolia-cms.com/forum/thread.html?threadId=2e16ec5c-2be3-4d9a-b79d-f6df9f2bc0bd


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Unger, Richard
2012-07-31 10:37:43 UTC
Permalink
Hi Paul,

Yes, we also develop our own modules. One of our modules exists only to supply model-classes, but that's not the only way to structure it - in theory the model classes can reside in any JAR on magnolia's classpath.
The model-classes are tied to the template-definitions (or areas, or components). When creating your template-definitions, you can specify a "modelClass" property, which identifies a Java class (by fully qualified name). This class is automatically instantiated and initialized by magnolia whenever your template (or area, or component) is rendered.
The model-class can supply additional functionality and data to the template, basically whenever freemarker is "not enough" or cumbersome, you can put that functionality in your model-class and thereby implement it in Java (or Groovy, if you want) instead of freemarker. The instantiated model-class is availabile from freemarker using the variable "model". Try outputting ${model.class.name} in any template script, for example.
Like the templates, areas and components, the model-classes form a hierarchy during rendering. So a component will have a model, and that model will have a parent model, which is the model of the area. And the area's model will have the page's model as a parent...
Model-Classes should inherit from "info.magnolia.rendering.model.RenderingModelImpl", or even better "info.magnolia.module.templatingkit.templates.pages.STKPageModel" (for pages) and "info.magnolia.module.templatingkit.templates.AbstractSTKTemplateModel" (for components).

Blossom is a different way of working, and I have no experience with that - others on this list might be able to help you more with Blossom...
I believe Blossom allows you to define your templates and components programmatically, but really I am not sure how that all works.

If you decide not to use Blossom, you can still pack your template- and component-definitions into your own module, and install (or upgrade) them using magnolia's powerful module bootstrapping mechanism.

What you describe makes sense, but I caution that it is a stateful model, requiring you to maintain a session on the magnolia server which holds the data you loaded for the user after login. In principle, a stateful model is fine, but it does come with scalability problems (lots of sessions means lots of RAM used, and sessions make clustering the public servers harder).

Regards from Vienna,

Richard




-----Ursprüngliche Nachricht-----
Von: user-list-***@magnolia-cms.com [mailto:user-list-***@magnolia-cms.com] Im Auftrag von Paul Shuttlewood (via Magnolia Forums)
Gesendet: Dienstag, 31. Juli 2012 12:19
An: Magnolia User List
Betreff: [magnolia-user] Re: How to design Magnolia to retrieve/set external data

Hi Richard,

Thanks for the detailed reply, it's certainly given me some pointers to look into.

Can I ask what you mean by "We then create one or more magnolia "Model-Classes""? I'm expecting to develop a magnolia module which will contain a new basic POJO model, an interface wrapper layer to my web services and of course my template definitions (in Freemarker as opposed to JSP is my preference). I'm looking at the Magnolia Blossom samples and this I think will give me that. What module/API are you developing to?

Ideally I want to deliver components and area definitions in my module, and allow content definers to create their pages and choose where they place my components/areas on their page. I also need to consider how different clients may want to render the POJO model differently.

My initial idea is that upon login, I will retrieve the complete POJO model for that person (i.e. make all retrieve web service calls). So as the user nagivates the different pages, I just access the different sections of the POJO model. I will only make a web service call if the user updates some part of the model or I need to refresh.

Regards,

Paul
--
Context is everything: http://forum.magnolia-cms.com/forum/thread.html?threadId=2e16ec5c-2be3-4d9a-b79d-f6df9f2bc0bd


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------





----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Lars Fischer (via Magnolia Forums)
2012-07-31 12:37:54 UTC
Permalink
Hi Paul,

there are indeed many possible designs to integrate external data.

I can point you to two very nice diagrams on the Magnolia documentation pages:

http://documentation.magnolia-cms.com/reference/diagrams/integration.html

I've used the second option using Blossom and the Data Module myself and it worked very well.

Using Blossom/Spring gives you some very nice shortcuts when calling Web Services, etc. For example, you could pull data from a
(REST) Web Service in a model or command class with just one line, e. g.:

NewsEvent[] newsEvents = new RestTemplate().getForObject(newsEventsUrl, NewsEvent[].class);

If you are using (remote) Web Services and performance/availability is an issue, you should think about transferring the data asynchronously into the Magnolia Data Module before querying them on a web page - you could use scheduled commands for this. But I guess that scenario would not be the best solution for getting current user information. It could be an approach to store/view/update data handled primarily by an external application.

Regards,
Lars
--
Context is everything: http://forum.magnolia-cms.com/forum/thread.html?threadId=2e16ec5c-2be3-4d9a-b79d-f6df9f2bc0bd


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Paul Shuttlewood (via Magnolia Forums)
2012-08-06 12:23:22 UTC
Permalink
Hi Richard,

If my model classes extend RenderingModelImpl, then I assume I perform my business logic in the execute() method. For me this is obtaining (or nagivating) my POJO model. But how do I access my POJO model from my freemarker script? I.e. the POJO model will have a list of persons, one specific script may want to list the first name and surname of each person on a seperate line.

Regards,

Paul
--
Context is everything: http://forum.magnolia-cms.com/forum/thread.html?threadId=2e16ec5c-2be3-4d9a-b79d-f6df9f2bc0bd


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Unger, Richard
2012-08-06 13:02:43 UTC
Permalink
Hi Paul,

Exactly - you would perform your business logic in the execute() method, and keep anything you need to display around, typically by storing it to fields in the class. So your model class might look something like:

class MyModel ... {
List<Person> personList = null;
public String execute(){
...
personList = loadPersonsBySOAPCall();
...
}

public List<Person> getPersonList() { return personList; }

}


In freemarker, you can now do things like the following:

[if model.personList?has_content]
[#list model.personList as person]
Name: ${person.name!"no name"}<br/>
Age: ${person.age!"no age" }
<hr/>
[/#list]
[#else]
No people were loaded!
[/#if]


How this looks depends a little bit on the shape of your POJOs and how the SOAP Service was constructed.
The basic idea is that if your model (or the POJOs) have a getter method called getXyz(), then you can access the value using model.xyz . So you can retrieve the POJOs via the model, and then retrieve the POJOs fields.

Hope that was clear.

Regards from Vienna,

Richard



-----Ursprüngliche Nachricht-----
Von: user-list-***@magnolia-cms.com [mailto:user-list-***@magnolia-cms.com] Im Auftrag von Paul Shuttlewood (via Magnolia Forums)
Gesendet: Montag, 06. August 2012 14:23
An: Magnolia User List
Betreff: [magnolia-user] Re: How to design Magnolia to retrieve/set external data

Hi Richard,

If my model classes extend RenderingModelImpl, then I assume I perform my business logic in the execute() method. For me this is obtaining (or nagivating) my POJO model. But how do I access my POJO model from my freemarker script? I.e. the POJO model will have a list of persons, one specific script may want to list the first name and surname of each person on a seperate line.

Regards,

Paul
--
Context is everything: http://forum.magnolia-cms.com/forum/thread.html?threadId=2e16ec5c-2be3-4d9a-b79d-f6df9f2bc0bd


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------





----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Paul Shuttlewood (via Magnolia Forums)
2012-08-06 14:00:31 UTC
Permalink
Thanks Richard, that's spot on.
--
Context is everything: http://forum.magnolia-cms.com/forum/thread.html?threadId=2e16ec5c-2be3-4d9a-b79d-f6df9f2bc0bd


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <user-list-***@magnolia-cms.com>
----------------------------------------------------------------
Loading...