Monday 27 July 2020

An Introduction to Hybris from basics

An Introduction to Hybris from basics:

 -- ecommerce site and PCM(Product content Management) solutions. eg. croma website.

 -- having search , login , navigation , cart , order , registration , detail , listing functionality  etc by default..

 -- database independent(if you move database from oracle to mysql , no need to worry about the database migration.*-items.xml file has all the tables ready and impex file has the import  and export datas to different databases(oracle , mysql hana etc...).).

 -- screenshots -- 


  1)hybris database independent

 

 2)java hql dependency


  

----------------------------------------------------------------


  

  -- need to write code by implementing extensions (diff modules).

    screenshots (why hybris 1) -- 


  1)why hybris 1 -- cost effective -- 

                      1) have different kinds of recipes like b2c , b2b , or both etc ,-- you need to install recipes.

2) structured way of writing the program  -- screenshot for folder structure (folder structure) . 


BL-business logic, OMS - ordermanagement 

3)Other ecommerce platform to communicate SAP -- need lots of code, for hybris -- has b2b takes care of it.

  

  2) Gartner study  -- says hybris is no.1 digital e-commerce platform.

  

  what is Fiori (UI5) -- Just front end -- can be connected with SAP backend

   SAP can't be rendered in mobiles -- has 3L screens.

   to make mobile friendly we have fiori.

   

  3)Hybris support responsive web design

  

  SAP -- 22 years

   

   -- SAP is having e-commerece for  6 last years. SAP bought hybris.

   screenshots(sap other e-commerce solutions)



   

----------------------------------------------------------------


Other SAP E-commerce solutions

  - online store

  - ISA 

  - WCEM

  - Hybris

  

diffrenece between ISA and hybris?

1)Look and Feel (LFA).

hybris is better

UI,

UX (User Experience on Website (how tasks are simplified))-now ,

CX (Customer Experience on product or brand) - future

2) ISA is not having advanced features like search , navigation etc.

3) ISA is not mobile friendly.

4) ISA supports only Synchronous integration.

Hybris supports both.

screen shot(hybris e-commerce site with sap integration) for after placing orders ,do shipping and all.


  -- HF - hot folder , DH -data hub , JMS MQ -message queue

  -- If sap is down for 10 mins , orders placed from hybris will be in queue and will be continued when sap server is online again (asynchronous integration).

   

-- because of these sap decided their future ecommerce solution is hybris.


-- ISA will not be supported after 2020 , so customers will be moved.


Hybris is called PCM(Product Content Management system) for 2 things,


1)Content -- whatever you see in the landing page of a e-commerce site called content.

  -- screenshot(content-managers-cmscockpit)


  -- content managers uses cmscockpit (https://localhost:9002/cmscockpit)

  -- deleted a best seller product for apparel uk website ( by going into apparel uk online in left bar) 

  

2)Product

----------------------------------------------------------------


2)Product 

   -- screenshot (product-managers-productcockpit)


   -- product managers uses productcockpit

   

 we can manage content and product , so hybris is called PCM software.

 

 http://localhost:9002/productcockpit

 

 screenshot (product-cockpit-edit-product-info)


 

 certfication based question -- 

     -- Q) how to find a site is developed using hybris or not?

    ans:

sol1)

if you click on any category or sub category on navigation menu , the url of the redirected category page, will contain the /c/  before <category-id/category-name>. it is the default behaviour of hybris, but some companies override it for SEO purpose.

screenshot (certiicationq1)


sol2)if you click on any product on category page , the url of the redirected product detail page, will contain the /p/  before <product-id/product-name>. 

sol3)If some companies override the url , then how can we find it?

  go to inspect element , and click on sources and find "open file" , click and type acc, you will see , most js files starts with acc (eg.acc.cart.js).

  screenshot(to-find-hybris-website)


  

  

note: they can do code optimisation and changes 20 files content into single file with different name (not starts with acc) , we can't find the website is hybris or not.

-- for code minification or optimisation , hybris provides inbuilt tool called grunt (you can use third party tools also).

  

  

Homepage -- 

 Every page has its own controller (spring mvc controller) page in java.

 what are default pages in hybris?

 

   --for homepage , it has homepagecontroller.java

   --category page -- CategoryController.java

   --searchresults page -- SearchPageController.java

   --product page -- ProductPageController.java

   --cart page -- CartPageController.java

   --checkout page -- CheckoutStepController.java

  

----------------------------------------------------------------



Ecommerce - Buying / selling of products / services from business / customer through internet.


Flavors / types of ecommerce

  -- B2B - companies doing business with each other.

     -- IBM - lenovo ( www.mcmaster.com)

  -- B2C - Business selling to public directly without human interaction.

-- flipkart , amazon

  -- C2B - Consumer posts his work details online. companies bid for his work.consumer reviews and select the company.

     -- elance.com , upwork.com

  -- C2C - Customer places ads online . another individual can come and buy.

     -- olx.com


Hybris majorly focus on B2B and B2C.

 

-- Recipe means Ecommerce flavor == acc == module.

