use of fi.otavanopisto.pyramus.dao.students.StudentDAO in project pyramus by otavanopisto.
the class EditStudentProjectJSONRequestController method process.
public void process(JSONRequestContext jsonRequestContext) {
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
StudentProjectModuleDAO studentProjectModuleDAO = DAOFactory.getInstance().getStudentProjectModuleDAO();
GradeDAO gradeDAO = DAOFactory.getInstance().getGradeDAO();
ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
AcademicTermDAO academicTermDAO = DAOFactory.getInstance().getAcademicTermDAO();
TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
Defaults defaults = defaultsDAO.getDefaults();
// Project
Long studentProjectId = jsonRequestContext.getLong("studentProject");
StudentProject studentProject = studentProjectDAO.findById(studentProjectId);
// Version check
Long version = jsonRequestContext.getLong("version");
if (!studentProject.getVersion().equals(version))
throw new StaleObjectStateException(StudentProject.class.getName(), studentProject.getId());
String name = jsonRequestContext.getString("name");
String description = jsonRequestContext.getString("description");
StaffMember staffMember = staffMemberDAO.findById(jsonRequestContext.getLoggedUserId());
Long optionalStudiesLengthTimeUnitId = jsonRequestContext.getLong("optionalStudiesLengthTimeUnit");
EducationalTimeUnit optionalStudiesLengthTimeUnit = educationalTimeUnitDAO.findById(optionalStudiesLengthTimeUnitId);
Double optionalStudiesLength = jsonRequestContext.getDouble("optionalStudiesLength");
String tagsText = jsonRequestContext.getString("tags");
Long studentId = jsonRequestContext.getLong("student");
CourseOptionality projectOptionality = (CourseOptionality) jsonRequestContext.getEnum("projectOptionality", CourseOptionality.class);
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);
}
}
}
Student student = studentDAO.findById(studentId);
if (!studentProject.getStudent().equals(student)) {
studentProjectDAO.updateStudent(studentProject, student, staffMember);
}
studentProjectDAO.update(studentProject, name, description, optionalStudiesLength, optionalStudiesLengthTimeUnit, projectOptionality, staffMember);
// Tags
studentProjectDAO.updateTags(studentProject, tagEntities);
// ProjectAssessments
int rowCount = jsonRequestContext.getInteger("assessmentsTable.rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String colPrefix = "assessmentsTable." + i;
Long assessmentModified = jsonRequestContext.getLong(colPrefix + ".modified");
if ((assessmentModified != null) && (assessmentModified.intValue() == 1)) {
Long assessmentId = jsonRequestContext.getLong(colPrefix + ".assessmentId");
ProjectAssessment projectAssessment = ((assessmentId != null) && (assessmentId.intValue() != -1)) ? projectAssessmentDAO.findById(assessmentId) : null;
Long assessmentArchived = jsonRequestContext.getLong(colPrefix + ".deleted");
if ((assessmentArchived != null) && (assessmentArchived.intValue() == 1)) {
if (projectAssessment != null)
projectAssessmentDAO.archive(projectAssessment);
else
throw new SmvcRuntimeException(PyramusStatusCode.OK, "Assessment marked for delete does not exist.");
} else {
Date assessmentDate = jsonRequestContext.getDate(colPrefix + ".date");
Long assessmentGradeId = jsonRequestContext.getLong(colPrefix + ".grade");
Grade grade = assessmentGradeId != null ? gradeDAO.findById(assessmentGradeId) : null;
String verbalAssessment = projectAssessment != null ? projectAssessment.getVerbalAssessment() : null;
Long verbalAssessmentModified = jsonRequestContext.getLong(colPrefix + ".verbalModified");
if ((verbalAssessmentModified != null) && (verbalAssessmentModified.intValue() == 1))
verbalAssessment = jsonRequestContext.getString(colPrefix + ".verbalAssessment");
if (projectAssessment == null) {
projectAssessmentDAO.create(studentProject, staffMember, grade, assessmentDate, verbalAssessment);
} else {
projectAssessmentDAO.update(projectAssessment, staffMember, grade, assessmentDate, verbalAssessment);
}
}
}
}
// Student project modules
Set<Long> existingModuleIds = new HashSet<>();
rowCount = jsonRequestContext.getInteger("modulesTable.rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String colPrefix = "modulesTable." + i;
Long studentProjectModuleId = jsonRequestContext.getLong(colPrefix + ".studentProjectModuleId");
CourseOptionality optionality = (CourseOptionality) jsonRequestContext.getEnum(colPrefix + ".optionality", CourseOptionality.class);
Long studyTermId = jsonRequestContext.getLong(colPrefix + ".academicTerm");
AcademicTerm academicTerm = studyTermId == null ? null : academicTermDAO.findById(studyTermId);
if (studentProjectModuleId == -1) {
Long moduleId = jsonRequestContext.getLong(colPrefix + ".moduleId");
Module module = moduleDAO.findById(moduleId);
studentProjectModuleId = studentProjectModuleDAO.create(studentProject, module, academicTerm, optionality).getId();
} else {
studentProjectModuleDAO.update(studentProjectModuleDAO.findById(studentProjectModuleId), academicTerm, optionality);
}
existingModuleIds.add(studentProjectModuleId);
}
// Removed Student project modules
List<StudentProjectModule> studentProjectModules = studentProjectModuleDAO.listByStudentProject(studentProject);
for (StudentProjectModule studentProjectModule : studentProjectModules) {
if (!existingModuleIds.contains(studentProjectModule.getId())) {
studentProjectModuleDAO.delete(studentProjectModule);
}
}
// Student project courses
rowCount = jsonRequestContext.getInteger("coursesTable.rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String colPrefix = "coursesTable." + i;
Long courseId = jsonRequestContext.getLong(colPrefix + ".courseId");
CourseOptionality optionality = (CourseOptionality) jsonRequestContext.getEnum(colPrefix + ".optionality", CourseOptionality.class);
Course course = courseId == -1 ? null : courseDAO.findById(courseId);
CourseStudent courseStudent = courseStudentDAO.findByCourseAndStudent(course, studentProject.getStudent());
if (courseStudent == null) {
CourseEnrolmentType courseEnrolmentType = defaults.getInitialCourseEnrolmentType();
CourseParticipationType participationType = defaults.getInitialCourseParticipationType();
Date enrolmentDate = new Date(System.currentTimeMillis());
Boolean lodging = Boolean.FALSE;
String organization = null;
String additionalInfo = null;
Room room = null;
BigDecimal lodgingFee = null;
Currency lodgingFeeCurrency = null;
BigDecimal reservationFee = null;
Currency reservationFeeCurrency = null;
try {
courseStudent = courseStudentDAO.create(course, studentProject.getStudent(), courseEnrolmentType, participationType, enrolmentDate, lodging, optionality, null, organization, additionalInfo, room, lodgingFee, lodgingFeeCurrency, reservationFee, reservationFeeCurrency, Boolean.FALSE);
} catch (DuplicateCourseStudentException dcse) {
Locale locale = jsonRequestContext.getRequest().getLocale();
throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, Messages.getInstance().getText(locale, "generic.errors.duplicateCourseStudent", new Object[] { student.getFullName() }));
}
} else {
courseStudentDAO.updateOptionality(courseStudent, optionality);
}
}
jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
use of fi.otavanopisto.pyramus.dao.students.StudentDAO in project pyramus by otavanopisto.
the class UpdateApplicationStateJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
try {
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
StaffMember staffMember = requestContext.getLoggedUserId() == null ? null : staffMemberDAO.findById(requestContext.getLoggedUserId());
if (staffMember == null) {
fail(requestContext, "Et ole kirjautunut sisään");
return;
}
Long id = requestContext.getLong("id");
if (id == null) {
fail(requestContext, "Puuttuva hakemustunnus");
return;
}
ApplicationState applicationState = ApplicationState.valueOf(requestContext.getString("state"));
Boolean lockApplication = requestContext.getBoolean("lockApplication");
Boolean setHandler = requestContext.getBoolean("setHandler");
Boolean removeHandler = requestContext.getBoolean("removeHandler");
// Application update
ApplicationDAO applicationDAO = DAOFactory.getInstance().getApplicationDAO();
Application application = applicationDAO.findById(id);
if (application == null) {
fail(requestContext, "Puuttuva hakemus");
return;
}
if (application.getState() != applicationState) {
if (applicationState == ApplicationState.APPROVED_BY_SCHOOL) {
// Gather required dynamic data from the application form
JSONObject formData = JSONObject.fromObject(application.getFormData());
String line = ApplicationUtils.applicationLineUiValue(application.getLine());
String applicantName = String.format("%s %s", getFormValue(formData, "field-first-names"), getFormValue(formData, "field-last-name"));
String ssn = ApplicationUtils.constructSSN(getFormValue(formData, "field-birthday"), getFormValue(formData, "field-ssn-end"));
String address = String.format("%s, %s %s, %s", getFormValue(formData, "field-street-address"), getFormValue(formData, "field-zip-code"), getFormValue(formData, "field-city"), getFormValue(formData, "field-country"));
String municipality = ApplicationUtils.municipalityUiValue(getFormValue(formData, "field-municipality"));
String nationality = ApplicationUtils.nationalityUiValue(getFormValue(formData, "field-nationality"));
String phone = getFormValue(formData, "field-phone");
String email = StringUtils.lowerCase(StringUtils.trim(getFormValue(formData, "field-email")));
String nickname = getFormValue(formData, "field-nickname");
String guardianMail = getFormValue(formData, "field-underage-email");
// Make sure we have application signatures and school approval
ApplicationSignaturesDAO applicationSignaturesDAO = DAOFactory.getInstance().getApplicationSignaturesDAO();
ApplicationSignatures applicationSignatures = applicationSignaturesDAO.findByApplication(application);
if (applicationSignatures == null || applicationSignatures.getStaffDocumentState() != ApplicationSignatureState.SIGNED) {
logger.log(Level.WARNING, String.format("Application %s not signed by staff", application.getApplicationId()));
fail(requestContext, "Oppilaitos ei ole vielä allekirjoittanut hyväksymisasiakirjaa");
return;
}
OnnistuuClient onnistuuClient = OnnistuuClient.getInstance();
// Create Onnistuu document (if not done before)
String documentId = null;
if (applicationSignatures.getApplicantDocumentId() == null) {
documentId = onnistuuClient.createDocument(String.format("Vastaanotto: %s", applicantName));
applicationSignatures = applicationSignaturesDAO.updateApplicantDocument(applicationSignatures, documentId, null, null, ApplicationSignatureState.DOCUMENT_CREATED);
} else {
documentId = applicationSignatures.getApplicantDocumentId();
}
if (applicationSignatures.getApplicantDocumentState() == ApplicationSignatureState.DOCUMENT_CREATED) {
byte[] pdf = onnistuuClient.generateApplicantSignatureDocument(requestContext, line, applicantName, ssn, address, municipality, nationality, phone, email);
onnistuuClient.addPdf(documentId, pdf);
applicationSignatures = applicationSignaturesDAO.updateApplicantDocument(applicationSignatures, documentId, null, null, ApplicationSignatureState.PDF_UPLOADED);
}
if (applicationSignatures.getApplicantDocumentState() == ApplicationSignatureState.PDF_UPLOADED) {
OnnistuuClient.Invitation invitation = onnistuuClient.createInvitation(documentId, email);
applicationSignatures = applicationSignaturesDAO.updateApplicantDocument(applicationSignatures, documentId, invitation.getUuid(), invitation.getPassphrase(), ApplicationSignatureState.INVITATION_CREATED);
}
// Construct accepted mail template
String staffDocUrl = String.format("https://www.onnistuu.fi/api/v1/invitation/%s/%s/files/0", applicationSignatures.getStaffInvitationId(), applicationSignatures.getStaffInvitationToken());
StringBuilder signUpUrl = new StringBuilder();
signUpUrl.append(requestContext.getRequest().getScheme());
signUpUrl.append("://");
signUpUrl.append(requestContext.getRequest().getServerName());
signUpUrl.append(":");
signUpUrl.append(requestContext.getRequest().getServerPort());
signUpUrl.append("/applications/accept.page?application=");
signUpUrl.append(application.getApplicationId());
String lineOrganization = ApplicationUtils.isOtaviaLine(application.getLine()) ? "Otavian" : "Otavan Opiston";
String signerOrganization = ApplicationUtils.isOtaviaLine(application.getLine()) ? "Otavia" : "Otavan Opisto";
String subject = String.format("Hyväksyminen %s opiskelijaksi", lineOrganization);
String content = IOUtils.toString(requestContext.getServletContext().getResourceAsStream("/templates/applications/mails/mail-accept-study-place.html"), "UTF-8");
content = String.format(content, nickname, lineOrganization, line.toLowerCase(), staffDocUrl, staffDocUrl, signUpUrl.toString(), signUpUrl.toString(), staffMember.getFullName(), signerOrganization);
if (StringUtils.isBlank(guardianMail)) {
Mailer.sendMail(Mailer.JNDI_APPLICATION, Mailer.HTML, null, email, subject, content);
} else {
Mailer.sendMail(Mailer.JNDI_APPLICATION, Mailer.HTML, null, email, guardianMail, subject, content);
}
// Add notification about sent mail
ApplicationLogDAO applicationLogDAO = DAOFactory.getInstance().getApplicationLogDAO();
applicationLogDAO.create(application, ApplicationLogType.HTML, String.format("<p>%s</p><p><b>%s</b></p>%s", "Hakijalle lähetetty ilmoitus opiskelijaksi hyväksymisestä", subject, content), staffMember);
} else // end of application has been approved logic
if (applicationState == ApplicationState.TRANSFERRED_AS_STUDENT) {
// Separate logic for transferring the applicant as student
// throws exception if multiple persons or is staff
Student student = ApplicationUtils.createPyramusStudent(application, staffMember);
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
personDAO.updateDefaultUser(student.getPerson(), student);
String credentialToken = RandomStringUtils.randomAlphanumeric(32).toLowerCase();
application = applicationDAO.updateApplicationStudentAndCredentialToken(application, student, credentialToken);
ApplicationUtils.mailCredentialsInfo(requestContext.getRequest(), student, application);
} else if (applicationState == ApplicationState.REJECTED) {
if (application.getState() == ApplicationState.REGISTERED_AS_STUDENT) {
Student student = application.getStudent();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
studentDAO.archive(student);
}
// #4226: Applications of rejected Internetix students are removed immediately
if (StringUtils.equals("aineopiskelu", application.getLine())) {
ApplicationUtils.deleteApplication(application);
requestContext.setRedirectURL(requestContext.getRequest().getContextPath() + "/applications/browse.page");
return;
}
} else if (applicationState == ApplicationState.PROCESSING) {
// #1216: If a signed application is returned to Processing state, remove the
// previous signatures so that the proper processing order can once again be followed
ApplicationSignaturesDAO applicationSignaturesDAO = DAOFactory.getInstance().getApplicationSignaturesDAO();
ApplicationSignatures applicationSignatures = applicationSignaturesDAO.findByApplication(application);
if (applicationSignatures != null) {
applicationSignaturesDAO.delete(applicationSignatures);
}
}
// Update the actual application state
application = applicationDAO.updateApplicationState(application, applicationState, staffMember);
if (Boolean.TRUE.equals(lockApplication) && application.getApplicantEditable()) {
application = applicationDAO.updateApplicantEditable(application, Boolean.FALSE, staffMember);
}
if (Boolean.TRUE.equals(setHandler)) {
application = applicationDAO.updateApplicationHandler(application, staffMember);
}
if (Boolean.TRUE.equals(removeHandler)) {
application = applicationDAO.updateApplicationHandler(application, null);
}
// Email notifications and log entries related to state change
ApplicationUtils.sendNotifications(application, requestContext.getRequest(), staffMember, false, null, true);
}
// Response parameters
requestContext.addResponseParameter("status", "OK");
requestContext.addResponseParameter("id", application.getId());
requestContext.addResponseParameter("state", application.getState());
requestContext.addResponseParameter("stateUi", ApplicationUtils.applicationStateUiValue(application.getState()));
requestContext.addResponseParameter("applicantEditable", application.getApplicantEditable());
requestContext.addResponseParameter("handler", application.getHandler() == null ? null : application.getHandler().getFullName());
requestContext.addResponseParameter("handlerId", application.getHandler() == null ? null : application.getHandler().getId());
requestContext.addResponseParameter("lastModified", application.getLastModified().getTime());
} catch (Exception e) {
requestContext.addResponseParameter("status", "FAIL");
requestContext.addResponseParameter("reason", e.getMessage());
logger.log(Level.SEVERE, "Error updating application state", e);
}
}
use of fi.otavanopisto.pyramus.dao.students.StudentDAO in project pyramus by otavanopisto.
the class CoursesService method listCourseStudentsByStudent.
public CourseStudentEntity[] listCourseStudentsByStudent(@WebParam(name = "studentId") Long studentId) {
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
Student student = studentDAO.findById(studentId);
return (CourseStudentEntity[]) EntityFactoryVault.buildFromDomainObjects(courseStudentDAO.listByStudent(student));
}
use of fi.otavanopisto.pyramus.dao.students.StudentDAO in project pyramus by otavanopisto.
the class CoursesService method addCourseStudent.
public CourseStudentEntity addCourseStudent(@WebParam(name = "courseId") Long courseId, @WebParam(name = "studentId") Long studentId, @WebParam(name = "courseEnrolmentTypeId") Long courseEnrolmentTypeId, @WebParam(name = "participationTypeId") Long participationTypeId, @WebParam(name = "enrolmentDate") Date enrolmentDate, @WebParam(name = "lodging") Boolean lodging, @WebParam(name = "optionality") String optionality) throws DuplicateCourseStudentException {
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
CourseParticipationTypeDAO participationTypeDAO = DAOFactory.getInstance().getCourseParticipationTypeDAO();
CourseEnrolmentTypeDAO enrolmentTypeDAO = DAOFactory.getInstance().getCourseEnrolmentTypeDAO();
CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
Defaults defaults = defaultsDAO.getDefaults();
Course course = courseDAO.findById(courseId);
Student student = studentDAO.findById(studentId);
CourseEnrolmentType courseEnrolmentType = courseEnrolmentTypeId == null ? defaults.getInitialCourseEnrolmentType() : enrolmentTypeDAO.findById(courseEnrolmentTypeId);
CourseParticipationType participationType = participationTypeId == null ? defaults.getInitialCourseParticipationType() : participationTypeDAO.findById(participationTypeId);
CourseOptionality cOptionality = null;
if (!StringUtils.isBlank(optionality))
cOptionality = CourseOptionality.valueOf(optionality);
Room room = null;
BigDecimal lodgingFee = null;
Currency lodgingFeeCurrency = null;
BigDecimal reservationFee = null;
Currency reservationFeeCurrency = null;
String organization = null;
String additionalInfo = null;
CourseStudent courseStudent = courseStudentDAO.create(course, student, courseEnrolmentType, participationType, enrolmentDate, lodging, cOptionality, null, organization, additionalInfo, room, lodgingFee, lodgingFeeCurrency, reservationFee, reservationFeeCurrency, Boolean.FALSE);
validateEntity(courseStudent);
return EntityFactoryVault.buildFromDomainObject(courseStudent);
}
use of fi.otavanopisto.pyramus.dao.students.StudentDAO in project pyramus by otavanopisto.
the class StudentsService method addStudentEmail.
public void addStudentEmail(@WebParam(name = "studentId") Long studentId, @WebParam(name = "defaultAddress") Boolean defaultAddress, @WebParam(name = "address") String address) {
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
Student student = studentDAO.findById(studentId);
address = StringUtils.trim(address);
if (StringUtils.isNotBlank(address)) {
// TODO contactType
ContactType contactType = contactTypeDAO.findById(new Long(1));
if (!UserUtils.isAllowedEmail(address, contactType, student.getPerson().getId()))
throw new RuntimeException("Email address is in use");
Email email = emailDAO.create(student.getContactInfo(), contactType, defaultAddress, address);
validateEntity(email);
}
}
Aggregations