Skip to content

Commit

Permalink
Allow to directly fetch specific shells.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenwenzel committed Nov 5, 2024
1 parent 3f0674a commit 888d35d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface AAS {
IRI API_SHELLS = SimpleValueFactory.getInstance().createIRI("aas-api:shells");
IRI API_SUBMODELS = SimpleValueFactory.getInstance().createIRI("aas-api:submodels");

String ASSETADMINISTRATIONSHELL_PREFIX = "urn:aas:AssetAdministrationShell:";
String SUBMODEL_PREFIX = "urn:aas:Submodel:";

static Value toRdfValue(Object value, ValueFactory vf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public IExtendedIterator<Record> shells() throws URISyntaxException, IOException
return query(endpoint, "shells", null, null);
}

public IExtendedIterator<Record> shell(String id, boolean encodeBase64) throws URISyntaxException, IOException {
return query(endpoint, "shells/" + (encodeBase64 ?
Base64.getEncoder().encodeToString(id.getBytes(StandardCharsets.UTF_8)) : id), null, null);
}

public IExtendedIterator<Record> submodels() throws URISyntaxException, IOException {
return query(endpoint, "submodels", null, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.github.linkedfactory.core.rdf4j.aas.AasClient;
import io.github.linkedfactory.core.rdf4j.common.HasValue;
import io.github.linkedfactory.core.rdf4j.common.query.CompositeBindingSet;
import io.github.linkedfactory.core.rdf4j.common.query.InnerJoinIterator;
import io.github.linkedfactory.core.rdf4j.common.query.InnerJoinIteratorEvaluationStep;
import io.github.linkedfactory.core.rdf4j.kvin.query.KvinFetch;
import net.enilink.commons.iterator.IExtendedIterator;
Expand Down Expand Up @@ -187,6 +186,22 @@ public void remove() throws QueryEvaluationException {
return new SingletonIteration<>(bs);
}

// retrieve shell if IRI starts with urn:aas:AssetAdministrationShell:
if (subjectValue.isIRI() && subjectValue.stringValue().startsWith(AAS.ASSETADMINISTRATIONSHELL_PREFIX)) {
String shellId = subjectValue.stringValue().substring(AAS.ASSETADMINISTRATIONSHELL_PREFIX.length());
try (IExtendedIterator<Record> it = client.shell(shellId, false)) {
Record shell = it.next();
QueryBindingSet newBs = new QueryBindingSet(bs);
newBs.removeBinding(subjectVar.getName());
newBs.addBinding(subjectVar.getName(), toRdfValue(shell));
return evaluate(stmt, newBs);
} catch (URISyntaxException e) {
throw new QueryEvaluationException(e);
} catch (IOException e) {
throw new QueryEvaluationException(e);
}
}

// retrieve submodel if IRI starts with urn:aas:Submodel:
if (subjectValue.isIRI() && subjectValue.stringValue().startsWith(AAS.SUBMODEL_PREFIX)) {
String submodelId = subjectValue.stringValue().substring(AAS.SUBMODEL_PREFIX.length());
Expand Down

0 comments on commit 888d35d

Please sign in to comment.