Search in sources :

Example 1 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class UserRESTService method createStudentFlag.

@POST
@Path("/students/{ID}/flags")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createStudentFlag(@Context Request request, @PathParam("ID") String id, fi.otavanopisto.muikku.rest.model.StudentFlag payload) {
    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 (payload.getFlagId() == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Missing flagId").build();
    }
    Flag flag = flagController.findFlagById(payload.getFlagId());
    if (flag == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Flag #%d not found", payload.getFlagId())).build();
    }
    if (!flagController.hasFlagPermission(flag, sessionController.getLoggedUser())) {
        return Response.status(Status.FORBIDDEN).entity(String.format("You do not have permission to flag students to flag %d", payload.getFlagId())).build();
    }
    return Response.ok(createRestModel(flagController.flagStudent(flag, studentIdentifier))).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) Flag(fi.otavanopisto.muikku.model.users.Flag) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 2 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class UserRESTService method searchStudentTransferCredits.

@GET
@Path("/students/{ID}/transferCredits")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response searchStudentTransferCredits(@PathParam("ID") String id, @QueryParam("curriculumEmpty") @DefaultValue("true") Boolean curriculumEmpty, @QueryParam("curriculumIdentifier") String curriculumIdentifier) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(id);
    if (studentIdentifier == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Invalid studentIdentifier %s", id)).build();
    }
    UserEntity studentEntity = userEntityController.findUserEntityByUserIdentifier(studentIdentifier);
    if (studentEntity == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Could not find user entity for identifier %s", id)).build();
    }
    if (!studentEntity.getId().equals(sessionController.getLoggedUserEntity().getId())) {
        if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.LIST_STUDENT_TRANSFER_CREDITS)) {
            return Response.status(Status.FORBIDDEN).build();
        }
    }
    List<TransferCredit> transferCredits = new ArrayList<TransferCredit>(gradingController.listStudentTransferCredits(studentIdentifier));
    for (int i = transferCredits.size() - 1; i >= 0; i--) {
        TransferCredit tc = transferCredits.get(i);
        SchoolDataIdentifier tcCurriculum = tc.getCurriculumIdentifier();
        if (tcCurriculum != null) {
            if (!StringUtils.isEmpty(curriculumIdentifier) && !Objects.equals(tcCurriculum.toId(), curriculumIdentifier)) {
                transferCredits.remove(i);
            }
        } else {
            if (!curriculumEmpty)
                transferCredits.remove(i);
        }
    }
    return Response.ok(createRestModel(transferCredits.toArray(new TransferCredit[0]))).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) ArrayList(java.util.ArrayList) TransferCredit(fi.otavanopisto.muikku.schooldata.entity.TransferCredit) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 3 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier 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 4 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class UserRESTService method listStudentPhoneNumbers.

@GET
@Path("/students/{ID}/phoneNumbers")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listStudentPhoneNumbers(@PathParam("ID") String id) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(id);
    if (studentIdentifier == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Invalid studentIdentifier %s", id)).build();
    }
    UserEntity studentEntity = userEntityController.findUserEntityByUserIdentifier(studentIdentifier);
    if (studentEntity == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Could not find user entity for identifier %s", id)).build();
    }
    if (!studentEntity.getId().equals(sessionController.getLoggedUserEntity().getId())) {
        if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.LIST_STUDENT_PHONE_NUMBERS)) {
            return Response.status(Status.FORBIDDEN).build();
        }
    }
    List<UserPhoneNumber> phoneNumbers = userController.listUserPhoneNumbers(studentIdentifier);
    Collections.sort(phoneNumbers, new Comparator<UserPhoneNumber>() {

        @Override
        public int compare(UserPhoneNumber o1, UserPhoneNumber o2) {
            return o1.getDefaultNumber() ? -1 : o2.getDefaultNumber() ? 1 : 0;
        }
    });
    return Response.ok(createRestModel(phoneNumbers.toArray(new UserPhoneNumber[0]))).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserPhoneNumber(fi.otavanopisto.muikku.schooldata.entity.UserPhoneNumber) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 5 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class UserRESTService method createFlag.

@POST
@Path("/flags/")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createFlag(fi.otavanopisto.muikku.rest.model.Flag payload) {
    if (StringUtils.isBlank(payload.getOwnerIdentifier())) {
        return Response.status(Status.BAD_REQUEST).entity("ownerIdentifier is missing").build();
    }
    if (StringUtils.isBlank(payload.getColor())) {
        return Response.status(Status.BAD_REQUEST).entity("color is missing").build();
    }
    if (StringUtils.isBlank(payload.getName())) {
        return Response.status(Status.BAD_REQUEST).entity("name is missing").build();
    }
    SchoolDataIdentifier ownerIdentifier = SchoolDataIdentifier.fromId(payload.getOwnerIdentifier());
    if (ownerIdentifier == null) {
        return Response.status(Status.BAD_REQUEST).entity("ownerIdentifier is malformed").build();
    }
    Flag flag = flagController.createFlag(ownerIdentifier, payload.getName(), payload.getColor(), payload.getDescription());
    return Response.ok(createRestModel(flag)).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) Flag(fi.otavanopisto.muikku.model.users.Flag) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Aggregations

SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)130 Path (javax.ws.rs.Path)63 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)59 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)58 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)53 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)50 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)48 ArrayList (java.util.ArrayList)38 GET (javax.ws.rs.GET)36 User (fi.otavanopisto.muikku.schooldata.entity.User)30 HashMap (java.util.HashMap)19 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)13 SearchResult (fi.otavanopisto.muikku.search.SearchResult)13 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)12 Date (java.util.Date)11 POST (javax.ws.rs.POST)11 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)10 WorkspaceAssessment (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment)10 HashSet (java.util.HashSet)9 PUT (javax.ws.rs.PUT)9