use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.
the class WorkspaceMaterialDAO method countByHiddenAndAssignmentTypeAndParents.
public Long countByHiddenAndAssignmentTypeAndParents(Boolean hidden, WorkspaceMaterialAssignmentType assignmentType, List<WorkspaceNode> parents) {
if (parents == null || parents.isEmpty()) {
return 0L;
}
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
Root<WorkspaceMaterial> root = criteria.from(WorkspaceMaterial.class);
criteria.select(criteriaBuilder.count(root));
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceMaterial_.hidden), hidden), criteriaBuilder.equal(root.get(WorkspaceMaterial_.assignmentType), assignmentType), root.get(WorkspaceMaterial_.parent).in(parents)));
return entityManager.createQuery(criteria).getSingleResult();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.
the class WorkspaceMaterialDAO method listByHiddenAndAssignmentTypeAndParents.
public List<WorkspaceMaterial> listByHiddenAndAssignmentTypeAndParents(BooleanPredicate hidden, WorkspaceMaterialAssignmentType assignmentType, List<WorkspaceNode> parents) {
if (parents == null || parents.isEmpty()) {
return Collections.emptyList();
}
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceMaterial> criteria = criteriaBuilder.createQuery(WorkspaceMaterial.class);
Root<WorkspaceMaterial> root = criteria.from(WorkspaceMaterial.class);
criteria.select(root);
List<Predicate> predicates = new ArrayList<>();
predicates.add(criteriaBuilder.equal(root.get(WorkspaceMaterial_.assignmentType), assignmentType));
predicates.add(root.get(WorkspaceMaterial_.parent).in(parents));
if (hidden != BooleanPredicate.IGNORE) {
predicates.add(criteriaBuilder.equal(root.get(WorkspaceMaterial_.hidden), hidden.asBoolean()));
}
criteria.where(criteriaBuilder.and(predicates.toArray(new Predicate[0])));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.
the class MaterialRESTService method createRestModel.
private fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceMaterial createRestModel(WorkspaceMaterial workspaceMaterial) {
WorkspaceNode workspaceNode = workspaceMaterialController.findWorkspaceNodeNextSibling(workspaceMaterial);
Long nextSiblingId = workspaceNode != null ? workspaceNode.getId() : null;
return new fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceMaterial(workspaceMaterial.getId(), workspaceMaterial.getMaterialId(), workspaceMaterial.getParent() != null ? workspaceMaterial.getParent().getId() : null, nextSiblingId, workspaceMaterial.getHidden(), workspaceMaterial.getAssignmentType(), workspaceMaterial.getCorrectAnswers(), workspaceMaterial.getPath(), workspaceMaterial.getTitle());
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.
the class MaterialRESTService method listMaterialWorkspaceMaterials.
@GET
// @Path("/material/{ID:[0-9]*}/workspaceMaterials/")
@Path("/material/{ID}/workspaceMaterials/")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listMaterialWorkspaceMaterials(@PathParam("ID") Long materialId) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.LIST_MATERIAL_WORKSPACE_MATERIALS)) {
return Response.status(Status.FORBIDDEN).build();
}
Material material = materialController.findMaterialById(materialId);
if (material == null) {
return Response.status(Status.NOT_FOUND).entity("Material not found").build();
}
List<WorkspaceMaterial> workspaceMaterials = workspaceMaterialController.listWorkspaceMaterialsByMaterial(material);
return Response.ok(createRestModel(workspaceMaterials.toArray(new WorkspaceMaterial[0]))).build();
}
use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial in project muikku by otavanopisto.
the class Evaluation2RESTService method createWorkspaceMaterialAssessment.
@POST
@Path("/workspace/{WORKSPACEENTITYID}/user/{USERENTITYID}/workspacematerial/{WORKSPACEMATERIALID}/assessment")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createWorkspaceMaterialAssessment(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("USERENTITYID") Long userEntityId, @PathParam("WORKSPACEMATERIALID") Long workspaceMaterialId, RestAssessment payload) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.ACCESS_EVALUATION)) {
return Response.status(Status.FORBIDDEN).build();
}
// User entity
UserEntity userEntity = userEntityController.findUserEntityById(userEntityId);
if (userEntity == null) {
return Response.status(Status.BAD_REQUEST).build();
}
// Workspace material
WorkspaceMaterial workspaceMaterial = workspaceMaterialController.findWorkspaceMaterialById(workspaceMaterialId);
if (workspaceMaterial == null) {
return Response.status(Status.BAD_REQUEST).build();
}
// Workspace material evaluation
WorkspaceMaterialEvaluation workspaceMaterialEvaluation = evaluationController.findWorkspaceMaterialEvaluationByWorkspaceMaterialAndStudent(workspaceMaterial, userEntity);
// Grade
SchoolDataIdentifier gradingScaleIdentifier = SchoolDataIdentifier.fromId(payload.getGradingScaleIdentifier());
GradingScale gradingScale = gradingController.findGradingScale(gradingScaleIdentifier);
SchoolDataIdentifier gradeIdentifier = SchoolDataIdentifier.fromId(payload.getGradeIdentifier());
GradingScaleItem gradingScaleItem = gradingController.findGradingScaleItem(gradingScale, gradeIdentifier);
// Assessor
SchoolDataIdentifier assessorIdentifier = SchoolDataIdentifier.fromId(payload.getAssessorIdentifier());
User assessingUser = userController.findUserByIdentifier(assessorIdentifier);
UserEntity assessor = userEntityController.findUserEntityByUser(assessingUser);
if (workspaceMaterialEvaluation == null) {
workspaceMaterialEvaluation = evaluationController.createWorkspaceMaterialEvaluation(userEntity, workspaceMaterial, gradingScale, gradingScaleItem, assessor, payload.getAssessmentDate(), payload.getVerbalAssessment());
} else {
workspaceMaterialEvaluation = evaluationController.updateWorkspaceMaterialEvaluation(workspaceMaterialEvaluation, gradingScale, gradingScaleItem, assessor, payload.getAssessmentDate(), payload.getVerbalAssessment());
}
// Remove possible workspace assignment supplementation request
SupplementationRequest supplementationRequest = evaluationController.findSupplementationRequestByStudentAndWorkspaceMaterialAndArchived(userEntityId, workspaceMaterialId, Boolean.FALSE);
if (supplementationRequest != null) {
evaluationController.deleteSupplementationRequest(supplementationRequest);
}
// WorkspaceMaterialEvaluation to RestAssessment
RestAssessment restAssessment = new RestAssessment(workspaceMaterialEvaluation.getId().toString(), assessorIdentifier.toId(), gradingScaleIdentifier.toId(), gradeIdentifier.toId(), workspaceMaterialEvaluation.getVerbalAssessment(), workspaceMaterialEvaluation.getEvaluated(), gradingScaleItem.isPassingGrade());
return Response.ok(restAssessment).build();
}
Aggregations