Create Export Content Catalog Cronjob.

 items.xml



<enumtype code="TargetType" autocreate="true" generate="true">

      <value code="LOCAL" />

<value code="BLOB" />

        </enumtype>



<relation code="AdvancedTypeExportConfig2Types" autocreate="true"

generate="true" localized="false">

<deployment table="AdvExportConfig2Types"

typecode="31000" />

<sourceElement qualifier="exportConfigurations"

type="AdvancedTypeExportConfiguration" cardinality="many" ordered="false">

<description>type export configs</description>

</sourceElement>

<targetElement qualifier="typesToExport" type="ComposedType"

cardinality="many" ordered="true" collectiontype="list">

<description>composed types that we will export</description>

</targetElement>

</relation>

<relation code="AdvancedTypeExportConfig2CatVersion"

autocreate="true" generate="true" localized="false">

<deployment table="AdvExConfig2CatVersion"

typecode="31001" />

<sourceElement qualifier="exportConfigurations"

type="AdvancedTypeExportConfiguration" cardinality="many" ordered="false">

<description>type export configs</description>

</sourceElement>

<targetElement qualifier="catalogVersionsToExport" type="CatalogVersion"

cardinality="many" ordered="false" collectiontype="set">

<description>catalog versions to export</description>

</targetElement>

</relation>

<relation code="AdvancedTypeExportConfig2Lang"

autocreate="true" generate="true" localized="false">

<deployment table="AdvExConfig2Lang"

typecode="31002" />

<sourceElement qualifier="exportConfigurations" type="AdvancedTypeExportConfiguration" cardinality="many" ordered="false">

<description>type export configs</description>

</sourceElement>

<targetElement qualifier="languages" type="Language"

cardinality="many" ordered="false" collectiontype="set">

<description>languages to export</description>

</targetElement>

</relation>

<relation code="AdvancedTypeExportConfig2BlackListedAttrDesc"

autocreate="true" generate="true" localized="false">

<deployment table="AdvExConfig2BlkAttrDesc"

typecode="21003" />

<sourceElement qualifier="blackListedExportConfigurations" type="AdvancedTypeExportConfiguration" cardinality="many" ordered="false">

<description>type export configs</description>

</sourceElement>

<targetElement qualifier="blacklistedAttributes" type="AttributeDescriptor"

cardinality="many" ordered="true" collectiontype="set">

<description>languages to export</description>

</targetElement>

</relation>

<relation code="AdvancedTypeExportConfig2BlacklistedTypes"

autocreate="true" generate="true" localized="false">

<deployment table="AdvExConfig2BlkTypes"

typecode="31005" />

<sourceElement qualifier="blackListedExportConfigurations" type="AdvancedTypeExportConfiguration" cardinality="many" ordered="false">

<description>type export configs</description>

</sourceElement>

<targetElement qualifier="blacklistedTypes" type="ComposedType"

cardinality="many" ordered="true" collectiontype="set">

<description>languages to export</description>

</targetElement>

</relation>

        




<itemtype code="AdvancedTypeExportCronJob" extends="CronJob" jaloclass="com.msasafety.ac.jalo.advancedexport.AdvancedTypeExportCronJob" autocreate="true" generate="true">

<attributes>

<attribute qualifier="exportScript" type="ImpExMedia">

<persistence type="property"/>

</attribute>

<attribute qualifier="exportedMedia" type="ImpExMedia">

<persistence type="property"/>

</attribute>

<attribute qualifier="exportedData" type="ImpExMedia">

<persistence type="property"/>

</attribute>

<attribute qualifier="exportConfiguration" type="AdvancedTypeExportConfiguration">

<persistence type="property"/>

<modifiers optional="false"/>

</attribute>

<!-- Enhancement 6 Start here -->

<attribute qualifier="target" type="TargetType">

<persistence type="property"/>

<defaultvalue>em().getEnumerationValue("TargetType", "LOCAL")</defaultvalue>

</attribute>

<!-- Enhancement 6 Ends here -->

</attributes>

</itemtype>

<itemtype code="AdvancedTypeExportConfiguration" extends="GenericItem" jaloclass="com.msasafety.ac.jalo.advancedexport.AdvancedTypeExportConfiguration" autocreate="true" generate="true">

<deployment table="AdvExportConfig"

typecode="31004" />

<attributes>

<attribute type="java.lang.String" qualifier="code">

<persistence type="property"/>

<modifiers unique="true" optional="false"/>

</attribute>

<attribute type="java.util.Date" qualifier="lastExport">

