Subversion Repositories SmartDukaan

Rev

Rev 1069 | Rev 1153 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1050 rajveer 1
package in.shop2020.util;
2
 
3
 
4
import java.io.BufferedReader;
5
import java.io.DataInputStream;
6
import java.io.File;
7
import java.io.FileInputStream;
8
import java.io.FileNotFoundException;
9
import java.io.IOException;
10
import java.io.InputStreamReader;
11
import java.util.ArrayList;
12
import java.util.HashMap;
13
import java.util.List;
14
import java.util.Map;
15
 
16
import in.shop2020.metamodel.core.Entity;
17
import in.shop2020.metamodel.core.EntityState;
18
import in.shop2020.metamodel.core.FreeformContent;
19
import in.shop2020.metamodel.core.Media;
20
import in.shop2020.metamodel.core.Slide;
1070 chandransh 21
//import in.shop2020.metamodel.definitions.OldEntityContainer;
1050 rajveer 22
import in.shop2020.metamodel.util.CreationUtils;
23
import in.shop2020.metamodel.util.ExpandedBullet;
1070 chandransh 24
//import in.shop2020.metamodel.util.OldCreationUtils;
1050 rajveer 25
import in.shop2020.storage.bdb.StorageManager;
26
 
27
 
28
/*
29
 * @author rajveer 
30
 * 
31
 *
32
 */
33
 
