Search in sources :

Example 6 with Announcement

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

the class AcceptanceTestsRESTService method updateAnnouncementWorkspace.

@PUT
@Path("/announcements/{ANNOUNCEMENTID}/workspace/{WORKSPACEID}")
@RESTPermit(handling = Handling.UNSECURED)
public Response updateAnnouncementWorkspace(@PathParam("ANNOUNCEMENTID") Long announcementId, @PathParam("WORKSPACEID") Long workspaceId) {
    Announcement newAnnouncement = announcementController.findById(announcementId);
    if (newAnnouncement == null) {
        return Response.status(Status.BAD_REQUEST).entity("Announcement not found").build();
    }
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
    if (workspaceEntity == null) {
        return Response.status(Status.BAD_REQUEST).entity("Workspace not found").build();
    }
    announcementController.addAnnouncementWorkspace(newAnnouncement, workspaceEntity);
    return Response.ok().build();
}
Also used : Announcement(fi.otavanopisto.muikku.plugins.announcer.model.Announcement) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) PUT(javax.ws.rs.PUT)

Example 7 with Announcement

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

the class AcceptanceTestsRESTService method deleteAnnouncements.

@DELETE
@Path("/announcements")
@RESTPermit(handling = Handling.UNSECURED)
public Response deleteAnnouncements() {
    for (Announcement announcement : announcementController.listAll()) {
        announcementController.deleteAnnouncementWorkspaces(announcement);
        announcementController.deleteAnnouncementTargetGroups(announcement);
        announcementController.delete(announcement);
    }
    return Response.noContent().build();
}
Also used : Announcement(fi.otavanopisto.muikku.plugins.announcer.model.Announcement) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 8 with Announcement

use of fi.otavanopisto.muikku.plugins.announcer.model.Announcement 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 9 with Announcement

use of fi.otavanopisto.muikku.plugins.announcer.model.Announcement 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 10 with Announcement

use of fi.otavanopisto.muikku.plugins.announcer.model.Announcement 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)

Aggregations

Announcement (fi.otavanopisto.muikku.plugins.announcer.model.Announcement)11 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)8 Path (javax.ws.rs.Path)8 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)7 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)5 AnnouncementWorkspace (fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace)5 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)4 AnnouncementUserGroup (fi.otavanopisto.muikku.plugins.announcer.model.AnnouncementUserGroup)4 ArrayList (java.util.ArrayList)3 DELETE (javax.ws.rs.DELETE)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 UserGroupUserEntity (fi.otavanopisto.muikku.model.users.UserGroupUserEntity)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 AnnouncementEnvironmentRestriction (fi.otavanopisto.muikku.plugins.announcer.dao.AnnouncementEnvironmentRestriction)1 Date (java.util.Date)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1