Subversion Repositories SmartDukaan

Rev

Go to most recent revision | 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.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.Gson;

public class SynonymExporter {
        
        List<Entity> entities;
        
        public SynonymExporter(List<Entity> entities){
                this.entities = entities;
        }

        public void storeSynonyms(){
                Map<Long, Map<String,List<String>>> synonyms = new HashMap<Long, Map<String,List<String>>>();
                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){
                                synonyms.put(entity.getID(), synonymMap);
                        }
                }
                
                String synonymFilename = Utils.EXPORT_JAVASCRIPT_CONTENT_PATH + "synonyms.json";
                Gson gson = new Gson();
                try {
                        DBUtils.store(gson.toJson(synonyms), synonymFilename);
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
}