Search in sources :

Example 96 with Tag

use of org.hl7.cql_annotations.r1.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 97 with Tag

use of org.hl7.cql_annotations.r1.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 98 with Tag

use of org.hl7.cql_annotations.r1.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)

Example 99 with Tag

use of org.hl7.cql_annotations.r1.Tag in project osmosis by openstreetmap.

the class EntityDao method getEntityHistory.

private ReleasableIterator<EntityHistory<T>> getEntityHistory(String selectedEntityStatement, MapSqlParameterSource parameterSource) {
    ReleasableContainer releasableContainer;
    releasableContainer = new ReleasableContainer();
    try {
        ReleasableIterator<EntityHistory<T>> entityIterator;
        ReleasableIterator<DbFeatureHistory<DbFeature<Tag>>> tagIterator;
        List<FeatureHistoryPopulator<T, ?, ?>> featurePopulators;
        EntityHistoryReader<T> entityHistoryReader;
        entityIterator = releasableContainer.add(getFeaturelessEntityHistory(selectedEntityStatement, parameterSource));
        tagIterator = releasableContainer.add(getTagHistory(selectedEntityStatement, parameterSource));
        featurePopulators = getFeatureHistoryPopulators(selectedEntityStatement, parameterSource);
        for (FeatureHistoryPopulator<T, ?, ?> featurePopulator : featurePopulators) {
            releasableContainer.add(featurePopulator);
        }
        entityHistoryReader = new EntityHistoryReader<T>(entityIterator, tagIterator, featurePopulators);
        // The sources are now all attached to the history reader so we don't want to release
        // them in the finally block.
        releasableContainer.clear();
        return entityHistoryReader;
    } finally {
        releasableContainer.close();
    }
}
Also used : ReleasableContainer(org.openstreetmap.osmosis.core.lifecycle.ReleasableContainer) DbFeatureHistory(org.openstreetmap.osmosis.core.database.DbFeatureHistory) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 100 with Tag

use of org.hl7.cql_annotations.r1.Tag in project osmosis by openstreetmap.

the class EntityDao method getTagHistory.

private ReleasableIterator<DbFeatureHistory<DbFeature<Tag>>> getTagHistory(String selectedEntityStatement, MapSqlParameterSource parameterSource) {
    FileBasedSort<DbFeatureHistory<DbFeature<Tag>>> sortingStore = new FileBasedSort<DbFeatureHistory<DbFeature<Tag>>>(new SingleClassObjectSerializationFactory(DbFeatureHistory.class), new DbFeatureHistoryComparator<Tag>(), true);
    try {
        String sql;
        SortingStoreRowMapperListener<DbFeatureHistory<DbFeature<Tag>>> storeListener;
        DbFeatureHistoryRowMapper<DbFeature<Tag>> dbFeatureHistoryRowMapper;
        DbFeatureRowMapper<Tag> dbFeatureRowMapper;
        TagRowMapper tagRowMapper;
        ReleasableIterator<DbFeatureHistory<DbFeature<Tag>>> resultIterator;
        sql = "SELECT et." + entityName + "_id AS id, et.k, et.v, et.version" + " FROM " + entityName + "_tags et" + " INNER JOIN " + selectedEntityStatement + " t ON et." + entityName + "_id = t." + entityName + "_id AND et.version = t.version";
        LOG.log(Level.FINER, "Tag history query: " + sql);
        // Sends all received data into the object store.
        storeListener = new SortingStoreRowMapperListener<DbFeatureHistory<DbFeature<Tag>>>(sortingStore);
        // Retrieves the version information associated with the tag.
        dbFeatureHistoryRowMapper = new DbFeatureHistoryRowMapper<DbFeature<Tag>>(storeListener);
        // Retrieves the entity information associated with the tag.
        dbFeatureRowMapper = new DbFeatureRowMapper<Tag>(dbFeatureHistoryRowMapper);
        // Retrieves the basic tag information.
        tagRowMapper = new TagRowMapper(dbFeatureRowMapper);
        // Perform the query passing the row mapper chain to process rows in a streamy fashion.
        namedParamJdbcTemplate.query(sql, parameterSource, tagRowMapper);
        // Open a iterator on the store that will release the store upon completion.
        resultIterator = new StoreReleasingIterator<DbFeatureHistory<DbFeature<Tag>>>(sortingStore.iterate(), sortingStore);
        // The store itself shouldn't be released now that it has been attached to the iterator.
        sortingStore = null;
        return resultIterator;
    } finally {
        if (sortingStore != null) {
            sortingStore.close();
        }
    }
}
Also used : SingleClassObjectSerializationFactory(org.openstreetmap.osmosis.core.store.SingleClassObjectSerializationFactory) DbFeatureHistory(org.openstreetmap.osmosis.core.database.DbFeatureHistory) DbFeature(org.openstreetmap.osmosis.core.database.DbFeature) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) FileBasedSort(org.openstreetmap.osmosis.core.sort.common.FileBasedSort)

Aggregations

Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)66 Test (org.junit.Test)26 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 ArrayList (java.util.ArrayList)16 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)16 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)16 Date (java.util.Date)12 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)12 Coding (org.hl7.fhir.r4.model.Coding)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 Test (org.junit.jupiter.api.Test)7 SQLException (java.sql.SQLException)6 UUID (java.util.UUID)6 LocationTag (org.openmrs.LocationTag)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Osmformat (crosby.binary.Osmformat)5