示例#1
0
def handle_post_reagent(s_id, r_id, client_state, username, body):
    '''
    Function expects integers sequence id and reagent id.
    Function also expects a client state, a string username, and
    a string for the body sent with the POST request.
    Function calls save client and return then returns the output of the
    function called.
    '''
    # Extract sequence and reagent IDs
    sequence_id = int(s_id)
    reagent_id = int(r_id)

    # Make sure we can edit this sequence
    sequence_metadata = db.get_sequence_metadata(sequence_id)
    if sequence_metadata["sequencetype"] != "Saved":
        raise Exception("Cannot edit sequence")

    # Save the reagent
    reagent = json.loads(body)
    db.update_reagent(
            reagent_id,
            reagent["name"],
            reagent["description"])

    # Flag the sequence validation as dirty
    db.update_sequence_dirty_flag(sequence_id, True)

    # Return the new state
    return save_client_state_and_return(client_state, db, username)
示例#2
0
def handle_get_state_view(client_state, username):
    '''
    Handles GET /state for View Sequence
    Function expects a client state and a string username.
    Function returns the "View Sequence" screen.
    '''

    server_state = get_server_state(username)
    # Do we have a component ID?
    if client_state["componentid"] == 0:
        # No, the component ID is missing.
        # Get the sequence and the ID of the first component
        sequence = sequence_manager.GetSequence(username,
                                                client_state["sequenceid"],
                                                False)
        client_state["componentid"] = sequence["components"][0]["id"]
        # Save client state
        db.update_user_client_state(username, client_state)

    # Allow editing if this is a saved sequence
    sequence_metadata = db.get_sequence_metadata(client_state["sequenceid"])
    edit_allowed = (sequence_metadata["sequencetype"] == "Saved")

    # Allow running if the system is not in use
    run_allowed = (server_state["runstate"]["status"] == "Idle")

    # Allow running from here if this is not a cassette
    run_here_allowed = False
    if run_allowed:
        component = sequence_manager.GetComponent(username,
                                                  client_state["componentid"],
                                                  client_state["sequenceid"])
        run_here_allowed = (component["componenttype"] != "CASSETTE")

    # Return the state
    return {
        "buttons": [{
            "type": "button",
            "id": "SEQUENCER",
            "enabled": True
        }, {
            "type": "button",
            "id": "EDITSEQUENCE",
            "enabled": edit_allowed
        }, {
            "type": "button",
            "id": "RUNSEQUENCE",
            "enabled": run_allowed
        }, {
            "type": "button",
            "id": "RUNSEQUENCEHERE",
            "enabled": run_here_allowed
        }],
        "sequenceid":
        client_state["sequenceid"],
        "componentid":
        client_state["componentid"]
    }
示例#3
0
def handle_get_state_view(client_state, username):
    '''
    Handles GET /state for View Sequence
    Function expects a client state and a string username.
    Function returns the "View Sequence" screen.
    '''

    server_state = get_server_state(username)
    # Do we have a component ID?
    if client_state["componentid"] == 0:
        # No, the component ID is missing.
        # Get the sequence and the ID of the first component
        sequence = sequence_manager.GetSequence(
                username,
                client_state["sequenceid"],
                False)
        client_state["componentid"] = sequence["components"][0]["id"]
        # Save client state
        db.update_user_client_state(username, client_state)

    # Allow editing if this is a saved sequence
    sequence_metadata = db.get_sequence_metadata(
            client_state["sequenceid"])
    edit_allowed = (sequence_metadata["sequencetype"] == "Saved")

    # Allow running if the system is not in use
    run_allowed = (server_state["runstate"]["status"] == "Idle")

    # Allow running from here if this is not a cassette
    run_here_allowed = False
    if run_allowed:
        component = sequence_manager.GetComponent(username,
                client_state["componentid"],
                client_state["sequenceid"])
        run_here_allowed = (component["componenttype"] != "CASSETTE")

    # Return the state
    return {"buttons":[{"type":"button",
        "id":"SEQUENCER",
        "enabled":True},
        {"type":"button",
        "id":"EDITSEQUENCE",
        "enabled":edit_allowed},
        {"type":"button",
        "id":"RUNSEQUENCE",
        "enabled":run_allowed},
        {"type":"button",
        "id":"RUNSEQUENCEHERE",
        "enabled":run_here_allowed}],
        "sequenceid":client_state["sequenceid"],
        "componentid":client_state["componentid"]}
