@Test public void testGetInferredUrisForDualContext() throws Exception { SecurityUtil.setUserContext(SecurityUtil.UserContext.DUAL_CONTEXT); Assert.assertEquals("inferred uri for staff resource: /" + ResourceNames.ATTENDANCES + " is incorrect.", createMutatedContainer("/schools/edOrg123/studentSchoolAssociations/students/attendances", ""), mutator.mutateBaseUri(VERSION, ResourceNames.ATTENDANCES, "", staff)); Assert.assertEquals("inferred uri for staff resource: /" + ResourceNames.COHORTS + " is incorrect.", createMutatedContainer("/staff/staff123/staffCohortAssociations/cohorts", ""), mutator.mutateBaseUri(VERSION, ResourceNames.COHORTS, "", staff)); Assert.assertEquals("inferred uri for staff resource: /" + ResourceNames.HOME + " is incorrect.", createMutatedContainer("/home", ""), mutator.mutateBaseUri(VERSION, ResourceNames.HOME, "", staff)); Assert.assertEquals("inferred uri for staff resource: /" + ResourceNames.PROGRAMS + " is incorrect.", createMutatedContainer("/staff/staff123/staffProgramAssociations/programs", ""), mutator.mutateBaseUri(VERSION, ResourceNames.PROGRAMS, "", staff)); Assert.assertEquals("inferred uri for staff resource: /" + ResourceNames.SECTIONS + " is incorrect.", createMutatedContainer("/schools/edOrg123/sections", ""), mutator.mutateBaseUri(VERSION, ResourceNames.SECTIONS, "", staff)); Assert.assertEquals("inferred uri for staff resource: /" + ResourceNames.STAFF + " is incorrect.", createMutatedContainer("/educationOrganizations/edOrg123/staffEducationOrgAssignmentAssociations/staff", ""), mutator.mutateBaseUri(VERSION, ResourceNames.STAFF, "", staff)); Assert.assertEquals("inferred uri for staff resource: /" + ResourceNames.STAFF_COHORT_ASSOCIATIONS + " is incorrect.", createMutatedContainer("/staff/staff123/staffCohortAssociations", ""), mutator.mutateBaseUri(VERSION, ResourceNames.STAFF_COHORT_ASSOCIATIONS, "", staff)); Assert.assertEquals("inferred uri for staff resource: /" + ResourceNames.STAFF_EDUCATION_ORGANIZATION_ASSOCIATIONS + " is incorrect.", createMutatedContainer("/staff/staff123/staffEducationOrgAssignmentAssociations", ""), mutator.mutateBaseUri(VERSION, ResourceNames.STAFF_EDUCATION_ORGANIZATION_ASSOCIATIONS, "", staff)); Assert.assertEquals("inferred uri for staff resource: /" + ResourceNames.STAFF_PROGRAM_ASSOCIATIONS + " is incorrect.", createMutatedContainer("/staff/staff123/staffProgramAssociations", ""), mutator.mutateBaseUri(VERSION, ResourceNames.STAFF_PROGRAM_ASSOCIATIONS, "", staff)); Assert.assertEquals("inferred uri for staff resource: /" + ResourceNames.STUDENTS + " is incorrect.", createMutatedContainer("/schools/edOrg123/studentSchoolAssociations/students", ""), mutator.mutateBaseUri(VERSION, ResourceNames.STUDENTS, "", staff)); Assert.assertEquals("inferred uri for staff resource: /" + ResourceNames.STUDENT_SCHOOL_ASSOCIATIONS + " is incorrect.", createMutatedContainer("/schools/edOrg123/studentSchoolAssociations", ""), mutator.mutateBaseUri(VERSION, ResourceNames.STUDENT_SCHOOL_ASSOCIATIONS, "", staff)); Assert.assertEquals("inferred uri for staff resource: /" + ResourceNames.TEACHERS + " is incorrect.", createMutatedContainer("/schools/edOrg123/teacherSchoolAssociations/teachers", ""), mutator.mutateBaseUri(VERSION, ResourceNames.TEACHERS, "", staff)); Assert.assertEquals("inferred uri for staff resource: /" + ResourceNames.TEACHER_SCHOOL_ASSOCIATIONS + " is incorrect.", createMutatedContainer("/schools/edOrg123/teacherSchoolAssociations", ""), mutator.mutateBaseUri(VERSION, ResourceNames.TEACHER_SCHOOL_ASSOCIATIONS, "", staff)); }
public MutatedContainer mutateBaseUri(String version, String resource, final String queryParameters, Entity user) { MutatedContainer mutated = new MutatedContainer(); mutated.setQueryParameters(queryParameters); if (mutated.getQueryParameters() == null) { mutated.setQueryParameters(""); } mutated.setPath(rootSearchMutator.mutatePath(version, resource, mutated.getQueryParameters())); if (mutated.getPath() == null && mutateToTeacher()) { return this.mutateBaseUriForTeacher(resource, mutated.getQueryParameters(), user); } else if (mutated.getPath() == null && mutateToStaff()) { return this.mutateBaseUriForStaff(resource, mutated.getQueryParameters(), user, mutated.getQueryParameters()); } else if (mutated.getPath() == null && isStudent(user) || isParent(user)) { return this.mutateStudentParentRequest( Arrays.<String> asList(version, resource), mutated.getQueryParameters(), user); } else { return mutated; } }
UriMutator { public MutatedContainer mutateBaseUri(String version, String resource, final String queryParameters, Entity user) { MutatedContainer mutated = new MutatedContainer(); mutated.setQueryParameters(queryParameters); if (mutated.getQueryParameters() == null) { mutated.setQueryParameters(""); } mutated.setPath(rootSearchMutator.mutatePath(version, resource, mutated.getQueryParameters())); if (mutated.getPath() == null && mutateToTeacher()) { return this.mutateBaseUriForTeacher(resource, mutated.getQueryParameters(), user); } else if (mutated.getPath() == null && mutateToStaff()) { return this.mutateBaseUriForStaff(resource, mutated.getQueryParameters(), user, mutated.getQueryParameters()); } else if (mutated.getPath() == null && isStudent(user) || isParent(user)) { return this.mutateStudentParentRequest( Arrays.<String> asList(version, resource), mutated.getQueryParameters(), user); } else { return mutated; } } }
UriMutator { public MutatedContainer mutateBaseUri(String version, String resource, final String queryParameters, Entity user) { MutatedContainer mutated = new MutatedContainer(); mutated.setQueryParameters(queryParameters); if (mutated.getQueryParameters() == null) { mutated.setQueryParameters(""); } mutated.setPath(rootSearchMutator.mutatePath(version, resource, mutated.getQueryParameters())); if (mutated.getPath() == null && mutateToTeacher()) { return this.mutateBaseUriForTeacher(resource, mutated.getQueryParameters(), user); } else if (mutated.getPath() == null && mutateToStaff()) { return this.mutateBaseUriForStaff(resource, mutated.getQueryParameters(), user, mutated.getQueryParameters()); } else if (mutated.getPath() == null && isStudent(user) || isParent(user)) { return this.mutateStudentParentRequest( Arrays.<String> asList(version, resource), mutated.getQueryParameters(), user); } else { return mutated; } }  }
UriMutator { public MutatedContainer mutateBaseUri(String version, String resource, final String queryParameters, Entity user) { MutatedContainer mutated = new MutatedContainer(); mutated.setQueryParameters(queryParameters); if (mutated.getQueryParameters() == null) { mutated.setQueryParameters(""); } mutated.setPath(rootSearchMutator.mutatePath(version, resource, mutated.getQueryParameters())); if (mutated.getPath() == null && mutateToTeacher()) { return this.mutateBaseUriForTeacher(resource, mutated.getQueryParameters(), user); } else if (mutated.getPath() == null && mutateToStaff()) { return this.mutateBaseUriForStaff(resource, mutated.getQueryParameters(), user, mutated.getQueryParameters()); } else if (mutated.getPath() == null && isStudent(user) || isParent(user)) { return this.mutateStudentParentRequest( Arrays.<String> asList(version, resource), mutated.getQueryParameters(), user); } else { return mutated; } }  MutatedContainer mutate(List<PathSegment> segments,
			String queryParameters, SLIPrincipal principal, String clientId); MutatedContainer mutateBaseUri(String version, String resource,
			final String queryParameters, Entity user); }
