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;
}
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());
}
}
}
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();
}
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);
}
}
}
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();
}
}
Aggregations