ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
AccessController.checkAccess(context.getServiceContext(), ACL_ADD_APPLICATIONS);
ApplicationClusterForm clusterForm = (ApplicationClusterForm)actionForm;
String[] childAppIds =
StringUtils.csvToStringArray(clusterForm.getSelectedChildApplications());
/* build list of new child applications */
List<ApplicationConfig> newChildApplications = getNewChildApplications(childAppIds);
String applicationId = clusterForm.getApplicationId();
if(applicationId != null){
/* update existing application */
ApplicationClusterConfig clusterConfig =
(ApplicationClusterConfig)
ApplicationConfigManager.getApplicationConfig(applicationId);
assert clusterConfig != null;
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);
}