Search in sources :

Example 1 with StudyProgrammeCategoryDAO

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");
}
Also used : EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) JSONObject(net.sf.json.JSONObject) StudyProgrammeCategory(fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory) StudyProgrammeCategoryDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) JSONArray(net.sf.json.JSONArray) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor)

Example 2 with StudyProgrammeCategoryDAO

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));
}
Also used : Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) StudyProgrammeCategory(fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) StudyProgrammeCategoryDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO)

Example 3 with StudyProgrammeCategoryDAO

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);
        }
    }
}
Also used : Defaults(fi.otavanopisto.pyramus.domainmodel.base.Defaults) StudyProgrammeCategory(fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory) StudyProgrammeCategoryDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO)

Example 4 with StudyProgrammeCategoryDAO

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);
}
Also used : StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) JSONObject(net.sf.json.JSONObject) StudyProgrammeCategoryDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO) JSONArray(net.sf.json.JSONArray) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO)

Example 5 with StudyProgrammeCategoryDAO

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);
}
Also used : StudyProgrammeCategory(fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory) StudyProgrammeCategoryDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO)

Aggregations

StudyProgrammeCategoryDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO)10 StudyProgrammeCategory (fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory)7 EducationTypeDAO (fi.otavanopisto.pyramus.dao.base.EducationTypeDAO)4 StudyProgrammeDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO)4 EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)4 JSONArrayExtractor (fi.otavanopisto.pyramus.util.JSONArrayExtractor)4 JSONArray (net.sf.json.JSONArray)4 JSONObject (net.sf.json.JSONObject)4 StudyProgramme (fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme)3 OrganizationDAO (fi.otavanopisto.pyramus.dao.base.OrganizationDAO)2 StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)2 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)1 DefaultsDAO (fi.otavanopisto.pyramus.dao.base.DefaultsDAO)1 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)1 Defaults (fi.otavanopisto.pyramus.domainmodel.base.Defaults)1 Organization (fi.otavanopisto.pyramus.domainmodel.base.Organization)1 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)1 ArrayList (java.util.ArrayList)1