Search in sources :

Example 21 with Project

use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.

the class CreateStudentProjectJSONRequestController method process.

public void process(JSONRequestContext jsonRequestContext) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
    StudentProjectModuleDAO studentProjectModuleDAO = DAOFactory.getInstance().getStudentProjectModuleDAO();
    TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
    DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
    User loggedUser = userDAO.findById(jsonRequestContext.getLoggedUserId());
    Long studentId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("studentId"));
    Long projectId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("projectId"));
    String tagsText = jsonRequestContext.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);
            }
        }
    }
    Student student = studentDAO.findById(studentId);
    Project project = projectId == -1 ? null : projectDAO.findById(projectId);
    String name;
    String description;
    EducationalTimeUnit unit;
    Double units;
    if (project == null) {
        name = Messages.getInstance().getText(jsonRequestContext.getRequest().getLocale(), "projects.createStudentProject.newStudentProject");
        description = null;
        unit = defaultsDAO.getDefaults().getBaseTimeUnit();
        units = 0.0;
    } else {
        name = project.getName();
        description = project.getDescription();
        unit = project.getOptionalStudiesLength().getUnit();
        units = project.getOptionalStudiesLength().getUnits();
    }
    StudentProject studentProject = studentProjectDAO.create(student, name, description, units, unit, null, loggedUser, project);
    studentProjectDAO.updateTags(studentProject, tagEntities);
    if (project != null) {
        List<ProjectModule> projectModules = project.getProjectModules();
        for (ProjectModule projectModule : projectModules) {
            studentProjectModuleDAO.create(studentProject, projectModule.getModule(), null, CourseOptionality.getOptionality(projectModule.getOptionality().getValue()));
        }
    }
    String redirectURL = jsonRequestContext.getRequest().getContextPath() + "/projects/editstudentproject.page?studentproject=" + studentProject.getId();
    String refererAnchor = jsonRequestContext.getRefererAnchor();
    if (!StringUtils.isBlank(refererAnchor))
        redirectURL += "#" + refererAnchor;
    jsonRequestContext.setRedirectURL(redirectURL);
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO) HashSet(java.util.HashSet) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)

Example 22 with Project

use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.

the class ListStudentProjectsJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
    CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
    ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
    Long projectId = requestContext.getLong("project");
    Project project = projectDAO.findById(projectId);
    Integer page = requestContext.getInteger("page");
    page = page != null ? page : 0;
    Integer maxResults = requestContext.getInteger("maxResults");
    maxResults = maxResults != null ? maxResults : 25;
    int firstResult = page * maxResults;
    long numStudentProjectsTotal = studentProjectDAO.countByProject(project);
    int numPages = (int) Math.ceil((double) numStudentProjectsTotal / maxResults);
    List<StudentProject> studentProjectsByProjectPage = studentProjectDAO.listByProject(project, firstResult, maxResults);
    int resultsCount = studentProjectsByProjectPage.size();
    JSONArray studentProjectsJSON = new JSONArray();
    for (StudentProject sp : studentProjectsByProjectPage) {
        StudentProjectBean bean = beanify(sp, courseDAO, courseStudentDAO, transferCreditDAO, courseAssessmentDAO, projectAssessmentDAO);
        JSONObject spJSON = new JSONObject();
        JSONArray spDates = new JSONArray();
        StringBuilder gradeText = new StringBuilder();
        for (ProjectAssessment assessment : bean.getAssessments()) {
            spDates.add(assessment.getDate().getTime());
            if (gradeText.length() > 0)
                gradeText.append(", ");
            if (assessment.getGrade() != null)
                gradeText.append(assessment.getGrade().getName());
            else
                gradeText.append("-");
        }
        spJSON.put("personId", bean.getStudentProject().getStudent().getPerson().getId());
        spJSON.put("studentProjectId", bean.getStudentProject().getId());
        spJSON.put("studentName", bean.getStudentProject().getStudent().getLastName() + ", " + bean.getStudentProject().getStudent().getFirstName());
        spJSON.put("studyProgrammeName", bean.getStudentProject().getStudent().getStudyProgramme().getName());
        spJSON.put("optionality", bean.getStudentProject().getOptionality());
        spJSON.put("dates", spDates);
        spJSON.put("grade", gradeText.toString());
        spJSON.put("passedMandatory", bean.getPassedMandatoryModuleCount() + "/" + bean.getMandatoryModuleCount());
        spJSON.put("passedOptional", bean.getPassedOptionalModuleCount() + "/" + bean.getOptionalModuleCount());
        studentProjectsJSON.add(spJSON);
    }
    String statusMessage;
    Locale locale = requestContext.getRequest().getLocale();
    if (studentProjectsByProjectPage.size() > 0) {
        statusMessage = Messages.getInstance().getText(locale, "projects.viewProject.studentProjects.searchStatus", new Object[] { firstResult + 1, firstResult + resultsCount, numStudentProjectsTotal });
    } else {
        statusMessage = Messages.getInstance().getText(locale, "projects.viewProject.studentProjects.searchStatusNoMatches");
    }
    requestContext.addResponseParameter("studentProjects", studentProjectsJSON);
    requestContext.addResponseParameter("page", page);
    requestContext.addResponseParameter("pages", numPages);
    requestContext.addResponseParameter("statusMessage", statusMessage);
}
Also used : Locale(java.util.Locale) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) JSONArray(net.sf.json.JSONArray) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) JSONObject(net.sf.json.JSONObject) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) JSONObject(net.sf.json.JSONObject) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO)

