Changeset 20758


Ignore:
Timestamp:
02/03/10 11:01:32 (2 years ago)
Author:
julie
Message:

move methods to helper class as they are shared with the portal and ajax

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/bio/webapp/src/org/intermine/bio/web/logic/OrthologueConverter.java

    r20754 r20758  
    1515import java.util.ArrayList; 
    1616import java.util.List; 
    17 import java.util.regex.Pattern; 
    1817 
    1918import org.apache.commons.lang.StringUtils; 
     
    2625import org.intermine.api.results.WebResults; 
    2726import org.intermine.metadata.Model; 
     27import org.intermine.model.InterMineObject; 
     28import org.intermine.objectstore.ObjectStoreException; 
    2829import org.intermine.pathquery.Constraints; 
    2930import org.intermine.pathquery.PathQuery; 
     
    3738public class OrthologueConverter extends BagConverter 
    3839{ 
    39  
    40     // D. melanogaster, C. lupus familiaris 
    41     private static final Pattern ORGANISM_SHORTNAME_MATCHER = Pattern.compile("([a-zA-Z]\\..+)"); 
    4240    private Model model; 
    4341 
     
    5149    } 
    5250 
    53     private PathQuery constructPathQuery(String bagType, String bagName, String organismName) { 
     51    private PathQuery constructPathQuery(String organismName) { 
    5452        PathQuery q = new PathQuery(model); 
    5553 
     
    6159        q.addConstraint("Gene.homologues.type", Constraints.eq("orthologue")); 
    6260 
    63         q.addConstraint(bagType, Constraints.in(bagName)); 
    6461        return q; 
    6562    } 
     
    6764    /** 
    6865     * runs the orthologue conversion pathquery and returns a comma-delimited list of identifiers 
    69      * used on list analysis page for intermine linking 
     66     * used on list analysis page for intermine linking, called via Ajax 
    7067     * @param profile the user's profile 
    7168     * @param bagType the class of the list, has to be gene I think 
     
    7471     * @return commadelimited list of identifiers, eg. eve,zen 
    7572     */ 
    76     public String getConvertedObjectFields(Profile profile, String bagType, 
    77             String bagName, String organismName) { 
     73    public String getConvertedObjectFields(Profile profile, String bagType, String bagName, 
     74            String organismName) { 
    7875        StringBuffer orthologues = null; 
    79         PathQuery pathQuery = constructPathQuery(bagType, bagName, organismName); 
     76        PathQuery pathQuery = constructPathQuery(organismName); 
     77        pathQuery.addConstraint(bagType, Constraints.in(bagName)); 
    8078        pathQuery.setView("Gene.homologues.homologue.primaryIdentifier"); 
    8179        pathQuery.syncLogicExpression("and"); 
     
    9997    /** 
    10098     * runs the orthologue conversion pathquery and returns list of intermine IDs 
    101      * used in the portal  
     99     * used in the portal 
    102100     * @param profile the user's profile 
    103101     * @param bagType the class of the list, has to be gene I think 
    104      * @param bagName name of list 
     102     * @param bagList list of intermine object IDs 
    105103     * @param organismName name of homologue's organism 
    106104     * @return list of intermine IDs 
    107105     */ 
    108106    public List<Integer> getConvertedObjectIds(Profile profile, String bagType, 
    109             String bagName, String organismName) { 
    110         PathQuery pathQuery = constructPathQuery(bagType, bagName, organismName); 
     107            List<Integer> bagList, String organismName) { 
     108        PathQuery pathQuery = constructPathQuery(organismName); 
     109        List<InterMineObject> objectList = null; 
     110        try { 
     111            objectList = im.getObjectStore().getObjectsByIds(bagList); 
     112        } catch (ObjectStoreException e) { 
     113            e.printStackTrace(); 
     114            return null; 
     115        } 
     116        pathQuery.addConstraint(bagType, Constraints.in(objectList)); 
    111117        pathQuery.setView(bagType + ".id"); 
    112118        pathQuery.syncLogicExpression("and"); 
     
    125131     */ 
    126132    public ActionMessage getActionMessage(String externalids, int convertedSize, String type, 
    127             String ... parameters) 
    128                     throws UnsupportedEncodingException { 
    129  
    130         String organism = null, dataset = null; 
    131  
    132         for (String param : parameters) { 
    133             if (StringUtils.isEmpty(param)) { 
    134                 continue; 
    135             } 
    136             if (ORGANISM_SHORTNAME_MATCHER.matcher(param).matches()) { 
    137                 organism = param; 
    138             } else { 
    139                 dataset = param; 
    140             } 
     133            String parameter) throws UnsupportedEncodingException { 
     134        if (StringUtils.isEmpty(parameter)) { 
     135            return null; 
    141136        } 
    142137 
     
    155150 
    156151        // organism 
    157         q.addConstraint("Gene.organism", Constraints.lookup(organism)); 
     152        q.addConstraint("Gene.organism", Constraints.lookup(parameter)); 
    158153 
    159154        // if the XML is too long, the link generates "HTTP Error 414 - Request URI too long" 
    160155        if (externalids.length() < 4000) { 
    161156            q.addConstraint("Gene.homologues.homologue", Constraints.lookup(externalids)); 
    162         } 
    163  
    164         if (!StringUtils.isEmpty(dataset)) { 
    165             // homologue.dataSets = dataset 
    166             q.addConstraint("Gene.homologues.dataSet.title", Constraints.eq(dataset)); 
    167157        } 
    168158 
     
    175165            { 
    176166                String.valueOf(convertedSize), 
    177                 organism, 
     167                parameter, 
    178168                String.valueOf(externalids.split(",").length), 
    179169                type, 
     
    186176    @Override 
    187177    public WebResults getConvertedObjects(Profile profile, List<Integer> fromList, String type, 
    188             String... parameters) { 
     178            String parameters) { 
    189179        // TODO Auto-generated method stub 
    190180        return null; 
  • trunk/intermine/web/main/src/org/intermine/dwr/AjaxServices.java

    r20740 r20758  
    1313import java.io.IOException; 
    1414import java.io.UnsupportedEncodingException; 
    15 import java.lang.reflect.Constructor; 
    16 import java.lang.reflect.InvocationTargetException; 
    1715import java.net.MalformedURLException; 
    1816import java.net.URL; 
     
    8179import org.intermine.web.autocompletion.AutoCompleter; 
    8280import org.intermine.web.logic.Constants; 
     81import org.intermine.web.logic.PortalHelper; 
    8382import org.intermine.web.logic.bag.BagConverter; 
    8483import org.intermine.web.logic.config.Type; 
     
    121120    private static final String INVALID_NAME_MSG = "Invalid name.  Names may only contain letters, " 
    122121        + "numbers, spaces, and underscores."; 
     122    private PortalHelper portalHelper = new PortalHelper(); 
     123     
    123124    /** 
    124125     * Creates a favourite Tag for the given templateName 
     
    13291330        return defaultList; 
    13301331    } 
    1331      
     1332 
    13321333    /** 
    13331334     * used on list analysis page to convert list contents to orthologues.  then forwarded to 
    13341335     * another intermine instance 
    1335      * @param bagName bag of genes to convert 
    1336      * @param selectedValue organism to convert to 
     1336     * @param bagType class of bag 
     1337     * @param bagName name of bag 
     1338     * @param selectedValue orthologue organism 
    13371339     * @return converted list of orthologues 
    1338      * @throws UnsupportedEncodingException if we can't encode the name of the organism 
    1339      * @throws ClassNotFoundException  
    1340      * @throws NoSuchMethodException  
    1341      * @throws SecurityException  
    1342      * @throws InvocationTargetException  
    1343      * @throws IllegalAccessException  
    1344      * @throws InstantiationException  
    1345      * @throws IllegalArgumentException  
    1346      */ 
    1347     public static String convertObjects(String bagType, String bagName, String selectedValue) 
    1348     throws UnsupportedEncodingException, ClassNotFoundException, SecurityException,  
    1349     NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException,  
    1350     InvocationTargetException { 
    1351          
     1340     * @throws UnsupportedEncodingException bad encoding 
     1341     */ 
     1342    public String convertObjects(String bagType, String bagName, String selectedValue)  
     1343    throws UnsupportedEncodingException { 
     1344        ServletContext servletContext = WebContextFactory.get().getServletContext(); 
    13521345        HttpServletRequest request = getRequest(); 
    13531346        HttpSession session = request.getSession(); 
    13541347        final InterMineAPI im = SessionMethods.getInterMineAPI(session); 
    13551348        Profile profile = SessionMethods.getProfile(session); 
    1356          
     1349        WebConfig webConfig = SessionMethods.getWebConfig(servletContext); 
     1350 
    13571351        BagQueryConfig bagQueryConfig = im.getBagQueryConfig(); 
     1352 
    13581353        // Use custom converters 
    13591354        Map<String, String []> additionalConverters = 
     
    13611356        if (additionalConverters != null) { 
    13621357            for (String converterClassName : additionalConverters.keySet()) { 
    1363                 Class clazz = Class.forName(converterClassName); 
    1364                 Constructor constructor = clazz.getConstructor(); 
    1365                 BagConverter bagConverter = (BagConverter) constructor.newInstance(); 
    1366                 return bagConverter.getConvertedObjectFields(profile, bagType, bagName,  
     1358 
     1359                String addparameter = PortalHelper.getAdditionalParameter(request, 
     1360                        additionalConverters.get(converterClassName)); 
     1361 
     1362                if (StringUtils.isNotEmpty(addparameter)) { 
     1363 
     1364                    BagConverter bagConverter = portalHelper.getBagConverter(im, webConfig,  
     1365                            converterClassName); 
     1366 
     1367 
     1368                return bagConverter.getConvertedObjectFields(profile, bagType, bagName, 
    13671369                        selectedValue); 
     1370                } 
    13681371            } 
    13691372        } 
     
    13711374    } 
    13721375 
     1376 
    13731377} 
  • trunk/intermine/web/main/src/org/intermine/web/struts/PortalQueryAction.java

    r20754 r20758  
    1111 */ 
    1212 
    13 import java.io.UnsupportedEncodingException; 
    14 import java.lang.reflect.Constructor; 
    15 import java.net.URLDecoder; 
    1613import java.util.ArrayList; 
    1714import java.util.HashMap; 
     
    5148import org.intermine.util.StringUtil; 
    5249import org.intermine.web.logic.Constants; 
     50import org.intermine.web.logic.PortalHelper; 
    5351import org.intermine.web.logic.bag.BagConverter; 
    5452import org.intermine.web.logic.config.WebConfig; 
     
    7068{ 
    7169    private static int index = 0; 
     70    private PortalHelper helper = new PortalHelper(); 
     71     
    7272//    private static final Logger LOG = Logger.getLogger(PortalQueryAction.class); 
    73     private Map<String, BagConverter> bagConverters = new HashMap(); 
    74  
    7573 
    7674    /** 
     
    167165            for (String converterClassName : additionalConverters.keySet()) { 
    168166 
    169                 String addparameter = getAdditionalParameter(request, 
     167                String addparameter = PortalHelper.getAdditionalParameter(request, 
    170168                        additionalConverters.get(converterClassName)); 
    171169 
    172170                if (StringUtils.isNotEmpty(addparameter)) { 
    173171 
    174                     BagConverter bagConverter = getBagConverter(im, webConfig, converterClassName); 
    175  
    176                     imBag = profile.createBag(bagName, className, ""); 
     172                    BagConverter bagConverter = helper.getBagConverter(im, webConfig,  
     173                            converterClassName); 
    177174                    List<Integer> converted = bagConverter.getConvertedObjectIds(profile, 
    178                             className, bagName, addparameter); 
     175                            className, bagList, addparameter); 
    179176                    // No matches 
    180177                    if (converted.size() <= 0) { 
     
    216213    } 
    217214 
    218     private BagConverter getBagConverter(InterMineAPI im, WebConfig webConfig, 
    219             String converterClassName) { 
    220  
    221         BagConverter bagConverter = bagConverters.get(converterClassName); 
    222  
    223         if (bagConverter == null) { 
    224             try { 
    225                 Class clazz = Class.forName(converterClassName); 
    226                 Constructor constructor = clazz.getConstructor(InterMineAPI.class, WebConfig.class); 
    227                 bagConverter = (BagConverter) constructor.newInstance(im, webConfig); 
    228             } catch (Exception e) { 
    229                 throw new RuntimeException("Failed to construct bagconverter for " 
    230                         + converterClassName, e); 
    231             } 
    232             bagConverters.put(converterClassName, bagConverter); 
    233         } 
    234         return bagConverter; 
    235     } 
    236  
    237     private String getAdditionalParameter(HttpServletRequest request, String[] paramArray) 
    238     throws UnsupportedEncodingException { 
    239  
    240         String[] urlFields = paramArray[0].split(","); 
    241         String addparameter = null; 
    242         for (String urlField : urlFields) { 
    243             // if one of the request vars matches the variables listed in the bagquery 
    244             // config, add the variable to be passed to the custom converter 
    245             String param = request.getParameter(urlField); 
    246             if (StringUtils.isNotEmpty(param)) { 
    247                 // the spaces in organisms, eg. D.%20rerio, need to be handled 
    248                 addparameter = URLDecoder.decode(param, "UTF-8"); 
    249             } 
    250         } 
    251         return addparameter; 
    252     } 
    253  
    254215    private ActionForward goToResults(ActionMapping mapping, HttpSession session, 
    255216            WebResults webResults) { 
  • trunk/intermine/webapp/main/resources/webapp/js/imdwr.js

    r20737 r20758  
    819819 
    820820function checkOrthologueMapping(statusCount, remoteMine, localMine) { 
     821 
    821822    var myForm = document.forms['orthologueLinkForm' + statusCount]; 
    822823    var orthologueSelect = myForm.orthologueDatasets; 
     
    825826    var localMapping = bits[0]; 
    826827    var remoteMapping = bits[1]; 
     828 
    827829    var selectedOrganism = orthologueSelect.options[orthologueSelect.selectedIndex].text; 
    828830    myForm.orthologue.value = selectedOrganism; 
    829831 
     832    // hide/show the radio button and name of intermine if they do/don't have orthologues 
    830833    if (localMapping != null && localMapping != "") { 
    831834        display('orthologueMappingLocalLabel' + statusCount, true); 
     
    846849        display('orthologueMappingLocalRadio' + statusCount, false); 
    847850    } 
    848 } 
     851    // if there is only one option, don't show a dropdown 
     852//    if (orthologueSelect.length == 1) { 
     853//        display('orthologueSelectDisplay' + statusCount, true); 
     854//        display('orthologueSelect' + statusCount, false); 
     855//        // update text to be selected value 
     856//        document.getElementById('orthologueSelect' + statusCount).innerHtml 
     857//            = orthologueSelect.options[0].text; 
     858//    } else { 
     859//        // show dropdown 
     860//        display('orthologueSelectDisplay' + statusCount, false); 
     861//        display('orthologueSelect' + statusCount, true); 
     862//    } 
     863} 
Note: See TracChangeset for help on using the changeset viewer.