use of fi.otavanopisto.pyramus.dao.base.CurriculumDAO in project pyramus by otavanopisto.
the class EditModuleJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
CourseDescriptionDAO courseDescriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
CourseDescriptionCategoryDAO descriptionCategoryDAO = DAOFactory.getInstance().getCourseDescriptionCategoryDAO();
CourseEducationTypeDAO courseEducationTypeDAO = DAOFactory.getInstance().getCourseEducationTypeDAO();
CourseEducationSubtypeDAO courseEducationSubtypeDAO = DAOFactory.getInstance().getCourseEducationSubtypeDAO();
ModuleComponentDAO moduleComponentDAO = DAOFactory.getInstance().getModuleComponentDAO();
EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
EducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getEducationSubtypeDAO();
SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
Long moduleId = requestContext.getLong("moduleId");
Module module = moduleDAO.findById(moduleId);
Long version = requestContext.getLong("version");
if (!module.getVersion().equals(version))
throw new StaleObjectStateException(Module.class.getName(), module.getId());
// Education types and subtypes submitted from the web page
Map<Long, Vector<Long>> chosenEducationTypes = new HashMap<>();
Enumeration<String> parameterNames = requestContext.getRequest().getParameterNames();
while (parameterNames.hasMoreElements()) {
String name = (String) parameterNames.nextElement();
if (name.startsWith("educationType.")) {
String[] nameElements = name.split("\\.");
Long educationTypeId = new Long(nameElements[1]);
Long educationSubtypeId = new Long(nameElements[2]);
Vector<Long> v = chosenEducationTypes.containsKey(educationTypeId) ? chosenEducationTypes.get(educationTypeId) : new Vector<Long>();
v.add(educationSubtypeId);
if (!chosenEducationTypes.containsKey(educationTypeId)) {
chosenEducationTypes.put(educationTypeId, v);
}
}
}
// Course Descriptions
List<CourseDescriptionCategory> descriptionCategories = descriptionCategoryDAO.listUnarchived();
Set<CourseDescription> nonExistingDescriptions = new HashSet<>();
for (CourseDescriptionCategory cat : descriptionCategories) {
String varName = "courseDescription." + cat.getId().toString();
Long descriptionCatId = requestContext.getLong(varName + ".catId");
String descriptionText = requestContext.getString(varName + ".text");
CourseDescription oldDesc = courseDescriptionDAO.findByCourseAndCategory(module, cat);
if (descriptionCatId != null && descriptionCatId.intValue() != -1) {
// Description has been submitted from form
if (oldDesc != null)
courseDescriptionDAO.update(oldDesc, module, cat, descriptionText);
else
courseDescriptionDAO.create(module, cat, descriptionText);
} else {
// Description wasn't submitted from form, if it exists, it's marked for deletion
if (oldDesc != null)
nonExistingDescriptions.add(oldDesc);
}
}
// Delete non existing descriptions
for (CourseDescription desc : nonExistingDescriptions) {
courseDescriptionDAO.delete(desc);
}
// Remove education types and subtypes
List<CourseEducationType> courseEducationTypes = module.getCourseEducationTypes();
for (int i = courseEducationTypes.size() - 1; i >= 0; i--) {
CourseEducationType courseEducationType = courseEducationTypes.get(i);
if (!chosenEducationTypes.containsKey(courseEducationType.getEducationType().getId())) {
courseEducationTypeDAO.delete(courseEducationType);
} else {
Vector<Long> v = chosenEducationTypes.get(courseEducationType.getEducationType().getId());
List<CourseEducationSubtype> courseEducationSubtypes = courseEducationType.getCourseEducationSubtypes();
for (int j = courseEducationSubtypes.size() - 1; j >= 0; j--) {
CourseEducationSubtype moduleEducationSubtype = courseEducationSubtypes.get(j);
if (!v.contains(moduleEducationSubtype.getEducationSubtype().getId())) {
courseEducationType.removeSubtype(moduleEducationSubtype);
}
}
}
}
for (Map.Entry<Long, Vector<Long>> entry : chosenEducationTypes.entrySet()) {
EducationType educationType = educationTypeDAO.findById(entry.getKey());
CourseEducationType courseEducationType;
if (!module.contains(educationType)) {
courseEducationType = courseEducationTypeDAO.create(module, educationType);
} else {
courseEducationType = module.getCourseEducationTypeByEducationTypeId(entry.getKey());
}
for (Long educationSubtypeId : entry.getValue()) {
EducationSubtype educationSubtype = educationSubtypeDAO.findById(educationSubtypeId);
if (!courseEducationType.contains(educationSubtype)) {
courseEducationSubtypeDAO.create(courseEducationType, educationSubtype);
}
}
}
// Module components
int rowCount = requestContext.getInteger("componentsTable.rowCount");
for (int i = 0; i < rowCount; i++) {
String colPrefix = "componentsTable." + i;
String componentName = requestContext.getString(colPrefix + ".name");
Double componentLength = requestContext.getDouble(colPrefix + ".length");
String componentDescription = requestContext.getString(colPrefix + ".description");
Long componentId = requestContext.getLong(colPrefix + ".componentId");
// TODO Component length; should be just hours but it currently depends on the default time unit - ok?
EducationalTimeUnit componentTimeUnit = defaultsDAO.getDefaults().getBaseTimeUnit();
if (componentId == -1) {
componentId = moduleComponentDAO.create(module, componentLength, componentTimeUnit, componentName, componentDescription).getId();
} else {
moduleComponentDAO.update(moduleComponentDAO.findById(componentId), componentLength, componentTimeUnit, componentName, componentDescription);
}
}
// Module basic information
Long subjectId = requestContext.getLong("subject");
Subject subject = subjectDAO.findById(subjectId);
Integer courseNumber = requestContext.getInteger("courseNumber");
String name = requestContext.getString("name");
String description = requestContext.getString("description");
User loggedUser = userDAO.findById(requestContext.getLoggedUserId());
Double moduleLength = requestContext.getDouble("moduleLength");
Long moduleLengthTimeUnitId = requestContext.getLong("moduleLengthTimeUnit");
Long maxParticipantCount = requestContext.getLong("maxParticipantCount");
String tagsText = requestContext.getString("tags");
List<Curriculum> allCurriculums = curriculumDAO.listUnarchived();
Set<Curriculum> curriculums = new HashSet<>();
for (Curriculum curriculum : allCurriculums) {
if ("1".equals(requestContext.getString("curriculum." + curriculum.getId()))) {
curriculums.add(curriculum);
}
}
Set<Tag> tagEntities = new HashSet<>();
if (!StringUtils.isBlank(tagsText)) {
List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
for (String tag : tags) {
if (!StringUtils.isBlank(tag)) {
Tag tagEntity = tagDAO.findByText(tag.trim());
if (tagEntity == null)
tagEntity = tagDAO.create(tag);
tagEntities.add(tagEntity);
}
}
}
EducationalTimeUnit moduleLengthTimeUnit = educationalTimeUnitDAO.findById(moduleLengthTimeUnitId);
moduleDAO.update(module, name, subject, courseNumber, moduleLength, moduleLengthTimeUnit, description, maxParticipantCount, loggedUser);
moduleDAO.updateCurriculums(module, curriculums);
// Tags
moduleDAO.updateTags(module, tagEntities);
requestContext.setRedirectURL(requestContext.getReferer(true));
}
use of fi.otavanopisto.pyramus.dao.base.CurriculumDAO in project pyramus by otavanopisto.
the class CreateModuleJSONRequestController method process.
/**
* Processes the request to create a module.
*
* @param requestContext The JSON request context
*/
public void process(JSONRequestContext requestContext) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
CourseDescriptionCategoryDAO descriptionCategoryDAO = DAOFactory.getInstance().getCourseDescriptionCategoryDAO();
CourseEducationTypeDAO courseEducationTypeDAO = DAOFactory.getInstance().getCourseEducationTypeDAO();
CourseEducationSubtypeDAO courseEducationSubtypeDAO = DAOFactory.getInstance().getCourseEducationSubtypeDAO();
ModuleComponentDAO moduleComponentDAO = DAOFactory.getInstance().getModuleComponentDAO();
EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
EducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getEducationSubtypeDAO();
SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
String name = requestContext.getString("name");
String description = requestContext.getString("description");
Subject subject = subjectDAO.findById(requestContext.getLong("subject"));
Integer courseNumber = requestContext.getInteger("courseNumber");
User loggedUser = userDAO.findById(requestContext.getLoggedUserId());
Long moduleLengthTimeUnitId = requestContext.getLong("moduleLengthTimeUnit");
Long maxParticipantCount = requestContext.getLong("maxParticipantCount");
EducationalTimeUnit moduleLengthTimeUnit = educationalTimeUnitDAO.findById(moduleLengthTimeUnitId);
Double moduleLength = requestContext.getDouble("moduleLength");
String tagsText = requestContext.getString("tags");
List<Curriculum> allCurriculums = curriculumDAO.listUnarchived();
Set<Curriculum> curriculums = new HashSet<>();
for (Curriculum curriculum : allCurriculums) {
if ("1".equals(requestContext.getString("curriculum." + curriculum.getId()))) {
curriculums.add(curriculum);
}
}
Set<Tag> tagEntities = new HashSet<>();
if (!StringUtils.isBlank(tagsText)) {
List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
for (String tag : tags) {
if (!StringUtils.isBlank(tag)) {
Tag tagEntity = tagDAO.findByText(tag.trim());
if (tagEntity == null)
tagEntity = tagDAO.create(tag);
tagEntities.add(tagEntity);
}
}
}
Module module = moduleDAO.create(name, subject, courseNumber, moduleLength, moduleLengthTimeUnit, description, maxParticipantCount, loggedUser);
moduleDAO.updateCurriculums(module, curriculums);
// Tags
moduleDAO.updateTags(module, tagEntities);
// Course Descriptions
List<CourseDescriptionCategory> descriptionCategories = descriptionCategoryDAO.listUnarchived();
for (CourseDescriptionCategory cat : descriptionCategories) {
String varName = "courseDescription." + cat.getId().toString();
Long descriptionCatId = requestContext.getLong(varName + ".catId");
String descriptionText = requestContext.getString(varName + ".text");
if (descriptionCatId != null && descriptionCatId.intValue() != -1) {
descriptionDAO.create(module, cat, descriptionText);
}
}
// Module components
int rowCount = requestContext.getInteger("componentsTable.rowCount");
for (int i = 0; i < rowCount; i++) {
String colPrefix = "componentsTable." + i;
String componentName = requestContext.getString(colPrefix + ".name");
Double componentLength = requestContext.getDouble(colPrefix + ".length");
String componentDescription = requestContext.getString(colPrefix + ".description");
// TODO Component length; should be just hours but it currently depends on the default time unit - ok?
EducationalTimeUnit componentTimeUnit = defaultsDAO.getDefaults().getBaseTimeUnit();
moduleComponentDAO.create(module, componentLength, componentTimeUnit, componentName, componentDescription).getId();
}
// Education types and subtypes submitted from the web page
Map<Long, Vector<Long>> chosenEducationTypes = new HashMap<>();
Enumeration<String> parameterNames = requestContext.getRequest().getParameterNames();
while (parameterNames.hasMoreElements()) {
name = (String) parameterNames.nextElement();
if (name.startsWith("educationType.")) {
String[] nameElements = name.split("\\.");
Long educationTypeId = new Long(nameElements[1]);
Long educationSubtypeId = new Long(nameElements[2]);
Vector<Long> v = chosenEducationTypes.containsKey(educationTypeId) ? chosenEducationTypes.get(educationTypeId) : new Vector<Long>();
v.add(educationSubtypeId);
if (!chosenEducationTypes.containsKey(educationTypeId)) {
chosenEducationTypes.put(educationTypeId, v);
}
}
}
for (Map.Entry<Long, Vector<Long>> entry : chosenEducationTypes.entrySet()) {
EducationType educationType = educationTypeDAO.findById(entry.getKey());
CourseEducationType courseEducationType;
if (!module.contains(educationType)) {
courseEducationType = courseEducationTypeDAO.create(module, educationType);
} else {
courseEducationType = module.getCourseEducationTypeByEducationTypeId(entry.getKey());
}
for (Long educationSubtypeId : entry.getValue()) {
EducationSubtype educationSubtype = educationSubtypeDAO.findById(educationSubtypeId);
if (!courseEducationType.contains(educationSubtype)) {
courseEducationSubtypeDAO.create(courseEducationType, educationSubtype);
}
}
}
String redirectURL = requestContext.getRequest().getContextPath() + "/modules/editmodule.page?module=" + module.getId();
String refererAnchor = requestContext.getRefererAnchor();
if (!StringUtils.isBlank(refererAnchor))
redirectURL += "#" + refererAnchor;
requestContext.setRedirectURL(redirectURL);
}
use of fi.otavanopisto.pyramus.dao.base.CurriculumDAO in project pyramus by otavanopisto.
the class EditStudentViewController method process.
public void process(PageRequestContext pageRequestContext) {
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
StudentActivityTypeDAO studentActivityTypeDAO = DAOFactory.getInstance().getStudentActivityTypeDAO();
StudentEducationalLevelDAO studentEducationalLevelDAO = DAOFactory.getInstance().getStudentEducationalLevelDAO();
StudentExaminationTypeDAO studentExaminationTypeDAO = DAOFactory.getInstance().getStudentExaminationTypeDAO();
StudentStudyEndReasonDAO studyEndReasonDAO = DAOFactory.getInstance().getStudentStudyEndReasonDAO();
UserVariableKeyDAO userVariableKeyDAO = DAOFactory.getInstance().getUserVariableKeyDAO();
UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
NationalityDAO nationalityDAO = DAOFactory.getInstance().getNationalityDAO();
SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
LanguageDAO languageDAO = DAOFactory.getInstance().getLanguageDAO();
ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
ContactURLTypeDAO contactURLTypeDAO = DAOFactory.getInstance().getContactURLTypeDAO();
CreditLinkDAO creditLinkDAO = DAOFactory.getInstance().getCreditLinkDAO();
CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
StudentLodgingPeriodDAO studentLodgingPeriodDAO = DAOFactory.getInstance().getStudentLodgingPeriodDAO();
PersonVariableKeyDAO personVariableKeyDAO = DAOFactory.getInstance().getPersonVariableKeyDAO();
PersonVariableDAO personVariableDAO = DAOFactory.getInstance().getPersonVariableDAO();
StudentStudyPeriodDAO studentStudyPeriodDAO = DAOFactory.getInstance().getStudentStudyPeriodDAO();
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
Locale locale = pageRequestContext.getRequest().getLocale();
User loggedUser = userDAO.findById(pageRequestContext.getLoggedUserId());
Long personId = pageRequestContext.getLong("person");
Person person = personDAO.findById(personId);
List<Student> students = UserUtils.canAccessAllOrganizations(loggedUser) ? studentDAO.listByPerson(person) : studentDAO.listByPersonAndOrganization(person, loggedUser.getOrganization());
Collections.sort(students, new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
/**
* Ordering study programmes as follows
* 1. studies that have start date but no end date (ongoing)
* 2. studies that have no start nor end date
* 3. studies that have ended
* 4. studies that are archived
* 5. other
*/
int o1class = (o1.getArchived()) ? 4 : (o1.getStudyStartDate() != null && o1.getStudyEndDate() == null) ? 1 : (o1.getStudyStartDate() == null && o1.getStudyEndDate() == null) ? 2 : (o1.getStudyEndDate() != null) ? 3 : 5;
int o2class = (o2.getArchived()) ? 4 : (o2.getStudyStartDate() != null && o2.getStudyEndDate() == null) ? 1 : (o2.getStudyStartDate() == null && o2.getStudyEndDate() == null) ? 2 : (o2.getStudyEndDate() != null) ? 3 : 5;
if (o1class == o2class) {
// classes are the same, we try to do last comparison from the start dates
return ((o1.getStudyStartDate() != null) && (o2.getStudyStartDate() != null)) ? o2.getStudyStartDate().compareTo(o1.getStudyStartDate()) : 0;
} else
return o1class < o2class ? -1 : o1class == o2class ? 0 : 1;
}
});
Map<Long, String> studentTags = new HashMap<>();
Map<Long, Boolean> studentHasCredits = new HashMap<>();
List<UserVariableKey> userVariableKeys = userVariableKeyDAO.listByUserEditable(Boolean.TRUE);
Collections.sort(userVariableKeys, new StringAttributeComparator("getVariableName"));
JSONObject studentLodgingPeriods = new JSONObject();
JSONObject studentStudyPeriodsJSON = new JSONObject();
for (Student student : students) {
StringBuilder tagsBuilder = new StringBuilder();
Iterator<Tag> tagIterator = student.getTags().iterator();
while (tagIterator.hasNext()) {
Tag tag = tagIterator.next();
tagsBuilder.append(tag.getText());
if (tagIterator.hasNext())
tagsBuilder.append(' ');
}
studentTags.put(student.getId(), tagsBuilder.toString());
studentHasCredits.put(student.getId(), creditLinkDAO.countByStudent(student) + courseAssessmentDAO.countByStudent(student) + transferCreditDAO.countByStudent(student) > 0);
JSONArray variables = new JSONArray();
for (UserVariableKey userVariableKey : userVariableKeys) {
UserVariable userVariable = userVariableDAO.findByUserAndVariableKey(student, userVariableKey);
JSONObject variable = new JSONObject();
variable.put("type", userVariableKey.getVariableType());
variable.put("name", userVariableKey.getVariableName());
variable.put("key", userVariableKey.getVariableKey());
variable.put("value", userVariable != null ? userVariable.getValue() : "");
variables.add(variable);
}
setJsDataVariable(pageRequestContext, "variables." + student.getId(), variables.toString());
List<StudentLodgingPeriod> studentLodgingPeriodEntities = studentLodgingPeriodDAO.listByStudent(student);
studentLodgingPeriodEntities.sort(Comparator.comparing(StudentLodgingPeriod::getBegin, Comparator.nullsLast(Comparator.naturalOrder())));
JSONArray lodgingPeriods = new JSONArray();
for (StudentLodgingPeriod period : studentLodgingPeriodEntities) {
JSONObject periodJSON = new JSONObject();
periodJSON.put("id", period.getId());
periodJSON.put("begin", period.getBegin() != null ? period.getBegin().getTime() : null);
periodJSON.put("end", period.getEnd() != null ? period.getEnd().getTime() : null);
lodgingPeriods.add(periodJSON);
}
if (!lodgingPeriods.isEmpty()) {
studentLodgingPeriods.put(student.getId(), lodgingPeriods);
}
List<StudentStudyPeriod> studyPeriods = studentStudyPeriodDAO.listByStudent(student);
studyPeriods.sort(Comparator.comparing(StudentStudyPeriod::getBegin, Comparator.nullsLast(Comparator.naturalOrder())));
JSONArray studyPeriodsJSON = new JSONArray();
for (StudentStudyPeriod studyPeriod : studyPeriods) {
JSONObject periodJSON = new JSONObject();
periodJSON.put("id", studyPeriod.getId());
periodJSON.put("begin", studyPeriod.getBegin() != null ? studyPeriod.getBegin().getTime() : null);
periodJSON.put("end", studyPeriod.getEnd() != null ? studyPeriod.getEnd().getTime() : null);
periodJSON.put("type", studyPeriod.getPeriodType());
studyPeriodsJSON.add(periodJSON);
}
if (!studyPeriodsJSON.isEmpty()) {
studentStudyPeriodsJSON.put(student.getId(), studyPeriodsJSON);
}
}
setJsDataVariable(pageRequestContext, "studentLodgingPeriods", studentLodgingPeriods.toString());
setJsDataVariable(pageRequestContext, "studentStudyPeriods", studentStudyPeriodsJSON.toString());
List<PersonVariableKey> personVariableKeys = personVariableKeyDAO.listUserEditablePersonVariableKeys();
Collections.sort(personVariableKeys, new StringAttributeComparator("getVariableName"));
JSONArray personVariablesJSON = new JSONArray();
for (PersonVariableKey personVariableKey : personVariableKeys) {
PersonVariable personVariable = personVariableDAO.findByPersonAndVariableKey(person, personVariableKey);
JSONObject personVariableJSON = new JSONObject();
personVariableJSON.put("type", personVariableKey.getVariableType());
personVariableJSON.put("name", personVariableKey.getVariableName());
personVariableJSON.put("key", personVariableKey.getVariableKey());
personVariableJSON.put("value", personVariable != null ? personVariable.getValue() : "");
personVariablesJSON.add(personVariableJSON);
}
setJsDataVariable(pageRequestContext, "personVariables", personVariablesJSON.toString());
List<Nationality> nationalities = nationalityDAO.listUnarchived();
Collections.sort(nationalities, new StringAttributeComparator("getName"));
List<Municipality> municipalities = municipalityDAO.listUnarchived();
Collections.sort(municipalities, new StringAttributeComparator("getName"));
List<Language> languages = languageDAO.listUnarchived();
Collections.sort(languages, new StringAttributeComparator("getName"));
List<School> schools = schoolDAO.listUnarchived();
Collections.sort(schools, new StringAttributeComparator("getName"));
List<ContactURLType> contactURLTypes = contactURLTypeDAO.listUnarchived();
Collections.sort(contactURLTypes, new StringAttributeComparator("getName"));
List<ContactType> contactTypes = contactTypeDAO.listUnarchived();
Collections.sort(contactTypes, new StringAttributeComparator("getName"));
String username = "";
boolean hasInternalAuthenticationStrategies = AuthenticationProviderVault.getInstance().hasInternalStrategies();
if (UserUtils.allowEditCredentials(loggedUser, person)) {
if (hasInternalAuthenticationStrategies) {
// TODO: Support for multiple internal authentication providers
List<InternalAuthenticationProvider> internalAuthenticationProviders = AuthenticationProviderVault.getInstance().getInternalAuthenticationProviders();
if (internalAuthenticationProviders.size() == 1) {
InternalAuthenticationProvider internalAuthenticationProvider = internalAuthenticationProviders.get(0);
if (internalAuthenticationProvider != null) {
UserIdentification userIdentification = userIdentificationDAO.findByAuthSourceAndPerson(internalAuthenticationProvider.getName(), person);
if (internalAuthenticationProvider.canUpdateCredentials()) {
if (userIdentification != null) {
username = internalAuthenticationProvider.getUsername(userIdentification.getExternalId());
}
}
}
}
}
}
JSONArray studentStudyPeriodTypesJSON = new JSONArray();
for (StudentStudyPeriodType studentStudyPeriodType : StudentStudyPeriodType.values()) {
JSONObject studyPeriodType = new JSONObject();
studyPeriodType.put("id", studentStudyPeriodType.toString());
studyPeriodType.put("displayName", Messages.getInstance().getText(locale, String.format("generic.studentStudyPeriods.%s", studentStudyPeriodType)));
studyPeriodType.put("beginOnly", StudentStudyPeriodType.BEGINDATE_ONLY.contains(studentStudyPeriodType));
studentStudyPeriodTypesJSON.add(studyPeriodType);
}
setJsDataVariable(pageRequestContext, "studentStudyPeriodTypes", studentStudyPeriodTypesJSON.toString());
List<Curriculum> curriculums = curriculumDAO.listUnarchived();
Collections.sort(curriculums, new StringAttributeComparator("getName"));
List<StudyProgramme> studyProgrammes = UserUtils.canAccessAllOrganizations(loggedUser) ? studyProgrammeDAO.listUnarchived() : studyProgrammeDAO.listByOrganization(loggedUser.getOrganization(), Archived.UNARCHIVED);
Collections.sort(studyProgrammes, new StringAttributeComparator("getName"));
List<StaffMember> studyApprovers = staffMemberDAO.listByProperty(StaffMemberProperties.STUDY_APPROVER.getKey(), "1");
// Add study approvers to the list that have been used before so the selections can be persisted
List<StaffMember> selectedStudyApprovers = students.stream().map(student -> student.getStudyApprover()).filter(Objects::nonNull).collect(Collectors.toList());
for (StaffMember selectedStudyApprover : selectedStudyApprovers) {
Long selectedStudyApproverId = selectedStudyApprover.getId();
boolean isSelectedInList = studyApprovers.stream().map(StaffMember::getId).anyMatch(selectedStudyApproverId::equals);
if (!isSelectedInList) {
studyApprovers.add(selectedStudyApprover);
}
}
studyApprovers.sort(Comparator.comparing(StaffMember::getLastName).thenComparing(StaffMember::getFirstName));
readUserVariablePresets(pageRequestContext);
pageRequestContext.getRequest().setAttribute("tags", studentTags);
pageRequestContext.getRequest().setAttribute("person", person);
pageRequestContext.getRequest().setAttribute("students", students);
pageRequestContext.getRequest().setAttribute("activityTypes", studentActivityTypeDAO.listUnarchived());
pageRequestContext.getRequest().setAttribute("contactURLTypes", contactURLTypes);
pageRequestContext.getRequest().setAttribute("contactTypes", contactTypes);
pageRequestContext.getRequest().setAttribute("examinationTypes", studentExaminationTypeDAO.listUnarchived());
pageRequestContext.getRequest().setAttribute("educationalLevels", studentEducationalLevelDAO.listUnarchived());
pageRequestContext.getRequest().setAttribute("nationalities", nationalities);
pageRequestContext.getRequest().setAttribute("municipalities", municipalities);
pageRequestContext.getRequest().setAttribute("languages", languages);
pageRequestContext.getRequest().setAttribute("schools", schools);
pageRequestContext.getRequest().setAttribute("studyProgrammes", studyProgrammes);
pageRequestContext.getRequest().setAttribute("curriculums", curriculums);
pageRequestContext.getRequest().setAttribute("studyEndReasons", studyEndReasonDAO.listByParentReason(null));
pageRequestContext.getRequest().setAttribute("variableKeys", userVariableKeys);
pageRequestContext.getRequest().setAttribute("personVariableKeys", personVariableKeys);
pageRequestContext.getRequest().setAttribute("studentHasCredits", studentHasCredits);
pageRequestContext.getRequest().setAttribute("hasInternalAuthenticationStrategies", hasInternalAuthenticationStrategies);
pageRequestContext.getRequest().setAttribute("username", username);
pageRequestContext.getRequest().setAttribute("allowEditCredentials", UserUtils.allowEditCredentials(loggedUser, person));
pageRequestContext.getRequest().setAttribute("studyApprovers", studyApprovers);
pageRequestContext.setIncludeJSP("/templates/students/editstudent.jsp");
}
use of fi.otavanopisto.pyramus.dao.base.CurriculumDAO in project pyramus by otavanopisto.
the class CreateStudentViewController method process.
public void process(PageRequestContext pageRequestContext) {
StudentActivityTypeDAO studentActivityTypeDAO = DAOFactory.getInstance().getStudentActivityTypeDAO();
StudentEducationalLevelDAO studentEducationalLevelDAO = DAOFactory.getInstance().getStudentEducationalLevelDAO();
StudentExaminationTypeDAO studentExaminationTypeDAO = DAOFactory.getInstance().getStudentExaminationTypeDAO();
StudentStudyEndReasonDAO studyEndReasonDAO = DAOFactory.getInstance().getStudentStudyEndReasonDAO();
UserVariableKeyDAO variableKeyDAO = DAOFactory.getInstance().getUserVariableKeyDAO();
StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
NationalityDAO nationalityDAO = DAOFactory.getInstance().getNationalityDAO();
SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
LanguageDAO languageDAO = DAOFactory.getInstance().getLanguageDAO();
ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
ContactURLTypeDAO contactURLTypeDAO = DAOFactory.getInstance().getContactURLTypeDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
User loggedUser = staffMemberDAO.findById(pageRequestContext.getLoggedUserId());
Long personId = pageRequestContext.getLong("personId");
if (personId != null) {
Person person = personDAO.findById(personId);
StaffMember staffMember = staffMemberDAO.findByPerson(person);
pageRequestContext.getRequest().setAttribute("person", person);
pageRequestContext.getRequest().setAttribute("staffMember", staffMember);
String emails = new JSONArrayExtractor("defaultAddress", "contactType", "address").extractString(staffMember.getContactInfo().getEmails());
String addresses = new JSONArrayExtractor("defaultAddress", "name", "contactType", "streetAddress", "postalCode", "city", "country").extractString(staffMember.getContactInfo().getAddresses());
String phones = new JSONArrayExtractor("defaultNumber", "contactType", "number").extractString(staffMember.getContactInfo().getPhoneNumbers());
setJsDataVariable(pageRequestContext, "createstudent_emails", emails);
setJsDataVariable(pageRequestContext, "createstudent_addresses", addresses);
setJsDataVariable(pageRequestContext, "createstudent_phones", phones);
}
List<StudyProgramme> studyProgrammes = UserUtils.canAccessAllOrganizations(loggedUser) ? studyProgrammeDAO.listUnarchived() : studyProgrammeDAO.listByOrganization(loggedUser.getOrganization(), Archived.UNARCHIVED);
Collections.sort(studyProgrammes, new StringAttributeComparator("getName"));
List<Nationality> nationalities = nationalityDAO.listUnarchived();
Collections.sort(nationalities, new StringAttributeComparator("getName"));
List<Municipality> municipalities = municipalityDAO.listUnarchived();
Collections.sort(municipalities, new StringAttributeComparator("getName"));
List<Language> languages = languageDAO.listUnarchived();
Collections.sort(languages, new StringAttributeComparator("getName"));
List<School> schools = schoolDAO.listUnarchived();
Collections.sort(schools, new StringAttributeComparator("getName"));
List<ContactURLType> contactURLTypes = contactURLTypeDAO.listUnarchived();
Collections.sort(contactURLTypes, new StringAttributeComparator("getName"));
List<ContactType> contactTypes = contactTypeDAO.listUnarchived();
Collections.sort(contactTypes, new StringAttributeComparator("getName"));
List<UserVariableKey> userVariableKeys = variableKeyDAO.listByUserEditable(Boolean.TRUE);
Collections.sort(userVariableKeys, new StringAttributeComparator("getVariableName"));
List<Curriculum> curriculums = curriculumDAO.listUnarchived();
Collections.sort(curriculums, new StringAttributeComparator("getName"));
String jsonContactTypes = new JSONArrayExtractor("name", "id").extractString(contactTypes);
String jsonVariableKeys = new JSONArrayExtractor("variableKey", "variableName", "variableType").extractString(userVariableKeys);
setJsDataVariable(pageRequestContext, "contactTypes", jsonContactTypes);
setJsDataVariable(pageRequestContext, "variableKeys", jsonVariableKeys);
pageRequestContext.getRequest().setAttribute("schools", schools);
pageRequestContext.getRequest().setAttribute("activityTypes", studentActivityTypeDAO.listUnarchived());
pageRequestContext.getRequest().setAttribute("contactURLTypes", contactURLTypes);
pageRequestContext.getRequest().setAttribute("examinationTypes", studentExaminationTypeDAO.listUnarchived());
pageRequestContext.getRequest().setAttribute("educationalLevels", studentEducationalLevelDAO.listUnarchived());
pageRequestContext.getRequest().setAttribute("nationalities", nationalities);
pageRequestContext.getRequest().setAttribute("municipalities", municipalities);
pageRequestContext.getRequest().setAttribute("languages", languages);
pageRequestContext.getRequest().setAttribute("studyProgrammes", studyProgrammes);
pageRequestContext.getRequest().setAttribute("curriculums", curriculums);
pageRequestContext.getRequest().setAttribute("studyEndReasons", studyEndReasonDAO.listByParentReason(null));
pageRequestContext.getRequest().setAttribute("variableKeys", userVariableKeys);
pageRequestContext.setIncludeJSP("/templates/students/createstudent.jsp");
}
use of fi.otavanopisto.pyramus.dao.base.CurriculumDAO in project pyramus by otavanopisto.
the class CurriculumsSetupWizardViewController method save.
@Override
public void save(PageRequestContext requestContext) throws SetupWizardException {
CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
int rowCount = requestContext.getInteger("curriculumsTable.rowCount");
for (int i = 0; i < rowCount; i++) {
String colPrefix = "curriculumsTable." + i;
String name = requestContext.getString(colPrefix + ".name");
curriculumDAO.create(name);
}
}
Aggregations