Subversion Repositories SmartDukaan

Rev

Rev 7590 | Rev 7932 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7590 Rev 7917
Line 1... Line 1...
1
package in.shop2020.util;
1
package in.shop2020.util;
2
 
2
 
3
import in.shop2020.metamodel.core.Bullet;
3
import in.shop2020.metamodel.core.Bullet;
-
 
4
import in.shop2020.metamodel.core.BulletDataObject;
4
import in.shop2020.metamodel.core.Entity;
5
import in.shop2020.metamodel.core.Entity;
5
import in.shop2020.metamodel.core.EntityState;
6
import in.shop2020.metamodel.core.EntityState;
6
import in.shop2020.metamodel.core.EntityStatus;
7
import in.shop2020.metamodel.core.EntityStatus;
7
import in.shop2020.metamodel.core.EnumDataObject;
8
import in.shop2020.metamodel.core.EnumDataObject;
8
import in.shop2020.metamodel.core.ExpertReview;
9
import in.shop2020.metamodel.core.ExpertReview;
Line 21... Line 22...
21
import in.shop2020.metamodel.definitions.SlideDefinition;
22
import in.shop2020.metamodel.definitions.SlideDefinition;
22
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
23
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
23
import in.shop2020.metamodel.util.CreationUtils;
24
import in.shop2020.metamodel.util.CreationUtils;
24
import in.shop2020.metamodel.util.ExpandedBullet;
25
import in.shop2020.metamodel.util.ExpandedBullet;
25
import in.shop2020.metamodel.util.ExpandedEntity;
26
import in.shop2020.metamodel.util.ExpandedEntity;
-
 
27
import in.shop2020.metamodel.util.ExpandedFeature;
26
import in.shop2020.model.v1.catalog.CatalogService.Client;
28
import in.shop2020.model.v1.catalog.CatalogService.Client;
27
import in.shop2020.model.v1.catalog.Item;
29
import in.shop2020.model.v1.catalog.Item;
28
import in.shop2020.model.v1.catalog.status;
30
import in.shop2020.model.v1.catalog.status;
29
import in.shop2020.thrift.clients.CatalogClient;
31
import in.shop2020.thrift.clients.CatalogClient;
30
import in.shop2020.utils.Logger;
32
import in.shop2020.utils.Logger;
Line 85... Line 87...
85
		ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath,destinationDbPath);
87
		ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath,destinationDbPath);
86
		/*List<Long> entityId = Arrays.asList(1001674l,1002575l,1005331l,1005165l,1005164l,1005111l,1005109l,1004952l,1004940l,1004871l,1004701l,1004429l,1004197l,1006174l,1006077l,1005901l,1005757l,1005754l,1005724l,1005704l,1005598l,1005576l,1005558l,1007394l,1007230l,1007226l,1007218l,1007089l,1006925l,1006822l,1006814l,1006175l);
88
		/*List<Long> entityId = Arrays.asList(1001674l,1002575l,1005331l,1005165l,1005164l,1005111l,1005109l,1004952l,1004940l,1004871l,1004701l,1004429l,1004197l,1006174l,1006077l,1005901l,1005757l,1005754l,1005724l,1005704l,1005598l,1005576l,1005558l,1007394l,1007230l,1007226l,1007218l,1007089l,1006925l,1006822l,1006814l,1006175l);
87
		for (Long eId : entityId){
89
		for (Long eId : entityId){
88
			contentmigrator.touchEntityState(eId);
90
			contentmigrator.touchEntityState(eId);
89
		}*/
91
		}*/
90
		contentmigrator.updateSources();
92
		contentmigrator.miscilleniousPopulate();
91
 
93
 
92
	}
94
	}
93
	
95
	
94
	private void updateSources() throws Exception{
96
	private void updateSources() throws Exception{
95
		Map<Long,List<ExpertReview>> erMap = CreationUtils.getExpertReviews();
97
		Map<Long,List<ExpertReview>> erMap = CreationUtils.getExpertReviews();
Line 2122... Line 2124...
2122
			e.printStackTrace();
2124
			e.printStackTrace();
2123
			System.out.println("Could not migrate " + entityId);
2125
			System.out.println("Could not migrate " + entityId);
2124
		}
2126
		}
2125
	}
2127
	}
