| 457 |
rajveer |
1 |
package in.shop2020.util;
|
|
|
2 |
|
| 479 |
rajveer |
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;
|
| 457 |
rajveer |
17 |
import in.shop2020.metamodel.definitions.Catalog;
|
|
|
18 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
|
|
19 |
import in.shop2020.metamodel.definitions.EntityContainer;
|
| 479 |
rajveer |
20 |
import in.shop2020.metamodel.util.CreationUtils;
|
|
|
21 |
//import in.shop2020.metamodel.util.OldCreationUtils;
|
| 457 |
rajveer |
22 |
|
|
|
23 |
/*
|
|
|
24 |
* @author rajveer
|
|
|
25 |
*
|
|
|
26 |
*
|
|
|
27 |
*/
|
|
|
28 |
|
|
|
29 |
public class ContentMigrator {
|
|
|
30 |
private String sourceDbPath;
|
|
|
31 |
private String destinationDbPath;
|
|
|
32 |
|
|
|
33 |
public static void main(String[] args) throws Exception {
|
|
|
34 |
String usage = "Usage: ContentMigrator {source db path}{destination db path}";
|
|
|
35 |
|
|
|
36 |
String sourceDbPath = null, destinationDbPath = null;
|
|
|
37 |
if(args.length < 2) {
|
|
|
38 |
System.out.println(usage);
|
|
|
39 |
System.exit(-1);
|
|
|
40 |
}else{
|
|
|
41 |
sourceDbPath = args[0];
|
|
|
42 |
destinationDbPath = args[1];
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath, destinationDbPath);
|
|
|
46 |
boolean result = contentmigrator.migrate();
|
|
|
47 |
System.out.println("Content migration status: "+ result);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public ContentMigrator(String sourceDbPath, String destinationDbPath) {
|
|
|
51 |
this.sourceDbPath = sourceDbPath;
|
|
|
52 |
this.destinationDbPath = destinationDbPath;
|
|
|
53 |
}
|
| 473 |
rajveer |
54 |
/**
|
|
|
55 |
* this function will read source definition and source entities, and will convert
|
|
|
56 |
* source entities to destination entities according to destination definitions.
|
|
|
57 |
*
|
|
|
58 |
* @return boolean
|
| 479 |
rajveer |
59 |
* @throws Exception
|
| 473 |
rajveer |
60 |
*/
|
| 479 |
rajveer |
61 |
public boolean migrate() throws Exception{
|
|
|
62 |
|
|
|
63 |
/*
|
|
|
64 |
*
|
|
|
65 |
|
| 473 |
rajveer |
66 |
DefinitionsContainer sourceDefs = new DefinitionsContainer(sourceDbPath);
|
|
|
67 |
DefinitionsContainer destinationDefs = new DefinitionsContainer(destinationDbPath);
|
|
|
68 |
EntityContainer sourceEnts = new EntityContainer(sourceDbPath);
|
|
|
69 |
EntityContainer destinationEnts = new EntityContainer(destinationDbPath);
|
|
|
70 |
|
| 479 |
rajveer |
71 |
Map<Long, Entity> entities = sourceEnts.getEntities();
|
| 473 |
rajveer |
72 |
|
| 479 |
rajveer |
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 |
|
|
|
208 |
|
|
|
209 |
out.write(sb.toString());
|
|
|
210 |
out.close();
|
|
|
211 |
*/
|
| 457 |
rajveer |
212 |
return true;
|
|
|
213 |
}
|
|
|
214 |
}
|