use of fi.otavanopisto.pyramus.domainmodel.users.StaffMember in project pyramus by otavanopisto.
the class UsersService method updateUser.
public void updateUser(@WebParam(name = "userId") Long userId, @WebParam(name = "firstName") String firstName, @WebParam(name = "lastName") String lastName, @WebParam(name = "role") String role) {
StaffMemberDAO staffDAO = DAOFactory.getInstance().getStaffMemberDAO();
StaffMember user = staffDAO.findById(userId);
Role userRole = EnumType.valueOf(Role.class, role);
Organization organization = user.getOrganization();
staffDAO.update(user, organization, firstName, lastName, userRole);
validateEntity(user);
}
use of fi.otavanopisto.pyramus.domainmodel.users.StaffMember 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.domainmodel.users.StaffMember in project pyramus by otavanopisto.
the class UsersService method createUser.
public UserEntity createUser(@WebParam(name = "firstName") String firstName, @WebParam(name = "lastName") String lastName, @WebParam(name = "externalId") String externalId, @WebParam(name = "authProvider") String authProvider, @WebParam(name = "role") String role) {
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
// TODO: should not create if user exists
Person person = personDAO.create(null, null, null, null, Boolean.FALSE);
userIdentificationDAO.create(person, authProvider, externalId);
Role userRole = EnumType.valueOf(Role.class, role);
// TODO organization
Organization organization = null;
StaffMember staffMember = staffMemberDAO.create(organization, firstName, lastName, userRole, person, false);
personDAO.updateDefaultUser(person, staffMember);
validateEntity(staffMember);
return EntityFactoryVault.buildFromDomainObject(staffMember);
}
use of fi.otavanopisto.pyramus.domainmodel.users.StaffMember in project pyramus by otavanopisto.
the class UsersAutoCompleteBinaryRequestController method process.
/**
* Processes a binary request.
* The request should contain the following parameters:
* <dl>
* <dt><code>text</code></dt>
* <dd>Already typed characters.</dd>
* </dl>
*
* @param binaryRequestContext The context of the binary request.
*/
public void process(BinaryRequestContext binaryRequestContext) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
String text = binaryRequestContext.getString("text");
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.append("<ul>");
if (!StringUtils.isBlank(text)) {
text = QueryParser.escape(StringUtils.trim(text)) + '*';
List<StaffMember> users = userDAO.searchUsersBasic(100, 0, text).getResults();
for (User user : users) {
addUser(resultBuilder, user);
}
}
resultBuilder.append("</ul>");
try {
binaryRequestContext.setResponseContent(resultBuilder.toString().getBytes("UTF-8"), "text/html;charset=UTF-8");
} catch (UnsupportedEncodingException e) {
throw new SmvcRuntimeException(e);
}
}
use of fi.otavanopisto.pyramus.domainmodel.users.StaffMember in project pyramus by otavanopisto.
the class StudentGroupsAutoCompleteBinaryRequestController method process.
/**
* Processes a binary request.
* The request should contain the following parameters:
* <dl>
* <dt><code>text</code></dt>
* <dd>Already typed characters.</dd>
* </dl>
*
* @param binaryRequestContext The context of the binary request.
*/
public void process(BinaryRequestContext binaryRequestContext) {
StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
String text = binaryRequestContext.getString("text");
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.append("<ul>");
if (!StringUtils.isBlank(text)) {
text = QueryParser.escape(StringUtils.trim(text)) + '*';
StaffMember loggedUser = staffMemberDAO.findById(binaryRequestContext.getLoggedUserId());
Organization organization = UserUtils.canAccessAllOrganizations(loggedUser) ? null : loggedUser.getOrganization();
List<StudentGroup> studentGroups = studentGroupDAO.searchStudentGroupsBasic(100, 0, organization, text).getResults();
for (StudentGroup studentGroup : studentGroups) {
addResult(resultBuilder, studentGroup);
}
}
resultBuilder.append("</ul>");
try {
binaryRequestContext.setResponseContent(resultBuilder.toString().getBytes("UTF-8"), "text/html;charset=UTF-8");
} catch (UnsupportedEncodingException e) {
throw new SmvcRuntimeException(e);
}
}
Aggregations