Search in sources :

Example 76 with Tag

use of org.mozilla.jss.asn1.Tag in project osmosis by openstreetmap.

the class CopyFilesetBuilder method process.

/**
 * {@inheritDoc}
 */
public void process(RelationContainer relationContainer) {
    Relation relation;
    int memberSequenceId;
    relation = relationContainer.getEntity();
    relationWriter.writeField(relation.getId());
    relationWriter.writeField(relation.getVersion());
    relationWriter.writeField(relation.getUser().getId());
    relationWriter.writeField(relation.getTimestamp());
    relationWriter.writeField(relation.getChangesetId());
    relationWriter.endRecord();
    for (Tag tag : relation.getTags()) {
        relationTagWriter.writeField(relation.getId());
        relationTagWriter.writeField(tag.getKey());
        relationTagWriter.writeField(tag.getValue());
        relationTagWriter.endRecord();
    }
    memberSequenceId = 0;
    for (RelationMember member : relation.getMembers()) {
        relationMemberWriter.writeField(relation.getId());
        relationMemberWriter.writeField(member.getMemberId());
        relationMemberWriter.writeField(memberTypeValueMapper.getMemberType(member.getMemberType()));
        relationMemberWriter.writeField(member.getMemberRole());
        relationMemberWriter.writeField(memberSequenceId++);
        relationMemberWriter.endRecord();
    }
}
Also used : Relation(org.openstreetmap.osmosis.core.domain.v0_6.Relation) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 77 with Tag

use of org.mozilla.jss.asn1.Tag in project osmosis by openstreetmap.

the class EntityDao method getEntity.

/**
 * Loads the specified entity from the database.
 *
 * @param entityId
 *            The unique identifier of the entity.
 * @return The loaded entity.
 */
public T getEntity(long entityId) {
    T entity;
    if (getStatement == null) {
        getStatement = prepareStatement(entityMapper.getSqlSelect(true, true));
    }
    try {
        getStatement.setLong(1, entityId);
        try (ResultSet resultSet = getStatement.executeQuery()) {
            if (!resultSet.next()) {
                throw new NoSuchRecordException(entityMapper.getEntityName() + " " + entityId + " doesn't exist.");
            }
            entity = entityMapper.parseRecord(resultSet);
        }
        for (DbFeature<Tag> dbTag : tagDao.getAll(entityId)) {
            entity.getTags().add(dbTag.getFeature());
        }
        // Add the type specific features.
        loadFeatures(entityId, entity);
        return entity;
    } catch (SQLException e) {
        throw new OsmosisRuntimeException("Query failed for " + entityMapper.getEntityName() + " " + entityId + ".", e);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) NoSuchRecordException(org.openstreetmap.osmosis.pgsimple.common.NoSuchRecordException) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException)

Example 78 with Tag

use of org.mozilla.jss.asn1.Tag in project osmosis by openstreetmap.

the class ChangeTagSorter method process.

/**
 * {@inheritDoc}
 */
public void process(ChangeContainer changeContainer) {
    EntityContainer readOnlyContainer;
    EntityContainer writeableContainer;
    Entity entity;
    Collection<Tag> sortedTags;
    readOnlyContainer = changeContainer.getEntityContainer();
    writeableContainer = readOnlyContainer.getWriteableInstance();
    entity = writeableContainer.getEntity();
    sortedTags = sortTags(entity.getTags());
    entity.getTags().clear();
    entity.getTags().addAll(sortedTags);
    changeSink.process(new ChangeContainer(writeableContainer, changeContainer.getAction()));
}
Also used : Entity(org.openstreetmap.osmosis.core.domain.v0_6.Entity) ChangeContainer(org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 79 with Tag

use of org.mozilla.jss.asn1.Tag in project osmosis by openstreetmap.

the class DatasetDriver method process.

/**
 * {@inheritDoc}
 */
@Override
public void process(Dataset dataset) {
    try (DatasetContext dsCtx = dataset.createReader()) {
        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();
    }
}
Also used : CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) OsmUser(org.openstreetmap.osmosis.core.domain.v0_6.OsmUser) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) DatasetContext(org.openstreetmap.osmosis.core.container.v0_6.DatasetContext)

Example 80 with Tag

use of org.mozilla.jss.asn1.Tag in project osmosis by openstreetmap.

the class ChangeWriter method write.

/**
 * Writes the specified node change to the database.
 *
 * @param node The node to be written.
 * @param action The change to be applied.
 */
public void write(Node node, ChangeAction action) {
    boolean visible;
    boolean exists;
    int prmIndex;
    assertEntityHasTimestamp(node);
    // Add or update the user in the database.
    userManager.addOrUpdateUser(node.getUser());
    // Create the changeset in the database.
    changesetManager.addChangesetIfRequired(node.getChangesetId(), node.getUser());
    // If this is a deletion, the entity is not visible.
    visible = !action.equals(ChangeAction.Delete);
    // Create the prepared statements for node creation if necessary.
    if (insertNodeStatement == null) {
        insertNodeStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_NODE));
        updateNodeStatement = statementContainer.add(dbCtx.prepareStatement(UPDATE_SQL_NODE));
        selectNodeCountStatement = statementContainer.add(dbCtx.prepareStatement(SELECT_SQL_NODE_COUNT));
        insertNodeCurrentStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_NODE_CURRENT));
        updateNodeCurrentStatement = statementContainer.add(dbCtx.prepareStatement(UPDATE_SQL_NODE_CURRENT));
        selectNodeCurrentCountStatement = statementContainer.add(dbCtx.prepareStatement(SELECT_SQL_NODE_CURRENT_COUNT));
        insertNodeTagStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_NODE_TAG));
        deleteNodeTagStatement = statementContainer.add(dbCtx.prepareStatement(DELETE_SQL_NODE_TAG));
        insertNodeTagCurrentStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_NODE_TAG_CURRENT));
        deleteNodeTagCurrentStatement = statementContainer.add(dbCtx.prepareStatement(DELETE_SQL_NODE_TAG_CURRENT));
    }
    // Remove the existing tags of the node history item.
    try {
        prmIndex = 1;
        deleteNodeTagStatement.setLong(prmIndex++, node.getId());
        deleteNodeTagStatement.setInt(prmIndex++, node.getVersion());
        deleteNodeTagStatement.execute();
    } catch (SQLException e) {
        throw new OsmosisRuntimeException("Unable to delete node history tags for node with id=" + node.getId() + ".", e);
    }
    // Update the node if it already exists in the history table, otherwise insert it.
    try {
        exists = checkIfEntityHistoryExists(selectNodeCountStatement, node.getId(), node.getVersion());
    } catch (SQLException e) {
        throw new OsmosisRuntimeException("Unable to check if current node with id=" + node.getId() + " exists.", e);
    }
    if (exists) {
        // Update the node in the history table.
        try {
            prmIndex = 1;
            updateNodeStatement.setTimestamp(prmIndex++, new Timestamp(node.getTimestamp().getTime()));
            updateNodeStatement.setBoolean(prmIndex++, visible);
            updateNodeStatement.setLong(prmIndex++, node.getChangesetId());
            updateNodeStatement.setInt(prmIndex++, FixedPrecisionCoordinateConvertor.convertToFixed(node.getLatitude()));
            updateNodeStatement.setInt(prmIndex++, FixedPrecisionCoordinateConvertor.convertToFixed(node.getLongitude()));
            updateNodeStatement.setLong(prmIndex++, tileCalculator.calculateTile(node.getLatitude(), node.getLongitude()));
            updateNodeStatement.setLong(prmIndex++, node.getId());
            updateNodeStatement.setInt(prmIndex++, node.getVersion());
            updateNodeStatement.execute();
        } catch (SQLException e) {
            throw new OsmosisRuntimeException("Unable to update history node with id=" + node.getId() + ".", e);
        }
    } else {
        // Insert the new node into the history table.
        try {
            prmIndex = 1;
            insertNodeStatement.setLong(prmIndex++, node.getId());
            insertNodeStatement.setInt(prmIndex++, node.getVersion());
            insertNodeStatement.setTimestamp(prmIndex++, new Timestamp(node.getTimestamp().getTime()));
            insertNodeStatement.setBoolean(prmIndex++, visible);
            insertNodeStatement.setLong(prmIndex++, node.getChangesetId());
            insertNodeStatement.setInt(prmIndex++, FixedPrecisionCoordinateConvertor.convertToFixed(node.getLatitude()));
            insertNodeStatement.setInt(prmIndex++, FixedPrecisionCoordinateConvertor.convertToFixed(node.getLongitude()));
            insertNodeStatement.setLong(prmIndex++, tileCalculator.calculateTile(node.getLatitude(), node.getLongitude()));
            insertNodeStatement.execute();
        } catch (SQLException e) {
            throw new OsmosisRuntimeException("Unable to insert history node with id=" + node.getId() + ".", e);
        }
    }
    // Insert the tags of the new node into the history table.
    for (Tag tag : node.getTags()) {
        try {
            prmIndex = 1;
            insertNodeTagStatement.setLong(prmIndex++, node.getId());
            insertNodeTagStatement.setInt(prmIndex++, node.getVersion());
            insertNodeTagStatement.setString(prmIndex++, tag.getKey());
            insertNodeTagStatement.setString(prmIndex++, tag.getValue());
            insertNodeTagStatement.execute();
        } catch (SQLException e) {
            throw new OsmosisRuntimeException("Unable to insert history node tag with id=" + node.getId() + " and key=(" + tag.getKey() + ").", e);
        }
    }
    if (populateCurrentTables) {
        // Delete the existing node tags from the current table.
        try {
            deleteNodeTagCurrentStatement.setLong(1, node.getId());
            deleteNodeTagCurrentStatement.execute();
        } catch (SQLException e) {
            throw new OsmosisRuntimeException("Unable to delete current node tags with id=" + node.getId() + ".", e);
        }
        // Update the node if it already exists in the current table, otherwise insert it.
        try {
            exists = checkIfEntityExists(selectNodeCurrentCountStatement, node.getId());
        } catch (SQLException e) {
            throw new OsmosisRuntimeException("Unable to check if current node with id=" + node.getId() + " exists.", e);
        }
        if (exists) {
            // Update the node in the current table.
            try {
                prmIndex = 1;
                updateNodeCurrentStatement.setInt(prmIndex++, node.getVersion());
                updateNodeCurrentStatement.setTimestamp(prmIndex++, new Timestamp(node.getTimestamp().getTime()));
                updateNodeCurrentStatement.setBoolean(prmIndex++, visible);
                updateNodeCurrentStatement.setLong(prmIndex++, node.getChangesetId());
                updateNodeCurrentStatement.setInt(prmIndex++, FixedPrecisionCoordinateConvertor.convertToFixed(node.getLatitude()));
                updateNodeCurrentStatement.setInt(prmIndex++, FixedPrecisionCoordinateConvertor.convertToFixed(node.getLongitude()));
                updateNodeCurrentStatement.setLong(prmIndex++, tileCalculator.calculateTile(node.getLatitude(), node.getLongitude()));
                updateNodeCurrentStatement.setLong(prmIndex++, node.getId());
                updateNodeCurrentStatement.execute();
            } catch (SQLException e) {
                throw new OsmosisRuntimeException("Unable to update current node with id=" + node.getId() + ".", e);
            }
        } else {
            // Insert the new node into the current table.
            try {
                prmIndex = 1;
                insertNodeCurrentStatement.setLong(prmIndex++, node.getId());
                insertNodeCurrentStatement.setInt(prmIndex++, node.getVersion());
                insertNodeCurrentStatement.setTimestamp(prmIndex++, new Timestamp(node.getTimestamp().getTime()));
                insertNodeCurrentStatement.setBoolean(prmIndex++, visible);
                insertNodeCurrentStatement.setLong(prmIndex++, node.getChangesetId());
                insertNodeCurrentStatement.setInt(prmIndex++, FixedPrecisionCoordinateConvertor.convertToFixed(node.getLatitude()));
                insertNodeCurrentStatement.setInt(prmIndex++, FixedPrecisionCoordinateConvertor.convertToFixed(node.getLongitude()));
                insertNodeCurrentStatement.setLong(prmIndex++, tileCalculator.calculateTile(node.getLatitude(), node.getLongitude()));
                insertNodeCurrentStatement.execute();
            } catch (SQLException e) {
                throw new OsmosisRuntimeException("Unable to insert current node with id=" + node.getId() + ".", e);
            }
        }
        // Insert the tags of the new node into the current table.
        for (Tag tag : node.getTags()) {
            try {
                prmIndex = 1;
                insertNodeTagCurrentStatement.setLong(prmIndex++, node.getId());
                insertNodeTagCurrentStatement.setString(prmIndex++, tag.getKey());
                insertNodeTagCurrentStatement.setString(prmIndex++, tag.getValue());
                insertNodeTagCurrentStatement.execute();
            } catch (SQLException e) {
                throw new OsmosisRuntimeException("Unable to insert current node tag with id=" + node.getId() + " and key=(" + tag.getKey() + ").", e);
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) Timestamp(java.sql.Timestamp) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException)

Aggregations

Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)66 SEQUENCE (org.mozilla.jss.asn1.SEQUENCE)23 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)23 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)17 IOException (java.io.IOException)16 Test (org.junit.Test)16 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)16 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)16 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)12 Date (java.util.Date)10 RelationMember (org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)10 OsmosisRuntimeException (org.openstreetmap.osmosis.core.OsmosisRuntimeException)9 Relation (org.openstreetmap.osmosis.core.domain.v0_6.Relation)9 Tag (org.mozilla.jss.asn1.Tag)7 SQLException (java.sql.SQLException)6 ArrayList (java.util.ArrayList)6 EXPLICIT (org.mozilla.jss.asn1.EXPLICIT)6 Osmformat (crosby.binary.Osmformat)5 NodeContainer (org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)5 Point (com.vividsolutions.jts.geom.Point)4