use of fi.otavanopisto.pyramus.domainmodel.courses.CourseState in project pyramus by otavanopisto.
the class SearchCoursesJSONRequestController method process.
/**
* Processes the request to search courses.
* The request should contain the either following parameters (for simple search):
* <dl>
* <dt><code>text</code></dt>
* <dd>The text to search for</dd>
* </dl>
* or the following parameters (for advanced search):
* <dl>
* <dt><code>name</code></dt>
* <dd>Course name to find.</dd>
* <dt><code>tags</code></dt>
* <dd>Tags to find.</dd>
* <dt><code>nameExtension</code></dt>
* <dd>The name extension to find.</dd>
* <dt><code>description</code></dt>
* <dd>The description to find.</dd>
* <dt><code>state</code></dt>
* <dd>The ID of the course state to find.</dd>
* <dt><code>subject</code></dt>
* <dd>The ID of the subject to find.</dd>
* <dt><code>timeframeStart</code></dt>
* <dd>The start of the timeframe to find.</dd>
* <dt><code>timeframeEnd</code></dt>
* <dd>The end of the timeframe to find.</dd>
* <dt><code>educationType</code></dt>
* <dd>The education type to find.</dd>
* <dt><code>educationSubtype</code></dt>
* <dd>The education subtype to find.</dd>
* <dt><code>timeframeMode</code></dt>
* <dd>The mode of the timeframe. Can be <code>INCLUSIVE</code>
* or <code>EXCLUSIVE</code>.</dd>
* </dl>
*
* @param jsonRequestContext The JSON request context
*/
public void process(JSONRequestContext requestContext) {
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
EducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getEducationSubtypeDAO();
// Determine the number of results shown per page. If not defined, default to ten results per page
Integer resultsPerPage = NumberUtils.createInteger(requestContext.getRequest().getParameter("maxResults"));
if (resultsPerPage == null)
resultsPerPage = 10;
// Determine the result page to be shown. If not defined, default to the first page
Integer page = NumberUtils.createInteger(requestContext.getRequest().getParameter("page"));
if (page == null) {
page = 0;
}
SearchResult<Course> searchResult;
if ("advanced".equals(requestContext.getRequest().getParameter("activeTab"))) {
String name = requestContext.getString("name");
String tags = requestContext.getString("tags");
if (!StringUtils.isBlank(tags))
tags = tags.replace(',', ' ');
String nameExtension = requestContext.getString("nameExtension");
String description = requestContext.getString("description");
CourseState courseState = null;
Long courseStateId = requestContext.getLong("state");
if (courseStateId != null) {
courseState = courseStateDAO.findById(courseStateId);
}
Subject subject = null;
Long subjectId = requestContext.getLong("subject");
if (subjectId != null) {
subject = subjectDAO.findById(subjectId);
}
Date timeframeStart = null;
String value = requestContext.getString("timeframeStart");
if (NumberUtils.isNumber(value)) {
timeframeStart = new Date(NumberUtils.createLong(value));
}
Date timeframeEnd = null;
value = requestContext.getString("timeframeEnd");
if (NumberUtils.isNumber(value)) {
timeframeEnd = new Date(NumberUtils.createLong(value));
}
EducationType educationType = null;
Long educationTypeId = requestContext.getLong("educationType");
if (educationTypeId != null) {
educationType = educationTypeDAO.findById(educationTypeId);
}
EducationSubtype educationSubtype = null;
Long educationSubtypeId = requestContext.getLong("educationSubtype");
if (educationSubtypeId != null) {
educationSubtype = educationSubtypeDAO.findById(educationSubtypeId);
}
CourseTemplateFilter courseTemplateFilter = (CourseTemplateFilter) requestContext.getEnum("courseTemplateFilter", CourseTemplateFilter.class);
SearchTimeFilterMode timeFilterMode = (SearchTimeFilterMode) requestContext.getEnum("timeframeMode", SearchTimeFilterMode.class);
searchResult = courseDAO.searchCourses(resultsPerPage, page, name, tags, nameExtension, description, courseState, subject, timeFilterMode, timeframeStart, timeframeEnd, educationType, educationSubtype, true, courseTemplateFilter);
} else {
String text = requestContext.getRequest().getParameter("text");
searchResult = courseDAO.searchCoursesBasic(resultsPerPage, page, text, true);
}
List<Map<String, Object>> results = new ArrayList<>();
List<Course> courses = searchResult.getResults();
for (Course course : courses) {
Map<String, Object> courseInfo = new HashMap<>();
courseInfo.put("id", course.getId());
courseInfo.put("name", course.getName());
courseInfo.put("nameExtension", course.getNameExtension());
if (course.getBeginDate() != null) {
courseInfo.put("beginDate", course.getBeginDate().getTime());
}
if (course.getEndDate() != null) {
courseInfo.put("endDate", course.getEndDate().getTime());
}
results.add(courseInfo);
}
String statusMessage;
Locale locale = requestContext.getRequest().getLocale();
if (searchResult.getTotalHitCount() > 0) {
statusMessage = Messages.getInstance().getText(locale, "courses.searchCourses.searchStatus", new Object[] { searchResult.getFirstResult() + 1, searchResult.getLastResult() + 1, searchResult.getTotalHitCount() });
} else {
statusMessage = Messages.getInstance().getText(locale, "courses.searchCourses.searchStatusNoMatches");
}
requestContext.addResponseParameter("results", results);
requestContext.addResponseParameter("statusMessage", statusMessage);
requestContext.addResponseParameter("pages", searchResult.getPages());
requestContext.addResponseParameter("page", searchResult.getPage());
}
use of fi.otavanopisto.pyramus.domainmodel.courses.CourseState in project pyramus by otavanopisto.
the class CoursesService method searchCourses.
public CourseEntitySearchResult searchCourses(@WebParam(name = "resultsPerPage") Integer resultsPerPage, @WebParam(name = "page") Integer page, @WebParam(name = "name") String name, @WebParam(name = "tags") String tags, @WebParam(name = "nameExtension") String nameExtension, @WebParam(name = "description") String description, @WebParam(name = "courseStateId") Long courseStateId, @WebParam(name = "subjectId") Long subjectId, @WebParam(name = "timeFilterMode") String timeFilterMode, @WebParam(name = "timeframeStart") Date timeframeStart, @WebParam(name = "timeframeEnd") Date timeframeEnd) {
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
CourseState courseState = courseStateId != null ? courseStateDAO.findById(courseStateId) : null;
Subject subject = subjectId != null ? subjectDAO.findById(subjectId) : null;
SearchTimeFilterMode tFilterMode = timeFilterMode != null ? SearchTimeFilterMode.valueOf(timeFilterMode) : null;
SearchResult<Course> searchResult = courseDAO.searchCourses(resultsPerPage, page, name, tags, nameExtension, description, courseState, subject, tFilterMode, timeframeStart, timeframeEnd, true);
return new CourseEntitySearchResult(searchResult.getPage(), searchResult.getPages(), searchResult.getTotalHitCount(), (CourseEntity[]) EntityFactoryVault.buildFromDomainObjects(searchResult.getResults()));
}
use of fi.otavanopisto.pyramus.domainmodel.courses.CourseState in project pyramus by otavanopisto.
the class CoursesService method createCourse.
public CourseEntity createCourse(@WebParam(name = "moduleId") Long moduleId, @WebParam(name = "name") String name, @WebParam(name = "nameExtension") String nameExtension, @WebParam(name = "subjectId") Long subjectId, @WebParam(name = "courseNumber") Integer courseNumber, @WebParam(name = "beginDate") Date beginDate, @WebParam(name = "endDate") Date endDate, @WebParam(name = "courseLength") Double courseLength, @WebParam(name = "courseLengthTimeUnitId") Long courseLengthTimeUnitId, @WebParam(name = "description") String description, @WebParam(name = "creatingUserId") Long creatingUserId) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
CourseComponentDAO componentDAO = DAOFactory.getInstance().getCourseComponentDAO();
CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
CourseEducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getCourseEducationTypeDAO();
CourseEducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getCourseEducationSubtypeDAO();
EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
Module module = moduleId == null ? null : moduleDAO.findById(moduleId);
Subject subject = subjectId == null ? null : subjectDAO.findById(subjectId);
EducationalTimeUnit courseLengthTimeUnit = courseLengthTimeUnitId == null ? null : educationalTimeUnitDAO.findById(courseLengthTimeUnitId);
User creatingUser = userDAO.findById(creatingUserId);
if (module != null) {
name = name == null ? module.getName() : name;
subject = subject == null ? module.getSubject() : subject;
courseNumber = courseNumber == null ? module.getCourseNumber() : courseNumber;
if (courseLength == null && module.getCourseLength() != null) {
courseLength = module.getCourseLength().getUnits();
courseLengthTimeUnit = module.getCourseLength().getUnit();
}
description = description == null ? module.getDescription() : description;
}
CourseState state = defaultsDAO.getDefaults().getInitialCourseState();
CourseType type = null;
// Course creation
Course course = courseDAO.create(module, name, nameExtension, state, type, subject, courseNumber, beginDate, endDate, courseLength, courseLengthTimeUnit, null, null, null, null, null, null, description, null, null, null, null, creatingUser);
validateEntity(course);
if (module != null) {
// Course Description copying from module to course
descriptionDAO.copy(module, course);
// Curriculums
courseDAO.updateCurriculums(course, new HashSet<Curriculum>(module.getCurriculums()));
// Components
List<ModuleComponent> moduleComponents = module.getModuleComponents();
if (moduleComponents != null) {
for (ModuleComponent moduleComponent : moduleComponents) {
EducationalLength educationalLength = moduleComponent.getLength();
CourseComponent courseComponent = componentDAO.create(course, educationalLength == null ? null : educationalLength.getUnits(), educationalLength == null ? null : educationalLength.getUnit(), moduleComponent.getName(), moduleComponent.getDescription());
validateEntity(courseComponent);
}
}
// Education types
List<CourseEducationType> typesInModule = module.getCourseEducationTypes();
if (typesInModule != null) {
for (CourseEducationType typeInModule : typesInModule) {
CourseEducationType typeInCourse = educationTypeDAO.create(course, typeInModule.getEducationType());
validateEntity(typeInCourse);
// Education subtypes
List<CourseEducationSubtype> subTypesInModule = typeInModule.getCourseEducationSubtypes();
if (subTypesInModule != null) {
for (CourseEducationSubtype subtypeInModule : subTypesInModule) {
CourseEducationSubtype courseEducationSubtype = educationSubtypeDAO.create(typeInCourse, subtypeInModule.getEducationSubtype());
validateEntity(courseEducationSubtype);
}
}
}
}
}
return EntityFactoryVault.buildFromDomainObject(course);
}
use of fi.otavanopisto.pyramus.domainmodel.courses.CourseState 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);
}
}
}
use of fi.otavanopisto.pyramus.domainmodel.courses.CourseState in project pyramus by otavanopisto.
the class CourseStatesSetupWizardViewController method save.
@Override
public void save(PageRequestContext requestContext) throws SetupWizardException {
CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
CourseState initialCourseState = null;
int rowCount = requestContext.getInteger("courseStatesTable.rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String colPrefix = "courseStatesTable." + i;
Boolean initialState = "true".equals(requestContext.getString(colPrefix + ".initialState"));
String name = requestContext.getRequest().getParameter(colPrefix + ".name");
CourseState courseState = courseStateDAO.create(name);
if (initialState) {
if (initialCourseState != null) {
throw new SetupWizardException("Two or more initialCourseStates defined");
}
initialCourseState = courseState;
}
}
if (initialCourseState != null) {
defaultsDAO.updateDefaultInitialCourseState(initialCourseState);
} else {
throw new SetupWizardException("initialCourseState not defined");
}
}
Aggregations