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
New feature for 1.0.0 : Metadata patching via VBO #101
Comments
I will add an example here taken from the swaggest docs (FYI we use swaggest a lot, specially for the JSON Schema validations we do so this is an implicit dependencies we already have)
@alliomeria @giancarlobi in case this is new for you. I feel the replacement logic is quite intuitive. And with the VBO and some UX tool we could have here a VERY powerful metadata cleanup/fixing/improving tool here, actually i feel this feature can become KEY. See https://www.drupal.org/project/views_bulk_operations PS: there is quite simplistic, per Field (and we use a single one so not of much use here), edit submodule there in that link. I tested it and the UI/UX is terrible and has many other issues. So we can even think of NOT doing it like that. |
While i code this (like now) i found some extra interesting use case: 1.- I do not want certain users or even roles to be able to add/remove/update certain JSON Paths (in this context they are really JSON Pointers This intersects directly with ACL permission layer i'm working on. So JSON patching would become another access plugin that would interact with a given resource (in this case aNODE:aFIELD:THEJSON) 2.- I want to exclude certain operations globally for certain keys. Like i do not want JSON Patch operation to act on certain required elements. e.g NO "op":"remove","path","/type" 3.-I want that certain operations are setting values under a controlled scenario (vocabularies or dictionaries). Ideas: A.- Build this into ACL permission as a parsing service plugin (i'm thinking that each type of operation for ACL purpose becomes a plugin that parses a given resource path, a given operation and can give me back, neutral, negative or positive access to that. This way i do not need to add anything in this functionality, i just evaluate whatever the input of this action is against the ACL machinery. CONS:I need to write that complex ACL machinery! B.- Start with simple. Add a configuration entity with denied JSON Pointers (a list) per operation. (operations relevant are add, remove, replace). Then using this, every time i want apply a JSON Patch i add maybe extra test operations? or remove some of them upfront so ones that need to run will fail and the whole patch operation will be skipped? |
Since i'm basically speaking to myself here: Another thing i wanted is of course to validate the jsonpatch operation upfront (syntax) and since i know my code, i'm doing it via a json schema validation, as i do with other JSONs in our code base. In case someone was "wondering" how that works. |
As i continue my journey here i think i will add additional actions since the experience here is good!
Documentation, a lot of that. |
All this is great! Contains the essential ingredients for a key feature that empowers individuals to perform metadata work efficiently and safely. Who doesn't love batch metadata editing capabilities? Potential food for thought for form UI: https://github.com/UCSCLibrary/BulkMetadataEditor/blob/master/libraries/BulkMetadataEditor/Form/Main.php Looking forward to testing this tool out and seeing it in action. |
I have this working now but I'm still wondering about how to make JSONPOINTERS better suited for our needs. Let me explain: "label": "My First Digital Object",
"term_aat_getty": [],
"ap:entitymapping": {
"entity:file": [
"images",
"warcs",
"documents",
"audios",
"videos",
"models"
],
"entity:node": [
"ismemberof"
]
},
"local_identifier": "",
"subject_wikidata": [
{
"uri": "http:\/\/www.wikidata.org\/entity\/Q1158971",
"label": "Dan"
}
] And a JSON Patch to replace the FIRST subject_wikidata entry if the Object has "My First Object" label would be like this [
{ "op": "test", "path": "/label", "value": "My First Object" },
{ "op": "replace", "path": "/subject_wikidata/0", "value": { "uri": "http:\/\/www.wikidata.org\/entity\/Q19819764", "label":"Allison"}
}
] Problem with this is that normally we won't have any control on what order a specific Wikidata Entry (or any list element) appears. So. What we really want is another option that we can prepare and then expand into a specific to our case JSON Pointer. Ideas: [
{
"pre":"find", "path": "/subject_wikidata[*].label", "match": "Dan", "op":"replace", "value": { "uri": "http:\/\/www.wikidata.org\/entity\/Q19819764", "label":"Allison" }
}
] This is of course not a valid JSONPATCH operation. Will continue explaining after a call I have.. TBC! Ok, so back here. I envision this as an out of specs Operation that I can preparse.
|
WE did some testing today with @alliomeria and there may be a few edge cases/needs (e.g JMESPATH filters our NULLS so you do not get the actual index as it is). Also the UI (gosh the UI!) is needed. I can write JSONPATCH. nOt sure 👀 people want to write JSONPATCH! So fields and logic needs to be exposed even if internally ALL is JSONPATCH. did I mention JSONPATCH? |
Being VBO Views Batch Operations this features is quite simple. This module needs to provide a few action plugins. A base one which allows strings to be replaced by other strings in the JSON.
As simple as that, with an exception: that the end result needs to be a valid JSON before and i would love to start using more powerful options since we are JSON fans.
JSON Patching and also JSON Diffs. Why? Because the order of things in JSON can not be ensured when dealing with properties, but also because a JSON Patch allows greater complexity. My main concern is the interface. Like i would love to have a Webform similar (if not the webform itself) to apply a change to a certain field and through that built the JSON Patch.
Also we have help for that. https://github.com/swaggest/json-diff
The text was updated successfully, but these errors were encountered: