use of fi.otavanopisto.pyramus.domainmodel.projects.Project 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);
}
use of fi.otavanopisto.pyramus.domainmodel.projects.Project 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);
}
use of fi.otavanopisto.pyramus.domainmodel.projects.Project 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);
}
use of fi.otavanopisto.pyramus.domainmodel.projects.Project 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));
}
use of fi.otavanopisto.pyramus.domainmodel.projects.Project in project pyramus by otavanopisto.
the class ModuleRESTService method listProjects.
@Path("/modules/{ID:[0-9]*}/projects")
@GET
@RESTPermit(ModulePermissions.LIST_PROJECTSBYMODULE)
public Response listProjects(@PathParam("ID") Long id) {
Module module = moduleController.findModuleById(id);
if (module == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (module.getArchived()) {
return Response.status(Status.NOT_FOUND).build();
}
List<Project> projects = moduleController.listProjectsByModule(module);
if (projects.isEmpty()) {
return Response.noContent().build();
}
return Response.ok(objectFactory.createModel(projects)).build();
}
Aggregations