@Test public void testIsSelf() { BasicService basicService = (BasicService) context.getBean("basicService", "teacher", new ArrayList<Treatment>(), securityRepo); basicService.setDefn(definitionStore.lookupByEntityType("teacher")); securityContextInjector.setEducatorContext("my-id"); assertTrue(basicService.isSelf(new NeutralQuery(new NeutralCriteria("_id", NeutralCriteria.OPERATOR_EQUAL, "my-id")))); NeutralQuery query = new NeutralQuery(new NeutralCriteria("_id", NeutralCriteria.CRITERIA_IN, Arrays.asList("my-id"))); assertTrue(basicService.isSelf(query)); query.addCriteria(new NeutralCriteria("someOtherProperty", NeutralCriteria.OPERATOR_EQUAL, "somethingElse")); assertTrue(basicService.isSelf(query)); query.addOrQuery(new NeutralQuery(new NeutralCriteria("refProperty", NeutralCriteria.OPERATOR_EQUAL, "my-id"))); assertTrue(basicService.isSelf(query)); query.addOrQuery(new NeutralQuery(new NeutralCriteria("_id", NeutralCriteria.OPERATOR_EQUAL, "someoneElse"))); assertFalse(basicService.isSelf(query)); assertFalse(basicService.isSelf(new NeutralQuery(new NeutralCriteria("_id", NeutralCriteria.CRITERIA_IN, Arrays.asList("my-id", "someoneElse"))))); }
protected boolean isSelf(NeutralQuery query) { List<NeutralCriteria> allTheCriteria = query.getCriteria(); for (NeutralQuery orQuery: query.getOrQueries()) { if(!isSelf(orQuery)) { return false; } } for(NeutralCriteria criteria: allTheCriteria) { if (criteria.getOperator().equals(NeutralCriteria.CRITERIA_IN) && criteria.getValue() instanceof List) { List<?> value = (List<?>) criteria.getValue(); if (value.size() == 1 && isSelf(value.get(0).toString())) { return true; } } else if (criteria.getOperator().equals(NeutralCriteria.OPERATOR_EQUAL) && criteria.getValue() instanceof String) { if (isSelf((String) criteria.getValue())){ return true; } } } return false; }
BasicService implements EntityService, AccessibilityCheck { protected boolean isSelf(NeutralQuery query) { List<NeutralCriteria> allTheCriteria = query.getCriteria(); for (NeutralQuery orQuery: query.getOrQueries()) { if(!isSelf(orQuery)) { return false; } } for(NeutralCriteria criteria: allTheCriteria) { if (criteria.getOperator().equals(NeutralCriteria.CRITERIA_IN) && criteria.getValue() instanceof List) { List<?> value = (List<?>) criteria.getValue(); if (value.size() == 1 && isSelf(value.get(0).toString())) { return true; } } else if (criteria.getOperator().equals(NeutralCriteria.OPERATOR_EQUAL) && criteria.getValue() instanceof String) { if (isSelf((String) criteria.getValue())){ return true; } } } return false; } }
BasicService implements EntityService, AccessibilityCheck { protected boolean isSelf(NeutralQuery query) { List<NeutralCriteria> allTheCriteria = query.getCriteria(); for (NeutralQuery orQuery: query.getOrQueries()) { if(!isSelf(orQuery)) { return false; } } for(NeutralCriteria criteria: allTheCriteria) { if (criteria.getOperator().equals(NeutralCriteria.CRITERIA_IN) && criteria.getValue() instanceof List) { List<?> value = (List<?>) criteria.getValue(); if (value.size() == 1 && isSelf(value.get(0).toString())) { return true; } } else if (criteria.getOperator().equals(NeutralCriteria.OPERATOR_EQUAL) && criteria.getValue() instanceof String) { if (isSelf((String) criteria.getValue())){ return true; } } } return false; } BasicService(String collectionName, List<Treatment> treatments, Repository<Entity> repo); }
BasicService implements EntityService, AccessibilityCheck { protected boolean isSelf(NeutralQuery query) { List<NeutralCriteria> allTheCriteria = query.getCriteria(); for (NeutralQuery orQuery: query.getOrQueries()) { if(!isSelf(orQuery)) { return false; } } for(NeutralCriteria criteria: allTheCriteria) { if (criteria.getOperator().equals(NeutralCriteria.CRITERIA_IN) && criteria.getValue() instanceof List) { List<?> value = (List<?>) criteria.getValue(); if (value.size() == 1 && isSelf(value.get(0).toString())) { return true; } } else if (criteria.getOperator().equals(NeutralCriteria.OPERATOR_EQUAL) && criteria.getValue() instanceof String) { if (isSelf((String) criteria.getValue())){ return true; } } } return false; } BasicService(String collectionName, List<Treatment> treatments, Repository<Entity> repo); @Override long count(NeutralQuery neutralQuery); @Override long countBasedOnContextualRoles(NeutralQuery neutralQuery); @Override List<String> create(List<EntityBody> content); @Override List<String> createBasedOnContextualRoles(List<EntityBody> content); @Override Iterable<String> listIds(final NeutralQuery neutralQuery); @Override String create(EntityBody content); @Override String createBasedOnContextualRoles(EntityBody content); @Override boolean accessibilityCheck(String id); @Override void delete(String id); @Override void deleteBasedOnContextualRoles(String id); @Override boolean update(String id, EntityBody content, boolean applySecurityContext); @Override boolean patch(String id, EntityBody content, boolean applySecurityContext); @Override EntityBody get(String id); @Override EntityBody get(String id, NeutralQuery neutralQuery); @Override Iterable<EntityBody> get(Iterable<String> ids); @Override Iterable<EntityBody> get(Iterable<String> ids, final NeutralQuery neutralQuery); @Override Iterable<EntityBody> list(NeutralQuery neutralQuery); @Override Iterable<EntityBody> listBasedOnContextualRoles(NeutralQuery neutralQuery); @Override boolean exists(String id); @Override EntityBody getCustom(String id); @Override void deleteCustom(String id); @Override void createOrUpdateCustom(String id, EntityBody customEntity); void setDefn(EntityDefinition defn); @Override EntityDefinition getEntityDefinition(); long getCountLimit(); int getBatchSize(); @Override CalculatedData<String> getCalculatedValues(String id); @Override CalculatedData<Map<String, Integer>> getAggregates(String id); @Override boolean collectionExists(String collection); }
BasicService implements EntityService, AccessibilityCheck { protected boolean isSelf(NeutralQuery query) { List<NeutralCriteria> allTheCriteria = query.getCriteria(); for (NeutralQuery orQuery: query.getOrQueries()) { if(!isSelf(orQuery)) { return false; } } for(NeutralCriteria criteria: allTheCriteria) { if (criteria.getOperator().equals(NeutralCriteria.CRITERIA_IN) && criteria.getValue() instanceof List) { List<?> value = (List<?>) criteria.getValue(); if (value.size() == 1 && isSelf(value.get(0).toString())) { return true; } } else if (criteria.getOperator().equals(NeutralCriteria.OPERATOR_EQUAL) && criteria.getValue() instanceof String) { if (isSelf((String) criteria.getValue())){ return true; } } } return false; } BasicService(String collectionName, List<Treatment> treatments, Repository<Entity> repo); @Override long count(NeutralQuery neutralQuery); @Override long countBasedOnContextualRoles(NeutralQuery neutralQuery); @Override List<String> create(List<EntityBody> content); @Override List<String> createBasedOnContextualRoles(List<EntityBody> content); @Override Iterable<String> listIds(final NeutralQuery neutralQuery); @Override String create(EntityBody content); @Override String createBasedOnContextualRoles(EntityBody content); @Override boolean accessibilityCheck(String id); @Override void delete(String id); @Override void deleteBasedOnContextualRoles(String id); @Override boolean update(String id, EntityBody content, boolean applySecurityContext); @Override boolean patch(String id, EntityBody content, boolean applySecurityContext); @Override EntityBody get(String id); @Override EntityBody get(String id, NeutralQuery neutralQuery); @Override Iterable<EntityBody> get(Iterable<String> ids); @Override Iterable<EntityBody> get(Iterable<String> ids, final NeutralQuery neutralQuery); @Override Iterable<EntityBody> list(NeutralQuery neutralQuery); @Override Iterable<EntityBody> listBasedOnContextualRoles(NeutralQuery neutralQuery); @Override boolean exists(String id); @Override EntityBody getCustom(String id); @Override void deleteCustom(String id); @Override void createOrUpdateCustom(String id, EntityBody customEntity); void setDefn(EntityDefinition defn); @Override EntityDefinition getEntityDefinition(); long getCountLimit(); int getBatchSize(); @Override CalculatedData<String> getCalculatedValues(String id); @Override CalculatedData<Map<String, Integer>> getAggregates(String id); @Override boolean collectionExists(String collection);  }