Search in sources :

Example 1 with EducationType

use of fi.otavanopisto.muikku.schooldata.entity.EducationType in project muikku by otavanopisto.

the class WorkspaceIndexBackingBean method init.

@RequestAction
public String init() {
    String urlName = getWorkspaceUrlName();
    if (StringUtils.isBlank(urlName)) {
        return NavigationRules.NOT_FOUND;
    }
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
    if (workspaceEntity == null) {
        return NavigationRules.NOT_FOUND;
    }
    canPublish = sessionController.hasWorkspacePermission(MuikkuPermissions.PUBLISH_WORKSPACE, workspaceEntity);
    workspaceEntityId = workspaceEntity.getId();
    published = workspaceEntity.getPublished();
    if (!published) {
        if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_UNPUBLISHED_WORKSPACE, workspaceEntity)) {
            return NavigationRules.NOT_FOUND;
        }
    }
    try {
        WorkspaceMaterial frontPage = workspaceMaterialController.ensureWorkspaceFrontPageExists(workspaceEntity);
        contentNodes = Arrays.asList(workspaceMaterialController.createContentNode(frontPage));
    } catch (WorkspaceMaterialException e) {
        logger.log(Level.SEVERE, "Error loading materials", e);
        return NavigationRules.INTERNAL_ERROR;
    }
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    schoolDataBridgeSessionController.startSystemSession();
    try {
        Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
        if (workspace == null) {
            logger.warning(String.format("Could not find workspace for workspaceEntity #%d", workspaceEntity.getId()));
            return NavigationRules.NOT_FOUND;
        }
        WorkspaceType workspaceType = workspaceController.findWorkspaceType(workspace.getWorkspaceTypeId());
        EducationType educationTypeObject = workspace.getEducationTypeIdentifier() == null ? null : courseMetaController.findEducationType(workspace.getEducationTypeIdentifier());
        Subject subjectObject = courseMetaController.findSubject(workspace.getSchoolDataSource(), workspace.getSubjectIdentifier());
        CourseLengthUnit lengthUnit = null;
        if ((workspace.getLength() != null) && (workspace.getLengthUnitIdentifier() != null)) {
            lengthUnit = courseMetaController.findCourseLengthUnit(workspace.getSchoolDataSource(), workspace.getLengthUnitIdentifier());
        }
        workspaceId = workspaceEntity.getId();
        workspaceName = workspace.getName();
        workspaceNameExtension = workspace.getNameExtension();
        subject = subjectObject != null ? subjectObject.getName() : null;
        educationType = educationTypeObject != null ? educationTypeObject.getName() : null;
        if (lengthUnit != null) {
            courseLength = workspace.getLength();
            courseLengthSymbol = lengthUnit.getSymbol();
        }
        beginDate = workspace.getBeginDate() != null ? Date.from(workspace.getBeginDate().toInstant()) : null;
        endDate = workspace.getEndDate() != null ? Date.from(workspace.getEndDate().toInstant()) : null;
        if (workspaceType != null) {
            this.workspaceType = workspaceType.getName();
        }
    } finally {
        schoolDataBridgeSessionController.endSystemSession();
    }
    WorkspaceEntityFile customFrontImage = workspaceEntityFileController.findWorkspaceEntityFile(workspaceEntity, "workspace-frontpage-image-cropped");
    hasCustomFrontPageImage = customFrontImage != null;
    customFrontPageImageUrl = hasCustomFrontPageImage ? String.format("/rest/workspace/workspaces/%d/workspacefile/workspace-frontpage-image-cropped", workspaceEntity.getId()) : null;
    materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
    announcementsBaseUrl = String.format("/workspace/%s/announcements", workspaceUrlName);
    workspaceVisitController.visit(workspaceEntity);
    return null;
}
Also used : WorkspaceType(fi.otavanopisto.muikku.schooldata.entity.WorkspaceType) WorkspaceEntityFile(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) EducationType(fi.otavanopisto.muikku.schooldata.entity.EducationType) CourseLengthUnit(fi.otavanopisto.muikku.schooldata.entity.CourseLengthUnit) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) Subject(fi.otavanopisto.muikku.schooldata.entity.Subject) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 2 with EducationType

use of fi.otavanopisto.muikku.schooldata.entity.EducationType 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 3 with EducationType

use of fi.otavanopisto.muikku.schooldata.entity.EducationType in project muikku by otavanopisto.

the class CoursePickerRESTService method listWorkspaces.

