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);
}
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");
}
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();
}
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();
}
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));
}
Aggregations