Search in sources :

Example 6 with User

use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.

the class CreateNotificationJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    ApplicationNotificationDAO applicationNotificationDAO = DAOFactory.getInstance().getApplicationNotificationDAO();
    UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
    String line = requestContext.getString("line");
    ApplicationState state = ApplicationState.valueOf(requestContext.getString("state"));
    Set<User> users = new HashSet<>();
    int rowCount = requestContext.getInteger("usersTable.rowCount");
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "usersTable." + i;
        Long userId = requestContext.getLong(colPrefix + ".userId");
        User user = userDAO.findById(userId);
        users.add(user);
    }
    ApplicationNotification applicationNotification = applicationNotificationDAO.create(line, state);
    applicationNotificationDAO.setUsers(applicationNotification, users);
    requestContext.setRedirectURL(requestContext.getRequest().getContextPath() + "/applications/editnotification.page?notification=" + applicationNotification.getId());
}
Also used : ApplicationNotification(fi.otavanopisto.pyramus.domainmodel.application.ApplicationNotification) User(fi.otavanopisto.pyramus.domainmodel.users.User) ApplicationNotificationDAO(fi.otavanopisto.pyramus.dao.application.ApplicationNotificationDAO) UserDAO(fi.otavanopisto.pyramus.dao.users.UserDAO) ApplicationState(fi.otavanopisto.pyramus.domainmodel.application.ApplicationState) HashSet(java.util.HashSet)

Example 7 with User

use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.

the class CoursesService method createCourse.

public CourseEntity createCourse(@WebParam(name = "moduleId") Long moduleId, @WebParam(name = "name") String name, @WebParam(name = "nameExtension") String nameExtension, @WebParam(name = "subjectId") Long subjectId, @WebParam(name = "courseNumber") Integer courseNumber, @WebParam(name = "beginDate") Date beginDate, @WebParam(name = "endDate") Date endDate, @WebParam(name = "courseLength") Double courseLength, @WebParam(name = "courseLengthTimeUnitId") Long courseLengthTimeUnitId, @WebParam(name = "description") String description, @WebParam(name = "creatingUserId") Long creatingUserId) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    CourseComponentDAO componentDAO = DAOFactory.getInstance().getCourseComponentDAO();
    CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
    CourseEducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getCourseEducationTypeDAO();
    CourseEducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getCourseEducationSubtypeDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
    Module module = moduleId == null ? null : moduleDAO.findById(moduleId);
    Subject subject = subjectId == null ? null : subjectDAO.findById(subjectId);
    EducationalTimeUnit courseLengthTimeUnit = courseLengthTimeUnitId == null ? null : educationalTimeUnitDAO.findById(courseLengthTimeUnitId);
    User creatingUser = userDAO.findById(creatingUserId);
    if (module != null) {
        name = name == null ? module.getName() : name;
        subject = subject == null ? module.getSubject() : subject;
        courseNumber = courseNumber == null ? module.getCourseNumber() : courseNumber;
        if (courseLength == null && module.getCourseLength() != null) {
            courseLength = module.getCourseLength().getUnits();
            courseLengthTimeUnit = module.getCourseLength().getUnit();
        }
        description = description == null ? module.getDescription() : description;
    }
    CourseState state = defaultsDAO.getDefaults().getInitialCourseState();
    CourseType type = null;
    // Course creation
    Course course = courseDAO.create(module, name, nameExtension, state, type, subject, courseNumber, beginDate, endDate, courseLength, courseLengthTimeUnit, null, null, null, null, null, null, description, null, null, null, null, creatingUser);
    validateEntity(course);
    if (module != null) {
        // Course Description copying from module to course
        descriptionDAO.copy(module, course);
        // Curriculums
        courseDAO.updateCurriculums(course, new HashSet<Curriculum>(module.getCurriculums()));
        // Components
        List<ModuleComponent> moduleComponents = module.getModuleComponents();
        if (moduleComponents != null) {
            for (ModuleComponent moduleComponent : moduleComponents) {
                EducationalLength educationalLength = moduleComponent.getLength();
                CourseComponent courseComponent = componentDAO.create(course, educationalLength == null ? null : educationalLength.getUnits(), educationalLength == null ? null : educationalLength.getUnit(), moduleComponent.getName(), moduleComponent.getDescription());
                validateEntity(courseComponent);
            }
        }
        // Education types
        List<CourseEducationType> typesInModule = module.getCourseEducationTypes();
        if (typesInModule != null) {
            for (CourseEducationType typeInModule : typesInModule) {
                CourseEducationType typeInCourse = educationTypeDAO.create(course, typeInModule.getEducationType());
                validateEntity(typeInCourse);
                // Education subtypes
                List<CourseEducationSubtype> subTypesInModule = typeInModule.getCourseEducationSubtypes();
                if (subTypesInModule != null) {
                    for (CourseEducationSubtype subtypeInModule : subTypesInModule) {
                        CourseEducationSubtype courseEducationSubtype = educationSubtypeDAO.create(typeInCourse, subtypeInModule.getEducationSubtype());
                        validateEntity(courseEducationSubtype);
                    }
                }
            }
        }
    }
    return EntityFactoryVault.buildFromDomainObject(course);
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) CourseType(fi.otavanopisto.pyramus.domainmodel.courses.CourseType) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) EducationalLength(fi.otavanopisto.pyramus.domainmodel.base.EducationalLength) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseEducationTypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) CourseEducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationSubtypeDAO) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) ModuleComponent(fi.otavanopisto.pyramus.domainmodel.modules.ModuleComponent) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module)

