Wednesday 28 November 2018

Hotfolder in hybris



*  We knew how you can use ImpEx files to import data in the system. 
*  Hybris supports Hot Folders, which are folders from which data can be automatically imported into the platform by simply placing the data inside of the folder.

*  The acceleratorservices extension template comes with this functionality that enables automated importing of data into Hybris Commerce from hot folders.

*  Internally CSV files translated into Hybris ImpEx to import content directly into the product catalogs.

Here is the practical example of Hotfolder


Step 1:- Create an XML file in hybrisinstructivecore extension.

Step 2:-Configure the XML file in hybrisinstructivecore-spring.xml file

Step 3:- After that ant clean all and server start

Step 4:- Prepare CSV file and place parallel to the processing folder.


Note:- CSV file must use ‘-’ followed by integer like this ‘hybris_product-01.csv’.



Step 1:-  Create XML file in trainingcore extension.


/hybrisinstructivecore/resources/hybrisinstructivecore/integration/hot-folder-store-hybrisinstructive-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:file="http://www.springframework.org/schema/integration/file"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/file
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

<context:annotation-config />

<bean id="baseDirectoryTraining" class="java.lang.String">
<constructor-arg
value="#{baseDirectory}/${tenantId}/HybrisInstructive" />
</bean>
<!-- 1) Scan for files -->
<file:inbound-channel-adapter
id="batchFilesTraining" directory="#{baseDirectoryTraining}"
filename-regex="^(.*)-(\d+)\.csv" comparator="fileOrderComparator">
<int:poller fixed-rate="1000" />
</file:inbound-channel-adapter>

<!-- 2) move the file to processing and setup header -->
<file:outbound-gateway
request-channel="batchFilesTraining" reply-channel="batchFilesTrainingProc"
directory="#{baseDirectoryTraining}/processing" delete-source-files="true" />
<int:service-activator
input-channel="batchFilesTrainingProc"
output-channel="batchFilesHeaderInit" ref="trainingHeaderSetupTask"
method="execute" />
<bean id="trainingHeaderSetupTask"
class="de.hybris.platform.acceleratorservices.dataimport.batch.task.HeaderSetupTask">
<property name="catalog" value="electronicsProductCatalog" />
<property name="net" value="false" />
<property name="storeBaseDirectory" ref="baseDirectoryTraining" />
</bean>

<bean id="trainingProductConverterMapping"
      class="de.hybris.platform.acceleratorservices.dataimport.batch.converter.mapping.impl.DefaultConverterMapping"
      p:mapping="hybris_product"
      p:converter-ref="trainingProductConverter"/>
       
      <bean id="productImpexHeader" class="java.lang.String">
<constructor-arg>
<value># ImpEx for importing data into $CATALOG$
$version=Staged
$productCatalog=electronicsProductCatalog
$catalogVersion=catalogVersion(catalog(id[default=$productCatalog]),version[default=$version])[unique=true,default=$productCatalog:$version]
$lang=en
$approved=approvalstatus(code)[default='approved']
</value>
</constructor-arg>
</bean>
       
<bean id="trainingProductConverter" class="de.hybris.platform.acceleratorservices.dataimport.batch.converter.impl.DefaultImpexConverter">
    <property name="header">
        <value>#{productImpexHeader}
            INSERT_UPDATE Product;code[unique=true];name[lang=$lang];ean;manufacturerName;manufacturerAID;$approved;$catalogVersion
        </value>
    </property>
    <property name="impexRow">
        <value>;{+0};{1};{2};{3};{4}</value>
    </property>
    <property name="type" value="Product"/>
</bean>
</beans>





Step 2:-
        Configure the XML file in hybrisinstructivecore-spring.xml file

/hybrisinstructivecore/resources/hybrisinstructivecore-spring.xml


<import resource="classpath:/hybrisinstructivecore/integration/hot-folder-store-hybrisinstructive-spring.xml"/>



Step 3:-  After that ant clean all and server start


Step 4:-  Folder will be created at this location with name HybrisInstructive.


D:\Hybris_Training\hybris\data\acceleratorservices\import\master\





Step 5:-
              Prepare a CSV file and place parallel to the processing folder.
 D:\Hybris_Training\hybris\data\acceleratorservices\import\master\HybrisInstructive

CSV name should be same as given in XML file.













Step 6:- Check the console to check import is successful or not.




Step 7:- 

             If the import is successful CSV file will be shifted to archive folder else it will shift to errors folder.





Step 8:- Login to Backoffice and check the product.




1 comment:

  1. Hello there,

    The CSV that throws the error does not come to the "error" folder. What can I do for it ?

    Archive folder is running The "error" folder is not working.

    Can you help me?

    Thank you very much in advance.

    ReplyDelete