I need the component fields in the extension only (not in application). After that I have to send the component data to some other API.
Below is my sample java code. I am not sure how to get component fields (title, metadata and some fields).
package com.tridion.kd.extensions;
import java.util.Iterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.tridion.configuration.Configuration;
import com.tridion.configuration.ConfigurationException;
import com.tridion.transport.transportpackage.*;
import com.tridion.ItemTypes;
import com.tridion.configuration.*;
import com.tridion.deployer.ProcessingException;
import com.tridion.deployer.Module;
import com.tridion.deployer.Processor;
import com.tridion.util.TCMURI;
public class MyCustomModule extends Module
{
private static Logger log = LoggerFactory.getLogger(MyCustomModule.class);
MetaDataFile compPresMetadata = null;
MetaDataFile componentMeta = null;
Configuration config = null;
MetaDataFile pageMetadata = null;
@SuppressWarnings("deprecation")
public MyCustomModule(Configuration config, Processor processor) throws ConfigurationException
{
super(config, processor);
this.config = config;
log.info("CacheFlusher Value");
}
// This method is called once for each TransportPackage that is deployed.
public void process(TransportPackage data)
{
try
{
ProcessorInstructions instructions = data.getProcessorInstructions();
Iterator iterator = instructions.getArguments();
do
{
if (!iterator.hasNext())
break;
Object argument = iterator.next();
if (argument instanceof Publication)
{
Publication pubKey = (Publication) argument;
log.debug("PublicationName from Response::" + pubKey.getTitle());
log.info("instructions.getMetaData(Page) " + instructions.getMetaData("Pages").getName());
MetaData compPresMetadataInfo = instructions.getMetaData("ComponentPresentations");
MetaData compMetadataInfo = instructions.getMetaData("Components");
MetaData pagesMetadataInfo = instructions.getMetaData("Pages");
compPresMetadata = data.getMetaData("ComponentPresentations", compPresMetadataInfo.getName());
pageMetadata = data.getMetaData("Pages", pagesMetadataInfo.getName());
log.info("compPresMetadataInfo.getName() " + compPresMetadataInfo.getName());
componentMeta = data.getMetaData("Components", compMetadataInfo.getName());
log.info("compMetadataInfo.getName() " + compMetadataInfo.getName());
if(pubKey.getTitle() == "040 Content Library EN")
{
Section section = null;
Iterator<Section> Sections = instructions.getSections();
for (; Sections.hasNext(); processSection(section, data))
{
section = Sections.next();
}
}
}
} while (true);
}
catch (Exception e)
{
log.error("Could not get custom configuration", e);
}
}
protected void processSection(Section section, TransportPackage data)
{
if (log.isDebugEnabled())
{
log.debug(" Section " + section.getName());
}
Iterator iterator = section.getFileItems();
Object item;
for (; iterator.hasNext(); processItem(item, section))
{
item = iterator.next();
}
}
@SuppressWarnings("deprecation")
protected void processItem(Object obj, Section section)
{
if (obj instanceof PageKey)
{
try
{
PageKey pageKey = (PageKey) obj;
Page page = (Page) pageMetadata.getMetaData(pageKey);
TCMURI pageTCMID = page.getId();
//invokeCacheRefreshByContentId(pageTCMID.toString());
log.debug("page.getId().getItemId() " + page.getId().getItemId());
log.debug("page.getId().getItemId() " + page.getId());
}
catch (Exception e)
{
if (log.isErrorEnabled())
{
log.error("Error occured in processing the Page Item" + e.getMessage());
}
}
}
else if (obj instanceof ComponentPresentationKey)
{
if (log.isDebugEnabled())
{
log.debug("Entered ComponentPresentation");
}
try
{
ComponentPresentationKey cpKey = (ComponentPresentationKey) obj;
log.debug("cpKey" + cpKey);
ComponentPresentation componentPresentation = (ComponentPresentation) compPresMetadata.getMetaData(cpKey);
log.debug("compPresMetadata.getMetaData(cpKey)" + compPresMetadata.getMetaData(cpKey));
if (log.isDebugEnabled())
{
log.debug("componentPresentationgetTemplateKey getTitle()"
+ componentPresentation.getTemplateKey().getTitle());
}
TCMURI compTCMID = componentPresentation.getComponentKey().getId();
//log.debug(componentPresentation.getComponentKey().getTitle());
String parsedComponentId = compTCMID.toString();
if (log.isDebugEnabled())
{
log.debug("RefreshCache component id::" + parsedComponentId);
}
if(section.getSchema(parsedComponentId).getTitle() == "Offers")
{
}
}
catch (Exception e)
{
if (log.isErrorEnabled())
{
log.error("Error occured in processing the Component Item" + e.getMessage());
}
}
}
else if(obj instanceof ComponentKey)
{
try
{
ComponentKey compKey = (ComponentKey) obj;
ComponentPresentation componentPresentation = (ComponentPresentation) compPresMetadata.getMetaData(compKey);
log.info("compMetadataInfo.getName() " + componentPresentation.getComponentKey().getId());
}
catch(Exception e)
{
}
}
}
}