Dear All,
I am setting some metadata value from Sitecore to AEM using below code.
But here issue is that same assignedEditor Value is setting in the both metadata fields mc:assignedEditor and dcterms:creator , because I am not able to clear the value from Value[] valArrAME
Can anyone please help me here ?
package com.amemayoclinic.migration.scripts.utils
import org.slf4j.LoggerFactory
import org.apache.commons.lang.StringUtils
import javax.jcr.Session
import javax.jcr.Value
import javax.jcr.ValueFactory
import java.text.ParseException
import java.text.SimpleDateFormat
import javax.jcr.PropertyType
import java.util.Calendar
import java.util.TimeZone
class MetadataOperationsUtil {
def LOG = LoggerFactory.getLogger(MetadataOperationsUtil.class)
def globalConfigurations
def globalConstants
def session
def logUtil
Value[] valArrAME
def updateDitaMetaDataForAME(newTopicPath, conceptDetails){
try {
def metadataNode = session.getNode(newTopicPath + "/jcr:content/metadata")
if (metadataNode == null) {
LOG.debug("Metadata node missing for the asset ${newTopicPath}")
return
}
else {
ValueFactory valueFactory = session.getValueFactory()
SimpleDateFormat reviewDateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'")
if (conceptDetails.assignedEditor != null && conceptDetails.assignedEditor != "") {
def sitecoreAssignEditorValue = conceptDetails.assignedEditor
multiStringDataTypeAME(sitecoreAssignEditorValue)
LOG.debug("updateDitaMetaDataForAME sitecoreAssignEditorValue == ${valArrAME}")
if (valArrAME != null){
metadataNode.setProperty("mc:assignedEditor", valArrAME)
}
}
if (conceptDetails.creator != null && conceptDetails.creator != "") {
def sitecoreCreatorValue = conceptDetails.creator
multiStringDataTypeAME(sitecoreCreatorValue)
LOG.debug("updateDitaMetaDataForAME creatorValue == ${valArrAME}")
if (valArrAME != null){
metadataNode.setProperty("dcterms:creator", valArrAME)
}
}
}
session.save()
}
catch (Exception metax) {
LOG.debug("[ERROR]: updateDitaMetaDataForAME Metadata ${metax.getMessage()}")
}
}
def multiStringDataTypeAME(sitecoreproperty) {
ValueFactory valueFactory = session.getValueFactory()
if (sitecoreproperty.contains('|')) {
def multiValueProps = sitecoreproperty.split('\\|')
valArrAME = new Value[multiValueProps.size()]
for (int i = 0; i < multiValueProps.size(); i++) {
valArrAME[i] = valueFactory.createValue(multiValueProps[i])
}
LOG.debug("multiStringDataTypeAME sitecoreproperty IF == ${valArrAME}")
valArrAME.clear()
//valArrAME.removeAll(valArrAME)
//lst.removeAll(lst);
}
else {
if (sitecoreproperty != null && sitecoreproperty != "") {
valArrAME = new Value[1]
valArrAME[0] = valueFactory.createValue(sitecoreproperty)
LOG.debug("multiStringDataTypeAME sitecoreproperty ELSE == ${valArrAME}")
}
}
session.save()
}
MetadataOperationsUtil() {
/*Empty Constructor. */
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @SUNITACH1
Try to move global variable inside
def multiStringDataTypeAME(sitecoreproperty) {
Value[] valArrAME
.....
return valArrAME // no need to call save() inside this function
}
and return the value to caller function.
Value[] valArrAME = multiStringDataTypeAME(sitecoreAssignEditorValue)
Value[] valArrAME = multiStringDataTypeAME(sitecoreCreatorValue)
This is how you will have a correct value.
Hi @SUNITACH1
Try to move global variable inside
def multiStringDataTypeAME(sitecoreproperty) {
Value[] valArrAME
.....
return valArrAME // no need to call save() inside this function
}
and return the value to caller function.
Value[] valArrAME = multiStringDataTypeAME(sitecoreAssignEditorValue)
Value[] valArrAME = multiStringDataTypeAME(sitecoreCreatorValue)
This is how you will have a correct value.
Thanks. I have updated like below and it is working fine.
package com.migration.scripts.utils
import org.slf4j.LoggerFactory
import org.apache.commons.lang.StringUtils
import javax.jcr.Session
import javax.jcr.Value
import javax.jcr.ValueFactory
import java.text.ParseException
import java.text.SimpleDateFormat
import javax.jcr.PropertyType
import java.util.Calendar
import java.util.TimeZone
class MetadataOperationsUtil {
def LOG = LoggerFactory.getLogger(MetadataOperationsUtil.class)
def globalConfigurations
def globalConstants
def session
def logUtil
//Value[] valArrAME
def updateDitaMetaData(newTopicPath, conceptDetails){
try {
def metadataNode = session.getNode(newTopicPath + "/jcr:content/metadata")
if (metadataNode == null) {
LOG.debug("Metadata node missing for the asset ${newTopicPath}")
return
}
else {
ValueFactory valueFactory = session.getValueFactory()
SimpleDateFormat reviewDateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'")
if (conceptDetails.assignedEditor != null && conceptDetails.assignedEditor != "") {
def sitecoreAssignEditorValue = conceptDetails.assignedEditor
Value[] valArrAME = multiStringDataTypeAME(sitecoreAssignEditorValue)
if (valArrAME != null){
LOG.debug("updateDitaMetaData sitecoreAssignEditorValue == ${valArrAME}")
metadataNode.setProperty("mc:assignedEditor", valArrAME)
}
}
if (conceptDetails.creator != null && conceptDetails.creator != "") {
def sitecoreCreatorValue = conceptDetails.creator
Value[] valArrAME = multiStringDataTypeAME(sitecoreCreatorValue)
if (valArrAME != null){
LOG.debug("updateDitaMetaData sitecoreCreatorValue == ${valArrAME}")
metadataNode.setProperty("dcterms:creator", valArrAME)
}
}
}
session.save()
}
catch (Exception metax) {
LOG.debug("[ERROR]: updateDitaMetaDataForAME Metadata ${metax.getMessage()}")
}
}
def multiStringDataTypeAME(sitecoreproperty) {
ValueFactory valueFactory = session.getValueFactory()
Value[] valArrAME
if (sitecoreproperty.contains('|')) {
def multiValueProps = sitecoreproperty.split('\\|')
valArrAME = new Value[multiValueProps.size()]
for (int i = 0; i < multiValueProps.size(); i++) {
valArrAME[i] = valueFactory.createValue(multiValueProps[i])
}
//LOG.debug("multiStringDataTypeAME sitecoreproperty == ${valArrAME}")
}
else {
if (sitecoreproperty != null && sitecoreproperty != "") {
valArrAME = new Value[1]
valArrAME[0] = valueFactory.createValue(sitecoreproperty)
//LOG.debug("multiStringDataTypeAME sitecoreproperty INDEX0 == ${valArrAME}")
}
}
return valArrAME // no need to call save() inside this function
}
MetadataOperationsUtil() {
/*Empty Constructor. */
}
}
Views
Likes
Replies
Views
Likes
Replies