use of mil.nga.geopackage.extension.Extensions in project geopackage-android-map by ngageoint.
the class TestSetupTeardown method setUpCreateCommon.
/**
* Set up create common
*
* @param geoPackage
* @throws SQLException
*/
private static void setUpCreateCommon(GeoPackage geoPackage) throws SQLException {
// Metadata
MetadataExtension metadataExtension = new MetadataExtension(geoPackage);
metadataExtension.createMetadataTable();
MetadataDao metadataDao = metadataExtension.getMetadataDao();
Metadata metadata1 = new Metadata();
metadata1.setMetadataScope(MetadataScopeType.DATASET);
metadata1.setStandardUri("TEST_URI_1");
metadata1.setMimeType("text/xml");
metadata1.setMetadata("TEST METADATA 1");
metadataDao.create(metadata1);
Metadata metadata2 = new Metadata();
metadata2.setMetadataScope(MetadataScopeType.FEATURE_TYPE);
metadata2.setStandardUri("TEST_URI_2");
metadata2.setMimeType("text/xml");
metadata2.setMetadata("TEST METADATA 2");
metadataDao.create(metadata2);
Metadata metadata3 = new Metadata();
metadata3.setMetadataScope(MetadataScopeType.TILE);
metadata3.setStandardUri("TEST_URI_3");
metadata3.setMimeType("text/xml");
metadata3.setMetadata("TEST METADATA 3");
metadataDao.create(metadata3);
// Metadata Reference
metadataExtension.createMetadataReferenceTable();
MetadataReferenceDao metadataReferenceDao = metadataExtension.getMetadataReferenceDao();
MetadataReference reference1 = new MetadataReference();
reference1.setReferenceScope(ReferenceScopeType.GEOPACKAGE);
reference1.setTimestamp(new Date());
reference1.setMetadata(metadata1);
metadataReferenceDao.create(reference1);
MetadataReference reference2 = new MetadataReference();
reference2.setReferenceScope(ReferenceScopeType.TABLE);
reference2.setTableName("TEST_TABLE_NAME_2");
reference2.setTimestamp(new Date());
reference2.setMetadata(metadata2);
reference2.setParentMetadata(metadata1);
metadataReferenceDao.create(reference2);
MetadataReference reference3 = new MetadataReference();
reference3.setReferenceScope(ReferenceScopeType.ROW_COL);
reference3.setTableName("TEST_TABLE_NAME_3");
reference3.setColumnName("TEST_COLUMN_NAME_3");
reference3.setRowIdValue(5L);
reference3.setTimestamp(new Date());
reference3.setMetadata(metadata3);
metadataReferenceDao.create(reference3);
// Extensions
geoPackage.createExtensionsTable();
ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();
Extensions extensions1 = new Extensions();
extensions1.setTableName("TEST_TABLE_NAME_1");
extensions1.setColumnName("TEST_COLUMN_NAME_1");
extensions1.setExtensionName("nga", "test_extension_1");
extensions1.setDefinition("TEST DEFINITION 1");
extensions1.setScope(ExtensionScopeType.READ_WRITE);
extensionsDao.create(extensions1);
Extensions extensions2 = new Extensions();
extensions2.setTableName("TEST_TABLE_NAME_2");
extensions2.setExtensionName("nga", "test_extension_2");
extensions2.setDefinition("TEST DEFINITION 2");
extensions2.setScope(ExtensionScopeType.WRITE_ONLY);
extensionsDao.create(extensions2);
Extensions extensions3 = new Extensions();
extensions3.setExtensionName("nga", "test_extension_3");
extensions3.setDefinition("TEST DEFINITION 3");
extensions3.setScope(ExtensionScopeType.READ_WRITE);
extensionsDao.create(extensions3);
// Attributes
List<AttributesColumn> columns = new ArrayList<AttributesColumn>();
columns.add(AttributesColumn.createColumn(6, "test_text_limited", GeoPackageDataType.TEXT, 5L, false, null));
columns.add(AttributesColumn.createColumn(7, "test_blob_limited", GeoPackageDataType.BLOB, 7L, false, null));
columns.add(AttributesColumn.createColumn(1, "test_text", GeoPackageDataType.TEXT, false, ""));
columns.add(AttributesColumn.createColumn(2, "test_real", GeoPackageDataType.REAL, false, null));
columns.add(AttributesColumn.createColumn(3, "test_boolean", GeoPackageDataType.BOOLEAN, false, null));
columns.add(AttributesColumn.createColumn(4, "test_blob", GeoPackageDataType.BLOB, false, null));
columns.add(AttributesColumn.createColumn(5, "test_integer", GeoPackageDataType.INTEGER, false, null));
AttributesTable attributesTable = geoPackage.createAttributesTable(AttributesTableMetadata.create("test_attributes", columns));
TestCase.assertNotNull(attributesTable);
Contents attributesContents = attributesTable.getContents();
TestCase.assertNotNull(attributesContents);
TestCase.assertEquals(ContentsDataType.ATTRIBUTES, attributesContents.getDataType());
TestCase.assertEquals("test_attributes", attributesContents.getTableName());
TestCase.assertEquals(attributesContents.getTableName(), attributesTable.getTableName());
Metadata attributesMetadata = new Metadata();
attributesMetadata.setMetadataScope(MetadataScopeType.ATTRIBUTE_TYPE);
attributesMetadata.setStandardUri("ATTRIBUTES_TEST_URI");
attributesMetadata.setMimeType("text/plain");
attributesMetadata.setMetadata("ATTRIBUTES METADATA");
metadataDao.create(attributesMetadata);
AttributesDao attributesDao = geoPackage.getAttributesDao(attributesTable.getTableName());
for (int i = 0; i < 10; i++) {
AttributesRow newRow = attributesDao.newRow();
for (AttributesColumn column : attributesTable.getColumns()) {
if (!column.isPrimaryKey()) {
// Leave nullable columns null 20% of the time
if (!column.isNotNull()) {
if (Math.random() < 0.2) {
continue;
}
}
Object value = null;
switch(column.getDataType()) {
case TEXT:
String text = UUID.randomUUID().toString();
if (column.getMax() != null && text.length() > column.getMax()) {
text = text.substring(0, column.getMax().intValue());
}
value = text;
break;
case REAL:
case DOUBLE:
value = Math.random() * 5000.0;
break;
case BOOLEAN:
value = Math.random() < .5 ? false : true;
break;
case INTEGER:
case INT:
value = (int) (Math.random() * 500);
break;
case BLOB:
byte[] blob = UUID.randomUUID().toString().getBytes();
if (column.getMax() != null && blob.length > column.getMax()) {
byte[] blobLimited = new byte[column.getMax().intValue()];
ByteBuffer.wrap(blob, 0, column.getMax().intValue()).get(blobLimited);
blob = blobLimited;
}
value = blob;
break;
default:
throw new UnsupportedOperationException("Not implemented for data type: " + column.getDataType());
}
newRow.setValue(column.getName(), value);
}
}
long rowId = attributesDao.create(newRow);
MetadataReference attributesReference = new MetadataReference();
attributesReference.setReferenceScope(ReferenceScopeType.ROW);
attributesReference.setTableName(attributesTable.getTableName());
attributesReference.setRowIdValue(rowId);
attributesReference.setTimestamp(new Date());
attributesReference.setMetadata(attributesMetadata);
metadataReferenceDao.create(attributesReference);
}
}
Aggregations