Search in sources :

Example 1 with AssetEntry

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));
}
Also used : AssetEntry(org.eclipse.dataspaceconnector.dataloading.AssetEntry)

Example 2 with AssetEntry

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()));
}
Also used : AssetEntry(org.eclipse.dataspaceconnector.dataloading.AssetEntry) EdcPersistenceException(org.eclipse.dataspaceconnector.spi.persistence.EdcPersistenceException) ComponentTest(org.eclipse.dataspaceconnector.common.annotations.ComponentTest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with AssetEntry

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);
        }
    }
}
Also used : AssetEntry(org.eclipse.dataspaceconnector.dataloading.AssetEntry) AbstractMap(java.util.AbstractMap) SQLException(java.sql.SQLException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) EdcPersistenceException(org.eclipse.dataspaceconnector.spi.persistence.EdcPersistenceException) EdcPersistenceException(org.eclipse.dataspaceconnector.spi.persistence.EdcPersistenceException) ComponentTest(org.eclipse.dataspaceconnector.common.annotations.ComponentTest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

AssetEntry (org.eclipse.dataspaceconnector.dataloading.AssetEntry)3 ComponentTest (org.eclipse.dataspaceconnector.common.annotations.ComponentTest)2 EdcPersistenceException (org.eclipse.dataspaceconnector.spi.persistence.EdcPersistenceException)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 AbstractMap (java.util.AbstractMap)1