@GET
@Path("/workspaces/")
@RESTPermitUnimplemented
public Response listWorkspaces(@QueryParam("search") String searchString, @QueryParam("subjects") List<String> subjects, @QueryParam("educationTypes") List<String> educationTypeIds, @QueryParam("curriculums") List<String> curriculumIds, @QueryParam("minVisits") Long minVisits, @QueryParam("includeUnpublished") @DefaultValue("false") Boolean includeUnpublished, @QueryParam("myWorkspaces") @DefaultValue("false") Boolean myWorkspaces, @QueryParam("orderBy") List<String> orderBy, @QueryParam("firstResult") @DefaultValue("0") Integer firstResult, @QueryParam("maxResults") @DefaultValue("50") Integer maxResults, @Context Request request) {
    List<CoursePickerWorkspace> workspaces = new ArrayList<>();
    boolean doMinVisitFilter = minVisits != null;
    UserEntity userEntity = myWorkspaces ? sessionController.getLoggedUserEntity() : null;
    List<WorkspaceEntity> workspaceEntities = null;
    String schoolDataSourceFilter = null;
    List<String> workspaceIdentifierFilters = null;
    if (doMinVisitFilter) {
        if (userEntity != null) {
            workspaceEntities = workspaceVisitController.listWorkspaceEntitiesByMinVisitsOrderByLastVisit(userEntity, minVisits);
        } else {
            workspaceEntities = workspaceVisitController.listWorkspaceEntitiesByMinVisitsOrderByLastVisit(sessionController.getLoggedUserEntity(), minVisits);
        }
    } else {
        if (userEntity != null) {
            workspaceEntities = workspaceUserEntityController.listActiveWorkspaceEntitiesByUserEntity(userEntity);
        }
    }
    Iterator<SearchProvider> searchProviderIterator = searchProviders.iterator();
    if (searchProviderIterator.hasNext()) {
        SearchProvider searchProvider = searchProviderIterator.next();
        SearchResult searchResult = null;
        if (workspaceEntities != null) {
            workspaceIdentifierFilters = new ArrayList<>();
            for (WorkspaceEntity workspaceEntity : workspaceEntities) {
                if (schoolDataSourceFilter == null) {
                    schoolDataSourceFilter = workspaceEntity.getDataSource().getIdentifier();
                }
                workspaceIdentifierFilters.add(workspaceEntity.getIdentifier());
            }
        }
        List<WorkspaceAccess> accesses = new ArrayList<>(Arrays.asList(WorkspaceAccess.ANYONE));
        if (sessionController.isLoggedIn()) {
            accesses.add(WorkspaceAccess.LOGGED_IN);
            accesses.add(WorkspaceAccess.MEMBERS_ONLY);
        }
        List<Sort> sorts = null;
        if (orderBy != null && orderBy.contains("alphabet")) {
            sorts = new ArrayList<>();
            sorts.add(new Sort("name.untouched", Sort.Order.ASC));
        }
        List<SchoolDataIdentifier> educationTypes = null;
        if (educationTypeIds != null) {
            educationTypes = new ArrayList<>(educationTypeIds.size());
            for (String educationTypeId : educationTypeIds) {
                SchoolDataIdentifier educationTypeIdentifier = SchoolDataIdentifier.fromId(educationTypeId);
                if (educationTypeIdentifier != null) {
                    educationTypes.add(educationTypeIdentifier);
                } else {
                    return Response.status(Status.BAD_REQUEST).entity(String.format("Malformed education type identifier", educationTypeId)).build();
                }
            }
        }
        List<SchoolDataIdentifier> curriculumIdentifiers = null;
        if (curriculumIds != null) {
            curriculumIdentifiers = new ArrayList<>(curriculumIds.size());
            for (String curriculumId : curriculumIds) {
                SchoolDataIdentifier curriculumIdentifier = SchoolDataIdentifier.fromId(curriculumId);
                if (curriculumIdentifier != null) {
                    curriculumIdentifiers.add(curriculumIdentifier);
                } else {
                    return Response.status(Status.BAD_REQUEST).entity(String.format("Malformed curriculum identifier", curriculumId)).build();
                }
            }
        }
        searchResult = searchProvider.searchWorkspaces(schoolDataSourceFilter, subjects, workspaceIdentifierFilters, educationTypes, curriculumIdentifiers, searchString, accesses, sessionController.getLoggedUser(), includeUnpublished, firstResult, maxResults, sorts);
        schoolDataBridgeSessionController.startSystemSession();
        try {
            List<Map<String, Object>> results = searchResult.getResults();
            for (Map<String, Object> result : results) {
                String searchId = (String) result.get("id");
                if (StringUtils.isNotBlank(searchId)) {
                    String[] id = searchId.split("/", 2);
                    if (id.length == 2) {
                        String dataSource = id[1];
                        String identifier = id[0];
                        SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(identifier, dataSource);
                        WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByDataSourceAndIdentifier(workspaceIdentifier.getDataSource(), workspaceIdentifier.getIdentifier());
                        if (workspaceEntity != null) {
                            String name = (String) result.get("name");
                            String nameExtension = (String) result.get("nameExtension");
                            String description = (String) result.get("description");
                            boolean canSignup = getCanSignup(workspaceEntity);
                            boolean isCourseMember = getIsAlreadyOnWorkspace(workspaceEntity);
                            String educationTypeId = (String) result.get("educationTypeIdentifier");
                            String educationTypeName = null;
                            if (StringUtils.isNotBlank(educationTypeId)) {
                                EducationType educationType = null;
                                SchoolDataIdentifier educationTypeIdentifier = SchoolDataIdentifier.fromId(educationTypeId);
                                if (educationTypeIdentifier == null) {
                                    logger.severe(String.format("Malformatted educationTypeIdentifier %s", educationTypeId));
                                } else {
                                    educationType = courseMetaController.findEducationType(educationTypeIdentifier.getDataSource(), educationTypeIdentifier.getIdentifier());
                                }
                                if (educationType != null) {
                                    educationTypeName = educationType.getName();
                                }
                            }
                            if (StringUtils.isNotBlank(name)) {
                                workspaces.add(createRestModel(workspaceEntity, name, nameExtension, description, educationTypeName, canSignup, isCourseMember));
                            } else {
                                logger.severe(String.format("Search index contains workspace %s that does not have a name", workspaceIdentifier));
                            }
                        } else {
                            logger.severe(String.format("Search index contains workspace %s that does not exits on the school data system", workspaceIdentifier));
                        }
                    }
                }
            }
        } finally {
            schoolDataBridgeSessionController.endSystemSession();
        }
    } else {
        return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }
    if (workspaces.isEmpty()) {
        return Response.noContent().build();
    }
    if (orderBy.contains("lastVisit")) {
        Collections.sort(workspaces, new Comparator<CoursePickerWorkspace>() {

            @Override
            public int compare(CoursePickerWorkspace workspace1, CoursePickerWorkspace workspace2) {
                if (workspace1.getLastVisit() == null || workspace2.getLastVisit() == null) {
                    return 0;
                }
                if (workspace1.getLastVisit().before(workspace2.getLastVisit())) {
                    return 1;
                }
                if (workspace1.getLastVisit().after(workspace2.getLastVisit())) {
                    return -1;
                }
                return 0;
            }
        });
    }
    return Response.ok(workspaces).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) EducationType(fi.otavanopisto.muikku.schooldata.entity.EducationType) ArrayList(java.util.ArrayList) Sort(fi.otavanopisto.muikku.search.SearchProvider.Sort) 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) WorkspaceAccess(fi.otavanopisto.muikku.model.workspace.WorkspaceAccess) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Map(java.util.Map) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 4 with EducationType

