use of org.alfresco.service.cmr.repository.ScriptLocation in project alfresco-repository by Alfresco.
the class ExecuteScriptJob method execute.
/**
* Executes the scheduled script
*
* @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
*/
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobData = context.getJobDetail().getJobDataMap();
// Get the script service from the job map
Object scriptServiceObj = jobData.get(PARAM_SCRIPT_SERVICE);
if (scriptServiceObj == null || !(scriptServiceObj instanceof ScriptService)) {
throw new AlfrescoRuntimeException("ExecuteScriptJob data must contain valid script service");
}
// Get the script location from the job map
Object scriptLocationObj = jobData.get(PARAM_SCRIPT_LOCATION);
if (scriptLocationObj == null || !(scriptLocationObj instanceof ScriptLocation)) {
throw new AlfrescoRuntimeException("ExecuteScriptJob data must contain valid script location");
}
// Get the authentication component from the job map
Object authenticationComponentObj = jobData.get(PARAM_AUTHENTICATION_COMPONENT);
if (authenticationComponentObj == null || !(authenticationComponentObj instanceof AuthenticationComponent)) {
throw new AlfrescoRuntimeException("ExecuteScriptJob data must contain valid authentication component");
}
// Execute the script as the system user
((AuthenticationComponent) authenticationComponentObj).setSystemUserAsCurrentUser();
try {
// Execute the script
((ScriptService) scriptServiceObj).executeScript((ScriptLocation) scriptLocationObj, null);
} finally {
((AuthenticationComponent) authenticationComponentObj).clearCurrentSecurityContext();
}
}
use of org.alfresco.service.cmr.repository.ScriptLocation in project alfresco-repository by Alfresco.
the class ActionTrackingServiceImplTest method testJavascriptAPI.
public void testJavascriptAPI() throws Exception {
// We need a background action to sleep for long enough for
// it still to be running when the JS fires off
final SleepActionExecuter sleepActionExec = (SleepActionExecuter) ctx.getBean(SleepActionExecuter.NAME);
sleepActionExec.setSleepMs(2000);
ActionImpl sleepAction;
ActionImpl action;
// Create three test actions:
((ActionTrackingServiceImpl) actionTrackingService).resetNextExecutionId();
// Sleep one that will still be running
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
sleepAction = (ActionImpl) createWorkingSleepAction(null);
// This isn't true!
sleepAction.setNodeRef(nodeRef);
this.actionService.executeAction(sleepAction, null, false, true);
txn.commit();
// Move one that will appear to be "running"
action = (ActionImpl) createFailingMoveAction();
actionTrackingService.recordActionExecuting(action);
// Finally one that has "failed"
// (Shouldn't show up in any lists)
txn = transactionService.getUserTransaction();
txn.begin();
action = (ActionImpl) createWorkingSleepAction(null);
action.setExecutionStartDate(new Date(1234));
action.setExecutionEndDate(new Date(54321));
action.setExecutionStatus(ActionStatus.Failed);
this.actionService.saveAction(this.nodeRef, action);
txn.commit();
// Call the test
Map<String, Object> model = new HashMap<String, Object>();
model.put("NodeRef", nodeRef.toString());
model.put("SleepAction", sleepAction);
ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/action/script/test_actionTrackingService.js");
this.scriptService.executeScript(location, model);
}
use of org.alfresco.service.cmr.repository.ScriptLocation in project alfresco-repository by Alfresco.
the class ActivityServiceImplTest method testJSAPI.
public void testJSAPI() throws Exception {
ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/activities/script/test_activityService.js");
String result = (String) this.scriptService.executeScript(location, new HashMap<String, Object>(0));
// Check the result and fail if message returned
if (result != null && result.length() != 0) {
fail("The activity service test JS script failed: " + result);
}
}
use of org.alfresco.service.cmr.repository.ScriptLocation in project alfresco-repository by Alfresco.
the class FormServiceImplTest method testJavascriptAPI.
@Test
public void testJavascriptAPI() throws Exception {
Map<String, Object> model = new HashMap<String, Object>();
model.put("testDoc", this.document.toString());
model.put("testDocName", this.documentName);
model.put("testAssociatedDoc", this.associatedDoc.toString());
model.put("folder", this.folder.toString());
model.put("folderName", this.folderName);
ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/forms/script/test_formService.js");
this.scriptService.executeScript(location, model);
}
use of org.alfresco.service.cmr.repository.ScriptLocation in project alfresco-repository by Alfresco.
the class SiteServiceImplTest method testJSAPI.
// == Test the JavaScript API ==
@Test
public void testJSAPI() throws Exception {
// Create a site with a custom property
SiteInfo siteInfo = this.siteService.createSite(TEST_SITE_PRESET, "mySiteWithCustomProperty", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
NodeRef siteNodeRef = siteInfo.getNodeRef();
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(1);
properties.put(QName.createQName(SiteModel.SITE_CUSTOM_PROPERTY_URL, "additionalInformation"), "information");
this.nodeService.addAspect(siteNodeRef, QName.createQName(SiteModel.SITE_MODEL_URL, "customSiteProperties"), properties);
// Create a model to pass to the unit test scripts
Map<String, Object> model = new HashMap<String, Object>();
model.put("customSiteName", "mySiteWithCustomProperty");
model.put("preexistingSiteCount", siteService.listSites(null, null).size());
// Execute the unit test script
ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/site/script/test_siteService.js");
this.scriptService.executeScript(location, model);
}
Aggregations