Search in sources :

Example 1 with WebSocketTicket

use of fi.otavanopisto.muikku.plugins.websocket.WebSocketTicket in project muikku by otavanopisto.

the class WebSocketTicketDAO method create.

public WebSocketTicket create(String ticket, Long user, String ip, Date timestamp) {
    WebSocketTicket webSocketTicket = new WebSocketTicket();
    webSocketTicket.setTicket(ticket);
    webSocketTicket.setUser(user);
    webSocketTicket.setIp(ip);
    webSocketTicket.setTimestamp(timestamp);
    getEntityManager().persist(webSocketTicket);
    return webSocketTicket;
}
Also used : WebSocketTicket(fi.otavanopisto.muikku.plugins.websocket.WebSocketTicket)

Example 2 with WebSocketTicket

use of fi.otavanopisto.muikku.plugins.websocket.WebSocketTicket in project muikku by otavanopisto.

the class WebSocketTicketDAO method findByTicket.

public WebSocketTicket findByTicket(String ticket) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<WebSocketTicket> criteria = criteriaBuilder.createQuery(WebSocketTicket.class);
    Root<WebSocketTicket> root = criteria.from(WebSocketTicket.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.get(WebSocketTicket_.ticket), ticket));
    return getSingleResult(entityManager.createQuery(criteria));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) WebSocketTicket(fi.otavanopisto.muikku.plugins.websocket.WebSocketTicket)

Example 3 with WebSocketTicket

use of fi.otavanopisto.muikku.plugins.websocket.WebSocketTicket 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)

Aggregations

WebSocketTicket (fi.otavanopisto.muikku.plugins.websocket.WebSocketTicket)3 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1