2126
	
2128
	
-
 
2129
	
2127
}
2130
}
-
 
2131
private void miscilleniousPopulate() throws Exception{
2128
 
2132
	
-
 
2133
	DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
2129
 
2134
	
-
 
2135
	//Get All Enum Values of Communication facilities 70114;
-
 
2136
	Map <Long, Entity> allEntities = CreationUtils.getEntities();
-
 
2137
	/*Map <Long, Entity> allEntities =new HashMap<Long, Entity>();
-
 
2138
	allEntities.put(1000069l, CreationUtils.getEntity(1000069l));*/
-
 
2139
	for (Map.Entry<Long, Entity> entry:allEntities.entrySet()){
-
 
2140
		Entity entity = entry.getValue();
-
 
2141
		Long categoryId = entity.getCategoryID();
-
 
2142
		EntityState es = CreationUtils.getEntityState(entity.getID());
-
 
2143
		if ((categoryId == 10002 || categoryId == 10003 || categoryId == 10004 || categoryId == 10005) 
-
 
2144
				&& (es != null && es.getStatus().equals(EntityStatus.READY))) {
-
 
2145
			ExpandedEntity expEntity = new ExpandedEntity(entity);
-
 
2146
			Slide miscSlide = expEntity.getSlide(130024l);
-
 
2147
			if(miscSlide == null) {
-
 
2148
				miscSlide = new Slide(130024l);
-
 
2149
				List<Slide> allSlides = expEntity.getSlides();
-
 
2150
				allSlides.add(miscSlide);
-
 
2151
				expEntity.getSlideSequence().add(expEntity.getSlideSequence().size() -1, 130024l);
-
 
2152
			}
-
 
2153
			Slide commSlide = expEntity.getSlide(130005l);
-
 
2154
			List<Feature> commFeatures = commSlide.getFeatures();
-
 
2155
			if(commFeatures == null){
-
 
2156
				commFeatures = new ArrayList<Feature>();
-
 
2157
				commSlide.setFeatures(commFeatures);
-
 
2158
			}
-
 
2159
			List<Feature> features = miscSlide.getFeatures();
-
 
2160
			if (features == null){
-
 
2161
				features = new ArrayList<Feature>();
-
 
2162
				miscSlide.setFeatures(features);
-
 
2163
			}
-
 
2164
			StringBuffer allFfts = new StringBuffer();
-
 
2165
			StringBuffer allFfts1 = new StringBuffer();
-
 
2166
			List<Slide> slides =  entity.getSlides();
-
 
2167
			Iterator<Slide> slideIter = slides.iterator();
-
 
2168
				while(slideIter.hasNext()) {
-
 
2169
					Slide slide = slideIter.next();
-
 
2170
					//if slide is organizer or games or social networking
-
 
2171
					long slideId = slide.getSlideDefinitionID();
-
 
2172
					if ( slideId == 130021l ){
-
 
2173
						List<String> ffts = slide.getFreeformContent().getFreeformTexts();
-
 
2174
						allFfts.setLength(0);
-
 
2175
						for(String fft:ffts ){
-
 
2176
							allFfts.append(", ").append(fft.trim().replaceAll("\r\n|\n", ", "));
-
 
2177
						}
-
 
2178
						Feature f = new Feature(120481l);
-
 
2179
						f.setBullets(Arrays.asList(new Bullet(new PrimitiveDataObject(allFfts.replace(0, 2, "").toString().replaceAll(" ,", ",").replaceAll(",,", ",")))));
-
 
2180
						features.add(f);
-
 
2181
						slideIter.remove();
-
 
2182
					//games	
-
 
2183
					} else if(slideId ==130033l) {
-
 
2184
						List<String> ffts = slide.getFreeformContent().getFreeformTexts();
-
 
2185
						allFfts.setLength(0);
-
 
2186
						for(String fft:ffts ){
-
 
2187
							allFfts.append(", ").append(fft.trim().replaceAll("\r\n|\n", ", "));
-
 
2188
						}
-
 
2189
						Feature f = new Feature(120483l);
-
 
2190
						f.setBullets(Arrays.asList(new Bullet(new PrimitiveDataObject(allFfts.replace(0, 2, "").toString().replaceAll(" ,", ",").replaceAll(",,", ",")))));
-
 
2191
						features.add(f);
-
 
2192
						slideIter.remove();
-
 
2193
					//Social networking
-
 
2194
					} else if(slideId ==130023l) {
-
 
2195
						allFfts.setLength(0);
-
 
2196
						List<String> ffts = slide.getFreeformContent().getFreeformTexts();
-
 
2197
						for(String fft:ffts ){
-
 
2198
							allFfts.append(", ").append(fft.trim().replaceAll("\r\n|\n", ", "));
-
 
2199
						}
-
 
2200
						Feature f = new Feature(120482l);
-
 
2201
						f.setBullets(Arrays.asList(new Bullet(new PrimitiveDataObject(allFfts.replace(0, 2, "").toString().replaceAll(" ,", ",").replaceAll(",,", ",")))));
-
 
2202
						features.add(f);
-
 
2203
						slideIter.remove();
-
 
2204
					//Internet slide	
-
 
2205
					} else if(slideId == 130050l) {
-
 
2206
						List<Feature> internetSlideFeatures = slide.getFeatures();
-
 
2207
						if(internetSlideFeatures != null){
-
 
2208
							for (Feature f : internetSlideFeatures) {
-
 
2209
								if (f.getFeatureDefinitionID()==120075l){
-
 
2210
									for (Bullet b: f.getBullets()){
-
 
2211
										allFfts1.append(", ").append(defContainer.getEnumValue(((EnumDataObject)b.getDataObject()).getEnumValueID()).getValue());
-
 
2212
									}
-
 
2213
								}
-
 
2214
								if (f.getFeatureDefinitionID()==120076l){
-
 
2215
									for (Bullet b: f.getBullets()){
-
 
2216
										String s = ((PrimitiveDataObject)b.getDataObject()).getValue();
-
 
2217
										if(!s.equals("")) {
-
 
2218
											allFfts1.append(", ").append(s);
-
 
2219
										}
-
 
2220
									}
-
 
2221
								}
-
 
2222
								
-
 
2223
							}
-
 
2224
						}
-
 
2225
						slideIter.remove();
-
 
2226
						//130039 -->120079(mail n msg)//130016 -->120039(types)
-
 
2227
					} else if (slideId == 130039l) { ////Mail n message slide
-
 
2228
						Feature communicationFacility = new Feature(120039l);
-
 
2229
						List<Bullet> commFacilityBullets = new ArrayList<Bullet>();
-
 
2230
						communicationFacility.setBullets(commFacilityBullets);
-
 
2231
						List<String> ffts = slide.getFreeformContent().getFreeformTexts();
-
 
2232
						if(ffts != null){
-
 
2233
							for(String fft:ffts ){
-
 
2234
								allFfts1.append(", ").append(fft.trim().replaceAll("\r\n|\n", ", "));
-
 
2235
							}
-
 
2236
						}
-
 
2237
						for (Feature f : slide.getFeatures()){
-
 
2238
							String commFacilityEnumString = new ExpandedFeature(f).getFeatureDefinition().getLabel();
-
 
2239
							Long commFacilityEnumVal = defContainer.getEnumValueID(70015l, commFacilityEnumString);
-
 
2240
							if(commFacilityEnumVal != -1) {
-
 
2241
								//System.out.println("Communication facilities: " + entity.getID() + " : " + commFacilityEnumString + ":" + commFacilityEnumVal);
-
 
2242
								commFacilityBullets.add(new Bullet(new EnumDataObject(commFacilityEnumVal)));
-
 
2243
							} else {
-
 
2244
								System.out.println("Could find enum for value: " + commFacilityEnumString + " for entity: " + entity.getID());
-
 
2245
							}
-
 
2246
							if (f.getFeatureDefinitionID() == 120079l){ //fft and bullet Instant Messaging
-
 
2247
								List<Bullet> imbullets  = f.getBullets();
-
 
2248
								if(imbullets != null){
-
 
2249
									for (Bullet bullet : imbullets){
-
 
2250
										String s = ((PrimitiveDataObject)bullet.getDataObject()).getValue();
-
 
2251
										if(!s.equals("")) {
-
 
2252
											allFfts1.append(", ").append(s);
-
 
2253
										}
-
 
2254
									}
-
 
2255
								}
-
 
2256
								List<String> imffts = f.getFreeformContent().getFreeformTexts();
-
 
2257
								if(imffts != null){
-
 
2258
									for(String fft:imffts){
-
 
2259
										allFfts1.append(", ").append(fft.trim().replaceAll("\r\n|\n", ", "));
-
 
2260
									}
-
 
2261
								}else {
-
 
2262
									System.out.println("no fft for instant messaging");
-
 
2263
								}
-
 
2264
								
-
 
2265
								
-
 
2266
							} else if (f.getFeatureDefinitionID() == 120061l){ //fft of Email feature
-
 
2267
								List<String> emailffts = f.getFreeformContent().getFreeformTexts();
-
 
2268
								if(emailffts != null){
-
 
2269
									for(String fft:emailffts){
-
 
2270
										allFfts1.append(", ").append(fft.trim().replaceAll("\r\n|\n", ", "));
-
 
2271
									}
-
 
2272
								} else {
-
 
2273
									System.out.println("no fft for email");
-
 
2274
								}
-
 
2275
							}
-
 
2276
							commFeatures.add(communicationFacility);
-
 
2277
						}
-
 
2278
						slideIter.remove();
-
 
2279
					} else if (slideId == 130016l || slideId == 130016f || slideId == 130016){
-
 
2280
						List<String> ffts = slide.getFreeformContent().getFreeformTexts();
-
 
2281
						if(ffts != null){
-
 
2282
							for(String fft:ffts ){
-
 
2283
								allFfts1.append(", ").append(fft.trim().replaceAll("\r\n|\n", ", "));
-
 
2284
							}
-
 
2285
						}
-
 
2286
						if(slide.getFeatures()!=null){
-
 
2287
							for (Feature f : slide.getFeatures()){
-
 
2288
								if (f.getFeatureDefinitionID() == 120039l){ //Types
-
 
2289
										commFeatures.add(f);
-
 
2290
								}
-
 
2291
							}
-
 
2292
						}
-
 
2293
						slideIter.remove();
-
 
2294
					} else if (slideId == 130022l){
-
 
2295
						List<String> ffts = slide.getFreeformContent().getFreeformTexts();
-
 
2296
						if(ffts != null){
-
 
2297
							for(String fft:ffts ){
-
 
2298
								allFfts1.append(", ").append(fft.trim().replaceAll("\r\n|\n", ", "));
-
 
2299
							}
-
 
2300
						}
-
 
2301
						slide.getFreeformContent().setFreeformTexts(null);
-
 
2302
					} else if (slideId == 130024l &&  slide.getFreeformContent() != null){
-
 
2303
						List<String> ffts = slide.getFreeformContent().getFreeformTexts();
-
 
2304
						if(ffts != null){
-
 
2305
							for(String fft:ffts ){
-
 
2306
								allFfts1.append(", ").append(fft.trim().replaceAll("\r\n|\n", ", "));
-
 
2307
							}
-
 
2308
						}
-
 
2309
						slide.getFreeformContent().setFreeformTexts(null);
-
 
2310
					} else if (slideId == 130026l){
-
 
2311
						List<String> ffts = slide.getFreeformContent().getFreeformTexts();
-
 
2312
						if(ffts != null){
-
 
2313
							for(String fft:ffts ){
-
 
2314
								allFfts1.append(", ").append(fft.trim().replaceAll("\r\n|\n", ", "));
-
 
2315
							}
-
 
2316
						}
-
 
2317
						slide.getFreeformContent().setFreeformTexts(null);
-
 
2318
					} else if (slideId == 130019l){
-
 
2319
						slideIter.remove();
-
 
2320
					}						
-
 
2321
				}
-
 
2322
				Feature f = new Feature(120484l);
-
 
2323
				f.setBullets(Arrays.asList(new Bullet(new PrimitiveDataObject(allFfts1.replace(0, 2, "").toString().replaceAll(" ,", ",").replaceAll(",,", ",")))));
-
 
2324
				features.add(f);
-
 
2325
				CreationUtils.updateEntity(entity);
-
 
2326
				touchEntityState(entity.getID());
-
 
2327
				System.out.println(entity.getID() + " modified successfully.");
-
 
2328
			}
-
 
2329
		}
-
 
2330
	}
2130
}
2331
}
2131
 
2332