Subversion Repositories SmartDukaan

Rev

Rev 1061 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/**
 * 
 */
package in.shop2020.util;

import in.shop2020.metamodel.definitions.Catalog;
import in.shop2020.metamodel.definitions.DefinitionsContainer;
import in.shop2020.metamodel.definitions.RuleDefinition;
import in.shop2020.metamodel.util.ExpandedFeature;

import org.python.core.PyObject;

/**
 * @author naveen
 *
 */
public class PrimitiveNormalizationJythonWrapper extends JythonWrapper {
        /**
         * 
         */
        private ExpandedFeature expFeature;

        /**
         * Resets current PythonInterpreter instance
         */
        public void reset() {
                super.reset();
                this.expFeature = null;
        }
        
        /**
         * 
         * @param expFeature
         */
        public void setExpandedFeature(ExpandedFeature expFeature) {
                this.initialize();
                
                this.expFeature = expFeature;
                this.py.set("expFeature", expFeature);
        }
        
        /**
         * @throws Exception 
         * 
         */
        public void excuteRule() throws Exception {
                if(this.py == null) {
                        throw new IllegalStateException("Not initialized properly");
                }

                DefinitionsContainer defs = 
                        Catalog.getInstance().getDefinitionsContainer();
                
                //Utils.info("this.expFeature=" + this.expFeature);
                
                RuleDefinition ruleDef = defs.getNormalizationRuleDefinition(
                                this.expFeature.getFeatureDefinition().
                                        getNormalizationRuleDefinitionID());
                
                String pyScript = ruleDef.getScript();
                String scriptFullPath = Utils.JYTHON_SRC_PATH + "normalizationrules/" + 
                        pyScript;
                
                Utils.info("ruleDef.getID()=" + ruleDef.getID());
                Utils.info("scriptFullPath=" + scriptFullPath);
                
                this.exec(scriptFullPath);
        }
        
        /**
         * 
         * @return
         */
        public String getNewValue() {
                if(this.py == null) {
                        throw new IllegalStateException("Exec is not called yet");
                }
                
                PyObject value = this.py.get("newvalue");
                
                return value.toString();
        }

        /**
         * 
         * @return
         */
        public long getNewUnitID() {
                if(this.py == null) {
                        throw new IllegalStateException("Exec is not called yet");
                }
                
                PyObject newunitid = this.py.get("newunitid");
                
                return Long.parseLong(newunitid.toString());
        }

}