use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode 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);
}
}
}
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode 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.WorkspaceNode 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);
}
}
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode in project muikku by otavanopisto.
the class WorkspaceRESTService method createWorkspaceFolder.
@POST
@Path("/workspaces/{WORKSPACEID}/folders/")
@RESTPermitUnimplemented
public Response createWorkspaceFolder(@PathParam("WORKSPACEID") Long workspaceEntityId, fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceFolder restFolder) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).entity("Not logged in").build();
}
if (restFolder == null) {
return Response.status(Status.BAD_REQUEST).build();
}
// Workspace
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.BAD_REQUEST).build();
}
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_MATERIALS, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
WorkspaceNode rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
WorkspaceNode nextSibling = restFolder.getNextSiblingId() == null ? null : workspaceMaterialController.findWorkspaceNodeById(restFolder.getNextSiblingId());
WorkspaceFolder workspaceFolder = workspaceMaterialController.createWorkspaceFolder(rootFolder, "Untitled");
if (nextSibling != null) {
workspaceMaterialController.moveAbove(workspaceFolder, nextSibling);
}
return Response.ok(createRestModel(workspaceFolder)).build();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode in project muikku by otavanopisto.
the class DeusNexMachinaRESTService method cleanWorkspaceMaterials.
@GET
@Path("/cleanworkspacematerials/{ID}")
@RESTPermit(DeusNexMachinaPermissions.CLEAN_WORKSPACE_MATERIALS)
public Response cleanWorkspaceMaterials(@PathParam("ID") Long workspaceEntityId, @Context Request request) {
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity != null) {
WorkspaceNode rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
try {
List<WorkspaceNode> nodes = workspaceMaterialController.listWorkspaceNodesByParent(rootFolder);
cleanMaterials(nodes);
} catch (Exception e) {
logger.log(Level.SEVERE, "Cleaning materials of workspace " + workspaceEntityId + " failed", e);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
} else {
return Response.status(Status.NOT_FOUND).entity("Unknown workspace " + workspaceEntityId).build();
}
return Response.status(Status.OK).entity("Workspace " + workspaceEntityId + " materials successfully cleaned").build();
}
Aggregations