Skip to content

Instantly share code, notes, and snippets.

@hi-ko
Last active November 29, 2022 18:08
Show Gist options
  • Save hi-ko/a39a0d1b4c2ed2009865ba294e5c5a56 to your computer and use it in GitHub Desktop.
Save hi-ko/a39a0d1b4c2ed2009865ba294e5c5a56 to your computer and use it in GitHub Desktop.
Alfresco Javascript Console Recipes
function getGlobalPropertyValue(propertyValue){
var ctxt = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
var globalProperties = ctxt.getBean('global-properties', Packages.java.util.Properties);
var placeholderHelper = new Packages.org.springframework.util.PropertyPlaceholderHelper('${', '}', ':', true);
var propertyValue = globalProperties[propertyValue];
if (propertyValue){
propertyValue = placeholderHelper.replacePlaceholders(propertyValue, globalProperties);
}
return propertyValue;
}
logger.log(getGlobalPropertyValue("share.host"));
function getSolrSummary() {
model.solrSubsystemEnabled = true;
var indexSubsystem='solr6';
var ctxt = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
var solrContextFactory = ctxt.getBean(indexSubsystem, Packages.org.alfresco.repo.search.impl.solr.SolrChildApplicationContextFactory);
var solrContext = solrContextFactory.getApplicationContext();
var solrAdminClient = solrContext
.getBean('search.solrAdminHTTPCLient', Packages.org.alfresco.repo.search.impl.solr.SolrAdminHTTPClient);
var args = new Packages.java.util.HashMap();
args.action = 'SUMMARY';
args.wt = 'json';
var trackingSummaryResponse = solrAdminClient.execute(args);
args.action = 'STATUS';
var trackingStatusResponse = solrAdminClient.execute(args);
var trackingSummary = JSON.parse(trackingSummaryResponse).Summary;
var trackingStatus = JSON.parse(trackingStatusResponse).status;
model.trackingSummary = trackingSummary;
model.trackingStatus = trackingStatus;
var coreNames = Object.keys(trackingSummary);
coreNames.sort(function(a, b){
return a.localeCompare(b);
});
model.coreNames = coreNames;
return model
}
print(getSolrSummary());
var ctxt, scheduler;
// get Spring context and Quartz scheduler
ctxt = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
scheduler = ctxt.getBean('schedulerFactory', Packages.org.quartz.Scheduler);
var jobKey = new Packages.org.quartz.JobKey('ldapPeopleJobDetail', 'DEFAULT');
print(jobKey);
// fire (unless explicitly defined in Job detail Spring bean, scheduler group is always DEFAULT)
scheduler.triggerJob(jobKey);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment