| 457 |
rajveer |
1 |
package in.shop2020.util;
|
|
|
2 |
|
| 479 |
rajveer |
3 |
import java.io.BufferedOutputStream;
|
|
|
4 |
import java.io.BufferedWriter;
|
|
|
5 |
import java.io.File;
|
|
|
6 |
import java.io.FileWriter;
|
|
|
7 |
import java.util.ArrayList;
|
|
|
8 |
import java.util.HashMap;
|
|
|
9 |
import java.util.List;
|
|
|
10 |
import java.util.Map;
|
|
|
11 |
import java.util.StringTokenizer;
|
|
|
12 |
|
|
|
13 |
import in.shop2020.metamodel.core.Entity;
|
|
|
14 |
import in.shop2020.metamodel.core.FreeformContent;
|
|
|
15 |
import in.shop2020.metamodel.core.Media;
|
|
|
16 |
import in.shop2020.metamodel.core.Slide;
|
| 580 |
rajveer |
17 |
import in.shop2020.metamodel.definitions.BulletDefinition;
|
| 457 |
rajveer |
18 |
import in.shop2020.metamodel.definitions.Catalog;
|
| 580 |
rajveer |
19 |
import in.shop2020.metamodel.definitions.Category;
|
|
|
20 |
import in.shop2020.metamodel.definitions.CategorySlideDefinition;
|
| 457 |
rajveer |
21 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
|
|
22 |
import in.shop2020.metamodel.definitions.EntityContainer;
|
| 580 |
rajveer |
23 |
import in.shop2020.metamodel.definitions.FeatureDefinition;
|
|
|
24 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
|
|
25 |
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
|
| 479 |
rajveer |
26 |
import in.shop2020.metamodel.util.CreationUtils;
|
|
|
27 |
//import in.shop2020.metamodel.util.OldCreationUtils;
|
| 457 |
rajveer |
28 |
|
| 580 |
rajveer |
29 |
|
| 457 |
rajveer |
30 |
/*
|
|
|
31 |
* @author rajveer
|
|
|
32 |
*
|
|
|
33 |
*
|
|
|
34 |
*/
|
|
|
35 |
|
|
|
36 |
public class ContentMigrator {
|
|
|
37 |
private String sourceDbPath;
|
|
|
38 |
private String destinationDbPath;
|
|
|
39 |
|
|
|
40 |
public static void main(String[] args) throws Exception {
|
|
|
41 |
String usage = "Usage: ContentMigrator {source db path}{destination db path}";
|
|
|
42 |
|
|
|
43 |
String sourceDbPath = null, destinationDbPath = null;
|
|
|
44 |
if(args.length < 2) {
|
|
|
45 |
System.out.println(usage);
|
|
|
46 |
System.exit(-1);
|
|
|
47 |
}else{
|
|
|
48 |
sourceDbPath = args[0];
|
|
|
49 |
destinationDbPath = args[1];
|
|
|
50 |
}
|
|
|
51 |
|
| 580 |
rajveer |
52 |
|
|
|
53 |
//ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath, destinationDbPath);
|
|
|
54 |
//boolean result = contentmigrator.migrate();
|
|
|
55 |
//System.out.println("Content migration status: "+ result);
|
| 457 |
rajveer |
56 |
}
|
|
|
57 |
|
|
|
58 |
public ContentMigrator(String sourceDbPath, String destinationDbPath) {
|
|
|
59 |
this.sourceDbPath = sourceDbPath;
|
|
|
60 |
this.destinationDbPath = destinationDbPath;
|
|
|
61 |
}
|
| 473 |
rajveer |
62 |
/**
|
|
|
63 |
* this function will read source definition and source entities, and will convert
|
|
|
64 |
* source entities to destination entities according to destination definitions.
|
|
|
65 |
*
|
|
|
66 |
* @return boolean
|
| 479 |
rajveer |
67 |
* @throws Exception
|
| 473 |
rajveer |
68 |
*/
|
| 580 |
rajveer |
69 |
|
| 479 |
rajveer |
70 |
public boolean migrate() throws Exception{
|
| 580 |
rajveer |
71 |
/*
|
| 473 |
rajveer |
72 |
DefinitionsContainer sourceDefs = new DefinitionsContainer(sourceDbPath);
|
|
|
73 |
DefinitionsContainer destinationDefs = new DefinitionsContainer(destinationDbPath);
|
|
|
74 |
EntityContainer sourceEnts = new EntityContainer(sourceDbPath);
|
|
|
75 |
EntityContainer destinationEnts = new EntityContainer(destinationDbPath);
|
|
|
76 |
|
| 479 |
rajveer |
77 |
Map<Long, Entity> entities = sourceEnts.getEntities();
|
| 473 |
rajveer |
78 |
|
| 479 |
rajveer |
79 |
File f = new File("/home/rajveer/Desktop/info.txt");
|
|
|
80 |
FileWriter fstream = new FileWriter(f);
|
|
|
81 |
BufferedWriter out = new BufferedWriter(fstream);
|
|
|
82 |
StringBuilder sb = new StringBuilder();
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
for(Entity entity: entities.values()){
|
|
|
86 |
List<Slide> slides = entity.getSlides();
|
|
|
87 |
|
|
|
88 |
//List<String> vidLabels = CreationUtils.getMediaLabels(entity.getID(),"youtube");
|
|
|
89 |
//List<String> imgLabels = CreationUtils.getMediaLabels(entity.getID(),"image");
|
|
|
90 |
|
|
|
91 |
//Map<String, Media> rawMedia = CreationUtils.getRawMedia(entity.getID());
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
// List<String> vidLabels = OldCreationUtils.getMediaLabels(entity.getID(),"youtube");
|
|
|
95 |
// List<String> imgLabels = OldCreationUtils.getMediaLabels(entity.getID(),"image");
|
|
|
96 |
|
|
|
97 |
Entity newEntity = new Entity(entity.getID(), entity.getCategoryID());
|
|
|
98 |
newEntity.setBrand(entity.getBrand());
|
|
|
99 |
newEntity.setModelName(entity.getModelName());
|
|
|
100 |
newEntity.setModelNumber(entity.getModelNumber());
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
Map<String, in.shop2020.creation.util.Media> rawMedia = OldCreationUtils.getRawMedia(entity.getID());
|
|
|
104 |
|
|
|
105 |
Map<String, Media> newrawMedia = new HashMap<String, Media>();
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
int totalRawVideos = 0;
|
|
|
109 |
int totalRawImages = 0;
|
|
|
110 |
|
|
|
111 |
if(rawMedia!=null){
|
|
|
112 |
for(String label: rawMedia.keySet()){
|
|
|
113 |
in.shop2020.creation.util.Media media = rawMedia.get(label);
|
|
|
114 |
|
|
|
115 |
label = media.getLabel();
|
|
|
116 |
String type = media.getType();
|
|
|
117 |
String location = media.getLocation();
|
|
|
118 |
|
|
|
119 |
Media newMedia = new Media(label, type, location);
|
|
|
120 |
|
|
|
121 |
newMedia.setTitle("Title");
|
|
|
122 |
if(type.equals("image")){
|
|
|
123 |
totalRawImages++;
|
|
|
124 |
newMedia.setFileName(media.getFileName());
|
|
|
125 |
newMedia.setVideoType("");
|
|
|
126 |
}else{
|
|
|
127 |
totalRawVideos++;
|
|
|
128 |
newMedia.setVideoType("withoutskin");
|
|
|
129 |
newMedia.setFileName("");
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
newrawMedia.put(label, newMedia);
|
|
|
133 |
System.out.println("old " + media.toString());
|
|
|
134 |
// System.out.println("new " + newMedia.toString());
|
|
|
135 |
// OldCreationUtils.removeMedia(entity.getID(), label);
|
| 580 |
rajveer |
136 |
// CreationUtils.addMedia(entity.getID(), newMedia);
|
| 479 |
rajveer |
137 |
}
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
int totalVideos = 0;
|
|
|
141 |
int totalImages = 0;
|
| 580 |
rajveer |
142 |
if(rawMedia==null){
|
| 479 |
rajveer |
143 |
for(Slide slide: slides ){
|
| 580 |
rajveer |
144 |
*/
|
|
|
145 |
/*
|
| 479 |
rajveer |
146 |
FreeformContent ffc = slide.getFreeformContent();
|
|
|
147 |
List<String> vidList = new ArrayList<String>();
|
|
|
148 |
List<String> imgList = new ArrayList<String>();
|
|
|
149 |
|
|
|
150 |
if(ffc!=null){
|
|
|
151 |
List<String> vidFfcLabels = ffc.getYoutubeRefs();
|
|
|
152 |
if(vidFfcLabels!=null){
|
|
|
153 |
for(String vidFfcLabel: vidFfcLabels){
|
|
|
154 |
StringTokenizer strTkn = new StringTokenizer(vidFfcLabel,"~!~");
|
|
|
155 |
String vidLabel = null;
|
|
|
156 |
if(strTkn.hasMoreTokens()){
|
|
|
157 |
vidLabel = strTkn.nextToken();
|
|
|
158 |
vidList.add(vidFfcLabel);
|
|
|
159 |
|
|
|
160 |
// ffc.removeMedia("youtube", vidFfcLabel);
|
|
|
161 |
// ffc.addMedia("youtube", vidLabel);
|
|
|
162 |
}
|
|
|
163 |
if(vidLabel == null){
|
|
|
164 |
System.out.println("Something is really breaking .. bu ha ha !!!");
|
|
|
165 |
}
|
|
|
166 |
totalVideos++;
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
List<String> imgFfcLabels = ffc.getImageRefs();
|
|
|
170 |
if(imgFfcLabels!=null){
|
|
|
171 |
for(String imgFfcLabel: imgFfcLabels){
|
|
|
172 |
StringTokenizer strTkn = new StringTokenizer(imgFfcLabel,"~!~");
|
|
|
173 |
String imgLabel = null;
|
|
|
174 |
if(strTkn.hasMoreTokens()){
|
|
|
175 |
imgLabel = strTkn.nextToken();
|
|
|
176 |
imgList.add(imgFfcLabel);
|
|
|
177 |
|
|
|
178 |
// ffc.removeMedia("image", imgFfcLabel);
|
|
|
179 |
// ffc.addMedia("image", imgLabel);
|
|
|
180 |
}
|
|
|
181 |
if(imgLabel == null){
|
|
|
182 |
System.out.println("Something is really breaking .. bu ha ha !!!");
|
|
|
183 |
}
|
|
|
184 |
totalImages++;
|
|
|
185 |
}
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
for(String vidlab : vidList){
|
|
|
189 |
ffc.removeMedia("youtube", vidlab);
|
|
|
190 |
ffc.addMedia("youtube", (new StringTokenizer(vidlab, "~!~")).nextToken());
|
|
|
191 |
}
|
|
|
192 |
for(String imglab : imgList){
|
|
|
193 |
ffc.removeMedia("image",imglab);
|
|
|
194 |
ffc.addMedia("image", (new StringTokenizer(imglab, "~!~")).nextToken());
|
|
|
195 |
}
|
|
|
196 |
slide.setFreeformContent(ffc);
|
|
|
197 |
System.out.println("Slide id is " + slide.getSlideDefinitionID() + " vid labels: " + vidFfcLabels + " img labels" + imgFfcLabels);
|
|
|
198 |
}
|
| 580 |
rajveer |
199 |
*/
|
|
|
200 |
/*
|
| 479 |
rajveer |
201 |
newEntity.addSlide(slide);
|
|
|
202 |
}
|
|
|
203 |
|
| 580 |
rajveer |
204 |
// System.out.println("entity:"+ entity.getID() + ":trv:" + totalRawVideos + ":tri:" + totalRawImages +":tv:" + totalVideos +":ti:" + totalImages);
|
|
|
205 |
// sb.append("entity:"+ entity.getID() + ":trv:" + totalRawVideos + ":tri:" + totalRawImages +":tv:" + totalVideos +":ti:" + totalImages+ ":tr:" +(totalRawVideos+totalRawImages) + ":t:" +(totalVideos+totalImages) + ":vd:" +(totalRawVideos-totalVideos) + ":id:" +(totalRawImages-totalImages) + "\n");
|
|
|
206 |
sb.append(entity.getID() + "\n");
|
|
|
207 |
|
|
|
208 |
|
| 479 |
rajveer |
209 |
destinationEnts.updateEntity(newEntity);
|
|
|
210 |
CreationUtils.storeEntity(newEntity);
|
|
|
211 |
|
|
|
212 |
Map<Long, List<Entity>> entitiesByCategory =
|
|
|
213 |
sourceEnts.getEntitiesbyCategory();
|
|
|
214 |
|
| 580 |
rajveer |
215 |
Map<Long, Entity> xentities = destinationEnts.getEntities();
|
| 479 |
rajveer |
216 |
|
|
|
217 |
CreationUtils.rewriteRepository(xentities, entitiesByCategory);
|
| 580 |
rajveer |
218 |
}
|
|
|
219 |
else{
|
|
|
220 |
sb.append(" " + entity.getID() + "\n");
|
|
|
221 |
}
|
| 479 |
rajveer |
222 |
}
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
out.write(sb.toString());
|
|
|
226 |
out.close();
|
|
|
227 |
*/
|
| 457 |
rajveer |
228 |
return true;
|
|
|
229 |
}
|
| 580 |
rajveer |
230 |
|
|
|
231 |
private boolean printDataModel() throws Exception{
|
|
|
232 |
DefinitionsContainer dfc = Catalog.getInstance().getDefinitionsContainer();
|
|
|
233 |
|
|
|
234 |
Map<Long, Category> categories = dfc.getCategories();
|
|
|
235 |
for(Category category: categories.values()){
|
|
|
236 |
if(category.getChildrenCategory() != null){
|
|
|
237 |
continue;
|
|
|
238 |
}
|
|
|
239 |
System.out.println(category.getLabel());
|
|
|
240 |
List<CategorySlideDefinition> slideDefs = dfc.getCategorySlideDefinitions(category.getID());
|
|
|
241 |
for(CategorySlideDefinition slideDef: slideDefs){
|
|
|
242 |
System.out.println(" "+ dfc.getSlideDefinition(slideDef.getSlideDefintionID()).getLabel() + " " + slideDef.getEditorialImportance());
|
|
|
243 |
//List<FeatureDefinition> featureDefs = dfc.getFeatureDefinitions(slideDef.getSlideDefintionID());
|
|
|
244 |
|
|
|
245 |
List<SlideFeatureDefinition> slideFeatureDefs = dfc.getSlideDefinition(slideDef.getSlideDefintionID()).getSlideFeatureDefinitions();
|
|
|
246 |
|
|
|
247 |
for(SlideFeatureDefinition slideFeatureDef: slideFeatureDefs){
|
|
|
248 |
FeatureDefinition featureDef = dfc.getFeatureDefinition(slideFeatureDef.getFeatureDefintionID());
|
|
|
249 |
BulletDefinition bulletDef = featureDef.getBulletDefinition();
|
|
|
250 |
System.out.println(" " + slideFeatureDef.getEditorialImportance() + " " + featureDef.getLabel() + " " + featureDef.allowsBlank() + " " + bulletDef.isLearned() + " " + bulletDef.isMultivalue());
|
|
|
251 |
List<Long> units = bulletDef.getUnitIDs();
|
|
|
252 |
if(units!=null){
|
|
|
253 |
for(Long unit: units){
|
|
|
254 |
System.out.println(" "+ dfc.getUnit(unit).getFullForm() + " "+ dfc.getUnit(unit).getShortForm());
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
if(bulletDef.getDatatypeDefinitionID()!=null){
|
|
|
258 |
System.out.println(" " + dfc.getDatatypeDefinition(bulletDef.getDatatypeDefinitionID()).getName());
|
|
|
259 |
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
/*
|
|
|
265 |
for(FeatureDefinition featureDef: featureDefs){
|
|
|
266 |
BulletDefinition bulletDef = featureDef.getBulletDefinition();
|
|
|
267 |
System.out.println(" " + featureDef.getLabel() + " " + featureDef.allowsBlank() + " " + bulletDef.isLearned() + " " + bulletDef.isMultivalue());
|
|
|
268 |
List<Long> units = bulletDef.getUnitIDs();
|
|
|
269 |
if(units!=null){
|
|
|
270 |
for(Long unit: units){
|
|
|
271 |
System.out.println(" "+ dfc.getUnit(unit).getFullForm() + " "+ dfc.getUnit(unit).getShortForm());
|
|
|
272 |
}
|
|
|
273 |
}
|
|
|
274 |
if(bulletDef.getDatatypeDefinitionID()!=null){
|
|
|
275 |
System.out.println(" " + dfc.getDatatypeDefinition(bulletDef.getDatatypeDefinitionID()).getName());
|
|
|
276 |
|
|
|
277 |
}
|
|
|
278 |
}
|
|
|
279 |
*/
|
|
|
280 |
}
|
|
|
281 |
}
|
|
|
282 |
return true;
|
|
|
283 |
}
|
| 457 |
rajveer |
284 |
}
|