Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
568 commits
Select commit Hold shift + click to select a range
47598a2
Addressing @ElDeveloper comments
josenavas Mar 12, 2016
5be562a
Merge branch 'artifact-study-pages-artifact-creation' into artifact-s…
josenavas Mar 12, 2016
e7591f4
Pep8ing
josenavas Mar 12, 2016
fa10ecc
Modifying database
josenavas Mar 13, 2016
4c05c38
Fixing type
josenavas Mar 13, 2016
d5aa103
Forking off the QiitaClient as it's own 'project' and update the targ…
josenavas Mar 13, 2016
d68049c
Merge branch 'artifact-study-page-qiita-client-package' into artifact…
josenavas Mar 13, 2016
1279ed5
Fixing setup.py
josenavas Mar 13, 2016
7c3135b
Merge branch 'artifact-study-page-qiita-client-package' into artifact…
josenavas Mar 13, 2016
ca52a5b
Adding type propery to software
josenavas Mar 14, 2016
0afb571
Adapting the job complete function to the type plugins
josenavas Mar 14, 2016
ccc1e8f
Cleaning env
josenavas Mar 14, 2016
ef83464
Merge pull request #1680 from josenavas/artifact-study-pages-artifact…
ElDeveloper Mar 14, 2016
990dc14
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 14, 2016
6347d21
initial commit
antgonza Mar 14, 2016
4d153e4
Limiting new user defined terms to alphanumeric + space
josenavas Mar 14, 2016
6f86470
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 14, 2016
1c4c347
Merge branch 'artifact-study-pages-prep-artifact-integration' into ar…
josenavas Mar 14, 2016
efe3415
Merge branch 'artifact-study-pages-prep-artifact-integration' into ar…
josenavas Mar 14, 2016
39c36ba
Merge branch 'artifact-study-page-qiita-client-package' into artifact…
josenavas Mar 14, 2016
4b3f9ce
Creating the biom type plugin and stubbing out the html summary gener…
josenavas Mar 14, 2016
2838e2e
Merge pull request #1684 from antgonza/fix-patch-37
ElDeveloper Mar 14, 2016
01a3ad3
Fixing typo
josenavas Mar 15, 2016
28bb3f9
Adding target gene type plugin
josenavas Mar 15, 2016
aefb908
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 15, 2016
8ea2653
Addressing @ElDeveloper's comments
josenavas Mar 15, 2016
4b2454d
Merge upstream/artifact-study-pages
josenavas Mar 15, 2016
f28f331
Merge pull request #1683 from josenavas/artifact-study-pages-prep-art…
ElDeveloper Mar 15, 2016
f35fcf0
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 15, 2016
4b22aa4
Fixing travis to install the qiita_client
josenavas Mar 15, 2016
d8bf07f
Fixing setup typo
josenavas Mar 15, 2016
fce4c30
Addressing @mortonjt's comment
josenavas Mar 15, 2016
9c97f59
Merge pull request #1685 from josenavas/artifact-study-page-qiita-cli…
antgonza Mar 15, 2016
8503746
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 15, 2016
8eaf5dd
Addressing @antgonza's comments
josenavas Mar 16, 2016
4c84a90
Merge branch 'artifact-study-pages-type-plugins-biom' of https://gith…
antgonza Mar 16, 2016
50a0eb3
Addressing @ElDeveloper's comments
josenavas Mar 16, 2016
2ee35d7
Adding patch method to the QiitaClient
josenavas Mar 16, 2016
6bfd6e2
Fixing docs
josenavas Mar 16, 2016
73cfbd4
Fixing tests due to nomenclature change
josenavas Mar 17, 2016
2379862
Merge pull request #1686 from josenavas/artifact-study-pages-type-plu…
antgonza Mar 17, 2016
0b220dc
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 17, 2016
0bd7d0f
Modify retrieve_filepaths to add an extra parameter 'fp_type'
josenavas Mar 17, 2016
ff3e2fb
Adding artifact.html_summary_fp property
josenavas Mar 17, 2016
7bb82e0
Adding html summary setter
josenavas Mar 17, 2016
d73f43b
Merge pull request #1692 from josenavas/artifact-study-pages-qiita-cl…
antgonza Mar 17, 2016
48238d9
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 17, 2016
2cc5459
Adding html_summary_fp to filepath_type table
josenavas Mar 17, 2016
a55379f
Adding patch method to the ArtifactFilepathsHandler
josenavas Mar 17, 2016
c289715
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 17, 2016
302e0b5
Addressing @antgonza's comment and adding a test
josenavas Mar 17, 2016
221894b
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 17, 2016
7a18077
initial commit
antgonza Mar 17, 2016
3cdd107
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 17, 2016
d67a3ab
Addressing @wasade's comments
josenavas Mar 18, 2016
9c99068
Doing small modifications in the patch due to the method name change
josenavas Mar 18, 2016
78c7ea0
Merge pull request #1687 from josenavas/artifact-study-pages-type-plu…
antgonza Mar 18, 2016
a6d9fed
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 18, 2016
72f863a
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 18, 2016
7d2b4c8
Fixing failing test
josenavas Mar 18, 2016
4f1d9fd
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 18, 2016
02e3644
Adapting the plugin to the new nomenclature
josenavas Mar 18, 2016
4eb0221
Fixing bug and adding test
josenavas Mar 19, 2016
c9db473
Finishing up validation
josenavas Mar 19, 2016
69b1c66
Adding one more test
josenavas Mar 19, 2016
7ddb855
addressing @josenavas comments
antgonza Mar 19, 2016
447e5ef
fixing flake8
antgonza Mar 19, 2016
ee31795
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 19, 2016
61e159c
Merge branch 'artifact-study-pages-type-plugins-tgene' of https://git…
antgonza Mar 19, 2016
191da2c
initial commit
antgonza Mar 20, 2016
af371b0
Merge branch 'artifact-study-pages-adding-biom' into artifact-study-p…
josenavas Mar 20, 2016
3a0eb6e
Merge branch 'artifact-study-pages-type-plugins-tgene' into artifact-…
josenavas Mar 20, 2016
8b0d578
Merge branch 'artifact-study-pages-type-plugins-tgene-summaries' into…
josenavas Mar 20, 2016
4f61979
adding demux summary
antgonza Mar 20, 2016
7b19ea9
Addressing comments
josenavas Mar 21, 2016
2f6fa27
Merge pull request #1694 from josenavas/artifact-study-pages-patch-fi…
antgonza Mar 21, 2016
2823205
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 21, 2016
afc250b
adding get_html_generator classmethod to command
josenavas Mar 21, 2016
419cd21
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 21, 2016
1ba7fbc
Adding artifact_summary_get_request and tests
josenavas Mar 21, 2016
6aee0d5
addressing @ElDeveloper comments
antgonza Mar 21, 2016
903f2e0
Change scripts permissions
josenavas Mar 21, 2016
322c84c
Fixing bug on qiita-plugin-launcher that prevented to log an error on…
josenavas Mar 21, 2016
953e862
Adding artifact_summary_post_request and tests
josenavas Mar 21, 2016
9ba931f
Adding minimal Artifact summary interface
josenavas Mar 21, 2016
1147180
Merge pull request #1696 from antgonza/artifact-study-pages-adding-biom
ElDeveloper Mar 21, 2016
9c5516f
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 21, 2016
b2addd2
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 22, 2016
c119b16
Fixing returns to be the object payload
josenavas Mar 22, 2016
d818a8b
Making the call to generate the artifact
josenavas Mar 22, 2016
e04f478
Fixing return payload
josenavas Mar 22, 2016
b8817c6
doing something with the post output
josenavas Mar 22, 2016
1abf01e
Adding visibility
josenavas Mar 22, 2016
e783180
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 22, 2016
286fd7e
Addressing comments
josenavas Mar 22, 2016
b69fe48
Merge pull request #1697 from josenavas/artifact-study-pages-type-plu…
antgonza Mar 22, 2016
c8c1fbd
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 22, 2016
04e7769
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 22, 2016
96f36d4
addressing @josenavas and @ElDeveloper comments
antgonza Mar 22, 2016
19181de
adding labels, RE: @ElDeveloper
antgonza Mar 22, 2016
b957d4a
Connecting artifact summary with processing
josenavas Mar 22, 2016
47fc001
Merge pull request #1698 from antgonza/artifact-study-pages-type-plug…
josenavas Mar 22, 2016
fa73eb1
displaying processing graph
josenavas Mar 23, 2016
225d9b2
Adding classmethod to command to retrieve commands that process given…
josenavas Mar 23, 2016
4043e9a
Adding outputs property to commands
josenavas Mar 23, 2016
c83d40c
Retrieving correct commands
josenavas Mar 23, 2016
35ddff3
Solgin merge conflicts
josenavas Mar 23, 2016
14aff19
Changin button styles - thanks @ElDeveloper
josenavas Mar 23, 2016
05de2db
Adding comments
josenavas Mar 23, 2016
a81f6a0
changing to **res
josenavas Mar 23, 2016
ce8725c
Removing console.log calls
josenavas Mar 23, 2016
8984c28
Adding list_options_handler_get_req
josenavas Mar 23, 2016
964952a
Forgot to change __init__.py
josenavas Mar 23, 2016
37711a4
Merge branch 'artifact-study-pages-type-plugins-connections' into art…
josenavas Mar 23, 2016
6f42168
for to list comp
josenavas Mar 23, 2016
6015a8c
Adding better way to choose parameters
josenavas Mar 23, 2016
d8db841
Merge pull request #1702 from josenavas/artifact-study-pages-type-plu…
ElDeveloper Mar 23, 2016
a0cb72e
Finishing up load artifact type gui
josenavas Mar 23, 2016
30c578d
Adding workflow_handler_post_req
josenavas Mar 23, 2016
d82c901
Adding type information to the required parameters
josenavas Mar 23, 2016
555156b
Adding required options to the returne objs
josenavas Mar 24, 2016
8f62384
Adding handler for creating a workflow
josenavas Mar 24, 2016
542fe6d
Adding endpoint to create the workflow
josenavas Mar 24, 2016
e398d9c
Completing workflow creation
josenavas Mar 24, 2016
946aef3
Adding patch request to the workflow
josenavas Mar 24, 2016
c360729
Finishing up interface for adding commands
josenavas Mar 24, 2016
a9b8822
Fixing add function in workflow to be able to add a new root job
josenavas Mar 24, 2016
050c1f4
Fixing patch call
josenavas Mar 24, 2016
5725b2e
Fixing a test
josenavas Mar 24, 2016
0dff918
Update JS to successfully be able to add any job
josenavas Mar 24, 2016
ba7ba48
Initial hook-yp to retrieve job info
josenavas Mar 24, 2016
61e5950
Showing processing job information
josenavas Mar 24, 2016
30987c9
Adding test
josenavas Mar 24, 2016
50e1507
Improving documentation
josenavas Mar 24, 2016
14e39cd
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 24, 2016
5207d8c
Hooking up workflow submission
josenavas Mar 24, 2016
f01a357
Allowing cascade removal
josenavas Mar 24, 2016
5c238bc
Hooking up interface and backend
josenavas Mar 24, 2016
5e40cd8
Updating the GUI accordingly after removal
josenavas Mar 24, 2016
dd69406
Fix submission enabling/disabling
josenavas Mar 24, 2016
1119fd6
Addressing @antgonza's comments
josenavas Mar 24, 2016
936098c
Adding JS docs
josenavas Mar 24, 2016
0e0866b
Fixing small bug
josenavas Mar 24, 2016
7f148fe
Show running jobs in the artifact page
josenavas Mar 24, 2016
50504b4
Fixing test
josenavas Mar 24, 2016
3958298
Addressing @antgonza's comments
josenavas Mar 24, 2016
b5686b5
setting not null property later so we can apply the patch
josenavas Mar 24, 2016
80be11e
Fixing bug in patch - and adding test to catch the bug
josenavas Mar 24, 2016
9f53e01
Adding missing var
josenavas Mar 24, 2016
246f619
Adding more missing vars
josenavas Mar 24, 2016
2fd8740
Addressing @ElDeveloper's comments
josenavas Mar 24, 2016
447e7ba
Merge pull request #1707 from josenavas/artifact-study-pages-fix-patches
antgonza Mar 25, 2016
898ffab
Merge pull request #1705 from josenavas/artifact-study-pages-type-plu…
antgonza Mar 25, 2016
22c5743
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 25, 2016
b7aeaa1
Merge pull request #1706 from josenavas/artifact-study-pages-show-procs
antgonza Mar 25, 2016
a6067ee
Making lab person optional
josenavas Mar 25, 2016
0f6d37f
Updating job status at submission
josenavas Mar 25, 2016
e3673e5
Adding download buttons
josenavas Mar 25, 2016
cc70ae3
Fixing tests
josenavas Mar 25, 2016
dbfe1c9
Merge pull request #1708 from josenavas/artifact-study-pages-opt-lab-…
antgonza Mar 25, 2016
f175495
Limiting study edit access to admin, owner and shared users
josenavas Mar 25, 2016
fcde985
Solving merge conflicts - ouch
josenavas Mar 25, 2016
0298f10
Create can_edit function in study so we can re-use
josenavas Mar 25, 2016
00de78d
Limiting edit permissions in the prep template summary
josenavas Mar 25, 2016
2cacd69
Merge pull request #1710 from josenavas/artifact-study-pages-download…
antgonza Mar 25, 2016
07aabe2
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 25, 2016
853acab
Limiting edition privileges in the artifact summary
josenavas Mar 25, 2016
7b02f76
Limit pt visibility for public studies
josenavas Mar 25, 2016
fa9130d
Adding a test
josenavas Mar 25, 2016
017fd89
Propagating the visibility up the parents
josenavas Mar 26, 2016
835fd2a
Filtering graph for public only
josenavas Mar 26, 2016
037e567
Refactoring the sample summary page and limiting edition privileges
josenavas Mar 26, 2016
dc80314
Fixing graph generation
josenavas Mar 26, 2016
61d1e2b
Merge pull request #1711 from josenavas/artifact-study-pages-limit-ac…
antgonza Mar 26, 2016
fac9d70
Addig the data type on the prep template summary
josenavas Mar 26, 2016
a5f6702
Changing default name in the artifact
josenavas Mar 26, 2016
21706e0
Moving edit and delete study to the study information page
josenavas Mar 26, 2016
6f5cdfb
Asking for the title instead of the alias when deleting and improving…
josenavas Mar 26, 2016
c179b68
Adding message when no prep templates has been added, instead of the …
josenavas Mar 26, 2016
23bf2ef
Redirecting to the study listing page when deleting a study
josenavas Mar 26, 2016
1587098
Showing the sample summary link only if there is a sample template fo…
josenavas Mar 26, 2016
fc57793
Fixing bug in default value
josenavas Mar 26, 2016
28554d8
Fix bug preventing to upload a qiime mapping file
josenavas Mar 26, 2016
6798c1e
Disable button if file is not selected
josenavas Mar 26, 2016
49f858f
In the edit page, it was assume that lab person existed
josenavas Mar 26, 2016
6effa7c
Redirecting once the workflow is submitted
josenavas Mar 26, 2016
e1173e2
Merge pull request #1712 from josenavas/artifact-study-pages-misc
antgonza Mar 26, 2016
f9aa2a7
Asking for confirmation before deleting a sample template
josenavas Mar 26, 2016
5820b44
Removing boostrap alert timeout
josenavas Mar 26, 2016
6467a4d
Fixing interface to show/hide the sample summary button accordingly
josenavas Mar 26, 2016
fb569bb
Not showing jobs completed succesfully and showing the error message …
josenavas Mar 26, 2016
0f76906
Merge pull request #1713 from josenavas/artifact-study-pages-misc2
antgonza Mar 26, 2016
f2aa041
Fixing artifact tests
josenavas Mar 26, 2016
4e054f1
Fixing prep template tests
josenavas Mar 26, 2016
6ee1f68
Fixing test processing
josenavas Mar 26, 2016
4a6dd5e
Fixing handler tests
josenavas Mar 26, 2016
1f9dccc
fixing prep template handlers tests
josenavas Mar 26, 2016
6dd28b0
Fixing search tests
josenavas Mar 26, 2016
bed50a4
Fixing software tests
josenavas Mar 26, 2016
6be4450
Fixing test study
josenavas Mar 26, 2016
ce64620
Adding patch operation to the artifact handler
josenavas Mar 26, 2016
4150efc
fixing API
josenavas Mar 26, 2016
9351dbb
Enabling user to change the artifact name
josenavas Mar 27, 2016
203b8ba
Changing buttons color
josenavas Mar 27, 2016
d724dfd
Show the add prep menu item only if there is a sample template added
josenavas Mar 27, 2016
dcb4a51
Merge pull request #1714 from josenavas/artifact-study-pages-assert-i…
antgonza Mar 27, 2016
3277917
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 27, 2016
25891f8
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 27, 2016
9cec1f2
Addressing @antgonza
josenavas Mar 28, 2016
7014f68
Merge branch 'artifact-study-pages-rename-artifacts' into artifact-st…
josenavas Mar 28, 2016
df9ddec
Merge pull request #1715 from josenavas/artifact-study-pages-rename-a…
antgonza Mar 28, 2016
6aed1f3
Adding user artifacts method to the user object
josenavas Mar 28, 2016
d92f4ba
Allow importing artifacts from other studies
josenavas Mar 28, 2016
8365dce
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 28, 2016
9325676
Addressing @ElDeveloper's and @antgonza's comments
josenavas Mar 29, 2016
94017de
initial commit
antgonza Mar 29, 2016
00d110a
Addressing failing test
josenavas Mar 29, 2016
588f63c
Merge pull request #1716 from josenavas/artifact-study-pages-import-a…
antgonza Mar 29, 2016
8664d43
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 29, 2016
2d21661
adding code to tgz
antgonza Mar 29, 2016
684c503
fix #1132, fix #877, fix #16
antgonza Mar 29, 2016
2797a55
Adding safe_submit
josenavas Mar 29, 2016
5175cf7
Offloading sample template processing from the server
josenavas Mar 29, 2016
1057a5e
fixing error
antgonza Mar 30, 2016
3f08333
Offloading prep template update
josenavas Mar 30, 2016
a94d35f
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 30, 2016
eb34439
Fixing sample template tests
josenavas Mar 30, 2016
5906c98
Fixin prep template tests
josenavas Mar 30, 2016
f017c03
Adding qiita ware tests
josenavas Mar 30, 2016
ddd16ae
Fixing race condition errors
josenavas Mar 30, 2016
873624a
Addressing @antgonza's comments
josenavas Mar 30, 2016
0ce37cc
Adding missing comment
josenavas Mar 30, 2016
6d8674a
addressing @josenavas comments
antgonza Mar 30, 2016
249e402
initial commit
antgonza Mar 30, 2016
a630f33
fixing error
antgonza Mar 30, 2016
ace249a
addressing @ElDeveloper comments
antgonza Mar 30, 2016
6dcbd5b
fixing conflicts
antgonza Mar 30, 2016
5cc2d7a
Addressing @ElDeveloper's comments
josenavas Mar 30, 2016
0ea7c56
Merge pull request #1718 from antgonza/downlaod-tgz
josenavas Mar 30, 2016
2ca44cc
Merge pull request #1720 from josenavas/artifact-study-pages-offload-…
antgonza Mar 30, 2016
1ee4399
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 30, 2016
df9e788
Merge pull request #1721 from antgonza/reducing-patches
josenavas Mar 30, 2016
0a38725
rm 40.py
antgonza Mar 30, 2016
26642f5
Merge pull request #1722 from antgonza/removing-40
josenavas Mar 30, 2016
5a23f64
Limit download of raw data
josenavas Mar 30, 2016
16dfc37
Removing directory form the list of files to download
josenavas Mar 30, 2016
b751301
Addressing @ElDeveloper's comments
josenavas Mar 31, 2016
ebfad82
Merge pull request #1725 from josenavas/download-raw-only-owner
antgonza Mar 31, 2016
2edca30
Disabling sorting and reducing font
josenavas Mar 31, 2016
486a63f
Merge pull request #1726 from josenavas/artifact-study-pages-summary
antgonza Mar 31, 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
34 changes: 21 additions & 13 deletions qiita_db/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,33 +952,41 @@ def ebi_submission_status(self, value):
ebi_submission_status.__doc__.format(', '.join(_VALID_EBI_STATUS))

