001    /**
002     * Do we want to use this space for anything?  Eg, revision history?
003     */
004    package edu.nrao.sss.model.proposal;
005    
006    import org.apache.log4j.Logger;
007    
008    import edu.nrao.sss.util.EnumerationUtility;
009    
010    /** <i>Placeholder for time when we integrate proposal work.</i>
011     * An enumeration of proposal types.
012     * 
013     * @version 1.1
014     * @since   2006-03-03
015     */
016    public enum ProposalType
017    {
018      // Syntax restrictions will not allow these constants to
019      // precede the enumeration elements.  However, due to
020      // restrictions on forward-referencing, they can't
021      // come after the elements, either.  Perhaps this
022      // restriction will be lifted later on.  --DMH
023      //
024      // private static final boolean RAPID     = true;
025      // private static final boolean LARGE     = true;
026      // private static final boolean IMMEDIATE = true;
027      
028      // TODO Ask for help with comments
029    
030      /** Represents a regular proposal.
031       *  <p>
032       *  The acceptable names of this element (for use with
033       *  {@code getInstanceFromName(String)}) are
034       *  <i>REGULAR_PROPOSAL</i> and <i>Regular Proposal</i>.</p>
035       */
036      REGULAR_PROPOSAL("Regular Proposal",
037                     //Large?  Rapid?  Immediate?  
038                       false,  false,  false, "SUBMIT_ALERT_RECIPIENTS"), 
039    
040      /** Represents a proposal for a large survey.
041       *  <p>
042       *  The acceptable names of this element (for use with
043       *  {@code getInstanceFromName(String)}) are
044       *  <i>LARGE_PROPOSAL_SURVEY</i> and <i>Large Proposal - Survey</i>.</p>
045       */
046      LARGE_PROPOSAL_SURVEY("Large Proposal - Survey",
047                          //Large?  Rapid?  Immediate?  
048                            true,   false,  false, "LARGE_ALERT_RECIPIENTS"),
049    
050      /** Represents a proposal for a larger project.
051       *  <p>
052       *  The acceptable names of this element (for use with
053       *  {@code getInstanceFromName(String)}) are
054       *  <i>LARGE_PROPOSAL_LARGE_PROJECT</i> and
055       *  <i>Large Proposal - Large Project</i>.</p>
056       */
057      LARGE_PROPOSAL_LARGE_PROJECT("Large Proposal - Large Project",
058                                 //Large?  Rapid?  Immediate?  
059                                   true,   false,  false, "LARGE_ALERT_RECIPIENTS"),
060    
061      /** Represents a rapid response proposal for exploratory time.
062       *  <p>
063       *  The acceptable names of this element (for use with
064       *  {@code getInstanceFromName(String)}) are
065       *  <i>EXPLORATORY_TIME</i> and <i>Rapid Response - Exploratory Time</i>.</p>
066       */
067      EXPLORATORY_TIME("Rapid Response - Exploratory Time",
068                     //Large?  Rapid?  Immediate?  
069                       false,  true,   true, "EXPLORATORY_TIME_RECIPIENTS"), 
070    
071      /** Represents a rapid response proposal for a target of opportunity.
072       *  <p>
073       *  The acceptable names of this element (for use with
074       *  {@code getInstanceFromName(String)}) are
075       *  <i>TARGET_OF_OPPORTUNITY</i> and
076       *  <i>Rapid Response - Target of Opportunity</i>.</p>
077       */
078      TARGET_OF_OPPORTUNITY("Rapid Response - Target of Opportunity",
079                          //Large?  Rapid?  Immediate?  
080                            false,  true,   true, "TARGET_OF_OPPORTUNITY_RECIPIENTS"), 
081    
082      /** Represents a rapid response proposal for a know transient phenomenon.
083       *  <p>
084       *  The acceptable names of this element (for use with
085       *  {@code getInstanceFromName(String)}) are
086       *  <i>KNOWN_TRANSIENT_PHENOMENA</i> and
087       *  <i>Rapid Response - Known Transient Phenomena</i>.</p>
088       */
089      KNOWN_TRANSIENT_PHENOMENA("Rapid Response - Known Transient Phenomena",
090                              //Large?  Rapid?  Immediate?  
091                                false,  true,   false, "TRANSIENT_ALERT_RECIPIENTS"),
092    
093      /** Represents a proposal of unknown type.
094       *  <p>
095       *  This element is used to implement the
096       *  <i>Null Object Pattern</i>.  In situations where a method might
097       *  be tempted to return <i>null</i>, this element is returned instead.</p>
098       */
099      UNKNOWN("Unknown Proposal Type", false, false, false, "NONE");
100      
101      private final String  name;
102      private final boolean isLarge;
103      private final boolean isRapid;
104      private final boolean isImmediate;
105      private final String  emailLookup;
106    
107      private ProposalType(String name, boolean isLarge, boolean isRapid, boolean isImmediate,
108                           String emailLookup)
109      {
110        this.name        = name;
111        this.isLarge     = isLarge;
112        this.isRapid     = isRapid;
113        this.isImmediate = isImmediate;
114        this.emailLookup = emailLookup;
115      }
116      
117      public String toString()
118      {
119        return name;
120      }
121      
122      /**
123       * Returns true if the proposal requires a large amount of viewing time and 
124       * thus must go through a special referring process.  Science and technical
125       * justification file restrictions are relaxed for large proposals.
126       * 
127       * @return true if the Proposal requires extra telescope time; false otherwise.
128       */
129      public boolean isLargeProposal()
130      {
131        return isLarge;
132      }
133      
134      /**
135       * Returns true if the proposal is a rapid response proposal; false, otherwise.
136       * 
137       * @return true if the Proposal is rapid response; false otherwise.
138       */
139      public boolean isRapidResponse()
140      {
141        return isRapid;
142      }
143      
144      /**
145       * Returns true if the proposal needs to be put into the current proposal cycle
146       * as opposed to waiting until the next proposal deadline and going through the
147       * referring process.
148       * 
149       * @return true if the Proposal should be scheduled for the current proposal cycle;
150       *         false if the Proposal can wait until the next proposal deadline.
151       */
152      
153      public boolean isImmediateResponse()
154      {
155        return isImmediate;
156      }
157    
158      private static final Logger log = Logger.getLogger(ProposalType.class);
159      
160      /**
161       * Returns the web.xml tag used to look up the list of people who should be sent
162       * email for each type of proposal.
163       * 
164       * @return a String representing the tag used in web.xml to lookup the list of people
165       *         who should be sent email for each proposal type.
166       */
167      public String getEmailLookup()
168      {
169        // TODO Ask Susan if we need this.  (It's a carry-over from her ProposalType.)
170        if (this.equals(UNKNOWN))
171          log.error("An attempt was made to get the email lookup for ProposalType.UNKNOWN");
172          
173        return emailLookup;
174      }
175    
176      /**
177       * Returns a default proposal type.
178       * @return a default proposal type.
179       */
180      public static ProposalType getDefault()
181      {
182        return REGULAR_PROPOSAL;
183      }
184      
185      /**
186       * Returns the proposal type represented by {@code text}.
187       * <p>
188       * For details about the transformation, see
189       * {@link EnumerationUtility#enumFromString(Class, String)}.</p>
190       * 
191       * @param text a text representation of a proposal type.
192       * 
193       * @return the proposal type represented by {@code text}.
194       */
195      public static ProposalType fromString(String text)
196      {
197        return EnumerationUtility.getSharedInstance()
198                                 .enumFromString(ProposalType.class, text);
199      }
200    }