Skip to content

Commit

Permalink
feat (core): Introduce ThingIO
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Jun 30, 2024
1 parent f1fe7cc commit 08e2889
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions java/dev/enola/cli/CommandWithModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public final void run() throws Exception {
// TODO Move elsewhere for continuous ("shell") mode, as this is "expensive".
ServiceProvider grpc = null;
if (group.load != null) {
// TODO Use (new) ThingIO / ResourceIntoThingConverters infra here! (With TLC.open(),
// similar to how it's done in RdfResourceIntoThingConverterTest; but needs more
// thought.)
// TODO Replace DatatypeRepository with store itself, once a Datatype is a Thing
DatatypeRepository dtr = new DatatypeRepositoryBuilder().build();
ThingMemoryRepositoryROBuilder store = new ThingMemoryRepositoryROBuilder();
Expand Down
3 changes: 3 additions & 0 deletions java/dev/enola/thing/io/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
public class Loader<T extends Thing>
implements ConverterInto<Stream<ReadableResource>, Store<?, T>> {

// TODO This must simply use the (new) ResourceIntoThingConverters !

// TODO Do this multi-threaded, in parallel...

private static final Logger LOG = LoggerFactory.getLogger(Loader.class);
Expand All @@ -59,6 +61,7 @@ private void load(ReadableResource resource, Store<?, T> store) {
things.get()
.forEach(
thingBuilder -> {
// TODO Move this into ResourceIntoThingConverters
thingBuilder.set(KIRI.E.ORIGIN, resource.uri());
var thing = thingBuilder.build();
store.merge(thing);
Expand Down
4 changes: 4 additions & 0 deletions java/dev/enola/thing/io/ResourceIntoThingConverters.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
public class ResourceIntoThingConverters<T extends Thing>
implements Converter<ReadableResource, List<Thing.Builder<T>>> {

// TODO Reconsider use of generics here -VS- in ThingIO

// TODO Support a more "streaming" API...

private final ImmutableList<ResourceIntoThingConverter<T>> converters;

public ResourceIntoThingConverters(Iterable<ResourceIntoThingConverter<T>> converters) {
Expand Down
44 changes: 44 additions & 0 deletions java/dev/enola/thing/io/ThingIO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2024 The Enola <https://enola.dev> Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.thing.io;

import dev.enola.common.io.resource.ResourceProvider;
import dev.enola.thing.Thing;

import java.net.URI;

public class ThingIO {

// TODO Support a more "streaming" API...

private final ResourceProvider rp = null; // TODO NOT new ResourceProviders();

private final ResourceIntoThingConverters<Thing> converter =
new ResourceIntoThingConverters<>();

public Iterable<Thing> read(URI uri) {
return read(uri, Thing.class);
}

public <T extends Thing> Iterable<T> read(URI uri, Class<T> klass) {
var resource = rp.getReadableResource(uri);
return null; // TODO converter.convert(resource);
}

public void write(Iterable<Thing> things, URI uri) {}
}

0 comments on commit 08e2889

Please sign in to comment.