Create the class

There are two type of project task:

  1. AbstractItemMigrationTask: tasks to apply to repository item (job, metadata, etc…)
  2. AbstractProjectMigrationTask: tasks to apply on a project (remove a folder, delete files, etc…)

AbstractItemMigrationTask

Those tasks will be aplied to all repository items. Override getTypes() method to specify only some item types.
You could extends AbstractJobMigrationTask instead of AbstractItemMigrationTask to make a task that will be apply only on jobs.

In our example, we will create a class which extends AbstractJobMigrationTask.
For example using only metadata items, see AddQuoteMarkMigrationTask.

1. Create a class
  1. Use org.talend.repository plugin
  2. use org.talend.repository.model.migration package
  3. Class must extends AbstractJobMigrationTask
2. implements required method

Use ModifyComponentsAction.searchAndRename() method:

    public ExecutionResult executeOnProcess(ProcessItem item) {
        try {
            ModifyComponentsAction.searchAndRename(item, "tRunProcess", "tRunJob"); //$NON-NLS-1$ //$NON-NLS-2$
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } catch (Exception e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
3. That's all

AbstractProjectMigrationTask

Those tasks are not relative to items.
For examples see ChangeXmiSerialization.
In this case, the method to implements is ExecutionResult execute(Project project).

Register this task

Register this class as a migration task using extension points

1. Edit "org.talend.repository" "plugin.xml" file
2. Add a project migration task:

:doc:addmigrationtaskextensionpoint.gif

3. Set properties as follow:

:doc:setmigrationtaskextpointprops.gif

  • id: represents the id of this migration task. This must be unique. This id will be referenced in projects to know if this task has been done.
  • name: the label of this task. Used in Error log view to log if this task is a success or a failure.
  • class: the complete name of the class created in step 1. Use Browse button to set it and class link to open it once filled.
  • beforeLogon: indicate if this task must be executed before or after user is logged on project. Rename component tasks must be executed after login, so specified false here (default value-nothing to do).

Test

1. Launch the product
2. Open "Error log" view
3. You should see this task done after logon in "Error log" view:

:doc:errorlogtaskdone.gif

4. You should see this line in "talend.project" file:
<migrationTasks>org.talend.repository.migration.renametRunProcess</migrationTasks>

indicating that this task has been done in that project.

To go farther

  • If you want to filter component more specifically (based on a node propertie for example), use ModifyComponentsAction.searchAndModify() method instead of ModifyComponentsAction.searchAndRename().
  • Same way if you want to do something else that renaming a component (add or remove a property for example).
  • See the RenametDBInputToMySQLMigrationTask migration task as a sample of these advanced use .
 
doc/component_rename.txt · Last modified: 2011/12/17 03:52 (external edit)
 
 
Recent changes RSS feed Driven by DokuWiki