use of fi.otavanopisto.pyramus.dao.base.PersonDAO in project pyramus by otavanopisto.
the class GetStudentStudyProgrammesJSONRequestController method process.
/**
* Processes JSON request
*
* In parameters
* - studentId - student id to retrieve information for
*
* Page parameters
* - student - Map including
* * id - Student id
* * firstname - First name
* * lastname - Last name
*
* @param requestContext JSON request context
*/
public void process(JSONRequestContext requestContext) {
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
Long personId = NumberUtils.createLong(requestContext.getRequest().getParameter("personId"));
Person person = personDAO.findById(personId);
List<Student> students = studentDAO.listByPerson(person);
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;
}
});
List<Map<String, Object>> result = new ArrayList<>();
for (int i = 0; i < students.size(); i++) {
Student student = students.get(i);
if (student != null) {
if (student.getStudyProgramme() != null) {
Map<String, Object> studentInfo = new HashMap<>();
studentInfo.put("studyProgrammeId", student.getStudyProgramme().getId());
String studyProgrammeName = student.getStudyProgramme().getName();
if (student.getStudyEndDate() != null) {
studyProgrammeName += " *";
}
studentInfo.put("studyProgrammeName", studyProgrammeName);
studentInfo.put("studentId", student.getId());
result.add(studentInfo);
} else {
Map<String, Object> studentInfo = new HashMap<>();
studentInfo.put("studyProgrammeId", new Long(-1));
if (!student.getArchived())
studentInfo.put("studyProgrammeName", Messages.getInstance().getText(requestContext.getRequest().getLocale(), "students.editStudent.noStudyProgrammeDropDownItemLabel"));
else
studentInfo.put("studyProgrammeName", Messages.getInstance().getText(requestContext.getRequest().getLocale(), "students.editStudent.noStudyProgrammeDropDownItemLabel") + " *");
studentInfo.put("studentId", student.getId());
result.add(studentInfo);
}
}
}
requestContext.addResponseParameter("studentStudyProgrammes", result);
}
use of fi.otavanopisto.pyramus.dao.base.PersonDAO in project pyramus by otavanopisto.
the class ListKoskiPersonLogEntriesJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
try {
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
KoskiPersonLogDAO koskiPersonLogDAO = DAOFactory.getInstance().getKoskiPersonLogDAO();
Long personId = requestContext.getLong("personId");
if (personId == null) {
logger.log(Level.WARNING, "Unable to load log entries due to missing personId.");
requestContext.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
Person person = personDAO.findById(personId);
List<KoskiPersonLog> logEntries = koskiPersonLogDAO.listByPerson(person);
logEntries.sort((a, b) -> Comparator.nullsFirst(Date::compareTo).reversed().compare(a.getDate(), b.getDate()));
Locale locale = requestContext.getRequest().getLocale();
List<Map<String, Object>> results = new ArrayList<>();
for (KoskiPersonLog logEntry : logEntries) {
String studyProgrammeName = logEntry.getStudent() != null && logEntry.getStudent().getStudyProgramme() != null ? logEntry.getStudent().getStudyProgramme().getName() : null;
Map<String, Object> logEntryInfo = new HashMap<>();
logEntryInfo.put("id", logEntry.getId());
logEntryInfo.put("date", logEntry.getDate().getTime());
logEntryInfo.put("state", logEntry.getState());
logEntryInfo.put("stateType", getStateType(logEntry));
logEntryInfo.put("text", getStateDisplayText(logEntry, locale));
logEntryInfo.put("personId", logEntry.getPerson().getId());
logEntryInfo.put("studentId", logEntry.getStudent() != null ? logEntry.getStudent().getId() : null);
logEntryInfo.put("studyProgrammeName", studyProgrammeName);
logEntryInfo.put("message", logEntry.getMessage());
results.add(logEntryInfo);
}
requestContext.addResponseParameter("logEntries", results);
requestContext.addResponseParameter("koskiStatus", getStatus(results));
} catch (Exception e) {
logger.log(Level.SEVERE, "Error loading log entries", e);
}
}
use of fi.otavanopisto.pyramus.dao.base.PersonDAO in project pyramus by otavanopisto.
the class ListKoskiPersonStudiesJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
try {
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
PersonVariableDAO personVariableDAO = DAOFactory.getInstance().getPersonVariableDAO();
Long personId = requestContext.getLong("personId");
if (personId == null) {
logger.log(Level.WARNING, "Unable to load log entries due to missing personId.");
requestContext.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
Person person = personDAO.findById(personId);
String personOid = personVariableDAO.findByPersonAndKey(person, KoskiConsts.VariableNames.KOSKI_HENKILO_OID);
if (StringUtils.isBlank(personOid)) {
return;
}
KoskiClient koskiClient = CDI.current().select(KoskiClient.class).get();
KoskiSettings koskiSettings = CDI.current().select(KoskiSettings.class).get();
KoskiController koskiController = CDI.current().select(KoskiController.class).get();
// Find student info from Koski
OppijaReturnVal koskiStudent = koskiClient.findPersonByOid(personOid);
List<Map<String, Object>> studyPermitIds = new ArrayList<>();
if (koskiStudent != null) {
Map<String, Student> oidMap = new HashMap<>();
List<Student> students = studentDAO.listByPerson(person);
for (Student student : students) {
if (student.getStudyProgramme() != null) {
KoskiStudyProgrammeHandler handlerType = koskiSettings.getStudyProgrammeHandlerType(student.getStudyProgramme().getId());
KoskiStudentHandler handler = handlerType != null ? koskiController.getStudentHandler(handlerType) : null;
if (handler != null) {
Set<KoskiStudentId> ids = handler.listOids(student);
ids.forEach(id -> oidMap.put(id.getOid(), student));
}
}
}
for (OpiskeluoikeusReturnVal studyPermit : koskiStudent.getOpiskeluoikeudet()) {
String oid = studyPermit.getOid();
if (oid != null) {
Student student = oidMap.get(oid);
Map<String, Object> studyPermitInfo = new HashMap<>();
studyPermitInfo.put("oid", oid);
studyPermitInfo.put("linkedStudyProgrammeName", student != null ? student.getStudyProgramme().getName() : null);
studyPermitInfo.put("linkedStudyProgrammeStartDate", student != null ? student.getStudyStartDate().getTime() : null);
studyPermitInfo.put("linkedStudentId", student != null ? student.getId() : null);
studyPermitIds.add(studyPermitInfo);
}
}
}
requestContext.addResponseParameter("studyPermitIDs", studyPermitIds);
} catch (Exception e) {
logger.log(Level.SEVERE, "Error loading log entries", e);
}
}
use of fi.otavanopisto.pyramus.dao.base.PersonDAO in project pyramus by otavanopisto.
the class SearchStudentsDialogJSONRequestContoller method process.
public void process(JSONRequestContext jsonRequestContext) {
StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
StaffMember loggedUser = staffMemberDAO.findById(jsonRequestContext.getLoggedUserId());
Organization organization = UserUtils.canAccessAllOrganizations(loggedUser) ? null : loggedUser.getOrganization();
Integer resultsPerPage = NumberUtils.createInteger(jsonRequestContext.getRequest().getParameter("maxResults"));
if (resultsPerPage == null) {
resultsPerPage = 10;
}
Integer page = NumberUtils.createInteger(jsonRequestContext.getRequest().getParameter("page"));
if (page == null) {
page = 0;
}
SearchResult<Person> searchResult;
String query = jsonRequestContext.getRequest().getParameter("query");
PersonFilter personFilter = (PersonFilter) jsonRequestContext.getEnum("studentFilter", PersonFilter.class);
StudyProgramme studyProgramme = null;
StudentGroup studentGroup = null;
Long studyProgrammeId = jsonRequestContext.getLong("studyProgrammeId");
Long studentGroupId = jsonRequestContext.getLong("studentGroupId");
if (studyProgrammeId.intValue() != -1)
studyProgramme = studyProgrammeDAO.findById(studyProgrammeId);
if (studentGroupId.intValue() != -1)
studentGroup = studentGroupDAO.findById(studentGroupId);
searchResult = personDAO.searchPersonsBasic(resultsPerPage, page, query, personFilter, studyProgramme, studentGroup, organization);
List<Map<String, Object>> results = new ArrayList<>();
List<Person> persons = searchResult.getResults();
for (Person person : persons) {
Student student = person.getLatestStudent();
if (student != null) {
Map<String, Object> info = new HashMap<>();
info.put("personId", person.getId());
info.put("id", student.getId());
info.put("firstName", student.getFirstName());
info.put("lastName", student.getLastName());
info.put("archived", student.getArchived());
results.add(info);
}
}
String statusMessage;
Locale locale = jsonRequestContext.getRequest().getLocale();
if (searchResult.getTotalHitCount() > 0) {
statusMessage = Messages.getInstance().getText(locale, "students.searchStudents.searchStatus", new Object[] { searchResult.getFirstResult() + 1, searchResult.getLastResult() + 1, searchResult.getTotalHitCount() });
} else {
statusMessage = Messages.getInstance().getText(locale, "students.searchStudents.searchStatusNoMatches");
}
jsonRequestContext.addResponseParameter("results", results);
jsonRequestContext.addResponseParameter("statusMessage", statusMessage);
jsonRequestContext.addResponseParameter("pages", searchResult.getPages());
jsonRequestContext.addResponseParameter("page", searchResult.getPage());
}
use of fi.otavanopisto.pyramus.dao.base.PersonDAO in project pyramus by otavanopisto.
the class SearchStudentsJSONRequestContoller method process.
public void process(JSONRequestContext jsonRequestContext) {
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
LanguageDAO languageDAO = DAOFactory.getInstance().getLanguageDAO();
MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
NationalityDAO nationalityDAO = DAOFactory.getInstance().getNationalityDAO();
StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
StaffMember loggedUser = staffMemberDAO.findById(jsonRequestContext.getLoggedUserId());
Organization organization = UserUtils.canAccessAllOrganizations(loggedUser) ? null : loggedUser.getOrganization();
Integer resultsPerPage = NumberUtils.createInteger(jsonRequestContext.getRequest().getParameter("maxResults"));
if (resultsPerPage == null) {
resultsPerPage = 10;
}
Integer page = NumberUtils.createInteger(jsonRequestContext.getRequest().getParameter("page"));
if (page == null) {
page = 0;
}
SearchResult<Person> searchResult;
if ("advanced".equals(jsonRequestContext.getRequest().getParameter("activeTab"))) {
String firstName = jsonRequestContext.getString("firstname");
String nickname = jsonRequestContext.getString("nickname");
String lastName = jsonRequestContext.getString("lastname");
String tags = jsonRequestContext.getString("tags");
if (!StringUtils.isBlank(tags))
tags = tags.replace(',', ' ');
String education = jsonRequestContext.getString("education");
String email = jsonRequestContext.getString("email");
Sex sex = (Sex) jsonRequestContext.getEnum("sex", Sex.class);
String ssn = jsonRequestContext.getString("ssn");
String addressCity = jsonRequestContext.getString("addressCity");
String addressCountry = jsonRequestContext.getString("addressCountry");
String addressPostalCode = jsonRequestContext.getString("addressPostalCode");
String addressStreetAddress = jsonRequestContext.getString("addressStreetAddress");
String phone = jsonRequestContext.getString("phone");
String title = jsonRequestContext.getString("title");
PersonFilter personFilter = (PersonFilter) jsonRequestContext.getEnum("studentFilter", PersonFilter.class);
Language language = null;
Long languageId = jsonRequestContext.getLong("language");
if (languageId != null) {
language = languageDAO.findById(languageId);
}
Nationality nationality = null;
Long nationalityId = jsonRequestContext.getLong("nationality");
if (nationalityId != null) {
nationality = nationalityDAO.findById(nationalityId);
}
Municipality municipality = null;
Long municipalityId = jsonRequestContext.getLong("municipality");
if (municipalityId != null) {
municipality = municipalityDAO.findById(municipalityId);
}
StudyProgramme studyProgramme = null;
Long studyProgrammeId = jsonRequestContext.getLong("studyProgramme");
if (studyProgrammeId != null) {
studyProgramme = studyProgrammeDAO.findById(studyProgrammeId);
}
searchResult = personDAO.searchPersons(resultsPerPage, page, firstName, lastName, nickname, tags, education, email, sex, ssn, addressCity, addressCountry, addressPostalCode, addressStreetAddress, phone, studyProgramme, language, nationality, municipality, title, personFilter, organization);
} else if ("active".equals(jsonRequestContext.getRequest().getParameter("activeTab"))) {
String query = jsonRequestContext.getRequest().getParameter("activesQuery");
searchResult = personDAO.searchPersonsBasic(resultsPerPage, page, query, PersonFilter.ACTIVE_STUDENTS, organization);
} else {
String query = jsonRequestContext.getRequest().getParameter("query");
searchResult = personDAO.searchPersonsBasic(resultsPerPage, page, query, PersonFilter.ALL, organization);
}
List<Map<String, Object>> results = new ArrayList<>();
List<Person> persons = searchResult.getResults();
for (Person person : persons) {
List<Student> studentList2 = studentDAO.listByPerson(person);
StaffMember staffMember = staffMemberDAO.findByPerson(person);
if (!studentList2.isEmpty() || staffMember != null) {
String activeStudyProgrammes = "";
String inactiveStudyProgrammes = "";
for (Student student1 : studentList2) {
if (student1.getStudyProgramme() != null && UserUtils.canAccessOrganization(loggedUser, student1.getOrganization())) {
if (!student1.getHasFinishedStudies()) {
if (activeStudyProgrammes.length() == 0)
activeStudyProgrammes = student1.getStudyProgramme().getName();
else
activeStudyProgrammes += ", " + student1.getStudyProgramme().getName();
} else {
if (inactiveStudyProgrammes.length() == 0)
inactiveStudyProgrammes = student1.getStudyProgramme().getName();
else
inactiveStudyProgrammes += ", " + student1.getStudyProgramme().getName();
}
}
}
String firstName = "";
String lastName = "";
Boolean archived = Boolean.FALSE;
Long id = null;
if (person.getLatestStudent() != null) {
firstName = person.getLatestStudent().getFirstName();
lastName = person.getLatestStudent().getLastName();
archived = person.getLatestStudent().getArchived();
id = person.getLatestStudent().getId();
} else {
if (staffMember != null) {
firstName = staffMember.getFirstName();
lastName = staffMember.getLastName();
}
}
Map<String, Object> info = new HashMap<>();
info.put("personId", person.getId());
info.put("id", id);
info.put("firstName", firstName);
info.put("lastName", lastName);
info.put("archived", archived);
info.put("activeStudyProgrammes", activeStudyProgrammes);
info.put("inactiveStudyProgrammes", inactiveStudyProgrammes);
info.put("active", person.getActive());
results.add(info);
}
}
String statusMessage;
Locale locale = jsonRequestContext.getRequest().getLocale();
if (searchResult.getTotalHitCount() > 0) {
statusMessage = Messages.getInstance().getText(locale, "students.searchStudents.searchStatus", new Object[] { searchResult.getFirstResult() + 1, searchResult.getLastResult() + 1, searchResult.getTotalHitCount() });
} else {
statusMessage = Messages.getInstance().getText(locale, "students.searchStudents.searchStatusNoMatches");
}
jsonRequestContext.addResponseParameter("results", results);
jsonRequestContext.addResponseParameter("statusMessage", statusMessage);
jsonRequestContext.addResponseParameter("pages", searchResult.getPages());
jsonRequestContext.addResponseParameter("page", searchResult.getPage());
}
Aggregations