Search in sources :

Example 96 with User

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

the class EditNotificationJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    ApplicationNotificationDAO applicationNotificationDAO = DAOFactory.getInstance().getApplicationNotificationDAO();
    UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
    Long notificationId = requestContext.getLong("notificationId");
    ApplicationNotification applicationNotification = applicationNotificationDAO.findById(notificationId);
    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 = applicationNotificationDAO.update(applicationNotification, 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 97 with User

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

the class CreateStudentGroupJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
    StudentGroupStudentDAO studentGroupStudentDAO = DAOFactory.getInstance().getStudentGroupStudentDAO();
    StudentGroupUserDAO studentGroupUserDAO = DAOFactory.getInstance().getStudentGroupUserDAO();
    TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
    OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
    // StudentGroup basic information
    String name = requestContext.getString("name");
    String description = requestContext.getString("description");
    Date beginDate = requestContext.getDate("beginDate");
    String tagsText = requestContext.getString("tags");
    Boolean guidanceGroup = requestContext.getBoolean("guidanceGroup");
    Set<Tag> tagEntities = new HashSet<>();
    if (!StringUtils.isBlank(tagsText)) {
        List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
        for (String tag : tags) {
            if (!StringUtils.isBlank(tag)) {
                Tag tagEntity = tagDAO.findByText(tag.trim());
                if (tagEntity == null)
                    tagEntity = tagDAO.create(tag);
                tagEntities.add(tagEntity);
            }
        }
    }
    User loggedUser = staffMemberDAO.findById(requestContext.getLoggedUserId());
    Organization organization = organizationDAO.findById(requestContext.getLong("organizationId"));
    if (!UserUtils.canAccessOrganization(loggedUser, organization)) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Invalid organization.");
    }
    StudentGroup studentGroup = studentGroupDAO.create(organization, name, description, beginDate, loggedUser, guidanceGroup);
    // Tags
    studentGroupDAO.setStudentGroupTags(studentGroup, tagEntities);
    // Personnel
    int rowCount = requestContext.getInteger("usersTable.rowCount");
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "usersTable." + i;
        Long userId = requestContext.getLong(colPrefix + ".userId");
        StaffMember staffMember = staffMemberDAO.findById(userId);
        studentGroupUserDAO.create(studentGroup, staffMember, loggedUser);
    }
    // Students
    int studentsTableRowCount = requestContext.getInteger("studentsTable.rowCount");
    for (int i = 0; i < studentsTableRowCount; i++) {
        String colPrefix = "studentsTable." + i;
        Long studentId = requestContext.getLong(colPrefix + ".studentId");
        Student student = studentDAO.findById(studentId);
        studentGroupStudentDAO.create(studentGroup, student, loggedUser);
    }
    String redirectURL = requestContext.getRequest().getContextPath() + "/students/editstudentgroup.page?studentgroup=" + studentGroup.getId();
    String refererAnchor = requestContext.getRefererAnchor();
    if (!StringUtils.isBlank(refererAnchor))
        redirectURL += "#" + refererAnchor;
    requestContext.setRedirectURL(redirectURL);
}
Also used : StudentGroupUserDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupUserDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Date(java.util.Date) StudentGroupStudentDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupStudentDAO) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) StudentGroupDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupDAO) StudentGroupStudentDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupStudentDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup) HashSet(java.util.HashSet)

Example 98 with User

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

