Skip to content

Commit

Permalink
Update default mapper version + allow to give mapper url
Browse files Browse the repository at this point in the history
  • Loading branch information
julianrojas87 committed Jan 23, 2024
1 parent a07bb3a commit 06a6911
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
5 changes: 1 addition & 4 deletions src/rml/rml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import { RML, RMLT, VOID } from "../voc";

const { literal } = DataFactory;

const RML_MAPPER_RELEASE =
"https://github.com/RMLio/rmlmapper-java/releases/download/v6.2.2/rmlmapper-6.2.2-r371-all.jar";

export type Source = {
location: string;
dataInput: Stream<string>;
Expand Down Expand Up @@ -71,7 +68,7 @@ export async function rmlMapper(
}
}

const jarFile = await getJarFile(jarLocation, false, RML_MAPPER_RELEASE);
const jarFile = await getJarFile(jarLocation);
const mappingLocations: string[] = [];

// Read mapping input stream
Expand Down
28 changes: 20 additions & 8 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@ import { existsSync } from "fs";
import { randomUUID as cryptoUUID } from "crypto";
import { exec } from "child_process";

const DEFAULT_URL = "https://github.com/RMLio/rmlmapper-java/releases/download/v6.5.1/rmlmapper-6.5.1-r371-all.jar";
const DEFAULT_LOCATION = "/tmp/rml-" + cryptoUUID() + ".jar";

const defaultLocation = "/tmp/rml-" + cryptoUUID() + ".jar";
let rmlJarPromise: undefined | Promise<string> = undefined;

export async function getJarFile(mLocation: string | undefined, offline: boolean, url: string): Promise<string> {
const location = mLocation || defaultLocation;
export async function getJarFile(mLocation: string | undefined): Promise<string> {
let location;
let url;

if (mLocation) {
if (mLocation.startsWith("http")) {
url = mLocation;
location = `./${mLocation.split("/")[mLocation.split("/").length - 1]}`;
} else {
location = mLocation;
url = DEFAULT_URL;
}
} else {
location = DEFAULT_LOCATION;
url = DEFAULT_URL;
}

try {
if (existsSync(location)) {
return location;
}
} catch (e: any) { }

// Did not find the file :/
if (offline) {
throw "Did not find jar file, and the runner is started in offline mode. Cannot continue.";
} catch (e: any) {
throw new Error(`Did not find given jar file ${location}`);
}

if (!rmlJarPromise) {
Expand Down
16 changes: 11 additions & 5 deletions test/rml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,24 @@ describe("Functional tests for the rmlMapper Connector Architecture function", (
const store = new Store();
store.addQuads(new Parser().parse(data));

expect(store.getQuads(null, null, null, null).length).toBe(4);
expect(store.getQuads(null, null, null, null).length).toBe(8);
expect(store.getQuads(
"http://example.org/001",
null,
RDF.type,
null,
"http://example.org/myNamedGraph").length
).toBe(2);
expect(store.getQuads(
null,
"http://purl.org/dc/terms/isVersionOf",
"http://example.org/001",
null).length
).toBe(1);
expect(store.getQuads(
"http://example.org/002",
RDFS.label,
null,
"http://example.org/myNamedGraph").length
"http://purl.org/dc/terms/isVersionOf",
"http://example.org/002",
null).length
).toBe(1);
});

Expand Down

0 comments on commit 06a6911

Please sign in to comment.