Search in sources :

Example 1 with FlagStudent

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();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) FlagStudent(fi.otavanopisto.muikku.model.users.FlagStudent) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 2 with FlagStudent

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) EntityManager(javax.persistence.EntityManager) FlagStudent(fi.otavanopisto.muikku.model.users.FlagStudent)

Example 3 with FlagStudent

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) FlagStudent(fi.otavanopisto.muikku.model.users.FlagStudent)

Example 4 with FlagStudent

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

Example 5 with FlagStudent

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);
    }
}
Also used : UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) FlagStudent(fi.otavanopisto.muikku.model.users.FlagStudent)

Aggregations

FlagStudent (fi.otavanopisto.muikku.model.users.FlagStudent)12 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)6 EntityManager (javax.persistence.EntityManager)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)3 Path (javax.ws.rs.Path)3 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)2 DELETE (javax.ws.rs.DELETE)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GET (javax.ws.rs.GET)1