def view(request): session = DBSession() uid = request.params["uid"] delete_recursive = json.loads(request.params["recursive"]) ro = ResearchObject.get(session, uid) if ro.owner == request.unauthenticated_userid: ResearchObject.remove(session, ro, delete_recursive) return {}
def init(self, session, ro_def): """Initialize this RO with a set of attributes Args: session (DBSession): ro_def (dict): set of properties to initialize this RO Returns: None """ loc_def = dict(ro_def) wkf = loc_def.pop('workflow') ResearchObject.init(self, session, loc_def) self.workflow = wkf # link to workflow associated to this provenance ROLink.connect(session, self.id, wkf, 'use') # link to workflow nodes associated with each process? # link to external data consumed input_data = set() for pexec in ro_def["executions"]: for port in pexec['inputs']: if port['data'] is not None: input_data.add(port['data']) input_ref = set() for did in input_data: ddef = get_data_def(ro_def, did) if ddef['type'] == 'ref': input_ref.add(ddef['value']) for did in input_ref: ROLink.connect(session, self.id, did, 'consume') # link to external data produced output_data = set() for pexec in ro_def["executions"]: for port in pexec['outputs']: if port['data'] is not None: output_data.add(port['data']) output_ref = set() for did in output_data: ddef = get_data_def(ro_def, did) if ddef['type'] == 'ref': output_ref.add(ddef['value']) for did in output_ref: ROLink.connect(session, self.id, did, 'produce')
def init(self, session, ro_def): """Initialize this RO with a set of attributes Args: session (DBSession): ro_def (dict): set of properties to initialize this RO Returns: None """ loc_def = dict(ro_def) doi = loc_def.pop('doi', "") ResearchObject.init(self, session, loc_def) self.doi = doi
def add_link(request, session, ro): """Add a new 'use' link between this RO and another Args: request (Request): session (DBSession): ro (ResearchObject): Returns: (None|uid): None if something failed, created link """ uid = request.params.get('ro_id', "") if len(uid) == 0: request.session.flash("Enter a RO id first", 'warning') return None # check whether the RO is already associated to this RO if uid == ro.id: request.session.flash("Can not create link with oneself", 'warning') return None linked = [link.target for link in ro.out_links if link.type == 'use'] if uid in linked: request.session.flash("%s is already linked" % uid, 'warning') return None # check whether uid correspond to a valid RO tgt = ResearchObject.get(session, uid) if tgt is None: request.session.flash("%s is not a valid RO" % uid, 'warning') return None # create link link = ROLink.connect(session, ro.id, uid, "use") return link
def init(self, session, ro_def): """Initialize this RO with a set of attributes Args: session (DBSession): ro_def (dict): set of properties to initialize this RO Returns: None """ ResearchObject.init(self, session, ro_def) # link to nodes used by this workflow uids = set(ndef['id'] for ndef in ro_def.get('nodes', [])) for uid in uids: ROLink.connect(session, self.id, uid, 'use')
def edit_init(request, session, tab): """Common init for all 'edit' views. Args: request: (Request) session: (DBSession) tab: (str) current tab in view Returns: (ResearchObject, dict of (str: any)): ro, view_params """ ro, view_params = view_init(request, session, tab) warn_links = [link for link in ro.out_links if link.type == 'produce'] error_links = [link for link in ro.in_links if link.type != 'contains'] view_params["warn_links"] = warn_links view_params["error_links"] = error_links if not view_params["allow_edit"]: msg = "Access to %s edition not granted for you" % ro.id request.session.flash(msg, 'warning') raise HTTPFound(location=request.route_url('home')) if 'back' in request.params: # request.session.flash("Edition stopped", 'success') loc = request.route_url('ro_view_%s' % tab, uid=ro.id) raise HTTPFound(location=loc) if 'update' in request.params: # edit project visibility public = 'visibility' in request.params ro.public = public if 'confirm_transfer' in request.params: if request.unauthenticated_userid != ro.owner: request.session.flash("Action non authorized for you", 'warning') raise HTTPFound(location=request.route_url('home')) user = User.get(session, request.params["new_owner"]) if user is None: msg = "User '%s' is unknown" % request.params["new_owner"] request.session.flash(msg, 'warning') raise HTTPFound(location=request.current_route_url()) ro.change_owner(session, user) loc = request.route_url("ro_view_home", uid=ro.id) transaction.commit() raise HTTPFound(location=loc) delete_recursive = "confirm_delete_recursive" in request.params if "confirm_delete" in request.params or delete_recursive: if ResearchObject.remove(session, ro, delete_recursive): transaction.commit() request.session.flash("RO '%s' deleted" % ro.id, 'success') else: request.session.flash("Failed to delete '%s'" % ro.id, 'warning') raise HTTPFound(location=request.route_url('home')) return ro, view_params
def init(self, session, ro_def): """Initialize this RO with a set of attributes Args: session (DBSession): ro_def (dict): set of properties to initialize this RO Returns: None """ loc_def = dict(ro_def) interface = loc_def.pop('interface', self.implements) value = loc_def.pop('value', None) ResearchObject.init(self, session, loc_def) self.interface = interface self.value = json.dumps(value)
def init(self, session, ro_def): """Initialize this RO with a set of attributes Args: session (DBSession): ro_def (dict): set of properties to initialize this RO Returns: None """ # remove attributes locally stored loc_def = dict(ro_def) schema = loc_def.pop('schema', "{}") ancestors = loc_def.pop('ancestors', []) ResearchObject.init(self, session, loc_def) self.schema = schema for ancestor in ancestors: ROLink.connect(session, ancestor, self.id, 'is_ancestor_of')
def init(self, session, ro_def): """Initialize this RO with a set of attributes Args: session (DBSession): ro_def (dict): set of properties to initialize this RO Returns: None """ # remove attributes locally stored loc_def = dict(ro_def) contents = loc_def.pop('contents', []) ctype = loc_def.pop('ctype', "container") ResearchObject.init(self, session, loc_def) self.ctype = ctype for ro in contents: ROLink.connect(session, self.id, ro.id, "contains")
def view(request): session = DBSession() ro, view_params = view_init_min(request, session) view_params['description'] = Markup(ro.html_description()) ancestors = [] for link in ro.in_links: if link.type == 'is_ancestor_of': ancestors.append(ResearchObject.get(session, link.source)) view_params['ancestors'] = ancestors return view_params
def init(self, session, ro_def): """Initialize this RO with a set of attributes Args: session (DBSession): ro_def (dict): set of properties to initialize this RO Returns: None """ loc_def = dict(ro_def) # check attributes if 'inputs' not in loc_def: loc_def['inputs'] = [] if 'outputs' not in loc_def: loc_def['outputs'] = [] ResearchObject.init(self, session, loc_def) # link to interfaces used by this node ports = chain(loc_def['inputs'], loc_def['outputs']) uids = set(port_def['interface'] for port_def in ports) for uid in uids: ROLink.connect(session, self.id, uid, 'use')
def repr_json(self, full=False): """Create a json representation of this object Args: full (bool): if True, also add all properties stored in definition default False Returns: dict """ d = ResearchObject.repr_json(self, full=full) if full: d['workflow'] = self.workflow return d
def repr_json(self, full=False): """Create a json representation of this object Args: full (bool): if True, also add all properties stored in definition default False Returns: dict """ d = ResearchObject.repr_json(self, full=full) if full: d['schema'] = json.loads(self.schema) d['ancestors'] = self.ancestors() return d
def fetch_ro(request, session): """Retrieve RO whose id is in URL. Args: request: (Request) session: (DBSession) Returns: (str, ResearchObject): uid, ro """ uid = request.matchdict['uid'] ro = ResearchObject.get(session, uid) if ro is None: request.session.flash("RO %s does not exists" % uid, 'warning') raise HTTPFound(location=request.route_url('home')) return uid, ro
def repr_json(self, full=False): """Create a json representation of this object Args: full (bool): if True, also add all properties stored in definition default False Returns: dict """ d = ResearchObject.repr_json(self, full=full) if full: d['interface'] = self.interface d['value'] = json.loads(self.value) return d
def append_ro(request, session, container): """Add a new RO in this container. Args: request (Request): session (DBSession): container (ROContainer): Returns: (None|uid): None if something failed, created link """ uid = request.params.get('ro_id', "") if len(uid) == 0: request.session.flash("Enter a RO id first", 'warning') return None # check whether the RO is already a member of the container if uid == container.id: request.session.flash("Can not contain oneself", 'warning') return None content = [link.target for link in container.out_links if link.type == 'contains'] if uid in content: request.session.flash("%s is already in this container" % uid, 'warning') return None # check whether uid correspond to a valid RO ro = ResearchObject.get(session, uid) if ro is None: request.session.flash("%s is not a valid RO" % uid, 'warning') return None # check whether user has 'install' rights on this RO role = ro.access_role(session, request.unauthenticated_userid) if role < Role.install: request.session.flash("You're not allowed to add %s to this container" % uid, 'warning') return None # create link link = ROLink.connect(session, container.id, uid, "contains") return link
def view(request): session = DBSession() user = request.unauthenticated_userid if 'uid' in request.params: # search a RO with a specific id uid = request.params['uid'] ro = ResearchObject.get(session, uid) if ro is None: return None else: # check credentials role = ro.access_role(session, user) if role == Role.denied: return None else: return ro.repr_json(full=True) else: ros = search(session, request.params) return [ro.id for ro in ros if ro.access_role(session, user) != Role.denied]
def view(request): session = DBSession() ro, view_params = view_init_min(request, session) if view_params["allow_edit"] and ('new_content' in request.params or request.params.get("ro_id", "") != ""): if append_ro(request, session, ro) is not None: loc = request.current_route_url() return HTTPFound(location=loc) view_params['description'] = Markup(ro.html_description()) content = [] for link in ro.out_links: if link.type == "contains": ro = ResearchObject.get(session, link.target) content.append((ro.name.lower(), ro)) content.sort() view_params['content'] = [ro for name, ro in content] return view_params
def view_init_min(request, session): """Common init for all 'view' parts. Args: request: (Request) session: (DBSession) Returns: (ResearchObject, dict of (str: any)): ro, view_params """ if 'main_search' in request.params: loc = request.route_url('ro_list', _query=dict(request.params)) raise HTTPFound(location=loc) uid, ro = fetch_ro(request, session) current_uid = request.unauthenticated_userid role = ro.access_role(session, current_uid) if role == Role.denied: request.session.flash("Access to %s not granted for you" % uid, 'warning') raise HTTPFound(location=request.route_url('home')) # allow edition allow_edit = (current_uid is not None and role == Role.edit) # find containers uids = fetch_containers(session, ro) containers = [(uid, ResearchObject.get(session, uid).name) for uid in uids] view_params = {"ro": ro, "containers": containers, "allow_edit": allow_edit, "minimized": True} return ro, view_params
def main(session): ro_top = ROContainer() ro_top.init(session, dict(owner=users[0].id, name="sample")) ro_top.public = True containers.append(ro_top) ro1 = ResearchObject() ro1.init(session, dict(owner=users[0].id, name="RO one")) ro1.add_policy(session, users[0], Role.view) ro1.add_policy(session, teams[2], Role.edit) ro2 = ResearchObject() ro2.init(session, dict(owner=users[0].id, name="RO two")) ROLink.connect(session, ro1.id, ro2.id, "contains") ro3 = ResearchObject() ro3.init(session, dict(owner=users[0].id, name="RO three")) ros = [] for i in range(5): ro = ResearchObject() ro.init(session, dict(owner=users[0].id, name="RO%d" % i)) ros.append(ro) roc = ROContainer() roc.init(session, dict(owner=users[0].id, name="myproject", remote="https://github.com/revesansparole/roc", contents=ros)) ROLink.connect(session, ro_top.id, roc.id, 'contains') ros = [] for i in range(5): ro = ResearchObject() ro.init(session, dict(owner=users[1].id, name="ROcp%d" % i)) ros.append(ro) ro = ROArticle() ro.init(session, dict(owner=users[2].id, name="cp article")) ro.add_policy(session, users[0], Role.view) ros.append(ro) roc2 = ROContainer() roc2.init(session, dict(owner=users[2].id, name="CPproject", contents=ros)) ROLink.connect(session, ro_top.id, roc2.id, 'contains') roa = ROArticle() roa.init(session, dict(owner=users[0].id, name="test article")) roa.doi = "10.1016/S0304-3800(98)00100-8" descr = dedent(""" We present a new approach to simulate the distribution of natural light within plant canopies. The canopy is described in 3D, each organ being represented by a set of polygons. Our model calculates the light incident on each polygon. The principle is to distinguish for each polygon the contribution of the light coming directly from light sources, the light scattered from close polygons and that scattered from far polygons. Close polygons are defined as located inside a sphere surrounding the studied polygon and having a diameter Ds. The direct light is computed by projection. The exchanges between close polygons are computed by the radiosity method, whereas the contribution from far polygons is estimated by a multi-layer model. The main part of computing time corresponds to the calculations of the geometric coefficients of the radiosity system. Then radiative exchanges can be quickly simulated for various conditions of the angular distribution of incoming light and various optical properties of soil and phytolelements. Simulations compare satisfactorily with those produced by a Monte Carlo ray tracing. They show that considering explicitly the close neighboring of each polygon improves the estimation of organs irradiance, by taking into account the local variability of fluxes. For a virtual maize canopy, these estimations are satisfying with Ds=0.5 m; in these conditions, the simulation time on a workstation was 25 min for a canopy of 100 plants.""") roa.store_description(descr) ROLink.connect(session, roc.id, roa.id, "contains") ROLink.connect(session, ro3.id, roa.id, "use")
def search(session, params): """Perform a query for RO objects Args: session (DBSession): params (dict): extra parameters for search Returns: (list of str): list of ids of RO matching query """ # query on RO direct common attributes query = session.query(ResearchObject.id) if "type" in params and params['type'] != 'ro': query = query.filter(ResearchObject.type == params["type"]) if "owner" in params: query = query.filter(ResearchObject.owner == params["owner"]) if "name" in params: name = params['name'] if name[-1] == "*": name = name[:-1] query = query.filter(ResearchObject.name.like("%s%%" % name)) else: query = query.filter(ResearchObject.name == name) # query = query.order_by(ResearchObject.name) uids = {uid for uid, in query.all()} # query on type of link if 'in' in params: # search all RO in a specific container uid = params['in'] query = session.query(ROLink.target) query = query.filter(ROLink.source == uid, ROLink.type == 'contains') uids &= {uid for uid, in query.all()} if 'use' in params: # search all RO that use a specific id uid = params['use'] query = session.query(ROLink.source) query = query.filter(ROLink.target == uid, ROLink.type == 'use') uids &= {uid for uid, in query.all()} # specific query by type if "type" in params: typ = params['type'] if typ in search_factory: loc_uids = search_factory[typ](session, params) if loc_uids is not None: uids &= loc_uids # fetch ROs res = [ResearchObject.get(session, uid) for uid in uids] # high level python expressed query if "toplevel" in params: res = [ro for ro in res if ro.is_lonely()] # sort by name res = sorted([(ro.name, ro) for ro in res]) return [ro for name, ro in res]