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