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();
}
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;
}
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;
}
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();
}
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();
}
Aggregations