public List < FogbugzCase > searchForCases ( String query ) throws InvalidResponseException , NoSuchCaseException { HashMap < String , String > params = new HashMap < String , String > ( ) ; // Hashmap defaults to <String, String> params . put ( "cmd" , "search" ) ; params . put ( "q" , query ) ; params . put ( "cols" , "ixBug,tags,fOpen,sTitle,sFixFor,ixPersonOpenedBy,ixPersonAssignedTo" + // No trailing comma this . getCustomFieldsCSV ( ) ) ; Document doc = null ; try { doc = this . getFogbugzDocument ( params ) ; } catch ( Exception e ) { throw new InvalidResponseException ( e . getMessage ( ) ) ; } // Check for case count in cases tag, so we know wheter to parse the response ever further or not. int caseCount = 0 ; try { Node casesContainer = doc . getElementsByTagName ( "cases" ) . item ( 0 ) ; caseCount = Integer . parseInt ( casesContainer . getAttributes ( ) . getNamedItem ( "count" ) . getTextContent ( ) ) ; } catch ( NumberFormatException e ) { log . log ( Level . INFO , "No valid number in case count XML response." , e ) ; } if ( caseCount < 1 ) { throw new NoSuchCaseException ( "Fogbugz did not return a case for query id " + query ) ; } NodeList caseNodes = doc . getElementsByTagName ( "case" ) ; ArrayList < FogbugzCase > caseList = new ArrayList < FogbugzCase > ( ) ; for ( int i = 0 ; i < caseNodes . getLength ( ) ; i ++ ) { caseList . add ( this . constructCaseFromXmlNode ( caseNodes . item ( i ) ) ) ; } return caseList ; }
Retrieves cases using the Fogbugz API by a query