the class CreateStudentJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    StudentActivityTypeDAO activityTypeDAO = DAOFactory.getInstance().getStudentActivityTypeDAO();
    StudentExaminationTypeDAO examinationTypeDAO = DAOFactory.getInstance().getStudentExaminationTypeDAO();
    StudentEducationalLevelDAO educationalLevelDAO = DAOFactory.getInstance().getStudentEducationalLevelDAO();
    StudentStudyEndReasonDAO studyEndReasonDAO = DAOFactory.getInstance().getStudentStudyEndReasonDAO();
    UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
    LanguageDAO languageDAO = DAOFactory.getInstance().getLanguageDAO();
    MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
    NationalityDAO nationalityDAO = DAOFactory.getInstance().getNationalityDAO();
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
    AddressDAO addressDAO = DAOFactory.getInstance().getAddressDAO();
    ContactInfoDAO contactInfoDAO = DAOFactory.getInstance().getContactInfoDAO();
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
    PhoneNumberDAO phoneNumberDAO = DAOFactory.getInstance().getPhoneNumberDAO();
    TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    StudentLodgingPeriodDAO lodgingPeriodDAO = DAOFactory.getInstance().getStudentLodgingPeriodDAO();
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    User loggedUser = staffMemberDAO.findById(requestContext.getLoggedUserId());
    Long personId = requestContext.getLong("personId");
    int emailCount2 = requestContext.getInteger("emailTable.rowCount");
    for (int i = 0; i < emailCount2; i++) {
        String colPrefix = "emailTable." + i;
        String email = StringUtils.trim(requestContext.getString(colPrefix + ".email"));
        if (StringUtils.isNotBlank(email)) {
            ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
            if (!UserUtils.isAllowedEmail(email, contactType, personId)) {
                throw new RuntimeException(Messages.getInstance().getText(requestContext.getRequest().getLocale(), "generic.errors.emailInUse"));
            }
        }
    }
    Date birthday = requestContext.getDate("birthday");
    String ssecId = requestContext.getString("ssecId");
    Sex sex = (Sex) requestContext.getEnum("gender", Sex.class);
    String basicInfo = requestContext.getString("basicInfo");
    Boolean secureInfo = requestContext.getBoolean("secureInfo");
    String firstName = StringUtils.trim(requestContext.getString("firstName"));
    String lastName = StringUtils.trim(requestContext.getString("lastName"));
    String nickname = StringUtils.trim(requestContext.getString("nickname"));
    String additionalInfo = requestContext.getString("additionalInfo");
    String otherContactInfo = requestContext.getString("otherContactInfo");
    String education = requestContext.getString("education");
    Double previousStudies = requestContext.getDouble("previousStudies");
    Date studyTimeEnd = requestContext.getDate("studyTimeEnd");
    Date studyStartTime = requestContext.getDate("studyStartDate");
    Date studyEndTime = requestContext.getDate("studyEndDate");
    String studyEndText = requestContext.getString("studyEndText");
    String tagsText = requestContext.getString("tags");
    Set<Tag> tagEntities = new HashSet<>();
    if (!StringUtils.isBlank(tagsText)) {
        List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
        for (String tag : tags) {
            if (!StringUtils.isBlank(tag)) {
                Tag tagEntity = tagDAO.findByText(tag.trim());
                if (tagEntity == null)
                    tagEntity = tagDAO.create(tag);
                tagEntities.add(tagEntity);
            }
        }
    }
    Long entityId = requestContext.getLong("language");
    Language language = entityId == null ? null : languageDAO.findById(entityId);
    entityId = requestContext.getLong("municipality");
    Municipality municipality = entityId == null ? null : municipalityDAO.findById(entityId);
    entityId = requestContext.getLong("activityType");
    StudentActivityType activityType = entityId == null ? null : activityTypeDAO.findById(entityId);
    entityId = requestContext.getLong("examinationType");
    StudentExaminationType examinationType = entityId == null ? null : examinationTypeDAO.findById(entityId);
    entityId = requestContext.getLong("educationalLevel");
    StudentEducationalLevel educationalLevel = entityId == null ? null : educationalLevelDAO.findById(entityId);
    entityId = requestContext.getLong("nationality");
    Nationality nationality = entityId == null ? null : nationalityDAO.findById(entityId);
    entityId = requestContext.getLong("school");
    School school = entityId != null && entityId > 0 ? schoolDAO.findById(entityId) : null;
    entityId = requestContext.getLong("studyProgramme");
    StudyProgramme studyProgramme = entityId != null && entityId > 0 ? studyProgrammeDAO.findById(entityId) : null;
    if (!UserUtils.canAccessOrganization(loggedUser, studyProgramme.getOrganization())) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Invalid studyprogramme.");
    }
    entityId = requestContext.getLong("studyEndReason");
    StudentStudyEndReason studyEndReason = entityId == null ? null : studyEndReasonDAO.findById(entityId);
    entityId = requestContext.getLong("curriculum");
    Curriculum curriculum = entityId == null ? null : curriculumDAO.findById(entityId);
    Person person = personId != null ? personDAO.findById(personId) : null;
    Person personBySSN = personDAO.findBySSN(ssecId);
    if (person == null) {
        if (personBySSN == null) {
            person = personDAO.create(birthday, ssecId, sex, basicInfo, secureInfo);
        } else {
            personDAO.update(personBySSN, birthday, ssecId, sex, basicInfo, secureInfo);
            person = personBySSN;
        }
    } else {
        personDAO.update(person, birthday, ssecId, sex, basicInfo, secureInfo);
    }
    Student student = studentDAO.create(person, firstName, lastName, nickname, additionalInfo, studyTimeEnd, activityType, examinationType, educationalLevel, education, nationality, municipality, language, school, studyProgramme, curriculum, previousStudies, studyStartTime, studyEndTime, studyEndReason, studyEndText, false);
    // Lodging periods
    Integer lodgingPeriodsCount = requestContext.getInteger("lodgingPeriodsTable.rowCount");
    if (lodgingPeriodsCount != null) {
        for (int i = 0; i < lodgingPeriodsCount; i++) {
            String colPrefix = "lodgingPeriodsTable." + i;
            Date begin = requestContext.getDate(colPrefix + ".begin");
            Date end = requestContext.getDate(colPrefix + ".end");
            lodgingPeriodDAO.create(student, begin, end);
        }
    }
    // Tags
    studentDAO.setStudentTags(student, tagEntities);
    if (person.getDefaultUser() == null) {
        personDAO.updateDefaultUser(person, student);
    }
    // Contact info
    contactInfoDAO.update(student.getContactInfo(), otherContactInfo);
    // Addresses
    int addressCount = requestContext.getInteger("addressTable.rowCount");
    for (int i = 0; i < addressCount; i++) {
        String colPrefix = "addressTable." + i;
        Boolean defaultAddress = requestContext.getBoolean(colPrefix + ".defaultAddress");
        ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
        String name = requestContext.getString(colPrefix + ".name");
        String street = requestContext.getString(colPrefix + ".street");
        String postal = requestContext.getString(colPrefix + ".postal");
        String city = requestContext.getString(colPrefix + ".city");
        String country = requestContext.getString(colPrefix + ".country");
        boolean hasAddress = name != null || street != null || postal != null || city != null || country != null;
        if (hasAddress) {
            addressDAO.create(student.getContactInfo(), contactType, name, street, postal, city, country, defaultAddress);
        }
    }
    // Email addresses
    int emailCount = requestContext.getInteger("emailTable.rowCount");
    for (int i = 0; i < emailCount; i++) {
        String colPrefix = "emailTable." + i;
        Boolean defaultAddress = requestContext.getBoolean(colPrefix + ".defaultAddress");
        ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
        String email = StringUtils.trim(requestContext.getString(colPrefix + ".email"));
        if (StringUtils.isNotBlank(email)) {
            emailDAO.create(student.getContactInfo(), contactType, defaultAddress, email);
        }
    }
    // Phone numbers
    int phoneCount = requestContext.getInteger("phoneTable.rowCount");
    for (int i = 0; i < phoneCount; i++) {
        String colPrefix = "phoneTable." + i;
        Boolean defaultNumber = requestContext.getBoolean(colPrefix + ".defaultNumber");
        ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
        String number = requestContext.getString(colPrefix + ".phone");
        if (number != null) {
            phoneNumberDAO.create(student.getContactInfo(), contactType, defaultNumber, number);
        }
    }
    // Student variables, create the defaults first and modify if modified
    userVariableDAO.createDefaultValueVariables(student);
    Integer variableCount = requestContext.getInteger("variablesTable.rowCount");
    if (variableCount != null) {
        for (int i = 0; i < variableCount; i++) {
            String colPrefix = "variablesTable." + i;
            Long edited = requestContext.getLong(colPrefix + ".edited");
            if (Objects.equals(new Long(1), edited)) {
                String variableKey = requestContext.getRequest().getParameter(colPrefix + ".key");
                String variableValue = requestContext.getRequest().getParameter(colPrefix + ".value");
                userVariableDAO.setUserVariable(student, variableKey, variableValue);
            }
        }
    }
    // Contact information of a student won't be reflected to Person
    // used when searching students, so a manual re-index is needed
    personDAO.forceReindex(student.getPerson());
    String redirectURL = requestContext.getRequest().getContextPath() + "/students/editstudent.page?person=" + student.getPerson().getId();
    String refererAnchor = requestContext.getRefererAnchor();
    if (!StringUtils.isBlank(refererAnchor)) {
        redirectURL += "#" + refererAnchor;
    }
    requestContext.setRedirectURL(redirectURL);
}
Also used : ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) StudentStudyEndReason(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StudentEducationalLevel(fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel) StudentLodgingPeriodDAO(fi.otavanopisto.pyramus.dao.students.StudentLodgingPeriodDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) MunicipalityDAO(fi.otavanopisto.pyramus.dao.base.MunicipalityDAO) StudentEducationalLevelDAO(fi.otavanopisto.pyramus.dao.students.StudentEducationalLevelDAO) HashSet(java.util.HashSet) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) StudentExaminationType(fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType) LanguageDAO(fi.otavanopisto.pyramus.dao.base.LanguageDAO) NationalityDAO(fi.otavanopisto.pyramus.dao.base.NationalityDAO) StudentActivityTypeDAO(fi.otavanopisto.pyramus.dao.students.StudentActivityTypeDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) ContactInfoDAO(fi.otavanopisto.pyramus.dao.base.ContactInfoDAO) StudentActivityType(fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) PhoneNumberDAO(fi.otavanopisto.pyramus.dao.base.PhoneNumberDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) Sex(fi.otavanopisto.pyramus.domainmodel.students.Sex) StudentStudyEndReasonDAO(fi.otavanopisto.pyramus.dao.students.StudentStudyEndReasonDAO) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) AddressDAO(fi.otavanopisto.pyramus.dao.base.AddressDAO) StudentExaminationTypeDAO(fi.otavanopisto.pyramus.dao.students.StudentExaminationTypeDAO) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO) Date(java.util.Date) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag)

