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

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


    entity = writeableContainer.getEntity();
    sortedTags = sortTags(entity.getTags());
    entity.getTags().clear();
    entity.getTags().addAll(sortedTags);
   
    changeSink.process(new ChangeContainer(writeableContainer, changeContainer.getAction()));
  }
View Full Code Here


        if (comparisonResult < 0) {
          // The from entity doesn't exist on the to source therefore
          // has been deleted. We don't know when the entity was
          // deleted so set the delete time to the current time.
          changeSink.process(
              new ChangeContainer(
                  timestampSetter.updateTimestamp(fromEntityContainer),
                  ChangeAction.Delete));
          fromEntityContainer = null;
        } else if (comparisonResult > 0) {
          // The to entity doesn't exist on the from source therefore has
          // been created.
          changeSink.process(new ChangeContainer(toEntityContainer, ChangeAction.Create));
          toEntityContainer = null;
        } else {
          // The entity exists on both sources, therefore we must
          // compare
          // the entities directly. If there is a difference, the
          // entity has been modified.
          if (!fromEntityContainer.getEntity().equals(toEntityContainer.getEntity())) {
            changeSink.process(new ChangeContainer(toEntityContainer, ChangeAction.Modify));
          }
          fromEntityContainer = null;
          toEntityContainer = null;
        }
      }
     
      // Any remaining "from" entities are deletes.
      while (fromEntityContainer != null || fromPostbox.hasNext()) {
        if (fromEntityContainer == null) {
          fromEntityContainer = fromPostbox.getNext();
        }

        // The from entity doesn't exist on the to source therefore
        // has been deleted. We don't know when the entity was
        // deleted so set the delete time to the current time.
        changeSink.process(
            new ChangeContainer(
                timestampSetter.updateTimestamp(fromEntityContainer),
                ChangeAction.Delete));
        fromEntityContainer = null;
      }
      // Any remaining "to" entities are creates.
      while (toEntityContainer != null || toPostbox.hasNext()) {
        if (toEntityContainer == null) {
          toEntityContainer = toPostbox.getNext();
        }
        changeSink.process(new ChangeContainer(toEntityContainer, ChangeAction.Create));
        toEntityContainer = null;
      }
     
      changeSink.complete();
      fromPostbox.outputComplete();
View Full Code Here

    currentChanges = new ArrayList<ChangeContainer>();
  }
 
 
  private void flushCurrentChanges() {
    ChangeContainer changeBegin;
    ChangeContainer changeEnd;
    ChangeAction actionBegin;
    ChangeAction actionEnd;
    ChangeAction actionResult;
   
    changeBegin = currentChanges.get(0);
    changeEnd = currentChanges.get(currentChanges.size() - 1);
   
    actionBegin = changeBegin.getAction();
    actionEnd = changeEnd.getAction();
   
    // If the final action is a delete we'll send a delete action regardless of whether the
    // first action was a create just in case the create should have been a modify.
    // If the first action is a create, then the result is always a create (except for delete
    // case above).
    // Everything else is treated as a modify.
    if (actionEnd.equals(ChangeAction.Delete)) {
      actionResult = ChangeAction.Delete;
    } else if (actionBegin.equals(ChangeAction.Create)) {
      actionResult = ChangeAction.Create;
    } else {
      actionResult = ChangeAction.Modify;
    }
   
    changeSink.process(new ChangeContainer(changeEnd.getEntityContainer(), actionResult));
   
    currentChanges.clear();
  }
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

   */
  @Override
  public ChangeContainer next() {
    EntityHistory<T> entityHistory;
    T entity;
    EntityContainer entityContainer;
    boolean createdPreviously;
   
    // Get the entity from the underlying source.
    entityHistory = source.next();
    entity = entityHistory.getEntity();
View Full Code Here

TOP

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

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.