use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceMaterialUploadBackingBean method upload.
public String upload() {
ObjectMapper objectMapper = new ObjectMapper();
if (!sessionController.isLoggedIn()) {
return "/error/internal-error.jsf";
}
// Workspace
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return "/error/internal-error.jsf";
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserIdentifier(workspaceEntity, sessionController.getLoggedUser());
if (workspaceUserEntity == null || workspaceUserEntity.getWorkspaceUserRole() == null || workspaceUserEntity.getWorkspaceUserRole().getArchetype() != WorkspaceRoleArchetype.TEACHER) {
return "/error/internal-error.jsf";
}
WorkspaceNode parent = null;
if (getFolderId() != null) {
WorkspaceFolder workspaceFolder = workspaceMaterialController.findWorkspaceFolderById(getFolderId());
if (workspaceFolder == null) {
return "/error/internal-error.jsf";
}
WorkspaceRootFolder workspaceRootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceNode(workspaceFolder);
if (workspaceRootFolder == null) {
return "/error/internal-error.jsf";
}
if (!workspaceRootFolder.getWorkspaceEntityId().equals(workspaceEntityId)) {
return "/error/internal-error.jsf";
}
} else {
parent = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
}
try {
FileMeta[] fileMetas = objectMapper.readValue(getUploadMeta(), FileMeta[].class);
for (FileMeta fileMeta : fileMetas) {
String fileId = fileMeta.getId();
try {
String contentType = fileMeta.getContentType();
String fileName = fileMeta.getName();
byte[] fileData = TempFileUtils.getTempFileData(fileId);
String license = null;
BinaryMaterial binaryMaterial = binaryMaterialController.createBinaryMaterial(fileName, contentType, fileData, license);
workspaceMaterialController.createWorkspaceMaterial(parent, binaryMaterial);
} finally {
TempFileUtils.deleteTempFile(fileId);
}
}
} catch (IOException e) {
logger.log(Level.SEVERE, "File uploading filed", e);
return "/error/internal-error.jsf";
}
return null;
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceFolderDAO method create.
public WorkspaceFolder create(WorkspaceNode parent, String title, String urlName, Integer orderNumber, Boolean hidden, WorkspaceFolderType folderType, MaterialViewRestrict viewRestrict) {
WorkspaceFolder workspaceFolder = new WorkspaceFolder();
workspaceFolder.setParent(parent);
workspaceFolder.setUrlName(urlName);
workspaceFolder.setFolderType(folderType);
workspaceFolder.setTitle(title);
workspaceFolder.setOrderNumber(orderNumber);
workspaceFolder.setHidden(hidden);
workspaceFolder.setViewRestrict(viewRestrict);
return persist(workspaceFolder);
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceFolderDAO method listByParentAndFolderType.
public List<WorkspaceFolder> listByParentAndFolderType(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);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceFolder_.parent), parent), criteriaBuilder.equal(root.get(WorkspaceFolder_.folderType), folderType)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class AcceptanceTestsRESTService method createWorkspaceMaterial.
@POST
@Path("/workspaces/{WORKSPACEENTITYID}/folders")
@RESTPermit(handling = Handling.UNSECURED)
public Response createWorkspaceMaterial(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, fi.otavanopisto.muikku.atests.WorkspaceFolder payload) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).entity("Workspace entity not found").build();
}
WorkspaceNode parentNode = null;
if (payload.getParentId() != null) {
parentNode = workspaceMaterialController.findWorkspaceNodeById(payload.getParentId());
if (parentNode == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid parentId").build();
}
} else {
parentNode = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
if (parentNode == null) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity("Could not find workspace root entity").build();
}
}
WorkspaceFolder workspaceFolder = workspaceMaterialController.createWorkspaceFolder(parentNode, payload.getTitle());
if (workspaceFolder == null) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity("Could not create workspace folder").build();
}
return Response.ok(createRestEntity(workspaceFolder)).build();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder in project muikku by otavanopisto.
the class WorkspaceRESTService method deleteWorkspaceFolder.
@DELETE
@Path("/workspaces/{WORKSPACEID}/folders/{WORKSPACEFOLDERID}")
@RESTPermitUnimplemented
public Response deleteWorkspaceFolder(@PathParam("WORKSPACEID") Long workspaceEntityId, @PathParam("WORKSPACEFOLDERID") Long workspaceFolderId) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).entity("Not logged in").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(workspaceFolderId);
if (workspaceFolder != null) {
workspaceMaterialController.deleteWorkspaceFolder(workspaceFolder);
}
return Response.ok(createRestModel(workspaceFolder)).build();
}
Aggregations