use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder 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.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceMaterialController method ensureWorkspaceHelpPageExists.
public WorkspaceMaterial ensureWorkspaceHelpPageExists(WorkspaceEntity workspace) {
WorkspaceFolder helpPageFolder = findWorkspaceHelpPageFolder(workspace);
if (helpPageFolder == null) {
helpPageFolder = createWorkspaceHelpPageFolder(workspace);
}
WorkspaceMaterial helpPageMaterial = null;
List<WorkspaceMaterial> helpPageMaterials = listWorkspaceMaterialsByParent(helpPageFolder);
if (helpPageMaterials.isEmpty()) {
String title = localeController.getText(sessionController.getLocale(), "plugin.workspace.helpPage.title");
String license = null;
HtmlMaterial htmlMaterial = htmlMaterialController.createHtmlMaterial(title, "", "text/html", 0l, license);
helpPageMaterial = createWorkspaceMaterial(helpPageFolder, htmlMaterial);
} else {
helpPageMaterial = helpPageMaterials.get(0);
}
return helpPageMaterial;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceMaterialController method appendChildFolders.
private void appendChildFolders(WorkspaceNode parent, List<WorkspaceNode> result, BooleanPredicate hidden) {
List<WorkspaceFolder> childFolders = workspaceFolderDAO.listByHiddenAndParentAndFolderType(hidden, parent, WorkspaceFolderType.DEFAULT);
result.addAll(childFolders);
for (WorkspaceFolder childFolder : childFolders) {
appendChildFolders(childFolder, result, hidden);
}
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceMaterialController method ensureWorkspaceFrontPageExists.
public WorkspaceMaterial ensureWorkspaceFrontPageExists(WorkspaceEntity workspace) {
WorkspaceFolder frontPageFolder = findWorkspaceFrontPageFolder(workspace);
if (frontPageFolder == null) {
frontPageFolder = createWorkspaceFrontPageFolder(workspace);
}
WorkspaceMaterial frontPageMaterial = null;
List<WorkspaceMaterial> frontPageMaterials = listWorkspaceMaterialsByParent(frontPageFolder);
if (frontPageMaterials.isEmpty()) {
String title = localeController.getText(sessionController.getLocale(), "plugin.workspace.frontPage.title");
String license = null;
HtmlMaterial htmlMaterial = htmlMaterialController.createHtmlMaterial(title, "", "text/html", 0l, license);
frontPageMaterial = createWorkspaceMaterial(frontPageFolder, htmlMaterial);
} else {
frontPageMaterial = frontPageMaterials.get(0);
}
return frontPageMaterial;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceMaterialController method deleteWorkspaceMaterial.
public void deleteWorkspaceMaterial(WorkspaceMaterial workspaceMaterial, boolean removeAnswers) throws WorkspaceMaterialContainsAnswersExeption {
try {
workspaceMaterialDeleteEvent.fire(new WorkspaceMaterialDeleteEvent(workspaceMaterial, removeAnswers));
List<WorkspaceNode> childNodes = workspaceNodeDAO.listByParentSortByOrderNumber(workspaceMaterial);
for (WorkspaceNode childNode : childNodes) {
if (childNode instanceof WorkspaceMaterial) {
deleteWorkspaceMaterial((WorkspaceMaterial) childNode, removeAnswers);
} else if (childNode instanceof WorkspaceFolder) {
deleteWorkspaceFolder((WorkspaceFolder) childNode);
}
}
} catch (Exception e) {
Throwable cause = e;
while (cause != null) {
cause = cause.getCause();
if (cause instanceof WorkspaceMaterialContainsAnswersExeption) {
throw (WorkspaceMaterialContainsAnswersExeption) cause;
}
}
throw e;
}
workspaceMaterialDAO.delete(workspaceMaterial);
}
Aggregations