@@ -157,87 +157,85 @@ public void setLabId(String labId)
157157 this .labId = labId ;
158158 }
159159
160- public boolean validate (Errors errors ) throws SQLException
160+ public boolean validate (Errors errors )
161161 {
162162 if (getQueryKey () == null || StringUtils .trimToNull (getQueryKey ()) == null )
163163 errors .reject (null , "The Search Criteria must be entered." );
164164 String qValue = getQueryValue ();
165- if (getQueryKey () != null && getQueryKey (). equals ( PepDBSchema . COLUMN_PARENT_SEQUENCE ) )
165+ if (getQueryKey () != null )
166166 {
167- if (StringUtils .trimToNull (qValue ) == null )
168- errors .reject (null , "The Parent Sequence must be entered." );
169- }
170- if (getQueryKey () != null && getQueryKey ().equals (PepDBSchema .COLUMN_CHILD_SEQUENCE ))
171- {
172- if (StringUtils .trimToNull (qValue ) == null )
173- errors .reject (null , "The Child Sequence must be entered." );
174- }
175- if (getQueryKey () != null && getQueryKey ().equals (PepDBSchema .COLUMN_PEPTIDE_GROUP_ID ))
176- {
177- if (StringUtils .trimToNull (qValue ) == null )
178- errors .reject (null , "Peptide Group must be selected to get peptides in a group." );
179- /*
180- if(StringUtils.trimToNull(getLabId()) == null)
181- errors.reject(null, "Peptide Number must be entered.");
182- */
183- }
184- if (getQueryKey () != null && getQueryKey ().equals (PepDBSchema .COLUMN_PEPTIDE_POOL_ID ))
185- {
186- if (StringUtils .trimToNull (qValue ) == null )
187- errors .reject (null , "Peptide Pool Name must be selected to get peptides in a pool." );
188- }
189- if (getQueryKey () != null && getQueryKey ().equals (PepDBSchema .COLUMN_PROTEIN_CAT_ID ))
190- {
191- if (StringUtils .trimToNull (qValue ) == null )
192- errors .reject (null , "Protein Category must be selected to get peptides in a protein category." );
193- else
167+ switch (getQueryKey ())
194168 {
195- ProteinCategory pc = PepDBManager .getProCatByID (Integer .parseInt (getQueryValue ()));
196- if (pc .getProtein_cat_desc ().trim ().contains ("-" ))
169+ case PepDBSchema .COLUMN_PARENT_SEQUENCE ->
197170 {
198- if (StringUtils .trimToNull (getAAStart ()) != null || StringUtils . trimToNull ( getAAEnd ()) ! = null )
199- errors .reject (null ,"When you select a hyphanated Protein Category : " + pc . getProtein_cat_desc ()+ " AAStart & AAEnd values are not allowed ." );
171+ if (StringUtils .trimToNull (qValue ) = = null )
172+ errors .reject (null , "The Parent Sequence must be entered ." );
200173 }
201- else
174+ case PepDBSchema . COLUMN_CHILD_SEQUENCE ->
202175 {
203- if (StringUtils .trimToNull (getAAStart ()) != null && validateInteger (getAAStart ().trim ()) == null )
204- errors .reject (null , "AAStart must be an Integer." );
205- if (StringUtils .trimToNull (getAAEnd ()) != null && validateInteger (getAAEnd ().trim ()) == null )
206- errors .reject (null , "AAEnd must be an Integer." );
207- if (StringUtils .trimToNull (getAAStart ()) != null && validateInteger (getAAStart ().trim ()) != null
208- && StringUtils .trimToNull (getAAEnd ()) != null && validateInteger (getAAEnd ().trim ()) != null
209- && validateInteger (getAAStart ().trim ()) > validateInteger (getAAEnd ().trim ()))
210- errors .reject (null , "AAStart must be less than or equal to AAEnd." );
176+ if (StringUtils .trimToNull (qValue ) == null )
177+ errors .reject (null , "The Child Sequence must be entered." );
211178 }
212- }
213- }
214- if (getQueryKey () != null && getQueryKey ().equals (PepDBSchema .COLUMN_PEPTIDE_ID ))
215- {
216- if (StringUtils .trimToNull (qValue ) == null )
217- errors .reject (null , "The Peptide Id range must be entered." );
218- if (qValue != null && !qValue .isEmpty ())
219- {
220- if (!(qValue .matches ("\\ d+-\\ d+" )))
179+ case PepDBSchema .COLUMN_PEPTIDE_GROUP_ID ->
221180 {
222- errors . reject ( null , "To get the peptides in the range you should specify the Range of numbers. \n " +
223- "The format for specify the range of peptide is <number>-<number> Example would be 30-100 " );
181+ if ( StringUtils . trimToNull ( qValue ) == null )
182+ errors . reject ( null , "Peptide Group must be selected to get peptides in a group. " );
224183 }
225- else
184+ case PepDBSchema .COLUMN_PEPTIDE_POOL_ID ->
185+ {
186+ if (StringUtils .trimToNull (qValue ) == null )
187+ errors .reject (null , "Peptide Pool Name must be selected to get peptides in a pool." );
188+ }
189+ case PepDBSchema .COLUMN_PROTEIN_CAT_ID ->
226190 {
227- String [] range = qValue .split ("-" );
228- if (Integer .parseInt (range [0 ]) > Integer .parseInt (range [1 ]))
191+ if (StringUtils .trimToNull (qValue ) == null )
192+ errors .reject (null , "Protein Category must be selected to get peptides in a protein category." );
193+ else
229194 {
230- errors .reject (null , "The minimum value which is before '-' should be less than the max value which is after '-'.\n " );
231-
195+ ProteinCategory pc = PepDBManager .getProCatByID (Integer .parseInt (getQueryValue ()));
196+ if (pc .getProtein_cat_desc ().trim ().contains ("-" ))
197+ {
198+ if (StringUtils .trimToNull (getAAStart ()) != null || StringUtils .trimToNull (getAAEnd ()) != null )
199+ errors .reject (null , "When you select a hyphanated Protein Category : " + pc .getProtein_cat_desc () + " AAStart & AAEnd values are not allowed." );
200+ }
201+ else
202+ {
203+ if (StringUtils .trimToNull (getAAStart ()) != null && validateInteger (getAAStart ().trim ()) == null )
204+ errors .reject (null , "AAStart must be an Integer." );
205+ if (StringUtils .trimToNull (getAAEnd ()) != null && validateInteger (getAAEnd ().trim ()) == null )
206+ errors .reject (null , "AAEnd must be an Integer." );
207+ if (StringUtils .trimToNull (getAAStart ()) != null && validateInteger (getAAStart ().trim ()) != null
208+ && StringUtils .trimToNull (getAAEnd ()) != null && validateInteger (getAAEnd ().trim ()) != null
209+ && validateInteger (getAAStart ().trim ()) > validateInteger (getAAEnd ().trim ()))
210+ errors .reject (null , "AAStart must be less than or equal to AAEnd." );
211+ }
212+ }
213+ }
214+ case PepDBSchema .COLUMN_PEPTIDE_ID ->
215+ {
216+ if (StringUtils .trimToNull (qValue ) == null )
217+ errors .reject (null , "The Peptide Id range must be entered." );
218+ if (qValue != null && !qValue .isEmpty ())
219+ {
220+ if (!(qValue .matches ("\\ d+-\\ d+" )))
221+ {
222+ errors .reject (null , "To get the peptides in the range you should specify the Range of numbers.\n " +
223+ "The format for specify the range of peptide is <number>-<number> Example would be 30-100" );
224+ }
225+ else
226+ {
227+ String [] range = qValue .split ("-" );
228+ if (Integer .parseInt (range [0 ]) > Integer .parseInt (range [1 ]))
229+ {
230+ errors .reject (null , "The minimum value which is before '-' should be less than the max value which is after '-'.\n " );
231+ }
232+ }
232233 }
233234 }
234235 }
235236 }
236- if (errors != null && errors .getErrorCount () >0 )
237- return false ;
238- return true ;
237+ return errors == null || !errors .hasErrors ();
239238 }
240-
241239 }
242240
243241 public static class DisplayPeptideForm
0 commit comments