use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceMaterialController method createContentNode.
private ContentNode createContentNode(WorkspaceNode rootMaterialNode, int level, boolean processHtml, boolean includeHidden) throws WorkspaceMaterialException {
boolean viewRestricted = false;
try {
switch(rootMaterialNode.getType()) {
case FOLDER:
WorkspaceFolder workspaceFolder = (WorkspaceFolder) rootMaterialNode;
viewRestricted = !sessionController.isLoggedIn() && workspaceFolder.getViewRestrict() == MaterialViewRestrict.LOGGED_IN;
ContentNode folderContentNode = new ContentNode(workspaceFolder.getTitle(), "folder", rootMaterialNode.getId(), null, level, null, null, rootMaterialNode.getParent().getId(), rootMaterialNode.getHidden(), null, 0l, 0l, workspaceFolder.getPath(), null, null, workspaceFolder.getViewRestrict(), viewRestricted);
List<WorkspaceNode> children = includeHidden ? workspaceNodeDAO.listByParentSortByOrderNumber(workspaceFolder) : workspaceNodeDAO.listByParentAndHiddenSortByOrderNumber(workspaceFolder, Boolean.FALSE);
List<FlattenedWorkspaceNode> flattenedChildren;
if (level >= FLATTENING_LEVEL) {
flattenedChildren = flattenWorkspaceNodes(children, level, includeHidden);
} else {
flattenedChildren = new ArrayList<>();
for (WorkspaceNode node : children) {
flattenedChildren.add(new FlattenedWorkspaceNode(false, null, node, level, node.getParent().getId(), node.getHidden()));
}
}
for (FlattenedWorkspaceNode child : flattenedChildren) {
ContentNode contentNode;
if (child.isEmptyFolder) {
contentNode = new ContentNode(child.emptyFolderTitle, "folder", rootMaterialNode.getId(), null, child.level, null, null, child.parentId, child.hidden, null, 0l, 0l, child.node.getPath(), null, null, MaterialViewRestrict.NONE, false);
} else {
contentNode = createContentNode(child.node, child.level, processHtml, includeHidden);
}
folderContentNode.addChild(contentNode);
}
return folderContentNode;
case MATERIAL:
DOMParser parser = null;
Transformer transformer = null;
if (processHtml) {
parser = new DOMParser(new HTMLConfiguration());
parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "no");
}
WorkspaceMaterial workspaceMaterial = (WorkspaceMaterial) rootMaterialNode;
Material material = materialController.findMaterialById(workspaceMaterial.getMaterialId());
Long currentRevision = material instanceof HtmlMaterial ? htmlMaterialController.lastHtmlMaterialRevision((HtmlMaterial) material) : 0l;
Long publishedRevision = material instanceof HtmlMaterial ? ((HtmlMaterial) material).getRevisionNumber() : 0l;
List<String> producerNames = null;
String html;
List<MaterialProducer> producers = materialController.listMaterialProducers(material);
if ((producers != null) && !producers.isEmpty()) {
producerNames = new ArrayList<>();
for (MaterialProducer producer : producers) {
producerNames.add(StringUtils.replace(StringEscapeUtils.escapeHtml4(producer.getName()), ",", ","));
}
}
viewRestricted = !sessionController.isLoggedIn() && material.getViewRestrict() == MaterialViewRestrict.LOGGED_IN;
if (!viewRestricted) {
html = processHtml ? getMaterialHtml(material, parser, transformer) : null;
} else {
html = String.format("<p class=\"content-view-restricted-message\">%s</p>", localeController.getText(sessionController.getLocale(), "plugin.workspace.materialViewRestricted"));
}
return new ContentNode(workspaceMaterial.getTitle(), material.getType(), rootMaterialNode.getId(), material.getId(), level, workspaceMaterial.getAssignmentType(), workspaceMaterial.getCorrectAnswers(), workspaceMaterial.getParent().getId(), workspaceMaterial.getHidden(), html, currentRevision, publishedRevision, workspaceMaterial.getPath(), material.getLicense(), StringUtils.join(producerNames, ','), material.getViewRestrict(), viewRestricted);
default:
return null;
}
} catch (SAXNotRecognizedException | SAXNotSupportedException | TransformerConfigurationException e) {
throw new WorkspaceMaterialException(e);
}
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceFolderDAO method listByHiddenAndParentAndFolderType.
public List<WorkspaceFolder> listByHiddenAndParentAndFolderType(BooleanPredicate hidden, WorkspaceNode parent, WorkspaceFolderType folderType) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceFolder> criteria = criteriaBuilder.createQuery(WorkspaceFolder.class);
Root<WorkspaceFolder> root = criteria.from(WorkspaceFolder.class);
criteria.select(root);
List<Predicate> predicates = new ArrayList<>();
predicates.add(criteriaBuilder.equal(root.get(WorkspaceFolder_.parent), parent));
predicates.add(criteriaBuilder.equal(root.get(WorkspaceFolder_.folderType), folderType));
if (hidden != BooleanPredicate.IGNORE) {
predicates.add(criteriaBuilder.equal(root.get(WorkspaceFolder_.hidden), hidden.asBoolean()));
}
criteria.where(criteriaBuilder.and(predicates.toArray(new Predicate[0])));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder 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.WorkspaceFolder in project muikku by otavanopisto.
the class DeusNexMachinaController method importHelpPageDocument.
public void importHelpPageDocument(WorkspaceEntity workspaceEntity, InputStream inputStream) throws DeusNexException {
DeusNexDocument deusNexDocument = parseDeusNexDocument(inputStream);
List<Resource> resources = deusNexDocument.getRootFolder().getResources();
if (!resources.isEmpty()) {
List<WorkspaceNode> createdNodes = new ArrayList<>();
WorkspaceFolder workspaceHelpPageFolder = workspaceMaterialController.createWorkspaceHelpPageFolder(workspaceEntity);
for (Resource resource : deusNexDocument.getRootFolder().getResources()) {
importResource(workspaceHelpPageFolder, workspaceHelpPageFolder, resource, deusNexDocument, createdNodes);
}
try {
postProcessResources(createdNodes);
} catch (Exception e) {
throw new DeusNexInternalException("PostProcesssing failed. ", e);
}
}
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class DeusNexMachinaController method importFrontPageDocument.
public void importFrontPageDocument(WorkspaceEntity workspaceEntity, InputStream inputStream) throws DeusNexException {
DeusNexDocument deusNexDocument = parseDeusNexDocument(inputStream);
List<Resource> resources = deusNexDocument.getRootFolder().getResources();
if (!resources.isEmpty()) {
List<WorkspaceNode> createdNodes = new ArrayList<>();
WorkspaceFolder workspaceFrontPageFolder = workspaceMaterialController.createWorkspaceFrontPageFolder(workspaceEntity);
for (Resource resource : deusNexDocument.getRootFolder().getResources()) {
importResource(workspaceFrontPageFolder, workspaceFrontPageFolder, resource, deusNexDocument, createdNodes);
}
try {
postProcessResources(createdNodes);
} catch (Exception e) {
throw new DeusNexInternalException("PostProcesssing failed. ", e);
}
}
}
Aggregations