<commit_before>/*
 * The Gemma project
 * 
 * Copyright (c) 2008 University of British Columbia
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package ubic.gemma.web.services;

import java.util.Collection;

import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import ubic.gemma.model.expression.experiment.ExpressionExperiment;
import ubic.gemma.model.expression.experiment.ExpressionExperimentService;

/**
 * Used for getting the Short Name given an Expression Experiment ID  eg: 793 --> GSE10470
 * 
 * @author klc, gavin
 * @version$Id$
 */

public class ExperimentNameEndpoint extends AbstractGemmaEndpoint {

    private static Log log = LogFactory.getLog( ExperimentNameEndpoint.class );

    private ExpressionExperimentService expressionExperimentService;

    /**
     * The local name of the expected request/response.
     */
    public static final String EXPERIMENT_LOCAL_NAME = "experimentName";

    /**
     * Sets the "business service" to delegate to.
     */
    public void setExpressionExperimentService( ExpressionExperimentService ees ) {
        this.expressionExperimentService = ees;
    }

    /**
     * Reads the given <code>requestElement</code>, and sends a the response back.
     * 
     * @param requestElement the contents of the SOAP message as DOM elements
     * @param document a DOM document to be used for constructing <code>Node</code>s
     * @return the response element
     */
    protected Element invokeInternal( Element requestElement, Document document ) throws Exception {
        StopWatch watch = new StopWatch();
        watch.start();

        setLocalName( EXPERIMENT_LOCAL_NAME );
        String eeId = "";

        Collection<String> eeResult = getNodeValues( requestElement, "ee_id" );
        // expect only one element in the collection
        for ( String id : eeResult )
            eeId = id;

        log.info( "XML input read: expression experiment id, " + eeId );

        ExpressionExperiment ee = expressionExperimentService.load( Long.parseLong( eeId ) );

        if ( ee == null ) {
            String msg = "No Expression Experiment with id, " + ee + " can be found.";
            return buildBadResponse( document, msg );
        }

        Element responseWrapper = document.createElementNS( NAMESPACE_URI, EXPERIMENT_LOCAL_NAME );
        Element responseElement = document.createElementNS( NAMESPACE_URI, EXPERIMENT_LOCAL_NAME + RESPONSE );
        responseWrapper.appendChild( responseElement );

        Element e1 = document.createElement( "ee_shortName" );
        e1.appendChild( document.createTextNode( ee.getShortName() ) );
        responseElement.appendChild( e1 );

        Element e2 = document.createElement( "ee_name" );
        e2.appendChild( document.createTextNode( ee.getName() ) );
        responseElement.appendChild( e2 );

        watch.stop();
        Long time = watch.getTime();
        log.info( "XML response for Expression Experiment Names result built in " + time + "ms." );    

        return responseWrapper;
    }

}<commit_msg>modified to accept a collection of id as input instead of just a single id<commit_after>/*
 * The Gemma project
 * 
 * Copyright (c) 2008 University of British Columbia
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package ubic.gemma.web.services;

import java.util.Collection;
import java.util.HashSet;

import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import ubic.gemma.model.expression.experiment.ExpressionExperiment;
import ubic.gemma.model.expression.experiment.ExpressionExperimentService;

/**
 * Used for getting the Short Name given an Expression Experiment ID  eg: 793 --> GSE10470
 * 
 * @author klc, gavin
 * @version$Id$
 */

public class ExperimentNameEndpoint extends AbstractGemmaEndpoint {

    private static Log log = LogFactory.getLog( ExperimentNameEndpoint.class );

    private ExpressionExperimentService expressionExperimentService;

    /**
     * The local name of the expected request/response.
     */
    public static final String EXPERIMENT_LOCAL_NAME = "experimentName";

    /**
     * Sets the "business service" to delegate to.
     */
    public void setExpressionExperimentService( ExpressionExperimentService ees ) {
        this.expressionExperimentService = ees;
    }

    /**
     * Reads the given <code>requestElement</code>, and sends a the response back.
     * 
     * @param requestElement the contents of the SOAP message as DOM elements
     * @param document a DOM document to be used for constructing <code>Node</code>s
     * @return the response element
     */
    @SuppressWarnings("unchecked")
    protected Element invokeInternal( Element requestElement, Document document ) throws Exception {
        StopWatch watch = new StopWatch();
        watch.start();

        setLocalName( EXPERIMENT_LOCAL_NAME );
        String eeId = "";

        Collection<String> eeInput = getArrayValues( requestElement, "ee_ids" );        
        Collection<Long> eeLongs = new HashSet<Long>();
        for (String ee : eeInput)
            eeLongs.add( Long.parseLong( ee ) );
        log.info( "XML input read: expression experiment id, " + eeInput );

        Collection<ExpressionExperiment> eeCol = expressionExperimentService.loadMultiple( eeLongs  );

        if ( eeCol == null || eeCol.isEmpty()) {
            String msg = "No input Expression Experiments can be found.";
            return buildBadResponse( document, msg );
        }

        Element responseWrapper = document.createElementNS( NAMESPACE_URI, EXPERIMENT_LOCAL_NAME );
        Element responseElement = document.createElementNS( NAMESPACE_URI, EXPERIMENT_LOCAL_NAME + RESPONSE );
        responseWrapper.appendChild( responseElement );

        for (ExpressionExperiment ee : eeCol){
            
            Element e1 = document.createElement( "ee_shortName" );
            e1.appendChild( document.createTextNode( ee.getShortName() ) );
            responseElement.appendChild( e1 );
    
            Element e2 = document.createElement( "ee_name" );
            e2.appendChild( document.createTextNode( ee.getName() ) );
            responseElement.appendChild( e2 );
        }

        watch.stop();
        Long time = watch.getTime();
        log.info( "XML response for Expression Experiment Names result built in " + time + "ms." );    

        return responseWrapper;
    }

}
{'fraction_non_alphanumeric': 0.08769872296064633, 'fraction_numerical': 0.006254886630179828, 'mean_word_length': 3.1108730583824316, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6722799', 'n_tokens_mistral': 2067, 'n_tokens_neox': 2005, 'n_words': 653}