Search in sources :

Example 61 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class GuiderRESTService method listUserNotifications.

@GET
@Path("/users/{IDENTIFIER}/latestNotifications")
@RESTPermit(GuiderPermissions.GUIDER_LIST_NOTIFICATIONS)
public Response listUserNotifications(@PathParam("IDENTIFIER") String identifierString) {
    SchoolDataIdentifier identifier = SchoolDataIdentifier.fromId(identifierString);
    UserEntity ue = userEntityController.findUserEntityByUserIdentifier(identifier);
    if (ue == null) {
        return Response.status(Status.NOT_FOUND).entity("User entity not found").build();
    }
    Map<String, Date> map = new HashMap<>();
    StudyTimeNotification notification = studyTimeLeftNotificationController.findLatestByUserIdentifier(identifier);
    if (notification != null)
        map.put("studytime", notification.getSent());
    NoPassedCoursesNotification noPassNotification = noPassedCoursesNotificationController.findLatestByUserIdentifier(identifier);
    if (noPassNotification != null)
        map.put("nopassedcourses", noPassNotification.getSent());
    AssesmentRequestNotification assessmentRequestNotification = assessmentRequestNotificationController.findLatestByUserIdentifier(identifier);
    if (assessmentRequestNotification != null)
        map.put("assesmentrequest", assessmentRequestNotification.getSent());
    return Response.ok().entity(map).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) AssesmentRequestNotification(fi.otavanopisto.muikku.plugins.timed.notifications.model.AssesmentRequestNotification) StudyTimeNotification(fi.otavanopisto.muikku.plugins.timed.notifications.model.StudyTimeNotification) HashMap(java.util.HashMap) NoPassedCoursesNotification(fi.otavanopisto.muikku.plugins.timed.notifications.model.NoPassedCoursesNotification) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Date(java.util.Date) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 62 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class InternalAuthController method findInternalAuthByEmailAndPassword.

public InternalAuth findInternalAuthByEmailAndPassword(String email, String password) {
    String passwordHash = DigestUtils.md5Hex(password);
    UserEntity userEntity = userEntityController.findUserEntityByEmailAddress(email);
    if (userEntity != null) {
        InternalAuth internalAuth = internalAuthDAO.findByUserIdAndPassword(userEntity.getId(), passwordHash);
        return internalAuth;
    }
    return null;
}
Also used : InternalAuth(fi.otavanopisto.muikku.plugins.internalauth.model.InternalAuth) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Example 63 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class InternalAuthenticationStrategy method processLogin.

@Override
public AuthenticationResult processLogin(AuthSource authSource, Map<String, String[]> requestParameters) {
    String email = StringUtils.lowerCase(getFirstRequestParameter(requestParameters, "email"));
    String password = getFirstRequestParameter(requestParameters, "password");
    InternalAuth internalAuth = internalLoginController.findInternalAuthByEmailAndPassword(email, password);
    if (internalAuth != null) {
        UserEntity userEntity = userEntityController.findUserEntityById(internalAuth.getUserEntityId());
        if (userEntity != null) {
            return processLogin(authSource, requestParameters, DigestUtils.md5Hex("INTERNAL-" + internalAuth.getId()), Arrays.asList(email), null, null);
        }
    }
    return new AuthenticationResult(Status.INVALID_CREDENTIALS);
}
Also used : InternalAuth(fi.otavanopisto.muikku.plugins.internalauth.model.InternalAuth) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) AuthenticationResult(fi.otavanopisto.muikku.auth.AuthenticationResult)

Example 64 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class WebSocketRESTService method createTicket.

@POST
@Path("/ticket")
@RESTPermitUnimplemented
public Response createTicket() {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    Long userEntityId = userEntity != null ? userEntity.getId() : null;
    Date timestamp = new Date();
    String ip = request.getRemoteAddr();
    String ticket = UUID.randomUUID().toString();
    webSocketTicketController.createTicket(ticket, userEntityId, ip, timestamp);
    return Response.ok(new WebSocketTicketRESTModel(ticket)).build();
}
Also used : UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Date(java.util.Date) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)

Example 65 with UserEntity

use of fi.otavanopisto.muikku.model.users.UserEntity in project muikku by otavanopisto.

the class NotificationController method sendNotification.

