@Test public void shouldGetCourseSectionMappings() throws SLIClientException, IOException, URISyntaxException { List<GenericEntity> sections = new ArrayList<GenericEntity>(); sections.add(createSection("S1", "CO1", "Section 1")); sections.add(createSection("S2", "CO2", "Section 2")); List<Entity> courseOfferings = new ArrayList<Entity>(); courseOfferings.add(createCourseOffering("CO1", "C1")); courseOfferings.add(createCourseOffering("CO2", "C2")); when(mockSliClient.read("/schools/SCHOOL_ID/courseOfferings/?limit=0")).thenReturn(courseOfferings); when(mockSliClient.read("/educationOrganizations/SCHOOL_ID")) .thenReturn(asList(createEdOrg(SCHOOL_ID, LEA_ID))); when(mockSliClient.read("/educationOrganizations/LEA_ID")).thenReturn(asList(createEdOrg(LEA_ID, SEA_ID))); when(mockSliClient.read("/educationOrganizations/SEA_ID")).thenReturn(asList(createEdOrg(SEA_ID, null))); when(mockSliClient.read("/educationOrganizations/SCHOOL_ID/courses?limit=0")).thenReturn( asList(createCourse("C1", "C1"))); when(mockSliClient.read("/educationOrganizations/LEA_ID/courses?limit=0")).thenReturn( asList(createCourse("C2", "C1"))); List<GenericEntity> result = sdkapiClient.getCourseSectionMappings(sections, SCHOOL_ID, TOKEN); Assert.assertEquals(2, result.size()); }
@Override public List<GenericEntity> getCourseSectionMappings(List<GenericEntity> sections, String schoolId, String token) { Map<String, GenericEntity> courseMap = new HashMap<String, GenericEntity>(); Map<String, String> sectionIDToCourseIDMap = new HashMap<String, String>(); Map<String, Set<GenericEntity>> sectionLookup = new HashMap<String, Set<GenericEntity>>(); if (sections != null) { Map<String, String> courseOfferingToCourseIDMap = new HashMap<String, String>(); String url = ""; if (schoolId != null) { url = SDKConstants.SCHOOLS_ENTITY + schoolId; } List<GenericEntity> courseOfferings = readEntityList(token, url + SDKConstants.COURSE_OFFERINGS + "?" + this.buildQueryString(null)); if (courseOfferings != null) { for (GenericEntity courseOffering : courseOfferings) { String courseOfferingId = (String) courseOffering.get(Constants.ATTR_ID); String courseId = (String) courseOffering.get(Constants.ATTR_COURSE_ID); courseOfferingToCourseIDMap.put(courseOfferingId, courseId); } } for (GenericEntity section : sections) { String courseOfferingId = (String) section.get(Constants.ATTR_COURSE_OFFERING_ID); String courseId = courseOfferingToCourseIDMap.get(courseOfferingId); if (!sectionLookup.containsKey(courseId)) { sectionLookup.put(courseId, new TreeSet<GenericEntity>(new GenericEntityComparator( Constants.ATTR_SECTION_NAME, String.class))); } sectionLookup.get(courseId).add(section); } List<String> edOrgIds = getEdorgHierarchy(schoolId, token); List<GenericEntity> courses = getCoursesForEdorgs(edOrgIds, token); for (GenericEntity course : courses) { Set<GenericEntity> matchedSections = sectionLookup.get(course.getId()); if (matchedSections != null) { courseMap.put(course.getId(), course); Iterator<GenericEntity> sectionEntities = matchedSections.iterator(); while (sectionEntities.hasNext()) { GenericEntity sectionEntity = sectionEntities.next(); course.appendToList(Constants.ATTR_SECTIONS, sectionEntity); sectionIDToCourseIDMap.put(sectionEntity.getId(), course.getId()); } } } } List<GenericEntity> courses = new ArrayList<GenericEntity>(courseMap.values()); Collections.sort(courses, new GenericEntityComparator(Constants.ATTR_COURSE_TITLE, String.class)); return courses; }
SDKAPIClient implements APIClient { @Override public List<GenericEntity> getCourseSectionMappings(List<GenericEntity> sections, String schoolId, String token) { Map<String, GenericEntity> courseMap = new HashMap<String, GenericEntity>(); Map<String, String> sectionIDToCourseIDMap = new HashMap<String, String>(); Map<String, Set<GenericEntity>> sectionLookup = new HashMap<String, Set<GenericEntity>>(); if (sections != null) { Map<String, String> courseOfferingToCourseIDMap = new HashMap<String, String>(); String url = ""; if (schoolId != null) { url = SDKConstants.SCHOOLS_ENTITY + schoolId; } List<GenericEntity> courseOfferings = readEntityList(token, url + SDKConstants.COURSE_OFFERINGS + "?" + this.buildQueryString(null)); if (courseOfferings != null) { for (GenericEntity courseOffering : courseOfferings) { String courseOfferingId = (String) courseOffering.get(Constants.ATTR_ID); String courseId = (String) courseOffering.get(Constants.ATTR_COURSE_ID); courseOfferingToCourseIDMap.put(courseOfferingId, courseId); } } for (GenericEntity section : sections) { String courseOfferingId = (String) section.get(Constants.ATTR_COURSE_OFFERING_ID); String courseId = courseOfferingToCourseIDMap.get(courseOfferingId); if (!sectionLookup.containsKey(courseId)) { sectionLookup.put(courseId, new TreeSet<GenericEntity>(new GenericEntityComparator( Constants.ATTR_SECTION_NAME, String.class))); } sectionLookup.get(courseId).add(section); } List<String> edOrgIds = getEdorgHierarchy(schoolId, token); List<GenericEntity> courses = getCoursesForEdorgs(edOrgIds, token); for (GenericEntity course : courses) { Set<GenericEntity> matchedSections = sectionLookup.get(course.getId()); if (matchedSections != null) { courseMap.put(course.getId(), course); Iterator<GenericEntity> sectionEntities = matchedSections.iterator(); while (sectionEntities.hasNext()) { GenericEntity sectionEntity = sectionEntities.next(); course.appendToList(Constants.ATTR_SECTIONS, sectionEntity); sectionIDToCourseIDMap.put(sectionEntity.getId(), course.getId()); } } } } List<GenericEntity> courses = new ArrayList<GenericEntity>(courseMap.values()); Collections.sort(courses, new GenericEntityComparator(Constants.ATTR_COURSE_TITLE, String.class)); return courses; } }
SDKAPIClient implements APIClient { @Override public List<GenericEntity> getCourseSectionMappings(List<GenericEntity> sections, String schoolId, String token) { Map<String, GenericEntity> courseMap = new HashMap<String, GenericEntity>(); Map<String, String> sectionIDToCourseIDMap = new HashMap<String, String>(); Map<String, Set<GenericEntity>> sectionLookup = new HashMap<String, Set<GenericEntity>>(); if (sections != null) { Map<String, String> courseOfferingToCourseIDMap = new HashMap<String, String>(); String url = ""; if (schoolId != null) { url = SDKConstants.SCHOOLS_ENTITY + schoolId; } List<GenericEntity> courseOfferings = readEntityList(token, url + SDKConstants.COURSE_OFFERINGS + "?" + this.buildQueryString(null)); if (courseOfferings != null) { for (GenericEntity courseOffering : courseOfferings) { String courseOfferingId = (String) courseOffering.get(Constants.ATTR_ID); String courseId = (String) courseOffering.get(Constants.ATTR_COURSE_ID); courseOfferingToCourseIDMap.put(courseOfferingId, courseId); } } for (GenericEntity section : sections) { String courseOfferingId = (String) section.get(Constants.ATTR_COURSE_OFFERING_ID); String courseId = courseOfferingToCourseIDMap.get(courseOfferingId); if (!sectionLookup.containsKey(courseId)) { sectionLookup.put(courseId, new TreeSet<GenericEntity>(new GenericEntityComparator( Constants.ATTR_SECTION_NAME, String.class))); } sectionLookup.get(courseId).add(section); } List<String> edOrgIds = getEdorgHierarchy(schoolId, token); List<GenericEntity> courses = getCoursesForEdorgs(edOrgIds, token); for (GenericEntity course : courses) { Set<GenericEntity> matchedSections = sectionLookup.get(course.getId()); if (matchedSections != null) { courseMap.put(course.getId(), course); Iterator<GenericEntity> sectionEntities = matchedSections.iterator(); while (sectionEntities.hasNext()) { GenericEntity sectionEntity = sectionEntities.next(); course.appendToList(Constants.ATTR_SECTIONS, sectionEntity); sectionIDToCourseIDMap.put(sectionEntity.getId(), course.getId()); } } } } List<GenericEntity> courses = new ArrayList<GenericEntity>(courseMap.values()); Collections.sort(courses, new GenericEntityComparator(Constants.ATTR_COURSE_TITLE, String.class)); return courses; }  }
SDKAPIClient implements APIClient { @Override public List<GenericEntity> getCourseSectionMappings(List<GenericEntity> sections, String schoolId, String token) { Map<String, GenericEntity> courseMap = new HashMap<String, GenericEntity>(); Map<String, String> sectionIDToCourseIDMap = new HashMap<String, String>(); Map<String, Set<GenericEntity>> sectionLookup = new HashMap<String, Set<GenericEntity>>(); if (sections != null) { Map<String, String> courseOfferingToCourseIDMap = new HashMap<String, String>(); String url = ""; if (schoolId != null) { url = SDKConstants.SCHOOLS_ENTITY + schoolId; } List<GenericEntity> courseOfferings = readEntityList(token, url + SDKConstants.COURSE_OFFERINGS + "?" + this.buildQueryString(null)); if (courseOfferings != null) { for (GenericEntity courseOffering : courseOfferings) { String courseOfferingId = (String) courseOffering.get(Constants.ATTR_ID); String courseId = (String) courseOffering.get(Constants.ATTR_COURSE_ID); courseOfferingToCourseIDMap.put(courseOfferingId, courseId); } } for (GenericEntity section : sections) { String courseOfferingId = (String) section.get(Constants.ATTR_COURSE_OFFERING_ID); String courseId = courseOfferingToCourseIDMap.get(courseOfferingId); if (!sectionLookup.containsKey(courseId)) { sectionLookup.put(courseId, new TreeSet<GenericEntity>(new GenericEntityComparator( Constants.ATTR_SECTION_NAME, String.class))); } sectionLookup.get(courseId).add(section); } List<String> edOrgIds = getEdorgHierarchy(schoolId, token); List<GenericEntity> courses = getCoursesForEdorgs(edOrgIds, token); for (GenericEntity course : courses) { Set<GenericEntity> matchedSections = sectionLookup.get(course.getId()); if (matchedSections != null) { courseMap.put(course.getId(), course); Iterator<GenericEntity> sectionEntities = matchedSections.iterator(); while (sectionEntities.hasNext()) { GenericEntity sectionEntity = sectionEntities.next(); course.appendToList(Constants.ATTR_SECTIONS, sectionEntity); sectionIDToCourseIDMap.put(sectionEntity.getId(), course.getId()); } } } } List<GenericEntity> courses = new ArrayList<GenericEntity>(courseMap.values()); Collections.sort(courses, new GenericEntityComparator(Constants.ATTR_COURSE_TITLE, String.class)); return courses; }  SLIClientFactory getClientFactory(); void setClientFactory(SLIClientFactory clientFactory); void setGracePeriod(String gracePeriod); String getGracePeriod(); @Override GenericEntity getEntity(String token, String type, String id, Map<String, String> params); @Override List<GenericEntity> getEntities(String token, String type, String ids, Map<String, String> params); @Override GenericEntity getHome(String token); @Override String getId(String token); @Override ConfigMap getEdOrgCustomData(String token, String id); @Override void putEdOrgCustomData(String token, String id, ConfigMap configMap); @Override List<GenericEntity> getEducationalOrganizations(String token, List<String> ids, Map<String, String> params); @Override List<GenericEntity> getEducationOrganizationsForStaff(String token, String staffId); @Override GenericEntity getEducationalOrganization(String token, String id); @Override GenericEntity getEducationOrganizationForStaff(String token, String staffId, String organizationCategory); @Override List<GenericEntity> getParentEducationalOrganizations(String token,
            List<GenericEntity> educationalOrganizations); @Override GenericEntity getParentEducationalOrganization(String token, GenericEntity educationalOrganization); @Override List<GenericEntity> getSchools(String token, List<String> ids); @Override List<GenericEntity> getMySchools(String token); @Override List<GenericEntity> getSchools(String token, List<String> ids, Map<String, String> params); @Override GenericEntity getSchool(String token, String id); @Override List<GenericEntity> getSessions(String token, String schoolId, Map<String, String> params); @Override List<GenericEntity> getSessions(String token, List<String> ids, Map<String, String> params); @Override List<GenericEntity> getSessionsForYear(String token, String schoolYear); @Override GenericEntity getSession(String token, String id); @Override List<GenericEntity> getSections(String token, Map<String, String> params); @Override List<GenericEntity> getSections(String token, List<String> ids, Map<String, String> params); @Override List<GenericEntity> getSectionsForNonEducator(String token, Map<String, String> params); @Override List<GenericEntity> getSectionsForTeacher(String teacherId, String token, Map<String, String> params); @Override List<GenericEntity> getSectionsForStudent(final String token, final String studentId,
            Map<String, String> params); @Override @CacheableUserData GenericEntity getSection(String token, String id); @Override GenericEntity getSectionHomeForStudent(String token, String studentId); @Override List<GenericEntity> getCourses(String token, List<String> ids, Map<String, String> params); List<GenericEntity> getCourses(String token, List<String> ids); @Override List<GenericEntity> getCoursesForStudent(String token, String studentId, Map<String, String> params); @Override List<GenericEntity> getCoursesSectionsForSchool(String token, String schoolId); @Override List<GenericEntity> getTranscriptsForStudent(String token, String studentId, Map<String, String> params); @Override GenericEntity getCourse(String token, String id); @Override List<GenericEntity> getStaff(String token, List<String> ids, Map<String, String> params); @Override GenericEntity getStaff(String token, String id); @Override GenericEntity getStaffWithEducationOrganization(String token, String id, String organizationCategory); @Override List<GenericEntity> getTeachers(String token, List<String> ids, Map<String, String> params); @Override @CacheableUserData GenericEntity getTeacher(String token, String id); @Override GenericEntity getTeacherWithSections(String token, String id); @Override GenericEntity getTeacherForSection(String token, String sectionId); @Override String getTeacherIdForSection(String token, String sectionId); @Override void getTeacherIdForSections(String token, List<String> sectionIds, Map<String, String> teacherIdCache); @Override List<GenericEntity> getTeachersForSchool(String token, String schoolId); @Override List<GenericEntity> getParentsForStudent(String token, String studentId, Map<String, String> params); @Override List<GenericEntity> getStudentsForSchool(String token, String schoolId, Map<String, String> params); @Override List<GenericEntity> getStudents(String token, Map<String, String> params); @Override List<GenericEntity> getStudents(String token, List<String> ids, Map<String, String> params); @Override List<GenericEntity> getStudentsForSection(String token, String sectionId); @Override List<GenericEntity> getStudentsWithSearch(String token, String firstName, String lastName, String schoolId); @Override List<GenericEntity> searchStudents(String token, String query, Map<String, String> params); @Override List<GenericEntity> getStudentsForSectionWithGradebookEntries(String token, String sectionId); @Override @CacheableUserData GenericEntity getStudent(String token, String id); @Override GenericEntity getStudentWithOptionalFields(String token, String id, List<String> optionalFields); @Override List<GenericEntity> getEnrollmentForStudent(String token, String studentId); @Override List<GenericEntity> getAttendanceForStudent(String token, String studentId, Map<String, String> params); @Override List<GenericEntity> getAcademicRecordsForStudent(String token, String studentId, Map<String, String> params); @Override List<GenericEntity> getAssessments(String token, List<String> ids, Map<String, String> params); @Override List<GenericEntity> getAssessmentsForStudent(String token, String studentId); @Override GenericEntity getAssessment(String token, String id); @Override @ExecutionTimeLogger.LogExecutionTime GenericEntity readEntity(String token, String url); @ExecutionTimeLogger.LogExecutionTime @Override @CacheableUserData List<GenericEntity> readEntityList(String token, String url); @Override List<GenericEntity> readEntityList(String token, List<String> ids, Map<String, String> params, String type); @Override List<GenericEntity> getCourseSectionMappings(List<GenericEntity> sections, String schoolId, String token); SLIClient getClient(String sessionToken); }
