Skip to content

Commit

Permalink
Merge pull request #1 from oliviervd/master
Browse files Browse the repository at this point in the history
v 0.1 resolver
  • Loading branch information
oliviervd authored Oct 5, 2023
2 parents 772225d + 9cb7006 commit b83e73a
Show file tree
Hide file tree
Showing 12 changed files with 263 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/dmg-resolver.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions client/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {supabase} from "./supabaseClient.js";
export async function connectorObjects() {
const {data, error} = await supabase
.from('dmg_objects_LDES')
.select('objectNumber, RESOLVES_TO, PURI, iiif_manifest, LDES_raw')
return data;
}

export async function writeIIIFSTATUS(_on, RES) {
const {data, error} = await supabase
.from('dmg_objects_LDES')
.update({'iiif_manifest_RESPONSE': RES})
.eq("objectNumber", _on)
}

export async function writePURI(_on, PURI) {
const{data, error} = await supabase
.from('dmg_objects_LDES')
.update({'PURI': PURI})
.eq("objectNumber", _on)
}

export async function writeSTATUS(_on, STATUS) {
const {data, error} = await supabase
.from('dmg_objects_LDES')
.update({'STATUS':STATUS})
.eq("objectNumber", _on)
}
10 changes: 10 additions & 0 deletions client/supabaseClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {createClient} from "@supabase/supabase-js";
import * as dotenv from 'dotenv'

// init dotenv
dotenv.config()

const SUPABASE_URL = process.env.SUPABASE_URL
const SUPABASE_KEY = process.env.SUPABASE_KEY

export const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {monitorHealthUpstream} from "./utils/tests.js";

function main() {
console.log("---------------------")
console.log("BOOTING UP HEALTH CHECK - RESOLVER")
console.log("---------------------")

// CHECK RECORDS
monitorHealthUpstream();
}

main();
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"name": "dmg-resolver",
"type": "module",
"version": "1.0.0",
"description": "resolver utility for maintining healthy upstream when parsing URIs",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "npm start",
"start": "node index.js"
},
"keywords": [
"resolver",
Expand All @@ -13,5 +16,12 @@
"gent"
],
"author": "Olivier Van D'huynslager",
"license": "MIT"
"license": "MIT",
"dependencies": {
"@supabase/supabase-js": "^2.38.0",
"dotenv": "^16.3.1"
},
"engines": {
"node": "14.x"
}
}
27 changes: 27 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# RESOLVER - DESIGN MUSEUM GENT
Node-based service to maintain a healthy upstream for the [REST-API](https://github.com/oliviervd/dmg-rest-api) of Design Museum Gent.

The service checks the museums database and REST-API on a weekly basis and based on a switch-case assigns it a status of HEALTHY or UNHEALTHY. This output is written away in a report and send to staff members within the museum for follow-up.

This way we want to ensure persistent URIs.

### output:

```
----------
0/5864
checking: https://data.designmuseumgent.be/id/object/0559
IIIF Manifest Response: 200
objectnumber in LDES: 0559
content in LDES matches with PID
STATUS: HEALTHY
----------
1/5864
checking: https://data.designmuseumgent.be/id/object/2017-0448
IIIF Manifest Response: 200
objectnumber in LDES: 2017-0448
content in LDES matches with PID
STATUS: HEALTHY
----------
```

136 changes: 136 additions & 0 deletions utils/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import {connectorObjects, writeIIIFSTATUS, writePURI, writeSTATUS} from "../client/client.js";
import * as dotenv from 'dotenv'

// init dotenv
dotenv.config()

const baseURI = process.env._baseURI

function sleep(ms){
return new Promise(resolve=>setTimeout(resolve, ms))
}

export async function monitorHealthUpstream() {
// this function checks the health of the published data and defines rerouting if necessary.

let _stream = await connectorObjects()
let _total = _stream.length
let _count = 0;
for (let i=0; i < _stream.length; i++) {

let statusManifest;
let statusLDES;

// define PID and write to DB if not yet in there.
const PURI = baseURI + `id/object/${_stream[i]["objectNumber"]}`
console.log("----------")
console.log(`${i}/${_total}`)
console.log(`checking: ${PURI}`)


// 1. check LDES - (see if it aligns with PID)
statusLDES = checkLDES(_stream[i]["objectNumber"], _stream[i]["LDES_raw"])

// SWITCH A
// 2. if this first check passes.
if(statusLDES){
// 3A. check status manifest (response request)
// SWITCH B
statusManifest = checkManifest(_stream[i]["iiif_manifest"], _stream[i]["objectNumber"])
await sleep(1000);
console.log("STATUS: HEALTHY")
}

// 3B. if this first check does not pass:
else {
// write: STATUS = UNHEALTHY (needs follow-up)
writeSTATUS(_stream[i]["objectNumber"], "UNHEALTHY")
console.log("STATUS: UNHEALTHY")
}



// 2. write PURI to DB
writePURI(_stream[i]["objectNumber"], PURI)

// 3. write route to resolve to to DB

await sleep(3000);

}
}

function defineStatus(RES_MANIFEST, RES_LDES){

}

function checkLDES(_on, LDES) {
// function that checks if the content alligns with the PID
// input: objectnumber (derived from PID)

let _STATUS;

const _onLDES = extractObjectNumberLDES(LDES)
if (_onLDES === _on) {
console.log("content in LDES matches with PID")
_STATUS = true;
} else {
console.log("WARNING: CONTENT DOES NOT MATCH.")
_STATUS = false
}
return _STATUS
}

function extractObjectNumberLDES(LDES) {
const LDES_ON = LDES['object']['http://www.w3.org/ns/adms#identifier'][1]['skos:notation']['@value']
console.log(`objectnumber in LDES: ${LDES_ON}`)
return LDES_ON
}

export async function checkManifest(manifest, _ON){
let _STATUS;
// fetch data upstream (db)
fetch(manifest)
.then((res) => {
//console.log(res.status)
console.log(`IIIF Manifest Response: ${res.status}`)
_STATUS = checkResponse(res.status, _ON)

})
.catch((err) => {
console.log(err)
})
return _STATUS;
}

function checkResponse(RES, _ON) {
// check response and write to DB.
// column: iiif_manifest_RESPONSE
let STAT;
switch(RES) {
case RES=200:
// OK
writeIIIFSTATUS(_ON, RES)
writeSTATUS(_ON, "HEALTHY")
STAT = true;

case RES=403:
// FORBIDDEN (restricted access)
writeIIIFSTATUS(_ON, RES)
writeSTATUS(_ON, "HEALTHY")
STAT = true;

case RES=404:
// NOT FOUND
writeIIIFSTATUS(_ON, RES)
writeSTATUS(_ON, "UNHEALTHY")
STAT = false;

case RES=503:
// SERVICE UNAVAILABLE
writeIIIFSTATUS(_ON, RES)
STAT = false;
}
return STAT;
}

0 comments on commit b83e73a

Please sign in to comment.