tridiontridion-2011tridion-content-deliverytridion-storage-extension

Create and Update Methods are getting called twice for each in tridion storage extension


I am not able to figure out why my custom Filesystem DOA for create and update method are getting called twice, so I am getting same records twice in my custom storage extension.

I have below class code for handling the page and same written for component and binaries:

package com.tridion.storage.dao;

import java.io.File;

import com.tridion.broker.StorageException;
import com.tridion.data.CharacterData;

import com.tridion.storage.PageMeta;
import com.tridion.storage.StorageManagerFactory;
import com.tridion.storage.StorageTypeMapping;
import com.tridion.storage.filesystem.FSEntityManager;
import com.tridion.storage.filesystem.FSPageDAO;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FSPageContentDAOExtension extends FSPageDAO implements PageDAO 
{
    private static Logger log = LoggerFactory.getLogger(FSPageContentDAOExtension.class);

    public FSPageContentDAOExtension(String storageId, String storageName, File storageLocation) 
    {
        super(storageId, storageName, storageLocation);     
        log.debug("Entering Constructor 1: FSPageContentDAOExtension(" + storageId + ","  + storageLocation.getPath() + ","  + storageName + ")");
    }

    public FSPageContentDAOExtension(String storageId, String storageName, File storageLocation, FSEntityManager entityManager) {
        super(storageId, storageName, storageLocation, entityManager);
        log.debug("Entering Constructor 2: FSPageContentDAOExtension(" + storageId + "," + entityManager.toString() +  ","  + storageLocation.getPath() + ","  + storageName + ")");
    }


    public void create(CharacterData page, String relativepath) throws StorageException 
    {
        super.create(page,relativepath);    

        log.info("Inside the Create");
        log.info("storageId.toLowerCase()-"+storageId.toLowerCase());

        try
        {
                log.info("Inside the Create - page.getPublicationId():"+page.getPublicationId()+"--"+relativepath);
                ItemDAO item = (ItemDAO) StorageManagerFactory.getDAO(page.getPublicationId(),StorageTypeMapping.PAGE_META);
                log.info("Inside the Create - item:"+item.getBindingName());
                if( item !=null)
                {     
                    log.info("Inside the Create - PageMeta:");
                    PageMeta pageMeta = (PageMeta) item.findByPrimaryKey(page.getPublicationId(),page.getId());
                    log.info("Inside the Create - PageMeta2:"+pageMeta.getFileName());
                    if(pageMeta!=null)
                    {
                        log.info("Create - PageMeta-"+pageMeta.getTitle());
                        int publicationId = pageMeta.getPublicationId();
                        String strIgnorePubIds = "232,481";
                        String pubId = Integer.toString(publicationId);
                        if(!strIgnorePubIds.contains(pubId))
                        {
                            String url = pageMeta.getUrl();
                            String tcmURI = Integer.toString(pageMeta.getItemId());
                            PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
                            if(publishActionDAO !=null)
                            {
                                PublishAction publishAction = new PublishAction();          
                                publishAction.setAction("ADD");
                                publishAction.setPublicationID(publicationId);
                                publishAction.setUrl(url);
                                publishAction.setLastPublishedDate(pageMeta.getLastPublishDate());
                                publishAction.setItemType(64);
                                publishAction.setTcmUri(tcmURI);
                                log.debug("Going to Store bean -"+ publishAction.toString());
                                publishActionDAO.store(publishAction);
                                createFlag = false;
                            }

                        } 
                    }
                }           
        }
        catch (StorageException se) 
        {           
            log.error("FSPageContentDAOExtension - Exception occurred " + se);
        }
    }

    public void update(CharacterData page,String originalRelativePath, String newRelativepath)throws StorageException {
        super.update(page,originalRelativePath,newRelativepath);;   
        log.info("Inside the Update");
        log.info("storageId.toLowerCase()-"+storageId);

        try
        {

                log.info("Inside the Update - page.getPublicationId():"+page.getPublicationId()+"--"+originalRelativePath+"--"+newRelativepath);
                ItemDAO item = (ItemDAO) StorageManagerFactory.getDAO(page.getPublicationId(),StorageTypeMapping.PAGE_META);
                log.info("Inside the Update - item:"+item.getBindingName());
                if( item !=null)
                {     
                    log.info("Inside the Update - PageMeta:");
                    PageMeta pageMeta = (PageMeta) item.findByPrimaryKey(page.getPublicationId(),page.getId());
                    log.info("Inside the Update - PageMeta2:"+pageMeta.getFileName());
                    if(pageMeta!=null)
                    {
                        log.info("Update - PageMeta-"+pageMeta.getTitle());
                        int publicationId = pageMeta.getPublicationId();
                        String strIgnorePubIds = "232,481";
                        String pubId = Integer.toString(publicationId);
                        if(!strIgnorePubIds.contains(pubId))
                        {
                            String url = pageMeta.getUrl();
                            String tcmURI = Integer.toString(pageMeta.getItemId());
                            PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
                            if(publishActionDAO !=null)
                            {
                                PublishAction publishAction = new PublishAction();          
                                publishAction.setAction("UPD");
                                publishAction.setUrl(url);
                                publishAction.setPublicationID(publicationId);
                                publishAction.setLastPublishedDate(pageMeta.getLastPublishDate());
                                publishAction.setItemType(64);
                                publishAction.setTcmUri(tcmURI);
                                log.debug("Going to Store bean -"+ publishAction.toString());
                                publishActionDAO.store(publishAction);
                                createFlag = false;
                            }                       
                        } 
                    }
                }
        }
        catch (StorageException se) 
        {           
            log.error("FSPageContentDAOExtension - Exception occurred " + se);
        }

    }

    public void remove(final int publicationId, final int pageID, final String relativePath) throws StorageException {

        log.info("Inside the Delete");      
        try
        {

                ItemDAO item = (ItemDAO) StorageManagerFactory.getDAO(publicationId,StorageTypeMapping.PAGE_META);
                if( item !=null)
                {       
                    PageMeta pageMeta = (PageMeta) item.findByPrimaryKey(publicationId,pageID);

                    if(pageMeta!=null)
                    {
                        log.info("Delete - PageMeta-"+pageMeta.getTitle());                 
                        String strIgnorePubIds = "232,481";
                        String pubId = Integer.toString(publicationId);
                        if(!strIgnorePubIds.contains(pubId))
                        {
                            String url = pageMeta.getUrl();
                            String tcmURI = Integer.toString(pageMeta.getItemId());
                            PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
                            if(publishActionDAO !=null)
                            {
                                PublishAction publishAction = new PublishAction();          
                                publishAction.setAction("DEL");
                                publishAction.setUrl(url);
                                publishAction.setLastPublishedDate(pageMeta.getLastPublishDate());
                                publishAction.setItemType(64);
                                publishAction.setTcmUri(tcmURI);
                                publishAction.setPublicationID(publicationId);
                                log.debug("Going to Store bean -"+ publishAction.toString());
                                publishActionDAO.store(publishAction);
                            }

                        } 
                    }
                }           
        }
        catch (StorageException se) 
        {           
            log.error("FSPageContentDAOExtension - Exception occurred " + se);
        }
        super.remove(publicationId, pageID, relativePath);  
    }
}