# --- methods ---
def artifacts(self, dtype=None):
def artifacts(self, dtype=None, artifact_type=None):
"""Returns the list of artifacts associated with the study

Parameters
----------
dtype : str, optional
If given, retrieve only artifacts for given data type. Default,
return all artifacts associated with the study.
artifact_type : str, optional
If given, retrieve only artifacts of given data type. Default,
return all artifacts associated with the study

Returns
-------
list of qiita_db.artifact.Artifact
"""
with qdb.sql_connection.TRN:
sql_args = [self._id]
sql_where = ""
if dtype:
sql = """SELECT artifact_id
FROM qiita.artifact
JOIN qiita.data_type USING (data_type_id)
JOIN qiita.study_artifact USING (artifact_id)
WHERE study_id = %s AND data_type = %s"""
sql_args = [self._id, dtype]
else:
sql = """SELECT artifact_id
FROM qiita.artifact
JOIN qiita.study_artifact USING (artifact_id)
WHERE study_id = %s"""
sql_args = [self._id]
sql_args.append(dtype)
sql_where = " AND data_type = %s"

if artifact_type:
sql_args.append(artifact_type)
sql_where += "AND artifact_type = %s"

sql = """SELECT artifact_id
FROM qiita.artifact
JOIN qiita.data_type USING (data_type_id)
JOIN qiita.study_artifact USING (artifact_id)
JOIN qiita.artifact_type USING (artifact_type_id)
WHERE study_id = %s{0}
ORDER BY artifact_id""".format(sql_where)

