Page 1 of 1
Admin Entity Add/Save additional functionalities
Posted: Thu Feb 20, 2014 3:39 am
by nanix84
Hi Guys,
Im wondering if admin too has some sort of Workflow activities.
I want to add a functionality when the user has clicked on "add" or when user hits "save"
If it comes to worst I need to extend and override the methods in AdminBasicEntityController to do that.
I need to change the demo site properties or etc. when the user has modified my added entity in admin.
Is it the Custom Persistence Handlers?
Please let me know whats the best approach on this
Thanks
Re: Admin Entity Add/Save additional functionalities
Posted: Thu Feb 20, 2014 1:35 pm
by phillipuniverse
Yup, custom persistence handlers are the way to go.
Re: Admin Entity Add/Save additional functionalities
Posted: Thu Feb 20, 2014 9:21 pm
by nanix84
Thanks phillip! This is great! less modifications
Lastly.. is this how it works? I don't want to modify the entity. I copied what's on the default implementation when it won't pass a custom persistence handler:
Code: Select all
@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
// return the entity
Entity response;
PersistenceModule myModule = (PersistenceModule) helper;
response = myModule.add(persistencePackage);
return response;
// My additional functionalities here to fetch or query entity items
}
and how can I query all of the records in this entity? like I would get the first record of this entity with the "priority" field sorted in ascending order. Or if it comes to worst, I will create a service for this entity and create DAO objects for manipulation. I just want the simplest and best approach.
Thanks
Re: Admin Entity Add/Save additional functionalities
Posted: Sat Mar 01, 2014 8:36 am
by RapidTransit
Did you add the Persistance Handler in your aplicationContext?
I think you also need to override canHandleAdd like this:
Code: Select all
@Override
public Boolean canHandleAdd(PersistencePackage persistencePackage) {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
return YOURCLASS.class.getName().equals(ceilingEntityFullyQualifiedClassname);
}
If you want to get records from say the catalog just add:
Code: Select all
@Resource(name = "blCatalogService")
protected CatalogService catalogService;
Re: Admin Entity Add/Save additional functionalities
Posted: Mon Mar 03, 2014 4:44 am
by nanix84
Yup I added the persistence handler in the appcontext.
and also the can handle add method.
As for the records, It's not a BLC entity so I need to create a new Service and DAO's for me to access it. I was wondering if there's an easy way for it. So I guess there's not and then I created my own Service/DAO's
Re: Admin Entity Add/Save additional functionalities
Posted: Tue Mar 04, 2014 9:57 pm
by pokemon007
Can you elaborate a bit? How do you hook up your service/dao with AdminBasicController or your derived controller with minimum code change? I have my own thymeleaf-based code doing asset editing, but moving to 3.1 I want to take advantage of the whole thymeleaf-based 3.1 admin UI framework.
Thanks.
-Charlie
Re: Admin Entity Add/Save additional functionalities
Posted: Mon Mar 10, 2014 8:47 pm
by pokemon007
How can I access request/session objects from within CustomerPersistenceHandler?
I'm building a B2B commerce and some entities will have "merchant" property to store the owner of the entity. I can subclass ProductCustomPersistenceHandler and override following methods:
Code: Select all
@Override
public Boolean canHandleAdd(PersistencePackage persistencePackage);
@Override
public Boolean canHandleUpdate(PersistencePackage persistencePackage);
@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException;
In add method I want to set the "merchant" property that is stored in session. The question is how to access request/session object from CustomPersistenceHandler. It seems not passed to this module. Currently I extend AdminProductController and ProductCustomPersistenceHandler such as MerchantProductController and overload add method so I can retrieve current merchant from session and pass it to MerchantCustomPersistenceHandler as one of the properties. It's not that pretty, but don't know if there is better approach.
Thank you in advance!
-Charlie
Re: Admin Entity Add/Save additional functionalities
Posted: Sat Mar 22, 2014 2:20 am
by pokemon007
As no one has better approach I'll take my approach as workaround.
Thanks.
-Charlie
Re: Admin Entity Add/Save additional functionalities
Posted: Sun Mar 23, 2014 7:57 pm
by phillipuniverse
@pokemon007, sorry for the tardy reply; I'm catching up on a bunch of forum posts that I have missed.
Anywhere within the admin application, just like the site application you can use BroadleafRequestContext.getBroadleafRequestContext() which should contain the current Servlet request. You can then grab anything you want from there by just saying BroadleafRequestContext.getBroadleafRequestContext().getRequest().
Also, if you're curious this helpful threadlocal object is included via the BroadleafRequestFilter and is set in the BroadleafRequestProcessor.
Re: Admin Entity Add/Save additional functionalities
Posted: Mon Mar 24, 2014 3:53 pm
by pokemon007
Thank you for the info. This works well and greatly simplified the code!
Appreciate it!
-Charlie