-
-
Save yregaieg/e9420508ea24b2cbc165212783e27f24 to your computer and use it in GitHub Desktop.
Alfresco Javascript Console Recipes
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
// Export ACP | |
var nodeToExport = companyhome.childByNamePath("Sites/swsdp/documentLibrary") | |
var exportAction= actions.create("export"); | |
exportAction.parameters['store'] = "workspace://SpacesStore"; | |
exportAction.parameters['package-name'] = "ACPexport"; | |
exportAction.parameters['destination'] = companyhome; | |
exportAction.parameters['include-children'] = true; | |
exportAction.parameters['include-self'] = false; | |
exportAction.parameters['encoding'] = "UTF-8"; | |
exportAction.execute(nodeToExport); |
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
var ctxt, synchronizer; | |
ctxt = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext(); | |
synchronizer = ctxt.getBean('userRegistrySynchronizer', Packages.org.alfresco.repo.security.sync.UserRegistrySynchronizer); | |
// forceUpdate = false, isFullSync = false - change for full update / with deletions | |
synchronizer.synchronize(false, false); |
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
var ctxt = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext(); | |
var properties = ctxt.getBean('global-properties', java.util.Properties); | |
logger.log(properties["db.user"]); |
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
var ctxt = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext(); | |
var nodeService = ctxt.getBean('NodeService', org.alfresco.service.cmr.repository.NodeService); | |
var QName = Packages.org.alfresco.service.namespace.QName; | |
var contentProp = QName.createQName("{http://www.alfresco.org/model/content/1.0}content"); | |
logger.log(nodeService.getProperty(document.nodeRef, contentProp).contentUrl); |
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
var users = people.getPeople(null); | |
for each(user in users){ | |
user = search.findNode(user); | |
logger.log(user.properties.userName+"," + user.properties.firstName+"," + user.properties.lastName + ","+user.properties.email); | |
} |
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
// Import ACP | |
var targetNodeForImport = companyhome.childByNamePath("Sites/swsdp2/documentLibrary"); | |
var ACPFile = companyhome.childByNamePath("ACPexport.acp"); | |
var importAction = actions.create("import"); | |
importAction.parameters.encoding = "UTF-8"; | |
importAction.parameters.destination = targetNodeForImport; | |
importAction.execute(ACPFile); |
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
Import a script from the repository using a name-based path: | |
<import resource="/Company Home/Data Dictionary/Scripts/library.js"> | |
Import a script from the repository using a NodeRef reference: | |
<import resource="workspace://SpacesStore/6f73de1b-d3b4-11db-80cb-112e6c2ea048"> | |
Import a script from a Java classpath location: | |
<import resource="classpath:alfresco/extension/myutils.js"> |
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
var s = siteService.getSites("", "", 0); | |
s.forEach(function(entry) { | |
var members = entry.listMembers(null, "", 0, false); | |
for (userName in members) { | |
logger.log(entry.shortName+ " :: "+ userName +" :: "+entry.getMembersRole(userName)); | |
} | |
}); |
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
var context = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext(); | |
var model = Packages.org.alfresco.model.ContentModel; | |
var policyBehaviourFilter = context.getBean('policyBehaviourFilter', Packages.org.alfresco.repo.policy.BehaviourFilter); | |
var def = { | |
query: "TYPE:'acme:targetType'", | |
language: "fts-alfresco" | |
}; | |
var nodes = search.query(def); | |
try { | |
policyBehaviourFilter.disableAllBehaviours(); | |
for each(var node in nodes) { | |
logger.log("Nuking node :" + node.nodeRef + " ; " + node.webdavUrl); | |
node.addAspect("sys:temporary"); | |
node.save(); | |
try { | |
node.remove(); | |
} catch (e) { | |
logger.log("^^^^^^ ERROR : " + e.message); | |
} | |
} | |
} finally { | |
policyBehaviourFilter.enableAllBehaviours(); | |
} |
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
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); | |
// For custom js based job - public urls for expiration | |
//scheduler.triggerJob('jobD', 'jobGroup'); | |
// For LDAP sync | |
// fire (unless explicitly defined in Job detail Spring bean, scheduler group is always DEFAULT) | |
scheduler.triggerJob('ldapPeopleJobDetail', 'DEFAULT'); |
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
function sendMail() { | |
var site = siteService.getSite(document.siteShortName); | |
var members = site.listMembers(null, "SiteManager", 0, false); | |
for (userName in members) { | |
var person = people.getPerson(userName); | |
var email = person.properties["cm:email"]; | |
var mail = actions.create("mail"); | |
mail.parameters.to = email; | |
mail.parameters.subject = "New document available: " + document.name; | |
mail.parameters.template = | |
companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/notify_user_email.html.ftl"); | |
mail.execute(document); | |
} | |
} | |
sendMail(); |
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
var context = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext(); | |
var model = Packages.org.alfresco.model.ContentModel; | |
var policyBehaviourFilter = context.getBean('policyBehaviourFilter', Packages.org.alfresco.repo.policy.BehaviourFilter); | |
setProperty(); | |
function setProperty() { | |
var referenceType = "node"; | |
var reference = ["workspace", "SpacesStore", "a8abc98e-bf2d-48ec-b3d8-002fa0cc7b97"]; | |
var node = search.findNode(referenceType, reference); | |
logger.log(node.name); | |
try { | |
logger.log("Modifiying node: " + node.name + " " + node.nodeRef); | |
policyBehaviourFilter.disableBehaviour(node.nodeRef, model.ASPECT_AUDITABLE); | |
node.properties['cm:title'] = 'Modified just now'; | |
node.save(); | |
} catch (e) { | |
logger.log(e.message); | |
} finally { | |
policyBehaviourFilter.enableBehaviour(node.nodeRef, model.ASPECT_AUDITABLE); | |
//Log modifier and modified date | |
logger.log("Modifier: " + node.properties['cm:modifier'] + " Modified: " + node.properties['cm:modified']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment