예제 #1
0
    def config_index():
        """
        Function shall expect no parameters.
        Function shall return a config object as a JSON object.
        Function shall query the database and obtain the config
        object from the db.
        """
        # Handle GET /configuration
        current_app.logger.debug(str(request))

        auth = request.authorization
        user = db.get_user(auth.username)

        config = {"type": "configuration"}
        config.update(db.get_configuration())
        config.update({"supportedoperations": db.get_supported_operations()})
        current_app.logger.debug(str(config))
        return jsonify(config)
예제 #2
0
    def config_index():
        '''
        Function shall expect no parameters.
        Function shall return a config object as a JSON object.
        Function shall query the database and obtain the config
        object from the db.
        '''
        # Handle GET /configuration
        current_app.logger.debug(str(request))

        auth = request.authorization
        user = db.get_user(auth.username)

        config = {"type": "configuration"}
        config.update(db.get_configuration())
        config.update({"supportedoperations": db.get_supported_operations()})
        current_app.logger.debug(str(config))
        return jsonify(config)
예제 #3
0
    def runstate_index():
        '''
        Function shall handle GET ../runstate.
        Function expects no paramaters to be passed in.
        Function shall return the state as a JSON object.
        This state will contain components from the client
        state and the server state.
        '''

        # Handle GET /runstate request
        # Get the user information and server state
        current_app.logger.debug(str(request))

        auth = request.authorization
        user = db.get_user(str(auth.username))
        server_state = core_server.GetServerState(user)
        client_state = getCurrentClientState(auth.username)

        # Start the state object
        return_state = {
            "type": "state",
            "user": user,
            "serverstate": server_state,
            "clientstate": copy.deepcopy(client_state),
            "timestamp": time.time()
        }

        # Complete with either the run or home states
        if server_state["runstate"]["running"]:
            return_state.update(
                handle_get_state_run(client_state, str(auth.username)))
            return_state["clientstate"]["screen"] = "RUN"
        else:
            return_state.update(
                handle_get_state_run(client_state, str(auth.username)))
            return_state["clientstate"]["screen"] = "HOME"
            return_state["clientstate"]["prompt"]["show"] = False

        # Return the state
        return jsonify(return_state)
예제 #4
0
    def runstate_index():
        """
        Function shall handle GET ../runstate.
        Function expects no paramaters to be passed in.
        Function shall return the state as a JSON object.
        This state will contain components from the client
        state and the server state.
        """

        # Handle GET /runstate request
        # Get the user information and server state
        current_app.logger.debug(str(request))

        auth = request.authorization
        user = db.get_user(str(auth.username))
        server_state = core_server.GetServerState(user)
        client_state = getCurrentClientState(auth.username)

        # Start the state object
        return_state = {
            "type": "state",
            "user": user,
            "serverstate": server_state,
            "clientstate": copy.deepcopy(client_state),
            "timestamp": time.time(),
        }

        # Complete with either the run or home states
        if server_state["runstate"]["running"]:
            return_state.update(handle_get_state_run(client_state, str(auth.username)))
            return_state["clientstate"]["screen"] = "RUN"
        else:
            return_state.update(handle_get_state_run(client_state, str(auth.username)))
            return_state["clientstate"]["screen"] = "HOME"
            return_state["clientstate"]["prompt"]["show"] = False

        # Return the state
        return jsonify(return_state)
예제 #5
0
    def reagent_index(sequence_id, reagent_ids):
        """
        Function expects a sequence id and a reagent id(s) that
        is passed in from the web request.
        Function returns a reagent(s) object as a JSON object.
        This function takes all reagent ids passed in
        (seperated by a dot -in the form of .../reagent/1.2.5.6).
        For each reagent id, this funcion shall obtain the reagent
        information and return all the information as a whole.
        """
        current_app.logger.debug(str(request))
        auth = request.authorization
        user = db.get_user(auth.username)
        # Split each reagent id based on a '.'
        reagent_ids = str(reagent_ids).split(".")

        # Create and return the reagent array
        reagents = {}
        reagents["type"] = "reagents"
        reagents["reagents"] = []
        for reagent_id in reagent_ids:
            reagents["reagents"].append(sequence_manager.GetReagent(user, int(reagent_id)))
        return jsonify(reagents)
예제 #6
0
    def reagent_index(sequence_id, reagent_ids):
        '''
        Function expects a sequence id and a reagent id(s) that
        is passed in from the web request.
        Function returns a reagent(s) object as a JSON object.
        This function takes all reagent ids passed in
        (seperated by a dot -in the form of .../reagent/1.2.5.6).
        For each reagent id, this funcion shall obtain the reagent
        information and return all the information as a whole.
        '''
        current_app.logger.debug(str(request))
        auth = request.authorization
        user = db.get_user(auth.username)
        # Split each reagent id based on a '.'
        reagent_ids = str(reagent_ids).split(".")

        # Create and return the reagent array
        reagents = {}
        reagents["type"] = "reagents"
        reagents["reagents"] = []
        for reagent_id in reagent_ids:
            reagents["reagents"].append(
                sequence_manager.GetReagent(user, int(reagent_id)))
        return jsonify(reagents)
