Beispiel #1
0
 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());
   }
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 public CaBIOPagerDataSource2(String beanName, String eh) {
   try {
     _sc = CaBIOUtils.newSearchCriteria(beanName);
     _sc.setMaxRecordset(new Integer(500));
   } catch (Exception ex) {
     ex.printStackTrace();
     throw new RuntimeException(
         "Error creating search criteria for " + beanName + ": " + ex.toString());
   }
   _eventHandler = eh;
   init();
 }
 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;
 }
Beispiel #5
0
 protected void initHeaders() {
   List h = new ArrayList();
   if (_sod == null) {
     throw new RuntimeException("sod is null");
   }
   if (_sc == null) {
     throw new RuntimeException("search criteria is null");
   }
   String beanName = _sc.getBeanName();
   if (beanName.endsWith("Impl")) {
     beanName = beanName.substring(0, beanName.indexOf("Impl"));
   }
   SearchableObject so = _sod.getSearchableObject(beanName);
   if (so == null) {
     throw new RuntimeException("Couldn't find so for " + beanName);
   }
   List labelProps = so.getLabelProperties();
   for (Iterator it = labelProps.iterator(); it.hasNext(); ) {
     String propName = (String) it.next();
     Attribute att = _sod.getAttribute(so, propName);
     if (att == null) {
       throw new RuntimeException(
           "CaBIOPagerDataSource.init(): couldn't find attribute "
               + propName
               + " on "
               + so.getClassname());
     }
     h.add(att.getLabel());
   }
   if (_eventHandler != null) {
     List assocs = getNavigableAssociations(so);
     for (Iterator it = assocs.iterator(); it.hasNext(); ) {
       Association assoc = (Association) it.next();
       h.add(assoc.getLabel());
     }
   }
   _headers = (String[]) h.toArray(new String[h.size()]);
 }