Example 99 with User

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

the class AccessLoggingFilter method doFilter.

/**
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
 *      javax.servlet.FilterChain)
 */
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
    if (!disabled) {
        try {
            HttpServletRequest request = (HttpServletRequest) req;
            AccessLogEntryDAO accessLogEntryDAO = DAOFactory.getInstance().getAccessLogEntryDAO();
            String requestURI = request.getRequestURI();
            if (requestURI != null) {
                if (requestURI.endsWith(".page") || requestURI.endsWith(".json") || requestURI.endsWith(".binary")) {
                    AccessLogEntryPath path = getPath(requestURI);
                    if (path.getActive()) {
                        User user = getUser(request);
                        String ip = request.getRemoteAddr();
                        String parameters = request.getQueryString();
                        accessLogEntryDAO.create(user, ip, new Date(), path, parameters);
                    }
                }
            }
        } catch (Exception ex) {
            Logging.logException("AccessLoggingFilter exception", ex);
        }
    }
    chain.doFilter(req, resp);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AccessLogEntryDAO(fi.otavanopisto.pyramus.dao.accesslog.AccessLogEntryDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) AccessLogEntryPath(fi.otavanopisto.pyramus.domainmodel.accesslog.AccessLogEntryPath) Date(java.util.Date) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 100 with User

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

