Subversion Repositories SmartDukaan

Rev

Rev 3438 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3438 Rev 5084
Line 4... Line 4...
4
import in.shop2020.metamodel.core.Entity;
4
import in.shop2020.metamodel.core.Entity;
5
import in.shop2020.metamodel.core.Feature;
5
import in.shop2020.metamodel.core.Feature;
6
import in.shop2020.metamodel.core.PrimitiveDataObject;
6
import in.shop2020.metamodel.core.PrimitiveDataObject;
7
import in.shop2020.metamodel.core.Slide;
7
import in.shop2020.metamodel.core.Slide;
8
 
8
 
-
 
9
import java.io.File;
9
import java.util.ArrayList;
10
import java.util.ArrayList;
10
import java.util.HashMap;
11
import java.util.HashMap;
11
import java.util.List;
12
import java.util.List;
12
import java.util.Map;
13
import java.util.Map;
13
 
14
 
-
 
15
import org.apache.commons.io.FileUtils;
14
import com.google.gson.Gson;
16
import com.google.gson.Gson;
-
 
17
import com.google.gson.reflect.TypeToken;
15
 
18
 
16
public class SynonymExporter {
19
public class SynonymExporter {
17
	
20
	
-
 
21
	private static String synonymFilename = Utils.EXPORT_JAVASCRIPT_CONTENT_PATH + "synonyms.json";
18
	List<Entity> entities;
22
	private Map<Long, Map<String,List<String>>> synonyms = new HashMap<Long, Map<String,List<String>>>();
19
	
23
	
20
	public SynonymExporter(List<Entity> entities){
24
	public SynonymExporter(){
-
 
25
		try {
-
 
26
			Gson g = new Gson();
-
 
27
			java.lang.reflect.Type typeOfT = new TypeToken<Map<Long, Map<String, List<String>>>>(){}.getType();
-
 
28
			synonyms = g.fromJson(FileUtils.readFileToString(new File(synonymFilename)), typeOfT);
21
		this.entities = entities;
29
			if(synonyms == null){
-
 
30
				synonyms = new HashMap<Long, Map<String,List<String>>>();
-
 
31
			}
-
 
32
		} catch (Exception e) {
-
 
33
			e.printStackTrace();
-
 
34
		}
22
	}
35
	}
23
 
36
 
24
	public void storeSynonyms(){
37
	public void storeSynonyms(List<Entity> entities){
25
		Map<Long, Map<String,List<String>>> synonyms = new HashMap<Long, Map<String,List<String>>>();
-
 
26
		for(Entity entity: entities)	{
38
		for(Entity entity: entities)	{
27
			Map<String,List<String>> synonymMap = null;
39
			Map<String,List<String>> synonymMap = null;
28
			Slide slide = entity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID);
40
			Slide slide = entity.getSlide(Utils.SUMMARY_SLIDE_DEFINITION_ID);
29
			List<Feature> features = slide.getFeatures();
41
			List<Feature> features = slide.getFeatures();
30
			for(Feature feature: features){
42
			for(Feature feature: features){
Line 54... Line 66...
54
						}
66
						}
55
						synonymMap.put("MODEL_NUMBER", modelNameSynonyms );
67
						synonymMap.put("MODEL_NUMBER", modelNameSynonyms );
56
					}
68
					}
57
				}
69
				}
58
			}
70
			}
-
 
71
			
59
			if(synonymMap != null){
72
			if(synonymMap == null){
60
				synonyms.put(entity.getID(), synonymMap);
73
				synonymMap = new HashMap<String,List<String>>();				
61
			}
74
			}
-
 
75
			
-
 
76
			List<String> brand = new ArrayList<String>();
-
 
77
			brand.add(entity.getBrand());
-
 
78
			List<String> modelName = new ArrayList<String>();
-
 
79
			modelName.add(entity.getModelName());
-
 
80
			List<String> modelNumber = new ArrayList<String>();
-
 
81
			modelNumber.add(entity.getModelNumber());
-
 
82
			synonymMap.put("ORIGINAL_BRAND", brand );
-
 
83
			synonymMap.put("ORIGINAL_MODEL_NAME", modelName );
-
 
84
			synonymMap.put("ORIGINAL_MODEL_NUMBER", modelNumber );
-
 
85
			synonyms.put(entity.getID(), synonymMap);
62
		}
86
		}
63
		
87
		
64
		String synonymFilename = Utils.EXPORT_JAVASCRIPT_CONTENT_PATH + "synonyms.json";
-
 
65
		Gson gson = new Gson();
88
		Gson gson = new Gson();
66
		try {
89
		try {
67
			DBUtils.store(gson.toJson(synonyms), synonymFilename);
90
			DBUtils.store(gson.toJson(synonyms), synonymFilename);
68
		} catch (Exception e) {
91
		} catch (Exception e) {
69
			e.printStackTrace();
92
			e.printStackTrace();
70
		}
93
		}
71
	}
94
	}
-
 
95
	
-
 
96
	public Map<Long, Map<String,List<String>>> getSynonyms(){
-
 
97
		return synonyms;
-
 
98
	}
-
 
99
	
-
 
100
	public static void main(String[] args) throws Exception {
-
 
101
		SynonymExporter sx = new SynonymExporter();
-
 
102
		System.out.println(sx.getSynonyms());
-
 
103
    }
72
}
104
}
73
105