Subversion Repositories SmartDukaan

Rev

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

Rev 8009 Rev 8014
Line 33... Line 33...
33
import java.io.ByteArrayInputStream;
33
import java.io.ByteArrayInputStream;
34
import java.io.ByteArrayOutputStream;
34
import java.io.ByteArrayOutputStream;
35
import java.io.DataInputStream;
35
import java.io.DataInputStream;
36
import java.io.File;
36
import java.io.File;
37
import java.io.FileInputStream;
37
import java.io.FileInputStream;
-
 
38
import java.io.FileNotFoundException;
38
import java.io.FileOutputStream;
39
import java.io.FileOutputStream;
-
 
40
import java.io.FileReader;
39
import java.io.InputStream;
41
import java.io.InputStream;
40
import java.io.InputStreamReader;
42
import java.io.InputStreamReader;
41
import java.io.ObjectInputStream;
43
import java.io.ObjectInputStream;
42
import java.io.ObjectOutputStream;
44
import java.io.ObjectOutputStream;
43
import java.io.OutputStream;
45
import java.io.OutputStream;
-
 
46
import java.io.Reader;
44
import java.text.MessageFormat;
47
import java.text.MessageFormat;
45
import java.util.ArrayList;
48
import java.util.ArrayList;
46
import java.util.Arrays;
49
import java.util.Arrays;
47
import java.util.Collection;
50
import java.util.Collection;
48
import java.util.Collections;
51
import java.util.Collections;
Line 58... Line 61...
58
import org.apache.commons.chain.CatalogFactory;
61
import org.apache.commons.chain.CatalogFactory;
59
import org.apache.commons.collections.CollectionUtils;
62
import org.apache.commons.collections.CollectionUtils;
60
import org.apache.commons.io.IOUtils;
63
import org.apache.commons.io.IOUtils;
61
import org.apache.commons.lang.StringUtils;
64
import org.apache.commons.lang.StringUtils;
62
 
65
 
-
 
66
import com.google.gson.Gson;
-
 
67
import com.google.gson.reflect.TypeToken;
-
 
68
 
63
/*
69
/*
64
 * @author rajveer 	
70
 * @author rajveer 	
65
 * 
71
 * 
66
 *
72
 *
67
 */
73
 */
Line 88... Line 94...
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);
94
		/*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);
89
		for (Long eId : entityId){
95
		for (Long eId : entityId){
90
			contentmigrator.touchEntityState(eId);
96
			contentmigrator.touchEntityState(eId);
91
		}*/
97
		}*/
92
		contentmigrator.step6();
98
		contentmigrator.step6();
-
 
99
		//System.out.println(contentmigrator.getItems().size());
93
 
100
 
94
	}
101
	}
95
	
102
	
96
	private void updateSources() throws Exception{
103
	private void updateSources() throws Exception{
97
		Map<Long,List<ExpertReview>> erMap = CreationUtils.getExpertReviews();
104
		Map<Long,List<ExpertReview>> erMap = CreationUtils.getExpertReviews();
Line 113... Line 120...
113
	}
120
	}
114
	private void touchEntityState(Long eId) throws Exception {
121
	private void touchEntityState(Long eId) throws Exception {
115
		EntityState es = CreationUtils.getEntityState(eId);
122
		EntityState es = CreationUtils.getEntityState(eId);
116
		es.setMerkedReadyOn(new Date());
123
		es.setMerkedReadyOn(new Date());
117
		CreationUtils.updateEntityState(es);
124
		CreationUtils.updateEntityState(es);
118
		System.out.println("Touched " + eId + " successfully!");
-
 
119
	}
125
	}
120
	private void updateModelForBBQ10() throws Exception{
126
	private void updateModelForBBQ10() throws Exception{
121
		Long entityId = 1007315l;
127
		Long entityId = 1007315l;
122
		EntityState e1 = CreationUtils.getEntityState(entityId);
128
		EntityState e1 = CreationUtils.getEntityState(entityId);
123
		Entity e2 = CreationUtils.getEntity(entityId);
129
		Entity e2 = CreationUtils.getEntity(entityId);
Line 2352... Line 2358...
2352
			}
2358
			}
2353
		}
2359
		}
2354
	}
2360
	}