<persistence type="property"/>

</attribute>

<attribute type="java.util.Date" qualifier="creationDate">

<persistence type="property"/>

</attribute>

<attribute type="java.util.Date" qualifier="modifiedDate">

<persistence type="property"/>

</attribute>

<attribute type="java.lang.Boolean" qualifier="relationsAsAttributes">

<persistence type="property"/>

<modifiers optional="false"/>

<defaultvalue>java.lang.Boolean.TRUE</defaultvalue>

</attribute>

</attributes>

</itemtype>





/**

 * 

 */

package com.msasafety.ac.advancedexport;

import com.msasafety.ac.model.advancedexport.AdvancedTypeExportCronJobModel;

import static java.io.File.separatorChar;

import de.hybris.platform.cronjob.enums.CronJobResult;

import de.hybris.platform.cronjob.enums.CronJobStatus;

import de.hybris.platform.impex.model.ImpExMediaModel;

import de.hybris.platform.servicelayer.config.ConfigurationService;

import de.hybris.platform.servicelayer.cronjob.AbstractJobPerformable;

import de.hybris.platform.servicelayer.cronjob.PerformResult;

import de.hybris.platform.servicelayer.impex.ExportConfig;

import de.hybris.platform.servicelayer.impex.ExportConfig.ValidationMode;

import de.hybris.platform.servicelayer.impex.ExportResult;

import de.hybris.platform.servicelayer.impex.ExportService;

import de.hybris.platform.servicelayer.impex.ImpExResource;

import de.hybris.platform.servicelayer.impex.impl.StreamBasedImpExResource;

import de.hybris.platform.servicelayer.media.MediaService;

import de.hybris.platform.util.CSVConstants;

import com.msasafety.ac.enums.TargetType;


import java.io.*;

import java.net.URISyntaxException;

import java.nio.charset.StandardCharsets;

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.Paths;

import java.security.InvalidKeyException;

import java.util.Date;


import org.apache.commons.io.FileUtils;

import org.apache.commons.lang.StringUtils;

import org.apache.log4j.Logger;

import org.springframework.beans.factory.annotation.Autowired;



import org.springframework.integration.zip.transformer.SpringZipUtils;

import org.apache.commons.configuration.Configuration;



/**

 * @author hydev

 *

 */

public class AdvancedTypeExportJob extends AbstractJobPerformable<AdvancedTypeExportCronJobModel> {

private static final String TARGET_TYPE_LOCAL = "LOCAL";

private static final String TARGET_TYPE_BLOB = "BLOB";

private static final String CMS_JOB = "export-CMS-Catalog";

private static final String SOLR_JOB = "export-SOLR-Setup";

private static final String PCM_JOB = "export-Product-Staged";

private static final String CLASSIFICATION_JOB = "export-ClassificationSystem";

private static final String CONFIG_GET_CONNECTION_DIRECT = "bfs.blob.build.connection.direct";

private static final String CONFIG_AZURE_CONNECTION_STRING = "azure.hotfolder.storage.account.connection-string";

private static final Logger LOG = Logger.getLogger(AdvancedTypeExportJob.class);


// private ModelService modelService;

private ExportService exportService;

@Autowired

private ConfigurationService configurationService;

@Autowired

private MediaService mediaService;


@Override

public PerformResult perform(final AdvancedTypeExportCronJobModel cron) {

try {

LOG.info(".........perform started........");

final String exportString = generateExportScript(cron);

LOG.info(".........Writing the file to blob started........");

copyToBlob(cron, exportString, cron.getCode().concat("-" + "Script"), ".txt", true, false, false);

LOG.info("........Writing the file to blob end............");

LOG.info("***** Exporting types ********");

LOG.info("Using script.......");

LOG.info(exportString);

final ExportResult result = getExportResultByConfig(cron, exportString);

if (result.isSuccessful()) {

LOG.info("***** Result is successful********");

cron.setExportedData(result.getExportedData());

cron.setExportedMedia(result.getExportedMedia());

modelService.save(cron);

LOG.info("***** Result is successful end ********");

}

LOG.info("........Writing the Data to blob started............");

copyToBlob(cron, exportString, cron.getCode().concat("-" + "Data"), ".csv", false, true, false);

LOG.info("........Writing the Data to blob end............");

/*

* LOG.info("........Writing the Media to blob started............");

* copyToBlob(cron, exportString, cron.getCode().concat("-" + "Media"), ".zip",

* false, false, true);

* LOG.info("........Writing the Media to blob end............");

*/

LOG.info(".........perform ended........result successful ? : "+result.isSuccessful());

return result.isSuccessful() ? new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED) : new PerformResult(CronJobResult.FAILURE, CronJobStatus.FINISHED);

} catch(Exception e) {

LOG.info("......... perform ended........with exceptions :  "+e.getMessage());

LOG.error(e.getMessage(), e);

return new PerformResult(CronJobResult.FAILURE, CronJobStatus.FINISHED);

}

}


