Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
bd958cf
Fixing the artifact handler
josenavas Apr 15, 2016
039b12e
Fixing docs
josenavas Apr 15, 2016
75510dc
Fixing processing job
josenavas Apr 15, 2016
90bc5d2
Fixing reference
josenavas Apr 15, 2016
8b9662e
Fixing qiita client
josenavas Apr 16, 2016
8bb9e6c
Fixing plugin.py
josenavas Apr 16, 2016
72b7c45
Fixing return
josenavas Apr 16, 2016
58168b8
Merge branch 'fix-rest-api-qiita-client' into fix-rest-api-biom
josenavas Apr 16, 2016
de25c31
Fixing validate
josenavas Apr 16, 2016
211b945
Fixing summary
josenavas Apr 16, 2016
9ddb2fa
Empty commit for doing the PR
josenavas Apr 16, 2016
73dc73f
Fixing failing tests
josenavas Apr 16, 2016
c24e6dd
Merge pull request #1793 from josenavas/fix-rest-api-artifact
ElDeveloper Apr 16, 2016
031def8
Merge branch 'fix-rest-api' of https://github.com/biocore/qiita into …
josenavas Apr 16, 2016
7c798a1
Merge pull request #1794 from josenavas/fix-rest-api-reference
ElDeveloper Apr 17, 2016
89ad399
Merge branch 'fix-rest-api' of https://github.com/biocore/qiita into …
josenavas Apr 17, 2016
3d6937e
Fixing summary.py
josenavas Apr 18, 2016
8b90273
Fixing validate
josenavas Apr 18, 2016
53fe87c
Merge branch 'fix-rest-api' of https://github.com/biocore/qiita into …
josenavas Apr 18, 2016
d1448d3
Updating image
josenavas Apr 18, 2016
5dbb34b
Update image
josenavas Apr 18, 2016
85b30e2
Fix plugin
josenavas Apr 18, 2016
bea1dec
Fixing pick_otus
josenavas Apr 18, 2016
bc6d2f4
Fixing split libraries
josenavas Apr 18, 2016
8f3f87d
fixing util
josenavas Apr 18, 2016
8523047
Merge branch 'fix-rest-api-qiita-client' into fix-rest-api-small-fixes
josenavas Apr 18, 2016
22e298b
Merge branch 'fix-rest-api-biom' into fix-rest-api-small-fixes
josenavas Apr 18, 2016
8a38122
small fixes
josenavas Apr 18, 2016
329a207
Performing the first heartbeat before doing anything else
josenavas Apr 18, 2016
af223ed
Reducing code duplication
josenavas Apr 18, 2016
27e3347
Addressing @ElDeveloper's comments
josenavas Apr 18, 2016
d1a7f43
Merge pull request #1795 from josenavas/fix-rest-api-qiita-client
ElDeveloper Apr 18, 2016
6ea18a4
Merge branch 'fix-rest-api' of https://github.com/biocore/qiita into …
josenavas Apr 18, 2016
8be4fdd
Merge pull request #1796 from josenavas/fix-rest-api-biom
ElDeveloper Apr 19, 2016
14025de
Merge branch 'fix-rest-api' of https://github.com/biocore/qiita into …
josenavas Apr 19, 2016
06bad61
Addressing @ElDeveloper's comments
josenavas Apr 19, 2016
d9d7aa7
Merge pull request #1799 from josenavas/fix-rest-api-target-gene-type
antgonza Apr 19, 2016
d2acb88
Merge branch 'fix-rest-api' of https://github.com/biocore/qiita into …
josenavas Apr 20, 2016
36c0fcd
Merge pull request #1800 from josenavas/fix-rest-api-target-gene
ElDeveloper Apr 20, 2016
cdea44e
Merge branch 'fix-rest-api' of https://github.com/biocore/qiita into …
josenavas Apr 20, 2016
44fcb32
Merge pull request #1801 from josenavas/fix-rest-api-small-fixes
antgonza Apr 21, 2016
1f44364
Fixing merge conflicts
josenavas Apr 21, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 50 additions & 80 deletions qiita_db/handlers/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------

from tornado.web import HTTPError

import qiita_db as qdb
from .oauth2 import OauthBaseHandler, authenticate_oauth

Expand All @@ -20,19 +22,25 @@ def _get_artifact(a_id):

Returns
-------
qiita_db.artifact.Artifact, bool, string
The requested artifact or None
Whether if we could get the artifact or not
Error message in case we couldn't get the artifact
qiita_db.artifact.Artifact
The requested artifact

Raises
------
HTTPError
If the artifact does not exist, with error code 404
If there is a problem instantiating the artifact, with error code 500
"""
try:
a_id = int(a_id)
artifact = qdb.artifact.Artifact(a_id)
except qdb.exceptions.QiitaDBUnknownIDError:
return None, False, 'Artifact does not exist'
except qdb.exceptions.QiitaDBError as e:
return None, False, 'Error instantiating the artifact: %s' % str(e)
raise HTTPError(404)
except Exception as e:
raise HTTPError(500, 'Error instantiating artifact %s: %s'
% (a_id, str(e)))

return artifact, True, ''
return artifact


class ArtifactFilepathsHandler(OauthBaseHandler):
Expand All @@ -49,23 +57,14 @@ def get(self, artifact_id):
Returns
-------
dict
Format:
{'success': bool,
'error': str,
'filepaths': list of (str, str)}
- success: whether the request is successful or not
- error: in case that success is false, it contains the error msg
- filepaths: the filepaths attached to the artifact and their
filepath types
{'filepaths': list of (str, str)}
The filepaths attached to the artifact and their filepath types
"""
with qdb.sql_connection.TRN:
artifact, success, error_msg = _get_artifact(artifact_id)
fps = None
if success:
fps = [(fp, fp_type) for _, fp, fp_type in artifact.filepaths]

