Subversion Repositories SmartDukaan

Rev

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

Rev 473 Rev 479
Line 1... Line 1...
1
package in.shop2020.util;
1
package in.shop2020.util;
2
 
2
 
-
 
3
import java.io.BufferedOutputStream;
-
 
4
import java.io.BufferedWriter;
-
 
5
import java.io.File;
-
 
6
import java.io.FileWriter;
-
 
7
import java.util.ArrayList;
-
 
8
import java.util.HashMap;
-
 
9
import java.util.List;
-
 
10
import java.util.Map;
-
 
11
import java.util.StringTokenizer;
-
 
12
 
-
 
13
import in.shop2020.metamodel.core.Entity;
-
 
14
import in.shop2020.metamodel.core.FreeformContent;
-
 
15
import in.shop2020.metamodel.core.Media;
-
 
16
import in.shop2020.metamodel.core.Slide;
3
import in.shop2020.metamodel.definitions.Catalog;
17
import in.shop2020.metamodel.definitions.Catalog;
4
import in.shop2020.metamodel.definitions.DefinitionsContainer;
18
import in.shop2020.metamodel.definitions.DefinitionsContainer;
5
import in.shop2020.metamodel.definitions.EntityContainer;
19
import in.shop2020.metamodel.definitions.EntityContainer;
-
 
20
import in.shop2020.metamodel.util.CreationUtils;
-
 
21
//import in.shop2020.metamodel.util.OldCreationUtils;
6
 
22
 
7
/*
23
/*
8
 * @author rajveer 
24
 * @author rajveer 
9
 * 
25
 * 
10
 *
26
 *
Line 38... Line 54...
38
	/**
54
	/**
39
	 * this function will read source definition and source entities, and will convert
55
	 * this function will read source definition and source entities, and will convert
40
	 * source entities to destination entities according to destination definitions.  
56
	 * source entities to destination entities according to destination definitions.  
41
	 * 
57
	 * 
42
	 * @return boolean
58
	 * @return boolean
-
 
59
	 * @throws Exception 
43
	 */
60
	 */