private ExportResult getExportResultByConfig(final AdvancedTypeExportCronJobModel cron, final String exportString) throws UnsupportedEncodingException {

final ImpExResource exportResource = new StreamBasedImpExResource(

new ByteArrayInputStream(exportString.getBytes(StandardCharsets.UTF_8)), CSVConstants.HYBRIS_ENCODING);

final ExportConfig exportConfig = new ExportConfig();

exportConfig.setFailOnError(false);

exportConfig.setValidationMode(ValidationMode.RELAXED);

exportConfig.setScript(exportResource);

exportConfig.setSingleFile(true);

cron.setExportScript(exportResource.getMedia());

modelService.save(cron);

return exportService.exportData(exportConfig);

}


private void copyToBlob(AdvancedTypeExportCronJobModel cron, String exportString, String filename, String fileExtension,

                        boolean copyScript, boolean copyData, boolean copyMedia) throws IOException, URISyntaxException, InvalidKeyException {

//Creating a sample file

File sourceFile = File.createTempFile(filename, fileExtension);

LOG.info("Creating a sample file at: " + sourceFile.toString());

try(final BufferedWriter output = new BufferedWriter(new FileWriter(sourceFile))) {

if (copyScript) {

LOG.info("******* copyScript *******");


output.write(exportString);

} else if (copyData) {

LOG.info("******* copyData start *******");

final ExportResult result = getExportResultByConfig(cron, exportString);

sourceFile = writeFileFromMedia(result.getExportedData(), sourceFile);

LOG.info("******* copyData end *******");

} else if (copyMedia) {

LOG.info("******* copyMedia start *******");

final ExportResult result = getExportResultByConfig(cron, exportString);

sourceFile = writeZipFileFromMedia(result.getExportedMedia(), sourceFile);

LOG.info("******* copyMedia end *******");

}

}


}


//TODO please check, this is not in use. if not needed, please remove

/**

* @param result

*/

private void copyExportedMediaToExportDir(final ExportResult result, final String exportPrefix, final TargetType target) throws IOException {

if(target.getCode().endsWith(TARGET_TYPE_LOCAL)) {

LOG.info("***** In copyExportedMediaToExportDir********");

final String exportDir = configurationService.getConfiguration().getString("advancedexport.export.dir");

LOG.info("***** exportDir********" + exportDir);

if (StringUtils.isBlank(exportDir)) {

throw new IOException("No exportDir provided");

}

final File dir = new File(exportDir);

if (!dir.exists() && !dir.mkdirs()) {

throw new IOException("Directory " + exportDir + " does not exist. Unable to create it.");

}

if (dir.isDirectory() && dir.canWrite()) {

final Path dirPath = Paths.get(dir.getAbsolutePath());

LOG.info("Directory " + exportDir + " exist.Started Writing");

copyExportedMediaFile(dirPath, result.getExportedData(), exportPrefix);

copyExportedMediaFile(dirPath, result.getExportedMedia(), exportPrefix);

} else {

LOG.error("Unable to write to " + exportDir + " or it is not a directory");

}

} else {

LOG.warn("target type is not " + TARGET_TYPE_LOCAL + ", but is " + target.getCode() + ". Ignoring.");

}

}


private void copyExportedMediaFile(final Path targetDir, final ImpExMediaModel impexModel, final String exportPrefix) throws IOException {

if(impexModel != null) {

LOG.info("copying the files");

Files.copy(Paths.get(findRealMediaPath(impexModel)),

targetDir.resolve(StringUtils.isEmpty(exportPrefix) ? "" : exportPrefix + impexModel.getRealFileName() + new Date()));

LOG.info("copying the end");

} else {

LOG.warn("impexModel is null. Ignoring");

}

}


private String findRealMediaPath(final ImpExMediaModel impexModel) {

final StringBuilder stringBuilder = new StringBuilder()

.append(configurationService.getConfiguration().getProperty("HYBRIS_DATA_DIR")).append(separatorChar)

.append("media").append(separatorChar)

.append("sys_").append(impexModel.getFolder().getTenantId())

.append(separatorChar).append(impexModel.getLocation());

LOG.info("sb.toString()" + stringBuilder.toString());

return stringBuilder.toString();

}


