diff --git a/src/components/panels/edit/modals/HubStubCreateModal.vue b/src/components/panels/edit/modals/HubStubCreateModal.vue index 897b3c79..42eb14fd 100644 --- a/src/components/panels/edit/modals/HubStubCreateModal.vue +++ b/src/components/panels/edit/modals/HubStubCreateModal.vue @@ -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://') diff --git a/src/lib/utils_export.js b/src/lib/utils_export.js index 7e63f767..78609b48 100644 --- a/src/lib/utils_export.js +++ b/src/lib/utils_export.js @@ -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 @@ -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}` @@ -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') @@ -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 } diff --git a/src/lib/utils_profile.js b/src/lib/utils_profile.js index 96720c5b..610a0639 100644 --- a/src/lib/utils_profile.js +++ b/src/lib/utils_profile.js @@ -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 } diff --git a/src/stores/profile.js b/src/stores/profile.js index 32e29ed6..3a866f9d 100644 --- a/src/stores/profile.js +++ b/src/stores/profile.js @@ -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() @@ -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.")