Search in sources :

Example 6 with Material

use of fi.otavanopisto.muikku.plugins.material.model.Material 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 7 with Material

use of fi.otavanopisto.muikku.plugins.material.model.Material 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 8 with Material

use of fi.otavanopisto.muikku.plugins.material.model.Material in project muikku by otavanopisto.

the class MaterialRESTService method deleteWorkspaceMaterialProducer.

@DELETE
@Path("/material/{MATERIALID}/producers/{PRODUCERID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response deleteWorkspaceMaterialProducer(@PathParam("MATERIALID") Long materialId, @PathParam("PRODUCERID") Long producerId) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).entity("Not logged in").build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.MANAGE_MATERIAL_PRODUCERS)) {
        return Response.status(Status.FORBIDDEN).entity("Permission denied").build();
    }
    Material material = materialController.findMaterialById(materialId);
    if (material == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Material %d not found", materialId)).build();
    }
    fi.otavanopisto.muikku.plugins.material.model.MaterialProducer materialProducer = materialController.findMaterialProducer(producerId);
    materialController.deleteMaterialProducer(materialProducer);
    return Response.noContent().build();
}
Also used : Material(fi.otavanopisto.muikku.plugins.material.model.Material) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 9 with Material

use of fi.otavanopisto.muikku.plugins.material.model.Material in project muikku by otavanopisto.

the class MaterialRESTService method updateMaterial.

@PUT
@Path("/material/{ID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response updateMaterial(@PathParam("ID") Long id, RestMaterial payload) {
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.MANAGE_MATERIALS)) {
        return Response.status(Status.FORBIDDEN).entity("Permission denied").build();
    }
    Material material = materialController.findMaterialById(id);
    if (material == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Material %d not found", id)).build();
    }
    if (StringUtils.isNotBlank(payload.getTitle()) && !StringUtils.equals(payload.getTitle(), material.getTitle())) {
        return Response.status(Status.BAD_REQUEST).entity("Refused to update title via this REST endpoint").build();
    }
    if (payload.getViewRestrict() == null) {
        return Response.status(Status.BAD_REQUEST).entity("Required field viewRestrict missing").build();
    }
    materialController.updateMaterialLicense(material, payload.getLicense());
    materialController.updateMaterialViewRestrict(material, payload.getViewRestrict());
    return Response.ok(createRestModel(material)).build();
}
Also used : Material(fi.otavanopisto.muikku.plugins.material.model.Material) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) PUT(javax.ws.rs.PUT)

Example 10 with Material

use of fi.otavanopisto.muikku.plugins.material.model.Material in project muikku by otavanopisto.

the class MaterialRESTService method listMaterialWorkspaceMaterials.

@GET
// @Path("/material/{ID:[0-9]*}/workspaceMaterials/")
@Path("/material/{ID}/workspaceMaterials/")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listMaterialWorkspaceMaterials(@PathParam("ID") Long materialId) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.LIST_MATERIAL_WORKSPACE_MATERIALS)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    Material material = materialController.findMaterialById(materialId);
    if (material == null) {
        return Response.status(Status.NOT_FOUND).entity("Material not found").build();
    }
    List<WorkspaceMaterial> workspaceMaterials = workspaceMaterialController.listWorkspaceMaterialsByMaterial(material);
    return Response.ok(createRestModel(workspaceMaterials.toArray(new WorkspaceMaterial[0]))).build();
}
Also used : Material(fi.otavanopisto.muikku.plugins.material.model.Material) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

Material (fi.otavanopisto.muikku.plugins.material.model.Material)20 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)15 Path (javax.ws.rs.Path)10 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)9 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)7 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)6 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)3 MaterialMeta (fi.otavanopisto.muikku.plugins.material.model.MaterialMeta)3 MaterialMetaKey (fi.otavanopisto.muikku.plugins.material.model.MaterialMetaKey)3 WorkspaceFieldIOException (fi.otavanopisto.muikku.plugins.workspace.fieldio.WorkspaceFieldIOException)3 WorkspaceFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)3 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)3 IOException (java.io.IOException)3 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)2 BinaryMaterial (fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)2 WorkspaceMaterialField (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialField)2 ArrayList (java.util.ArrayList)2 DELETE (javax.ws.rs.DELETE)2