private File writeFileFromMedia(final ImpExMediaModel impexModel,File sourceFile) throws IOException {

InputStream  mediaStream = mediaService.getStreamFromMedia(impexModel);

FileUtils.copyInputStreamToFile(mediaStream, sourceFile);

return sourceFile;

}


private File writeZipFileFromMedia(final ImpExMediaModel impexModel, File sourceFile) throws IOException {

SpringZipUtils.copy(mediaService.getStreamFromMedia(impexModel), sourceFile);

return sourceFile;

}


/**

* Use a custom export script generator to dynamically create an export script

*

* @param cron

* @return script payload

*/

protected String generateExportScript(final AdvancedTypeExportCronJobModel cron) {

return new AdvancedTypeExportScriptGenerator(modelService.getSource(cron.getExportConfiguration())).generateScript();

}


/**

* @param exportService

*           the exportService to set

*/

public void setExportService(final ExportService exportService) {

this.exportService = exportService;

}

}




/**
 * 
 */
package com.msasafety.ac.advancedexport;
import de.hybris.platform.catalog.jalo.CatalogManager;
import de.hybris.platform.catalog.jalo.CatalogVersion;
import de.hybris.platform.impex.constants.ImpExConstants;
import de.hybris.platform.impex.jalo.ImpExManager;
import de.hybris.platform.impex.jalo.exp.generator.ExportScriptGenerator;
import de.hybris.platform.impex.jalo.exp.generator.MigrationScriptModifier;
import de.hybris.platform.jalo.Item;
import de.hybris.platform.jalo.JaloSession;
import de.hybris.platform.jalo.SearchResult;
import de.hybris.platform.jalo.c2l.Language;
import de.hybris.platform.jalo.flexiblesearch.FlexibleSearch;
import de.hybris.platform.jalo.security.UserRight;
import de.hybris.platform.jalo.type.AttributeDescriptor;
import de.hybris.platform.jalo.type.ComposedType;
import de.hybris.platform.jalo.type.RelationDescriptor;
import de.hybris.platform.jalo.type.TypeManager;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.msasafety.ac.jalo.advancedexport.AdvancedTypeExportConfiguration;


/**
 * @author hydev
 *
 */
public class AdvancedTypeExportScriptGenerator   extends ExportScriptGenerator
{
private final Set<ComposedType> exportTypes;
private final Set<CatalogVersion> catalogVersions;
private final Set<AttributeDescriptor> blacklistedAttributes;
private final Set<ComposedType> blacklistedTypes;
private final boolean exportAttributesAsRelations;
private String creationDate;
private String modifiedDate;
private AdvancedTypeExportConfiguration exportConfig;

private static final Logger LOG = Logger.getLogger(AdvancedTypeExportScriptGenerator.class);

public AdvancedTypeExportScriptGenerator(final List<ComposedType> types, final Set<CatalogVersion> catalogVersions,
final Set<AttributeDescriptor> blacklistedAttributes, final Set<ComposedType> blacklistedTypes,
final Set<Language> languages, final boolean exportAttributesAsRelations,Date creationDate,Date modifiedDate)
{
LOG.info("cONSTRCUTURE ONE");
this.catalogVersions = catalogVersions;
this.blacklistedAttributes = mergeWithSubDescriptors(blacklistedAttributes);
this.blacklistedTypes = blacklistedTypes;
this.exportTypes = findAllSubTypes(types);
this.setLanguages(languages);
this.registerScriptModifier(new MigrationScriptModifier());
this.exportAttributesAsRelations = exportAttributesAsRelations;
if(modifiedDate!=null){
this.modifiedDate = new SimpleDateFormat("yyyy-MM-dd").format(modifiedDate);
}
if(creationDate !=null){
this.creationDate = new SimpleDateFormat("yyyy-MM-dd").format(creationDate);
}
}

public AdvancedTypeExportScriptGenerator(final AdvancedTypeExportConfiguration exportConfig)
{
this(exportConfig.getTypesToExport(), exportConfig.getCatalogVersionsToExport(), exportConfig.getBlacklistedAttributes(),
exportConfig.getBlacklistedTypes(), exportConfig.getLanguages(), true,exportConfig.getCreationDate(),exportConfig.getModifiedDate());
this.exportConfig = exportConfig;
}

protected Set<AttributeDescriptor> mergeWithSubDescriptors(final Set<AttributeDescriptor> blkAttrs)
{
final Set<AttributeDescriptor> allAttributeDescriptors = new HashSet<AttributeDescriptor>(blkAttrs);
for (final AttributeDescriptor ad : blkAttrs)
{
allAttributeDescriptors.addAll(ad.getAllSubAttributeDescriptors());
}
return allAttributeDescriptors;
}

/**
* @param types
* @return
*/
private Set<ComposedType> findAllSubTypes(final List<ComposedType> types)
{
final Set<ComposedType> allExportTypes = new LinkedHashSet<ComposedType>();
for (final ComposedType type : types)
{
allExportTypes.addAll(findSubTypes(type));
}
return allExportTypes;
}

@Override
protected Set<ComposedType> determineInitialTypes()
{
return exportTypes;
}

protected Set<ComposedType> findSubTypes(final ComposedType parent)
{

assert parent != null;

final Set<ComposedType> allSubTypes = new LinkedHashSet<ComposedType>();
if (!parent.isAbstract() && haveItemsForType(parent) && !blacklistedTypes.contains(parent))
{
allSubTypes.add(parent);
}

if (CollectionUtils.isNotEmpty(parent.getSubTypes()))
{
for (final ComposedType type : parent.getSubTypes())
{
// append all the sub types of we have any
allSubTypes.addAll(findSubTypes(type));
}
}

return allSubTypes;
}

/**
* @param type
* @return
*/
protected String generateQueryForTypeForDateSpecific(final ComposedType type)
{
// query that returns all items but no subtypes
String query = "SELECT {PK} FROM {" + type.getCode() + "!}";
if (isCatalogItem(type) && CollectionUtils.isNotEmpty(catalogVersions))
{
query += " WHERE {" + getCatalogVersionAttribute(type).getQualifier() + "} IN (";
for (final CatalogVersion catalogVersion : catalogVersions)
{
query += catalogVersion.getPK().toString() + ",";
}

query = StringUtils.removeEnd(query, ",");
query += ")";
if(StringUtils.isNotEmpty(creationDate) && StringUtils.isEmpty(modifiedDate)){
query += "  and {creationtime} >= '" + creationDate + "'";
}
if(modifiedDate != null && creationDate == null){
query += " and {modifiedtime} >= '" + modifiedDate + "'";
}
if(modifiedDate != null && creationDate != null){
query +=  " and {creationtime} >= '" + creationDate + "' or  {modifiedtime} >= '" + modifiedDate  +"'";
}
}
LOG.info(query);
return query;
}
protected String generateQueryForType(final ComposedType type)
{
// query that returns all items but no subtypes
String query = "SELECT {PK} FROM {" + type.getCode() + "!}";
if (isCatalogItem(type) && CollectionUtils.isNotEmpty(catalogVersions))
{
query += " WHERE {" + getCatalogVersionAttribute(type).getQualifier() + "} IN (";
for (final CatalogVersion catalogVersion : catalogVersions)
{
query += catalogVersion.getPK().toString() + ",";
}

query = StringUtils.removeEnd(query, ",");
query += ")";
}
LOG.info(query);
return query;
}
protected String generateQueryForTypeWithoutCatalogueVersion(final ComposedType type)
{
//SELECT {PK} FROM {ContentSlotName as C join PageTemplate as P on {C:template}={P:PK} } where {P:catalogVersion} IN (8796094726745)
if(StringUtils.equalsIgnoreCase(type.getCode(), "ContentSlotName") && CollectionUtils.isNotEmpty(catalogVersions)) {
// query that returns all items but no subtypes
String query = "SELECT {PK} FROM {" + type.getCode() + "! as C JOIN PageTemplate as P on {C:template}={P:PK} }";
if (CollectionUtils.isNotEmpty(catalogVersions))
{
query += " WHERE {P:catalogVersion} IN (";
for (final CatalogVersion catalogVersion : catalogVersions)
{
query += catalogVersion.getPK().toString() + ",";
}

query = StringUtils.removeEnd(query, ",");
query += ")";
}
if(creationDate != null && modifiedDate == null){
query += "  where {C:creationtime} >= '" + creationDate + "'";;
}
if(modifiedDate != null && creationDate == null){
query += " where {C:modifiedtime} >= '" + modifiedDate + "'"; 
}
if(modifiedDate != null && creationDate != null){
query +=  " where {C:creationtime} >= '" + creationDate + "' or  {C:modifiedtime} >= '" + modifiedDate  +"'";
}
LOG.info(query);
return query;

} else {
// query that returns all items but no subtypes
String query = "SELECT {PK} FROM {" + type.getCode() + "!}";
if(creationDate != null && modifiedDate == null){
query += "  where {creationtime} >= '" + creationDate + "'";;
}
if(modifiedDate != null && creationDate == null){
query += " where {modifiedtime} >= '" + modifiedDate + "'"; 
}
if(modifiedDate != null && creationDate != null){
query +=  " where {creationtime} >= '" + creationDate + "' or  {modifiedtime} >= '" + modifiedDate  +"'";
}
LOG.info(query);
return query;
}
}

@Override
protected void writeScript() throws IOException
{
writeComment(" -------------------------------------------------------");
writeComment("# used 'header validation mode' during script generation was: "
+ ImpExManager.getImportStrictMode().getCode());
final Locale thisLocale = JaloSession.getCurrentSession().getSessionContext().getLanguage().getLocale();
writeBeanShell("impex.setLocale( new Locale( \"" + thisLocale.getLanguage() + "\" , \"" + thisLocale.getCountry()
+ "\" ) )");
writeComment(" -------------------------------------------------------");

for (final ComposedType type : getTypes())
{
if (LOG.isDebugEnabled())
{
LOG.info("generating script statements for type " + type.getCode());
}

getScriptWriter().writeSrcLine("");
writeComment("---- Extension: " + type.getExtensionName() + " ---- Type: " + type.getCode() + " ----");

writeTargetFileStatement(type, ".csv");
writeHeader(type);
writeExportStatement(type, false);
}
}

/**
* Write the export statement, we use a flexible search so we don't export any sub types
* @param type
* @param inclSubtypes
* @throws IOException
*/
@Override
protected void writeExportStatement(final ComposedType type, final boolean includeSubTypes) throws IOException
{
// if we don't have a catalog item or we have one but no catalog versions to filter
// then we use the normal exportItems method of Exporter
if (!isCatalogItem(type) || CollectionUtils.isEmpty(catalogVersions))
{
writeBeanShell("impex.exportItemsFlexibleSearch( \"" + generateQueryForTypeWithoutCatalogueVersion(type) + "\")");
}
else
// we have catalog versions then we use the flexible search method
{
writeBeanShell("impex.exportItemsFlexibleSearch( \"" + generateQueryForTypeForDateSpecific(type) + "\")");
}

}

/**
* Enhances the standard blacklisting functionality by adding a more generic blacklist of common attributes e.g.
* creationTime
*/
protected boolean isIgnoreColumn(final ComposedType type, final AttributeDescriptor ad)
{

final boolean ignore = CollectionUtils.isNotEmpty(blacklistedAttributes) && blacklistedAttributes.contains(ad)
|| super.isIgnoreColumn(type, ad.getQualifier());
if (ignore)
{
//LOG.info("Ignoring qualifier [" + ad.getQualifier() + "] of composed type [" + type.getCode() + "]");
}
return ignore;
}

protected boolean overrideRelationAsAttribute(@SuppressWarnings("unused") final AttributeDescriptor ad)
{
return exportAttributesAsRelations;
}

/**
* Override to allow relations to be set inside the type, we need this to be able to handle deletes
*/
@Override
protected void writeHeader(final ComposedType type) throws IOException
{
// special case USER RIGHT
if (TypeManager.getInstance().getComposedType(UserRight.class).isAssignableFrom(type))
{
getScriptWriter()
.writeComment(
"SPECIAL CASE: Type UserRight will be exported with special logic (without header definition), see https://wiki.hybris.com/x/PIFvAg");
}
else
{
//adding additional attributes for solr data types
addAdditionalModifierForSolr(type);


// gather columns string
final Collection<AttributeDescriptor> attribs = type.getAttributeDescriptorsIncludingPrivate();
boolean hasUnique = false;
final Set<String> columns = new TreeSet<String>();
for (final AttributeDescriptor ad : attribs)
{
if (!isIgnoreColumn(type, ad)
&& !(ad instanceof RelationDescriptor && !(ad.isProperty()))
&& !ad.getQualifier().equals(Item.PK)
&& (ad.isInitial() || ad.isWritable())
&& (!ad.getQualifier().equals("itemtype") || TypeManager.getInstance().getType("EnumerationValue")
.isAssignableFrom(type))
// export relations as attributes
|| ((!isIgnoreColumn(type, ad) && ad instanceof RelationDescriptor && overrideRelationAsAttribute(ad))))
{
if (!ad.isOptional())
{
addAdditionalModifier(type.getCode(), ad.getQualifier(), ImpExConstants.Syntax.Modifier.ALLOWNULL, "true");
}
if (ad.isUnique()
|| getAdditionalModifiers(type, ad.getQualifier()).get(ImpExConstants.Syntax.Modifier.UNIQUE) != null)
{
hasUnique = true;
}
if (!ad.isWritable())
{
addAdditionalModifier(type.getCode(), ad.getQualifier(), ImpExConstants.Syntax.Modifier.FORCE_WRITE, "true");
}
if (ad.isLocalized())
{
for (final Language lang : this.getLanguages())
{
columns.add(generateColumn(ad, lang.getIsoCode()));
}
}
else
{
columns.add(generateColumn(ad, null));
}
}
}
columns.addAll(getAdditionalColumns(type));
final Map line = new HashMap();
int index = 0;
final String firstColumn = generateFirstHeaderColumn(type, hasUnique);
line.put(Integer.valueOf(index), firstColumn);
index++;

if (isUseDocumentID())
{
line.put(Integer.valueOf(index), ImpExConstants.Syntax.DOCUMENT_ID_PREFIX + "Item");
}
else
{
line.put(Integer.valueOf(index), Item.PK
+ (hasUnique ? "" : ImpExConstants.Syntax.MODIFIER_START + ImpExConstants.Syntax.Modifier.UNIQUE
+ ImpExConstants.Syntax.MODIFIER_EQUAL + Boolean.TRUE + ImpExConstants.Syntax.MODIFIER_END));
}
index++;

for (final Iterator<String> iter = columns.iterator(); iter.hasNext(); index++)
{
final String column = iter.next();
if (column.length() != 0)
{
line.put(Integer.valueOf(index), column);
}
}
getScriptWriter().write(line);
}
}

/*
* (non-Javadoc)
* @see de.hybris.platform.impex.jalo.exp.generator.AbstractScriptGenerator#generateScript()
*/
@Override
public String generateScript()
{
final String result = super.generateScript();
if (exportConfig != null)
{
exportConfig.setLastExport(new Date());
}
return result;
}

/**
* Check if we have any items for this type by doing a count on a flexible search
* @param type
* @return
*/
protected boolean haveItemsForType(final ComposedType type)
{
final String query = generateQueryForType(type);
final SearchResult result = FlexibleSearch.getInstance().search(query, type.getJaloClass());
return result.getCount() > 0;
}

protected boolean isCatalogItem(final ComposedType type)
{
return CatalogManager.getInstance().isCatalogItem(type);
}

protected AttributeDescriptor getCatalogVersionAttribute(final ComposedType type)
{
return CatalogManager.getInstance().getCatalogVersionAttribute(type);
}

protected void addAdditionalModifierForSolr(final ComposedType type)
{
if (type != null)
{
if (type.getCode().equalsIgnoreCase("SolrIndexedProperty"))
{
addAdditionalModifier(type.getCode(), "solrIndexedType", ImpExConstants.Syntax.Modifier.UNIQUE, "true");
addAdditionalModifier(type.getCode(), "name", ImpExConstants.Syntax.Modifier.UNIQUE, "true");
}
if (type.getCode().equalsIgnoreCase("SolrSynonymConfig"))
{
addAdditionalModifier(type.getCode(), "facetSearchConfig", ImpExConstants.Syntax.Modifier.UNIQUE, "true");
addAdditionalModifier(type.getCode(), "language", ImpExConstants.Syntax.Modifier.UNIQUE, "true");
addAdditionalModifier(type.getCode(), "synonymFrom", ImpExConstants.Syntax.Modifier.UNIQUE, "true");
}
if (type.getCode().equalsIgnoreCase("SolrStopWord"))
{
addAdditionalModifier(type.getCode(), "facetSearchConfig", ImpExConstants.Syntax.Modifier.UNIQUE, "true");
addAdditionalModifier(type.getCode(), "language", ImpExConstants.Syntax.Modifier.UNIQUE, "true");
}
if (type.getCode().equalsIgnoreCase("SolrCategoryRedirect"))
{
addAdditionalModifier(type.getCode(), "redirectItem", ImpExConstants.Syntax.Modifier.UNIQUE, "true");
}
if (type.getCode().equalsIgnoreCase("SolrFacetSearchKeywordRedirect"))
{
addAdditionalModifier(type.getCode(), "facetSearchConfig", ImpExConstants.Syntax.Modifier.UNIQUE, "true");
addAdditionalModifier(type.getCode(), "language", ImpExConstants.Syntax.Modifier.UNIQUE, "true");
addAdditionalModifier(type.getCode(), "keyword", ImpExConstants.Syntax.Modifier.UNIQUE, "true");
addAdditionalModifier(type.getCode(), "matchType", ImpExConstants.Syntax.Modifier.UNIQUE, "true");
}
if (type.getCode().equalsIgnoreCase("SolrURIRedirect"))
{
addAdditionalModifier(type.getCode(), "url", ImpExConstants.Syntax.Modifier.UNIQUE, "true");
}

}

}
}



