24f38d1dc1c770cba7d8b59a2319123403070624
[jalview.git] / src / jalview / ws / uimodel / PDBRestRequest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3  * Copyright (C) 2014 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21
22 package jalview.ws.uimodel;
23
24 import jalview.bin.Cache;
25 import jalview.datamodel.SequenceI;
26 import jalview.ws.dbsources.PDBRestClient.PDBDocField;
27
28 import java.util.Collection;
29
30 /**
31  * Represents the PDB request to be consumed by the PDBRestClient
32  * 
33  * @author tcnofoegbu
34  *
35  */
36 public class PDBRestRequest
37 {
38   private String fieldToSearchBy;
39
40   private String searchTerm;
41
42   private String fieldToSortBy;
43
44   private SequenceI associatedSequence;
45
46   private boolean allowEmptySequence;
47
48   private boolean allowUnpublishedEntries = Cache.getDefault(
49           "ALLOW_UNPUBLISHED_PDB_QUERYING", false);
50
51   private int responseSize;
52
53   private boolean isSortAscending;
54
55   private Collection<PDBDocField> wantedFields;
56
57   public String getFieldToSearchBy()
58   {
59     return fieldToSearchBy;
60   }
61
62   public void setFieldToSearchBy(String fieldToSearchBy)
63   {
64     this.fieldToSearchBy = fieldToSearchBy;
65   }
66
67   public String getSearchTerm()
68   {
69     return searchTerm;
70   }
71
72   public void setSearchTerm(String searchTerm)
73   {
74     this.searchTerm = searchTerm;
75   }
76
77   public boolean isAllowEmptySeq()
78   {
79     return allowEmptySequence;
80   }
81
82   public void setAllowEmptySeq(boolean allowEmptySeq)
83   {
84     this.allowEmptySequence = allowEmptySeq;
85   }
86
87   public int getResponseSize()
88   {
89     return responseSize;
90   }
91
92   public void setResponseSize(int responseSize)
93   {
94     this.responseSize = responseSize;
95   }
96
97   public Collection<PDBDocField> getWantedFields()
98   {
99     return wantedFields;
100   }
101
102   public void setWantedFields(Collection<PDBDocField> wantedFields)
103   {
104     this.wantedFields = wantedFields;
105   }
106
107   public String getFieldToSortBy()
108   {
109     return fieldToSortBy;
110   }
111
112   public void setFieldToSortBy(String fieldToSortBy, boolean isSortAscending)
113   {
114     this.fieldToSortBy = fieldToSortBy;
115     this.isSortAscending = isSortAscending;
116   }
117
118   public boolean isAscending()
119   {
120     return isSortAscending;
121   }
122
123   public SequenceI getAssociatedSequence()
124   {
125     return associatedSequence;
126   }
127
128   public void setAssociatedSequence(SequenceI associatedSequence)
129   {
130     this.associatedSequence = associatedSequence;
131   }
132
133   public String getQuery()
134   {
135     return fieldToSearchBy + searchTerm
136             + (isAllowEmptySeq() ? "" : " AND molecule_sequence:['' TO *]")
137             + (isAllowUnpublishedEntries() ? "" : " AND status:REL");
138   }
139
140   public String toString()
141   {
142     return "Query : " + getQuery() + " sort field: " + fieldToSortBy
143             + " isAsc: " + isAscending() + " Associated Seq : "
144             + associatedSequence;
145   }
146
147   public boolean isAllowUnpublishedEntries()
148   {
149     return allowUnpublishedEntries;
150   }
151
152   public void setAllowUnpublishedEntries(boolean allowUnpublishedEntries)
153   {
154     this.allowUnpublishedEntries = allowUnpublishedEntries;
155   }
156 }