Search in sources :

Example 1 with TaskNotFoundException

use of com.enonic.xp.task.TaskNotFoundException in project xp by enonic.

the class NamedTaskScriptFactoryImpl method doCreate.

private NamedTaskScript doCreate(final TaskDescriptor descriptor, final PropertyTree data) {
    final ResourceKey scriptResourceKey = ResourceKey.from(descriptor.getApplicationKey(), TASKS_PATH_PREFIX + descriptor.getName() + "/" + descriptor.getName() + ".js");
    final ScriptExports exports;
    try {
        exports = this.scriptService.execute(scriptResourceKey);
    } catch (ResourceNotFoundException e) {
        throw new TaskNotFoundException(descriptor.getKey(), "Missing task script");
    }
    final boolean exists = exports.hasMethod(NamedTaskScript.SCRIPT_METHOD_NAME);
    if (!exists) {
        throw new TaskNotFoundException(descriptor.getKey(), "Missing exported function '" + NamedTaskScript.SCRIPT_METHOD_NAME + "' in task script");
    }
    return new NamedTaskScript(exports, descriptor, data);
}
Also used : TaskNotFoundException(com.enonic.xp.task.TaskNotFoundException) ScriptExports(com.enonic.xp.script.ScriptExports) ResourceNotFoundException(com.enonic.xp.resource.ResourceNotFoundException) ResourceKey(com.enonic.xp.resource.ResourceKey)

Aggregations

ResourceKey (com.enonic.xp.resource.ResourceKey)1 ResourceNotFoundException (com.enonic.xp.resource.ResourceNotFoundException)1 ScriptExports (com.enonic.xp.script.ScriptExports)1 TaskNotFoundException (com.enonic.xp.task.TaskNotFoundException)1