Ejemplo n.º 1
0
def approve():
    # Check if user has logged in
    if g.user is not None:
        if request.method == 'GET':
            print("approve")
            # query mongo
            # pass json to the template
            db = get_db()
            collection = db[
                current_app.config['TRANSFORMATIONS_DATABASE_NAME']]
            transformations = collection.transformations.find(
                {"status": "submitted"})
            transformations_data = []
            try:
                for data_tuple in transformations:
                    data = dict()
                    data['status'] = data_tuple.get('status')
                    data['transformation_type'] = data_tuple.get(
                        'transformationType')
                    data['name'] = data_tuple.get('transformationId')
                    transformations_data.append(data)
            except pymongo.errors.ServerSelectionTimeoutError as err:
                print(err)

            return render_template('publish/approve.html',
                                   columns=transformations_data)
        else:
            form_dic = request.form.to_dict()
            transformation_id = form_dic.get('transformationId')
            if transformation_id:
                db = get_db()
                collection = db[
                    current_app.config['TRANSFORMATIONS_DATABASE_NAME']]
                transformations = collection.transformations.find(
                    {"status": "submitted"})
                transformations_data = []
                for data_tuple in transformations:
                    data_name = data_tuple.get('transformationId')
                    if data_name == transformation_id:
                        collection.transformations.update_one(
                            {'transformationId': transformation_id},
                            {'$set': {
                                'status': 'approved'
                            }})
                    else:
                        data = dict()
                        data['status'] = data_tuple.get('status')
                        data['transformation_type'] = data_tuple.get(
                            'transformationType')
                        data['name'] = data_tuple.get('transformationId')
                        transformations_data.append(data)
            return render_template('publish/approve.html',
                                   columns=transformations_data)
    return redirect(url_for('auth.login'))
Ejemplo n.º 2
0
def jsonList(type):
    db = get_db()
    collection = db[current_app.config['TRANSFORMATIONS_DATABASE_NAME']]
    retVal = []
    for toolInfo in collection.tools.find({"tooltype": type}):
        retVal.append(singleToolInfo(str(ObjectId(toolInfo['_id'])), db))
    return json.dumps(
        retVal, default=json_util.default)  # Not sure this is json formatted
Ejemplo n.º 3
0
def transformation_form():
    if g.user is not None:
        db = get_db()
        collection = db[current_app.config['TRANSFORMATIONS_DATABASE_NAME']]

        tools = collection.tools.find({}, {"title": 1})
        return render_template('pages/post_transformation_form.html',
                               tools=tools)
    return redirect(url_for('auth.login'))
Ejemplo n.º 4
0
def softwares():

    db = get_db()
    collection = db[current_app.config['TRANSFORMATIONS_DATABASE_NAME']]

    tools = collection.tools.find()
    raise HTTPException()
    return render_template('pages/softwares.html',
                           tools=tools,
                           getIcon=getIcon)
Ejemplo n.º 5
0
def hasIcons(softwares):
    db = get_db()
    collection = db[current_app.config['TRANSFORMATIONS_DATABASE_NAME']]
    for tool_name in softwares:
        tool = collection.tools.find_one({"title": tool_name})
        if (tool):
            gridFSIcon = gridfs.GridFS(collection, "icons")
            fs = gridFSIcon.find_one({"metadata.tool_id": str(tool["_id"])})
            if fs:
                return True
    return False
Ejemplo n.º 6
0
def getIcon(tool_name):
    db = get_db()
    collection = db[current_app.config['TRANSFORMATIONS_DATABASE_NAME']]
    tool = collection.tools.find_one({"title": tool_name})
    image = ""
    if (tool):
        gridFSIcon = gridfs.GridFS(collection, "icons")
        fs = gridFSIcon.find_one({"metadata.tool_id": str(tool["_id"])})
        if fs:
            base64_data = codecs.encode(fs.read(), 'base64')
            image = base64_data.decode('utf-8')
    return image
Ejemplo n.º 7
0
def home():
    # example: /?software=Cell+Profiler
    software = request.args.get('software')
    db = get_db()
    collection = db[current_app.config['TRANSFORMATIONS_DATABASE_NAME']]
    if software:
        transformations = collection.transformations.find(
            {"dependencies": software})
    else:
        transformations = collection.transformations.find(
            {"status": "approved"})
    return render_template('pages/home.html',
                           transformations=transformations,
                           getIcon=getIcon,
                           hasIcons=hasIcons)
