Search in sources :

Example 1 with StudentContactLogEntryDAO

use of fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryDAO in project pyramus by otavanopisto.

the class ManageStudentContactEntriesViewController method process.

/**
 * Processes the page request.
 *
 * In parameters
 * - person
 *
 * Page parameters
 * - person - Person object
 * - contactEntries - List of StudentContactLogEntry objects
 *
 * @param pageRequestContext pageRequestContext
 */
public void process(PageRequestContext pageRequestContext) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    StudentContactLogEntryDAO logEntryDAO = DAOFactory.getInstance().getStudentContactLogEntryDAO();
    StudentContactLogEntryCommentDAO entryCommentDAO = DAOFactory.getInstance().getStudentContactLogEntryCommentDAO();
    Long personId = pageRequestContext.getLong("person");
    Person person = personDAO.findById(personId);
    pageRequestContext.getRequest().setAttribute("person", person);
    List<Student> students = studentDAO.listByPerson(person);
    Collections.sort(students, new Comparator<Student>() {

        @Override
        public int compare(Student o1, Student o2) {
            /**
             * Ordering study programmes as follows
             *  1. studies that have start date but no end date (ongoing)
             *  2. studies that have no start nor end date
             *  3. studies that have ended
             *  4. studies that are archived
             */
            int o1class = (o1.getArchived()) ? 4 : (o1.getStudyStartDate() != null && o1.getStudyEndDate() == null) ? 1 : (o1.getStudyStartDate() == null && o1.getStudyEndDate() == null) ? 2 : (o1.getStudyEndDate() != null) ? 3 : 5;
            int o2class = (o2.getArchived()) ? 4 : (o2.getStudyStartDate() != null && o2.getStudyEndDate() == null) ? 1 : (o2.getStudyStartDate() == null && o2.getStudyEndDate() == null) ? 2 : (o2.getStudyEndDate() != null) ? 3 : 5;
            if (o1class == o2class) {
                // classes are the same, we try to do last comparison from the start dates
                return ((o1.getStudyStartDate() != null) && (o2.getStudyStartDate() != null)) ? o1.getStudyStartDate().compareTo(o2.getStudyStartDate()) : 0;
            } else
                return o1class < o2class ? -1 : o1class == o2class ? 0 : 1;
        }
    });
    Map<Long, List<StudentContactLogEntry>> contactEntries = new HashMap<>();
    final Map<Long, List<StudentContactLogEntryComment>> contactEntryComments = new HashMap<>();
    for (int i = 0; i < students.size(); i++) {
        Student student = students.get(i);
        List<StudentContactLogEntry> listStudentContactEntries = logEntryDAO.listByStudent(student);
        for (int j = 0; j < listStudentContactEntries.size(); j++) {
            StudentContactLogEntry entry = listStudentContactEntries.get(j);
            List<StudentContactLogEntryComment> listComments = entryCommentDAO.listByEntry(entry);
            Collections.sort(listComments, new Comparator<StudentContactLogEntryComment>() {

                public int compare(StudentContactLogEntryComment o1, StudentContactLogEntryComment o2) {
                    Date d1 = o1.getCommentDate();
                    Date d2 = o2.getCommentDate();
                    int val = d1 == null ? d2 == null ? 0 : 1 : d2 == null ? -1 : d1.compareTo(d2);
                    if (val == 0)
                        return o1.getId().compareTo(o2.getId());
                    else
                        return val;
                }
            });
            contactEntryComments.put(entry.getId(), listComments);
        }
        // Now we can sort entries based on date of entry and/or dates of the comments on the entry
        Collections.sort(listStudentContactEntries, new Comparator<StudentContactLogEntry>() {

            private Date getDateForEntry(StudentContactLogEntry entry) {
                Date d = entry.getEntryDate();
                List<StudentContactLogEntryComment> comments = contactEntryComments.get(entry.getId());
                for (int i = 0; i < comments.size(); i++) {
                    StudentContactLogEntryComment comment = comments.get(i);
                    if (d == null) {
                        d = comment.getCommentDate();
                    } else {
                        if (d.before(comment.getCommentDate()))
                            d = comment.getCommentDate();
                    }
                }
                return d;
            }

            public int compare(StudentContactLogEntry o1, StudentContactLogEntry o2) {
                Date d1 = getDateForEntry(o1);
                Date d2 = getDateForEntry(o2);
                int val = d1 == null ? d2 == null ? 0 : 1 : d2 == null ? -1 : d2.compareTo(d1);
                if (val == 0)
                    return o2.getId().compareTo(o1.getId());
                else
                    return val;
            }
        });
        contactEntries.put(student.getId(), listStudentContactEntries);
    }
    pageRequestContext.getRequest().setAttribute("students", students);
    pageRequestContext.getRequest().setAttribute("contactEntries", contactEntries);
    pageRequestContext.getRequest().setAttribute("contactEntryComments", contactEntryComments);
    pageRequestContext.setIncludeJSP("/templates/students/managestudentcontactentries.jsp");
}
Also used : HashMap(java.util.HashMap) StudentContactLogEntryDAO(fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryDAO) StudentContactLogEntry(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntry) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Date(java.util.Date) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) StudentContactLogEntryComment(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntryComment) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) StudentContactLogEntryCommentDAO(fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryCommentDAO) List(java.util.List) Person(fi.otavanopisto.pyramus.domainmodel.base.Person)