34
public class ContentMigratorToBDB {
35
	private String sourceDbPath;
36
	private String destinationDbPath;
37
 
38
	public static void main(String[] args) throws Exception {
39
		String usage = "Usage: ContentMigrator {source db path}{destination db path}";
40
 
41
		String sourceDbPath = null, destinationDbPath = null;
42
		if(args.length < 2) {
43
			System.out.println(usage);
44
			System.exit(-1);
45
		}else{
46
			sourceDbPath = args[0];
47
			destinationDbPath = args[1];
48
		}
49
 
1069 rajveer 50
		StorageManager.getStorageManager().close();
1050 rajveer 51
 
52
		ContentMigratorToBDB contentmigrator = new ContentMigratorToBDB(sourceDbPath, destinationDbPath);
53
		//boolean result = contentmigrator.addMedia();
1069 rajveer 54
		//boolean result = contentmigrator.addLearnedFields();
1055 rajveer 55
		//boolean result = contentmigrator.migrate();
56
		//System.out.println("Content migration status:  "+ result);
1050 rajveer 57
	}
58
 
59
	public ContentMigratorToBDB(String sourceDbPath, String destinationDbPath) {
60
		this.sourceDbPath = sourceDbPath;
61
		this.destinationDbPath = destinationDbPath;
62
	}
1069 rajveer 63
 
1070 chandransh 64
//	public boolean addLearnedFields() throws Exception{
65
//		OldEntityContainer oldEnts = new OldEntityContainer(sourceDbPath);
66
//		Map<Long, List<ExpandedBullet>> learnedBullets = oldEnts.getLearnedBullets();
67
//		CreationUtils.storeLearnedBullets(learnedBullets);
68
//		return true;
69
//		
70
//	}
71
//	
72
//	public boolean addMedia() throws NumberFormatException, IOException, Exception{
73
//	    FileInputStream fstream = new FileInputStream("/home/rajveer/Desktop/test1");
74
//	    DataInputStream in = new DataInputStream(fstream);
75
//	    BufferedReader br = new BufferedReader(new InputStreamReader(in));
76
//	    String strLine;
77
//	    
78
//	    while ((strLine = br.readLine()) != null)   {
79
//	    	String[] parts  = strLine.split(":");
80
//	    	long entityID = Long.parseLong(parts[0]);
81
//	    	long slideID = Long.parseLong(parts[1]);
82
//	    	Entity entity = StorageManager.getStorageManager().getEntity(entityID);
83
//	    	Map<String, Media> medias =  OldCreationUtils.getRawMedia(entityID);
84
//	    	String imageLabels = parts[2];
85
//	    	String videoLabels = parts[3];
86
//	    	if(!imageLabels.equalsIgnoreCase("null")){
87
//	    		String[] labels = imageLabels.split(",");
88
//	    		for(int i = 0; i < labels.length; i++){
89
//	    			if(medias.containsKey(labels[i])){
90
//	    				Media media = medias.get(labels[i]);
91
//	    				entity.getSlide(slideID).getFreeformContent().addMedia(media);
92
//	    			}
93
//	    		}
94
//	    	}
95
//	    	if(!videoLabels.equalsIgnoreCase("null")){
96
//	    		String[] labels = videoLabels.split(",");
97
//	    		for(int i = 0; i < labels.length; i++){
98
//	    			if(medias.containsKey(labels[i])){
99
//	    				Media media = medias.get(labels[i]);
100
//	    				entity.getSlide(slideID).getFreeformContent().addMedia(media);
101
//	    			}
102
//	    		}
103
//	    	}
104
//	    	StorageManager.getStorageManager().updateEntity(entity);
105
//	    }
106
//	    in.close();
107
//	    return true;
108
//}
1069 rajveer 109
 
1050 rajveer 110
	/**
111
	 * this function will read source definition and source entities, and will convert
112
	 * source entities to destination entities according to destination definitions.  
113
	 * 
114
	 * @return boolean
115
	 * @throws Exception 
116
	 */
1070 chandransh 117
//	public boolean migrate() throws Exception{
118
//		OldEntityContainer sourceEnts = new OldEntityContainer(sourceDbPath);
119
//		
120
//		StringBuilder sb = new StringBuilder();
121
//		Map<Long, Entity> entities = sourceEnts.getEntities();
122
//		for(Long entityId: entities.keySet()){
123
//			Entity entity = OldCreationUtils.getEntity(entityId);
124
//			if(entity.getID() == 0){
125
//				continue;
126
//			}
127
//			Entity newEntity = new Entity(entity.getID(), entity.getCategoryID());
128
//			newEntity.setBrand(entity.getBrand());
129
//			newEntity.setModelName(entity.getModelName());
130
//			newEntity.setModelNumber(entity.getModelNumber());
131
//			
132
//			newEntity.setSlideSequence(OldCreationUtils.getSlideSequence(entity.getID()));
133
//			
134
//			List<Slide> slides = entity.getSlides();
135
//			if(slides!=null){
136
//			for(Slide slide: slides){
137
//				FreeformContent ffc = slide.getFreeformContent();
138
//				//sb.append(entityId+ ":" + slide.getSlideDefinitionID() + ":"+ ffc.getFreeformTexts()+"\n");
139
//				FreeformContent newFfc = new FreeformContent();
140
//				newFfc.setFreeformTexts(ffc.getFreeformTexts());
141
//				slide.setFreeformContent(newFfc);
142
//				//if(ffc.getAllLabels()!=null && !ffc.getAllLabels().isEmpty()){
143
//					//sb.append(entity.getID() + ":" + slide.getSlideDefinitionID() + ":" + ffc.getAllLabels() + "\n");
144
//					//sb.append(entity.getID() + ":" + slide.getSlideDefinitionID() + ":" + ffc.getImageLabels() + ":" + ffc.getYoutubeLabels() + "\n");
145
//					//System.out.println(entity.getID() + ":" + slide.getSlideDefinitionID() + ":" + ffc.getImageLabels() + ":" + ffc.getYoutubeLabels());
146
////					System.out.println("some image found");
147
////					System.out.println(ffc.getImageLabels());
148
////					System.out.println(ffc.getYoutubeLabels());
149
//				//}
150
//				//System.out.println(ffc.getImageLabels());
151
//				//System.out.println(ffc.getYoutubeLabels());
152
//				//FreeformContent newFfc = new FreeformContent();
153
//				//newFfc.setFreeformTexts(ffc.getFreeformTexts());
154
//			}
155
//			}
156
//			newEntity.setSlides(slides);
157
//			EntityState entityMetadata = new EntityState(entityId, "admin");
158
//			StorageManager.getStorageManager().createEntity(newEntity, entityMetadata);
159
//			
160
//			//System.out.println(StorageManager.getStorageManager().getStorageManager().getEntity(entityId).getSlide(130033).getFreeformContent().getFreeformTexts());
161
//			
162
//			//StorageManager.getStorageManager().close();
163
//			//System.out.println("Entity id is" + entity.getID());
164
//		}
165
//		
166
//		StorageManager.getStorageManager().close();
167
//		//System.out.println(sb.toString());
168
//		return true;
169
//	}
1050 rajveer 170
}