| 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.BufferedReader;
|
- |
|
| 5 |
import java.io.BufferedWriter;
|
- |
|
| 6 |
import java.io.DataInputStream;
|
- |
|
| 7 |
import java.io.File;
|
- |
|
| 8 |
import java.io.FileInputStream;
|
- |
|
| 9 |
import java.io.FileWriter;
|
- |
|
| 10 |
import java.io.InputStreamReader;
|
- |
|
| 11 |
import java.util.ArrayList;
|
- |
|
| 12 |
import java.util.Collection;
|
- |
|
| 13 |
import java.util.HashMap;
|
- |
|
| 14 |
import java.util.List;
|
- |
|
| 15 |
import java.util.Map;
|
- |
|
| 16 |
import java.util.Map.Entry;
|
- |
|
| 17 |
import java.util.StringTokenizer;
|
- |
|
| 18 |
import java.util.TreeMap;
|
- |
|
| 19 |
|
- |
|
| 20 |
import in.shop2020.metamodel.core.Bullet;
|
3 |
import in.shop2020.metamodel.core.Bullet;
|
| 21 |
import in.shop2020.metamodel.core.BulletDataObject;
|
- |
|
| 22 |
import in.shop2020.metamodel.core.CompositeDataObject;
|
- |
|
| 23 |
import in.shop2020.metamodel.core.Entity;
|
4 |
import in.shop2020.metamodel.core.Entity;
|
| 24 |
import in.shop2020.metamodel.core.EntityState;
|
5 |
import in.shop2020.metamodel.core.EntityState;
|
| 25 |
import in.shop2020.metamodel.core.EntityStatus;
|
- |
|
| 26 |
import in.shop2020.metamodel.core.EnumDataObject;
|
- |
|
| 27 |
import in.shop2020.metamodel.core.Feature;
|
6 |
import in.shop2020.metamodel.core.Feature;
|
| 28 |
import in.shop2020.metamodel.core.FreeformContent;
|
7 |
import in.shop2020.metamodel.core.FreeformContent;
|
| 29 |
import in.shop2020.metamodel.core.Media;
|
8 |
import in.shop2020.metamodel.core.Media;
|
| - |
|
9 |
import in.shop2020.metamodel.core.MediaNew;
|
| 30 |
import in.shop2020.metamodel.core.PrimitiveDataObject;
|
10 |
import in.shop2020.metamodel.core.PrimitiveDataObject;
|
| 31 |
import in.shop2020.metamodel.core.Slide;
|
11 |
import in.shop2020.metamodel.core.Slide;
|
| 32 |
import in.shop2020.metamodel.definitions.BulletDefinition;
|
12 |
import in.shop2020.metamodel.definitions.BulletDefinition;
|
| 33 |
import in.shop2020.metamodel.definitions.Catalog;
|
13 |
import in.shop2020.metamodel.definitions.Catalog;
|
| 34 |
import in.shop2020.metamodel.definitions.Category;
|
14 |
import in.shop2020.metamodel.definitions.Category;
|
| 35 |
import in.shop2020.metamodel.definitions.CategorySlideDefinition;
|
15 |
import in.shop2020.metamodel.definitions.CategorySlideDefinition;
|
| 36 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
16 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
| 37 |
import in.shop2020.metamodel.definitions.FacetDefinition;
|
- |
|
| 38 |
import in.shop2020.metamodel.definitions.FeatureDefinition;
|
17 |
import in.shop2020.metamodel.definitions.FeatureDefinition;
|
| 39 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
18 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
| 40 |
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
|
19 |
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
|
| 41 |
import in.shop2020.metamodel.util.CreationUtils;
|
20 |
import in.shop2020.metamodel.util.CreationUtils;
|
| 42 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
- |
|
| 43 |
//import in.shop2020.metamodel.util.OldCreationUtils;
|
- |
|
| 44 |
//import in.shop2020.metamodel.util.OldCreationUtils;
|
- |
|
| 45 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
21 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
| - |
|
22 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
| 46 |
import in.shop2020.model.v1.catalog.InventoryService.Client;
|
23 |
import in.shop2020.model.v1.catalog.InventoryService.Client;
|
| 47 |
import in.shop2020.model.v1.catalog.Item;
|
24 |
import in.shop2020.model.v1.catalog.Item;
|
| 48 |
import in.shop2020.model.v1.catalog.status;
|
25 |
import in.shop2020.model.v1.catalog.status;
|
| 49 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
26 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
| 50 |
|
27 |
|
| - |
|
28 |
import java.io.BufferedReader;
|
| - |
|
29 |
import java.io.DataInputStream;
|
| - |
|
30 |
import java.io.File;
|
| - |
|
31 |
import java.io.FileInputStream;
|
| - |
|
32 |
import java.io.InputStreamReader;
|
| - |
|
33 |
import java.util.ArrayList;
|
| - |
|
34 |
import java.util.LinkedHashMap;
|
| - |
|
35 |
import java.util.List;
|
| - |
|
36 |
import java.util.Map;
|
| - |
|
37 |
import java.util.TreeMap;
|
| 51 |
|
38 |
|
| 52 |
/*
|
39 |
/*
|
| 53 |
* @author rajveer
|
40 |
* @author rajveer
|
| 54 |
*
|
41 |
*
|
| 55 |
*
|
42 |
*
|
| Line 60... |
Line 47... |
| 60 |
private String destinationDbPath;
|
47 |
private String destinationDbPath;
|
| 61 |
public static void main(String[] args) throws Exception {
|
48 |
public static void main(String[] args) throws Exception {
|
| 62 |
String usage = "Usage: ContentMigrator {source db path}{destination db path}";
|
49 |
String usage = "Usage: ContentMigrator {source db path}{destination db path}";
|
| 63 |
|
50 |
|
| 64 |
String sourceDbPath = null, destinationDbPath = null; String dryRun = null;
|
51 |
String sourceDbPath = null, destinationDbPath = null; String dryRun = null;
|
| 65 |
if(args.length < 2) {
|
52 |
// if(args.length < 2) {
|
| 66 |
System.out.println(usage);
|
53 |
// System.out.println(usage);
|
| 67 |
System.exit(-1);
|
54 |
// System.exit(-1);
|
| 68 |
}else{
|
55 |
// }else{
|
| 69 |
sourceDbPath = args[0];
|
56 |
// sourceDbPath = args[0];
|
| 70 |
destinationDbPath = args[1];
|
57 |
// destinationDbPath = args[1];
|
| 71 |
dryRun = args[2];
|
58 |
// dryRun = args[2];
|
| 72 |
}
|
59 |
// }
|
| - |
|
60 |
//
|
| - |
|
61 |
ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath, destinationDbPath);
|
| - |
|
62 |
contentmigrator.migrateMedia();
|
| 73 |
|
63 |
|
| 74 |
ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath, destinationDbPath);
|
- |
|
| 75 |
contentmigrator.populateHelpdocEntityIds();
|
- |
|
| 76 |
|
64 |
|
| - |
|
65 |
//contentmigrator.populateHelpdocEntityIds();
|
| 77 |
//contentmigrator.migrateDataBack();
|
66 |
//contentmigrator.migrateDataBack();
|
| 78 |
//contentmigrator.migrateBrandModel(dryRun);
|
67 |
//contentmigrator.migrateBrandModel(dryRun);
|
| 79 |
//contentmigrator.migrateData();
|
68 |
//contentmigrator.migrateData();
|
| 80 |
//contentmigrator.migrateRemoveBorrowedCategoryIdFromSlide();
|
69 |
//contentmigrator.migrateRemoveBorrowedCategoryIdFromSlide();
|
| 81 |
//contentmigrator.migrateModel1();
|
70 |
//contentmigrator.migrateModel1();
|
| Line 117... |
Line 106... |
| 117 |
//ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath, destinationDbPath);
|
106 |
//ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath, destinationDbPath);
|
| 118 |
//boolean result = contentmigrator.migrate();
|
107 |
//boolean result = contentmigrator.migrate();
|
| 119 |
//System.out.println("Content migration status: "+ result);
|
108 |
//System.out.println("Content migration status: "+ result);
|
| 120 |
}
|
109 |
}
|
| 121 |
|
110 |
|
| - |
|
111 |
|
| 122 |
public ContentMigrator(String sourceDbPath, String destinationDbPath) {
|
112 |
public ContentMigrator(String sourceDbPath, String destinationDbPath) {
|
| 123 |
this.sourceDbPath = sourceDbPath;
|
113 |
this.sourceDbPath = sourceDbPath;
|
| 124 |
this.destinationDbPath = destinationDbPath;
|
114 |
this.destinationDbPath = destinationDbPath;
|
| 125 |
}
|
115 |
}
|
| - |
|
116 |
|
| - |
|
117 |
public void migrateMedia() throws Exception {
|
| - |
|
118 |
Map<Long, Entity> map = CreationUtils.getEntities();
|
| - |
|
119 |
for (Long entityId : map.keySet()) {
|
| - |
|
120 |
Entity entity = map.get(entityId);
|
| - |
|
121 |
if (entity == null || entity.getSlides() == null) {
|
| - |
|
122 |
continue;
|
| - |
|
123 |
}
|
| - |
|
124 |
for (Slide slide : entity.getSlides()) {
|
| - |
|
125 |
FreeformContent ffc = slide.getFreeformContent();
|
| - |
|
126 |
|
| - |
|
127 |
if (ffc == null || ffc.getMediasNew() == null) {
|
| - |
|
128 |
continue;
|
| - |
|
129 |
}
|
| - |
|
130 |
|
| - |
|
131 |
Map<String, Media> newMap = new LinkedHashMap<String, Media>();
|
| - |
|
132 |
Media media = null;
|
| - |
|
133 |
for (String label : ffc.getMediasNew().keySet()) {
|
| - |
|
134 |
MediaNew m = ffc.getMediasNew().get(label);
|
| - |
|
135 |
media = new Media(m.getLabel(), Media.Type.valueOf(m
|
| - |
|
136 |
.getType().name()), m.getLocation());
|
| - |
|
137 |
media.setTitle(m.getTitle());
|
| - |
|
138 |
media.setFileName(m.getFileName());
|
| - |
|
139 |
newMap.put(label, media);
|
| - |
|
140 |
}
|
| - |
|
141 |
ffc.setMedias(newMap);
|
| - |
|
142 |
ffc.setMediasNew(null);
|
| - |
|
143 |
|
| - |
|
144 |
|
| - |
|
145 |
// if (ffc == null || ffc.getMedias() == null) {
|
| - |
|
146 |
// continue;
|
| - |
|
147 |
// }
|
| - |
|
148 |
// Map<String, MediaNew> newMap = new LinkedHashMap<String, MediaNew>();
|
| - |
|
149 |
// MediaNew mediaNew = null;
|
| - |
|
150 |
// for (String label : ffc.getMedias().keySet()) {
|
| - |
|
151 |
// Media m = ffc.getMedias().get(label);
|
| - |
|
152 |
// if (m.getType().equalsIgnoreCase("image")) {
|
| - |
|
153 |
// mediaNew = new MediaNew(m.getLabel(),
|
| - |
|
154 |
// MediaNew.Type.IMAGE, m.getLocation());
|
| - |
|
155 |
// mediaNew.setFileName(m.getFileName());
|
| - |
|
156 |
// } else if (m.getType().equalsIgnoreCase("youtube")) {
|
| - |
|
157 |
// if (m.getVideoType().equalsIgnoreCase("withskin")) {
|
| - |
|
158 |
// mediaNew = new MediaNew(m.getLabel(),
|
| - |
|
159 |
// MediaNew.Type.VIDEO_WITH_SKIN,
|
| - |
|
160 |
// m.getLocation());
|
| - |
|
161 |
// } else {
|
| - |
|
162 |
// mediaNew = new MediaNew(m.getLabel(),
|
| - |
|
163 |
// MediaNew.Type.VIDEO_WITHOUT_SKIN,
|
| - |
|
164 |
// m.getLocation());
|
| - |
|
165 |
// }
|
| - |
|
166 |
// }
|
| - |
|
167 |
//
|
| - |
|
168 |
// if (mediaNew != null) {
|
| - |
|
169 |
// mediaNew.setTitle(m.getTitle());
|
| - |
|
170 |
// newMap.put(label, mediaNew);
|
| - |
|
171 |
// }
|
| - |
|
172 |
// }
|
| - |
|
173 |
// ffc.setMediasNew(newMap);
|
| - |
|
174 |
// ffc.setMedias(null);
|
| - |
|
175 |
}
|
| - |
|
176 |
CreationUtils.updateEntity(entity);
|
| - |
|
177 |
}
|
| 126 |
|
178 |
}
|
| - |
|
179 |
|
| 127 |
public boolean populateHelpdocEntityIds() throws Exception{
|
180 |
public boolean populateHelpdocEntityIds() throws Exception{
|
| 128 |
for(Entity entity: CreationUtils.getEntities().values()){
|
181 |
for(Entity entity: CreationUtils.getEntities().values()){
|
| 129 |
CreationUtils.updateEntity(entity);
|
182 |
CreationUtils.updateEntity(entity);
|
| 130 |
}
|
183 |
}
|
| 131 |
return true;
|
184 |
return true;
|
| 132 |
}
|
185 |
}
|
| 133 |
|
186 |
|
| 134 |
public boolean migrateBrandModel(String dryRun) throws Exception{
|
187 |
public boolean migrateBrandModel(String dryRun) throws Exception{
|
| 135 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
188 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
| 136 |
Client client = catalogServiceClient.getClient();
|
189 |
Client client = catalogServiceClient.getClient();
|
| 137 |
List<Item> items = client.getAllItemsByStatus(status.ACTIVE);
|
190 |
List<Item> items = client.getAllItemsByStatus(status.ACTIVE);
|
| 138 |
items.addAll(client.getAllItemsByStatus(status.PAUSED));
|
191 |
items.addAll(client.getAllItemsByStatus(status.PAUSED));
|
| Line 179... |
Line 232... |
| 179 |
}
|
232 |
}
|
| 180 |
}
|
233 |
}
|
| 181 |
System.out.println(sb.toString());
|
234 |
System.out.println(sb.toString());
|
| 182 |
return true;
|
235 |
return true;
|
| 183 |
}
|
236 |
}
|
| 184 |
|
237 |
|
| 185 |
/**
|
238 |
/**
|
| 186 |
* this function will read source definition and source entities, and will convert
|
239 |
* this function will read source definition and source entities, and will convert
|
| 187 |
* source entities to destination entities according to destination definitions.
|
240 |
* source entities to destination entities according to destination definitions.
|
| 188 |
*
|
241 |
*
|
| 189 |
* @return boolean
|
242 |
* @return boolean
|
| Line 1202... |
Line 1255... |
| 1202 |
|
1255 |
|
| 1203 |
FileInputStream fstream = new FileInputStream("/home/rajveer/Desktop/1");
|
1256 |
FileInputStream fstream = new FileInputStream("/home/rajveer/Desktop/1");
|
| 1204 |
DataInputStream in = new DataInputStream(fstream);
|
1257 |
DataInputStream in = new DataInputStream(fstream);
|
| 1205 |
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
1258 |
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
| 1206 |
String strLine;
|
1259 |
String strLine;
|
| 1207 |
|
1260 |
|
| 1208 |
while ((strLine = br.readLine()) != null) {
|
1261 |
while ((strLine = br.readLine()) != null) {
|
| 1209 |
long entityID = Long.parseLong(strLine);
|
1262 |
long entityID = Long.parseLong(strLine);
|
| 1210 |
String entityDBFile = sourceDbPath + "entities" + File.separator + entityID +"/entity.ser";
|
1263 |
String entityDBFile = sourceDbPath + "entities" + File.separator + entityID +"/entity.ser";
|
| 1211 |
System.out.println (entityDBFile);
|
1264 |
System.out.println (entityDBFile);
|
| 1212 |
Entity entity = (Entity)DBUtils.read(entityDBFile);
|
1265 |
Entity entity = (Entity)DBUtils.read(entityDBFile);
|
| Line 1218... |
Line 1271... |
| 1218 |
}
|
1271 |
}
|
| 1219 |
catent.add(entity);
|
1272 |
catent.add(entity);
|
| 1220 |
catEntities.put(entity.getCategoryID(), catent);
|
1273 |
catEntities.put(entity.getCategoryID(), catent);
|
| 1221 |
}
|
1274 |
}
|
| 1222 |
in.close();
|
1275 |
in.close();
|
| 1223 |
|
- |
|
| 1224 |
|
- |
|
| 1225 |
|
1276 |
|
| 1226 |
|
- |
|
| 1227 |
|
- |
|
| 1228 |
String entitiesDBFile = sourceDbPath + "entities" + File.separator + "entities.ser";
|
1277 |
String entitiesDBFile = sourceDbPath + "entities" + File.separator + "entities.ser";
|
| 1229 |
String entitiesbycategoryDBFile = sourceDbPath + "entities" + File.separator + "entitiesbycategory.ser";
|
1278 |
String entitiesbycategoryDBFile = sourceDbPath + "entities" + File.separator + "entitiesbycategory.ser";
|
| 1230 |
|
1279 |
|
| 1231 |
DBUtils.delete(entitiesDBFile);
|
1280 |
DBUtils.delete(entitiesDBFile);
|
| 1232 |
DBUtils.store(entities, entitiesDBFile);
|
1281 |
DBUtils.store(entities, entitiesDBFile);
|
| 1233 |
|
1282 |
|
| 1234 |
// Remove existing
|
1283 |
// Remove existing
|
| 1235 |
DBUtils.delete(entitiesbycategoryDBFile);
|
1284 |
DBUtils.delete(entitiesbycategoryDBFile);
|
| 1236 |
DBUtils.store(catEntities, entitiesbycategoryDBFile);
|
1285 |
DBUtils.store(catEntities, entitiesbycategoryDBFile);
|
| 1237 |
|
1286 |
|
| 1238 |
return false;
|
1287 |
return false;
|
| 1239 |
|
- |
|
| 1240 |
}
|
1288 |
}
|
| 1241 |
|
1289 |
|
| 1242 |
private boolean printDataModel() throws Exception{
|
1290 |
private boolean printDataModel() throws Exception{
|
| 1243 |
DefinitionsContainer dfc = Catalog.getInstance().getDefinitionsContainer();
|
1291 |
DefinitionsContainer dfc = Catalog.getInstance().getDefinitionsContainer();
|
| 1244 |
StringBuilder sb = new StringBuilder();
|
1292 |
StringBuilder sb = new StringBuilder();
|
| 1245 |
|
1293 |
|
| 1246 |
Map<Long, SlideDefinition> allSlideDefs = dfc.getSlideDefinitions();
|
1294 |
Map<Long, SlideDefinition> allSlideDefs = dfc.getSlideDefinitions();
|
| 1247 |
for(Long slideDefId: allSlideDefs.keySet()){
|
1295 |
for(Long slideDefId: allSlideDefs.keySet()){
|
| 1248 |
SlideDefinition slideDef = allSlideDefs.get(slideDefId);
|
1296 |
SlideDefinition slideDef = allSlideDefs.get(slideDefId);
|
| 1249 |
sb.append(slideDefId + " - " + slideDef.getLabel() + "\n");
|
1297 |
sb.append(slideDefId + " - " + slideDef.getLabel() + "\n");
|
| 1250 |
if(!slideDef.getChildrenSlideDefinitionIDs().isEmpty()){
|
1298 |
if(!slideDef.getChildrenSlideDefinitionIDs().isEmpty()){
|