예제 #7
0
    def state_index(self=None):
        '''
        This function requires authentication prior to executing.
        Function takes in no parameters.
        Function shall direct the client based on the client's
        current screen.
        Function returns the state to the client as a JSON object.
        '''

        auth = request.authorization
        user = db.get_user(str(auth.username))
        server_state = get_server_state(str(auth.username))
        client_state = getCurrentClientState(str(auth.username))
        current_app.logger.debug(str(request) + "\nClientstate: " + \
                str(client_state) + "\nServerstate: " + str(server_state))
        # Is the remote user the one that is currently running the system?
        if str(auth.username) == server_state["runstate"]["username"]:
            # Yes, so make sure the user is on the run screen
            if client_state["screen"] != "RUN":
                # Update the client state
                client_state["screen"] = "RUN"
                db.update_user_client_state(str(auth.username), client_state)

        return_state = {
            "type": "state",
            "user": user,
            "serverstate": server_state,
            "clientstate": client_state,
            "timestamp": time.time()
        }
        # Check which screen is active
        choice = str(client_state["screen"])

        current_app.logger.debug("Request for state" +
                "\nREQUEST: " + str(request) + \
                "\nClient state: " + str(client_state) + \
                "\nServer state: " + str(server_state))

        #current_app.logger.debug("Client State: "+ str(client_state) + \
        #        "\nChoice from client_state[screen]: " +str(choice))

        if choice == "HOME":
            return_state.update(handle_get_state_home(auth.username))
        elif choice == "SELECT_SAVEDSEQUENCES":
            return_state.update(
                handle_get_state_select_savedsequences(client_state,
                                                       auth.username))
        elif choice == "SELECT_RUNHISTORY":
            return_state.update(
                handle_get_state_select_runhistory(client_state,
                                                   auth.username))
        elif choice == "VIEW":
            return_state.update(
                handle_get_state_view(client_state, auth.username))
        elif choice == "EDIT":
            return_state.update(
                handle_get_state_edit(client_state, auth.username))
        elif choice == "RUN":
            return_state.update(
                handle_get_state_run(client_state, auth.username))
        else:
            current_app.logger.debug("Unknown screen: %s" % str(choice))
            raise Exception("Unknown screen: %s" % str(choice))
        #current_app.logger.debug("Return state: " + str(return_state))
        return jsonify(return_state)
예제 #8
0
    def state_index(self=None):
        """
        This function requires authentication prior to executing.
        Function takes in no parameters.
        Function shall direct the client based on the client's
        current screen.
        Function returns the state to the client as a JSON object.
        """

        auth = request.authorization
        user = db.get_user(str(auth.username))
        server_state = get_server_state(str(auth.username))
        client_state = getCurrentClientState(str(auth.username))
        current_app.logger.debug(
            str(request) + "\nClientstate: " + str(client_state) + "\nServerstate: " + str(server_state)
        )
        # Is the remote user the one that is currently running the system?
        if str(auth.username) == server_state["runstate"]["username"]:
            # Yes, so make sure the user is on the run screen
            if client_state["screen"] != "RUN":
                # Update the client state
                client_state["screen"] = "RUN"
                db.update_user_client_state(str(auth.username), client_state)

        return_state = {
            "type": "state",
            "user": user,
            "serverstate": server_state,
            "clientstate": client_state,
            "timestamp": time.time(),
        }
        # Check which screen is active
        choice = str(client_state["screen"])

        current_app.logger.debug(
            "Request for state"
            + "\nREQUEST: "
            + str(request)
            + "\nClient state: "
            + str(client_state)
            + "\nServer state: "
            + str(server_state)
        )

        # current_app.logger.debug("Client State: "+ str(client_state) + \
        #        "\nChoice from client_state[screen]: " +str(choice))

        if choice == "HOME":
            return_state.update(handle_get_state_home(auth.username))
        elif choice == "SELECT_SAVEDSEQUENCES":
            return_state.update(handle_get_state_select_savedsequences(client_state, auth.username))
        elif choice == "SELECT_RUNHISTORY":
            return_state.update(handle_get_state_select_runhistory(client_state, auth.username))
        elif choice == "VIEW":
            return_state.update(handle_get_state_view(client_state, auth.username))
        elif choice == "EDIT":
            return_state.update(handle_get_state_edit(client_state, auth.username))
        elif choice == "RUN":
            return_state.update(handle_get_state_run(client_state, auth.username))
        else:
            current_app.logger.debug("Unknown screen: %s" % str(choice))
            raise Exception("Unknown screen: %s" % str(choice))
        # current_app.logger.debug("Return state: " + str(return_state))
        return jsonify(return_state)