Skip to content

Commit

Permalink
Object typing fix (#25)
Browse files Browse the repository at this point in the history
Making the metadata engine a little smarter and more forgiving when it comes to object types that it will accept for summarization duties

Fixes #24
  • Loading branch information
kauberry authored and dmlb2000 committed May 6, 2017
1 parent 26356e7 commit f1b517c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions metadata/rest/fileinfo_queries/earliest_latest.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
"""CherryPy File Details object class."""
from cherrypy import tools, HTTPError, request
from metadata.orm import Files, Transactions
from metadata.rest.reporting_queries.query_base import QueryBase
from peewee import fn

# pylint: disable=too-few-public-methods


class EarliestLatestFiles(object):
class EarliestLatestFiles(QueryBase):
"""Retrieves earliest and latest file entries for a set of metadata specifiers."""

exposed = True

@staticmethod
def _get_earliest_latest(item_type, item_list, time_basis):
accepted_item_types = ['proposal', 'submitter', 'instrument']
accepted_item_types = list(
set(QueryBase.object_type_mappings.keys() + QueryBase.object_type_mappings.values())
)
accepted_time_basis_types = [
'submitted', 'modified', 'created',
'submit', 'modified', 'create',
'submit_time', 'modified_time', 'create_time',
'submitted_date', 'modified_date', 'created_date',
]

item_type = QueryBase.object_type_mappings.get(item_type)
time_basis = time_basis.lower()
if item_type not in accepted_item_types or time_basis not in accepted_time_basis_types:
raise HTTPError('400 Invalid Query')
Expand Down
2 changes: 1 addition & 1 deletion metadata/rest/transaction_queries/query_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _get_file_list(transaction_id):
files_list = (Files
.select()
.where(where_clause)
.order_by(Files.subdir, Files.name))
.order_by(Files.name))

return {f.id: f.to_hash() for f in files_list}

Expand Down

0 comments on commit f1b517c

Please sign in to comment.