|
|
@ -20,8 +20,8 @@ package org.wso2.carbon.device.mgt.core.config.tenant;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
|
|
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
|
|
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfigurationManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.ConfigurationManagerConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.ConfigurationManagerConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.util.ConfigurationManagerUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.util.ConfigurationManagerUtil;
|
|
|
|
import org.wso2.carbon.registry.api.Resource;
|
|
|
|
import org.wso2.carbon.registry.api.Resource;
|
|
|
@ -36,17 +36,17 @@ import java.io.StringWriter;
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* This class implements all the functionality exposed as part of the TenantConfigurationManagementService.
|
|
|
|
* This class implements all the functionality exposed as part of the PlatformConfigurationManagementService.
|
|
|
|
* Main usage of this module is saving/retrieving tenant configurations to the registry.
|
|
|
|
* Main usage of this module is saving/retrieving tenant configurations to the registry.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class TenantConfigurationManagementServiceImpl
|
|
|
|
public class TenantConfigurationManagementServiceImpl
|
|
|
|
implements TenantConfigurationManagementService {
|
|
|
|
implements PlatformConfigurationManagementService {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(TenantConfigurationManagementServiceImpl.class);
|
|
|
|
private static final Log log = LogFactory.getLog(TenantConfigurationManagementServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean saveConfiguration(TenantConfiguration tenantConfiguration, String resourcePath)
|
|
|
|
public boolean saveConfiguration(PlatformConfiguration tenantConfiguration, String resourcePath)
|
|
|
|
throws ConfigurationManagementException {
|
|
|
|
throws ConfigurationManagementException {
|
|
|
|
boolean status;
|
|
|
|
boolean status;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -54,7 +54,7 @@ public class TenantConfigurationManagementServiceImpl
|
|
|
|
log.debug("Persisting tenant configurations in Registry");
|
|
|
|
log.debug("Persisting tenant configurations in Registry");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StringWriter writer = new StringWriter();
|
|
|
|
StringWriter writer = new StringWriter();
|
|
|
|
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
|
|
|
JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
|
|
|
|
Marshaller marshaller = context.createMarshaller();
|
|
|
|
Marshaller marshaller = context.createMarshaller();
|
|
|
|
marshaller.marshal(tenantConfiguration, writer);
|
|
|
|
marshaller.marshal(tenantConfiguration, writer);
|
|
|
|
|
|
|
|
|
|
|
@ -74,19 +74,19 @@ public class TenantConfigurationManagementServiceImpl
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public TenantConfiguration getConfiguration(String resourcePath)
|
|
|
|
public PlatformConfiguration getConfiguration(String resourcePath)
|
|
|
|
throws ConfigurationManagementException {
|
|
|
|
throws ConfigurationManagementException {
|
|
|
|
Resource resource;
|
|
|
|
Resource resource;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
resource = ConfigurationManagerUtil.getRegistryResource(resourcePath);
|
|
|
|
resource = ConfigurationManagerUtil.getRegistryResource(resourcePath);
|
|
|
|
if(resource != null){
|
|
|
|
if(resource != null){
|
|
|
|
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
|
|
|
JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
|
|
|
|
Unmarshaller unmarshaller = context.createUnmarshaller();
|
|
|
|
Unmarshaller unmarshaller = context.createUnmarshaller();
|
|
|
|
return (TenantConfiguration) unmarshaller.unmarshal(
|
|
|
|
return (PlatformConfiguration) unmarshaller.unmarshal(
|
|
|
|
new StringReader(new String((byte[]) resource.getContent(), Charset
|
|
|
|
new StringReader(new String((byte[]) resource.getContent(), Charset
|
|
|
|
.forName(ConfigurationManagerConstants.CharSets.CHARSET_UTF8))));
|
|
|
|
.forName(ConfigurationManagerConstants.CharSets.CHARSET_UTF8))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new TenantConfiguration();
|
|
|
|
return new PlatformConfiguration();
|
|
|
|
} catch (JAXBException e) {
|
|
|
|
} catch (JAXBException e) {
|
|
|
|
throw new ConfigurationManagementException(
|
|
|
|
throw new ConfigurationManagementException(
|
|
|
|
"Error occurred while parsing the Tenant configuration : " + e.getMessage(), e);
|
|
|
|
"Error occurred while parsing the Tenant configuration : " + e.getMessage(), e);
|
|
|
|