| 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;
|
| 1226 |
rajveer |
21 |
import in.shop2020.metamodel.definitions.Catalog;
|
|
|
22 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
| 1070 |
chandransh |
23 |
//import in.shop2020.metamodel.definitions.OldEntityContainer;
|
| 1050 |
rajveer |
24 |
import in.shop2020.metamodel.util.CreationUtils;
|
|
|
25 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
| 1070 |
chandransh |
26 |
//import in.shop2020.metamodel.util.OldCreationUtils;
|
| 1050 |
rajveer |
27 |
import in.shop2020.storage.bdb.StorageManager;
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
/*
|
|
|
31 |
* @author rajveer
|
|
|
32 |
*
|
|
|
33 |
*
|
|
|
34 |
*/
|
|
|
35 |
|
|
|
36 |
public class ContentMigratorToBDB {
|
|
|
37 |
private String sourceDbPath;
|
|
|
38 |
private String destinationDbPath;
|
|
|
39 |
|
|
|
40 |
public static void main(String[] args) throws Exception {
|
|
|
41 |
String usage = "Usage: ContentMigrator {source db path}{destination db path}";
|
|
|
42 |
|
|
|
43 |
String sourceDbPath = null, destinationDbPath = null;
|
|
|
44 |
if(args.length < 2) {
|
|
|
45 |
System.out.println(usage);
|
|
|
46 |
System.exit(-1);
|
|
|
47 |
}else{
|
|
|
48 |
sourceDbPath = args[0];
|
|
|
49 |
destinationDbPath = args[1];
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
|
| 1153 |
rajveer |
53 |
//StorageManager.getStorageManager().close();
|
|
|
54 |
|
| 1050 |
rajveer |
55 |
ContentMigratorToBDB contentmigrator = new ContentMigratorToBDB(sourceDbPath, destinationDbPath);
|
| 8749 |
amit.gupta |
56 |
contentmigrator.migrateEntityState();
|
| 1050 |
rajveer |
57 |
//boolean result = contentmigrator.addMedia();
|
| 1069 |
rajveer |
58 |
//boolean result = contentmigrator.addLearnedFields();
|
| 1055 |
rajveer |
59 |
//boolean result = contentmigrator.migrate();
|
|
|
60 |
//System.out.println("Content migration status: "+ result);
|
| 1153 |
rajveer |
61 |
|
| 1226 |
rajveer |
62 |
//boolean result = contentmigrator.migrateEntityState();
|
| 8749 |
amit.gupta |
63 |
//boolean result = contentmigrator.migrateRemoveBorrowedCategoryIdFromSlide();
|
| 1226 |
rajveer |
64 |
//System.out.println(CreationUtils.getEntity(1000471).getSlide(130011));
|
|
|
65 |
//System.out.println(CreationUtils.getFacetValues());
|
|
|
66 |
|
| 1050 |
rajveer |
67 |
}
|
|
|
68 |
|
|
|
69 |
public ContentMigratorToBDB(String sourceDbPath, String destinationDbPath) {
|
|
|
70 |
this.sourceDbPath = sourceDbPath;
|
|
|
71 |
this.destinationDbPath = destinationDbPath;
|
|
|
72 |
}
|
| 1069 |
rajveer |
73 |
|
| 1226 |
rajveer |
74 |
|
| 1153 |
rajveer |
75 |
public boolean migrateEntityState() throws Exception{
|
|
|
76 |
Map<Long, Entity> entities = CreationUtils.getEntities();
|
|
|
77 |
for(Long entityId: entities.keySet()){
|
|
|
78 |
Entity entity = entities.get(entityId);
|
|
|
79 |
EntityState oldState = CreationUtils.getEntityState(entityId);
|
|
|
80 |
EntityState newState = new EntityState(oldState.getID(), entity.getCategoryID(), oldState.getCreatedBy());
|
|
|
81 |
|
|
|
82 |
newState.setBrand(entity.getBrand());
|
|
|
83 |
newState.setModelName(entity.getModelName());
|
|
|
84 |
newState.setModelNumber(entity.getModelNumber());
|
|
|
85 |
|
|
|
86 |
newState.setStatus(oldState.getStatus());
|
|
|
87 |
newState.setAssignedBy(oldState.getAssignedBy());
|
|
|
88 |
newState.setAssignedTo(oldState.getAssignedTo());
|
|
|
89 |
newState.setAssignedOn(oldState.getAssignedOn());
|
|
|
90 |
|
|
|
91 |
newState.setCreatedBy(oldState.getCreatedBy());
|
|
|
92 |
newState.setCreatedOn(oldState.getCreatedOn());
|
|
|
93 |
|
|
|
94 |
newState.setCompletedOn(oldState.getCompletedOn());
|
|
|
95 |
newState.setCompletedBy(oldState.getCompletedBy());
|
|
|
96 |
|
|
|
97 |
newState.setMerkedReadyBy(oldState.getMerkedReadyBy());
|
|
|
98 |
newState.setMerkedReadyOn(oldState.getMerkedReadyOn());
|
|
|
99 |
CreationUtils.updateEntityState(newState);
|
|
|
100 |
}
|
|
|
101 |
return true;
|
|
|
102 |
}
|
| 1070 |
chandransh |
103 |
// public boolean addLearnedFields() throws Exception{
|
|
|
104 |
// OldEntityContainer oldEnts = new OldEntityContainer(sourceDbPath);
|
|
|
105 |
// Map<Long, List<ExpandedBullet>> learnedBullets = oldEnts.getLearnedBullets();
|
|
|
106 |
// CreationUtils.storeLearnedBullets(learnedBullets);
|
|
|
107 |
// return true;
|
|
|
108 |
//
|
|
|
109 |
// }
|
|
|
110 |
//
|
|
|
111 |
// public boolean addMedia() throws NumberFormatException, IOException, Exception{
|
|
|
112 |
// FileInputStream fstream = new FileInputStream("/home/rajveer/Desktop/test1");
|
|
|
113 |
// DataInputStream in = new DataInputStream(fstream);
|
|
|
114 |
// BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
|
|
115 |
// String strLine;
|
|
|
116 |
//
|
|
|
117 |
// while ((strLine = br.readLine()) != null) {
|
|
|
118 |
// String[] parts = strLine.split(":");
|
|
|
119 |
// long entityID = Long.parseLong(parts[0]);
|
|
|
120 |
// long slideID = Long.parseLong(parts[1]);
|
|
|
121 |
// Entity entity = StorageManager.getStorageManager().getEntity(entityID);
|
|
|
122 |
// Map<String, Media> medias = OldCreationUtils.getRawMedia(entityID);
|
|
|
123 |
// String imageLabels = parts[2];
|
|
|
124 |
// String videoLabels = parts[3];
|
|
|
125 |
// if(!imageLabels.equalsIgnoreCase("null")){
|
|
|
126 |
// String[] labels = imageLabels.split(",");
|
|
|
127 |
// for(int i = 0; i < labels.length; i++){
|
|
|
128 |
// if(medias.containsKey(labels[i])){
|
|
|
129 |
// Media media = medias.get(labels[i]);
|
|
|
130 |
// entity.getSlide(slideID).getFreeformContent().addMedia(media);
|
|
|
131 |
// }
|
|
|
132 |
// }
|
|
|
133 |
// }
|
|
|
134 |
// if(!videoLabels.equalsIgnoreCase("null")){
|
|
|
135 |
// String[] labels = videoLabels.split(",");
|
|
|
136 |
// for(int i = 0; i < labels.length; i++){
|
|
|
137 |
// if(medias.containsKey(labels[i])){
|
|
|
138 |
// Media media = medias.get(labels[i]);
|
|
|
139 |
// entity.getSlide(slideID).getFreeformContent().addMedia(media);
|
|
|
140 |
// }
|
|
|
141 |
// }
|
|
|
142 |
// }
|
|
|
143 |
// StorageManager.getStorageManager().updateEntity(entity);
|
|
|
144 |
// }
|
|
|
145 |
// in.close();
|
|
|
146 |
// return true;
|
|
|
147 |
//}
|
| 1069 |
rajveer |
148 |
|
| 1050 |
rajveer |
149 |
/**
|
|
|
150 |
* this function will read source definition and source entities, and will convert
|
|
|
151 |
* source entities to destination entities according to destination definitions.
|
|
|
152 |
*
|
|
|
153 |
* @return boolean
|
|
|
154 |
* @throws Exception
|
|
|
155 |
*/
|
| 1070 |
chandransh |
156 |
// public boolean migrate() throws Exception{
|
|
|
157 |
// OldEntityContainer sourceEnts = new OldEntityContainer(sourceDbPath);
|
|
|
158 |
//
|
|
|
159 |
// StringBuilder sb = new StringBuilder();
|
|
|
160 |
// Map<Long, Entity> entities = sourceEnts.getEntities();
|
|
|
161 |
// for(Long entityId: entities.keySet()){
|
|
|
162 |
// Entity entity = OldCreationUtils.getEntity(entityId);
|
|
|
163 |
// if(entity.getID() == 0){
|
|
|
164 |
// continue;
|
|
|
165 |
// }
|
|
|
166 |
// Entity newEntity = new Entity(entity.getID(), entity.getCategoryID());
|
|
|
167 |
// newEntity.setBrand(entity.getBrand());
|
|
|
168 |
// newEntity.setModelName(entity.getModelName());
|
|
|
169 |
// newEntity.setModelNumber(entity.getModelNumber());
|
|
|
170 |
//
|
|
|
171 |
// newEntity.setSlideSequence(OldCreationUtils.getSlideSequence(entity.getID()));
|
|
|
172 |
//
|
|
|
173 |
// List<Slide> slides = entity.getSlides();
|
|
|
174 |
// if(slides!=null){
|
|
|
175 |
// for(Slide slide: slides){
|
|
|
176 |
// FreeformContent ffc = slide.getFreeformContent();
|
|
|
177 |
// //sb.append(entityId+ ":" + slide.getSlideDefinitionID() + ":"+ ffc.getFreeformTexts()+"\n");
|
|
|
178 |
// FreeformContent newFfc = new FreeformContent();
|
|
|
179 |
// newFfc.setFreeformTexts(ffc.getFreeformTexts());
|
|
|
180 |
// slide.setFreeformContent(newFfc);
|
|
|
181 |
// //if(ffc.getAllLabels()!=null && !ffc.getAllLabels().isEmpty()){
|
|
|
182 |
// //sb.append(entity.getID() + ":" + slide.getSlideDefinitionID() + ":" + ffc.getAllLabels() + "\n");
|
|
|
183 |
// //sb.append(entity.getID() + ":" + slide.getSlideDefinitionID() + ":" + ffc.getImageLabels() + ":" + ffc.getYoutubeLabels() + "\n");
|
|
|
184 |
// //System.out.println(entity.getID() + ":" + slide.getSlideDefinitionID() + ":" + ffc.getImageLabels() + ":" + ffc.getYoutubeLabels());
|
|
|
185 |
//// System.out.println("some image found");
|
|
|
186 |
//// System.out.println(ffc.getImageLabels());
|
|
|
187 |
//// System.out.println(ffc.getYoutubeLabels());
|
|
|
188 |
// //}
|
|
|
189 |
// //System.out.println(ffc.getImageLabels());
|
|
|
190 |
// //System.out.println(ffc.getYoutubeLabels());
|
|
|
191 |
// //FreeformContent newFfc = new FreeformContent();
|
|
|
192 |
// //newFfc.setFreeformTexts(ffc.getFreeformTexts());
|
|
|
193 |
// }
|
|
|
194 |
// }
|
|
|
195 |
// newEntity.setSlides(slides);
|
|
|
196 |
// EntityState entityMetadata = new EntityState(entityId, "admin");
|
|
|
197 |
// StorageManager.getStorageManager().createEntity(newEntity, entityMetadata);
|
|
|
198 |
//
|
|
|
199 |
// //System.out.println(StorageManager.getStorageManager().getStorageManager().getEntity(entityId).getSlide(130033).getFreeformContent().getFreeformTexts());
|
|
|
200 |
//
|
|
|
201 |
// //StorageManager.getStorageManager().close();
|
|
|
202 |
// //System.out.println("Entity id is" + entity.getID());
|
|
|
203 |
// }
|
|
|
204 |
//
|
|
|
205 |
// StorageManager.getStorageManager().close();
|
|
|
206 |
// //System.out.println(sb.toString());
|
|
|
207 |
// return true;
|
|
|
208 |
// }
|
| 1050 |
rajveer |
209 |
}
|