44
	public boolean migrate(){
61
	public boolean migrate() throws Exception{
-
 
62
		
-
 
63
		/*
-
 
64
		 * 
-
 
65
		 
45
		DefinitionsContainer sourceDefs = new DefinitionsContainer(sourceDbPath);
66
		DefinitionsContainer sourceDefs = new DefinitionsContainer(sourceDbPath);
46
		DefinitionsContainer destinationDefs = new DefinitionsContainer(destinationDbPath);
67
		DefinitionsContainer destinationDefs = new DefinitionsContainer(destinationDbPath);
47
		EntityContainer sourceEnts = new EntityContainer(sourceDbPath);
68
		EntityContainer sourceEnts = new EntityContainer(sourceDbPath);
48
		EntityContainer destinationEnts = new EntityContainer(destinationDbPath);
69
		EntityContainer destinationEnts = new EntityContainer(destinationDbPath);
49
		
70
		
-
 
71
		Map<Long, Entity> entities = sourceEnts.getEntities();
-
 
72
		
-
 
73
		File f = new File("/home/rajveer/Desktop/info.txt");
-
 
74
		FileWriter fstream = new FileWriter(f);
-
 
75
        BufferedWriter out = new BufferedWriter(fstream);
-
 
76
        StringBuilder sb = new StringBuilder();
-
 
77
        
-
 
78
        
-
 
79
		for(Entity entity: entities.values()){
-
 
80
			List<Slide> slides = entity.getSlides();
-
 
81
			
-
 
82
			//List<String> vidLabels = CreationUtils.getMediaLabels(entity.getID(),"youtube");
-
 
83
			//List<String> imgLabels = CreationUtils.getMediaLabels(entity.getID(),"image");
-
 
84
			
-
 
85
			//Map<String, Media> rawMedia = CreationUtils.getRawMedia(entity.getID());
-
 
86
			
-
 
87
			
-
 
88
//			List<String> vidLabels = OldCreationUtils.getMediaLabels(entity.getID(),"youtube");
-
 
89
//			List<String> imgLabels = OldCreationUtils.getMediaLabels(entity.getID(),"image");
-
 
90
		
-
 
91
			Entity newEntity = new Entity(entity.getID(), entity.getCategoryID());
-
 
92
			newEntity.setBrand(entity.getBrand());
-
 
93
			newEntity.setModelName(entity.getModelName());
-
 
94
			newEntity.setModelNumber(entity.getModelNumber());
-
 
95
			
-
 
96
			
-
 
97
			Map<String, in.shop2020.creation.util.Media> rawMedia = OldCreationUtils.getRawMedia(entity.getID());
-
 
98
			
-
 
99
			Map<String, Media> newrawMedia = new HashMap<String, Media>();
-
 
100
			
-
 
101
			
-
 
102
			int totalRawVideos = 0;
-
 
103
			int totalRawImages = 0;
-
 
104
			
-
 
105
			if(rawMedia!=null){
-
 
106
				for(String label: rawMedia.keySet()){
-
 
107
					in.shop2020.creation.util.Media media = rawMedia.get(label);
-
 
108
					
-
 
109
					label = media.getLabel();
-
 
110
					String type = media.getType();
-
 
111
					String location = media.getLocation();
-
 
112
					
-
 
113
					Media newMedia = new Media(label, type, location);
-
 
114
					
-
 
115
					newMedia.setTitle("Title");
-
 
116
					if(type.equals("image")){
-
 
117
						totalRawImages++;
-
 
118
						newMedia.setFileName(media.getFileName());
-
 
119
						newMedia.setVideoType("");
-
 
120
					}else{
-
 
121
						totalRawVideos++;
-
 
122
						newMedia.setVideoType("withoutskin");
-
 
123
						newMedia.setFileName("");
-
 
124
					}
-
 
125
 
-
 
126
					newrawMedia.put(label, newMedia);
-
 
127
					System.out.println("old " + media.toString());
-
 
128
	//				System.out.println("new " + newMedia.toString());
-
 
129
	//				OldCreationUtils.removeMedia(entity.getID(), label);
-
 
130
					CreationUtils.addMedia(entity.getID(), newMedia);
-
 
131
				}
-
 
132
			}
-
 
133
			
-
 
134
			int totalVideos = 0;
-
 
135
			int totalImages = 0;
-
 
136
			for(Slide slide: slides ){
-
 
137
				FreeformContent ffc = slide.getFreeformContent();
-
 
138
				List<String> vidList = new ArrayList<String>();
-
 
139
				List<String> imgList = new ArrayList<String>();
-
 
140
				
-
 
141
				if(ffc!=null){
-
 
142
					List<String> vidFfcLabels = ffc.getYoutubeRefs();
-
 
143
					if(vidFfcLabels!=null){
-
 
144
						for(String vidFfcLabel: vidFfcLabels){
-
 
145
							StringTokenizer strTkn = new StringTokenizer(vidFfcLabel,"~!~");
-
 
146
							String vidLabel = null;
-
 
147
							if(strTkn.hasMoreTokens()){
-
 
148
								vidLabel = strTkn.nextToken();
-
 
149
								vidList.add(vidFfcLabel);
-
 
150
								
-
 
151
//								ffc.removeMedia("youtube", vidFfcLabel);
-
 
152
//								ffc.addMedia("youtube", vidLabel);
-
 
153
							}
-
 
154
							if(vidLabel == null){
-
 
155
								System.out.println("Something is really breaking .. bu ha ha !!!");
-
 
156
							}
-
 
157
							totalVideos++;
-
 
158
						}
-
 
159
					}
-
 
160
					List<String> imgFfcLabels = ffc.getImageRefs();
-
 
161
					if(imgFfcLabels!=null){
-
 
162
						for(String imgFfcLabel: imgFfcLabels){
-
 
163
							StringTokenizer strTkn = new StringTokenizer(imgFfcLabel,"~!~");
-
 
164
							String imgLabel = null;
-
 
165
							if(strTkn.hasMoreTokens()){
-
 
166
								imgLabel = strTkn.nextToken();
-
 
167
								imgList.add(imgFfcLabel);
-
 
168
								
-
 
169
//								ffc.removeMedia("image", imgFfcLabel);
-
 
170
//								ffc.addMedia("image", imgLabel);							
-
 
171
							}
-
 
172
							if(imgLabel == null){
-
 
173
								System.out.println("Something is really breaking .. bu ha ha !!!");
-
 
174
							}
-
 
175
							totalImages++;
-
 
176
						}
-
 
177
					}
-
 
178
					
-
 
179
					for(String vidlab : vidList){
-
 
180
						ffc.removeMedia("youtube", vidlab);
-
 
181
						ffc.addMedia("youtube", (new StringTokenizer(vidlab, "~!~")).nextToken());
-
 
182
					}
-
 
183
					for(String imglab : imgList){
-
 
184
						ffc.removeMedia("image",imglab);
-
 
185
						ffc.addMedia("image", (new StringTokenizer(imglab, "~!~")).nextToken());
-
 
186
					}
-
 
187
					slide.setFreeformContent(ffc);
-
 
188
					System.out.println("Slide id is " + slide.getSlideDefinitionID() + "   vid labels:  " + vidFfcLabels + "   img labels" + imgFfcLabels);
-
 
189
				}
-
 
190
				
-
 
191
				newEntity.addSlide(slide);
-
 
192
			}
-
 
193
			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");
-
 
195
			
-
 
196
			destinationEnts.updateEntity(newEntity);
-
 
197
			CreationUtils.storeEntity(newEntity);
-
 
198
			
-
 
199
			Map<Long, List<Entity>> entitiesByCategory = 
-
 
200
				sourceEnts.getEntitiesbyCategory();
-
 
201
			
-
 
202
			Map<Long, Entity> xentities = sourceEnts.getEntities();
-
 
203
			
-
 
204
			CreationUtils.rewriteRepository(xentities, entitiesByCategory);
-
 
205
 
-
 
206
		}
-
 
207
		
50
		
208
		
-
 
209
		out.write(sb.toString());
-
 
210
		out.close();
-
 
211
		*/
51
		return true;
212
		return true;
52
	}
213
	}
53
}
214
}