1 package uk.ac.ebi.intenz.webapp.dtos;
2
3 import java.io.IOException;
4 import java.net.HttpURLConnection;
5 import java.net.InetSocketAddress;
6 import java.net.Proxy;
7 import java.net.URL;
8 import java.net.URLConnection;
9 import java.sql.Connection;
10 import java.sql.SQLException;
11 import java.util.ArrayList;
12 import java.util.HashSet;
13 import java.util.Iterator;
14 import java.util.List;
15 import java.util.Set;
16
17 import javax.servlet.http.HttpServletRequest;
18
19 import org.apache.commons.collections.list.SetUniqueList;
20 import org.apache.struts.action.ActionErrors;
21 import org.apache.struts.action.ActionMapping;
22 import org.apache.struts.action.ActionMessage;
23 import org.apache.struts.action.ActionMessages;
24 import org.apache.struts.taglib.html.Constants;
25 import org.apache.struts.validator.ValidatorForm;
26
27 import uk.ac.ebi.biobabel.validator.DbIdentifierValidator;
28 import uk.ac.ebi.intenz.domain.constants.EnzymeNameTypeConstant;
29 import uk.ac.ebi.intenz.domain.constants.EnzymeSourceConstant;
30 import uk.ac.ebi.intenz.domain.constants.EnzymeViewConstant;
31 import uk.ac.ebi.intenz.domain.constants.Status;
32 import uk.ac.ebi.intenz.domain.constants.XrefDatabaseConstant;
33 import uk.ac.ebi.intenz.domain.enzyme.EnzymeCommissionNumber;
34 import uk.ac.ebi.intenz.domain.enzyme.EnzymeEntry;
35 import uk.ac.ebi.intenz.domain.enzyme.EnzymeLink;
36 import uk.ac.ebi.intenz.domain.exceptions.DomainException;
37 import uk.ac.ebi.intenz.domain.exceptions.EcException;
38 import uk.ac.ebi.intenz.mapper.EnzymeEntryMapper;
39 import uk.ac.ebi.intenz.webapp.utilities.AutoGrowingList;
40 import uk.ac.ebi.rhea.mapper.MapperException;
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 public class EnzymeDTO extends ValidatorForm {
133
134
135 private Integer uowId;
136
137 private boolean isActive;
138 private String id;
139 private String ec;
140 private String transferredEc;
141 private String transferredToEc;
142 private EnzymeNameDTO systematicName;
143 private String note;
144 private String historyLine;
145 private String latestHistoryEventNote;
146 private String latestHistoryEventClass;
147 private String latestHistoryEventGroupId;
148 private String latestHistoryEventId;
149 private String latestHistoryBeforeId;
150 private String latestHistoryAfterId;
151 private String statusCode;
152 private String statusText;
153 private String source;
154
155 private String className;
156 private String classEc;
157 private String subclassName;
158 private String subclassEc;
159 private String subSubclassName;
160 private String subSubclassEc;
161
162 private List commonNames;
163 private List<ReactionDTO> reactionDtos;
164 private List synonyms;
165 private List<CofactorDTO> cofactors;
166 private List links;
167 private List uniProtLinks;
168 private List comments;
169 private List<ReferenceDTO> references;
170
171 private String xcharsView;
172
173
174
175 public String getXcharsView () {
176 return xcharsView;
177 }
178
179 public void setXcharsView (String xcharsView) {
180 this.xcharsView = xcharsView;
181 }
182
183 public boolean isActive() {
184 return isActive;
185 }
186
187 public void setActive(boolean active) {
188 isActive = active;
189 }
190
191 public EnzymeDTO() {
192 isActive = true;
193 id = "";
194 ec = "";
195 systematicName = new EnzymeNameDTO();
196 systematicName.setName("");
197 systematicName.setXmlName("");
198 systematicName.setSource(EnzymeSourceConstant.INTENZ.toString());
199 systematicName.setSourceDisplay(EnzymeSourceConstant.INTENZ.toDisplayString());
200 systematicName.setView(EnzymeViewConstant.IUBMB_INTENZ.toString());
201 systematicName.setViewDisplayImage(EnzymeViewConstant.IUBMB_INTENZ.toDisplayImage());
202 systematicName.setViewDisplayString(EnzymeViewConstant.IUBMB_INTENZ.toDisplayString());
203 systematicName.setType(EnzymeNameTypeConstant.SYSTEMATIC_NAME.toString());
204 note = "";
205 historyLine = "";
206 latestHistoryEventNote = "";
207 latestHistoryEventClass = "";
208 latestHistoryEventGroupId = "";
209 latestHistoryEventId = "";
210 latestHistoryBeforeId = "";
211 latestHistoryAfterId = "";
212 statusCode = "SU";
213 statusText = "suggested";
214 source = "INTENZ";
215
216 className = "";
217 classEc = "";
218 subclassName = "";
219 subclassEc = "";
220 subSubclassName = "";
221 subSubclassEc = "";
222 xcharsView = "false";
223
224 commonNames = new AutoGrowingList(EnzymeNameDTO.class);
225 reactionDtos = new AutoGrowingList(ReactionDTO.class);
226 synonyms = new AutoGrowingList(EnzymeNameDTO.class);
227 cofactors = new AutoGrowingList(CofactorDTO.class);
228 links = new AutoGrowingList(EnzymeLinkDTO.class);
229 uniProtLinks = new AutoGrowingList(EnzymeLinkDTO.class);
230 comments = new AutoGrowingList(CommentDTO.class);
231 references = new AutoGrowingList(ReferenceDTO.class);
232 }
233
234 public EnzymeDTO(EnzymeDTO enzymeDTO) {
235 setUowId(enzymeDTO.getUowId());
236 setId(enzymeDTO.getId());
237 setEc(enzymeDTO.getEc());
238 setTransferredEc(enzymeDTO.getTransferredEc());
239 setSystematicName(new EnzymeNameDTO(enzymeDTO.getSystematicName()));
240 setNote(enzymeDTO.getNote());
241 setHistoryLine(enzymeDTO.getHistoryLine());
242 setLatestHistoryEventNote(enzymeDTO.getLatestHistoryEventNote());
243 setLatestHistoryEventClass(enzymeDTO.getLatestHistoryEventClass());
244 setLatestHistoryEventGroupId(enzymeDTO.getLatestHistoryEventGroupId());
245 setLatestHistoryEventId(enzymeDTO.getLatestHistoryEventId());
246 setStatusCode(enzymeDTO.getStatusCode());
247 setStatusText(enzymeDTO.getStatusText());
248 setSource(enzymeDTO.getSource());
249 setClassName(enzymeDTO.getClassName());
250 setClassEc(enzymeDTO.getClassEc());
251 setSubclassName(enzymeDTO.getSubclassName());
252 setSubclassEc(enzymeDTO.getSubclassEc());
253 setSubSubclassName(enzymeDTO.getSubSubclassName());
254 setSubSubclassEc(enzymeDTO.getSubSubclassEc());
255 setXcharsView(enzymeDTO.getXcharsView());
256
257 List commonNames = enzymeDTO.getCommonNames();
258 List newCommonNames = new AutoGrowingList(EnzymeNameDTO.class);
259 for (int iii = 0; iii < commonNames.size(); iii++) {
260 EnzymeNameDTO commonName = (EnzymeNameDTO) commonNames.get(iii);
261 newCommonNames.add(new EnzymeNameDTO(commonName));
262 }
263 setCommonNames(newCommonNames);
264
265 List reactions = enzymeDTO.getReactionDtos();
266 List newReactions = new AutoGrowingList(ReactionDTO.class);
267 for (int iii = 0; iii < reactions.size(); iii++) {
268 ReactionDTO reaction = (ReactionDTO) reactions.get(iii);
269 newReactions.add(new ReactionDTO(reaction));
270 }
271 setReactionDtos(newReactions);
272
273 List synonyms = enzymeDTO.getSynonyms();
274 List newSynonyms = new AutoGrowingList(EnzymeNameDTO.class);
275 for (int iii = 0; iii < synonyms.size(); iii++) {
276 EnzymeNameDTO synonym = (EnzymeNameDTO) synonyms.get(iii);
277 newSynonyms.add(new EnzymeNameDTO(synonym));
278 }
279 setSynonyms(newSynonyms);
280
281 List<CofactorDTO> cofactors = enzymeDTO.getCofactors();
282 List<CofactorDTO> newCofactors = new AutoGrowingList(CofactorDTO.class);
283 for (int iii = 0; iii < cofactors.size(); iii++) {
284 CofactorDTO cofactor = cofactors.get(iii);
285 newCofactors.add(new CofactorDTO(cofactor));
286 }
287 setCofactors(newCofactors);
288
289 List links = enzymeDTO.getLinks();
290 List newLinks = new AutoGrowingList(EnzymeLinkDTO.class);
291 for (int iii = 0; iii < links.size(); iii++) {
292 EnzymeLinkDTO link = (EnzymeLinkDTO) links.get(iii);
293 newLinks.add(new EnzymeLinkDTO(link));
294 }
295 setLinks(newLinks);
296
297 List uniProtLinks = enzymeDTO.getUniProtLinks();
298 List newUniprotLinks = new AutoGrowingList(EnzymeLinkDTO.class);
299 for (int iii = 0; iii < uniProtLinks.size(); iii++) {
300 EnzymeLinkDTO link = (EnzymeLinkDTO) uniProtLinks.get(iii);
301 newUniprotLinks.add(new EnzymeLinkDTO(link));
302 }
303 setUniProtLinks(newUniprotLinks);
304
305 List comments = enzymeDTO.getComments();
306 List newComments = new AutoGrowingList(CommentDTO.class);
307 for (int iii = 0; iii < comments.size(); iii++) {
308 CommentDTO comment = (CommentDTO) comments.get(iii);
309 newComments.add(new CommentDTO(comment));
310 }
311 setComments(newComments);
312
313 List<ReferenceDTO> references = enzymeDTO.getReferences();
314 List newReferences = new AutoGrowingList(ReferenceDTO.class);
315 for (int iii = 0; iii < references.size(); iii++) {
316 ReferenceDTO reference = (ReferenceDTO) references.get(iii);
317 newReferences.add(new ReferenceDTO(reference));
318 }
319 setReferences(newReferences);
320 }
321
322
323
324 public List getAllLinks() {
325 List allLinks = new AutoGrowingList(EnzymeLinkDTO.class);
326 allLinks.addAll(links);
327 allLinks.addAll(uniProtLinks);
328 return allLinks;
329 }
330
331 public String getClassEc() {
332 return classEc;
333 }
334
335 public void setClassEc(String classEc) {
336 this.classEc = classEc;
337 }
338
339 public String getClassName() {
340 return className;
341 }
342
343 public void setClassName(String className) {
344 this.className = className;
345 }
346
347 public List<CofactorDTO> getCofactors() {
348 return cofactors;
349 }
350
351 public void setCofactors(List<CofactorDTO> cofactors) {
352 this.cofactors = cofactors;
353 }
354
355 public List getComments() {
356 return comments;
357 }
358
359 public void setComments(List comments) {
360 this.comments = comments;
361 }
362
363 public List getCommonNames() {
364 return commonNames;
365 }
366
367 public void setCommonNames(List commonNames) {
368 this.commonNames = commonNames;
369 }
370
371 public String getEc() {
372 return ec;
373 }
374
375 public void setEc(String ec) {
376 this.ec = ec;
377 }
378
379 public boolean isPreliminaryEc(){
380 return EnzymeCommissionNumber.isPreliminary(ec);
381 }
382
383 public String getHistoryLine() {
384 return historyLine;
385 }
386
387 public void setHistoryLine(String historyLine) {
388 this.historyLine = historyLine;
389 }
390
391 public String getId() {
392 return id;
393 }
394
395 public void setId(String id) {
396 this.id = id;
397 }
398
399 public String getLatestHistoryAfterId() {
400 return latestHistoryAfterId;
401 }
402
403 public void setLatestHistoryAfterId(String latestHistoryAfterId) {
404 this.latestHistoryAfterId = latestHistoryAfterId;
405 }
406
407 public String getLatestHistoryBeforeId() {
408 return latestHistoryBeforeId;
409 }
410
411 public void setLatestHistoryBeforeId(String latestHistoryBeforeId) {
412 this.latestHistoryBeforeId = latestHistoryBeforeId;
413 }
414
415 public String getLatestHistoryEventClass() {
416 return latestHistoryEventClass;
417 }
418
419 public void setLatestHistoryEventClass(String latestHistoryEventClass) {
420 this.latestHistoryEventClass = latestHistoryEventClass;
421 }
422
423 public String getLatestHistoryEventGroupId() {
424 return latestHistoryEventGroupId;
425 }
426
427 public void setLatestHistoryEventGroupId(String latestHistoryEventGroupId) {
428 this.latestHistoryEventGroupId = latestHistoryEventGroupId;
429 }
430
431 public String getLatestHistoryEventId() {
432 return latestHistoryEventId;
433 }
434
435 public void setLatestHistoryEventId(String latestHistoryEventId) {
436 this.latestHistoryEventId = latestHistoryEventId;
437 }
438
439 public String getLatestHistoryEventNote() {
440 return latestHistoryEventNote;
441 }
442
443 public void setLatestHistoryEventNote(String latestHistoryEventNote) {
444 this.latestHistoryEventNote = latestHistoryEventNote;
445 }
446
447 public List getLinks() {
448 return links;
449 }
450
451 public void setLinks(List links) {
452 this.links = links;
453 }
454
455 public String getNote() {
456 return note;
457 }
458
459 public void setNote(String note) {
460 this.note = note;
461 }
462
463 public List<ReactionDTO> getReactionDtos() {
464 return reactionDtos;
465 }
466
467 public void setReactionDtos(List<ReactionDTO> reactions) {
468 this.reactionDtos = reactions;
469 }
470
471 public List<ReferenceDTO> getReferences() {
472 return references;
473 }
474
475 public void setReferences(List<ReferenceDTO> references) {
476 this.references = references;
477 }
478
479 public String getSource() {
480 return source;
481 }
482
483 public void setSource(String source) {
484 this.source = source;
485 }
486
487 public String getStatusCode() {
488 return statusCode;
489 }
490
491 public void setStatusCode(String statusCode) {
492 this.statusCode = statusCode;
493 }
494
495 public String getStatusText() {
496 return statusText;
497 }
498
499 public void setStatusText(String statusText) {
500 this.statusText = statusText;
501 }
502
503 public String getSubSubclassEc() {
504 return subSubclassEc;
505 }
506
507 public void setSubSubclassEc(String subSubclassEc) {
508 this.subSubclassEc = subSubclassEc;
509 }
510
511 public String getSubSubclassName() {
512 return subSubclassName;
513 }
514
515 public void setSubSubclassName(String subSubclassName) {
516 this.subSubclassName = subSubclassName;
517 }
518
519 public String getSubclassEc() {
520 return subclassEc;
521 }
522
523 public void setSubclassEc(String subclassEc) {
524 this.subclassEc = subclassEc;
525 }
526
527 public String getSubclassName() {
528 return subclassName;
529 }
530
531 public void setSubclassName(String subclassName) {
532 this.subclassName = subclassName;
533 }
534
535 public List getSynonyms() {
536 return synonyms;
537 }
538
539 public void setSynonyms(List synonyms) {
540 this.synonyms = synonyms;
541 }
542
543 public EnzymeNameDTO getSystematicName() {
544 return systematicName;
545 }
546
547 public void setSystematicName(EnzymeNameDTO systematicName) {
548 this.systematicName = systematicName;
549 }
550
551 public String getTransferredEc() {
552 return transferredEc;
553 }
554
555 public void setTransferredEc(String transferredEc) {
556 this.transferredEc = transferredEc;
557 }
558
559 public String getTransferredToEc() {
560 return transferredToEc;
561 }
562
563 public void setTransferredToEc(String transferredToEc) {
564 this.transferredToEc = transferredToEc;
565 }
566
567 public List getUniProtLinks() {
568 return uniProtLinks;
569 }
570
571 public void setUniProtLinks(List uniProtLinks) {
572 this.uniProtLinks = uniProtLinks;
573 }
574
575
576
577 public Integer getUowId() {
578 return uowId;
579 }
580
581 public void setUowId(Integer uowId) {
582 this.uowId = uowId;
583 }
584
585
586
587 public Object getCofactor(int index) {
588 return cofactors.toArray()[index];
589 }
590
591 public CommentDTO getComment(int index) {
592 return (CommentDTO) comments.get(index);
593 }
594
595 public EnzymeNameDTO getCommonName(int index) {
596 return (EnzymeNameDTO) commonNames.get(index);
597 }
598
599 public EnzymeLinkDTO getLink(int index) {
600 return (EnzymeLinkDTO) links.get(index);
601 }
602
603 public ReactionDTO getReactionDto(int index) {
604 return reactionDtos.get(index);
605 }
606
607 public ReferenceDTO getReference(int index) {
608 return references.get(index);
609 }
610
611 public EnzymeNameDTO getSynonym(int index) {
612 return (EnzymeNameDTO) synonyms.get(index);
613 }
614
615 public EnzymeLinkDTO getUniProtLink(int index) {
616 return (EnzymeLinkDTO) uniProtLinks.get(index);
617 }
618
619 public List getLinks(String dbCode){
620 List selectedLinks = new ArrayList();
621 for (int i = 0; i < links.size(); i++){
622 EnzymeLinkDTO link = (EnzymeLinkDTO) links.get(i);
623 if (link.getDatabaseCode().equals(dbCode))
624 selectedLinks.add(link);
625 }
626 return selectedLinks;
627 }
628
629 public List getGoLinks(){
630 return getLinks(XrefDatabaseConstant.GO.getDatabaseCode());
631 }
632
633 public List getCasLinks(){
634 return getLinks(XrefDatabaseConstant.CAS.getDatabaseCode());
635 }
636
637 @Override
638 public void reset(ActionMapping mapping, HttpServletRequest request) {
639
640 }
641
642 @Override
643 public ActionErrors validate(ActionMapping mapping,
644 HttpServletRequest request) {
645 ActionErrors errors = null;
646 if (isActive) {
647
648 errors = super.validate(mapping, request);
649
650 errors.add(systematicName.validate(mapping, request));
651
652
653 validateCommonNames(errors, mapping, request);
654
655
656 validateSynonyms(errors, mapping, request);
657
658
659 validateAllNames(errors, request);
660
661
662 validateReactions(errors, mapping, request);
663
664
665
666
667
668 validateComments(errors, mapping, request);
669
670
671 validateLinks(errors, mapping, request);
672
673
674 validateUniProtLinks(errors, mapping, request);
675
676
677 validateReferences(errors, mapping, request);
678
679 updateStatus();
680 } else {
681 errors = validateInactive(request, errors);
682 }
683
684
685 if (request.getParameter(Constants.TOKEN_KEY) != null) {
686 request.setAttribute(Constants.TOKEN_KEY,
687 request.getParameter(Constants.TOKEN_KEY));
688 }
689
690 return (errors == null || errors.isEmpty()) ? null : errors;
691 }
692
693
694
695
696
697
698
699 private ActionErrors validateInactive(HttpServletRequest request,
700 ActionErrors errors) {
701
702 if (transferredToEc != null && transferredToEc.length() > 0) {
703 if (errors == null) errors = new ActionErrors();
704 Connection con = (Connection)
705 request.getSession().getAttribute("connection");
706 EnzymeCommissionNumber targetEc = null;
707 try {
708 targetEc = EnzymeCommissionNumber.valueOf(transferredToEc);
709 EnzymeEntry targetEntry = null;
710 try {
711 targetEntry = new EnzymeEntryMapper().findByEc(
712 targetEc.getEc1(), targetEc.getEc2(),
713 targetEc.getEc3(), targetEc.getEc4(), Status.APPROVED,
714 con);
715 if (targetEntry == null) {
716 errors.add("transferredToEc", new ActionMessage(
717 "errors.application.ec.nonexisting", targetEc));
718 } else if (!targetEntry.isActive()) {
719 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
720 "errors.application.ec.inactive", targetEc));
721 }
722 } catch (Exception e) {
723 errors.add("transferredToEc", new ActionMessage(
724 "errors.application.database", transferredToEc));
725 }
726 } catch (Exception e) {
727 errors.add("transferredToEc", new ActionMessage(
728 "errors.application.ec.detail", transferredToEc));
729 }
730 }
731 return errors;
732 }
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749 private void validateCommonNames(ActionErrors errors, ActionMapping mapping, HttpServletRequest request) {
750 assert errors != null : "Parameter 'errors' must not be null.";
751 assert mapping != null : "Parameter 'mapping' must not be null.";
752 assert request != null : "Parameter 'request' must not be null.";
753
754 removeEmptyNameItems(commonNames);
755 removeDuplicates(commonNames);
756 boolean intenzViewUsed = false;
757 for (int iii = 0; iii < commonNames.size(); iii++) {
758
759 EnzymeNameDTO enzymeNameDTO = (EnzymeNameDTO) commonNames.get(iii);
760 errors.add(enzymeNameDTO.validate(mapping, request));
761
762 if (EnzymeViewConstant.isInIntEnzView(enzymeNameDTO.getView()) &&
763 ((enzymeNameDTO.getName() != null && !enzymeNameDTO.getName().equals("")) ||
764 (enzymeNameDTO.getXmlName() != null && !enzymeNameDTO.getXmlName().equals("")))) {
765 if (intenzViewUsed) {
766 ActionMessage message = new ActionMessage("errors.form.common_name.invalidView");
767 errors.add("commonName", message);
768 } else
769 intenzViewUsed = true;
770 }
771 }
772 }
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787 private void validateSynonyms(ActionErrors errors, ActionMapping mapping, HttpServletRequest request) {
788 assert errors != null : "Parameter 'errors' must not be null.";
789 assert mapping != null : "Parameter 'mapping' must not be null.";
790 assert request != null : "Parameter 'request' must not be null.";
791
792 removeEmptyNameItems(synonyms);
793 removeDuplicates(synonyms);
794 for (int iii = 0; iii < synonyms.size(); iii++) {
795 EnzymeNameDTO enzymeNameDTO = (EnzymeNameDTO) synonyms.get(iii);
796 errors.add(enzymeNameDTO.validate(mapping, request));
797 }
798 }
799
800
801
802
803
804
805
806 private void validateAllNames(ActionErrors errors, HttpServletRequest request) {
807 assert errors != null : "Parameter 'errors' must not be null.";
808 assert request != null : "Parameter 'request' must not be null.";
809
810 for (int iii = 0; iii < commonNames.size(); iii++) {
811 EnzymeNameDTO commonName = (EnzymeNameDTO) commonNames.get(iii);
812
813
814
815
816
817 for (int jjj = 0; jjj < synonyms.size(); jjj++) {
818 EnzymeNameDTO synonym = (EnzymeNameDTO) synonyms.get(jjj);
819 if (systematicName.getXmlName().equals(synonym.getXmlName())) {
820 ActionMessage message = new ActionMessage("errors.form.synonym.duplicate_sys_name", synonym.getName());
821 errors.add("otherNames", message);
822 return;
823 }
824 if (commonName.getXmlName().equals(synonym.getXmlName())) {
825 ActionMessage message = new ActionMessage("errors.form.common_name.duplicate_synonym", commonName.getName());
826 errors.add("commonName", message);
827 return;
828 }
829 }
830 }
831
832 }
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848 private void validateReactions(ActionErrors errors, ActionMapping mapping, HttpServletRequest request) {
849 assert errors != null : "Parameter 'errors' must not be null.";
850 assert mapping != null : "Parameter 'mapping' must not be null.";
851 assert request != null : "Parameter 'request' must not be null.";
852
853 removeEmptyReactionItems();
854 removeDuplicates(reactionDtos);
855 if (reactionDtos.size() == 0) {
856 ActionMessage message = new ActionMessage("errors.form.reaction.notExisting");
857 errors.add("reaction", message);
858 return;
859 }
860 for (int iii = 0; iii < reactionDtos.size(); iii++) {
861 ReactionDTO reactionDTO = reactionDtos.get(iii);
862 errors.add(reactionDTO.validate(mapping, request));
863 }
864 }
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906 private void validateComments(ActionErrors errors, ActionMapping mapping, HttpServletRequest request) {
907 assert errors != null : "Parameter 'errors' must not be null.";
908 assert mapping != null : "Parameter 'mapping' must not be null.";
909 assert request != null : "Parameter 'request' must not be null.";
910
911 removeEmptyCommentItems();
912 removeDuplicates(comments);
913 checkForPeriod(errors);
914 for (int iii = 0; iii < comments.size(); iii++) {
915 CommentDTO commentDTO = (CommentDTO) comments.get(iii);
916 errors.add(commentDTO.validate(mapping, request));
917 }
918 }
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939 private void validateLinks(ActionErrors errors, ActionMapping mapping, HttpServletRequest request) {
940 assert errors != null : "Parameter 'errors' must not be null.";
941 assert mapping != null : "Parameter 'mapping' must not be null.";
942 assert request != null : "Parameter 'request' must not be null.";
943
944 removeEmptyLinkItems();
945 removeLinkDuplicates();
946 try {
947 updateStaticLinks();
948 } catch (DomainException e) {
949 ActionMessage message = new ActionMessage(e.getMessageKey(), e.getProperty());
950 errors.add("links", message);
951 }
952 for (int iii = 0; iii < links.size(); iii++) {
953 EnzymeLinkDTO enzymeLinkDTO = (EnzymeLinkDTO) links.get(iii);
954 errors.add(enzymeLinkDTO.validate(mapping, request));
955 if (enzymeLinkDTO.getDatabaseName().equals(XrefDatabaseConstant.CAS.getDisplayName())) {
956 if (enzymeLinkDTO.getAccession() == null || enzymeLinkDTO.getAccession().equals("")) {
957 ActionMessage error = new ActionMessage("errors.form.link.invalidCasValue");
958 errors.add("links", error);
959 }
960
961 if (!DbIdentifierValidator.getInstance().validate(enzymeLinkDTO.getAccession(), DbIdentifierValidator.CAS_REGISTRY_NUMBER)){
962 ActionMessage error = new ActionMessage("errors.form.link.invalidCasFormat");
963 errors.add("links", error);
964 }
965 }
966 if (enzymeLinkDTO.getDatabaseName().equals(XrefDatabaseConstant.MEROPS.getDisplayName())) {
967 try {
968 URL url = new URL(enzymeLinkDTO.getUrl());
969 URLConnection connection = url.openConnection();
970 connection.connect();
971 } catch (IOException e) {
972 ActionMessage message = new ActionMessage("errors.form.link.invalidMeropsUrl");
973 errors.add("links", message);
974 }
975 }
976 if (enzymeLinkDTO.getDatabaseName().equals(XrefDatabaseConstant.MIM.getDisplayName())) {
977 if (enzymeLinkDTO.getAccession() == null || enzymeLinkDTO.getAccession().equals("") ||
978 enzymeLinkDTO.getName() == null || enzymeLinkDTO.getName().equals("")) {
979 ActionMessage message = new ActionMessage("errors.form.link.MimIncomplete");
980 errors.add("links", message);
981 }
982 }
983 if (enzymeLinkDTO.getDatabaseName().equals(XrefDatabaseConstant.PROSITE.getDisplayName())) {
984 if (enzymeLinkDTO.getAccession() == null || enzymeLinkDTO.getAccession().equals("")) {
985 ActionMessage message = new ActionMessage("errors.form.link.invalidPrositeValue");
986 errors.add("links", message);
987 } else {
988 enzymeLinkDTO.setUrl(XrefDatabaseConstant.PROSITE.getUrl() + enzymeLinkDTO.getAccession());
989 }
990 }
991 if (enzymeLinkDTO.getDatabaseName().equals(XrefDatabaseConstant.DIAGRAM.getDisplayName())) {
992 if (enzymeLinkDTO.getName() == null || enzymeLinkDTO.getName().equals("")) {
993 ActionMessage message = new ActionMessage("errors.form.link.invalidDiagramName");
994 errors.add("links", message);
995 }
996 try {
997 URL url = new URL(enzymeLinkDTO.getUrl());
998 Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("www-proxy.ebi.ac.uk", 8080));
999 HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
1000 if (connection.getResponseCode() != HttpURLConnection.HTTP_OK){
1001 ActionMessage message = new ActionMessage("errors.form.link.invalidDiagramUrl");
1002 errors.add("links", message);
1003 }
1004 } catch (IOException e) {
1005 ActionMessage message = new ActionMessage("errors.form.link.invalidDiagramUrl");
1006 errors.add("links", message);
1007 }
1008 }
1009 }
1010 }
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025 private void validateUniProtLinks(ActionErrors errors, ActionMapping mapping, HttpServletRequest request) {
1026 assert errors != null : "Parameter 'errors' must not be null.";
1027 assert mapping != null : "Parameter 'mapping' must not be null.";
1028 assert request != null : "Parameter 'request' must not be null.";
1029
1030 for (int iii = 0; iii < uniProtLinks.size(); iii++) {
1031 EnzymeLinkDTO enzymeLinkDTO = (EnzymeLinkDTO) uniProtLinks.get(iii);
1032 errors.add(enzymeLinkDTO.validate(mapping, request));
1033 }
1034 }
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049 private void validateReferences(ActionErrors errors, ActionMapping mapping, HttpServletRequest request) {
1050 assert errors != null : "Parameter 'errors' must not be null.";
1051 assert mapping != null : "Parameter 'mapping' must not be null.";
1052 assert request != null : "Parameter 'request' must not be null.";
1053
1054 removeEmptyReferenceItems();
1055 removeDuplicates(references);
1056 for (int iii = 0; iii < references.size(); iii++) {
1057 ReferenceDTO referenceDTO = (ReferenceDTO) references.get(iii);
1058 errors.add(referenceDTO.validate(mapping, request));
1059 }
1060 }
1061
1062 private void removeEmptyNameItems(List names) {
1063 assert names != null : "Parameter 'names' must not be null.";
1064 for (int iii = 0; iii < names.size(); iii++) {
1065 EnzymeNameDTO enzymeNameDTO = (EnzymeNameDTO) names.get(iii);
1066 if (enzymeNameDTO.getXmlName() == null || enzymeNameDTO.getXmlName().equals("")) {
1067 names.remove(iii);
1068 iii--;
1069 }
1070 }
1071 }
1072
1073 private void removeEmptyReactionItems() {
1074 for (int iii = 0; iii < reactionDtos.size(); iii++) {
1075 ReactionDTO reactionDTO = (ReactionDTO) reactionDtos.get(iii);
1076 if (reactionDTO.getXmlTextualRepresentation() == null || reactionDTO.getXmlTextualRepresentation().equals("")) {
1077 reactionDtos.remove(iii);
1078 iii--;
1079 }
1080 }
1081 }
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098 private void removeEmptyLinkItems() {
1099 assert links != null : "Parameter 'links' must not be null.";
1100 for (int iii = 0; iii < links.size(); iii++) {
1101 EnzymeLinkDTO enzymeLinkDTO = (EnzymeLinkDTO) links.get(iii);
1102 if (enzymeLinkDTO.getDatabaseName().equals(XrefDatabaseConstant.UNDEF.getDisplayName())) {
1103 links.remove(iii);
1104 iii--;
1105 }
1106 }
1107 }
1108
1109 private void removeEmptyCommentItems() {
1110 for (int iii = 0; iii < comments.size(); iii++) {
1111 CommentDTO commentDTO = (CommentDTO) comments.get(iii);
1112 if (commentDTO.getXmlComment() == null || commentDTO.getXmlComment().equals("")) {
1113 comments.remove(iii);
1114 iii--;
1115 }
1116 }
1117 }
1118
1119 private void removeEmptyReferenceItems() {
1120 assert references != null : "Parameter 'references' must not be null.";
1121 for (int iii = 0; iii < references.size(); iii++) {
1122 ReferenceDTO referenceDTO = references.get(iii);
1123 if (referenceDTO.isEmpty()) {
1124 references.remove(iii);
1125 iii--;
1126 }
1127 }
1128 }
1129
1130 private void checkForPeriod(ActionMessages errors) {
1131 for (int iii = 0; iii < comments.size(); iii++) {
1132 CommentDTO commentDTO = (CommentDTO) comments.get(iii);
1133 if (!commentDTO.getXmlComment().endsWith(".")) {
1134 ActionMessage error = new ActionMessage("errors.form.comment.missing_period", "" + (iii + 1));
1135 errors.add("comments", error);
1136 return;
1137 }
1138 }
1139 }
1140
1141
1142
1143
1144 private void removeLinkDuplicates() {
1145 assert links != null : "Parameter 'links' must not be null.";
1146 Set databaseNames = new HashSet();
1147 Set checkedLinks = new HashSet();
1148 for (int iii = 0; iii < links.size(); iii++) {
1149 EnzymeLinkDTO enzymeLinkDTO = (EnzymeLinkDTO) links.get(iii);
1150 if (databaseNames.contains(enzymeLinkDTO.getDatabaseName())) {
1151
1152 if (XrefDatabaseConstant.isUniqueXrefDatabaseName(enzymeLinkDTO.getDatabaseName())) {
1153 links.remove(enzymeLinkDTO);
1154 } else {
1155 for (Iterator it = checkedLinks.iterator(); it.hasNext();) {
1156 EnzymeLinkDTO checkedLink = (EnzymeLinkDTO) it.next();
1157 if (checkedLink.equals(enzymeLinkDTO)) links.remove(enzymeLinkDTO);
1158 }
1159 }
1160 } else {
1161 databaseNames.add(enzymeLinkDTO.getDatabaseName());
1162 checkedLinks.add(enzymeLinkDTO);
1163 }
1164 }
1165 }
1166
1167 private void removeDuplicates(List list) {
1168 list.retainAll(SetUniqueList.decorate(list));
1169 }
1170
1171
1172
1173
1174
1175
1176 private void updateStaticLinks() throws DomainException {
1177 assert links != null : "Parameter 'links' must not be null.";
1178 for (int iii = 0; iii < links.size(); iii++) {
1179 EnzymeLinkDTO enzymeLinkDTO = (EnzymeLinkDTO) links.get(iii);
1180 EnzymeLink staticLink = EnzymeLink.getStaticLink(XrefDatabaseConstant.valueOf(enzymeLinkDTO.getDatabaseCode()));
1181 if (staticLink != null) {
1182 enzymeLinkDTO.setDatabaseName(staticLink.getXrefDatabaseConstant().getDisplayName());
1183 enzymeLinkDTO.setName(staticLink.getName());
1184 enzymeLinkDTO.setUrl(staticLink.getFullUrl(
1185 EnzymeCommissionNumber.isPreliminary(ec)?
1186 enzymeLinkDTO.getAccession() : ec));
1187 }
1188 }
1189 }
1190
1191 private void updateStatus() {
1192 if (statusCode != null && !statusCode.equals("")) {
1193 statusText = Status.fromCode(statusCode).toString();
1194 }
1195 }
1196 }
1197