Search in sources :

Example 1 with Organization

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

the class EditCourseJSONRequestController method processSignupStudentGroups.

private void processSignupStudentGroups(JSONRequestContext requestContext, Course course, StaffMember loggedUser) {
    CourseSignupStudentGroupDAO courseSignupStudentGroupDAO = DAOFactory.getInstance().getCourseSignupStudentGroupDAO();
    StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
    List<CourseSignupStudentGroup> signupStudentGroups = courseSignupStudentGroupDAO.listByCourse(course);
    Integer studentGroupsRowCount = requestContext.getInteger("signupStudentGroupsTable.rowCount");
    if (studentGroupsRowCount != null) {
        Set<Long> studentGroupIdsPresent = new HashSet<>();
        for (int i = 0; i < studentGroupsRowCount; i++) {
            Long studentGroupId = requestContext.getLong(String.format("signupStudentGroupsTable.%d.studentGroupId", i));
            if (studentGroupId != null) {
                studentGroupIdsPresent.add(studentGroupId);
            }
        }
        // Create missing groups
        studentGroupIdsPresent.forEach(studentGroupId -> {
            if (signupStudentGroups.stream().noneMatch(signupStudentGroup -> Objects.equals(signupStudentGroup.getStudentGroup().getId(), studentGroupId))) {
                StudentGroup studentGroup = studentGroupDAO.findById(studentGroupId);
                if ((studentGroup != null) && UserUtils.canAccessOrganization(loggedUser, studentGroup.getOrganization())) {
                    courseSignupStudentGroupDAO.create(course, studentGroup);
                } else {
                    throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Invalid organization.");
                }
            }
        });
        // Remove groups that don't exist anymore
        signupStudentGroups.stream().filter(signupStudentGroup -> !studentGroupIdsPresent.contains(signupStudentGroup.getStudentGroup().getId())).forEach(signupStudentGroup -> {
            if (UserUtils.canAccessOrganization(loggedUser, signupStudentGroup.getStudentGroup().getOrganization())) {
                courseSignupStudentGroupDAO.delete(signupStudentGroup);
            } else {
                throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Invalid organization.");
            }
        });
    }
}
Also used : CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) CourseSignupStudyProgramme(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudyProgramme) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) Enumeration(java.util.Enumeration) UserUtils(fi.otavanopisto.pyramus.framework.UserUtils) Date(java.util.Date) BasicCourseResource(fi.otavanopisto.pyramus.domainmodel.courses.BasicCourseResource) OtherCost(fi.otavanopisto.pyramus.domainmodel.courses.OtherCost) JSONRequestContext(fi.internetix.smvc.controllers.JSONRequestContext) GradeCourseResource(fi.otavanopisto.pyramus.domainmodel.courses.GradeCourseResource) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) OtherCostDAO(fi.otavanopisto.pyramus.dao.courses.OtherCostDAO) BigDecimal(java.math.BigDecimal) Vector(java.util.Vector) CourseComponentResourceDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentResourceDAO) CourseParticipationTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseParticipationTypeDAO) Locale(java.util.Locale) Map(java.util.Map) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) CourseEducationTypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) UserRole(fi.otavanopisto.pyramus.framework.UserRole) CourseDescriptionCategory(fi.otavanopisto.pyramus.domainmodel.courses.CourseDescriptionCategory) CourseSignupStudentGroup(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudentGroup) CourseStaffMemberRoleDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberRoleDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentGroupDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupDAO) StaleObjectStateException(org.hibernate.StaleObjectStateException) CourseSignupStudentGroupDAO(fi.otavanopisto.pyramus.dao.courses.CourseSignupStudentGroupDAO) DuplicateCourseStudentException(fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException) Set(java.util.Set) GradeCourseResourceDAO(fi.otavanopisto.pyramus.dao.courses.GradeCourseResourceDAO) PyramusStatusCode(fi.otavanopisto.pyramus.framework.PyramusStatusCode) Messages(fi.otavanopisto.pyramus.I18N.Messages) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) Objects(java.util.Objects) List(java.util.List) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType) CourseEnrolmentTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseEnrolmentTypeDAO) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) StudentCourseResourceDAO(fi.otavanopisto.pyramus.dao.courses.StudentCourseResourceDAO) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Resource(fi.otavanopisto.pyramus.domainmodel.resources.Resource) CourseStaffMemberRole(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMemberRole) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) CourseStateDAO(fi.otavanopisto.pyramus.dao.courses.CourseStateDAO) CourseDescription(fi.otavanopisto.pyramus.domainmodel.courses.CourseDescription) ResourceType(fi.otavanopisto.pyramus.domainmodel.resources.ResourceType) HashMap(java.util.HashMap) Currency(java.util.Currency) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseSignupStudyProgrammeDAO(fi.otavanopisto.pyramus.dao.courses.CourseSignupStudyProgrammeDAO) CourseTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseTypeDAO) StudentCourseResource(fi.otavanopisto.pyramus.domainmodel.courses.StudentCourseResource) MonetaryAmount(fi.otavanopisto.pyramus.persistence.usertypes.MonetaryAmount) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) HashSet(java.util.HashSet) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) BasicCourseResourceDAO(fi.otavanopisto.pyramus.dao.courses.BasicCourseResourceDAO) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) JSONRequestController(fi.otavanopisto.pyramus.framework.JSONRequestController) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) Room(fi.otavanopisto.pyramus.domainmodel.accommodation.Room) Role(fi.otavanopisto.pyramus.domainmodel.users.Role) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO) ResourceDAO(fi.otavanopisto.pyramus.dao.resources.ResourceDAO) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO) CourseComponentResource(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponentResource) CourseType(fi.otavanopisto.pyramus.domainmodel.courses.CourseType) EducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) CourseEnrolmentType(fi.otavanopisto.pyramus.domainmodel.courses.CourseEnrolmentType) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) CourseDescriptionCategoryDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionCategoryDAO) CourseEducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationSubtypeDAO) DAOFactory(fi.otavanopisto.pyramus.dao.DAOFactory) StudentGroupDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupDAO) CourseSignupStudentGroupDAO(fi.otavanopisto.pyramus.dao.courses.CourseSignupStudentGroupDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) CourseSignupStudentGroupDAO(fi.otavanopisto.pyramus.dao.courses.CourseSignupStudentGroupDAO) CourseSignupStudentGroup(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudentGroup) CourseSignupStudentGroup(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudentGroup) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup) HashSet(java.util.HashSet)

