Subversion Repositories SmartDukaan

Rev

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

Rev 479 Rev 580
Line 12... Line 12...
12
 
12
 
13
import in.shop2020.metamodel.core.Entity;
13
import in.shop2020.metamodel.core.Entity;
14
import in.shop2020.metamodel.core.FreeformContent;
14
import in.shop2020.metamodel.core.FreeformContent;
15
import in.shop2020.metamodel.core.Media;
15
import in.shop2020.metamodel.core.Media;
16
import in.shop2020.metamodel.core.Slide;
16
import in.shop2020.metamodel.core.Slide;
-
 
17
import in.shop2020.metamodel.definitions.BulletDefinition;
17
import in.shop2020.metamodel.definitions.Catalog;
18
import in.shop2020.metamodel.definitions.Catalog;
-
 
19
import in.shop2020.metamodel.definitions.Category;
-
 
20
import in.shop2020.metamodel.definitions.CategorySlideDefinition;
18
import in.shop2020.metamodel.definitions.DefinitionsContainer;
21
import in.shop2020.metamodel.definitions.DefinitionsContainer;
19
import in.shop2020.metamodel.definitions.EntityContainer;
22
import in.shop2020.metamodel.definitions.EntityContainer;
-
 
23
import in.shop2020.metamodel.definitions.FeatureDefinition;
-
 
24
import in.shop2020.metamodel.definitions.SlideDefinition;
-
 
25
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
20
import in.shop2020.metamodel.util.CreationUtils;
26
import in.shop2020.metamodel.util.CreationUtils;
21
//import in.shop2020.metamodel.util.OldCreationUtils;
27
//import in.shop2020.metamodel.util.OldCreationUtils;
22
 
28
 
-
 
29
 
23
/*
30
/*
24
 * @author rajveer 
31
 * @author rajveer 
25
 * 
32
 * 
26
 *
33
 *
27
 */
34
 */
Line 40... Line 47...
40
		}else{
47
		}else{
41
			sourceDbPath = args[0];
48
			sourceDbPath = args[0];
42
			destinationDbPath = args[1];
49
			destinationDbPath = args[1];
43
		}
50
		}
44
		
51
		
-
 
52
		
45
		ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath, destinationDbPath);
53
		//ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath, destinationDbPath);
46
		boolean result = contentmigrator.migrate();
54
		//boolean result = contentmigrator.migrate();
47
		System.out.println("Content migration status:  "+ result);
55
		//System.out.println("Content migration status:  "+ result);
48
	}
56
	}
49
 
57
 
