public class ProductServiceImpl<T extends Product> extends Object implements ProductService<T>, ChangeGenerator<Object[]>
ChangeGenerator
; it will also generate Events of TypeModifier and Type | Field and Description |
---|---|
protected org.apache.commons.collections.Transformer |
nameToProductCategoryTransformer
This can be derived from the dao also, but its a chance to implement a common
cache/lookup strategy for fetching Categories for performance reasons
|
protected Map<String,ProductIndexSearch<T>> |
searchMap
Map of Index Name to the
ProductIndexSearch
Default ProductIndexSearch is mapped to null key |
DEFAULT_PRODUCT_NAME, PRODUCT_LOOKUP_CACHE_NAME, PRODUCT_SEARCH_CACHE_NAME
FILTER_PARENTS, FILTER_PARENTS_IMMEDIATE
Constructor and Description |
---|
ProductServiceImpl() |
Modifier and Type | Method and Description |
---|---|
void |
addChangeListener(ChangeListener changeListener)
Allow Notify all
ChangeListener s about a change |
void |
clearCache()
Clear all
Product related Cache |
void |
convert(IHierarchialReference entity,
Class to)
If we wish to transform an entity type we should perform the transformation and then the update.
|
T |
convertToCategory(T product)
Converts an existing Product in the hierarchy to a Category
|
Long |
count(Query<T> query)
|
int |
countFilterParents(T parent,
boolean immediate)
Return number of nodes that are parents under the specified parent Node
The parent node must have a valid Product.getId() or HierarchialDomainObject.getHierarchy() ; immediate is false. |
Long |
delete(Collection<Long> ids) |
Long |
delete(Long id)
A special Delete operation on the entity that will remove the entity and related entities based on id.
|
void |
delete(T persistentObject) |
void |
deleteSubHierarchy(T rootNode)
Delete a root node and its children.
May throw an exception is there is a fault in the hierarchy or any node could not be deleted for some reason. |
List<T> |
filterParents(T parent,
boolean immediate)
Return
List of nodes that are parents under the specified parent Node The parent node must have a valid Product.getId() or HierarchialDomainObject.getHierarchy() ; immediate is false. |
List<String> |
getAdditionalCacheNames()
Register additional caches, so that on
clearCache() all registered caches can be cleared |
List<ProductAlias> |
getAliasForProduct(T product)
For a given Product (T) derive all its
ProductAlias |
org.springframework.cache.Cache |
getCache() |
org.springframework.cache.CacheManager |
getCacheManager() |
org.apache.commons.collections.Transformer |
getConvertToCategoryTransformer() |
<PD extends ProductDao<T>> |
getDao()
Avoid using this from any API call; if a final project is for sure DB dependent then only use this for convenience.
|
T |
getEntityInstance()
The entity instance maybe an extension of the Base ensure Queries work for extensions
derive the exact instance required for the Query.
|
String |
getLastChildHierarchyCode(T parent)
Get last childs hierarchy code
|
List |
getListeners()
Get list directly.
|
org.apache.commons.collections.Transformer |
getNameToProductCategoryTransformer()
This can be derived from the dao also, but its a chance to implement a common
cache/lookup strategy for fetching Categories for performance reasons
|
List<T> |
getParents(T product,
boolean includeDefault,
boolean includeThis)
Get parents in the hierarchy for this product.
Note: param includeDefault is for convenience; however in a loop its more optimial to query it separately and then add to list. |
List<T> |
getParents(T product,
boolean includeThis,
String DEFAULT_PRODUCT_NAME,
QueryOptimizer queryOptimizer)
Get parents for the product.
|
T |
getProduct(T queryObject)
A Convenience method that can identify a
Product uniquely by any unique key. |
Collection<T> |
getProducts(Collection<String> productNames)
For a given list of Product Names produce a Collection of Products matching those Names.
|
QueryOptimizer |
getQueryOptimizer()
Uses a
QueryOptimizer to limit the joins and fields required for hierarchical records |
List<AutoGenMenuItem> |
getRelatedNavigations()
Navigations & menus associated with Product Data
that we want to refresh on
clearCache() |
Map<String,ProductIndexSearch<T>> |
getSearchMap()
Map of Index Name to the
ProductIndexSearch
Default ProductIndexSearch is mapped to null key |
ProductIndexSearch<T> |
getSearchService(String indexName) |
void |
index()
Re-Index all the Products using Spider
|
void |
init() |
boolean |
isExistsAsParent(T node) |
T |
load(Object objectId) |
T |
load(Object arg0,
Class arg1)
In some situations the DAO represents an Interface or perhaps a parent of the actual Entity./
The exact type of the entity would have to be Supplied.
|
List |
loadHierarchy(ProductReference rootNode,
boolean loadLeaves)
Same as
#loadHierarchy(Product, boolean) , but supports ProductReference version |
List |
loadHierarchy(T rootNode,
boolean loadLeaves) |
List<T> |
loadHierarchyFlat(T rootNode)
Queries the list as a flat list but does not to a structural hierarchical conversion (Homogeneous list)
|
Page<T> |
loadPage(Query<T> query)
Load data in paginated fashion.
|
Map<String,String> |
locateResourceForProduct(T productCategory,
String... resourceTypeAttributesIds)
Get the configuration from the parent folder name and its parent.
|
String |
makeSpaceForNodeInParent(T node,
T parent,
Integer sequence) |
void |
move(T node,
T parent,
Integer order)
Move a content under a parent.
|
void |
notifyAllListeners(Object[] event)
Whenever a node is selected/updated, it also notifies its listeners.
|
T |
prepareNewProduct(T product,
Integer sequence)
Prepares a new product entity for sequence, hierarchy etc based on the parent set
Persistence depends on the implementation. |
List<T> |
query(Query<T> queryEntity)
|
<SUB_T> List<SUB_T> |
query(Query<T> query,
Class<SUB_T> claz)
Derive a SubSet (claz) of T only as an queried entity.
|
List |
query(String arg0,
String dialect,
Object... arg1)
Execute a raw Query in the native implementation language.
|
Page |
query(String arg0,
String dialect,
PageInfo arg1,
Object... arg2)
Execute a raw Query in the native implementation language.
|
Page<T> |
queryPage(Query<T> query)
|
<SUB_T> Page<SUB_T> |
queryPage(Query<T> query,
Class<SUB_T> claz)
Derive a SubSet (claz) of T only as an queried entity.
|
ProductAlias |
save(ProductAlias alias)
Save a
ProductAlias |
ProductAttribute |
save(ProductAttribute attrib)
Ability to update a single
ProductAttribute without updating the whole Product
Useful in Ajax situations where we want to save a partial aspect of the product only. |
T |
save(T transientObject) |
List |
search(String indexName,
com.neurosys.spider.domain.SearchParams searchParams,
PageInfo pageInfo,
String... categoryNames)
Perform indexed/lucene based searches
|
int |
searchCount(String indexName,
com.neurosys.spider.domain.SearchParams searchParams,
String... categoryNames)
Perform indexed/lucene based searches
|
void |
setAdditionalCacheNames(List<String> additionalCacheNames)
Register additional caches, so that on
clearCache() all registered caches can be cleared |
void |
setCache(org.springframework.cache.Cache cache) |
void |
setCacheManager(org.springframework.cache.CacheManager cacheManager) |
void |
setConvertToCategoryTransformer(org.apache.commons.collections.Transformer convertToCategoryTransformer) |
void |
setDao(ProductDao dao) |
void |
setListeners(List listeners)
Set list directly.
|
void |
setNameToProductCategoryTransformer(org.apache.commons.collections.Transformer nameToProductCategoryTransformer)
This can be derived from the dao also, but its a chance to implement a common
cache/lookup strategy for fetching Categories for performance reasons
|
void |
setQueryOptimizer(QueryOptimizer queryOptimizer)
Uses a
QueryOptimizer to limit the joins and fields required for hierarchical records |
void |
setRelatedNavigations(List<AutoGenMenuItem> relatedNavigations)
Navigations & menus associated with Product Data
that we want to refresh on
clearCache() |
void |
setSearchMap(Map<String,ProductIndexSearch<T>> searchMap)
Map of Index Name to the
ProductIndexSearch
Default ProductIndexSearch is mapped to null key |
protected void |
sysAutoIndex()
Based on a Scheduled job keep refreshing the Index
|
int |
update(String query,
boolean isNative,
Object... params)
An Update query with optional params
|
void |
updateNav()
Update and
AutoGenMenuItem linked to the service |
protected Map<String,ProductIndexSearch<T extends Product>> searchMap
ProductIndexSearch
Default ProductIndexSearch
is mapped to null keyprotected org.apache.commons.collections.Transformer nameToProductCategoryTransformer
@PostConstruct public void init()
public List<T> loadHierarchyFlat(T rootNode)
loadHierarchyFlat
in interface HierarchyService<T extends Product>
rootNode
- loadLeaves
- public List loadHierarchy(T rootNode, boolean loadLeaves)
loadHierarchy
in interface HierarchyService<T extends Product>
rootNode
- thispublic List loadHierarchy(ProductReference rootNode, boolean loadLeaves)
ProductService
#loadHierarchy(Product, boolean)
, but supports ProductReference
versionloadHierarchy
in interface ProductService<T extends Product>
rootNode
- thispublic Long count(Query<T> query) throws Exception
QueryableDao
Query
and on Queryable
fields only.
Query.setNullSet(Set)
Queryable
fields will face problems.public Page<T> loadPage(Query<T> query)
ProductDao
loadPage
in interface ProductDao<T extends Product>
public void delete(T persistentObject)
delete
in interface GenericDao<T extends Product>
public <PD extends ProductDao<T>> PD getDao()
getDao
in interface ProductService<T extends Product>
public void setDao(ProductDao dao)
public Long delete(Long id)
GenericDao
delete
in interface GenericDao<T extends Product>
Long
public Long delete(Collection<Long> ids)
delete
in interface ProductDao<T extends Product>
public T load(Object arg0, Class arg1)
GenericDao
load
in interface GenericDao<T extends Product>
arg0
- as Id for Entityarg1
- as Class
of entitypublic void move(T node, T parent, Integer order) throws Exception
HierarchyService
IHierarchialReference.getParentId()
and IHierarchialReference.getHierarchy()
.move
in interface HierarchyService<T extends Product>
move
in interface ProductDao<T extends Product>
parent
- @nullable true (if IHierarchialReference.ROOT
order
- as Integer @nullable true (optional)Exception
public List<T> query(Query<T> queryEntity) throws Exception
QueryableDao
public Page<T> queryPage(Query<T> query) throws Exception
QueryableDao
Query
and on Queryable
fields only.
Query.setNullSet(Set)
Queryable
fields will face problems.public void deleteSubHierarchy(T rootNode) throws Exception
HierarchyService
deleteSubHierarchy
in interface HierarchyService<T extends Product>
deleteSubHierarchy
in interface ProductDao<T extends Product>
Exception
public String getLastChildHierarchyCode(T parent)
ProductDao
getLastChildHierarchyCode
in interface HierarchyService<T extends Product>
getLastChildHierarchyCode
in interface ProductDao<T extends Product>
public String makeSpaceForNodeInParent(T node, T parent, Integer sequence)
makeSpaceForNodeInParent
in interface ProductDao<T extends Product>
public List<T> filterParents(T parent, boolean immediate)
ProductDao
List
of nodes that are parents under the specified parent Node Product.getId()
or HierarchialDomainObject.getHierarchy()
; immediate is false.filterParents
in interface ProductDao<T extends Product>
parent
- as Timmediate
- as boolean; if true will fetch only parents immediately under the specified parentpublic int countFilterParents(T parent, boolean immediate)
ProductDao
Product.getId()
or HierarchialDomainObject.getHierarchy()
; immediate is false.countFilterParents
in interface ProductDao<T extends Product>
parent
- as Timmediate
- as boolean; if true will fetch only parents immediately under the specified parentpublic T prepareNewProduct(T product, Integer sequence)
prepareNewProduct
in interface ProductService<T extends Product>
product
- as Tsequence
- as Integer, @nullable trueProduct
objectpublic T convertToCategory(T product)
ProductService
convertToCategory
in interface ProductService<T extends Product>
public <SUB_T> List<SUB_T> query(Query<T> query, Class<SUB_T> claz) throws Exception
QueryableDao
public <SUB_T> Page<SUB_T> queryPage(Query<T> query, Class<SUB_T> claz) throws Exception
QueryableDao
public Map<String,String> locateResourceForProduct(T productCategory, String... resourceTypeAttributesIds)
locateResourceForProduct
in interface ProductService<T extends Product>
productCategory
- as T. Resources are common for siblings under a category/parent, hence productCategory is request for.public void convert(IHierarchialReference entity, Class to)
ProductDao
InheritanceType.SINGLE_TABLE
or oen where there is a shared DiscriminatorValue
convert
in interface HierarchyService<T extends Product>
convert
in interface ProductDao<T extends Product>
public ProductAttribute save(ProductAttribute attrib)
ProductDao
ProductAttribute
without updating the whole Product
save
in interface ProductDao<T extends Product>
attrib
- as ProductAttribute
ProductAttribute
public T getProduct(T queryObject) throws Exception
ProductService
Product
uniquely by any unique key. Results from this may also be eligible for Caching
Product.getId()
, Product.getName()
, HierarchialDomainObject.getHierarchy()
and any unique identifiers added to the base EntitygetProduct
in interface ProductService<T extends Product>
Exception
public List query(String arg0, String dialect, Object... arg1) throws Exception
FreeQuery
query
in interface FreeQuery
arg0
- as String in native Schema languagedialect
- as String. NULL or empty or "NATIVE" implies NATIVE, "JPA" implies JPA will be used. Additional dialects can be supported but they will be implementation dependent.arg1
- as Query parameters to the string.
List
Exception
public Page query(String arg0, String dialect, PageInfo arg1, Object... arg2) throws Exception
FreeQuery
query
in interface FreeQuery
arg0
- as String in native Schema languagedialect
- as String. NULL or empty or "NATIVE" implies NATIVE, "JPA" implies JPA will be used. Additional dialects can be supported but they will be implementation dependent.arg1
- as PageInfo
for pagination of resultarg2
- as Query parameters to the string
Page
Exception
public List search(String indexName, com.neurosys.spider.domain.SearchParams searchParams, PageInfo pageInfo, String... categoryNames) throws Exception
ProductService
search
in interface ProductService<T extends Product>
indexName
- as String @Nuallble true implies the default index wilt be searchedsearchParams
- as SearchParams @nullable falsepageInfo
- as PageIngo @nullable truecategoryNames
- @nullable trueException
public List<T> getParents(T product, boolean includeDefault, boolean includeThis)
ProductCategoryLookup
to get a cached state of the default product (configs) @ root.
P DEFAULT = (P)productCategoryLookup.transform(ProductService.DEFAULT_PRODUCT_NAME);
getParents
in interface ProductService<T extends Product>
product
- includeDefault
- as boolean (To include the default configuration holder parent to all @ root level)includeThis
- as boolean, if this product should be a leaf node in the hierarchy.public Collection<T> getProducts(Collection<String> productNames)
getProducts
in interface ProductService<T extends Product>
productNames
- as List of Stringpublic int searchCount(String indexName, com.neurosys.spider.domain.SearchParams searchParams, String... categoryNames) throws Exception
ProductService
searchCount
in interface ProductService<T extends Product>
indexName
- as String @Nuallble true implies the default index wilt be searchedsearchParams
- as SearchParams @nullable falsecategoryNames
- @nullable trueException
public int update(String query, boolean isNative, Object... params)
FreeQuery
@Scheduled(cron="${search.indexer.product.cron}") protected void sysAutoIndex() throws Exception
Exception
public void index() throws Exception
ProductService
index
in interface ProductService<T extends Product>
Exception
public void updateNav()
AutoGenMenuItem
linked to the servicepublic void clearCache()
ProductService
Product
related CacheclearCache
in interface ProductService<T extends Product>
public org.apache.commons.collections.Transformer getNameToProductCategoryTransformer()
public void setNameToProductCategoryTransformer(org.apache.commons.collections.Transformer nameToProductCategoryTransformer)
public Map<String,ProductIndexSearch<T>> getSearchMap()
ProductIndexSearch
Default ProductIndexSearch
is mapped to null keypublic void setSearchMap(Map<String,ProductIndexSearch<T>> searchMap)
ProductIndexSearch
Default ProductIndexSearch
is mapped to null keypublic ProductIndexSearch<T> getSearchService(String indexName)
getSearchService
in interface ProductService<T extends Product>
public List<String> getAdditionalCacheNames()
clearCache()
all registered caches can be clearedpublic void setAdditionalCacheNames(List<String> additionalCacheNames)
clearCache()
all registered caches can be clearedpublic List<AutoGenMenuItem> getRelatedNavigations()
clearCache()
public void setRelatedNavigations(List<AutoGenMenuItem> relatedNavigations)
clearCache()
public ProductAlias save(ProductAlias alias)
ProductDao
ProductAlias
save
in interface ProductDao<T extends Product>
public List<ProductAlias> getAliasForProduct(T product)
ProductDao
ProductAlias
getAliasForProduct
in interface ProductDao<T extends Product>
public boolean isExistsAsParent(T node)
isExistsAsParent
in interface ProductDao<T extends Product>
public org.apache.commons.collections.Transformer getConvertToCategoryTransformer()
public void setConvertToCategoryTransformer(org.apache.commons.collections.Transformer convertToCategoryTransformer)
public QueryOptimizer getQueryOptimizer()
QueryOptimizer
to limit the joins and fields required for hierarchical recordspublic void setQueryOptimizer(QueryOptimizer queryOptimizer)
QueryOptimizer
to limit the joins and fields required for hierarchical recordspublic T getEntityInstance()
QueryableDao
getEntityInstance
in interface QueryableDao<T extends Product>
public org.springframework.cache.Cache getCache()
getCache
in interface ProductService<T extends Product>
public void addChangeListener(ChangeListener changeListener)
ChangeGenerator
ChangeListener
s about a changeaddChangeListener
in interface ChangeGenerator<Object[]>
public void notifyAllListeners(Object[] event)
ChangeGenerator
notifyAllListeners
in interface ChangeGenerator<Object[]>
public List getListeners()
ChangeGenerator
getListeners
in interface ChangeGenerator<Object[]>
public void setListeners(List listeners)
ChangeGenerator
setListeners
in interface ChangeGenerator<Object[]>
public List<T> getParents(T product, boolean includeThis, String DEFAULT_PRODUCT_NAME, QueryOptimizer queryOptimizer)
ProductDao
getParents
in interface ProductDao<T extends Product>
product
- as productDEFAULT_PRODUCT_NAME
- as String of the default product name. If empty, then its not included.queryOptimizer
- as QueryOptimizer
public org.springframework.cache.CacheManager getCacheManager()
public void setCacheManager(org.springframework.cache.CacheManager cacheManager)
public void setCache(org.springframework.cache.Cache cache)
Copyright © 2018. All rights reserved.