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();
}
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();
}
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();
}
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();
}
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()));
}
}
Aggregations