use of fi.otavanopisto.muikku.model.users.FlagStudent in project muikku by otavanopisto.
the class UserRESTService method listStudentFlags.
@GET
@Path("/students/{ID}/flags")
@RESTPermit(handling = Handling.INLINE)
public Response listStudentFlags(@Context Request request, @PathParam("ID") String id, @QueryParam("ownerIdentifier") String ownerId) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.FORBIDDEN).build();
}
SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(id);
if (studentIdentifier == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Invalid studentIdentifier %s", id)).build();
}
if (StringUtils.isBlank(ownerId)) {
return Response.status(Response.Status.NOT_IMPLEMENTED).entity("Listing student flags without owner is not implemented").build();
}
SchoolDataIdentifier ownerIdentifier = SchoolDataIdentifier.fromId(ownerId);
if (ownerIdentifier == null) {
return Response.status(Status.BAD_REQUEST).entity("ownerIdentifier is malformed").build();
}
if (!ownerIdentifier.equals(sessionController.getLoggedUser())) {
return Response.status(Status.FORBIDDEN).build();
}
List<FlagStudent> flags = flagController.listByOwnedAndSharedStudentFlags(studentIdentifier, ownerIdentifier);
return Response.ok(createRestModel(flags.toArray(new FlagStudent[0]))).build();
}
use of fi.otavanopisto.muikku.model.users.FlagStudent in project muikku by otavanopisto.
the class FlagStudentDAO method listStudentIdentifiersByFlags.
public List<UserSchoolDataIdentifier> listStudentIdentifiersByFlags(List<Flag> flags) {
if ((flags == null) || flags.isEmpty()) {
return Collections.emptyList();
}
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserSchoolDataIdentifier> criteria = criteriaBuilder.createQuery(UserSchoolDataIdentifier.class);
Root<FlagStudent> root = criteria.from(FlagStudent.class);
criteria.select(root.get(FlagStudent_.studentIdentifier));
criteria.where(root.get(FlagStudent_.flag).in(flags));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.model.users.FlagStudent in project muikku by otavanopisto.
the class FlagStudentDAO method listByFlag.
public List<FlagStudent> listByFlag(Flag flag) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<FlagStudent> criteria = criteriaBuilder.createQuery(FlagStudent.class);
Root<FlagStudent> root = criteria.from(FlagStudent.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(FlagStudent_.flag), flag));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.model.users.FlagStudent in project muikku by otavanopisto.
the class FlagStudentDAO method create.
public FlagStudent create(Flag flag, UserSchoolDataIdentifier studentIdentifier, Date created) {
FlagStudent flagShare = new FlagStudent();
flagShare.setFlag(flag);
flagShare.setStudentIdentifier(studentIdentifier);
flagShare.setCreated(created);
return persist(flagShare);
}
use of fi.otavanopisto.muikku.model.users.FlagStudent in project muikku by otavanopisto.
the class FlagController method unflagStudent.
public void unflagStudent(Flag flag, SchoolDataIdentifier studentIdentifier) {
UserSchoolDataIdentifier studentSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierBySchoolDataIdentifier(studentIdentifier);
if (studentSchoolDataIdentifier == null) {
logger.severe(String.format("Could not find school data user by identifier %s", studentIdentifier));
return;
}
FlagStudent flagStudent = flagStudentDAO.findByFlagAndStudentIdentifier(flag, studentSchoolDataIdentifier);
if (flagStudent != null) {
unflagStudent(flagStudent);
}
}
Aggregations