the class SearchStudentGroupsJSONRequestController method process.

/**
 * Processes the request to search student groups.
 *
 * @param jsonRequestContext The JSON request context
 */
public void process(JSONRequestContext requestContext) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
    // Determine the number of results shown per page. If not defined, default to ten results per page
    Integer resultsPerPage = NumberUtils.createInteger(requestContext.getRequest().getParameter("maxResults"));
    if (resultsPerPage == null)
        resultsPerPage = 10;
    // Determine the result page to be shown. If not defined, default to the first page
    Integer page = NumberUtils.createInteger(requestContext.getRequest().getParameter("page"));
    if (page == null) {
        page = 0;
    }
    SearchResult<StudentGroup> searchResult;
    StaffMember loggedUser = userDAO.findById(requestContext.getLoggedUserId());
    Organization organization = UserUtils.canAccessAllOrganizations(loggedUser) ? null : loggedUser.getOrganization();
    if ("advanced".equals(requestContext.getRequest().getParameter("activeTab"))) {
        String name = requestContext.getRequest().getParameter("name");
        String description = requestContext.getRequest().getParameter("description");
        String tags = requestContext.getString("tags");
        if (!StringUtils.isBlank(tags))
            tags = tags.replace(',', ' ');
        Long userId = requestContext.getLong("user");
        User user = null;
        if ((userId != null ? userId.intValue() : -1) > -1)
            user = userDAO.findById(userId);
        Date timeframeStart = null;
        String value = requestContext.getRequest().getParameter("timeframeStart");
        if (NumberUtils.isNumber(value)) {
            timeframeStart = new Date(NumberUtils.createLong(value));
        }
        Date timeframeEnd = null;
        value = requestContext.getRequest().getParameter("timeframeEnd");
        if (NumberUtils.isNumber(value)) {
            timeframeEnd = new Date(NumberUtils.createLong(value));
        }
        searchResult = studentGroupDAO.searchStudentGroups(resultsPerPage, page, organization, name, tags, description, user, timeframeStart, timeframeEnd, true);
    } else {
        String text = requestContext.getRequest().getParameter("text");
        searchResult = studentGroupDAO.searchStudentGroupsBasic(resultsPerPage, page, organization, text);
    }
    List<Map<String, Object>> results = new ArrayList<>();
    List<StudentGroup> studentGroups = searchResult.getResults();
    for (StudentGroup studentGroup : studentGroups) {
        Map<String, Object> info = new HashMap<>();
        info.put("id", studentGroup.getId());
        info.put("name", studentGroup.getName());
        if (studentGroup.getBeginDate() != null) {
            info.put("beginDate", studentGroup.getBeginDate().getTime());
        }
        results.add(info);
    }
    String statusMessage;
    Locale locale = requestContext.getRequest().getLocale();
    if (searchResult.getTotalHitCount() > 0) {
        statusMessage = Messages.getInstance().getText(locale, "students.searchStudentGroups.searchStatus", new Object[] { searchResult.getFirstResult() + 1, searchResult.getLastResult() + 1, searchResult.getTotalHitCount() });
    } else {
        statusMessage = Messages.getInstance().getText(locale, "students.searchStudentGroups.searchStatusNoMatches");
    }
    requestContext.addResponseParameter("results", results);
    requestContext.addResponseParameter("statusMessage", statusMessage);
    requestContext.addResponseParameter("pages", searchResult.getPages());
    requestContext.addResponseParameter("page", searchResult.getPage());
}
Also used : Locale(java.util.Locale) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) User(fi.otavanopisto.pyramus.domainmodel.users.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) Date(java.util.Date) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) StudentGroupDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupDAO) HashMap(java.util.HashMap) Map(java.util.Map) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup)

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