def set_new_undercut(premisegroup_uid, current_argument: Argument, db_user: User, issue: Issue) \ -> Tuple[Argument, bool]: """ Inserts a new undercut with the given parameters. :param premisegroup_uid: premisegroup_uid :param current_argument: Argument :param db_user: User :param issue: Issue.uid :return: Argument, Boolean if the argument is a duplicate """ # duplicate? db_argument = DBDiscussionSession.query(Argument).filter(Argument.premisegroup_uid == premisegroup_uid, Argument.is_supportive == False, Argument.argument_uid == current_argument.uid).first() if db_argument: return db_argument, True else: new_argument = Argument(premisegroup=premisegroup_uid, is_supportive=False, author=db_user.uid, issue=issue.uid) new_argument.set_conclusions_argument(current_argument.uid) DBDiscussionSession.add(new_argument) DBDiscussionSession.flush() transaction.commit() return new_argument, False
def __create_argument_by_uids(db_user: User, premisegroup_uid, conclusion_uid, argument_uid, is_supportive, db_issue: Issue) -> Optional[Argument]: """ Connects the given id's to a new argument :param db_user: User.nickname :param premisegroup_uid: PremiseGroup.uid :param conclusion_uid: Statement.uid :param argument_uid: Argument.uid :param is_supportive: Boolean :param db_issue: Issue :return: """ LOG.debug( "Entering __create_argument_by_uids with user: %s, premisegroup_uid: %s, conclusion_uid :%s, " "argument_uid: %s, is_supportive: %s, issue: %s", db_user.nickname, premisegroup_uid, conclusion_uid, argument_uid, is_supportive, db_issue.uid) new_argument = DBDiscussionSession.query(Argument).filter( Argument.premisegroup_uid == premisegroup_uid, Argument.is_supportive == is_supportive, Argument.conclusion_uid == conclusion_uid, Argument.issue_uid == db_issue.uid).first() if not new_argument: new_argument = Argument(premisegroup=premisegroup_uid, is_supportive=is_supportive, author=db_user.uid, issue=db_issue.uid, conclusion=conclusion_uid) new_argument.set_conclusions_argument(argument_uid) DBDiscussionSession.add(new_argument) DBDiscussionSession.flush() new_argument = DBDiscussionSession.query(Argument).filter( Argument.premisegroup_uid == premisegroup_uid, Argument.is_supportive == is_supportive, Argument.author_uid == db_user.uid, Argument.conclusion_uid == conclusion_uid, Argument.argument_uid == argument_uid, Argument.issue_uid == db_issue.uid).first() transaction.commit() if new_argument: LOG.debug("Argument was inserted") return new_argument else: LOG.debug("Argument was not inserted") return None
def __create_argument_by_uids(db_user: User, premisegroup_uid, conclusion_uid, argument_uid, is_supportive, db_issue: Issue) -> Union[Argument, None]: """ Connects the given id's to a new argument :param db_user: User.nickname :param premisegroup_uid: PremiseGroup.uid :param conclusion_uid: Statement.uid :param argument_uid: Argument.uid :param is_supportive: Boolean :param db_issue: Issue :return: """ logger('StatementsHelper', 'main with user: '******', premisegroup_uid: ' + str(premisegroup_uid) + ', conclusion_uid: ' + str(conclusion_uid) + ', argument_uid: ' + str(argument_uid) + ', is_supportive: ' + str(is_supportive) + ', issue: ' + str(db_issue.uid)) new_argument = DBDiscussionSession.query(Argument).filter(Argument.premisegroup_uid == premisegroup_uid, Argument.is_supportive == is_supportive, Argument.conclusion_uid == conclusion_uid, Argument.issue_uid == db_issue.uid).first() if not new_argument: new_argument = Argument(premisegroup=premisegroup_uid, is_supportive=is_supportive, author=db_user.uid, issue=db_issue.uid, conclusion=conclusion_uid) new_argument.set_conclusions_argument(argument_uid) DBDiscussionSession.add(new_argument) DBDiscussionSession.flush() # TODO This should be redundant code! new_argument should be the new argument new_argument = DBDiscussionSession.query(Argument).filter(Argument.premisegroup_uid == premisegroup_uid, Argument.is_supportive == is_supportive, Argument.author_uid == db_user.uid, Argument.conclusion_uid == conclusion_uid, Argument.argument_uid == argument_uid, Argument.issue_uid == db_issue.uid).first() transaction.commit() if new_argument: logger('StatementsHelper', 'argument was inserted') return new_argument else: logger('StatementsHelper', 'argument was not inserted') return None