Search in sources :

Example 1 with InvalidScriptException

use of fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException in project pyramus by otavanopisto.

the class CourseAPI method create.

public Long create(Long organizationId, Long moduleId, Long typeId, String name, String nameExtension, String description, String subjectCode) throws InvalidScriptException {
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
    CourseTypeDAO courseTypeDAO = DAOFactory.getInstance().getCourseTypeDAO();
    OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
    Module module = moduleDAO.findById(moduleId);
    if (module == null) {
        throw new InvalidScriptException("Module #" + moduleId + " not found.");
    }
    User loggedUser = userDAO.findById(loggedUserId);
    if (loggedUser == null) {
        throw new InvalidScriptException("Logged user not found.");
    }
    Subject subject = subjectDAO.findByCode(subjectCode);
    if (subject == null) {
        throw new InvalidScriptException("Subject by code '" + subjectCode + "' not found.");
    }
    Organization organization = organizationDAO.findById(organizationId);
    if (organization == null) {
        throw new InvalidScriptException("Default organization not found.");
    }
    CourseType type = typeId != null ? courseTypeDAO.findById(typeId) : null;
    // TODO: Add support for these:
    CourseState courseState = defaultsDAO.getDefaults().getInitialCourseState();
    Date beginDate = null;
    Date endDate = null;
    Double distanceTeachingDays = null;
    Double localTeachingDays = null;
    Double teachingHours = null;
    Double distanceTeachingHours = null;
    Double planningHours = null;
    Double assessingHours = null;
    Date enrolmentTimeEnd = null;
    BigDecimal courseFee = null;
    Currency courseFeeCurrency = null;
    return courseDAO.create(module, organization, name, nameExtension, courseState, type, subject, module.getCourseNumber(), beginDate, endDate, module.getCourseLength().getUnits(), module.getCourseLength().getUnit(), distanceTeachingDays, localTeachingDays, teachingHours, distanceTeachingHours, planningHours, assessingHours, description, module.getMaxParticipantCount(), courseFee, courseFeeCurrency, enrolmentTimeEnd, loggedUser).getId();
}
Also used : CourseTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseTypeDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) InvalidScriptException(fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) Date(java.util.Date) BigDecimal(java.math.BigDecimal) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Currency(java.util.Currency) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) CourseType(fi.otavanopisto.pyramus.domainmodel.courses.CourseType) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO)

Example 2 with InvalidScriptException

use of fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException in project pyramus by otavanopisto.

the class CourseAPI method getVariable.

public String getVariable(Long courseId, String key) throws InvalidScriptException {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    CourseBaseVariableDAO courseBaseVariableDAO = DAOFactory.getInstance().getCourseBaseVariableDAO();
    Course course = courseDAO.findById(courseId);
    if (course == null) {
        throw new InvalidScriptException(String.format("Course #%d could not be found", courseId));
    }
    return courseBaseVariableDAO.findByCourseAndVariableKey(course, key);
}
Also used : InvalidScriptException(fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseBaseVariableDAO(fi.otavanopisto.pyramus.dao.base.CourseBaseVariableDAO) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course)

Example 3 with InvalidScriptException

use of fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException in project pyramus by otavanopisto.

the class StudentGroupStudentAPI method create.

public Long create(Long studentId, Long studentGroupId) throws InvalidScriptException {
    User loggedUser = DAOFactory.getInstance().getStaffMemberDAO().findById(loggedUserId);
    if (loggedUser == null) {
        throw new InvalidScriptException("Logged user could not be found");
    }
    Student student = DAOFactory.getInstance().getStudentDAO().findById(studentId);
    if (student == null) {
        throw new InvalidScriptException("Could not find student #" + studentId);
    }
    StudentGroup studentGroup = DAOFactory.getInstance().getStudentGroupDAO().findById(studentGroupId);
    if (studentGroup == null) {
        throw new InvalidScriptException("Could not find student group #" + studentGroupId);
    }
    return (DAOFactory.getInstance().getStudentGroupStudentDAO()).create(studentGroup, student, loggedUser).getId();
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) InvalidScriptException(fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup)

Example 4 with InvalidScriptException

use of fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException in project pyramus by otavanopisto.

the class StudyProgrammeAPI method create.

public Long create(String name, Long categoryId, String code, Long organizationId, boolean hasEvaluationFees) throws InvalidScriptException {
    OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
    StudyProgrammeCategory category = null;
    if (categoryId != null) {
        category = DAOFactory.getInstance().getStudyProgrammeCategoryDAO().findById(categoryId);
        if (category == null) {
            throw new InvalidScriptException("StudyProgrammeCategory #" + categoryId + " not found.");
        }
    }
    Organization organization = organizationId != null ? organizationDAO.findById(organizationId) : null;
    if (organization == null) {
        throw new InvalidScriptException("Organization not found.");
    }
    return (DAOFactory.getInstance().getStudyProgrammeDAO().create(organization, name, category, code, hasEvaluationFees).getId());
}
Also used : Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) StudyProgrammeCategory(fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory) InvalidScriptException(fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO)

Example 5 with InvalidScriptException

use of fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException in project pyramus by otavanopisto.

the class ModuleAPI method create.

public Long create(String name, String description, Long maxParticipantCount, String subjectCode, Integer courseNumber) throws InvalidScriptException {
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
    Subject subject = subjectDAO.findByCode(subjectCode);
    if (subject == null) {
        throw new InvalidScriptException("Subject by code '" + subjectCode + "' not found.");
    }
    User loggedUser = userDAO.findById(loggedUserId);
    if (loggedUser == null) {
        throw new InvalidScriptException("Logged user not found.");
    }
    EducationalTimeUnit timeUnit = defaultsDAO.getDefaults().getBaseTimeUnit();
    return moduleDAO.create(name, subject, courseNumber, 0d, timeUnit, description, maxParticipantCount, loggedUser).getId();
}
Also used : StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) InvalidScriptException(fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)

Aggregations

InvalidScriptException (fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException)18 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)6 User (fi.otavanopisto.pyramus.domainmodel.users.User)6 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)5 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)5 OrganizationDAO (fi.otavanopisto.pyramus.dao.base.OrganizationDAO)4 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)4 Organization (fi.otavanopisto.pyramus.domainmodel.base.Organization)4 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)4 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)3 SubjectDAO (fi.otavanopisto.pyramus.dao.base.SubjectDAO)3 ModuleDAO (fi.otavanopisto.pyramus.dao.modules.ModuleDAO)3 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)3 DAOFactory (fi.otavanopisto.pyramus.dao.DAOFactory)2 ContactTypeDAO (fi.otavanopisto.pyramus.dao.base.ContactTypeDAO)2 CourseBaseVariableDAO (fi.otavanopisto.pyramus.dao.base.CourseBaseVariableDAO)2 DefaultsDAO (fi.otavanopisto.pyramus.dao.base.DefaultsDAO)2 EmailDAO (fi.otavanopisto.pyramus.dao.base.EmailDAO)2 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)2 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)2