use of org.eclipse.dataspaceconnector.dataloading.AssetEntry in project edc-showcase by microsoft.
the class CatalogDataseedingExtension method createAssets.
private List<AssetEntry> createAssets(String connectorId) {
var asset1 = Asset.Builder.newInstance().property("type", "file").name("test-document").id("test-document_" + connectorId).contentType("text/plain").version("1.0").build();
var dataAddress1 = DataAddress.Builder.newInstance().type("file").property("path", "/home/paul/Documents/").property("filename", "test-document.txt").build();
var asset2 = Asset.Builder.newInstance().property("type", "AzureStorage").name("test-document-az").id("test-document-az_" + connectorId).contentType("text/plain").version("1.0").build();
var dataAddress2 = DataAddress.Builder.newInstance().type("AzureStorage").property("account", "edcshowcasegpstorage").property("container", "src-container").property("blobname", "test-document.txt").build();
var asset3 = Asset.Builder.newInstance().property("type", "AzureStorage").name("schematic_drawing-az").id("schematic-drawing-az_" + connectorId).contentType("image/png").version("1.0").build();
var dataAddress3 = DataAddress.Builder.newInstance().type("AzureStorage").property("account", "edcshowcasegpstorage").property("container", "src-container").property("blobname", "complex_schematic_drawing.jpg").build();
var asset4 = Asset.Builder.newInstance().property("type", "http").name("demo-todos").id("demo-todos_" + connectorId).version("1.0").build();
var dataAddress4 = DataAddress.Builder.newInstance().type("http").property("targetUrl", "https://jsonplaceholder.typicode.com/todos/1").build();
var asset5 = Asset.Builder.newInstance().property("type", "http").name("demo-train-data").id("demo-train-data_" + connectorId).version("1.0").build();
var dataAddress5 = DataAddress.Builder.newInstance().type("http").property("targetUrl", "https://jsonplaceholder.typicode.com/todos/2").build();
return List.of(new AssetEntry(asset1, dataAddress1), new AssetEntry(asset2, dataAddress2), new AssetEntry(asset3, dataAddress3), new AssetEntry(asset4, dataAddress4), new AssetEntry(asset5, dataAddress5));
}
use of org.eclipse.dataspaceconnector.dataloading.AssetEntry in project DataSpaceConnector by eclipse-dataspaceconnector.
the class SqlAssetIndexTest method acceptEntry_exists.
@Test
@DisplayName("Accept an asset entry that already exists")
void acceptEntry_exists() {
var asset = getAsset("id1");
sqlAssetIndex.accept(new AssetEntry(asset, getDataAddress()));
assertThatThrownBy(() -> sqlAssetIndex.accept(asset, getDataAddress())).isInstanceOf(EdcPersistenceException.class).hasMessageContaining(String.format("Cannot persist. Asset with ID '%s' already exists.", asset.getId()));
}
use of org.eclipse.dataspaceconnector.dataloading.AssetEntry in project DataSpaceConnector by eclipse-dataspaceconnector.
the class SqlAssetIndexTest method acceptAssetEntry_doesNotExist.
@Test
@DisplayName("Accept an asset entry that doesn't exist yet")
void acceptAssetEntry_doesNotExist() {
var assetExpected = getAsset("id1");
sqlAssetIndex.accept(new AssetEntry(assetExpected, getDataAddress()));
try (var connection = getConnection()) {
var assetProperties = transactionContext.execute(() -> {
var assetCount = executeQuery(connection, sqlAssetIndex::mapRowCount, sqlAssetQueries.getSqlAssetCountByIdClause(), assetExpected.getId()).iterator().next();
if (assetCount <= 0) {
return null;
} else if (assetCount > 1) {
throw new IllegalStateException("Expected result set size of 0 or 1 but got " + assetCount);
}
return executeQuery(connection, sqlAssetIndex::mapPropertyResultSet, sqlAssetQueries.getSqlPropertyFindByIdClause(), assetExpected.getId()).stream().collect(Collectors.toMap(AbstractMap.SimpleImmutableEntry::getKey, AbstractMap.SimpleImmutableEntry::getValue));
});
var assetFound = Asset.Builder.newInstance().id(assetExpected.getId()).properties(assetProperties).build();
assertThat(assetFound).isNotNull();
assertThat(assetFound).usingRecursiveComparison().isEqualTo(assetExpected);
} catch (Exception e) {
if (e instanceof EdcPersistenceException) {
throw (EdcPersistenceException) e;
} else {
throw new EdcPersistenceException(e.getMessage(), e);
}
}
}
Aggregations