use of fi.otavanopisto.muikku.schooldata.entity.EducationType in project muikku by otavanopisto.

the class PyramusCourseMetaSchoolDataBridge method listEducationTypes.

@Override
public List<EducationType> listEducationTypes() {
    List<EducationType> result = new ArrayList<>();
    fi.otavanopisto.pyramus.rest.model.EducationType[] types = pyramusClient.get("/common/educationTypes", fi.otavanopisto.pyramus.rest.model.EducationType[].class);
    if (types != null) {
        for (fi.otavanopisto.pyramus.rest.model.EducationType type : types) {
            SchoolDataIdentifier identifier = pyramusIdentifierMapper.getEducationTypeIdentifier(type.getId());
            result.add(new PyramusEducationType(identifier, type.getName()));
        }
    }
    return result;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) PyramusEducationType(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusEducationType) EducationType(fi.otavanopisto.muikku.schooldata.entity.EducationType) PyramusEducationType(fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusEducationType) ArrayList(java.util.ArrayList)

Aggregations

EducationType (fi.otavanopisto.muikku.schooldata.entity.EducationType)4 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)3 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)2 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)2 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)1 WorkspaceAccess (fi.otavanopisto.muikku.model.workspace.WorkspaceAccess)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 PyramusEducationType (fi.otavanopisto.muikku.plugins.schooldatapyramus.entities.PyramusEducationType)1 WorkspaceEntityFile (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile)1 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)1 CourseLengthUnit (fi.otavanopisto.muikku.schooldata.entity.CourseLengthUnit)1 Subject (fi.otavanopisto.muikku.schooldata.entity.Subject)1 WorkspaceType (fi.otavanopisto.muikku.schooldata.entity.WorkspaceType)1 SearchProvider (fi.otavanopisto.muikku.search.SearchProvider)1 Sort (fi.otavanopisto.muikku.search.SearchProvider.Sort)1