50
	public ContentMigrator(String sourceDbPath, String destinationDbPath) {
58
	public ContentMigrator(String sourceDbPath, String destinationDbPath) {
51
		this.sourceDbPath = sourceDbPath;
59
		this.sourceDbPath = sourceDbPath;
52
		this.destinationDbPath = destinationDbPath;
60
		this.destinationDbPath = destinationDbPath;
Line 56... Line 64...
56
	 * source entities to destination entities according to destination definitions.  
64
	 * source entities to destination entities according to destination definitions.  
57
	 * 
65
	 * 
58
	 * @return boolean
66
	 * @return boolean
59
	 * @throws Exception 
67
	 * @throws Exception 
60
	 */
68
	 */
-
 
69
	
61
	public boolean migrate() throws Exception{
70
	public boolean migrate() throws Exception{
62
		
-
 
63
		/*
-
 
64
		 * 
-
 
65
		 
71
	/*	 
66
		DefinitionsContainer sourceDefs = new DefinitionsContainer(sourceDbPath);
72
		DefinitionsContainer sourceDefs = new DefinitionsContainer(sourceDbPath);
67
		DefinitionsContainer destinationDefs = new DefinitionsContainer(destinationDbPath);
73
		DefinitionsContainer destinationDefs = new DefinitionsContainer(destinationDbPath);
68
		EntityContainer sourceEnts = new EntityContainer(sourceDbPath);
74
		EntityContainer sourceEnts = new EntityContainer(sourceDbPath);
69
		EntityContainer destinationEnts = new EntityContainer(destinationDbPath);
75
		EntityContainer destinationEnts = new EntityContainer(destinationDbPath);
70
		
76
		
Line 125... Line 131...
125
 
131
 
126
					newrawMedia.put(label, newMedia);
132
					newrawMedia.put(label, newMedia);
127
					System.out.println("old " + media.toString());
133
					System.out.println("old " + media.toString());
128
	//				System.out.println("new " + newMedia.toString());
134
	//				System.out.println("new " + newMedia.toString());
129
	//				OldCreationUtils.removeMedia(entity.getID(), label);
135
	//				OldCreationUtils.removeMedia(entity.getID(), label);
130
					CreationUtils.addMedia(entity.getID(), newMedia);
136
	//				CreationUtils.addMedia(entity.getID(), newMedia);
131
				}
137
				}
132
			}
138
			}
133
			
139
			
134
			int totalVideos = 0;
140
			int totalVideos = 0;
135
			int totalImages = 0;
141
			int totalImages = 0;
-
 
142
			if(rawMedia==null){
136
			for(Slide slide: slides ){
143
			for(Slide slide: slides ){
-
 
144
			*/
-
 
145
				/*
137
				FreeformContent ffc = slide.getFreeformContent();
146
				FreeformContent ffc = slide.getFreeformContent();
138
				List<String> vidList = new ArrayList<String>();
147
				List<String> vidList = new ArrayList<String>();
139
				List<String> imgList = new ArrayList<String>();
148
				List<String> imgList = new ArrayList<String>();
140
				
149
				
141
				if(ffc!=null){
150
				if(ffc!=null){
Line 185... Line 194...
185
						ffc.addMedia("image", (new StringTokenizer(imglab, "~!~")).nextToken());
194
						ffc.addMedia("image", (new StringTokenizer(imglab, "~!~")).nextToken());
186
					}
195
					}
187
					slide.setFreeformContent(ffc);
196
					slide.setFreeformContent(ffc);
188
					System.out.println("Slide id is " + slide.getSlideDefinitionID() + "   vid labels:  " + vidFfcLabels + "   img labels" + imgFfcLabels);
197
					System.out.println("Slide id is " + slide.getSlideDefinitionID() + "   vid labels:  " + vidFfcLabels + "   img labels" + imgFfcLabels);
189
				}
198
				}
190
				
199
			*/
-
 
200
		/*
191
				newEntity.addSlide(slide);
201
				newEntity.addSlide(slide);
192
			}
202
			}
-
 
203
			
193
			System.out.println("entity:"+ entity.getID() + ":trv:" + totalRawVideos + ":tri:" + totalRawImages +":tv:" + totalVideos +":ti:" + totalImages);
204
//			System.out.println("entity:"+ entity.getID() + ":trv:" + totalRawVideos + ":tri:" + totalRawImages +":tv:" + totalVideos +":ti:" + totalImages);
194
			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");
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
			
195
			
208
			
196
			destinationEnts.updateEntity(newEntity);
209
			destinationEnts.updateEntity(newEntity);
197
			CreationUtils.storeEntity(newEntity);
210
			CreationUtils.storeEntity(newEntity);
198
			
211
			
199
			Map<Long, List<Entity>> entitiesByCategory = 
212
			Map<Long, List<Entity>> entitiesByCategory = 
200
				sourceEnts.getEntitiesbyCategory();
213
				sourceEnts.getEntitiesbyCategory();
201
			
214
			
202
			Map<Long, Entity> xentities = sourceEnts.getEntities();
215
			Map<Long, Entity> xentities = destinationEnts.getEntities();
203
			
216
			
204
			CreationUtils.rewriteRepository(xentities, entitiesByCategory);
217
			CreationUtils.rewriteRepository(xentities, entitiesByCategory);
-
 
218
			}
-
 
219
			else{
-
 
220
				sb.append("				" + entity.getID() + "\n");
205
 
221
			}
206
		}
222
		}
207
		
223
		
208
		
224
		
209
		out.write(sb.toString());
225
		out.write(sb.toString());
210
		out.close();
226
		out.close();
211
		*/
227
		*/
212
		return true;
228
		return true;
213
	}
229
	}
-
 
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
	}
214
}
284
}