Example 8 with User

use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.

the class FileService method uploadStudentFile.

@WebMethod
public void uploadStudentFile(@WebParam(name = "studentId") Long studentId, @WebParam(name = "name") String name, @WebParam(name = "fileName") String fileName, @WebParam(name = "fileTypeId") Long fileTypeId, @WebParam(name = "contentType") String contentType, @WebParam(name = "creatorId") Long creatorId, @WebParam(name = "content") DataHandler content) {
    StudentFileDAO studentFileDAO = DAOFactory.getInstance().getStudentFileDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    Student student = studentDAO.findById(studentId);
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    FileTypeDAO fileTypeDAO = DAOFactory.getInstance().getFileTypeDAO();
    User creator = creatorId != null ? userDAO.findById(creatorId) : null;
    FileType fileType = fileTypeId != null ? fileTypeDAO.findById(fileTypeId) : null;
    byte[] data = null;
    try {
        InputStream inputStream = content.getInputStream();
        data = IOUtils.toByteArray(inputStream);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    studentFileDAO.create(student, name, fileName, null, fileType, contentType, data, creator);
}
Also used : StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) FileTypeDAO(fi.otavanopisto.pyramus.dao.file.FileTypeDAO) StudentFileDAO(fi.otavanopisto.pyramus.dao.file.StudentFileDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) FileType(fi.otavanopisto.pyramus.domainmodel.file.FileType) InputStream(java.io.InputStream) IOException(java.io.IOException) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) WebMethod(javax.jws.WebMethod)

Example 9 with User

use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.

the class ModulesService method createModule.

public ModuleEntity createModule(@WebParam(name = "name") String name, @WebParam(name = "subjectId") Long subjectId, @WebParam(name = "courseNumber") Integer courseNumber, @WebParam(name = "moduleLength") Double moduleLength, @WebParam(name = "moduleLengthTimeUnitId") Long moduleLengthTimeUnitId, @WebParam(name = "description") String description, @WebParam(name = "creatingUserId") Long creatingUserId) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    Subject subject = subjectDAO.findById(subjectId);
    User creatingUser = userDAO.findById(creatingUserId);
    EducationalTimeUnit moduleLengthTimeUnit = moduleLengthTimeUnitId == null ? null : educationalTimeUnitDAO.findById(moduleLengthTimeUnitId);
    Module module = moduleDAO.create(name, subject, courseNumber, moduleLength, moduleLengthTimeUnit, description, null, creatingUser);
    validateEntity(module);
    return EntityFactoryVault.buildFromDomainObject(module);
}
Also used : StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)

Example 10 with User

use of fi.otavanopisto.pyramus.domainmodel.users.User in project pyramus by otavanopisto.