-- Go to recipe folder in hybris install folder and Install B2B acc , if you want to work on B2B sites or B2C acc for B2C sites.

   screenshot(recipe-install-b2b-b2c)


   

Recipe contains what?

   1) buile.gradle -- list of extensions

     -- if you want to write the code , you need to create extensions  or open existing extension and write the code.

-- if you want to use both B2B and B2C , you need to install b2c_b2b_acc recipe.

  -- OOTB - out of the box -- already available functionality.

  

  

   

   2) readme - what recipe will do.

   

B2C vs B2B-

  1) registration avalible in B2C but not available in B2B.

    - how regisrtation can happen in B2B ?

  sol1:

    some companies allow self registration.

  sol2: regisrtation by invite (mail link for registration).

  sol3: just create the account and give the credentials.

  2) 100% ecommerce 

      -- b2c is 100% ecommerce. you can directly buy anything but in b2b , you need to interact with the business people before getting into business with each other.

       3) Payment

            -- b2c , there are lot of payment gateways available. CC/DC/PayPal/WePay etc.

            -- screenshot(payment-gateway) for b2c.


-- b2b payment:

    --screenshot(b2b-payment).


  4)pricing - in b2c products have price is one price it will show all customers

      -- pricing user wise can change price in b2b .

  5) in b2b , only login user can place the order (you should be in b2b customer group to create order).in b2c , both guest and login user can place the order.

    -- screenshot(checkout-b2b-po-no)


  6)quotation - is not there in b2c.

    -- quotation - is important company to company based on quotation will order take.

  7)cart items only one currency in b2c.

    Cart items have different currency in b2b.

  8)Demand is direct demand if there place order in b2c.

      -- if there is discount available , apply and order . otherwise direct order will be placed.

    Demand - available to promise (ATP) based on product delivery and demand in b2b.

  -- if order to be placed , specified quantity to be promised (ATP) on specified date.

Wednesday 13 November 2019

Spring Annoations - Important Annotations

@Component -- when used above the class , it will create bean of that class which will be injected when the class called with @Autowired annotation.

It can be used in any class or interface.

@Component
public class ProductService { 
...
}

@Service -- same as @Component annotation but can be used only on service layer class (ie. where your business logic goes).


@Service
public class ProductService { 
...
}

@Repository --same as @Component annotation but can be used only on persistence layer (ie. storage , retrieval of data).


@Repository
public interface ProductRepository extends JpaRepository<Product, Long> { 
.....
}

Here "ProductRepository" extends JpaRepository , so it can have all JPA methods like findAll , findById etc . If you want to know more about JpaMethods click here.
"Product" is the entity or table and Long is the auto generated id for entity "Product".



@Controller  --same as @Component annotation but can be used only on presentation layer (ie. where your define your api).


@Controller
@Path("product")
public class ProductResource { 
...
}

@Path is used to specify the api path.


@RequestMapping  -- used in classes on presentation layer for rest API's (GET,POST,PUT and DELETE methods).


@Controller
@Path("product")
public class ProductResource { 

Autowired
ProductService productService;

 @RequestMapping(value = "/id", method = RequestMethod.GET, produces = {
        "application/JSON"
    })
    @ResponseBody
    List<Vendor> getProductDetail() {
        return productService.getProductDetail();
    }

}

RequestMapping(value = "/id", method = RequestMethod.GET, produces = {"application/JSON"}) -Here the request method is GET and return value is of type JSON.


Example for service , controller with repository

ProductService.java

@Component
public class ProductService { 
Autowired
ProductRepository productRepository;

public List<Product> getProductData() throws IOException {

List<Product> productDataList = articleRepository.getProductData();

return productDataList;

}
}

ProductRepository.java

@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {

@Query("select p from Product p")
    List<Product> getProductData();
}

ProductResource.java

@Controller
@Path("product")
public class ProductResource { 

Autowired
ProductService productService;

 @RequestMapping(value = "/prod", method = RequestMethod.GET, produces = {
        "application/JSON"
    })
    @ResponseBody
    List<Product> getProductData() {
        return productService.getProductData();
    }

}



@Autowired  -- used to inject the created bean of a class into a reference object.


@Component
public class SampleService { 
Autowired
SampleRepository sampleRepository;

....

}

Here sampleRepository is used to access all the methods with in the  SampleRepository.


@Async  -- used to define a process as seperate thread which is independent of current thread output.The method which uses @Async annotation will run parallely to the method which called it.You can return async method with FUTURE datatype return value or it can be a void method.


@Async
public void loadProductDescription()  {

productRepository.productLoadDescriptionEvict();

}

loadProductDescription -- this method should be called from another class for Async to properly work.Create another class and call this method ,
 so it can run parallel corresponding to the method called it.


@Transactional  -- when you put this annotation above any method it will take care of database management.That is it takes care of open a transaction and commit a transaction , if any error occur it will roll down the transaction and if succeeded , it wil close the transaction.



