Search in sources :

Example 6 with AnnouncementWorkspace

use of fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace in project muikku by otavanopisto.

the class AnnouncerRESTService method findAnnouncementById.

@GET
@Path("/announcements/{ID}")
@RESTPermit(AnnouncerPermissions.FIND_ANNOUNCEMENT)
public Response findAnnouncementById(@PathParam("ID") Long announcementId) {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    Announcement announcement = announcementController.findById(announcementId);
    if (announcement == null) {
        return Response.status(Status.NOT_FOUND).entity("Announcement not found").build();
    }
    List<AnnouncementUserGroup> announcementUserGroups = announcementController.listAnnouncementUserGroups(announcement);
    List<AnnouncementWorkspace> announcementWorkspaces = announcementController.listAnnouncementWorkspacesSortByUserFirst(announcement, userEntity);
    return Response.ok(createRESTModel(announcement, announcementUserGroups, announcementWorkspaces)).build();
}
Also used : Announcement(fi.otavanopisto.muikku.plugins.announcer.model.Announcement) AnnouncementUserGroup(fi.otavanopisto.muikku.plugins.announcer.model.AnnouncementUserGroup) AnnouncementWorkspace(fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 7 with AnnouncementWorkspace

use of fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace in project muikku by otavanopisto.

the class AnnouncerRESTService method createRESTModel.

private AnnouncementRESTModel createRESTModel(Announcement announcement, List<AnnouncementUserGroup> announcementUserGroups, List<AnnouncementWorkspace> announcementWorkspaces) {
    AnnouncementRESTModel restModel = new AnnouncementRESTModel();
    restModel.setPublisherUserEntityId(announcement.getPublisherUserEntityId());
    restModel.setCaption(announcement.getCaption());
    restModel.setContent(announcement.getContent());
    restModel.setCreated(announcement.getCreated());
    restModel.setStartDate(announcement.getStartDate());
    restModel.setEndDate(announcement.getEndDate());
    restModel.setId(announcement.getId());
    restModel.setPubliclyVisible(announcement.getPubliclyVisible());
    restModel.setArchived(announcement.getArchived());
    List<Long> userGroupEntityIds = new ArrayList<>();
    for (AnnouncementUserGroup announcementUserGroup : announcementUserGroups) {
        userGroupEntityIds.add(announcementUserGroup.getUserGroupEntityId());
    }
    restModel.setUserGroupEntityIds(userGroupEntityIds);
    List<Long> workspaceEntityIds = new ArrayList<>();
    List<WorkspaceBasicInfo> workspaceBasicInfos = new ArrayList<>();
    for (AnnouncementWorkspace announcementWorkspace : announcementWorkspaces) {
        workspaceEntityIds.add(announcementWorkspace.getWorkspaceEntityId());
        WorkspaceBasicInfo workspaceBasicInfo = workspaceRESTModelController.workspaceBasicInfo(announcementWorkspace.getWorkspaceEntityId());
        if (workspaceBasicInfo != null)
            workspaceBasicInfos.add(workspaceBasicInfo);
        else
            logger.warning(String.format("Logged user couldn't find workspace basic info for workspace"));
    }
    restModel.setWorkspaceEntityIds(workspaceEntityIds);
    restModel.setWorkspaces(workspaceBasicInfos);
    Date date = currentDate();
    if (date.before(announcement.getStartDate())) {
        restModel.setTemporalStatus(AnnouncementTemporalStatus.UPCOMING);
    } else if (date.after(announcement.getEndDate())) {
        restModel.setTemporalStatus(AnnouncementTemporalStatus.ENDED);
    } else {
        restModel.setTemporalStatus(AnnouncementTemporalStatus.ACTIVE);
    }
    return restModel;
}
Also used : AnnouncementUserGroup(fi.otavanopisto.muikku.plugins.announcer.model.AnnouncementUserGroup) AnnouncementWorkspace(fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace) ArrayList(java.util.ArrayList) WorkspaceBasicInfo(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceBasicInfo) Date(java.util.Date)

Example 8 with AnnouncementWorkspace

use of fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace in project muikku by otavanopisto.

the class AnnouncementsViewBackingBean method init.

@RequestAction
public String init() {
    UserEntity loggedUserEntity = sessionController.getLoggedUserEntity();
    if (announcementId != null) {
        currentAnnouncement = announcementController.findById(announcementId);
        if (currentAnnouncement != null) {
            List<AnnouncementWorkspace> announcementWorkspaces = announcementController.listAnnouncementWorkspacesSortByUserFirst(currentAnnouncement, loggedUserEntity);
            currentAnnouncementWorkspaces = new ArrayList<WorkspaceBasicInfo>();
            for (AnnouncementWorkspace aw : announcementWorkspaces) {
                currentAnnouncementWorkspaces.add(workspaceRESTModelController.workspaceBasicInfo(aw.getWorkspaceEntityId()));
            }
        }
    }
    AnnouncementEnvironmentRestriction environment = sessionController.hasEnvironmentPermission(AnnouncerPermissions.LIST_ENVIRONMENT_GROUP_ANNOUNCEMENTS) ? AnnouncementEnvironmentRestriction.PUBLICANDGROUP : AnnouncementEnvironmentRestriction.PUBLIC;
    AnnouncementTimeFrame timeFrame = AnnouncementTimeFrame.CURRENT;
    activeAnnouncements = announcementController.listAnnouncements(true, true, environment, timeFrame, loggedUserEntity, false, false);
    return null;
}
Also used : AnnouncementWorkspace(fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace) AnnouncementTimeFrame(fi.otavanopisto.muikku.plugins.announcer.dao.AnnouncementTimeFrame) AnnouncementEnvironmentRestriction(fi.otavanopisto.muikku.plugins.announcer.dao.AnnouncementEnvironmentRestriction) WorkspaceBasicInfo(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceBasicInfo) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 9 with AnnouncementWorkspace

use of fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace in project muikku by otavanopisto.

the class AnnouncementWorkspaceDAO method listByAnnouncementAndWorkspacesAndArchived.

public List<AnnouncementWorkspace> listByAnnouncementAndWorkspacesAndArchived(Announcement announcement, List<WorkspaceEntity> workspaces, Boolean archived) {
    if (CollectionUtils.isEmpty(workspaces)) {
        return listByAnnouncementAndArchived(announcement, archived);
    }
    List<Long> workspaceEntityIds = workspaces.stream().map((WorkspaceEntity workspace) -> workspace.getId()).collect(Collectors.toList());
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<AnnouncementWorkspace> criteria = criteriaBuilder.createQuery(AnnouncementWorkspace.class);
    Root<AnnouncementWorkspace> root = criteria.from(AnnouncementWorkspace.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(AnnouncementWorkspace_.announcement), announcement), root.get(AnnouncementWorkspace_.workspaceEntityId).in(workspaceEntityIds), criteriaBuilder.equal(root.get(AnnouncementWorkspace_.archived), archived)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) AnnouncementWorkspace(fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace)

Example 10 with AnnouncementWorkspace

use of fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace in project muikku by otavanopisto.

the class AnnouncementWorkspaceDAO method listByArchived.

public List<AnnouncementWorkspace> listByArchived(Boolean archived) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<AnnouncementWorkspace> criteria = criteriaBuilder.createQuery(AnnouncementWorkspace.class);
    Root<AnnouncementWorkspace> root = criteria.from(AnnouncementWorkspace.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.get(AnnouncementWorkspace_.archived), archived));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) AnnouncementWorkspace(fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace)

Aggregations

AnnouncementWorkspace (fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace)11 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)5 Announcement (fi.otavanopisto.muikku.plugins.announcer.model.Announcement)5 AnnouncementUserGroup (fi.otavanopisto.muikku.plugins.announcer.model.AnnouncementUserGroup)5 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)4 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)4 EntityManager (javax.persistence.EntityManager)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 Path (javax.ws.rs.Path)4 ArrayList (java.util.ArrayList)3 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)2 AnnouncementEnvironmentRestriction (fi.otavanopisto.muikku.plugins.announcer.dao.AnnouncementEnvironmentRestriction)2 WorkspaceBasicInfo (fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceBasicInfo)2 Date (java.util.Date)2 GET (javax.ws.rs.GET)2 AnnouncementTimeFrame (fi.otavanopisto.muikku.plugins.announcer.dao.AnnouncementTimeFrame)1 Predicate (javax.persistence.criteria.Predicate)1 DELETE (javax.ws.rs.DELETE)1 PUT (javax.ws.rs.PUT)1 RequestAction (org.ocpsoft.rewrite.annotation.RequestAction)1