Search in sources :

Example 86 with UserEntity

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

the class UserEntityFileController method storeUserEntityFile.

public UserEntityFile storeUserEntityFile(String identifier, String name, String contentType, byte[] data, UserEntityFileVisibility visibility) {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    UserEntityFile userEntityFile = userEntityFileDAO.findByUserEntityAndIdentifier(userEntity, identifier);
    if (userEntityFile == null) {
        userEntityFile = userEntityFileDAO.create(userEntity, identifier, name, contentType, data, visibility);
    } else {
        userEntityFile = userEntityFileDAO.updateData(userEntityFile, identifier, name, contentType, data, visibility);
    }
    return userEntityFile;
}
Also used : UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) UserEntityFile(fi.otavanopisto.muikku.model.users.UserEntityFile)

Example 87 with UserEntity

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

the class WorkspaceVisitController method visit.

public void visit(WorkspaceEntity workspaceEntity) {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    if (userEntity == null) {
        return;
    } else {
        synchronized (userEntity) {
            WorkspaceVisit workspaceVisit = workspaceVisitDAO.lockingFindByUserEntityAndWorkspaceEntity(userEntity, workspaceEntity);
            if (workspaceVisit == null) {
                workspaceVisit = workspaceVisitDAO.create(userEntity, workspaceEntity, new Date());
            }
            workspaceVisitDAO.updateNumVisitsAndLastVisit(workspaceVisit, workspaceVisit.getNumVisits() + 1, new Date());
        }
    }
}
Also used : WorkspaceVisit(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceVisit) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Date(java.util.Date)

Example 88 with UserEntity

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

the class WebSocketRESTService method check.

@GET
@Path("/ticket/{TICKET}/check")
@RESTPermitUnimplemented
public Response check(@PathParam("TICKET") String ticketStr) {
    WebSocketTicket ticket = webSocketTicketController.findTicket(ticketStr);
    if (ticket != null) {
        UserEntity user = sessionController.getLoggedUserEntity();
        Long userId = user != null ? user.getId() : null;
        boolean valid = userId != null ? userId.equals(ticket.getUser()) : ticket.getUser() == null;
        if (valid)
            return Response.noContent().build();
        else
            return Response.status(Response.Status.NOT_FOUND).build();
    } else
        return Response.status(Response.Status.NOT_FOUND).build();
}
Also used : WebSocketTicket(fi.otavanopisto.muikku.plugins.websocket.WebSocketTicket) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 89 with UserEntity

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

the class WebSocketMessenger method sendMessage.

public void sendMessage(String eventType, Object data, List<UserEntity> recipients) {
    WebSocketMessage message = new WebSocketMessage(eventType, data);
    ObjectMapper mapper = new ObjectMapper();
    String strMessage = null;
    try {
        strMessage = mapper.writeValueAsString(message);
    } catch (Exception e) {
        logger.warning("Unable to serialize websocket message");
        return;
    }
    List<Long> recipientIds = new ArrayList<Long>(recipients.size());
    for (UserEntity userEntity : recipients) {
        recipientIds.add(userEntity.getId());
    }
    for (String ticket : sessions.keySet()) {
        Session session = sessions.get(ticket);
        try {
            if (session == null || !session.isOpen()) {
                closeSession(session, ticket, null);
                continue;
            }
            Long userId = (Long) session.getUserProperties().get("UserId");
            if (userId != null && recipientIds.contains(userId)) {
                session.getBasicRemote().sendText(strMessage);
            }
        } catch (Exception e) {
            logger.log(Level.WARNING, "Unable to send websocket message", e);
            closeSession(session, ticket, null);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Session(javax.websocket.Session)

Example 90 with UserEntity

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

the class CommunicatorRESTModels method getSenderBasicInfo.

/**
 * Returns message sender UserBasicInfo
 *
 * @param communicatorMessage
 * @return
 */
public UserBasicInfo getSenderBasicInfo(CommunicatorMessage communicatorMessage) {
    schoolDataBridgeSessionController.startSystemSession();
    try {
        UserEntity userEntity = userEntityController.findUserEntityById(communicatorMessage.getSender());
        User user = userController.findUserByUserEntityDefaults(userEntity);
        // TODO: userController.hasPicture(userEntity);
        Boolean hasPicture = false;
        if (user == null)
            return null;
        UserBasicInfo result = new UserBasicInfo(userEntity.getId(), user.getFirstName(), user.getLastName(), user.getNickName(), user.getStudyProgrammeName(), hasPicture, user.hasEvaluationFees(), user.getCurriculumIdentifier());
        return result;
    } finally {
        schoolDataBridgeSessionController.endSystemSession();
    }
}
Also used : UserBasicInfo(fi.otavanopisto.muikku.rest.model.UserBasicInfo) User(fi.otavanopisto.muikku.schooldata.entity.User) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

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