以下は、DAO でコンポーネントとバイナリを追跡するためのサンプル コードです。
コンポーネント: 追加するサンプル コード。更新と削除も同様です。
@Component("JPAComponentDAOExtension")
@Scope("prototype")
public class JPAComponentDAOExtension extends JPAComponentPresentationDAO implements ComponentPresentationDAO
{
public JPAComponentDAOExtension(String storageId, EntityManagerFactory entityManagerFactory, String storageName)
{
super(storageId, entityManagerFactory, storageName);
}
public JPAComponentDAOExtension(String storageId, EntityManagerFactory entityManagerFactory, EntityManager entityManager, String storageName)
{
super(storageId, entityManagerFactory, entityManager, storageName);
}
public void create(ComponentPresentation itemToCreate, ComponentPresentationTypeEnum componentPresentationType) throws StorageException
{
super.create(itemToCreate,componentPresentationType);
String tcmURI = Integer.toString(itemToCreate.getComponentId());
ItemDAO item = (ItemDAO) StorageManagerFactory.getDAO(itemToCreate.getPublicationId(),StorageTypeMapping.COMPONENT_META);
ComponentMeta meta = (ComponentMeta) item.findByPrimaryKey(itemToCreate.getPublicationId(),itemToCreate.getComponentId());
String schemaID = Integer.toString(meta.getSchemaId()) ;
PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
PublishAction publishAction = new PublishAction();
publishAction.setAction("ADD");
publishAction.setTcmUri(tcmURI);
publishAction.setSchemaID(schemaID);
publishActionDAO.store(publishAction);
}
}
バイナリ: サンプル コード Add と update と delete も同様
@Component("JPABinaryDAOExtension")
@Scope("prototype")
public class JPABinaryDAOExtension extends JPABinaryContentDAO implements BinaryContentDAO
{
public JPABinaryDAOExtension(String storageId, EntityManagerFactory entityManagerFactory, String storageName)
{
super(storageId, entityManagerFactory, storageName);
}
public JPABinaryDAOExtension(String storageId, EntityManagerFactory entityManagerFactory, EntityManager entityManager, String storageName)
{
super(storageId, entityManagerFactory, entityManager, storageName);
}
public void create(final BinaryContent binaryContent, final String relativePath) throws StorageException
{
super.create(binaryContent, relativePath);
String url = relativePath;
String tcmURI = Integer.toString(binaryContent.getBinaryId());
ItemDAO item = (ItemDAO) StorageManagerFactory.getDAO(binaryContent.getPublicationId(),StorageTypeMapping.BINARY_META);
BinaryMeta binarymeta = (BinaryMeta) item.findBinaryByPrimaryKey(binaryContent.getPublicationId(),binaryContent.getBinaryId());
binarymeta.getBinaryType();//to get the binary type
//You can also check the Relative path as below for specific binary type entries as suggested by Mihai
if (relativePath.toLowerCase().endsWith(".pdf")) //Looking for PDFs only
{
PublishActionDAO publishActionDAO = (PublishActionDAO) StorageManagerFactory.getDefaultDAO("PublishAction");
PublishAction publishAction = new PublishAction();
publishAction.setAction("ADD");
publishAction.setUrl(url);
publishAction.setTcmUri(tcmURI);
publishActionDAO.store(publishAction);
}
}
}