Thursday, 12 May 2016

Create/Publish new store(website) using hybris accelerator extension template

In Hybris yaccelerator is a default out-of-box store but we want to create our own  by using Hybris multi-channel suite.Follow the below steps for the same.

Step 1: Go to cmd and hybris bin plateform directory and run >ant modulegen











Step 2: Choose extension template as "accelerator" , name as "training" and package name as "com.training"














After performing all above step , Below seven extension gets

(1)  trainingcockpits
(2)  trainingcore
(3)  trainingfacades
(4)  trainingfulfilmentprocess
(5)  traininginitialdata
(6)  trainingstorefront
(7)  trainingtest








































Step 3: Now add all the 7 newly created extensions in localextensions.xml

Step 4: Run ant clean all

Step 5: Start hybris server using hybrisserver.bat

Step 6: Initialize extension from Hybris admin console


In case any CMSSite related issues is faced. Please initialise apparel/electronics(which ever you going to use) first from admin console.

Wednesday, 11 May 2016

Initialization and Update of the hybris Commerce Suite

There are two representations of the Type System of the hybris Commerce Suite.
  •    There is a file-based representation that is spread across in the various items.xml files of the hybris Commerce Suite extensions. This representation is not actively used by the hybris Commerce Suite at runtime. You can modify this representation at any time by modifying the items.xml file of an extension. However, modifications of the items.xml files only take effect after an initialization or an update of the hybris Commerce Suite.
  •    The database of the hybris Commerce Suite also contains a representation of the type system. This representation is actually in use by the hybris Commerce Suite at runtime. The representation in use reflects the state the type system was in when the hybris Commerce Suite was last updated or initialized






Locking the hybris Suite

Hybris Administration Console also allows you to lock the system against initialization or update. While this lock is in effect, the hybris Commerce Suite can neither be updated nor initialized. This lock therefore prevents loss of data. Lock can be activated and deactivated both from theInitialization and the Update page of the hybris Administration Console

Initialization

Initialization drops existing type definitions from the database prior to rebuilding, so the entire type system is created from scratch. So during an initialization, type system definitions are created to match the type system definition in the items.xml files

Initializing the hybris Commerce Suite

Access the Initialization Page

 1.)Open the hybris Administration Console.
2.) Go to the Platform tab and select Initialization option. The Initialization page now displays.



Click the Initialize button. This:

1.) Aborts all running cron jobs
2.) Removes all tables from the database schema. The DROP TABLE statement is used. This removes not only hybris Commerce Suite data, but all data stored in the database schema. Since hybris Commerce Suite version 5.1, during the initialization process the system no longer removes all tables. Now it only removes those tables that are declared in its current items.xml files. Old tables - orphaned data - stay intact

The init process prior to hybris Commerce Suite version 5.1 creates the type system by iterating through all extension managers and calling their methods in this order:

initializeRemoveObjects
initializeCreateTypes
initializeModifyTypes
initializeCreateObjects

3.) The init process in hybris Commerce Suite 5.1 or later prepares the ddl and dml scripts and executes them (unless dryrun is enabled, in which case the scripts are not executed). This way - the schema is prepared and persisted into db. Ddl scripts also remove tables.

4.) Clears cache and Creates a number of media folders

5.) Sets licenses

At this point the type system has been initialized. The Initialization continues with creating essential data and project data (This is optional, but enabled for all extensions by defautl). Furthermore, during the init process the hmc configuration is cleared and types are localized.

You can also initialize the system from the command line by running the command ant initialize.

Update

During an update, type system definitions are modified to match the new type system definition in the items.xml files.  
First and foremost, the update mechanism makes sure that all data that existed in the system before the update is still accessible after the update.
Therefore:
1.)Update preserves the table name, to which a type was mapped, even if it was changed in items.xml
2.)Update preserves the column name, to which an attribute was mapped, even if it was changed in items.xml
3.)Update preserves the column type for an attribute, even if it was changed in items.xml
4.)Update does not drop any tables and columns
5.)Update does not delete any item data, including type instances and type system data (composed types etc.)
6.)Update drops and recreate indices, if they are added or changed in items.xml
7.)Update does NOT change the attribute from optional to mandatory, even if it was changed in items.xml