SDKAPIClient implements APIClient { @Override public List<GenericEntity> getCourseSectionMappings(List<GenericEntity> sections, String schoolId, String token) { Map<String, GenericEntity> courseMap = new HashMap<String, GenericEntity>(); Map<String, String> sectionIDToCourseIDMap = new HashMap<String, String>(); Map<String, Set<GenericEntity>> sectionLookup = new HashMap<String, Set<GenericEntity>>(); if (sections != null) { Map<String, String> courseOfferingToCourseIDMap = new HashMap<String, String>(); String url = ""; if (schoolId != null) { url = SDKConstants.SCHOOLS_ENTITY + schoolId; } List<GenericEntity> courseOfferings = readEntityList(token, url + SDKConstants.COURSE_OFFERINGS + "?" + this.buildQueryString(null)); if (courseOfferings != null) { for (GenericEntity courseOffering : courseOfferings) { String courseOfferingId = (String) courseOffering.get(Constants.ATTR_ID); String courseId = (String) courseOffering.get(Constants.ATTR_COURSE_ID); courseOfferingToCourseIDMap.put(courseOfferingId, courseId); } } for (GenericEntity section : sections) { String courseOfferingId = (String) section.get(Constants.ATTR_COURSE_OFFERING_ID); String courseId = courseOfferingToCourseIDMap.get(courseOfferingId); if (!sectionLookup.containsKey(courseId)) { sectionLookup.put(courseId, new TreeSet<GenericEntity>(new GenericEntityComparator( Constants.ATTR_SECTION_NAME, String.class))); } sectionLookup.get(courseId).add(section); } List<String> edOrgIds = getEdorgHierarchy(schoolId, token); List<GenericEntity> courses = getCoursesForEdorgs(edOrgIds, token); for (GenericEntity course : courses) { Set<GenericEntity> matchedSections = sectionLookup.get(course.getId()); if (matchedSections != null) { courseMap.put(course.getId(), course); Iterator<GenericEntity> sectionEntities = matchedSections.iterator(); while (sectionEntities.hasNext()) { GenericEntity sectionEntity = sectionEntities.next(); course.appendToList(Constants.ATTR_SECTIONS, sectionEntity); sectionIDToCourseIDMap.put(sectionEntity.getId(), course.getId()); } } } } List<GenericEntity> courses = new ArrayList<GenericEntity>(courseMap.values()); Collections.sort(courses, new GenericEntityComparator(Constants.ATTR_COURSE_TITLE, String.class)); return courses; }  SLIClientFactory getClientFactory(); void setClientFactory(SLIClientFactory clientFactory); void setGracePeriod(String gracePeriod); String getGracePeriod(); @Override GenericEntity getEntity(String token, String type, String id, Map<String, String> params); @Override List<GenericEntity> getEntities(String token, String type, String ids, Map<String, String> params); @Override GenericEntity getHome(String token); @Override String getId(String token); @Override ConfigMap getEdOrgCustomData(String token, String id); @Override void putEdOrgCustomData(String token, String id, ConfigMap configMap); @Override List<GenericEntity> getEducationalOrganizations(String token, List<String> ids, Map<String, String> params); @Override List<GenericEntity> getEducationOrganizationsForStaff(String token, String staffId); @Override GenericEntity getEducationalOrganization(String token, String id); @Override GenericEntity getEducationOrganizationForStaff(String token, String staffId, String organizationCategory); @Override List<GenericEntity> getParentEducationalOrganizations(String token,
            List<GenericEntity> educationalOrganizations); @Override GenericEntity getParentEducationalOrganization(String token, GenericEntity educationalOrganization); @Override List<GenericEntity> getSchools(String token, List<String> ids); @Override List<GenericEntity> getMySchools(String token); @Override List<GenericEntity> getSchools(String token, List<String> ids, Map<String, String> params); @Override GenericEntity getSchool(String token, String id); @Override List<GenericEntity> getSessions(String token, String schoolId, Map<String, String> params); @Override List<GenericEntity> getSessions(String token, List<String> ids, Map<String, String> params); @Override List<GenericEntity> getSessionsForYear(String token, String schoolYear); @Override GenericEntity getSession(String token, String id); @Override List<GenericEntity> getSections(String token, Map<String, String> params); @Override List<GenericEntity> getSections(String token, List<String> ids, Map<String, String> params); @Override List<GenericEntity> getSectionsForNonEducator(String token, Map<String, String> params); @Override List<GenericEntity> getSectionsForTeacher(String teacherId, String token, Map<String, String> params); @Override List<GenericEntity> getSectionsForStudent(final String token, final String studentId,
            Map<String, String> params); @Override @CacheableUserData GenericEntity getSection(String token, String id); @Override GenericEntity getSectionHomeForStudent(String token, String studentId); @Override List<GenericEntity> getCourses(String token, List<String> ids, Map<String, String> params); List<GenericEntity> getCourses(String token, List<String> ids); @Override List<GenericEntity> getCoursesForStudent(String token, String studentId, Map<String, String> params); @Override List<GenericEntity> getCoursesSectionsForSchool(String token, String schoolId); @Override List<GenericEntity> getTranscriptsForStudent(String token, String studentId, Map<String, String> params); @Override GenericEntity getCourse(String token, String id); @Override List<GenericEntity> getStaff(String token, List<String> ids, Map<String, String> params); @Override GenericEntity getStaff(String token, String id); @Override GenericEntity getStaffWithEducationOrganization(String token, String id, String organizationCategory); @Override List<GenericEntity> getTeachers(String token, List<String> ids, Map<String, String> params); @Override @CacheableUserData GenericEntity getTeacher(String token, String id); @Override GenericEntity getTeacherWithSections(String token, String id); @Override GenericEntity getTeacherForSection(String token, String sectionId); @Override String getTeacherIdForSection(String token, String sectionId); @Override void getTeacherIdForSections(String token, List<String> sectionIds, Map<String, String> teacherIdCache); @Override List<GenericEntity> getTeachersForSchool(String token, String schoolId); @Override List<GenericEntity> getParentsForStudent(String token, String studentId, Map<String, String> params); @Override List<GenericEntity> getStudentsForSchool(String token, String schoolId, Map<String, String> params); @Override List<GenericEntity> getStudents(String token, Map<String, String> params); @Override List<GenericEntity> getStudents(String token, List<String> ids, Map<String, String> params); @Override List<GenericEntity> getStudentsForSection(String token, String sectionId); @Override List<GenericEntity> getStudentsWithSearch(String token, String firstName, String lastName, String schoolId); @Override List<GenericEntity> searchStudents(String token, String query, Map<String, String> params); @Override List<GenericEntity> getStudentsForSectionWithGradebookEntries(String token, String sectionId); @Override @CacheableUserData GenericEntity getStudent(String token, String id); @Override GenericEntity getStudentWithOptionalFields(String token, String id, List<String> optionalFields); @Override List<GenericEntity> getEnrollmentForStudent(String token, String studentId); @Override List<GenericEntity> getAttendanceForStudent(String token, String studentId, Map<String, String> params); @Override List<GenericEntity> getAcademicRecordsForStudent(String token, String studentId, Map<String, String> params); @Override List<GenericEntity> getAssessments(String token, List<String> ids, Map<String, String> params); @Override List<GenericEntity> getAssessmentsForStudent(String token, String studentId); @Override GenericEntity getAssessment(String token, String id); @Override @ExecutionTimeLogger.LogExecutionTime GenericEntity readEntity(String token, String url); @ExecutionTimeLogger.LogExecutionTime @Override @CacheableUserData List<GenericEntity> readEntityList(String token, String url); @Override List<GenericEntity> readEntityList(String token, List<String> ids, Map<String, String> params, String type); @Override List<GenericEntity> getCourseSectionMappings(List<GenericEntity> sections, String schoolId, String token); SLIClient getClient(String sessionToken);  }