Subversion Repositories SmartDukaan

Rev

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

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

import java.util.ArrayList;
import java.util.List;

import in.shop2020.metamodel.core.Bullet;
import in.shop2020.metamodel.core.Feature;
import in.shop2020.metamodel.definitions.Catalog;
import in.shop2020.metamodel.definitions.DefinitionsContainer;
import in.shop2020.metamodel.definitions.FeatureDefinition;

/**
 * Utility class that supports core Feature class. All related 
 * objects are fetched from database and aggregated here.
 *
 * @author naveen
 *
 */
public class ExpandedFeature extends Feature {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        
        /**
         * Expanded from Feature Definition ID
         */
        private FeatureDefinition featureDefinition;
        
        /**
         * Expanded from list of Bullet objects
         */
        private List<ExpandedBullet> expandedBullets;

        /**
         * Takes Feature object as input and converts all references 
         * into corresponding detail objects
         * 
         * @param feature
         * @throws Exception
         */
        public ExpandedFeature(Feature feature) throws Exception {
                super(feature.getFeatureDefinitionID());
                
                // Copy rest of the properties
                super.setBullets(feature.getBullets());
                super.setFreeformContent(feature.getFreeformContent());
                
                // Expand feature definition id
                DefinitionsContainer defs = 
                        Catalog.getInstance().getDefinitionsContainer();
                
                this.featureDefinition = 
                        defs.getFeatureDefinition(feature.getFeatureDefinitionID());
                // Expand bullets
                if(this.getBullets() != null) {
                        this.expandedBullets = new ArrayList<ExpandedBullet>();
                        
                        for(Bullet bullet : this.getBullets()) {
                                ExpandedBullet expBullet = new ExpandedBullet(bullet, 
                                                this.featureDefinition.getBulletDefinition());
                                
                                this.expandedBullets.add(expBullet);
                        }
                }
        }

        /**
         * @return the featureDefinition Feature Definition object
         */
        public FeatureDefinition getFeatureDefinition() {
                return featureDefinition;
        }

        /**
         * @return the expandedBullets List of ExpandedBullet objects
         */
        public List<ExpandedBullet> getExpandedBullets() {
                return expandedBullets;
        }

        /**
         * 
         * @return List of String values for each bullet
         */
        public List<String> getBulletValues() {
                List<String> values = new ArrayList<String>();
                
                if(this.expandedBullets != null) {
                        for(ExpandedBullet expBullet : this.expandedBullets) {
                                if(expBullet != null) {
                                        values.add(expBullet.getValue());
                                }
                        }
                }
                
                return values;
        }
        
        /* (non-Javadoc)
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString() {
                return "ExpandedFeature [expandedBullets=" + expandedBullets
                                + ", featureDefinition=" + featureDefinition + ", toString()="
                                + super.toString() + "]";
        }

}