//LocalCache.java
package com.dbecom.platform.pricing.server.persistance;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import com.dbecom.platform.foundation.logging.Logger;
public abstract class LocalCache {
/**
* The default maximum cache size.
*/
public static final int DEFAULT_MAX_SIZE = 300;
private static Logger logger=Logger.getLogger(LocalCache.class);
/**
* Returns the configured default maximum size.
* @param astrConfigName a unique identifier used to lookup the configured default maximum size.
* Normally, this is the class name of the caching class.
* @param aDefaultMaxSize the default maximum size to use if none is configured.
* @return the configured default maximum size.
*/
public static int getDefaultMaxSize(String astrConfigName, int aDefaultMaxSize) {
/* int result = WCConfigProperties.getIntegerConfigValue(
astrConfigName+"/maxSize", aDefaultMaxSize);*/
logger.enter("getDefaultMaxSize", astrConfigName,aDefaultMaxSize);
int result = 300;
logger.exit("getDefaultMaxSize",result);
return result;
}
/**
* A cache entry.
*/
private class Entry {
public Object iKey = null;
public Object iValue = null;
public int inSize = 1;
public Entry iLRUEntry = null;
public Entry iMRUEntry = null;
public Timestamp iExpireTime = null;
public Entry(Object aKey, Object aValue, int anSize, Timestamp anExpireTime) {
iKey = aKey;
iValue = aValue;
inSize = anSize;
iExpireTime = anExpireTime;
}
public String toString() {
return (iValue == null ? null : iValue.toString());
}
}
private HashMap ihshCache = new HashMap();
private int inMaxSize = DEFAULT_MAX_SIZE;
private int inSize = 0;
private Entry iLRUEntry = null;
private Entry iMRUEntry = null;
/**
* Constructor for Cache, with a maximum size that defaults to <pre>{@link #DEFAULT_MAX_SIZE}</pre>.
*/
public LocalCache() {
logger.enter("LocalCache");
inMaxSize = getDefaultMaxSize(this.getClass().getName(), DEFAULT_MAX_SIZE);
logger.exit("LocalCache");
}
/**
* Constructor for Cache.
* @param anMaxSize the maximum size of the cache.
*/
public LocalCache(int anMaxSize) {
logger.enter("anMaxSize");
inMaxSize = anMaxSize;
logger.exit("anMaxSize");
}
/**
* Adds an entry to the cache as the MRU (most recently used) entry.
* @param aEntry the entry.
*/
private void addMRUEntry(Entry aEntry) {
logger.enter("addMRUEntry", aEntry);
if(iMRUEntry == null) {
iMRUEntry = aEntry;
iLRUEntry = aEntry;
}
else {
iMRUEntry.iMRUEntry = aEntry;
aEntry.iLRUEntry = iMRUEntry;
iMRUEntry = aEntry;
}
inSize += aEntry.inSize;
logger.exit("addMRUEntry");
}
/**
* Clears the cache.
*/
public void clear() {
logger.enter("clear");
synchronized(this) {
ihshCache.clear();
inSize = 0;
iLRUEntry = null;
iMRUEntry = null;
}
logger.exit("clear");
}
/**
* Removes the value which the key is mapped to.
* @param aKey the key.
* @return the removed value.
* @exception Exception
*/
public Object remove(Object aKey) throws Exception {
logger.enter("remove", aKey);
synchronized(this) {
Entry entry = (Entry)ihshCache.get(aKey);
if(entry == null) { return null; }
ihshCache.remove(entry.iKey);
removeEntry(entry);
logger.exit("remove",entry.iValue);
return entry.iValue;
}
}
/**
* Returns the value which the key is mapped to.
* @param aKey the key.
* @return the value.
* @exception Exception
*/
public Object get(Object aKey) throws Exception {
logger.enter("get",aKey);
Entry entry = null;
synchronized(this) {
entry = (Entry)ihshCache.get(aKey);
if(entry != null) {
if(entry != iMRUEntry) {
removeEntry(entry);
addMRUEntry(entry);
}
if (entry.iExpireTime.after(new Timestamp(System.currentTimeMillis()))){
logger.exit("get",entry.iValue);
return entry.iValue;
}else{
logger.info("Cache expired, value="+entry.iValue);
}
}
}
Object value = miss(aKey);
int nSize = getSize(value);
entry = new Entry(aKey, value, nSize, setExpirationTime());
synchronized(this) {
if(nSize <= inMaxSize) {
Entry oldEntry = (Entry)ihshCache.put(aKey, entry);
if(oldEntry != null) { removeEntry(oldEntry); }
addMRUEntry(entry);
while(inSize > inMaxSize) {
ihshCache.remove(iLRUEntry.iKey);
removeEntry(iLRUEntry);
}
}
}
logger.exit("get",value);
return value;
}
//Set the expiration time of the price list cache. Now we set it to 2:00AM next day.
protected Timestamp setExpirationTime(){
Date date=new Date();
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.add(calendar.DATE,1);
calendar.set(Calendar.HOUR_OF_DAY, 2);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
date=calendar.getTime();
return new Timestamp(date.getTime());
}
/**
* Returns the size of a value.
* This method is called by {@link #get(Object)} and should be overridden by the
* implementing class.
* @param aValue the value.
* @return 1 for all values.
*/
protected int getSize(Object aValue) {
logger.enter("getSize", aValue);
logger.exit("getSize", 1);
return 1;
}
/**
* Returns the value a key is mapped to.
* This method is called by {@link #get(Object)} when the mapping is not found in
* the cache and should be overridden by the implementing class.
* @param aKey the key.
* @return the value.
* @exception Exception
*/
protected abstract Object miss(Object aKey) throws Exception;
/**
* Removes an entry from the cache.
* @param aEntry the entry.
*/
private void removeEntry(Entry aEntry) {
logger.enter("removeEntry", aEntry);
if(aEntry == iMRUEntry) { iMRUEntry = aEntry.iLRUEntry; }
else { aEntry.iMRUEntry.iLRUEntry = aEntry.iLRUEntry; }
if(aEntry == iLRUEntry) { iLRUEntry = aEntry.iMRUEntry; }
else { aEntry.iLRUEntry.iMRUEntry = aEntry.iMRUEntry; }
aEntry.iMRUEntry = null;
aEntry.iLRUEntry = null;
inSize -= aEntry.inSize;
logger.exit("removeEntry");
}
/**
* Returns the maximum size of the cache.
* @return the maximum size of the cache.
*/
public int getMaxSize() {
logger.enter("getMaxSize");
logger.exit("getMaxSize",inMaxSize);
return inMaxSize;
}
/**
* Sets the maximum size of the cache.
* @param anMaxSize the maximum size of the cache.
*/
public void setMaxSize(int anMaxSize) {
logger.enter("setMaxSize", anMaxSize);
synchronized(this) {
inMaxSize = anMaxSize;
while(inSize > inMaxSize) {
ihshCache.remove(iLRUEntry.iKey);
removeEntry(iLRUEntry);
}
}
logger.exit("setMaxSize");
}
/**
* Sets the maximum size of the cache.
* @param anMaxSize the maximum size of the cache.
* @deprecated renamed to {@link #setMaxSize(int)}.
*/
public void setSize(int anMaxSize) {
logger.enter("setSize",anMaxSize);
setMaxSize(anMaxSize);
logger.exit("setSize");
}
/**
* Returns the string representation of the cache for diagnostic purposes.
* @return the string representation of the cache.
*/
public String toString() {
logger.enter("toString");
logger.exit("toString",ihshCache.toString());
return ihshCache.toString();
}
}
//PricingListCache.java
package com.dbecom.platform.pricing.server.persistance;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.dbecom.platform.pricing.client.exception.BadInputParameterException;
import com.dbecom.platform.pricing.client.exception.PricingErrors;
import com.dbecom.platform.pricing.client.model.PricingList;
@Component
public class PricingListCache extends LocalCache {
private static Logger logger = Logger.getLogger(PricingListCache.class);
@Autowired
PricingListDao pricelistDao;
public static class Key{
private String pricelistId = null;
private String orgId = null;
public Key(String orgId, String pricinglistId){
this.orgId = orgId;
this.pricelistId = pricinglistId;
}
public String getPricelistId(){
return pricelistId;
}
public String getOrgId(){
return orgId;
}
private static boolean equals(Object aObj1, Object aObj2) {
return (aObj1 == null ? aObj2 == null : aObj2 != null && aObj1.equals(aObj2));
}
public boolean equals(Object aObj) {
if(!(aObj instanceof Key)){
return false;
}
Key key = (Key)aObj;
return (equals(key.getPricelistId(), pricelistId)) && (equals(key.getOrgId(), orgId));
}
private static final int hashCodeFor(Object obj, String defaultstr) {
return obj==null?defaultstr.hashCode():obj.hashCode();
}
/**
* @return int
* @see Object#hashCode()
*/
public int hashCode() {
int n = 0;
if (orgId != null && !orgId.isEmpty()){
n ^= orgId.hashCode();
}else{
n ^= hashCodeFor(orgId, "nullo");
}
if (pricelistId != null && !pricelistId.isEmpty()){
n ^= pricelistId.hashCode();
}else{
n ^= hashCodeFor(pricelistId, "nullp");
}
return n;
}
}
public PricingListCache(){
super();
}
/**
* Constructs a price list cache with the specified cache size.
* @param anCacheSize the cache size
*/
public PricingListCache(int anCacheSize) {
super(anCacheSize);
}
public BigInteger getPricelistKey(Key aKey) throws Exception{
BigInteger rtPricelistKey = null;
Map<BigInteger, List> entry = (Map<BigInteger, List>)get(aKey);
if (entry != null){
Iterator itr = entry.keySet().iterator();
if (itr.hasNext()){
rtPricelistKey = (BigInteger)itr.next();
}
}
return rtPricelistKey;
}
@Override
protected Object miss(Object aKey) throws Exception {
Key key = (Key)aKey;
String orgId = key.getOrgId();
String plId = key.getPricelistId();
Map<BigInteger, List> value = new HashMap<BigInteger, List>();
if ((orgId==null || orgId.isEmpty()) || (plId==null || plId.isEmpty())) { return null; }
PricingList pricelist = pricelistDao.findByOrgAndId(orgId, plId);
List list = new ArrayList();
if (pricelist != null){
list.add(pricelist.getDescription());
list.add(pricelist.getType());
list.add(pricelist.getPrecedence());
}else{
throw new BadInputParameterException(PricingErrors.PRICE_LIST_NOT_EXIST);
}
logger.info("Not hit cache entry. Need to retrieve from DB and then populate into cache. PricelistKey = "+pricelist.getKey());
value.put(pricelist.getKey(), list);
return value;
}
}
//深度遍历形成所有目录
//the v1 ======+descNameMap
public void populateCatgroupHierachy(){
List<Catgroup> catgrpDOList = catgrpDao.findAllCatalogGroups();
//System.out.println("how many categories found?"+catgrpDOList.size());
Iterator<Catgroup> iter = catgrpDOList.iterator();
while(iter.hasNext()){
//Set<ParentCatgroup> parentCatgroups = new HashSet<ParentCatgroup>();
//List<ParentCatgroup> parentCatgroups = new ArrayList<ParentCatgroup>();
Catgroup catgrpDO = iter.next();
if(catgrpDO.getCatgroupRule() != null){
//String str[] = catgrpDO.getCatgroupRule().split(regex);
ObjectMapper om = new ObjectMapper();
CategoryRule categoryRule;
try {
categoryRule = om.readValue(catgrpDO.getCatgroupRule(), CategoryRule.class);
for(String categoryId : categoryRule.getCategory()){
for(String brandId : categoryRule.getBrand()){
for(String tagId : categoryRule.getTag()){
CatCatgrpKey catCatgrpKey = new CatCatgrpKey(categoryId, brandId, tagId);
if(salesCategoryMap.containsKey(catCatgrpKey)){
salesCategoryMap.get(catCatgrpKey).add(catgrpDO.getCatgroupKey());
}else{
List<String> strs = new ArrayList<String>();
strs.add(catgrpDO.getCatgroupKey());
salesCategoryMap.put(catCatgrpKey, strs);
}
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
parentCategoryRecurse(catgrpDO);
}
}
private List<ParentCatgroup> parentCategoryRecurse(Catgroup catgrpDO){
if(categoryMap.containsKey(catgrpDO.getCatgroupKey())){
return categoryMap.get(catgrpDO.getCatgroupKey());
}
List<Catgrprel> catgrprelDOList = catgrprelDao.findAllParentCategoriesForCategory(catgrpDO.getCatgroupKey());
if(catgrprelDOList == null || catgrprelDOList.size() == 0){
if(!categoryMap.containsKey(catgrpDO.getCatgroupKey())){
List<ParentCatgroup> parentCatgroups = new ArrayList<ParentCatgroup>();
String name = "";
//get name from Catgrpdesc
List<Catgrpdesc> descs = catgrpDO.getCatgrpdescs();
ParentCatgroup parentCatgroup = new ParentCatgroup();
Iterator<Catgrpdesc> iter1 = descs.iterator();
while(iter1.hasNext()){
Catgrpdesc desc = iter1.next();
if(desc.getId().getLanguageId().equals(getLangId())){
if(desc.getName() != null){
name = desc.getName();
}
break;
}
}
parentCatgroup.setCategory_name_path("/"+name);
descNameMap.put(catgrpDO.getCatgroupKey(), name);
parentCatgroup.setCategory_full_path("/"+catgrpDO.getCatgroupId());
parentCatgroup.setCategory_key_path("/"+catgrpDO.getCatgroupKey());
parentCatgroup.setCategory_id(catgrpDO.getCatgroupId());
parentCatgroup.setCategory_level(1);
parentCatgroup.setDepth(1);
Catalog catalog = catalogDao.findCatalogByKey(catgrpDO.getCatalog_key());
parentCatgroup.setCatalog_id(catalog.getCatalogId());
parentCatgroup.setCatalog_type(catalog.getCatalogtype());
String facetable_category_info = parentCatgroup.getDepth() + "|" + parentCatgroup.getCategory_level() + "|" + parentCatgroup.getCategory_id() + "|" + name;
parentCatgroup.setFacetable_category_info(facetable_category_info);
parentCatgroups.add(parentCatgroup);
Set<String> categorySet = new HashSet<String>();
categoryMap.put(catgrpDO.getCatgroupKey(), parentCatgroups);
categoryRelMap.put(catgrpDO.getCatgroupKey(), categorySet);
return parentCatgroups;
}else{
return categoryMap.get(catgrpDO.getCatgroupKey());
}
}
List<ParentCatgroup> parentCatgroupsNew = new ArrayList<ParentCatgroup>();
Set<String> categorySet = new HashSet<String>();
String name = "";
//get name from Catgrpdesc
List<Catgrpdesc> descs = catgrpDO.getCatgrpdescs();
Iterator<Catgrpdesc> iter1 = descs.iterator();
while(iter1.hasNext()){
Catgrpdesc desc = iter1.next();
if(desc.getId().getLanguageId().equals(getLangId())){
if(desc.getName() != null){
name = desc.getName();
}
break;
}
}
descNameMap.put(catgrpDO.getCatgroupKey(), name);
for(Catgrprel catgrprel : catgrprelDOList){
Catgroup catgrpParentDO = catgrprel.getCatgroupParent();
categorySet.add(catgrpParentDO.getCatgroupKey());
List<ParentCatgroup> parentCatgroups = parentCategoryRecurse(catgrpParentDO);
for(ParentCatgroup parentCatgroup : parentCatgroups){
ParentCatgroup parentCatgroupClone = parentCatgroup.clone();
parentCatgroupClone.setCategory_full_path(parentCatgroup.getCategory_full_path()+"/"+catgrpDO.getCatgroupId());
parentCatgroupClone.setCategory_key_path(parentCatgroup.getCategory_key_path()+"/"+catgrpDO.getCatgroupKey());
parentCatgroupClone.setCategory_level(parentCatgroup.getCategory_level()+1);
parentCatgroupClone.setDepth(1);
parentCatgroupClone.setCategory_name_path(parentCatgroup.getCategory_name_path() + "/"+name);
parentCatgroupClone.setCategory_id(catgrpDO.getCatgroupId());
String facetable_category_info = 1 + "|" + parentCatgroupClone.getCategory_level() + "|" + catgrpDO.getCatgroupId() + "|" + name;
parentCatgroupClone.setFacetable_category_info(facetable_category_info);
parentCatgroupsNew.add(parentCatgroupClone);
}
}
categoryMap.put(catgrpDO.getCatgroupKey(), parentCatgroupsNew);
categoryRelMap.put(catgrpDO.getCatgroupKey(), categorySet);
return parentCatgroupsNew;
}
//the v2 ====== generate decomposeParentCatgroup in map
/*public void populateCatgroupHierachy(){
List<Catgroup> catgrpDOList = catgrpDao.findAllCatalogGroups();
//System.out.println("how many categories found?"+catgrpDOList.size());
Iterator<Catgroup> iter = catgrpDOList.iterator();
while(iter.hasNext()){
//Set<ParentCatgroup> parentCatgroups = new HashSet<ParentCatgroup>();
//List<ParentCatgroup> parentCatgroups = new ArrayList<ParentCatgroup>();
Catgroup catgrpDO = iter.next();
if(catgrpDO.getCatgroupRule() != null){
//String str[] = catgrpDO.getCatgroupRule().split(regex);
ObjectMapper om = new ObjectMapper();
CategoryRule categoryRule;
try {
categoryRule = om.readValue(catgrpDO.getCatgroupRule(), CategoryRule.class);
for(String categoryId : categoryRule.getCategory()){
for(String brandId : categoryRule.getBrand()){
for(String tagId : categoryRule.getTag()){
CatCatgrpKey catCatgrpKey = new CatCatgrpKey(categoryId, brandId, tagId);
if(salesCategoryMap.containsKey(catCatgrpKey)){
salesCategoryMap.get(catCatgrpKey).add(catgrpDO.getCatgroupKey());
}else{
List<String> strs = new ArrayList<String>();
strs.add(catgrpDO.getCatgroupKey());
salesCategoryMap.put(catCatgrpKey, strs);
}
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Set<ParentCatgroup> decomposeSet = new HashSet<ParentCatgroup>();
parentCategoryRecurse(catgrpDO, decomposeSet, 1, 0);
}
}
private List<ParentCatgroup> parentCategoryRecurse(Catgroup catgrpDO, Set<ParentCatgroup> decomposeSet, int depth, int dis){
if(categoryMap.containsKey(catgrpDO.getCatgroupKey())){
if(!decomposeCategoryMap.containsKey(catgrpDO.getCatgroupKey()+depth)){
Set<ParentCatgroup> decomposeSetClone = decomposeCategoryMap.get(catgrpDO.getCatgroupKey()+1);
for(ParentCatgroup parentCatgroup : decomposeSetClone){
ParentCatgroup parentCatgroupClone = parentCatgroup.clone();
parentCatgroupClone.setDepth(parentCatgroupClone.getDepth()+dis);
String facetable_category_info = parentCatgroupClone.getDepth() + "|" + parentCatgroup.getCategory_level() + "|" + parentCatgroup.getCategory_id() + "|" + descNameMap.get(catgrpDO.getCatgroupKey());
parentCatgroupClone.setFacetable_category_info(facetable_category_info);
decomposeSet.add(parentCatgroupClone);
}
decomposeCategoryMap.put(catgrpDO.getCatgroupKey()+depth, decomposeSet);
}else{
decomposeSet = decomposeCategoryMap.get(catgrpDO.getCatgroupKey()+depth);
}
return categoryMap.get(catgrpDO.getCatgroupKey());
}
List<Catgrprel> catgrprelDOList = catgrprelDao.findAllParentCategoriesForCategory(catgrpDO.getCatgroupKey());
if(catgrprelDOList == null || catgrprelDOList.size() == 0){
if(!categoryMap.containsKey(catgrpDO.getCatgroupKey())){
List<ParentCatgroup> parentCatgroups = new ArrayList<ParentCatgroup>();
String name = "";
//get name from Catgrpdesc
List<Catgrpdesc> descs = catgrpDO.getCatgrpdescs();
ParentCatgroup parentCatgroup = new ParentCatgroup();
Iterator<Catgrpdesc> iter1 = descs.iterator();
while(iter1.hasNext()){
Catgrpdesc desc = iter1.next();
if(desc.getId().getLanguageId().equals(getLangId())){
if(desc.getName() != null){
name = desc.getName();
}
break;
}
}
parentCatgroup.setCategory_name_path("/"+name);
descNameMap.put(catgrpDO.getCatgroupKey(), name);
//System.out.println("which is the current category is "+catgrpKey);
parentCatgroup.setCategory_full_path("/"+catgrpDO.getCatgroupId());
parentCatgroup.setCategory_key_path("/"+catgrpDO.getCatgroupKey());
parentCatgroup.setCategory_id(catgrpDO.getCatgroupId());
parentCatgroup.setCategory_level(1);
Catalog catalog = catalogDao.findCatalogByKey(catgrpDO.getCatalog_key());
parentCatgroup.setCatalog_id(catalog.getCatalogId());
parentCatgroup.setCatalog_type(catalog.getCatalogtype());
parentCatgroup.setDepth(1);
String facetable_category_info = parentCatgroup.getDepth() + "|" + parentCatgroup.getCategory_level() + "|" + parentCatgroup.getCategory_id() + "|" + name;
parentCatgroup.setFacetable_category_info(facetable_category_info);
parentCatgroups.add(parentCatgroup);
ParentCatgroup decomposeParentCatgroup = parentCatgroup.clone();
decomposeParentCatgroup.setDepth(depth);
Set<ParentCatgroup> decomposeSetClone = new HashSet<ParentCatgroup>();
Set<ParentCatgroup> decomposeSetClone2 = new HashSet<ParentCatgroup>();
Set<String> categorySet = new HashSet<String>();
decomposeSet.add(decomposeParentCatgroup);
//ParentCatgroup decomposeParentCatgroupClone = parentCatgroup.clone();
//decomposeParentCatgroupClone.setDepth(1);
decomposeSetClone.add(decomposeParentCatgroup);//in map
decomposeSetClone2.add(parentCatgroup);
categoryMap.put(catgrpDO.getCatgroupKey(), parentCatgroups);
categoryRelMap.put(catgrpDO.getCatgroupKey(), categorySet);
decomposeCategoryMap.put(catgrpDO.getCatgroupKey()+depth, decomposeSetClone);
decomposeCategoryMap.put(catgrpDO.getCatgroupKey()+1, decomposeSetClone2);
return parentCatgroups;
}else{
return categoryMap.get(catgrpDO.getCatgroupKey());
}
}
List<ParentCatgroup> parentCatgroupsNew = new ArrayList<ParentCatgroup>();
Set<ParentCatgroup> decomposeSetClone2 = new HashSet<ParentCatgroup>();
Set<String> categorySet = new HashSet<String>();
//Set<ParentCatgroup> mergeChild = new HashSet<ParentCatgroup>();
for(Catgrprel catgrprel : catgrprelDOList){
Catgroup catgrpParentDO = catgrprel.getCatgroupParent();
categorySet.add(catgrpParentDO.getCatgroupKey());
Set<ParentCatgroup> parent = new HashSet<ParentCatgroup>();
List<ParentCatgroup> parentCatgroups = parentCategoryRecurse(catgrpParentDO, parent, depth+1, dis+1);
Set<ParentCatgroup> decomposeSetClone = new HashSet<ParentCatgroup>();
if(!decomposeCategoryMap.containsKey(catgrpParentDO.getCatgroupKey()+2)){
for(ParentCatgroup parentCatgroup : decomposeCategoryMap.get(catgrpParentDO.getCatgroupKey()+1)){
ParentCatgroup parentCatgroupClone = parentCatgroup.clone();
parentCatgroupClone.setDepth(parentCatgroupClone.getDepth()+1);
decomposeSetClone.add(parentCatgroupClone);
}
decomposeCategoryMap.put(catgrpParentDO.getCatgroupKey()+2, decomposeSetClone);
}
decomposeSetClone2.addAll(decomposeCategoryMap.get(catgrpParentDO.getCatgroupKey()+2));
for(ParentCatgroup parentCatgroup : parentCatgroups){
ParentCatgroup parentCatgroupClone = parentCatgroup.clone();
parentCatgroupClone.setCategory_full_path(parentCatgroup.getCategory_full_path()+"/"+catgrpDO.getCatgroupId());
parentCatgroupClone.setCategory_key_path(parentCatgroup.getCategory_key_path()+"/"+catgrpDO.getCatgroupKey());
parentCatgroupClone.setCategory_level(parentCatgroup.getCategory_level()+1);
String name = "";
//get name from Catgrpdesc
List<Catgrpdesc> descs = catgrpDO.getCatgrpdescs();
Iterator<Catgrpdesc> iter1 = descs.iterator();
while(iter1.hasNext()){
Catgrpdesc desc = iter1.next();
if(desc.getId().getLanguageId().equals(getLangId())){
if(desc.getName() != null){
name = desc.getName();
}
break;
}
}
descNameMap.put(catgrpDO.getCatgroupKey(), name);
parentCatgroupClone.setCategory_name_path(parentCatgroup.getCategory_name_path()+"/"+name);
String facetable_category_info = parentCatgroup.getDepth() + "|" + parentCatgroupClone.getCategory_level() + "|" + catgrpDO.getCatgroupId() + "|" + name;
parentCatgroupClone.setFacetable_category_info(facetable_category_info);
parentCatgroupClone.setCategory_id(catgrpDO.getCatgroupId());
if(depth != 1){
ParentCatgroup decomposeParentCatgroup = parentCatgroupClone.clone();
decomposeParentCatgroup.setDepth(depth);
String facetable = depth + "|" + parentCatgroup.getCategory_level() + "|" + parentCatgroup.getCategory_id() + "|" + name;
decomposeParentCatgroup.setFacetable_category_info(facetable);
decomposeSet.add(decomposeParentCatgroup);
}else{
decomposeSet.add(parentCatgroupClone);
}
//parentCatgroupClone.setFacetable_category_info(facetable_category_info);
parentCatgroupsNew.add(parentCatgroupClone);
}
decomposeSet.addAll(parent);
}
decomposeSetClone2.addAll(parentCatgroupsNew);
categoryMap.put(catgrpDO.getCatgroupKey(), parentCatgroupsNew);
categoryRelMap.put(catgrpDO.getCatgroupKey(), categorySet);
if(depth != 1){
decomposeCategoryMap.put(catgrpDO.getCatgroupKey()+depth, decomposeSet);
}
decomposeCategoryMap.put(catgrpDO.getCatgroupKey()+1, decomposeSetClone2);
return parentCatgroupsNew;
}*/