// PathVisio, // a tool for data visualization and analysis using Biological Pathways // Copyright 2006-2011 BiGCaT Bioinformatics // // 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 org.pathvisio.wikipathways.server; import java.io.File; import java.io.FileInputStream; import java.net.URL; import java.rmi.RemoteException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; import javax.servlet.ServletContext; import javax.xml.rpc.ServiceException; import org.bridgedb.DataSource; import org.bridgedb.Xref; import org.bridgedb.bio.BioDataSource; import org.pathvisio.core.debug.Logger; import org.pathvisio.core.model.ConverterException; import org.pathvisio.core.model.Pathway; import org.pathvisio.core.model.PathwayElement; import org.pathvisio.wikipathways.client.IdSearchPanel; import org.pathvisio.wikipathways.client.Query; import org.pathvisio.wikipathways.client.Result; import org.pathvisio.wikipathways.client.ResultsTable; import org.pathvisio.wikipathways.client.SearchException; import org.pathvisio.wikipathways.client.SearchService; import org.pathvisio.wikipathways.webservice.WSIndexField; import org.pathvisio.wikipathways.webservice.WSSearchResult; import org.wikipathways.client.WikiPathwaysClient; import com.google.gwt.user.server.rpc.RemoteServiceServlet; /** * Implements the {@link SearchService}. * @author thomas */ public class SearchServiceImpl extends RemoteServiceServlet implements SearchService { WikiPathwaysClient client; public SearchServiceImpl() throws ServiceException { BioDataSource.init(); } protected static URL getClientUrl(ServletContext servlet) { URL url = null; try { url = new URL( "http://www.wikipathways.org/wpi/webservice/webservice.php" ); Properties prop = new Properties(); prop.load(new FileInputStream( new File(servlet.getRealPath(""), "wikipathways.props")) ); String wsurl = (String)prop.get("webservice-url"); if(wsurl != null) { url = new URL(wsurl); } } catch (Exception e) { e.printStackTrace(); } return url; } private WikiPathwaysClient getClient() { if(client == null) { try { client = new WikiPathwaysClient(getClientUrl(getServletContext())); } catch(Exception e) { throw new RuntimeException("Unable to create wikipathways client", e); } } return client; } private ImageManager getImageManager() { if(!ImageManager.isInit()) { ImageManager.init(getServletContext().getRealPath(""), getClient()); } return ImageManager.getInstance(); } public Result[] search(Query query) throws SearchException { try { if(Query.TYPE_ID.equals(query.getType())) { //System code specified, use id search return searchIdentifier(query); } else { //Use text search return searchText(query.getText()); } } catch (Exception e) { throw new SearchException(e); } } private Result createPathwayResult(final WSSearchResult wsr, String id) { Logger.log.info("Creating pathway result for: " + wsr.getId()); String iddescr = null; try { if(id != null) { Pathway pathway = getImageManager().getPathway(wsr); String idlist = "
Title: " + wsr.getName(); descr += " |
Organism: " + wsr.getSpecies(); descr += " |
Pathway ID: " + wsr.getId(); if(iddescr != null) descr += " |
" + "IDs mapping to " + id + ": " + iddescr; descr += " |