Subversion Repositories SmartDukaan

Rev

Rev 323 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
102 naveen 1
/**
2
 * 
3
 */
4
package in.shop2020.util;
5
 
6
import in.shop2020.metamodel.definitions.Catalog;
7
import in.shop2020.metamodel.definitions.DefinitionsContainer;
8
import in.shop2020.metamodel.definitions.RuleDefinition;
9
import in.shop2020.metamodel.util.ExpandedFeature;
10
 
11
import org.python.core.PyObject;
12
 
13
/**
14
 * @author naveen
15
 *
16
 */
17
public class PrimitiveNormalizationJythonWrapper extends JythonWrapper {
18
	/**
19
	 * 
20
	 */
21
	private ExpandedFeature expFeature;
22
 
23
	/**
24
	 * Resets current PythonInterpreter instance
25
	 */
26
	public void reset() {
27
		super.reset();
28
		this.expFeature = null;
29
	}
30
 
31
	/**
32
	 * 
33
	 * @param expFeature
34
	 */
35
	public void setExpandedFeature(ExpandedFeature expFeature) {
36
		this.initialize();
37
 
38
		this.expFeature = expFeature;
39
		this.py.set("expFeature", expFeature);
40
	}
41
 
42
	/**
43
	 * @throws Exception 
44
	 * 
45
	 */
46
	public void excuteRule() throws Exception {
47
		if(this.py == null) {
48
			throw new IllegalStateException("Not initialized properly");
49
		}
50
 
51
		DefinitionsContainer defs = 
52
			Catalog.getInstance().getDefinitionsContainer();
53
 
54
		Utils.info("this.expFeature=" + this.expFeature);
55
 
56
		RuleDefinition ruleDef = defs.getNormalizationRuleDefinition(
57
				this.expFeature.getFeatureDefinition().
58
					getNormalizationRuleDefinitionID());
59
 
60
		String pyScript = ruleDef.getScript();
61
		String scriptFullPath = Utils.JYTHON_SRC_PATH + "normalizationrules/" + 
62
			pyScript;
63
 
64
		Utils.info("ruleDef.getID()=" + ruleDef.getID());
65
		Utils.info("scriptFullPath=" + scriptFullPath);
66
 
67
		this.exec(scriptFullPath);
68
	}
69
 
70
	/**
71
	 * 
72
	 * @return
73
	 */
74
	public String getNewValue() {
75
		if(this.py == null) {
76
			throw new IllegalStateException("Exec is not called yet");
77
		}
78
 
79
		PyObject value = this.py.get("newvalue");
80
 
81
		return value.toString();
82
	}
83
 
84
	/**
85
	 * 
86
	 * @return
87
	 */
88
	public long getNewUnitID() {
89
		if(this.py == null) {
90
			throw new IllegalStateException("Exec is not called yet");
91
		}
92
 
93
		PyObject newunitid = this.py.get("newunitid");
94
 
95
		return Long.parseLong(newunitid.toString());
96
	}
97
 
98
}