Search in sources :

Example 1 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class AssessmentRequestRESTService method createAssessmentRequest.

@POST
@Path("/workspace/{WORKSPACEENTITYID}/assessmentRequests")
@RESTPermitUnimplemented
public Response createAssessmentRequest(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, AssessmentRequestRESTModel newAssessmentRequest) {
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.UNAUTHORIZED).build();
    }
    WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserIdentifier(workspaceEntity, sessionController.getLoggedUser());
    try {
        WorkspaceAssessmentRequest assessmentRequest = assessmentRequestController.createWorkspaceAssessmentRequest(workspaceUserEntity, newAssessmentRequest.getRequestText());
        communicatorAssessmentRequestController.sendAssessmentRequestMessage(assessmentRequest);
        return Response.ok(restModel(assessmentRequest)).build();
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Couldn't create workspace assessment request.", e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceAssessmentRequest(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)

Example 2 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class CalendarRESTService method getEvents.

@GET
@Path("/calendars/{CALID}/events/")
@RESTPermitUnimplemented
public Response getEvents(@PathParam("CALID") Long calendarId, @QueryParam("timeMin") DateTimeParameter timeMin, @QueryParam("timeMax") DateTimeParameter timeMax) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Response.Status.FORBIDDEN).build();
    }
    if (calendarId == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    UserCalendar userCalendar = calendarController.findUserCalendar(calendarId);
    if (userCalendar == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    if (!userCalendar.getUserId().equals(sessionController.getLoggedUserEntity().getId())) {
        return Response.status(Response.Status.FORBIDDEN).build();
    }
    try {
        List<CalendarEvent> result = new ArrayList<>();
        List<fi.otavanopisto.muikku.calendar.CalendarEvent> calendarEvents = calendarController.listCalendarEvents(userCalendar, timeMin != null ? timeMin.getDateTime() : null, timeMax != null ? timeMax.getDateTime() : null);
        for (fi.otavanopisto.muikku.calendar.CalendarEvent calendarEvent : calendarEvents) {
            result.add(createEventRestModel(userCalendar, calendarEvent));
        }
        return Response.ok(result).build();
    } catch (CalendarServiceException e) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
}
Also used : CalendarServiceException(fi.otavanopisto.muikku.calendar.CalendarServiceException) ArrayList(java.util.ArrayList) DefaultCalendarEvent(fi.otavanopisto.muikku.calendar.DefaultCalendarEvent) CalendarEvent(fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEvent) UserCalendar(fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 3 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class CoursePickerRESTService method getWorkspace.

@GET
@Path("/workspaces/{ID}")
@RESTPermitUnimplemented
public Response getWorkspace(@PathParam("ID") Long workspaceEntityId) {
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    Workspace workspace = null;
    schoolDataBridgeSessionController.startSystemSession();
    try {
        workspace = workspaceController.findWorkspace(workspaceEntity);
    } finally {
        schoolDataBridgeSessionController.endSystemSession();
    }
    if (workspace == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    boolean canSignup = getCanSignup(workspaceEntity);
    boolean isCourseMember = getIsAlreadyOnWorkspace(workspaceEntity);
    String educationTypeName = null;
    if (workspace.getWorkspaceTypeId() != null) {
        EducationType educationType = courseMetaController.findEducationType(workspace.getWorkspaceTypeId());
        if (educationType != null) {
            educationTypeName = educationType.getName();
        }
    }
    return Response.ok(createRestModel(workspaceEntity, workspace.getName(), workspace.getNameExtension(), workspace.getDescription(), educationTypeName, canSignup, isCourseMember)).build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) EducationType(fi.otavanopisto.muikku.schooldata.entity.EducationType) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 4 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class UserRESTService method searchUsers.

@GET
@Path("/users")
@RESTPermitUnimplemented
public Response searchUsers(@QueryParam("searchString") String searchString, @QueryParam("firstResult") @DefaultValue("0") Integer firstResult, @QueryParam("maxResults") @DefaultValue("10") Integer maxResults, @QueryParam("userGroupIds") List<Long> userGroupIds, @QueryParam("myUserGroups") Boolean myUserGroups, @QueryParam("workspaceIds") List<Long> workspaceIds, @QueryParam("myWorkspaces") Boolean myWorkspaces, @QueryParam("archetype") String archetype, @DefaultValue("false") @QueryParam("onlyDefaultUsers") Boolean onlyDefaultUsers) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Status.FORBIDDEN).build();
    }
    if (CollectionUtils.isNotEmpty(userGroupIds) && Boolean.TRUE.equals(myUserGroups))
        return Response.status(Status.BAD_REQUEST).build();
    if (CollectionUtils.isNotEmpty(workspaceIds) && Boolean.TRUE.equals(myWorkspaces))
        return Response.status(Status.BAD_REQUEST).build();
    UserEntity loggedUser = sessionController.getLoggedUserEntity();
    EnvironmentRoleArchetype roleArchetype = archetype != null ? EnvironmentRoleArchetype.valueOf(archetype) : null;
    Set<Long> userGroupFilters = null;
    Set<Long> workspaceFilters = null;
    if (!sessionController.hasEnvironmentPermission(RoleFeatures.ACCESS_ONLY_GROUP_STUDENTS)) {
        if ((myUserGroups != null) && myUserGroups) {
            userGroupFilters = new HashSet<Long>();
            // Groups where user is a member
            List<UserGroupEntity> userGroups = userGroupEntityController.listUserGroupsByUserIdentifier(sessionController.getLoggedUser());
            for (UserGroupEntity userGroup : userGroups) {
                userGroupFilters.add(userGroup.getId());
            }
        } else if (!CollectionUtils.isEmpty(userGroupIds)) {
            userGroupFilters = new HashSet<Long>();
            // Defined user groups
            userGroupFilters.addAll(userGroupIds);
        }
    } else {
        // User can only list users from his/her own user groups
        userGroupFilters = new HashSet<Long>();
        // Groups where user is a member and the ids of the groups
        List<UserGroupEntity> userGroups = userGroupEntityController.listUserGroupsByUserIdentifier(sessionController.getLoggedUser());
        Set<Long> accessibleUserGroupEntityIds = userGroups.stream().map(UserGroupEntity::getId).collect(Collectors.toSet());
        if (CollectionUtils.isNotEmpty(userGroupIds)) {
            // if there are specified user groups, they need to be subset of the groups that the user can access
            if (!CollectionUtils.isSubCollection(userGroupIds, accessibleUserGroupEntityIds))
                return Response.status(Status.BAD_REQUEST).build();
            userGroupFilters.addAll(userGroupIds);
        } else {
            userGroupFilters.addAll(accessibleUserGroupEntityIds);
        }
    }
    if ((myWorkspaces != null) && myWorkspaces) {
        // Workspaces where user is a member
        List<WorkspaceEntity> workspaces = workspaceUserEntityController.listWorkspaceEntitiesByUserEntity(loggedUser);
        Set<Long> myWorkspaceIds = new HashSet<Long>();
        for (WorkspaceEntity ws : workspaces) myWorkspaceIds.add(ws.getId());
        workspaceFilters = new HashSet<Long>(myWorkspaceIds);
    } else if (!CollectionUtils.isEmpty(workspaceIds)) {
        // Defined workspaces
        workspaceFilters = new HashSet<Long>(workspaceIds);
    }
    SearchProvider elasticSearchProvider = getProvider("elastic-search");
    if (elasticSearchProvider != null) {
        String[] fields = new String[] { "firstName", "lastName", "nickName", "email" };
        SearchResult result = elasticSearchProvider.searchUsers(searchString, fields, roleArchetype != null ? Arrays.asList(roleArchetype) : null, userGroupFilters, workspaceFilters, null, false, false, onlyDefaultUsers, firstResult, maxResults);
        List<Map<String, Object>> results = result.getResults();
        boolean hasImage = false;
        List<fi.otavanopisto.muikku.rest.model.User> ret = new ArrayList<fi.otavanopisto.muikku.rest.model.User>();
        if (!results.isEmpty()) {
            for (Map<String, Object> o : results) {
                String[] id = ((String) o.get("id")).split("/", 2);
                UserEntity userEntity = userEntityController.findUserEntityByDataSourceAndIdentifier(id[1], id[0]);
                if (userEntity != null) {
                    String emailAddress = userEmailEntityController.getUserDefaultEmailAddress(userEntity, true);
                    Date studyStartDate = getDateResult(o.get("studyStartDate"));
                    Date studyTimeEnd = getDateResult(o.get("studyTimeEnd"));
                    ret.add(new fi.otavanopisto.muikku.rest.model.User(userEntity.getId(), (String) o.get("firstName"), (String) o.get("lastName"), (String) o.get("nickName"), hasImage, (String) o.get("nationality"), (String) o.get("language"), (String) o.get("municipality"), (String) o.get("school"), emailAddress, studyStartDate, studyTimeEnd));
                }
            }
            return Response.ok(ret).build();
        } else
            return Response.noContent().build();
    }
    return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
Also used : User(fi.otavanopisto.muikku.schooldata.entity.User) EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) EnvironmentRoleArchetype(fi.otavanopisto.muikku.model.users.EnvironmentRoleArchetype) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) SearchProvider(fi.otavanopisto.muikku.search.SearchProvider) SearchResult(fi.otavanopisto.muikku.search.SearchResult) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Date(java.util.Date) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Map(java.util.Map) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 5 with RESTPermitUnimplemented

use of fi.otavanopisto.muikku.rest.RESTPermitUnimplemented in project muikku by otavanopisto.

the class WorkspaceRESTService method listWorkspaceMaterials.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/materials/")
@RESTPermitUnimplemented
public Response listWorkspaceMaterials(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @QueryParam("parentId") Long parentId, @QueryParam("assignmentType") String assignmentType) {
    if (parentId == null && assignmentType == null) {
        return Response.status(Status.NOT_IMPLEMENTED).entity("Listing workspace materials without parentId or assignmentType is currently not implemented").build();
    }
    WorkspaceMaterialAssignmentType workspaceAssignmentType = null;
    if (assignmentType != null) {
        workspaceAssignmentType = WorkspaceMaterialAssignmentType.valueOf(assignmentType);
        if (workspaceAssignmentType == null) {
            return Response.status(Status.BAD_REQUEST).entity("Invalid assignmentType parameter").build();
        }
    }
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity("Could not find a workspace entity").build();
    }
    List<WorkspaceMaterial> workspaceMaterials = null;
    if (parentId != null) {
        WorkspaceNode parent = workspaceMaterialController.findWorkspaceNodeById(parentId);
        if (parent == null) {
            return Response.status(Status.BAD_REQUEST).entity("Given workspace parent material does not exist").build();
        }
        WorkspaceRootFolder rootFolder = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceNode(parent);
        if (rootFolder == null) {
            return Response.status(Status.BAD_REQUEST).entity("Could not find a workspace root folder").build();
        }
        if (!rootFolder.getWorkspaceEntityId().equals(workspaceEntityId)) {
            return Response.status(Status.BAD_REQUEST).entity("Invalid parentId").build();
        }
        if (assignmentType != null) {
            workspaceMaterials = workspaceMaterialController.listWorkspaceMaterialsByParentAndAssignmentType(parent, workspaceEntity, workspaceAssignmentType, BooleanPredicate.IGNORE);
            workspaceMaterials.removeIf(material -> isHiddenMaterial(material));
        } else {
            workspaceMaterials = workspaceMaterialController.listWorkspaceMaterialsByParent(parent);
        }
    } else {
        workspaceMaterials = workspaceMaterialController.listWorkspaceMaterialsByAssignmentType(workspaceEntity, workspaceAssignmentType, BooleanPredicate.IGNORE);
        workspaceMaterials.removeIf(material -> isHiddenMaterial(material));
    }
    if (workspaceMaterials.isEmpty()) {
        return Response.noContent().build();
    }
    return Response.ok(createRestModel(workspaceMaterials.toArray(new WorkspaceMaterial[0]))).build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceMaterialAssignmentType(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialAssignmentType) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Aggregations

RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)40 Path (javax.ws.rs.Path)40 GET (javax.ws.rs.GET)23 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)20 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)13 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)10 POST (javax.ws.rs.POST)8 Material (fi.otavanopisto.muikku.plugins.material.model.Material)7 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)7 ArrayList (java.util.ArrayList)7 PUT (javax.ws.rs.PUT)6 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)5 WorkspaceRootFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder)5 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)5 Produces (javax.ws.rs.Produces)5 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)4 MaterialMetaKey (fi.otavanopisto.muikku.plugins.material.model.MaterialMetaKey)4 User (fi.otavanopisto.muikku.schooldata.entity.User)4 CacheControl (javax.ws.rs.core.CacheControl)4 EntityTag (javax.ws.rs.core.EntityTag)4