From 3c54c4b19c9b8d6be09e46ffe0f84608e51d4eaf Mon Sep 17 00:00:00 2001 From: Franz Osorio <5622674+f-osorio@users.noreply.github.com> Date: Thu, 21 Nov 2024 09:22:45 -0500 Subject: [PATCH] Revert "Update electronic locator" --- .../edit/fields/helpers/ActionButton.vue | 5 - src/lib/utils_export.js | 198 +++++++++--------- src/lib/utils_profile.js | 30 ++- src/stores/profile.js | 53 +---- 4 files changed, 114 insertions(+), 172 deletions(-) diff --git a/src/components/panels/edit/fields/helpers/ActionButton.vue b/src/components/panels/edit/fields/helpers/ActionButton.vue index 1bfb3877..e49a46a2 100644 --- a/src/components/panels/edit/fields/helpers/ActionButton.vue +++ b/src/components/panels/edit/fields/helpers/ActionButton.vue @@ -383,8 +383,6 @@ }, hasDefaultValues: function(){ - // console.info("this.structure", this.structure.propertyLabel) - // console.info("this.structure", this.structure) // if the selected item has defaults if (this.structure.valueConstraint.defaults.length > 0){ return true @@ -397,11 +395,8 @@ parentId = parentId.split("_")[0] } - if (!parentId.endsWith("Work") && !parentId.endsWith("Instance") && !parentId.endsWith("Hub") && !parentId.endsWith("Item")){ - for (let sibling of this.profileStore.rtLookup[parentId].propertyTemplates){ - // console.info("sibling: ", sibling.propertyLabel) if (sibling.valueConstraint.defaults.length > 0){ return true } diff --git a/src/lib/utils_export.js b/src/lib/utils_export.js index 9a167119..9c39443c 100644 --- a/src/lib/utils_export.js +++ b/src/lib/utils_export.js @@ -160,6 +160,7 @@ const utilsExport = { bnode.appendChild(rdftype) return bnode }else{ + // just normally make it let bnode = this.createElByBestNS(userValue['@type']) if (userValue['@id']){ @@ -181,14 +182,9 @@ const utilsExport = { * @return {boolean} */ createLiteral: function(property,userValue){ - let p = this.createElByBestNS(property) - - + let p = this.createElByBestNS(property) // it should be stored under the same key - if (userValue[property] && property != "http://id.loc.gov/ontologies/bibframe/electronicLocator"){ - // without this exception, an edit to an incoming URL in SupplementaryContentNote's "Electronic Location" will update the "rdf:resource" - // but will also add it to the inside of the tag. - + if (userValue[property]){ // one last sanity check, don't make empty literals if (userValue[property].trim()==''){ return false @@ -199,7 +195,7 @@ const utilsExport = { if (userValue['@id']){ p.setAttributeNS(this.namespace.rdf, 'rdf:resource', userValue['@id']) } - + if (!this.checkForEDTFDatatype){ this.checkForEDTFDatatype = useConfigStore().checkForEDTFDatatype} if (userValue['@datatype']){ @@ -445,7 +441,7 @@ const utilsExport = { let orginalProfile = profile // cut the ref to the orginal profile = JSON.parse(JSON.stringify(profile)) - + let xmlParser = returnDOMParser() // these will store the top level elements @@ -691,7 +687,9 @@ const utilsExport = { xmlLog.push(['Set userValue to:', JSON.parse(JSON.stringify(userValue)) ]) - + + + if (this.ignoreProperties.indexOf(ptObj.propertyURI) > -1){ xmlLog.push(`Skpping it because it is in the ignoreProperties list`) continue @@ -750,13 +748,12 @@ const utilsExport = { xmlLog.push(`Root level bnode: ${ptObj.propertyURI}`) let pLvl1 = this.createElByBestNS(ptObj.propertyURI) - let bnodeLvl1 = this.createBnode(userValue, ptObj.propertyURI) - xmlLog.push(`Created lvl 1 predicate: ${pLvl1.tagName} and bnode: ${bnodeLvl1.tagName}`) // loop though the properties for (let key1 of Object.keys(userValue).filter(k => (!k.includes('@') ? true : false ) )){ + xmlLog.push(`Looking at property : ${key1} in the userValue`) // console.log('userValue',userValue) let pLvl2 = this.createElByBestNS(key1) @@ -772,7 +769,6 @@ const utilsExport = { if (userValue[key1] && userValue[key1][0] && userValue[key1][0]['@id']){ let rdftype = this.createElByBestNS(key1) rdftype.setAttributeNS(this.namespace.rdf, 'rdf:resource', userValue[key1][0]['@id']) - bnodeLvl1.appendChild(rdftype) xmlLog.push(`This bnode just has a rdf:type : ${rdftype} setting it an continuing`) continue @@ -780,8 +776,7 @@ const utilsExport = { let rdftype = this.createElByBestNS(key1) rdftype.innerHTML=escapeHTML(userValue[key1][0]['http://www.w3.org/2000/01/rdf-schema#label'][0]['http://www.w3.org/2000/01/rdf-schema#label']) xmlLog.push(`This bnode just has a rdf:type and label : ${rdftype} setting it an continuing`) - - bnodeLvl1.appendChild(rdftype) + bnodeLvl1.appendChild(rdftype) continue } } @@ -802,7 +797,6 @@ const utilsExport = { if (this.isBnode(value1)){ // yes let bnodeLvl2 = this.createBnode(value1,key1) - pLvl2.appendChild(bnodeLvl2) bnodeLvl1.appendChild(pLvl2) xmlLog.push(`Creating bnode lvl 2 for it ${bnodeLvl2.tagName}`) @@ -810,86 +804,84 @@ const utilsExport = { // now loop through its properties and see whats nested for (let key2 of Object.keys(value1).filter(k => (!k.includes('@') ? true : false ) )){ let pLvl3 = this.createElByBestNS(key2) - xmlLog.push(`Creating lvl 3 property: ${pLvl3.tagName} for ${key2}`) - - for (let value2 of value1[key2]){ - if (this.isBnode(value2)){ - // more nested bnode - // one more level - let bnodeLvl3 = this.createBnode(value2,key2) - pLvl3.appendChild(bnodeLvl3) - bnodeLvl2.appendChild(pLvl3) - xmlLog.push(`Creating lvl 3 bnode: ${bnodeLvl3.tagName} for ${key2}`) - - - for (let key3 of Object.keys(value2).filter(k => (!k.includes('@') ? true : false ) )){ - let pLvl4 = this.createElByBestNS(key2) - for (let value3 of value2[key3]){ - if (this.isBnode(value3)){ - // one more level - let bnodeLvl4 = this.createBnode(value3,key3) - pLvl4.appendChild(bnodeLvl4) - bnodeLvl3.appendChild(pLvl4) - xmlLog.push(`Creating lvl 4 bnode: ${bnodeLvl4.tagName} for ${key3}`) - - - for (let key4 of Object.keys(value3).filter(k => (!k.includes('@') ? true : false ) )){ - for (let value4 of value3[key4]){ - if (this.isBnode(value4)){ - console.error("Max hierarchy depth reached, but there are more levels left:", key4, 'in', userValue ) - xmlLog.push(`Max hierarchy depth reached, but there are more levels left for ${key4}`) - - }else{ - - for (let key5 of Object.keys(value4).filter(k => (!k.includes('@') ? true : false ) )){ - if (typeof value4[key5] == 'string' || typeof value4[key5] == 'number'){ - // its a label or some other literal - let p5 = this.createLiteral(key5, value4) - if (p5!==false) bnodeLvl4.appendChild(p5); - xmlLog.push(`Added literal ${p5} for ${key5}`) - }else{ - console.error('key5', key5, value4[key5], 'not a literal, should not happen') - xmlLog.push(`Error not a literal but I thought it was at ${key5}`) - } - } - - } - - } - - } - - - }else{ - for (let key4 of Object.keys(value3).filter(k => (!k.includes('@') ? true : false ) )){ - if (typeof value3[key4] == 'string' || typeof value3[key4] == 'number'){ - // its a label or some other literal - let p4 = this.createLiteral(key4, value3) - if (p4!==false) bnodeLvl3.appendChild(p4) - //xmlLog.push(`Added literal ${p4} for ${key4}`) - }else{ - console.error('key4', key4, value3[key4], 'not a literal, should not happen') - xmlLog.push(`Error not a literal but I thought it was at ${key4}`) - } - } - } - } - } - }else{ - for (let key3 of Object.keys(value2).filter(k => (!k.includes('@') ? true : false ) )){ - if (typeof value2[key3] == 'string' || typeof value2[key3] == 'number'){ - // its a label or some other literal - let p3 = this.createLiteral(key3, value2) - if (p3!==false) bnodeLvl2.appendChild(p3) - xmlLog.push(`Created Literal ${p3.innerHTML} for ${key3}`) - }else{ - console.error('key3', key3, value2[key3], 'not a literal, should not happen') - xmlLog.push(`Error not a literal but I thought it was at ${key3}`) - } - } - } - } + for (let value2 of value1[key2]){ + if (this.isBnode(value2)){ + // more nested bnode + // one more level + let bnodeLvl3 = this.createBnode(value2,key2) + pLvl3.appendChild(bnodeLvl3) + bnodeLvl2.appendChild(pLvl3) + xmlLog.push(`Creating lvl 3 bnode: ${bnodeLvl3.tagName} for ${key2}`) + + + for (let key3 of Object.keys(value2).filter(k => (!k.includes('@') ? true : false ) )){ + let pLvl4 = this.createElByBestNS(key2) + for (let value3 of value2[key3]){ + if (this.isBnode(value3)){ + // one more level + let bnodeLvl4 = this.createBnode(value3,key3) + pLvl4.appendChild(bnodeLvl4) + bnodeLvl3.appendChild(pLvl4) + xmlLog.push(`Creating lvl 4 bnode: ${bnodeLvl4.tagName} for ${key3}`) + + + for (let key4 of Object.keys(value3).filter(k => (!k.includes('@') ? true : false ) )){ + for (let value4 of value3[key4]){ + if (this.isBnode(value4)){ + console.error("Max hierarchy depth reached, but there are more levels left:", key4, 'in', userValue ) + xmlLog.push(`Max hierarchy depth reached, but there are more levels left for ${key4}`) + + }else{ + + for (let key5 of Object.keys(value4).filter(k => (!k.includes('@') ? true : false ) )){ + if (typeof value4[key5] == 'string' || typeof value4[key5] == 'number'){ + // its a label or some other literal + let p5 = this.createLiteral(key5, value4) + if (p5!==false) bnodeLvl4.appendChild(p5); + xmlLog.push(`Added literal ${p5} for ${key5}`) + }else{ + console.error('key5', key5, value4[key5], 'not a literal, should not happen') + xmlLog.push(`Error not a literal but I thought it was at ${key5}`) + } + } + + } + + } + + } + + + }else{ + for (let key4 of Object.keys(value3).filter(k => (!k.includes('@') ? true : false ) )){ + if (typeof value3[key4] == 'string' || typeof value3[key4] == 'number'){ + // its a label or some other literal + let p4 = this.createLiteral(key4, value3) + if (p4!==false) bnodeLvl3.appendChild(p4); + xmlLog.push(`Added literal ${p4} for ${key4}`) + }else{ + console.error('key4', key4, value3[key4], 'not a literal, should not happen') + xmlLog.push(`Error not a literal but I thought it was at ${key4}`) + } + } + } + } + } + }else{ + for (let key3 of Object.keys(value2).filter(k => (!k.includes('@') ? true : false ) )){ + if (typeof value2[key3] == 'string' || typeof value2[key3] == 'number'){ + // its a label or some other literal + let p3 = this.createLiteral(key3, value2) + if (p3!==false) bnodeLvl2.appendChild(p3) + xmlLog.push(`Created Literal ${p3.innerHTML} for ${key3}`) + }else{ + console.error('key3', key3, value2[key3], 'not a literal, should not happen') + xmlLog.push(`Error not a literal but I thought it was at ${key3}`) + } + } + } + } } }else{ xmlLog.push(`It's value at lvl is not a bnode, looping through and adding a literal value`) @@ -909,11 +901,14 @@ const utilsExport = { if (keys.length>0){ for (let key2 of keys){ if (typeof value1[key2] == 'string' || typeof value1[key2] == 'number'){ - let p2 = this.createLiteral(key2, value1) - xmlLog.push(`Creating literal ${JSON.stringify(value1)}`) - if (p2!==false) bnodeLvl1.appendChild(p2); + // its a label or some other literal + let p2 = this.createLiteral(key2, value1) + xmlLog.push(`Creating literal ${JSON.stringify(value1)}`) + if (p2!==false) bnodeLvl1.appendChild(p2); }else if (Array.isArray(value1[key2])){ + for (let arrayValue of value1[key2]){ + let keysLevel2 = Object.keys(arrayValue).filter(k => (!k.includes('@') ? true : false ) ) if (keysLevel2.length>0){ @@ -946,6 +941,7 @@ const utilsExport = { } }else if (keys.length==0 && value1['@id']){ + let p2 = this.createLiteral(key1, value1) if (p2!==false) bnodeLvl1.appendChild(p2); @@ -975,6 +971,7 @@ const utilsExport = { componentXmlLookup[`${rt}-${pt}`] = formatXML(pLvl1.outerHTML) }else{ + // this.debug(ptObj.propertyURI, 'root level element does not look like a bnode', userValue) xmlLog.push(`Root level does not look like a bnode: ${ptObj.propertyURI}`) let userValueArray = userValue @@ -1053,6 +1050,7 @@ const utilsExport = { console.error("Does not have URI, ERROR") }else if (await utilsRDF.suggestTypeNetwork(ptObj.propertyURI) == 'http://www.w3.org/2000/01/rdf-schema#Literal'){ + // console.log("Top level literal HERE!",userValue) // its just a top level literal property // loop through its keys and make the values @@ -1091,8 +1089,8 @@ const utilsExport = { } } componentXmlLookup[`${rt}-${pt}`] = allXMLFragments - //Exception for electronicLocator so it is handled by in the next block, otherwise, it won't appear in the XML - }else if (ptObj.propertyURI != "http://id.loc.gov/ontologies/bibframe/electronicLocator" && await utilsRDF.suggestTypeNetwork(ptObj.propertyURI) == 'http://www.w3.org/2000/01/rdf-schema#Resource'){ + }else if (await utilsRDF.suggestTypeNetwork(ptObj.propertyURI) == 'http://www.w3.org/2000/01/rdf-schema#Resource'){ + // if it is a marked in the profile as a literal and has expected value of rdf:Resource flatten it to a string literal let allXMLFragments = '' for (let key1 of Object.keys(userValue).filter(k => (!k.includes('@') ? true : false ) )){ diff --git a/src/lib/utils_profile.js b/src/lib/utils_profile.js index 1eab6571..0765c164 100644 --- a/src/lib/utils_profile.js +++ b/src/lib/utils_profile.js @@ -351,10 +351,7 @@ const utilsProfile = { * @return {array} - will return the value array at the end of the property path if it exists */ returnValueFromPropertyPath: function(pt,propertyPath){ - - // this needs to include a check for "supplementaryContent", so the note will populate in the form - let isLocator = propertyPath.some((pp) => pp.propertyURI.includes("electronicLocator") || pp.propertyURI.includes("supplementaryContent") ) - + let deepestLevel if (propertyPath[propertyPath.length-1]){ deepestLevel = propertyPath[propertyPath.length-1].level @@ -363,10 +360,8 @@ const utilsProfile = { } let pointer = pt.userValue - - // The note in the supplementaryContent is not in the propertyPath - // for (let p of propertyPath){ + // the property path has two parts // {level: 0, propertyURI: 'http://id.loc.gov/ontologies/bibframe/title'} @@ -383,24 +378,27 @@ const utilsProfile = { // down the hiearchy then just select the first element, as we don't support multiple values at the early levels if (p.level !== deepestLevel){ pointer = pointer[p.propertyURI][0] - } else { + }else{ pointer = pointer[p.propertyURI] } - } else { + + }else{ + console.error("Expecting Array in this userValue property:",pt,p,propertyPath) return false + } }else{ - return false + // the level doesn't exist here, we were unable to traverse the whole hierachy + // whihch means the value is not set, so we retun false to say it failed + return false + } + + } - - if (isLocator){ - // deleting this avoids the creation of a "rdf:Resource" tag for "URL of Instance" - delete pointer[0]["@type"] - } - + return pointer diff --git a/src/stores/profile.js b/src/stores/profile.js index 05939448..20c0d919 100644 --- a/src/stores/profile.js +++ b/src/stores/profile.js @@ -1467,22 +1467,6 @@ export const useProfileStore = defineStore('profile', { setValueLiteral: function(componentGuid, fieldGuid, propertyPath, value, lang, repeatedLiteral){ // make a copy of the property path, dont modify the linked one passed propertyPath = JSON.parse(JSON.stringify(propertyPath)) - - - //The propertyPath for supplementaryContent's note is missing the note. It jumps straight to the label - // so insert it so XML can get built - if (propertyPath.some((pp) => pp.propertyURI.includes("supplementaryContent")) && propertyPath.at(-1).propertyURI == "http://www.w3.org/2000/01/rdf-schema#label"){ - propertyPath.splice(1, 0, { level: 1, propertyURI: "http://id.loc.gov/ontologies/bibframe/note" }) - propertyPath.at(-1).level = 2 - } - - // this needs to include a check for "supplementaryContent", so the note will populate in the form - let isLocator = propertyPath.some((pp) => pp.propertyURI.includes("electronicLocator") || pp.propertyURI.includes("supplementaryContent")) - - // for the electronic locator, the path ends with `sameAs`, but it just gets in the way, toss it - if (isLocator){ - propertyPath = propertyPath.filter((v)=> { return (v.propertyURI!=='http://www.w3.org/2002/07/owl#sameAs') }) - } let lastProperty = propertyPath.at(-1).propertyURI // locate the correct pt to work on in the activeProfile @@ -1599,10 +1583,6 @@ export const useProfileStore = defineStore('profile', { // and now add in the literal value into the correct property blankNode[lastProperty] = value - // for electronicLocators, update the ID, so the XML can get built correctly - if (isLocator && Object.keys(blankNode).some((key) => key == "http://id.loc.gov/ontologies/bibframe/electronicLocator")){ - blankNode["@id"] = value - } // if we just set an empty value, remove the value property, and if there are no other values, remvoe the entire property if (value.trim() === ''){ @@ -1697,21 +1677,6 @@ export const useProfileStore = defineStore('profile', { * @return {array} - an array of objs representing the literals */ returnLiteralValueFromProfile: function(componentGuid, propertyPath){ - - // for the electronic locator, the path ends with `sameAs`, but it just gets in the way, toss it - let isLocator = propertyPath.some((pp) => pp.propertyURI.includes("electronicLocator") || pp.propertyURI.includes("supplementaryContent") ) - - if (isLocator){ - // `sameAs` gets in the way for the electronicLocator, toss it - propertyPath = propertyPath.filter((v)=> { return (v.propertyURI!=='http://www.w3.org/2002/07/owl#sameAs') }) - - //The propertyPath for supplementaryContent's note is missing the note. It jumps straight to the label - // fix the propertyPath so the XML can get built correctly - if (propertyPath.some((pp) => pp.propertyURI.includes("supplementaryContent")) && propertyPath.at(-1).propertyURI == "http://www.w3.org/2000/01/rdf-schema#label"){ - propertyPath.splice(1, 0, { level: 1, propertyURI: "http://id.loc.gov/ontologies/bibframe/note" }) - propertyPath.at(-1).level = 2 - } - } let pt = utilsProfile.returnPt(this.activeProfile,componentGuid) let valueLocation = utilsProfile.returnValueFromPropertyPath(pt,propertyPath) @@ -1737,12 +1702,6 @@ export const useProfileStore = defineStore('profile', { value: unescape(v[deepestLevelURI]), '@language' : (v['@language']) ? v['@language'] : null, }) - } else if (isLocator){ //for electronicLocator, incoming records have the value in `@id` - values.push({ - '@guid':v['@guid'], - value: unescape(v["@id"]), - '@language' : (v['@language']) ? v['@language'] : null, - }) }else{ return false //console.warn('While looking for ',deepestLevelURI, ' could not find in ', pt, 'valueLocation:',valueLocation) @@ -4322,12 +4281,10 @@ export const useProfileStore = defineStore('profile', { //Check if the component's userValue is empty - isEmptyComponent: function(c){ const component = c const emptyArray = new Array("@root") const userValue = JSON.parse(JSON.stringify(component["userValue"])) - // if there is only a @root if (JSON.stringify(Object.keys(component.userValue)) == JSON.stringify(emptyArray)){ @@ -4338,18 +4295,12 @@ export const useProfileStore = defineStore('profile', { if (!key.startsWith("@")){ let result = false try{ - // this makes sure that the propertiesPanel will have the correct symbol when the incoming data - // has an populate electronicLocator - if (component.propertyURI != "http://id.loc.gov/ontologies/bibframe/electronicLocator"){ - result = Object.keys(userValue[key][0]).every((childKey) => childKey.startsWith("@")) - } else { - result = !Object.keys(userValue[key][0]).some((childKey) => childKey.startsWith("@id")) - } + result = Object.keys(component.userValue[key][0]).every((childKey) => childKey.startsWith("@")) } catch(err) { console.error("error: Checking if component is empty") } - return result + } } }