Skip to content

Instantly share code, notes, and snippets.

View jgoldhammer's full-sized avatar

Jens Goldhammer jgoldhammer

View GitHub Profile
@jgoldhammer
jgoldhammer / alfresco simple batch processing example.js
Last active December 25, 2015 07:39
A first example to show the possibilities with the simple batch processing extension for alfresco javascript execution. It has the only limitation that the processorfunction must have the name process
var batchName ='MyProcessor';
var numberOfThreads = 4;
var numberOfProcessedItems = 10;
var runAsSystem = true;
var processorFunction = function process(node){
if(node.hasAspect('cm:titled')){
logger.error(node);
}
};
@jgoldhammer
jgoldhammer / alfresco jobs rootobject example.js
Last active December 25, 2015 07:48
Start a job via the jobs root object. You have to get the job first by its name and than can run the job. This action executes the "executeNow" function of the job Mbean in the jmx interface.
print(jobs.listJobs());
var job = jobs.getJob('tempFileCleanerTrigger');
job.run();
@jgoldhammer
jgoldhammer / alfresco policies root object example.js
Last active July 4, 2018 06:55
shows how to temporarly disable and enable the policy behaviours of a node
var node = search.findNode(<nodeRefOfADocumentOrFolder>);
var modified = node.properties.modified;
policies.disableForNode(node);
node.setName("C10");
node.save();
node.reset();
policies.enableForNode(node);
var modifiedAfter = node.properties.modified;
@jgoldhammer
jgoldhammer / alfresco jmxClient rootobject example.js
Last active December 25, 2015 07:48
the jmxClient provides access to the system/alfresco global properties by listing them and get a specific system/alfresco global property Only executable in the javascript console because of the print statement.
print(jmxClient.listSystemProperties());
print('Java version:'+jmxClient.getSystemProperty('java.version'));
print(jmx.listAlfProperties());
print('Activiti enabled?'+jmx.getAlfProperty('system.workflow.engine.activiti.enabled'));
@jgoldhammer
jgoldhammer / alfresco-start-temporary-job-in-repository.js
Last active December 19, 2016 12:18
Create a temporary (not persisted) job in alfresco to run javascript code in the backend
jobs.scheduleTemporaryJob({
jobName: 'SimpleAuthorModificationJob',
runAs: 'system',
cronExpression: '0 0/1 * 1/1 * ? *',
script: function(){
batchExecuter.processFolderRecursively({
'root': repository.getCompanyHome(),
onNode: function(node) {
if (node.isDocument) {
node.properties['cm:author'] = 'Alfresco';
@jgoldhammer
jgoldhammer / alfresco-database-root-object-example.js
Created October 16, 2016 21:11
How to use the database root object in alfresco to run queries against the database of alfresco. It allows to run queries and updates.
database.query("dataSource", "Select * from alf_node where id=?",2);
database.update("dataSource", "Update alf_node set id=? where id=?",2,2);
@jgoldhammer
jgoldhammer / alfresco-filewriter-rootobject-example.js
Last active October 17, 2016 21:18
example for the scriptwriter (can only be executed in js-console)
fileWriter.createFile();
fileWriter.appendLine("Hello");
var logfile = fileWriter.persist(
"Test"+java.lang.System.nanoTime(),
repository.getCompanyHome(),
"text/plain",
"cm:content",
false);
print(logfile.content);
@jgoldhammer
jgoldhammer / alfresco-downloads-script-example.js
Created October 16, 2016 22:20
example how to create a download of other files.
var download = downloads.create(repository.getCompanyHome(),true);
print(downloads.getStatus(download).getStatus());
// check if the company home node is a favorite of the current user
print(favorites.isFavorite(repository.getCompanyHome()));
// get all favorites of the current user with start =0 and limit 20
print(favorites.getFavorites(0,20));
// add the company home node as favorite of the user
favorites.add(repository.getCompanyHome());
print(permissions.getPermissions(repository.getCompanyHome());
print(permissions.hasPermission(repository.getCompanyHome().nodeRef,"Delete"));
print(permissions.hasPermission(repository.getCompanyHome().nodeRef,"Delete","abeecher"));
permissions.setPermission(repository.getCompanyHome().nodeRef,"Delete","abeecher",true);
print(permissions.hasPermission(repository.getCompanyHome().nodeRef,"Delete","abeecher"));
permissions.deletePermission(repository.getCompanyHome().nodeRef,"Delete","abeecher");
print(permissions.hasPermission(repository.getCompanyHome().nodeRef,"Delete","abeecher"));