Search in sources :

Example 1 with StudyProgrammeCategory

use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory in project pyramus by otavanopisto.

the class StudyProgrammeCategoryEntityFactory method buildFromDomainObject.

public StudyProgrammeCategoryEntity buildFromDomainObject(Object domainObject) {
    if (domainObject == null) {
        return null;
    }
    StudyProgrammeCategory studyProgrammeCategory = (StudyProgrammeCategory) domainObject;
    EducationTypeEntity educationTypeEntity = EntityFactoryVault.buildFromDomainObject(studyProgrammeCategory.getEducationType());
    return new StudyProgrammeCategoryEntity(studyProgrammeCategory.getId(), studyProgrammeCategory.getName(), studyProgrammeCategory.getArchived(), educationTypeEntity);
}
Also used : StudyProgrammeCategory(fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory)

Example 2 with StudyProgrammeCategory

use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory 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 3 with StudyProgrammeCategory

use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory in project pyramus by otavanopisto.

the class StudentRESTService method updateStudyProgrammeCategory.

@Path("/studyProgrammeCategories/{ID:[0-9]*}")
@PUT
@RESTPermit(StudyProgrammeCategoryPermissions.UPDATE_STUDYPROGRAMMECATEGORY)
public Response updateStudyProgrammeCategory(@PathParam("ID") Long id, fi.otavanopisto.pyramus.rest.model.StudyProgrammeCategory entity) {
    StudyProgrammeCategory studyProgrammeCategory = studyProgrammeCategoryController.findStudyProgrammeCategoryById(id);
    if (studyProgrammeCategory == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (studyProgrammeCategory.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    String name = entity.getName();
    if (StringUtils.isBlank(name)) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    if (entity.getEducationTypeId() == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    EducationType educationType = commonController.findEducationTypeById(entity.getEducationTypeId());
    if (educationType == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    return Response.ok().entity(objectFactory.createModel(studyProgrammeCategoryController.updateStudyProgrammeCategory(studyProgrammeCategory, name, educationType))).build();
}
Also used : EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) StudyProgrammeCategory(fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) PUT(javax.ws.rs.PUT)

Example 4 with StudyProgrammeCategory

use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory in project pyramus by otavanopisto.

the class StudyProgrammeCategoryDAO method listByName.

public List<StudyProgrammeCategory> listByName(String name) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StudyProgrammeCategory> criteria = criteriaBuilder.createQuery(StudyProgrammeCategory.class);
    Root<StudyProgrammeCategory> root = criteria.from(StudyProgrammeCategory.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.get(StudyProgrammeCategory_.name), name));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) StudyProgrammeCategory(fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory)

Example 5 with StudyProgrammeCategory

use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory 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)

Aggregations

StudyProgrammeCategory (fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory)15 StudyProgrammeCategoryDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO)7 EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)5 Organization (fi.otavanopisto.pyramus.domainmodel.base.Organization)5 StudyProgramme (fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme)4 EducationTypeDAO (fi.otavanopisto.pyramus.dao.base.EducationTypeDAO)3 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)3 Path (javax.ws.rs.Path)3 OrganizationDAO (fi.otavanopisto.pyramus.dao.base.OrganizationDAO)2 StudyProgrammeDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO)2 ArrayList (java.util.ArrayList)2 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)1 DefaultsDAO (fi.otavanopisto.pyramus.dao.base.DefaultsDAO)1 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)1 Address (fi.otavanopisto.pyramus.domainmodel.base.Address)1 BillingDetails (fi.otavanopisto.pyramus.domainmodel.base.BillingDetails)1 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)1 ContactURL (fi.otavanopisto.pyramus.domainmodel.base.ContactURL)1 ContactURLType (fi.otavanopisto.pyramus.domainmodel.base.ContactURLType)1 CourseBaseVariable (fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariable)1