Changeset 20758
- Timestamp:
- 02/03/10 11:01:32 (2 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
-
bio/webapp/src/org/intermine/bio/web/logic/OrthologueConverter.java (modified) (12 diffs)
-
intermine/web/main/src/org/intermine/dwr/AjaxServices.java (modified) (6 diffs)
-
intermine/web/main/src/org/intermine/web/logic/PortalHelper.java (added)
-
intermine/web/main/src/org/intermine/web/struts/PortalQueryAction.java (modified) (5 diffs)
-
intermine/webapp/main/resources/webapp/js/imdwr.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bio/webapp/src/org/intermine/bio/web/logic/OrthologueConverter.java
r20754 r20758 15 15 import java.util.ArrayList; 16 16 import java.util.List; 17 import java.util.regex.Pattern;18 17 19 18 import org.apache.commons.lang.StringUtils; … … 26 25 import org.intermine.api.results.WebResults; 27 26 import org.intermine.metadata.Model; 27 import org.intermine.model.InterMineObject; 28 import org.intermine.objectstore.ObjectStoreException; 28 29 import org.intermine.pathquery.Constraints; 29 30 import org.intermine.pathquery.PathQuery; … … 37 38 public class OrthologueConverter extends BagConverter 38 39 { 39 40 // D. melanogaster, C. lupus familiaris41 private static final Pattern ORGANISM_SHORTNAME_MATCHER = Pattern.compile("([a-zA-Z]\\..+)");42 40 private Model model; 43 41 … … 51 49 } 52 50 53 private PathQuery constructPathQuery(String bagType, String bagName, StringorganismName) {51 private PathQuery constructPathQuery(String organismName) { 54 52 PathQuery q = new PathQuery(model); 55 53 … … 61 59 q.addConstraint("Gene.homologues.type", Constraints.eq("orthologue")); 62 60 63 q.addConstraint(bagType, Constraints.in(bagName));64 61 return q; 65 62 } … … 67 64 /** 68 65 * 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 70 67 * @param profile the user's profile 71 68 * @param bagType the class of the list, has to be gene I think … … 74 71 * @return commadelimited list of identifiers, eg. eve,zen 75 72 */ 76 public String getConvertedObjectFields(Profile profile, String bagType, 77 String bagName, StringorganismName) {73 public String getConvertedObjectFields(Profile profile, String bagType, String bagName, 74 String organismName) { 78 75 StringBuffer orthologues = null; 79 PathQuery pathQuery = constructPathQuery(bagType, bagName, organismName); 76 PathQuery pathQuery = constructPathQuery(organismName); 77 pathQuery.addConstraint(bagType, Constraints.in(bagName)); 80 78 pathQuery.setView("Gene.homologues.homologue.primaryIdentifier"); 81 79 pathQuery.syncLogicExpression("and"); … … 99 97 /** 100 98 * runs the orthologue conversion pathquery and returns list of intermine IDs 101 * used in the portal 99 * used in the portal 102 100 * @param profile the user's profile 103 101 * @param bagType the class of the list, has to be gene I think 104 * @param bag Name name of list102 * @param bagList list of intermine object IDs 105 103 * @param organismName name of homologue's organism 106 104 * @return list of intermine IDs 107 105 */ 108 106 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)); 111 117 pathQuery.setView(bagType + ".id"); 112 118 pathQuery.syncLogicExpression("and"); … … 125 131 */ 126 132 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; 141 136 } 142 137 … … 155 150 156 151 // organism 157 q.addConstraint("Gene.organism", Constraints.lookup( organism));152 q.addConstraint("Gene.organism", Constraints.lookup(parameter)); 158 153 159 154 // if the XML is too long, the link generates "HTTP Error 414 - Request URI too long" 160 155 if (externalids.length() < 4000) { 161 156 q.addConstraint("Gene.homologues.homologue", Constraints.lookup(externalids)); 162 }163 164 if (!StringUtils.isEmpty(dataset)) {165 // homologue.dataSets = dataset166 q.addConstraint("Gene.homologues.dataSet.title", Constraints.eq(dataset));167 157 } 168 158 … … 175 165 { 176 166 String.valueOf(convertedSize), 177 organism,167 parameter, 178 168 String.valueOf(externalids.split(",").length), 179 169 type, … … 186 176 @Override 187 177 public WebResults getConvertedObjects(Profile profile, List<Integer> fromList, String type, 188 String ...parameters) {178 String parameters) { 189 179 // TODO Auto-generated method stub 190 180 return null; -
trunk/intermine/web/main/src/org/intermine/dwr/AjaxServices.java
r20740 r20758 13 13 import java.io.IOException; 14 14 import java.io.UnsupportedEncodingException; 15 import java.lang.reflect.Constructor;16 import java.lang.reflect.InvocationTargetException;17 15 import java.net.MalformedURLException; 18 16 import java.net.URL; … … 81 79 import org.intermine.web.autocompletion.AutoCompleter; 82 80 import org.intermine.web.logic.Constants; 81 import org.intermine.web.logic.PortalHelper; 83 82 import org.intermine.web.logic.bag.BagConverter; 84 83 import org.intermine.web.logic.config.Type; … … 121 120 private static final String INVALID_NAME_MSG = "Invalid name. Names may only contain letters, " 122 121 + "numbers, spaces, and underscores."; 122 private PortalHelper portalHelper = new PortalHelper(); 123 123 124 /** 124 125 * Creates a favourite Tag for the given templateName … … 1329 1330 return defaultList; 1330 1331 } 1331 1332 1332 1333 /** 1333 1334 * used on list analysis page to convert list contents to orthologues. then forwarded to 1334 1335 * 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 1337 1339 * @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(); 1352 1345 HttpServletRequest request = getRequest(); 1353 1346 HttpSession session = request.getSession(); 1354 1347 final InterMineAPI im = SessionMethods.getInterMineAPI(session); 1355 1348 Profile profile = SessionMethods.getProfile(session); 1356 1349 WebConfig webConfig = SessionMethods.getWebConfig(servletContext); 1350 1357 1351 BagQueryConfig bagQueryConfig = im.getBagQueryConfig(); 1352 1358 1353 // Use custom converters 1359 1354 Map<String, String []> additionalConverters = … … 1361 1356 if (additionalConverters != null) { 1362 1357 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, 1367 1369 selectedValue); 1370 } 1368 1371 } 1369 1372 } … … 1371 1374 } 1372 1375 1376 1373 1377 } -
trunk/intermine/web/main/src/org/intermine/web/struts/PortalQueryAction.java
r20754 r20758 11 11 */ 12 12 13 import java.io.UnsupportedEncodingException;14 import java.lang.reflect.Constructor;15 import java.net.URLDecoder;16 13 import java.util.ArrayList; 17 14 import java.util.HashMap; … … 51 48 import org.intermine.util.StringUtil; 52 49 import org.intermine.web.logic.Constants; 50 import org.intermine.web.logic.PortalHelper; 53 51 import org.intermine.web.logic.bag.BagConverter; 54 52 import org.intermine.web.logic.config.WebConfig; … … 70 68 { 71 69 private static int index = 0; 70 private PortalHelper helper = new PortalHelper(); 71 72 72 // private static final Logger LOG = Logger.getLogger(PortalQueryAction.class); 73 private Map<String, BagConverter> bagConverters = new HashMap();74 75 73 76 74 /** … … 167 165 for (String converterClassName : additionalConverters.keySet()) { 168 166 169 String addparameter = getAdditionalParameter(request,167 String addparameter = PortalHelper.getAdditionalParameter(request, 170 168 additionalConverters.get(converterClassName)); 171 169 172 170 if (StringUtils.isNotEmpty(addparameter)) { 173 171 174 BagConverter bagConverter = getBagConverter(im, webConfig, converterClassName); 175 176 imBag = profile.createBag(bagName, className, ""); 172 BagConverter bagConverter = helper.getBagConverter(im, webConfig, 173 converterClassName); 177 174 List<Integer> converted = bagConverter.getConvertedObjectIds(profile, 178 className, bag Name, addparameter);175 className, bagList, addparameter); 179 176 // No matches 180 177 if (converted.size() <= 0) { … … 216 213 } 217 214 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 bagquery244 // config, add the variable to be passed to the custom converter245 String param = request.getParameter(urlField);246 if (StringUtils.isNotEmpty(param)) {247 // the spaces in organisms, eg. D.%20rerio, need to be handled248 addparameter = URLDecoder.decode(param, "UTF-8");249 }250 }251 return addparameter;252 }253 254 215 private ActionForward goToResults(ActionMapping mapping, HttpSession session, 255 216 WebResults webResults) { -
trunk/intermine/webapp/main/resources/webapp/js/imdwr.js
r20737 r20758 819 819 820 820 function checkOrthologueMapping(statusCount, remoteMine, localMine) { 821 821 822 var myForm = document.forms['orthologueLinkForm' + statusCount]; 822 823 var orthologueSelect = myForm.orthologueDatasets; … … 825 826 var localMapping = bits[0]; 826 827 var remoteMapping = bits[1]; 828 827 829 var selectedOrganism = orthologueSelect.options[orthologueSelect.selectedIndex].text; 828 830 myForm.orthologue.value = selectedOrganism; 829 831 832 // hide/show the radio button and name of intermine if they do/don't have orthologues 830 833 if (localMapping != null && localMapping != "") { 831 834 display('orthologueMappingLocalLabel' + statusCount, true); … … 846 849 display('orthologueMappingLocalRadio' + statusCount, false); 847 850 } 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.
