use of fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption in project muikku by otavanopisto.
the class WorkspaceRESTService method deleteNode.
@DELETE
@Path("/workspaces/{WORKSPACEID}/materials/{WORKSPACEMATERIALID}")
@RESTPermitUnimplemented
public Response deleteNode(@PathParam("WORKSPACEID") Long workspaceEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId, @QueryParam("removeAnswers") Boolean removeAnswers, @QueryParam("updateLinkedMaterials") @DefaultValue("false") Boolean updateLinkedMaterials) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).entity("Not logged in").build();
}
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_MATERIALS, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(workspaceMaterialId);
if (workspaceMaterial == null) {
return Response.status(Status.NOT_FOUND).build();
} else {
try {
// #1261: HtmlMaterial attachments should be removed from all workspace materials sharing the same HtmlMaterial
if (updateLinkedMaterials) {
WorkspaceNode parentNode = workspaceMaterial.getParent();
if (parentNode instanceof WorkspaceMaterial) {
Long parentMaterialId = ((WorkspaceMaterial) parentNode).getMaterialId();
if (parentMaterialId != null) {
Material parentMaterial = materialController.findMaterialById(parentMaterialId);
if (parentMaterial instanceof HtmlMaterial) {
List<WorkspaceMaterial> sharedWorkspaceMaterials = workspaceMaterialController.listWorkspaceMaterialsByMaterial(parentMaterial);
for (WorkspaceMaterial sharedWorkspaceMaterial : sharedWorkspaceMaterials) {
WorkspaceMaterial childWorkspaceMaterial = workspaceMaterialController.findWorkspaceMaterialByParentAndUrlName(sharedWorkspaceMaterial, workspaceMaterial.getUrlName());
if (childWorkspaceMaterial.getId().equals(workspaceMaterial.getId())) {
// skip the one we delete below
continue;
}
workspaceMaterialController.deleteWorkspaceMaterial(childWorkspaceMaterial, removeAnswers != null ? removeAnswers : false);
}
}
}
}
}
workspaceMaterialController.deleteWorkspaceMaterial(workspaceMaterial, removeAnswers != null ? removeAnswers : false);
return Response.noContent().build();
} catch (WorkspaceMaterialContainsAnswersExeption e) {
return Response.status(Status.CONFLICT).entity(new WorkspaceMaterialDeleteError(WorkspaceMaterialDeleteError.Reason.CONTAINS_ANSWERS)).build();
} catch (Exception e) {
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
}
}
use of fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption in project muikku by otavanopisto.
the class HtmlMaterialRESTService method publishMaterial.
@POST
@Path("/{id}/publish/")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response publishMaterial(@PathParam("id") Long id, HtmlRestMaterialPublish entity) {
if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.MANAGE_MATERIALS)) {
return Response.status(Status.FORBIDDEN).entity("Permission denied").build();
}
HtmlMaterial htmlMaterial = htmlMaterialController.findHtmlMaterialById(id);
if (htmlMaterial == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (!htmlMaterial.getRevisionNumber().equals(entity.getFromRevision())) {
return Response.status(Status.CONFLICT).entity(new HtmlRestMaterialPublishError(HtmlRestMaterialPublishError.Reason.CONCURRENT_MODIFICATIONS)).build();
}
try {
File fileRevision = coOpsApi.fileGet(id.toString(), entity.getToRevision());
if (fileRevision == null) {
return Response.status(Status.NOT_FOUND).build();
}
htmlMaterialController.updateHtmlMaterialToRevision(htmlMaterial, fileRevision.getContent(), entity.getToRevision(), false, entity.getRemoveAnswers() != null ? entity.getRemoveAnswers() : false);
} catch (WorkspaceMaterialContainsAnswersExeption e) {
return Response.status(Status.CONFLICT).entity(new HtmlRestMaterialPublishError(HtmlRestMaterialPublishError.Reason.CONTAINS_ANSWERS)).build();
} catch (CoOpsNotImplementedException | CoOpsNotFoundException | CoOpsUsageException | CoOpsInternalErrorException | CoOpsForbiddenException e) {
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
return Response.noContent().build();
}
use of fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption in project muikku by otavanopisto.
the class MaterialUnEmbedder method unembedWorkspaceMaterials.
@Lock
public void unembedWorkspaceMaterials(WorkspaceNode parentNode) throws DeusNexInternalException {
try {
loadHtmlMaterialPieces();
for (WorkspaceNode node : workspaceMaterialController.listWorkspaceNodesByParent(parentNode)) {
unembedWorkspaceNode(parentNode, node);
}
saveHtmlMaterialPieces();
} catch (XPathExpressionException | SAXException | IOException | ParserConfigurationException | TransformerException | WorkspaceMaterialContainsAnswersExeption e) {
throw new DeusNexInternalException(e.getClass().getName() + ": " + e.getMessage());
}
}
use of fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption 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();
}
use of fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption in project muikku by otavanopisto.
the class AcceptanceTestsRESTService method deleteWorkspace.
@DELETE
@Path("/workspaces/{WORKSPACEENTITYID}")
@RESTPermit(handling = Handling.UNSECURED)
public Response deleteWorkspace(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(404).entity("Not found").build();
}
try {
List<WorkspaceMaterialProducer> workspaceMaterialProducers = workspaceController.listWorkspaceMaterialProducers(workspaceEntity);
for (WorkspaceMaterialProducer workspaceMaterialProducer : workspaceMaterialProducers) {
workspaceController.deleteWorkspaceMaterialProducer(workspaceMaterialProducer);
}
} catch (Exception e) {
return Response.status(500).entity(e.getMessage()).build();
}
try {
workspaceMaterialController.deleteAllWorkspaceNodes(workspaceEntity);
} catch (WorkspaceMaterialContainsAnswersExeption e) {
return Response.status(500).entity(e.getMessage()).build();
}
List<WorkspaceUserEntity> workspaceUserEntities = workspaceUserEntityController.listWorkspaceUserEntitiesIncludeArchived(workspaceEntity);
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
workspaceUserEntityController.deleteWorkspaceUserEntity(workspaceUserEntity);
}
workspaceEntityController.deleteWorkspaceEntity(workspaceEntity);
return Response.noContent().build();
}
Aggregations