Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
24 naveen 1
/**
2
 * 
3
 */
4
package in.shop2020.metamodel.util;
5
 
6
import java.util.ArrayList;
7
import java.util.List;
8
 
9
import in.shop2020.metamodel.core.Bullet;
10
import in.shop2020.metamodel.core.Feature;
11
import in.shop2020.metamodel.definitions.Catalog;
12
import in.shop2020.metamodel.definitions.DefinitionsContainer;
13
import in.shop2020.metamodel.definitions.FeatureDefinition;
14
 
15
/**
51 naveen 16
 * Utility class that supports core Feature class. All related 
17
 * objects are fetched from database and aggregated here.
18
 *
24 naveen 19
 * @author naveen
20
 *
21
 */
22
public class ExpandedFeature extends Feature {
23
	/**
24
	 * 
25
	 */
26
	private static final long serialVersionUID = 1L;
49 naveen 27
 
28
	/**
51 naveen 29
	 * Expanded from Feature Definition ID
49 naveen 30
	 */
24 naveen 31
	private FeatureDefinition featureDefinition;
49 naveen 32
 
33
	/**
51 naveen 34
	 * Expanded from list of Bullet objects
49 naveen 35
	 */
24 naveen 36
	private List<ExpandedBullet> expandedBullets;
37
 
38
	/**
51 naveen 39
	 * Takes Feature object as input and converts all references 
40
	 * into corresponding detail objects
49 naveen 41
	 * 
42
	 * @param feature
43
	 * @throws Exception
24 naveen 44
	 */
45
	public ExpandedFeature(Feature feature) throws Exception {
46
		super(feature.getFeatureDefinitionID());
47
 
48
		// Copy rest of the properties
49
		super.setBullets(feature.getBullets());
50
		super.setFreeformContent(feature.getFreeformContent());
51
 
52
		// Expand feature definition id
53
		DefinitionsContainer defs = 
54
			Catalog.getInstance().getDefinitionsContainer();
55
 
56
		this.featureDefinition = 
57
			defs.getFeatureDefinition(feature.getFeatureDefinitionID());
58
		// Expand bullets
59
		if(this.getBullets() != null) {
60
			this.expandedBullets = new ArrayList<ExpandedBullet>();
61
 
62
			for(Bullet bullet : this.getBullets()) {
63
				ExpandedBullet expBullet = new ExpandedBullet(bullet, 
64
						this.featureDefinition.getBulletDefinition());
65
 
66
				this.expandedBullets.add(expBullet);
67
			}
68
		}
69
	}
70
 
71
	/**
51 naveen 72
	 * @return the featureDefinition Feature Definition object
24 naveen 73
	 */
74
	public FeatureDefinition getFeatureDefinition() {
75
		return featureDefinition;
76
	}
77
 
78
	/**
51 naveen 79
	 * @return the expandedBullets List of ExpandedBullet objects
24 naveen 80
	 */
81
	public List<ExpandedBullet> getExpandedBullets() {
82
		return expandedBullets;
83
	}
84
 
207 naveen 85
	/**
86
	 * 
87
	 * @return List of String values for each bullet
88
	 */
89
	public List<String> getBulletValues() {
90
		List<String> values = new ArrayList<String>();
91
 
92
		if(this.expandedBullets != null) {
93
			for(ExpandedBullet expBullet : this.expandedBullets) {
243 naveen 94
				if(expBullet != null) {
95
					values.add(expBullet.getValue());
96
				}
207 naveen 97
			}
98
		}
99
 
100
		return values;
101
	}
102
 
33 naveen 103
	/* (non-Javadoc)
104
	 * @see java.lang.Object#toString()
105
	 */
106
	@Override
107
	public String toString() {
108
		return "ExpandedFeature [expandedBullets=" + expandedBullets
109
				+ ", featureDefinition=" + featureDefinition + ", toString()="
110
				+ super.toString() + "]";
111
	}
112
 
24 naveen 113
}