Example 2 with Organization

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

the class UsersService method updateUser.

public void updateUser(@WebParam(name = "userId") Long userId, @WebParam(name = "firstName") String firstName, @WebParam(name = "lastName") String lastName, @WebParam(name = "role") String role) {
    StaffMemberDAO staffDAO = DAOFactory.getInstance().getStaffMemberDAO();
    StaffMember user = staffDAO.findById(userId);
    Role userRole = EnumType.valueOf(Role.class, role);
    Organization organization = user.getOrganization();
    staffDAO.update(user, organization, firstName, lastName, userRole);
    validateEntity(user);
}
Also used : Role(fi.otavanopisto.pyramus.domainmodel.users.Role) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember)

Example 3 with Organization

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

the class UsersService method createUser.

public UserEntity createUser(@WebParam(name = "firstName") String firstName, @WebParam(name = "lastName") String lastName, @WebParam(name = "externalId") String externalId, @WebParam(name = "authProvider") String authProvider, @WebParam(name = "role") String role) {
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
    // TODO: should not create if user exists
    Person person = personDAO.create(null, null, null, null, Boolean.FALSE);
    userIdentificationDAO.create(person, authProvider, externalId);
    Role userRole = EnumType.valueOf(Role.class, role);
    // TODO organization
    Organization organization = null;
    StaffMember staffMember = staffMemberDAO.create(organization, firstName, lastName, userRole, person, false);
    personDAO.updateDefaultUser(person, staffMember);
    validateEntity(staffMember);
    return EntityFactoryVault.buildFromDomainObject(staffMember);
}
Also used : Role(fi.otavanopisto.pyramus.domainmodel.users.Role) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) UserIdentificationDAO(fi.otavanopisto.pyramus.dao.users.UserIdentificationDAO)

Example 4 with Organization

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

the class StudentGroupsAutoCompleteBinaryRequestController method process.

/**
 * Processes a binary request.
 * The request should contain the following parameters:
 * <dl>
 *   <dt><code>text</code></dt>
 *   <dd>Already typed characters.</dd>
 * </dl>
 *
 * @param binaryRequestContext The context of the binary request.
 */
