Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | 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
 
59
		// Expand bullets
60
		if(this.getBullets() != null) {
61
			this.expandedBullets = new ArrayList<ExpandedBullet>();
62
 
63
			for(Bullet bullet : this.getBullets()) {
64
				ExpandedBullet expBullet = new ExpandedBullet(bullet, 
65
						this.featureDefinition.getBulletDefinition());
66
 
67
				this.expandedBullets.add(expBullet);
68
			}
69
		}
70
	}
71
 
72
	/**
51 naveen 73
	 * @return the featureDefinition Feature Definition object
24 naveen 74
	 */
75
	public FeatureDefinition getFeatureDefinition() {
76
		return featureDefinition;
77
	}
78
 
79
	/**
51 naveen 80
	 * @return the expandedBullets List of ExpandedBullet objects
24 naveen 81
	 */
82
	public List<ExpandedBullet> getExpandedBullets() {
83
		return expandedBullets;
84
	}
85
 
207 naveen 86
	/**
87
	 * 
88
	 * @return List of String values for each bullet
89
	 */
90
	public List<String> getBulletValues() {
91
		List<String> values = new ArrayList<String>();
92
 
93
		if(this.expandedBullets != null) {
94
			for(ExpandedBullet expBullet : this.expandedBullets) {
243 naveen 95
				if(expBullet != null) {
96
					values.add(expBullet.getValue());
97
				}
207 naveen 98
			}
99
		}
100
 
101
		return values;
102
	}
103
 
33 naveen 104
	/* (non-Javadoc)
105
	 * @see java.lang.Object#toString()
106
	 */
107
	@Override
108
	public String toString() {
109
		return "ExpandedFeature [expandedBullets=" + expandedBullets
110
				+ ", featureDefinition=" + featureDefinition + ", toString()="
111
				+ super.toString() + "]";
112
	}
113
 
24 naveen 114
}