the class OpenIDAuthorizationStrategy method processResponse.

@SuppressWarnings("unchecked")
public User processResponse(RequestContext requestContext) throws AuthenticationException {
    UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
    try {
        HttpSession session = requestContext.getRequest().getSession();
        // extract the parameters from the authentication response
        // (which comes in as a HTTP request from the OpenID provider)
        ParameterList openidResp = new ParameterList(requestContext.getRequest().getParameterMap());
        // retrieve the previously stored discovery information
        DiscoveryInformation discovered = (DiscoveryInformation) session.getAttribute("discovered");
        // extract the receiving URL from the HTTP request
        StringBuffer receivingURL = requestContext.getRequest().getRequestURL();
        String queryString = requestContext.getRequest().getQueryString();
        if (queryString != null && queryString.length() > 0) {
            receivingURL.append("?").append(requestContext.getRequest().getQueryString());
        }
        // verify the response
        VerificationResult verification = consumerManager.verify(receivingURL.toString(), openidResp, discovered);
        // examine the verification result and extract the verified identifier
        Identifier verified = verification.getVerifiedId();
        if (verified != null) {
            AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse();
            List<String> emails = null;
            if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
                FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);
                emails = fetchResp.getAttributeValues("email");
            }
            UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
            User user = userDAO.findByExternalIdAndAuthProvider(verified.getIdentifier(), getName());
            if (user == null) {
                user = userDAO.findByEmail(emails.get(0));
                if (user != null) {
                    String expectedLoginServer = userVariableDAO.findByUserAndKey(user, "openid.expectedlogin");
                    String loginServer = verification.getAuthResponse().getParameterValue("openid.op_endpoint");
                    if (!StringUtils.isBlank(expectedLoginServer) && expectedLoginServer.equals(loginServer)) {
                        userVariableDAO.setUserVariable(user, "openid.expectedlogin", null);
                        userDAO.updateExternalId(user, verified.getIdentifier());
                    } else {
                        throw new AuthenticationException(AuthenticationException.LOCAL_USER_MISSING);
                    }
                } else {
                    throw new AuthenticationException(AuthenticationException.LOCAL_USER_MISSING);
                }
            }
            return user;
        } else {
            return null;
        }
    } catch (MessageException e) {
        throw new SmvcRuntimeException(e);
    } catch (DiscoveryException e) {
        throw new SmvcRuntimeException(e);
    } catch (AssociationException e) {
        throw new SmvcRuntimeException(e);
    }
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) AuthenticationException(fi.otavanopisto.pyramus.plugin.auth.AuthenticationException) HttpSession(javax.servlet.http.HttpSession) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) FetchResponse(org.openid4java.message.ax.FetchResponse) Identifier(org.openid4java.discovery.Identifier) UserDAO(fi.otavanopisto.pyramus.dao.users.UserDAO) VerificationResult(org.openid4java.consumer.VerificationResult) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) MessageException(org.openid4java.message.MessageException) DiscoveryInformation(org.openid4java.discovery.DiscoveryInformation) AuthSuccess(org.openid4java.message.AuthSuccess) ParameterList(org.openid4java.message.ParameterList) AssociationException(org.openid4java.association.AssociationException) DiscoveryException(org.openid4java.discovery.DiscoveryException)

Aggregations

User (fi.otavanopisto.pyramus.domainmodel.users.User)107 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)43 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)29 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)28 Path (javax.ws.rs.Path)28 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)24 Date (java.util.Date)23 UserDAO (fi.otavanopisto.pyramus.dao.users.UserDAO)22 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)21 HashSet (java.util.HashSet)18 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)15 StudentGroup (fi.otavanopisto.pyramus.domainmodel.students.StudentGroup)15 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)14 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)14 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)14 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)13 Organization (fi.otavanopisto.pyramus.domainmodel.base.Organization)12 StudentGroupUser (fi.otavanopisto.pyramus.domainmodel.students.StudentGroupUser)12 GET (javax.ws.rs.GET)12 DefaultsDAO (fi.otavanopisto.pyramus.dao.base.DefaultsDAO)11