Skip to content

Commit

Permalink
Merge pull request #169 from lcnetdev/stub-hub-language
Browse files Browse the repository at this point in the history
add label and clean up hub stub creation logic
  • Loading branch information
thisismattmiller authored Dec 16, 2024
2 parents 81af73c + d8b7298 commit 8f7c740
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 49 deletions.
14 changes: 12 additions & 2 deletions src/components/panels/edit/modals/HubStubCreateModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,19 @@
async buildHub(){
let langObj
if (this.hubLang){
langObj = {
uri: this.hubLang,
label: this.langsLookup.filter((v)=> { return (v.uri == this.hubLang) } )[0].label
}
}else{
langObj = null
}
this.postStatus='posting'
let results = await this.profileStore.buildPostHubStub(this.hubCreator,this.hubTitle,this.hubLang,this.preferenceStore.catCode)
let results = await this.profileStore.buildPostHubStub(this.hubCreator,this.hubTitle,langObj,this.preferenceStore.catCode)
if (results && results.postLocation){
results.postLocation = results.postLocation.replace("http://",'https://')
Expand Down
95 changes: 55 additions & 40 deletions src/lib/utils_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -1750,13 +1750,13 @@ const utilsExport = {
*
* @param {object} hubCreatorObj - obj with creator label, uri,marcKey
* @param {string} title - title string
* @param {string} langUri - uri to language
* @param {string} langObj - {uri:"",label:""}
* @return {string}
*/
createHubStubXML: async function(hubCreatorObj,title,langUri,catalogerId){
createHubStubXML: async function(hubCreatorObj,title,langObj,catalogerId){

console.log(hubCreatorObj,title,langUri,catalogerId)




// we are creating the xml in two formats, create the root node for both
Expand All @@ -1769,13 +1769,20 @@ const utilsExport = {
rdfBasic.setAttributeNS("http://www.w3.org/2000/xmlns/", `xmlns:${ns}`, this.namespace[ns])
}

if (!hubCreatorObj) return false
if (!hubCreatorObj.label || !hubCreatorObj.marcKey ||!hubCreatorObj.uri) return false
// they are allowed to have a hub without a creator...
// if (!hubCreatorObj) return false
// if (!hubCreatorObj.label || !hubCreatorObj.marcKey ||!hubCreatorObj.uri) return false

// but needsa title
if (!title) return false

console.log("hubCreatorObj",hubCreatorObj)
if (!hubCreatorObj){ hubCreatorObj = {'label':''}}
if (!hubCreatorObj.label){ hubCreatorObj.label = ''}



let aap = utilsProfile.returnAap(hubCreatorObj.label,title)

let aapHash = await md5(aap)
aapHash = `${aapHash.slice(0, 8)}-${aapHash.slice(8, 12)}-${aapHash.slice(12, 16)}-${aapHash.slice(16, 20)}-${aapHash.slice(20, 32)}`
let hubUri = `http://id.loc.gov/resources/hubs/${aapHash}`
Expand All @@ -1799,51 +1806,58 @@ const utilsExport = {


// the creator
let elContributionProperty = document.createElementNS(this.namespace.bf ,'bf:contribution')
let elContributionClass = document.createElementNS(this.namespace.bf ,'bf:Contribution')
if (hubCreatorObj && hubCreatorObj.label && hubCreatorObj.label != ''){
let elContributionProperty = document.createElementNS(this.namespace.bf ,'bf:contribution')
let elContributionClass = document.createElementNS(this.namespace.bf ,'bf:Contribution')

let rdftype = this.createElByBestNS('rdf:type')
rdftype.setAttributeNS(this.namespace.rdf, 'rdf:resource', 'http://id.loc.gov/ontologies/bibframe/PrimaryContribution')
let rdftype = this.createElByBestNS('rdf:type')
rdftype.setAttributeNS(this.namespace.rdf, 'rdf:resource', 'http://id.loc.gov/ontologies/bibframe/PrimaryContribution')

elContributionClass.appendChild(rdftype)
elContributionProperty.appendChild(elContributionClass)
elContributionClass.appendChild(rdftype)
elContributionProperty.appendChild(elContributionClass)

let elAgentProperty = document.createElementNS(this.namespace.bf ,'bf:agent')
let elAgentClass = document.createElementNS(this.namespace.bf ,'bf:Agent')
elAgentClass.setAttributeNS(this.namespace.rdf, 'rdf:about', hubCreatorObj.uri)
let elAgentProperty = document.createElementNS(this.namespace.bf ,'bf:agent')
let elAgentClass = document.createElementNS(this.namespace.bf ,'bf:Agent')
elAgentClass.setAttributeNS(this.namespace.rdf, 'rdf:about', hubCreatorObj.uri)



elAgentProperty.appendChild(elAgentClass)
elAgentProperty.appendChild(elAgentClass)

// let elAgentType = document.createElementNS(this.namespace.bf ,'bf:agent')
let AgentRdftype = this.createElByBestNS('rdf:type')
AgentRdftype.setAttributeNS(this.namespace.rdf, 'rdf:resource', hubCreatorObj.typeFull)
// let elAgentType = document.createElementNS(this.namespace.bf ,'bf:agent')
let AgentRdftype = this.createElByBestNS('rdf:type')
AgentRdftype.setAttributeNS(this.namespace.rdf, 'rdf:resource', hubCreatorObj.typeFull)

elAgentClass.appendChild(AgentRdftype)
let elAgentLabel = document.createElementNS(this.namespace.rdfs ,'rdfs:label')
elAgentLabel.innerHTML = hubCreatorObj.label
elAgentClass.appendChild(elAgentLabel)
elAgentClass.appendChild(AgentRdftype)
let elAgentLabel = document.createElementNS(this.namespace.rdfs ,'rdfs:label')
elAgentLabel.innerHTML = hubCreatorObj.label
elAgentClass.appendChild(elAgentLabel)

let elAgentMarcKey = document.createElementNS(this.namespace.bflc ,'bflc:marcKey')
elAgentMarcKey.innerHTML = hubCreatorObj.marcKey
elAgentClass.appendChild(elAgentMarcKey)
let elAgentMarcKey = document.createElementNS(this.namespace.bflc ,'bflc:marcKey')
elAgentMarcKey.innerHTML = hubCreatorObj.marcKey
elAgentClass.appendChild(elAgentMarcKey)

elContributionClass.appendChild(elAgentProperty)
elContributionClass.appendChild(elAgentProperty)

elHub.appendChild(elContributionProperty)
elHub.appendChild(elContributionProperty)
}

if (langObj){
let elLanguageProperty = document.createElementNS(this.namespace.bf ,'bf:language')
let elLanguageClass = document.createElementNS(this.namespace.bf ,'bf:Language')
elLanguageClass.setAttributeNS(this.namespace.rdf, 'rdf:about', langObj.uri)

let elLanguageProperty = document.createElementNS(this.namespace.bf ,'bf:language')
let elLanguageClass = document.createElementNS(this.namespace.bf ,'bf:Language')
elLanguageClass.setAttributeNS(this.namespace.rdf, 'rdf:about', langUri)
let elCodeProperty = document.createElementNS(this.namespace.bf ,'bf:code')
elCodeProperty.innerHTML = langObj.uri.split("/").pop();
elLanguageClass.appendChild(elCodeProperty)
elLanguageProperty.appendChild(elLanguageClass)

let elCodeProperty = document.createElementNS(this.namespace.bf ,'bf:code')
elCodeProperty.innerHTML = langUri.split("/").pop();
elLanguageClass.appendChild(elCodeProperty)
elLanguageProperty.appendChild(elLanguageClass)
elHub.appendChild(elLanguageProperty)
let elLangLabel = document.createElementNS(this.namespace.rdfs ,'rdfs:label')
elLangLabel.innerHTML = langObj.label
elLanguageClass.appendChild(elLangLabel)

elHub.appendChild(elLanguageProperty)
}

// // uri
// let elTitleProperty = document.createElementNS(this.namespace.bf ,'bf:title')
Expand Down Expand Up @@ -1924,12 +1938,13 @@ const utilsExport = {

rdf.appendChild(elHub)

console.log(aap)
console.log(aapHash)
console.log(hubUri)
// console.log(aap)
// console.log(aapHash)
// console.log(hubUri)
// console.log(rdf)
let xml = (new XMLSerializer()).serializeToString(rdf)

console.log(xml)
// console.log(xml)
return xml

}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils_profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ const utilsProfile = {
* @return {string} - the AAP
*/
returnAap: function(contributor,title){
if (!contributor || !title){
if (contributor == null || !title || typeof(contributor) == 'undefined'){
return false
}

Expand Down
10 changes: 4 additions & 6 deletions src/stores/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4498,13 +4498,13 @@ export const useProfileStore = defineStore('profile', {
*
* @param {object} hubCreatorObj - obj with creator label, uri,marcKey
* @param {string} title - title string
* @param {string} langUri - uri to language
* @param {string} langObj - {uri:"",label:""}
* @return {String}
*/
async buildPostHubStub(hubCreatorObj,title,langUri,catCode){
async buildPostHubStub(hubCreatorObj,title,langObj,catCode){

console.log("hubCreatorObj",hubCreatorObj)
let xml = await utilsExport.createHubStubXML(hubCreatorObj,title,langUri,catCode)
// console.log("hubCreatorObj",hubCreatorObj)
let xml = await utilsExport.createHubStubXML(hubCreatorObj,title,langObj,catCode)

console.log(xml)
let eid = 'e' + decimalTranslator.new()
Expand All @@ -4515,8 +4515,6 @@ export const useProfileStore = defineStore('profile', {
try{
pubResuts = await utilsNetwork.publish(xml, eid, {id: 'Hub'})



}catch (error){
console.log(error)
alert("There was an error creating your Hub. Please report this issue.")
Expand Down

0 comments on commit 8f7c740

Please sign in to comment.