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();
}
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();
}
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();
}
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);
}
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();
}
Aggregations