mil.nga.geopackage.metadata.Metadata Java Examples

The following examples show how to use mil.nga.geopackage.metadata.Metadata. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetadataExtension.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Remove all trace of the extension
 * 
 * @since 3.2.0
 */
public void removeExtension() {

	if (geoPackage.isTable(MetadataReference.TABLE_NAME)) {
		geoPackage.dropTable(MetadataReference.TABLE_NAME);
	}

	if (geoPackage.isTable(Metadata.TABLE_NAME)) {
		geoPackage.dropTable(Metadata.TABLE_NAME);
	}

	try {
		if (extensionsDao.isTableExists()) {
			extensionsDao.deleteByExtension(EXTENSION_NAME);
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to delete Metadata extension. GeoPackage: "
						+ geoPackage.getName(),
				e);
	}

}
 
Example #2
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean createMetadataTable() {
	verifyWritable();

	boolean created = false;
	MetadataDao dao = getMetadataDao();
	try {
		if (!dao.isTableExists()) {
			created = tableCreator.createMetadata() > 0;
			if (created) {
				// Create the metadata extension record
				MetadataExtension metadataExtension = new MetadataExtension(
						this);
				metadataExtension.getOrCreate();
			}
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to check if " + Metadata.class.getSimpleName()
						+ " table exists and create it",
				e);
	}
	return created;
}
 
Example #3
Source File: GeoPackageDaoManager.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Unregister all GeoPackage DAO with the connection source
 * 
 * @param connectionSource
 *            connection source
 */
public static void unregisterDaos(ConnectionSource connectionSource) {
	// TODO when ormlite-core version > 5.1 is released, replace with:
	// "DaoManager.unregisterDaos(connectionSource);"
	// See https://github.com/j256/ormlite-core/pull/149
	unregisterDao(connectionSource, Contents.class,
			SpatialReferenceSystem.class,
			SpatialReferenceSystemSfSql.class,
			SpatialReferenceSystemSqlMm.class, Extensions.class,
			GriddedCoverage.class, GriddedTile.class, GeometryIndex.class,
			TableIndex.class, FeatureTileLink.class,
			ExtendedRelation.class, TileScaling.class,
			GeometryColumns.class, GeometryColumnsSfSql.class,
			GeometryColumnsSqlMm.class, Metadata.class,
			MetadataReference.class, DataColumns.class,
			DataColumnConstraints.class, TileMatrix.class,
			TileMatrixSet.class, ContentsId.class);
}
 
Example #4
Source File: MetadataUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	MetadataDao dao = geoPackage.getMetadataDao();

	if (dao.isTableExists()) {
		// Get current count
		long count = dao.countOf();

		long id = 12345;
		MetadataScopeType scopeType = MetadataScopeType.SOFTWARE;
		String standardUri = "https://www.nga.mil";
		String mimeType = "text/xml";
		String metadataText = "Create metadata text";

		// Create new metadata
		Metadata metadata = new Metadata();
		metadata.setId(id);
		metadata.setMetadataScope(scopeType);
		metadata.setStandardUri(standardUri);
		metadata.setMimeType(mimeType);
		metadata.setMetadata(metadataText);
		dao.create(metadata);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);

		// Verify saved metadata
		Metadata queryMetadata = dao.queryForId(id);
		TestCase.assertEquals(id, queryMetadata.getId());
		TestCase.assertEquals(scopeType, queryMetadata.getMetadataScope());
		TestCase.assertEquals(standardUri, queryMetadata.getStandardUri());
		TestCase.assertEquals(mimeType, queryMetadata.getMimeType());
		TestCase.assertEquals(metadataText, queryMetadata.getMetadata());
	}

}
 
Example #5
Source File: MetadataExtension.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get or create the extension
 * 
 * @return extensions
 */
