mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Code de-duplicate ok to edit metadata.
This commit is contained in:
@@ -343,12 +343,13 @@ class DatasetAssociationManager(base.ModelManager,
|
||||
rval["modify_item_roles"] = modify_item_role_list
|
||||
return rval
|
||||
|
||||
def __ok_to_edit_metadata(self, trans, dataset_id):
|
||||
def ok_to_edit_metadata(self, dataset_id):
|
||||
# prevent modifying metadata when dataset is queued or running as input/output
|
||||
# This code could be more efficient, i.e. by using mappers, but to prevent slowing down loading a History panel, we'll leave the code here for now
|
||||
for job_to_dataset_association in trans.sa_session.query(
|
||||
sa_session = self.app.model.context
|
||||
for job_to_dataset_association in sa_session.query(
|
||||
self.app.model.JobToInputDatasetAssociation).filter_by(dataset_id=dataset_id).all() \
|
||||
+ trans.sa_session.query(self.app.model.JobToOutputDatasetAssociation).filter_by(dataset_id=dataset_id).all():
|
||||
+ sa_session.query(self.app.model.JobToOutputDatasetAssociation).filter_by(dataset_id=dataset_id).all():
|
||||
if job_to_dataset_association.job.state not in [job_to_dataset_association.job.states.OK, job_to_dataset_association.job.states.ERROR, job_to_dataset_association.job.states.DELETED]:
|
||||
return False
|
||||
return True
|
||||
@@ -357,7 +358,7 @@ class DatasetAssociationManager(base.ModelManager,
|
||||
"""Sniff and assign the datatype to a given dataset association (ldda or hda)"""
|
||||
data = trans.sa_session.query(self.model_class).get(dataset_assoc.id)
|
||||
if data.datatype.allow_datatype_change:
|
||||
if not self.__ok_to_edit_metadata(trans, data.id):
|
||||
if not self.ok_to_edit_metadata(data.id):
|
||||
raise exceptions.ItemAccessibilityException('This dataset is currently being used as input or output. You cannot change datatype until the jobs have completed or you have canceled them.')
|
||||
else:
|
||||
path = data.dataset.file_name
|
||||
@@ -369,15 +370,22 @@ class DatasetAssociationManager(base.ModelManager,
|
||||
else:
|
||||
raise exceptions.InsufficientPermissionsException('Changing datatype "%s" is not allowed.' % (data.extension))
|
||||
|
||||
def set_metadata(self, trans, dataset_assoc):
|
||||
def set_metadata(self, trans, dataset_assoc, overwrite=False):
|
||||
"""Trigger a job that detects and sets metadata on a given dataset association (ldda or hda)"""
|
||||
data = trans.sa_session.query(self.model_class).get(dataset_assoc.id)
|
||||
if not self.__ok_to_edit_metadata(trans, data.id):
|
||||
if not self.ok_to_edit_metadata(data.id):
|
||||
raise exceptions.ItemAccessibilityException('This dataset is currently being used as input or output. You cannot edit metadata until the jobs have completed or you have canceled them.')
|
||||
else:
|
||||
trans.app.datatypes_registry.set_external_metadata_tool.tool_action.execute(
|
||||
trans.app.datatypes_registry.set_external_metadata_tool, trans, incoming={'input1': data},
|
||||
overwrite=False) # overwrite is False as per existing behavior
|
||||
if overwrite:
|
||||
for name, spec in data.metadata.spec.items():
|
||||
# We need to be careful about the attributes we are resetting
|
||||
if name not in ['name', 'info', 'dbkey', 'base_name']:
|
||||
if spec.get('default'):
|
||||
setattr(data.metadata, name, spec.unwrap(spec.get('default')))
|
||||
|
||||
self.app.datatypes_registry.set_external_metadata_tool.tool_action.execute(
|
||||
self.app.datatypes_registry.set_external_metadata_tool, trans, incoming={'input1': data},
|
||||
overwrite=overwrite)
|
||||
|
||||
def update_permissions(self, trans, dataset_assoc, **kwd):
|
||||
action = kwd.get('action', 'set_permissions')
|
||||
|
||||
@@ -19,7 +19,7 @@ from galaxy import (
|
||||
)
|
||||
from galaxy.datatypes import sniff
|
||||
from galaxy.datatypes.display_applications.util import decode_dataset_user, encode_dataset_user
|
||||
from galaxy.exceptions import RequestParameterInvalidException
|
||||
from galaxy.exceptions import MessageException, RequestParameterInvalidException
|
||||
from galaxy.model.item_attrs import UsesAnnotations, UsesItemRatings
|
||||
from galaxy.util import (
|
||||
inflector,
|
||||
@@ -393,14 +393,7 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE
|
||||
def set_edit(self, trans, payload=None, **kwd):
|
||||
"""Allows user to modify parameters of an HDA."""
|
||||
def __ok_to_edit_metadata(dataset_id):
|
||||
# prevent modifying metadata when dataset is queued or running as input/output
|
||||
# This code could be more efficient, i.e. by using mappers, but to prevent slowing down loading a History panel, we'll leave the code here for now
|
||||
for job_to_dataset_association in trans.sa_session.query(
|
||||
self.app.model.JobToInputDatasetAssociation).filter_by(dataset_id=dataset_id).all() \
|
||||
+ trans.sa_session.query(self.app.model.JobToOutputDatasetAssociation).filter_by(dataset_id=dataset_id).all():
|
||||
if job_to_dataset_association.job.state not in [job_to_dataset_association.job.states.OK, job_to_dataset_association.job.states.ERROR, job_to_dataset_association.job.states.DELETED]:
|
||||
return False
|
||||
return True
|
||||
return self.hda_manager.ok_to_edit_metadata(dataset_id)
|
||||
|
||||
status = 'success'
|
||||
operation = payload.get('operation')
|
||||
@@ -466,17 +459,10 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE
|
||||
elif operation == 'autodetect':
|
||||
# The user clicked the Auto-detect button on the 'Edit Attributes' form
|
||||
# prevent modifying metadata when dataset is queued or running as input/output
|
||||
if not __ok_to_edit_metadata(data.id):
|
||||
return self.message_exception(trans, 'This dataset is currently being used as input or output. You cannot change metadata until the jobs have completed or you have canceled them.')
|
||||
else:
|
||||
for name, spec in data.metadata.spec.items():
|
||||
# We need to be careful about the attributes we are resetting
|
||||
if name not in ['name', 'info', 'dbkey', 'base_name']:
|
||||
if spec.get('default'):
|
||||
setattr(data.metadata, name, spec.unwrap(spec.get('default')))
|
||||
message = 'Attributes have been queued to be updated.'
|
||||
trans.app.datatypes_registry.set_external_metadata_tool.tool_action.execute(trans.app.datatypes_registry.set_external_metadata_tool, trans, incoming={'input1': data})
|
||||
trans.sa_session.flush()
|
||||
try:
|
||||
self.hda_manager.set_metadata(trans, data, overwrite=True)
|
||||
except MessageException as e:
|
||||
return self.message_exception(trans, e.err_msg)
|
||||
elif operation == 'conversion':
|
||||
target_type = payload.get('target_type')
|
||||
if target_type:
|
||||
|
||||
Reference in New Issue
Block a user