Changeset 266


Ignore:
Timestamp:
Nov 17, 2009, 11:11:18 AM (11 years ago)
Author:
jjbot
Message:

Adjusted unwrapper functions to be able to deal with input hashes.

Location:
web
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • web/IbidasAtomicServices2.py

    r265 r266  
    1313
    1414    def getAvailableItemRelationTypes(self):
    15         #FIXME: insert real query
     15        """Returns all the types associated with item_child_links.
     16        """
     17        print "Called getAvailableItemRelationTypes"
    1618        msg = IbidasSimpleMessage()
    17         types = self.cd.term[0:100]
     19        types = self.cd.term.join(self.cd.item_child_link, 'term_id', 'type_id').up()
     20        types = types.union(types)
    1821        msg.addTerms(types)
    1922        return msg.finalize()
    2023
    2124    def getAvailableItemTypes(self):
    22         #FIXME: insert real query
     25        """Returns all the types associated with items.
     26        """
     27        print "Called getAvailableItemTypes"
    2328        msg = IbidasSimpleMessage()
    24         types = self.cd.term[101:200]
     29        types = self.cd.term.join(self.cd.item, 'term_id', 'type_id').up()
     30        types = types.union(types)
    2531        msg.addTerms(types)
    2632        return msg.finalize()
    2733
    2834    def getItemChildren(self, items):
    29         pass
     35        """Returns all the direct children of the provided items.
     36        """
     37        print items
     38        items = items['items']
     39        msg = IbidasSimpleMessage()
     40        ids = [int(x) for x in items]
     41        items = self.cd.item[_.item_id.within(*ids)]
     42
     43        links = self.cd.item_child_link.join(items, 'parent_id', 'item_id')
     44        msg.addItemLinks(links)
     45        items = self.cd.item.join(links, 'item_id', 'child_id').up()
     46        print "Nr of children found: ", len(items)
     47        msg.addItems(items)
     48
     49        return msg.finalize()
    3050
    3151    def getItemParents(self, items):
    32         pass
     52        """Returs all the direct parents of the provided items.
     53        """
     54        print items
     55        items = items['items']
     56        msg = IbidasSimpleMessage()
     57        ids = [int(x) for x in items]
     58        items = self.cd.item[_.item_id.within(*ids)]
     59
     60        links = self.cd.item_child_link.join(items, 'child_id', 'item_id')
     61        msg.addItemLinks(links)
     62        items = self.cd.item.join(links, 'item_id', 'parent_id').up()
     63        print "Nr of parents found: ", len(items)
     64        msg.addItems(items)
     65
     66        return msg.finalize()
    3367
    3468    def getItemNeighbours(self, items):
    35         pass
     69        """Returns all the direct neighbours of the provided items.
     70        """
     71        print items
     72        items = items['items']
     73        msg = IbidasSimpleMessage()
     74        ids = [int(x) for x in items]
     75        items = self.cd.item[_.item_id.within(*ids)]
     76
     77        links = self.cd.item_child_link.join(items, 'parent_id', 'item_id')
     78        msg.addItemLinks(links)
     79        items = self.cd.item.join(links, 'item_id', 'child_id')
     80        msg.addItems(items)
     81       
     82        links = self.cd.item_child_link.join(items, 'child_id', 'item_id')
     83        msg.addItemLinks(links)
     84        items = self.cd.item.join(links, 'item_id', 'parent_id')
     85        msg.addItems(items)
     86
     87        return msg.finalize()
    3688
    3789    def getItemsByID(self, ids):
     
    53105        return msg.finalize()
    54106
    55     def getItemsBySourceID(self, sourceID):
     107    def getSetContentBySourceName(self, name):
     108        """Returns all the items and links associated with the
     109        provided set_name."""
     110        setid = self.cd.set[_.name==name]()
     111        return self.getSetContentBySourceID(setid)
     112
     113    def getSetContentBySourceID(self, sourceID):
     114        """Returns all the items and links associated with the
     115        provided set_id."""
     116        source_ids = sourceID['items']
     117        print "getSetContentBySourceID called"
     118        print "source_id: ", sourceID
    56119        msg = IbidasSimpleMessage()
    57         items = self.cd.item[_.source_id==sourceID]
     120        items = self.cd.item[_.source_id.within(*source_ids)]
     121        items = items[0:500]
    58122        msg.addItems(items)
     123
     124        l1 = self.cd.item_child_link.join(items, 'child_id', 'item_id')
     125        l1 = l1.up()
     126        l1 = l1.join(items, 'parent_id', 'item_id').up()
     127        msg.addItemLinks(l1)
     128
     129        l2 = self.cd.item_child_link.join(items, 'parent_id', 'item_id')
     130        l2 = l2.up()
     131        l2 = l2.join(items, 'child_id', 'item_id').up()
     132        msg.addItemLinks(l2)
     133       
     134        return msg.finalize()
    59135
    60136    def testConnection(self):
  • web/IbidasSimpleMessage.py

    r265 r266  
    2727   
    2828    ITEM_FN = ('item_id', 'type_id', 'source_id', 'display_name')
    29     ITEMLINK_FN = tuple()
     29    ITEMLINK_FN = ('item_link_id', 'type_id', 'source_id',
     30            'parent_id', 'child_id')
    3031    SET_FN = ('set_id', 'name') # Removed description due to Nones
    3132    SETLINK_FN = tuple()
     
    103104        if not self.itemlinks is None:
    104105            out[self.ITEMLINK_STR] = self.itemlinks.to_python()
    105             out[self.ITEMLINK_FN_STR] = self.item_fn
     106            out[self.ITEMLINK_FN_STR] = self.itemlink_fn
    106107        if not self.terms is None:
    107108            out[self.TERM_STR] = self.terms.to_python()
Note: See TracChangeset for help on using the changeset viewer.