Search in sources :

Example 11 with CoOpsSession

use of fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession in project muikku by otavanopisto.

the class CoOpsSessionEventsController method createSessionEvents.

public List<Object> createSessionEvents(List<CoOpsSession> sessions, String status) {
    List<Object> result = new ArrayList<Object>();
    String email = null;
    // TODO: Localize
    String displayName = "Anonymous";
    for (CoOpsSession session : sessions) {
        String sessionId = session.getSessionId();
        Long userEntityId = session.getUserEntityId();
        if (userEntityId != null) {
            UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
            if (userEntity != null) {
                email = userEmailEntityController.getUserDefaultEmailAddress(userEntity, false);
                User user = userController.findUserByDataSourceAndIdentifier(userEntity.getDefaultSchoolDataSource(), userEntity.getDefaultIdentifier());
                if (user != null) {
                    displayName = user.getFirstName() + ' ' + user.getLastName();
                }
            }
        }
        if (StringUtils.isBlank(email)) {
            email = sessionId + "@nomail.invalid";
        }
        result.add(new CoOpsSessionEvent(sessionId, displayName, email, status));
    }
    return result;
}
Also used : CoOpsSession(fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession) User(fi.otavanopisto.muikku.schooldata.entity.User) ArrayList(java.util.ArrayList) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Example 12 with CoOpsSession

use of fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession in project muikku by otavanopisto.

the class CoOpsSessionDAO method listByClosed.

public List<CoOpsSession> listByClosed(Boolean closed) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CoOpsSession> criteria = criteriaBuilder.createQuery(CoOpsSession.class);
    Root<CoOpsSession> root = criteria.from(CoOpsSession.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.get(CoOpsSession_.closed), closed));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CoOpsSession(fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession)

Example 13 with CoOpsSession

use of fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession in project muikku by otavanopisto.

the class CoOpsSessionDAO method listByFileAndClosed.

public List<CoOpsSession> listByFileAndClosed(HtmlMaterial htmlMaterial, Boolean closed) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CoOpsSession> criteria = criteriaBuilder.createQuery(CoOpsSession.class);
    Root<CoOpsSession> root = criteria.from(CoOpsSession.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CoOpsSession_.htmlMaterial), htmlMaterial), criteriaBuilder.equal(root.get(CoOpsSession_.closed), closed)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CoOpsSession(fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession)

Aggregations

CoOpsSession (fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession)13 CoOpsInternalErrorException (fi.foyt.coops.CoOpsInternalErrorException)4 CoOpsUsageException (fi.foyt.coops.CoOpsUsageException)4 Patch (fi.foyt.coops.model.Patch)4 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)4 EntityManager (javax.persistence.EntityManager)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 CoOpsNotFoundException (fi.foyt.coops.CoOpsNotFoundException)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 CoOpsConflictException (fi.foyt.coops.CoOpsConflictException)2 CoOpsForbiddenException (fi.foyt.coops.CoOpsForbiddenException)2 ErrorMessage (fi.foyt.coops.extensions.websocket.ErrorMessage)2 HtmlMaterialRevision (fi.otavanopisto.muikku.plugins.material.coops.model.HtmlMaterialRevision)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 CloseReason (javax.websocket.CloseReason)2 CoOpsNotImplementedException (fi.foyt.coops.CoOpsNotImplementedException)1 PatchMessage (fi.foyt.coops.extensions.websocket.PatchMessage)1 Join (fi.foyt.coops.model.Join)1