Search in sources :

Example 1 with WorkspaceMaterialContainsAnswersExeption

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();
        }
    }
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceMaterialDeleteError(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialDeleteError) WorkspaceMaterialContainsAnswersExeption(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption) Material(fi.otavanopisto.muikku.plugins.material.model.Material) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceFieldIOException(fi.otavanopisto.muikku.plugins.workspace.fieldio.WorkspaceFieldIOException) IOException(java.io.IOException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)

Example 2 with WorkspaceMaterialContainsAnswersExeption

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();
}
Also used : CoOpsUsageException(fi.foyt.coops.CoOpsUsageException) CoOpsNotImplementedException(fi.foyt.coops.CoOpsNotImplementedException) CoOpsInternalErrorException(fi.foyt.coops.CoOpsInternalErrorException) WorkspaceMaterialContainsAnswersExeption(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption) CoOpsNotFoundException(fi.foyt.coops.CoOpsNotFoundException) CoOpsForbiddenException(fi.foyt.coops.CoOpsForbiddenException) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) File(fi.foyt.coops.model.File) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 3 with WorkspaceMaterialContainsAnswersExeption

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());
    }
}
Also used : XPathExpressionException(javax.xml.xpath.XPathExpressionException) DeusNexInternalException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException) WorkspaceMaterialContainsAnswersExeption(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException) Lock(javax.ejb.Lock)

Example 4 with WorkspaceMaterialContainsAnswersExeption

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();
}
Also used : WorkspaceMaterialEvaluation(fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation) WorkspaceMaterialContainsAnswersExeption(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) 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 5 with WorkspaceMaterialContainsAnswersExeption

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();
}
Also used : WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceMaterialProducer(fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer) WorkspaceMaterialContainsAnswersExeption(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Aggregations

WorkspaceMaterialContainsAnswersExeption (fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption)6 Path (javax.ws.rs.Path)5 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)4 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)4 DELETE (javax.ws.rs.DELETE)3 CoOpsForbiddenException (fi.foyt.coops.CoOpsForbiddenException)2 CoOpsInternalErrorException (fi.foyt.coops.CoOpsInternalErrorException)2 CoOpsNotFoundException (fi.foyt.coops.CoOpsNotFoundException)2 CoOpsNotImplementedException (fi.foyt.coops.CoOpsNotImplementedException)2 CoOpsUsageException (fi.foyt.coops.CoOpsUsageException)2 File (fi.foyt.coops.model.File)2 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)2 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)2 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)2 IOException (java.io.IOException)2 WorkspaceMaterialProducer (fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 DeusNexInternalException (fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException)1 WorkspaceMaterialEvaluation (fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation)1 Material (fi.otavanopisto.muikku.plugins.material.model.Material)1