Search in sources :

Example 26 with WorkspaceMaterial

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.

the class Evaluation2RESTService method findWorkspaceMaterialAssessment.

@GET
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/workspacematerial/{WORKSPACEMATERIALID}/assessment")
@RESTPermit(handling = Handling.INLINE)
public Response findWorkspaceMaterialAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERENTITYID") Long userEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    // User entity
    UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
    if (userEntity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    // Workspace material
    WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(workspaceMaterialId);
    if (workspaceMaterial == null) {
        return Response.status(Status.NOT_FOUND).entity("workspaceMaterial not found").build();
    }
    // Workspace material evaluation
    WorkspaceMaterialEvaluation workspaceMaterialEvaluation = evaluationController.findWorkspaceMaterialEvaluationByWorkspaceMaterialAndStudent(workspaceMaterial, userEntity);
    if (workspaceMaterialEvaluation == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    // WorkspaceMaterialEvaluation to RestAssessment
    UserEntity assessingUser = userEntityController.findUserEntityById(workspaceMaterialEvaluation.getAssessorEntityId());
    String assessmentIdentifier = workspaceMaterialEvaluation.getId().toString();
    String assessingUserIdentifier = new SchoolDataIdentifier(assessingUser.getDefaultIdentifier(), assessingUser.getDefaultSchoolDataSource().getIdentifier()).toId();
    String gradingScaleIdentifier = new SchoolDataIdentifier(workspaceMaterialEvaluation.getGradingScaleIdentifier(), workspaceMaterialEvaluation.getGradingScaleSchoolDataSource()).toId();
    String gradeIdentifier = new SchoolDataIdentifier(workspaceMaterialEvaluation.getGradeIdentifier(), workspaceMaterialEvaluation.getGradeSchoolDataSource()).toId();
    RestAssessment restAssessment = new RestAssessment(assessmentIdentifier, assessingUserIdentifier, gradingScaleIdentifier, gradeIdentifier, workspaceMaterialEvaluation.getVerbalAssessment(), workspaceMaterialEvaluation.getEvaluated(), // TODO Passing grade
    null);
    return Response.ok(restAssessment).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceMaterialEvaluation(fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation) RestAssessment(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 27 with WorkspaceMaterial

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.

the class Evaluation2RESTService method toRestAssessmentRequest.

private RestAssessmentRequest toRestAssessmentRequest(CompositeAssessmentRequest compositeAssessmentRequest) {
    Long assignmentsDone = 0L;
    Long assignmentsTotal = 0L;
    // Assignments total
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByIdentifier(compositeAssessmentRequest.getCourseIdentifier());
    if (workspaceEntity == null) {
        logger.severe(String.format("WorkspaceEntity for course %s not found", compositeAssessmentRequest.getCourseIdentifier()));
    } else {
        List<WorkspaceMaterial> evaluatedAssignments = workspaceMaterialController.listVisibleWorkspaceMaterialsByAssignmentType(workspaceEntity, WorkspaceMaterialAssignmentType.EVALUATED);
        assignmentsTotal = new Long(evaluatedAssignments.size());
        // Assignments done by user
        if (assignmentsTotal > 0) {
            UserEntity userEntity = userEntityController.findUserEntityByUserIdentifier(compositeAssessmentRequest.getUserIdentifier());
            if (userEntity == null) {
                logger.severe(String.format("UserEntity not found for AssessmentRequest student %s not found", compositeAssessmentRequest.getUserIdentifier()));
            } else {
                List<WorkspaceMaterialReplyState> replyStates = new ArrayList<WorkspaceMaterialReplyState>();
                replyStates.add(WorkspaceMaterialReplyState.FAILED);
                replyStates.add(WorkspaceMaterialReplyState.PASSED);
                replyStates.add(WorkspaceMaterialReplyState.SUBMITTED);
                replyStates.add(WorkspaceMaterialReplyState.INCOMPLETE);
                assignmentsDone = workspaceMaterialReplyController.getReplyCountByUserEntityAndReplyStatesAndWorkspaceMaterials(userEntity.getId(), replyStates, evaluatedAssignments);
            }
        }
    }
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(compositeAssessmentRequest.getCourseStudentIdentifier());
    UserEntity userEntity = userEntityController.findUserEntityByUserIdentifier(compositeAssessmentRequest.getUserIdentifier());
    // An active workspace supplementation request will override graded, passing, and evaluationDate
    Boolean graded = Boolean.TRUE;
    Boolean passing = compositeAssessmentRequest.getPassing();
    Date evaluationDate = compositeAssessmentRequest.getEvaluationDate();
    if (userEntity != null) {
        SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspaceAndArchived(userEntity.getId(), workspaceEntity.getId(), Boolean.FALSE);
        if (supplementationRequest != null) {
            graded = Boolean.FALSE;
            passing = Boolean.FALSE;
            evaluationDate = supplementationRequest.getRequestDate();
        }
    }
    RestAssessmentRequest restAssessmentRequest = new RestAssessmentRequest();
    restAssessmentRequest.setWorkspaceUserEntityId(workspaceUserEntity == null ? null : workspaceUserEntity.getId());
    restAssessmentRequest.setWorkspaceUserIdentifier(compositeAssessmentRequest.getCourseStudentIdentifier().toId());
    restAssessmentRequest.setUserEntityId(userEntity == null ? null : userEntity.getId());
    restAssessmentRequest.setAssessmentRequestDate(compositeAssessmentRequest.getAssessmentRequestDate());
    restAssessmentRequest.setEvaluationDate(evaluationDate);
    restAssessmentRequest.setPassing(passing);
    restAssessmentRequest.setGraded(graded);
    restAssessmentRequest.setAssignmentsDone(assignmentsDone);
    restAssessmentRequest.setAssignmentsTotal(assignmentsTotal);
    restAssessmentRequest.setEnrollmentDate(compositeAssessmentRequest.getCourseEnrollmentDate());
    restAssessmentRequest.setFirstName(compositeAssessmentRequest.getFirstName());
    restAssessmentRequest.setLastName(compositeAssessmentRequest.getLastName());
    restAssessmentRequest.setStudyProgramme(compositeAssessmentRequest.getStudyProgramme());
    restAssessmentRequest.setWorkspaceEntityId(workspaceEntity == null ? null : workspaceEntity.getId());
    restAssessmentRequest.setWorkspaceName(compositeAssessmentRequest.getCourseName());
    restAssessmentRequest.setWorkspaceNameExtension(compositeAssessmentRequest.getCourseNameExtension());
    restAssessmentRequest.setWorkspaceUrlName(workspaceEntity == null ? null : workspaceEntity.getUrlName());
    return restAssessmentRequest;
}
Also used : ArrayList(java.util.ArrayList) RestAssessmentRequest(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessmentRequest) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Date(java.util.Date) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) SupplementationRequest(fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest) RestSupplementationRequest(fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestSupplementationRequest) WorkspaceMaterialReplyState(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReplyState)

Example 28 with WorkspaceMaterial

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.

the class DeusNexMachinaController method postProcessHtml.

private void postProcessHtml(HtmlMaterial material) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException, TransformerException {
    StringReader htmlReader = new StringReader(material.getHtml());
    DOMParser parser = new DOMParser(new HTMLConfiguration());
    parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
    InputSource inputSource = new InputSource(htmlReader);
    parser.parse(inputSource);
    org.w3c.dom.Document domDocument = parser.getDocument();
    boolean modified = false;
    // Embedded YouTube clips; strip protocol
    List<Element> elements = DeusNexXmlUtils.getElementsByXPath(domDocument.getDocumentElement(), "//iframe");
    if (!elements.isEmpty()) {
        for (Element element : elements) {
            String src = element.getAttribute("src");
            if (src != null && src.startsWith("http://www.youtube.com/")) {
                element.setAttribute("src", src.substring(5));
                modified = true;
            }
        }
    }
    // Embedded documents; add data attributes and determine correct material title
    elements = DeusNexXmlUtils.getElementsByXPath(domDocument.getDocumentElement(), "//iframe[@data-type=\"embedded-document\"]");
    if (!elements.isEmpty()) {
        modified = true;
        for (Element element : elements) {
            Integer resourceNo = Integer.valueOf(element.getAttribute("data-resource-no"));
            WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(getResourceWorkspaceNodeId(resourceNo));
            HtmlMaterial htmlMaterial = htmlMaterialController.findHtmlMaterialById(workspaceMaterial.getMaterialId());
            // If a header precedes an embedded document, use its text as the embedded
            // document's title and remove it from the parent document altogether
            Node possibleHeaderNode = getPreviousSiblingElement(element);
            if (isHeader(possibleHeaderNode)) {
                String headerText = StringUtils.trim(possibleHeaderNode.getTextContent());
                if (!StringUtils.isBlank(headerText)) {
                    htmlMaterialController.updateHtmlMaterialTitle(htmlMaterial, headerText);
                    possibleHeaderNode.getParentNode().removeChild(possibleHeaderNode);
                }
            }
            element.setAttribute("data-material-id", String.valueOf(htmlMaterial.getId()));
            element.setAttribute("data-material-type", htmlMaterial.getType());
            element.setAttribute("data-workspace-material-id", String.valueOf(workspaceMaterial.getId()));
        }
    }
    // Update to post-processed version, if applicable
    if (modified) {
        StringWriter writer = new StringWriter();
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        transformer.setOutputProperty(OutputKeys.INDENT, "no");
        transformer.transform(new DOMSource(domDocument), new StreamResult(writer));
        htmlMaterialController.updateHtmlMaterialHtml(material, writer.getBuffer().toString());
    }
}
Also used : InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) HTMLConfiguration(org.cyberneko.html.HTMLConfiguration) Element(org.w3c.dom.Element) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) Node(org.w3c.dom.Node) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) DOMParser(org.apache.xerces.parsers.DOMParser) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)

