Examples: mapping rules using in-line Groovy

Here are examples of the ignoring files of type executable only on Fridays and the setting a day-of-week attribute rules.

Ignoring files of type executable only on Fridays

This sample rule ignores files with type executable unless the files is executable only on a Friday. This rule illustrates how to write a condition in Groovy while leaving the action in written using the built-in action.
INSERT {
IMPORT com.telelogic.cm.migrate.MigrateObject;
IMPORT static java.util.Calendar.*;
}

WHEN { migrateObject.type() == 'executable' &&
	Calendar.getInstance().get(DAY_OF_WEEK) != FRIDAY } IGNORE

Setting a day-of-week attribute

This sample rule sets the 'day' attribute on all files named '*.day' to the name of the week day. While this rule might not be useful, it illustrates how to write an action in Groovy while leaving the condition in written using built-in condition.

Although this example is excessive and is longer than needed, the example shows how to use the INSERT mechanism to declare some helper methods.
IMPORT com.telelogic.cm.migrate.MigrateObject;
IMPORT org.joda.time.*;

WHEN %name ~ '*.day' { migrateObject.setAttribute('day', getWeekDay()) }

INSERT
{
	String getWeekDay()
	{
		return new DateTime().dayOfWeek().getAsText();
	}

}

Feedback