@Test public void testEdOrgThroughStaff() { securityContextInjector.setStaffContext(); Entity edorg1 = createEntity(EntityNames.SCHOOL, "edorg1", new HashMap<String, Object>()); Entity edorg2 = createEntity(EntityNames.SCHOOL, "edorg2", new HashMap<String, Object>()); Mockito.when(repo.findAll(Mockito.eq(EntityNames.EDUCATION_ORGANIZATION), Mockito.any(NeutralQuery.class))).thenReturn(Arrays.asList(edorg1), Arrays.asList(edorg2)); Map<String, Object> sca1Body = new HashMap<String, Object>(); sca1Body.put(ParameterConstants.STAFF_ID, "staff1"); final Entity sca1 = createEntity(EntityNames.STAFF_COHORT_ASSOCIATION, "sca1", sca1Body); final Entity staff1 = createEntity(EntityNames.STAFF, "staff1", new HashMap<String, Object>()); Mockito.when(repo.findAll(Mockito.eq(EntityNames.STAFF), argThat(new BaseMatcher<NeutralQuery>() { @Override public boolean matches(Object item) { NeutralQuery matching = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.OPERATOR_EQUAL, sca1.getBody().get(ParameterConstants.STAFF_ID))); NeutralQuery other = (NeutralQuery) item; return matching.getCriteria().equals(other.getCriteria()); } @Override public void describeTo(Description description) { } }))).thenReturn(Arrays.asList(staff1)); Map<String, Object> seoa1Body = new HashMap<String, Object>(); seoa1Body.put(ParameterConstants.STAFF_REFERENCE, "staff1"); seoa1Body.put(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "edorg1"); Entity seoa1 = createEntity(EntityNames.STAFF_ED_ORG_ASSOCIATION, "seoa1", seoa1Body); Map<String, Object> seoa2Body = new HashMap<String, Object>(); seoa2Body.put(ParameterConstants.STAFF_REFERENCE, "staff1"); seoa2Body.put(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE, "edorg2"); Entity seoa2 = createEntity(EntityNames.STAFF_ED_ORG_ASSOCIATION, "seoa2", seoa2Body); Mockito.when(repo.findAll(Mockito.eq(EntityNames.STAFF_ED_ORG_ASSOCIATION), argThat(new BaseMatcher<NeutralQuery>() { @Override public boolean matches(Object item) { NeutralQuery matching = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, NeutralCriteria.OPERATOR_EQUAL, staff1.getEntityId())); NeutralQuery other = (NeutralQuery) item; return matching.getCriteria().equals(other.getCriteria()); } @Override public void describeTo(Description description) { } }))).thenReturn(Arrays.asList(seoa1, seoa2)); Set<String> edorgIds = arbiter.determineEdorgs(Arrays.asList(sca1), EntityNames.STAFF_COHORT_ASSOCIATION); Assert.assertEquals(2, edorgIds.size()); Assert.assertTrue(edorgIds.contains("edorg1")); Assert.assertTrue(edorgIds.contains("edorg2")); }
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);  }