Search in sources :

Example 71 with WorkspaceEntity

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();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 72 with WorkspaceEntity

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();
}
Also used : Announcement(fi.otavanopisto.muikku.plugins.announcer.model.Announcement) AnnouncementUserGroup(fi.otavanopisto.muikku.plugins.announcer.model.AnnouncementUserGroup) ArrayList(java.util.ArrayList) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) AnnouncementWorkspace(fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace) AnnouncementEnvironmentRestriction(fi.otavanopisto.muikku.plugins.announcer.dao.AnnouncementEnvironmentRestriction) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 73 with WorkspaceEntity

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();
}
Also used : Announcement(fi.otavanopisto.muikku.plugins.announcer.model.Announcement) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) AnnouncementUserGroup(fi.otavanopisto.muikku.plugins.announcer.model.AnnouncementUserGroup) AnnouncementWorkspace(fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace) 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) PUT(javax.ws.rs.PUT)

Example 74 with WorkspaceEntity

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();
}
Also used : Announcement(fi.otavanopisto.muikku.plugins.announcer.model.Announcement) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) AnnouncementWorkspace(fi.otavanopisto.muikku.plugins.announcer.workspace.model.AnnouncementWorkspace) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 75 with WorkspaceEntity

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());
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Date(java.util.Date)

Aggregations

WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)190 Path (javax.ws.rs.Path)102 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)82 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)65 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)51 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)49 GET (javax.ws.rs.GET)46 ArrayList (java.util.ArrayList)38 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)29 POST (javax.ws.rs.POST)26 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)25 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)21 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)21 WorkspaceForumArea (fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea)20 RequestAction (org.ocpsoft.rewrite.annotation.RequestAction)19 ForumArea (fi.otavanopisto.muikku.plugins.forum.model.ForumArea)17 Date (java.util.Date)17 DELETE (javax.ws.rs.DELETE)17 PUT (javax.ws.rs.PUT)16 WorkspaceRootFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)15