Search in sources :

Example 11 with Defaults

use of fi.otavanopisto.pyramus.domainmodel.base.Defaults in project pyramus by otavanopisto.

the class CourseStudentAPI method create.

public Long create(Long courseId, Long studentId) throws InvalidScriptException {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    Defaults defaults = DAOFactory.getInstance().getDefaultsDAO().getDefaults();
    Course course = courseDAO.findById(courseId);
    if (course == null) {
        throw new InvalidScriptException("Course #" + courseId + " not found.");
    }
    Student student = studentDAO.findById(studentId);
    if (student == null) {
        throw new InvalidScriptException("Student #" + studentId + " not found.");
    }
    Room room = null;
    BigDecimal lodgingFee = null;
    Currency lodgingFeeCurrency = null;
    BigDecimal reservationFee = null;
    Currency reservationFeeCurrency = null;
    String organization = null;
    String additionalInfo = null;
    try {
        return courseStudentDAO.create(course, student, defaults.getInitialCourseEnrolmentType(), defaults.getInitialCourseParticipationType(), new Date(), false, CourseOptionality.OPTIONAL, null, organization, additionalInfo, room, lodgingFee, lodgingFeeCurrency, reservationFee, reservationFeeCurrency, Boolean.FALSE).getId();
    } catch (DuplicateCourseStudentException dcse) {
        throw new InvalidScriptException("Student #" + studentId + " has an already existing coursestudent.");
    }
}
Also used : DuplicateCourseStudentException(fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException) InvalidScriptException(fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) Defaults(fi.otavanopisto.pyramus.domainmodel.base.Defaults) Currency(java.util.Currency) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) Room(fi.otavanopisto.pyramus.domainmodel.accommodation.Room)

Example 12 with Defaults

use of fi.otavanopisto.pyramus.domainmodel.base.Defaults in project pyramus by otavanopisto.

the class UserUtils method hasManagementOrganizationAccess.

public static boolean hasManagementOrganizationAccess(User user) {
    if (user == null) {
        return false;
    }
    if (user.getRole() == Role.ADMINISTRATOR) {
        return true;
    } else {
        DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
        Defaults defaults = defaultsDAO.getDefaults();
        Long managementOrganizationId = defaults.getOrganization() != null ? defaults.getOrganization().getId() : null;
        Long userOrganizationId = (user != null && user.getOrganization() != null) ? user.getOrganization().getId() : null;
        if (managementOrganizationId != null && Objects.equals(userOrganizationId, managementOrganizationId)) {
            return true;
        }
    }
    return false;
}
Also used : Defaults(fi.otavanopisto.pyramus.domainmodel.base.Defaults) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO)

Example 13 with Defaults

use of fi.otavanopisto.pyramus.domainmodel.base.Defaults in project pyramus by otavanopisto.

the class AdminPasswordSetupWizardViewController method save.

@Override
public void save(PageRequestContext requestContext) throws SetupWizardException {
    String username = requestContext.getString("username");
    String password = requestContext.getString("password1");
    String firstName = requestContext.getString("firstName");
    String lastName = requestContext.getString("lastName");
    String passwordMD5 = DigestUtils.md5Hex(password);
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    InternalAuthDAO internalAuthDAO = DAOFactory.getInstance().getInternalAuthDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
    DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
    Defaults defaults = defaultsDAO.getDefaults();
    InternalAuth internalAuth = internalAuthDAO.create(username, passwordMD5);
    Person person = personDAO.create(null, null, null, null, Boolean.FALSE);
    userIdentificationDAO.create(person, "internal", String.valueOf(internalAuth.getId()));
    User user = userDAO.create(defaults.getOrganization(), firstName, lastName, Role.ADMINISTRATOR, person, false);
    personDAO.updateDefaultUser(person, user);
}
Also used : PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Defaults(fi.otavanopisto.pyramus.domainmodel.base.Defaults) User(fi.otavanopisto.pyramus.domainmodel.users.User) InternalAuthDAO(fi.otavanopisto.pyramus.dao.users.InternalAuthDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) InternalAuth(fi.otavanopisto.pyramus.domainmodel.users.InternalAuth) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) UserIdentificationDAO(fi.otavanopisto.pyramus.dao.users.UserIdentificationDAO)

Aggregations

Defaults (fi.otavanopisto.pyramus.domainmodel.base.Defaults)13 DefaultsDAO (fi.otavanopisto.pyramus.dao.base.DefaultsDAO)9 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)5 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)5 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)4 User (fi.otavanopisto.pyramus.domainmodel.users.User)4 StudyProgrammeDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO)3 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)3 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)3 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)3 Room (fi.otavanopisto.pyramus.domainmodel.accommodation.Room)3 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)3 StudentGroupUser (fi.otavanopisto.pyramus.domainmodel.students.StudentGroupUser)3 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)3 BigDecimal (java.math.BigDecimal)3 Currency (java.util.Currency)3 Date (java.util.Date)3 Path (javax.ws.rs.Path)3 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)2 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)2