public void process(BinaryRequestContext binaryRequestContext) {
    StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    String text = binaryRequestContext.getString("text");
    StringBuilder resultBuilder = new StringBuilder();
    resultBuilder.append("<ul>");
    if (!StringUtils.isBlank(text)) {
        text = QueryParser.escape(StringUtils.trim(text)) + '*';
        StaffMember loggedUser = staffMemberDAO.findById(binaryRequestContext.getLoggedUserId());
        Organization organization = UserUtils.canAccessAllOrganizations(loggedUser) ? null : loggedUser.getOrganization();
        List<StudentGroup> studentGroups = studentGroupDAO.searchStudentGroupsBasic(100, 0, organization, text).getResults();
        for (StudentGroup studentGroup : studentGroups) {
            addResult(resultBuilder, studentGroup);
        }
    }
    resultBuilder.append("</ul>");
    try {
        binaryRequestContext.setResponseContent(resultBuilder.toString().getBytes("UTF-8"), "text/html;charset=UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new SmvcRuntimeException(e);
    }
}
Also used : StudentGroupDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup)

Example 5 with Organization

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

the class DebugDataViewController method process.

public void process(PageRequestContext requestContext) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
    ResourceCategoryDAO resourceCategoryDAO = DAOFactory.getInstance().getResourceCategoryDAO();
    MaterialResourceDAO materialResourceDAO = DAOFactory.getInstance().getMaterialResourceDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
    String type = requestContext.getRequest().getParameter("type");
    int count = Integer.parseInt(requestContext.getRequest().getParameter("count"));
    int start = 1;
    String s = requestContext.getRequest().getParameter("start");
    if (!StringUtils.isBlank(s)) {
        start = Integer.parseInt(s);
    }
    User user = userDAO.findById(requestContext.getLoggedUserId());
    if ("module".equals(type)) {
        for (int i = start; i < (start + count); i++) {
            EducationalTimeUnit etu = educationalTimeUnitDAO.findById(new Long(1));
            moduleDAO.create("Moduli " + i, null, null, new Double(10), etu, "KuvaustekstiƤ modulille " + i, null, user);
        }
    } else if ("course".equals(type)) {
        for (int i = start; i < (start + count); i++) {
            EducationalTimeUnit etu = educationalTimeUnitDAO.findById(new Long(1));
            CourseState courseState = courseStateDAO.findById(new Long(1));
            Organization organization = organizationDAO.findById(1L);
            courseDAO.create(moduleDAO.findById(new Long(1)), organization, "Kurssi " + i, "", courseState, null, null, null, null, null, new Double(10), etu, null, null, null, null, null, null, "KuvaustekstiƤ kurssille " + i, null, null, null, null, user);
        }
    } else if ("resource".equals(type)) {
        for (int i = start; i < (start + count); i++) {
            ResourceCategory resourceCategory = resourceCategoryDAO.findById(new Long(1));
            materialResourceDAO.create("Materiaaliresurssi " + i, resourceCategory, new Double(500));
        }
    } else if ("project".equals(type)) {
        for (int i = start; i < (start + count); i++) {
            EducationalTimeUnit etu = educationalTimeUnitDAO.findById(new Long(1));
            projectDAO.create("Projekti " + i, "KuvaustekstiƤ projektille " + i, new Double(10), etu, user);
        }
    } else if ("student".equals(type)) {
        for (int i = start; i < (start + count); i++) {
            Person person = personDAO.create(new Date(), "030310-123R", Sex.MALE, null, Boolean.FALSE);
            studentDAO.create(person, "Etunimi " + i, "Sukunimi " + i, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, false);
        }
    }
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) ResourceCategoryDAO(fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO) ResourceCategory(fi.otavanopisto.pyramus.domainmodel.resources.ResourceCategory) Date(java.util.Date) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) CourseStateDAO(fi.otavanopisto.pyramus.dao.courses.CourseStateDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) MaterialResourceDAO(fi.otavanopisto.pyramus.dao.resources.MaterialResourceDAO) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)

Aggregations

Organization (fi.otavanopisto.pyramus.domainmodel.base.Organization)41 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)24 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)23 OrganizationDAO (fi.otavanopisto.pyramus.dao.base.OrganizationDAO)22 Date (java.util.Date)14 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)13 User (fi.otavanopisto.pyramus.domainmodel.users.User)13 StudentGroup (fi.otavanopisto.pyramus.domainmodel.students.StudentGroup)12 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)11 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)11 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)11 HashSet (java.util.HashSet)11 Path (javax.ws.rs.Path)11 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)10 EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)10 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)10 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)10 HashMap (java.util.HashMap)9 EducationTypeDAO (fi.otavanopisto.pyramus.dao.base.EducationTypeDAO)8 ArrayList (java.util.ArrayList)8