Can I implement impex from java in hybris - java

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

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(...)).

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.

Related

Best way to get values from a external file in java

I have a java code which I'm currently running as a jar. This code checks for a specific file in the given directory which is currently hard coded in the code.
To give more flexibility and not to touch the code. I would like to have the folers list managed by a different file and the code reads this config file and gets the list of folders each time and execute it.
I would like to know which is the best possible option of maintaining the folder list outside the code so that anyone can update it. Can a properties be used for this ? can we dynamically take values from a property file
In Java you have the java.util.Properties that allow you to load flat key/value data from external resources.
If you need something that can be dynamically updated, there's also the more sophisticated Preferences library. This one allows you to:
Keep data organized in tree structures (it's a tree of nodes, each node storing its own key/value preferences).
Make use of basic types (primitive types, strings and binary data).
Make use of platform-dependent "native" stores transparently (under the hood, it's going to use the file system on Unix systems and registries on Windows by default).
Plug in your own backing store if needed.
Get any data changes performed within the application persisted transparently.
Register node/preference change listeners and react to any change if needed.
The API is quite old and hasn't been updated, but it doesn't mean it's deprecated. It is used mostly with GUI applications (notably, IntelliJ IDEA was storing its configuration using Preferences the last time I checked).
There's also an attempt to revive this library that I made with a project called cross-preferences by integrating modern distributed config stores (such as zookeeper, etcd or consul) as backing stores for java.util.prefs.Preferences and providing a web console for preference management.

how to save data localy without using database

suppose that I have an Employee Class and there is another Class Company that has more than one Employee so I want to save the Employee objects locally, that means every time I run my application I can retrieve these objects.
I would suggest using some kind of embedded solution. There are a number of options available such as H2 or Neo4j.
For a comprehensive list check out Wikipedia.
Although these solutions are technically databases the don't run on their own server, they run inside your current Java process.
To get started with H2 the following steps are required:
Add the h2*.jar to the classpath (H2 does not have any dependencies)
Use the JDBC driver class: org.h2.Driver
The database URL jdbc:h2:~/test opens the database test in your user home directory
A new database is automatically created
After that, you can simply use JDBC against the new database everything is stored on disk.
I would not recommend using Java-serialization of Java objects to a file (Serializable). This is not a maintanable solution and whenever your code changes (for the classes that were serialized) you have to work out some plan on how to migrate your data.
Another solution is to dump your object graph as JSON in a file. There are multiple libraries that can help you with serialization and deserialization from Java to JSON and vice versa. One example is the excellent Jackson library that easily and without fuzz converts objects to and from JSON.
you can use Microsoft Excel to save the attributes of this object and retrieve them later, there is an api for excel http://poi.apache.org/download.html

Import and export data as files using Spring/Hibernate

I need to be able to export and import data from one instance of my application (spring / hibernate) to another.
My data are stored in multiple tables (with foreign key contraints), and can contain LOBs. I am also required to export the data in files (no specific format).
The Data pump API looks promising but I need to do something "easy to use" (basically a "export those data" button and nothing else), so I can't use external tools such as the one integrated in sql developer
Does spring provide a way to to use this API (or a similar one), or is there another framework that I could use?
Have a look at the Spring Data and Batch projects. They might help.
I don't know what "from one instance to another" means. Are these separate versions?
if export/import is between database then writing procedures sounds good to me.If it can be for any format(file/webservice) to any then go for mule(http://www.mulesoft.org/what-mule-esb) ,Spring batch.

User Profiles using properties in Java

I am making a math game in Java and I want to create the ability for the user to create a local account (or log in to an existing one), which would have a unique properties file. How would I do this?
You have a couple of options to look into. Java comes with the necessary libraries with which you can create, open, read and write to files. Using the File class, you could create an account file, for instance "User1.properties", and save the information in an easy to parse format. If you're looking to go one further, you can look into using XML or JSON, which are commonly used formats for saving information in this way. Here's some helpful links to get you started.
Using files in Java
Using XML in Java
Using JSON in Java
Another option you have available is to use a database in a similar fashion to websites. The type of database you use is up to you, although MySQL is an example of one commonly used database. Once again, here is a link to help you get started with MySQL in Java.
Regardless of what you use, you will need to take the username and password provided (or whatever combination of login credentials you would like your system to use), and compare them with those stored in your file or database.

simple cms - only to create/edit content and export it via jdbc or java api

(i even don't know if i need a cms)
what i need is: a simple web based way for a functional department to create/edit multilingual text documents (probably tagged with customizable semantic tags).
The containing Texts are used in an RIA showing statistical data and infos about it. This infos and other user visible Stings should be fully managed by functional department.
the destination of the this texts/documents is an embedded apache derby db - delivered together with RIA release (as zip-File,- the texts are static).
So on the other hand the cms (if this is an cms) should provide an interface to export the data - either a simple db-structure to get data via jdbc or a java api.
so what cmc/?? do you suggest for this usecase
thx in advance
Maybe you could use a java web framework like Tapestry to create a simple web application.
It has some premade components too easily modify and save data to a database.

Categories