-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
504 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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.cli; | ||
|
||
import dev.enola.core.meta.EntityKindRepository; | ||
import dev.enola.core.proto.EnolaServiceGrpc; | ||
|
||
import picocli.CommandLine; | ||
|
||
@CommandLine.Command(name = "validate", description = "Validate Models (and exit)") | ||
public class ValidateCommand extends CommandWithModel { | ||
|
||
@Override | ||
protected void run(EntityKindRepository ekr, EnolaServiceGrpc.EnolaServiceBlockingStub service) | ||
throws Exception {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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.repo; | ||
|
||
import dev.enola.data.RepositoryRW; | ||
import dev.enola.thing.Thing; | ||
|
||
public interface ThingRepositoryRW extends ThingRepository, RepositoryRW<Thing> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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.validation; | ||
|
||
public interface Collector { | ||
|
||
void add(String predicateIRI, String message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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.validation; | ||
|
||
import dev.enola.thing.Thing; | ||
|
||
// TODO Find a better name / design... I'm too tired right now! ;) | ||
public interface Collector2 { | ||
|
||
void add(Thing thing, String predicateIRI, String message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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.validation; | ||
|
||
import dev.enola.thing.Link; | ||
import dev.enola.thing.PredicatesObjects; | ||
import dev.enola.thing.repo.ThingRepository; | ||
|
||
import java.net.URI; | ||
|
||
public class LinksValidator implements Validator<PredicatesObjects> { | ||
|
||
private final ThingRepository repo; | ||
|
||
public LinksValidator(ThingRepository repo) { | ||
this.repo = repo; | ||
} | ||
|
||
@Override | ||
public void validate(PredicatesObjects thing, Collector collector) { | ||
thing.datatypes() | ||
.forEach((predicateIRI, datatypeIRI) -> c(predicateIRI, datatypeIRI, collector)); | ||
thing.properties().forEach((predicateIRI, object) -> c(predicateIRI, object, collector)); | ||
} | ||
|
||
private void c(String predicateIRI, String linkedIRI, Collector collector) { | ||
if (linkedIRI.startsWith("file:")) | ||
// TODO Remove this workaround again eventually | ||
// file: shouldn't be Links in the first place (but :URL) | ||
return; | ||
|
||
if (repo.get(linkedIRI) == null) { | ||
collector.add(predicateIRI, "Unknown thing: " + linkedIRI); | ||
} | ||
} | ||
|
||
private void c(String predicateIRI, Object object, Collector collector) { | ||
if (object instanceof Link link) { | ||
c(predicateIRI, link.iri(), collector); | ||
} else if (object instanceof URI uri) { | ||
c(predicateIRI, uri.toString(), collector); | ||
} else if (object instanceof PredicatesObjects predicatesObjects) { | ||
validate(predicatesObjects, collector); | ||
} else if (object instanceof Iterable<?> iterable) { | ||
for (var element : iterable) { | ||
if (element instanceof PredicatesObjects thing) { | ||
validate(thing, collector); | ||
} | ||
} | ||
} // else skip it | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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.validation; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import dev.enola.thing.Link; | ||
import dev.enola.thing.Thing; | ||
import dev.enola.thing.impl.ImmutableThing; | ||
import dev.enola.thing.repo.ThingMemoryRepositoryRW; | ||
import dev.enola.thing.repo.ThingRepositoryRW; | ||
|
||
import org.junit.Test; | ||
|
||
public class LinksValidatorTest { | ||
|
||
// TODO Add missing test coverage for (working) blank nodes, Iterables, URI instead Link | ||
|
||
Thing one = ImmutableThing.builder().iri("http://example.com/one").build(); | ||
Thing two = | ||
ImmutableThing.builder() | ||
.iri("http://example.com/two") | ||
.set("http://example.com/property1", new Link(one.iri())) | ||
.build(); | ||
Thing bad1 = | ||
ImmutableThing.builder() | ||
.iri("http://example.com/three") | ||
.set("http://example.com/property1", new Link("http://example.com/MISSING")) | ||
.build(); | ||
Thing bad2 = | ||
ImmutableThing.builder() | ||
.iri("http://example.com/four") | ||
.set("http://example.com/property1", "hi", "http://example.com/MISSING") | ||
.build(); | ||
|
||
ThingRepositoryRW repo = new ThingMemoryRepositoryRW(); | ||
TestCollector collector = new TestCollector(); | ||
Validators v = new Validators(new LinksValidator(repo)); | ||
|
||
@Test | ||
public void empty() { | ||
v.validate(repo, collector); | ||
repo.store(one); | ||
assertThat(collector.getDiagnostics()).isEmpty(); | ||
} | ||
|
||
@Test | ||
public void aok() { | ||
repo.store(one, two); | ||
v.validate(repo, collector); | ||
assertThat(collector.getDiagnostics()).isEmpty(); | ||
} | ||
|
||
@Test | ||
public void bad() { | ||
repo.store(one, two, bad1, bad2); | ||
v.validate(repo, collector); | ||
assertThat(collector.getDiagnostics()).hasSize(2); | ||
} | ||
} |
Oops, something went wrong.