response = {'success': success, 'error': error_msg,
'filepaths': fps}
artifact = _get_artifact(artifact_id)
response = {
'filepaths': [(fp, fp_type)
for _, fp, fp_type in artifact.filepaths]}

self.write(response)

Expand All @@ -77,15 +76,6 @@ def patch(self, artifact_id):
---------
artifact_id : str
The id of the artifact whose filepaths information is being updated

Returns
-------
dict
Format:
{'success': bool,
'error': str}
- success: whether the request is successful or not
- error: in case that success is false, it contains the error msg
"""
req_op = self.get_argument('op')
req_path = self.get_argument('path')
Expand All @@ -94,20 +84,18 @@ def patch(self, artifact_id):
if req_op == 'add':
req_path = [v for v in req_path.split('/') if v]
if len(req_path) != 1 or req_path[0] != 'html_summary':
success = False
error_msg = 'Incorrect path parameter value'
raise HTTPError(400, 'Incorrect path parameter value')
else:
artifact, success, error_msg = _get_artifact(artifact_id)
if success:
artifact = _get_artifact(artifact_id)
try:
artifact.html_summary_fp = req_value
except Exception as e:
raise HTTPError(500, str(e))
else:
success = False
error_msg = ('Operation "%s" not supported. Current supported '
'operations: add' % req_op)
raise HTTPError(400, 'Operation "%s" not supported. Current '
'supported operations: add' % req_op)

response = {'success': success, 'error': error_msg}

self.write(response)
self.finish()


class ArtifactMappingHandler(OauthBaseHandler):
Expand All @@ -124,32 +112,24 @@ def get(self, artifact_id):
Returns
-------
dict
Format:
{'success': bool,
'error': str,
'mapping': str}
- success: whether the request is successful or not
- error: in case that success is false, it contains the error msg
- mapping: the filepath to the mapping file
{'mapping': str}
The filepath to the mapping file
"""
with qdb.sql_connection.TRN:
artifact, success, error_msg = _get_artifact(artifact_id)
fp = None
if success:
# In the current system, we don't have any artifact that
# is the result of two other artifacts, and there is no way
# of generating such artifact. This operation will be
# eventually supported, but in interest of time we are not
# going to implement that here.
prep_templates = artifact.prep_templates
if len(prep_templates) > 1:
raise NotImplementedError(
"Artifact %d has more than one prep template")

fp = prep_templates[0].qiime_map_fp

response = {'success': success, 'error': error_msg,
'mapping': fp}
artifact = _get_artifact(artifact_id)
# In the current system, we don't have any artifact that
# is the result of two other artifacts, and there is no way
# of generating such artifact. This operation will be
# eventually supported, but in interest of time we are not
# going to implement that here.
prep_templates = artifact.prep_templates
if len(prep_templates) > 1:
raise NotImplementedError(
"Artifact %d has more than one prep template")

fp = prep_templates[0].qiime_map_fp

response = {'mapping': fp}

self.write(response)

Expand All @@ -167,21 +147,11 @@ def get(self, artifact_id):
Returns
-------
dict
Format:
{'success': bool,
'error': str,
'type': str}
- success: whether the request is successful or not
- error: in case that success is false, it contains the error msg
- type: the artifact type
{'type': str}
The artifact type
"""
with qdb.sql_connection.TRN:
artifact, success, error_msg = _get_artifact(artifact_id)
atype = None
if success:
atype = artifact.artifact_type

response = {'success': success, 'error': error_msg,
'type': atype}
artifact = _get_artifact(artifact_id)
response = {'type': artifact.artifact_type}

self.write(response)
37 changes: 20 additions & 17 deletions qiita_db/handlers/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,27 @@ def write_error(self, status_code, **kwargs):
This function is automatically called by the tornado package on errors,
and should never be called directly.
"""
if status_code in {403, 404, 405}:
# We don't need to log these failues in the logging table
return
# log the error
exc_info = kwargs['exc_info']
trace_info = ''.join(['%s\n' % line for line in
format_exception(*exc_info)])
req_dict = self.request.__dict__
# must trim body to 1024 chars to prevent huge error messages
req_dict['body'] = req_dict.get('body', '')[:1024]
request_info = ''.join(['<strong>%s</strong>: %s\n' %
(k, req_dict[k]) for k in
req_dict.keys() if k != 'files'])
error = exc_info[1]
qdb.logger.LogEntry.create(
'Runtime',
'ERROR:\n%s\nTRACE:\n%s\nHTTP INFO:\n%s\n' %
(error, trace_info, request_info))

# We don't need to log 403, 404 or 405 failures in the logging table
if status_code not in {403, 404, 405}:
# log the error
error_lines = ['%s\n' % line
for line in format_exception(*exc_info)]
trace_info = ''.join(error_lines)
req_dict = self.request.__dict__
# must trim body to 1024 chars to prevent huge error messages
req_dict['body'] = req_dict.get('body', '')[:1024]
request_info = ''.join(['<strong>%s</strong>: %s\n' %
(k, req_dict[k]) for k in
req_dict.keys() if k != 'files'])
error = exc_info[1]
qdb.logger.LogEntry.create(
'Runtime',
'ERROR:\n%s\nTRACE:\n%s\nHTTP INFO:\n%s\n' %
(error, trace_info, request_info))

self.finish(exc_info[1].log_message)

def head(self):
"""Adds proper response for head requests"""
Expand Down
Loading