use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceRESTService method getWorkspaceFolder.
@GET
@Path("/workspaces/{WORKSPACEID}/folders/{WORKSPACEFOLDERID}")
@RESTPermitUnimplemented
public Response getWorkspaceFolder(@PathParam("WORKSPACEID") Long workspaceEntityId, @PathParam("WORKSPACEFOLDERID") Long workspaceFolderId) {
// Workspace
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
// WorkspaceFolder
WorkspaceFolder workspaceFolder = workspaceMaterialController.findWorkspaceFolderById(workspaceFolderId);
if (workspaceFolder == null) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok(createRestModel(workspaceFolder)).build();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceRESTService method updateWorkspaceFolder.
@PUT
@Path("/workspaces/{WORKSPACEID}/folders/{WORKSPACEFOLDERID}")
@RESTPermitUnimplemented
public Response updateWorkspaceFolder(@PathParam("WORKSPACEID") Long workspaceEntityId, @PathParam("WORKSPACEFOLDERID") Long workspaceFolderId, 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();
}
// WorkspaceFolder
WorkspaceFolder workspaceFolder = workspaceMaterialController.findWorkspaceFolderById(restFolder.getId());
if (workspaceFolder == null) {
return Response.status(Status.BAD_REQUEST).build();
}
// Workspace folder belongs to workspace check
Long folderWorkspaceEntityId = workspaceMaterialController.getWorkspaceEntityId(workspaceFolder);
if (!folderWorkspaceEntityId.equals(workspaceEntityId)) {
return Response.status(Status.BAD_REQUEST).build();
}
// Actual update
WorkspaceNode parentNode = restFolder.getParentId() == null ? null : workspaceMaterialController.findWorkspaceNodeById(restFolder.getParentId());
WorkspaceNode nextSibling = restFolder.getNextSiblingId() == null ? null : workspaceMaterialController.findWorkspaceNodeById(restFolder.getNextSiblingId());
Boolean hidden = restFolder.getHidden();
String title = restFolder.getTitle();
MaterialViewRestrict viewRestrict = restFolder.getViewRestrict();
workspaceFolder = workspaceMaterialController.updateWorkspaceFolder(workspaceFolder, title, parentNode, nextSibling, hidden, viewRestrict);
return Response.ok(createRestModel(workspaceFolder)).build();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceMaterialController method cloneWorkspaceNode.
private WorkspaceNode cloneWorkspaceNode(WorkspaceNode workspaceNode, WorkspaceNode parent, boolean cloneMaterials, boolean overrideCloneMaterials) {
WorkspaceNode newNode;
boolean isHtmlMaterial = false;
Integer index = workspaceNodeDAO.getMaximumOrderNumber(parent);
index = index == null ? 0 : ++index;
if (workspaceNode instanceof WorkspaceMaterial) {
WorkspaceMaterial workspaceMaterial = (WorkspaceMaterial) workspaceNode;
Material material = getMaterialForWorkspaceMaterial(workspaceMaterial);
isHtmlMaterial = material instanceof HtmlMaterial;
Material clonedMaterial = cloneMaterials && !overrideCloneMaterials ? materialController.cloneMaterial(material) : material;
// Implementation of feature #1232 (front and help pages should always be copies)
if (isHtmlMaterial && !cloneMaterials) {
WorkspaceNode parentNode = workspaceMaterial.getParent();
if (parentNode instanceof WorkspaceFolder) {
WorkspaceFolder parentFolder = (WorkspaceFolder) parentNode;
if (parentFolder.getFolderType() == WorkspaceFolderType.FRONT_PAGE || parentFolder.getFolderType() == WorkspaceFolderType.HELP_PAGE) {
clonedMaterial = materialController.cloneMaterial(material);
}
}
}
newNode = createWorkspaceMaterial(parent, clonedMaterial, workspaceMaterial.getTitle(), generateUniqueUrlName(parent, workspaceMaterial.getUrlName()), index, workspaceMaterial.getHidden(), workspaceMaterial.getAssignmentType(), workspaceMaterial.getCorrectAnswers());
} else if (workspaceNode instanceof WorkspaceFolder) {
newNode = createWorkspaceFolder(parent, ((WorkspaceFolder) workspaceNode).getTitle(), generateUniqueUrlName(parent, workspaceNode.getUrlName()), index, workspaceNode.getHidden(), ((WorkspaceFolder) workspaceNode).getFolderType(), ((WorkspaceFolder) workspaceNode).getViewRestrict());
} else {
throw new IllegalArgumentException("Uncloneable workspace node " + workspaceNode.getClass());
}
List<WorkspaceNode> childNodes = workspaceNodeDAO.listByParentSortByOrderNumber(workspaceNode);
for (WorkspaceNode childNode : childNodes) {
cloneWorkspaceNode(childNode, newNode, cloneMaterials, isHtmlMaterial);
}
return newNode;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceMaterialController method flattenWorkspaceNodes.
public List<FlattenedWorkspaceNode> flattenWorkspaceNodes(List<WorkspaceNode> workspaceNodes, int level, boolean includeHidden) {
List<FlattenedWorkspaceNode> result = new ArrayList<>();
for (WorkspaceNode workspaceNode : workspaceNodes) {
if (workspaceNode.getType() == WorkspaceNodeType.FOLDER) {
WorkspaceFolder workspaceFolder = (WorkspaceFolder) workspaceNode;
List<WorkspaceNode> children = includeHidden ? workspaceNodeDAO.listByParentSortByOrderNumber(workspaceFolder) : workspaceNodeDAO.listByParentAndHiddenSortByOrderNumber(workspaceFolder, Boolean.FALSE);
result.add(new FlattenedWorkspaceNode(true, workspaceFolder.getTitle(), workspaceFolder, level, workspaceFolder.getParent().getId(), workspaceFolder.getHidden()));
result.addAll(flattenWorkspaceNodes(children, level + 1, includeHidden));
} else {
result.add(new FlattenedWorkspaceNode(false, null, workspaceNode, level, workspaceNode.getParent().getId(), workspaceNode.getHidden()));
}
}
return result;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceMaterialController method createWorkspaceFolder.
public WorkspaceFolder createWorkspaceFolder(WorkspaceNode parent, String title, String urlName, Integer index, Boolean hidden, WorkspaceFolderType folderType, MaterialViewRestrict viewRestrict) {
WorkspaceFolder workspaceFolder = workspaceFolderDAO.create(parent, title, urlName, index, hidden, folderType, viewRestrict);
workspaceFolderCreateEvent.fire(new WorkspaceFolderCreateEvent(workspaceFolder));
return workspaceFolder;
}
Aggregations