KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > AttributeValue


1 package org.tigris.scarab.om;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 // JDK classes
50
import java.util.List JavaDoc;
51 import java.util.ArrayList JavaDoc;
52 import java.util.Locale JavaDoc;
53 import java.sql.Connection JavaDoc;
54
55 import org.apache.commons.lang.ObjectUtils;
56
57 // Turbine classes
58
import org.apache.torque.TorqueException;
59 import org.apache.torque.om.Persistent;
60 import org.apache.fulcrum.localization.Localization;
61
62 import org.tigris.scarab.tools.localization.L10NKeySet;
63 import org.tigris.scarab.tools.localization.LocalizationKey;
64 import org.tigris.scarab.util.ScarabConstants;
65 import org.tigris.scarab.util.ScarabException;
66 import org.tigris.scarab.util.Log;
67 import org.tigris.scarab.om.ScarabUserManager;
68 import org.tigris.scarab.om.Module;
69
70 /**
71  * This class is for dealing with Issue Attribute Values
72  *
73  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
74  * @author <a HREF="mailto:jon@collab.net">Jon S. Stevens</a>
75  * @author <a HREF="mailto:elicia@collab.net">Elicia David</a>
76  * @version $Id: AttributeValue.java 9104 2004-05-10 21:04:51Z dabbous $
77  */

