Thanks again Dan,

Just making good use of the 'poly' module/addon for my notes functionality,
via a wee bit of 'editor inheritance' :)

On Wed, Sep 16, 2015 at 4:04 PM, Dan Haywood <[email protected]>
wrote:

> As a follow-up, here's a very similar service that's in our Neo4J demo app:
>
>
> https://github.com/isisaddons/isis-app-neoapp/blob/master/dom/src/main/java/neoapp/dom/services/titling/TitlingService.java
>
>
> On 16 September 2015 at 07:02, Dan Haywood <[email protected]>
> wrote:
>
> > Hi Steve,
> >
> > Although there isn't any direct support for this, it's should be
> > relatively easy to do by using the underlying JDO API.
> >
> > As a quick code sketch:
> >
> > public interface CreateTrackingEntity {
> >     void setCreatedBy(String createdBy);
> >     void setCreatedOn(DateTime createdOn);
> > }
> >
> > public interface ModifyTrackingEntity {
> >     void setModifiedBy(String username);
> >     void setModifiedOn(DateTime modifiedOn);
> > }
> >
> >
> > Your entity should implement one or both of the above.
> >
> > Then, define a service such as:
> >
> > @RequestScoped
> > @DomainService(nature=NatureOfService.DOMAIN)
> > public class UpdateableEntityServices implements
> > javax.jdo.listener.StoreLifecycleListener {
> >
> >     @PostConstruct
> >     public void open() {
> >
> >
> isisJdoSupport.getJdoPersistenceManager().addInstanceLifecycleListener(this);
> >     }
> >
> >     @PreDestroy
> >     public void close() {
> >
> >
> isisJdoSupport.getJdoPersistenceManager().removeInstanceLifecycleListener(this);
> >     }
> >
> >     @Programmatic
> >     public void preStore (InstanceLifecycleEvent event) {
> >
> >         final Object pi = event.getPersistentInstance();
> >
> >         if(pi instanceof org.datanucleus.enhancement.Persistable) {
> >             boolean isPersistent =
> > ((org.datanucleus.enhancement.Persistable)pi).dnIsPersistent();
> >
> >             if(!isPersistent) {
> >                 if(pi instanceof CreateTrackingEntity) {
> >
> >  ((CreateTrackingEntity)pi).setCreatedBy(container.getUserName());
> >
> >  ((CreateTrackingEntity)pi).setCreatedOn(clockService.nowAsDateTime());
> >                 }
> >             } else {
> >                 if(pi instanceof ModifyTrackingEntity) {
> >
> >  ((ModifyTrackingEntity)pi).setModifiedBy(container.getUserName());
> >
> >  ((ModifyTrackingEntity)pi).setModifedOn(clockService.nowAsDateTime());
> >                 }
> >             }
> >         }
> >     }
> >
> >     @Programmatic
> >     public void postStore (InstanceLifecycleEvent event) {
> >         // no-op
> >     }
> >
> >     @Inject
> >     private DomainObjectContainer container;
> >
> >     @Inject
> >     private ClockService clockService;
> >
> >     @Inject
> >     private IsisJdoSupport isisJdoSupport;
> > }
> >
> >
> >
> > ~~~~~~~~~~~~
> > There is actually a ticket in JIRA for this [1], so I'll formalize this
> as
> > a service in Isis 1.10.0.
> >
> > HTH
> > Dan
> >
> > [1] https://issues.apache.org/jira/browse/ISIS-867
> >
> >
> > On 16 September 2015 at 05:18, Stephen Cameron <
> [email protected]
> > > wrote:
> >
> >> Hi,
> >>
> >> Could someone please assist me in adding this capability, to automate
> the
> >> creation and update of values in these standard fields
> >>
> >> created_by
> >> created_on
> >> modified_by
> >> modified_on
> >>
> >> That is I need to set the first two on creating a new object, and the
> last
> >> two on modifying an object.
> >>
> >> Thanks
> >> Steve Cameron
> >>
> >
> >
>

Reply via email to