View Javadoc
1   package uk.ac.ebi.intenz.webapp.dtos;
2   
3   import javax.servlet.http.HttpServletRequest;
4   
5   import org.apache.struts.action.ActionErrors;
6   import org.apache.struts.action.ActionForm;
7   import org.apache.struts.action.ActionMapping;
8   
9   import uk.ac.ebi.intenz.domain.constants.EnzymeViewConstant;
10  import uk.ac.ebi.intenz.domain.constants.XrefDatabaseConstant;
11  
12  /**
13   * @author Michael Darsow
14   * @version $Revision: 1.2 $ $Date: 2008/01/28 12:33:07 $
15   */
16  public class EnzymeLinkDTO extends ActionForm implements Comparable {
17    // ------------------------------ FIELDS ------------------------------
18  
19    private String databaseName;
20    private String databaseCode;
21    private String source;
22    private String url;
23    private String accession;
24    private String name;
25    private String sourceDisplay;
26    private String view;
27    private String viewDisplayString;
28    private String viewDisplayImage;
29    private String dataComment;
30  
31    // --------------------------- CONSTRUCTORS ---------------------------
32  
33    public EnzymeLinkDTO() {
34      databaseName = "";
35      databaseCode = "";
36      url = "";
37      accession = "";
38      name = "";
39      source = "INTENZ";
40      view = "INTENZ";
41      sourceDisplay = "IntEnz";
42      viewDisplayString = "all views";
43      viewDisplayImage = "<img src=\"images/blue_bullet.gif\"/><img src=\"images/green_bullet.gif\"/><img src=\"images/red_bullet.gif\"/>";
44      dataComment = "";
45    }
46  
47    public EnzymeLinkDTO(EnzymeLinkDTO enzymeLinkDTO) {
48      setDatabaseName(enzymeLinkDTO.getDatabaseName());
49      setDatabaseCode(enzymeLinkDTO.getDatabaseCode());
50      setSource(enzymeLinkDTO.getSource());
51      setUrl(enzymeLinkDTO.getUrl());
52      setAccession(enzymeLinkDTO.getAccession());
53      setName(enzymeLinkDTO.getName());
54      setSourceDisplay(enzymeLinkDTO.getSourceDisplay());
55      setView(enzymeLinkDTO.getView());
56      setViewDisplayString(enzymeLinkDTO.getViewDisplayString());
57      setViewDisplayImage(enzymeLinkDTO.getViewDisplayImage());
58      setDataComment(enzymeLinkDTO.getDataComment());
59    }
60  
61    // --------------------- GETTER / SETTER METHODS ---------------------
62  
63    public String getAccession() {
64      return accession;
65    }
66  
67    public void setAccession(String accession) {
68      this.accession = accession;
69    }
70  
71    public String getDatabaseCode() {
72      return databaseCode;
73    }
74  
75    public void setDatabaseCode(String databaseCode) {
76      this.databaseCode = databaseCode;
77    }
78  
79    public String getDatabaseName() {
80      return databaseName;
81    }
82  
83    /**
84     * Sets the database name <b>and</b> code.
85     *
86     * @param databaseName
87     */
88    public void setDatabaseName(String databaseName) {
89      this.databaseName = databaseName;
90      this.databaseCode = XrefDatabaseConstant.getDatabaseCodeOf(databaseName);
91    }
92  
93    public String getName() {
94       // if its a prosite link set the correct name.
95      if( this.databaseCode.equals(XrefDatabaseConstant.PROSITE.getDatabaseCode()))
96        this.name = XrefDatabaseConstant.PROSITE.getDisplayName();
97      return name;
98    }
99  
100   public void setName(String name) {
101     this.name = name;
102   }
103 
104   public String getSource() {
105     return source;
106   }
107 
108   public void setSource(String source) {
109     this.source = source;
110   }
111 
112   public String getSourceDisplay() {
113     return sourceDisplay;
114   }
115 
116   public void setSourceDisplay(String sourceDisplay) {
117     this.sourceDisplay = sourceDisplay;
118   }
119 
120   public String getUrl() {
121     return url;
122   }
123 
124   public void setUrl(String url) {
125     this.url = url;
126   }
127 
128   public String getView() {
129     return view;
130   }
131 
132   public void setView(String view) {
133     this.view = view;
134   }
135 
136   public String getViewDisplayImage() {
137     return viewDisplayImage;
138   }
139 
140   public void setViewDisplayImage(String viewDisplayImage) {
141     this.viewDisplayImage = viewDisplayImage;
142   }
143 
144   public String getViewDisplayString() {
145     return viewDisplayString;
146   }
147 
148   public void setViewDisplayString(String viewDisplayString) {
149     this.viewDisplayString = viewDisplayString;
150   }
151 
152     public String getDataComment() {
153         return dataComment;
154     }
155 
156     public void setDataComment(String dataComment) {
157         this.dataComment = dataComment;
158     }
159 
160 
161   // ------------------------ CANONICAL METHODS ------------------------
162 
163   public boolean equals(Object o) {
164     if (this == o) return true;
165     if (!(o instanceof EnzymeLinkDTO)) return false;
166 
167     final EnzymeLinkDTO enzymeLinkDTO = (EnzymeLinkDTO) o;
168 
169     if (accession != null ? !accession.equals(enzymeLinkDTO.accession) : enzymeLinkDTO.accession != null) return false;
170     if (databaseName != null ? !databaseName.equals(enzymeLinkDTO.databaseName) : enzymeLinkDTO.databaseName != null) return false;
171     if (name != null ? !name.equals(enzymeLinkDTO.name) : enzymeLinkDTO.name != null) return false;
172     if (url != null ? !url.equals(enzymeLinkDTO.url) : enzymeLinkDTO.url != null) return false;
173 
174     return true;
175   }
176 
177   public int hashCode() {
178     int result;
179     result = (databaseName != null ? databaseName.hashCode() : 0);
180     result = 29 * result + (url != null ? url.hashCode() : 0);
181     result = 29 * result + (accession != null ? accession.hashCode() : 0);
182     result = 29 * result + (name != null ? name.hashCode() : 0);
183     return result;
184   }
185 
186   public String toString() {
187     StringBuffer output = new StringBuffer();
188     output.append("databaseName: ");
189     output.append(databaseName);
190     output.append("\n");
191     output.append("databaseCode: ");
192     output.append(databaseCode);
193     output.append("\n");
194     output.append("source: ");
195     output.append(source);
196     output.append("\n");
197     output.append("url: ");
198     output.append(url);
199     output.append("\n");
200     output.append("accession: ");
201     output.append(accession);
202     output.append("\n");
203     output.append("name: ");
204     output.append(name);
205     output.append("\n");
206     output.append("sourceDisplay: ");
207     output.append(sourceDisplay);
208     output.append("\n");
209     output.append("view: ");
210     output.append(view);
211     output.append("\n");
212     output.append("viewDisplayString: ");
213     output.append(viewDisplayString);
214     output.append("\n");
215     output.append("viewDisplayImage: ");
216     output.append(viewDisplayImage);
217     output.append("\n");
218     return output.toString();
219   }
220 
221   // ------------------------ INTERFACE METHODS ------------------------
222 
223   // --------------------- Interface Comparable ---------------------
224 
225   /**
226    * Used for ordering links in a collection.
227    * <p/>
228    * Static and other links are ordered by their xrefDatabaseConstant name, SwissProt and MIM cross-references by their name
229    * and PROSITE links by their accession. Other links are ordered by their specific URL if the xrefDatabaseConstant name is the same.
230    *
231    * @param o The object to be compared to this.
232    * @return neg, 0 or pos. value to indicate the order of these two objects.
233    * @throws NullPointerException if <code>o</code> is <code>null</code>.
234    */
235   public int compareTo(Object o) {
236     if (o == null) throw new NullPointerException("Parameter 'o' must not be null.");
237     EnzymeLinkDTO enzymeLinkDTO = (EnzymeLinkDTO) o;
238 
239     if (databaseName.equals(enzymeLinkDTO.getDatabaseName())) {
240       if (name.equals(enzymeLinkDTO.getName())) {
241         if (accession.equals(enzymeLinkDTO.getAccession())) {
242           return url.compareTo(enzymeLinkDTO.getUrl());
243         }
244         return accession.compareTo(enzymeLinkDTO.getAccession());
245       }
246       return name.compareTo(enzymeLinkDTO.getName());
247     }
248 
249     return databaseName.compareTo(enzymeLinkDTO.getDatabaseName());
250   }
251 
252   // -------------------------- OTHER METHODS --------------------------
253 
254   public void reset(ActionMapping mapping, HttpServletRequest request) {
255     databaseName = "";
256     databaseCode = "";
257     source = "";
258     url = "";
259     accession = "";
260     name = "";
261     sourceDisplay = "";
262     view = "";
263     viewDisplayString = "";
264     viewDisplayImage = "";
265   }
266 
267   public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
268     ActionErrors errors = new ActionErrors();
269     updateView();
270     return errors;
271   }
272 
273   /**
274    * Updates <code>viewDisplayImage</code> and <code>viewDisplayString</code> using the given <code>view</code> value.
275    */
276   private void updateView() {
277     if (view != null && !view.equals("")) {
278       viewDisplayImage = EnzymeViewConstant.toDisplayImage(view);
279       viewDisplayString = EnzymeViewConstant.toDisplayString(view);
280     }
281   }
282 
283   private void validateCASRegistryNumber() {
284     if(this.getDatabaseCode().equals(XrefDatabaseConstant.CAS.getDatabaseCode())) {
285 //      return IntEnzValidations.validateCASRegistryNumberFormat()
286     }
287   }
288 }
289