Rev 29359 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.dao.util;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import com.google.gson.Gson;import com.spice.profitmandi.dao.model.ContentPojo;import com.spice.profitmandi.dao.model.ProductPojo;import com.spice.profitmandi.dao.repository.dtr.Mongo;@Componentpublic class ContentPojoPopulator {private static final Gson gs = new Gson();private static final Logger LOGGER = LogManager.getLogger(CustomTransactionConvertorUtil.class);@Autowiredprivate Mongo contentMongoClient;public ProductPojo getShortContent(long entityId) {ContentPojo cp = null;ProductPojo pp = null;try {cp = gs.fromJson(contentMongoClient.getEntityById(entityId).toString(), ContentPojo.class);} catch (Exception e) {e.printStackTrace();return null;}LOGGER.info("cp" + cp);pp = new ProductPojo();pp.setId(entityId);pp.setDefaultImgUrl(cp.getDefaultImageUrl());pp.setDescription(String.join(", ", cp.getKeySpecs().subList(0, Math.min(cp.getKeySpecs().size(), 3))));pp.setImageUrl(cp.getDefaultImageUrl());pp.setUrl(cp.getUrl());pp.setTitle(cp.getTitle());return pp;}public ProductPojo getShortContent(String brand, String modelName, String modelNumber) {String name = getProductName(brand, modelName, modelNumber);return getShortContent(name);}private String getProductName(String brand, String modelName, String modelNumber) {StringBuilder sb = new StringBuilder();sb.append(((brand != null) ? brand + " " : "")).append(((modelName != null) ? modelName + " " : "")).append(((modelNumber != null) ? modelNumber : ""));return sb.toString();}public ProductPojo getShortContent(String name) {ContentPojo cp = null;ProductPojo pp = null;try {cp = contentMongoClient.getEntityByName(name);} catch (Exception e) {e.printStackTrace();return null;}try {pp = new ProductPojo();pp.setId(cp.getId());pp.setDefaultImgUrl(cp.getDefaultImageUrl());pp.setDescription(String.join(", ", cp.getKeySpecs().subList(0, Math.min(cp.getKeySpecs().size(), 3))));pp.setTitle(pp.getTitle());pp.setImageUrl(cp.getDefaultImageUrl());pp.setUrl(cp.getUrl());pp.setTitle(cp.getTitle());pp.setThumbnailImageUrl(cp.getThumbnailImageUrl());} catch (Exception e) {e.printStackTrace();pp = null;}return pp;}}