my Storage bundle as below:

<?xml version="1.0" encoding="UTF-8"?>
<StorageDAOBundles>
    <StorageDAOBundle type="persistence">
        <StorageDAO typeMapping="PublishAction" class="com.tridion.storage.dao.JPAPublishActionDAO" />
    </StorageDAOBundle>

    <StorageDAOBundle type="filesystem">
    <StorageDAO typeMapping="Binary" class="com.tridion.storage.dao.FSBinaryContentDAOExtension" />
    </StorageDAOBundle>

    <StorageDAOBundle type="filesystem">
        <StorageDAO typeMapping="Page" class="com.tridion.storage.dao.FSPageContentDAOExtension" />
    </StorageDAOBundle>

    <StorageDAOBundle type="filesystem">
        <StorageDAO typeMapping="ComponentPresentation" class="com.tridion.storage.dao.FSComponentContentDAOExtension" />
    </StorageDAOBundle>
</StorageDAOBundles>

My Sample cd_storage XML

<Storages>
    <StorageBindings>
        <Bundle src="search_dao_bundle.xml"/>
    </StorageBindings>  
    <Storage Type="persistence" Id="searchdb" dialect="MSSQL" Class="com.tridion.storage.persistence.JPADAOFactory">
        <Pool Type="jdbc" Size="5" MonitorInterval="60" IdleTimeout="120" CheckoutTimeout="120" />
        <DataSource Class="com.microsoft.sqlserver.jdbc.SQLServerDataSource">
            <Property Name="serverName" Value="*****" />
            <!--Property Name="portNumber" Value="1433" /-->
            <Property Name="databaseName" Value="**********" />
            <Property Name="user" Value="*****" />
            <Property Name="password" Value="********" />
        </DataSource>
    </Storage>

    <Storage Type="filesystem" Class="com.tridion.storage.filesystem.FSDAOFactory" Id="defaultFile" defaultFilesystem="false">
        <Root Path="F:\test.com New" />
    </Storage>
    <Storage Type="filesystem" Class="com.tridion.storage.filesystem.FSDAOFactory" Id="defaultDataFile" defaultFilesystem="true" defaultStorage="true">
        <Root Path="F:\test.com New\data" />
    </Storage>  
</Storages>
<ItemTypes defaultStorageId="defaultdb" cached="false"> 
        <Item typeMapping="PublishAction" cached="false" storageId="searchdb" />    
        <Item typeMapping="Query" storageId="defaultdb"/>
        <Item typeMapping="SearchFilter" storageId="defaultDataFile"/>
        <Item typeMapping="XSLT" cached="false" storageId="defaultDataFile"/>
        <Item typeMapping="ComponentPresentation" itemExtension=".Jsp" cached="false" storageId="defaultDataFile"/>
        <Item typeMapping="ComponentPresentation" itemExtension=".Asp" cached="false" storageId="defaultDataFile"/>
        <Item typeMapping="ComponentPresentation" itemExtension=".Xml" cached="false" storageId="defaultDataFile"/>
        <Item typeMapping="ComponentPresentation" itemExtension=".txt" cached="false" storageId="defaultDataFile"/>
        <Item typeMapping="Schema" cached="false" storageId="defaultDataFile"/>
        <Item typeMapping="Page" cached="false" storageId="defaultFile"/>
        <Item typeMapping="Binary" cached="false" storageId="defaultFile"/>
</ItemTypes>    

Solution

  • The reason why two records where getting inserted in my custom table was that we are having two custom PAGE Deployer extension implemented on our presentation server.

    So, both the deployer are calling the base class FSPageDAO and interface methods of PageDAO.

    Above problem can be solved only if we have got some code to handle the restriction of calling base classes in our DAO.

    Else there is no way to control this if you have deployer extension implemented on the server.

    Please suggest, if we can check and control in our DAO (if possible).

    Thanks.