/** * Set the feature types for this request. Immediately parses the class names to * ClassDescriptors and fails as soon as possible. * * @param featureTypes A collection of feature type names. * @throws BadRequestException if the feature types are not mappable to classes, and if those * classes are not Sequence Features. */ public void setFeatureTypes(Collection<String> featureTypes) { this.featureTypes = new HashSet<String>(featureTypes); this.featureCds = new HashSet<ClassDescriptor>(); Set<String> badTypes = new HashSet<String>(); Model model = api.getModel(); ClassDescriptor sfCd = model.getClassDescriptorByName(sequenceFeature); for (String f : this.featureTypes) { ClassDescriptor cld = model.getClassDescriptorByName(f); if (cld == null) { badTypes.add(f); } else { try { if (!sequenceFeature.equals(f) && !sfCd.getUnqualifiedName().equals(f) && !ClassDescriptor.findSuperClassNames(model, f).contains(sequenceFeature)) { throw new BadRequestException(f + " is not a " + sequenceFeature); } } catch (MetaDataException e) { // This should never happen. throw new ServiceException(e); } featureCds.add(cld); for (ClassDescriptor subCld : model.getAllSubs(cld)) { featureCds.add(subCld); } } } if (!badTypes.isEmpty()) { throw new BadRequestException( "The following feature types are not " + "valid feature class names: " + badTypes); } }
/** * Make a feature track of the form (for a feature of the type <code>ClassName</code>): * * <pre> * { * "type": "JBrowse/View/Track/CanvasFeatures", * "storeClass": "JBrowse/Store/SeqFeature/REST", * "category": "Features", * "key": "Class Name", * "label": "ClassName", * "baseUrl": "http://www.foo.com/foomine/service/jbrowse/1234", * "autocomplete": "all", * "region_feature_densities": true, * "query": { "type": "ClassName" } * } * </pre> * * @param feature The type of feature to build a track for. * @return A representation of the track configuration. */ private Map<String, Object> featureTrack(ClassDescriptor feature) { Map<String, Object> ret = new HashMap<String, Object>(); ret.put("type", "JBrowse/View/Track/CanvasFeatures"); ret.put("storeClass", "JBrowse/Store/SeqFeature/REST"); ret.put("category", featureCat); ret.put("key", WebUtil.formatClass(feature, config)); // In JBrowse "key" means human-readable. ret.put( "label", dataset + "-" + feature.getUnqualifiedName()); // and "label" means machine-readable. ret.put("baseUrl", getBaseUrl() + domain); Map<String, Object> query = new HashMap<String, Object>(); query.put("type", feature.getUnqualifiedName()); ret.put("query", query); ret.put("autocomplete", "all"); ret.put("region_feature_densities", true); return ret; }
private static List<String> getAttributeView(ClassDescriptor cld) { List<String> view = new ArrayList<String>(); String basePath = cld.getUnqualifiedName() + "."; for (AttributeDescriptor att : cld.getAllAttributeDescriptors()) { if (!"id".equals(att.getName())) { view.add(basePath + att.getName()); } } return view; }
private Map<String, Object> getObjectDetails(InterMineObject imo) { WebConfig webConfig = InterMineContext.getWebConfig(); Model m = im.getModel(); Map<String, Object> objectDetails = new HashMap<String, Object>(); String className = DynamicUtil.getSimpleClassName(imo.getClass()); ClassDescriptor cd = m.getClassDescriptorByName(className); for (FieldConfig fc : FieldConfigHelper.getClassFieldConfigs(webConfig, cd)) { try { Path p = new Path(m, cd.getUnqualifiedName() + "." + fc.getFieldExpr()); if (p.endIsAttribute() && fc.getShowInSummary()) { objectDetails.put( p.getNoConstraintsString().replaceAll("^[^.]*\\.", ""), PathUtil.resolvePath(p, imo)); } } catch (PathException e) { LOG.error(e); } } return objectDetails; }
/** * Get the view as configured in the webconfig. Guarantees to return a non-empty non-null list. * * @param type The type we are trying to get a view for. * @param model The data model * @param webConfig The web-configuration. * @param fieldConfigs * @return The list of paths that we can use to construct a query. * @throws UnconfiguredException if the class has not configured view. */ private static List<String> getConfiguredView(ClassDescriptor cld, WebConfig webConfig) throws UnconfiguredException { Collection<String> view = new LinkedHashSet<String>(); // Preserve order and uniqueness. Model m = cld.getModel(); for (FieldConfig fieldConfig : resultConfigs(webConfig, cld)) { try { Path p = new Path(m, cld.getUnqualifiedName() + "." + fieldConfig.getFieldExpr()); // add subpaths of references and roots, attrs themselves, ignore collections. if (p.isRootPath() || p.endIsReference()) { view.addAll(getSubview(webConfig, m, p)); } else if (p.endIsAttribute()) { view.add(p.getNoConstraintsString()); } } catch (PathException e) { LOG.error("Invalid path configured in webconfig for class: " + cld); } } if (view.isEmpty()) { throw new UnconfiguredException(); } return new ArrayList<String>(view); }
/** {@inheritDoc} */ @SuppressWarnings("unused") @Override public ActionForward execute( @SuppressWarnings("unused") ActionMapping mapping, @SuppressWarnings("unused") ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception { long startTime = System.currentTimeMillis(); HttpSession session = request.getSession(); InterMineAPI im = SessionMethods.getInterMineAPI(session); if (im.getBagManager().isAnyBagToUpgrade(SessionMethods.getProfile(session))) { recordError(new ActionMessage("login.upgradeListManually"), request); } // fetch & set requested object InterMineObject requestedObject = getRequestedObject(im, request); if (requestedObject != null) { ReportObjectFactory reportObjectFactory = SessionMethods.getReportObjects(session); ReportObject reportObject = reportObjectFactory.get(requestedObject); request.setAttribute("object", reportObject); request.setAttribute("reportObject", reportObject); request.setAttribute("requestedObject", requestedObject); // hell starts here TagManager tagManager = im.getTagManager(); ServletContext servletContext = session.getServletContext(); ObjectStore os = im.getObjectStore(); String superuser = im.getProfileManager().getSuperuser(); if (superuser.equals(SessionMethods.getProfile(session).getUsername())) { request.setAttribute("SHOW_TAGS", true); } // place InlineLists based on TagManager, reportObject is cached while Controller is not Map<String, List<InlineList>> placedInlineLists = new TreeMap<String, List<InlineList>>(); // traverse all unplaced (non-header) InlineLists for (InlineList list : reportObject.getNormalInlineLists()) { FieldDescriptor fd = list.getDescriptor(); String taggedType = getTaggedType(fd); // assign lists to any aspects they are tagged to or put in unplaced lists String fieldPath = fd.getClassDescriptor().getUnqualifiedName() + "." + fd.getName(); List<Tag> tags = tagManager.getTags(null, fieldPath, taggedType, superuser); for (Tag tag : tags) { String tagName = tag.getTagName(); if (AspectTagUtil.isAspectTag(tagName)) { List<InlineList> listsForAspect = placedInlineLists.get(tagName); if (listsForAspect == null) { listsForAspect = new ArrayList<InlineList>(); placedInlineLists.put(tagName, listsForAspect); } listsForAspect.add(list); } else if (tagName.equals(TagNames.IM_SUMMARY)) { List<InlineList> summaryLists = placedInlineLists.get(tagName); if (summaryLists == null) { summaryLists = new ArrayList<InlineList>(); placedInlineLists.put(tagName, summaryLists); } summaryLists.add(list); } } } // any lists that aren't tagged will be 'unplaced' List<InlineList> unplacedInlineLists = new ArrayList<InlineList>(reportObject.getNormalInlineLists()); unplacedInlineLists.removeAll(placedInlineLists.values()); long now = System.currentTimeMillis(); LOG.info("TIME placed inline lists: " + (now - startTime) + "ms"); long stepTime = now; request.setAttribute("mapOfInlineLists", placedInlineLists); request.setAttribute("listOfUnplacedInlineLists", unplacedInlineLists); Map<String, Map<String, DisplayField>> placementRefsAndCollections = new TreeMap<String, Map<String, DisplayField>>(); Set<String> aspects = new LinkedHashSet<String>(SessionMethods.getCategories(servletContext)); Set<ClassDescriptor> cds = os.getModel().getClassDescriptorsForClass(requestedObject.getClass()); for (String aspect : aspects) { placementRefsAndCollections.put( TagNames.IM_ASPECT_PREFIX + aspect, new TreeMap<String, DisplayField>(String.CASE_INSENSITIVE_ORDER)); } Map<String, DisplayField> miscRefs = new TreeMap<String, DisplayField>(reportObject.getRefsAndCollections()); placementRefsAndCollections.put(TagNames.IM_ASPECT_MISC, miscRefs); // summary refs and colls Map<String, DisplayField> summaryRefsCols = new TreeMap<String, DisplayField>(); placementRefsAndCollections.put(TagNames.IM_SUMMARY, summaryRefsCols); for (Iterator<Entry<String, DisplayField>> iter = reportObject.getRefsAndCollections().entrySet().iterator(); iter.hasNext(); ) { Map.Entry<String, DisplayField> entry = iter.next(); DisplayField df = entry.getValue(); if (df instanceof DisplayReference) { categoriseBasedOnTags( ((DisplayReference) df).getDescriptor(), "reference", df, miscRefs, tagManager, superuser, placementRefsAndCollections, SessionMethods.isSuperUser(session)); } else if (df instanceof DisplayCollection) { categoriseBasedOnTags( ((DisplayCollection) df).getDescriptor(), "collection", df, miscRefs, tagManager, superuser, placementRefsAndCollections, SessionMethods.isSuperUser(session)); } } // remove any fields overridden by displayers removeFieldsReplacedByReportDisplayers(reportObject, placementRefsAndCollections); request.setAttribute("placementRefsAndCollections", placementRefsAndCollections); String type = reportObject.getType(); request.setAttribute("objectType", type); String stableLink = PortalHelper.generatePortalLink(reportObject.getObject(), im, request); if (stableLink != null) { request.setAttribute("stableLink", stableLink); } stepTime = System.currentTimeMillis(); startTime = stepTime; // attach only non empty categories Set<String> allClasses = new HashSet<String>(); for (ClassDescriptor cld : cds) { allClasses.add(cld.getUnqualifiedName()); } TemplateManager templateManager = im.getTemplateManager(); Map<String, List<ReportDisplayer>> displayerMap = reportObject.getReportDisplayers(); stepTime = System.currentTimeMillis(); startTime = stepTime; List<String> categories = new LinkedList<String>(); for (String aspect : aspects) { // 1) Displayers // 2) Inline Lists if ((displayerMap != null && displayerMap.containsKey(aspect)) || placedInlineLists.containsKey(aspect)) { categories.add(aspect); } else { // 3) Templates if (!templateManager.getReportPageTemplatesForAspect(aspect, allClasses).isEmpty()) { categories.add(aspect); } else { // 4) References & Collections if (placementRefsAndCollections.containsKey("im:aspect:" + aspect) && placementRefsAndCollections.get("im:aspect:" + aspect) != null) { for (DisplayField df : placementRefsAndCollections.get("im:aspect:" + aspect).values()) { categories.add(aspect); break; } } } } } if (!categories.isEmpty()) { request.setAttribute("categories", categories); } now = System.currentTimeMillis(); LOG.info("TIME made list of categories: " + (now - stepTime) + "ms"); } return null; }