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();
}
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);
}
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();
}
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());
}
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();
}
Aggregations