Search in sources :

Example 1 with Tag

use of fi.otavanopisto.muikku.model.base.Tag in project muikku by otavanopisto.

the class TagDAO method findByText.

public Tag findByText(String text) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tag> criteria = criteriaBuilder.createQuery(Tag.class);
    Root<Tag> root = criteria.from(Tag.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.get(Tag_.text), text));
    return getSingleResult(entityManager.createQuery(criteria));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) Tag(fi.otavanopisto.muikku.model.base.Tag)

Example 2 with Tag

use of fi.otavanopisto.muikku.model.base.Tag in project muikku by otavanopisto.

the class AcceptanceTestsRESTService method parseTags.

private Set<Tag> parseTags(Set<String> tags) {
    Set<Tag> result = new HashSet<Tag>();
    for (String t : tags) {
        Tag tag = tagController.findTag(t);
        if (tag == null)
            tag = tagController.createTag(t);
        result.add(tag);
    }
    return result;
}
Also used : Tag(fi.otavanopisto.muikku.model.base.Tag) HashSet(java.util.HashSet)

Example 3 with Tag

use of fi.otavanopisto.muikku.model.base.Tag in project muikku by otavanopisto.

the class CommunicatorMessageDAO method create.

public CommunicatorMessage create(CommunicatorMessageId communicatorMessageId, Long sender, CommunicatorMessageCategory category, String caption, String content, Date created, Set<Tag> tags) {
    CommunicatorMessage msg = new CommunicatorMessage();
    int s = tags != null ? tags.size() : 0;
    Set<Long> tagIds = new HashSet<Long>(s);
    if (tags != null) {
        for (Tag t : tags) tagIds.add(t.getId());
    }
    msg.setCommunicatorMessageId(communicatorMessageId);
    msg.setSender(sender);
    msg.setCategory(category);
    msg.setCaption(caption);
    msg.setContent(content);
    msg.setCreated(created);
    msg.setTags(tagIds);
    msg.setArchivedBySender(false);
    msg.setTrashedBySender(false);
    getEntityManager().persist(msg);
    return msg;
}
Also used : CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) Tag(fi.otavanopisto.muikku.model.base.Tag) HashSet(java.util.HashSet)

Example 4 with Tag

use of fi.otavanopisto.muikku.model.base.Tag in project muikku by otavanopisto.

the class CommunicatorRESTService method postMessage.

@POST
@Path("/messages")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response postMessage(CommunicatorNewMessageRESTModel newMessage) throws AuthorizationException {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    CommunicatorMessageId communicatorMessageId = communicatorController.createMessageId();
    Set<Tag> tagList = parseTags(newMessage.getTags());
    List<UserEntity> recipients = new ArrayList<UserEntity>();
    for (Long recipientId : newMessage.getRecipientIds()) {
        UserEntity recipient = userEntityController.findUserEntityById(recipientId);
        if (recipient != null)
            recipients.add(recipient);
    }
    List<UserGroupEntity> userGroupRecipients = null;
    List<WorkspaceEntity> workspaceStudentRecipients = null;
    List<WorkspaceEntity> workspaceTeacherRecipients = null;
    if (!CollectionUtils.isEmpty(newMessage.getRecipientGroupIds())) {
        if (sessionController.hasEnvironmentPermission(CommunicatorPermissionCollection.COMMUNICATOR_GROUP_MESSAGING)) {
            userGroupRecipients = new ArrayList<UserGroupEntity>();
            for (Long groupId : newMessage.getRecipientGroupIds()) {
                UserGroupEntity group = userGroupEntityController.findUserGroupEntityById(groupId);
                userGroupRecipients.add(group);
            }
        } else {
            // Trying to feed group ids when you don't have permission greets you with bad request
            return Response.status(Status.BAD_REQUEST).build();
        }
    }
    if (!CollectionUtils.isEmpty(newMessage.getRecipientStudentsWorkspaceIds())) {
        workspaceStudentRecipients = new ArrayList<WorkspaceEntity>();
        for (Long workspaceId : newMessage.getRecipientStudentsWorkspaceIds()) {
            WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
            if (sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_WORKSPACE_MESSAGING, workspaceEntity))
                workspaceStudentRecipients.add(workspaceEntity);
            else
                return Response.status(Status.BAD_REQUEST).build();
        }
    }
    if (!CollectionUtils.isEmpty(newMessage.getRecipientTeachersWorkspaceIds())) {
        workspaceTeacherRecipients = new ArrayList<WorkspaceEntity>();
        for (Long workspaceId : newMessage.getRecipientTeachersWorkspaceIds()) {
            WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
            if (sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_WORKSPACE_MESSAGING, workspaceEntity))
                workspaceTeacherRecipients.add(workspaceEntity);
            else
                return Response.status(Status.BAD_REQUEST).build();
        }
    }
    if (StringUtils.isBlank(newMessage.getCategoryName())) {
        return Response.status(Status.BAD_REQUEST).entity("CategoryName missing").build();
    }
    // TODO Category not existing at this point would technically indicate an invalid state
    CommunicatorMessageCategory categoryEntity = communicatorController.persistCategory(newMessage.getCategoryName());
    CommunicatorMessage message = communicatorController.createMessage(communicatorMessageId, userEntity, recipients, userGroupRecipients, workspaceStudentRecipients, workspaceTeacherRecipients, categoryEntity, newMessage.getCaption(), newMessage.getContent(), tagList);
    sendNewMessageNotifications(message);
    return Response.ok(restModels.restFullMessage(message)).build();
}
Also used : CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) ArrayList(java.util.ArrayList) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) CommunicatorMessageCategory(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) EntityTag(javax.ws.rs.core.EntityTag) Tag(fi.otavanopisto.muikku.model.base.Tag) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 5 with Tag