UriMutator { public MutatedContainer mutateBaseUri(String version, String resource, final String queryParameters, Entity user) { MutatedContainer mutated = new MutatedContainer(); mutated.setQueryParameters(queryParameters); if (mutated.getQueryParameters() == null) { mutated.setQueryParameters(""); } mutated.setPath(rootSearchMutator.mutatePath(version, resource, mutated.getQueryParameters())); if (mutated.getPath() == null && mutateToTeacher()) { return this.mutateBaseUriForTeacher(resource, mutated.getQueryParameters(), user); } else if (mutated.getPath() == null && mutateToStaff()) { return this.mutateBaseUriForStaff(resource, mutated.getQueryParameters(), user, mutated.getQueryParameters()); } else if (mutated.getPath() == null && isStudent(user) || isParent(user)) { return this.mutateStudentParentRequest( Arrays.<String> asList(version, resource), mutated.getQueryParameters(), user); } else { return mutated; } }  MutatedContainer mutate(List<PathSegment> segments,
			String queryParameters, SLIPrincipal principal, String clientId); MutatedContainer mutateBaseUri(String version, String resource,
			final String queryParameters, Entity user); static final int NUM_SEGMENTS_IN_TWO_PART_REQUEST; static final int NUM_SEGMENTS_IN_ONE_PART_REQUEST; }