clusterConfig.setName(clusterForm.getName());
final List oldChildApplications = clusterConfig.getApplications();
/* add applications outside the cluster
(applications that are no longer in the cluster) */
for(Iterator it=oldChildApplications.iterator();it.hasNext();){
ApplicationConfig appConfig = (ApplicationConfig)it.next();
if(!newChildApplications.contains(appConfig)){
ApplicationConfigManager.addApplication(appConfig);
appConfig.setClusterConfig(null);
}
}
/* remove applications outside the cluster
(applications that are now part of cluster) */
for(Iterator it=newChildApplications.iterator();it.hasNext();){
ApplicationConfig appConfig = (ApplicationConfig)it.next();
if(!oldChildApplications.contains(appConfig)){
ApplicationConfigManager.deleteApplication(appConfig);
appConfig.setClusterConfig(clusterConfig);
}
}
clusterConfig.setApplications(newChildApplications);
ApplicationConfigManager.updateApplication(clusterConfig);
UserActivityLogger.getInstance().logActivity(
context.getUser().getUsername(),
"Updated application cluster "+ "\""+clusterConfig.getName()+"\"");
}else{
/* add new application cluster */
ApplicationClusterConfig clusterConfig =
new ApplicationClusterConfig(
ApplicationConfig.getNextApplicationId(),
clusterForm.getName());
for(Iterator it=newChildApplications.iterator();it.hasNext();){
ApplicationConfig appConfig = (ApplicationConfig)it.next();
appConfig.setClusterConfig(clusterConfig);
ApplicationConfigManager.deleteApplication(appConfig, true);
}
clusterConfig.setApplications(newChildApplications);
/* remove from stand-alone list */