Search in sources :

Example 1 with WorkspaceMaterialProducer

use of fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer in project muikku by otavanopisto.

the class WorkspaceRESTService method createWorkspace.

@POST
@Path("/workspaces/")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createWorkspace(@QueryParam("sourceWorkspaceIdentifier") String sourceWorkspaceId, @QueryParam("sourceWorkspaceEntityId") Long sourceWorkspaceEntityId, fi.otavanopisto.muikku.plugins.workspace.rest.model.Workspace payload) {
    SchoolDataIdentifier workspaceIdentifier = null;
    if (sourceWorkspaceId != null) {
        workspaceIdentifier = SchoolDataIdentifier.fromId(sourceWorkspaceId);
        if (workspaceIdentifier == null) {
            return Response.status(Status.BAD_REQUEST).entity(String.format("Invalid source workspace identifier %s", sourceWorkspaceId)).build();
        }
    }
    WorkspaceEntity sourceWorkspaceEntity = null;
    if (sourceWorkspaceEntityId != null) {
        sourceWorkspaceEntity = workspaceEntityController.findWorkspaceEntityById(sourceWorkspaceEntityId);
        if (sourceWorkspaceEntity == null) {
            return Response.status(Status.BAD_REQUEST).entity(String.format("Invalid source workspace entity id %d", sourceWorkspaceEntityId)).build();
        }
        workspaceIdentifier = new SchoolDataIdentifier(sourceWorkspaceEntity.getIdentifier(), sourceWorkspaceEntity.getDataSource().getIdentifier());
    }
    if (workspaceIdentifier == null) {
        return Response.status(Status.NOT_IMPLEMENTED).entity("Creating new workspaces without sourceWorkspace is not not implemented yet").build();
    }
    if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.COPY_WORKSPACE)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    if (StringUtils.isBlank(payload.getName())) {
        return Response.status(Status.BAD_REQUEST).entity("Name is required").build();
    }
    Workspace workspace = workspaceController.copyWorkspace(workspaceIdentifier, payload.getName(), payload.getNameExtension(), payload.getDescription());
    if (workspace == null) {
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(String.format("Failed to create copy of workspace %s", sourceWorkspaceId)).build();
    }
    WorkspaceEntity workspaceEntity = findCopiedWorkspaceEntity(workspace);
    if (workspaceEntity == null) {
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(String.format("Failed to create local copy of workspace %s", sourceWorkspaceId)).build();
    }
    // #2599: Also copy workspace default license and producers
    if (sourceWorkspaceEntity != null) {
        workspaceEntityController.updateDefaultMaterialLicense(workspaceEntity, sourceWorkspaceEntity.getDefaultMaterialLicense());
        List<WorkspaceMaterialProducer> workspaceMaterialProducers = workspaceController.listWorkspaceMaterialProducers(sourceWorkspaceEntity);
        for (WorkspaceMaterialProducer workspaceMaterialProducer : workspaceMaterialProducers) {
            workspaceController.createWorkspaceMaterialProducer(workspaceEntity, workspaceMaterialProducer.getName());
        }
    }
    return Response.ok(createRestModel(workspaceEntity, workspace.getName(), workspace.getNameExtension(), workspace.getDescription(), convertWorkspaceCurriculumIds(workspace), workspace.getSubjectIdentifier())).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceMaterialProducer(fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 2 with WorkspaceMaterialProducer

use of fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer in project muikku by otavanopisto.

the class WorkspaceRESTService method deleteWorkspaceMaterialProducer.

@DELETE
@Path("/workspaces/{WORKSPACEENTITYID}/materialProducers/{ID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response deleteWorkspaceMaterialProducer(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("ID") Long workspaceMaterialProducerId) {
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_MATERIAL_PRODUCERS, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    WorkspaceMaterialProducer materialProducer = workspaceController.findWorkspaceMaterialProducer(workspaceMaterialProducerId);
    workspaceController.deleteWorkspaceMaterialProducer(materialProducer);
    return Response.noContent().build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceMaterialProducer(fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 3 with WorkspaceMaterialProducer

use of fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer in project muikku by otavanopisto.

the class AcceptanceTestsRESTService method deleteWorkspace.

@DELETE
@Path("/workspaces/{WORKSPACEENTITYID}")
@RESTPermit(handling = Handling.UNSECURED)
public Response deleteWorkspace(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId) {
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(404).entity("Not found").build();
    }
    try {
        List<WorkspaceMaterialProducer> workspaceMaterialProducers = workspaceController.listWorkspaceMaterialProducers(workspaceEntity);
        for (WorkspaceMaterialProducer workspaceMaterialProducer : workspaceMaterialProducers) {
            workspaceController.deleteWorkspaceMaterialProducer(workspaceMaterialProducer);
        }
    } catch (Exception e) {
        return Response.status(500).entity(e.getMessage()).build();
    }
    try {
        workspaceMaterialController.deleteAllWorkspaceNodes(workspaceEntity);
    } catch (WorkspaceMaterialContainsAnswersExeption e) {
        return Response.status(500).entity(e.getMessage()).build();
    }
    List<WorkspaceUserEntity> workspaceUserEntities = workspaceUserEntityController.listWorkspaceUserEntitiesIncludeArchived(workspaceEntity);
    for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
        workspaceUserEntityController.deleteWorkspaceUserEntity(workspaceUserEntity);
    }
    workspaceEntityController.deleteWorkspaceEntity(workspaceEntity);
    return Response.noContent().build();
}
Also used : WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceMaterialProducer(fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer) WorkspaceMaterialContainsAnswersExeption(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 4 with WorkspaceMaterialProducer

use of fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer in project muikku by otavanopisto.

the class WorkspaceMaterialProducerDAO method create.

public WorkspaceMaterialProducer create(WorkspaceEntity workspaceEntity, String name) {
    WorkspaceMaterialProducer workspaceMaterialProducer = new WorkspaceMaterialProducer();
    workspaceMaterialProducer.setName(name);
    workspaceMaterialProducer.setWorkspaceEntity(workspaceEntity);
    return persist(workspaceMaterialProducer);
}
Also used : WorkspaceMaterialProducer(fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer)

Example 5 with WorkspaceMaterialProducer

use of fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer in project muikku by otavanopisto.

the class WorkspaceMaterialProducerDAO method listByWorkspaceEntity.

public List<WorkspaceMaterialProducer> listByWorkspaceEntity(WorkspaceEntity workspaceEntity) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<WorkspaceMaterialProducer> criteria = criteriaBuilder.createQuery(WorkspaceMaterialProducer.class);
    Root<WorkspaceMaterialProducer> root = criteria.from(WorkspaceMaterialProducer.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.equal(root.get(WorkspaceMaterialProducer_.workspaceEntity), workspaceEntity));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) WorkspaceMaterialProducer(fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer)

Aggregations

WorkspaceMaterialProducer (fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer)6 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)4 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)4 Path (javax.ws.rs.Path)4 DELETE (javax.ws.rs.DELETE)2 POST (javax.ws.rs.POST)2 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 WorkspaceMaterialContainsAnswersExeption (fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption)1 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)1 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)1 EntityManager (javax.persistence.EntityManager)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1