protected void init() { // System.err.println( "INIT: _sc.getBeanName() = " + _sc.getBeanName() ); try { if (_cache == null) { _cache = ObjectCacheFactory.defaultObjectCache(); } _sod = SODUtils.getInstance(); // Try to retrive from cache. _sc.setReturnCount(new Boolean(true)); _sc.setReturnObjects(new Boolean(true)); SearchResult sr = _cache.get(_sc); if (sr == null) { sr = _sc.search(); _cache.put(_sc, sr); } _count = sr.getCount().intValue(); List newItems = Arrays.asList(sr.getResultSet()); for (Iterator i = newItems.iterator(); i.hasNext(); ) { _objects.add(i.next()); } } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException("Error initializing: " + ex.toString()); } }
public PagerItem[] getItems(int startIdx, int numItems) throws Exception { // System.err.println( "getItems(): startIdx = " + startIdx + // ", numItems = " + numItems ); int pis = startIdx + numItems; _sc.setStartAt(new Integer(startIdx + 1)); _sc.setMaxRecordset(new Integer(numItems)); SearchResult sr = _cache.get(_sc); if (sr == null) { sr = _sc.search(); _cache.put(_sc, sr); } _objects = Arrays.asList(sr.getResultSet()); // System.err.println( "_objects.size() = " + _objects.size() ); pis = Math.min(_objects.size(), numItems); if (pis < 0) { pis = 0; } // System.err.println( "pis = " + pis ); PagerItem[] items = new PagerItem[pis]; SearchableObject so = _sod.getSearchableObject(_sc.getBeanName()); for (int i = 0; i < items.length; i++) { // Object obj = _objects.get( startIdx + i ); Object obj = _objects.get(i); Object idObj = CaBIOUtils.getProperty(obj, "id"); String id = (idObj != null ? idObj.toString() : ""); // System.err.println( "creating pi for " + obj.getClass().getName() + ":" + id ); List labelProps = so.getLabelProperties(); List assocs = getNavigableAssociations(so); List vals = new ArrayList(); for (ListIterator j = labelProps.listIterator(); j.hasNext(); ) { Object val = CaBIOUtils.getProperty(obj, ((String) j.next()).trim()); if (val != null) { vals.add(val.toString()); } else { vals.add(""); } } if (_eventHandler != null) { for (ListIterator j = assocs.listIterator(); j.hasNext(); ) { Association assoc = (Association) j.next(); vals.add( "<a href=\"javascript:" + _eventHandler + "('" + obj.getClass().getName() + "', '" + id + "', '" + assoc.getRole() + "')\">" + assoc.getLabel() + getCountString(obj, assoc.getRole()) + "</a>"); } } items[i] = new PagerItemImpl(id, (String[]) vals.toArray(new String[vals.size()])); } return items; }
public DefaultMutableTreeNode buildTree(String ontName, String rootTerm) throws Exception { DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(); MessageLog.printInfo("OntologyTree.initTree(): caching tree for " + ontName); SearchCriteria sc = CaBIOUtils.newSearchCriteria(ontName); sc.putCriterion("name", Criterion.EQUAL_TO, rootTerm); Object[] results = sc.search().getResultSet(); if (results.length == 1) { CMAPOntology root = (CMAPOntology) results[0]; CMAPOntologyRelationship[] rels = (CMAPOntologyRelationship[]) root.getChildRelationships(); CMAPOntology rootObj = rels[0].getChild(); String id = CaBIOUtils.getProperty(rootObj, "id").toString(); String name = rootTerm; treeRoot.setUserObject( new WebNode(id, name, "javascript:" + _eventHandler + "('" + id + "', '" + name + "')")); buildTree(treeRoot, rootObj); } else if (results.length > 1) { throw new Exception("Found more that one root for root term: " + rootTerm); } else { throw new Exception("Found not root for root term: " + rootTerm); } return treeRoot; }