use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class AcceptanceTestsRESTService method publishWorkspace.
@GET
@Path("/workspaces/{WORKSPACEENTITYID}/publish")
@RESTPermit(handling = Handling.UNSECURED)
public Response publishWorkspace(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(404).entity("Not found").build();
}
workspaceEntityController.updatePublished(workspaceEntity, true);
return Response.noContent().build();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class AnnouncerRESTService method listAnnouncements.
@GET
@Path("/announcements")
@RESTPermit(handling = Handling.INLINE)
public Response listAnnouncements(@QueryParam("hideEnvironmentAnnouncements") @DefaultValue("false") boolean hideEnvironmentAnnouncements, @QueryParam("hideWorkspaceAnnouncements") @DefaultValue("false") boolean hideWorkspaceAnnouncements, @QueryParam("hideGroupAnnouncements") @DefaultValue("false") boolean hideGroupAnnouncements, @QueryParam("workspaceEntityId") Long workspaceEntityId, @QueryParam("onlyMine") @DefaultValue("false") boolean onlyMine, @QueryParam("onlyEditable") @DefaultValue("false") boolean onlyEditable, @QueryParam("onlyArchived") @DefaultValue("false") boolean onlyArchived, @QueryParam("timeFrame") @DefaultValue("CURRENT") AnnouncementTimeFrame timeFrame) {
UserEntity currentUserEntity = sessionController.getLoggedUserEntity();
if (currentUserEntity == null) {
return Response.noContent().build();
}
List<Announcement> announcements = null;
AnnouncementEnvironmentRestriction environment = hideEnvironmentAnnouncements ? AnnouncementEnvironmentRestriction.NONE : sessionController.hasEnvironmentPermission(AnnouncerPermissions.LIST_ENVIRONMENT_GROUP_ANNOUNCEMENTS) ? AnnouncementEnvironmentRestriction.PUBLICANDGROUP : AnnouncementEnvironmentRestriction.PUBLIC;
if (workspaceEntityId == null) {
boolean includeGroups = !hideGroupAnnouncements;
boolean includeWorkspaces = !hideWorkspaceAnnouncements;
announcements = announcementController.listAnnouncements(includeGroups, includeWorkspaces, environment, timeFrame, currentUserEntity, onlyMine, onlyArchived);
} else {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.BAD_REQUEST).entity("Workspace entity with given ID not found").build();
}
if (!sessionController.hasWorkspacePermission(AnnouncerPermissions.LIST_WORKSPACE_ANNOUNCEMENTS, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).entity("You don't have the permission to list workspace announcements").build();
}
announcements = announcementController.listWorkspaceAnnouncements(Arrays.asList(workspaceEntity), environment, timeFrame, currentUserEntity, onlyMine, onlyArchived);
}
List<AnnouncementRESTModel> restModels = new ArrayList<>();
for (Announcement announcement : announcements) {
if (onlyEditable && !canEdit(announcement, currentUserEntity)) {
continue;
}
List<AnnouncementUserGroup> announcementUserGroups = announcementController.listAnnouncementUserGroups(announcement);
List<AnnouncementWorkspace> announcementWorkspaces = announcementController.listAnnouncementWorkspacesSortByUserFirst(announcement, currentUserEntity);
AnnouncementRESTModel restModel = createRESTModel(announcement, announcementUserGroups, announcementWorkspaces);
restModels.add(restModel);
}
return Response.ok(restModels).build();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class AnnouncerRESTService method updateAnnouncement.
@PUT
@Path("/announcements/{ID}")
@RESTPermit(handling = Handling.INLINE)
public Response updateAnnouncement(@PathParam("ID") Long announcementId, AnnouncementRESTModel restModel) {
UserEntity userEntity = sessionController.getLoggedUserEntity();
if (announcementId == null) {
return Response.status(Status.BAD_REQUEST).build();
}
Announcement oldAnnouncement = announcementController.findById(announcementId);
if (oldAnnouncement == null) {
return Response.status(Status.NOT_FOUND).build();
}
// Check that the user has permission to update the old announcement
if (!canEdit(oldAnnouncement, userEntity))
return Response.status(Status.FORBIDDEN).entity("You don't have the permission to update this announcement.").build();
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.UPDATE_ANNOUNCEMENT)) {
return Response.status(Status.FORBIDDEN).entity("You don't have the permission to update 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.UPDATE_WORKSPACE_ANNOUNCEMENT, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).entity("You don't have the permission to update workspace announcement").build();
}
}
Announcement newAnnouncement = announcementController.updateAnnouncement(oldAnnouncement, restModel.getCaption(), restModel.getContent(), restModel.getStartDate(), restModel.getEndDate(), restModel.getPubliclyVisible(), restModel.isArchived());
announcementController.clearAnnouncementTargetGroups(newAnnouncement);
for (Long userGroupEntityId : userGroupEntityIds) {
UserGroupEntity userGroupEntity = userGroupEntityController.findUserGroupEntityById(userGroupEntityId);
if (userGroupEntity == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid userGroupEntityId").build();
}
announcementController.addAnnouncementTargetGroup(newAnnouncement, userGroupEntity);
}
announcementController.clearAnnouncementWorkspaces(newAnnouncement);
for (Long workspaceEntityId : workspaceEntityIds) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid workspaceEntityId").build();
}
announcementController.addAnnouncementWorkspace(newAnnouncement, workspaceEntity);
}
List<AnnouncementUserGroup> announcementUserGroups = announcementController.listAnnouncementUserGroups(newAnnouncement);
List<AnnouncementWorkspace> announcementWorkspaces = announcementController.listAnnouncementWorkspaces(newAnnouncement);
return Response.ok(createRESTModel(newAnnouncement, announcementUserGroups, announcementWorkspaces)).build();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class AnnouncerRESTService method deleteAnnouncement.
@DELETE
@Path("/announcements/{ID}")
@RESTPermit(handling = Handling.INLINE)
public Response deleteAnnouncement(@PathParam("ID") Long announcementId) {
Announcement announcement = announcementController.findById(announcementId);
if (announcement == null) {
return Response.status(Status.NOT_FOUND).build();
}
List<AnnouncementWorkspace> announcementWorkspaces = announcementController.listAnnouncementWorkspaces(announcement);
if (announcementWorkspaces.isEmpty() && !sessionController.hasEnvironmentPermission(AnnouncerPermissions.DELETE_ANNOUNCEMENT)) {
return Response.status(Status.FORBIDDEN).entity("You don't have the permission to update environment announcements").build();
}
for (AnnouncementWorkspace announcementWorkspace : announcementWorkspaces) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(announcementWorkspace.getWorkspaceEntityId());
if (workspaceEntity == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid workspaceEntityId").build();
}
if (!sessionController.hasWorkspacePermission(AnnouncerPermissions.DELETE_WORKSPACE_ANNOUNCEMENT, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).entity("You don't have the permission to update workspace announcement").build();
}
}
announcementController.archive(announcement);
return Response.noContent().build();
}
use of fi.otavanopisto.muikku.model.workspace.WorkspaceEntity in project muikku by otavanopisto.
the class AssessmentRequestController method createWorkspaceAssessmentRequest.
public WorkspaceAssessmentRequest createWorkspaceAssessmentRequest(WorkspaceUserEntity workspaceUserEntity, String requestText) {
String dataSource = workspaceUserEntity.getWorkspaceEntity().getDataSource().getIdentifier();
WorkspaceEntity workspaceEntity = workspaceUserEntity.getWorkspaceEntity();
return gradingController.createWorkspaceAssessmentRequest(dataSource, workspaceUserEntity.getIdentifier(), dataSource, workspaceEntity.getIdentifier(), workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier(), requestText, new Date());
}
Aggregations