public List<Extensions> getOrCreate() {

	List<Extensions> extensions = new ArrayList<>();

	extensions.add(getOrCreate(EXTENSION_NAME, Metadata.TABLE_NAME, null,
			DEFINITION, ExtensionScopeType.READ_WRITE));
	extensions.add(getOrCreate(EXTENSION_NAME, MetadataReference.TABLE_NAME,
			null, DEFINITION, ExtensionScopeType.READ_WRITE));

	return extensions;
}
 
Example #6
Source File: MetadataUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	MetadataDao dao = geoPackage.getMetadataDao();

	if (dao.isTableExists()) {
		// Get current count
		long count = dao.countOf();

		long id = 12345;
		MetadataScopeType scopeType = MetadataScopeType.SOFTWARE;
		String standardUri = "https://www.nga.mil";
		String mimeType = "text/xml";
		String metadataText = "Create metadata text";

		// Create new metadata
		Metadata metadata = new Metadata();
		metadata.setId(id);
		metadata.setMetadataScope(scopeType);
		metadata.setStandardUri(standardUri);
		metadata.setMimeType(mimeType);
		metadata.setMetadata(metadataText);
		dao.create(metadata);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);

		// Verify saved metadata
		Metadata queryMetadata = dao.queryForId(id);
		TestCase.assertEquals(id, queryMetadata.getId());
		TestCase.assertEquals(scopeType, queryMetadata.getMetadataScope());
		TestCase.assertEquals(standardUri, queryMetadata.getStandardUri());
		TestCase.assertEquals(mimeType, queryMetadata.getMimeType());
		TestCase.assertEquals(metadataText, queryMetadata.getMetadata());
	}

}
 
Example #7
Source File: MetadataReferenceUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	MetadataReferenceDao dao = geoPackage.getMetadataReferenceDao();
	MetadataDao metadataDao = geoPackage.getMetadataDao();

	if (dao.isTableExists()) {
		// Get current count
		long count = dao.countOf();

		long fileId = 5555;
		long parentId = 5556;

		// Create new metadata
		Metadata metadata = new Metadata();
		metadata.setId(fileId);
		metadata.setMetadataScope(MetadataScopeType.FEATURE);
		metadata.setStandardUri("https://www.nga.mil");
		metadata.setMimeType("text/xml");
		metadata.setMetadata("Create metadata text");
		metadataDao.create(metadata);

		Metadata metadata2 = new Metadata();
		metadata2.setId(parentId);
		metadata2.setMetadataScope(MetadataScopeType.FEATURE_TYPE);
		metadata2.setStandardUri("https://www.nga.mil");
		metadata2.setMimeType("text/xml");
		metadata2.setMetadata("Create metadata text 2");
		metadataDao.create(metadata2);

		ReferenceScopeType scopeType = ReferenceScopeType.ROW;
		String tableName = "CREATE_TABLE_NAME";
		long rowIdValue = 50;
		Date timestamp = new Date();

		MetadataReference reference = new MetadataReference();
		reference.setReferenceScope(scopeType);
		reference.setTableName(tableName);
		reference.setRowIdValue(rowIdValue);
		reference.setTimestamp(timestamp);
		reference.setMetadata(metadata);
		reference.setParentMetadata(metadata2);
		dao.create(reference);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);

		// Verify saved metadata
		List<MetadataReference> queryMetadataReferenceList = dao
				.queryByMetadata(fileId, parentId);
		TestCase.assertNotNull(queryMetadataReferenceList);
		TestCase.assertEquals(1, queryMetadataReferenceList.size());
		MetadataReference queryMetadataReference = queryMetadataReferenceList
				.get(0);
		TestCase.assertEquals(scopeType,
				queryMetadataReference.getReferenceScope());
		TestCase.assertEquals(tableName,
				queryMetadataReference.getTableName());
		TestCase.assertNull(queryMetadataReference.getColumnName());
		TestCase.assertEquals(rowIdValue, queryMetadataReference
				.getRowIdValue().longValue());
		TestCase.assertEquals(timestamp,
				queryMetadataReference.getTimestamp());
		TestCase.assertEquals(fileId, queryMetadataReference.getFileId());
		TestCase.assertEquals(parentId, queryMetadataReference
				.getParentId().longValue());
		TestCase.assertNotNull(queryMetadataReference.getMetadata());
		TestCase.assertNotNull(queryMetadataReference.getParentMetadata());
	}

}
 
