Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to manually create item using model driven assembler

Avatar

Former Community Member

Hello

I am using Model Driven Development, however all of my data insertion is not going to happen via the forms. There may be a background process that may pull the data from some where and insert into the database table, I am trying to use the existing assembler e.g, CurrencyAssembler to fetch all data or create a new item into it. How can I do it? I tried to instantiate CurrencyAssembler in my java class and call createItem(Currency) but I get null pointer exception, If I call the fill() on it, it needs PropertySpecifier object which is not allowed to be created outside its package. How do I use these assemblers for my non-form push and pull?

thanks

RK

1 Accepted Solution

Avatar

Correct answer by
Employee

From my response in a different thread: You should pass the destination name to DST. And it is called <ModelName>.<NameOfEntity>.

With respect to PropertySpecifiers:

You should use the PropertySpecifier.getPropertySpecifier(String destName, List properties, boolean includeDefault [, isUpdate]) factory method. It is described here: http://help.adobe.com/en_US/enterpriseplatform/10.0/AEPDeveloperGuide/WSc3ff6d0ea77859461172e0811f00...

Rohit

View solution in original post

14 Replies

Avatar

Former Community Member

There are a couple of things you can do here: either you can simply notify data services of the change made via the separate process. This will allow the changes to be pushed out to clients and on the cluster. Alternately you can have the data services assembler itself persist changes from Java.

The way to do this is via the DataServiceTransaction API. This is only available from the webapp in which the message broker itself is running. Calling createItem()/updateItem()/deleteItem() on the DST will cause messages to be sent out to registered clients. If you set sendChangesToAdapter to true, it will also handle the actual persistence for you.

You can create an instance of DataServiceTransaction using begin() or use getCurrentDataServiceTransaction() to get the current DST if one already exists. Please make sure you call rollback() or commit() as appropriate when done with the DST.

Avatar

Former Community Member

Thanks for the response.. I still have some issues and doubts

I am calling the method doSomething() from flex client using flash remoting. Inside this, I am testing the DataServiceTransaction. Eventually there would be another thread in the webapp that will do the database updates.

public class MyApiMgr {

public void doSomething() {
         DataServiceTransaction dtx = DataServiceTransaction.begin(false); 
         //DataServiceTransaction dtx = DataServiceTransaction.getCurrentDataServiceTransaction(); < -- this results in null pointer exception
         dtx.setSendChangesToAdapter(true);
         Currency c1 = new Currency();
         c1.setCurrencyCode("ABC");
         c1.setCurrencyName("Dummy Currency");
         c1.setCurrencyLastUpdated(new Date());
         dtx.createItem("currencyService", c1); <-- this results in the exception below
         dtx.commit();

}

}

[RPC Fault faultString="No destination with id 'currencyService' is registered with the DataService." faultCode="Server.Processing" faultDetail="null"]

For model driven development, the LCDS manual explains not to configure any destination in the data-management-config.xml file, it is configured automatically so how do we send information back to the client, no db insertion is happening either.

pls help.

Avatar

Correct answer by
Employee

From my response in a different thread: You should pass the destination name to DST. And it is called <ModelName>.<NameOfEntity>.

With respect to PropertySpecifiers:

You should use the PropertySpecifier.getPropertySpecifier(String destName, List properties, boolean includeDefault [, isUpdate]) factory method. It is described here: http://help.adobe.com/en_US/enterpriseplatform/10.0/AEPDeveloperGuide/WSc3ff6d0ea77859461172e0811f00...

Rohit

Avatar

Former Community Member

As a follow up on this thread, when the updates are sent to the client (using the DataServiceTransaction.commit()), which function gets called in the mxml file. I want to catch those events in the client and act on them accordingly. Currently they are being silently written to grid on my screen...

Avatar

Level 8

The ActionScript files that are generated from the model implement the service calls for the client. You can override the functions to add debug logic.

_Super_Servicename.as is a superclass....do not modify this file, it gets overwritten every time you save the model

Servicename.as extends the superclass. Edit this file, it will not get overwrittin. Override the superclass functions as required.

http://help.adobe.com/en_US/LiveCycleDataServicesES/3.1/Developing/WSe81149e85f4b32cb58d6bd19126e806...

scott

Avatar

Former Community Member

Scott

Thanks for the response but which method from that file gets called when a response is received from the server..

I checked the file SuperServicename.as and it has the Fill methods and the ones to create/update an item etc..

Thanks

RK

Avatar

Former Community Member

Rupak,

I believe if you register a listener on the ArrayCollection you get as a result of the fill, you will get an event CollectionEvent.COLLECTION_CHANGE on data coming in from the server.

Regards,

Ashish Vashisht

Avatar

Former Community Member

Ok, to cut the chase, all I want to do is to display on the top of the grid the newly added items to the grid (basically keep the table sorted, latest event always on the top). I am getting these items to be displayed in real time by server side push.

How do I achieve this..I am using advancedDataGrid but I can use DataGrid Too if that helps…

Avatar

Employee

All DataService CRUD methods return an AsyncToken.  You can add a TokenResponder to this token with you callback function specificed.

http://help.adobe.com/en_US/LiveCycleDataServicesES/3.1/Modeling/WS63EC411D-CAB9-4f46-A6FC-D3864605D...

Hope this helps,

Pam Colwell

DataServices Team

Avatar

Employee

> all I want to do is to display on the top of the grid the newly added items to the grid

In the implementing assembler, in the refreshFill() method return PREPEND_TO_FILL

http://help.adobe.com/en_US/enterpriseplatform/10.0/ExperienceServicesAPI/flex/data/assemblers/Assem...

Is this getting you closer?

Pam Colwell

DataServices Team

Avatar

Former Community Member

Pam

I think so but am still not there.. I am using the following code to push the entry from the server. How do I specify PREPEND_TO_FILL.

public void doSomething() {
DataServiceTransaction dtx = DataServiceTransaction.begin(false);
dtx.setSendChangesToAdapter(true);
Currency c1 = new Currency();
c1.setCurrencyCode("ABC");
c1.setCurrencyName("Dummy Currency");
c1.setCurrencyLastUpdated(new Date());
dtx.createItem("currencyService", c1); <-- this results in the exception below
dtx.commit();

}

thanks

Rupak

Avatar

Employee

You can also register an eventListener on the DataService on the client side.  This will receive server side push events.

Avatar

Former Community Member

Pam

I like the PREPEND approach but not sure if it can be used with code snippet I am using..

If you are referring to registering an eventListener on DataService as in :-

  <services:AlarmService id="alarmServicefault="alarmFaultHandler(event)" result="alarmResultHandler(event)" />

then the alarmResultHandler() doesnot get called when the data is pushed from the server using DataServiceTransaction. It gets called when I launch the screen and it calls Fill() to populate the grid..

pls advise

thanks

Avatar

Employee

> DataServiceWrapper that I can add an event listener on MessageEvent.MESSAGE but when I tried it, the handler never gets called when a service side push is performed on this service...Checking again,, I dont even see this event in the reference anymore

DataServiceWrapper has a serviceControl property that isa DataService

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/com/adobe/fiber/services/wrapper/...

You can add your event listener to this property