public void sendNotification(String category, String subject, String content, UserEntity recipient, SchoolDataIdentifier recipientIdentifier, String notificationType) {
    HashMap<String, Object> map = new HashMap<>();
    map.put("notificationType", notificationType);
    map.put("recipient", recipient.getId());
    map.put("recipientIdentifier", recipientIdentifier.toId());
    map.put("time", String.valueOf(System.currentTimeMillis()));
    UserEntity guidanceCounselor = null;
    SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(recipient.getDefaultIdentifier(), recipient.getDefaultSchoolDataSource().getIdentifier());
    List<UserGroupEntity> userGroupEntities = userGroupEntityController.listUserGroupsByUserIdentifier(userIdentifier);
    // #3089: An awkward workaround to use the latest guidance group based on its identifier. Assumes a larger
    // identifier means a more recent entity. A more proper fix would be to sync group creation dates from
    // Pyramus and include them in the Elastic index. Then again, user groups would have to be refactored
    // entirely, as Pyramus handles group members as students (one study programme) while Muikku handles
    // them as user entities (all study programmes)...
    userGroupEntities.sort(new Comparator<UserGroupEntity>() {

        public int compare(UserGroupEntity o1, UserGroupEntity o2) {
            long l1 = NumberUtils.toLong(StringUtils.substringAfterLast(o1.getIdentifier(), "-"), -1);
            long l2 = NumberUtils.toLong(StringUtils.substringAfterLast(o2.getIdentifier(), "-"), -1);
            return (int) (l2 - l1);
        }
    });
    userGroupEntities: for (UserGroupEntity userGroupEntity : userGroupEntities) {
        UserGroup userGroup = userGroupController.findUserGroup(userGroupEntity);
        if (userGroup.isGuidanceGroup()) {
            List<GroupUser> groupUsers = userGroupController.listUserGroupStaffMembers(userGroup);
            for (GroupUser groupUser : groupUsers) {
                User user = userGroupController.findUserByGroupUser(groupUser);
                guidanceCounselor = userEntityController.findUserEntityByUser(user);
                break userGroupEntities;
            }
        }
    }
    LogProvider provider = getProvider(LOG_PROVIDER);
    if (provider != null) {
        provider.log(COLLECTION_NAME, map);
    }
    if (isDryRun()) {
        String recipientEmail = getRecipientEmail();
        if (recipientEmail == null) {
            logger.log(Level.INFO, String.format("Sending notification %s - %s to %s", category, subject, recipient.getDefaultIdentifier()));
        } else {
            mailer.sendMail(MailType.HTML, Arrays.asList(recipientEmail), subject, "SENT TO: " + recipient.getDefaultIdentifier() + "<br/><br/><br/>" + content);
        }
    } else {
        ArrayList<UserEntity> recipients = new ArrayList<>();
        recipients.add(recipient);
        if (guidanceCounselor != null) {
            recipients.add(guidanceCounselor);
        }
        String studentEmail = userEmailEntityController.getUserDefaultEmailAddress(recipient, Boolean.FALSE);
        if (studentEmail != null) {
            mailer.sendMail(MailType.HTML, Arrays.asList(studentEmail), subject, content);
        } else {
            logger.log(Level.WARNING, String.format("Cannot send email notification to student %s because no email address was found", recipient.getDefaultIdentifier()));
        }
        communicatorController.postMessage(recipient, category, subject, content, recipients);
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) User(fi.otavanopisto.muikku.schooldata.entity.User) GroupUser(fi.otavanopisto.muikku.schooldata.entity.GroupUser) GroupUser(fi.otavanopisto.muikku.schooldata.entity.GroupUser) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) UserGroup(fi.otavanopisto.muikku.schooldata.entity.UserGroup) LogProvider(fi.otavanopisto.muikku.plugins.commonlog.LogProvider) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)163 Path (javax.ws.rs.Path)101 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)88 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)65 GET (javax.ws.rs.GET)58 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)54 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)50 User (fi.otavanopisto.muikku.schooldata.entity.User)36 ArrayList (java.util.ArrayList)35 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)27 POST (javax.ws.rs.POST)26 Date (java.util.Date)24 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)22 HashMap (java.util.HashMap)20 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)18 EnvironmentUser (fi.otavanopisto.muikku.model.users.EnvironmentUser)14 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)14 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)13 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)12 PUT (javax.ws.rs.PUT)12