-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
removeMetadata #633
removeMetadata #633
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -871,25 +871,46 @@ export default class IndexedFormula extends Formula { // IN future - allow pass | |
} | ||
|
||
/** | ||
* Removes all statements in a doc, along with the related metadata including request/response | ||
* Removes all metadata | ||
* @param doc - The document / graph | ||
*/ | ||
removeDocument(doc: Quad_Graph): IndexedFormula { | ||
const meta = this.sym('chrome://TheCurrentSession') // or this.rdfFactory.namedNode('chrome://TheCurrentSession') | ||
const linkNamespaceURI = 'http://www.w3.org/2007/ont/link#' // alain | ||
// remove request/response and metadata | ||
const requests = this.statementsMatching(undefined, this.sym(`${linkNamespaceURI}requestedURI`), this.rdfFactory.literal(doc.value), meta).map(st => st.subject) | ||
removeMetadata(doc: Quad_Graph): IndexedFormula { | ||
const meta = this.fetcher?.appNode // this.sym('chrome://TheCurrentSession') | ||
const linkNamespaceURI = 'http://www.w3.org/2007/ont/link#' | ||
const kb = this | ||
// removeMatches() --> removeMany() --> remove() fails on Collection | ||
function removeBySubject (subject) { | ||
const sts = kb.statementsMatching(subject, null, null, meta) | ||
// console.log(sts) | ||
for (var i = 0; i < sts.length; i++) { | ||
kb.removeStatement(sts[i]) | ||
} | ||
} | ||
const requests = this.statementsMatching(null, this.sym(`${linkNamespaceURI}requestedURI`), this.rdfFactory.literal(doc.value), meta).map(st => st.subject) | ||
for (var r = 0; r < requests.length; r++) { | ||
const request = requests[r] | ||
if (request !== undefined) { | ||
this.removeMatches(request, null, null, meta) | ||
if (request != null) { // null or undefined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment says "or undefined" but the code onyl checks for null. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Loose inequality does it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Angelo is correct. If you remove line 884 which checks for undefined, the !=null will throw an undefined error if request is undefined. |
||
const response = this.any(request, this.sym(`${linkNamespaceURI}response`), null, meta) as Quad_Subject | ||
if (response !== undefined) { // ts | ||
this.removeMatches(response, null, null, meta) | ||
// console.log('REQUEST ' + request.value) | ||
removeBySubject(request) | ||
if (response != null) { // null or undefined | ||
// console.log('RESPONSE ' + response.value) | ||
removeBySubject(response) | ||
} | ||
} | ||
} | ||
this.removeMatches(this.sym(doc.value), null, null, meta) // content-type | ||
// console.log('DOCTYPE ' + doc.value) | ||
removeBySubject(doc) | ||
return this | ||
} | ||
|
||
/** | ||
* Removes all statements in a doc, along with the related metadata including request/response | ||
* @param doc - The document / graph | ||
*/ | ||
removeDocument(doc: Quad_Graph): IndexedFormula { | ||
// remove request/response and metadata | ||
this.removeMetadata(doc) | ||
|
||
// remove document | ||
var sts: Quad[] = this.statementsMatching(undefined, undefined, undefined, doc).slice() // Take a copy as this is the actual index | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,6 +223,17 @@ describe('UpdateManager', () => { | |
expect(updater.editable(doc1)).to.equal(undefined) | ||
}) | ||
|
||
it('Should not detect a document is editable from metadata after removeMetadata', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How are these tests related to the changes? I would have expected a test that assures that Collections are now working. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They test the new function |
||
loadMeta(updater.store) | ||
updater.store.removeMetadata(doc1) | ||
expect(updater.editable(doc1)).to.equal(undefined) | ||
}) | ||
|
||
it('Should not detect a document is editable from metadata after removeDocument', () => { | ||
loadMeta(updater.store) | ||
updater.store.removeDocument(doc1) | ||
expect(updater.editable(doc1)).to.equal(undefined) | ||
}) | ||
|
||
it('Async version should detect a document is editable from metadata', async () => { | ||
loadMeta(updater.store) | ||
|
@@ -233,13 +244,9 @@ describe('UpdateManager', () => { | |
|
||
it('Async version should not detect a document is editable from metadata after flush', async () => { | ||
loadMeta(updater.store) | ||
|
||
expect(updater.editable(doc1)).to.equal('SPARQL') | ||
|
||
updater.flagAuthorizationMetadata() | ||
|
||
const result = await updater.checkEditable(doc1) | ||
|
||
expect(result).to.equal(undefined) | ||
}) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to fix the remove() function to work with Collection instead of applying a workarround here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it would. I did not find howto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What goes wrong with when one f the nodes being removed is a collection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timbl
This is I hope is a detailed enough issue #631