Search in sources :

Example 1 with ProjectModule

use of fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule 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 ProjectModule

use of fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule 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 3 with ProjectModule

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

the class ProjectRESTService method listProjectModules.

@Path("/projects/{PROJECTID:[0-9]*}/modules")
@GET
@RESTPermit(ProjectPermissions.LIST_PROJECTMODULES)
public Response listProjectModules(@PathParam("PROJECTID") Long projectId) {
    Project project = projectController.findProjectById(projectId);
    if (project == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (project.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    List<ProjectModule> projectModules = projectController.listProjectModules(project);
    if (projectModules.isEmpty()) {
        return Response.noContent().build();
    }
    return Response.ok(objectFactory.createModel(projectModules)).build();
}
Also used : Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 4 with ProjectModule

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

the class ProjectRESTService method updateProjectModule.

@Path("/projects/{PROJECTID:[0-9]*}/modules/{ID:[0-9]*}")
@PUT
@RESTPermit(ProjectPermissions.UPDATE_PROJECTMODULE)
public Response updateProjectModule(@PathParam("PROJECTID") Long projectId, @PathParam("ID") Long id, fi.otavanopisto.pyramus.rest.model.ProjectModule entity) {
    Project project = projectController.findProjectById(projectId);
    if (project == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (project.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    ProjectModule projectModule = projectController.findProjectModuleById(id);
    if (projectModule == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!projectModule.getProject().getId().equals(projectId)) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (projectModule.getProject().getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    ProjectModuleOptionality optionality = null;
    switch(entity.getOptionality()) {
        case MANDATORY:
            optionality = ProjectModuleOptionality.MANDATORY;
            break;
        case OPTIONAL:
            optionality = ProjectModuleOptionality.OPTIONAL;
            break;
    }
    return Response.ok(objectFactory.createModel(projectController.updateProjectModule(projectModule, optionality))).build();
}
Also used : Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) ProjectModuleOptionality(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModuleOptionality) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) PUT(javax.ws.rs.PUT)

Example 5 with ProjectModule

use of fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule 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();
    User loggedUser = userDAO.findById(jsonRequestContext.getLoggedUserId());
    Long studentId = jsonRequestContext.getLong("studentId");
    Long projectId = jsonRequestContext.getLong("projectId");
    CourseOptionality projectOptionality = (CourseOptionality) jsonRequestContext.getEnum("optionality", CourseOptionality.class);
    Student student = studentDAO.findById(studentId);
    Project project = projectDAO.findById(projectId);
    StudentProject studentProject = studentProjectDAO.create(student, project.getName(), project.getDescription(), project.getOptionalStudiesLength().getUnits(), project.getOptionalStudiesLength().getUnit(), projectOptionality, loggedUser, project);
    Set<Tag> tags = new HashSet<>();
    for (Tag tag : project.getTags()) {
        tags.add(tag);
    }
    studentProjectDAO.updateTags(studentProject, tags);
    List<ProjectModule> projectModules = project.getProjectModules();
    for (ProjectModule projectModule : projectModules) {
        studentProjectModuleDAO.create(studentProject, projectModule.getModule(), null, CourseOptionality.getOptionality(projectModule.getOptionality().getValue()));
    }
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject) 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) ProjectDAO(fi.otavanopisto.pyramus.dao.projects.ProjectDAO) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) HashSet(java.util.HashSet)

Aggregations

ProjectModule (fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule)15 Project (fi.otavanopisto.pyramus.domainmodel.projects.Project)12 HashSet (java.util.HashSet)6 ProjectDAO (fi.otavanopisto.pyramus.dao.projects.ProjectDAO)5 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)5 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)4 Module (fi.otavanopisto.pyramus.domainmodel.modules.Module)4 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)4 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)4 EntityManager (javax.persistence.EntityManager)4 Path (javax.ws.rs.Path)4 StudentProjectDAO (fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO)3 StudentProjectModuleDAO (fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO)3 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)3 TagDAO (fi.otavanopisto.pyramus.dao.base.TagDAO)2 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)2 CourseOptionality (fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality)2 StudentProject (fi.otavanopisto.pyramus.domainmodel.projects.StudentProject)2 User (fi.otavanopisto.pyramus.domainmodel.users.User)2 ArrayList (java.util.ArrayList)2