Search in sources :

Example 26 with Tag

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

the class PbfBlobDecoder method buildTags.

private void buildTags(CommonEntityData entityData, List<Integer> keys, List<Integer> values, PbfFieldDecoder fieldDecoder) {
    Collection<Tag> tags = entityData.getTags();
    // Ensure parallel lists are of equal size.
    if (keys.size() != values.size()) {
        throw new OsmosisRuntimeException("Number of tag keys (" + keys.size() + ") and tag values (" + values.size() + ") don't match");
    }
    Iterator<Integer> keyIterator = keys.iterator();
    Iterator<Integer> valueIterator = values.iterator();
    while (keyIterator.hasNext()) {
        String key = fieldDecoder.decodeString(keyIterator.next());
        String value = fieldDecoder.decodeString(valueIterator.next());
        Tag tag = new Tag(key, value);
        tags.add(tag);
    }
}
Also used : Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) OsmosisRuntimeException(org.openstreetmap.osmosis.core.OsmosisRuntimeException)

Example 27 with Tag

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

the class CopyFilesetBuilder method process.

/**
 * {@inheritDoc}
 */
public void process(WayContainer wayContainer) {
    Way way;
    int sequenceId;
    way = wayContainer.getEntity();
    // Ignore ways with a single node because they can't be loaded into postgis.
    if (way.getWayNodes().size() > 1) {
        wayWriter.writeField(way.getId());
        wayWriter.writeField(way.getVersion());
        wayWriter.writeField(way.getUser().getId());
        wayWriter.writeField(way.getTimestamp());
        wayWriter.writeField(way.getChangesetId());
        if (enableBboxBuilder) {
            wayWriter.writeField(wayGeometryBuilder.createWayBbox(way));
        }
        if (enableLinestringBuilder) {
            wayWriter.writeField(wayGeometryBuilder.createWayLinestring(way));
        }
        wayWriter.endRecord();
        for (Tag tag : way.getTags()) {
            wayTagWriter.writeField(way.getId());
            wayTagWriter.writeField(tag.getKey());
            wayTagWriter.writeField(tag.getValue());
            wayTagWriter.endRecord();
        }
        sequenceId = 0;
        for (WayNode wayNode : way.getWayNodes()) {
            wayNodeWriter.writeField(way.getId());
            wayNodeWriter.writeField(wayNode.getNodeId());
            wayNodeWriter.writeField(sequenceId++);
            wayNodeWriter.endRecord();
        }
    }
}
Also used : WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way)

Example 28 with Tag

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

the class EntityDao method addTags.

/**
 * Adds the specified tags to the database.
 *
 * @param entityId
 *            The identifier of the entity to add these features to.
 * @param tags
 *            The features to add.
 */
private void addTags(long entityId, Collection<Tag> tags) {
    Collection<DbFeature<Tag>> dbList;
    dbList = new ArrayList<DbFeature<Tag>>(tags.size());
    for (Tag tag : tags) {
        dbList.add(new DbFeature<Tag>(entityId, tag));
    }
    tagDao.addAll(dbList);
}
Also used : DbFeature(org.openstreetmap.osmosis.core.database.DbFeature) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 29 with Tag

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

the class TagRowMapper method processRow.

/**
 * {@inheritDoc}
 */
@Override
public void processRow(ResultSet resultSet) throws SQLException {
    String key;
    String value;
    Tag tag;
    key = resultSet.getString("k");
    value = resultSet.getString("v");
    tag = new Tag(key, value);
    listener.process(tag, resultSet);
}
Also used : Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 30 with Tag

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

the class ChangeWriter method write.

/**
 * Writes the specified relation change to the database.
 *
 * @param relation The relation to be written.
 * @param action The change to be applied.
 */