Example 29 with WorkspaceMaterial

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.

the class DeusNexMachinaController method importResource.

private void importResource(WorkspaceNode importRoot, WorkspaceNode parent, Resource resource, DeusNexDocument deusNexDocument, List<WorkspaceNode> createdNodes) throws DeusNexException {
    WorkspaceNode node = findNode(parent, resource);
    if (resource.getType() == Type.FOLDER) {
        Folder folderResource = (Folder) resource;
        WorkspaceFolder folder = null;
        if (node instanceof WorkspaceFolder) {
            folder = (WorkspaceFolder) node;
        }
        if (folder == null) {
            folder = createFolder(parent, folderResource);
            try {
                setResourceWorkspaceNodeId(resource.getNo(), folder.getId());
            } catch (IOException e) {
                throw new DeusNexInternalException("Failed to store resourceNo lookup file", e);
            }
            createdNodes.add(folder);
        }
        for (Resource childResource : folderResource.getResources()) {
            importResource(importRoot, folder, childResource, deusNexDocument, createdNodes);
        }
    } else {
        if (node == null) {
            logger.fine("importing " + resource.getPath());
            Material material = createMaterial(importRoot, resource, deusNexDocument);
            if (material != null) {
                WorkspaceMaterialAssignmentType assignmentType = null;
                if (resource instanceof Query) {
                    switch(((Query) resource).getQueryType()) {
                        case "1":
                            assignmentType = WorkspaceMaterialAssignmentType.EXERCISE;
                            break;
                        case "2":
                            assignmentType = WorkspaceMaterialAssignmentType.EVALUATED;
                            break;
                    }
                } else if (material instanceof HtmlMaterial) {
                    assignmentType = determineEmbeddedAssignmentType((HtmlMaterial) material);
                }
                WorkspaceMaterial workspaceMaterial = workspaceMaterialController.createWorkspaceMaterial(parent, material, resource.getName(), assignmentType, WorkspaceMaterialCorrectAnswersDisplay.ALWAYS);
                try {
                    setResourceWorkspaceNodeId(resource.getNo(), workspaceMaterial.getId());
                } catch (IOException e) {
                    throw new DeusNexInternalException("Failed to store resourceNo lookup file", e);
                }
                if (resource instanceof ResourceContainer) {
                    List<Resource> childResources = ((ResourceContainer) resource).getResources();
                    if (childResources != null) {
                        for (Resource childResource : childResources) {
                            importResource(importRoot, workspaceMaterial, childResource, deusNexDocument, createdNodes);
                        }
                    }
                }
                if (resource.getHidden()) {
                    workspaceMaterialController.hideWorkspaceNode(workspaceMaterial);
                }
                createdNodes.add(workspaceMaterial);
            }
        } else {
            logger.info(node.getPath() + " already exists, skipping");
        }
    }
}
Also used : Query(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Query) DeusNexInternalException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException) Resource(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource) Material(fi.otavanopisto.muikku.plugins.material.model.Material) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) BinaryMaterial(fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) IOException(java.io.IOException) WorkspaceMaterialAssignmentType(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialAssignmentType) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) Folder(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Folder) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) ResourceContainer(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.ResourceContainer)

