| 10 |
shop2020 |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.metamodel.util;
|
|
|
5 |
|
| 16 |
naveen |
6 |
import in.shop2020.metamodel.definitions.BulletDefinition;
|
| 45 |
naveen |
7 |
import in.shop2020.metamodel.definitions.Catalog;
|
| 10 |
shop2020 |
8 |
import in.shop2020.metamodel.definitions.Category;
|
| 57 |
naveen |
9 |
import in.shop2020.metamodel.definitions.CategoryFacetDefinition;
|
| 10 |
shop2020 |
10 |
import in.shop2020.metamodel.definitions.CategorySlideDefinition;
|
| 16 |
naveen |
11 |
import in.shop2020.metamodel.definitions.CompositeDefinition;
|
|
|
12 |
import in.shop2020.metamodel.definitions.CompositePartDefinition;
|
|
|
13 |
import in.shop2020.metamodel.definitions.DatatypeDefinition;
|
| 45 |
naveen |
14 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
| 10 |
shop2020 |
15 |
import in.shop2020.metamodel.definitions.EditorialImportance;
|
| 16 |
naveen |
16 |
import in.shop2020.metamodel.definitions.EnumDefinition;
|
|
|
17 |
import in.shop2020.metamodel.definitions.EnumValue;
|
| 57 |
naveen |
18 |
import in.shop2020.metamodel.definitions.FacetDefinition;
|
| 16 |
naveen |
19 |
import in.shop2020.metamodel.definitions.FeatureDefinition;
|
| 61 |
naveen |
20 |
import in.shop2020.metamodel.definitions.RuleDefinition;
|
| 16 |
naveen |
21 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
|
|
22 |
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
|
| 10 |
shop2020 |
23 |
import in.shop2020.metamodel.definitions.Unit;
|
| 57 |
naveen |
24 |
import in.shop2020.metamodel.jaxb.core.BulletDefinitionType;
|
|
|
25 |
import in.shop2020.metamodel.jaxb.core.CategorySlideDefinitionType;
|
|
|
26 |
import in.shop2020.metamodel.jaxb.core.CategoryType;
|
|
|
27 |
import in.shop2020.metamodel.jaxb.core.CompositeDefinitionType;
|
|
|
28 |
import in.shop2020.metamodel.jaxb.core.CompositePartDefinitionType;
|
|
|
29 |
import in.shop2020.metamodel.jaxb.core.DatatypeDefinitionType;
|
|
|
30 |
import in.shop2020.metamodel.jaxb.core.DefinitionType;
|
|
|
31 |
import in.shop2020.metamodel.jaxb.core.EditorialImportanceType;
|
|
|
32 |
import in.shop2020.metamodel.jaxb.core.EnumDefinitionType;
|
|
|
33 |
import in.shop2020.metamodel.jaxb.core.EnumValueType;
|
|
|
34 |
import in.shop2020.metamodel.jaxb.core.FeatureDefinitionType;
|
|
|
35 |
import in.shop2020.metamodel.jaxb.core.SlideDefinitionType;
|
|
|
36 |
import in.shop2020.metamodel.jaxb.core.SlideFeatureDefinitionType;
|
|
|
37 |
import in.shop2020.metamodel.jaxb.core.UnitType;
|
| 61 |
naveen |
38 |
import in.shop2020.metamodel.jaxb.facets.CategoryFacetDefinitionType;
|
|
|
39 |
import in.shop2020.metamodel.jaxb.facets.FacetDefinitionType;
|
| 57 |
naveen |
40 |
import in.shop2020.metamodel.jaxb.facets.IRDefinitionType;
|
| 61 |
naveen |
41 |
import in.shop2020.metamodel.jaxb.facets.RuleDefinitionType;
|
| 18 |
naveen |
42 |
import in.shop2020.util.Utils;
|
| 10 |
shop2020 |
43 |
|
|
|
44 |
import java.io.FileInputStream;
|
| 16 |
naveen |
45 |
import java.util.ArrayList;
|
| 10 |
shop2020 |
46 |
import java.util.HashMap;
|
|
|
47 |
import java.util.Iterator;
|
|
|
48 |
import java.util.List;
|
|
|
49 |
import java.util.Map;
|
| 24 |
naveen |
50 |
import java.util.TreeMap;
|
| 10 |
shop2020 |
51 |
|
|
|
52 |
import javax.xml.bind.JAXBContext;
|
|
|
53 |
import javax.xml.bind.JAXBElement;
|
|
|
54 |
import javax.xml.bind.Unmarshaller;
|
|
|
55 |
|
|
|
56 |
import org.apache.commons.lang.ArrayUtils;
|
|
|
57 |
import org.apache.commons.lang.StringUtils;
|
|
|
58 |
|
|
|
59 |
/**
|
| 51 |
naveen |
60 |
* Command line utility that imports model properties defined in XML
|
|
|
61 |
*
|
| 17 |
naveen |
62 |
* MM - Meta-Model Tool
|
| 10 |
shop2020 |
63 |
*
|
| 51 |
naveen |
64 |
* It can be used to do following things
|
|
|
65 |
*
|
|
|
66 |
* - Import
|
|
|
67 |
* - Datatype definitions
|
|
|
68 |
* - Feature definitions
|
|
|
69 |
* - Slide definitions
|
|
|
70 |
* - Categories
|
| 63 |
naveen |
71 |
* - Facet Definition
|
|
|
72 |
* - Category Facet Definition
|
|
|
73 |
* - IR Data Rules
|
|
|
74 |
* - IR Meta-data Rules
|
| 51 |
naveen |
75 |
*
|
|
|
76 |
* - Show
|
|
|
77 |
* - Datatype definitions
|
|
|
78 |
* - Feature definitions
|
|
|
79 |
* - Slide definitions
|
|
|
80 |
* - Categories
|
| 63 |
naveen |
81 |
* - Facet Definition
|
|
|
82 |
* - Category Facet Definition
|
|
|
83 |
* - IR Data Rules
|
|
|
84 |
* - IR Meta-data Rules
|
| 51 |
naveen |
85 |
*
|
|
|
86 |
* - Show all definition objects that define a category
|
|
|
87 |
*
|
|
|
88 |
*
|
| 10 |
shop2020 |
89 |
* @author naveen
|
|
|
90 |
*
|
|
|
91 |
*/
|
|
|
92 |
public class MM {
|
| 49 |
naveen |
93 |
/**
|
|
|
94 |
*
|
|
|
95 |
*/
|
| 16 |
naveen |
96 |
public static final String DEFINITIONS_SRC_PATH =
|
|
|
97 |
"/home/naveen/workspace/eclipse/webapp/src/xml/model/";
|
| 34 |
naveen |
98 |
|
| 43 |
naveen |
99 |
// LOCAL
|
| 49 |
naveen |
100 |
/**
|
|
|
101 |
*
|
|
|
102 |
*/
|
| 16 |
naveen |
103 |
public static final String DEFINITIONS_DB_PATH =
|
| 26 |
naveen |
104 |
"/home/naveen/workspace/eclipse/db/definitions/";
|
| 49 |
naveen |
105 |
|
|
|
106 |
/**
|
|
|
107 |
*
|
|
|
108 |
*/
|
| 16 |
naveen |
109 |
public static final String ENTITIES_DB_PATH =
|
| 26 |
naveen |
110 |
"/home/naveen/workspace/eclipse/db/entities/";
|
| 10 |
shop2020 |
111 |
|
| 34 |
naveen |
112 |
/** WEB
|
|
|
113 |
public static final String DEFINITIONS_DB_PATH =
|
|
|
114 |
"/var/lib/tomcat6/webapps/shop2020/db/definitions/";
|
|
|
115 |
public static final String ENTITIES_DB_PATH =
|
|
|
116 |
"/var/lib/tomcat6/webapps/shop2020/db/entities/";
|
|
|
117 |
*/
|
| 43 |
naveen |
118 |
|
|
|
119 |
/** Validation tool
|
|
|
120 |
public static final String DEFINITIONS_DB_PATH =
|
|
|
121 |
"./db/definitions/";
|
|
|
122 |
public static final String ENTITIES_DB_PATH =
|
|
|
123 |
"./db/entities/";
|
|
|
124 |
*/
|
| 34 |
naveen |
125 |
|
| 49 |
naveen |
126 |
/**
|
|
|
127 |
*
|
|
|
128 |
*/
|
| 10 |
shop2020 |
129 |
private String definitionSetName;
|
| 49 |
naveen |
130 |
|
|
|
131 |
/**
|
|
|
132 |
*
|
|
|
133 |
*/
|
| 10 |
shop2020 |
134 |
private String srcFile;
|
| 49 |
naveen |
135 |
|
|
|
136 |
/**
|
|
|
137 |
*
|
|
|
138 |
*/
|
| 10 |
shop2020 |
139 |
private String dbFile;
|
|
|
140 |
|
|
|
141 |
/**
|
| 61 |
naveen |
142 |
* Usage: MM [show|import|showcategory] [units|datatypedefinitions|featuredefinitions|slidedefinitions|categories|facetdefinitions|categoryfacetdefinitions|irdatarules|irmetadatarules] {Category ID}
|
| 51 |
naveen |
143 |
*
|
| 10 |
shop2020 |
144 |
* @param args
|
|
|
145 |
*/
|
|
|
146 |
public static void main(String[] args) throws Exception {
|
| 16 |
naveen |
147 |
String[] definitionSetNames = new String[] {"units",
|
|
|
148 |
"datatypedefinitions", "featuredefinitions", "slidedefinitions",
|
| 61 |
naveen |
149 |
"categories", "facetdefinitions", "categoryfacetdefinitions",
|
|
|
150 |
"irdatarules", "irmetadatarules"};
|
| 10 |
shop2020 |
151 |
|
| 45 |
naveen |
152 |
String[] commands = new String[] {"show", "import", "showcategory"};
|
| 10 |
shop2020 |
153 |
|
| 16 |
naveen |
154 |
String usage = "Usage: MM ["+ StringUtils.join(commands, "|") +"] ["+
|
| 45 |
naveen |
155 |
StringUtils.join(definitionSetNames, "|") + "] {Category ID}";
|
| 16 |
naveen |
156 |
|
| 10 |
shop2020 |
157 |
if(args.length < 2) {
|
|
|
158 |
System.out.println(usage);
|
|
|
159 |
System.exit(-1);
|
|
|
160 |
}
|
| 42 |
naveen |
161 |
Utils.info("MM "+ args[0] + " " + args[1]);
|
| 17 |
naveen |
162 |
|
| 10 |
shop2020 |
163 |
String inputCommand = args[0];
|
|
|
164 |
|
|
|
165 |
if(!ArrayUtils.contains(commands, inputCommand)) {
|
|
|
166 |
System.out.println(usage);
|
|
|
167 |
System.exit(-1);
|
|
|
168 |
}
|
|
|
169 |
|
| 45 |
naveen |
170 |
if(inputCommand.equals("show") || inputCommand.endsWith("import")) {
|
|
|
171 |
String inputDefinitionSet = args[1];
|
|
|
172 |
if(!ArrayUtils.contains(definitionSetNames, inputDefinitionSet)) {
|
|
|
173 |
System.out.println(usage);
|
|
|
174 |
System.exit(-1);
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
MM mm = new MM(inputDefinitionSet);
|
|
|
178 |
if(inputCommand.equals("import")) {
|
|
|
179 |
mm.importDefinitionSet();
|
|
|
180 |
}
|
|
|
181 |
else if(inputCommand.equals("show")) {
|
|
|
182 |
mm.showDefinitionSet();
|
|
|
183 |
}
|
| 10 |
shop2020 |
184 |
}
|
|
|
185 |
|
| 45 |
naveen |
186 |
if(inputCommand.equals("showcategory")) {
|
|
|
187 |
String categoryID = args[1];
|
|
|
188 |
long catID = 0;
|
|
|
189 |
try {
|
|
|
190 |
catID = Long.parseLong(categoryID);
|
|
|
191 |
}
|
|
|
192 |
catch (NumberFormatException nfe) {
|
|
|
193 |
System.out.println("Invalid category ID");
|
|
|
194 |
System.exit(-1);
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
MM mm = new MM();
|
|
|
198 |
mm.showCategory(catID);
|
| 10 |
shop2020 |
199 |
}
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
/**
|
|
|
203 |
*
|
| 45 |
naveen |
204 |
*/
|
|
|
205 |
public MM() {
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
/**
|
|
|
209 |
*
|
| 10 |
shop2020 |
210 |
* @param definitionSet
|
|
|
211 |
*/
|
|
|
212 |
public MM(String definitionSetName) {
|
|
|
213 |
this.definitionSetName = definitionSetName;
|
|
|
214 |
this.srcFile = DEFINITIONS_SRC_PATH + this.definitionSetName + ".xml";
|
|
|
215 |
this.dbFile = DEFINITIONS_DB_PATH + this.definitionSetName + ".ser";
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
/**
|
|
|
219 |
*
|
| 45 |
naveen |
220 |
* @param categoryID
|
|
|
221 |
* @throws Exception
|
| 10 |
shop2020 |
222 |
*/
|
| 45 |
naveen |
223 |
public void showCategory(long categoryID) throws Exception {
|
|
|
224 |
DefinitionsContainer defs =
|
|
|
225 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
226 |
|
|
|
227 |
ExpandedCategory expCategory = defs.getExpandedCategory(categoryID);
|
|
|
228 |
|
|
|
229 |
Utils.info(expCategory);
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
/**
|
|
|
233 |
*
|
|
|
234 |
*/
|
| 10 |
shop2020 |
235 |
@SuppressWarnings("unchecked")
|
|
|
236 |
public void importDefinitionSet() throws Exception {
|
| 57 |
naveen |
237 |
String type = "core";
|
|
|
238 |
if(this.definitionSetName.equals("facetdefinitions") ||
|
| 61 |
naveen |
239 |
this.definitionSetName.equals("categoryfacetdefinitions") ||
|
|
|
240 |
this.definitionSetName.equals("irdatarules") ||
|
|
|
241 |
this.definitionSetName.equals("irmetadatarules")) {
|
| 57 |
naveen |
242 |
type = "facets";
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
Object oDefType = this.unmarshallSrcFile(this.srcFile, type);
|
|
|
246 |
DefinitionType defType = null;
|
|
|
247 |
IRDefinitionType irDefType = null;
|
|
|
248 |
|
|
|
249 |
if(type.equals("core")) {
|
|
|
250 |
defType = (DefinitionType)oDefType;
|
|
|
251 |
}
|
|
|
252 |
else if (type.equals("facets")) {
|
|
|
253 |
irDefType = (IRDefinitionType)oDefType;
|
|
|
254 |
}
|
|
|
255 |
|
| 16 |
naveen |
256 |
Object objectToStore = null;
|
| 10 |
shop2020 |
257 |
|
| 57 |
naveen |
258 |
// CORE
|
|
|
259 |
|
| 10 |
shop2020 |
260 |
// Units
|
|
|
261 |
if(this.definitionSetName.equals("units")) {
|
|
|
262 |
Map unitsMap = this.convertUnits(defType);
|
| 16 |
naveen |
263 |
objectToStore = unitsMap;
|
| 10 |
shop2020 |
264 |
}
|
|
|
265 |
|
|
|
266 |
// Categories
|
|
|
267 |
else if(this.definitionSetName.equals("categories")) {
|
|
|
268 |
Map<Long, Category> categoriesMap = new HashMap<Long, Category>();
|
|
|
269 |
Category root = this.convertCategories(defType, categoriesMap);
|
| 42 |
naveen |
270 |
//Utils.info(categoriesMap);
|
|
|
271 |
//Utils.info(root);
|
| 10 |
shop2020 |
272 |
//System.exit(0);
|
|
|
273 |
|
|
|
274 |
// Tree
|
| 16 |
naveen |
275 |
String categoryTreeDBFile = DEFINITIONS_DB_PATH + "categorytree" +
|
|
|
276 |
".ser";
|
|
|
277 |
|
| 10 |
shop2020 |
278 |
if(root != null) {
|
| 17 |
naveen |
279 |
DBUtils.store(root, categoryTreeDBFile);
|
| 10 |
shop2020 |
280 |
}
|
|
|
281 |
|
|
|
282 |
// Map
|
| 16 |
naveen |
283 |
objectToStore = categoriesMap;
|
| 10 |
shop2020 |
284 |
}
|
| 16 |
naveen |
285 |
|
|
|
286 |
// Datatype Definitions
|
|
|
287 |
else if(this.definitionSetName.equals("datatypedefinitions")) {
|
| 24 |
naveen |
288 |
Map<Long, DatatypeDefinition> datatypeDefsMap =
|
|
|
289 |
this.convertDatatypeDefinition(defType);
|
| 16 |
naveen |
290 |
|
| 24 |
naveen |
291 |
// Store enum value id to value map separately
|
|
|
292 |
String enumValueDBFile = DEFINITIONS_DB_PATH + "enumvalues" +
|
|
|
293 |
".ser";
|
|
|
294 |
|
|
|
295 |
// RE-VISIT - May not be optimal
|
|
|
296 |
Map<Long, EnumValue> enumValuesMap = new TreeMap<Long, EnumValue>();
|
|
|
297 |
for(Long datatypeDefID : datatypeDefsMap.keySet()) {
|
|
|
298 |
DatatypeDefinition datatypeDef =
|
|
|
299 |
datatypeDefsMap.get(datatypeDefID);
|
|
|
300 |
|
|
|
301 |
if(datatypeDef instanceof EnumDefinition) {
|
|
|
302 |
List<EnumValue> enumValues =
|
|
|
303 |
((EnumDefinition) datatypeDef).getEnumValues();
|
|
|
304 |
|
|
|
305 |
for(EnumValue enumValue : enumValues) {
|
|
|
306 |
enumValuesMap.put(new Long(enumValue.getID()),
|
|
|
307 |
enumValue);
|
|
|
308 |
}
|
|
|
309 |
}
|
|
|
310 |
}
|
| 42 |
naveen |
311 |
Utils.info("enumValuesMap=" + enumValuesMap);
|
| 24 |
naveen |
312 |
DBUtils.store(enumValuesMap, enumValueDBFile);
|
|
|
313 |
|
| 16 |
naveen |
314 |
objectToStore = datatypeDefsMap;
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
// Feature Definitions
|
|
|
318 |
else if(this.definitionSetName.equals("featuredefinitions")) {
|
|
|
319 |
Map featureDefsMap = this.convertFeatureDefinitions(defType);
|
|
|
320 |
|
|
|
321 |
objectToStore = featureDefsMap;
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
// Slide Definitions
|
|
|
325 |
else if(this.definitionSetName.equals("slidedefinitions")) {
|
|
|
326 |
Map slideDefsMap = this.convertSlideDefinitions(defType);
|
|
|
327 |
|
|
|
328 |
objectToStore = slideDefsMap;
|
|
|
329 |
}
|
|
|
330 |
|
| 57 |
naveen |
331 |
// FACETS
|
|
|
332 |
|
|
|
333 |
// Facet Definitions
|
|
|
334 |
else if(this.definitionSetName.equals("facetdefinitions")) {
|
|
|
335 |
Map facetDefsMap = this.convertFacetDefinitions(irDefType);
|
|
|
336 |
|
|
|
337 |
objectToStore = facetDefsMap;
|
|
|
338 |
}
|
|
|
339 |
|
|
|
340 |
|
|
|
341 |
// Category Facet Definitions
|
|
|
342 |
else if(this.definitionSetName.equals("categoryfacetdefinitions")) {
|
|
|
343 |
Map categoryFacetDefsMap =
|
|
|
344 |
this.convertCategoryFacetDefinitions(irDefType);
|
|
|
345 |
|
|
|
346 |
objectToStore = categoryFacetDefsMap;
|
|
|
347 |
}
|
|
|
348 |
|
| 61 |
naveen |
349 |
// IR Data Rules
|
|
|
350 |
else if(this.definitionSetName.equals("irdatarules")) {
|
|
|
351 |
Map irdataRuleDefsMap =
|
|
|
352 |
this.convertRuleDefinitions(irDefType);
|
|
|
353 |
|
|
|
354 |
objectToStore = irdataRuleDefsMap;
|
|
|
355 |
}
|
|
|
356 |
|
|
|
357 |
// IR Meta-Data Rules
|
|
|
358 |
else if(this.definitionSetName.equals("irmetadatarules")) {
|
|
|
359 |
Map irmetadataRuleDefsMap =
|
|
|
360 |
this.convertRuleDefinitions(irDefType);
|
|
|
361 |
|
|
|
362 |
objectToStore = irmetadataRuleDefsMap;
|
|
|
363 |
}
|
|
|
364 |
|
| 16 |
naveen |
365 |
if(objectToStore != null) {
|
| 17 |
naveen |
366 |
DBUtils.store(objectToStore, this.dbFile);
|
| 16 |
naveen |
367 |
}
|
| 10 |
shop2020 |
368 |
}
|
|
|
369 |
|
|
|
370 |
/**
|
|
|
371 |
*
|
|
|
372 |
*/
|
|
|
373 |
public void showDefinitionSet() throws Exception {
|
| 17 |
naveen |
374 |
Object obj = DBUtils.read(this.dbFile);
|
| 42 |
naveen |
375 |
Utils.info(obj.toString());
|
| 10 |
shop2020 |
376 |
|
|
|
377 |
if(this.definitionSetName.equals("categories")) {
|
| 16 |
naveen |
378 |
String categoryTreeDBFile = DEFINITIONS_DB_PATH + "categorytree" +
|
|
|
379 |
".ser";
|
|
|
380 |
|
| 17 |
naveen |
381 |
Category root = (Category)DBUtils.read(categoryTreeDBFile);
|
| 42 |
naveen |
382 |
Utils.info(root.toString());
|
|
|
383 |
//Utils.info("root.getChildrenCategory().size: " +
|
| 18 |
naveen |
384 |
// root.getChildrenCategory().size());
|
| 10 |
shop2020 |
385 |
}
|
|
|
386 |
}
|
|
|
387 |
|
|
|
388 |
/**
|
|
|
389 |
*
|
| 57 |
naveen |
390 |
* @param defType
|
|
|
391 |
* @return
|
|
|
392 |
*/
|
| 61 |
naveen |
393 |
private Map<Long, RuleDefinition> convertRuleDefinitions(
|
|
|
394 |
IRDefinitionType defType) {
|
|
|
395 |
Map<Long, RuleDefinition> idRuleDef =
|
|
|
396 |
new TreeMap<Long, RuleDefinition>();
|
|
|
397 |
|
|
|
398 |
List<RuleDefinitionType> jaxbRuleDefs = defType.getRuleDefinition();
|
|
|
399 |
|
|
|
400 |
for(RuleDefinitionType jaxbRuleDef : jaxbRuleDefs) {
|
|
|
401 |
long id = jaxbRuleDef.getID();
|
|
|
402 |
String script = jaxbRuleDef.getScript();
|
|
|
403 |
|
|
|
404 |
RuleDefinition ruleDef = new RuleDefinition(id, script);
|
|
|
405 |
ruleDef.setDescription(jaxbRuleDef.getDescription());
|
|
|
406 |
|
|
|
407 |
idRuleDef.put(new Long(id), ruleDef);
|
|
|
408 |
}
|
|
|
409 |
|
|
|
410 |
Utils.info("idRuleDef=" + idRuleDef);
|
|
|
411 |
return idRuleDef;
|
|
|
412 |
}
|
|
|
413 |
|
|
|
414 |
/**
|
|
|
415 |
*
|
|
|
416 |
* @param defType
|
|
|
417 |
* @return
|
|
|
418 |
*/
|
| 57 |
naveen |
419 |
private Map<Long, FacetDefinition> convertFacetDefinitions(
|
|
|
420 |
IRDefinitionType defType) {
|
| 61 |
naveen |
421 |
List<FacetDefinitionType> jaxbFacetDefs = defType.getFacetDefinition();
|
|
|
422 |
|
|
|
423 |
Map<Long, FacetDefinition> idFacetDefs =
|
|
|
424 |
new TreeMap<Long, FacetDefinition>();
|
|
|
425 |
|
|
|
426 |
for(FacetDefinitionType jaxbFacetDef : jaxbFacetDefs) {
|
|
|
427 |
long id = jaxbFacetDef.getID();
|
|
|
428 |
String target = jaxbFacetDef.getTarget();
|
|
|
429 |
|
|
|
430 |
FacetDefinition facetDef = new FacetDefinition(id, target);
|
|
|
431 |
|
|
|
432 |
if(jaxbFacetDef.getFeatureDefinitionID() != null) {
|
|
|
433 |
long featureDefID = jaxbFacetDef.getFeatureDefinitionID();
|
|
|
434 |
facetDef.setFeatureDefinitionID(featureDefID);
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
if(jaxbFacetDef.getSlideDefinitionID() != null) {
|
|
|
438 |
long slideDefID = jaxbFacetDef.getSlideDefinitionID();
|
|
|
439 |
facetDef.setSlideDefinitionID(slideDefID);
|
|
|
440 |
}
|
|
|
441 |
|
| 62 |
naveen |
442 |
long irDataRuleID = jaxbFacetDef.getIRDataRuleID();
|
|
|
443 |
facetDef.setIrDataRuleID(irDataRuleID);
|
| 61 |
naveen |
444 |
|
| 62 |
naveen |
445 |
long irMetaDataRuleID = jaxbFacetDef.getIRMetaDataRuleID();
|
|
|
446 |
facetDef.setIrMetaDataRuleID(irMetaDataRuleID);
|
|
|
447 |
|
| 61 |
naveen |
448 |
facetDef.setDescription(jaxbFacetDef.getDescription());
|
|
|
449 |
|
|
|
450 |
idFacetDefs.put(new Long(id), facetDef);
|
|
|
451 |
}
|
|
|
452 |
Utils.info("idFacetDefs=" + idFacetDefs);
|
|
|
453 |
return idFacetDefs;
|
| 57 |
naveen |
454 |
}
|
|
|
455 |
|
|
|
456 |
/**
|
|
|
457 |
*
|
|
|
458 |
* @param defType
|
|
|
459 |
* @return
|
| 61 |
naveen |
460 |
* @throws Exception
|
| 57 |
naveen |
461 |
*/
|
|
|
462 |
private Map<Long, CategoryFacetDefinition> convertCategoryFacetDefinitions(
|
| 61 |
naveen |
463 |
IRDefinitionType defType) throws Exception {
|
|
|
464 |
List<CategoryFacetDefinitionType> jaxbCategoryFacetDefs =
|
|
|
465 |
defType.getCategoryFacetDefinition();
|
|
|
466 |
|
|
|
467 |
Map<Long, CategoryFacetDefinition> idCategoryFacetDefs =
|
|
|
468 |
new TreeMap<Long, CategoryFacetDefinition>();
|
|
|
469 |
|
|
|
470 |
for(CategoryFacetDefinitionType jaxbCategoryFacetDef :
|
|
|
471 |
jaxbCategoryFacetDefs) {
|
|
|
472 |
long categoryID = jaxbCategoryFacetDef.getCategoryID();
|
|
|
473 |
|
| 62 |
naveen |
474 |
List<Long> jaxbFacetDefIDs =
|
|
|
475 |
jaxbCategoryFacetDef.getFacetDefinitionID();
|
| 61 |
naveen |
476 |
|
|
|
477 |
CategoryFacetDefinition categoryFacetDef =
|
|
|
478 |
new CategoryFacetDefinition(categoryID);
|
|
|
479 |
|
| 62 |
naveen |
480 |
categoryFacetDef.setFacetDefinitionIDs(jaxbFacetDefIDs);
|
| 61 |
naveen |
481 |
|
|
|
482 |
idCategoryFacetDefs.put(new Long(categoryID), categoryFacetDef);
|
|
|
483 |
}
|
|
|
484 |
|
|
|
485 |
// Append parent's facets
|
|
|
486 |
// Go only one level for now
|
|
|
487 |
// Categories need to be imported first
|
|
|
488 |
DefinitionsContainer defs =
|
|
|
489 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
490 |
|
|
|
491 |
for(Long categoryID : idCategoryFacetDefs.keySet()) {
|
|
|
492 |
Category category = defs.getCategory(categoryID.longValue());
|
|
|
493 |
Category parentCategory = category.getParentCategory();
|
|
|
494 |
|
|
|
495 |
if(parentCategory != null) {
|
|
|
496 |
long parentCategoryID = parentCategory.getID();
|
|
|
497 |
|
|
|
498 |
CategoryFacetDefinition parentCategoryFacetDef =
|
|
|
499 |
idCategoryFacetDefs.get(new Long(parentCategoryID));
|
|
|
500 |
|
|
|
501 |
if(parentCategoryFacetDef != null) {
|
|
|
502 |
List<Long> parentsFacetIDs =
|
| 62 |
naveen |
503 |
parentCategoryFacetDef.getFacetDefinitionIDs();
|
| 61 |
naveen |
504 |
|
|
|
505 |
if(parentsFacetIDs != null) {
|
|
|
506 |
CategoryFacetDefinition categoryFacetDef =
|
|
|
507 |
idCategoryFacetDefs.get(categoryID);
|
|
|
508 |
|
| 62 |
naveen |
509 |
categoryFacetDef.appendFacetDefinitionIDs(
|
|
|
510 |
parentsFacetIDs);
|
| 61 |
naveen |
511 |
}
|
|
|
512 |
}
|
|
|
513 |
}
|
|
|
514 |
}
|
|
|
515 |
|
|
|
516 |
Utils.info("idCategoryFacetDefs=" + idCategoryFacetDefs);
|
|
|
517 |
return idCategoryFacetDefs;
|
| 57 |
naveen |
518 |
}
|
|
|
519 |
|
|
|
520 |
/**
|
|
|
521 |
*
|
| 10 |
shop2020 |
522 |
* @return Map
|
|
|
523 |
*/
|
| 16 |
naveen |
524 |
private Map<Long, SlideDefinition> convertSlideDefinitions(
|
|
|
525 |
DefinitionType defType) {
|
|
|
526 |
|
|
|
527 |
Map<Long, SlideDefinition> defs =
|
|
|
528 |
new HashMap<Long, SlideDefinition>();
|
|
|
529 |
|
|
|
530 |
List<SlideDefinitionType> jaxbDefs = defType.getSlideDefinition();
|
|
|
531 |
Iterator<SlideDefinitionType> itjaxbDefs = jaxbDefs.iterator();
|
|
|
532 |
|
|
|
533 |
// Slide definitions
|
|
|
534 |
while(itjaxbDefs.hasNext()) {
|
|
|
535 |
SlideDefinitionType jaxbDef = itjaxbDefs.next();
|
|
|
536 |
|
| 42 |
naveen |
537 |
Utils.info("Slide label=" + jaxbDef.getLabel());
|
| 16 |
naveen |
538 |
SlideDefinition def = new SlideDefinition(jaxbDef.getID(),
|
|
|
539 |
jaxbDef.getLabel());
|
|
|
540 |
def.setDescription(jaxbDef.getDescription());
|
|
|
541 |
|
| 42 |
naveen |
542 |
// Children Slides
|
|
|
543 |
Utils.info("jaxbDef.getChildSlideID=" + jaxbDef.getChildSlideID());
|
|
|
544 |
def.setChildrenSlideDefinitionIDs(jaxbDef.getChildSlideID());
|
|
|
545 |
|
| 16 |
naveen |
546 |
// Slide Feature Definition
|
|
|
547 |
List<SlideFeatureDefinitionType> jaxbSlideFeatureDefs =
|
|
|
548 |
jaxbDef.getSlideFeatureDefinition();
|
|
|
549 |
|
|
|
550 |
if(jaxbSlideFeatureDefs != null) {
|
|
|
551 |
def.setSlideFeatureDefinitions((
|
|
|
552 |
this.convertSlideFeatureDefinitions(
|
|
|
553 |
jaxbSlideFeatureDefs)));
|
|
|
554 |
}
|
| 42 |
naveen |
555 |
Utils.info("def=" + def);
|
| 16 |
naveen |
556 |
|
|
|
557 |
defs.put(new Long(jaxbDef.getID()), def);
|
|
|
558 |
}
|
|
|
559 |
|
|
|
560 |
return defs;
|
|
|
561 |
}
|
|
|
562 |
|
|
|
563 |
/**
|
|
|
564 |
*
|
|
|
565 |
* @param jaxbDefs
|
|
|
566 |
* @return List<SlideFeatureDefinition>
|
|
|
567 |
*/
|
|
|
568 |
private List<SlideFeatureDefinition> convertSlideFeatureDefinitions(
|
|
|
569 |
List<SlideFeatureDefinitionType> jaxbDefs) {
|
|
|
570 |
|
|
|
571 |
List<SlideFeatureDefinition> defs =
|
|
|
572 |
new ArrayList<SlideFeatureDefinition>();
|
|
|
573 |
|
|
|
574 |
Iterator<SlideFeatureDefinitionType> itjaxbDefs = jaxbDefs.iterator();
|
|
|
575 |
|
|
|
576 |
// Slide-feature definitions
|
|
|
577 |
while(itjaxbDefs.hasNext()) {
|
|
|
578 |
SlideFeatureDefinitionType jaxbDef = itjaxbDefs.next();
|
|
|
579 |
SlideFeatureDefinition def = new SlideFeatureDefinition(
|
|
|
580 |
jaxbDef.getFeatureDefinitionID());
|
|
|
581 |
|
|
|
582 |
def.setEditorialImportance(this.convertEditorialImportance(
|
|
|
583 |
jaxbDef.getEditorialImportance()));
|
|
|
584 |
|
|
|
585 |
def.setDescription(jaxbDef.getDescription());
|
|
|
586 |
|
|
|
587 |
defs.add(def);
|
|
|
588 |
}
|
|
|
589 |
|
|
|
590 |
return defs;
|
|
|
591 |
}
|
|
|
592 |
|
|
|
593 |
/**
|
|
|
594 |
*
|
| 49 |
naveen |
595 |
* @param defType
|
|
|
596 |
* @return
|
| 16 |
naveen |
597 |
*/
|
|
|
598 |
private Map<Long, FeatureDefinition> convertFeatureDefinitions(
|
|
|
599 |
DefinitionType defType) {
|
|
|
600 |
|
|
|
601 |
Map<Long, FeatureDefinition> defs =
|
|
|
602 |
new HashMap<Long, FeatureDefinition>();
|
|
|
603 |
|
|
|
604 |
List<FeatureDefinitionType> jaxbDefs = defType.getFeatureDefinition();
|
|
|
605 |
Iterator<FeatureDefinitionType> itjaxbDefs = jaxbDefs.iterator();
|
|
|
606 |
|
|
|
607 |
// Feature definitions
|
|
|
608 |
while(itjaxbDefs.hasNext()) {
|
|
|
609 |
FeatureDefinitionType jaxbDef = itjaxbDefs.next();
|
|
|
610 |
|
| 42 |
naveen |
611 |
//Utils.info("Feature label=" + jaxbDef.getLabel());
|
| 16 |
naveen |
612 |
FeatureDefinition def = new FeatureDefinition(jaxbDef.getID(),
|
|
|
613 |
jaxbDef.getLabel());
|
|
|
614 |
def.setAllowsBlank(jaxbDef.isCanbeBlank());
|
|
|
615 |
def.setDescription(jaxbDef.getDescription());
|
|
|
616 |
|
|
|
617 |
// Bullet Definition
|
|
|
618 |
BulletDefinitionType jaxbBulletDef = jaxbDef.getBulletDefinition();
|
|
|
619 |
if(jaxbBulletDef != null) {
|
|
|
620 |
def.setBulletDefinition(this.convertBulletDefinition(
|
|
|
621 |
jaxbBulletDef));
|
|
|
622 |
}
|
| 42 |
naveen |
623 |
Utils.info("def=" + def);
|
| 16 |
naveen |
624 |
|
|
|
625 |
defs.put(new Long(jaxbDef.getID()), def);
|
|
|
626 |
}
|
|
|
627 |
|
|
|
628 |
return defs;
|
|
|
629 |
}
|
|
|
630 |
|
|
|
631 |
/**
|
|
|
632 |
*
|
|
|
633 |
* @param jaxbDef BulletDefinitionType
|
|
|
634 |
* @return BulletDefinition
|
|
|
635 |
*/
|
|
|
636 |
private BulletDefinition convertBulletDefinition(
|
|
|
637 |
BulletDefinitionType jaxbDef) {
|
|
|
638 |
|
|
|
639 |
BulletDefinition def = new BulletDefinition(
|
|
|
640 |
jaxbDef.getDatatypeDefinitionID());
|
|
|
641 |
|
|
|
642 |
Long unitID = jaxbDef.getUnitID();
|
|
|
643 |
if(unitID != null) {
|
|
|
644 |
def.setUnitID(unitID.longValue());
|
|
|
645 |
}
|
| 47 |
naveen |
646 |
Utils.info("jaxbDef.isIsMultivalue=" + jaxbDef.isIsMultivalue());
|
|
|
647 |
|
| 16 |
naveen |
648 |
def.setMultivalue(jaxbDef.isIsMultivalue());
|
|
|
649 |
def.setLearned(jaxbDef.isIsLearned());
|
|
|
650 |
def.setDescription(jaxbDef.getDescription());
|
|
|
651 |
|
|
|
652 |
return def;
|
|
|
653 |
}
|
| 49 |
naveen |
654 |
|
| 16 |
naveen |
655 |
/**
|
|
|
656 |
*
|
| 49 |
naveen |
657 |
* @param defType
|
|
|
658 |
* @return
|
| 16 |
naveen |
659 |
*/
|
|
|
660 |
private Map<Long, DatatypeDefinition> convertDatatypeDefinition(
|
|
|
661 |
DefinitionType defType) {
|
|
|
662 |
|
|
|
663 |
Map<Long, DatatypeDefinition> defs =
|
|
|
664 |
new HashMap<Long, DatatypeDefinition>();
|
|
|
665 |
|
|
|
666 |
List<DatatypeDefinitionType> jaxbDefs = defType.getDatatypeDefinition();
|
|
|
667 |
Iterator<DatatypeDefinitionType> it = jaxbDefs.iterator();
|
|
|
668 |
|
|
|
669 |
while(it.hasNext()) {
|
|
|
670 |
DatatypeDefinitionType jaxbDef = it.next();
|
|
|
671 |
|
|
|
672 |
DatatypeDefinition def = null;
|
|
|
673 |
CompositeDefinitionType compositeDefType =
|
|
|
674 |
jaxbDef.getCompositeDefinition();
|
|
|
675 |
|
|
|
676 |
EnumDefinitionType enumDefType =
|
|
|
677 |
jaxbDef.getEnumDefinition();
|
|
|
678 |
|
|
|
679 |
// Composite data type
|
|
|
680 |
if(compositeDefType != null) {
|
|
|
681 |
CompositeDefinition compDef = new CompositeDefinition(
|
| 20 |
naveen |
682 |
jaxbDef.getID(), jaxbDef.getName(),
|
|
|
683 |
compositeDefType.getSeparator());
|
| 16 |
naveen |
684 |
|
|
|
685 |
List<CompositePartDefinitionType> jaxbPartDefs =
|
|
|
686 |
compositeDefType.getCompositePartDefinition();
|
|
|
687 |
|
|
|
688 |
Iterator<CompositePartDefinitionType> itPartDefs =
|
|
|
689 |
jaxbPartDefs.iterator();
|
|
|
690 |
|
|
|
691 |
// Collect parts
|
|
|
692 |
while(itPartDefs.hasNext()) {
|
|
|
693 |
CompositePartDefinitionType jaxbPartDef = itPartDefs.next();
|
|
|
694 |
CompositePartDefinition partDef =
|
|
|
695 |
this.convertCompositePartDefinition(jaxbPartDef);
|
|
|
696 |
|
|
|
697 |
compDef.addCompositePartDefinition(partDef);
|
|
|
698 |
}
|
|
|
699 |
|
|
|
700 |
def = compDef;
|
|
|
701 |
}
|
|
|
702 |
|
|
|
703 |
// Enumerated values
|
|
|
704 |
else if(enumDefType != null) {
|
|
|
705 |
EnumDefinition enumDef = new EnumDefinition(jaxbDef.getID(),
|
|
|
706 |
jaxbDef.getName());
|
|
|
707 |
|
|
|
708 |
List<EnumValueType> jaxbEnumValues =
|
|
|
709 |
enumDefType.getEnumValue();
|
|
|
710 |
|
|
|
711 |
Iterator<EnumValueType> itEnumValues =
|
|
|
712 |
jaxbEnumValues.iterator();
|
|
|
713 |
|
|
|
714 |
// Collect individual value
|
|
|
715 |
while(itEnumValues.hasNext()) {
|
|
|
716 |
EnumValueType jaxbEnumValue = itEnumValues.next();
|
|
|
717 |
EnumValue enumValue =
|
|
|
718 |
this.convertEnumValueDefinition(jaxbEnumValue);
|
|
|
719 |
|
|
|
720 |
enumDef.addEnumValue(enumValue);
|
|
|
721 |
}
|
|
|
722 |
|
|
|
723 |
def = enumDef;
|
|
|
724 |
}
|
|
|
725 |
|
|
|
726 |
// Primitive
|
|
|
727 |
else {
|
|
|
728 |
def = new DatatypeDefinition(jaxbDef.getID(),
|
|
|
729 |
jaxbDef.getName());
|
|
|
730 |
}
|
|
|
731 |
|
|
|
732 |
def.setDescription(jaxbDef.getDescription());
|
| 42 |
naveen |
733 |
Utils.info("def=" + def);
|
| 16 |
naveen |
734 |
|
|
|
735 |
defs.put(new Long(jaxbDef.getID()), def);
|
|
|
736 |
}
|
|
|
737 |
|
|
|
738 |
return defs;
|
|
|
739 |
}
|
|
|
740 |
|
|
|
741 |
/**
|
|
|
742 |
*
|
|
|
743 |
* @param jaxbEnumValue
|
|
|
744 |
* @return EnumValue
|
|
|
745 |
*/
|
|
|
746 |
private EnumValue convertEnumValueDefinition(EnumValueType jaxbEnumValue) {
|
|
|
747 |
|
|
|
748 |
EnumValue enumValue = new EnumValue(jaxbEnumValue.getID(),
|
|
|
749 |
jaxbEnumValue.getValue());
|
|
|
750 |
|
|
|
751 |
return enumValue;
|
|
|
752 |
}
|
|
|
753 |
/**
|
|
|
754 |
*
|
|
|
755 |
* @param jaxbPartDef
|
|
|
756 |
* @return CompositePartDefinition
|
|
|
757 |
*/
|
|
|
758 |
private CompositePartDefinition convertCompositePartDefinition(
|
|
|
759 |
CompositePartDefinitionType jaxbPartDef) {
|
|
|
760 |
|
|
|
761 |
CompositePartDefinition partDef = new CompositePartDefinition(
|
|
|
762 |
jaxbPartDef.getLabel(), jaxbPartDef.getDatatypeDefinitionID(),
|
|
|
763 |
jaxbPartDef.getUnitID());
|
|
|
764 |
|
|
|
765 |
partDef.setDescription(jaxbPartDef.getDescription());
|
|
|
766 |
|
|
|
767 |
return partDef;
|
|
|
768 |
}
|
| 49 |
naveen |
769 |
|
| 16 |
naveen |
770 |
/**
|
|
|
771 |
*
|
| 49 |
naveen |
772 |
* @param defType
|
|
|
773 |
* @param catMap
|
|
|
774 |
* @return
|
| 16 |
naveen |
775 |
*/
|
|
|
776 |
private Category convertCategories(DefinitionType defType,
|
|
|
777 |
Map<Long, Category> catMap) {
|
| 10 |
shop2020 |
778 |
|
|
|
779 |
List<CategoryType> jaxbCats = defType.getCategory();
|
|
|
780 |
Iterator<CategoryType> it = jaxbCats.iterator();
|
|
|
781 |
|
|
|
782 |
// Get root category
|
|
|
783 |
CategoryType jaxbCat = it.next();
|
|
|
784 |
if(jaxbCat == null) {
|
| 42 |
naveen |
785 |
Utils.info("Invalid file: " + this.srcFile);
|
| 10 |
shop2020 |
786 |
return null;
|
|
|
787 |
}
|
|
|
788 |
|
|
|
789 |
Category root = this.convertCategoryType(jaxbCat, null, catMap);
|
| 42 |
naveen |
790 |
Utils.info("catMap.get(10002)=" + catMap.get(new Long(10002)));
|
| 32 |
naveen |
791 |
|
| 10 |
shop2020 |
792 |
return root;
|
|
|
793 |
}
|
|
|
794 |
|
|
|
795 |
/**
|
|
|
796 |
*
|
|
|
797 |
* @param jaxbCat
|
| 49 |
naveen |
798 |
* @param parentCat
|
|
|
799 |
* @param catMap
|
|
|
800 |
* @return
|
| 10 |
shop2020 |
801 |
*/
|
| 32 |
naveen |
802 |
@SuppressWarnings("unchecked")
|
| 16 |
naveen |
803 |
private Category convertCategoryType(CategoryType jaxbCat,
|
|
|
804 |
Category parentCat, Map<Long, Category> catMap) {
|
| 18 |
naveen |
805 |
|
| 10 |
shop2020 |
806 |
Category cat = new Category(jaxbCat.getID());
|
|
|
807 |
cat.setLabel(jaxbCat.getName());
|
|
|
808 |
cat.setDescription(jaxbCat.getDescription());
|
|
|
809 |
if(parentCat != null) {
|
|
|
810 |
cat.setParentCategory(parentCat);
|
| 32 |
naveen |
811 |
|
|
|
812 |
// Copy parent's category-slide definitions
|
|
|
813 |
ArrayList<CategorySlideDefinition> parentCSDef =
|
|
|
814 |
(ArrayList<CategorySlideDefinition>)
|
|
|
815 |
parentCat.getCategorySlideDefintions();
|
|
|
816 |
|
|
|
817 |
if(parentCSDef != null) {
|
|
|
818 |
cat.setCategorySlideDefintions(
|
|
|
819 |
(List<CategorySlideDefinition>) parentCSDef.clone());
|
|
|
820 |
}
|
| 10 |
shop2020 |
821 |
}
|
|
|
822 |
|
|
|
823 |
// Category Slide Definition
|
| 32 |
naveen |
824 |
List<CategorySlideDefinitionType> jaxbDefs =
|
|
|
825 |
jaxbCat.getCategorySlideDefinition();
|
|
|
826 |
|
| 10 |
shop2020 |
827 |
Iterator<CategorySlideDefinitionType> it = jaxbDefs.iterator();
|
|
|
828 |
while(it.hasNext()) {
|
|
|
829 |
CategorySlideDefinitionType jaxbDef = it.next();
|
| 32 |
naveen |
830 |
CategorySlideDefinition catSlideDef
|
|
|
831 |
= this.convertCategorySlideDefinitionType(jaxbCat.getID(), jaxbDef);
|
|
|
832 |
|
| 10 |
shop2020 |
833 |
cat.addCategorySlideDefintion(catSlideDef);
|
|
|
834 |
}
|
|
|
835 |
|
|
|
836 |
// Children
|
|
|
837 |
List<CategoryType> jaxbChildren = jaxbCat.getChildCategory();
|
| 42 |
naveen |
838 |
//Utils.info("jaxbChildren.size: " + jaxbChildren.size());
|
| 10 |
shop2020 |
839 |
|
|
|
840 |
Iterator<CategoryType> itChildren = jaxbChildren.iterator();
|
|
|
841 |
while(itChildren.hasNext()) {
|
|
|
842 |
CategoryType jaxbChildCat = itChildren.next();
|
| 32 |
naveen |
843 |
Category childCat = this.convertCategoryType(jaxbChildCat, cat,
|
|
|
844 |
catMap);
|
| 10 |
shop2020 |
845 |
cat.addChild(childCat);
|
|
|
846 |
}
|
| 42 |
naveen |
847 |
//Utils.info("Parent cat: " + cat);
|
| 32 |
naveen |
848 |
// DEBUG ONLY
|
| 42 |
naveen |
849 |
Utils.info("####### Cat ID: " + cat.getID());
|
| 32 |
naveen |
850 |
if(cat.getCategorySlideDefintions() != null) {
|
|
|
851 |
for(CategorySlideDefinition csd : cat.getCategorySlideDefintions()){
|
| 42 |
naveen |
852 |
Utils.info("####### SlideDefintionID=" +
|
| 32 |
naveen |
853 |
csd.getSlideDefintionID());
|
|
|
854 |
}
|
|
|
855 |
}
|
|
|
856 |
|
| 10 |
shop2020 |
857 |
catMap.put(new Long(jaxbCat.getID()), cat);
|
|
|
858 |
return cat;
|
|
|
859 |
}
|
|
|
860 |
|
|
|
861 |
/**
|
|
|
862 |
*
|
| 49 |
naveen |
863 |
* @param categoryID
|
| 10 |
shop2020 |
864 |
* @param jaxbDef
|
|
|
865 |
* @return
|
|
|
866 |
*/
|
| 16 |
naveen |
867 |
private CategorySlideDefinition convertCategorySlideDefinitionType(
|
|
|
868 |
long categoryID, CategorySlideDefinitionType jaxbDef) {
|
|
|
869 |
|
| 10 |
shop2020 |
870 |
CategorySlideDefinition catSlideDef = new CategorySlideDefinition(
|
| 32 |
naveen |
871 |
jaxbDef.getSlideDefinitionID());
|
| 10 |
shop2020 |
872 |
|
|
|
873 |
catSlideDef.setDescription(jaxbDef.getDescription());
|
|
|
874 |
|
|
|
875 |
EditorialImportanceType jaxbEdImp = jaxbDef.getEditorialImportance();
|
|
|
876 |
EditorialImportance edImp = this.convertEditorialImportance(jaxbEdImp);
|
|
|
877 |
catSlideDef.setEditorialImportance(edImp);
|
|
|
878 |
|
|
|
879 |
return catSlideDef;
|
|
|
880 |
}
|
|
|
881 |
|
|
|
882 |
/**
|
|
|
883 |
*
|
|
|
884 |
* @return Map
|
|
|
885 |
*/
|
|
|
886 |
private Map<Long, Unit> convertUnits(DefinitionType defType) {
|
|
|
887 |
|
|
|
888 |
Map<Long, Unit> allUnits = new HashMap<Long, Unit>();
|
|
|
889 |
List<UnitType> jaxbUnits = defType.getUnit();
|
|
|
890 |
Iterator<UnitType> it = jaxbUnits.iterator();
|
|
|
891 |
|
|
|
892 |
while(it.hasNext()) {
|
|
|
893 |
UnitType jaxbUnit = it.next();
|
|
|
894 |
|
|
|
895 |
Unit unit = new Unit(jaxbUnit.getID());
|
|
|
896 |
unit.setDescription(jaxbUnit.getDescription());
|
|
|
897 |
unit.setFullForm(jaxbUnit.getFullform());
|
|
|
898 |
unit.setShortForm(jaxbUnit.getShortform());
|
| 42 |
naveen |
899 |
Utils.info("unit=" + unit);
|
| 10 |
shop2020 |
900 |
|
|
|
901 |
allUnits.put(new Long(jaxbUnit.getID()), unit);
|
|
|
902 |
}
|
|
|
903 |
|
|
|
904 |
return allUnits;
|
|
|
905 |
}
|
| 49 |
naveen |
906 |
|
| 10 |
shop2020 |
907 |
/**
|
|
|
908 |
*
|
| 49 |
naveen |
909 |
* @param srcFile
|
|
|
910 |
* @return
|
|
|
911 |
* @throws Exception
|
| 10 |
shop2020 |
912 |
*/
|
| 57 |
naveen |
913 |
private Object unmarshallSrcFile(String srcFile, String type)
|
|
|
914 |
throws Exception {
|
| 10 |
shop2020 |
915 |
|
| 57 |
naveen |
916 |
JAXBContext jc = JAXBContext.newInstance("in.shop2020.metamodel.jaxb." +
|
|
|
917 |
type);
|
| 10 |
shop2020 |
918 |
|
|
|
919 |
// create an Unmarshaller
|
|
|
920 |
Unmarshaller u = jc.createUnmarshaller();
|
|
|
921 |
|
| 16 |
naveen |
922 |
JAXBElement<?> element = (JAXBElement<?>)u.unmarshal(
|
|
|
923 |
new FileInputStream(srcFile));
|
| 10 |
shop2020 |
924 |
|
| 57 |
naveen |
925 |
return element.getValue();
|
| 10 |
shop2020 |
926 |
}
|
|
|
927 |
|
|
|
928 |
/**
|
|
|
929 |
*
|
| 16 |
naveen |
930 |
* @param jaxbEdImp
|
|
|
931 |
* @return EditorialImportance
|
|
|
932 |
*/
|
|
|
933 |
private EditorialImportance convertEditorialImportance(
|
|
|
934 |
EditorialImportanceType jaxbEdImp) {
|
|
|
935 |
|
|
|
936 |
String strEdImp = jaxbEdImp.value();
|
|
|
937 |
EditorialImportance edImp = null;
|
|
|
938 |
|
|
|
939 |
if(strEdImp.equals("Mandatory"))
|
|
|
940 |
edImp = EditorialImportance.MANDATORY;
|
|
|
941 |
else if(strEdImp.equals("Optional"))
|
|
|
942 |
edImp = EditorialImportance.OPTIONAL;
|
|
|
943 |
else
|
|
|
944 |
edImp = EditorialImportance.RECOMMENDED;
|
|
|
945 |
|
|
|
946 |
return edImp;
|
|
|
947 |
}
|
| 10 |
shop2020 |
948 |
}
|