Skip to content

Commit

Permalink
Merge pull request #21 from Sage-Bionetworks/update-openapi
Browse files Browse the repository at this point in the history
Update OpenAPI spec. Fixes #17. Will address other updates to Python to match spec in PR for #20.
  • Loading branch information
jaeddy committed Jul 2, 2019
2 parents faef8d0 + b910be5 commit 12a9a12
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 564 deletions.
127 changes: 19 additions & 108 deletions synprov/controllers/activities_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import six
import uuid
import humps
import json

from py2neo import Graph, Node, NodeMatcher

from synprov.config import neomod
from synprov.graphmodels import Activity, Reference, Agent
from synprov.util import neo4j_to_d3


graph = Graph(neomod.neo.db.url)
Expand All @@ -22,122 +24,31 @@ def create_activity(body): # noqa: E501
:rtype: Activity
"""
act = Activity(**humps.decamelize(body))
act.save()
# act = Activity(**humps.decamelize(body))
# act.save()

return act.node


def delete_activity(id): # noqa: E501
"""Delete an.
Delete an Activity # noqa: E501
:param id: The id of activity to delete.
:type id: str
:rtype: file
"""
# return act.node
return 'Not Implemented', 501


def get_activity(id): # noqa: E501
"""Get an existing.
Get an existing Activity # noqa: E501
:param id: The ID of the activity to fetch.
:type id: str
:rtype: Activity
"""
matcher = NodeMatcher(graph)
activity = matcher.match('Activity',
activity_id={id}).first()
return activity


def get_activity_used(id): # noqa: E501
"""Get used by an existing.
Get entities used by an existing Activity # noqa: E501
:param id: The ID of the activity to fetch.
:type id: str
:rtype: List[Reference]
"""
used = graph.run(
'''
MATCH (refs)<-[:USED]-(a:Activity {activity_id: {a_id}})
RETURN refs
''',
a_id=id
)
return [r['refs'] for r in used.data()]


def get_activity_generated(id): # noqa: E501
"""Get generated by an existing.
def get_activities_graph(limit=20): # noqa: E501
"""Get provenance graph
Get entities generated by an existing Activity # noqa: E501
Retrieve all nodes and relationships in the graph that pass filters. # noqa: E501
:param id: The ID of the activity to fetch.
:type id: str
:param limit: maximum number of nodes to return
:type limit: int
:rtype: List[Reference]
:rtype: D3Graph
"""
generated = graph.run(
# TODO: with the current query, the 'limit' parameter applies
# to relationships, not really to nodes
results = graph.run(
'''
MATCH (refs)-[:WASGENERATEDBY]->(a:Activity {activity_id: {a_id}})
RETURN refs
MATCH (s)-[r]-(t)
RETURN s as source, r as relationship, t as target
LIMIT {limit}
''',
a_id=id
limit=limit
)
return [r['refs'] for r in generated.data()]


def get_activity_agents(id): # noqa: E501
"""Get agents for an existing.
Get agents associated with an existing Activity # noqa: E501
:param id: The ID of the activity to fetch.
:type id: str
:rtype: List[Agent]
"""
agents = graph.run(
'''
MATCH (agts)<-[:WASASSOCIATEDWITH]->(a:Activity {activity_id: {a_id}})
RETURN agts
''',
a_id=id
)
return [r['agts'] for r in agents.data()]


def list_activities(): # noqa: E501
""".
List Activities # noqa: E501
:rtype: List[Activity]
"""
return 'Not Implemented', 501


def update_activity(id, body=None): # noqa: E501
"""Update an.
Update an Activity # noqa: E501
:param id: The id of the activity to update.
:type id: str
:param body: Update an Activity
:type body: dict | bytes
:rtype: Activity
"""
return 'Not Implemented', 501
return neo4j_to_d3(results.data())
21 changes: 5 additions & 16 deletions synprov/controllers/agents_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,14 @@
graph = Graph(neomod.neo.db.url)


def get_agent(id): # noqa: E501
"""Get an existing.
def get_agent_subgraph(id): # noqa: E501
"""Get subgraph connected to an agent.
Get an existing Agent # noqa: E501
Retrieve all nodes and relationships in the graph that pass filters. # noqa: E501
:param id: The ID of the agent to fetch.
:type id: str
:rtype: Agent
:rtype: Graph
"""
return 'do some magic!'


def list_agents(): # noqa: E501
""".
List Agents # noqa: E501
:rtype: List[Agent]
"""
return 'do some magic!'
return 'Not Implemented', 501
21 changes: 5 additions & 16 deletions synprov/controllers/references_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,14 @@
graph = Graph(neomod.neo.db.url)


def get_reference(id): # noqa: E501
"""Get an existing.
def get_reference_subgraph(id): # noqa: E501
"""Get subgraph connected to an entity.
Get an existing Reference # noqa: E501
Retrieve the nodes and relationships in a neighborhood around a specified entity. # noqa: E501
:param id: The ID of the entity to fetch.
:type id: str
:rtype: Reference
:rtype: Graph
"""
return 'do some magic!'


def list_references(): # noqa: E501
""".
List References # noqa: E501
:rtype: List[Reference]
"""
return 'do some magic!'
return 'Not Implemented', 501
46 changes: 0 additions & 46 deletions synprov/database.py

This file was deleted.

78 changes: 0 additions & 78 deletions synprov/models.py

This file was deleted.

0 comments on commit 12a9a12

Please sign in to comment.