fixed the query and lookup retrieval that started and made it work
@@ -704,24 +704,35 @@ import won from "./won.js";
}
const mappingsPromises = loadedDocumentUris.map(async docUri => {
+ try {
if (docUri.startsWith("event") || docUri.startsWith(baseUriForEvents)) {
const messageUri = docUri;
- const correspondingRemoteMessageUri = getIn(
- await executeQueryOnRdfStore(
+ const queryResult = await executeQueryOnRdfStore(
tmpstore,
`
prefix event: <${baseUriForEvents}>
prefix msg: <http://purl.org/webofneeds/message#>
- select distinct ?remoteUri where {
- { <${messageUri}> msg:hasCorrespondingRemoteMessage ?remoteUri } union
- { ?remoteUri msg:hasCorrespondingRemoteMessage <${messageUri}> }
+ select distinct ?graphOfMessage where {
+ { <${messageUri}> msg:hasCorrespondingRemoteMessage ?graphOfMessage } union
+ { ?graphOfMessage msg:hasCorrespondingRemoteMessage <${messageUri}> } union
+ { <${messageUri}> msg:hasForwardedMessage ?graphOfMessage } union
+ { <${messageUri}> msg:hasForwardedMessage/msg:hasCorrespondingRemoteMessage ?graphOfMessage }
}
`
- ),
- [0, "remoteUri", "value"] // the result is nested a bit, so we need to extract the uri here
);
+ console.log("queryResult:", queryResult);
+ if (!queryResult || queryResult.length == 0) {
+ return {
+ uri: messageUri,
+ containedGraphUris: [],
+ };
+ }
+ const graphUrisOfMessage = queryResult.map(result =>
+ getIn(result, ["graphOfMessage", "value"])
+ );
+ console.log("graphUrisOfMessage:", graphUrisOfMessage);
const urisInStoreThatStartWith = uri =>
Array.from(
new Set(
@@ -733,14 +744,21 @@ import won from "./won.js";
const graphUrisInEventDoc = urisInStoreThatStartWith(
messageUri + "#"
- ).concat(urisInStoreThatStartWith(correspondingRemoteMessageUri + "#"));
-
+ ).concat(
+ graphUrisOfMessage
+ .map(uri => urisInStoreThatStartWith(uri + "#"))
+ .reduce((arr1, arr2) => arr1.concat(arr2))
+ );
+ console.log("graphUrisInEventDoc:", graphUrisInEventDoc);
return {
uri: messageUri,
- correspondingRemoteMessageUri,
- containedGraphUris: graphUrisInEventDoc,
+ containedGraphUris: Array.from(new Set(graphUrisInEventDoc)), //deduplicate
};
}
+ } catch (ex) {
+ console.error("caught:" + ex);
+ rethrow(ex, `failed to loadDocumentUris due to reason: `);
+ }
});
const mappingsArray = (await Promise.all(mappingsPromises)).filter(m => m);
