001: package org.tigris.scarab.util.word;
002:
003: /* ================================================================
004: * Copyright (c) 2000-2002 CollabNet. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are
008: * met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * 3. The end-user documentation included with the redistribution, if
018: * any, must include the following acknowlegement: "This product includes
019: * software developed by Collab.Net <http://www.Collab.Net/>."
020: * Alternately, this acknowlegement may appear in the software itself, if
021: * and wherever such third-party acknowlegements normally appear.
022: *
023: * 4. The hosted project names must not be used to endorse or promote
024: * products derived from this software without prior written
025: * permission. For written permission, please contact info@collab.net.
026: *
027: * 5. Products derived from this software may not use the "Tigris" or
028: * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
029: * prior written permission of Collab.Net.
030: *
031: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034: * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042: *
043: * ====================================================================
044: *
045: * This software consists of voluntary contributions made by many
046: * individuals on behalf of Collab.Net.
047: */
048:
049: import java.text.DateFormat;
050: import java.text.SimpleDateFormat;
051: import java.util.Date;
052: import java.util.List;
053: import java.util.ArrayList;
054: import java.util.Iterator;
055:
056: import org.apache.torque.TorqueException;
057: import org.tigris.scarab.om.Module;
058: import org.tigris.scarab.om.RModuleIssueType;
059: import org.tigris.scarab.om.RModuleUserAttribute;
060: import org.tigris.scarab.om.ScarabUser;
061: import org.tigris.scarab.om.ScarabUserImplPeer;
062: import org.tigris.scarab.tools.ScarabLocalizationTool;
063: import org.tigris.scarab.tools.localization.L10NKeySet;
064:
065: /**
066: * This class is created by the IssueSearch object to contain a single result.
067: * It represents a row on the IssueList.vm screen. It is mostly
068: * a data structure with some additional functionality to format a
069: * multivalued attribute as CSV.
070: *
071: * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
072: */
073: public class QueryResult {
074: /** the search that created this QueryResult */
075: private final IssueSearch search;
076: private String issueId;
077: private String idPrefix;
078: private String idCount;
079: private String uniqueId;
080: private List attributeValues;
081: private Integer moduleId;
082: private Integer issueTypeId;
083: private Integer createdBy;
084: private Date createdDate;
085: private Date modifiedDate;
086: private Integer modifiedBy;
087:
088: /**
089: * Ctor. Should only be called by an IssueSearch.
090: *
091: * @param search the <code>IssueSearch</code> that created this result
092: */
093: QueryResult(IssueSearch search) {
094: this .search = search;
095: }
096:
097: /**
098: * Get the IssueId value.
099: * @return the IssueId value.
100: */
101: public final String getIssueId() {
102: return issueId;
103: }
104:
105: /**
106: * Set the IssueId value.
107: * @param newIssueId The new IssueId value.
108: */
109: public final void setIssueId(String newIssueId) {
110: this .issueId = newIssueId;
111: }
112:
113: /**
114: * Get the IdPrefix value.
115: * @return the IdPrefix value.
116: */
117: public final String getIdPrefix() {
118: return idPrefix;
119: }
120:
121: /**
122: * Set the IdPrefix value.
123: * @param newIdPrefix The new IdPrefix value.
124: */
125: public final void setIdPrefix(String newIdPrefix) {
126: this .idPrefix = newIdPrefix;
127: }
128:
129: /**
130: * Get the IdCount value.
131: * @return the IdCount value.
132: */
133: public final String getIdCount() {
134: return idCount;
135: }
136:
137: /**
138: * Set the IdCount value.
139: * @param newIdCount The new IdCount value.
140: */
141: public final void setIdCount(String newIdCount) {
142: this .idCount = newIdCount;
143: }
144:
145: /**
146: * Combines getIdPrefix() and getIdCount()
147: */
148: public final String getUniqueId() {
149: if (uniqueId == null) {
150: uniqueId = getIdPrefix() + getIdCount();
151: }
152:
153: return uniqueId;
154: }
155:
156: /**
157: * Get the AttributeValues value.
158: * @return the AttributeValues value.
159: */
160: public final List getAttributeValues() {
161: return attributeValues;
162: }
163:
164: /**
165: * Get the AttributeValues value.
166: * @return the AttributeValues value.
167: */
168: public final List getAttributeValuesAsCSV() {
169: List result = null;
170: if (attributeValues != null) {
171: result = new ArrayList(attributeValues.size());
172: for (Iterator i = attributeValues.iterator(); i.hasNext();) {
173: String csv = null;
174: List multiVal = (List) i.next();
175: if (multiVal.size() == 1) {
176: csv = (String) multiVal.get(0);
177: if (csv == null) {
178: csv = "";
179: }
180: } else {
181: StringBuffer sb = new StringBuffer();
182: boolean addComma = false;
183: for (Iterator j = multiVal.iterator(); j.hasNext();) {
184: if (addComma) {
185: sb.append(", ");
186: } else {
187: addComma = true;
188: }
189:
190: sb.append(j.next().toString());
191: }
192: csv = sb.toString();
193: }
194: result.add(csv);
195: }
196: }
197:
198: return result;
199: }
200:
201: /**
202: * Populate any attribute considered 'internal' with the proper value. To decide
203: * which should be filled, it will use the list 'preferences', which shares the same
204: * order than the attribute list.
205: *
206: * @param preferences
207: */
208: public void populateInternalAttributes(List preferences) {
209: this .populateInternalAttributes(preferences, null);
210: }
211:
212: /**
213: * Populate, including localization of dates, any attribute considered 'internal' with
214: * the proper value. To decide which should be filled, it will use the list 'preferences', which shares the same
215: * order than the attribute list.
216: *
217: * @param preferences
218: */
219: public void populateInternalAttributes(List preferences,
220: ScarabLocalizationTool l10n) {
221: if (preferences == null) {
222: // No preferences, no need to do anything
223: return;
224: }
225:
226: if (l10n == null) {
227: l10n = new ScarabLocalizationTool();
228: }
229:
230: for (int i = 0; i < preferences.size(); i++) {
231: RModuleUserAttribute rmua = (RModuleUserAttribute) preferences
232: .get(i);
233: if (rmua.isInternal()) {
234: List list = new ArrayList();
235: if (rmua.getInternalAttribute().equals(
236: RModuleUserAttribute.CREATED_BY.getName())) {
237: ScarabUser user = this .getCreatedByUser();
238: if (user != null) {
239: list.add(user.getName());
240: }
241: } else if (rmua.getInternalAttribute().equals(
242: RModuleUserAttribute.CREATED_DATE.getName())) {
243: Date date = this .getCreatedDate();
244: if (date != null) {
245: DateFormat df = new SimpleDateFormat(
246: L10NKeySet.ShortDatePattern
247: .getMessage(l10n));
248: list.add(df.format(this .getCreatedDate()));
249: }
250: } else if (rmua.getInternalAttribute().equals(
251: RModuleUserAttribute.MODIFIED_BY.getName())) {
252: ScarabUser user = this .getModifiedByUser();
253: if (user != null) {
254: list.add(user.getName());
255: }
256: } else if (rmua.getInternalAttribute().equals(
257: RModuleUserAttribute.MODIFIED_DATE.getName())) {
258: Date date = this .getModifiedDate();
259: if (date != null) {
260: DateFormat df = new SimpleDateFormat(
261: L10NKeySet.ShortDatePattern
262: .getMessage(l10n));
263: list.add(df.format(this .getModifiedDate()));
264: }
265: }
266: attributeValues.set(i, list);
267: }
268: }
269: }
270:
271: /**
272: * Set the AttributeValues value.
273: * @param newAttributeValues The new AttributeValues value.
274: */
275: public final void setAttributeValues(List newAttributeValues) {
276: this .attributeValues = newAttributeValues;
277: }
278:
279: /**
280: * Get the ModuleId value.
281: * @return the ModuleId value.
282: */
283: public final Integer getModuleId() {
284: return moduleId;
285: }
286:
287: /**
288: * Set the ModuleId value.
289: * @param newModuleId The new ModuleId value.
290: */
291: public final void setModuleId(Integer newModuleId) {
292: this .moduleId = newModuleId;
293: }
294:
295: /**
296: * Get the <code>Module</code> related thru getModuleId(). This method
297: * provides caching so that multiple QueryResult objects in the same
298: * resultset save db hits.
299: */
300: public final Module getModule() throws TorqueException {
301: return search.getModule(moduleId);
302: }
303:
304: /**
305: * Get the IssueTypeId value.
306: * @return the IssueTypeId value.
307: */
308: public final Integer getIssueTypeId() {
309: return issueTypeId;
310: }
311:
312: /**
313: * Set the IssueTypeId value.
314: * @param newIssueTypeId The new IssueTypeId value.
315: */
316: public final void setIssueTypeId(Integer newIssueTypeId) {
317: this .issueTypeId = newIssueTypeId;
318: }
319:
320: /**
321: * Get the <code>RModuleIssueType</code> related thru getModuleId() and
322: * getIssueTypeId(). This method provides caching so that multiple
323: * QueryResult objects in the same resultset save db hits.
324: */
325: public final RModuleIssueType getRModuleIssueType()
326: throws TorqueException {
327: return search.getRModuleIssueType(moduleId, issueTypeId);
328: }
329:
330: public void setCreatedBy(Integer createdBy) {
331: this .createdBy = createdBy;
332:
333: }
334:
335: public Integer getCreatedBy() {
336: return this .createdBy;
337: }
338:
339: public ScarabUser getCreatedByUser() {
340: ScarabUser user = null;
341: try {
342: user = ScarabUserImplPeer
343: .retrieveScarabUserImplByPK(this .createdBy);
344: } catch (Exception e) {
345: }
346: return user;
347: }
348:
349: public void setCreatedDate(Date created) {
350: this .createdDate = created;
351: }
352:
353: public Date getCreatedDate() {
354: return this .createdDate;
355: }
356:
357: public void setModifiedBy(Integer modified) {
358: this .modifiedBy = modified;
359: }
360:
361: public Integer getModifiedBy() {
362: return this .modifiedBy;
363: }
364:
365: public ScarabUser getModifiedByUser() {
366: ScarabUser user = null;
367: try {
368: user = ScarabUserImplPeer
369: .retrieveScarabUserImplByPK(this .modifiedBy);
370: } catch (Exception e) {
371: }
372: return user;
373: }
374:
375: public void setModifiedDate(Date modifiedDate) {
376: this .modifiedDate = modifiedDate;
377: }
378:
379: public Date getModifiedDate() {
380: return this.modifiedDate;
381: }
382: }
|