Ejemplo n.º 1
0
    def put(self):
        set_id = self._request.matchdict['id']
        try:
            dset = DBSession.query(DigitalSet).filter(
                DigitalSet.id_set == set_id).one()
            dset.set_from_dict(self._request.validated)

            old_groups = DBSession.query(GroupSet).filter(
                GroupSet.id_set == set_id).all()
            old_ids = [gs.id_group for gs in old_groups]
            new_ids = [
                g['id_group'] for g in self._request.validated['groups']
            ]
            new_groups = [
                GroupSet(set_id, gid) for gid in new_ids if not gid in old_ids
            ]
            for new_group in new_groups:
                DBSession.add(new_group)

            for old_group in old_groups:
                if old_group.id_group not in new_ids:
                    DBSession.delete(old_group)

            # metadata = [x for x in DBSession.query(Metadata).filter(Metadata.id == dset.id_set).all()]
            update_metadata(self._request.validated['metadata'], dset.id_set,
                            'set')
            DBSession.flush()
            return APIResponse(
                add_metadata_record(dset.get_dict(), dset.id_set, 'set'))

        except Exception as e:
            print(e)
            raise HTTPNotFound()
Ejemplo n.º 2
0
    def collection_post(self):
        self._request.validated['id_item'] = str(uuid4())
        self._request.validated['created'] = datetime.datetime.now()
        # di = DigitalItem(**self._request.validated)
        v = self._request.validated
        print(v)
        metakeys = [m['key'] for m in v['metadata']]
        print(metakeys)

        missing_metakeys = check_missing_metakeys(metakeys, 'i')
        if len(missing_metakeys) > 0:
            raise HTTPBadRequest('missing metadata keys: %s' %
                                 ', '.join(missing_metakeys))

        di = DigitalItem(v['id_item'], v['mime'], v['created'], '',
                         v['id_user'], v['rights'])

        update_metadata(v['metadata'], di.id_item, 'item')
        DBSession.add(di)
        DBSession.flush()

        for link in v['links']:
            l = Link(str(uuid4()), di.id_item, link['id_user'], link['type'],
                     link['description'], link['uri'])
            DBSession.add(l)

        for group_id in v['group_ids']:
            print('Adding to group %s' % group_id)
            group_item = GroupItem(group_id, di.id_item, 0, 0)
            DBSession.add(group_item)

        print(di)
        return APIResponse(self._add_metadata(di))
Ejemplo n.º 3
0
 def delete(self):
     annotation_id = self._request.matchdict['annot_id']
     q = DBSession.query(Link).filter(Link.id_link == annotation_id)
     if self._request.user.auth_level < RIGHTLevels.Editor:
         q = q.filter(Link.id_user == self._request.user.id_user)
     link = q.one()
     DBSession.delete(link)
     DBSession.flush()
     return APIResponse(True)
Ejemplo n.º 4
0
 def delete(self):
     container_id = self._request.matchdict['container_id']
     cnt = DBSession.query(Container).filter(Container.id_view == self._view_id).filter(Container.id_container == container_id).one()
     cntitems = DBSession.query(ContainerItem).filter(ContainerItem.id_container == container_id).all()
     for itm in cntitems:
         DBSession.delete(cnt)
     DBSession.delete(cnt)
     DBSession.flush()
     return APIResponse(True)
Ejemplo n.º 5
0
def group_item_service_func_del(request):
    group_id = request.matchdict['group_id']
    item_id = request.matchdict['item_id']
    gi = DBSession.query(GroupItem).filter(
        sqlalchemy.and_(GroupItem.id_group == group_id,
                        GroupItem.id_item == item_id)).one()
    DBSession.delete(gi)
    DBSession.flush()
    req = Request.blank('/api/v1/dig/' + group_id)
    return request.invoke_subrequest(req)
Ejemplo n.º 6
0
 def put(self):
     item_id = self._request.matchdict['id']
     key = self._request.matchdict['key']
     try:
         res = DBSession.query(Metadata).filter(Metadata.key == key).filter(Metadata.id == item_id).one()
         res.value = self._request.validated['value']
         DBSession.flush()
         return res.get_dict()
     except Exception as e:
         print(str(e))
         raise HTTPBadRequest()
Ejemplo n.º 7
0
def set_di_mods(request):
    di_id = request.matchdict['id']
    try:
        mods = parse_mods(request.body.decode('utf8'))
        print(mods)
        new_meta = [{'key': key, 'value': mods[key]} for key in mods]
        update_metadata(new_meta, di_id, 'item', False)
        DBSession.flush()
        subreq = Request.blank('/api/v1/di/' + di_id)
        response = request.invoke_subrequest(subreq)
        return response
    except Exception as e:
        print('Exception %s' % str(e))
        raise HTTPBadRequest()
