Exemplo n.º 1
0
def q():
    try:
        content = json.loads(request.data)
    except:
        return jsonify({'error': 'could not get POST content.'})

    try:
        webservicepassword = content['webservicepassword'][0].replace("\t", "")
        login = content['login'][0]
        bf = bfabric.Bfabric(login=login, password=webservicepassword)
        print(content['endpoint'][0])
        print(content['query'])
        res = bf.read_object(endpoint=content['endpoint'][0],
                             obj=content['query'])
        logger.info("'{}' login success query {} ...".format(
            login, content['query']))
    except:
        logger.info("'{}' login failed ...".format(login))
        return jsonify({'status': 'jsonify failed: bfabric python module.'})

    try:
        return jsonify({'res': res})
    except:
        logger.info("'{}' query failed ...".format(login))
        return jsonify({'status': 'jsonify failed'})
Exemplo n.º 2
0
def s():
    try:
        content = json.loads(request.data)
    except:
        return jsonify({'error': 'could not get POST content.'})

    bf = bfabric.Bfabric()
    print content
    res = bf.save_object(endpoint=content['endpoint'][0], obj=content['query'])

    try:
        return jsonify({'res': res})
    except:
        return jsonify({'status': 'jsonify failed'})
Exemplo n.º 3
0
def q():
    try:
        content = json.loads(request.data)
    except:
        return jsonify({'error': 'could not get POST content.'})

    bf = bfabric.Bfabric(login=content['login'],
                         password=content['webservicepassword'])
    print content
    res = bf.read_object(endpoint=content['endpoint'][0], obj=content['query'])

    try:
        return jsonify({'res': res})
    except:
        return jsonify({'status': 'jsonify failed'})
Exemplo n.º 4
0
def query():
    try:
        content = json.loads(request.data)
    except:
        return jsonify({
            'error': 'could not get POST content.',
            'appid': appid
        })

    print "PASSWORD CLEARTEXT", content['webservicepassword']

    bf = bfabric.Bfabric(login=content['login'],
                         password=content['webservicepassword'],
                         webbase='http://fgcz-bfabric.uzh.ch/bfabric')

    for i in content.keys():
        print "{}\t{}".format(i, content[i])

    if 'projectid' in content:
        workunits = bf.read_object(endpoint='workunit',
                                   obj={
                                       'applicationid':
                                       content['applicationid'],
                                       'projectid': content['projectid']
                                   })
        #workunits = bf.read_object(endpoint='workunit', obj={'applicationid': 205, 'projectid': 1352})
        print workunits
        return jsonify({'workunits': map(lambda x: x._id, workunits)})
    #elif 'query' in content and "{}".format(content['query']) is 'project':
    else:
        user = bf.read_object(endpoint='user', obj={'login':
                                                    content['login']})[0]
        projects = map(lambda x: x._id, user.project)
        return jsonify({'projects': projects})

    return jsonify({'error': 'could not process query'})
Exemplo n.º 5
0
class BfabricJSONEncoder(JSONEncoder):
    def default(self, obj):
        try:
            iterable = iter(obj)
        except TypeError:
            pass
        else:
            return (dict(iterable))

        return JSONEncoder.default(self, obj)


app = Flask(__name__)
app.json_encoder = BfabricJSONEncoder
bfapp = bfabric.Bfabric(login='******')

inlcude_child_extracts = True
"""
generic query interface for read interface

example (assumes the proxy runs on localhost):

R>     rv <- POST('http://localhost:5000/query', 
               body = toJSON(list(login = login, 
                                  webservicepassword = webservicepassword,
                                  query = 'resource',
                                  projectid = project,
                                  applicationid = 205)), 
               encode = 'json')
    
Exemplo n.º 6
0
        return JSONEncoder.default(self, obj)


address = ("fgcz-ms.uzh.ch", 514)
name = "bfabric9_flask"
syslog_handler = logging.handlers.SysLogHandler(address=address)

# from flask.logging import default_handler
formatter = logging.Formatter('%(name)s %(message)s')
syslog_handler.setFormatter(formatter)

app = Flask(__name__)
# app.logger.removeHandler(default_handler)
app.logger.addHandler(syslog_handler)
app.json_encoder = BfabricJSONEncoder
bfapp = bfabric.Bfabric()

inlcude_child_extracts = True
"""
generic query interface for read interface

example (assumes the proxy runs on localhost):

R>     rv <- POST('http://localhost:5000/query', 
               body = toJSON(list(login = login, 
                                  webservicepassword = webservicepassword,
                                  query = 'resource',
                                  projectid = project,
                                  applicationid = 205)), 
               encode = 'json')