1 package uk.ac.ebi.intenz.webapp.dtos;
2
3 import org.apache.struts.action.ActionErrors;
4 import org.apache.struts.action.ActionForm;
5 import org.apache.struts.action.ActionMapping;
6
7 import javax.servlet.http.HttpServletRequest;
8
9 import uk.ac.ebi.intenz.domain.constants.EnzymeViewConstant;
10 import uk.ac.ebi.xchars.SpecialCharacters;
11
12
13
14
15
16 public class CofactorDTO extends ActionForm {
17
18 private String cofactorValue;
19 private String xmlCofactorValue;
20 private String orderIn;
21 private String source;
22 private String view;
23 private String sourceDisplay;
24 private String viewDisplayString;
25 private String viewDisplayImage;
26 private String accession;
27 private String compoundId;
28
29 public CofactorDTO() {
30 cofactorValue = "";
31 xmlCofactorValue = "";
32 orderIn = "0";
33 source = "INTENZ";
34 view = "INTENZ";
35 sourceDisplay = "IntEnz";
36 viewDisplayString = "all views";
37 viewDisplayImage = "<img src=\"images/blue_bullet.gif\"/><img src=\"images/green_bullet.gif\"/><img src=\"images/red_bullet.gif\"/>";
38 }
39
40 public CofactorDTO(CofactorDTO cofactorDTO) {
41 setCofactorValue(cofactorDTO.getCofactorValue());
42 setXmlCofactorValue(cofactorDTO.getXmlCofactorValue());
43 setOrderIn(cofactorDTO.getOrderIn());
44 setSource(cofactorDTO.getSource());
45 setView(cofactorDTO.getView());
46 setSourceDisplay(cofactorDTO.getSourceDisplay());
47 setViewDisplayString(cofactorDTO.getViewDisplayString());
48 setViewDisplayImage(cofactorDTO.getViewDisplayImage());
49 setAccession(cofactorDTO.accession);
50 }
51
52 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
53 ActionErrors errors = new ActionErrors();
54
55 updateView();
56 if (xmlCofactorValue != null && !xmlCofactorValue.equals("")) {
57 SpecialCharacters encoding = (SpecialCharacters) request.getSession().getAttribute("characters");
58 cofactorValue = encoding.xml2Display(xmlCofactorValue.trim());
59 }
60 return errors.isEmpty() ? null : errors;
61 }
62
63 public boolean equals(Object o) {
64 if (this == o) return true;
65 if (!(o instanceof CofactorDTO)) return false;
66
67 final CofactorDTO cofactorDTO = (CofactorDTO) o;
68
69 if (source != null ? !source.equals(cofactorDTO.source) : cofactorDTO.source != null) return false;
70 if (xmlCofactorValue != null ? !xmlCofactorValue.equals(cofactorDTO.xmlCofactorValue) : cofactorDTO.xmlCofactorValue != null)
71 return false;
72
73 return true;
74 }
75
76 public int hashCode() {
77 int result;
78 result = (xmlCofactorValue != null ? xmlCofactorValue.hashCode() : 0);
79 result = 29 * result + (source != null ? source.hashCode() : 0);
80 result = 29 * result + (accession != null? accession.hashCode() : 0);
81 return result;
82 }
83
84
85
86
87 private void updateView() {
88 if (view != null && !view.equals("")) {
89 viewDisplayImage = EnzymeViewConstant.toDisplayImage(view);
90 viewDisplayString = EnzymeViewConstant.toDisplayString(view);
91 }
92 }
93
94
95
96 public String getCofactorValue() {
97 return cofactorValue;
98 }
99
100 public void setCofactorValue(String cofactorValue) {
101 this.cofactorValue = cofactorValue;
102 }
103
104 public String getXmlCofactorValue() {
105 return xmlCofactorValue;
106 }
107
108 public void setXmlCofactorValue(String xmlCofactorValue) {
109 this.xmlCofactorValue = xmlCofactorValue;
110 }
111
112 public String getOrderIn() {
113 return orderIn;
114 }
115
116 public void setOrderIn(String orderIn) {
117 this.orderIn = orderIn;
118 }
119
120 public String getSource() {
121 return source;
122 }
123
124 public void setSource(String source) {
125 this.source = source;
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 getSourceDisplay() {
137 return sourceDisplay;
138 }
139
140 public void setSourceDisplay(String sourceDisplay) {
141 this.sourceDisplay = sourceDisplay;
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 getViewDisplayImage() {
153 return viewDisplayImage;
154 }
155
156 public void setViewDisplayImage(String viewDisplayImage) {
157 this.viewDisplayImage = viewDisplayImage;
158 }
159
160 public String getAccession() {
161 return accession;
162 }
163
164 public void setAccession(String accession) {
165 this.accession = accession;
166 }
167
168 public String getCompoundId() {
169 return compoundId;
170 }
171
172 public void setCompoundId(String compoundId) {
173 this.compoundId = compoundId;
174 }
175
176
177 }