Example 23 with Project

use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.

the class SearchProjectsJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    Integer resultsPerPage = NumberUtils.createInteger(requestContext.getRequest().getParameter("maxResults"));
    if (resultsPerPage == null) {
        resultsPerPage = 10;
    }
    Integer page = NumberUtils.createInteger(requestContext.getRequest().getParameter("page"));
    if (page == null) {
        page = 0;
    }
    // Gather the search terms
    String text = requestContext.getRequest().getParameter("text");
    // Search via the DAO object
    SearchResult<Project> searchResult = projectDAO.searchProjectsBasic(resultsPerPage, page, text);
    List<Map<String, Object>> results = new ArrayList<>();
    List<Project> projects = searchResult.getResults();
    for (Project project : projects) {
        Map<String, Object> projectInfo = new HashMap<>();
        projectInfo.put("id", project.getId());
        projectInfo.put("name", project.getName());
        results.add(projectInfo);
    }
    String statusMessage;
    Locale locale = requestContext.getRequest().getLocale();
    if (searchResult.getTotalHitCount() > 0) {
        statusMessage = Messages.getInstance().getText(locale, "projects.searchProjects.searchStatus", new Object[] { searchResult.getFirstResult() + 1, searchResult.getLastResult() + 1, searchResult.getTotalHitCount() });
    } else {
        statusMessage = Messages.getInstance().getText(locale, "projects.searchProjects.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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) HashMap(java.util.HashMap) Map(java.util.Map) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO)

Example 24 with Project

use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.

the class EditProjectViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    Long projectId = NumberUtils.createLong(pageRequestContext.getRequest().getParameter("project"));
    Project project = projectDAO.findById(projectId);
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = project.getTags().iterator();
    while (tagIterator.hasNext()) {
        Tag tag = tagIterator.next();
        tagsBuilder.append(tag.getText());
        if (tagIterator.hasNext())
            tagsBuilder.append(' ');
    }
    List<EducationalTimeUnit> educationalTimeUnits = educationalTimeUnitDAO.listUnarchived();
    Collections.sort(educationalTimeUnits, new StringAttributeComparator("getName"));
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    this.setJsDataVariable(pageRequestContext, "projectId", project.getId().toString());
    pageRequestContext.getRequest().setAttribute("project", project);
    pageRequestContext.getRequest().setAttribute("optionalStudiesLengthTimeUnits", educationalTimeUnits);
    pageRequestContext.getRequest().setAttribute("users", userDAO.listAll());
    pageRequestContext.setIncludeJSP("/templates/projects/editproject.jsp");
}
Also used : Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)

Example 25 with Project

use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.

the class MatriculationExamSettingsViewController method doGet.

