Search in sources :

Example 11 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class MaterialMetaRESTService method listMaterialMetaKeys.

@GET
@Path("/metakeys")
@Produces(MediaType.APPLICATION_JSON)
@RESTPermitUnimplemented
public Response listMaterialMetaKeys() {
    List<MaterialMetaKey> materialMetaKeys = materialController.listMaterialMetaKeys();
    List<String> result = new ArrayList<>(materialMetaKeys.size());
    for (MaterialMetaKey materialMetaKey : materialMetaKeys) {
        result.add(materialMetaKey.getName());
    }
    return Response.ok(result).build();
}
Also used : ArrayList(java.util.ArrayList) MaterialMetaKey(fi.otavanopisto.muikku.plugins.material.model.MaterialMetaKey) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 12 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class MaterialMetaRESTService method createMaterialMeta.

@POST
@Path("/materials/{id}/meta")
@Produces(MediaType.APPLICATION_JSON)
@RESTPermitUnimplemented
public Response createMaterialMeta(@PathParam("id") Long id, fi.otavanopisto.muikku.plugins.material.rest.MaterialMeta payload) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.MANAGE_MATERIAL_META)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    Material material = materialController.findMaterialById(id);
    if (material == null) {
        return Response.status(Status.NOT_FOUND).entity("Material not found").build();
    }
    if (StringUtils.isBlank(payload.getKey())) {
        return Response.status(Status.BAD_REQUEST).entity("Missing key").build();
    }
    MaterialMetaKey key = materialController.findMaterialMetaKey(payload.getKey());
    if (key == null) {
        return Response.status(Status.BAD_REQUEST).entity("Invalid key").build();
    }
    return Response.ok(createRestModel(materialController.createMaterialMeta(material, key, payload.getValue()))).build();
}
Also used : MaterialMetaKey(fi.otavanopisto.muikku.plugins.material.model.MaterialMetaKey) Material(fi.otavanopisto.muikku.plugins.material.model.Material) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)

Example 13 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class MaterialMetaRESTService method listMaterialMetas.

@GET
@Path("/materials/{id}/meta/")
@Produces(MediaType.APPLICATION_JSON)
@RESTPermitUnimplemented
public Response listMaterialMetas(@PathParam("id") Long id) {
    Material material = materialController.findMaterialById(id);
    if (material == null) {
        return Response.status(Status.NOT_FOUND).entity("Material not found").build();
    }
    List<MaterialMeta> metas = materialController.listMaterialMetas(material);
    if (metas.isEmpty()) {
        return Response.noContent().build();
    }
    return Response.ok(createRestModel(metas.toArray(new MaterialMeta[0]))).build();
}
Also used : MaterialMeta(fi.otavanopisto.muikku.plugins.material.model.MaterialMeta) Material(fi.otavanopisto.muikku.plugins.material.model.Material) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 14 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class WebSocketRESTService method createTicket.

@POST
@Path("/ticket")
@RESTPermitUnimplemented
public Response createTicket() {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    Long userEntityId = userEntity != null ? userEntity.getId() : null;
    Date timestamp = new Date();
    String ip = request.getRemoteAddr();
    String ticket = UUID.randomUUID().toString();
    webSocketTicketController.createTicket(ticket, userEntityId, ip, timestamp);
    return Response.ok(new WebSocketTicketRESTModel(ticket)).build();
}
Also used : UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Date(java.util.Date) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)

Example 15 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class WorkspaceRESTService method getWorkspaceMaterialAnswers.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/materials/{WORKSPACEMATERIALID}/compositeMaterialReplies")
@RESTPermitUnimplemented
public Response getWorkspaceMaterialAnswers(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId, @QueryParam("userEntityId") Long userEntityId) {
    // TODO: Security
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).entity("Not logged in").build();
    }
    // TODO Return everyone's answers
    if (userEntityId == null) {
        return Response.status(Status.NOT_IMPLEMENTED).build();
    }
    UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
    WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(workspaceMaterialId);
    if (workspaceMaterial == null) {
        return Response.status(Status.NOT_FOUND).entity("Workspace material could not be found").build();
    }
    List<WorkspaceMaterialFieldAnswer> answers = new ArrayList<>();
    try {
        fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReply reply = workspaceMaterialReplyController.findWorkspaceMaterialReplyByWorkspaceMaterialAndUserEntity(workspaceMaterial, userEntity);
        if (reply != null) {
            List<WorkspaceMaterialField> fields = workspaceMaterialFieldController.listWorkspaceMaterialFieldsByWorkspaceMaterial(workspaceMaterial);
            for (WorkspaceMaterialField field : fields) {
                String value = workspaceMaterialFieldController.retrieveFieldValue(field, reply);
                Material material = field.getQueryField().getMaterial();
                WorkspaceMaterialFieldAnswer answer = new WorkspaceMaterialFieldAnswer(workspaceMaterial.getId(), material.getId(), field.getEmbedId(), field.getQueryField().getName(), value);
                answers.add(answer);
            }
        }
        WorkspaceMaterialCompositeReply result = new WorkspaceMaterialCompositeReply(answers, reply != null ? reply.getState() : null, reply != null ? reply.getCreated() : null, reply != null ? reply.getLastModified() : null, reply != null ? reply.getSubmitted() : null, reply != null ? reply.getWithdrawn() : null);
        return Response.ok(result).build();
    } catch (WorkspaceFieldIOException e) {
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity("Internal error occurred while retrieving field answers: " + e.getMessage()).build();
    }
}
Also used : WorkspaceFieldIOException(fi.otavanopisto.muikku.plugins.workspace.fieldio.WorkspaceFieldIOException) ArrayList(java.util.ArrayList) WorkspaceMaterialCompositeReply(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceMaterialCompositeReply) Material(fi.otavanopisto.muikku.plugins.material.model.Material) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceMaterialFieldAnswer(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceMaterialFieldAnswer) WorkspaceMaterialField(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialField) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Aggregations

RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)40 Path (javax.ws.rs.Path)40 GET (javax.ws.rs.GET)23 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)20 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)13 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)10 POST (javax.ws.rs.POST)8 Material (fi.otavanopisto.muikku.plugins.material.model.Material)7 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)7 ArrayList (java.util.ArrayList)7 PUT (javax.ws.rs.PUT)6 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)5 WorkspaceRootFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)5 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)5 Produces (javax.ws.rs.Produces)5 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)4 MaterialMetaKey (fi.otavanopisto.muikku.plugins.material.model.MaterialMetaKey)4 User (fi.otavanopisto.muikku.schooldata.entity.User)4 CacheControl (javax.ws.rs.core.CacheControl)4 EntityTag (javax.ws.rs.core.EntityTag)4