2355
	private void step6() throws Exception {
2361
	private void step6() throws Exception {
2356
		//Get All Enum Values of Communication facilities 70114;
2362
		//Get All Enum Values of Communication facilities 70114;
2357
		Map <Long, Entity> allEntities = CreationUtils.getEntities();
2363
		DefinitionsContainer defc = Catalog.getInstance().getDefinitionsContainer();
2358
		/*Map <Long, Entity> allEntities = new HashMap<Long, Entity>();
2364
		Map <Long, Long> allEntities = getValues();
2359
		allEntities.put(1002529l, CreationUtils.getEntity(1002529l));
-
 
2360
		allEntities.put(1007932l, CreationUtils.getEntity(1007932l));
-
 
2361
		allEntities.put(1007930l, CreationUtils.getEntity(1007930l));
-
 
2362
		allEntities.put(1007934l, CreationUtils.getEntity(1007934l));
-
 
2363
		allEntities.put(1007936l, CreationUtils.getEntity(1007936l));
-
 
2364
		allEntities.put(1007935l, CreationUtils.getEntity(1007935l));*/
-
 
2365
		for (Map.Entry<Long, Entity> entry:allEntities.entrySet()){
2365
		for (Map.Entry<Long, Long> entry:allEntities.entrySet()){
2366
			Entity entity = entry.getValue();
2366
			Long entityId = entry.getKey();
-
 
2367
			Entity entity = CreationUtils.getEntity(entityId); 
2367
			Long categoryId = entity.getCategoryID();
2368
			Long categoryId = entity.getCategoryID();
-
 
2369
			boolean found = false;
2368
			//System.out.println("entity : " + entity.getID());
2370
			//System.out.println("entity : " + entity.getID());
2369
			DefinitionsContainer defc = Catalog.getInstance().getDefinitionsContainer();
-
 
2370
			EntityState es = CreationUtils.getEntityState(entity.getID());
2371
			EntityState es = CreationUtils.getEntityState(entity.getID());
2371
			if(!es.getStatus().equals(EntityStatus.UNASSIGNED)) {
2372
			if(!es.getStatus().equals(EntityStatus.UNASSIGNED)) {
2372
				if ((categoryId == 10002 || categoryId == 10003 || categoryId == 10004 || categoryId == 10005) 
2373
				if ((categoryId == 10002 || categoryId == 10003 || categoryId == 10004 || categoryId == 10005) 
2373
						&& es != null) {
2374
						&& es != null) {
2374
					List<Slide> allSlides = entity.getSlides();
-
 
2375
					if(allSlides!=null){
-
 
2376
						Iterator<Slide> slideIterator = allSlides.iterator();
-
 
2377
						while(slideIterator.hasNext()){
-
 
2378
							Slide sl = slideIterator.next();
-
 
2379
							if(defc.getSlideDefinition(sl.getSlideDefinitionID()) == null) {
-
 
2380
								System.out.println("removed slide : " + sl.getSlideDefinitionID());
-
 
2381
								slideIterator.remove();
-
 
2382
								if (entity.getSlideSequence().remove(sl.getSlideDefinitionID())){
-
 
2383
									System.out.println("removed from category slide sequence: " + sl.getSlideDefinitionID());
-
 
2384
								}else {
-
 
2385
									System.out.println("not found category slide sequence: " + sl.getSlideDefinitionID());
-
 
2386
								}
-
 
2387
							}
-
 
2388
						}
-
 
2389
					}
-
 
2390
					
2375
					
2391
					Slide videoSlide = entity.getSlide(130031l);
2376
					Slide videoSlide = entity.getSlide(130031l);
2392
					if(videoSlide != null){
2377
					if(videoSlide != null){
2393
						FreeformContent videoffc  = videoSlide.getFreeformContent();
2378
						List<Feature> features = videoSlide.getFeatures();
2394
						if (videoffc != null) {
2379
						if(features != null) {
-
 
2380
							Iterator<Feature> iter = features.iterator();
-
 
2381
							while(iter.hasNext()){
2395
							videoffc.setFreeformTexts(null);
2382
								Feature f = iter.next();
-
 
2383
								if(f.getFeatureDefinitionID() == 120475l){
-
 
2384
									found = true;
-
 
2385
									if(!entry.getValue().equals(((EnumDataObject)f.getBullets().get(0).getDataObject()).getEnumValueID())){
-
 
2386
										f.getBullets().get(0).setDataObject(new EnumDataObject(entry.getValue()));
-
 
2387
										try{
-
 
2388
											System.out.println("Recording feature updated:" + entityId);
-
 
2389
											CreationUtils.updateEntity(entity);
-
 
2390
											touchEntityState(entityId);
-
 
2391
										}catch (Exception e){
-
 
2392
											System.out.println("Could not update entity : " + entity.getID());
-
 
2393
										}
-
 
2394
									}
-
 
2395
									break;
2396
						}
2396
								}
2397
					}
2397
							}
2398
					Slide batterySlide = entity.getSlide(130043l);
2398
							
2399
					if(batterySlide != null){
2399
							if(!found){
2400
						List <Feature> features = batterySlide.getFeatures();
2400
								Feature f = new Feature(120475l);
2401
						Iterator<Feature> fIterator = features.iterator();
2401
								f.setBullets(Arrays.asList(new Bullet(new EnumDataObject(entry.getValue()))));
2402
						while (fIterator.hasNext()){
2402
								features.add(f);
-
 
2403
								try{
-
 
2404
									System.out.println("Recording feature created:" + entityId);
2403
							Feature f = fIterator.next();
2405
									CreationUtils.updateEntity(entity);
2404
							long fId = f.getFeatureDefinitionID();
2406
									touchEntityState(entityId);
2405
							if(fId == 120073){
2407
								}catch (Exception e){
-
 
2408
									System.out.println("Could not update entity : " + entity.getID());
2406
								fIterator.remove();
2409
								}
2407
							}
2410
							}
2408
						}
2411
						}
2409
					}
2412
					}
2410
					try{
-
 
2411
						CreationUtils.updateEntity(entity);
-
 
2412
					}catch (Exception e){
-
 
2413
						System.out.println("Could not update entity : " + entity.getID());
-
 
2414
					}
-
 
2415
					touchEntityState(entity.getID());
-
 
2416
				}
2413
				}
2417
 
2414
 
2418
			}
2415
			}
2419
		}
2416
		}
2420
	}
2417
	}
-
 
2418
	
-
 
2419
	private Map<Long,Long> getValues() {
-
 
2420
		try {
-
 
2421
			Reader reader = new FileReader("/root/sample.json");
-
 
2422
			return new Gson().fromJson(reader, new TypeToken<Map<Long,Long>>() {}.getType());
-
 
2423
		} catch (FileNotFoundException e) {
-
 
2424
			e.printStackTrace();
-
 
2425
			return new HashMap<Long, Long>();
-
 
2426
		}
-
 
2427
	}
2421
}
2428
}
2422
 
2429