Ejemplo n.º 1
0
    def delete_success(self):
        oid = subject_bll.insert("Asignatura Muy Nueva", "AMN", 6, 3,
                                 "Obligatoria", 1, 1)
        subject = subject_dal.get_by_name("Asignatura Muy Nueva")

        if subject is None:
            raise BLLException("The subject was not created")

        subject_bll.delete(oid)

        subject = subject_dal.get_by_name("Asignatura Muy Nueva")
        if subject is not None:
            raise BLLException("The subject hasn't been deleted")
Ejemplo n.º 2
0
    def update_success(self):
        subject_list = subject_dal.get_all()
        old_subject = subject_list[0]
        oid = old_subject["subjectId"]

        subject_bll.update(oid, "Asignatura Muy Nueva", "AMN", 12, 1,
                           "Obligatoria", 1, 1)

        subject = subject_dal.get_by_name(old_subject["name"])
        if subject is not None:
            raise BLLException(
                "The subject has the same name as before the change")

        subject = subject_dal.get_by_name("Asignatura Muy Nueva")
        if subject is None:
            raise BLLException("The subject has not got the new name")
Ejemplo n.º 3
0
def insert(
    name: str,
    acronym: str,
    n_credits: int,
    course: int,
    subject_type: str,
    degree_id: int,
    department_id: int,
) -> int:
    """Insert a new subject"""

    check_not_null(name, "The subject's name cannot be empty")
    check_not_null(acronym, "The subject's acronym cannot be empty")
    check_not_null(n_credits, "The subject's credits cannot be empty")
    check_not_null(course, "The subject's course cannot be empty")
    check_not_null(subject_type, "The subject's subject type cannot be empty")
    check_not_null(degree_id, "The subject's degree_id cannot be empty")
    check_not_null(department_id,
                   "The subject's department_id cannot be empty")

    check_field_is_enum(
        subject_type,
        {"Formacion Basica", "Optativa", "Obligatoria"},
        f"The field 'subject_type' must be one of ('Formacion Basica', 'Optativa', 'Obligatoria')",
    )

    # Insert the new subject
    try:
        oid = subject_dal.insert(name, acronym, n_credits, course,
                                 subject_type, degree_id, department_id)
    except DALException as exc:
        raise BLLException(exc) from exc

    return oid
Ejemplo n.º 4
0
def bussines_law_14(category: str, department_id: int):
    professors = professor_dal.get_by_department(department_id)
    c = Counter([professor["category"] for professor in professors])
    c[category] += 1
    if c["CU"] + c["TU"] <= c["PCD"] + c["PAD"]:
        raise BLLException(
            "en cada departamento se tiene que cumplir que #CU+#TU > #PCD+#PAD"
        )
Ejemplo n.º 5
0
def delete(oid: int) -> int:
    """Delete a group"""
    check_oid_exists(oid)

    try:
        res = group_dal.delete(oid)
    except DALException as exc:
        raise BLLException(exc) from exc

    return res
Ejemplo n.º 6
0
def delete(oid: int) -> int:
    """Delete a department"""
    check_oid_exists(oid)

    try:
        res = department_dal.delete(oid)
    except DALException as exc:
        raise BLLException(exc) from exc

    return res
Ejemplo n.º 7
0
def insert(name: str) -> int:
    """Insert a new department"""

    check_not_null(name, "The subject's name cannot be empty")

    # Insert the new department
    try:
        oid = department_dal.insert(name)
    except DALException as exc:
        raise BLLException(exc) from exc

    return oid
Ejemplo n.º 8
0
def update(oid: int, name: str) -> int:
    """Update a department"""

    check_oid_exists(oid)
    check_not_null(name, "The department's name cannot be empty")

    try:
        new_oid = department_dal.update(oid, name)
    except DALException as exc:
        raise BLLException(exc) from exc

    return new_oid
Ejemplo n.º 9
0
def update(
    oid: int,
    office_id: int,
    department_id: int,
    category: str,
    dni: str,
    first_name: str,
    surname: str,
    birth_date: str,
    email: str,
) -> int:
    """Update a professor"""

    check_oid_exists(oid)
    check_not_null(office_id, "The group's office_id cannot be empty")
    check_not_null(department_id, "The group's department_id cannot be empty")
    check_not_null(category, "The group's category cannot be empty")
    check_not_null(dni, "The group's dni cannot be empty")
    check_not_null(first_name, "The group's first_name cannot be empty")
    check_not_null(surname, "The group's surname cannot be empty")
    check_not_null(birth_date, "The group's birth_date cannot be empty")
    check_not_null(email, "The group's email cannot be empty")

    check_field_is_enum(
        category,
        {"CU", "TU", "PCD", "PAD"},
        f"The field 'category' must be one of ('CU', 'TU', 'PCD', 'PAD')",
    )

    check_dni(dni)
    check_dni_exists(dni, oid)
    check_email_exists(dni, oid)
    bussines_law_14(category, department_id)

    try:
        new_oid = professor_dal.update(
            oid,
            office_id,
            department_id,
            category,
            dni,
            first_name,
            surname,
            birth_date,
            email,
        )

    except DALException as exc:
        raise BLLException(exc) from exc

    return new_oid
