private static List < Map < String , String > > getStatusIdRecords ( String [ ] pdbIDs ) { List < Map < String , String > > result = new ArrayList < Map < String , String > > ( pdbIDs . length ) ; String serverName = System . getProperty ( PDB_SERVER_PROPERTY ) ; if ( serverName == null ) serverName = DEFAULT_PDB_SERVER ; else logger . info ( String . format ( "Got System property %s=%s" , PDB_SERVER_PROPERTY , serverName ) ) ; // Build REST query URL if ( pdbIDs . length < 1 ) { throw new IllegalArgumentException ( "No pdbIDs specified" ) ; } String urlStr = String . format ( "http://%s/pdb/rest/idStatus?structureId=" , serverName ) ; for ( String pdbId : pdbIDs ) { pdbId = pdbId . toUpperCase ( ) ; //check the cache if ( recordsCache . containsKey ( pdbId ) ) { //logger.debug("Fetching "+pdbId+" from Cache"); result . add ( recordsCache . get ( pdbId ) ) ; } else { urlStr += pdbId + "," ; } } // check if any ids still need fetching if ( urlStr . charAt ( urlStr . length ( ) - 1 ) == ' ' ) { return result ; } try { logger . info ( "Fetching {}" , urlStr ) ; URL url = new URL ( urlStr ) ; InputStream uStream = url . openStream ( ) ; InputSource source = new InputSource ( uStream ) ; SAXParserFactory parserFactory = SAXParserFactory . newInstance ( ) ; SAXParser parser = parserFactory . newSAXParser ( ) ; XMLReader reader = parser . getXMLReader ( ) ; PDBStatusXMLHandler handler = new PDBStatusXMLHandler ( ) ; reader . setContentHandler ( handler ) ; reader . parse ( source ) ; // Fetch results of SAX parsing List < Map < String , String > > records = handler . getRecords ( ) ; //add to cache for ( Map < String , String > record : records ) { String pdbId = record . get ( "structureId" ) . toUpperCase ( ) ; if ( pdbId != null ) { recordsCache . put ( pdbId , record ) ; } } // return results result . addAll ( handler . getRecords ( ) ) ; // TODO should throw these forward and let the caller log } catch ( IOException e ) { logger . error ( "Problem getting status for {} from PDB server. Error: {}" , Arrays . toString ( pdbIDs ) , e . getMessage ( ) ) ; return null ; } catch ( SAXException e ) { logger . error ( "Problem getting status for {} from PDB server. Error: {}" , Arrays . toString ( pdbIDs ) , e . getMessage ( ) ) ; return null ; } catch ( ParserConfigurationException e ) { logger . error ( "Problem getting status for {} from PDB server. Error: {}" , Arrays . toString ( pdbIDs ) , e . getMessage ( ) ) ; return null ; } return result ; }
Fetches the status of one or more pdbIDs from the server .