Search in sources :

Example 1 with ProjectDAO

use of fi.otavanopisto.pyramus.dao.projects.ProjectDAO in project pyramus by otavanopisto.

the class GetProjectModulesJSONRequestController method process.

public void process(JSONRequestContext jsonRequestContext) {
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    Long projectId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("project"));
    Project project = projectDAO.findById(projectId);
    List<Map<String, Object>> projectModules = new ArrayList<>();
    for (ProjectModule projectModule : project.getProjectModules()) {
        Map<String, Object> moduleInfo = new HashMap<>();
        moduleInfo.put("id", projectModule.getId());
        moduleInfo.put("moduleId", projectModule.getModule().getId());
        moduleInfo.put("name", projectModule.getModule().getName());
        moduleInfo.put("optionality", projectModule.getOptionality().getValue());
        projectModules.add(moduleInfo);
    }
    jsonRequestContext.addResponseParameter("projectModules", projectModules);
}
Also used : Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO)

Example 2 with ProjectDAO

use of fi.otavanopisto.pyramus.dao.projects.ProjectDAO in project pyramus by otavanopisto.

the class ArchiveProjectJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    Long projectId = requestContext.getLong("projectId");
    Project project = projectDAO.findById(projectId);
    projectDAO.archive(project);
}
Also used : Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO)

Example 3 with ProjectDAO

use of fi.otavanopisto.pyramus.dao.projects.ProjectDAO in project pyramus by otavanopisto.

the class CreateProjectJSONRequestController method process.

public void process(JSONRequestContext jsonRequestContext) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    ProjectModuleDAO projectModuleDAO = DAOFactory.getInstance().getProjectModuleDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
    // Project
    String name = jsonRequestContext.getRequest().getParameter("name");
    String description = jsonRequestContext.getRequest().getParameter("description");
    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);
            }
        }
    }
    User loggedUser = userDAO.findById(jsonRequestContext.getLoggedUserId());
    Long optionalStudiesLengthTimeUnitId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("optionalStudiesLengthTimeUnit"));
    EducationalTimeUnit optionalStudiesLengthTimeUnit = educationalTimeUnitDAO.findById(optionalStudiesLengthTimeUnitId);
    Double optionalStudiesLength = NumberUtils.createDouble(jsonRequestContext.getRequest().getParameter("optionalStudiesLength"));
    Project project = projectDAO.create(name, description, optionalStudiesLength, optionalStudiesLengthTimeUnit, loggedUser);
    // Tags
    projectDAO.updateTags(project, tagEntities);
    // Project modules
    int rowCount = NumberUtils.createInteger(jsonRequestContext.getRequest().getParameter("modulesTable.rowCount")).intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "modulesTable." + i;
        Long moduleId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter(colPrefix + ".moduleId"));
        Module module = moduleDAO.findById(moduleId);
        int optionality = new Integer(jsonRequestContext.getRequest().getParameter(colPrefix + ".optionality")).intValue();
        projectModuleDAO.create(project, module, ProjectModuleOptionality.getOptionality(optionality));
    }
    String redirectURL = jsonRequestContext.getRequest().getContextPath() + "/projects/editproject.page?project=" + project.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) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) ProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.ProjectModuleDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) ProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.ProjectModuleDAO) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO) HashSet(java.util.HashSet) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)

Example 4 with ProjectDAO

use of fi.otavanopisto.pyramus.dao.projects.ProjectDAO in project pyramus by otavanopisto.

the class EditProjectJSONRequestController method process.

