cancel
Showing results for 
Search instead for 
Did you mean: 

OCC Architectural question about version 2.

Former Member
0 Kudos
1,844

I wonder what is everyone opinion about one simple fact.

OCC or a.k.a. commercewebservices version 2 is one of the worst architectures I have seen in Hybris.

Let me explain: Version 1 is fine, you have controllers, you call facades, they do the conversion you get a result as Data object, it is the same on the storefront it is an ok architecture it is from pre sap days when Hybris was not in SAP so it is good.

Version 2 however uses ANOTHER layer of conversion. So you convert your models to Data objects in the facades THEN you get the DATA which is ALREADY a DTO and you convert the DATA to WsDTO what is the point it is already a DTO !?

So right now if you need to add a field in a model and return it in version 2 you have to:

  • change the model

  • change the bean for the Data object new property

  • change the converter/populator that is used by the facade. (here you were done in v1)

  • change the WsDTO bean xml

  • change the Orika config in another xml

  • Hook everything together.

  • Debug is it an issue in the model, in the data, in the converter, in Orika (yup thats fun) in the spring config you have for orika or in your WsDTO.

  • Do it again for the next service

So please can someone explain me what is the point of using Orika to convert from an already a DTO called Data for some reason to another DTO called WsDTO for some reason. I expect in version 3 to have a RealDTO and third conversion ?

I am not sure who is the author of this but I believe this is an overkill.

My goal here is to st conversation because after all we know that no one actually helps in the experts. If there is no conversation started here I will start it on stackoverflow and twitter as well since this is an amazing joke.

P.S. I Love ORIKA but to overdesign and misuse it in such a way is just a joke, you can convert directly with orika

P.S.S. Also for some v2 services like register you still use old school populators to populate directly the Data object (like register) so why the fck do you need Orika at all !?

View Entire Topic
Former Member
0 Kudos

Hello Kinga, this is another story.

Right now the commerce facades contains a lot of logics that they should not. The bussines logic should be in the services the Facade is just a Facade, but thats a different story.

I have been working on a ecommerce module that was using Orika directly converting models and trust me it was working like a blast (it was about an year ago), so basically we even had a defaultFallbackConverter that basically was converting all matches that orika can find between the model and the class I mean something like:

mapperFactory.classMap(BaseModel.class, BaseData.class).byDefault().register();

so it was working like a blast for about 500+ models, indeed ti is hard to debug as I stated previously, but it works like a blast.

Right now the quality of the OCC is pretty bad (in an old version I use) and I am really really sad.

Check an example the UserController#getUser

 @Secured(
                 { "ROLE_CUSTOMERGROUP", "ROLE_TRUSTED_CLIENT", "ROLE_CUSTOMERMANAGERGROUP" })
 @RequestMapping(value = "/{userId}", method = RequestMethod.GET)
 @ResponseBody
 public UserWsDTO getUser(@RequestParam(defaultValue = DEFAULT_FIELD_SET) final String fields) {
     final CustomerData customerData = customerFacade.getCurrentCustomer();
     return getDataMapper().map(customerData, UserWsDTO.class, fields);
 }

The url param userId is not used at all, even if it is called an user it works only for customers the whole OCC doesn't work for Employees (which are also users) and what the method does ? calls a facade... that converts then calls an orika that converts... and this is a hell of a slow (yes the cache helps)

This UserController is so BAD that it doesn't follow the ARCHITECTURE at all... see another method

  @Secured(
                 { "ROLE_CUSTOMERGROUP", "ROLE_TRUSTED_CLIENT", "ROLE_CUSTOMERMANAGERGROUP" })
 @RequestMapping(value = "/{userId}", method = RequestMethod.DELETE)
 @ResponseStatus(HttpStatus.OK)
 public void deactivateUser() {
     final UserModel userModel = userService.getCurrentUser();
     if (!userModel.isLoginDisabled()) {
         userModel.setLoginDisabled(true);
         modelService.save(userModel);
     }
     if (LOG.isDebugEnabled()) {
         LOG.debug("deactivateUser: userId=" + userModel.getUid());
     }
 }


uses service and models directly. I am not aware do SAP use any Sonar or any standards for writing code or code reviews but I guess no, SAP developers even skip layers everywhere.... it is indeed a spaghetti architecture that just pretends to be lasagna 😉

former_member747843
Active Participant
0 Kudos

1) OCC was created to be used by storefront so for customers - in accelerator you also cannot login with employee credentials.
2) getUser method don't use {userId} because it is already handled in filter which set current customer so there is no point to duplicate that code
3) deactivateUser method implementation was already improved and use facades

You have wrote that 'no one actually helps in the experts' but for me it looks like you don't need help or explanation but just place to complain. You have started from OCC, then criticized commerce layer and end up with services which should contain all logic.
It looks like you want to rewrite whole Hybris platform. Maybe in some perfect world it would be possible but usually there is no passibility to write everything from scratch and there is limited time for feature implementation and in case of framework there is also something called backward compatibility.

And probably you will be able to find other code which you will not like but I don't see point in discussing about every single methods of controllers in here.

Former Member
0 Kudos

Hello , no actually I wanted to st conversation why it is written so badly so someone can do something about it. If it was an open source platform and if I had tests I would open a PR since I can't I can only speak here. In any case I do want Hybris to be better platform, because I use it, because I believe it si the best Java commerce platform right now however it is getting bloated and slow and worst then before compared to 5 years ago and this makes me sad and a bit angry.

In any case I completely understand why userId is not used.. I do not know why this is called "users" endpoints not "customers" but that's a different story I guess someone didn't check the PR again.

In any case right now the OCC is extremely slow to extend following the architecture of Version 2. I prefer the version 1 architecture or completely Model To Data vs Orika. In any case I gave an example above that you are using Services in controllers so I do not know is the architecture Controllers -> Facades -> Services because it doesn't look like that to me for OCC.

About rewriting Hybris this is something we can chat about on different channel ;)