示例#1
0
def create_project(name, account_id_team_leader, account_id_secretary,
                   account_id_session, token):
    """
    Create new project

    :param name: Name
    :type name: str
    :param account_id_team_leader: Account id of the project team leader
    :type account_id_team_leader: int
    :param account_id_secretary: Account id of the project secretary
    :type account_id_secretary: int
    :param account_id_session: Account id of the session
    :type account_id_session: int
    :param token: Session token
    :type token: str

    :rtype: None
    """

    if account_id_session in tokens and tokens[account_id_session] == token:
        project = Project(None, name, account_id_team_leader,
                          account_id_secretary)
        db_session.add(project)

        project._account_id_team_leader = account_id_team_leader
        project._account_id_secretary = account_id_secretary

        try:
            db_session.commit()
        except:
            return None, 500

        return None, 201

    return None, 401
示例#2
0
def createProject(postRequest: POSTProjects):
    """
    Handler function to create a new Project.

    Creates a new Project and initializes the project directory.
    It does this by cloning the repository specified in the request to the 
    general project directory specified in the radonCTTConfig
    """
    r = Response()

    if not postRequest.repository_url:
        r = Response(response='No repository url specified',
                     status='422',
                     mimetype="text/xml")
        r.headers["Content-Type"] = "text/xml; charset=utf-8"
        return r

    if not postRequest.servicetemplate_location:
        r = Response(response='No servicetemplate location specified',
                     status='422',
                     mimetype='text/xml')
        r.headers['Content-Type'] = 'text/xml; charset=utf-8'
        return r

    try:
        # --------------------------------------|
        # OBJECT CREATION
        newProject = Project(
            status='WAITING',
            repository_url=postRequest.repository_url,
            servicetemplate_location=postRequest.servicetemplate_location,
            project_path='NaN')
        databaseSession.add(newProject)
        databaseSession.flush()

        # --------------------------------------|
        # IMPORT OPERATION
        importation.run(newProject)
        # --------------------------------------|

        r = Response(response=json.dumps(newProject.to_dict()),
                     status='201',
                     mimetype="text/json")
        r.headers["Content-Type"] = "application/json; charset=utf-8"

        databaseSession.commit()
    except:
        databaseSession.rollback()
        raise
    finally:
        databaseSession.remove()

    return r