public void process(JSONRequestContext jsonRequestContext) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
    ProjectModuleDAO projectModuleDAO = DAOFactory.getInstance().getProjectModuleDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
    // Project
    Long projectId = jsonRequestContext.getLong("project");
    Project project = projectDAO.findById(projectId);
    // Version check
    Long version = jsonRequestContext.getLong("version");
    if (!project.getVersion().equals(version))
        throw new StaleObjectStateException(Project.class.getName(), project.getId());
    String name = jsonRequestContext.getRequest().getParameter("name");
    String description = jsonRequestContext.getRequest().getParameter("description");
    User user = userDAO.findById(jsonRequestContext.getLoggedUserId());
    Long optionalStudiesLengthTimeUnitId = jsonRequestContext.getLong("optionalStudiesLengthTimeUnit");
    EducationalTimeUnit optionalStudiesLengthTimeUnit = educationalTimeUnitDAO.findById(optionalStudiesLengthTimeUnitId);
    Double optionalStudiesLength = jsonRequestContext.getDouble("optionalStudiesLength");
    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);
            }
        }
    }
    if (optionalStudiesLength == null) {
        Messages messages = Messages.getInstance();
        Locale locale = jsonRequestContext.getRequest().getLocale();
        jsonRequestContext.addMessage(Severity.ERROR, messages.getText(locale, "projects.editProject.projectOptionalStudiesLengthNotDefined"));
    }
    projectDAO.update(project, name, description, optionalStudiesLength, optionalStudiesLengthTimeUnit, user);
    // Tags
    projectDAO.updateTags(project, tagEntities);
    // Project modules
    Set<Long> existingIds = new HashSet<>();
    int rowCount = jsonRequestContext.getInteger("modulesTable.rowCount").intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "modulesTable." + i;
        int optionality = new Integer(jsonRequestContext.getRequest().getParameter(colPrefix + ".optionality")).intValue();
        Long projectModuleId = jsonRequestContext.getLong(colPrefix + ".projectModuleId");
        if (projectModuleId == -1) {
            Long moduleId = jsonRequestContext.getLong(colPrefix + ".moduleId");
            Module module = moduleDAO.findById(moduleId);
            projectModuleId = projectModuleDAO.create(project, module, ProjectModuleOptionality.getOptionality(optionality)).getId();
        } else {
            projectModuleDAO.update(projectModuleDAO.findById(projectModuleId), ProjectModuleOptionality.getOptionality(optionality));
        }
        existingIds.add(projectModuleId);
    }
    List<ProjectModule> projectModules = projectModuleDAO.listByProject(project);
    for (ProjectModule projectModule : projectModules) {
        if (!existingIds.contains(projectModule.getId())) {
            projectModuleDAO.delete(projectModule);
        }
    }
    jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
Also used : Locale(java.util.Locale) User(fi.otavanopisto.pyramus.domainmodel.users.User) ProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.ProjectModuleDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) HashSet(java.util.HashSet) Messages(fi.otavanopisto.pyramus.I18N.Messages) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) StaleObjectStateException(org.hibernate.StaleObjectStateException) ProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.ProjectModuleDAO) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO)

Example 5 with ProjectDAO

use of fi.otavanopisto.pyramus.dao.projects.ProjectDAO 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

ProjectDAO (fi.otavanopisto.pyramus.dao.projects.ProjectDAO)15 Project (fi.otavanopisto.pyramus.domainmodel.projects.Project)14 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)7 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)6 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)6 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)5 ProjectModule (fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule)5 User (fi.otavanopisto.pyramus.domainmodel.users.User)5 HashSet (java.util.HashSet)5 TagDAO (fi.otavanopisto.pyramus.dao.base.TagDAO)3 ModuleDAO (fi.otavanopisto.pyramus.dao.modules.ModuleDAO)3 StudentProjectDAO (fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO)3 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)3 Module (fi.otavanopisto.pyramus.domainmodel.modules.Module)3 StudentProject (fi.otavanopisto.pyramus.domainmodel.projects.StudentProject)3 StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)3 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)2 MatriculationExamDAO (fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamDAO)2 MatriculationExamSubjectSettingsDAO (fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamSubjectSettingsDAO)2 ProjectModuleDAO (fi.otavanopisto.pyramus.dao.projects.ProjectModuleDAO)2