1 16 package org.jmanage.core.services; 17 18 import org.jmanage.core.config.*; 19 import org.jmanage.core.data.ApplicationConfigData; 20 import org.jmanage.core.data.MBeanData; 21 import org.jmanage.core.util.UserActivityLogger; 22 import org.jmanage.core.util.CoreUtils; 23 import org.jmanage.core.util.ACLConstants; 24 import org.jmanage.core.util.ErrorCodes; 25 26 import java.util.ArrayList ; 27 import java.util.List ; 28 import java.util.Iterator ; 29 30 35 public class ConfigurationServiceImpl implements ConfigurationService { 36 37 public ApplicationConfigData addApplication(ServiceContext context, 38 ApplicationConfigData data){ 39 40 AccessController.checkAccess(context, ACLConstants.ACL_ADD_APPLICATIONS); 41 42 String appId = ApplicationConfig.getNextApplicationId(); 43 Integer port = data.getPort(); 44 45 ApplicationConfig config = 46 ApplicationConfigFactory.create(appId, data.getName(), 47 data.getType(), 48 data.getHost(), 49 port, 50 data.getURL(), 51 data.getUsername(), 52 data.getPassword(), 53 data.getParamValues()); 54 55 try { 56 ApplicationConfigManager.addApplication(config); 57 } catch (ApplicationConfigManager.DuplicateApplicationNameException e) { 58 throw new ServiceException(ErrorCodes.APPLICATION_NAME_ALREADY_EXISTS, 59 e.getAppName()); 60 } 61 62 data.setApplicationId(appId); 63 64 65 UserActivityLogger.getInstance().logActivity( 66 context.getUser().getUsername(), 67 "Added application "+ "\""+config.getName()+"\""); 68 69 return data; 70 } 71 72 public List getAllApplications(ServiceContext context) { 74 List appConfigs = ApplicationConfigManager.getApplications(); 75 return appConfigListToAppConfigDataList(appConfigs); 76 } 77 78 private List appConfigListToAppConfigDataList(List appConfigs){ 79 ArrayList appDataObjs = new ArrayList (appConfigs.size()); 80 for(Iterator it=appConfigs.iterator(); it.hasNext(); ){ 81 ApplicationConfigData configData = new ApplicationConfigData(); 82 ApplicationConfig appConfig = (ApplicationConfig)it.next(); 83 CoreUtils.copyProperties(configData, appConfig); 84 appDataObjs.add(configData); 85 if(appConfig.isCluster()){ 86 List childApplications = 87 appConfigListToAppConfigDataList(appConfig.getApplications()); 88 configData.setChildApplications(childApplications); 89 } 90 } 91 return appDataObjs; 92 } 93 94 95 public List getConfiguredMBeans(ServiceContext context) 96 throws ServiceException { 97 98 AccessController.checkAccess(context, 99 ACLConstants.ACL_VIEW_APPLICATIONS); 100 101 String applicationName = context.getApplicationConfig().getName(); 102 ApplicationConfig appConfig = 103 ServiceUtils.getApplicationConfigByName(applicationName); 104 List mbeanList = appConfig.getMBeans(); 105 ArrayList mbeanDataList = new ArrayList (mbeanList.size()); 106 for(Iterator it=mbeanList.iterator(); it.hasNext();){ 107 MBeanConfig mbeanConfig = (MBeanConfig)it.next(); 108 mbeanDataList.add(new MBeanData(mbeanConfig.getObjectName(), 109 mbeanConfig.getName())); 110 } 111 return mbeanDataList; 112 } 113 114 public GraphConfig addGraph(ServiceContext context,GraphConfig graphConfig){ 115 ApplicationConfig appConfig = context.getApplicationConfig(); 116 try { 118 ApplicationConfigManager.updateApplication(appConfig); 119 } catch (ApplicationConfigManager.DuplicateApplicationNameException e) { 120 throw new RuntimeException (e); 122 } 123 return graphConfig; 124 } 125 } 126 | Popular Tags |