mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Added a feature to pick default platform configurations
This commit is contained in:
parent
964eae6f92
commit
17ecadb913
@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template;
|
|||||||
|
|
||||||
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.w3c.dom.Document;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
@ -42,12 +43,14 @@ import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util.
|
|||||||
import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager;
|
import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager;
|
||||||
import org.wso2.carbon.registry.api.RegistryException;
|
import org.wso2.carbon.registry.api.RegistryException;
|
||||||
import org.wso2.carbon.registry.api.Resource;
|
import org.wso2.carbon.registry.api.Resource;
|
||||||
|
import org.wso2.carbon.utils.CarbonUtils;
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Marshaller;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
import java.io.File;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
@ -63,10 +66,15 @@ public class DeviceTypeManager implements DeviceManager {
|
|||||||
private String deviceType;
|
private String deviceType;
|
||||||
private DeviceTypePluginDAOManager deviceTypePluginDAOManager;
|
private DeviceTypePluginDAOManager deviceTypePluginDAOManager;
|
||||||
private LicenseManager licenseManager;
|
private LicenseManager licenseManager;
|
||||||
|
private PlatformConfiguration defaultPlatformConfiguration;
|
||||||
private boolean propertiesExist;
|
private boolean propertiesExist;
|
||||||
private boolean requiredDeviceTypeAuthorization;
|
private boolean requiredDeviceTypeAuthorization;
|
||||||
private boolean claimable;
|
private boolean claimable;
|
||||||
|
|
||||||
|
private static final String PATH_MOBILE_PLUGIN_CONF_DIR =
|
||||||
|
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugin-configs" + File.separator
|
||||||
|
+ "mobile";
|
||||||
|
|
||||||
private FeatureManager featureManager;
|
private FeatureManager featureManager;
|
||||||
|
|
||||||
public DeviceTypeManager(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
|
public DeviceTypeManager(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
|
||||||
@ -107,6 +115,14 @@ public class DeviceTypeManager implements DeviceManager {
|
|||||||
claimable = deviceTypeConfiguration.getClaimable().isEnabled();
|
claimable = deviceTypeConfiguration.getClaimable().isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loading default platform configuration
|
||||||
|
try {
|
||||||
|
defaultPlatformConfiguration = this.getDefaultConfiguration();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while default platform configuration";
|
||||||
|
throw new DeviceTypeDeployerFileException(msg, e);
|
||||||
|
}
|
||||||
|
|
||||||
DeviceDetails deviceDetails = deviceTypeConfiguration.getDeviceDetails();
|
DeviceDetails deviceDetails = deviceTypeConfiguration.getDeviceDetails();
|
||||||
|
|
||||||
if (deviceDetails != null) {
|
if (deviceDetails != null) {
|
||||||
@ -205,6 +221,8 @@ public class DeviceTypeManager implements DeviceManager {
|
|||||||
return (PlatformConfiguration) unmarshaller.unmarshal(
|
return (PlatformConfiguration) unmarshaller.unmarshal(
|
||||||
new StringReader(new String((byte[]) resource.getContent(), Charset.
|
new StringReader(new String((byte[]) resource.getContent(), Charset.
|
||||||
forName(DeviceTypePluginConstants.CHARSET_UTF8))));
|
forName(DeviceTypePluginConstants.CHARSET_UTF8))));
|
||||||
|
} else if (defaultPlatformConfiguration != null) {
|
||||||
|
return defaultPlatformConfiguration;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (DeviceTypeMgtPluginException e) {
|
} catch (DeviceTypeMgtPluginException e) {
|
||||||
@ -371,6 +389,39 @@ public class DeviceTypeManager implements DeviceManager {
|
|||||||
return requiredDeviceTypeAuthorization;
|
return requiredDeviceTypeAuthorization;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlatformConfiguration getDefaultConfiguration() throws DeviceManagementException {
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Loading default " + deviceType + " platform configuration from " + deviceType +
|
||||||
|
"-default-platform-configuration.xml");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String platformConfigurationPath =
|
||||||
|
PATH_MOBILE_PLUGIN_CONF_DIR + File.separator + deviceType + "-default-platform-configuration.xml";
|
||||||
|
File platformConfig = new File(platformConfigurationPath);
|
||||||
|
|
||||||
|
if (platformConfig.exists()) {
|
||||||
|
Document doc = DeviceTypeUtils.convertToDocument(platformConfig);
|
||||||
|
JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
|
||||||
|
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||||
|
return (PlatformConfiguration) unmarshaller.unmarshal(doc);
|
||||||
|
} else {
|
||||||
|
log.warn(deviceType + "-default-platform-configuration.xml is not available, hence default " +
|
||||||
|
deviceType + "platform configuration cannot be loaded.");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch (JAXBException e) {
|
||||||
|
throw new DeviceManagementException(
|
||||||
|
"Error occurred while parsing the " + deviceType + " default platform configuration : " + e
|
||||||
|
.getMessage(), e);
|
||||||
|
} catch (DeviceTypeMgtPluginException e) {
|
||||||
|
throw new DeviceManagementException(
|
||||||
|
"Error occurred while parsing the " + deviceType + " default platform configuration : " + e
|
||||||
|
.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
|
|||||||
@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util
|
|||||||
|
|
||||||
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.w3c.dom.Document;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
|
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.internal.DeviceTypeManagementDataHolder;
|
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.internal.DeviceTypeManagementDataHolder;
|
||||||
@ -30,6 +31,10 @@ import org.wso2.carbon.registry.core.Registry;
|
|||||||
import javax.naming.Context;
|
import javax.naming.Context;
|
||||||
import javax.naming.InitialContext;
|
import javax.naming.InitialContext;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
import javax.xml.XMLConstants;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -128,4 +133,18 @@ public class DeviceTypeUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Document convertToDocument(File file) throws DeviceTypeMgtPluginException {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
factory.setNamespaceAware(true);
|
||||||
|
try {
|
||||||
|
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||||
|
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||||
|
return docBuilder.parse(file);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new DeviceTypeMgtPluginException("Error occurred while parsing file '" + file.getName() + "' to" +
|
||||||
|
" a org.w3c.dom.Document", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -157,4 +157,13 @@ public interface DeviceManager {
|
|||||||
*/
|
*/
|
||||||
boolean requireDeviceAuthorization();
|
boolean requireDeviceAuthorization();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the default configuration values which is stored in the configuration file
|
||||||
|
* rather than fetching from the registry.
|
||||||
|
*
|
||||||
|
* @return Returns Default PlatformConfiguration
|
||||||
|
* @throws DeviceManagementException
|
||||||
|
*/
|
||||||
|
PlatformConfiguration getDefaultConfiguration() throws DeviceManagementException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,7 +87,6 @@
|
|||||||
<li><a href="{{@app.context}}/policies"><i class="fw fw-policy"></i>Policy Management</a></li>
|
<li><a href="{{@app.context}}/policies"><i class="fw fw-policy"></i>Policy Management</a></li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#unless isCloud}}
|
|
||||||
{{#if permissions.TENANT_CONFIGURATION}}
|
{{#if permissions.TENANT_CONFIGURATION}}
|
||||||
<li><a><i class="fw fw-settings"></i>Configuration Management</a>
|
<li><a><i class="fw fw-settings"></i>Configuration Management</a>
|
||||||
<ul>
|
<ul>
|
||||||
@ -99,7 +98,6 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/unless}}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user