Search in sources :

Example 6 with Project

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

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

the class ProjectRESTService method updateProject.

@Path("/projects/{ID:[0-9]*}")
@PUT
@RESTPermit(ProjectPermissions.UPDATE_PROJECT)
public Response updateProject(@PathParam("ID") Long id, fi.otavanopisto.pyramus.rest.model.Project entity) {
    Project project = projectController.findProjectById(id);
    if (project == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (project.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    EducationalTimeUnit optionalStudiesLengthUnit = entity.getOptionalStudiesLengthUnitId() != null ? commonController.findEducationalTimeUnitById(entity.getOptionalStudiesLengthUnitId()) : null;
    Double optionalStudiesLength = entity.getOptionalStudiesLength();
    String name = entity.getName();
    String description = entity.getDescription();
    if (StringUtils.isBlank(name)) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    project = projectController.updateProjectTags(project, entity.getTags() == null ? new ArrayList<String>() : entity.getTags());
    return Response.ok(objectFactory.createModel(projectController.updateProject(project, name, description, optionalStudiesLength, optionalStudiesLengthUnit, sessionController.getUser()))).build();
}
Also used : Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) PUT(javax.ws.rs.PUT)

Example 8 with Project

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

the class ProjectRESTService method createProject.

@Path("/projects")
@POST
@RESTPermit(ProjectPermissions.CREATE_PROJECT)
public Response createProject(fi.otavanopisto.pyramus.rest.model.Project entity) {
    EducationalTimeUnit optionalStudiesLengthUnit = entity.getOptionalStudiesLengthUnitId() != null ? commonController.findEducationalTimeUnitById(entity.getOptionalStudiesLengthUnitId()) : null;
    Double optionalStudiesLength = entity.getOptionalStudiesLength();
    String name = entity.getName();
    String description = entity.getDescription();
    if (StringUtils.isBlank(name)) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Project project = projectController.createProject(name, description, optionalStudiesLength, optionalStudiesLengthUnit, sessionController.getUser());
    if (entity.getTags() != null) {
        for (String tag : entity.getTags()) {
            projectController.createProjectTag(project, tag);
        }
    }
    return Response.ok(objectFactory.createModel(project)).build();
}
Also used : Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) POST(javax.ws.rs.POST)

Example 9 with Project

use of fi.otavanopisto.pyramus.domainmodel.projects.Project 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 10 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();
    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

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