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))
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()
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()
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()
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()
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()
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'))
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'))
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'))