private void doGet(PageRequestContext pageRequestContext) {
    MatriculationExamDAO dao = DAOFactory.getInstance().getMatriculationExamDAO();
    MatriculationExamSubjectSettingsDAO matriculationExamSubjectSettingsDAO = DAOFactory.getInstance().getMatriculationExamSubjectSettingsDAO();
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    GradingScaleDAO gradingScaleDAO = DAOFactory.getInstance().getGradingScaleDAO();
    List<GradingScale> gradingScales = gradingScaleDAO.listUnarchived();
    pageRequestContext.getRequest().setAttribute("gradingScales", gradingScales);
    MatriculationExam exam;
    if ("new".equals(pageRequestContext.getString("examId"))) {
        pageRequestContext.getRequest().setAttribute("examId", pageRequestContext.getString("examId"));
        exam = null;
    } else {
        Long examId = pageRequestContext.getLong("examId");
        exam = dao.findById(examId);
        pageRequestContext.getRequest().setAttribute("examId", examId);
    }
    pageRequestContext.getRequest().setAttribute("exam", exam);
    JSONArray subjectsJSON = new JSONArray();
    List<MatriculationExamSubject> matriculationExamSubjects = Arrays.asList(MatriculationExamSubject.values());
    matriculationExamSubjects.sort(Comparator.comparing(MatriculationExamSubject::toString));
    for (MatriculationExamSubject subject : matriculationExamSubjects) {
        MatriculationExamSubjectSettings subset = exam != null ? matriculationExamSubjectSettingsDAO.findBy(exam, subject) : null;
        JSONObject subjectJSON = new JSONObject();
        subjectJSON.put("subjectCode", subject);
        subjectJSON.put("projectId", (subset != null && subset.getProject() != null) ? subset.getProject().getId() : null);
        subjectJSON.put("examDate", (subset != null && subset.getExamDate() != null) ? subset.getExamDate().getTime() : null);
        subjectsJSON.add(subjectJSON);
    }
    setJsDataVariable(pageRequestContext, "subjectData", subjectsJSON.toString());
    List<Project> projects = projectDAO.listUnarchived();
    projects.sort(Comparator.comparing(Project::getName));
    JSONArray projectsJSON = new JSONArray();
    for (Project project : projects) {
        JSONObject projectJSON = new JSONObject();
        projectJSON.put("id", project.getId());
        projectJSON.put("name", project.getName());
        projectsJSON.add(projectJSON);
    }
    setJsDataVariable(pageRequestContext, "projectData", projectsJSON.toString());
    pageRequestContext.setIncludeJSP("/templates/matriculation/management-enrollment-settings.jsp");
}
Also used : GradingScale(fi.otavanopisto.pyramus.domainmodel.grading.GradingScale) GradingScaleDAO(fi.otavanopisto.pyramus.dao.grading.GradingScaleDAO) JSONArray(net.sf.json.JSONArray) MatriculationExamDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamDAO) MatriculationExamSubjectSettings(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubjectSettings) MatriculationExamSubjectSettingsDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO) MatriculationExam(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExam) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) JSONObject(net.sf.json.JSONObject) MatriculationExamSubject(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamSubject) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO)

Aggregations

Project (fi.otavanopisto.pyramus.domainmodel.projects.Project)25 ProjectDAO (fi.otavanopisto.pyramus.dao.projects.ProjectDAO)14 ProjectModule (fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule)12 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)8 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)8 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)7 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)7 HashSet (java.util.HashSet)7 Path (javax.ws.rs.Path)7 Module (fi.otavanopisto.pyramus.domainmodel.modules.Module)6 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)4 StudentProjectDAO (fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO)4 StudentProject (fi.otavanopisto.pyramus.domainmodel.projects.StudentProject)4 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)4 ArrayList (java.util.ArrayList)4 TagDAO (fi.otavanopisto.pyramus.dao.base.TagDAO)3 MatriculationExamSubjectSettingsDAO (fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO)3 StudentProjectModuleDAO (fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO)3 User (fi.otavanopisto.pyramus.domainmodel.users.User)3 ProjectAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO)2