Skip to content

Commit

Permalink
Merge pull request #132 from lcnetdev/update-electronic-locator
Browse files Browse the repository at this point in the history
Update electronic locator
  • Loading branch information
f-osorio authored Nov 21, 2024
2 parents 49f586c + 41ad5d0 commit c2240a8
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 114 deletions.
5 changes: 5 additions & 0 deletions src/components/panels/edit/fields/helpers/ActionButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@
},
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
Expand All @@ -395,8 +397,11 @@
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
}
Expand Down
198 changes: 100 additions & 98 deletions src/lib/utils_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ const utilsExport = {
bnode.appendChild(rdftype)
return bnode
}else{

// just normally make it
let bnode = this.createElByBestNS(userValue['@type'])
if (userValue['@id']){
Expand All @@ -182,9 +181,14 @@ 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]){
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.

// one last sanity check, don't make empty literals
if (userValue[property].trim()==''){
return false
Expand All @@ -195,7 +199,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']){
Expand Down Expand Up @@ -441,7 +445,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
Expand Down Expand Up @@ -687,9 +691,7 @@ 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
Expand Down Expand Up @@ -748,12 +750,13 @@ 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)
Expand All @@ -769,14 +772,16 @@ 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
}else if (userValue[key1] && userValue[key1][0] && userValue[key1][0]['http://www.w3.org/2000/01/rdf-schema#label']){
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
}
}
Expand All @@ -797,91 +802,94 @@ 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}`)

// 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}`)
}
}
}
}
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}`)
}
}
}
}
}
}else{
xmlLog.push(`It's value at lvl is not a bnode, looping through and adding a literal value`)
Expand All @@ -901,14 +909,11 @@ const utilsExport = {
if (keys.length>0){
for (let key2 of keys){
if (typeof value1[key2] == 'string' || typeof value1[key2] == 'number'){
// 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);
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){

Expand Down Expand Up @@ -941,7 +946,6 @@ const utilsExport = {

}
}else if (keys.length==0 && value1['@id']){

let p2 = this.createLiteral(key1, value1)
if (p2!==false) bnodeLvl1.appendChild(p2);

Expand Down Expand Up @@ -971,7 +975,6 @@ 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
Expand Down Expand Up @@ -1050,7 +1053,6 @@ 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
Expand Down Expand Up @@ -1089,8 +1091,8 @@ const utilsExport = {
}
}
componentXmlLookup[`${rt}-${pt}`] = allXMLFragments
}else if (await utilsRDF.suggestTypeNetwork(ptObj.propertyURI) == 'http://www.w3.org/2000/01/rdf-schema#Resource'){

//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'){
// 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 ) )){
Expand Down
30 changes: 16 additions & 14 deletions src/lib/utils_profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ 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
Expand All @@ -360,8 +363,10 @@ 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'}

Expand All @@ -378,27 +383,24 @@ 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{
// 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

return false
}


}


if (isLocator){
// deleting this avoids the creation of a "rdf:Resource" tag for "URL of Instance"
delete pointer[0]["@type"]
}

return pointer


Expand Down
Loading

0 comments on commit c2240a8

Please sign in to comment.