Rev 3438 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.util;import in.shop2020.metamodel.core.Bullet;import in.shop2020.metamodel.core.Entity;import in.shop2020.metamodel.core.Feature;import in.shop2020.metamodel.core.PrimitiveDataObject;import in.shop2020.metamodel.core.Slide;import java.io.File;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import org.apache.commons.io.FileUtils;import com.google.gson.Gson;import com.google.gson.reflect.TypeToken;public class SynonymExporter {private static String synonymFilename = Utils.EXPORT_JAVASCRIPT_CONTENT_PATH + "synonyms.json";private Map<Long, Map<String,List<String>>> synonyms = new HashMap<Long, Map<String,List<String>>>();public SynonymExporter(){try {Gson g = new Gson();java.lang.reflect.Type typeOfT = new TypeToken<Map<Long, Map<String, List<String>>>>(){}.getType();synonyms = g.fromJson(FileUtils.readFileToString(new File(synonymFilename)), typeOfT);if(synonyms == null){synonyms = new HashMap<Long, Map<String,List<String>>>();}} catch (Exception e) {e.printStackTrace();}}public void storeSynonyms(List<Entity> entities){for(Entity entity: entities) {Map<String,List<String>> synonymMap = null;Slide slide = entity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID);List<Feature> features = slide.getFeatures();for(Feature feature: features){if(feature.getFeatureDefinitionID() == 120156){List<Bullet> bullets = feature.getBullets();if(bullets != null){List<String> modelNameSynonyms= new ArrayList<String>();for(Bullet bullet: bullets){PrimitiveDataObject pdo = (PrimitiveDataObject)bullet.getDataObject();modelNameSynonyms.add(pdo.getValue());}if(synonymMap == null){synonymMap = new HashMap<String,List<String>>();}synonymMap.put("MODEL_NAME", modelNameSynonyms );}}else if(feature.getFeatureDefinitionID() == 120157){List<Bullet> bullets = feature.getBullets();if(bullets != null){List<String> modelNameSynonyms= new ArrayList<String>();for(Bullet bullet: bullets){PrimitiveDataObject pdo = (PrimitiveDataObject)bullet.getDataObject();modelNameSynonyms.add(pdo.getValue());}if(synonymMap == null){synonymMap = new HashMap<String,List<String>>();}synonymMap.put("MODEL_NUMBER", modelNameSynonyms );}}}if(synonymMap == null){synonymMap = new HashMap<String,List<String>>();}List<String> brand = new ArrayList<String>();brand.add(entity.getBrand());List<String> modelName = new ArrayList<String>();modelName.add(entity.getModelName());List<String> modelNumber = new ArrayList<String>();modelNumber.add(entity.getModelNumber());synonymMap.put("ORIGINAL_BRAND", brand );synonymMap.put("ORIGINAL_MODEL_NAME", modelName );synonymMap.put("ORIGINAL_MODEL_NUMBER", modelNumber );synonyms.put(entity.getID(), synonymMap);}Gson gson = new Gson();try {DBUtils.store(gson.toJson(synonyms), synonymFilename);} catch (Exception e) {e.printStackTrace();}}public Map<Long, Map<String,List<String>>> getSynonyms(){return synonyms;}public static void main(String[] args) throws Exception {SynonymExporter sx = new SynonymExporter();System.out.println(sx.getSynonyms());}}