Ejemplo n.º 8
0
Archivo: link.py Proyecto: iimcz/emod
 def collection_post(self):
     item_id = self._request.matchdict['item_id']
     try:
         v = self._request.validated
         link = Link(str(uuid4()), item_id, v['id_user'], v['type'],
                     v['description'], v['uri'])
         link = Link(str(uuid4()), item_id, v['id_user'], v['type'],
                     v['description'], v['uri'])
         DBSession.add(link)
         DBSession.flush()
         return link.get_dict()
     except Exception as e:
         print(str(e))
         return HTTPBadRequest
Ejemplo n.º 9
0
 def collection_post(self):
     v = self._request.validated
     v['id_user'] = self._request.user.id_user
     type = 'annotation'
     if v['time'] > 0 or v['duration'] > 0:
         if v['duration'] > 0:
             type = '%s;%d;%d' % (type, v['time'], v['duration'])
         else:
             type = '%s;%d' % (type, v['time'])
     link = Link(str(uuid4()), v['id_item'], v['id_user'], type, '',
                 v['uri'])
     DBSession.add(link)
     DBSession.flush()
     return APIResponse(link.get_dict())
Ejemplo n.º 10
0
 def put(self):
     dg_id = self._request.matchdict['id']
     try:
         group = DBSession.query(DIGroup).filter(
             DIGroup.id_group == dg_id).one()
         group.type = self._request.validated['type']
         update_metadata(self._request.validated['metadata'],
                         group.id_group, 'group')
         DBSession.flush()
         # return APIResponse(self._add_metadata(group))
         return APIResponse(
             add_metadata_record(group.get_dict(), group.id_group, 'group'))
     except Exception as e:
         print(e)
         raise HTTPNotFound()
Ejemplo n.º 11
0
 def put(self):
     di_id = self._request.matchdict['id']
     try:
         item = DBSession.query(DigitalItem).filter(
             DigitalItem.id_item == di_id).one()
         item.set_from_dict(self._request.validated)
         update_metadata(self._request.validated['metadata'], item.id_item,
                         'item')
         update_links(self._request.validated['links'], item.id_item)
         DBSession.flush()
         return APIResponse(self._add_metadata(item))
     except Exception as e:
         print(e)
         traceback.print_exc()
         raise HTTPNotFound()
Ejemplo n.º 12
0
 def put(self):
     view_id = self._request.matchdict['view_id']
     try:
         q = DBSession.query(View).filter(View.id_view == view_id)
         if self._request.user.auth_level < RIGHTLevels.Editor:
             q = q.filter(View.id_user == self._request.user.id_user)
         view = q.one()
         view.set_from_dict(self._request.validated)
         update_metadata(self._request.validated['metadata'], view.id_view,
                         'view')
         DBSession.flush()
         return APIResponse(view.get_dict())
     except Exception as e:
         print(e)
         raise HTTPNotFound()
Ejemplo n.º 13
0
Archivo: user.py Proyecto: iimcz/emod
    def put(self):
        user = self._verify_access()
        v = self._request.validated
        if self._request.user.auth_level < 3:
            v['auth_level'] = user.auth_level
        print(v)
        user.set_from_dict(v)

        # set_dict() doesn't set password, so let's hash and update it manually
        new_pw =  v.get('passwd', '')
        if new_pw:
            user.passwd = hash_pw(new_pw)

        DBSession.flush()
        return APIResponse(user.get_dict())
Ejemplo n.º 14
0
    def collection_post(self):
        key = self._request.validated['key']
        item_id = self._request.matchdict['id']
        try:
            # Let's check if the id/key pair is already present. If it is, then bail out
            res = DBSession.query(Metadata).filter(Metadata.id == item_id).filter(Metadata.key == key).count()
            if res:
                print('key already present...')
                raise HTTPBadRequest()
            # We're adding new metadata, so let's check whether the key is already present in metaKey table
            meta_key = [x for x in DBSession.query(MetaKey).filter(MetaKey.key == key).all()]
            if len(meta_key) < 1:
                # nope, so let's create it
                meta_key = MetaKey(key, 'string', '', '')
                DBSession.add(meta_key)

            metadata = Metadata(item_id, 'item', key, self._request.validated['value'])
            DBSession.add(metadata)
            DBSession.flush()
            return metadata.get_dict()
        except Exception as e:
            print(str(e))
            raise HTTPBadRequest()



                    # @view(permission=Everyone)
    # def collection_get(self):
    #     return [x.get_dict() for x in DBSession.query(DigitalItem).all()]
    #
    # @view(permission=Everyone, schema = DigitalItemSchema, validators=(colander_body_validator,))
    # def collection_post(self):
    #     self._request.validated['id_item'] = str(uuid4())
    #     self._request.validated['created'] = datetime.datetime.now()
    #     #di = DigitalItem(**self._request.validated)
    #     v = self._request.validated
    #     di = DigitalItem(v['id_item'], v['mime'], v['created'], '', v['author'], v['rights'])
    #     print(di)
    #
    #     required_keys = DBSession.query(MetaKey).filter(MetaKey.mandatory.contains('i'))
    #     print('Required keys: %s' % (','.join((x.key for x in required_keys))))
    #
    #     DBSession.add(di)
    #     DBSession.flush()
    #     print(di)
    #     return di.get_dict()