<bean id="advancedTypeExportJob" class="com.msasafety.ac.advancedexport.AdvancedTypeExportJob" scope="tenant" parent="abstractJobPerformable">
<property name="exportService" ref="exportService"/>
</bean>




#if target catalog already has data (i.e. this is a re-load and not the initial load) then ContentSlotName needs to move to blacklisttypes from exporttypes;


$exporttypes=BannerComponent,CMSImageComponent,CMSLinkComponent,CMSParagraphComponent,JspIncludeComponent,MiniFacetComponent,MSABadgedCardComponent,MSADetailedCardComponent,MSADoubleDetailedCardComponent,MSAExtendedDoubleDetailedCardComponent,MSAMarketCardComponent,MSAParagraphComponent,MSASearchComponent,MSASocialMediaDetailCardComponent,MSAStockComponent,MSAWhatsNewCardComponent,MSAWhatsNewCarouselComponent,PageTemplate,RotatingImagesComponent,SimpleBannerComponent,MSAExploreProductsSearchComponent,ProductCarouselComponent,SimpleMSABannerComponent,MSA2CategoryBannerComponent,MSAButtonBannerComponent,MSACMSLinkComponent,MSAGenericBannerComponent,MSAApplicationNavLinksListComponent,MSANewsReleasesComponent,MSASocialMediaCardComponent,MiniCartComponent,MSAApplicationIndividualTabComponent,MSA2TabsListComponent,MSAApplicationAccordionSectionComponent,MSAApplicationAccordionListComponent,MSAApplicationBannerComponent,CMSNavigationNode,CMSNavigationEntry,FooterComponent,MSACarouselInnerComponent,MSACarouselComponent,NavigationBarComponent,EmailPageTemplate,CategoryPage,EmailPage,ContentPage,MSAContentPage,ProductPage,ContentSlotName,AccordionParagraphContainer,AccordionParagraphComponent,RecentlyViewedProductCMSComponent,UserViewedHistoryProductCMSComponent,ContentSlot,ContentSlotForTemplate,ContentSlotForPage,MSAApplicationCardComponent,MSAHomePageBannerComponent,MSAFooterComponent,MSAMegaNavigationComponent

