@Test public void testEdOrgFromAssociation() { securityContextInjector.setEducatorContext(); Entity edorg1 = createEntity(EntityNames.SCHOOL, "edorg1", new HashMap<String, Object>()); Entity edorg2 = createEntity(EntityNames.SCHOOL, "edorg2", new HashMap<String, Object>()); Entity edorg3 = createEntity(EntityNames.SCHOOL, "edorg3", new HashMap<String, Object>()); Mockito.when(repo.findAll(Mockito.eq(EntityNames.EDUCATION_ORGANIZATION), argThat(new BaseMatcher<NeutralQuery>() { @SuppressWarnings("unchecked") @Override public boolean matches(Object item) { NeutralQuery matching1 = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, "edorg1")); NeutralQuery matching2 = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, "edorg2")); NeutralQuery matching3 = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, "edorg3")); NeutralQuery other = (NeutralQuery) item; return matching1.getCriteria().equals(other.getCriteria()) || matching2.getCriteria().equals(other.getCriteria()) || matching3.getCriteria().equals(other.getCriteria()); } @Override public void describeTo(Description description) { } }))).thenReturn(Arrays.asList(edorg1), Arrays.asList(edorg2), Arrays.asList(edorg3)); Entity student1 = createEntity(EntityNames.STUDENT, "student1", new HashMap<String, Object>()); Map<String, Object> ssa1Body = new HashMap<String, Object>(); ssa1Body.put(ParameterConstants.SCHOOL_ID, "edorg1"); ssa1Body.put(ParameterConstants.STUDENT_ID, "student1"); Entity ssa1 = createEntity(EntityNames.STUDENT_SCHOOL_ASSOCIATION, "ssa1", ssa1Body); Map<String, Object> ssa2Body = new HashMap<String, Object>(); ssa2Body.put(ParameterConstants.SCHOOL_ID, "edorg2"); ssa2Body.put(ParameterConstants.STUDENT_ID, "student1"); Entity ssa2 = createEntity(EntityNames.STUDENT_SCHOOL_ASSOCIATION, "ssa2", ssa2Body); Map<String, Object> ssa3Body = new HashMap<String, Object>(); ssa3Body.put(ParameterConstants.SCHOOL_ID, "edorg3"); ssa3Body.put(ParameterConstants.STUDENT_ID, "student1"); Entity ssa3 = createEntity(EntityNames.STUDENT_SCHOOL_ASSOCIATION, "ssa3", ssa3Body); Mockito.when(repo.findAll(Mockito.eq(EntityNames.STUDENT_SCHOOL_ASSOCIATION), argThat(new BaseMatcher<NeutralQuery>() { @Override public boolean matches(Object item) { NeutralQuery matching = new NeutralQuery(new NeutralCriteria(ParameterConstants.STUDENT_ID, NeutralCriteria.OPERATOR_EQUAL, "student1")); NeutralQuery other = (NeutralQuery) item; return matching.getCriteria().equals(other.getCriteria()); } @Override public void describeTo(Description description) { } }))).thenReturn(Arrays.asList(ssa1, ssa2, ssa3)); Set<String> edorgIds = arbiter.determineEdorgs(Arrays.asList(student1), EntityNames.STUDENT); Assert.assertEquals(3, edorgIds.size()); Assert.assertTrue(edorgIds.contains("edorg1")); Assert.assertTrue(edorgIds.contains("edorg2")); Assert.assertTrue(edorgIds.contains("edorg3")); }
public Set<String> determineEdorgs(Iterable<Entity> entities, String entityType) { Set<String> edorgs = new HashSet<String>(); for (Entity entity : findOwner(entities, entityType, false)) { edorgs.add(entity.getEntityId()); } return edorgs; }
EdOrgOwnershipArbiter extends OwnershipArbiter { public Set<String> determineEdorgs(Iterable<Entity> entities, String entityType) { Set<String> edorgs = new HashSet<String>(); for (Entity entity : findOwner(entities, entityType, false)) { edorgs.add(entity.getEntityId()); } return edorgs; } }
EdOrgOwnershipArbiter extends OwnershipArbiter { public Set<String> determineEdorgs(Iterable<Entity> entities, String entityType) { Set<String> edorgs = new HashSet<String>(); for (Entity entity : findOwner(entities, entityType, false)) { edorgs.add(entity.getEntityId()); } return edorgs; }  }
EdOrgOwnershipArbiter extends OwnershipArbiter { public Set<String> determineEdorgs(Iterable<Entity> entities, String entityType) { Set<String> edorgs = new HashSet<String>(); for (Entity entity : findOwner(entities, entityType, false)) { edorgs.add(entity.getEntityId()); } return edorgs; }  @SuppressWarnings("unused") @PostConstruct void init(); Set<String> determineEdorgs(Iterable<Entity> entities, String entityType); Set<String> determineHierarchicalEdorgs(Iterable<Entity> entities, String entityType); boolean isEntityOwnedByEdOrg(String entityType); }
EdOrgOwnershipArbiter extends OwnershipArbiter { public Set<String> determineEdorgs(Iterable<Entity> entities, String entityType) { Set<String> edorgs = new HashSet<String>(); for (Entity entity : findOwner(entities, entityType, false)) { edorgs.add(entity.getEntityId()); } return edorgs; }  @SuppressWarnings("unused") @PostConstruct void init(); Set<String> determineEdorgs(Iterable<Entity> entities, String entityType); Set<String> determineHierarchicalEdorgs(Iterable<Entity> entities, String entityType); boolean isEntityOwnedByEdOrg(String entityType);  }