I have succesfully able to populate the my storage extension table using my custom deployer, now I can see my records are going perfectly if user publish any page.
Now I want to handle the Unpublishing part, so I have written the Custom page undeployer, please see sample code below:
@SuppressWarnings({ "rawtypes" })
public void process(TransportPackage data) throws ProcessingException
{
ProcessorInstructions instructions = data.getProcessorInstructions();
try
{
for (Iterator iterator = instructions.getArguments(); iterator.hasNext(); )
{
Object argument = iterator.next();
if (argument instanceof PageKey)
{
PageKey pageKey = (PageKey)argument;
TCDURI pageMetaURI = new TCDURI(pageKey.getId().getPublicationId(), 1168231104576L, pageKey.getId().getItemId());
PageMeta pageMeta = this.pageMetaHome.findByPrimaryKey(pageMetaURI.getPublicationId(),
(int)pageMetaURI.getItemId());
if (pageMeta == null)
{
DeploymentHandler.undeploy(pageMetaURI);
}
else
{
PublishAction publishAction = new PublishAction();
publishAction.setAction("DEL");
long id = publishAction.getId();
PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
publishAction = publishActionDAO.findByPrimaryKey(id);
if (publishAction == null)
{
log.debug("FindByPrimaryKey: cannot retrieve object with primary key:" + id);
}
else
{
publishAction = publishActionDAO.update(publishAction);
log.debug("SearchPageUndeployer Updated bean -" + publishAction);
}
}
}
}
}
catch (Exception e)
{
throw new ProcessingException("SearchPageUndeployer: Could not undeploy page", e);
}
super.process(data);
}
In above code you can see I am trying to update my new storage extension "PublishAction", however when I am trying to fetch the ID from the table for which record I want to modify, I am always getting ID as 0 as I am not able to get the ID from the table.
Please suggest what need to implemented in my DAO to get the ID of from table for record which needs to be updated.
Thanks.
You can create in your DAO a method like findByTCMURI
to search for your publish action based on the page tcm uri. The code would be something like this:
public PublishAction findByTCMURI(String tcmURI) throws StorageException {
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("from PublishAction pa where pa.tcmuri = :tcmuri");
Map<String, Object> queryParams = new HashMap<String, Object>();
queryParams.put("tcmuri", tcmURI);
return executeQuerySingleResult(queryBuilder.toString(), queryParams);
}
Should do the trick. Hope this helps.