How to get Component object in Component Presentation storage extension

386 views Asked by At

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 usingitemToCreate.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.

1

There are 1 answers

1
Ram G On BEST ANSWER

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