Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3e6542f697b9e6a644f008e9578adeb3082fc060 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*******************************************************************************
 * Copyright (c) 2004 - 2005 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylar.bugzilla.core.internal;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Class describing the configuration of products and components for a given
 * Bugzilla installation. 
 */
public class ProductConfiguration implements Serializable {

	/** Automatically generated serialVersionUID */
	private static final long serialVersionUID = 3257004354337519410L;

	private Map<String, ProductEntry> products = new HashMap<String, ProductEntry>();
	
	public ProductConfiguration() {
		super();
	}

	/**
	 * Adds a product to the configuration.
	 */
	public void addProduct(String name) {
		if (!products.containsKey(name)) {
			ProductEntry product = new ProductEntry(name);
			products.put(name, product);
		}
	}
	
	/**
	 * Returns an array of names of current products.
	 */
	public String[] getProducts() {
		return products.keySet().toArray(new String[0]);
	}
	
	/**
	 * Returns an array of names of component that exist for a given product
	 * or <code>null</code> if the product does not exist.
	 */
	public String[] getComponents(String product) {
		ProductEntry entry = products.get(product);
		if (entry != null) {
			return entry.getComponents();
		}
		else return null;
	}

	/**
	 * Returns an array of names of versions that exist for a given product
	 * or <code>null</code> if the product does not exist.
	 */
	public String[] getVersions(String product) {
		ProductEntry entry = products.get(product);
		if (entry != null) {
			return entry.getVersions();
		}
		else return null;
	}

	/**
	 * Returns an array of names of valid severity values.
	 */
	public String[] getSeverities() {
		return new String[] {"blocker", "critical", "major", "normal", "minor", "trivial", "enhancement"};
	}
	
	/**
	 * Returns an array of names of valid OS values.
	 */
	public String[] getOSs() {
		return new String[] {"All", "Windows XP", "Linux", "other"};
	}
	
	/**
	 * Returns an array of names of valid platform values.
	 */
	public String[] getPlatforms() {
		return new String[] {"All", "Macintosh", "PC"};
	}
	
	/**
	 * Returns an array of names of valid platform values.
	 */
	public String[] getPriorities() {
		return new String[] {"P1", "P2", "P3", "P4", "P5"};
	}

	/**
	 * Adds a component to the given product.
	 */
	public void addComponent(String product, String component) {
		ProductEntry entry = products.get(product);
		if (entry == null) {
			entry = new ProductEntry(product);
			products.put(product, entry);
		}
		entry.addComponent(component);
	}
	
	/**
	 * Adds a list of components to the given product.
	 */
	public void addComponents(String product, String[] components) {
		ProductEntry entry = products.get(product);
		if (entry == null) {
			entry = new ProductEntry(product);
			products.put(product, entry);
		}
		for (int i = 0; i < components.length; i++) {
			String component = components[i];
			entry.addComponent(component);	
		}
	}
	
	/**
	 * Adds a list of components to the given product.
	 */
	public void addVersions(String product, String[] versions) {
		ProductEntry entry = products.get(product);
		if (entry == null) {
			entry = new ProductEntry(product);
			products.put(product, entry);
		}
		for (int i = 0; i < versions.length; i++) {
			String version = versions[i];
			entry.addVersion(version);	
		}
	}
	
	/**
	 * Container for product information: name, components.
	 */
	private static class ProductEntry implements Serializable {

		/** Automatically generated serialVersionUID */
		private static final long serialVersionUID = 3977018465733391668L;

		String productName;
		List<String> components = new ArrayList<String>();
		List<String> versions = new ArrayList<String>();

		ProductEntry(String name) {
			this.productName = name;
		}
		String[] getComponents() {
			return components.toArray(new String[0]);
		}
		void addComponent(String componentName) {
			if (!components.contains(componentName)) {
				components.add(componentName);
			}
		}
		String[] getVersions() {
			return versions.toArray(new String[0]);
		}
		void addVersion(String name) {
			if (!versions.contains(name)) {
				versions.add(name);
			}
		}
	}
}

Back to the top