use of fi.otavanopisto.pyramus.dao.base.PersonDAO in project pyramus by otavanopisto.
the class PersonAPI method create.
public Long create(Date birthday, String socialSecurityNumber, String sex, String basicInfo, boolean secureInfo) {
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
Sex sexEntity;
if ("m".equals(sex)) {
sexEntity = Sex.MALE;
} else if ("f".equals(sex)) {
sexEntity = Sex.FEMALE;
} else if ("o".equals(sex)) {
sexEntity = Sex.OTHER;
} else {
throw new IllegalArgumentException("sex must be \"m\" or \"f\" or \"o\"");
}
Person person = personDAO.create(birthday, socialSecurityNumber, sexEntity, basicInfo, secureInfo);
return person.getId();
}
use of fi.otavanopisto.pyramus.dao.base.PersonDAO in project pyramus by otavanopisto.
the class StaffMemberAPI method create.
public Long create(String firstName, String lastName, String role, Long personId, Long organizationId) throws InvalidScriptException {
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
Person person = personDAO.findById(personId);
if (person == null) {
throw new InvalidScriptException("Person not found");
}
Organization organization = organizationId != null ? organizationDAO.findById(organizationId) : null;
if (organization == null) {
throw new InvalidScriptException("Organization not found");
}
StaffMember staffMember = staffMemberDAO.create(organization, firstName, lastName, Role.valueOf(role), person, false);
if (staffMember == null) {
throw new InvalidScriptException("Failed to create new staff member");
} else {
if (person.getDefaultUser() == null) {
personDAO.updateDefaultUser(person, staffMember);
}
return staffMember.getId();
}
}
use of fi.otavanopisto.pyramus.dao.base.PersonDAO in project pyramus by otavanopisto.
the class StaffMemberAPI method addEmail.
public void addEmail(Long staffMemberId, Long contactTypeId, String address, Boolean defaultAddress) throws InvalidScriptException {
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
address = address != null ? address.trim() : null;
ContactType contactType = contactTypeDAO.findById(contactTypeId);
if (contactType == null) {
throw new InvalidScriptException("ContactType could not be found");
}
StaffMember staffMember = staffMemberDAO.findById(staffMemberId);
if (staffMember == null) {
throw new InvalidScriptException("StaffMember could not be found");
}
Person person = personDAO.findByUniqueEmail(address);
if (person != null) {
if (!staffMember.getPerson().getId().equals(person.getId())) {
throw new InvalidScriptException("Email is already defined for another user");
}
StaffMember emailStaffMember = staffMemberDAO.findByUniqueEmail(address);
if (emailStaffMember != null && emailStaffMember.getId().equals(staffMemberId)) {
throw new InvalidScriptException("Email is already defined for this staff member");
}
}
emailDAO.create(staffMember.getContactInfo(), contactType, defaultAddress, address);
}
use of fi.otavanopisto.pyramus.dao.base.PersonDAO in project pyramus by otavanopisto.
the class StudentAPI method create.
public Long create(Long personId, String firstName, String lastName, String email, Long emailContactTypeId, String nickname, String additionalInfo, Date studyTimeEnd, Long activityType, Long examinationType, Long educationalLevel, String education, Long nationality, Long municipality, Long language, Long schoolId, Long studyProgrammeId, Double previousStudies, Date studyStartDate, Date studyEndDate, Long studyEndReasonId, String studyEndText, boolean lodging) throws InvalidScriptException {
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
StudentLodgingPeriodDAO studentLodgingPeriodDAO = DAOFactory.getInstance().getStudentLodgingPeriodDAO();
UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
email = email != null ? email.trim() : null;
Person personEntity = null;
if (personId != null) {
personEntity = personDAO.findById(personId);
}
StudentActivityType activityTypeEntity = null;
if (activityType != null) {
activityTypeEntity = DAOFactory.getInstance().getStudentActivityTypeDAO().findById(activityType);
}
StudentExaminationType examinationTypeEntity = null;
if (examinationType != null) {
examinationTypeEntity = DAOFactory.getInstance().getStudentExaminationTypeDAO().findById(examinationType);
}
StudentEducationalLevel educationalLevelEntity = null;
if (educationalLevel != null) {
educationalLevelEntity = DAOFactory.getInstance().getStudentEducationalLevelDAO().findById(educationalLevel);
}
Nationality nationalityEntity = null;
if (nationality != null) {
nationalityEntity = DAOFactory.getInstance().getNationalityDAO().findById(nationality);
}
Municipality municipalityEntity = null;
if (municipality != null) {
municipalityEntity = DAOFactory.getInstance().getMunicipalityDAO().findById(municipality);
}
Language languageEntity = null;
if (language != null) {
languageEntity = DAOFactory.getInstance().getLanguageDAO().findById(language);
}
School school = null;
if (schoolId != null) {
school = DAOFactory.getInstance().getSchoolDAO().findById(schoolId);
}
StudyProgramme studyProgramme = null;
if (studyProgrammeId != null) {
studyProgramme = DAOFactory.getInstance().getStudyProgrammeDAO().findById(studyProgrammeId);
}
StudentStudyEndReason studyEndReason = null;
if (studyEndReasonId != null) {
studyEndReason = DAOFactory.getInstance().getStudentStudyEndReasonDAO().findById(studyEndReasonId);
}
firstName = StringUtils.trim(firstName);
lastName = StringUtils.trim(lastName);
nickname = StringUtils.trim(nickname);
Student student = studentDAO.create(personEntity, firstName, lastName, nickname, additionalInfo, studyTimeEnd, activityTypeEntity, examinationTypeEntity, educationalLevelEntity, education, nationalityEntity, municipalityEntity, languageEntity, school, studyProgramme, null, previousStudies, studyStartDate, studyEndDate, studyEndReason, studyEndText, false);
userVariableDAO.createDefaultValueVariables(student);
if (lodging && studyStartDate != null)
studentLodgingPeriodDAO.create(student, studyStartDate, studyEndDate);
if (personEntity.getDefaultUser() == null) {
personDAO.updateDefaultUser(personEntity, student);
}
if (StringUtils.isNotBlank(email)) {
ContactType emailContactType = contactTypeDAO.findById(emailContactTypeId);
if (emailContactType == null) {
throw new InvalidScriptException("Could not find contact type for email");
}
emailDAO.create(student.getContactInfo(), emailContactType, true, email);
}
return student.getId();
}
use of fi.otavanopisto.pyramus.dao.base.PersonDAO in project pyramus by otavanopisto.
the class PersonAPI method findIdByEmail.
public Long findIdByEmail(String email) {
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
// Trim the email address
email = email != null ? email.trim() : null;
Person person = personDAO.findByUniqueEmail(email);
if (person != null) {
return person.getId();
}
return null;
}
Aggregations