0

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.

Daniel Neagu
  • 1,711
  • 11
  • 13
Manoj Singh
  • 7,569
  • 34
  • 119
  • 198

1 Answers1

3

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Daniel Neagu
  • 1,711
  • 11
  • 13
  • Hi Daniel, thanks for reply!! using above query we can get multiple records as in my case if user publishes new page it will add a record in table with "ADD" in ACTION field and again user publishes same page it will add "UPD" in ACTION field as a new record and if user un-publishes same page will add in new record with "DEL" in ACTION as new record in table. Now in this case I will have multiple entries in table with same tcmuri and publication ID, any suggestions on this – Manoj Singh Jan 10 '13 at 13:43
  • 1
    Hi there. If you need multiple entries from the table you can just use executeQueryListResult instead of executeQuerySingleResult and make sure your method returns List. Then you can just loop through them and execute your business logic. – Daniel Neagu Jan 10 '13 at 16:28