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