78 public abstract class AttributeValue
79     extends BaseAttributeValue
80     implements Persistent
81 {
82     private ActivitySet activitySet;
83     private Integer JavaDoc oldOptionId;
84     private Integer JavaDoc oldUserId;
85     private String JavaDoc oldValue;
86     private Integer JavaDoc oldNumericValue;
87     private boolean oldOptionIdIsSet;
88     private boolean oldUserIdIsSet;
89     private boolean oldValueIsSet;
90     private boolean oldNumericValueIsSet;
91     private AttributeValue chainedValue;
92     
93     private String JavaDoc activityDescription = null;
94     private Activity saveActivity = null;
95
96     private static String JavaDoc className = "AttributeValue";
97
98     
99     /** Creates a new attribute. Do not do anything here.
100      * All initialization should be performed in init().
101      */

102     protected AttributeValue()
103     {
104         oldOptionIdIsSet = false;
105         oldUserIdIsSet = false;
106         oldValueIsSet = false;
107         oldNumericValueIsSet = false;
108     }
109
110     /**
111      * Get the value of chainedValue.
112      * @return value of chainedValue.
113      */

114     public AttributeValue getChainedValue()
115     {
116         return chainedValue;
117     }
118     
119     /**
120      * Set the value of chainedValue.
121      * @param v Value to assign to chainedValue.
122      */

123     public void setChainedValue(AttributeValue v)
124         throws Exception JavaDoc
125     {
126         if (v == null)
127         {
128             this.chainedValue = null;
129         }
130         else
131         {
132             if (v.getAttributeId() == null && getAttributeId() != null)
133             {
134                 v.setAttributeId(getAttributeId());
135             }
136             else if (v.getAttribute() != null
137                      && !v.getAttribute().equals(getAttribute()))
138             {
139                 throw new ScarabException(L10NKeySet.ExceptionCantChainAttributeValues,
140                                           v.getAttributeId(),
141                                           getAttributeId());
142             }
143             
144             if (v.getIssueId() == null && getIssueId() != null)
145             {
146                 v.setIssueId(getIssueId());
147             }
148             else if (v.getIssue() != null
149                       && !v.getIssue().equals(getIssue()))
150             {
151                 throw new ScarabException(L10NKeySet.ExceptionCantChainIssues,
152                                           v.getIssueId(),
153                                           getIssueId());
154             }
155
156             if (this.chainedValue == null)
157             {
158                 this.chainedValue = v;
159             }
160             else
161             {
162                 chainedValue.setChainedValue(v);
163             }
164             
165             if (activitySet != null)
166             {
167                 v.startActivitySet(activitySet);
168             }
169         }
170     }
171
172     /**
173      * This method returns a flat List of all AttributeValues that might
174      * be chained to this one. This AttributeValue will be first in the List.
175      *
176      * @return a <code>List</code> of AttributeValue's
177      */

178     public List JavaDoc getValueList()
179     {
180         List JavaDoc list = new ArrayList JavaDoc();
181         list.add(this);
182         AttributeValue av = getChainedValue();
183         while (av != null)
184         {
185             list.add(av);
186             av = av.getChainedValue();
187         }
188         return list;
189     }
190
191     /**
192      * sets the AttributeId for this as well as any chained values.
193      */

194     public void setAttributeId(Integer JavaDoc nk)
195         throws TorqueException
196     {
197         super.setAttributeId(nk);
198         if (chainedValue != null)
199         {
200             chainedValue.setAttributeId(nk);
201         }
202     }
203
204     /**
205      * sets the IssueId for this as well as any chained values.
206      */

207     public void setIssueId(Long JavaDoc nk)
208         throws TorqueException
209     {
210         super.setIssueId(nk);
211         if (chainedValue != null)
212         {
213             chainedValue.setIssueId(nk);
214         }
215     }
216
217     /**
218      * Enters this attribute value into a activitySet. All changes to a
219      * value must occur within a activitySet. The activitySet is cleared
220      * once the attribute value is saved.
221      *
222      * @param activitySet a <code>ActivitySet</code> value
223      * @exception ScarabException if a new activitySet is set before
224      * the value is saved.
225      */

226     public void startActivitySet(ActivitySet activitySet)
227         throws ScarabException, Exception JavaDoc
228     {
229         if (activitySet == null)
230         {
231             throw new ScarabException(L10NKeySet.ExceptionCanNotStartActivitySet);
232         }
233         
234         if (this.activitySet == null)
235         {
236             this.activitySet = activitySet;
237         }
238         else
239         {
240             throw new ScarabException(L10NKeySet.ExceptionActivitySetInProgress);
241         }
242 /*
243 This is wrong. It prevented the old/new value stuff from working properly!
244 If we have an existing issue and we change some attributes, then when the
245 history was created, the data was not valid in it for some reason. I'm not
246 quite sure why this was added. (JSS)
247
248 Leaving here so that John can remove or fix.
249
250         oldOptionIdIsSet = false;
251         oldValueIsSet = false;
252         oldOptionId = null;
253         oldValue = null;
254 */

255
256         // Check for previous active activities on this attribute
257
// If they exist, set old value for this activity
258
List JavaDoc result = null;
259         Issue issue = getIssue();
260         if (issue != null)
261         {
262             result = issue
263                 .getActivitiesWithNullEndDate(getAttribute());
264         }
265         if (result != null && result.size() > 0)
266         {
267             for (int i=0; i<result.size(); i++)
268             {
269                 Activity a = (Activity)result.get(i);
270                 oldOptionId = a.getNewOptionId();
271                 oldValue = a.getNewValue();
272             }
273         }
274         if (chainedValue != null)
275         {
276             chainedValue.startActivitySet(activitySet);
277         }
278     }
279     
280     private void endActivitySet()
281     {
282         this.activitySet = null;
283         this.saveActivity = null;
284         oldOptionId = null;
285         oldValue = null;
286         oldOptionIdIsSet = false;
287         oldValueIsSet = false;
288         if (chainedValue != null)
289         {
290             chainedValue.endActivitySet();
291         }
292     }
293
294     private void checkActivitySet(LocalizationKey l10nKey)
295         throws ScarabException
296     {
297         if (activitySet == null)
298         {
299             throw new ScarabException(l10nKey);
300         }
301     }
302
303     public String JavaDoc getQueryKey()
304     {
305         String JavaDoc key = super.getQueryKey();
306         if (key == null || key.length() == 0)
307         {
308             try
309             {
310                 key = "__" + getAttribute().getQueryKey();
311             }
312             catch (Exception JavaDoc e)
313             {
314                 key = "";
315             }
316         }
317         
318         return key;
319     }
320
321     public boolean equals(Object JavaDoc obj)
322     {
323         boolean b = false;
324         if (obj instanceof AttributeValue)
325         {
326             b = super.equals(obj);
327             if (!b)
328             {
329                 //FIXME! this code will equate 2 AttributeValues that are
330
// multivalued, but are in a flat list.
331
AttributeValue aval = (AttributeValue)obj;
332                 b = (getChainedValue() == null) &&
333                     ObjectUtils.equals(aval.getAttributeId(), getAttributeId())
334                     && ObjectUtils.equals(aval.getIssueId(), getIssueId());
335             }
336         }
337         return b;
338     }
339
340     public int hashCode()
341     {
342         int retVal = 0;
343
344         if (getChainedValue() != null || getPrimaryKey() != null)
345         {
346             // get the hash code from the primary key
347
// field from BaseObject
348
retVal = super.hashCode();
349         }
350         else
351         {
352             int issueHashCode = 0;
353             if (getIssueId() != null)
354             {
355                 issueHashCode = getIssueId().hashCode();
356             }
357             retVal = getAttributeId().hashCode() ^ issueHashCode;
358         }
359         return retVal;
360     }
361
362     public String JavaDoc toString()
363     {
364         try
365         {
366             String JavaDoc s = '{' + super.toString() + ": " + getAttribute().getName();
367             if (getOptionId() != null)
368             {
369                 s += " optionId=" + getOptionId();
370             }
371             if (getUserId() != null)
372             {
373                 s += " userId=" + getUserId();
374             }
375             if (getValue() != null)
376             {
377                 s += " value=" + getValue();
378             }
379             
380             return s + '}';
381         }
382         catch (Exception JavaDoc e)
383         {
384             return super.toString();
385         }
386     }
387
388     /**
389      * Get the OptionId
390      * @return String
391      */

392     public String JavaDoc getOptionIdAsString()
393     {
394         String JavaDoc optionIdString = "";
395         if (getOptionId() != null)
396         {
397             optionIdString = getOptionId().toString();
398         }
399         return optionIdString;
400     }
401
402     /**
403      * Makes sure to set the Value as well, to make display of the
404      * option easier
405      *
406      * @param optionId a <code>Integer</code> value
407      */

408     public void setOptionId(Integer JavaDoc optionId)
409         throws TorqueException
410     {
411         if ( optionId != null )
412         {
413             Module module = getIssue().getModule();
414             IssueType issueType = getIssue().getIssueType();
415             if (module == null || issueType == null)
416             {
417                 AttributeOption option = AttributeOptionManager
418                     .getInstance(optionId);
419                 setValueOnly(option.getName());
420             }
421             else
422             {
423                 // FIXME! create a key and get the instance directly from
424
// the manager.
425
List JavaDoc options = null;
426                 try
427                 {
428                     options = module
429                         .getRModuleOptions(getAttribute(), issueType);
430                 }
431                 catch (Exception JavaDoc e)
432                 {
433                     if (e instanceof TorqueException)
434                     {
435                         throw (TorqueException)e; //EXCEPTION
436
}
437                     else
438                     {
439                         throw new TorqueException(e); //EXCEPTION
440
}
441                 }
442                 for (int i=options.size()-1; i>=0; i--)
443                 {
444                     RModuleOption option = (RModuleOption)options.get(i);
445                     if (option.getOptionId().equals(optionId))
446                     {
447                         setValueOnly(option.getDisplayValue());
448                         break;
449                     }
450                 }
451             }
452         }
453         else
454         {
455             // any reason to set a option_id to null, once its already set?
456
setValueOnly(null);
457         }
458         
459         setOptionIdOnly(optionId);
460     }
461
462     /**
463      * Makes sure to set the Value as well
464      *
465      * @param v
466      */

467     public void setNumericValue(Integer JavaDoc v)
468     {
469         setValueOnly(String.valueOf(v));
470         if (v != getNumericValue())
471         {
472             // if the value is set multiple times before saving only
473
// save the last saved value
474
if (!isNew() && !oldNumericValueIsSet)
475             {
476                 oldNumericValue = getNumericValue();
477                 oldNumericValueIsSet = true;
478             }
479             super.setNumericValue(v);
480         }
481     }
482
483     protected void setOptionIdOnly(Integer JavaDoc optionId)
484         throws TorqueException
485     {
486         if (!ObjectUtils.equals(optionId, getOptionId()))
487         {
488             // if the value is set multiple times before saving only
489
// save the last saved value
490
if (!isNew() && !oldOptionIdIsSet && getOptionId() != null)
491             {
492                 oldOptionId = getOptionId();
493                 oldOptionIdIsSet = true;
494             }
495             super.setOptionId(optionId);
496         }
497     }
498
499     /**
500      * Makes sure to set the Value as well, to make display of the
501      * user easier
502      *
503      * @param userId a <code>Integer</code> value
504      */

505     public void setUserId(Integer JavaDoc userId)
506         throws TorqueException
507     {
508         if (userId != null)
509         {
510             ScarabUser user = ScarabUserManager.getInstance(userId);
511             setValueOnly(user.getUserName());
512         }
513         else
514         {
515             // any reason to set a user_id to null, once its already set?
516
setValueOnly(null);
517         }
518
519         setUserIdOnly(userId);
520     }
521
522     protected void setUserIdOnly(Integer JavaDoc value)
523         throws TorqueException
524     {
525         if (!ObjectUtils.equals(value, getUserId()))
526         {
527             // if the value is set multiple times before saving only
528
// save the last saved value
529
if (!isNew() && !oldUserIdIsSet)
530             {
531                 oldUserId = getUserId();
532                 oldUserIdIsSet = true;
533             }
534             super.setUserId(value);
535         }
536     }
537
538     /**
539      * Not implemented always throws an exception
540      *
541      * @return a <code>Integer[]</code> value
542      * @exception Exception if an error occurs
543      */

544     public Integer JavaDoc[] getOptionIds()
545         throws Exception JavaDoc
546     {
547         List JavaDoc optionIds = new ArrayList JavaDoc();
548         if (getOptionId() != null)
549         {
550             optionIds.add(getOptionId());
551         }
552         AttributeValue chainedAV = getChainedValue();
553         while (chainedAV != null)
554         {
555             if (chainedAV.getOptionId() != null)
556             {
557                 optionIds.add(chainedAV.getOptionId());
558             }
559             chainedAV = chainedAV.getChainedValue();
560         }
561         if (Log.get().isDebugEnabled())
562         {
563             Log.get().debug(this + " optionIds: " + optionIds);
564         }
565         
566         return (Integer JavaDoc[])optionIds.toArray(new Integer JavaDoc[optionIds.size()]);
567     }
568
569     public void setOptionIds(Integer JavaDoc[] ids)
570         throws Exception JavaDoc
571     {
572         if (ids != null && ids.length > 0)
573         {
574             setOptionId(ids[0]);
575         }
576         if (ids != null && ids.length > 1)
577         {
578             for (int i=1; i<ids.length; i++)
579             {
580                 AttributeValue av = AttributeValue
581                     .getNewInstance(getAttributeId(), getIssue());
582                 setChainedValue(av);
583                 av.setOptionId(ids[i]);
584             }
585         }
586     }
587
588     /**
589      * Not implemented always throws an exception
590      *
591      * @return a <code>Integer[]</code> value
592      * @exception Exception if an error occurs
593      */

594     public Integer JavaDoc[] getUserIds()
595         throws Exception JavaDoc
596     {
597         throw new ScarabException(L10NKeySet.ExceptionGetUserIdsNotImplemented);
598     }
599
600     public void setUserIds(Integer JavaDoc[] ids)
601         throws Exception JavaDoc
602     {
603         if (ids != null && ids.length > 0)
604         {
605             setUserId(ids[0]);
606         }
607         if (ids != null && ids.length > 1)
608         {
609             for (int i=1; i<ids.length; i++)
610             {
611                 AttributeValue av = AttributeValue
612                     .getNewInstance(getAttributeId(), getIssue());
613                 setChainedValue(av);
614                 av.setUserId(ids[i]);
615             }
616         }
617     }
618
619     public void setValue(String JavaDoc value)
620     {
621         setValueOnly(value);
622     }
623
624     protected void setValueOnly(String JavaDoc value)
625     {
626         if (!ObjectUtils.equals(value, getValue()))
627         {
628             // if the value is set multiple times before saving only
629
// save the last saved value
630
if (!isNew() && !oldValueIsSet)
631             {
632                 oldValue = getValue();
633                 oldValueIsSet = true;
634             }
635             super.setValue(value);
636         }
637     }
638
639     public boolean isSet()
640     {
641         return !(getOptionId() == null && getValue() == null
642                  && getUserId() == null);
643     }
644
645     public boolean isRequired()
646        throws Exception JavaDoc
647     {
648         return getRModuleAttribute().getRequired();
649     }
650
651     public RModuleAttribute getRModuleAttribute()
652         throws Exception JavaDoc
653     {
654         Issue issue = getIssue();
655         RModuleAttribute rma = null;
656         if (issue != null)
657         {
658             Module module = issue.getModule();
659             if (module != null)
660             {
661                 rma = module.getRModuleAttribute(
662                     getAttribute(), getIssue().getIssueType());
663             }
664             else
665             {
666                 throw new Exception JavaDoc ("Module is null: Please report this issue."); //EXCEPTION
667
}
668         }
669         else
670         {
671             throw new Exception JavaDoc ("Issue is null: Please report this issue."); //EXCEPTION
672
}
673         return rma;
674     }
675
676     public AttributeOption getAttributeOption()
677         throws TorqueException
678     {
679         return getAttribute()
680             .getAttributeOption(getOptionId());
681     }
682
683     /**
684      * if the Attribute related to this value is marked as relevant
685      * to quick search in the module related to the Issue
686      * related to this value.
687      *
688      * @return a <code>boolean</code> value
689      */

690     public boolean isQuickSearchAttribute()
691         throws Exception JavaDoc
692     {
693         boolean result = false;
694         List JavaDoc qsAttributes = getIssue().getIssueType()
695             .getQuickSearchAttributes(getIssue().getModule());
696         for (int i=qsAttributes.size()-1; i>=0; i--)
697         {
698             if (((Attribute)qsAttributes.get(i)).equals(getAttribute()))
699             {
700                 result = true;
701                 break;
702             }
703         }
704         return result;
705     }
706
707     /**
708      * Creates, initializes and returns a new AttributeValue.
709      * @return new Attribute instance
710      * @param rma the Attribute's rma
711      * @param issue Issue object which this attribute is associated with
712      */

713     public static AttributeValue getNewInstance(
714         RModuleAttribute rma, Issue issue) throws TorqueException
715     {
716         return getNewInstance(rma.getAttributeId(), issue);
717     }
718
719     /**
720      * Creates, initializes and returns a new AttributeValue.
721      * @return new AttributeValue instance
722      * @param issue Issue object which this attributeValue is associated
723      * @param attId the Attribute's Id
724      */

725     public static AttributeValue getNewInstance(
726         Integer JavaDoc attId, Issue issue) throws TorqueException
727     {
728         Attribute attribute = AttributeManager.getInstance(attId);
729         return getNewInstance(attribute, issue);
730     }
731
732     /**
733      * Creates, initializes and returns a new AttributeValue.
734      * @return new AttributeValue instance
735      * @param attribute the Attribute
736      * @param issue Issue object which this attributeValue is associated
737      */

738     public static synchronized AttributeValue getNewInstance(
739         Attribute attribute, Issue issue) throws TorqueException
740     {
741         AttributeValue attv = null;
742         try
743         {
744             String JavaDoc className = attribute
745                 .getAttributeType().getJavaClassName();
746             attv = (AttributeValue)
747                 Class.forName(className).newInstance();
748             attv.setAttribute(attribute);
749             attv.setIssue(issue);
750     
751             attv.init();
752         }
753         catch (Exception JavaDoc e)
754         {
755             throw new TorqueException(e); //EXCEPTION
756
}
757         return attv;
758     }
759
760     /**
761      * Loads from database data specific for this Attribute including Name.
762      * These are data common to all Attribute instances with same id.
763      * Data retrieved here will then be used in setResources.
764      * @return Object containing Attribute resources which will be
765      * used in setResources.
766      */

767     protected abstract Object JavaDoc loadResources() throws Exception JavaDoc;
768     
769     /**
770      * This method is used by an Attribute instance to obtain
771      * specific resources such as option list for SelectOneAttribute.
772      * It may, for example put them into instance variables. Attributes
773      * may use common resources as-is or create it's own resources
774      * based on common, it should not, however, modify common resources
775      * since they will be used by other Attribute instances.
776      *
777      * @param resources Resources common for Attributes with the specified id.
778      */

779     protected abstract void setResources(Object JavaDoc resources);
780         
781     /** Override this method if you need any initialization for this attr.
782      * @throws Exception Generic Exception
783      */

784     public abstract void init() throws Exception JavaDoc;
785     
786     public boolean supportsVoting()
787     {
788         return false;
789     }
790     
791     public AttributeValue copy() throws TorqueException
792     {
793         AttributeValue copyObj = AttributeValue
794             .getNewInstance(getAttributeId(), getIssue());
795         return copyInto(copyObj);
796     }
797
798     public void save(Connection JavaDoc dbcon)
799         throws TorqueException
800     {
801         if (isModified() && !getAttribute().isUserAttribute())
802         {
803             String JavaDoc desc = null;
804             try
805             {
806                 checkActivitySet(L10NKeySet.ExceptionCanNotSaveAttributeValue);
807                 desc = getActivityDescription();
808             }
809             catch (Exception JavaDoc e)
810             {
811                 throw new TorqueException(e); //EXCEPTION
812
}
813             // Save activity record
814
// Save new activity record, if activity has not been set
815
if (saveActivity == null)
816             {
817                 if (getDeleted())
818                 {
819                     saveActivity = ActivityManager
820                         .create(getIssue(), getAttribute(), activitySet,
821                                 desc, null, getNumericValue(), ScarabConstants.INTEGER_0,
822                                 getUserId(), null, getOptionId(), null,
823                                 getValue(), null, dbcon);
824                 }
825                 else
826                 {
827                     saveActivity = ActivityManager
828                         .create(getIssue(), getAttribute(), activitySet,
829                                 desc, null, oldNumericValue, getNumericValue(),
830                                 oldUserId, getUserId(), oldOptionId, getOptionId(),
831                                 oldValue, getValue(), dbcon);
832                 }
833             }
834         }
835         super.save(dbcon);
836         if (chainedValue != null)
837         {
838             chainedValue.save(dbcon);
839         }
840         endActivitySet();
841     }
842
843     /**
844      * Gets the Activity record associated with this AttributeValue
845      * It can only be retrieved after the save() method has been called
846      * since that is when it is generated.
847      */

848     public Activity getActivity()
849     {
850         return this.saveActivity;
851     }
852
853     public void setActivity(Activity activity)
854     {
855         this.saveActivity = activity;
856     }
857
858     /**
859      * Allows you to override the description for
860      * the activity that is generated when this attributevalue
861      * is saved.
862      */

863     public void setActivityDescription(String JavaDoc string)
864     {
865         this.activityDescription = string;
866     }
867
868     /**
869      * Not sure it is a good idea to save description in activity record
870      * the description can be generated from the other data.
871      */

872     private String JavaDoc getActivityDescription()
873         throws Exception JavaDoc
874     {
875         if (activityDescription != null)
876         {
877             return activityDescription;
878         }
879         String JavaDoc attributeName = getRModuleAttribute().getDisplayValue();
880         String JavaDoc newValue = getValue();
881
882         String JavaDoc result = null;
883         if (getDeleted())
884         {
885             result = Localization.format(
886                 ScarabConstants.DEFAULT_BUNDLE_NAME,
887                 getLocale(),
888                 "AttributeHasBeenUndefined", attributeName);
889         }
890         else
891         {
892             if (newValue.length() > 30)
893             {
894                 newValue = newValue.substring(0,30) + "...";
895             }
896             if (oldValue == null)
897             {
898                 Object JavaDoc[] args = {
899                     attributeName,
900                     newValue
901                 };
902                 result = Localization.format(
903                     ScarabConstants.DEFAULT_BUNDLE_NAME,
904                     getLocale(),
905                     "AttributeSetToNewValue", args);
906             }
907             else
908             {
909                 // so that we don't modify the existing oldValue
910
String JavaDoc tmpOldValue = null;
911                 if (oldValue.length() > 30)
912                 {
913                     tmpOldValue = oldValue.substring(0,30) + "...";
914                 }
915                 else
916                 {
917                     tmpOldValue = oldValue;
918                 }
919                 Object JavaDoc[] args = {
920                     attributeName,
921                     tmpOldValue,
922                     newValue
923                 };
924                 result = Localization.format(
925                     ScarabConstants.DEFAULT_BUNDLE_NAME,
926                     getLocale(),
927                     "AttributeChangedFromToNewValue", args);
928             }
929         }
930         return result;
931     }
932
933     /**
934      * Sets the properties of one attribute value based on another
935      * NOTE: Does not copy the deleted field
936      */

937     public void setProperties(AttributeValue attVal1)
938         throws Exception JavaDoc
939     {
940         setAttribute(attVal1.getAttribute());
941         setIssue(attVal1.getIssue());
942         setNumericValue(attVal1.getNumericValue());
943         setOptionId(attVal1.getOptionId());
944         setUserId(attVal1.getUserId());
945         setValue(attVal1.getValue());
946     }
947
948     /**
949      * Returns a (possibly user-specific) locale.
950      *
951      * @return a Locale selected for the Fulcrum Localization context
952      */

953     private Locale JavaDoc getLocale()
954     {
955         return ScarabConstants.DEFAULT_LOCALE;
956     }
957 }
958
959
960
961
Popular Tags