$blacklisttypes=CatalogVersionSyncScheduleMedia,HeaderLibrary,LogFile,ImpExMedia,ImpExExportMedia,CockpitUIConfigurationMedia



#===========

# NNA22

#===========


$jobname=NNA22-export-CMS-Catalog

$catalogname=nna22ContentCatalog:Staged

$cataloglanguages=en,es,fr

# AdvancedTypeExportConfiguration for NNA22 export

INSERT_UPDATE AdvancedTypeExportConfiguration ; code[unique=true] ; catalogVersionsToExport(catalog(id),version) ; languages(isocode) ; typesToExport(code) ; blacklistedTypes(code)

; $jobname ; $catalogname ; $cataloglanguages ; $exporttypes ; $blacklisttypes

# Blacklisted attributes

INSERT_UPDATE AdvancedTypeExportConfiguration ; code[unique=true] ; blacklistedAttributes(enclosingType(code),qualifier) ;

; $jobname ; Item:creationtime,Item:modifiedtime,Item:assignedCockpitItemTemplates,Item:comments,Item:owner,Item:allDocuments,Item:savedValues,Media:URL2,Media:folder,PageTemplate:availableContentSlots,FooterComponent:navigationNodes,AbstractPage:navigationNodeList

INSERT_UPDATE ServicelayerJob ; code[unique=true] ; springId[unique=true]

; $jobname ; advancedTypeExportJob

INSERT_UPDATE AdvancedTypeExportCronJob ; code[unique=true] ; job(code) ; exportConfiguration(code) ; sessionUser(uid) ; sessionLanguage(isocode)[default=en] ; active[default=true] ;

; $jobname ; $jobname ; $jobname ; admin ; en ; true ;





Comments

Popular Posts