@Test
  public void testBackrefrenceForWay_Full() throws OsmTransferException {
    Way w = lookupWay(ds, 1);
    assertNotNull(w);
    // way with name "way-1" is referred to by two relations
    //

    OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(w);
    reader.setReadFull(true);
    DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);
    assertEquals(6, referers.getWays().size()); // 6 ways referred by two relations
    for (Way w1 : referers.getWays()) {
      assertEquals(false, w1.isIncomplete());
    }
    assertEquals(2, referers.getRelations().size()); // two relations referring to
    Set<Long> expectedNodeIds = new HashSet<Long>();
    for (Way way : referers.getWays()) {
      Way orig = (Way) ds.getPrimitiveById(way);
      for (Node n : orig.getNodes()) {
        expectedNodeIds.add(n.getId());
      }
    }
    assertEquals(expectedNodeIds.size(), referers.getNodes().size());
    for (Node n : referers.getNodes()) {
      assertEquals(true, expectedNodeIds.contains(n.getId()));
    }

    Relation r = lookupRelation(referers, 0);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    r = lookupRelation(referers, 1);
    assertEquals(false, r.isIncomplete());
  }
Пример #2
0
  /**
   * Formats a name for a relation
   *
   * @param relation the relation
   * @return the name
   */
  @Override
  public String format(Relation relation) {
    StringBuilder name = new StringBuilder();
    if (relation.isIncomplete()) {
      name.append(tr("incomplete"));
    } else {
      TaggingPreset preset =
          TaggingPresetNameTemplateList.getInstance().findPresetTemplate(relation);

      formatRelationNameAndType(relation, name, preset);

      int mbno = relation.getMembersCount();
      name.append(trn("{0} member", "{0} members", mbno, mbno));

      if (relation.hasIncompleteMembers()) {
        name.append(", ").append(tr("incomplete"));
      }

      name.append(")");
    }
    decorateNameWithId(name, relation);

    String result = name.toString();
    for (NameFormatterHook hook : formatHooks) {
      String hookResult = hook.checkFormat(relation, result);
      if (hookResult != null) return hookResult;
    }

    return result;
  }
  @Test
  public void testBackrefrenceForWay() throws OsmTransferException {
    Way w = lookupWay(ds, 1);
    assertNotNull(w);
    // way with name "way-1" is referred to by two relations
    //

    OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(w);
    reader.setReadFull(false);
    DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);
    assertEquals(0, referers.getNodes().size()); // no nodes loaded
    assertEquals(6, referers.getWays().size()); // 6 ways referred by two relations
    for (Way w1 : referers.getWays()) {
      assertEquals(true, w1.isIncomplete());
    }
    assertEquals(2, referers.getRelations().size()); // two relations referring to w

    Relation r = lookupRelation(referers, 0);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    r = lookupRelation(referers, 1);
    assertEquals(false, r.isIncomplete());
  }
Пример #4
0
 protected void loadIncompleteRelationMembers() throws OsmTransferException {
   // if incomplete relation members exist, download them too
   for (Relation r : ds.getRelations()) {
     if (canceled) return;
     // Relations may be incomplete in case of nested relations if child relations are accessed
     // before their parent
     // (it may happen because "relations" has no deterministic sort order, see #10388)
     if (r.isIncomplete() || r.hasIncompleteMembers()) {
       synchronized (this) {
         if (canceled) return;
         objectReader =
             new OsmServerObjectReader(r.getId(), OsmPrimitiveType.RELATION, fullRelation);
       }
       DataSet theirDataSet =
           objectReader.parseOsm(
               progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
       synchronized (this) {
         objectReader = null;
       }
       new DataSetMerger(ds, theirDataSet).merge();
     }
   }
 }
  @Test
  public void testBackrefrenceForRelation_Full() throws OsmTransferException {
    Relation r = lookupRelation(ds, 1);
    assertNotNull(r);
    // way with name "relation-1" is referred to by four relations:
    //    relation-6, relation-7, relation-8, relation-9
    //

    OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(r);
    reader.setReadFull(true);
    DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);

    Set<Long> referringRelationsIds = new HashSet<Long>();
    r = lookupRelation(referers, 6);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());
    r = lookupRelation(referers, 7);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());
    r = lookupRelation(referers, 8);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());
    r = lookupRelation(referers, 9);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());

    // all relations are fully loaded
    //
    for (Relation r1 : referers.getRelations()) {
      assertEquals(false, r1.isIncomplete());
    }

    // make sure we read all ways referred to by parent relations. These
    // ways are completely read after reading the relations
    //
    Set<Long> expectedWayIds = new HashSet<Long>();
    for (RelationMember m : lookupRelation(ds, 6).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (RelationMember m : lookupRelation(ds, 7).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (RelationMember m : lookupRelation(ds, 8).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (RelationMember m : lookupRelation(ds, 9).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (long id : expectedWayIds) {
      Way w = (Way) referers.getPrimitiveById(id, OsmPrimitiveType.WAY);
      assertNotNull(w);
      assertEquals(false, w.isIncomplete());
    }

    Set<Long> expectedNodeIds = new HashSet<Long>();
    for (int i = 6; i < 10; i++) {
      Relation r1 = lookupRelation(ds, i);
      expectedNodeIds.addAll(getNodeIdsInRelation(r1));
    }

    assertEquals(expectedNodeIds.size(), referers.getNodes().size());
    for (Node n : referers.getNodes()) {
      assertEquals(true, expectedNodeIds.contains(n.getId()));
    }
  }
  @Test
  public void testBackrefrenceForRelation() throws OsmTransferException {
    Relation r = lookupRelation(ds, 1);
    assertNotNull(r);
    // way with name "relation-1" is referred to by four relations:
    //    relation-6, relation-7, relation-8, relation-9
    //

    OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(r);
    reader.setReadFull(false);
    DataSet referers = reader.parseOsm(NullProgressMonitor.INSTANCE);

    Set<Long> referringRelationsIds = new HashSet<Long>();
    r = lookupRelation(referers, 6);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());
    r = lookupRelation(referers, 7);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());
    r = lookupRelation(referers, 8);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());
    r = lookupRelation(referers, 9);
    assertNotNull(r);
    assertEquals(false, r.isIncomplete());
    referringRelationsIds.add(r.getId());

    for (Relation r1 : referers.getRelations()) {
      if (!referringRelationsIds.contains(r1.getId())) {
        assertEquals(true, r1.isIncomplete());
      }
    }

    // make sure we read all ways referred to by parent relations. These
    // ways are incomplete after reading.
    //
    Set<Long> expectedWayIds = new HashSet<Long>();
    for (RelationMember m : lookupRelation(ds, 6).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (RelationMember m : lookupRelation(ds, 7).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (RelationMember m : lookupRelation(ds, 8).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }
    for (RelationMember m : lookupRelation(ds, 9).getMembers()) {
      if (m.isWay()) {
        expectedWayIds.add(m.getMember().getId());
      }
    }

    assertEquals(expectedWayIds.size(), referers.getWays().size());
    for (Way w1 : referers.getWays()) {
      assertEquals(true, expectedWayIds.contains(w1.getId()));
      assertEquals(true, w1.isIncomplete());
    }

    // make sure we didn't read any nodes
    //
    assertEquals(0, referers.getNodes().size());
  }