Example 2 with StudentContactLogEntryDAO

use of fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryDAO in project pyramus by otavanopisto.

the class ArchiveContactEntryJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    StudentContactLogEntryDAO entryDAO = DAOFactory.getInstance().getStudentContactLogEntryDAO();
    Long entryId = requestContext.getLong("entryId");
    StudentContactLogEntry entry = entryDAO.findById(entryId);
    entryDAO.archive(entry);
}
Also used : StudentContactLogEntryDAO(fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryDAO) StudentContactLogEntry(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntry)

Example 3 with StudentContactLogEntryDAO

use of fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryDAO in project pyramus by otavanopisto.

the class CreateContactEntryCommentJSONRequestController method process.

/**
 * Method to process JSON requests.
 *
 * In parameters
 * - entryId - Id to identify the entry where the comment is being bind into
 * - commentText - Textual message or description about the contact
 * - commentCreatorName - Name of the person who made the contact
 * - commentDate - Date of the entry
 *
 * Page parameters
 * - results Map including
 * * id - New comment id
 * * entryId - Entry id
 * * creatorName - Comment creator
 * * timestamp - Comment date
 * * text - Comment message
 *
 * @param jsonRequestContext JSON request context
 */
public void process(JSONRequestContext jsonRequestContext) {
    StudentContactLogEntryDAO logEntryDAO = DAOFactory.getInstance().getStudentContactLogEntryDAO();
    StudentContactLogEntryCommentDAO entryCommentDAO = DAOFactory.getInstance().getStudentContactLogEntryCommentDAO();
    try {
        Long entryId = jsonRequestContext.getLong("entryId");
        StudentContactLogEntry entry = logEntryDAO.findById(entryId);
        String commentText = jsonRequestContext.getRequest().getParameter("commentText");
        String commentCreatorName = jsonRequestContext.getRequest().getParameter("commentCreatorName");
        Date commentDate = new Date(NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("commentDate")));
        StudentContactLogEntryComment comment = entryCommentDAO.create(entry, commentText, commentDate, commentCreatorName);
        Map<String, Object> info = new HashMap<>();
        info.put("id", comment.getId());
        info.put("creatorName", comment.getCreatorName());
        info.put("timestamp", comment.getCommentDate().getTime());
        info.put("text", comment.getText());
        info.put("entryId", entryId);
        jsonRequestContext.addResponseParameter("results", info);
    } catch (Exception e) {
        throw new SmvcRuntimeException(e);
    }
}
Also used : StudentContactLogEntryComment(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntryComment) StudentContactLogEntryCommentDAO(fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryCommentDAO) HashMap(java.util.HashMap) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StudentContactLogEntryDAO(fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryDAO) StudentContactLogEntry(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntry) Date(java.util.Date) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException)

Example 4 with StudentContactLogEntryDAO

use of fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryDAO in project pyramus by otavanopisto.

the class EditContactEntryJSONRequestController method process.

