예제 #1
0
def editLinkByID (id: str, newLink):
    #TODO normalize
    if (isinstance(newLink, Link)):
        dbconnection.updateLinkById(id, newLink)
    else:
        link = Link()
        link.fromJSON(newLink)
        dbconnection.updateLinkById(id, link)
예제 #2
0
def getLinksContainingWord(field, word):
    current_app.logger.info("call to getLinksContainingWord")
    regularExpression = "^.*" + word + ".*$"
    regularExpression = re.compile(regularExpression, re.IGNORECASE)
    query = {field: {"$regex": regularExpression}}
    entities = docsCollection.find(query)
    entitiesFormatted = []
    for entity in entities:
        link = Link()
        link.fromJSON(entity)
        entitiesFormatted.append(link)
    return entitiesFormatted
예제 #3
0
def getLinkByField(field, value):
    if field == "_id":
        query = {field: ObjectId(value)}
    else:
        query = {field: value}
    entity = docsCollection.find_one(query)
    if entity:
        link = Link()
        link.fromJSON(entity)
        return link
    else:
        return False
예제 #4
0
def getLinksByField(field, value):
    if field == "_id":
        query = {field: ObjectId(value)}
    else:
        query = {field: value}
    entities = docsCollection.find(query)
    entitiesFormatted = []
    for entity in entities:
        #current_app.logger.info("prueba")
        link = Link()
        link.fromJSON(entity)
        entitiesFormatted.append(link)
    return entitiesFormatted
예제 #5
0
def editLinkPartially (title, newLink):
    #TODO rewrite for query by id, check if needed
    editionLink = getLink(title)
    formattedNewLink = Link()
    formattedNewLink.fromJSON(newLink)

    if formattedNewLink.alias:
        editionLink.alias = formattedNewLink.alias
    
    if formattedNewLink.operation:
        editionLink.operation = formattedNewLink.operation
    
    if formattedNewLink.links:
        editionLink.links = formattedNewLink.links

    editLinkByID(editionLink.id, editionLink)
예제 #6
0
def drawLinkBetween2 (title: str, operation: str, source: str, destination: str):
    #TODO normalize and rewrite to query by id

    if TextOperations.hasEnoughSlots(operation, 2):
        links = [source, destination]
        link = Link(title, operation, links)
        saveLink(link)
예제 #7
0
def updateLinkById(id, modifiedLink):
    query = {"_id": ObjectId(id)}
    link = modifiedLink.toJSON()
    entity = docsCollection.update_one(query, {"$set": link})

    for innerLink in link["links"]:
        if not existsLink(innerLink):
            newLink = Link(innerLink)
            addLink(newLink)
예제 #8
0
def updateLink(title, modifiedLink):
    query = {"alias": title}
    link = modifiedLink.toJSON()
    entity = docsCollection.update_one(query, {"$set": link})

    for innerLink in link["links"]:
        if not existsLink(innerLink):
            newLink = Link(innerLink)
            addLink(newLink)
예제 #9
0
def registerSimpleLink(jsonInput: object) -> list:
    """
    Creates and saves a new link to the database, using a json as input. Validates that the json has the required format. The created link will either have just an alias (an empty link), or be complete (alias, plus operation and links). The function returns the created link.

    Parameters
    ----------
    name : jsonInput
        A json provided as input, which will be validated against the TextOperations.validateJSON function (an "alias" property is the only requirement).

    Raises
    ------
    TypeError
        If jsonInput parameter doesn't pass the validation, an error is raised.
    """    
    if (TextOperations.validateJSON(jsonInput)):
        linkAlias = jsonInput["alias"]
        link = Link(linkAlias)
        if propertyExists(jsonInput, "text"):
            link.fromUnformattedText(jsonInput["text"])
        createdLinks = saveLink(link)
        return createdLinks
    else:
        raise TypeError("Inadequate json input format. JSON input must have a name attribute, at least.")
예제 #10
0
def addLink(link):
    jsonLink = link.toJSON()
    createdLinks = []
    query = {"alias": link.alias}
    if not docsCollection.find_one(query):
        x = docsCollection.insert_one(jsonLink)
        createdLinks.append(jsonify(jsonLink))

    for linkInside in link.links:
        if not existsLink(linkInside):
            newLink = Link(linkInside)
            createdLinks.append(addLink(newLink))

    return createdLinks
예제 #11
0
def registerSimpleEntry (title: str, text: str):
    #TODO rewrite and normalize
    newEntry = Link(title, text, [], "")
    saveLink(newEntry)
예제 #12
0
def groupLinks (title: str, operation: str, titles: list):
    #TODO normalize and raise exception if conditions aren't fulfilled and rewrite to query by id
    if TextOperations.hasEnoughSlots(operation, len(titles)):
        link = Link(title, operation, titles)
        saveLink(link)
예제 #13
0
def enumerateLinks (title: str, operationBeginning: str, titles: list):
    #TODO normalize and rewrite to query by id
    operation = TextOperations.generateOperation(operationBeginning, len(titles))
    link = Link (title, operation, titles)
    saveLink(link)
예제 #14
0
def getLink(title):
    query = {"alias": title}
    entity = docsCollection.find_one(query)
    link = Link()
    link.fromJSON(entity)
    return link
예제 #15
0
def registerLink (title: str, operation: str, entitiesLinked:list = []):
    #TODO normalize and check if needed
    newLink = Link(title, operation, entitiesLinked)
    saveLink (newLink)
예제 #16
0
def registerLinkFromUnformattedText(title: str, text: str):
    #TODO normalize and check if needed
    newEntry = Link(title, text, [], "")
    newEntry.fromUnformattedText(text)
    saveLink(newEntry)
예제 #17
0
def registerEmptyEntry(title: str):
    #TODO normalize and check if needed
    newEntry = Link(title)
    saveLink(newEntry)