Ejemplo n.º 15
0
    def collection_post(self):
        self._request.validated['id_group'] = str(uuid4())
        self._request.validated['created'] = datetime.datetime.now()

        v = self._request.validated
        print(v)
        metakeys = [m['key'] for m in v['metadata']]
        print(metakeys)

        missing_metakeys = check_missing_metakeys(metakeys, 'g')
        if len(missing_metakeys) > 0:
            raise HTTPBadRequest('missing metadata keys: %s' %
                                 ', '.join(missing_metakeys))

        dg = DIGroup(v['id_group'], v['created'], '', v['id_user'], v['type'])
        update_metadata(v['metadata'], dg.id_group, 'group')
        DBSession.add(dg)
        DBSession.flush()

        print(dg)
        return APIResponse(
            add_metadata_record(dg.get_dict(), dg.id_group, 'group'))
Ejemplo n.º 16
0
    def collection_post(self):
        self._request.validated['id_set'] = str(uuid4())
        self._request.validated['created'] = datetime.datetime.now()
        # di = DigitalItem(**self._request.validated)
        v = self._request.validated
        print(v)
        metakeys = [m['key'] for m in v['metadata']]
        print(metakeys)

        missing_metakeys = check_missing_metakeys(metakeys, 's')
        if len(missing_metakeys) > 0:
            raise HTTPBadRequest('missing metadata keys: %s' %
                                 ', '.join(missing_metakeys))

        dset = DigitalSet(v['id_set'], v['created'], '', v['id_user'])

        update_metadata(v['metadata'], dset.id_set, 'set')

        DBSession.add(dset)
        DBSession.flush()

        return APIResponse(
            add_metadata_record(dset.get_dict(), dset.id_set, 'set'))
Ejemplo n.º 17
0
 def put(self):
     key = self._request.matchdict['key']
     metakey = DBSession.query(MetaKey).filter(MetaKey.key == key).one()
     metakey.set_from_dict(self._request.validated)
     DBSession.flush()
     return APIResponse(metakey.get_dict())
Ejemplo n.º 18
0
    def collection_post(self):
        self._request.validated['id_view'] = str(uuid4())
        self._request.validated['created'] = datetime.datetime.now()
        copy_view_id = self._request.GET.get('view_id', '')
        v = self._request.validated
        print(v)
        metakeys = [m['key'] for m in v['metadata']]
        print(metakeys)

        missing_metakeys = check_missing_metakeys(metakeys, 'i')
        if len(missing_metakeys) > 0:
            raise HTTPBadRequest('missing metadata keys: %s' %
                                 ', '.join(missing_metakeys))

        view = View(v['id_view'], v['created'], v['description'], v['id_user'],
                    v['public'])
        update_metadata(v['metadata'], view.id_view, 'view')

        DBSession.add(view)
        DBSession.flush()
        #
        # for meta in v['metadata']:
        #     m = Metadata(view.id_view, 'view', meta['key'], meta['value'])
        #     DBSession.add(m)
        # DBSession.flush()

        # If user specified a view_id parameter, let's make a copy
        if copy_view_id:
            old_view = DBSession.query(View).filter(
                View.id_view == copy_view_id).one()
            old_items = DBSession.query(ViewItem).filter(
                ViewItem.id_view == copy_view_id).all()
            for item in old_items:
                print('Adding item' + item.id_item)
                vi = ViewItem(view.id_view, item.id_item, item.path)
                DBSession.add(vi)
            old_containers = DBSession\
                .query(Container, ContainerItem)\
                .join(ContainerItem, ContainerItem.id_container == Container.id_container)\
                .filter(Container.id_view == copy_view_id)\
                .all()
            process_conts = {}
            for ci in old_containers:
                cid = ci[0].id_container
                if not cid in process_conts:
                    c = ci[0]
                    new_cid = str(uuid4())
                    print('Adding container %s as %s' % (cid, new_cid))
                    process_conts[cid] = new_cid
                    cont = Container(new_cid, view.id_view, c.type,
                                     c.description, c.x, c.y, c.width,
                                     c.height, c.z, c.data)
                    DBSession.add(cont)
                else:
                    new_cid = process_conts[cid]

                print('Adding item %s to container %s' %
                      (ci[1].id_item, new_cid))
                citem = ContainerItem(new_cid, ci[1].id_item, ci[1].data)
                DBSession.add(citem)

        print(view)
        return APIResponse(
            add_metadata_record(view.get_dict(), view.id_view, 'view'))
Ejemplo n.º 19
0
Archivo: user.py Proyecto: iimcz/emod
 def collection_post(self):
     v = self._request.validated
     user = User(str(uuid.uuid4()), v['username'], v['fullname'], hash_pw(v['passwd']), v['auth_level'])
     DBSession.add(user)
     DBSession.flush()
     return APIResponse(user.get_dict())