Package org.openstreetmap.osmosis.core.container.v0_6

Examples of org.openstreetmap.osmosis.core.container.v0_6.DatasetContext


    // The entity has been modified if it is visible and was created previously.
    // It is a create if it is visible and was NOT created previously.
    // It is a delete if it is NOT visible and was created previously.
    // No action if it is NOT visible and was NOT created previously.
    if (entityHistory.isVisible() && createdPreviously) {
      return new ChangeContainer(entityContainer, ChangeAction.Modify);
    } else if (entityHistory.isVisible() && !createdPreviously) {
      return new ChangeContainer(entityContainer, ChangeAction.Create);
    } else if (!entityHistory.isVisible() && createdPreviously) {
      return new ChangeContainer(entityContainer, ChangeAction.Delete);
    } else {
      // This is an unusual case in that an initial version has been marked as not visible.
      // The production database contains many examples of this, presumably due to the original
      // TIGER import not being deleted properly.
      return new ChangeContainer(entityContainer, ChangeAction.Delete);
    }
  }
View Full Code Here


   * {@inheritDoc}
   */
  public boolean hasNext() {
    while (!nextValueLoaded && sourceIterator.hasNext()) {
      List<ChangeContainer> changeList;
      ChangeContainer changeContainer;
      boolean createdPreviously;
     
      // Get the next change list from the underlying stream.
      changeList = sourceIterator.next();
     
      // Check the first node, if it has a version greater than 1 the node
      // existed prior to the interval beginning and therefore cannot be a
      // create.
      createdPreviously = (changeList.get(0).getEntityContainer().getEntity().getVersion() > 1);
     
      // Get the most current change.
      changeContainer = changeList.get(changeList.size() - 1);
     
      // The entity has been modified if it is a create/modify and was created previously.
      // It is a create if it is create/modify and was NOT created previously.
      // It is a delete if it is a delete and was created previously.
      // No action if it is a delete and was NOT created previously.
      if (!ChangeAction.Delete.equals(changeContainer.getAction()) && createdPreviously) {
        nextValue = new ChangeContainer(changeContainer.getEntityContainer(), ChangeAction.Modify);
        nextValueLoaded = true;
      } else if (!ChangeAction.Delete.equals(changeContainer.getAction()) && !createdPreviously) {
        nextValue = new ChangeContainer(changeContainer.getEntityContainer(), ChangeAction.Create);
        nextValueLoaded = true;
      } else if (ChangeAction.Delete.equals(changeContainer.getAction()) && createdPreviously) {
        nextValue = new ChangeContainer(changeContainer.getEntityContainer(), ChangeAction.Delete);
        nextValueLoaded = true;
      }
    }
   
    return nextValueLoaded;
View Full Code Here

      // As we process, we must update the timestamp to match the latest
      // record we have received.
      currentTimestamp = state.getTimestamp();

      while (sourceIterator.hasNext()) {
        ChangeContainer change;
        Date nextTimestamp;

        change = sourceIterator.next();
        nextTimestamp = change.getEntityContainer().getEntity().getTimestamp();

        if (currentTimestamp.compareTo(nextTimestamp) < 0) {
          currentTimestamp = nextTimestamp;
        }
View Full Code Here

   */
  public void run() {
    try {
      EntityContainerComparator comparator;
      EntityContainer base = null;
      ChangeContainer change = null;
      Map<String, Object> metaData;
     
      // Create a comparator for comparing two entities by type and identifier.
      comparator = new EntityContainerComparator(new EntityByTypeThenIdComparator());
     
      // Initialise the pipeline with a combination of the metadata from
      // both inputs. The change stream metadata will be applied second
      // and will override any values with the same key.
      metaData = new HashMap<String, Object>();
      metaData.putAll(basePostbox.outputInitialize());
      metaData.putAll(changePostbox.outputInitialize());
      sink.initialize(metaData);
     
      // We continue in the comparison loop while both sources still have data.
      while ((base != null || basePostbox.hasNext()) && (change != null || changePostbox.hasNext())) {
        int comparisonResult;
       
        // Get the next input data where required.
        if (base == null) {
          base = basePostbox.getNext();
        }
        if (change == null) {
          change = changePostbox.getNext();
        }
       
        // Compare the two sources.
        comparisonResult = comparator.compare(base, change.getEntityContainer());
       
        if (comparisonResult < 0) {
          processBaseOnlyEntity(base);
          base = null;
         
View Full Code Here

   * {@inheritDoc}
   */
  public void run() {
    try {
      EntityContainerComparator comparator;
      ChangeContainer changeContainer0 = null;
      ChangeContainer changeContainer1 = null;
     
      // Create a comparator for comparing two entities by type and identifier.
      comparator = new EntityContainerComparator(new EntityByTypeThenIdThenVersionComparator());
     
      // We can't get meaningful data from the initialize data on the
      // input streams, so pass empty meta data to the sink and discard
      // the input meta data.
      postbox0.outputInitialize();
      postbox1.outputInitialize();
      changeSink.initialize(Collections.<String, Object>emptyMap());
     
      // We continue in the comparison loop while both sources still have data.
      while (
          (changeContainer0 != null || postbox0.hasNext())
          && (changeContainer1 != null || postbox1.hasNext())) {
        long comparisonResult;
       
        // Get the next input data where required.
        if (changeContainer0 == null) {
          changeContainer0 = postbox0.getNext();
        }
        if (changeContainer1 == null) {
          changeContainer1 = postbox1.getNext();
        }
       
        // Compare the two entities.
        comparisonResult =
          comparator.compare(changeContainer0.getEntityContainer(), changeContainer1.getEntityContainer());
       
        if (comparisonResult < 0) {
          // Entity 0 doesn't exist on the other source and can be
          // sent straight through.
          changeSink.process(changeContainer0);
          changeContainer0 = null;
        } else if (comparisonResult > 0) {
          // Entity 1 doesn't exist on the other source and can be
          // sent straight through.
          changeSink.process(changeContainer1);
          changeContainer1 = null;
        } else {
          // The entity exists on both sources so we must resolve the conflict.
          if (conflictResolutionMethod.equals(ConflictResolutionMethod.Timestamp)) {
            int timestampComparisonResult;
           
            timestampComparisonResult =
              changeContainer0.getEntityContainer().getEntity().getTimestamp()
              .compareTo(changeContainer1.getEntityContainer().getEntity().getTimestamp());
           
            if (timestampComparisonResult < 0) {
              changeSink.process(changeContainer1);
            } else if (timestampComparisonResult > 0) {
              changeSink.process(changeContainer0);
            } else {
              // If both have identical timestamps, use the second source.
              changeSink.process(changeContainer1);
            }
           
          } else if (conflictResolutionMethod.equals(ConflictResolutionMethod.LatestSource)) {
            changeSink.process(changeContainer1);
          } else if (conflictResolutionMethod.equals(ConflictResolutionMethod.Version)) {
            int version0 = changeContainer0.getEntityContainer().getEntity().getVersion();
            int version1 = changeContainer1.getEntityContainer().getEntity().getVersion();
            if (version0 < version1) {
              changeSink.process(changeContainer1);
            } else if (version0 > version1) {
              changeSink.process(changeContainer0);
            } else {
View Full Code Here

  public void process(ChangeContainer changeContainer) {
    if (!ChangeAction.Delete.equals(changeContainer.getAction())) {
      EntityContainer output = super.processEntityContainer(changeContainer.getEntityContainer());

      if (output != null) {
        sink.process(new ChangeContainer(output, changeContainer.getAction()));
      }
    } else {
      sink.process(changeContainer);
    }
  }
View Full Code Here

    simplifier.setChangeSink(new NullChangeWriter());
    simplifier.initialize(new HashMap<String, Object>());
    Node node;

    node = new Node(new CommonEntityData(1, 2, new Date(), OsmUser.NONE, 2), 1, 1);
    simplifier.process(new ChangeContainer(new NodeContainer(node), ChangeAction.Modify));

    try {
      node = new Node(new CommonEntityData(1, 1, new Date(), OsmUser.NONE, 1), 1, 1);
      simplifier.process(new ChangeContainer(new NodeContainer(node), ChangeAction.Modify));
    } catch (OsmosisRuntimeException e) {
      if (e.getMessage().startsWith("Pipeline entities are not sorted")) {
        return;
      }
      throw e;
View Full Code Here

    simplifier.setChangeSink(new NullChangeWriter());
    simplifier.initialize(new HashMap<String, Object>());
    Node node;

    node = new Node(new CommonEntityData(2, 2, new Date(), OsmUser.NONE, 2), 1, 1);
    simplifier.process(new ChangeContainer(new NodeContainer(node), ChangeAction.Modify));

    try {
      node = new Node(new CommonEntityData(1, 2, new Date(), OsmUser.NONE, 1), 1, 1);
      simplifier.process(new ChangeContainer(new NodeContainer(node), ChangeAction.Modify));
    } catch (OsmosisRuntimeException e) {
      if (e.getMessage().startsWith("Pipeline entities are not sorted")) {
        return;
      }
      throw e;
View Full Code Here

    simplifier.initialize(new HashMap<String, Object>());
    Node node;
    Way way;
   
    way = new Way(new CommonEntityData(2, 2, new Date(), OsmUser.NONE, 2));
    simplifier.process(new ChangeContainer(new WayContainer(way), ChangeAction.Modify));

    try {
      node = new Node(new CommonEntityData(1, 2, new Date(), OsmUser.NONE, 1), 1, 1);
      simplifier.process(new ChangeContainer(new NodeContainer(node), ChangeAction.Modify));
    } catch (OsmosisRuntimeException e) {
      if (e.getMessage().startsWith("Pipeline entities are not sorted")) {
        return;
      }
      throw e;
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public void process(Dataset dataset) {
    DatasetContext dsCtx = dataset.createReader();
   
    try {
      EntityManager<Node> nodeManager = dsCtx.getNodeManager();
      OsmUser user;
      Node node;
     
      // Create the user for edits to be performed under. This is an existing user with an
      // updated name.
      user = new OsmUser(10, "user10b");
     
      // Modify node 1 to add a new tag.
      node = nodeManager.getEntity(1).getWriteableInstance();
      node.setUser(user);
      node.getTags().add(new Tag("change", "new tag"));
      nodeManager.modifyEntity(node);
     
      // Delete node 6.
      nodeManager.removeEntity(6);
     
      // Add node 7 using the NONE user.
      node = new Node(new CommonEntityData(7, 16, buildDate("2008-01-02 18:19:20"), OsmUser.NONE, 93), -11, -12);
      node.getTags().addAll(
          Arrays.asList(new Tag[]{new Tag("created_by", "Me7"), new Tag("change", "new node")}));
      nodeManager.addEntity(node);
     
      dsCtx.complete();
     
    } finally {
      dsCtx.release();
    }
  }
View Full Code Here

TOP

Related Classes of org.openstreetmap.osmosis.core.container.v0_6.DatasetContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.