Skip to content

Commit eb9019e

Browse files
committed
feat (core): Introduce ThingIO
1 parent 92232fe commit eb9019e

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

java/dev/enola/cli/CommandWithModel.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ public final void run() throws Exception {
8787
// TODO Move elsewhere for continuous ("shell") mode, as this is "expensive".
8888
ServiceProvider grpc = null;
8989
if (group.load != null) {
90+
// TODO Use (new) ThingIO / ResourceIntoThingConverters infra here! (With TLC.open(),
91+
// similar to how it's done in RdfResourceIntoThingConverterTest; but needs more
92+
// thought.)
9093
// TODO Replace DatatypeRepository with store itself, once a Datatype is a Thing
9194
DatatypeRepository dtr = new DatatypeRepositoryBuilder().build();
9295
ThingMemoryRepositoryROBuilder store = new ThingMemoryRepositoryROBuilder();

java/dev/enola/thing/io/Loader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
public class Loader<T extends Thing>
3434
implements ConverterInto<Stream<ReadableResource>, Store<?, T>> {
3535

36+
// TODO This must simply use the (new) ResourceIntoThingConverters !
37+
3638
// TODO Do this multi-threaded, in parallel...
3739

3840
private static final Logger LOG = LoggerFactory.getLogger(Loader.class);
@@ -59,6 +61,7 @@ private void load(ReadableResource resource, Store<?, T> store) {
5961
things.get()
6062
.forEach(
6163
thingBuilder -> {
64+
// TODO Move this into ResourceIntoThingConverters
6265
thingBuilder.set(KIRI.E.ORIGIN, resource.uri());
6366
var thing = thingBuilder.build();
6467
store.merge(thing);

java/dev/enola/thing/io/ResourceIntoThingConverters.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
public class ResourceIntoThingConverters<T extends Thing>
3333
implements Converter<ReadableResource, List<Thing.Builder<T>>> {
3434

35+
// TODO Reconsider use of generics here -VS- in ThingIO
36+
37+
// TODO Support a more "streaming" API...
38+
3539
private final ImmutableList<ResourceIntoThingConverter<T>> converters;
3640

3741
public ResourceIntoThingConverters(Iterable<ResourceIntoThingConverter<T>> converters) {

java/dev/enola/thing/io/ThingIO.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright 2024 The Enola <https://enola.dev> Authors
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package dev.enola.thing.io;
19+
20+
import dev.enola.common.io.resource.ResourceProvider;
21+
import dev.enola.thing.Thing;
22+
23+
import java.net.URI;
24+
25+
public class ThingIO {
26+
27+
// TODO Support a more "streaming" API...
28+
29+
private final ResourceProvider rp = null; // TODO NOT new ResourceProviders();
30+
31+
private final ResourceIntoThingConverters<Thing> converter =
32+
new ResourceIntoThingConverters<>();
33+
34+
public Iterable<Thing> read(URI uri) {
35+
return read(uri, Thing.class);
36+
}
37+
38+
public <T extends Thing> Iterable<T> read(URI uri, Class<T> klass) {
39+
var resource = rp.getReadableResource(uri);
40+
return null; // TODO converter.convert(resource);
41+
}
42+
43+
public void write(Iterable<Thing> things, URI uri) {}
44+
}

0 commit comments

Comments
 (0)