|
|
@ -20,15 +20,10 @@ import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.w3c.dom.Document;
|
|
|
|
import org.w3c.dom.Document;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.rssmanager.core.dao.RSSDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.exception.DeviceMgtDAOFactory;
|
|
|
|
import org.wso2.carbon.rssmanager.core.environment.EnvironmentManager;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|
|
|
import org.wso2.carbon.rssmanager.core.environment.EnvironmentManagerFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.DeviceMgtDbCreator;
|
|
|
|
import org.wso2.carbon.rssmanager.core.exception.RSSManagerException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.rssmanager.core.manager.adaptor.EnvironmentAdaptor;
|
|
|
|
|
|
|
|
import org.wso2.carbon.rssmanager.core.util.RSSDbCreator;
|
|
|
|
|
|
|
|
import org.wso2.carbon.rssmanager.core.util.RSSManagerUtil;
|
|
|
|
|
|
|
|
import org.wso2.carbon.utils.CarbonUtils;
|
|
|
|
import org.wso2.carbon.utils.CarbonUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
import javax.xml.bind.Unmarshaller;
|
|
|
|
import javax.xml.bind.Unmarshaller;
|
|
|
@ -39,12 +34,11 @@ import java.io.File;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class DeviceConfigurationManager {
|
|
|
|
public class DeviceConfigurationManager {
|
|
|
|
|
|
|
|
|
|
|
|
private RSSConfig currentRSSConfig;
|
|
|
|
private DeviceMgtConfig currentDeviceConfig;
|
|
|
|
private static DeviceConfigurationManager deviceConfigManager;
|
|
|
|
private static DeviceConfigurationManager deviceConfigManager;
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(DeviceConfigurationManager.class);
|
|
|
|
private static final Log log = LogFactory.getLog(DeviceConfigurationManager.class);
|
|
|
|
private final String rssConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "conf" + File
|
|
|
|
private final String deviceMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
|
|
|
|
.separator +
|
|
|
|
|
|
|
|
DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME;
|
|
|
|
DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME;
|
|
|
|
|
|
|
|
|
|
|
|
private final String cdmSetupSql = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator +
|
|
|
|
private final String cdmSetupSql = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator +
|
|
|
@ -64,41 +58,30 @@ public class DeviceConfigurationManager {
|
|
|
|
|
|
|
|
|
|
|
|
public synchronized void initConfig() throws DeviceManagementException {
|
|
|
|
public synchronized void initConfig() throws DeviceManagementException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
File rssConfig = new File(rssConfigXMLPath);
|
|
|
|
File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
|
|
|
|
Document doc = RSSManagerUtil.convertToDocument(rssConfig);
|
|
|
|
Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
|
|
|
|
|
|
|
|
/* Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
|
|
|
|
//rss-config supports secure vault as it needs to be resolve when parsing
|
|
|
|
//rss-config supports secure vault as it needs to be resolve when parsing
|
|
|
|
RSSManagerUtil.secureResolveDocument(doc);
|
|
|
|
DeviceManagerUtil.secureResolveDocument(doc);*/
|
|
|
|
/* Un-marshaling RSS configuration */
|
|
|
|
/* Un-marshaling RSS configuration */
|
|
|
|
JAXBContext rssContext = JAXBContext.newInstance(RSSConfig.class);
|
|
|
|
JAXBContext rssContext = JAXBContext.newInstance(DeviceMgtConfig.class);
|
|
|
|
Unmarshaller unmarshaller = rssContext.createUnmarshaller();
|
|
|
|
Unmarshaller unmarshaller = rssContext.createUnmarshaller();
|
|
|
|
this.currentRSSConfig = (RSSConfig) unmarshaller.unmarshal(doc);
|
|
|
|
this.currentDeviceConfig = (DeviceMgtConfig) unmarshaller.unmarshal(doc);
|
|
|
|
//set jndi data source name for future use
|
|
|
|
//set jndi data source name for future use
|
|
|
|
RSSManagerUtil.setJndiDataSourceName(currentRSSConfig.getRSSManagementRepository().getDataSourceConfig().
|
|
|
|
DeviceManagerUtil.setJndiDataSourceName(currentDeviceConfig.getDeviceMgtRepository().getDataSourceConfig().
|
|
|
|
getJndiLookupDefintion().getJndiName());
|
|
|
|
getJndiLookupDefintion().getJndiName());
|
|
|
|
DataSource dataSource = RSSDAOFactory.resolveDataSource(this.currentRSSConfig.getRSSManagementRepository()
|
|
|
|
DataSource dataSource = DeviceMgtDAOFactory.resolveDataSource(this.currentDeviceConfig.getDeviceMgtRepository()
|
|
|
|
.getDataSourceConfig());
|
|
|
|
.getDataSourceConfig());
|
|
|
|
RSSManagerUtil.setDataSource(dataSource);
|
|
|
|
DeviceManagerUtil.setDataSource(dataSource);
|
|
|
|
String setupOption = System.getProperty("setup");
|
|
|
|
|
|
|
|
//if -Dsetup option specified then create rss manager tables
|
|
|
|
|
|
|
|
if (setupOption != null) {
|
|
|
|
|
|
|
|
log.info("Setup option specified");
|
|
|
|
|
|
|
|
RSSDbCreator dbCreator = new RSSDbCreator(dataSource);
|
|
|
|
|
|
|
|
dbCreator.setRssDBScriptDirectory(cdmSetupSql);
|
|
|
|
|
|
|
|
log.info("Creating Meta Data tables");
|
|
|
|
|
|
|
|
dbCreator.createRegistryDatabase();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Initialization of environment manager
|
|
|
|
|
|
|
|
EnvironmentManager environmentManager = EnvironmentManagerFactory.getEnvironmentManager(currentRSSConfig.
|
|
|
|
|
|
|
|
getRSSEnvironments());
|
|
|
|
|
|
|
|
environmentManager
|
|
|
|
|
|
|
|
.initEnvironments(currentRSSConfig.getRSSProvider(), currentRSSConfig.getRSSManagementRepository());
|
|
|
|
|
|
|
|
this.adaptor = new EnvironmentAdaptor(environmentManager);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RSSManagerException("Error occurred while initializing RSS config", e);
|
|
|
|
throw new DeviceManagementException("Error occurred while initializing RSS config", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public RSSConfig getCurrentRSSConfig() {
|
|
|
|
|
|
|
|
return currentRSSConfig;
|
|
|
|
|
|
|
|
|
|
|
|
public DeviceMgtConfig getCurrentDeviceConfig() {
|
|
|
|
|
|
|
|
return currentDeviceConfig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|