문제

The definition of runProcess() method in PipelineManager is

public PipelineResult runProcess(String pChainId, Object pParam)
            throws RunProcessException

This gives me an impression that ANY object can be passed as the second param. However, ATG OOTB has PipelineManager component referring to CommercePipelineManager class which overrides the runProcess() method and downcast pParam to map and adds siteId to it.

Basically, this enforces the client code to send only Map. Thus, if one needs to create a new pipeline chain, has to use map as data structure to pass on the data. Offcourse, one can always get around this by creating a new PipelineManager component, but I was just wondering the thought behind explicitly using map in CommercePipelineManager

도움이 되었습니까?

해결책

I'm working with ATG 9.X now and I believe PipelineManager itself doesn't cast parameter to anything and just pass it over to underlying chains - so if you implement your own processor chain you are free to pass any parameter, but in most of the OOTB processors there is convention to pass the map that may contain other required parameters.

Very typical code for OOTB Commerce processors (and often for your own customizations and extentions of commerce pipeline - to follow OOTB convention) is to pass the parameter as a map that would contain everything required inside the processor (in most cases it's Order object, sometimes Profile and other requisites). The processor itself usually doesn't have any dependencies (provided through the injection). The very first thing processor would do is to cast first parameter to the map and pull whatever it needs for functionality (checking that it has all required things inside).

Theoretically it may give better modularization and logic decoupling, providing you have good abstraction based on interfaces (so you can cast map values to interface type, not implementation).

E.g. here is the code snippet for the typical processor

  public int runProcess(Object pParam, PipelineResult pResult) throws Exception
  {
    HashMap map = (HashMap) pParam;
    OrderManager mgr = (OrderManager) map.get(PipelineConstants.ORDERMANAGER);
    Order order = (Order) map.get(PipelineConstants.ORDER);

    if (order == null)
      throw new InvalidParameterException("...");
    if (mgr == null)
      throw new InvalidParameterException("...");

    // ... business logic 

    return SUCCESS;
  }

P.S. I agree it could be designed better. However there are a few other "medieval" things in ATG that are strange and hard to explain nowadays - but it's probably OK, keeping in mind that platform development started in 1991

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top