private static List<Taggable> children(final AtlasEntity entity) { final List<Taggable> taggables = new ArrayList<>(); taggables.add(entity); final List<Relation> relations = new ArrayList<>(entity.relations()); relations.sort(RELATION_ID_COMPARATOR); Iterables.addAll(taggables, relations); return taggables; }
private boolean isSimple(final AtlasEntity entity) { for (final Relation relation : entity.relations()) { if (isBuilding(relation)) { return false; } } return true; } }
/** * Take all the relations an {@link AtlasEntity} belongs to, and replace them with the * corresponding relations linking back to this {@link MultiAtlas}. * * @param entity * The {@link AtlasEntity} * @return The relations of this entity, as viewed from this multi atlas. */ protected Set<Relation> multifyRelations(final AtlasEntity entity) { final Set<Relation> subRelations = entity.relations(); final Set<Relation> result = new HashSet<>(); for (final Relation relation : subRelations) { result.add(relation(relation.getIdentifier())); } return result; }
protected void validateRelationsPresent() { for (final AtlasEntity entity : this.atlas.entities()) { for (final Relation relation : entity.relations()) { if (relation == null) { throw new CoreException( "Entity {} {} lists some parent relation that is not present: {}", entity.getType(), entity.getIdentifier(), entity.relations().stream() .map(parent -> parent == null ? "null" : String.valueOf(parent.getIdentifier())) .collect(Collectors.toSet())); } } } }
/** * A method that creates properties for a GeoJSON Feature from the tags. * * @return A GeoJSON properties object that is to be put in a Feature. */ public JsonObject geoJsonProperties() { final JsonObject properties = new JsonObject(); getTags().forEach(properties::addProperty); properties.addProperty(GeoJsonUtils.IDENTIFIER, getIdentifier()); properties.addProperty(GeoJsonUtils.OSM_IDENTIFIER, getOsmIdentifier()); properties.addProperty(GeoJsonUtils.ITEM_TYPE, String.valueOf(getType())); final Optional<String> shardName = getAtlas().metaData().getShardName(); shardName.ifPresent(shard -> properties.addProperty("shard", shard)); final Set<Relation> relations = relations(); if (relations.size() > 0) { final JsonArray relationsArray = new JsonArray(); properties.add("relations", relationsArray); for (final Relation relation : relations) { final JsonObject relationObject = relation.geoJsonProperties(); relationsArray.add(relationObject); } } return properties; }
/** * Checks if an {@link AtlasObject} is a outline or part member of a building relation. This is * an equivalent tagging to building=* or building:part=yes. * * @param object * {@link AtlasObject} to check * @return true if the object is part of any relation where it has role outline or part */ private boolean isBuildingRelationMember(final AtlasObject object) { return object instanceof AtlasEntity && ((AtlasEntity) object).relations().stream() .anyMatch(relation -> Validators.isOfType(relation, RelationTypeTag.class, RelationTypeTag.BUILDING) && relation.members().stream() .anyMatch(member -> member.getEntity().equals(object) && (member.getRole().equals("outline")) || member.getRole().equals("part"))); }
properties.addProperty("identifier", source.getIdentifier()); add(properties, "tags", source.getTags(), tagPrinter); add(properties, "relations", source.relations(), identifierMapper);
protected String parentRelationsAsDiffViewFriendlyString() { final StringList relationIds = new StringList(); for (final Relation relation : this.relations()) { relationIds.add(relation.getIdentifier()); } final String relationsString = relationIds.join(","); return relationsString; }
final Set<Relation> parentRelations = entity.relations(); for (final Relation parentRelation : parentRelations)
protected void validateRelationsLinked() { for (final AtlasEntity entity : this.atlas.entities()) { for (final Relation relation : entity.relations()) { if (!relation.members().asBean() .getItemFor(entity.getIdentifier(), entity.getType()).isPresent()) { throw new CoreException( "Entity {} {} lists parent relation {} which does not have it as a member.", entity.getType(), entity.getIdentifier(), relation.getIdentifier()); } } } }
public CompleteRelation withExtraMember(final AtlasEntity newMember, final AtlasEntity memberFromWhichToCopyRole) { final Relation sourceRelation = Iterables.stream(memberFromWhichToCopyRole.relations()) .firstMatching(relation -> relation.getIdentifier() == this.getIdentifier()) .orElseThrow(() -> new CoreException( "Cannot copy role from {} {} as it does not have relation {} as parent", memberFromWhichToCopyRole.getType(), memberFromWhichToCopyRole.getIdentifier(), this.getIdentifier())); final String role = sourceRelation.members().asBean() .getItemFor(memberFromWhichToCopyRole.getIdentifier(), memberFromWhichToCopyRole.getType()) .orElseThrow(() -> new CoreException( "Cannot copy role from {} {} as it is not a member of {} {}", memberFromWhichToCopyRole.getType(), memberFromWhichToCopyRole.getIdentifier(), this.getClass().getSimpleName(), this)) .getRole(); return withExtraMember(newMember, role); }
@Test public void testMergeRelations() { final FeatureChange featureChange1 = new FeatureChange(ChangeType.ADD, new CompleteArea(123L, null, null, Sets.hashSet(456L))); final FeatureChange featureChange2 = new FeatureChange(ChangeType.ADD, new CompleteArea(123L, null, null, Sets.hashSet(567L))); Assert.assertEquals(Sets.hashSet(456L, 567L), Iterables.stream(featureChange1.merge(featureChange2).getReference().relations()) .map(Relation::getIdentifier).collectToSet()); }
@Test public void testMergeRelationsCollision() { final FeatureChange featureChange1 = new FeatureChange(ChangeType.ADD, new CompleteArea(123L, null, null, Sets.hashSet(456L))); final FeatureChange featureChange2 = new FeatureChange(ChangeType.ADD, new CompleteArea(123L, null, null, Sets.hashSet(456L))); Assert.assertEquals(Sets.hashSet(456L), Iterables.stream(featureChange1.merge(featureChange2).getReference().relations()) .map(Relation::getIdentifier).collectToSet()); }