示例#3
0
def list_projects(account_id_session, token):
    """
    List projects
    
    :param account_id_session: Account id of the session
    :type account_id_session: int
    :param token: Session token
    :type token: str

    :rtype: Projects
    """

    if account_id_session in tokens and tokens[account_id_session] == token:
        projects = db_session.query(Project).all()

        projectsList = []

        if projects is None:
            return projectsList, 200

        for project in projects:
            p = Project(project_id=project.project_id,
                        project_name=project.project_name,
                        account_id_team_leader=project.account_id_team_leader,
                        account_id_secretary=project.account_id_secretary)
            projectsList.append(p)
        return projectsList, 200

    return None, 401
    def test_create_project(self):
        """Test case for create_project

        
        """
        name = Project()
        response = self.client.open('//project/',
                                    method='POST',
                                    data=json.dumps(name),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
def projects_put(project):
    """
    You shouldn't put the entire List
    
    :param project: The project you want to update
    :type project: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        project = Project.from_dict(connexion.request.get_json())
    return 'do some magic!'
    def test_assign_mentor(self):
        """Test case for assign_mentor

        
        """
        user_proj_id = Project()
        response = self.client.open('//project/assignMentor/',
                                    method='POST',
                                    data=json.dumps(user_proj_id),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
def projects_post(project):
    """
    Create a new project
    
    :param project: The project you want to create
    :type project: dict | bytes

    :rtype: Message
    """
    if connexion.request.is_json:
        project = Project.from_dict(connexion.request.get_json())
    return 'do some magic!'
    def test_projects_post(self):
        """
        Test case for projects_post

        Create a new project
        """
        project = Project()
        response = self.client.open('/project-tracker/projects',
                                    method='POST',
                                    data=json.dumps(project),
                                    content_type='application/json')
        self.assert200(response,
                       "Response body is : " + response.data.decode('utf-8'))
示例#9
0
def assign_mentor(user_proj_id=None):  # noqa: E501
    """assign_mentor

    Assign a project mentor to a project. # noqa: E501

    :param user_proj_id: ID of project and user
    :type user_proj_id: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        user_proj_id = Project.from_dict(connexion.request.get_json())  # noqa: E501
    return 'do some magic!'
示例#10
0
def create_project(name=None):  # noqa: E501
    """create_project

    Create a project # noqa: E501

    :param name: Name of project
    :type name: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        name = Project.from_dict(connexion.request.get_json())  # noqa: E501
    return 'do some magic!'
    def test_projects_put(self):
        """
        Test case for projects_put

        You shouldn't put the entire List
        """
        project = Project()
        response = self.client.open('/project-tracker/projects',
                                    method='PUT',
                                    data=json.dumps(project),
                                    content_type='application/json')
        self.assert200(response,
                       "Response body is : " + response.data.decode('utf-8'))
    def test_project_post(self):
        """Test case for project_post

        project_post
        """
        body = Project()
        response = self.client.open(
            '//project',
            method='POST',
            data=json.dumps(body),
            content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
def projects_id_put(id, project):
    """
    update an existing project
    
    :param id: The project id
    :type id: float
    :param project: the project you want to update
    :type project: dict | bytes

    :rtype: Message
    """
    if connexion.request.is_json:
        project = Project.from_dict(connexion.request.get_json())
    return 'do some magic!'
    def test_projects_id_put(self):
        """
        Test case for projects_id_put

        update an existing project
        """
        project = Project()
        response = self.client.open(
            '/project-tracker/projects/{id}'.format(id=3.4),
            method='PUT',
            data=json.dumps(project),
            content_type='application/json')
        self.assert200(response,
                       "Response body is : " + response.data.decode('utf-8'))
示例#15
0
def run(project: Project):
    """
    Runs the import operation on the given Project

    Args:
    - project (Project): The Project you wish to run the import operation on
    """

    #Get the project path
    projectPath = f"{radonCTTConfig['PATHS']['Project_Dir']}{project.id}{os.path.sep}"

    #Create the directory for the new project
    directory = os.path.dirname(projectPath)
    if not os.path.exists(directory):
        os.makedirs(directory)

    #Copy the SUT into it
    repo = Repo.clone_from(project.repository_url, projectPath)

    #Save Project path in Project resource
    project.project_path = projectPath
    databaseSession.flush()
示例#16
0
def project_project_id_patch(projectId):  # noqa: E501
    """返回一个Project的详细信息

    # noqa: E501

    :param projectId:
    :type projectId: int

    :rtype: Learner
    """

    db_session = None
    if "DEVMODE" in os.environ:
        if os.environ["DEVMODE"] == "True":
            db_session = orm.init_db(os.environ["DEV_DATABASEURI"])
        else:
            db_session = orm.init_db(os.environ["DATABASEURI"])
    else:
        db_session = orm.init_db(os.environ["DATABASEURI"])
    validation_result = wxLogin.validateUser()
    if not validation_result["result"]:
        db_session.remove()
        return {"error": "Failed to validate access token"}, 401
    learner = db_session.query(orm.Learner_db).filter(
        orm.Learner_db.openid == validation_result["openid"]).one_or_none()
    if not learner.validated:
        db_session.remove()
        return {"error": "Learner not validated"}, 401
    project = db_session.query(
        orm.Project_db).filter(orm.Project_db.id == projectId).one_or_none()
    if connexion.request.is_json:
        patch = Project.from_dict(connexion.request.get_json())
    patchDict = {
        "name":
        patch.name,
        "status":
        patch.status,
        "projectTerm":
        patch.project_term,
        "projectTermLength":
        patch.project_term_length,
        "projectStartDate":
        patch.project_start_date,
        "averageIntendedCreditHourPerWeek":
        patch.average_intended_credit_hour_per_week,
        "totalIntendedCreditHour":
        patch.total_intended_credit_hour,
        "projectMentorID":
        patch.project_mentor_id,
        "projectMentor":
        patch.project_mentor,
        "averageGuidingHourPerWeek":
        patch.average_guiding_hour_per_week,
        "projectMeta":
        json.dumps(connexion.request.get_json()["projectMeta"] if patch.
                   project_meta is not None else None),
        "projectApprovalInfo":
        json.dumps(connexion.request.get_json()["projectApprovalInfo"]
                   if patch.project_approval_info is not None else None),
        "content":
        json.dumps(connexion.request.get_json()["content"] if patch.
                   content is not None else None),
        "conclusionInfo":
        json.dumps(connexion.request.get_json()["conclusionInfo"] if patch.
                   conclusion_info is not None else None),
        "coverImageURL":
        connexion.request.get_json().get("coverImageURL", ""),
    }
    patchDict = {k: v for k, v in patchDict.items() if v is not None}
    # patchMapper = {
    #     "name": project.name,
    #     "status": project.status,
    #     "projectTerm": project.projectTerm,
    #     "projectTermLength": project.projectTermLength,
    #     "projectStartDate": project.projectStartDate,
    #     "averageIntendedCreditHourPerWeek": project.averageIntendedCreditHourPerWeek,
    #     "totalIntendedCreditHour": project.totalIntendedCreditHour,
    #     "projectMentorID": project.projectMentorID,
    #     "projectMentor": project.projectMentor,
    #     "averageGuidingHourPerWeek": project.averageGuidingHourPerWeek,
    #     "projectMeta": project.projectMeta,
    #     "projectApprovalInfo": project.projectApprovalInfo,
    #     "content": project.content,
    #     "conclusionInfo": project.conclusionInfo,
    #     "lastUpdatedTime": project.lastUpdatedTime,
    # }
    try:
        for item, value in patchDict.items():
            setattr(project, item, value)
        db_session.commit()
    except Exception as e:
        db_session.remove()
        return {"error": str(e)}, 401
    db_session.remove()
    return {}, 200, {
        "Authorization": validation_result["access_token"],
        "refresh_token": validation_result["refresh_token"]
    }
示例#17
0
def project_post(project):  # noqa: E501
    """创建一个Learner

    # noqa: E501

    :param learner:
    :type learner: dict | bytes

    :rtype: InlineResponse201
    """
    db_session = None
    if "DEVMODE" in os.environ:
        if os.environ["DEVMODE"] == "True":
            db_session = orm.init_db(os.environ["DEV_DATABASEURI"])
        else:
            db_session = orm.init_db(os.environ["DATABASEURI"])
    else:
        db_session = orm.init_db(os.environ["DATABASEURI"])
    validation_result = wxLogin.validateUser()
    if not validation_result["result"]:
        db_session.remove()
        return {"error": "Failed to validate access token"}, 401
    learner = db_session.query(orm.Learner_db).filter(
        orm.Learner_db.openid == validation_result["openid"]).one_or_none()
    if not learner.validated:
        db_session.remove()
        return {"error": "Learner not validated"}, 401
    if connexion.request.is_json:
        project = Project.from_dict(connexion.request.get_json())
    project_dict = connexion.request.get_json()
    try:
        db_session.add(
            orm.Project_db(
                name=project.name,
                status="未提交",
                createdTime=datetime.date.today().strftime('%Y-%m-%d'),
                createdByID=learner.id,
                createdBy=learner.familyName + learner.givenName,
                relatedCourseId=project.related_course_id,
                relatedCourse=project.related_course,
                projectTerm=project.project_term,
                projectTermLength=project.project_term_length,
                projectStartDate=project.project_start_date,
                averageIntendedCreditHourPerWeek=project.
                average_intended_credit_hour_per_week,
                totalIntendedCreditHour=project.total_intended_credit_hour,
                projectMentorID=project.project_mentor_id,
                projectMentor=project.project_mentor,
                averageGuidingHourPerWeek=project.
                average_guiding_hour_per_week,
                projectMeta=json.dumps(project_dict["projectMeta"]),
                projectApprovalInfo=json.dumps(
                    project_dict["projectApprovalInfo"]),
                conclusionInfo=json.dumps(project_dict["conclusionInfo"]),
                content='[]',
                coverImageURL=project_dict["coverImageURL"]))
        db_session.commit()
    except Exception as e:
        db_session.remove()
        return {"error": str(e)}, 401
    db_session.remove()
    return {}, 201, {
        "Authorization": validation_result["access_token"],
        "refresh_token": validation_result["refresh_token"]
    }