Esempio n. 1
0
def add_study_to_file_mdata(submission_id, file_id, data):
    ''' Adds a new study to the metadata of this file. 
    Throws:
        InvalidId -- if the submission_id is not corresponding to MongoDB rules (pymongo specific error)
        DoesNotExist -- if there is no submission with this id in the DB (Mongoengine specific error)
        #### -- NOT ANY MORE! -- ResourceNotFoundException -- my custom exception, thrown if a file 
                                                        with the file_id does not exist within this submission.
        NoEntityCreated - my custom exception, thrown if a request to create an entity was received, 
                          but the entity could not be created because it exists already.
        NoEntityIdentifyingFieldsProvided -- my custom exception, thrown if the study 
                                             doesn't contain any identifying field (e.g.internal_id, name).
        EditConflictException -- my custom exception, thrown when the entity hasn't been inserted, most likely
                             because of an editing conflict
    '''
    sender = get_request_source(data)
    file_obj = data_access.FileDataAccess.retrieve_submitted_file(file_id)
    file_logic = app_logic.FileBusinessLogicBuilder.build_from_type(
        file_obj.file_type)
    added = file_logic.add_entity_to_filemeta(data, constants.STUDY_TYPE,
                                              sender, file_id, file_obj)
    if not added:
        raise exceptions.EditConflictException("Study couldn't be added.")
    file_logic.status_checker.check_and_update_all_statuses(
        file_id, file_obj.reload())
    return True
Esempio n. 2
0
def update_study(submission_id, file_id, study_id, data):
    ''' Updates the study with the data received from the request. 
    Throws:
        InvalidId -- if the submission_id or file_id is not corresponding to MongoDB rules (pymongo specific error)
        DoesNotExist -- if there is no submission nor file_id with this id in the DB (Mongoengine specific error)
##        ResourceNotFoundException -- my custom exception, thrown if the study doesn't exist.
        NoEntityIdentifyingFieldsProvided -- my custom exception, thrown if the study 
                                             doesn't contain any identifying field (e.g.internal_id, name).
        DeprecatedDocument -- my custom exception, thrown if the version of the document to be
                              modified is older than the current document in the DB.
    '''
    sender = get_request_source(data)
    upd = data_access.FileDataAccess.update_study_in_db(data,
                                                        sender,
                                                        file_id,
                                                        study_id=study_id)
    logging.info("I AM UPDATING A STUDY - result: %s", upd)
    if not upd:
        raise exceptions.EditConflictException(
            "The study couldn't be updated.")
    file_obj = data_access.FileDataAccess.retrieve_submitted_file(file_id)
    file_logic = app_logic.FileBusinessLogicBuilder.build_from_type(
        file_obj.file_type)
    file_logic.status_checker.check_and_update_all_statuses(
        file_id, file_obj.reload())
    return upd
Esempio n. 3
0
def delete_study(submission_id, file_id, study_id):
    ''' Deletes a study specified by study id.
    Returns:
        True if the study has been successfully deleted. Otherwise it throws exception
    Throws:
        InvalidId -- if the submission_id is not corresponding to MongoDB rules (pymongo specific error)
        DoesNotExist -- if there is no submission with this id in the DB (Mongoengine specific error)
        ResourceNotFoundException -- my custom exception, thrown if the study does not exist.
    '''
    file_obj = data_access.FileDataAccess.retrieve_submitted_file(file_id)
    deleted = data_access.FileDataAccess.delete_study(study_id, file_id,
                                                      file_obj)
    if not deleted:
        raise exceptions.EditConflictException(
            "The study couldn't be deleted.")
    file_logic = app_logic.FileBusinessLogicBuilder.build_from_type(
        file_obj.file_type)
    file_logic.status_checker.check_and_update_all_statuses(
        file_id, file_obj.reload())
    return deleted
Esempio n. 4
0
 def add_entity_to_filemeta(cls,
                            entity_json,
                            entity_type,
                            sender,
                            file_id,
                            submitted_file=None):
     if data_access.FileDataAccess.search_JSON_entity(
             entity_json, entity_type, file_id, submitted_file) != None:
         raise exceptions.NoEntityCreatedException(
             "The entity already exists in the list. For update, please send a PUT request."
         )
     inserted = data_access.FileDataAccess.insert_JSONentity_in_db(
         entity_json, entity_type, sender, file_id, submitted_file)
     if inserted == True:
         file_obj = data_access.FileDataAccess.retrieve_submitted_file(
             file_id)
         file_logic = FileBusinessLogicBuilder.build_from_file(
             file_id, file_obj)
         file_logic.submit_presubmission_tasks(
             [constants.UPDATE_MDATA_TASK], file_obj)
         return True
     else:
         raise exceptions.EditConflictException(
             "The entity couldn't be inserted.")