Search in sources :

Example 1 with WorkspaceFeeInfo

use of fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceFeeInfo in project muikku by otavanopisto.

the class WorkspaceRESTService method getFeeInfo.

@GET
@Path("/workspaces/{ID}/feeInfo")
@RESTPermit(value = MuikkuPermissions.VIEW_WORKSPACE_FEE, requireLoggedIn = true)
public Response getFeeInfo(@PathParam("ID") Long workspaceEntityId) {
    SchoolDataIdentifier userIdentifier = sessionController.getLoggedUser();
    if (userIdentifier == null) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    User user = userController.findUserByIdentifier(userIdentifier);
    if (user == null) {
        return Response.status(Status.FORBIDDEN).build();
    }
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
    if (workspace == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    // #3069: If the user has evaluation fees and a school set, all workspaces have an
    // evaluation fee. Otherwise it depends on the applicability of the workspace itself.
    boolean evaluationFees = user.hasEvaluationFees() && (StringUtils.isNotEmpty(user.getSchool()) || workspace.isEvaluationFeeApplicable());
    return Response.ok(new WorkspaceFeeInfo(evaluationFees)).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) User(fi.otavanopisto.muikku.schooldata.entity.User) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceFeeInfo(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceFeeInfo) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)1 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)1 WorkspaceFeeInfo (fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceFeeInfo)1 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)1 User (fi.otavanopisto.muikku.schooldata.entity.User)1 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)1 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)1 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1