use of fi.otavanopisto.pyramus.dao.base.EmailDAO 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);
}
}
use of fi.otavanopisto.pyramus.dao.base.EmailDAO in project pyramus by otavanopisto.
the class StudentsService method updateStudentEmail.
public void updateStudentEmail(@WebParam(name = "studentId") Long studentId, @WebParam(name = "fromAddress") String fromAddress, @WebParam(name = "toAddress") String toAddress) {
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
Student student = studentDAO.findById(studentId);
// Trim the email address
toAddress = toAddress != null ? toAddress.trim() : null;
for (Email email : student.getContactInfo().getEmails()) {
if (email.getAddress().equals(fromAddress)) {
email = emailDAO.update(email, email.getContactType(), email.getDefaultAddress(), toAddress);
validateEntity(email);
break;
}
}
}
use of fi.otavanopisto.pyramus.dao.base.EmailDAO in project pyramus by otavanopisto.
the class UsersService method removeUserEmail.
public void removeUserEmail(@WebParam(name = "userId") Long userId, @WebParam(name = "address") String address) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
fi.otavanopisto.pyramus.domainmodel.users.User user = userDAO.findById(userId);
for (Email email : user.getContactInfo().getEmails()) {
if (email.getAddress().equals(address)) {
emailDAO.delete(email);
break;
}
}
}
use of fi.otavanopisto.pyramus.dao.base.EmailDAO in project pyramus by otavanopisto.
the class UsersService method addUserEmail.
public void addUserEmail(@WebParam(name = "userId") Long userId, @WebParam(name = "address") String address) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
StaffMember user = userDAO.findById(userId);
// Trim the email address
address = StringUtils.trim(address);
if (StringUtils.isNotBlank(address)) {
// TODO contact type, default address
ContactType contactType = contactTypeDAO.findById(new Long(1));
if (!UserUtils.isAllowedEmail(address, contactType, user.getPerson().getId()))
throw new RuntimeException("Email address is in use");
Email email = emailDAO.create(user.getContactInfo(), contactType, Boolean.TRUE, address);
validateEntity(email);
}
}
use of fi.otavanopisto.pyramus.dao.base.EmailDAO in project pyramus by otavanopisto.
the class ImportLDAPUsersViewController method processSend.
public void processSend(PageRequestContext requestContext) {
EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
List<User> createdUsers = new ArrayList<User>();
int rowCount = requestContext.getInteger("importTable.rowCount");
for (int i = 0; i < rowCount; i++) {
String colPrefix = "importTable." + i;
if ("1".equals(requestContext.getString(colPrefix + ".import"))) {
String email = requestContext.getString(colPrefix + ".email");
String firstName = requestContext.getString(colPrefix + ".firstName");
String lastName = requestContext.getString(colPrefix + ".lastName");
String roleName = requestContext.getString(colPrefix + ".role");
String id = requestContext.getString(colPrefix + ".id");
Role role = Enum.valueOf(Role.class, roleName);
User user = userDAO.create(firstName, lastName, id, "LDAP", role);
emailDAO.create(user.getContactInfo(), null, Boolean.TRUE, email);
createdUsers.add(user);
}
}
requestContext.getRequest().setAttribute("createdUsers", createdUsers);
requestContext.setRedirectURL(requestContext.getRequest().getContextPath() + "system/importldapusers.page");
}
Aggregations