/**
 * Method to process JSON requests.
 *
 * In parameters
 * - entryId - Long parameter to identify the contact entry that is being modified
 * - entryText - Textual message or description about the contact
 * - entryCreatorName - Name of the person who made the contact
 * - entryDate - Date of the entry
 * - entryType - Type of the entry
 *
 * Page parameters
 * - results Map including
 * * id - Entry id
 * * creatorName - Entry creator name
 * * date - Entry date
 * * text - Entry message
 * * type - Entry type
 *
 * @param jsonRequestContext JSON request context
 */
public void process(JSONRequestContext jsonRequestContext) {
    StudentContactLogEntryDAO logEntryDAO = DAOFactory.getInstance().getStudentContactLogEntryDAO();
    try {
        Long entryId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("entryId"));
        StudentContactLogEntry entry = logEntryDAO.findById(entryId);
        String entryText = jsonRequestContext.getRequest().getParameter("entryText");
        String entryCreator = jsonRequestContext.getRequest().getParameter("entryCreatorName");
        Date entryDate = new Date(NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("entryDate")));
        StudentContactLogEntryType entryType = StudentContactLogEntryType.valueOf(jsonRequestContext.getString("entryType"));
        logEntryDAO.update(entry, entryType, entryText, entryDate, entryCreator);
        Map<String, Object> info = new HashMap<>();
        info.put("id", entry.getId());
        info.put("creatorName", entry.getCreatorName());
        info.put("timestamp", entry.getEntryDate().getTime());
        info.put("text", entry.getText());
        info.put("type", entry.getType());
        info.put("studentId", entry.getStudent().getId());
        jsonRequestContext.addResponseParameter("results", info);
    } catch (Exception e) {
        throw new SmvcRuntimeException(e);
    }
}
Also used : StudentContactLogEntryType(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntryType) HashMap(java.util.HashMap) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StudentContactLogEntryDAO(fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryDAO) StudentContactLogEntry(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntry) Date(java.util.Date) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException)

Example 5 with StudentContactLogEntryDAO

use of fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryDAO in project pyramus by otavanopisto.

the class GetContactEntryJSONRequestController method process.

/**
 * Method to process JSON requests.
 *
 * In parameters
 * - entryId - Long parameter to identify the contact entry that is being modified
 *
 * Page parameters
 * - results Map including
 * * id - Entry id
 * * creatorName - Entry creator name
 * * date - Entry date
 * * text - Entry message
 * * type - Entry type
 *
 * @param jsonRequestContext JSON request context
 */
public void process(JSONRequestContext jsonRequestContext) {
    StudentContactLogEntryDAO logEntryDAO = DAOFactory.getInstance().getStudentContactLogEntryDAO();
    try {
        Long entryId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("entryId"));
        StudentContactLogEntry entry = logEntryDAO.findById(entryId);
        Map<String, Object> info = new HashMap<>();
        info.put("id", entry.getId());
        info.put("creatorName", entry.getCreatorName());
        info.put("timestamp", entry.getEntryDate().getTime());
        info.put("text", entry.getText());
        info.put("type", entry.getType());
        info.put("studentId", entry.getStudent().getId());
        jsonRequestContext.addResponseParameter("results", info);
    } catch (Exception e) {
        throw new SmvcRuntimeException(e);
    }
}
Also used : HashMap(java.util.HashMap) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StudentContactLogEntryDAO(fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryDAO) StudentContactLogEntry(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntry) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException)

Aggregations

StudentContactLogEntryDAO (fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryDAO)7 StudentContactLogEntry (fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntry)7 HashMap (java.util.HashMap)6 Date (java.util.Date)5 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)4 StudentContactLogEntryCommentDAO (fi.otavanopisto.pyramus.dao.students.StudentContactLogEntryCommentDAO)3 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)3 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)3 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)2 StudentContactLogEntryComment (fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntryComment)2 StudentContactLogEntryType (fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntryType)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 PageRequestContext (fi.internetix.smvc.controllers.PageRequestContext)1 RequestContext (fi.internetix.smvc.controllers.RequestContext)1 Messages (fi.otavanopisto.pyramus.I18N.Messages)1 Breadcrumbable (fi.otavanopisto.pyramus.breadcrumbs.Breadcrumbable)1 DAOFactory (fi.otavanopisto.pyramus.dao.DAOFactory)1 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)1