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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations