use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class CommunicatorAssessmentRequestController method sendAssessmentRequestMessage.
public CommunicatorMessage sendAssessmentRequestMessage(WorkspaceAssessmentRequest assessmentRequest) {
SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(assessmentRequest.getWorkspaceUserIdentifier(), assessmentRequest.getWorkspaceUserSchoolDataSource());
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
if (workspaceUserEntity == null) {
logger.severe(String.format("Could not find workspace user entity for identifier", workspaceUserIdentifier));
return null;
}
UserSchoolDataIdentifier userSchoolDataIdentifier = workspaceUserEntity.getUserSchoolDataIdentifier();
if (userSchoolDataIdentifier == null) {
logger.severe(String.format("Could not find userSchoolDataIdentifier for workspace user entity %d", workspaceUserEntity.getId()));
return null;
}
WorkspaceEntity workspaceEntity = workspaceUserEntity.getWorkspaceEntity();
if (workspaceEntity == null) {
logger.severe(String.format("Could not find workspaceEntity for workspace user entity %d", workspaceUserEntity.getId()));
return null;
}
UserEntity studentEntity = userSchoolDataIdentifier.getUserEntity();
if (studentEntity == null) {
logger.severe(String.format("Could not find studentEntity for workspace user entity %d", workspaceUserEntity.getId()));
return null;
}
CommunicatorMessageId communicatorMessageId = assessmentRequestController.findCommunicatorMessageId(workspaceUserEntity);
schoolDataBridgeSessionController.startSystemSession();
try {
SchoolDataIdentifier studentIdentifier = new SchoolDataIdentifier(userSchoolDataIdentifier.getIdentifier(), userSchoolDataIdentifier.getDataSource().getIdentifier());
List<UserEntity> teachers = new ArrayList<UserEntity>();
List<WorkspaceUserEntity> workspaceTeachers = workspaceUserEntityController.listActiveWorkspaceStaffMembers(workspaceEntity);
for (WorkspaceUserEntity workspaceTeacher : workspaceTeachers) {
teachers.add(workspaceTeacher.getUserSchoolDataIdentifier().getUserEntity());
}
User student = userController.findUserByIdentifier(studentIdentifier);
if (student == null) {
logger.severe(String.format("Could not find student %s", studentIdentifier));
return null;
}
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
if (workspace == null) {
logger.severe(String.format("Could not find workspace for workspace entity %d", workspaceEntity.getId()));
return null;
}
String messageCategory = getText("plugin.communicator.assessmentrequest.category");
String messageTitle = assessmentRequestTitle(workspace, student);
String messageBody = assessmentRequestBody(workspace, student, assessmentRequest.getRequestText());
List<String> teacherEmails = new ArrayList<>(teachers.size());
for (UserEntity teacher : teachers) {
String teacherEmail = userEmailEntityController.getUserDefaultEmailAddress(teacher, false);
if (StringUtils.isNotBlank(teacherEmail)) {
teacherEmails.add(teacherEmail);
}
}
if (!teacherEmails.isEmpty()) {
mailer.sendMail(MailType.HTML, teacherEmails, messageTitle, messageBody);
}
if (communicatorMessageId != null) {
return communicatorController.replyToMessage(studentEntity, messageCategory, messageTitle, messageBody, teachers, communicatorMessageId);
} else {
CommunicatorMessage postMessage = communicatorController.postMessage(studentEntity, messageCategory, messageTitle, messageBody, teachers);
assessmentRequestController.setCommunicatorMessageId(assessmentRequest, postMessage.getCommunicatorMessageId());
return postMessage;
}
} finally {
schoolDataBridgeSessionController.endSystemSession();
}
}
use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class UserSchoolDataController method listUsersByEntity.
public List<User> listUsersByEntity(UserEntity userEntity) {
List<User> result = new ArrayList<>();
List<UserSchoolDataIdentifier> identifiers = userSchoolDataIdentifierDAO.listByUserEntityAndArchived(userEntity, Boolean.FALSE);
for (UserSchoolDataIdentifier identifier : identifiers) {
UserSchoolDataBridge userBridge = getUserBridge(identifier.getDataSource());
User user = findUserByIdentifier(userBridge, identifier.getIdentifier());
if (user != null) {
result.add(user);
}
}
return result;
}
use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class UserGroupEntityDAO method listByUserEntityExcludeArchived.
public List<UserGroupEntity> listByUserEntityExcludeArchived(UserEntity userEntity) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserGroupEntity> criteria = criteriaBuilder.createQuery(UserGroupEntity.class);
Root<UserGroupUserEntity> root = criteria.from(UserGroupUserEntity.class);
Join<UserGroupUserEntity, UserSchoolDataIdentifier> join = root.join(UserGroupUserEntity_.userSchoolDataIdentifier);
Join<UserGroupUserEntity, UserGroupEntity> join2 = root.join(UserGroupUserEntity_.userGroupEntity);
criteria.select(root.get(UserGroupUserEntity_.userGroupEntity));
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(join.get(UserSchoolDataIdentifier_.userEntity), userEntity), criteriaBuilder.equal(join.get(UserSchoolDataIdentifier_.archived), Boolean.FALSE), criteriaBuilder.equal(join2.get(UserGroupEntity_.archived), Boolean.FALSE), criteriaBuilder.equal(root.get(UserGroupUserEntity_.archived), Boolean.FALSE)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class UserGroupUserEntityDAO method haveSharedUserGroups.
public boolean haveSharedUserGroups(UserEntity user1, UserEntity user2) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
Root<UserGroupEntity> root = criteria.from(UserGroupEntity.class);
Subquery<UserGroupEntity> user1Groups = criteria.subquery(UserGroupEntity.class);
Subquery<UserGroupEntity> user2Groups = criteria.subquery(UserGroupEntity.class);
Root<UserGroupUserEntity> user1Root = user1Groups.from(UserGroupUserEntity.class);
Join<UserGroupUserEntity, UserSchoolDataIdentifier> user1Identifier = user1Root.join(UserGroupUserEntity_.userSchoolDataIdentifier);
Root<UserGroupUserEntity> user2Root = user2Groups.from(UserGroupUserEntity.class);
Join<UserGroupUserEntity, UserSchoolDataIdentifier> user2Identifier = user2Root.join(UserGroupUserEntity_.userSchoolDataIdentifier);
user1Groups.select(user1Root.get(UserGroupUserEntity_.userGroupEntity));
user2Groups.select(user2Root.get(UserGroupUserEntity_.userGroupEntity));
user1Groups.where(criteriaBuilder.and(criteriaBuilder.equal(user1Identifier.get(UserSchoolDataIdentifier_.userEntity), user1), criteriaBuilder.equal(user1Root.get(UserGroupUserEntity_.archived), Boolean.FALSE)));
user2Groups.where(criteriaBuilder.and(criteriaBuilder.equal(user2Identifier.get(UserSchoolDataIdentifier_.userEntity), user2), criteriaBuilder.equal(user2Root.get(UserGroupUserEntity_.archived), Boolean.FALSE)));
criteria.select(criteriaBuilder.count(root));
criteria.where(criteriaBuilder.and(root.in(user1Groups), root.in(user2Groups), criteriaBuilder.equal(root.get(UserGroupEntity_.archived), Boolean.FALSE)));
return entityManager.createQuery(criteria).getSingleResult() > 0;
}
use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class UserSchoolDataIdentifierDAO method findByDataSourceAndIdentifier.
public UserSchoolDataIdentifier findByDataSourceAndIdentifier(SchoolDataSource dataSource, String identifier) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserSchoolDataIdentifier> criteria = criteriaBuilder.createQuery(UserSchoolDataIdentifier.class);
Root<UserSchoolDataIdentifier> root = criteria.from(UserSchoolDataIdentifier.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(UserSchoolDataIdentifier_.dataSource), dataSource), criteriaBuilder.equal(root.get(UserSchoolDataIdentifier_.identifier), identifier)));
return getSingleResult(entityManager.createQuery(criteria));
}
Aggregations