This is what the process looks like:
  • The type system definitions from all extensions items.xml files are read in.
  • The hybris Commerce Suite type system in the database is modified according to the type definitions of all extensions items.xml files.


  1. Adding newly defined types to the type system definition in the database.Type definitions and attribute definitions that are not part of the type system definition in the database are added.
  2. Modifying existing types to match the type system definition in the database.Type definitions and attribute definitions that are changed compared to the type system definition in the database are modified.
  3. Again, like in the init process, the old update logic (prior to hybris Commerce Suite 5.1) iterates through extensions and uses extension manager methods to create and modify types. Whereas, in the new update (since hybris Commerce Suite 5.1), ddl and dml scripts are also generated here.
  4. Update then continues with creating essential and project data, optionally, if selected.





Create Cron Job and Run Manually from HMC

CronJob:


Cron job is basically a piece of business logic which you may set torun just once, once an hour, every 35 minutes and 17 seconds, every day, every week and so on. Typically cron jobs can be used for creating data for backups, updating catalog contents, or recalculating prices. The key idea of applying cron jobs is to start a long or periodic process in a background, having the possibility to protocol each run and to easily check its result.

The concept consists of three types that interact with one another:CronJob, Job, and Trigger, as well as the JobPerformable class which is tightly related to the Job type.

· 1.)Job type describes the logic to be executed, defined by an associated JobPerformable

· 2.)CronJob type holds the configuration for a single run of a Job, as well as the protocol information, like logs

· 3.)Trigger type is used for scheduling when to run a Job.
Summarizing, a Job defines what should be done, a Trigger says when, and a CronJob specifies the setup used by Job


The division into CronJob, Job/JobPerformable, and Trigger types allows to reuse the code. For example, you may create a database backup as a Job several times using Trigger at different locations as CronJob without coding the actual backup logic twice.














Steps to create Cronjob
Step 1: Create an extension using ant extgen and mentioned the below details
  • extension.name=cronjobtutorial
  • extension.package=de.hybris.cronjobtutorial

Add the entry of this extension in localextensions.xml

run ant clean all

Step 2:Declare a custom CronJob type called HelloWorldCronJob. Add the below entry in cronjobtutorial-items.xml file located in resources folder in your new extension

            xsi:noNamespaceSchemaLocation="items.xsd">
    <itemtypes>
        <itemtype generate="true"
           code="HelloWorldCronJob"
           jaloclass="de.hybris.cronjobtutorial.jalo.HelloWorldCronJob"
           extends="CronJob"
           autocreate="true">     
        </itemtype>
    </itemtypes>
</items>

Step 3: Create a class which defines your logic. The class extending AbstractJobPerformable 
and override the perform method

public class MyJobPerformable extends AbstractJobPerformable<CronJobModel>
{
private static final Logger LOG = Logger.getLogger(MyJobPerformable.class.getName());

@Override
public PerformResult perform(final CronJobModel cronJobModel)
{
LOG.info("**********************************");
LOG.info("Greeting from MyJobPerformable!!!");
LOG.info("Yehhh maja aa gaya!!!");
LOG.info("**********************************");

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

}

}
Step 4: Define MyJobPerformable  as a Spring bean in the cronjobtutorial-spring.xml file located in the resources folder of the cronjobtutorial extension 


<bean id="myJobPerformable" class="de.hybris.cronjobtutorial.MyJobPerformable"

parent="abstractJobPerformable"/>


Step 5: Run the command ant clean all
Step 6: Start Hybris server using hybrisserver.bat

Step 7: Open Hybris admin console. Go to platorm>update. Select Cronjobtutorial check box 
and click update

Step 8: Go in the hybris Admin Console to the Console tab select ImpEx Import and execute the following impex-script there by clicking on the Import Content button. Using this query we are defining the kind of key value pair. Which means a cronjob with code HelloWorldCronJob" is mapped with "myJobPerformable" having all business logic written


INSERT_UPDATE CronJob; code[unique=true];job(code);singleExecutable;sessionLanguage(isocode)
;HelloWorldCronJob;myJobPerformable;false;de


Step 9: Open HMC using (http://localhost:9001/hmc/hybris). 
Navigate to System > Cronjobs and start the cronjob. 
Refer snap shot below.




















Step 10: Once cronjob finished message is displayed on HMC. 
Check you hybris console and you can see the results.