public void write(Relation relation, ChangeAction action) {
    boolean visible;
    boolean exists;
    int prmIndex;
    List<RelationMember> relationMemberList;
    assertEntityHasTimestamp(relation);
    // Add or update the user in the database.
    userManager.addOrUpdateUser(relation.getUser());
    // Create the changeset in the database.
    changesetManager.addChangesetIfRequired(relation.getChangesetId(), relation.getUser());
    relationMemberList = relation.getMembers();
    // If this is a deletion, the entity is not visible.
    visible = !action.equals(ChangeAction.Delete);
    // Create the prepared statements for relation creation if necessary.
    if (insertRelationStatement == null) {
        insertRelationStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_RELATION));
        updateRelationStatement = statementContainer.add(dbCtx.prepareStatement(UPDATE_SQL_RELATION));
        selectRelationCountStatement = statementContainer.add(dbCtx.prepareStatement(SELECT_SQL_RELATION_COUNT));
        insertRelationCurrentStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_RELATION_CURRENT));
        updateRelationCurrentStatement = statementContainer.add(dbCtx.prepareStatement(UPDATE_SQL_RELATION_CURRENT));
        selectRelationCurrentCountStatement = statementContainer.add(dbCtx.prepareStatement(SELECT_SQL_RELATION_CURRENT_COUNT));
        insertRelationTagStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_RELATION_TAG));
        deleteRelationTagStatement = statementContainer.add(dbCtx.prepareStatement(DELETE_SQL_RELATION_TAG));
        insertRelationTagCurrentStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_RELATION_TAG_CURRENT));
        deleteRelationTagCurrentStatement = statementContainer.add(dbCtx.prepareStatement(DELETE_SQL_RELATION_TAG_CURRENT));
        switch(dbCtx.getDatabaseType()) {
            case POSTGRESQL:
                insertRelationMemberStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_RELATION_MEMBER_PGSQL));
                break;
            case MYSQL:
                insertRelationMemberStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_RELATION_MEMBER_MYSQL));
                break;
            default:
                throw new OsmosisRuntimeException("Unknown database type " + dbCtx.getDatabaseType() + ".");
        }
        deleteRelationMemberStatement = statementContainer.add(dbCtx.prepareStatement(DELETE_SQL_RELATION_MEMBER));
        switch(dbCtx.getDatabaseType()) {
            case POSTGRESQL:
                insertRelationMemberCurrentStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_RELATION_MEMBER_CURRENT_PGSQL));
                break;
            case MYSQL:
                insertRelationMemberCurrentStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_RELATION_MEMBER_CURRENT_MYSQL));
                break;
            default:
                throw new OsmosisRuntimeException("Unknown database type " + dbCtx.getDatabaseType() + ".");
        }
        deleteRelationMemberCurrentStatement = statementContainer.add(dbCtx.prepareStatement(DELETE_SQL_RELATION_MEMBER_CURRENT));
    }
    // Remove the existing tags of the relation history item.
    try {
        prmIndex = 1;
        deleteRelationTagStatement.setLong(prmIndex++, relation.getId());
        deleteRelationTagStatement.setInt(prmIndex++, relation.getVersion());
        deleteRelationTagStatement.execute();
    } catch (SQLException e) {
        throw new OsmosisRuntimeException("Unable to delete relation history tags for relation with id=" + relation.getId() + ".", e);
    }
    // Remove the existing relation members of the relation history item.
    try {
        prmIndex = 1;
        deleteRelationMemberStatement.setLong(prmIndex++, relation.getId());
        deleteRelationMemberStatement.setInt(prmIndex++, relation.getVersion());
        deleteRelationMemberStatement.execute();
    } catch (SQLException e) {
        throw new OsmosisRuntimeException("Unable to delete relation history members for relation with id=" + relation.getId() + ".", e);
    }
    // Update the relation if it already exists in the history table, otherwise insert it.
    try {
        exists = checkIfEntityHistoryExists(selectRelationCountStatement, relation.getId(), relation.getVersion());
    } catch (SQLException e) {
        throw new OsmosisRuntimeException("Unable to check if current relation with id=" + relation.getId() + " exists.", e);
    }
    if (exists) {
        // Update the relation in the history table.
        try {
            prmIndex = 1;
            updateRelationStatement.setTimestamp(prmIndex++, new Timestamp(relation.getTimestamp().getTime()));
            updateRelationStatement.setBoolean(prmIndex++, visible);
            updateRelationStatement.setLong(prmIndex++, relation.getChangesetId());
            updateRelationStatement.setLong(prmIndex++, relation.getId());
            updateRelationStatement.setInt(prmIndex++, relation.getVersion());
            updateRelationStatement.execute();
        } catch (SQLException e) {
            throw new OsmosisRuntimeException("Unable to update history relation with id=" + relation.getId() + ".", e);
        }
    } else {
        // Insert the new relation into the history table.
        try {
            prmIndex = 1;
            insertRelationStatement.setLong(prmIndex++, relation.getId());
            insertRelationStatement.setInt(prmIndex++, relation.getVersion());
            insertRelationStatement.setTimestamp(prmIndex++, new Timestamp(relation.getTimestamp().getTime()));
            insertRelationStatement.setBoolean(prmIndex++, visible);
            insertRelationStatement.setLong(prmIndex++, relation.getChangesetId());
            insertRelationStatement.execute();
        } catch (SQLException e) {
            throw new OsmosisRuntimeException("Unable to insert history relation with id=" + relation.getId() + ".", e);
        }
    }
    // Insert the tags of the new relation into the history table.
    for (Tag tag : relation.getTags()) {
        try {
            prmIndex = 1;
            insertRelationTagStatement.setLong(prmIndex++, relation.getId());
            insertRelationTagStatement.setInt(prmIndex++, relation.getVersion());
            insertRelationTagStatement.setString(prmIndex++, tag.getKey());
            insertRelationTagStatement.setString(prmIndex++, tag.getValue());
            insertRelationTagStatement.execute();
        } catch (SQLException e) {
            throw new OsmosisRuntimeException("Unable to insert history relation tag with id=" + relation.getId() + " and key=(" + tag.getKey() + ").", e);
        }
    }
    // Insert the members of the new relation into the history table.
    for (int i = 0; i < relationMemberList.size(); i++) {
        RelationMember relationMember;
        relationMember = relationMemberList.get(i);
        try {
            prmIndex = 1;
            insertRelationMemberStatement.setLong(prmIndex++, relation.getId());
            insertRelationMemberStatement.setInt(prmIndex++, relation.getVersion());
            insertRelationMemberStatement.setString(prmIndex++, memberTypeRenderer.render(relationMember.getMemberType()));
            insertRelationMemberStatement.setLong(prmIndex++, relationMember.getMemberId());
            insertRelationMemberStatement.setString(prmIndex++, relationMember.getMemberRole());
            insertRelationMemberStatement.setInt(prmIndex++, i + 1);
            insertRelationMemberStatement.execute();
        } catch (SQLException e) {
            throw new OsmosisRuntimeException("Unable to insert history relation member with relation id=" + relation.getId() + ", member type=" + relationMember.getMemberId() + " and member id=" + relationMember.getMemberId() + ".", e);
        }
    }
    if (populateCurrentTables) {
        // Delete the existing relation tags from the current table.
        try {
            deleteRelationTagCurrentStatement.setLong(1, relation.getId());
            deleteRelationTagCurrentStatement.execute();
        } catch (SQLException e) {
            throw new OsmosisRuntimeException("Unable to delete current relation tags with id=" + relation.getId() + ".", e);
        }
        // Delete the existing relation members from the current table.
        try {
            deleteRelationMemberCurrentStatement.setLong(1, relation.getId());
            deleteRelationMemberCurrentStatement.execute();
        } catch (SQLException e) {
            throw new OsmosisRuntimeException("Unable to delete current relation members with id=" + relation.getId() + ".", e);
        }
        // Update the relation if it already exists in the current table, otherwise insert it.
        try {
            exists = checkIfEntityExists(selectRelationCurrentCountStatement, relation.getId());
        } catch (SQLException e) {
            throw new OsmosisRuntimeException("Unable to check if current relation with id=" + relation.getId() + " exists.", e);
        }
        if (exists) {
            // Update the relation in the current table.
            try {
                prmIndex = 1;
                updateRelationCurrentStatement.setInt(prmIndex++, relation.getVersion());
                updateRelationCurrentStatement.setTimestamp(prmIndex++, new Timestamp(relation.getTimestamp().getTime()));
                updateRelationCurrentStatement.setBoolean(prmIndex++, visible);
                updateRelationCurrentStatement.setLong(prmIndex++, relation.getChangesetId());
                updateRelationCurrentStatement.setLong(prmIndex++, relation.getId());
                updateRelationCurrentStatement.execute();
            } catch (SQLException e) {
                throw new OsmosisRuntimeException("Unable to update current relation with id=" + relation.getId() + ".", e);
            }
        } else {
            // Insert the new node into the current table.
            try {
                prmIndex = 1;
                insertRelationCurrentStatement.setLong(prmIndex++, relation.getId());
                insertRelationCurrentStatement.setInt(prmIndex++, relation.getVersion());
                insertRelationCurrentStatement.setTimestamp(prmIndex++, new Timestamp(relation.getTimestamp().getTime()));
                insertRelationCurrentStatement.setBoolean(prmIndex++, visible);
                insertRelationCurrentStatement.setLong(prmIndex++, relation.getChangesetId());
                insertRelationCurrentStatement.execute();
            } catch (SQLException e) {
                throw new OsmosisRuntimeException("Unable to insert current relation with id=" + relation.getId() + ".", e);
            }
        }
        // Insert the tags of the new relation into the current table.
        for (Tag tag : relation.getTags()) {
            try {
                prmIndex = 1;
                insertRelationTagCurrentStatement.setLong(prmIndex++, relation.getId());
                insertRelationTagCurrentStatement.setString(prmIndex++, tag.getKey());
                insertRelationTagCurrentStatement.setString(prmIndex++, tag.getValue());
                insertRelationTagCurrentStatement.execute();
            } catch (SQLException e) {
                throw new OsmosisRuntimeException("Unable to insert current relation tag with id=" + relation.getId() + " and key=(" + tag.getKey() + ").", e);
            }
        }
        // Insert the members of the new relation into the current table.
        for (int i = 0; i < relationMemberList.size(); i++) {
            RelationMember relationMember;
            relationMember = relationMemberList.get(i);
            try {
                prmIndex = 1;
                insertRelationMemberCurrentStatement.setLong(prmIndex++, relation.getId());
                insertRelationMemberCurrentStatement.setString(prmIndex++, memberTypeRenderer.render(relationMember.getMemberType()));
                insertRelationMemberCurrentStatement.setLong(prmIndex++, relationMember.getMemberId());
                insertRelationMemberCurrentStatement.setString(prmIndex++, relationMember.getMemberRole());
                insertRelationMemberCurrentStatement.setInt(prmIndex++, i + 1);
                insertRelationMemberCurrentStatement.execute();
            } catch (SQLException e) {
                throw new OsmosisRuntimeException("Unable to insert current relation member with relation id=" + relation.getId() + ", member type=" + relationMember.getMemberId() + " and member id=" + relationMember.getMemberId() + ".", e);
            }
        }
    }
}
Also used : RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember) 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