Changeset 20740
- Timestamp:
- 26/02/10 16:15:13 (2 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
bio/webapp/src/org/intermine/bio/web/logic/OrthologueConverter.java (modified) (3 diffs)
-
intermine/web/main/src/org/intermine/dwr/AjaxServices.java (modified) (1 diff)
-
intermine/web/main/src/org/intermine/web/logic/Constants.java (modified) (1 diff)
-
intermine/web/main/src/org/intermine/web/logic/bag/BagConverter.java (modified) (4 diffs)
-
intermine/web/main/src/org/intermine/web/struts/ObjectDetailsController.java (modified) (1 diff)
-
intermine/web/main/src/org/intermine/web/struts/PortalQueryAction.java (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bio/webapp/src/org/intermine/bio/web/logic/OrthologueConverter.java
r20728 r20740 15 15 import java.util.ArrayList; 16 16 import java.util.List; 17 import java.util.regex.Matcher;18 17 import java.util.regex.Pattern; 19 18 20 import javax.servlet.ServletContext;21 import javax.servlet.http.HttpSession;22 23 19 import org.apache.commons.lang.StringUtils; 24 import org.apache.log4j.Logger;25 20 import org.apache.struts.action.ActionMessage; 26 import org.directwebremoting.WebContextFactory;27 21 import org.intermine.api.InterMineAPI; 28 22 import org.intermine.api.profile.Profile; 29 23 import org.intermine.api.query.PathQueryExecutor; 30 import org.intermine.api.query.WebResultsExecutor;31 24 import org.intermine.api.results.ExportResultsIterator; 32 25 import org.intermine.api.results.ResultElement; 33 26 import org.intermine.api.results.WebResults; 34 27 import org.intermine.metadata.Model; 35 import org.intermine.model.InterMineObject;36 import org.intermine.objectstore.ObjectStore;37 import org.intermine.objectstore.ObjectStoreException;38 28 import org.intermine.pathquery.Constraints; 39 import org.intermine.pathquery.Path;40 import org.intermine.pathquery.PathException;41 29 import org.intermine.pathquery.PathQuery; 42 30 import org.intermine.web.logic.bag.BagConverter; 43 31 import org.intermine.web.logic.config.WebConfig; 44 import org.intermine.web.logic.pathqueryresult.PathQueryResultHelper;45 import org.intermine.web.logic.session.SessionMethods;46 32 47 33 /** … … 52 38 { 53 39 54 private static final Logger LOG = Logger.getLogger(OrthologueConverter.class);40 55 41 // D. melanogaster, C. lupus familiaris 56 42 private static final Pattern ORGANISM_SHORTNAME_MATCHER = Pattern.compile("([a-zA-Z]\\..+)"); 57 private static InterMineAPI im; 58 private static Model model; 59 private static WebConfig webConfig; 60 private static ObjectStore os; 43 private Model model; 44 61 45 62 public OrthologueConverter() {63 super();64 ServletContext servletContext = WebContextFactory.get().getServletContext();65 HttpSession session = WebContextFactory.get().getSession();66 im = SessionMethods.getInterMineAPI(session);67 webConfig = SessionMethods.getWebConfig(servletContext);46 /** 47 * @param im intermine api 48 * @param webConfig the webconfig 49 */ 50 public OrthologueConverter(InterMineAPI im, WebConfig webConfig) { 51 super(im, webConfig); 68 52 model = im.getModel(); 69 os = im.getObjectStore();70 }71 72 /**73 * {@inheritDoc}74 * @throws PathException75 */76 public WebResults getConvertedObjects (Profile profile, List<Integer> fromList, String type,77 String ... parameters) throws ObjectStoreException, PathException {78 String organism = null, dataset = null;79 53 80 for (String param : parameters) {81 if (StringUtils.isEmpty(param)) {82 continue;83 }84 Matcher m = ORGANISM_SHORTNAME_MATCHER.matcher(param);85 if (m.matches()) {86 organism = param;87 } else {88 dataset = param;89 }90 }91 List<InterMineObject> objectList = os.getObjectsByIds(fromList);92 PathQuery q = generateQuery(objectList, type, organism, dataset);93 94 LOG.info("PATH QUERY:" + q.toXml(PathQuery.USERPROFILE_VERSION));95 WebResultsExecutor executor = im.getWebResultsExecutor(profile);96 97 return executor.execute(q);98 54 } 99 55 100 private static PathQuery constructPathQuery(String organism, String dataset) {56 private PathQuery constructPathQuery(String bagType, String bagName, String organismName) { 101 57 PathQuery q = new PathQuery(model); 102 58 103 59 // organism 104 q.addConstraint("Gene.homologues.homologue.organism", Constraints.lookup(organism)); 60 q.addConstraint("Gene.homologues.homologue.organism.shortName", 61 Constraints.eq(organismName)); 105 62 106 63 // homologue.type = "orthologue" 107 64 q.addConstraint("Gene.homologues.type", Constraints.eq("orthologue")); 108 65 109 if (StringUtils.isNotEmpty(dataset)) { 110 // homologue.dataSets = dataset 111 q.addConstraint("Gene.homologues.dataSets.title", Constraints.eq(dataset)); 112 } 66 q.addConstraint(bagType, Constraints.in(bagName)); 113 67 return q; 114 68 } 115 69 116 private PathQuery generateQuery(List<InterMineObject> objectList, String type, String organism, 117 String dataset) 118 throws PathException { 119 PathQuery q = constructPathQuery(organism, dataset); 120 121 List<Path> view = PathQueryResultHelper.getDefaultView(type, model, webConfig, 122 "Gene.homologues.homologue", false); 123 view = getFixedView(view); 124 q.setViewPaths(view); 125 126 q.addConstraint(type, Constraints.in(objectList)); 127 128 q.syncLogicExpression("and"); 129 return q; 130 } 131 132 133 private static PathQuery generateQuery(String bagType, String bagName, String organismName) { 134 PathQuery q = constructPathQuery(organismName, null); 135 q.setView("Gene.homologues.homologue.primaryIdentifier"); 136 q.addConstraint(bagType, Constraints.in(bagName)); 137 q.syncLogicExpression("and"); 138 return q; 139 } 140 141 public String getFieldsFromConvertedObjects(Profile profile, String bagType, 70 /** 71 * runs the orthologue conversion pathquery and returns a comma-delimited list of identifiers 72 * @param profile the user's profile 73 * @param bagType the class of the list, has to be gene I think 74 * @param bagName name of list 75 * @param organismName name of homologue's organism 76 * @return commadelimited list of identifiers, eg. eve,zen 77 */ 78 public String getConvertedObjectFields(Profile profile, String bagType, 142 79 String bagName, String organismName) { 143 String orthologues = ""; 144 PathQuery pathQuery = generateQuery(bagType, bagName, organismName); 80 StringBuffer orthologues = null; 81 PathQuery pathQuery = constructPathQuery(bagType, bagName, organismName); 82 pathQuery.setView("Gene.homologues.homologue.primaryIdentifier"); 83 pathQuery.syncLogicExpression("and"); 145 84 PathQueryExecutor executor = im.getPathQueryExecutor(profile); 146 85 ExportResultsIterator it = executor.execute(pathQuery); 147 86 148 87 while (it.hasNext()) { 149 88 List<ResultElement> row = it.next(); 150 89 String orthologue = row.get(0).getField().toString(); 151 if ( StringUtils.isNotEmpty(orthologues)) {152 orthologues += ",";90 if (orthologues != null) { 91 orthologues.append(","); 153 92 } 154 orthologues += orthologue;93 orthologues.append(orthologue); 155 94 } 156 157 return orthologues; 95 if (orthologues == null) { 96 return null; 97 } 98 return orthologues.toString(); 158 99 } 159 100 160 101 /** 161 * If view contains joined organism, this will make sure, that 162 * organism is joined as a inner join. Else constraint on organism doesn't work. 163 * @param pathQuery 164 * @param joinPath 165 * @throws PathException 102 * runs the orthologue conversion pathquery and returns list of intermine IDs 103 * @param profile the user's profile 104 * @param bagType the class of the list, has to be gene I think 105 * @param bagName name of list 106 * @param organismName name of homologue's organism 107 * @return list of intermine IDs 166 108 */ 167 p rivate List<Path> getFixedView(List<Path> view) throws PathException {168 String invalidPath = "Gene.homologues.homologue:organism";169 String validPath = "Gene.homologues.homologue.organism";170 List<Path> ret = new ArrayList<Path>();171 for (Path path : view) {172 if (path.toString().contains(invalidPath)) {173 String newPathString = path.toString().replace(invalidPath, validPath);174 path = new Path(path.getModel(), newPathString);175 }176 ret.add(path);109 public List<Integer> getConvertedObjectIds(Profile profile, String bagType, 110 String bagName, String organismName) { 111 PathQuery pathQuery = constructPathQuery(bagType, bagName, organismName); 112 pathQuery.setView(bagType + ".id"); 113 PathQueryExecutor executor = im.getPathQueryExecutor(profile); 114 ExportResultsIterator it = executor.execute(pathQuery); 115 List<Integer> ids = new ArrayList(); 116 while (it.hasNext()) { 117 List<ResultElement> row = it.next(); 118 ids.add((Integer) row.get(0).getField()); 177 119 } 178 return ret;120 return ids; 179 121 } 180 122 … … 241 183 return am; 242 184 } 185 186 @Override 187 public WebResults getConvertedObjects(Profile profile, List<Integer> fromList, String type, 188 String... parameters) { 189 // TODO Auto-generated method stub 190 return null; 191 } 243 192 } -
trunk/intermine/web/main/src/org/intermine/dwr/AjaxServices.java
r20728 r20740 1364 1364 Constructor constructor = clazz.getConstructor(); 1365 1365 BagConverter bagConverter = (BagConverter) constructor.newInstance(); 1366 return bagConverter.get FieldsFromConvertedObjects(profile, bagType, bagName,1366 return bagConverter.getConvertedObjectFields(profile, bagType, bagName, 1367 1367 selectedValue); 1368 1368 } -
trunk/intermine/web/main/src/org/intermine/web/logic/Constants.java
r20646 r20740 105 105 106 106 /** 107 * The name of the property that is set to TRUE in the PortalQueryAction Action to indicate108 * to the ObjectDetailsController that we have come from a portal page.109 */110 public static final String PORTAL_QUERY_FLAG = "PORTAL_QUERY_FLAG";111 112 /**113 107 * The name of the property to look up to find the maximum size of an inline table. 114 108 */ -
trunk/intermine/web/main/src/org/intermine/web/logic/bag/BagConverter.java
r20728 r20740 14 14 import java.util.List; 15 15 16 import javax.servlet.ServletContext;17 import javax.servlet.http.HttpSession;18 19 16 import org.apache.struts.action.ActionMessage; 20 import org.directwebremoting.WebContextFactory;21 17 import org.intermine.api.InterMineAPI; 22 18 import org.intermine.api.profile.Profile; 23 19 import org.intermine.api.results.WebResults; 24 import org.intermine.metadata.Model;25 import org.intermine.objectstore.ObjectStore;26 20 import org.intermine.objectstore.ObjectStoreException; 27 21 import org.intermine.pathquery.PathException; 28 22 import org.intermine.web.logic.config.WebConfig; 29 import org.intermine.web.logic.session.SessionMethods;30 23 31 24 … … 35 28 * 36 29 */ 37 public abstract class BagConverter { 38 39 private static InterMineAPI im = null; 40 private static Model model = null; 41 private static WebConfig webConfig = null; 42 private static ObjectStore os = null; 43 44 30 public abstract class BagConverter 31 { 32 33 protected InterMineAPI im = null; 34 protected WebConfig webConfig = null; 35 36 /** 37 * 38 * @param im intermine API 39 * @param webConfig the webconfig 40 */ 41 public BagConverter(InterMineAPI im, WebConfig webConfig) { 42 this.im = im; 43 this.webConfig = webConfig; 44 } 45 45 46 /** 46 47 * Returns a List<ResultRows> of converted objects 48 * @param profile user's profile 47 49 * @param parameters the parameters 48 50 * @param fromList the list to convert … … 53 55 * @throws PathException bad path 54 56 */ 55 public abstract WebResults getConvertedObjects(Profile profile, List<Integer> fromList, String type,56 String ... parameters)57 public abstract WebResults getConvertedObjects(Profile profile, List<Integer> fromList, 58 String type, String ... parameters) 57 59 throws ClassNotFoundException, ObjectStoreException, PathException; 58 60 … … 67 69 * @throws UnsupportedEncodingException exception 68 70 */ 69 public abstract ActionMessage getActionMessage(String externalids, int convertedSize, String type,70 String ... parameters)71 public abstract ActionMessage getActionMessage(String externalids, int convertedSize, 72 String type, String ... parameters) 71 73 throws ObjectStoreException, UnsupportedEncodingException; 72 73 public abstract String getFieldsFromConvertedObjects(Profile profile, String bagType, 74 75 /** 76 * 77 * @param profile user's profile 78 * @param bagType class of list 79 * @param bagName name of list 80 * @param constraintValue value of constraint 81 * @return string of comma delimited identifiers 82 */ 83 public abstract String getConvertedObjectFields(Profile profile, String bagType, 84 String bagName, String constraintValue); 85 86 /** 87 * 88 * @param profile user's profile 89 * @param bagType class of list 90 * @param bagName name of list 91 * @param constraintValue value of constraint 92 * @return list of intermine IDs 93 */ 94 public abstract List<Integer> getConvertedObjectIds(Profile profile, String bagType, 74 95 String bagName, String constraintValue); 75 96 } -
trunk/intermine/web/main/src/org/intermine/web/struts/ObjectDetailsController.java
r20462 r20740 88 88 request.setAttribute("object", dobj); 89 89 90 if (session.getAttribute(Constants.PORTAL_QUERY_FLAG) != null) {91 session.removeAttribute(Constants.PORTAL_QUERY_FLAG);92 // FIXME see #191193 // setVerboseCollections(session, dobj);94 }95 96 90 Map<String, Map> placementRefsAndCollections = new TreeMap<String, Map>(); 97 91 Set<String> aspects = new HashSet<String>(SessionMethods.getCategories(servletContext)); -
trunk/intermine/web/main/src/org/intermine/web/struts/PortalQueryAction.java
r20728 r20740 11 11 */ 12 12 13 import java.io.UnsupportedEncodingException; 13 14 import java.lang.reflect.Constructor; 14 15 import java.net.URLDecoder; … … 36 37 import org.intermine.api.profile.Profile; 37 38 import org.intermine.api.query.WebResultsExecutor; 38 import org.intermine.api.results.ResultElement;39 39 import org.intermine.api.results.WebResults; 40 import org.intermine.api.results.flatouterjoins.MultiRow;41 import org.intermine.api.results.flatouterjoins.MultiRowValue;42 40 import org.intermine.api.template.TemplateManager; 43 41 import org.intermine.api.template.TemplatePopulator; … … 45 43 import org.intermine.api.util.NameUtil; 46 44 import org.intermine.metadata.Model; 47 import org.intermine.model.InterMineObject;48 45 import org.intermine.objectstore.ObjectStoreException; 49 46 import org.intermine.objectstore.query.ConstraintOp; 50 import org.intermine.objectstore.query.ResultsRow;51 47 import org.intermine.pathquery.Constraints; 52 48 import org.intermine.pathquery.Path; 53 49 import org.intermine.pathquery.PathException; 54 50 import org.intermine.pathquery.PathQuery; 55 import org.intermine.util.StringUtil;56 51 import org.intermine.web.logic.Constants; 57 52 import org.intermine.web.logic.bag.BagConverter; … … 75 70 private static int index = 0; 76 71 // private static final Logger LOG = Logger.getLogger(PortalQueryAction.class); 72 private Map<String, BagConverter> bagConverters = new HashMap(); 73 74 77 75 /** 78 76 * Link-ins from other sites end up here (after some redirection). … … 95 93 final InterMineAPI im = SessionMethods.getInterMineAPI(session); 96 94 ServletContext servletContext = session.getServletContext(); 97 String extId = request.getParameter("externalid"); 95 98 96 String origin = request.getParameter("origin"); 99 97 String className = request.getParameter("class"); 100 //String organism = request.getParameter("organism");98 String extId = request.getParameter("externalid"); 101 99 if ((extId == null) || (extId.length() <= 0)) { 102 100 extId = request.getParameter("externalids"); 103 101 } 102 104 103 // Add a message to welcome the user 105 104 Properties properties = SessionMethods.getWebProperties(servletContext); 106 105 String welcomeMsg = properties.getProperty("portal.welcome." + origin); 107 if (StringUtil .isEmpty(welcomeMsg)) {106 if (StringUtils.isEmpty(welcomeMsg)) { 108 107 welcomeMsg = properties.getProperty("portal.welcome"); 109 108 } … … 115 114 } 116 115 117 session.setAttribute(Constants.PORTAL_QUERY_FLAG, Boolean.TRUE); 118 119 // Set collapsed/uncollapsed state of object details UI 120 // TODO This might not be used anymore 121 Map<String, Boolean> collapsed = SessionMethods.getCollapsedMap(session); 122 collapsed.put("fields", Boolean.TRUE); 123 collapsed.put("further", Boolean.FALSE); 124 collapsed.put("summary", Boolean.FALSE); 125 126 Profile profile = SessionMethods.getProfile(session); 116 127 117 String[] idList = extId.split(","); 128 118 … … 139 129 BagQueryConfig bagQueryConfig = im.getBagQueryConfig(); 140 130 141 // If the class is not in the model, we can't continue 142 try { 143 className = StringUtil.capitalise(className); 144 Class.forName(model.getPackageName() + "." + className); 145 } catch (ClassNotFoundException clse) { 131 // If the class is not in the model, we can't continue 132 if (model.getClassDescriptorByName(className) == null) { 146 133 recordError(new ActionMessage("errors.badportalclass"), request); 147 134 return goToNoResults(mapping, session); 148 135 } 149 String bagName = NameUtil.generateNewName(profile.getSavedBags().keySet(), "link"); 150 136 151 137 PathQuery pathQuery = new PathQuery(model); 152 138 List<Path> view = PathQueryResultHelper.getDefaultView(className, model, webConfig, null, … … 157 143 158 144 Map<String, BagQueryResult> returnBagQueryResults = new HashMap(); 145 Profile profile = SessionMethods.getProfile(session); 159 146 WebResultsExecutor executor = im.getWebResultsExecutor(profile); 160 147 WebResults webResults = executor.execute(pathQuery, returnBagQueryResults); 161 148 149 String bagName = NameUtil.generateNewName(profile.getSavedBags().keySet(), "link"); 162 150 InterMineBag imBag = profile.createBag(bagName, className, ""); 163 151 List<Integer> bagList = new ArrayList(); … … 177 165 if (additionalConverters != null) { 178 166 for (String converterClassName : additionalConverters.keySet()) { 179 Class clazz = Class.forName(converterClassName); 180 Constructor constructor = clazz.getConstructor(); 181 String[] paramArray = additionalConverters.get(converterClassName); 182 String[] urlFields = paramArray[0].split(","); 183 String[] addparameters = new String[urlFields.length]; 184 int i = 0; 185 for (String urlField : urlFields) { 186 // if one of the request vars matches the variables listed in the bagquery 187 // config, add the variable to be passed to the custom converter 188 String param = request.getParameter(urlField); 189 if (StringUtils.isNotEmpty(param)) { 190 // the spaces in organisms, eg. D.%20rerio, need to be handled 191 addparameters[i] = URLDecoder.decode(param, "UTF-8"); 192 } 193 } 167 168 String[] addparameters = getAdditionalParameters(request, 169 additionalConverters.get(converterClassName)); 170 194 171 if (addparameters.length > 0) { 195 BagConverter bagConverter = (BagConverter) constructor.newInstance(); 196 WebResults convertedWebResult = bagConverter.getConvertedObjects(profile,197 bagList, className, addparameters); 172 173 BagConverter bagConverter = getBagConverter(converterClassName); 174 198 175 imBag = profile.createBag(bagName, className, ""); 199 List<Integer> converted = new ArrayList<Integer>(); 200 for (MultiRow<ResultsRow<MultiRowValue<ResultElement>>> resRow 201 : convertedWebResult) { 202 ResultElement resElement = resRow.get(0).get(0).getValue(); 203 Object obj = resElement.getObject(); 204 if (obj instanceof InterMineObject) { 205 converted.add(((InterMineObject) obj).getId()); 206 } 207 } 176 List<Integer> converted = bagConverter.getConvertedObjectIds(profile, 177 className, bagName, addparameters[0]); 208 178 // No matches 209 179 if (converted.size() <= 0) { … … 224 194 } 225 195 } 226 // Attach messages 227 if (bagList.size() == 0 && bagQueryResult.getMatches().size() == 1) { 228 ActionMessage msg = new ActionMessage("results.lookup.noresults.one", 229 new Integer(bagQueryResult.getMatches().size()), 230 className); 231 actionMessages.add(Constants.PORTAL_MSG, msg); 232 } else if (bagList.size() == 0 && bagQueryResult.getMatches().size() > 1) { 233 ActionMessage msg = new ActionMessage("results.lookup.noresults.many", 234 new Integer(bagQueryResult.getMatches().size()), 235 className); 236 actionMessages.add(Constants.PORTAL_MSG, msg); 237 } else if (bagList.size() > 0) { 238 ActionMessage msg = new ActionMessage("results.lookup.matches.many", 239 new Integer(bagList.size())); 240 actionMessages.add(Constants.PORTAL_MSG, msg); 241 } else if (bagList.size() == 0) { 242 ActionMessage msg = new ActionMessage("portal.nomatches", extId); 243 actionMessages.add(Constants.PORTAL_MSG, msg); 244 } 196 197 attachMessages(actionMessages, className, bagQueryResult.getMatches().size(), 198 bagList.size(), extId); 199 245 200 session.setAttribute(Constants.PORTAL_MSG, actionMessages); 246 201 … … 260 215 } 261 216 217 private BagConverter getBagConverter(String converterClassName) { 218 219 BagConverter bagConverter = bagConverters.get(converterClassName); 220 221 if (bagConverter == null) { 222 try { 223 Class clazz = Class.forName(converterClassName); 224 Constructor constructor = clazz.getConstructor(); 225 bagConverter = (BagConverter) constructor.newInstance(); 226 } catch (Exception e) { 227 throw new RuntimeException("Failed to construct bagconverter for " 228 + converterClassName, e); 229 } 230 bagConverters.put(converterClassName, bagConverter); 231 } 232 return bagConverter; 233 } 234 235 private String[] getAdditionalParameters(HttpServletRequest request, String[] paramArray) 236 throws UnsupportedEncodingException { 237 238 String[] urlFields = paramArray[0].split(","); 239 String[] addparameters = new String[urlFields.length]; 240 int i = 0; 241 for (String urlField : urlFields) { 242 // if one of the request vars matches the variables listed in the bagquery 243 // config, add the variable to be passed to the custom converter 244 String param = request.getParameter(urlField); 245 if (StringUtils.isNotEmpty(param)) { 246 // the spaces in organisms, eg. D.%20rerio, need to be handled 247 addparameters[i] = URLDecoder.decode(param, "UTF-8"); 248 } 249 } 250 return addparameters; 251 } 252 262 253 private ActionForward goToResults(ActionMapping mapping, 263 254 HttpSession session, WebResults webResults) { … … 287 278 } 288 279 280 private void attachMessages(ActionMessages actionMessages, String className, 281 int bagQueryResultSize, 282 int bagListSize, String extId) { 283 // Attach messages 284 if (bagListSize == 0 && bagQueryResultSize == 1) { 285 ActionMessage msg = new ActionMessage("results.lookup.noresults.one", 286 new Integer(bagQueryResultSize), 287 className); 288 actionMessages.add(Constants.PORTAL_MSG, msg); 289 } else if (bagListSize == 0 && bagQueryResultSize > 1) { 290 ActionMessage msg = new ActionMessage("results.lookup.noresults.many", 291 new Integer(bagQueryResultSize), 292 className); 293 actionMessages.add(Constants.PORTAL_MSG, msg); 294 } else if (bagListSize > 0) { 295 ActionMessage msg = new ActionMessage("results.lookup.matches.many", 296 new Integer(bagListSize)); 297 actionMessages.add(Constants.PORTAL_MSG, msg); 298 } else if (bagListSize == 0) { 299 ActionMessage msg = new ActionMessage("portal.nomatches", extId); 300 actionMessages.add(Constants.PORTAL_MSG, msg); 301 } 302 } 303 289 304 /** 290 * @deprecated Use the BagQueryRunnerinstead305 * @deprecated Use the quicksearch action instead 291 306 */ 292 307 private String loadObjectDetails(ServletContext servletContext, HttpSession session,
Note: See TracChangeset
for help on using the changeset viewer.
