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

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


      // 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

  /**
   * {@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

        public void process(ChangeContainer container) {
            if (progressListener.isCanceled()) {
                target.cancel();
                throw new OsmosisRuntimeException("Cancelled by user");
            }
            final EntityContainer entityContainer = container.getEntityContainer();
            final Entity entity = entityContainer.getEntity();
            final ChangeAction changeAction = container.getAction();
            if (changeAction.equals(ChangeAction.Delete)) {
                SimpleFeatureType ft = entity instanceof Node ? OSMUtils.nodeType() : OSMUtils
                        .wayType();
                String id = Long.toString(entity.getId());
View Full Code Here

                    Optional<Object> value = values.get(i);
                    featureBuilder.set(descriptor.getName(), value.orNull());
                }
                SimpleFeature feature = featureBuilder.buildFeature(ref.name());
                Entity entity = converter.toEntity(feature, id);
                EntityContainer container;
                if (entity instanceof Node) {
                    container = new NodeContainer((Node) entity);
                } else {
                    container = new WayContainer((Way) entity);
                }
View Full Code Here

        Iterator<EntityContainer> iterator = Iterators.concat(nodes, ways);
        if (file.getName().endsWith(".pbf")) {
            BlockOutputStream output = new BlockOutputStream(new FileOutputStream(file));
            OsmosisSerializer serializer = new OsmosisSerializer(output);
            while (iterator.hasNext()) {
                EntityContainer entity = iterator.next();
                serializer.process(entity);
            }
            serializer.complete();
        } else {
            XmlWriter writer = new XmlWriter(file, CompressionMethod.None);
            while (iterator.hasNext()) {
                EntityContainer entity = iterator.next();
                writer.process(entity);
            }
            writer.complete();
        }
View Full Code Here

                    Optional<Object> value = values.get(i);
                    featureBuilder.set(descriptor.getName(), value.orNull());
                }
                SimpleFeature feature = featureBuilder.buildFeature(ref.name());
                Entity entity = converter.toEntity(feature, null);
                EntityContainer container;
                if (entity instanceof Node) {
                    container = new NodeContainer((Node) entity);
                } else {
                    container = new WayContainer((Way) entity);
                }
View Full Code Here

  public void process() {
    // Setup
    Entity entityMocked = mock(Entity.class);
    when(entityMocked.getType()).thenReturn(EntityType.Node);

    EntityContainer entityContainerMocked = mock(EntityContainer.class);
    when(entityContainerMocked.getEntity()).thenReturn(entityMocked);

    // Action
    elasticSearchWriterTask.process(entityContainerMocked);
    elasticSearchWriterTask.complete();
View Full Code Here

TOP

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

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.