use of fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Query 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.dnm.parser.structure.model.Query in project muikku by otavanopisto.
the class DeusNexStructureParser method parseQueryDocument.
private Query parseQueryDocument(Element resourceElement) throws DeusNexSyntaxException, XPathExpressionException, DeusNexInternalException {
Element documentElement = (Element) DeusNexXmlUtils.findNodeByXPath(resourceElement, "styledocument");
List<Resource> embeddedElements = new ArrayList<>();
if (documentElement == null) {
logger.severe("Missing data/document node");
return null;
}
List<Element> embeddedResourceElements = DeusNexXmlUtils.getElementsByXPath(resourceElement, "embedded/res");
for (Element embeddedResourceElement : embeddedResourceElements) {
Resource resource = parseResource(embeddedResourceElement);
if (resource != null) {
embeddedElements.add(resource);
}
}
Query query = new Query();
parseBasicResourceProperties(resourceElement, query);
query.setDocument(documentElement);
query.setResources(embeddedElements);
query.setQueryIdType(DeusNexXmlUtils.getChildValue(resourceElement, "queryIdType"));
query.setQueryStorageType(DeusNexXmlUtils.getChildValue(resourceElement, "queryStorageType"));
query.setQueryState(DeusNexXmlUtils.getChildValue(resourceElement, "queryState"));
query.setQueryType(DeusNexXmlUtils.getChildValue(resourceElement, "queryType"));
return query;
}
use of fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Query in project muikku by otavanopisto.
the class DeusNexStructureParser method parseFCKQuery.
private Query parseFCKQuery(Element resourceElement) throws DeusNexSyntaxException, XPathExpressionException, DeusNexInternalException {
Element documentElement = (Element) DeusNexXmlUtils.findNodeByXPath(resourceElement, "document");
if (documentElement == null) {
logger.severe("Missing data/document node");
return null;
}
List<Resource> embeddedElements = new ArrayList<>();
List<Element> embeddedResourceElements = DeusNexXmlUtils.getElementsByXPath(resourceElement, "embedded/res");
for (Element embeddedResourceElement : embeddedResourceElements) {
Resource resource = parseResource(embeddedResourceElement);
if (resource != null) {
embeddedElements.add(resource);
}
}
Query query = new Query();
parseBasicResourceProperties(resourceElement, query);
query.setDocument(documentElement);
query.setResources(embeddedElements);
query.setQueryIdType(DeusNexXmlUtils.getChildValue(resourceElement, "queryIdType"));
query.setQueryStorageType(DeusNexXmlUtils.getChildValue(resourceElement, "queryStorageType"));
query.setQueryState(DeusNexXmlUtils.getChildValue(resourceElement, "queryState"));
query.setQueryType(DeusNexXmlUtils.getChildValue(resourceElement, "queryType"));
return query;
}
Aggregations