package de.mpg.mpiz_koeln.featureClient.test;

import java.util.Collection;
import java.util.Map;

import org.biomoby.shared.MobyException;
import org.biomoby.shared.datatypes.Annotated_GO_Term;

import de.mpg.mpiz_koeln.featureClient.FeatureClient;
import de.mpg.mpiz_koeln.featureClient.FeatureClientException;
import de.mpg.mpiz_koeln.featureClient.FeatureClientResult;

/**
 * This example shows how to call a web service multiple times with a simple object input.
 */
class SimpleMultiCall {
    public static void main( String[] args ) throws MobyException, FeatureClientException {
        // the client queries the default central if no given otherwise
        FeatureClient client = new FeatureClient();
        // the timeout of the service calls is 45 seconds
        client.setTimeout( 45 );
        // you can specify the authority of a service to be sure to find exactly this service
        client.addService( "mpiz-koeln.mpg.de", "get_go_information_by_go_term" );

        // the three different inputs for the three service calls
        client.addMultipleCallInput( "GO", "0044408" );
        client.addMultipleCallInput( "GO", "0020015" );
        client.addMultipleCallInput( "GO", "0004396" );

        // call the service
        Collection< FeatureClientResult > result = client.call();

        for ( FeatureClientResult mobyServiceResult : result ) {
            // the map stores for each id of the input object a list of results
            Map< String, Collection< Annotated_GO_Term > > terms = mobyServiceResult.getMultipleCallResult();

            // print out the results for each identifier
            for ( String identifier : terms.keySet() ) {
                System.out.println( "For the id " + identifier );
                for ( Annotated_GO_Term term : terms.get( identifier ) ) {
                    System.out.println( term.get_Term() );
                    System.out.println( term.get_process() );
                    System.out.println( term.get_Definition() );
                }
                System.out.println();
            }

            // you can also access directly a result for an input. You have to give the job identifier, in this case
            // the id of the input.
            Collection< Annotated_GO_Term > goterms = mobyServiceResult.getMulipleCallResult( "0020015" );
            for ( Annotated_GO_Term term : goterms ) {
                System.out.println( term.get_Term() );
                System.out.println( term.get_process() );
                System.out.println( term.get_Definition() );
            }
        }
        System.exit( 0 );
    }
}
