Subversion Repositories SmartDukaan

Rev

Rev 1055 | Rev 1069 | 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;
1055 rajveer 21
//import in.shop2020.metamodel.definitions.OldEntityContainer;
1050 rajveer 22
import in.shop2020.metamodel.util.CreationUtils;
23
import in.shop2020.metamodel.util.ExpandedBullet;
1055 rajveer 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
 
50
		//StorageManager.getStorageManager().close();
51
 
52
		ContentMigratorToBDB contentmigrator = new ContentMigratorToBDB(sourceDbPath, destinationDbPath);
53
		//boolean result = contentmigrator.addMedia();
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
	}
1055 rajveer 63
	/*
1050 rajveer 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
}
1055 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
	 */
1055 rajveer 117
	/*
1050 rajveer 118
	public boolean migrate() throws Exception{
119
		OldEntityContainer sourceEnts = new OldEntityContainer(sourceDbPath);
120
 
121
		StringBuilder sb = new StringBuilder();
122
		Map<Long, Entity> entities = sourceEnts.getEntities();
123
		for(Long entityId: entities.keySet()){
124
			entityId = (long) 1000146;
125
			Entity entity = OldCreationUtils.getEntity(entityId);
126
			if(entity.getID() == 0){
127
				continue;
128
			}
129
			Entity newEntity = new Entity(entity.getID(), entity.getCategoryID());
130
			newEntity.setBrand(entity.getBrand());
131
			newEntity.setModelName(entity.getModelName());
132
			newEntity.setModelNumber(entity.getModelNumber());
133
 
134
			newEntity.setSlideSequence(OldCreationUtils.getSlideSequence(entity.getID()));
135
 
136
			List<Slide> slides = entity.getSlides();
137
			if(slides!=null){
138
			for(Slide slide: slides){
139
				FreeformContent ffc = slide.getFreeformContent();
140
				//sb.append(entityId+ ":" + slide.getSlideDefinitionID() + ":"+ ffc.getFreeformTexts()+"\n");
141
				FreeformContent newFfc = new FreeformContent();
142
				newFfc.setFreeformTexts(ffc.getFreeformTexts());
143
				slide.setFreeformContent(newFfc);
144
				//if(ffc.getAllLabels()!=null && !ffc.getAllLabels().isEmpty()){
145
					//sb.append(entity.getID() + ":" + slide.getSlideDefinitionID() + ":" + ffc.getAllLabels() + "\n");
146
				//	sb.append(entity.getID() + ":" + slide.getSlideDefinitionID() + ":" + ffc.getImageLabels() + ":" + ffc.getYoutubeLabels() + "\n");
147
					//System.out.println(entity.getID() + ":" + slide.getSlideDefinitionID() + ":" + ffc.getImageLabels() + ":" + ffc.getYoutubeLabels());
148
//					System.out.println("some image found");
149
//					System.out.println(ffc.getImageLabels());
150
//					System.out.println(ffc.getYoutubeLabels());
151
				//}
152
				//System.out.println(ffc.getImageLabels());
153
				//System.out.println(ffc.getYoutubeLabels());
154
				//FreeformContent newFfc = new FreeformContent();
155
				//newFfc.setFreeformTexts(ffc.getFreeformTexts());
156
			}
157
			}
158
			newEntity.setSlides(slides);
159
			EntityState entityMetadata = new EntityState(entityId, "admin");
160
			//StorageManager.getStorageManager().createEntity(newEntity, entityMetadata);
161
 
162
			System.out.println(StorageManager.getStorageManager().getStorageManager().getEntity(entityId).getSlide(130033).getFreeformContent().getFreeformTexts());
163
 
164
			StorageManager.getStorageManager().close();
165
			System.out.println("Entity id is" + entity.getID());
166
		}
167
 
168
		//StorageManager.getStorageManager().close();
169
		System.out.println(sb.toString());
170
		return true;
171
	}
1055 rajveer 172
	*/
1050 rajveer 173
}