Jump to content
groovyPost Forums

Not able to save metadata through Groovy


scat

Recommended Posts

Dear All,

We are migrating content from Sitecore to AEM.

For this below is the one Sitecore content  json

"topicBody": [
{
"itemId": "84dbfa1a",
"itemUrl": "",
"itemName": "Test Defect-Treatment",
"__typename": "TreatmentConcept",
"templateId": "c51297ec",
"pocId": "TXC-20096525",
"conceptBody": [
{
"itemId": "54ceda8a",
"itemName": "Test Defect-Closure",
"templateId": "d1a1f112",
"__typename": "KmSection",
"pocId": "SEC-2009",
"title": "Closure"
},
{
"itemId": "84134c21",
"itemName": "Test Defect-Patient Observation",
"templateId": "d1a1f112",
"__typename": "KmSection",
"pocId": "SEC-2006",
"title": "Observation"
}
],
"title": "Treatment",
"type": "",
"workflowItemManager": "mfad\\ALS07"
},
{
"itemId": "01ffe5c6",
"itemUrl": "",
"itemName": "Test Defect-Patient Considerations",
"__typename": "ConditionPatientConsiderationsConcept",
"templateId": "69265f07",
"pocId": "PTC-20117566",
"conceptBody": [
{
"itemId": "3a4f77ab",
"itemName": "Test Defect-Endocarditis Prophylaxis",
"templateId": "d1a1f112",
"__typename": "KmSection",
"pocId": "SEC-20096528",
"title": "Endocarditis prophylaxis"
}
],
"title": "Patient considerations",
"type": "",
"workflowItemManager": "mfad\\ALS07"
}
],

 

********************************* GROOVY SCRIPT **************************

I have written the below script for setting the metadata after creation of ditamap.

 

 
 def createADitaMap(title, topicBody){
        CreateDitaTopic topic = new CreateDitaTopic()
        try {
            def topicBodyItemTitle = title
            def newTopicPath
 
            if(type == "CPM"){
                JcrUtil.createPath(globalConfigurations.reuseLibraryCpmMaps+"/"+topicBodyItemTitle, JcrResourceConstants.NT_SLING_FOLDER, JcrResourceConstants.NT_SLING_FOLDER, session, true)
                newTopicPath = globalConfigurations.reuseLibraryCpmMaps+"/"+topicBodyItemTitle+"/"+topicBodyItemTitle+".ditamap"
            }else {
                JcrUtil.createPath(globalConfigurations.ameDitaMapBaseFolderPath+"/"+baseFolderForPoc+"/mapsandTopics", JcrResourceConstants.NT_SLING_FOLDER, JcrResourceConstants.NT_SLING_FOLDER, session, true)
                newTopicPath = globalConfigurations.ameDitaMapBaseFolderPath+"/"+baseFolderForPoc+"/mapsandTopics/"+topicBodyItemTitle+".ditamap"
            }
 
            def lbMapnode = resourceResolver.getResource(newTopicPath)
            if(null == lbMapnode) {
topic.create(session, title, newTopicPath, globalConfigurations.clinicalKnowledgeditaMapTemplatePath, resourceResolver, true)
def metadataNode = session.getNode(newTopicPath + "/jcr:content/metadata")
//out.println "metadataNode for updateDitaMetaDataForAME: ${metadataNode}"
if (metadataNode != null) {
metadataNode.setProperty("dc:title", topicBodyItemTitle)
metadataNode.setProperty("mc:assignedEditor", topicBody.assignedEditor)
metadataNode.setProperty("mc:PocId", topicBody.pocId)
}
                
            }
            session.save()
        } catch (NullPointerException npe) { /* Handling transitive API exception. */
            out.println "NullPointer Exception during topic creation in createADitaMap ${npe.getMessage()}"
        }catch (Exception e) {
            out.println "Exception during topic creation in createADitaMap ${e}"
        }
    }

Here my metadata is not saving and not working. I am getting the topicBodyItemTitle value dynamically. But metadata is not saving and also it should save like if TOPICBODY title is topicBodyItemTitle  then it should save the metadata related to topicbody and not conceptbody. I am not able to achieve this. Can somebody please help me here.

Thanks in advance.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Who's Online   0 Members, 0 Anonymous, 1 Guest (See full list)

    • There are no registered users currently online
×
×
  • Create New...