use of fi.otavanopisto.muikku.model.base.Tag in project muikku by otavanopisto.

the class CommunicatorRESTService method postMessageReply.

@POST
@Path("/messages/{COMMUNICATORMESSAGEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response postMessageReply(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId, CommunicatorNewMessageRESTModel newMessage) throws AuthorizationException {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    CommunicatorMessageId communicatorMessageId2 = communicatorController.findCommunicatorMessageId(communicatorMessageId);
    Set<Tag> tagList = parseTags(newMessage.getTags());
    List<UserEntity> recipients = new ArrayList<UserEntity>();
    for (Long recipientId : newMessage.getRecipientIds()) {
        UserEntity recipient = userEntityController.findUserEntityById(recipientId);
        if (recipient != null)
            recipients.add(recipient);
    }
    List<UserGroupEntity> userGroupRecipients = null;
    List<WorkspaceEntity> workspaceStudentRecipients = null;
    List<WorkspaceEntity> workspaceTeacherRecipients = null;
    if (!CollectionUtils.isEmpty(newMessage.getRecipientGroupIds())) {
        if (sessionController.hasEnvironmentPermission(CommunicatorPermissionCollection.COMMUNICATOR_GROUP_MESSAGING)) {
            userGroupRecipients = new ArrayList<UserGroupEntity>();
            for (Long groupId : newMessage.getRecipientGroupIds()) {
                UserGroupEntity group = userGroupEntityController.findUserGroupEntityById(groupId);
                userGroupRecipients.add(group);
            }
        } else {
            // Trying to feed group ids when you don't have permission greets you with bad request
            return Response.status(Status.BAD_REQUEST).build();
        }
    }
    if (!CollectionUtils.isEmpty(newMessage.getRecipientStudentsWorkspaceIds())) {
        workspaceStudentRecipients = new ArrayList<WorkspaceEntity>();
        for (Long workspaceId : newMessage.getRecipientStudentsWorkspaceIds()) {
            WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
            if (sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_WORKSPACE_MESSAGING, workspaceEntity))
                workspaceStudentRecipients.add(workspaceEntity);
            else
                return Response.status(Status.BAD_REQUEST).build();
        }
    }
    if (!CollectionUtils.isEmpty(newMessage.getRecipientTeachersWorkspaceIds())) {
        workspaceTeacherRecipients = new ArrayList<WorkspaceEntity>();
        for (Long workspaceId : newMessage.getRecipientTeachersWorkspaceIds()) {
            WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
            if (sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_WORKSPACE_MESSAGING, workspaceEntity))
                workspaceTeacherRecipients.add(workspaceEntity);
            else
                return Response.status(Status.BAD_REQUEST).build();
        }
    }
    // TODO Category not existing at this point would technically indicate an invalid state
    CommunicatorMessageCategory categoryEntity = communicatorController.persistCategory(newMessage.getCategoryName());
    CommunicatorMessage message = communicatorController.createMessage(communicatorMessageId2, userEntity, recipients, userGroupRecipients, workspaceStudentRecipients, workspaceTeacherRecipients, categoryEntity, newMessage.getCaption(), newMessage.getContent(), tagList);
    sendNewMessageNotifications(message);
    return Response.ok(restModels.restFullMessage(message)).build();
}
Also used : CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) CommunicatorMessage(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage) ArrayList(java.util.ArrayList) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) CommunicatorMessageCategory(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) EntityTag(javax.ws.rs.core.EntityTag) Tag(fi.otavanopisto.muikku.model.base.Tag) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Aggregations

Tag (fi.otavanopisto.muikku.model.base.Tag)9 ArrayList (java.util.ArrayList)4 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)3 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)3 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)3 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)3 CommunicatorMessageCategory (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory)3 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)3 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)3 HashSet (java.util.HashSet)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 EntityTag (javax.ws.rs.core.EntityTag)3 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)1 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 HashMap (java.util.HashMap)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1