Search in sources :

Example 16 with WorkspaceFolder

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;
}
Also used : WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) BinaryMaterial(fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)

Example 17 with WorkspaceFolder

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);
}
Also used : WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)

Example 18 with 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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)

Example 19 with WorkspaceFolder

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();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 20 with WorkspaceFolder

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();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)

Aggregations

WorkspaceFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)20 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)11 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)6 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)6 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)5 IOException (java.io.IOException)5 Path (javax.ws.rs.Path)5 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)4 ArrayList (java.util.ArrayList)4 DeusNexInternalException (fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException)3 Resource (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource)3 Material (fi.otavanopisto.muikku.plugins.material.model.Material)3 TransformerException (javax.xml.transform.TransformerException)3 XPathExpressionException (javax.xml.xpath.XPathExpressionException)3 SAXException (org.xml.sax.SAXException)3 DeusNexException (fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexException)2 DeusNexDocument (fi.otavanopisto.muikku.plugins.dnm.parser.structure.DeusNexDocument)2 BinaryMaterial (fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)2 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2