Hi Paul,
within...

On Tue, 31 Oct 2017 at 03:52 Paul Benedict Jabines <jabines...@gmail.com>
wrote:

> Hi,
>
> We are currently using Apache Isis for the team. I have some
> straightforward questions below, kindly answer. I look at the apache isis
> doc and screencasts, I cant find the answer of these.
>
> We are integrating Apache Isis with AngularJS via RESTful Objects.
>
> 1. Do we really need to create a View Model for each Domain Entities?
>        a. for the sake of security? where we select only the properties of
> the entity that should be shown.
>

No, not for security, and not for performance either (necessarily).

The real question is whether the REST API you are exposing is a public API
or an internal private API.

If it's a public API, which is to say that there are third-party clients
out over which you have no control, then view models are the way to go.  In
this case view models provide an isolation layer which allow you to modify
the structure of the underlying domain entities without breaking this API.

If it's a private API, which is to say that the only clients of the REST
API are under your  control, then view models are an unnecessary overhead.
In this case, just expose domain entities directly.

The caveat to the "private API" option is that private APIs have a habit of
becoming public APIs.  Even if the REST API is only exposed within your
organisation's intranet, other teams may "discover" your REST API and start
writing applications that consume it.  If that REST API is exposing domain
entities, you could easily break those other teams' clients if you refactor.

If your REST API is intended to be public (or you can't be sure that it
will remain private), the exposing view models will entail a lot of
marshalling of state from domain entities into view models.
There are numerous open source tools that can help with that, for example
modelmapper.org, Dozer <http://dozer.sourceforge.net> and Orika
<https://github.com/orika-mapper/orika>.

Or, rather than marshalling state, the view model could hold a reference to
the underlying domain entity/ies and dynamically read from it (ie, all the
view model's properties are derived from the entity's).

A third option is to define an RDBMS view, and then map a "non-durable"
entity to that view.
The RDBMS view then becomes the public API that must be preserved.
The DataNucleus documents  describe
<http://www.datanucleus.org:15080/products/accessplatform_5_1/jdo/mapping.html#schema_rdbms_views>
how to create non-durable views; a "real-world" example can also be found
in Estatio
<https://github.com/estatio/estatio/blob/rel/tag-1.20.20171025-1442/estatioapp/module/lease/dom/src/main/java/org/estatio/dom/lease/invoicing/viewmodel/InvoiceSummaryForInvoiceRun.java#L53>
.




> 2. What can JAXB View model do which cannot be done by using Apache Isis
> View Model. At the moment, from what I can see on the screen cast, what
> JAXB View model can do can be done using Apache Isis View Model.
>
>
The Apache Isis view models (@ViewModel, or
@DomainObject(nature=VIEW_MODEL)) use a home-grown implementation to
serialize the state of the view model into a memento.  The JAXB ones
instead use JAXB serialization.

While @ViewModel is less annotations, there are some major limitations: it
doesn't support every domain type (see implementation
<https://github.com/apache/isis/blob/master/core/runtime/src/main/java/org/apache/isis/core/runtime/services/memento/Dom4jUtil.java#L113>)
and it also doesn't support collections.

(FYI, I am thinking of improving @ViewModel to remove these limiations.
Within the framework there is actually quite a powerful "memento" service
that can serialize the state of domain objects, a left-over from the
client/server support we used to have from Apache Isis' predecessor,
nakedobjects framework. Hopefully this could be leveraged to give the best
of both worlds).



> Thank you for your response.
>
>
No worries.  Since I couldn't find this material on our website, either,
I've also adapted the above answer and added it, see here
<http://isis.apache.org/guides/ugfun/ugfun.html#__ugfun_building-blocks_view-models_for-rest-clients>
.

HTH
Dan



> --
> - Paul
>
> <
> https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail
> >
> Virus-free.
> www.avast.com
> <
> https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail
> >
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>

Reply via email to