use of fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation in project muikku by otavanopisto.
the class AcceptanceTestsRESTService method deleteWorkspaceMaterial.
@DELETE
@Path("/workspaces/{WORKSPACEENTITYID}/htmlmaterials/{WORKSPACEMATERIALID}")
@RESTPermit(handling = Handling.UNSECURED)
public Response deleteWorkspaceMaterial(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId) {
WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(workspaceMaterialId);
if (workspaceMaterial == null) {
return Response.status(Status.NOT_FOUND).entity("Not Found").build();
}
HtmlMaterial htmlMaterial = htmlMaterialController.findHtmlMaterialById(workspaceMaterial.getMaterialId());
if (htmlMaterial == null) {
return Response.status(Status.BAD_REQUEST).entity("Not a html material").build();
}
try {
workspaceMaterialController.deleteWorkspaceMaterial(workspaceMaterial, true);
} catch (WorkspaceMaterialContainsAnswersExeption e) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
List<WorkspaceMaterialEvaluation> evaluations = evaluationController.listWorkspaceMaterialEvaluationsByWorkspaceMaterialId(workspaceMaterialId);
for (WorkspaceMaterialEvaluation evaluation : evaluations) {
evaluationController.deleteWorkspaceMaterialEvaluation(evaluation);
}
htmlMaterialController.deleteHtmlMaterial(htmlMaterial);
return Response.noContent().build();
}
Aggregations