Example 30 with WorkspaceMaterial

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.

the class DeusNexMachinaController method postProcessResources.

private void postProcessResources(List<WorkspaceNode> createdNodes) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException, TransformerException {
    for (WorkspaceNode node : createdNodes) {
        if (node.getType() == WorkspaceNodeType.MATERIAL) {
            WorkspaceMaterial workspaceMaterial = (WorkspaceMaterial) node;
            HtmlMaterial htmlMaterial = htmlMaterialController.findHtmlMaterialById(workspaceMaterial.getMaterialId());
            if (htmlMaterial != null && StringUtils.isNotBlank(htmlMaterial.getHtml())) {
                postProcessHtml(htmlMaterial);
            }
        }
    }
}
Also used : HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)

Aggregations

WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)66 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)24 Path (javax.ws.rs.Path)24 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)18 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)17 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)16 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)15 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)14 WorkspaceRootFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)14 GET (javax.ws.rs.GET)14 Material (fi.otavanopisto.muikku.plugins.material.model.Material)13 ArrayList (java.util.ArrayList)11 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)7 WorkspaceMaterialEvaluation (fi.otavanopisto.muikku.plugins.evaluation.model.WorkspaceMaterialEvaluation)6 BinaryMaterial (fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)6 WorkspaceFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)6 WorkspaceMaterialReply (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReply)6 POST (javax.ws.rs.POST)6 SupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.model.SupplementationRequest)5 RestSupplementationRequest (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestSupplementationRequest)5