示例#1
0
def get_tasks(appNumber):
    #get the database connection
    cnx = get_connection()

     #get application
    application = load_application(appNumber)
    if application == None:
        return make_response(jsonify( { 'error': 'Application not found' } ), 404)

    #Get Data
    cursor = cnx.cursor()
    query = ("SELECT * from `HumanTaskService`.`Tasks` where ApplicationId="+str(application['id']))
    cursor.execute(query)
    rows = cursor.fetchall()
    cursor.close()
    cnx.close()

    #Build result
    tasks = []
    if (len(rows) > 0):
        for task in rows:
            taskResult = {
                "id":task[0],
                "applicationNumber": appNumber,
                "params":task[2],
                "copies":task[3]
            }
            tasks.append(taskResult)

    return jsonify(Tasks=tasks),200
示例#2
0
def add_task():
    if not request.json:
        abort(400)

    #get the database connection
    cnx = get_connection()

    #get application
    application = load_application(request.json['applicationNumber'])
    if application == None:
        return make_response(jsonify( { 'error': 'Application not found' } ), 404)

    #Add Data
    #TODO: Check parameters
    try:               
        cursor = cnx.cursor()
        command = ("INSERT INTO `HumanTaskService`.`Tasks` (`ApplicationId`, `Params`, `Copies`) VALUES (%s, %s, %s)")
        #TODO Get the number of copies from application, if not avaliable in object
        data_command = (application['id'],request.json['params'],request.json['copies'])
        cursor.execute(command,data_command)
        cnx.commit()
    except mysql.connector.Error as err:
        abort(400) #invalid parameters
    
    #return the new object
    task_id = cursor.lastrowid

    task = {
        'id': task_id,
        'applicationNumber': request.json['applicationNumber'],
        'params': request.json['params'],
        'copies': request.json['copies']
    }

    return jsonify({ 'task': task }), 201
示例#3
0
def resolve_task():
    if not request.json:
        abort(400)

    #get the database connection
    cnx = get_connection()

    #get application
    application = load_application(request.json['applicationNumber'])
    if application == None:
        return make_response(jsonify( { 'error': 'Application not found' } ), 404)

    #Add Data
    #TODO: Check parameters
    try:               
        cursor = cnx.cursor()
        command = ("INSERT INTO `HumanTaskService`.`TaskResults` (`UserId`, `Result`, `FinishDate`, `ApplicationId`, `TaskId`) VALUES (%s, %s, %s, %s, %s)")
        #TODO Get the number of copies from application, if not avaliable in object
        data_command = (request.json['userId'],request.json['result'],datetime.datetime.now(),application['id'],request.json['taskId'])
        cursor.execute(command,data_command)
        cnx.commit()
    except mysql.connector.Error as err:
        abort(400) #invalid parameters
    
    #return the new object
    task_id = cursor.lastrowid

    #TODO: Check datetime format
    return jsonify(id= task_id,
        applicationNumber= request.json['applicationNumber'],
        userId= request.json['userId'],
        taskId= request.json['taskId'],
        result= request.json['result'],
        finishDate= datetime.datetime.now()), 201
示例#4
0
def get_newtask(user,appNumber):
    #get the database connection
    cnx = get_connection()

    #
    #TODO: Get User
    #


     #get application
    application = load_application(appNumber)
    if application == None:
        return make_response(jsonify( { 'error': 'Application not found' } ), 404)

    #Get Data
    cursor = cnx.cursor()
    #
    #TODO Check the scheduler type
    #

    #Sequencial schedule
    query = ("SELECT * FROM HumanTaskService.Tasks WHERE HumanTaskService.Tasks.ApplicationId = " + str(application['id']) + 
             " AND HumanTaskService.Tasks.id NOT IN (select TaskId from HumanTaskService.TaskResults where HumanTaskService.TaskResults.ApplicationId = " + str(application['id']) + 
             " AND HumanTaskService.TaskResults.UserId = " + str(user) + ") LIMIT 1")
    cursor.execute(query)
    rows = cursor.fetchall()
    cursor.close()
    cnx.close()

    #Build result
    if (len(rows) > 0):
        return jsonify(
            id=rows[0][0],
            applicationNumber=appNumber,
            params=rows[0][2],
            copies=rows[0][3]
        ), 200

    #
    #TODO: No more tasks..and now?
    #
    return None