UNPKG

@treecg/ldes-orchestrator

Version:

Fills the gaps that a Linked Data Platform (LDP) cannot do by itself for creating a Linked Data Event Stream (LDES) in LDP.

273 lines (272 loc) 18.1 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var fs_1 = require("fs"); var path_1 = __importDefault(require("path")); var ldes_announcements_1 = require("@treecg/ldes-announcements"); var index_1 = require("../index"); var Login_1 = require("../src/Login"); var Conversion_1 = require("../src/util/Conversion"); var Util_1 = require("../src/util/Util"); var solidHelper_1 = require("./solidHelper"); var parse = require('parse-link-header'); describe('Integration test for LDESinSolid and Orchestrating functionalities', function () { var base = (0, solidHelper_1.solidUrl)(); var session; var announcement; var solidPodPath = path_1.default.join(__dirname, 'solidPod'); beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () { var viewString, viewStore, announcementConfig; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, Login_1.getSession)()]; case 1: // create session session = _a.sent(); viewString = '<https://test/output/root.ttl> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://w3id.org/tree#Node>.'; return [4 /*yield*/, (0, Conversion_1.turtleStringToStore)(viewString)]; case 2: viewStore = _a.sent(); announcementConfig = { bucketizer: 'substring', creatorName: 'woutslabbinck', creatorURL: "https://github.com/woutslabbinck", originalLDESURL: 'https://smartdata.dev-vlaanderen.be/base/gemeente', pageSize: '100', propertyPath: '<http://www.w3.org/2000/01/rdf-schema#label>', viewId: 'https://test/output/root.ttl' }; return [4 /*yield*/, (0, ldes_announcements_1.createViewAnnouncement)(viewStore, announcementConfig)]; case 3: announcement = _a.sent(); return [2 /*return*/]; } }); }); }); describe('General tests', function () { it('server online', function () { return __awaiter(void 0, void 0, void 0, function () { var getRequest; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, fetch(base)]; case 1: getRequest = _a.sent(); expect(getRequest.status).toBe(200); return [2 /*return*/]; } }); }); }); it('is logged in', function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { expect(session.info.isLoggedIn).toBe(true); return [2 /*return*/]; }); }); }); }); describe('LDES-Orchestrator', function () { it('Verifying contents of created LDES in LDP', function () { return __awaiter(void 0, void 0, void 0, function () { var ldesDirectoryName, ldesBaseUrl, ldesConfig, aclConfig, ldes, ldesPath, ldesContainerResponse, ldesContainerStore, _a, inboxFromStore, inboxFromResponse, ldesRootAclResponse, ldesRootAclStore, _b, ldesRootPublicSubject, ldesRootAccessRightsPublic, ldesRootPrivateSubject, ldesRootAccessRightsPrivate, ldesDirectoryFiles, relationDirectoryName, rootStore, rootIRI, collectionIRI, relationNode, relationDirectoryPath, relationDirectoryFiles, relationAclResponse, relationAclStore, _c, relationPublicSubject, relationAccessRightsPublic, relationPrivateSubject, relationAccessRightsPrivate; return __generator(this, function (_d) { switch (_d.label) { case 0: ldesDirectoryName = 'newLDES'; ldesBaseUrl = "".concat(base + ldesDirectoryName, "/"); ldesConfig = { base: ldesBaseUrl, treePath: index_1.DCT.modified, shape: 'https://tree.linkeddatafragments.org/announcements/shape', relationType: index_1.TREE.GreaterThanOrEqualToRelation }; if (!session.info.webId) throw Error("Should be present"); aclConfig = { agent: session.info.webId }; ldes = new index_1.LDESinSolid(ldesConfig, aclConfig, session, 1); return [4 /*yield*/, ldes.createLDESinLDP()]; case 1: _d.sent(); ldesPath = path_1.default.join(solidPodPath, ldesDirectoryName); return [4 /*yield*/, session.fetch(ldesBaseUrl, { method: "GET", headers: { Accept: "text/turtle" } })]; case 2: ldesContainerResponse = _d.sent(); _a = Conversion_1.turtleStringToStore; return [4 /*yield*/, ldesContainerResponse.text()]; case 3: return [4 /*yield*/, _a.apply(void 0, [_d.sent(), ldesBaseUrl])]; case 4: ldesContainerStore = _d.sent(); inboxFromStore = ldesContainerStore.getQuads(ldesBaseUrl, index_1.LDP.inbox, null, null)[0].object.id; inboxFromResponse = parse(ldesContainerResponse.headers.get('Link'))[index_1.LDP.inbox]; // inbox Link header url must also be in the metadata expect(inboxFromStore).toBe(inboxFromResponse.url); return [4 /*yield*/, session.fetch("".concat(ldesBaseUrl, ".acl"), { method: "GET", headers: { Accept: "text/turtle" } })]; case 5: ldesRootAclResponse = _d.sent(); _b = Conversion_1.turtleStringToStore; return [4 /*yield*/, ldesRootAclResponse.text()]; case 6: return [4 /*yield*/, _b.apply(void 0, [_d.sent(), "".concat(ldesBaseUrl, ".acl")])]; case 7: ldesRootAclStore = _d.sent(); ldesRootPublicSubject = ldesRootAclStore.getQuads(null, index_1.ACL.agentClass, index_1.FOAF.Agent, null)[0].subject.id; ldesRootAccessRightsPublic = ldesRootAclStore.getObjects(ldesRootPublicSubject, index_1.ACL.mode, null).map(function (object) { return object.id; }); expect(ldesRootAccessRightsPublic.includes(index_1.ACL.Read)).toBe(true); ldesRootPrivateSubject = ldesRootAclStore.getQuads(null, index_1.ACL.agent, session.info.webId, null)[0].subject.id; ldesRootAccessRightsPrivate = ldesRootAclStore.getObjects(ldesRootPrivateSubject, index_1.ACL.mode, null).map(function (object) { return object.id; }); expect(ldesRootAccessRightsPrivate.includes(index_1.ACL.Read)).toBe(true); expect(ldesRootAccessRightsPrivate.includes(index_1.ACL.Write)).toBe(true); expect(ldesRootAccessRightsPrivate.includes(index_1.ACL.Control)).toBe(true); ldesDirectoryFiles = (0, fs_1.readdirSync)(ldesPath); relationDirectoryName = inboxFromStore.replace(ldesBaseUrl, '').slice(0, -1); expect(ldesDirectoryFiles.includes('.meta')).toBe(true); expect(ldesDirectoryFiles.includes('.acl$.jsonld') || ldesDirectoryFiles.includes('.acl')).toBe(true); expect(ldesDirectoryFiles.includes('root.ttl')).toBe(true); expect(ldesDirectoryFiles.includes(relationDirectoryName)).toBe(true); expect(ldesDirectoryFiles.length).toBe(4); return [4 /*yield*/, (0, solidHelper_1.fileAsStore)(path_1.default.join(ldesPath, 'root.ttl'))]; case 8: rootStore = _d.sent(); rootIRI = "".concat(ldesBaseUrl, "root.ttl"); collectionIRI = rootStore.getSubjects(index_1.RDF.type, index_1.LDES.EventStream, null)[0].id; expect(rootStore.getObjects(collectionIRI, index_1.TREE.shape, null)[0].id).toBe('https://tree.linkeddatafragments.org/announcements/shape'); expect(rootStore.getObjects(collectionIRI, index_1.TREE.view, null)[0].id).toBe(rootIRI); expect(rootStore.getObjects(rootIRI, index_1.RDF.type, null)[0].id).toBe(index_1.TREE.Node); expect(rootStore.getObjects(rootIRI, index_1.TREE.relation, null).length).toBe(1); relationNode = rootStore.getObjects(rootIRI, index_1.TREE.relation, null)[0].id; expect(rootStore.getObjects(relationNode, index_1.RDF.type, null)[0].id).toBe(ldesConfig.relationType); expect(rootStore.getObjects(relationNode, index_1.TREE.path, null)[0].id).toBe(ldesConfig.treePath); expect(rootStore.getObjects(relationNode, index_1.TREE.node, null)[0].id).toBe("".concat(ldesBaseUrl + relationDirectoryName, "/")); expect(rootStore.getObjects(relationNode, index_1.TREE.value, null)[0].datatype.value).toBe(index_1.XSD.dateTime); relationDirectoryPath = path_1.default.join(ldesPath, relationDirectoryName); relationDirectoryFiles = (0, fs_1.readdirSync)(relationDirectoryPath); expect(relationDirectoryFiles.includes('.acl$.jsonld') || ldesDirectoryFiles.includes('.acl')).toBe(true); // expect(relationDirectoryFiles.includes('.meta')).toBe(true) // Note: only present in shape solid server expect(relationDirectoryFiles.length).toBe(1); return [4 /*yield*/, session.fetch("".concat(ldesBaseUrl + relationDirectoryName, "/.acl"), { method: "GET", headers: { Accept: "text/turtle" } })]; case 9: relationAclResponse = _d.sent(); _c = Conversion_1.turtleStringToStore; return [4 /*yield*/, relationAclResponse.text()]; case 10: return [4 /*yield*/, _c.apply(void 0, [_d.sent(), "".concat(ldesBaseUrl, ".acl")])]; case 11: relationAclStore = _d.sent(); relationPublicSubject = relationAclStore.getQuads(null, index_1.ACL.agentClass, index_1.FOAF.Agent, null)[0].subject.id; relationAccessRightsPublic = relationAclStore.getObjects(relationPublicSubject, index_1.ACL.mode, null).map(function (object) { return object.id; }); expect(relationAccessRightsPublic.includes(index_1.ACL.Read)).toBe(true); expect(relationAccessRightsPublic.includes(index_1.ACL.Append)).toBe(true); relationPrivateSubject = relationAclStore.getQuads(null, index_1.ACL.agent, session.info.webId, null)[0].subject.id; relationAccessRightsPrivate = relationAclStore.getObjects(relationPrivateSubject, index_1.ACL.mode, null).map(function (object) { return object.id; }); expect(relationAccessRightsPrivate.includes(index_1.ACL.Read)).toBe(true); expect(relationAccessRightsPrivate.includes(index_1.ACL.Write)).toBe(true); expect(relationAccessRightsPrivate.includes(index_1.ACL.Control)).toBe(true); return [2 /*return*/]; } }); }); }); it('verify ldes in solid works', function () { return __awaiter(void 0, void 0, void 0, function () { var ldesBaseUrl, ldesConfig, aclConfig, ldes, firstContainer, emptyLDES, response, oneResource, orchestrator, againEmpty, secondContainer; return __generator(this, function (_a) { switch (_a.label) { case 0: ldesBaseUrl = "".concat(base, "ldes/"); ldesConfig = { base: ldesBaseUrl, treePath: index_1.DCT.modified, shape: 'https://tree.linkeddatafragments.org/announcements/shape', relationType: index_1.TREE.GreaterThanOrEqualToRelation }; if (!session.info.webId) throw Error("Should be present"); aclConfig = { agent: session.info.webId }; ldes = new index_1.LDESinSolid(ldesConfig, aclConfig, session, 1); return [4 /*yield*/, ldes.createLDESinLDP()]; case 1: _a.sent(); return [4 /*yield*/, ldes.getCurrentContainer()]; case 2: firstContainer = _a.sent(); return [4 /*yield*/, ldes.getAmountResources()]; case 3: emptyLDES = _a.sent(); expect(emptyLDES).toBe(0); return [4 /*yield*/, (0, ldes_announcements_1.postAnnouncement)(announcement, ldesBaseUrl)]; case 4: response = _a.sent(); expect(response.status).toBe(201); return [4 /*yield*/, ldes.getAmountResources()]; case 5: oneResource = _a.sent(); expect(oneResource).toBe(1); orchestrator = new index_1.Orchestrator(session); orchestrator.orchestrateLDES(ldes, .1); return [4 /*yield*/, (0, Util_1.sleep)(200)]; case 6: _a.sent(); orchestrator.stopOrchestrating(); return [4 /*yield*/, (0, Util_1.sleep)(1000)]; case 7: _a.sent(); return [4 /*yield*/, ldes.getAmountResources()]; case 8: againEmpty = _a.sent(); expect(againEmpty).toBe(0); return [4 /*yield*/, ldes.getCurrentContainer()]; case 9: secondContainer = _a.sent(); expect(firstContainer).not.toBe(secondContainer); expect(firstContainer).toContain(ldesBaseUrl); expect(secondContainer).toContain(ldesBaseUrl); return [2 /*return*/]; } }); }); }); }); });