示例#4
0
def handle_post_component(s_id, c_id, unit, client_state, username, body):
    '''
    Function expects integers sequence id, component id, and insertion id.
    Function also expects a client state and a string for the body sent
    with the POST request.
    Function calls save client and return then returns the output of the
    function called.
    '''
    # Extract sequence and component IDs
    current_app.logger.debug("Handle post component.")

    sequence_id = int(s_id)
    component_id = int(c_id)
    insertion_id = unit

    # Make sure we can edit this sequence
    sequence_metadata = db.get_sequence_metadata(sequence_id)
    if sequence_metadata["sequencetype"] != "Saved":
        raise Exception("Cannot edit sequence")

    # Parse the component JSON if present
    component = None
    if len(body) != 0:
        component = json.loads(body)

    # Are we working with an existing component?
    if component_id != 0:
        # Yes, so update the existing component
        sequence_manager.UpdateComponent(
                username, int(sequence_id),
                int(component_id),
                int(insertion_id),
                component)
    else:
        # No, so add a new component
        component_id = sequence_manager.AddComponent(
                username, int(sequence_id),
                int(insertion_id),
                component)

        # Update the client to show the new component
        client_state["componentid"] = component_id

    # Return the new state
    return save_client_state_and_return(
            client_state, username)
示例#5
0
    def reagent_post_index(s_id, r_id):
        '''
        Function shall handle all POST .../reagent/<reagent_id>
        web requests.
        Function expects integers sequence id and reagent id to
        be passed in as parameters.
        Function returns the output of save client state and
        return.
        The function obtains the data of the body sent with
        the POST request and updates the reagent on the database
        before calling save client state and return.
        '''
        # Get objects

        auth = request.authorization
        username = str(auth.username)
        server_state = get_server_state(username)
        client_state = getCurrentClientState(username)
        # Get POST object
        body = request.data
        current_app.logger.debug("Body sent: " + str(body))

        # Make sure we can edit this sequence
        sequence_metadata = db.get_sequence_metadata(int(s_id))
        if sequence_metadata["sequencetype"] != "Saved":
            raise Exception("Cannot edit sequence")

        # Save the reagent
        reagent = json.loads(body)
        db.update_reagent(
                int(r_id),
                reagent["name"],
                reagent["description"])

        # Flag the sequence validation as dirty
        db.update_sequence_dirty_flag(int(s_id), True)

        # Return the new state
        return save_client_state_and_return(
                client_state, username)
示例#6
0
    def component_post_index(s_id, c_id, unit=None):
        '''
        This function handles all POST for components from the
        client.
        Function expects an integer sequence_id, an integer component_id,
        and an optional parameter, insertion id.
        Function shall return the output of save client and return.
        Based on the body sent with the POST request, this function
        shall use sequence_manager to update the component passed in.
        '''

        auth = request.authorization
        username = str(auth.username)
        server_state = get_server_state(username)
        client_state = getCurrentClientState(username)
        # Get POST object
        body = request.data

        insertion_id = None
        if unit != None:
            insertion_id = int(unit)

        current_app.logger.debug('POST /sequence/s_id/component/c_id' +
                "\nRequest: " + str(request) + \
                "\nBody recieved: " + str(body) + \
                "\nInsertion ID: " + str(insertion_id))
        sequence_metdata = db.get_sequence_metadata(int(s_id))
        if sequence_metdata['sequencetype'] != 'Saved':
            raise Exception("Cannot edit sequence!")
        component = None

        if len(body) != 0:
            component = json.loads(body)
        if int(c_id) != 0:
            current_app.logger.debug("Updating component")
            # Check if insertion_id is none
            if insertion_id != None:
                sequence_manager.UpdateComponent(
                        username, int(s_id), int(c_id),
                        int(insertion_id), component)
            else:
                sequence_manager.UpdateComponent(
                        username, int(s_id), int(c_id),
                        None, component)

        else:
            # Check if insertion_id is None
            if insertion_id != None:
                c_id = sequence_manager.AddComponent(
                        username, int(s_id),
                        int(insertion_id), component)
                current_app.logger.debug("Adding component: " + \
                        str(c_id))
                client_state["componentid"] = c_id
            else :
                c_id = sequence_manager.AddComponent(
                        username, int(s_id),
                        None, component)
                current_app.logger.debug("Adding component: " + \
                        str(c_id))
                client_state["componentid"] = c_id

        return save_client_state_and_return(
                client_state, username)