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   import org.apache.struts.action.ActionMessage;
9   
10  import uk.ac.ebi.biobabel.util.StringUtil;
11  import uk.ac.ebi.intenz.domain.constants.EnzymeViewConstant;
12  import uk.ac.ebi.intenz.webapp.utilities.IntEnzValidations;
13  import uk.ac.ebi.xchars.SpecialCharacters;
14  import uk.ac.ebi.xchars.XMLErrorReport;
15  import uk.ac.ebi.xchars.utilities.XCharsValidator;
16  
17  /**
18   * @author Michael Darsow
19   * @version $Revision: 1.2 $ $Date: 2008/01/28 12:33:07 $
20   */
21  public class ReferenceDTO extends ActionForm {
22  
23    private String pubId;
24    private String type;
25    private String authors;
26    private String title;
27    private String year;
28    private String pubName;
29    private String firstPage;
30    private String lastPage;
31    private String edition;
32    private String editor;
33    private String volume;
34    private String publisher;
35    private String publisherPlace;
36    private String pubMedId;
37    private String medlineId;
38    private String view;
39    private String source;
40    private String sourceDisplay;
41    private String viewDisplayString;
42    private String viewDisplayImage;
43  
44    private String xmlAuthors;
45    private String xmlTitle;
46    private String xmlPubName;
47    private String xmlEditor;
48    private String xmlPublisher;
49  
50    public ReferenceDTO() {
51      pubId = "";
52      type = "J";
53      authors = "";
54      title = "";
55      year = "";
56      pubName = "";
57      firstPage = "";
58      lastPage = "";
59      edition = "";
60      editor = "";
61      volume = "";
62      publisher = "";
63      publisherPlace = "";
64      pubMedId = "";
65      medlineId = "";
66      source = "INTENZ";
67      view = "INTENZ";
68      sourceDisplay = "IntEnz";
69      viewDisplayString = "all views";
70      viewDisplayImage = "\"<img src=\\\"images/blue_bullet.gif\\\"/><img src=\\\"images/green_bullet.gif\\\"/><img src=\\\"images/red_bullet.gif\\\"/>\"";
71      xmlAuthors = "";
72      xmlTitle = "";
73      xmlPubName = "";
74      xmlEditor = "";
75      xmlPublisher = "";
76    }
77  
78    public ReferenceDTO(ReferenceDTO referenceDTO) {
79      setPubId(referenceDTO.getPubId());
80      setType(referenceDTO.getType());
81      setAuthors(referenceDTO.getAuthors());
82      setTitle(referenceDTO.getTitle());
83      setYear(referenceDTO.getYear());
84      setPubName(referenceDTO.getPubName());
85      setFirstPage(referenceDTO.getFirstPage());
86      setLastPage(referenceDTO.getLastPage());
87      setEdition(referenceDTO.getEdition());
88      setEditor(referenceDTO.getEditor());
89      setVolume(referenceDTO.getVolume());
90      setPublisher(referenceDTO.getPublisher());
91      setPublisherPlace(referenceDTO.getPublisherPlace());
92      setPubMedId(referenceDTO.getPubMedId());
93      setMedlineId(referenceDTO.getMedlineId());
94      setView(referenceDTO.getView());
95      setSource(referenceDTO.getSource());
96      setSourceDisplay(referenceDTO.getSourceDisplay());
97      setViewDisplayString(referenceDTO.getViewDisplayString());
98      setViewDisplayImage(referenceDTO.getViewDisplayImage());
99      setXmlAuthors(referenceDTO.getXmlAuthors());
100     setXmlTitle(referenceDTO.getXmlTitle());
101     setXmlPubName(referenceDTO.getXmlPubName());
102     setXmlEditor(referenceDTO.getXmlEditor());
103     setXmlPublisher(referenceDTO.getXmlPublisher());
104   }
105 
106     @Override
107   public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
108     ActionErrors errors = new ActionErrors();
109 
110     SpecialCharacters encoding = (SpecialCharacters) request.getSession().getAttribute("characters");
111     updateAuthors(encoding);
112     updateTitle(encoding);
113     updateEditor(encoding);
114     updatePubName(encoding);
115     updatePublisher(encoding);
116     updateView();
117 
118     // Name:
119     if (StringUtil.isNullOrEmpty(xmlPubName)){
120     	errors.add("reference", new ActionMessage("validator.reference.name.required"));
121     }
122 
123     // Authors:
124     XMLErrorReport xmlErrors = XCharsValidator.validate(xmlAuthors);
125     if (xmlErrors != null)
126     	errors.add("reference",
127     			new ActionMessage("errors.form.xchars", "authors", xmlAuthors, xmlErrors.getErrorMessage()));
128     if (!IntEnzValidations.hasNoUnicode(xmlAuthors))
129     	errors.add("reference", new ActionMessage("errors.form.unicode", "authors", xmlAuthors));
130 
131     // Editor:
132     xmlErrors = XCharsValidator.validate(xmlEditor);
133     if (xmlErrors != null)
134     	errors.add("reference",
135     			new ActionMessage("errors.form.xchars", "editor", xmlEditor, xmlErrors.getErrorMessage()));
136     if (!IntEnzValidations.hasNoUnicode(xmlEditor))
137     	errors.add("reference", new ActionMessage("errors.form.unicode", "editor", xmlEditor));
138 
139     // Title:
140     if (!StringUtil.isNullOrEmpty(xmlTitle)){
141         xmlErrors = XCharsValidator.validate(xmlTitle);
142         if (xmlErrors != null)
143         	errors.add("reference",
144         			new ActionMessage("errors.form.xchars", "title", xmlTitle, xmlErrors.getErrorMessage()));
145         if (!IntEnzValidations.hasNoUnicode(xmlTitle))
146         	errors.add("reference", new ActionMessage("errors.form.unicode", "title", xmlTitle));
147     }
148 
149 //	if (!StringUtil.isNullOrEmpty(edition) && !StringUtil.isInteger(edition)){
150 //      ActionMessage message = new ActionMessage("errors.form.reference.edition");
151 //      errors.add("reference", message);
152 //	}
153     
154     if (StringUtil.isNullOrEmpty(year)){
155       ActionMessage message = new ActionMessage("errors.form.reference.year.missing");
156       errors.add("reference", message);
157     }
158     return errors;
159   }
160 
161     @Override
162   public void reset(ActionMapping mapping, HttpServletRequest request) {
163     pubId = "";
164     type = "J";
165     authors = "";
166     title = "";
167     year = "";
168     pubName = "";
169     firstPage = "";
170     lastPage = "";
171     edition = "";
172     editor = "";
173     volume = "";
174     publisher = "";
175     publisherPlace = "";
176     pubMedId = "";
177     medlineId = "";
178     view = "";
179     source = "";
180     sourceDisplay = "";
181     viewDisplayString = "";
182     viewDisplayImage = "";
183     xmlAuthors = "";
184     xmlTitle = "";
185     xmlPubName = "";
186     xmlEditor = "";
187     xmlPublisher = "";
188   }
189 
190   /**
191    * A reference is regarded as an empty reference if the fields below do not contain a value.
192    *
193    * @return <code>true</code> if at least one of the checked fields does contain a value.
194    */
195   public boolean isEmpty() {
196     return (xmlAuthors == null || xmlAuthors.equals("")) && (xmlTitle == null || xmlTitle.equals("")) &&
197            (year == null || year.equals("")) && (xmlPubName == null || xmlPubName.equals("")) &&
198            (firstPage == null || firstPage.equals("")) && (lastPage == null || lastPage.equals("")) &&
199            (edition == null || edition.equals("")) && (xmlEditor == null || xmlEditor.equals("")) &&
200            (volume == null || volume.equals("")) && (xmlPublisher == null || xmlPublisher.equals("")) &&
201            (publisherPlace == null || publisherPlace.equals("")) && (pubMedId == null || pubMedId.equals(""));
202   }
203 
204     @Override
205   public boolean equals(Object o) {
206     if (this == o) return true;
207     if (!(o instanceof ReferenceDTO)) return false;
208 
209     final ReferenceDTO referenceDTO = (ReferenceDTO) o;
210 
211     if (edition != null ? !edition.equals(referenceDTO.edition) : referenceDTO.edition != null) return false;
212     if (firstPage != null ? !firstPage.equals(referenceDTO.firstPage) : referenceDTO.firstPage != null) return false;
213     if (lastPage != null ? !lastPage.equals(referenceDTO.lastPage) : referenceDTO.lastPage != null) return false;
214     if (pubMedId != null ? !pubMedId.equals(referenceDTO.pubMedId) : referenceDTO.pubMedId != null) return false;
215     if (publisherPlace != null ? !publisherPlace.equals(referenceDTO.publisherPlace) : referenceDTO.publisherPlace !=
216                                                                                        null)
217       return false;
218     if (type != null ? !type.equals(referenceDTO.type) : referenceDTO.type != null) return false;
219     if (volume != null ? !volume.equals(referenceDTO.volume) : referenceDTO.volume != null) return false;
220     if (xmlAuthors != null ? !xmlAuthors.equals(referenceDTO.xmlAuthors) : referenceDTO.xmlAuthors != null) return false;
221     if (xmlEditor != null ? !xmlEditor.equals(referenceDTO.xmlEditor) : referenceDTO.xmlEditor != null) return false;
222     if (xmlPubName != null ? !xmlPubName.equals(referenceDTO.xmlPubName) : referenceDTO.xmlPubName != null) return false;
223     if (xmlPublisher != null ? !xmlPublisher.equals(referenceDTO.xmlPublisher) : referenceDTO.xmlPublisher != null) return false;
224     if (xmlTitle != null ? !xmlTitle.equals(referenceDTO.xmlTitle) : referenceDTO.xmlTitle != null) return false;
225     if (year != null ? !year.equals(referenceDTO.year) : referenceDTO.year != null) return false;
226 
227     return true;
228   }
229 
230     @Override
231   public int hashCode() {
232     int result;
233     result = (type != null ? type.hashCode() : 0);
234     result = 29 * result + (year != null ? year.hashCode() : 0);
235     result = 29 * result + (firstPage != null ? firstPage.hashCode() : 0);
236     result = 29 * result + (lastPage != null ? lastPage.hashCode() : 0);
237     result = 29 * result + (edition != null ? edition.hashCode() : 0);
238     result = 29 * result + (volume != null ? volume.hashCode() : 0);
239     result = 29 * result + (publisherPlace != null ? publisherPlace.hashCode() : 0);
240     result = 29 * result + (pubMedId != null ? pubMedId.hashCode() : 0);
241     result = 29 * result + (xmlAuthors != null ? xmlAuthors.hashCode() : 0);
242     result = 29 * result + (xmlTitle != null ? xmlTitle.hashCode() : 0);
243     result = 29 * result + (xmlPubName != null ? xmlPubName.hashCode() : 0);
244     result = 29 * result + (xmlEditor != null ? xmlEditor.hashCode() : 0);
245     result = 29 * result + (xmlPublisher != null ? xmlPublisher.hashCode() : 0);
246     return result;
247   }
248 
249   private void updateAuthors(SpecialCharacters encoding) {
250     if (xmlAuthors != null && !xmlAuthors.equals("")) {
251       authors = encoding.xml2Display(xmlAuthors = xmlAuthors.trim());
252     }
253   }
254 
255   private void updateTitle(SpecialCharacters encoding) {
256     if (xmlTitle != null && !xmlTitle.equals("")) {
257       title = encoding.xml2Display(xmlTitle = xmlTitle.trim());
258     }
259   }
260 
261   private void updatePubName(SpecialCharacters encoding) {
262     if (xmlPubName != null && !xmlPubName.equals("")) {
263       pubName = encoding.xml2Display(xmlPubName = xmlPubName.trim());
264     }
265   }
266 
267   private void updateEditor(SpecialCharacters encoding) {
268     if (xmlEditor != null && !xmlEditor.equals("")) {
269       editor = encoding.xml2Display(xmlEditor = xmlEditor.trim());
270     }
271   }
272 
273   private void updatePublisher(SpecialCharacters encoding) {
274     if (xmlPublisher != null && !xmlPublisher.equals("")) {
275       publisher = encoding.xml2Display(xmlPublisher = xmlPublisher.trim());
276     }
277   }
278 
279   /**
280    * Updates <code>viewDisplayImage</code> and <code>viewDisplayString</code> using the given <code>view</code> value.
281    */
282   private void updateView() {
283     if (view != null && !view.equals("")) {
284       viewDisplayImage = EnzymeViewConstant.toDisplayImage(view);
285       viewDisplayString = EnzymeViewConstant.toDisplayString(view);
286     }
287   }
288 
289 
290   // ------------------------------- GETTER & SETTER --------------------------------
291 
292   public String getPubId() {
293     return pubId;
294   }
295 
296   public void setPubId(String pubId) {
297     this.pubId = pubId;
298   }
299 
300   public String getType() {
301     return type;
302   }
303 
304   public void setType(String type) {
305     this.type = type;
306   }
307 
308   public String getAuthors() {
309     return authors;
310   }
311 
312   public void setAuthors(String authors) {
313     this.authors = authors;
314   }
315 
316   public String getTitle() {
317     return title;
318   }
319 
320   public void setTitle(String title) {
321     this.title = title;
322   }
323 
324   public String getYear() {
325     return year;
326   }
327 
328   public void setYear(String year) {
329     this.year = year;
330   }
331 
332   public String getPubName() {
333     return pubName;
334   }
335 
336   public void setPubName(String pubName) {
337     this.pubName = pubName;
338   }
339 
340   public String getFirstPage() {
341     return firstPage;
342   }
343 
344   public void setFirstPage(String firstPage) {
345     this.firstPage = firstPage;
346   }
347 
348   public String getLastPage() {
349     return lastPage;
350   }
351 
352   public void setLastPage(String lastPage) {
353     this.lastPage = lastPage;
354   }
355 
356   public String getEdition() {
357     return edition;
358   }
359 
360   public void setEdition(String edition) {
361     this.edition = edition;
362   }
363 
364   public String getEditor() {
365     return editor;
366   }
367 
368   public void setEditor(String editor) {
369     this.editor = editor;
370   }
371 
372   public String getVolume() {
373     return volume;
374   }
375 
376   public void setVolume(String volume) {
377     this.volume = volume;
378   }
379 
380   public String getPublisher() {
381     return publisher;
382   }
383 
384   public void setPublisher(String publisher) {
385     this.publisher = publisher;
386   }
387 
388   public String getPublisherPlace() {
389     return publisherPlace;
390   }
391 
392   public void setPublisherPlace(String publisherPlace) {
393     this.publisherPlace = publisherPlace;
394   }
395 
396   public String getPubMedId() {
397     return pubMedId;
398   }
399 
400   public void setPubMedId(String pubMedId) {
401     this.pubMedId = pubMedId;
402   }
403 
404   public String getMedlineId() {
405     return medlineId;
406   }
407 
408   public void setMedlineId(String medlineId) {
409     this.medlineId = medlineId;
410   }
411 
412   public String getView() {
413     return view;
414   }
415 
416   public void setView(String view) {
417     this.view = view;
418   }
419 
420   public String getSource() {
421     return source;
422   }
423 
424   public void setSource(String source) {
425     this.source = source;
426   }
427 
428   public String getSourceDisplay() {
429     return sourceDisplay;
430   }
431 
432   public void setSourceDisplay(String sourceDisplay) {
433     this.sourceDisplay = sourceDisplay;
434   }
435 
436   public String getViewDisplayString() {
437     return viewDisplayString;
438   }
439 
440   public void setViewDisplayString(String viewDisplayString) {
441     this.viewDisplayString = viewDisplayString;
442   }
443 
444   public String getViewDisplayImage() {
445     return viewDisplayImage;
446   }
447 
448   public void setViewDisplayImage(String viewDisplayImage) {
449     this.viewDisplayImage = viewDisplayImage;
450   }
451 
452   public String getXmlAuthors() {
453     return xmlAuthors;
454   }
455 
456   public void setXmlAuthors(String xmlAuthors) {
457     this.xmlAuthors = xmlAuthors;
458   }
459 
460   public String getXmlTitle() {
461     return xmlTitle;
462   }
463 
464   public void setXmlTitle(String xmlTitle) {
465     this.xmlTitle = xmlTitle;
466   }
467 
468   public String getXmlPubName() {
469     return xmlPubName;
470   }
471 
472   public void setXmlPubName(String xmlPubName) {
473     this.xmlPubName = xmlPubName;
474   }
475 
476   public String getXmlEditor() {
477     return xmlEditor;
478   }
479 
480   public void setXmlEditor(String xmlEditor) {
481     this.xmlEditor = xmlEditor;
482   }
483 
484   public String getXmlPublisher() {
485     return xmlPublisher;
486   }
487 
488   public void setXmlPublisher(String xmlPublisher) {
489     this.xmlPublisher = xmlPublisher;
490   }
491 }