Ejemplo n.º 8
0
def search():
    try:
        db = get_db()
        database = db[current_app.config['TRANSFORMATIONS_DATABASE_NAME']]
        # text search for transformationId & description
        transformation = database.transformations.find(
            {"$text": {
                "$search": request.args.get("search")
            }})

    except Exception as e:
        print("Exception")
        raise
    return render_template('pages/home.html',
                           transformations=transformation,
                           getIcon=getIcon,
                           hasIcons=hasIcons)
Ejemplo n.º 9
0
def view_transformation(transformation_id):
    try:

        db = get_db()
        database = db[current_app.config['TRANSFORMATIONS_DATABASE_NAME']]
        transformation = database.transformations.find_one(
            {"_id": ObjectId(transformation_id)})
        alltransformations = database.transformations.find({"transformationId":
                                                             transformation["transformationId"] }).sort("version", -1).\
                                                             collation(Collation(locale='en_US', numericOrdering=True))

    except Exception as e:
        print("Exception")
        raise
    return render_template('pages/view_transformation.html',
                           originalTransformation=transformation,
                           transformations=alltransformations,
                           getIcon=getIcon,
                           replaceEmptyString=replaceEmptyString)
Ejemplo n.º 10
0
def post_transformation():
    # Check if user has logged in or anonymous submission is allowed
    if g.user is not None or current_app.config["ANONYMOUS_SUBMISSION"].lower(
    ) == "true":
        if request.method == 'POST':

            transformation_type = request.form['radioOptions']

            try:
                if request.form['create'] == "json":
                    info_json = request.form['info_json']
                    dict_info_json = json.loads(info_json)
                    source_code_url = None
                    docker_image_name = None
                    for repo in dict_info_json["repository"]:
                        if repo["repType"] == "git":
                            source_code_url = repo["repUrl"]
                        if repo["repType"] == "docker":
                            docker_image_name = repo["repUrl"]
                    dict_info_json["url"] = source_code_url
                    dict_info_json["dockerImageName"] = docker_image_name
                    dict_info_json.pop("repository")
                    dict_info_json.pop("@context")
                else:
                    dict_info_json = request.form.to_dict(flat=False)
                    single_fields = [
                        "name", "version", "author", "description",
                        "dockerImageName", "url"
                    ]
                    for f in single_fields:
                        dict_info_json[f] = dict_info_json[f][0]
                    if transformation_type == "extractor":

                        dict_info_json["contexts"][0] = json.loads(
                            dict_info_json["contexts"][0])
                        dict_info_json["process"] = json.loads(
                            dict_info_json["process"])
                    else:
                        dict_info_json["input_formats"] = dict_info_json[
                            "input_formats"][0].replace(" ", "").split(",")
                        dict_info_json["output_formats"] = dict_info_json[
                            "output_formats"][0].replace(" ", "").split(",")

                db = get_db()
                database = db[
                    current_app.config['TRANSFORMATIONS_DATABASE_NAME']]

                dict_info_json["transformationId"] = dict_info_json.pop("name")
                dict_info_json["externalServices"] = dict_info_json.pop(
                    "external_services")

                dict_info_json["transformationType"] = transformation_type
                dict_info_json["status"] = "submitted"

                dict_info_json["created"] = datetime.datetime.utcnow()
                dict_info_json["updated"] = datetime.datetime.utcnow()

                print(dict_info_json)
                # Prior to insert, check the name and version if they already exist then error out, otherwise insert
                query_result_id = database.transformations.find_one({
                    "transformationId":
                    dict_info_json["transformationId"],
                    "version":
                    dict_info_json["version"]
                })
                if query_result_id:
                    return redirect(
                        url_for('pages.update_transformation',
                                transformation_id=query_result_id["_id"]))
                result_id = database.transformations.insert(dict_info_json)
                print(transformation_type + " added. ID: " + str(result_id))
                return redirect(
                    url_for('pages.view_transformation',
                            transformation_id=result_id))
            except ValueError as e:
                raise ValueError("Invalid JSON.")
            except json.JSONDecodeError as e:
                raise json.JSONDecodeError("Unable to decode the JSON")
            except KeyError as ke:
                raise KeyError(
                    "There is a missing necessary section of the extractor info"
                )

        return render_template('pages/post_transformation.html')
    return redirect(url_for('auth.login'))