Search in sources :

Example 1 with RESTPermit

use of fi.otavanopisto.security.rest.RESTPermit in project muikku by otavanopisto.

the class AcceptanceTestsRESTService method createWorkspace.

@POST
@Path("/workspaces")
@RESTPermit(handling = Handling.UNSECURED)
public Response createWorkspace(fi.otavanopisto.muikku.atests.Workspace payload) {
    SchoolDataWorkspaceDiscoveredEvent event = new SchoolDataWorkspaceDiscoveredEvent(payload.getSchoolDataSource(), payload.getIdentifier(), payload.getName(), null);
    schoolDataWorkspaceDiscoveredEvent.fire(event);
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(event.getDiscoveredWorkspaceEntityId());
    if (payload.getPublished() != null) {
        workspaceEntityController.updatePublished(workspaceEntity, payload.getPublished());
    }
    return Response.ok(createRestEntity(workspaceEntity, payload.getName())).build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) SchoolDataWorkspaceDiscoveredEvent(fi.otavanopisto.muikku.schooldata.events.SchoolDataWorkspaceDiscoveredEvent) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 2 with RESTPermit

use of fi.otavanopisto.security.rest.RESTPermit in project muikku by otavanopisto.

the class AcceptanceTestsRESTService method createWorkspaceMaterial.

@POST
@Path("/workspaces/{WORKSPACEID}/htmlmaterials")
@RESTPermit(handling = Handling.UNSECURED)
public Response createWorkspaceMaterial(fi.otavanopisto.muikku.atests.WorkspaceHtmlMaterial payload) {
    if (payload.getParentId() == null) {
        return Response.status(Status.BAD_REQUEST).entity("Mandatory parentId is missing").build();
    }
    HtmlMaterial htmlMaterial = htmlMaterialController.createHtmlMaterial(payload.getTitle(), payload.getHtml(), payload.getContentType(), payload.getRevisionNumber(), payload.getLicense());
    WorkspaceNode parent = workspaceMaterialController.findWorkspaceNodeById(payload.getParentId());
    if (parent == null) {
        return Response.status(Status.BAD_REQUEST).entity("Invalid parentId").build();
    }
    WorkspaceMaterial workspaceMaterial = workspaceMaterialController.createWorkspaceMaterial(parent, htmlMaterial);
    String assignmentType = payload.getAssignmentType();
    if (StringUtils.isNotBlank(assignmentType)) {
        WorkspaceMaterialAssignmentType workspaceMaterialAssignmentType = WorkspaceMaterialAssignmentType.valueOf(assignmentType);
        if (workspaceMaterialAssignmentType == null) {
            return Response.status(Status.BAD_REQUEST).entity(String.format("Invalid assignmentType '%s'", assignmentType)).build();
        }
        workspaceMaterialController.updateWorkspaceMaterialAssignmentType(workspaceMaterial, workspaceMaterialAssignmentType);
    }
    return Response.ok(createRestEntity(workspaceMaterial, htmlMaterial)).build();
}
Also used : HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) WorkspaceMaterialAssignmentType(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialAssignmentType) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 3 with RESTPermit

use of fi.otavanopisto.security.rest.RESTPermit in project muikku by otavanopisto.

the class AcceptanceTestsRESTService method createWorkspaceDiscussion.

@POST
@Path("/workspaces/{WORKSPACEENTITYID}/discussiongroups/{GROUPID}/discussions")
@RESTPermit(handling = Handling.UNSECURED)
public Response createWorkspaceDiscussion(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("GROUPID") Long groupId, fi.otavanopisto.muikku.atests.Discussion payload) {
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity("WorkspaceEntity not found").build();
    }
    ForumAreaGroup group = forumController.findForumAreaGroup(groupId);
    if (group == null) {
        return Response.status(Status.NOT_FOUND).entity("Group not found").build();
    }
    if (StringUtils.isBlank(payload.getName())) {
        return Response.status(Status.BAD_REQUEST).entity("Mandatory name is missing").build();
    }
    return Response.ok(createRestEntity(forumController.createWorkspaceForumArea(workspaceEntity, payload.getName(), payload.getDescription(), group.getId()))).build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ForumAreaGroup(fi.otavanopisto.muikku.plugins.forum.model.ForumAreaGroup) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 4 with RESTPermit

use of fi.otavanopisto.security.rest.RESTPermit in project muikku by otavanopisto.

the class AcceptanceTestsRESTService method deleteWorkspaceDiscussion.

@DELETE
@Path("/workspaces/{WORKSPACEENTITYID}/discussiongroups/{GROUPID}/discussions/{DISCUSSIONID}")
@RESTPermit(handling = Handling.UNSECURED)
public Response deleteWorkspaceDiscussion(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("GROUPID") Long groupId, @PathParam("DISCUSSIONID") Long discussionId) {
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity("WorkspaceEntity not found").build();
    }
    ForumAreaGroup group = forumController.findForumAreaGroup(groupId);
    if (group == null) {
        return Response.status(Status.NOT_FOUND).entity("Group not found").build();
    }
    ForumArea forumArea = forumController.getForumArea(discussionId);
    if (forumArea == null) {
        return Response.status(Status.NOT_FOUND).entity("Discussion not found").build();
    }
    List<ForumThread> threads = forumController.listForumThreads(forumArea, 0, Integer.MAX_VALUE, true);
    for (ForumThread thread : threads) {
        List<ForumThreadReply> replies = forumController.listForumThreadReplies(thread, 0, Integer.MAX_VALUE, true);
        for (ForumThreadReply reply : replies) {
            forumController.deleteReply(reply);
        }
        forumController.deleteThread(thread);
    }
    forumController.deleteArea(forumArea);
    return Response.noContent().build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ForumAreaGroup(fi.otavanopisto.muikku.plugins.forum.model.ForumAreaGroup) ForumThread(fi.otavanopisto.muikku.plugins.forum.model.ForumThread) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) EnvironmentForumArea(fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) ForumThreadReply(fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 5 with RESTPermit

use of fi.otavanopisto.security.rest.RESTPermit in project muikku by otavanopisto.

the class AcceptanceTestsRESTService method createPasswordChangeEntry.

@POST
@Path("/passwordchange/{EMAIL}")
@RESTPermit(handling = Handling.UNSECURED)
public Response createPasswordChangeEntry(@PathParam("EMAIL") String email) {
    UserEntity userEntity = userEntityController.findUserEntityByEmailAddress(email);
    if (userEntity == null)
        return Response.status(Status.NOT_FOUND).build();
    String confirmationHash = "testtesttest";
    userPendingPasswordChangeDAO.create(userEntity, confirmationHash);
    return Response.noContent().build();
}
Also used : 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)

Aggregations

RESTPermit (fi.otavanopisto.security.rest.RESTPermit)215 Path (javax.ws.rs.Path)214 GET (javax.ws.rs.GET)99 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)90 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)83 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)61 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)57 POST (javax.ws.rs.POST)51 DELETE (javax.ws.rs.DELETE)45 ArrayList (java.util.ArrayList)36 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)30 ForumArea (fi.otavanopisto.muikku.plugins.forum.model.ForumArea)30 PUT (javax.ws.rs.PUT)26 ForumThread (fi.otavanopisto.muikku.plugins.forum.model.ForumThread)24 WorkspaceForumArea (fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea)21 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)20 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)20 User (fi.otavanopisto.muikku.schooldata.entity.User)19 EnvironmentForumArea (fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea)18 Date (java.util.Date)16