Ejemplo n.º 10
0
def insert(professorId: int, groupId: int, credits: int) -> int:
    """Insert a new group"""

    check_not_null(professorId, "The group's professorId cannot be empty")
    check_not_null(groupId, "The group's groupId cannot be empty")
    check_not_null(credits, "The group's credits cannot be empty")

    # Insert the new group
    try:
        oid = teaching_loads_dal.insert(professorId, groupId, credits)
        bussines_law_13(professorId, groupId)
    except DALException as exc:
        raise BLLException(exc) from exc

    return oid
Ejemplo n.º 11
0
def update(oid: int, professorId: int, groupId: int, credits: int) -> int:
    """Update a group"""

    check_oid_exists(oid)
    check_not_null(professorId, "The group's name cannot be empty")
    check_not_null(groupId, "The group's activity cannot be empty")
    check_not_null(credits, "The group's year cannot be empty")

    try:
        new_oid = teaching_loads_dal.update(oid, professorId, groupId, credits)
        bussines_law_13(professorId, groupId)
    except DALException as exc:
        raise BLLException(exc) from exc

    return new_oid
Ejemplo n.º 12
0
def insert(name: str, activity: str, year: int, subjectId: int,
           classroomId: int) -> int:
    """Insert a new group"""

    check_not_null(name, "The group's name cannot be empty")
    check_not_null(activity, "The group's activity cannot be empty")
    check_not_null(year, "The group's year cannot be empty")
    check_not_null(subjectId, "The group's subjectId cannot be empty")
    check_not_null(classroomId, "The group's classroomId cannot be empty")

    # Insert the new group
    try:
        oid = group_dal.insert(name, activity, year, subjectId, classroomId)
    except DALException as exc:
        raise BLLException(exc) from exc

    return oid
Ejemplo n.º 13
0
def bussines_law_13(professor_id: int, group_id: int) -> None:
    """En un año académico un profesor no puede impartir docencia en más de 5 grupos."""
    year = group_dal.get_by_oid(group_id)["year"]

    teaching_loads_by_professor_id = teaching_loads_dal.get_by_professor_id(
        professor_id)

    groups_id_by_year = {
        group["groupId"]
        for group in group_dal.get_by_year(year)
    }

    counter = 0
    for teaching_load in teaching_loads_by_professor_id:
        if teaching_load["groupId"] in groups_id_by_year:
            counter += 1

        if counter > 5:
            raise BLLException(
                "En un año académico un profesor no puede impartir docencia en más de 5 grupos"
            )
Ejemplo n.º 14
0
def update(
    oid: int,
    name: str,
    activity: str,
    year: int,
    subjectId: int,
    classroomId: int,
) -> int:
    """Update a group"""

    check_oid_exists(oid)
    check_not_null(name, "The group's name cannot be empty")
    check_not_null(activity, "The group's activity cannot be empty")
    check_not_null(year, "The group's year cannot be empty")
    check_not_null(subjectId, "The group's subjectId cannot be empty")
    check_not_null(classroomId, "The group's classroomId cannot be empty")

    try:
        new_oid = group_dal.update(oid, name, activity, year, subjectId,
                                   classroomId)
    except DALException as exc:
        raise BLLException(exc) from exc

    return new_oid
Ejemplo n.º 15
0
def check_name_exists(name: str) -> None:
    if subject_dal.get_by_name(name):
        raise BLLException("There must be no subject with the same name")
Ejemplo n.º 16
0
def check_oid_exists(oid: int) -> None:
    """Check that there exists a group with the provided OID"""

    subj = group_dal.get_by_oid(oid)
    if subj is None:
        raise BLLException(f"Cannot find a group with oid {oid}")
Ejemplo n.º 17
0
def check_not_null(value, msg: str):
    if value is None or (isinstance(value, str) and value.strip() == ""):
        raise BLLException(msg)
Ejemplo n.º 18
0
def check_field_is_enum(value, iterable, msg: str):
    if value not in iterable:
        raise BLLException(msg)
Ejemplo n.º 19
0
def check_acronym_exists(acronym: str) -> None:
    if subject_dal.get_by_acronym(acronym):
        raise BLLException("There must be no subject with the same acronym")