Search in sources :

Example 31 with UserGroupEntity

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

the class AcceptanceTestsRESTService method createAnnouncement.

@POST
@Path("/announcements")
@RESTPermit(handling = Handling.UNSECURED)
public Response createAnnouncement(fi.otavanopisto.muikku.atests.Announcement payload) {
    UserEntity user = userEntityController.findUserEntityById(payload.getPublisherUserEntityId());
    Announcement announcement = announcementController.createAnnouncement(user, payload.getCaption(), payload.getContent(), payload.getStartDate(), payload.getEndDate(), payload.getPubliclyVisible());
    if (payload.getUserGroupEntityIds() != null) {
        List<Long> userGroups = payload.getUserGroupEntityIds();
        for (Long userGroupId : userGroups) {
            UserGroupEntity userGroup = userGroupEntityController.findUserGroupEntityById(userGroupId);
            announcementController.addAnnouncementTargetGroup(announcement, userGroup);
        }
    }
    return Response.ok(announcement.getId()).build();
}
Also used : Announcement(fi.otavanopisto.muikku.plugins.announcer.model.Announcement) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 32 with UserGroupEntity

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

the class AcceptanceTestsRESTService method createCommunicatorMessage.

@POST
@Path("/communicator/messages")
@RESTPermit(handling = Handling.UNSECURED)
public Response createCommunicatorMessage(fi.otavanopisto.muikku.atests.CommunicatorMessage payload) {
    UserEntity user = userEntityController.findUserEntityById(payload.getSenderId());
    CommunicatorMessageId communicatorMessageId = communicatorController.createMessageId();
    Set<Tag> tagList = parseTags(payload.getTags());
    List<UserEntity> recipients = new ArrayList<UserEntity>();
    for (Long recipientId : payload.getRecipientIds()) {
        UserEntity recipient = userEntityController.findUserEntityById(recipientId);
        if (recipient != null)
            recipients.add(recipient);
    }
    for (Long groupId : payload.getRecipientGroupIds()) {
        UserGroupEntity group = userGroupEntityController.findUserGroupEntityById(groupId);
        List<UserGroupUserEntity> groupUsers = userGroupEntityController.listUserGroupUserEntitiesByUserGroupEntity(group);
        for (UserGroupUserEntity groupUser : groupUsers) {
            UserSchoolDataIdentifier userSchoolDataIdentifier = groupUser.getUserSchoolDataIdentifier();
            UserEntity userEntity = userSchoolDataIdentifier.getUserEntity();
            recipients.add(userEntity);
        }
    }
    for (Long workspaceId : payload.getRecipientStudentsWorkspaceIds()) {
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
        List<WorkspaceUserEntity> workspaceUsers = workspaceUserEntityController.listActiveWorkspaceStudents(workspaceEntity);
        for (WorkspaceUserEntity wosu : workspaceUsers) {
            recipients.add(wosu.getUserSchoolDataIdentifier().getUserEntity());
        }
    }
    for (Long workspaceId : payload.getRecipientTeachersWorkspaceIds()) {
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
        List<WorkspaceUserEntity> workspaceUsers = workspaceUserEntityController.listActiveWorkspaceStaffMembers(workspaceEntity);
        for (WorkspaceUserEntity wosu : workspaceUsers) {
            recipients.add(wosu.getUserSchoolDataIdentifier().getUserEntity());
        }
    }
    CommunicatorMessageCategory categoryEntity = communicatorController.persistCategory(payload.getCategoryName());
    fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage message = communicatorController.createMessage(communicatorMessageId, user, recipients, null, null, null, categoryEntity, payload.getCaption(), payload.getContent(), tagList);
    Long communicatorMessageId2 = message.getCommunicatorMessageId().getId();
    fi.otavanopisto.muikku.atests.CommunicatorMessage result = new fi.otavanopisto.muikku.atests.CommunicatorMessage(message.getId(), communicatorMessageId2, message.getSender(), payload.getCategoryName(), message.getCaption(), message.getContent(), message.getCreated(), payload.getTags(), payload.getRecipientIds(), payload.getRecipientGroupIds(), payload.getRecipientStudentsWorkspaceIds(), payload.getRecipientTeachersWorkspaceIds());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("sender", "Admin User");
    params.put("subject", message.getCaption());
    params.put("content", message.getContent());
    params.put("url", "https://dev.muikku.fi/communicator");
    notifierController.sendNotification(communicatorNewInboxMessageNotification, user, recipients, params);
    return Response.ok(result).build();
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CommunicatorMessageCategory(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageCategory) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) UserGroupUserEntity(fi.otavanopisto.muikku.model.users.UserGroupUserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Tag(fi.otavanopisto.muikku.model.base.Tag) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 33 with UserGroupEntity

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

the class AnnouncerRESTService method createAnnouncement.

@POST
@Path("/announcements")
@RESTPermit(handling = Handling.INLINE)
public Response createAnnouncement(AnnouncementRESTModel restModel) {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    List<Long> workspaceEntityIds = restModel.getWorkspaceEntityIds();
    if (workspaceEntityIds == null) {
        workspaceEntityIds = Collections.emptyList();
    }
    List<Long> userGroupEntityIds = restModel.getUserGroupEntityIds();
    if (userGroupEntityIds == null) {
        userGroupEntityIds = Collections.emptyList();
    }
    if (workspaceEntityIds.isEmpty() && !sessionController.hasEnvironmentPermission(AnnouncerPermissions.CREATE_ANNOUNCEMENT)) {
        return Response.status(Status.FORBIDDEN).entity("You don't have the permission to create environment announcements").build();
    }
    for (Long workspaceEntityId : workspaceEntityIds) {
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
        if (workspaceEntity == null) {
            return Response.status(Status.BAD_REQUEST).entity("Invalid workspaceEntityId").build();
        }
        if (!sessionController.hasWorkspacePermission(AnnouncerPermissions.CREATE_WORKSPACE_ANNOUNCEMENT, workspaceEntity)) {
            return Response.status(Status.FORBIDDEN).entity("You don't have the permission to create workspace announcement").build();
        }
    }
    Announcement announcement = announcementController.createAnnouncement(userEntity, restModel.getCaption(), restModel.getContent(), restModel.getStartDate(), restModel.getEndDate(), restModel.getPubliclyVisible());
    for (Long userGroupEntityId : userGroupEntityIds) {
        UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityById(userGroupEntityId);
        if (userGroupEntity == null) {
            return Response.status(Status.BAD_REQUEST).entity("Invalid userGroupEntityId").build();
        }
        announcementController.addAnnouncementTargetGroup(announcement, userGroupEntity);
    }
    for (Long workspaceEntityId : workspaceEntityIds) {
        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
        if (workspaceEntity == null) {
            return Response.status(Status.BAD_REQUEST).entity("Invalid workspaceEntityId").build();
        }
        announcementController.addAnnouncementWorkspace(announcement, workspaceEntity);
    }
    return Response.noContent().build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Announcement(fi.otavanopisto.muikku.plugins.announcer.model.Announcement) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 34 with UserGroupEntity

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

the class UserGroupEntityDAO method create.

public UserGroupEntity create(SchoolDataSource defaultSchoolDataSource, String defaultIdentifier, boolean archived) {
    UserGroupEntity userGroup = new UserGroupEntity();
    userGroup.setArchived(archived);
    userGroup.setSchoolDataSource(defaultSchoolDataSource);
    userGroup.setIdentifier(defaultIdentifier);
    getEntityManager().persist(userGroup);
    return userGroup;
}
Also used : UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Example 35 with UserGroupEntity

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

the class UserGroupEntityDAO method findByDataSourceAndIdentifier.

public UserGroupEntity findByDataSourceAndIdentifier(SchoolDataSource schoolDataSource, String identifier) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<UserGroupEntity> criteria = criteriaBuilder.createQuery(UserGroupEntity.class);
    Root<UserGroupEntity> root = criteria.from(UserGroupEntity.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(UserGroupEntity_.schoolDataSource), schoolDataSource), criteriaBuilder.equal(root.get(UserGroupEntity_.identifier), identifier)));
    return getSingleResult(entityManager.createQuery(criteria));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity)

Aggregations

UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)40 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)14 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)12 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)12 Path (javax.ws.rs.Path)12 ArrayList (java.util.ArrayList)11 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)10 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)9 EntityManager (javax.persistence.EntityManager)8 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)7 UserGroup (fi.otavanopisto.muikku.schooldata.entity.UserGroup)6 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)5 HashMap (java.util.HashMap)5 POST (javax.ws.rs.POST)5 Permission (fi.otavanopisto.muikku.model.security.Permission)4 Announcement (fi.otavanopisto.muikku.plugins.announcer.model.Announcement)4 Tag (fi.otavanopisto.muikku.model.base.Tag)3 EnvironmentRoleArchetype (fi.otavanopisto.muikku.model.users.EnvironmentRoleArchetype)3 CommunicatorMessage (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessage)3