Last active
June 10, 2020 13:40
-
-
Save yregaieg/6aaf35b884701aca5f4cd358613764e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Script to locate error nodes from solr error report, and do something with them. | |
* | |
* @author Younes Regaieg <[email protected]> | |
* @version 1.0 | |
**/ | |
//----- Solr error report to be fetched from solr /solr4/alfresco/query?q=EXCEPTIONMESSAGE:*&wt=json&rows=<number-of-rows-to-fetch> | |
//----- Swap this dummy object with a real object from the output of the endpoint mentionned above. | |
var solrErrorsReport = { | |
"responseHeader":{ | |
"status":0, | |
"QTime":0, | |
"params":{ | |
"q":"EXCEPTIONMESSAGE:*", | |
"rows":"10", | |
"wt":"json"}}, | |
"response":{"numFound":265,"start":0,"docs":[ | |
{ | |
"id":"ERROR-123", | |
"_version_":0, | |
"DBID":123}] | |
}}; | |
//---- The actual process method, proceed with care, and do what ever is necessary to fix the node ! | |
function process(node){ | |
logger.log("Processing node " + node.nodeRef + " with name " + node.name); | |
// Delete the node -- this actually just archives the node unless aspect Temporary is applied | |
// To actually delete the node, you need to uncomment the next line ! | |
// node.remove(); | |
} | |
//------------ The real magic happens here, you probably should not fiddle with the following part --------------- | |
//---------------------------------------------------------------------------------------------------------------- | |
var ctx = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext(); | |
var nodeService = ctx.getBean("nodeService", Packages.org.alfresco.service.cmr.repository.NodeService); | |
if (solrErrorsReport.response){ | |
if (solrErrorsReport.response.docs){ | |
var docs = solrErrorsReport.response.docs; | |
for (var i=0; i<docs.length; i++){ | |
var doc = docs[i]; | |
logger.log("Detected DBID:"+doc.DBID); | |
var nodeRef = nodeService.getNodeRef(doc.DBID); | |
if (nodeRef){ | |
var node = search.findNode(nodeRef); | |
process(node); | |
}else{ | |
logger.log("It sounds like the node does no longer exist !"); | |
} | |
} | |
}else{ | |
logger.log("no errors detected !"); | |
} | |
}else{ | |
logger.log("Sounds like a mal-formatted object was provided !"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment