@Test public void mergeSchemaMergesMatchingPredicates() throws Exception { final MergeSchemas mergeSchemas = new MergeSchemas(); Map<String, Type> generatedSchema = new HashMap<>(); Type predType1 = createTypeWithPredicate("generated", Direction.IN); predType1.getPredicate("generated", Direction.IN).setHasBeenList(true); predType1.getPredicate("generated", Direction.IN).setOwner(new Type("testOwner")); generatedSchema.put("Type", predType1); Map<String, Type> customSchema = new HashMap<>(); Type predType2 = createTypeWithPredicate("generated", Direction.IN); predType2.getPredicate("generated", Direction.IN).setHasBeenList(false); predType2.getPredicate("generated", Direction.IN).setOwner(new Type("testOwner")); customSchema.put("Type", predType2); Map<String, Type> mergedSchema = mergeSchemas.mergeSchema(generatedSchema, customSchema); assertThat(mergedSchema, hasEntry(is("Type"), hasProperty("predicates", contains( predicate().withName("generated").withDirection(Direction.IN).withWasList(true) )))); assertThat(mergedSchema, hasEntry(is("Type"), hasProperty("predicates", not(hasItem( predicate().withName("generated").withDirection(Direction.IN).withWasList(false)) )))); }
public Map<String, Type> mergeSchema(Map<String, Type> generatedSchema, Map<String, Type> customSchema) { Map<String, Type> mergedSchema = generatedSchema; Collection<Predicate> mergedPredicates; for (Map.Entry<String, Type> entry : customSchema.entrySet()) { mergedPredicates = new HashSet<>(); if (mergedSchema.get(entry.getKey()) != null) { for (Predicate customPredicate : entry.getValue().getPredicates()) { if (mergedSchema.get(entry.getKey()) .getPredicate(customPredicate.getName(), customPredicate.getDirection()) != null) { Predicate generatedPredicate = mergedSchema.get(entry.getKey()) .getPredicate(customPredicate.getName(), customPredicate.getDirection()); Predicate mergedPredicate = generatedPredicate.merge(customPredicate); mergedPredicate.setIsExplicit(true); mergedPredicates.add(mergedPredicate); } else { mergedPredicates.add(customPredicate); } } mergedSchema.get(entry.getKey()).setPredicates(mergedPredicates); } else { mergedSchema.put(entry.getKey(), entry.getValue()); } } return mergedSchema; }
MergeSchemas { public Map<String, Type> mergeSchema(Map<String, Type> generatedSchema, Map<String, Type> customSchema) { Map<String, Type> mergedSchema = generatedSchema; Collection<Predicate> mergedPredicates; for (Map.Entry<String, Type> entry : customSchema.entrySet()) { mergedPredicates = new HashSet<>(); if (mergedSchema.get(entry.getKey()) != null) { for (Predicate customPredicate : entry.getValue().getPredicates()) { if (mergedSchema.get(entry.getKey()) .getPredicate(customPredicate.getName(), customPredicate.getDirection()) != null) { Predicate generatedPredicate = mergedSchema.get(entry.getKey()) .getPredicate(customPredicate.getName(), customPredicate.getDirection()); Predicate mergedPredicate = generatedPredicate.merge(customPredicate); mergedPredicate.setIsExplicit(true); mergedPredicates.add(mergedPredicate); } else { mergedPredicates.add(customPredicate); } } mergedSchema.get(entry.getKey()).setPredicates(mergedPredicates); } else { mergedSchema.put(entry.getKey(), entry.getValue()); } } return mergedSchema; } }
MergeSchemas { public Map<String, Type> mergeSchema(Map<String, Type> generatedSchema, Map<String, Type> customSchema) { Map<String, Type> mergedSchema = generatedSchema; Collection<Predicate> mergedPredicates; for (Map.Entry<String, Type> entry : customSchema.entrySet()) { mergedPredicates = new HashSet<>(); if (mergedSchema.get(entry.getKey()) != null) { for (Predicate customPredicate : entry.getValue().getPredicates()) { if (mergedSchema.get(entry.getKey()) .getPredicate(customPredicate.getName(), customPredicate.getDirection()) != null) { Predicate generatedPredicate = mergedSchema.get(entry.getKey()) .getPredicate(customPredicate.getName(), customPredicate.getDirection()); Predicate mergedPredicate = generatedPredicate.merge(customPredicate); mergedPredicate.setIsExplicit(true); mergedPredicates.add(mergedPredicate); } else { mergedPredicates.add(customPredicate); } } mergedSchema.get(entry.getKey()).setPredicates(mergedPredicates); } else { mergedSchema.put(entry.getKey(), entry.getValue()); } } return mergedSchema; } MergeSchemas(); }
MergeSchemas { public Map<String, Type> mergeSchema(Map<String, Type> generatedSchema, Map<String, Type> customSchema) { Map<String, Type> mergedSchema = generatedSchema; Collection<Predicate> mergedPredicates; for (Map.Entry<String, Type> entry : customSchema.entrySet()) { mergedPredicates = new HashSet<>(); if (mergedSchema.get(entry.getKey()) != null) { for (Predicate customPredicate : entry.getValue().getPredicates()) { if (mergedSchema.get(entry.getKey()) .getPredicate(customPredicate.getName(), customPredicate.getDirection()) != null) { Predicate generatedPredicate = mergedSchema.get(entry.getKey()) .getPredicate(customPredicate.getName(), customPredicate.getDirection()); Predicate mergedPredicate = generatedPredicate.merge(customPredicate); mergedPredicate.setIsExplicit(true); mergedPredicates.add(mergedPredicate); } else { mergedPredicates.add(customPredicate); } } mergedSchema.get(entry.getKey()).setPredicates(mergedPredicates); } else { mergedSchema.put(entry.getKey(), entry.getValue()); } } return mergedSchema; } MergeSchemas(); Map<String, Type> mergeSchema(Map<String, Type> generatedSchema, Map<String, Type> customSchema); }
MergeSchemas { public Map<String, Type> mergeSchema(Map<String, Type> generatedSchema, Map<String, Type> customSchema) { Map<String, Type> mergedSchema = generatedSchema; Collection<Predicate> mergedPredicates; for (Map.Entry<String, Type> entry : customSchema.entrySet()) { mergedPredicates = new HashSet<>(); if (mergedSchema.get(entry.getKey()) != null) { for (Predicate customPredicate : entry.getValue().getPredicates()) { if (mergedSchema.get(entry.getKey()) .getPredicate(customPredicate.getName(), customPredicate.getDirection()) != null) { Predicate generatedPredicate = mergedSchema.get(entry.getKey()) .getPredicate(customPredicate.getName(), customPredicate.getDirection()); Predicate mergedPredicate = generatedPredicate.merge(customPredicate); mergedPredicate.setIsExplicit(true); mergedPredicates.add(mergedPredicate); } else { mergedPredicates.add(customPredicate); } } mergedSchema.get(entry.getKey()).setPredicates(mergedPredicates); } else { mergedSchema.put(entry.getKey(), entry.getValue()); } } return mergedSchema; } MergeSchemas(); Map<String, Type> mergeSchema(Map<String, Type> generatedSchema, Map<String, Type> customSchema);  }