How to get Component object in Component Presentation storage extension
I am trying to write storage extension in Tridion 2011 where I will extend JPAComponentPresentationDAO and implement ComponentPresentationDAO .
public void create(ComponentPresentation itemToCreate, ComponentPresentationTypeEnum componentPresentationType) throws StorageException < super.create(itemToCreate,componentPresentationType); String tcmURI = Integer.toString(itemToCreate.getComponentId()); Component compObject // I want Component object to get the schema ID PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction"); PublishAction publishAction = new PublishAction(); publishAction.setAction("ADD"); publishAction.setTcmUri(tcmURI); publishActionDAO.store(publishAction); >
In above sample code I want to make Component object using itemToCreate.getComponentId() where I get the component ID, so that I can pass some useful detail to my entity class which will store that data in my database table.
It is a bit unclear what you’re asking. Do you simply want to know how to get the DAO for Component s from within this code?
Yes, actullay I want to handle component publish and unpublish, so that I am trying to get Component object here so that I can get schema id of published or unpublished component
1 Answer 1
You will be able to get the Schema Id from ComponentMeta which is inherited from ItemMeta. First you need to get the ItemDAO from the StorageManagerFactory and then findByPrimaryKey will give to ComponentMeta. This only works after your super.create which should persist the component to broker db. Try this out.
Sample snippet :
ItemDAO item = (ItemDAO) StorageManagerFactory.getDAO(pubid,StorageTypeMapping.COMPONENT_META); ComponentMeta meta = (ComponentMeta) item.findByPrimaryKey(pubid,compid); int schemaID = meta.getSchemaId() ;
Note: you need to pass the pubid, compid from you itemToCreate tcmURI