@Path(value="/")
@Consumes(value={"application/json","application/text","text/html","application/x-www-form-urlencoded"})
@Produces(value="application/json;charset=utf-8")
public class StrategiesService<P extends Product,U extends IGenericEcomUser,CONTEXT>
extends SecurableService
implements ChangeListener, ChangeGenerator
EComSession
Web Service Layer for accessing Strategies over a users Session (Guest or Logged in)
Strategy is a ChangeGenerator and a ChangeListener
then any object notified will call onChange(ChangeGenerator, Object) of the same Strategy with the event being | Modifier and Type | Field and Description |
|---|---|
protected org.apache.commons.collections.Transformer |
throwableToMessage
Marshal errors to just their messages
|
applicationContext, CACHE, NO_CACHE, request, response| Constructor and Description |
|---|
StrategiesService() |
StrategiesService(boolean checkAuthFiltered) |
| Modifier and Type | Method and Description |
|---|---|
protected PartialTransactionException |
_strategiesCalcData(Map<P,Number> productQtyMap,
List<CartItem> cartItems,
U user,
String currency,
List<PromotionForUser> promotions,
Amount subTotal,
Number totalQuantity,
Collection<String> paramNames,
EComSession session,
CONTEXT context,
PartialTransactionException pte)
Can override if there are any App specific Strategies not handled by this default service
|
void |
addChangeListener(ChangeListener changeListener)
Allow Notify all
ChangeListeners about a change |
protected CONTEXT |
deriveContext(U user,
EComSession session,
String contextStr)
Derive Context - Give pref to param, if not provided then rely on Session.
Context Derivation Algo: If contextProviderStrategy exists then pass raw contextStr to it and derive CONTEXT object(s) and will also update the ContextualSession.setPartialContext(Object). |
AdapterService |
getAdapterService()
Strategies can be Adapters; that can be updated @ runtime.
|
Object |
getAreas(String id,
String type)
For international shipping etc, area information
|
AreaStrategy<AreaType,CONTEXT> |
getAreaStrategy() |
CartProductTransformService<P,CartItem> |
getCartProductTransform()
Handle All conversions
|
ContextProviderStrategy<U,CONTEXT> |
getContextProviderStrategy() |
CurrencyStrategy |
getCurrencyStrategy() |
List |
getListeners()
Get list directly.
|
CumulativeChargeStrategy |
getPackagingStrategy() |
ProductService |
getProductService() |
PromotionStrategy<P,U> |
getPromotionStrategy() |
SaleStrategy |
getSaleStrategy() |
CumulativeChargeStrategy |
getShippingStrategy() |
CumulativeChargeStrategy |
getTaxStrategy() |
org.apache.commons.collections.Transformer |
getThrowableToMessage()
Marshal errors to just their messages
|
void |
init() |
protected void |
logValidationError(String strategyName,
Amount subTotal,
List<CartItem> cartItems,
U user,
String currency,
Collection<String> paramNames,
EComSession session,
String contextStr,
Throwable e) |
void |
notifyAllListeners(Object object)
Whenever a node is selected/updated, it also notifies its listeners.
|
void |
onChange(ChangeGenerator changeGenerator,
Object context)
Allow Strategies that are
ChangeGenerators to modify the session via ContextualSession.setPartialContext(Object) |
String |
productListCalcs(String productNames,
String params,
String currency,
String toCurrency,
String context)
A JSON object that contains all data from various strategies available
to this service; over the Products in the Session-Cart
|
String |
reloadScripts(String keysStr)
Reload the strategies that can be reloaded (Scripts)
|
String |
sessionCartCalcs(String params,
String currency,
String toCurrency,
String context)
A JSON object that contains all data from various strategies available
to this service; over the Products in the Session-Cart
|
void |
setAdapterService(AdapterService adapterService)
Strategies can be Adapters; that can be updated @ runtime.
|
void |
setAreaStrategy(AreaStrategy<AreaType,CONTEXT> areaStrategy) |
void |
setCartProductTransform(CartProductTransformService<P,CartItem> cartProductTransform)
Handle All conversions
|
void |
setContextProviderStrategy(ContextProviderStrategy<U,CONTEXT> contextProviderStrategy) |
void |
setCurrencyStrategy(CurrencyStrategy currencyStrategy) |
void |
setListeners(List listeners)
Set list directly.
|
void |
setPackagingStrategy(CumulativeChargeStrategy packagingStrategy) |
void |
setProductService(ProductService productService) |
void |
setPromotionStrategy(PromotionStrategy<P,U> promotionStrategy) |
void |
setSaleStrategy(SaleStrategy saleStrategy) |
void |
setShippingStrategy(CumulativeChargeStrategy shippingStrategy) |
void |
setTaxStrategy(CumulativeChargeStrategy taxStrategy) |
void |
setThrowableToMessage(org.apache.commons.collections.Transformer throwableToMessage)
Marshal errors to just their messages
|
Map |
strategiesCalcData(List<CartItem> cartItems,
U user,
String currency,
String toCurrency,
Collection<String> paramNames,
EComSession session,
String contextStr) |
checkAuthFilterInvoked, filter, queryfilter, getCacheDef, getTestString, queryprotected org.apache.commons.collections.Transformer throwableToMessage
public StrategiesService()
public StrategiesService(boolean checkAuthFiltered)
@PostConstruct public void init()
protected CONTEXT deriveContext(U user, EComSession session, String contextStr)
ContextualSession.setPartialContext(Object).
ContextualSession.getContext()user - as Usession - as EComSessioncontextStr - as String (loosely app defined as usually JSON) (custom to Application)protected void logValidationError(String strategyName, Amount subTotal, List<CartItem> cartItems, U user, String currency, Collection<String> paramNames, EComSession session, String contextStr, Throwable e)
protected PartialTransactionException _strategiesCalcData(Map<P,Number> productQtyMap, List<CartItem> cartItems, U user, String currency, List<PromotionForUser> promotions, Amount subTotal, Number totalQuantity, Collection<String> paramNames, EComSession session, CONTEXT context, PartialTransactionException pte)
productQtyMap - as Map of Product to NumbercartItems - as List of CartItemuser - as Ucurrency - as Stringpromotions - as List of PromotionForUsersubTotal - as Amount (sub total calculated **so far**)totalQuantity - as # of items as NumberparamNames - as List of String of derivations requested byclientcontext - as CONTEXTpte - as PartialTransactionException to add to incase of errors, warnings, info messages to return back to client.PartialTransactionExceptionpublic Map strategiesCalcData(List<CartItem> cartItems, U user, String currency, String toCurrency, Collection<String> paramNames, EComSession session, String contextStr)
cartItems - as List of CartItem.user - as Usercurrency - as String, for the currency to display all calcs intoCurrency - as String, an optional nullable parameter that specifies any additional calculation conversion for an alternate currency. See also currencyStrategyparamNames - as Collection of String; @nullable true. If not null and type of error specified, will fetch additional (non-strategy), related info.
RuntimeException that does not fit in the following. This will not even result in a return object, and be passed on the to the calling API to be handledValidationException; these will also replace any value in the result MapBreakChainExceptionContinueProcessingExceptioncontextStr - as String (loosely app defined as usually JSON) (custom to Application)Map with all calculations per Strategy + a context if ContextualSession.getContext() existsAbstractCartService,
CartItem@GET @Path(value="sessionCartCalcs") public String sessionCartCalcs(@QueryParam(value="params") String params, @QueryParam(value="currency") String currency, @QueryParam(value="toCurrency") String toCurrency, @QueryParam(value="context") String context) throws Exception
params - as comma separated String of params; @nullable true. If null will fetch all params
#strategiesCalcData(List, AbstractUser, List)currency - as String, for the currency to display all calcs intoCurrency - as String, an optional nullable parameter that specifies any additional calculation conversion for an alternate currency. See also currencyStrategycontext - as String (loosely app defined as usually JSON) (custom to Application)ContextualSession.getContext() existsException@POST @Path(value="productListCalcs") public String productListCalcs(@FormParam(value="productNames") String productNames, @FormParam(value="params") String params, @FormParam(value="currency") String currency, @QueryParam(value="toCurrency") String toCurrency, @FormParam(value="context") String context) throws Exception
productNames - as List of product names or keys that represent the items in the cartparams - as comma separated String of params; @nullable true. If null will fetch all params
#strategiesCalcData(List, AbstractUser, List)currency - as String, for the currency to display all calcs intoCurrency - as String, an optional nullable parameter that specifies any additional calculation conversion for an alternate currency. See also currencyStrategycontext - as String (loosely app defined as usually JSON) (custom to Application)ContextualSession.getContext() existsException@GET @Path(value="areas") public Object getAreas(@QueryParam(value="id") String id, @QueryParam(value="type") String type)
is - as Area Id @nullable true. If Null, will fetch the full mapid - as String. If specified will fetch only AreaType for that id and type, or return null if it does not existtype - as String. If specified, will clarify the nature/level of Id. Like region, country, state, zip etc.AreaType record if id is null
OR List of AreaTypes or a Map of id to AreaType (depends on implementation of AreaStrategy.@GET @Path(value="admin/reload") public String reloadScripts(@QueryParam(value="keys") String keysStr) throws Exception
keysStr - as comma separated keys that define the Script(s) @nullable true; if no name provided then all are reloadedExceptionpublic CumulativeChargeStrategy getShippingStrategy()
public void setShippingStrategy(CumulativeChargeStrategy shippingStrategy)
public CumulativeChargeStrategy getTaxStrategy()
public void setTaxStrategy(CumulativeChargeStrategy taxStrategy)
public CumulativeChargeStrategy getPackagingStrategy()
public void setPackagingStrategy(CumulativeChargeStrategy packagingStrategy)
public SaleStrategy getSaleStrategy()
public void setSaleStrategy(SaleStrategy saleStrategy)
public ProductService getProductService()
public void setProductService(ProductService productService)
public PromotionStrategy<P,U> getPromotionStrategy()
public void setPromotionStrategy(PromotionStrategy<P,U> promotionStrategy)
public ContextProviderStrategy<U,CONTEXT> getContextProviderStrategy()
public void setContextProviderStrategy(ContextProviderStrategy<U,CONTEXT> contextProviderStrategy)
public AreaStrategy<AreaType,CONTEXT> getAreaStrategy()
public void setAreaStrategy(AreaStrategy<AreaType,CONTEXT> areaStrategy)
public CurrencyStrategy getCurrencyStrategy()
public void setCurrencyStrategy(CurrencyStrategy currencyStrategy)
public org.apache.commons.collections.Transformer getThrowableToMessage()
public void setThrowableToMessage(org.apache.commons.collections.Transformer throwableToMessage)
public AdapterService getAdapterService()
AdapterServicepublic void setAdapterService(AdapterService adapterService)
AdapterServicepublic CartProductTransformService<P,CartItem> getCartProductTransform()
CartProductTransformServicepublic void setCartProductTransform(CartProductTransformService<P,CartItem> cartProductTransform)
CartProductTransformServicepublic void onChange(ChangeGenerator changeGenerator, Object context)
ChangeGenerators to modify the session via ContextualSession.setPartialContext(Object)onChange in interface ChangeListenerchangeGenerator - as the generator that caused the change. Specially useful if the Listener is subscribing to multiple ChangeGeneratorscontext - as the model change communicatedpublic void addChangeListener(ChangeListener changeListener)
ChangeGeneratorChangeListeners about a changeaddChangeListener in interface ChangeGeneratorpublic void notifyAllListeners(Object object)
ChangeGeneratornotifyAllListeners in interface ChangeGeneratorpublic List getListeners()
ChangeGeneratorgetListeners in interface ChangeGeneratorpublic void setListeners(List listeners)
ChangeGeneratorsetListeners in interface ChangeGeneratorCopyright © 2018. All rights reserved.