use of fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO in project pyramus by otavanopisto.
the class StudyProgrammeCategoriesViewController method process.
/**
* Processes the page request by including the corresponding JSP page to the response.
*
* @param pageRequestContext Page request context
*/
public void process(PageRequestContext pageRequestContext) {
StudyProgrammeCategoryDAO studyProgrammeCategoryDAO = DAOFactory.getInstance().getStudyProgrammeCategoryDAO();
EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
List<EducationType> educationTypes = educationTypeDAO.listUnarchived();
Collections.sort(educationTypes, new StringAttributeComparator("getName"));
List<StudyProgrammeCategory> studyProgrammeCategories = studyProgrammeCategoryDAO.listUnarchived();
JSONArray jsonStudyProgrammeCategories = new JSONArrayExtractor("name", "id").extract(studyProgrammeCategories);
for (int i = 0; i < jsonStudyProgrammeCategories.size(); i++) {
JSONObject jsonStudyProgrammeCategory = jsonStudyProgrammeCategories.getJSONObject(i);
if (studyProgrammeCategories.get(i).getEducationType() != null) {
jsonStudyProgrammeCategory.put("educationTypeId", studyProgrammeCategories.get(i).getEducationType().getId());
}
}
String jsonEducationTypes = new JSONArrayExtractor("name", "id").extractString(educationTypes);
this.setJsDataVariable(pageRequestContext, "studyProgrammeCategories", jsonStudyProgrammeCategories.toString());
this.setJsDataVariable(pageRequestContext, "educationTypes", jsonEducationTypes);
pageRequestContext.setIncludeJSP("/templates/settings/studyprogrammecategories.jsp");
}
use of fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO in project pyramus by otavanopisto.
the class SaveStudyProgrammesJSONRequestController method process.
public void process(JSONRequestContext jsonRequestContext) {
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
StudyProgrammeCategoryDAO studyProgrammeCategoryDAO = DAOFactory.getInstance().getStudyProgrammeCategoryDAO();
OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
StaffMember loggedUser = staffMemberDAO.findById(jsonRequestContext.getLoggedUserId());
int rowCount = NumberUtils.createInteger(jsonRequestContext.getRequest().getParameter("studyProgrammesTable.rowCount")).intValue();
for (int i = 0; i < rowCount; i++) {
String colPrefix = "studyProgrammesTable." + i;
boolean modified = jsonRequestContext.getInteger(colPrefix + ".modified") == 1;
if (modified) {
Long studyProgrammeId = jsonRequestContext.getLong(colPrefix + ".studyProgrammeId");
String name = jsonRequestContext.getString(colPrefix + ".name");
String code = jsonRequestContext.getString(colPrefix + ".code");
Long categoryId = jsonRequestContext.getLong(colPrefix + ".category");
Long organizationId = jsonRequestContext.getLong(colPrefix + ".organization");
boolean hasEvaluationFees = StringUtils.equals("1", jsonRequestContext.getString(colPrefix + ".hasEvaluationFees"));
StudyProgrammeCategory category = null;
Organization organization = null;
if (categoryId != null) {
category = studyProgrammeCategoryDAO.findById(categoryId);
}
if (organizationId != null) {
organization = organizationDAO.findById(organizationId);
}
if (!UserUtils.canAccessOrganization(loggedUser, organization)) {
throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "No permission to assign organization to study programme.");
}
if (studyProgrammeId == -1) {
studyProgrammeDAO.create(organization, name, category, code, hasEvaluationFees);
} else {
StudyProgramme studyProgramme = studyProgrammeDAO.findById(studyProgrammeId);
if (!UserUtils.canAccessOrganization(loggedUser, studyProgramme.getOrganization())) {
throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Can not access study programme from another organization.");
}
studyProgrammeDAO.update(studyProgramme, organization, name, category, code, hasEvaluationFees);
}
}
}
jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
use of fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO in project pyramus by otavanopisto.
the class StudyProgrammesSetupWizardViewController method save.
@Override
public void save(PageRequestContext requestContext) throws SetupWizardException {
StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
StudyProgrammeCategoryDAO studyProgrammeCategoryDAO = DAOFactory.getInstance().getStudyProgrammeCategoryDAO();
DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
Defaults defaults = defaultsDAO.getDefaults();
int rowCount = NumberUtils.createInteger(requestContext.getRequest().getParameter("studyProgrammesTable.rowCount")).intValue();
for (int i = 0; i < rowCount; i++) {
String colPrefix = "studyProgrammesTable." + i;
Long studyProgrammeId = requestContext.getLong(colPrefix + ".studyProgrammeId");
String name = requestContext.getString(colPrefix + ".name");
String code = requestContext.getString(colPrefix + ".code");
Long categoryId = requestContext.getLong(colPrefix + ".category");
boolean hasEvaluationFees = false;
StudyProgrammeCategory category = null;
if (categoryId != null) {
category = studyProgrammeCategoryDAO.findById(categoryId);
}
if (studyProgrammeId == -1) {
studyProgrammeDAO.create(defaults.getOrganization(), name, category, code, hasEvaluationFees);
}
}
}
use of fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO in project pyramus by otavanopisto.
the class StudyProgrammesSetupWizardViewController method setup.
@Override
public void setup(PageRequestContext pageRequestContext) throws SetupWizardException {
StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
StudyProgrammeCategoryDAO studyProgrammeCategoryDAO = DAOFactory.getInstance().getStudyProgrammeCategoryDAO();
List<StudyProgramme> studyProgrammes = studyProgrammeDAO.listUnarchived();
JSONArray jsonStudyProgrammes = new JSONArrayExtractor("name", "code", "id").extract(studyProgrammes);
for (int i = 0; i < jsonStudyProgrammes.size(); i++) {
JSONObject jsonStudyProgrammeCategory = jsonStudyProgrammes.getJSONObject(i);
if (studyProgrammes.get(i).getCategory() != null) {
jsonStudyProgrammeCategory.put("categoryId", studyProgrammes.get(i).getCategory().getId());
}
}
String jsonCategories = new JSONArrayExtractor("name", "id").extractString(studyProgrammeCategoryDAO.listUnarchived());
this.setJsDataVariable(pageRequestContext, "studyProgrammes", jsonStudyProgrammes.toString());
this.setJsDataVariable(pageRequestContext, "categories", jsonCategories);
}
use of fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO in project pyramus by otavanopisto.
the class ArchiveStudyProgrammeCategoryJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
StudyProgrammeCategoryDAO studyProgrammeCategoryDAO = DAOFactory.getInstance().getStudyProgrammeCategoryDAO();
Long studyProgrammeCategoryId = requestContext.getLong("studyProgrammeCategory");
StudyProgrammeCategory studyProgrammeCategory = studyProgrammeCategoryDAO.findById(studyProgrammeCategoryId);
studyProgrammeCategoryDAO.archive(studyProgrammeCategory);
}
Aggregations