0
votes

I want to create an impex from java in hybris, because my requirement is to add the featureproperty dynamically , instead of doing it from HMC.

I have never done impex from code and I have seen no example on the internet for reference, If impex cannot be done from java then what is the best bet for me to make it dynamic. I am new to hybris. Any reference or hint will do for me. Please help, Thank you

2

2 Answers

2
votes

Impex is used for importing and exporting data. You have multiple options to import data using Impex files.

  • Manual import during Initialization/Update process

The Initialization/Update process is used to create all data, that is needed for starting the platform. During this process hybris creates tables/columns in the database, the type system and it also imports data. This data is classified as "Essential Data" that is essential for the system to start (like currencies, languages, users), and project data, which is necessary for a specific extension to run. When you want to use the accelerator, all the data, that is needed is created in the myacceleratorinitialdata extension. With this extension you can create a basic web shop (like web sites, stores, catalogs) and even sample data (like sample products/prices/stock, sample cms pages/components, sample media items).

  • Using hot folder

The hot folder is often used for automatic/periodic import of data. On the servers hard drive there is a folder which is monitored for changes. When a CSV file is put to this folder, the data in this folder is imported into the database. However you have to configure how it is imported. It is often used to import updates for product, price or stock data.

  • Manual import by uploading file in the hybris admin console

In the hybris admin console there is a page where you can import a snippet of impex content. It is often used to do mainenance work (like manually disabling a number of products). The default URL pointing to that service is: https://localhost:9002/console/impex/import

  • Impex API

If you REALLY need to import Impex data via Java code, there is an API: https://help.hybris.com/6.5.0/hcd/8bee24e986691014b97bcd2c7e6ff732.html

In my many years of writing hybris applications, I never had to use this API. Often it is more suitable to use one of the above mentioned mechanisms OR the ModelService (see below).


Keep in mind, that every data item you want to create, can be created using the ModelService. It's very simple to write data to the database using the ModelService. Here is an simplified example for how to create a new product using the ModelService:

ProductModel product = modelService.create(ProductModel.class);
product.setCode("123");
product.setDescription("A product imported using ModelService");
product.setCatalogVersion(catalogVersion);
modelService.save(product);

For every data type, there is a Java class with the suffix "Model" (e.g. ProductModel, StockLevelModel, PriceRowModel, MediaModel). These model classes have getter and setter methods for every attribute of that data type (e.g. product.setCode(...)). Even relations to other data types can be retrieved/saved using getter/setter methods (e.g. product.setCatalogVersion(...)).

0
votes

We can create impex using Java springs. You can check hot folder implementation where impex is generated through the OOTB java classes.

you can check in yaccelerator core integration spring files for better understanding.