| 70 |
naveen |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.util;
|
|
|
5 |
|
|
|
6 |
import in.shop2020.metamodel.definitions.CMPRuleDefinition;
|
|
|
7 |
import in.shop2020.metamodel.util.ExpandedCMPSlideRuleDefinition;
|
|
|
8 |
import in.shop2020.metamodel.util.ExpandedSlide;
|
|
|
9 |
|
|
|
10 |
import org.python.core.PyInteger;
|
|
|
11 |
|
|
|
12 |
/**
|
|
|
13 |
* Wrapper around Jython for Comparison Python scripts
|
|
|
14 |
*
|
|
|
15 |
* @author naveen
|
|
|
16 |
*
|
|
|
17 |
*/
|
|
|
18 |
public class CMPJythonWrapper extends JythonWrapper {
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* Local instance of CMPSlideRuleDefinition - Used to pick script to execute
|
|
|
22 |
*/
|
|
|
23 |
private ExpandedCMPSlideRuleDefinition
|
|
|
24 |
expandedCMPSlideRuleDefinition = null;
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Resets current PythonInterpreter instance
|
|
|
28 |
*/
|
|
|
29 |
public void reset() {
|
|
|
30 |
super.reset();
|
|
|
31 |
this.expandedCMPSlideRuleDefinition = null;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Executes Comparison rule from ExpandedCMPSlideRuleDefinition instance
|
|
|
36 |
*/
|
|
|
37 |
public void execCMPRule() {
|
|
|
38 |
if(this.py == null || this.expandedCMPSlideRuleDefinition == null) {
|
|
|
39 |
throw new IllegalStateException(
|
|
|
40 |
"Not initialized properly");
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
CMPRuleDefinition cmpRuleDef =
|
|
|
44 |
this.expandedCMPSlideRuleDefinition.getCMPRuleDefinition();
|
|
|
45 |
|
|
|
46 |
String pyScript = cmpRuleDef.getScript();
|
|
|
47 |
String scriptFullPath = Utils.JYTHON_SRC_PATH + "comparisonrules/" +
|
|
|
48 |
pyScript;
|
|
|
49 |
|
|
|
50 |
Utils.info("cmpRuleDef.getID()=" + cmpRuleDef.getID());
|
|
|
51 |
Utils.info("scriptFullPath=" + scriptFullPath);
|
|
|
52 |
|
|
|
53 |
this.exec(scriptFullPath);
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* @param expandedCMPSlideRuleDefinition the expandedCMPSlideRuleDefinition
|
|
|
58 |
* to set
|
|
|
59 |
*/
|
|
|
60 |
public void setExpandedCMPSlideRuleDefinition(
|
|
|
61 |
ExpandedCMPSlideRuleDefinition expandedCMPSlideRuleDefinition) {
|
|
|
62 |
this.initialize();
|
|
|
63 |
|
|
|
64 |
this.expandedCMPSlideRuleDefinition = expandedCMPSlideRuleDefinition;
|
|
|
65 |
this.py.set("expCMPSlideRuleDef", expandedCMPSlideRuleDefinition);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
*
|
|
|
70 |
* @param feature
|
|
|
71 |
*/
|
|
|
72 |
public void setExpandedSlide(ExpandedSlide expandedSlide) {
|
|
|
73 |
this.initialize();
|
|
|
74 |
|
|
|
75 |
this.py.set("expSlide", expandedSlide);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Return integer score value
|
|
|
80 |
*
|
|
|
81 |
* @return int score
|
|
|
82 |
*/
|
|
|
83 |
public int getScore() {
|
|
|
84 |
if(this.py == null) {
|
|
|
85 |
throw new IllegalStateException("Exec is not called yet");
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
PyInteger score = (PyInteger)this.py.get("score");
|
|
|
89 |
|
| 71 |
naveen |
90 |
if(score == null) {
|
|
|
91 |
CMPRuleDefinition cmpRuleDef =
|
|
|
92 |
this.expandedCMPSlideRuleDefinition.getCMPRuleDefinition();
|
|
|
93 |
|
|
|
94 |
String pyScript = cmpRuleDef.getScript();
|
|
|
95 |
Utils.severe("No score returned from script " + pyScript);
|
|
|
96 |
return -1;
|
|
|
97 |
}
|
|
|
98 |
|
| 70 |
naveen |
99 |
return score.asInt();
|
|
|
100 |
}
|
|
|
101 |
}
|