Managing Applications with RedwoodScript
You can use RedwoodScript to manage applications. ApplicationObjects are objects that can have an application and the application can be retrieved by the getParentApplication() method. This differs from most other properties, because of the Parent part of the method name. This has been done, so that the method name matches the name of the method you use on application objects.
Example
You want to move all objects from the Global.App1 to the Global.App1.Part1.App2 application.
{
Partition partition = jcsSession.getPartitionByName("Part1");
Application oldApplication = jcsSession.getApplicationByName("App1");
Application newApplication = jcsSession.getApplicationByName(partition, oldApplication, "App2");
for (ApplicationObject o : oldApplication.getChildApplications())
{
o.setParentApplication(newApplication);
jcsSession.persist();
}
}
You want to force users to specify an application when ApplicationObjects (except Applications) are created. (Note that ApplicationObjects are objects which can have a parent application). This can be used as a trigger.
{
Object o = jcsTriggerContext.getSchedulerEntity();
if (o instanceof ApplicationObject && ((ApplicationObject) o).getParentApplication() == null && !( o instanceof Application))
{
throw new RuntimeException("Object " + jcsTriggerContext.getSchedulerEntity().getErrorNameEN() + " does not have an Application set. Please set an application!");
}
}
Redwood Script