Example #8
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public MetadataDao getMetadataDao() {
	return createDao(Metadata.class);
}
 
Example #9
Source File: MetadataReference.java    From geopackage-core-java with MIT License 4 votes vote down vote up
public Metadata getMetadata() {
	return metadata;
}
 
Example #10
Source File: MetadataReference.java    From geopackage-core-java with MIT License 4 votes vote down vote up
public void setMetadata(Metadata metadata) {
	this.metadata = metadata;
	fileId = metadata != null ? metadata.getId() : -1;
}
 
Example #11
Source File: MetadataReference.java    From geopackage-core-java with MIT License 4 votes vote down vote up
public Metadata getParentMetadata() {
	return parentMetadata;
}
 
Example #12
Source File: MetadataReference.java    From geopackage-core-java with MIT License 4 votes vote down vote up
public void setParentMetadata(Metadata parentMetadata) {
	this.parentMetadata = parentMetadata;
	parentId = parentMetadata != null ? parentMetadata.getId() : -1;
}
 
Example #13
Source File: MetadataReferenceUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	MetadataReferenceDao dao = geoPackage.getMetadataReferenceDao();
	MetadataDao metadataDao = geoPackage.getMetadataDao();

	if (dao.isTableExists()) {
		// Get current count
		long count = dao.countOf();

		long fileId = 5555;
		long parentId = 5556;

		// Create new metadata
		Metadata metadata = new Metadata();
		metadata.setId(fileId);
		metadata.setMetadataScope(MetadataScopeType.FEATURE);
		metadata.setStandardUri("https://www.nga.mil");
		metadata.setMimeType("text/xml");
		metadata.setMetadata("Create metadata text");
		metadataDao.create(metadata);

		Metadata metadata2 = new Metadata();
		metadata2.setId(parentId);
		metadata2.setMetadataScope(MetadataScopeType.FEATURE_TYPE);
		metadata2.setStandardUri("https://www.nga.mil");
		metadata2.setMimeType("text/xml");
		metadata2.setMetadata("Create metadata text 2");
		metadataDao.create(metadata2);

		ReferenceScopeType scopeType = ReferenceScopeType.ROW;
		String tableName = "CREATE_TABLE_NAME";
		long rowIdValue = 50;
		Date timestamp = new Date();

		MetadataReference reference = new MetadataReference();
		reference.setReferenceScope(scopeType);
		reference.setTableName(tableName);
		reference.setRowIdValue(rowIdValue);
		reference.setTimestamp(timestamp);
		reference.setMetadata(metadata);
		reference.setParentMetadata(metadata2);
		dao.create(reference);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);

		// Verify saved metadata
		List<MetadataReference> queryMetadataReferenceList = dao
				.queryByMetadata(fileId, parentId);
		TestCase.assertNotNull(queryMetadataReferenceList);
		TestCase.assertEquals(1, queryMetadataReferenceList.size());
		MetadataReference queryMetadataReference = queryMetadataReferenceList
				.get(0);
		TestCase.assertEquals(scopeType,
				queryMetadataReference.getReferenceScope());
		TestCase.assertEquals(tableName,
				queryMetadataReference.getTableName());
		TestCase.assertNull(queryMetadataReference.getColumnName());
		TestCase.assertEquals(rowIdValue, queryMetadataReference
				.getRowIdValue().longValue());
		TestCase.assertEquals(timestamp,
				queryMetadataReference.getTimestamp());
		TestCase.assertEquals(fileId, queryMetadataReference.getFileId());
		TestCase.assertEquals(parentId, queryMetadataReference
				.getParentId().longValue());
		TestCase.assertNotNull(queryMetadataReference.getMetadata());
		TestCase.assertNotNull(queryMetadataReference.getParentMetadata());
	}

}