@Transactional(propagation = Propagation.REQUIRES_NEW)
public void saveOrUpdateArticleInfoVendorList(Long vendor) throws IOException, JAXBException {
List<Product> ProductListForVendorId = productRepository
.findByVendor(vendor);
if (ProductListForVendorId != null) {
for (int j = 0; j < ProductListForVendorId.size(); j++) {
updatProductInfoForEachProduct(ProductListForVendorId.get(j).getProductId());
}
}
}

@Transactional -- this method will be executed as seperate transaction.


@Scheduled -- used for executing time based jobs. If you want a method to execute at particular time , you should annotate the method with @Scheduled annotation. 


@Scheduled(cron = "0 5 * * * ?")
public void productUpdateJob()  {

productRepository.updateProdcutDescriptionFromSource();


}

Here the prodcut description will be updated from given source for 05:00 in the morning.



@Value  -- used to retrieve value stored in application.properties file


@Value("${token.secret.key}")
    private String secretKeyForToken;

Here token.secret.key - is the key present in application.properties.
secretKeyForToken - hold the value for the key specified.

In application.properties file,

token.secret.key = sddfe34343dsdweed@#%


@SpringBootApplication -- this annotation enables the project as spring boot application.

@EnableCaching -- to enable cache in your spring boot application

@EnableAsync -- to enable async in your sping boot application

@EnableRetry -- to enable retry logic in your sping boot application

@EntityScan -- the classes within the specified packages only be scanned for bean creation.

@EnableJpaRepositories -- to enable JPA repository in your sping boot application



@SpringBootApplication
@EnableCaching
@EnableAsync
@EnableRetry
@EntityScan(basePackages = { "com.learnsoftware.productmanagement" })
@EnableJpaRepositories(basePackages = { "com.learnsoftware.productmanagement" })
public class Application {

public static void main(String[] args) {

SpringApplication.run(Application.class, args);
}

}

Here the classes within "com.learnsoftware.productmanagement" package only scanned and nly enable for JpaRepository .

@Cacheable -- used to catch the data with the specified cache name.

@CacheEvict -- used to clear the data with the specified cache name.


@Cacheable("ProductCodeAndDescription")
public List<ProductCodeAndDescription> getAllProductCodeAndDescription() {

String qry = "select p.product_id,p.product_description from product p";
Query query = entityManager.createNativeQuery(qry);
List<Object[]> productList = query.getResultList();
ProductCodeAndDescription productCodeAndDescription = null;
List<ProductCodeAndDescription> productCodeAndDescriptionList = new ArrayList<>();
for (Object[] row : productList) {
productCodeAndDescription = new ProductCodeAndDescription();
productCodeAndDescription.setProductId(Long.parseLong(row[0].toString()));
productCodeAndDescription.setProductDescription(row[1].toString());
productCodeAndDescriptionList.add(productCodeAndDescription);

}
return productCodeAndDescriptionList;
}

@CacheEvict(value = "ProductCodeAndDescription", allEntries = true)
public void evictProdcutDetails() {

}

Here "ProductCodeAndDescription" - is the name of the cache.



@retryable -- used to retry the method if fails (due to network issues) for the specified the count.

@Recover  -- if the method fails even after retry attempts , then the annotated with @Recover will be called.

Note: the method should throw the secified exception(SQLException) in order to come to recovery method.

@Retryable(value = { SQLException.class }, maxAttempts = 3, backoff = @Backoff(delay = 1000))
public String getProductResponse(){
...
}

There will be up to 3 retries with a delay of 1000 milliseconds.

@Recover
void recoverMethod(SQLException e, String sql){
...
}



@Scope -- to specify the scope of the bean . By default scope will be singleton. If you want more information about scope click here.

@Component
@Scope("prototype")
public class ProductService {
...
}

JpaRepository annotations

@Repository --same as @Component annotation but can be used only on persistence layer (ie. storage , retrieval of data).


@Modifying -- should use when a query tries to modify your table .

@Query -- query which does transaction goes with this annotation.

@Param -- used to specify the parameters which will be used within the query.


@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {

@Modifying
@Transactional
@Query(value = "UPDATE product SET status=:status WHERE product_id=:productId", nativeQuery = true)
void updateProductStatus(@Param("productId") Long productId, @Param("status") Integer status);

}

Here "productId" and "status" are two parameters which should be specified with colon(:).
nativeQuery = true -- to specify it as native query.
@Transactional -- to specify it as a seperate transaction.

Jersy Rest Api Annotations


@GET  --- should use for retrieving the data.
@Path  -- used to specify the path for the api.
@Produces -- used to specify the return type of the method.
@Consumes -- used to specify the input type of the method
@PUT -- should use for updating the data.
@POST -- should use for inserting or updating the data.
@Delete -- should use for deleting the data.
@PathParam -- used to specify the path related params
@FormDataParam  -- used to specify the file input
@QueryParam  -- used for string or integer input

If you want to know more about Rest API click here.

Unity Top Download

Latest post

An Introduction to Hybris from basics

An Introduction to Hybris from basics:  -- ecommerce site and PCM(Product content Management) solutions. eg. croma website.  -- having sear...

Popular posts