qdb.sql_connection.TRN.add(sql, sql_args)
return [qdb.artifact.Artifact(aid)
for aid in qdb.sql_connection.TRN.execute_fetchflatten()]
Expand Down
10 changes: 10 additions & 0 deletions qiita_db/test/test_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,16 @@ def test_retrieve_artifacts(self):
self.assertEqual(self.study.artifacts(dtype="16S"), [exp[-1]])
self.assertEqual(self.study.artifacts(dtype="18S"), exp[:-1])

self.assertEqual(self.study.artifacts(artifact_type="BIOM"),
[qdb.artifact.Artifact(4),
qdb.artifact.Artifact(5),
qdb.artifact.Artifact(6)])

self.assertEqual(self.study.artifacts(dtype="18S",
artifact_type="BIOM"),
[qdb.artifact.Artifact(4),
qdb.artifact.Artifact(5)])

def test_retrieve_artifacts_none(self):
new = qdb.study.Study.create(
qdb.user.User('test@foo.bar'),
Expand Down
16 changes: 16 additions & 0 deletions qiita_db/test/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,5 +418,21 @@ def test_delete_messages(self):
obs = self.conn_handler.execute_fetchall(sql)
self.assertItemsEqual(obs, [[1], [3]])

def test_user_artifacts(self):
user = qdb.user.User('test@foo.bar')
obs = user.user_artifacts()
exp = {qdb.study.Study(1): [qdb.artifact.Artifact(1),
qdb.artifact.Artifact(2),
qdb.artifact.Artifact(3),
qdb.artifact.Artifact(4),
qdb.artifact.Artifact(5),
qdb.artifact.Artifact(6)]}
self.assertEqual(obs, exp)
obs = user.user_artifacts(artifact_type='BIOM')
exp = {qdb.study.Study(1): [qdb.artifact.Artifact(4),
qdb.artifact.Artifact(5),
qdb.artifact.Artifact(6)]}
self.assertEqual(obs, exp)

if __name__ == "__main__":
main()
42 changes: 42 additions & 0 deletions qiita_db/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from re import sub
from datetime import datetime

from future.utils import viewitems

from qiita_core.exceptions import (IncorrectEmailError, IncorrectPasswordError,
IncompetentQiitaDeveloperError)
from qiita_core.qiita_settings import qiita_config
Expand Down Expand Up @@ -475,6 +477,46 @@ def unread_messages(self):
return qdb.sql_connection.TRN.execute_fetchindex()

# ------- methods ---------
def user_artifacts(self, artifact_type=None):
"""Returns the artifacts owned by the user, grouped by study

Parameters
----------
artifact_type : str, optional
The artifact type to retrieve. Default: retrieve all artfact types

Returns
-------
dict of {qiita_db.study.Study: list of qiita_db.artifact.Artifact}
The artifacts owned by the user
"""
with qdb.sql_connection.TRN:
sql_args = [self.id, qiita_config.portal]
sql_a_type = ""
if artifact_type:
sql_a_type = " AND artifact_type = %s"
sql_args.append(artifact_type)

sql = """SELECT study_id, array_agg(
artifact_id ORDER BY artifact_id)
FROM qiita.study
JOIN qiita.study_portal USING (study_id)
JOIN qiita.portal_type USING (portal_type_id)
JOIN qiita.study_artifact USING (study_id)
JOIN qiita.artifact USING (artifact_id)
JOIN qiita.artifact_type USING (artifact_type_id)
WHERE email = %s AND portal = %s{0}
GROUP BY study_id
ORDER BY study_id""".format(sql_a_type)
qdb.sql_connection.TRN.add(sql, sql_args)
db_res = dict(qdb.sql_connection.TRN.execute_fetchindex())
res = {}
for s_id, artifact_ids in viewitems(db_res):
res[qdb.study.Study(s_id)] = [
qdb.artifact.Artifact(a_id) for a_id in artifact_ids]

return res

def change_password(self, oldpass, newpass):
"""Changes the password from oldpass to newpass

Expand Down
86 changes: 51 additions & 35 deletions qiita_pet/handlers/api_proxy/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def artifact_get_req(user_id, artifact_id):

@execute_as_transaction
def artifact_post_req(user_id, filepaths, artifact_type, name,
prep_template_id):
prep_template_id, artifact_id=None):
"""Creates the initial artifact for the prep template

Parameters
Expand All @@ -250,6 +250,8 @@ def artifact_post_req(user_id, filepaths, artifact_type, name,
Name to give the artifact
prep_template_id : int or str castable to int
Prep template to attach the artifact to
artifact_id : int or str castable to int, optional
The id of the imported artifact

Returns
-------
Expand All @@ -267,41 +269,55 @@ def artifact_post_req(user_id, filepaths, artifact_type, name,
if access_error:
return access_error

uploads_path = get_mountpoint('uploads')[0][1]
path_builder = partial(join, uploads_path, str(study_id))
cleaned_filepaths = []
for ftype, file_list in viewitems(filepaths):
# JavaScript sends us this list as a comma-separated list
for fp in file_list.split(','):
# JavaScript will send this value as an empty string if the
# list of files was empty. In such case, the split will generate
# a single element containing the empty string. Check for that case
# here and, if fp is not the empty string, proceed to check if
# the file exists
if fp:
# Check if filepath being passed exists for study
full_fp = path_builder(fp)
exists = check_fp(study_id, full_fp)
if exists['status'] != 'success':
return {'status': 'error',
'message': 'File does not exist: %s' % fp}
cleaned_filepaths.append((full_fp, ftype))

# This should never happen, but it doesn't hurt to actually have
# a explicit check, in case there is something odd with the JS
if not cleaned_filepaths:
return {'status': 'error',
'message': "Can't create artifact, no files provided."}
if artifact_id:
# if the artifact id has been provided, import the artifact
try:
artifact = Artifact.copy(Artifact(artifact_id), prep)
except Exception as e:
# We should hit this exception rarely (that's why it is an
# exception) since at this point we have done multiple checks.
# However, it can occur in weird cases, so better let the GUI know
# that this failed
return {'status': 'error',
'message': "Error creating artifact: %s" % str(e)}

try:
artifact = Artifact.create(cleaned_filepaths, artifact_type, name=name,
prep_template=prep)
except Exception as e:
# We should hit this exception rarely (that's why it is an exception)
# since at this point we have done multiple checks. However, it can
# occur in weird cases, so better let the GUI know that this failed
return {'status': 'error',
'message': "Error creating artifact: %s" % str(e)}
else:
uploads_path = get_mountpoint('uploads')[0][1]
path_builder = partial(join, uploads_path, str(study_id))
cleaned_filepaths = []
for ftype, file_list in viewitems(filepaths):
# JavaScript sends us this list as a comma-separated list
for fp in file_list.split(','):
# JavaScript will send this value as an empty string if the
# list of files was empty. In such case, the split will
# generate a single element containing the empty string. Check
# for that case here and, if fp is not the empty string,
# proceed to check if the file exists
if fp:
# Check if filepath being passed exists for study
full_fp = path_builder(fp)
exists = check_fp(study_id, full_fp)
if exists['status'] != 'success':
return {'status': 'error',
'message': 'File does not exist: %s' % fp}
cleaned_filepaths.append((full_fp, ftype))

# This should never happen, but it doesn't hurt to actually have
# a explicit check, in case there is something odd with the JS
if not cleaned_filepaths:
return {'status': 'error',
'message': "Can't create artifact, no files provided."}

try:
artifact = Artifact.create(cleaned_filepaths, artifact_type,
name=name, prep_template=prep)
except Exception as e:
# We should hit this exception rarely (that's why it is an
# exception) since at this point we have done multiple checks.
# However, it can occur in weird cases, so better let the GUI know
# that this failed
return {'status': 'error',
'message': "Error creating artifact: %s" % str(e)}

return {'status': 'success',
'message': '',
Expand Down
23 changes: 21 additions & 2 deletions qiita_pet/handlers/api_proxy/studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from __future__ import division
from collections import defaultdict

from future.utils import viewitems

from qiita_db.user import User
from qiita_db.study import Study
from qiita_db.metadata_template.prep_template import PrepTemplate
Expand Down Expand Up @@ -180,7 +182,7 @@ def study_prep_get_req(study_id, user_id):
'info': prep_info}


def study_files_get_req(study_id, prep_template_id, artifact_type):
def study_files_get_req(user_id, study_id, prep_template_id, artifact_type):
"""Returns the uploaded files for the study id categorized by artifact_type

It retrieves the files uploaded for the given study and tries to do a
Expand All @@ -189,6 +191,8 @@ def study_files_get_req(study_id, prep_template_id, artifact_type):

Parameters
----------
user_id : str
The id of the user making the request
study_id : int
The study id
prep_template_id : int
Expand Down Expand Up @@ -242,8 +246,23 @@ def study_files_get_req(study_id, prep_template_id, artifact_type):
# because selected is initialized to the empty list
file_types.insert(0, (first[0], first[1], selected))

# Create a list of artifacts that the user has access to, in case that
# he wants to import the files from another artifact
user = User(user_id)
artifact_options = []
user_artifacts = user.user_artifacts(artifact_type=artifact_type)
study = Study(study_id)
if study not in user_artifacts:
user_artifacts[study] = study.artifacts(artifact_type=artifact_type)
for study, artifacts in viewitems(user_artifacts):
study_label = "%s (%d)" % (study.title, study.id)
for a in artifacts:
artifact_options.append(
(a.id, "%s - %s (%d)" % (study_label, a.name, a.id)))

return {'status': 'success',
'message': '',
'remaining': remaining,
'file_types': file_types,
'num_prefixes': num_prefixes}
'num_prefixes': num_prefixes,
'artifacts': artifact_options}
27 changes: 27 additions & 0 deletions qiita_pet/handlers/api_proxy/tests/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,26 @@ def test_artifact_post_req(self):
a = Artifact(new_artifact_id)
self._files_to_remove.extend([fp for _, fp, _ in a.filepaths])

# Test importing an artifact
# Create new prep template to attach artifact to
pt = npt.assert_warns(
QiitaDBWarning, PrepTemplate.create,
pd.DataFrame({'new_col': {'1.SKD6.640190': 1}}), Study(1), '16S')
self._files_to_remove.extend([fp for _, fp in pt.get_filepaths()])

new_artifact_id_2 = get_count('qiita.artifact') + 1
obs = artifact_post_req(
'test@foo.bar', {}, 'FASTQ', 'New Test Artifact 2', pt.id,
new_artifact_id)
exp = {'status': 'success',
'message': '',
'artifact': new_artifact_id_2}
self.assertEqual(obs, exp)
# Instantiate the artifact to make sure it was made and
# to clean the environment
a = Artifact(new_artifact_id)
self._files_to_remove.extend([fp for _, fp, _ in a.filepaths])

def test_artifact_post_req_error(self):
# Create a new prep template to attach the artifact to
pt = npt.assert_warns(
Expand Down Expand Up @@ -368,6 +388,13 @@ def test_artifact_post_req_error(self):
"has an artifact associated"}
self.assertEqual(obs, exp)

# Exception
obs = artifact_post_req(user_id, {}, artifact_type, name, 1, 1)
exp = {'status': 'error',
'message': "Error creating artifact: Prep template 1 already "
"has an artifact associated"}
self.assertEqual(obs, exp)

def test_artifact_status_put_req(self):
obs = artifact_status_put_req(1, 'test@foo.bar', 'sandbox')
exp = {'status': 'success',
Expand Down
Loading