mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge pull request #871 from Megala21/application-mgt
Merging with master and adding some java-doc comments
This commit is contained in:
commit
b872ea2cf4
@ -22,13 +22,13 @@
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.apimgt.annotations</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - API Management Annotations</name>
|
||||
<description>WSO2 Carbon - API Management Custom Annotation Module</description>
|
||||
|
||||
@ -21,12 +21,12 @@
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<artifactId>org.wso2.carbon.apimgt.application.extension.api</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<name>WSO2 Carbon - API Application Management API</name>
|
||||
|
||||
@ -42,6 +42,7 @@ public class APIUtil {
|
||||
|
||||
private static Log log = LogFactory.getLog(APIUtil.class);
|
||||
private static final String DEFAULT_CDMF_API_TAG = "device_management";
|
||||
private static final String DEFAULT_AGENT_API_TAG = "device_agent";
|
||||
private static final String DEFAULT_CERT_API_TAG = "scep_management";
|
||||
public static final String PERMISSION_PROPERTY_NAME = "name";
|
||||
|
||||
@ -106,6 +107,7 @@ public class APIUtil {
|
||||
List<String> allowedApisTags = getDeviceManagementProviderService().getAvailableDeviceTypes();
|
||||
allowedApisTags.add(DEFAULT_CDMF_API_TAG);
|
||||
allowedApisTags.add(DEFAULT_CERT_API_TAG);
|
||||
allowedApisTags.add(DEFAULT_AGENT_API_TAG);
|
||||
return allowedApisTags;
|
||||
}
|
||||
|
||||
|
||||
@ -22,12 +22,12 @@
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<artifactId>org.wso2.carbon.apimgt.application.extension</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - API Application Management</name>
|
||||
|
||||
@ -84,109 +84,118 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
||||
String keyType, String username,
|
||||
boolean isAllowedAllDomains, String validityTime)
|
||||
throws APIManagerException {
|
||||
StoreClient storeClient = APIApplicationManagerExtensionDataHolder.getInstance().getIntegrationClientService()
|
||||
.getStoreClient();
|
||||
StoreClient storeClient =
|
||||
APIApplicationManagerExtensionDataHolder.getInstance().getIntegrationClientService()
|
||||
.getStoreClient();
|
||||
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
||||
.getTenantDomain();
|
||||
try {
|
||||
ApplicationList applicationList = storeClient.getApplications()
|
||||
.applicationsGet("", applicationName, 1, 0, CONTENT_TYPE, null);
|
||||
Application application;
|
||||
if (applicationList == null || applicationList.getList() == null || applicationList.getList().size() == 0) {
|
||||
//create application;
|
||||
application = new Application();
|
||||
application.setName(applicationName);
|
||||
application.setSubscriber(username);
|
||||
application.setDescription("");
|
||||
application.setThrottlingTier(ApiApplicationConstants.DEFAULT_TIER);
|
||||
application.setGroupId("");
|
||||
application = storeClient.getIndividualApplication().applicationsPost(application, CONTENT_TYPE);
|
||||
} else {
|
||||
ApplicationInfo applicationInfo = applicationList.getList().get(0);
|
||||
application = storeClient.getIndividualApplication()
|
||||
.applicationsApplicationIdGet(applicationInfo.getApplicationId(), CONTENT_TYPE, null, null);
|
||||
}
|
||||
if (application == null) {
|
||||
throw new APIManagerException(
|
||||
"Api application creation failed for " + applicationName + " to the user " + username);
|
||||
}
|
||||
|
||||
ApplicationList applicationList = storeClient.getApplications()
|
||||
.applicationsGet("", applicationName, 1, 0, CONTENT_TYPE, null);
|
||||
Application application;
|
||||
if (applicationList == null || applicationList.getList() == null || applicationList.getList().size() == 0) {
|
||||
//create application;
|
||||
application = new Application();
|
||||
application.setName(applicationName);
|
||||
application.setSubscriber(username);
|
||||
application.setDescription("");
|
||||
application.setThrottlingTier(ApiApplicationConstants.DEFAULT_TIER);
|
||||
application.setGroupId("");
|
||||
application = storeClient.getIndividualApplication().applicationsPost(application, CONTENT_TYPE);
|
||||
} else {
|
||||
ApplicationInfo applicationInfo = applicationList.getList().get(0);
|
||||
application = storeClient.getIndividualApplication()
|
||||
.applicationsApplicationIdGet(applicationInfo.getApplicationId(), CONTENT_TYPE, null, null);
|
||||
}
|
||||
if (application == null) {
|
||||
throw new APIManagerException (
|
||||
"Api application creation failed for " + applicationName + " to the user " + username);
|
||||
}
|
||||
SubscriptionList subscriptionList = storeClient.getSubscriptions().subscriptionsGet
|
||||
(null, application.getApplicationId(), "", 0, 100, CONTENT_TYPE, null);
|
||||
List<Subscription> needToSubscribe = new ArrayList<>();
|
||||
// subscribe to apis.
|
||||
if (tags != null && tags.length > 0) {
|
||||
for (String tag : tags) {
|
||||
APIList apiList = storeClient.getApis().apisGet(MAX_API_PER_TAG, 0, tenantDomain, "tag:" + tag
|
||||
, CONTENT_TYPE, null);
|
||||
if (apiList.getList() == null || apiList.getList().size() == 0) {
|
||||
apiList = storeClient.getApis().apisGet(MAX_API_PER_TAG, 0
|
||||
, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, "tag:" + tag, CONTENT_TYPE, null);
|
||||
}
|
||||
|
||||
SubscriptionList subscriptionList = storeClient.getSubscriptions().subscriptionsGet
|
||||
(null, application.getApplicationId(), "", 0, 100, CONTENT_TYPE, null);
|
||||
List<Subscription> needToSubscribe = new ArrayList<>();
|
||||
// subscribe to apis.
|
||||
if (tags != null && tags.length > 0) {
|
||||
for (String tag: tags) {
|
||||
APIList apiList = storeClient.getApis().apisGet(MAX_API_PER_TAG, 0, tenantDomain, "tag:" + tag
|
||||
, CONTENT_TYPE, null);
|
||||
if (apiList.getList() == null || apiList.getList().size() == 0) {
|
||||
apiList = storeClient.getApis().apisGet(MAX_API_PER_TAG, 0
|
||||
, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, "tag:" + tag, CONTENT_TYPE, null);
|
||||
}
|
||||
|
||||
if (apiList.getList() != null && apiList.getList().size() > 0) {
|
||||
for (APIInfo apiInfo : apiList.getList()) {
|
||||
String id = apiInfo.getProvider().replace("@", "-AT-")
|
||||
+ "-" + apiInfo.getName()+ "-" + apiInfo.getVersion();
|
||||
boolean subscriptionExist = false;
|
||||
if (subscriptionList.getList() != null && subscriptionList.getList().size() > 0) {
|
||||
for (Subscription subs : subscriptionList.getList()) {
|
||||
if (subs.getApiIdentifier().equals(id)) {
|
||||
subscriptionExist = true;
|
||||
break;
|
||||
if (apiList.getList() != null && apiList.getList().size() > 0) {
|
||||
for (APIInfo apiInfo : apiList.getList()) {
|
||||
String id = apiInfo.getProvider().replace("@", "-AT-")
|
||||
+ "-" + apiInfo.getName() + "-" + apiInfo.getVersion();
|
||||
boolean subscriptionExist = false;
|
||||
if (subscriptionList.getList() != null && subscriptionList.getList().size() > 0) {
|
||||
for (Subscription subs : subscriptionList.getList()) {
|
||||
if (subs.getApiIdentifier().equals(id)) {
|
||||
subscriptionExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!subscriptionExist) {
|
||||
Subscription subscription = new Subscription();
|
||||
//fix for APIMANAGER-5566 admin-AT-tenant1.com-Tenant1API1-1.0.0
|
||||
if (!subscriptionExist) {
|
||||
Subscription subscription = new Subscription();
|
||||
//fix for APIMANAGER-5566 admin-AT-tenant1.com-Tenant1API1-1.0.0
|
||||
|
||||
subscription.setApiIdentifier(id);
|
||||
subscription.setApplicationId(application.getApplicationId());
|
||||
subscription.tier(ApiApplicationConstants.DEFAULT_TIER);
|
||||
if (!needToSubscribe.contains(subscription)){
|
||||
needToSubscribe.add(subscription);
|
||||
subscription.setApiIdentifier(id);
|
||||
subscription.setApplicationId(application.getApplicationId());
|
||||
subscription.tier(ApiApplicationConstants.DEFAULT_TIER);
|
||||
if (!needToSubscribe.contains(subscription)) {
|
||||
needToSubscribe.add(subscription);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!needToSubscribe.isEmpty()) {
|
||||
storeClient.getSubscriptionMultitpleApi().subscriptionsMultiplePost(needToSubscribe, CONTENT_TYPE);
|
||||
}
|
||||
//end of subscription
|
||||
if (!needToSubscribe.isEmpty()) {
|
||||
storeClient.getSubscriptionMultitpleApi().subscriptionsMultiplePost(needToSubscribe, CONTENT_TYPE);
|
||||
}
|
||||
//end of subscription
|
||||
|
||||
List<ApplicationKey> applicationKeys = application.getKeys();
|
||||
if (applicationKeys != null) {
|
||||
for (ApplicationKey applicationKey : applicationKeys) {
|
||||
if (keyType.equals(applicationKey.getKeyType().toString())) {
|
||||
ApiApplicationKey apiApplicationKey = new ApiApplicationKey();
|
||||
apiApplicationKey.setConsumerKey(applicationKey.getConsumerKey());
|
||||
apiApplicationKey.setConsumerSecret(applicationKey.getConsumerSecret());
|
||||
return apiApplicationKey;
|
||||
List<ApplicationKey> applicationKeys = application.getKeys();
|
||||
if (applicationKeys != null) {
|
||||
for (ApplicationKey applicationKey : applicationKeys) {
|
||||
if (keyType.equals(applicationKey.getKeyType().toString())) {
|
||||
if (applicationKey.getConsumerKey() != null && !applicationKey.getConsumerKey().isEmpty()) {
|
||||
ApiApplicationKey apiApplicationKey = new ApiApplicationKey();
|
||||
apiApplicationKey.setConsumerKey(applicationKey.getConsumerKey());
|
||||
apiApplicationKey.setConsumerSecret(applicationKey.getConsumerSecret());
|
||||
return apiApplicationKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ApplicationKeyGenerateRequest applicationKeyGenerateRequest = new ApplicationKeyGenerateRequest();
|
||||
List<String> allowedDomains = new ArrayList<>();
|
||||
if (isAllowedAllDomains) {
|
||||
allowedDomains.add(ApiApplicationConstants.ALLOWED_DOMAINS);
|
||||
} else {
|
||||
allowedDomains.add(APIManagerUtil.getTenantDomain());
|
||||
}
|
||||
applicationKeyGenerateRequest.setAccessAllowDomains(allowedDomains);
|
||||
applicationKeyGenerateRequest.setCallbackUrl("");
|
||||
applicationKeyGenerateRequest.setKeyType(ApplicationKeyGenerateRequest.KeyTypeEnum.PRODUCTION);
|
||||
applicationKeyGenerateRequest.setValidityTime(validityTime);
|
||||
ApplicationKeyGenerateRequest applicationKeyGenerateRequest = new ApplicationKeyGenerateRequest();
|
||||
List<String> allowedDomains = new ArrayList<>();
|
||||
if (isAllowedAllDomains) {
|
||||
allowedDomains.add(ApiApplicationConstants.ALLOWED_DOMAINS);
|
||||
} else {
|
||||
allowedDomains.add(APIManagerUtil.getTenantDomain());
|
||||
}
|
||||
applicationKeyGenerateRequest.setAccessAllowDomains(allowedDomains);
|
||||
applicationKeyGenerateRequest.setCallbackUrl("");
|
||||
applicationKeyGenerateRequest.setKeyType(ApplicationKeyGenerateRequest.KeyTypeEnum.PRODUCTION);
|
||||
applicationKeyGenerateRequest.setValidityTime(validityTime);
|
||||
|
||||
ApplicationKey applicationKey = storeClient.getIndividualApplication().applicationsGenerateKeysPost(
|
||||
application.getApplicationId(), applicationKeyGenerateRequest, CONTENT_TYPE, null, null);
|
||||
ApiApplicationKey apiApplicationKey = new ApiApplicationKey();
|
||||
apiApplicationKey.setConsumerKey(applicationKey.getConsumerKey());
|
||||
apiApplicationKey.setConsumerSecret(applicationKey.getConsumerSecret());
|
||||
return apiApplicationKey;
|
||||
ApplicationKey applicationKey = storeClient.getIndividualApplication().applicationsGenerateKeysPost(
|
||||
application.getApplicationId(), applicationKeyGenerateRequest, CONTENT_TYPE, null, null);
|
||||
if (applicationKey.getConsumerKey() != null && !applicationKey.getConsumerKey().isEmpty()) {
|
||||
ApiApplicationKey apiApplicationKey = new ApiApplicationKey();
|
||||
apiApplicationKey.setConsumerKey(applicationKey.getConsumerKey());
|
||||
apiApplicationKey.setConsumerSecret(applicationKey.getConsumerSecret());
|
||||
return apiApplicationKey;
|
||||
}
|
||||
throw new APIManagerException("Failed to generate keys for tenant: " + tenantDomain);
|
||||
} catch (FeignException e) {
|
||||
throw new APIManagerException("Failed to create api application for tenant: " + tenantDomain, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,13 +21,13 @@
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.apimgt.handlers</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - API Security Handler Component</name>
|
||||
<description>WSO2 Carbon - API Management Security Handler Module</description>
|
||||
|
||||
@ -44,6 +44,8 @@ import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Contains util methods for synapse gateway authentication handler
|
||||
@ -62,21 +64,47 @@ public class Utils {
|
||||
public static IOTServerConfiguration initConfig() {
|
||||
try {
|
||||
|
||||
String IOTServerAPIConfigurationPath =
|
||||
CarbonUtils.getCarbonConfigDirPath() + File.separator + IOT_APIS_CONFIG_FILE;
|
||||
String IOTServerAPIConfigurationPath = CarbonUtils.getCarbonConfigDirPath() + File.separator
|
||||
+ IOT_APIS_CONFIG_FILE;
|
||||
File file = new File(IOTServerAPIConfigurationPath);
|
||||
Document doc = Utils.convertToDocument(file);
|
||||
|
||||
JAXBContext fileContext = JAXBContext.newInstance(IOTServerConfiguration.class);
|
||||
Unmarshaller unmarshaller = fileContext.createUnmarshaller();
|
||||
return (IOTServerConfiguration) unmarshaller.unmarshal(doc);
|
||||
|
||||
IOTServerConfiguration iotServerConfiguration = (IOTServerConfiguration) unmarshaller.unmarshal(
|
||||
doc);
|
||||
iotServerConfiguration.setHostname(replaceProperties(iotServerConfiguration.getHostname()));
|
||||
iotServerConfiguration.setVerificationEndpoint(
|
||||
replaceProperties(iotServerConfiguration.getVerificationEndpoint()));
|
||||
iotServerConfiguration.setDynamicClientRegistrationEndpoint(
|
||||
replaceProperties(iotServerConfiguration.getDynamicClientRegistrationEndpoint()));
|
||||
iotServerConfiguration.setOauthTokenEndpoint(
|
||||
replaceProperties(iotServerConfiguration.getOauthTokenEndpoint()));
|
||||
return iotServerConfiguration;
|
||||
} catch (JAXBException | APIMCertificateMGTException e) {
|
||||
log.error("Error occurred while initializing Data Source config", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the values from system variables and sets to xml.
|
||||
*/
|
||||
public static String replaceProperties(String text) {
|
||||
String regex = "\\$\\{(.*?)\\}";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matchPattern = pattern.matcher(text);
|
||||
while (matchPattern.find()) {
|
||||
String sysPropertyName = matchPattern.group(1);
|
||||
String sysPropertyValue = System.getProperty(sysPropertyName);
|
||||
if (sysPropertyValue != null && !sysPropertyName.isEmpty()) {
|
||||
text = text.replaceAll("\\$\\{(" + sysPropertyName + ")\\}", sysPropertyValue);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class build the iot-api-config.xml file.
|
||||
* @param file
|
||||
|
||||
@ -19,22 +19,22 @@
|
||||
|
||||
<ServerConfiguration>
|
||||
<!-- IoT server host name, this is referred from APIM gateway to call to IoT server for certificate validation-->
|
||||
<Hostname>https://localhost:9443/</Hostname>
|
||||
<Hostname>https://${iot.core.host}:${iot.core.https.port}/</Hostname>
|
||||
|
||||
<!--End point to verify the certificate-->
|
||||
<VerificationEndpoint>https://localhost:9443/api/certificate-mgt/v1.0/admin/certificates/verify/</VerificationEndpoint>
|
||||
<VerificationEndpoint>https://${iot.core.host}:${iot.core.https.port}/api/certificate-mgt/v1.0/admin/certificates/verify/</VerificationEndpoint>
|
||||
|
||||
<!--Admin username/password - this is to use for oauth token generation-->
|
||||
<Username>admin</Username>
|
||||
<Password>admin</Password>
|
||||
|
||||
<!--Dynamic client registration endpoint-->
|
||||
<DynamicClientRegistrationEndpoint>https://localhost:9443/dynamic-client-web/register</DynamicClientRegistrationEndpoint>
|
||||
<DynamicClientRegistrationEndpoint>https://${iot.keymanager.host}:${iot.keymanager.https.port}/client-registration/v0.11/register</DynamicClientRegistrationEndpoint>
|
||||
|
||||
<!--Oauth token endpoint-->
|
||||
<OauthTokenEndpoint>https://localhost:9443/oauth2/token</OauthTokenEndpoint>
|
||||
<OauthTokenEndpoint>https://${iot.keymanager.host}:${iot.keymanager.https.port}/oauth2/token</OauthTokenEndpoint>
|
||||
|
||||
<APIS>
|
||||
<ContextPath>/services/echo</ContextPath>
|
||||
<ContextPath>/services</ContextPath>
|
||||
</APIS>
|
||||
</ServerConfiguration>
|
||||
@ -13,13 +13,13 @@
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.apimgt.integration.client</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - API Management Integration Client</name>
|
||||
<description>WSO2 Carbon - API Management Integration Client</description>
|
||||
|
||||
@ -21,24 +21,43 @@ package org.wso2.carbon.apimgt.integration.client.util;
|
||||
|
||||
import feign.Client;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import javax.net.ssl.*;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.io.InputStream;
|
||||
import java.security.*;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import feign.Logger;
|
||||
import feign.Request;
|
||||
import feign.Response;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.base.ServerConfiguration;
|
||||
|
||||
public class Utils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(Utils.class);
|
||||
|
||||
private static final String KEY_STORE_TYPE = "JKS";
|
||||
/**
|
||||
* Default truststore type of the client
|
||||
*/
|
||||
private static final String TRUST_STORE_TYPE = "JKS";
|
||||
/**
|
||||
* Default keymanager type of the client
|
||||
*/
|
||||
private static final String KEY_MANAGER_TYPE = "SunX509"; //Default Key Manager Type
|
||||
/**
|
||||
* Default trustmanager type of the client
|
||||
*/
|
||||
private static final String TRUST_MANAGER_TYPE = "SunX509"; //Default Trust Manager Type
|
||||
|
||||
private static final String SSLV3 = "SSLv3";
|
||||
|
||||
|
||||
//This method is only used if the mb features are within DAS.
|
||||
public static String replaceProperties(String text) {
|
||||
String regex = "\\$\\{(.*?)\\}";
|
||||
@ -55,15 +74,20 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static Client getSSLClient() {
|
||||
return new Client.Default(getTrustedSSLSocketFactory(), new HostnameVerifier() {
|
||||
@Override
|
||||
public boolean verify(String s, SSLSession sslSession) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System.getProperty("org.wso2.ignoreHostnameVerification"));
|
||||
if(isIgnoreHostnameVerification) {
|
||||
return new Client.Default(getSimpleTrustedSSLSocketFactory(), new HostnameVerifier() {
|
||||
@Override
|
||||
public boolean verify(String s, SSLSession sslSession) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}else {
|
||||
return new Client.Default(getTrustedSSLSocketFactory(), null);
|
||||
}
|
||||
}
|
||||
|
||||
private static SSLSocketFactory getTrustedSSLSocketFactory() {
|
||||
private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() {
|
||||
try {
|
||||
TrustManager[] trustAllCerts = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
@ -86,4 +110,60 @@ public class Utils {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static SSLSocketFactory getTrustedSSLSocketFactory() {
|
||||
try {
|
||||
String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password");
|
||||
String keyStoreLocation = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location");
|
||||
String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty(
|
||||
"Security.TrustStore.Password");
|
||||
String trustStoreLocation = ServerConfiguration.getInstance().getFirstProperty(
|
||||
"Security.TrustStore.Location");
|
||||
KeyStore keyStore = loadKeyStore(keyStoreLocation,keyStorePassword,KEY_STORE_TYPE);
|
||||
KeyStore trustStore = loadTrustStore(trustStoreLocation,trustStorePassword);
|
||||
|
||||
return initSSLConnection(keyStore,keyStorePassword,trustStore);
|
||||
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException
|
||||
|CertificateException | IOException | UnrecoverableKeyException e) {
|
||||
log.error("Error while creating the SSL socket factory due to "+e.getMessage(),e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static SSLSocketFactory initSSLConnection(KeyStore keyStore,String keyStorePassword,KeyStore trustStore) throws NoSuchAlgorithmException, UnrecoverableKeyException,
|
||||
KeyStoreException, KeyManagementException {
|
||||
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KEY_MANAGER_TYPE);
|
||||
keyManagerFactory.init(keyStore, keyStorePassword.toCharArray());
|
||||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TRUST_MANAGER_TYPE);
|
||||
trustManagerFactory.init(trustStore);
|
||||
|
||||
// Create and initialize SSLContext for HTTPS communication
|
||||
SSLContext sslContext = SSLContext.getInstance(SSLV3);
|
||||
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
|
||||
SSLContext.setDefault(sslContext);
|
||||
return sslContext.getSocketFactory();
|
||||
}
|
||||
|
||||
|
||||
private static KeyStore loadKeyStore(String keyStorePath, String ksPassword,String type)
|
||||
throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException {
|
||||
InputStream fileInputStream = null;
|
||||
try {
|
||||
char[] keypassChar = ksPassword.toCharArray();
|
||||
KeyStore keyStore = KeyStore.getInstance(type);
|
||||
fileInputStream = new FileInputStream(keyStorePath);
|
||||
keyStore.load(fileInputStream, keypassChar);
|
||||
return keyStore;
|
||||
} finally {
|
||||
if (fileInputStream != null) {
|
||||
fileInputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static KeyStore loadTrustStore(String trustStorePath, String tsPassword)
|
||||
throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException {
|
||||
return loadKeyStore(trustStorePath,tsPassword,TRUST_STORE_TYPE);
|
||||
}
|
||||
}
|
||||
@ -13,13 +13,13 @@
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.apimgt.integration.generated.client</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - API Management Integration Generated Client</name>
|
||||
<description>WSO2 Carbon - API Management Integration Client</description>
|
||||
|
||||
@ -22,13 +22,13 @@
|
||||
<parent>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.apimgt.webapp.publisher</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - API Management Webapp Publisher</name>
|
||||
<description>WSO2 Carbon - API Management Webapp Publisher</description>
|
||||
|
||||
@ -22,13 +22,13 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>carbon-devicemgt</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>apimgt-extensions</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>WSO2 Carbon - API Management Extensions Component</name>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
@ -22,13 +22,13 @@
|
||||
<parent>
|
||||
<artifactId>application-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.device.application.mgt.api</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>WSO2 Carbon - Application Management API</name>
|
||||
<description>WSO2 Carbon - Application Management API</description>
|
||||
@ -36,13 +36,6 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration>
|
||||
@ -132,6 +125,10 @@
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-jaxrs</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-core-asl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>jsr311-api</artifactId>
|
||||
@ -228,5 +225,6 @@
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -18,14 +18,60 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.api.services;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import io.swagger.annotations.Extension;
|
||||
import io.swagger.annotations.ExtensionProperty;
|
||||
import io.swagger.annotations.Info;
|
||||
import io.swagger.annotations.SwaggerDefinition;
|
||||
import io.swagger.annotations.Tag;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.application.mgt.common.Application;
|
||||
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
version = "1.0.0",
|
||||
title = "Application Management Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name", value = "ApplicationManagementService"),
|
||||
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/applications"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "application_management", description = "Application Management related APIs")
|
||||
}
|
||||
)
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@Scope(
|
||||
name = "Get Application Details",
|
||||
description = "Get application details",
|
||||
key = "perm:application:get",
|
||||
permissions = {"/device-mgt/application/get"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Create an Application",
|
||||
description = "Create an application",
|
||||
key = "perm:application:create",
|
||||
permissions = {"/device-mgt/application/create"}
|
||||
),
|
||||
}
|
||||
)
|
||||
@Path("/applications")
|
||||
@Api(value = "Application Management", description = "This API carries all application management related operations " +
|
||||
"such as get all the applications, add application, etc.")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@ -35,19 +81,18 @@ public interface ApplicationManagementAPI {
|
||||
public final static String SCOPE = "scope";
|
||||
|
||||
@GET
|
||||
@Path("applications")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
httpMethod = "GET",
|
||||
value = "get all applications",
|
||||
notes = "This will get all applications",
|
||||
tags = "Application Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:get-application")
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:application:get")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ -73,21 +118,62 @@ public interface ApplicationManagementAPI {
|
||||
value = "Validates if the requested variant has not been modified since the time specified",
|
||||
required = false)
|
||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "Provide from which position apps should return",
|
||||
required = false,
|
||||
defaultValue = "20")
|
||||
@QueryParam("offset") int offset,
|
||||
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Provide how many apps it should return",
|
||||
required = false,
|
||||
defaultValue = "0")
|
||||
@QueryParam("limit") int limit
|
||||
|
||||
@QueryParam("limit") int limit,
|
||||
@ApiParam(
|
||||
name = "searchQuery",
|
||||
value = "Relevant search query to search on",
|
||||
required = false,
|
||||
defaultValue = "*")
|
||||
@QueryParam("searchQuery") String searchQuery
|
||||
);
|
||||
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Create an application",
|
||||
notes = "This will create a new application",
|
||||
tags = "Application Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:application:create")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "OK. \n Successfully created an application.",
|
||||
response = Application.class),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n " +
|
||||
"Empty body because the client already has the latest version of the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while getting the application list.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response createApplication(
|
||||
@ApiParam(
|
||||
name = "application",
|
||||
value = "The application that need to be created.",
|
||||
required = true)
|
||||
@Valid Application application);
|
||||
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package org.wso2.carbon.device.application.mgt.api.services;/*
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
@ -16,22 +16,82 @@ package org.wso2.carbon.device.application.mgt.api.services;/*
|
||||
*
|
||||
*/
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
package org.wso2.carbon.device.application.mgt.api.services;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import io.swagger.annotations.Extension;
|
||||
import io.swagger.annotations.ExtensionProperty;
|
||||
import io.swagger.annotations.Info;
|
||||
import io.swagger.annotations.SwaggerDefinition;
|
||||
import io.swagger.annotations.Tag;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.application.mgt.common.Platform;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* API for handling platform related operations in application management.
|
||||
*/
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
version = "1.0.0",
|
||||
title = "Platform Management Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name", value = "PlatformManagementService"),
|
||||
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/platforms"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "application_management", description = "Platform Management APIS related with "
|
||||
+ "Application Management")
|
||||
}
|
||||
)
|
||||
@Scopes (
|
||||
scopes = {
|
||||
@org.wso2.carbon.apimgt.annotations.api.Scope(
|
||||
name = "Get platform details",
|
||||
description = "Get platform details",
|
||||
key = "perm:platform:get",
|
||||
permissions = {"/device-mgt/platform/get"}
|
||||
),
|
||||
@org.wso2.carbon.apimgt.annotations.api.Scope(
|
||||
name = "Add a platform",
|
||||
description = "Add a platform",
|
||||
key = "perm:platform:add",
|
||||
permissions = {"/device-mgt/platform/add"}
|
||||
),
|
||||
@org.wso2.carbon.apimgt.annotations.api.Scope(
|
||||
name = "Update a platform",
|
||||
description = "Update a platform",
|
||||
key = "perm:platform:update",
|
||||
permissions = {"/device-mgt/platform/update"}
|
||||
)
|
||||
}
|
||||
)
|
||||
@Api(value = "Platform Management", description = "This API carries all platform management related operations " +
|
||||
"such as get all the available platform for a tenant, etc.")
|
||||
@Path("/platforms")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/platforms")
|
||||
public interface PlatformManagementAPI {
|
||||
public final static String SCOPE = "scope";
|
||||
String SCOPE = "scope";
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@ -45,7 +105,7 @@ public interface PlatformManagementAPI {
|
||||
tags = "Platform Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:get-platform")
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:platform:get")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ -62,14 +122,12 @@ public interface PlatformManagementAPI {
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response getPlatforms(
|
||||
@ApiParam(
|
||||
name = "status",
|
||||
allowableValues = "ENABLED, DISABLED, ALL",
|
||||
value = "Provide the status of platform for that tenant:\n" +
|
||||
"- ENABLED: The platforms that are currently enabled for the tenant\n" +
|
||||
"- DISABLED: The platforms that can be used by the tenant but disabled to be used for tenant\n" +
|
||||
"- ALL: All the list of platforms that can be used by the tenant",
|
||||
required = false)
|
||||
@ApiParam(name = "status", allowableValues = "ENABLED, DISABLED, ALL", value =
|
||||
"Provide the status of platform for that tenant:\n"
|
||||
+ "- ENABLED: The platforms that are currently enabled for the tenant\n"
|
||||
+ "- DISABLED: The platforms that can be used by the tenant but disabled "
|
||||
+ "to be used for tenant\n"
|
||||
+ "- ALL: All the list of platforms that can be used by the tenant", required = false)
|
||||
@QueryParam("status")
|
||||
@Size(max = 45)
|
||||
String status
|
||||
@ -84,11 +142,11 @@ public interface PlatformManagementAPI {
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "get platform",
|
||||
notes = "This will get application which was registered with {code}",
|
||||
notes = "This will return the platform which is registered with {identifier}",
|
||||
tags = "Platform Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:get-platform")
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:platform:get")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ -124,7 +182,7 @@ public interface PlatformManagementAPI {
|
||||
tags = "Platform Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:add-platform")
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:platform:add")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ -162,7 +220,7 @@ public interface PlatformManagementAPI {
|
||||
tags = "Platform Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:update-platform")
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:platform:update")
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
@ -26,12 +26,18 @@ import org.wso2.carbon.device.application.mgt.common.Platform;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.PlatformManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.PlatformManagementDAOException;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@Path("/platforms")
|
||||
public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
||||
|
||||
private static final String ALL_STATUS = "ALL";
|
||||
@ -40,9 +46,14 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
||||
|
||||
private static Log log = LogFactory.getLog(PlatformManagementAPIImpl.class);
|
||||
|
||||
@GET
|
||||
@Override
|
||||
public Response getPlatforms(@QueryParam("status") String status) {
|
||||
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("API request received for getting the platforms with the status " + status);
|
||||
}
|
||||
try {
|
||||
List<Platform> platforms = APIUtil.getPlatformManager().getPlatforms(tenantDomain);
|
||||
List<Platform> results;
|
||||
@ -69,6 +80,9 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
||||
} else {
|
||||
results = platforms;
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Number of platforms with the status " + status + " : " + results.size());
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(results).build();
|
||||
} catch (PlatformManagementException e) {
|
||||
log.error("Error while getting the platforms for tenant - " + tenantDomain, e);
|
||||
@ -91,6 +105,7 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Override
|
||||
public Response addPlatform(Platform platform) {
|
||||
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
|
||||
@ -100,10 +115,12 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI {
|
||||
APIUtil.getPlatformManager().register(tenantDomain, platform);
|
||||
return Response.status(Response.Status.CREATED).build();
|
||||
} else {
|
||||
return APIUtil.getResponse("Invalid payload! Platform ID and names are mandatory fields!", Response.Status.BAD_REQUEST);
|
||||
return APIUtil.getResponse("Invxalid payload! Platform ID and names are mandatory fields!",
|
||||
Response.Status.BAD_REQUEST);
|
||||
}
|
||||
} else {
|
||||
return APIUtil.getResponse("Invalid payload! Platform needs to be passed as payload!", Response.Status.BAD_REQUEST);
|
||||
return APIUtil.getResponse("Invalid payload! Platform needs to be passed as payload!",
|
||||
Response.Status.BAD_REQUEST);
|
||||
}
|
||||
} catch (PlatformManagementException e) {
|
||||
return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
|
||||
|
||||
@ -29,6 +29,40 @@
|
||||
-->
|
||||
<PermissionConfiguration>
|
||||
<APIVersion></APIVersion>
|
||||
<!--Permission Tree Name-->
|
||||
<!--End of Permission Tree-->
|
||||
|
||||
<!-- Application related permissions -->
|
||||
<Permission>
|
||||
<name>Get Application</name>
|
||||
<path>/device-mgt/application/get</path>
|
||||
<url>/application-mgt/applications</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Create Application</name>
|
||||
<path>/device-mgt/application/create</path>
|
||||
<url>/application-mgt/applications</url>
|
||||
<method>POST</method>
|
||||
</Permission>
|
||||
|
||||
<!-- Platform related permissions -->
|
||||
<Permission>
|
||||
<name>Get Platform</name>
|
||||
<path>/device-mgt/platform/get</path>
|
||||
<url>/application-mgt/platforms/*</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Add Platform</name>
|
||||
<path>/device-mgt/platform/add</path>
|
||||
<url>/application-mgt/platforms</url>
|
||||
<method>POST</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Update Platform</name>
|
||||
<path>/device-mgt/platform/update</path>
|
||||
<url>/application-mgt/platforms/*</url>
|
||||
<method>PUT</method>
|
||||
</Permission>
|
||||
|
||||
|
||||
</PermissionConfiguration>
|
||||
|
||||
@ -33,6 +33,9 @@ http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
||||
</jaxrs:server>
|
||||
|
||||
<bean id="applicationMgtServiceBean" class="org.wso2.carbon.device.application.mgt.api.services.impl.ApplicationManagementAPIImpl"/>
|
||||
<!--<bean id="platformManagementAPIBean" class="org.wso2.carbon.device.application.mgt.api.services.impl.PlatformManagementAPIImpl" />-->
|
||||
<bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.api.JSONMessageHandler"/>
|
||||
|
||||
</beans>
|
||||
|
||||
|
||||
|
||||
@ -21,13 +21,13 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>application-mgt</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.device.application.mgt.common</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Application Management Common</name>
|
||||
<description>WSO2 Carbon - Application Management Common</description>
|
||||
|
||||
@ -25,6 +25,9 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Application represents the an Application in Application Store
|
||||
*/
|
||||
public class Application {
|
||||
|
||||
@Exclude
|
||||
|
||||
@ -20,6 +20,9 @@ package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a list of {@link Application}.
|
||||
*/
|
||||
public class ApplicationList {
|
||||
|
||||
private List<Application> applications;
|
||||
|
||||
@ -21,6 +21,9 @@ package org.wso2.carbon.device.application.mgt.common;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class holds the details when releasing an Application to application store.
|
||||
*/
|
||||
public class ApplicationRelease {
|
||||
|
||||
private enum Channel {
|
||||
|
||||
@ -18,8 +18,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
|
||||
|
||||
/**
|
||||
* Represents the category a particular {@link Application} belongs to.
|
||||
*/
|
||||
public class Category {
|
||||
|
||||
private int id;
|
||||
|
||||
@ -18,6 +18,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
/**
|
||||
* Represents a comment for an {@link Application}.
|
||||
*/
|
||||
public class Comment {
|
||||
|
||||
private String id;
|
||||
|
||||
@ -19,10 +19,15 @@
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Filter represents a criteria that can be used for searching applications.
|
||||
*/
|
||||
public class Filter {
|
||||
|
||||
/**
|
||||
* Order which the search results should be shown. Ascending or Descending.
|
||||
*/
|
||||
public enum SortingOrder {
|
||||
ASC, DESC
|
||||
}
|
||||
|
||||
@ -19,8 +19,15 @@
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
//TODO
|
||||
|
||||
/**
|
||||
* FilterProperty defines the property that can be used to filter the Application.
|
||||
*/
|
||||
public class FilterProperty {
|
||||
|
||||
/**
|
||||
* Operators that can be used in search.
|
||||
*/
|
||||
public enum Operator {
|
||||
EQUALS ("="),
|
||||
GRATER_THAN (">"),
|
||||
|
||||
@ -19,6 +19,9 @@ package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Represents an lifecycle of an {@link Application}.
|
||||
*/
|
||||
public class Lifecycle {
|
||||
|
||||
private LifecycleState lifecycleState;
|
||||
|
||||
@ -18,6 +18,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
/**
|
||||
* Represents a state in {@link Lifecycle}.
|
||||
*/
|
||||
public class LifecycleState {
|
||||
|
||||
private int id;
|
||||
|
||||
@ -18,6 +18,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
/**
|
||||
* This class represents the pagination details that will be used when fetching application details from database.
|
||||
*/
|
||||
public class Pagination {
|
||||
|
||||
private int offset;
|
||||
|
||||
@ -17,6 +17,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
/**
|
||||
* Represents the payment related information for the {@link Application}.
|
||||
*/
|
||||
public class Payment {
|
||||
private boolean freeApp;
|
||||
|
||||
|
||||
@ -23,6 +23,9 @@ import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the platform of an {@link Application}.
|
||||
*/
|
||||
public class Platform {
|
||||
|
||||
/**
|
||||
@ -175,6 +178,9 @@ public class Platform {
|
||||
return !(name == null || identifier == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a property of a {@link Platform}.
|
||||
*/
|
||||
public static class Property implements Cloneable {
|
||||
|
||||
private String name;
|
||||
|
||||
@ -20,6 +20,9 @@ package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Represents subscription of an {@link Application}
|
||||
*/
|
||||
public class Subscription {
|
||||
|
||||
private Visibility.Type type;
|
||||
|
||||
@ -18,6 +18,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
/**
|
||||
* Represents an user of {@link Application}.
|
||||
*/
|
||||
public class User {
|
||||
|
||||
private String userName;
|
||||
@ -44,4 +47,9 @@ public class User {
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User-name : " + userName + "\t Tenant-ID : " + tenantId;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
//TODO: move to app
|
||||
/**
|
||||
* This class represents the visibility details of an Application.
|
||||
*/
|
||||
public class Visibility {
|
||||
|
||||
private Type type;
|
||||
@ -61,6 +63,9 @@ public class Visibility {
|
||||
this.applicationRelease = applicationRelease;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of the visibility of the application.
|
||||
*/
|
||||
public class Type {
|
||||
|
||||
private String id;
|
||||
|
||||
@ -18,16 +18,19 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.exception;
|
||||
|
||||
/**
|
||||
* Represents the exception thrown during application management.
|
||||
*/
|
||||
public class ApplicationManagementException extends Exception {
|
||||
|
||||
String message;
|
||||
|
||||
public ApplicationManagementException(String message, Throwable throwable){
|
||||
public ApplicationManagementException(String message, Throwable throwable) {
|
||||
super(message, throwable);
|
||||
setMessage(message);
|
||||
}
|
||||
|
||||
public ApplicationManagementException(String message){
|
||||
public ApplicationManagementException(String message) {
|
||||
super(message);
|
||||
setMessage(message);
|
||||
}
|
||||
|
||||
@ -17,6 +17,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.exception;
|
||||
|
||||
/**
|
||||
* Exception thrown due to Database Connection issues.
|
||||
*/
|
||||
public class DBConnectionException extends ApplicationManagementException {
|
||||
|
||||
private static final long serialVersionUID = -3151279331929070297L;
|
||||
|
||||
@ -17,6 +17,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.exception;
|
||||
|
||||
/**
|
||||
* Exception thrown due to an issue in database transactions.
|
||||
*/
|
||||
public class IllegalTransactionStateException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -3151279331929070297L;
|
||||
|
||||
@ -17,6 +17,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.exception;
|
||||
|
||||
/**
|
||||
* Exception thrown due to invalid configurations provided for Application Management.
|
||||
*/
|
||||
public class InvalidConfigurationException extends ApplicationManagementException {
|
||||
|
||||
public InvalidConfigurationException(String message, Throwable throwable) {
|
||||
|
||||
@ -17,6 +17,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.exception;
|
||||
|
||||
/**
|
||||
* Exception caused during the platform management.
|
||||
*/
|
||||
public class PlatformManagementException extends ApplicationManagementException {
|
||||
|
||||
public PlatformManagementException(String message, Throwable ex) {
|
||||
|
||||
@ -17,6 +17,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.exception;
|
||||
|
||||
/**
|
||||
* Exception thrown due to an issue in TransactionManagement of Database.
|
||||
*/
|
||||
public class TransactionManagementException extends ApplicationManagementException {
|
||||
|
||||
private static final long serialVersionUID = -3151279321929070297L;
|
||||
|
||||
@ -21,6 +21,9 @@ package org.wso2.carbon.device.application.mgt.common.jaxrs;
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
|
||||
/**
|
||||
* This class is used to exclude certain fields when serializing and de-serializing based on the annotation.
|
||||
*/
|
||||
public class AnnotationExclusionStrategy implements ExclusionStrategy {
|
||||
|
||||
@Override
|
||||
@ -32,4 +35,4 @@ public class AnnotationExclusionStrategy implements ExclusionStrategy {
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,10 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This class is the representation of custom developed Exclude annotation.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface Exclude {
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,17 +19,43 @@
|
||||
package org.wso2.carbon.device.application.mgt.common.services;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.Application;
|
||||
import org.wso2.carbon.device.application.mgt.common.Filter;
|
||||
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
|
||||
import org.wso2.carbon.device.application.mgt.common.Filter;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
||||
|
||||
public interface ApplicationManager{
|
||||
/**
|
||||
* This interface manages the application creation, deletion and editing of the application.
|
||||
*/
|
||||
public interface ApplicationManager {
|
||||
|
||||
public Application createApplication(Application application) throws ApplicationManagementException;
|
||||
/**
|
||||
* Creates an application.
|
||||
* @param application Application that need to be created.
|
||||
* @return Created application
|
||||
* @throws ApplicationManagementException Application Management Exception
|
||||
*/
|
||||
public Application createApplication(Application application) throws ApplicationManagementException;
|
||||
|
||||
public Application editApplication(Application application) throws ApplicationManagementException;
|
||||
/**
|
||||
* Updates an already existing application.
|
||||
* @param application Application that need to be updated.
|
||||
* @return Updated Application
|
||||
* @throws ApplicationManagementException Application Management Exception
|
||||
*/
|
||||
public Application editApplication(Application application) throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Delete an application identified by the unique ID.
|
||||
* @param uuid Unique ID for tha application
|
||||
* @throws ApplicationManagementException Application Management Exception
|
||||
*/
|
||||
public void deleteApplication(String uuid) throws ApplicationManagementException;
|
||||
|
||||
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException;
|
||||
/**
|
||||
* To get the applications based on the search filter.
|
||||
* @param filter Search filter
|
||||
* @return Applications that matches the given filter criteria.
|
||||
* @throws ApplicationManagementException Application Management Exception
|
||||
*/
|
||||
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException;
|
||||
}
|
||||
|
||||
@ -18,11 +18,12 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.services;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.Application;
|
||||
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
|
||||
import org.wso2.carbon.device.application.mgt.common.Filter;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
||||
|
||||
public interface ApplicationReleaseManager{
|
||||
/**
|
||||
* ApplicationReleaseManager is responsible for handling all the operations related with
|
||||
* {@link org.wso2.carbon.device.application.mgt.common.ApplicationRelease} which involving addition, updation ,
|
||||
* deletion and viewing.
|
||||
*
|
||||
*/
|
||||
public interface ApplicationReleaseManager {
|
||||
|
||||
}
|
||||
|
||||
@ -18,6 +18,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.services;
|
||||
|
||||
/**
|
||||
* This interface manages all the operations related with Application Upload.
|
||||
*/
|
||||
public interface ApplicationUploadManager {
|
||||
|
||||
}
|
||||
|
||||
@ -18,13 +18,14 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.services;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.Application;
|
||||
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
|
||||
import org.wso2.carbon.device.application.mgt.common.Category;
|
||||
import org.wso2.carbon.device.application.mgt.common.Filter;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
||||
|
||||
public interface CategoryManager{
|
||||
/**
|
||||
* CategoryManager is responsible for handling add, delete, update opertaions related with {@link Category}
|
||||
*/
|
||||
public interface CategoryManager {
|
||||
|
||||
public Category createCategory(Category application) throws ApplicationManagementException;
|
||||
|
||||
|
||||
@ -18,5 +18,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.services;
|
||||
|
||||
public interface CommentsManager{
|
||||
/**
|
||||
* CommentsManager is responsible for handling all the add/update/delete/get operations related with
|
||||
* {@link org.wso2.carbon.device.application.mgt.common.Comment}.
|
||||
*/
|
||||
public interface CommentsManager {
|
||||
}
|
||||
|
||||
@ -18,6 +18,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.services;
|
||||
|
||||
/**
|
||||
* This interface manages all the operations related with lifecycle state.
|
||||
*/
|
||||
public interface LifecycleStateManager {
|
||||
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Platform manager is responsible for handling platforms, which will be used to as a registry of platforms.
|
||||
* And will be able to provide the platforms related informations to other classes which requires.
|
||||
* And will be able to provide the platforms related information to other classes which requires.
|
||||
*/
|
||||
public interface PlatformManager {
|
||||
|
||||
@ -37,9 +37,11 @@ public interface PlatformManager {
|
||||
|
||||
void register(String tenantDomain, Platform platform) throws PlatformManagementException;
|
||||
|
||||
void update(String tenantDomain, String oldPlatformIdentifier, Platform platform) throws PlatformManagementException;
|
||||
void update(String tenantDomain, String oldPlatformIdentifier, Platform platform)
|
||||
throws PlatformManagementException;
|
||||
|
||||
void unregister(String tenantDomain, String platformIdentifier, boolean isFileBased) throws PlatformManagementException;
|
||||
void unregister(String tenantDomain, String platformIdentifier, boolean isFileBased)
|
||||
throws PlatformManagementException;
|
||||
|
||||
void addMapping(String tenantDomain, List<String> platformIdentifiers) throws PlatformManagementException;
|
||||
|
||||
|
||||
@ -18,5 +18,8 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.services;
|
||||
|
||||
/**
|
||||
* This interface manages all the operations related with Application Subscription.
|
||||
*/
|
||||
public interface SubscriptionManager {
|
||||
}
|
||||
|
||||
@ -18,6 +18,9 @@
|
||||
|
||||
package org.wso2.carbon.device.application.mgt.common.services;
|
||||
|
||||
/**
|
||||
* This interface manages all the operations related with Application Visibility.
|
||||
*/
|
||||
public interface VisibilityManager {
|
||||
|
||||
}
|
||||
|
||||
@ -18,5 +18,9 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.common.services;
|
||||
|
||||
/**
|
||||
* VisibilityTypeManager is responsible for handling all the operations related to VisibilityType, this includes
|
||||
* creating, updating and viewing the {@link org.wso2.carbon.device.application.mgt.common.Visibility.Type}
|
||||
*/
|
||||
public interface VisibilityTypeManager {
|
||||
}
|
||||
|
||||
@ -21,13 +21,13 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>application-mgt</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.device.application.mgt.core</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Application Management Core</name>
|
||||
<description>WSO2 Carbon - Application Management Core</description>
|
||||
@ -73,7 +73,9 @@
|
||||
org.wso2.carbon.device.mgt.common.*,
|
||||
org.apache.axis2.*,
|
||||
org.wso2.carbon.user.core.*,
|
||||
org.wso2.carbon.user.api.*
|
||||
org.wso2.carbon.user.api.*,
|
||||
org.wso2.carbon.ndatasource.core,
|
||||
org.apache.axiom.om.*; version="${axiom.osgi.version.range}"
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.device.application.mgt.core.internal.*,
|
||||
@ -153,6 +155,10 @@
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.user.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
|
||||
@ -18,9 +18,13 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.dao.common;
|
||||
|
||||
import org.apache.axiom.om.OMElement;
|
||||
import org.apache.axiom.om.util.AXIOMUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException;
|
||||
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO;
|
||||
@ -28,9 +32,20 @@ import org.wso2.carbon.device.application.mgt.core.dao.impl.application.H2Applic
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.MySQLApplicationDAOImpl;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.GenericPlatformDAOImpl;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.ApplicationMgtDatabaseCreator;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.Constants;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
||||
import org.wso2.carbon.ndatasource.core.CarbonDataSource;
|
||||
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
||||
import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* This class intends to act as the primary entity that hides all DAO instantiation related complexities and logic so
|
||||
@ -87,5 +102,68 @@ public class DAOFactory {
|
||||
}
|
||||
throw new IllegalStateException("Database engine has not initialized properly.");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes the databases by creating the database.
|
||||
* @throws ApplicationManagementDAOException Exceptions thrown during the creation of the tables
|
||||
*/
|
||||
public static void initDatabases() throws ApplicationManagementDAOException {
|
||||
CarbonDataSource carbonDataSource = null;
|
||||
DataSource dataSource = null;
|
||||
String dataSourceName = ConfigurationManager.getInstance()
|
||||
.getConfiguration().getDatasourceName();
|
||||
DataSourceService service = DataHolder.getInstance().getDataSourceService();
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
||||
.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
|
||||
try {
|
||||
carbonDataSource = service.getDataSource(dataSourceName);
|
||||
dataSource = (DataSource) carbonDataSource.getDSObject();
|
||||
if (System.getProperty("setup") == null) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Application Management Database schema initialization check was skipped since "
|
||||
+ "\'setup\' variable was not given during startup");
|
||||
}
|
||||
} else {
|
||||
DatabaseCreator databaseCreator = new ApplicationMgtDatabaseCreator(dataSource);
|
||||
String validationQuery = getValidationQuery(
|
||||
(String) carbonDataSource.getDSMInfo().getDefinition().getDsXMLConfiguration());
|
||||
if (!databaseCreator.isDatabaseStructureCreated(validationQuery)) {
|
||||
databaseCreator.createRegistryDatabase();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Application Management tables are created in the database");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new ApplicationManagementDAOException("Error while creating application-mgt database during the "
|
||||
+ "startup ", e);
|
||||
} catch (Exception e) {
|
||||
throw new ApplicationManagementDAOException("Error while creating application-mgt database in the "
|
||||
+ "startup ", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To get the the validation query to make sure whether the tables exist already in application management databse
|
||||
* @param dsXMLConfiguration Datasource XML configurations
|
||||
* @return Validation query
|
||||
*/
|
||||
private static String getValidationQuery(String dsXMLConfiguration) {
|
||||
String DEFAULT_VALIDATION_QUERY = "SELECT 1";
|
||||
try {
|
||||
OMElement omElement = AXIOMUtil.stringToOM(dsXMLConfiguration);
|
||||
return omElement.getFirstChildWithName(new QName("validationQuery")).getText();
|
||||
} catch (XMLStreamException e) {
|
||||
log.error("Error while reading the validation query from the data source configuration of "
|
||||
+ "application-mgt (application-mgt-datasources.xml", e);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Due to fail to read the validation query from application-mgt datasources, using the "
|
||||
+ "default validation query : " + DEFAULT_VALIDATION_QUERY);
|
||||
}
|
||||
return DEFAULT_VALIDATION_QUERY;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -410,7 +410,12 @@ public class MySQLApplicationDAOImpl extends AbstractApplicationDAOImpl {
|
||||
|
||||
@Override
|
||||
public Application createApplication(Application application) throws ApplicationManagementDAOException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request received in DAO Layer to create an application");
|
||||
log.debug("Application Details : ");
|
||||
log.debug("UUID : " + application.getUuid() + " Name : " + application.getName() + " User name : " +
|
||||
application.getUser().getUserName());
|
||||
}
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
@ -18,6 +18,8 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.dao.impl.platform;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.application.mgt.common.Platform;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException;
|
||||
@ -35,6 +37,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformDAO {
|
||||
private static Log log = LogFactory.getLog(GenericPlatformDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public int register(String tenantDomain, Platform platform) throws PlatformManagementDAOException {
|
||||
@ -339,14 +342,22 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
||||
|
||||
@Override
|
||||
public List<Platform> getPlatforms(String tenantDomain) throws PlatformManagementDAOException {
|
||||
String selectQuery = "SELECT MAPPING.ID, PLATFORM.IDENTIFIER FROM (SELECT * FROM APPM_PLATFORM WHERE TENANT_DOMAIN=? OR IS_SHARED = TRUE AND FILE_BASED = FALSE) PLATFORM " +
|
||||
"LEFT JOIN APPM_PLATFORM_TENANT_MAPPING MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID";
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("GetPlaforms request received for the tenantDomain " + tenantDomain);
|
||||
}
|
||||
String selectQuery =
|
||||
"SELECT MAPPING.ID, PLATFORM.IDENTIFIER FROM (SELECT * FROM APPM_PLATFORM WHERE TENANT_DOMAIN=? OR "
|
||||
+ "IS_SHARED = TRUE AND FILE_BASED = FALSE) PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING "
|
||||
+ "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID";
|
||||
try {
|
||||
Connection connection = ConnectionManagerUtil.openConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(selectQuery);
|
||||
preparedStatement.setString(1, tenantDomain);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
List<Platform> platforms = new ArrayList<>();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Platform retrieved for the tenant domain " + tenantDomain);
|
||||
}
|
||||
while (resultSet.next()) {
|
||||
String identifier = resultSet.getString("PLATFORM.IDENTIFIER");
|
||||
int mappingID = resultSet.getInt("MAPPING.ID");
|
||||
@ -357,12 +368,20 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
||||
platform.setEnabled(false);
|
||||
}
|
||||
platforms.add(platform);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Platform Identifier - " + identifier + " isEnabled - " + platform.isEnabled());
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Number of platforms available for the tenant domain - " + tenantDomain + " :" + platforms
|
||||
.size());
|
||||
}
|
||||
return platforms;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new PlatformManagementDAOException("Error occured when loading the platforms for tenant - " + tenantDomain, e);
|
||||
throw new PlatformManagementDAOException(
|
||||
"Error occured when loading the platforms for tenant - " + tenantDomain, e);
|
||||
} catch (SQLException e) {
|
||||
throw new PlatformManagementDAOException("Error occured when executing query - " + selectQuery, e);
|
||||
throw new PlatformManagementDAOException("Error occurred when executing query - " + selectQuery, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeConnection();
|
||||
}
|
||||
|
||||
@ -21,6 +21,9 @@ import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
|
||||
/**
|
||||
* Represents a property of the {@link Platform}.
|
||||
*/
|
||||
@XmlRootElement(name = "Property")
|
||||
public class Property {
|
||||
|
||||
|
||||
@ -17,9 +17,11 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.application.mgt.common.Platform;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.PlatformManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
|
||||
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
|
||||
import org.wso2.carbon.user.api.Tenant;
|
||||
@ -34,6 +36,7 @@ import java.util.Map;
|
||||
|
||||
public class PlatformManagerImpl implements PlatformManager {
|
||||
private Map<String, Map<String, Platform>> inMemoryStore;
|
||||
private static Log log = LogFactory.getLog(PlatformManagerImpl.class);
|
||||
|
||||
public PlatformManagerImpl() {
|
||||
this.inMemoryStore = new HashMap<>();
|
||||
@ -53,20 +56,39 @@ public class PlatformManagerImpl implements PlatformManager {
|
||||
|
||||
@Override
|
||||
public List<Platform> getPlatforms(String tenantDomain) throws PlatformManagementException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Request for getting platforms received for the tenant domain " + tenantDomain + " at "
|
||||
+ "PlatformManager level");
|
||||
}
|
||||
List<Platform> platforms = DAOFactory.getPlatformDAO().getPlatforms(tenantDomain);
|
||||
int platformIndex = 0;
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Number of platforms received from DAO layer is " + platforms.size() + " for the tenant "
|
||||
+ tenantDomain);
|
||||
}
|
||||
for (Platform platform : platforms) {
|
||||
if (platform.isFileBased()) {
|
||||
Map<String, Platform> superTenantPlatforms = this.inMemoryStore.get(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||
Map<String, Platform> superTenantPlatforms = this.inMemoryStore
|
||||
.get(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||
Platform registeredPlatform = superTenantPlatforms.get(platform.getIdentifier());
|
||||
if (registeredPlatform != null) {
|
||||
platforms.set(platformIndex, new Platform(registeredPlatform));
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Platform Name - " + platform.getName() + ", IsRegistered - " + true);
|
||||
}
|
||||
} else {
|
||||
platforms.remove(platformIndex);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Platform Name - " + platform.getName() + ", IsRegistered - " + false);
|
||||
}
|
||||
}
|
||||
}
|
||||
platformIndex++;
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Number of effective platforms for the tenant " + tenantDomain + " : " + platforms.size());
|
||||
}
|
||||
return platforms;
|
||||
}
|
||||
|
||||
|
||||
@ -18,10 +18,23 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.application.mgt.core.internal;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.services.*;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationUploadManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.VisibilityTypeManager;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
|
||||
/**
|
||||
* DataHolder is responsible for holding the references to OSGI Services.
|
||||
*/
|
||||
public class DataHolder {
|
||||
|
||||
private DeviceManagementProviderService deviceManagementService;
|
||||
@ -50,6 +63,8 @@ public class DataHolder {
|
||||
|
||||
private static final DataHolder applicationMgtDataHolder = new DataHolder();
|
||||
|
||||
private DataSourceService dataSourceService;
|
||||
|
||||
private DataHolder() {
|
||||
|
||||
}
|
||||
@ -153,4 +168,12 @@ public class DataHolder {
|
||||
public void setRealmService(RealmService realmService) {
|
||||
this.realmService = realmService;
|
||||
}
|
||||
|
||||
public void setDataSourceService(DataSourceService dataSourceService) {
|
||||
this.dataSourceService = dataSourceService;
|
||||
}
|
||||
|
||||
public DataSourceService getDataSourceService() {
|
||||
return dataSourceService;
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,15 +19,26 @@
|
||||
package org.wso2.carbon.device.application.mgt.core.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.*;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.ApplicationUploadManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.VisibilityTypeManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
|
||||
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
@ -47,24 +58,31 @@ import javax.naming.NamingException;
|
||||
* policy="dynamic"
|
||||
* bind="setRealmService"
|
||||
* unbind="unsetRealmService"
|
||||
* @scr.reference name="datasource.service"
|
||||
* interface="org.wso2.carbon.ndatasource.core.DataSourceService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setDataSourceService"
|
||||
* unbind="unsetDataSourceService"
|
||||
*/
|
||||
public class ServiceComponent {
|
||||
|
||||
private static Log log = LogFactory.getLog(ServiceComponent.class);
|
||||
|
||||
|
||||
protected void activate(ComponentContext componentContext) throws NamingException {
|
||||
protected void activate(ComponentContext componentContext) throws NamingException,
|
||||
ApplicationManagementDAOException {
|
||||
BundleContext bundleContext = componentContext.getBundleContext();
|
||||
try {
|
||||
String datasourceName = ConfigurationManager.getInstance()
|
||||
.getConfiguration().getDatasourceName();
|
||||
String datasourceName = ConfigurationManager.getInstance().getConfiguration().getDatasourceName();
|
||||
DAOFactory.init(datasourceName);
|
||||
|
||||
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance();
|
||||
DataHolder.getInstance().setApplicationManager(applicationManager);
|
||||
bundleContext.registerService(ApplicationManager.class.getName(), applicationManager, null);
|
||||
|
||||
ApplicationReleaseManager applicationReleaseManager = ApplicationManagementUtil.getApplicationReleaseManagerInstance();
|
||||
ApplicationReleaseManager applicationReleaseManager = ApplicationManagementUtil
|
||||
.getApplicationReleaseManagerInstance();
|
||||
DataHolder.getInstance().setReleaseManager(applicationReleaseManager);
|
||||
bundleContext.registerService(ApplicationReleaseManager.class.getName(), applicationReleaseManager, null);
|
||||
|
||||
@ -100,11 +118,8 @@ public class ServiceComponent {
|
||||
DataHolder.getInstance().setApplicationUploadManager(uploadManager);
|
||||
bundleContext.registerService(ApplicationUploadManager.class.getName(), uploadManager, null);
|
||||
|
||||
DAOFactory.init(datasourceName);
|
||||
log.info("ApplicationManagement core bundle has been successfully initialized");
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("ApplicationManagement core bundle has been successfully initialized");
|
||||
}
|
||||
} catch (InvalidConfigurationException e) {
|
||||
log.error("Error while activating Application Management core component. ", e);
|
||||
}
|
||||
@ -135,4 +150,12 @@ public class ServiceComponent {
|
||||
protected void unsetRealmService(RealmService realmService) {
|
||||
DataHolder.getInstance().setRealmService(null);
|
||||
}
|
||||
|
||||
protected void setDataSourceService(DataSourceService dataSourceService) {
|
||||
DataHolder.getInstance().setDataSourceService(dataSourceService);
|
||||
}
|
||||
|
||||
protected void unsetDataSourceService(DataSourceService dataSourceService) {
|
||||
DataHolder.getInstance().setDataSourceService(null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.application.mgt.core.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* ApplicationMgtDatabaseCreator is responsible for creating the Application Management related tables.
|
||||
*/
|
||||
public class ApplicationMgtDatabaseCreator extends DatabaseCreator {
|
||||
private static final Log log = LogFactory.getLog(ApplicationMgtDatabaseCreator.class);
|
||||
private static final String setupSQLScriptBaseLocation =
|
||||
CarbonUtils.getCarbonHome() + File.separator + "dbscripts" + File.separator + "cdm" + File.separator
|
||||
+ "application-mgt" + File.separator;
|
||||
|
||||
public ApplicationMgtDatabaseCreator(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
}
|
||||
|
||||
protected String getDbScriptLocation(String databaseType) {
|
||||
String scriptName = databaseType + ".sql";
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Loading application management database script from :" + scriptName);
|
||||
}
|
||||
return setupSQLScriptBaseLocation + scriptName;
|
||||
}
|
||||
}
|
||||
@ -22,14 +22,14 @@
|
||||
<parent>
|
||||
<artifactId>application-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.device.application.mgt.ui</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<name>WSO2 Carbon - Application Management Base UI</name>
|
||||
<description>WSO2 Carbon - Application Management Base UI</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
{
|
||||
"displayName": "Carbon Application Management App",
|
||||
"logLevel": "info",
|
||||
"initScripts": ["/app/modules/init.js"],
|
||||
"urlMappings": [
|
||||
{
|
||||
"url": "/uuf/login",
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>carbon-devicemgt</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -38,8 +38,6 @@
|
||||
<module>org.wso2.carbon.device.application.mgt.common</module>
|
||||
<module>org.wso2.carbon.device.application.mgt.api</module>
|
||||
<module>org.wso2.carbon.device.application.mgt.ui</module>
|
||||
<!--<module>org.wso2.carbon.device.application.mgt.android.platform</module>-->
|
||||
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
@ -62,4 +60,5 @@
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>certificate-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -38,8 +38,8 @@
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>certificate-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -38,8 +38,8 @@
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
||||
@ -21,13 +21,13 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>certificate-mgt</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Certificate Management Core</name>
|
||||
<description>WSO2 Carbon - Certificate Management Core</description>
|
||||
|
||||
@ -22,14 +22,14 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>carbon-devicemgt</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>certificate-mgt</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>WSO2 Carbon - Certificate Management Component</name>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>device-mgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -112,7 +112,7 @@
|
||||
org.w3c.dom,
|
||||
org.wso2.carbon.context,
|
||||
org.wso2.carbon.device.mgt.common.*,
|
||||
org.wso2.carbon.device.mgt.extensions.*,
|
||||
org.wso2.carbon.device.mgt.extensions.device.type.template.*,
|
||||
org.wso2.carbon.registry.api,
|
||||
org.wso2.carbon.registry.core,
|
||||
org.wso2.carbon.registry.core.*,
|
||||
|
||||
@ -29,12 +29,12 @@ import org.osgi.framework.ServiceRegistration;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceTypeConfiguration;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception.DeviceTypeConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.internal.DeviceTypeManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.DeviceTypeConfigIdentifier;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.DeviceTypeManagerService;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.util.DeviceTypeConfigUtil;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.DeviceTypeConfigIdentifier;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.DeviceTypeManagerService;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer;
|
||||
|
||||
import org.apache.axis2.context.ConfigurationContext;
|
||||
import org.apache.axis2.deployment.AbstractDeployer;
|
||||
import org.apache.axis2.deployment.DeploymentException;
|
||||
import org.apache.axis2.deployment.repository.util.DeploymentFileData;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* This is the device deployer that will read and deploy the device type ui files from
|
||||
* "deployment/server/devicetypes-ui"
|
||||
* directory.
|
||||
*/
|
||||
public class DeviceTypeUIDeployer extends AbstractDeployer {
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceTypeUIDeployer.class);
|
||||
protected Map<String, String> deviceTypeDeployedUIMap = new ConcurrentHashMap<String, String>();
|
||||
private static final String DEVICEMGT_JAGGERY_APP_PATH = CarbonUtils.getCarbonRepository() + File.separator
|
||||
+ "jaggeryapps" + File.separator + "devicemgt" + File.separator + "app" + File.separator + "units"
|
||||
+ File.separator;
|
||||
|
||||
private static final String UNIT_PREFIX = "cdmf.unit.device.type";
|
||||
|
||||
@Override
|
||||
public void init(ConfigurationContext configurationContext) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirectory(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExtension(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
|
||||
if (!deploymentFileData.getFile().isDirectory()) {
|
||||
return;
|
||||
}
|
||||
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
|
||||
if (tenantDomain != null && !tenantDomain.isEmpty()) {
|
||||
File jaggeryAppPath = new File(
|
||||
DEVICEMGT_JAGGERY_APP_PATH + tenantDomain + "." + deploymentFileData.getName());
|
||||
try {
|
||||
if (!jaggeryAppPath.exists()) {
|
||||
FileUtils.forceMkdir(jaggeryAppPath);
|
||||
FileUtils.copyDirectory(deploymentFileData.getFile(), jaggeryAppPath);
|
||||
File[] listOfFiles = jaggeryAppPath.listFiles();
|
||||
|
||||
for (int i = 0; i < listOfFiles.length; i++) {
|
||||
if (listOfFiles[i].isFile()) {
|
||||
String content = FileUtils.readFileToString(listOfFiles[i]);
|
||||
FileUtils.writeStringToFile(listOfFiles[i], content.replaceAll(UNIT_PREFIX
|
||||
, tenantDomain + "." + UNIT_PREFIX));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.debug("units already exists " + deploymentFileData.getName());
|
||||
}
|
||||
this.deviceTypeDeployedUIMap.put(deploymentFileData.getAbsolutePath(),
|
||||
jaggeryAppPath.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
if (jaggeryAppPath.exists()) {
|
||||
try {
|
||||
FileUtils.deleteDirectory(jaggeryAppPath);
|
||||
} catch (IOException e1) {
|
||||
log.error("Failed to delete directory " + jaggeryAppPath.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
log.error("Cannot deploy deviceType ui : " + deploymentFileData.getName(), e);
|
||||
throw new DeploymentException(
|
||||
"Device type ui file " + deploymentFileData.getName() + " is not deployed ", e);
|
||||
}
|
||||
|
||||
} else {
|
||||
log.error("Cannot deploy deviceType ui: " + deploymentFileData.getName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undeploy(String filePath) throws DeploymentException {
|
||||
try {
|
||||
String jaggeryUnitPath = this.deviceTypeDeployedUIMap.remove(filePath);
|
||||
FileUtils.deleteDirectory(new File(jaggeryUnitPath));
|
||||
log.info("Device Type units un deployed successfully.");
|
||||
} catch (IOException e) {
|
||||
throw new DeploymentException("Failed to remove the units: " + filePath);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
|
||||
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.bind.annotation.XmlElementDecl;
|
||||
import javax.xml.bind.annotation.XmlRegistry;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* This object contains factory methods for each
|
||||
* Java content interface and Java element interface
|
||||
* generated in the org.wso2.carbon package.
|
||||
* <p>An ObjectFactory allows you to programatically
|
||||
* construct new instances of the Java representation
|
||||
* for XML content. The Java representation of XML
|
||||
* content can consist of schema derived interfaces
|
||||
* and classes representing the binding of schema
|
||||
* type definitions, element declarations and model
|
||||
* groups. Factory methods for each of these are
|
||||
* provided in this class.
|
||||
*
|
||||
*/
|
||||
@XmlRegistry
|
||||
public class ObjectFactory {
|
||||
|
||||
private final static QName _DeviceTypeConfiguration_QNAME = new QName("", "DeviceTypeConfiguration");
|
||||
|
||||
/**
|
||||
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.wso2.carbon
|
||||
*
|
||||
*/
|
||||
public ObjectFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link DeviceTypeConfiguration }
|
||||
*
|
||||
*/
|
||||
public DeviceTypeConfiguration createDeviceTypeConfiguration() {
|
||||
return new DeviceTypeConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link Operation }
|
||||
*
|
||||
*/
|
||||
public Operation createOperation() {
|
||||
return new Operation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link Attributes }
|
||||
*
|
||||
*/
|
||||
public Attributes createAttributes() {
|
||||
return new Attributes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link ProvisioningConfig }
|
||||
*
|
||||
*/
|
||||
public ProvisioningConfig createProvisioningConfig() {
|
||||
return new ProvisioningConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link TableConfig }
|
||||
*
|
||||
*/
|
||||
public TableConfig createTableConfig() {
|
||||
return new TableConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link Table }
|
||||
*
|
||||
*/
|
||||
public Table createTable() {
|
||||
return new Table();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link Property }
|
||||
*
|
||||
*/
|
||||
public Property createProperty() {
|
||||
return new Property();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link JndiConfig }
|
||||
*
|
||||
*/
|
||||
public JndiConfig createJndiConfig() {
|
||||
return new JndiConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link FormParameters }
|
||||
*
|
||||
*/
|
||||
public FormParameters createFormParameters() {
|
||||
return new FormParameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link Features }
|
||||
*
|
||||
*/
|
||||
public Features createFeatures() {
|
||||
return new Features();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link Feature }
|
||||
*
|
||||
*/
|
||||
public Feature createFeature() {
|
||||
return new Feature();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link PushNotificationProvider }
|
||||
*
|
||||
*/
|
||||
public PushNotificationProvider createPushNotificationProvider() {
|
||||
return new PushNotificationProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link DataSource }
|
||||
*
|
||||
*/
|
||||
public DataSource createDataSource() {
|
||||
return new DataSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link ConfigProperties }
|
||||
*
|
||||
*/
|
||||
public ConfigProperties createConfigProperties() {
|
||||
return new ConfigProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link License }
|
||||
*
|
||||
*/
|
||||
public License createLicense() {
|
||||
return new License();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link DeviceDetails }
|
||||
*
|
||||
*/
|
||||
public DeviceDetails createDeviceDetails() {
|
||||
return new DeviceDetails();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link QueryParameters }
|
||||
*
|
||||
*/
|
||||
public QueryParameters createQueryParameters() {
|
||||
return new QueryParameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link JAXBElement }{@code <}{@link DeviceTypeConfiguration }{@code >}}
|
||||
*
|
||||
*/
|
||||
@XmlElementDecl(namespace = "", name = "DeviceTypeConfiguration")
|
||||
public JAXBElement<DeviceTypeConfiguration> createDeviceTypeConfiguration(DeviceTypeConfiguration value) {
|
||||
return new JAXBElement<DeviceTypeConfiguration>(_DeviceTypeConfiguration_QNAME, DeviceTypeConfiguration.class, null, value);
|
||||
}
|
||||
|
||||
}
|
||||
@ -28,7 +28,7 @@ import org.wso2.carbon.registry.core.service.RegistryService;
|
||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.device.mgt.iot.internal.DeviceTypeManagementServiceComponent"
|
||||
* @scr.component name="org.wso2.carbon.device.mgt.iot.internal.DeviceTypeExtensionServiceComponent"
|
||||
* immediate="true"
|
||||
* @scr.reference name="config.context.service"
|
||||
* interface="org.wso2.carbon.utils.ConfigurationContextService"
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.util;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception.DeviceTypeConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
|
||||
@ -22,9 +22,6 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.util;
|
||||
* This holds the constants used for this bundle.
|
||||
*/
|
||||
public class DeviceTypePluginConstants {
|
||||
public static final String MEDIA_TYPE_XML = "application/xml";
|
||||
public static final String CHARSET_UTF8 = "UTF8";
|
||||
public static final String LANGUAGE_CODE_ENGLISH_US = "en_US";
|
||||
|
||||
public static final String CDMF_UI_TYPE = "devicetype/ui";
|
||||
public static final String CDMF_UI_TYPE_DIR = "devicetypes-ui";
|
||||
|
||||
@ -1,128 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||
~ Version 2.0 (the "License"); you may not use this file except
|
||||
~ in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
-->
|
||||
<DeviceTypeConfiguration name="samples">
|
||||
|
||||
<DeviceDetails table-id="SAMPLE_DEVICE_1"/>
|
||||
|
||||
<Features>
|
||||
<Feature code="abc">
|
||||
<Name>abc</Name>
|
||||
<Description>this is a feature</Description>
|
||||
<Operation context="/bulb/{state}" method="PUT" type="application/json">
|
||||
<QueryParameters>
|
||||
<Parameter>deviceId</Parameter>
|
||||
</QueryParameters>
|
||||
<FormParameters>
|
||||
<Parameter>test</Parameter>
|
||||
</FormParameters>
|
||||
</Operation>
|
||||
</Feature>
|
||||
</Features>
|
||||
|
||||
<Claimable enabled="true"/>
|
||||
|
||||
<Sensors table-id="SAMPLE_DEVICE_2">
|
||||
<Sensor code="CPU_Temperature">
|
||||
<Name>temperature sensor fitted</Name>
|
||||
<StreamDefinition>org.wso2.temperature.stream</StreamDefinition>
|
||||
<Description>this is a sensor</Description>
|
||||
<SensorStaticProperties>
|
||||
<Property name="unit">celcius</Property>
|
||||
<Property name="model_number">atmeggga11234</Property>
|
||||
</SensorStaticProperties>
|
||||
</Sensor>
|
||||
<Sensor code="DHT11_Temperature">
|
||||
<Name>temperature sensor fitted</Name>
|
||||
<StreamDefinition>org.wso2.temperature.stream</StreamDefinition>
|
||||
<Description>this is a sensor</Description>
|
||||
<SensorStaticProperties>
|
||||
<Property name="unit">celcius</Property>
|
||||
</SensorStaticProperties>
|
||||
<SensorDynamicProperties>
|
||||
<Property name="model_number"/>
|
||||
</SensorDynamicProperties>
|
||||
</Sensor>
|
||||
</Sensors>
|
||||
|
||||
<ProvisioningConfig>
|
||||
<SharedWithAllTenants>false</SharedWithAllTenants>
|
||||
</ProvisioningConfig>
|
||||
|
||||
<DeviceAuthorizationConfig>
|
||||
<authorizationRequired>true</authorizationRequired>
|
||||
</DeviceAuthorizationConfig>
|
||||
|
||||
<PushNotificationProvider type="MQTT">
|
||||
<FileBasedProperties>true</FileBasedProperties>
|
||||
<!--if file based properties is set to false then the configuration will be picked from platform configuration-->
|
||||
<ConfigProperties>
|
||||
<Property Name="mqttAdapterName">sample.mqtt.adapter</Property>
|
||||
<Property Name="url">tcp://localhost:1883</Property>
|
||||
<Property Name="username">admin</Property>
|
||||
<Property Name="password">admin</Property>
|
||||
<Property Name="qos">0</Property>
|
||||
<Property Name="scopes"/>
|
||||
<Property Name="clearSession">true</Property>
|
||||
</ConfigProperties>
|
||||
</PushNotificationProvider>
|
||||
|
||||
<PolicyMonitoring enabled="true"/>
|
||||
|
||||
<License>
|
||||
<Language>en_US</Language>
|
||||
<Version>1.0.0</Version>
|
||||
<Text>This is license text</Text>
|
||||
</License>
|
||||
|
||||
<TaskConfiguration>
|
||||
<Enable>true</Enable>
|
||||
<Frequency>600000</Frequency>
|
||||
<Operations>
|
||||
<Operation>
|
||||
<Name>DEVICE_INFO</Name>
|
||||
<RecurrentTimes>1</RecurrentTimes>
|
||||
</Operation>
|
||||
<Operation>
|
||||
<Name>APPLICATION_LIST</Name>
|
||||
<RecurrentTimes>5</RecurrentTimes>
|
||||
</Operation>
|
||||
<Operation>
|
||||
<Name>DEVICE_LOCATION</Name>
|
||||
<RecurrentTimes>1</RecurrentTimes>
|
||||
</Operation>
|
||||
</Operations>
|
||||
</TaskConfiguration>
|
||||
|
||||
<DataSource>
|
||||
<jndiConfig>
|
||||
<name>jdbc/SampleDM_DB</name>
|
||||
</jndiConfig>
|
||||
<tableConfig>
|
||||
<Table name="SAMPLE_DEVICE_1">
|
||||
<PrimaryKey>SAMPLE_DEVICE_ID</PrimaryKey>
|
||||
<Attributes>
|
||||
<Attribute>column1</Attribute>
|
||||
<Attribute>column2</Attribute>
|
||||
</Attributes>
|
||||
</Table>
|
||||
</tableConfig>
|
||||
</DataSource>
|
||||
|
||||
</DeviceTypeConfiguration>
|
||||
@ -0,0 +1,100 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||
~ Version 2.0 (the "License"); you may not use this file except
|
||||
~ in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<artifactId>device-mgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.device.mgt.extensions.pull.notification</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Pull Notification Provider Implementation</name>
|
||||
<description>WSO2 Carbon - Pull Notification Provider Implementation</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||
<Bundle-Description>Pull Notification Provider Bundle</Bundle-Description>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.device.mgt.extensions.pull.notification.internal,
|
||||
org.wso2.carbon.device.mgt.extensions.pull.notification.*
|
||||
</Export-Package>
|
||||
<Import-Package>
|
||||
org.osgi.framework,
|
||||
org.osgi.service.component,
|
||||
org.apache.commons.logging,
|
||||
org.wso2.carbon.device.mgt.common.*,
|
||||
org.wso2.carbon.device.mgt.core.service
|
||||
org.wso2.carbon.policy.mgt.core.*,
|
||||
org.wso2.carbon.policy.mgt.core,
|
||||
com.google.gson,
|
||||
org.wso2.carbon.device.mgt.core.service.*
|
||||
</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.pull.notification;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
||||
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
|
||||
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
|
||||
import org.wso2.carbon.device.mgt.extensions.pull.notification.internal.PullNotificationDataHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PullNotificationSubscriberImpl implements PullNotificationSubscriber {
|
||||
|
||||
public final class OperationCodes {
|
||||
private OperationCodes() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
public static final String POLICY_MONITOR = "POLICY_MONITOR";
|
||||
}
|
||||
|
||||
|
||||
private static final Log log = LogFactory.getLog(PullNotificationSubscriberImpl.class);
|
||||
|
||||
public void init(Map<String, String> properties) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(DeviceIdentifier deviceIdentifier, Operation operation) throws PullNotificationExecutionFailedException {
|
||||
try {
|
||||
if (!Operation.Status.ERROR.equals(operation.getStatus()) && operation.getCode() != null &&
|
||||
OperationCodes.POLICY_MONITOR.equals(operation.getCode())) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.info("Received compliance status from POLICY_MONITOR operation ID: " + operation.getId());
|
||||
}
|
||||
List<ComplianceFeature> features = getComplianceFeatures(operation.getPayLoad());
|
||||
PullNotificationDataHolder.getInstance().getPolicyManagerService()
|
||||
.checkCompliance(deviceIdentifier, features);
|
||||
|
||||
} else {
|
||||
PullNotificationDataHolder.getInstance().getDeviceManagementProviderService().updateOperation(
|
||||
deviceIdentifier, operation);
|
||||
}
|
||||
} catch (OperationManagementException e) {
|
||||
throw new PullNotificationExecutionFailedException(e);
|
||||
} catch (PolicyComplianceException e) {
|
||||
throw new PullNotificationExecutionFailedException("Invalid payload format compliant feature", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
|
||||
}
|
||||
|
||||
private static List<ComplianceFeature> getComplianceFeatures(Object compliancePayload) throws
|
||||
PolicyComplianceException {
|
||||
String compliancePayloadString = new Gson().toJson(compliancePayload);
|
||||
if (compliancePayload == null) {
|
||||
return null;
|
||||
}
|
||||
// Parsing json string to get compliance features.
|
||||
JsonElement jsonElement = new JsonParser().parse(compliancePayloadString);
|
||||
JsonArray jsonArray = jsonElement.getAsJsonArray();
|
||||
Gson gson = new Gson();
|
||||
ComplianceFeature complianceFeature;
|
||||
List<ComplianceFeature> complianceFeatures = new ArrayList<ComplianceFeature>(jsonArray.size());
|
||||
|
||||
for (JsonElement element : jsonArray) {
|
||||
complianceFeature = gson.fromJson(element, ComplianceFeature.class);
|
||||
complianceFeatures.add(complianceFeature);
|
||||
}
|
||||
return complianceFeatures;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.pull.notification.internal;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||
|
||||
public class PullNotificationDataHolder {
|
||||
|
||||
private DeviceManagementProviderService deviceManagementProviderService;
|
||||
private PolicyManagerService policyManagerService;
|
||||
|
||||
private static PullNotificationDataHolder thisInstance = new PullNotificationDataHolder();
|
||||
|
||||
public static PullNotificationDataHolder getInstance() {
|
||||
return thisInstance;
|
||||
}
|
||||
|
||||
public DeviceManagementProviderService getDeviceManagementProviderService() {
|
||||
return deviceManagementProviderService;
|
||||
}
|
||||
|
||||
public void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
|
||||
this.deviceManagementProviderService = deviceManagementProviderService;
|
||||
}
|
||||
|
||||
public PolicyManagerService getPolicyManagerService() {
|
||||
return policyManagerService;
|
||||
}
|
||||
|
||||
public void setPolicyManagerService(PolicyManagerService policyManagerService) {
|
||||
this.policyManagerService = policyManagerService;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.pull.notification.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.device.mgt.extensions.pull.notification.internal.PullNotificationServiceComponent" immediate="true"
|
||||
* @scr.reference name="carbon.device.mgt.provider"
|
||||
* interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setDeviceManagementProviderService"
|
||||
* unbind="unsetDeviceManagementProviderService"
|
||||
* @scr.reference name="org.wso2.carbon.policy.mgt.core"
|
||||
* interface="org.wso2.carbon.policy.mgt.core.PolicyManagerService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setPolicyManagerService"
|
||||
* unbind="unsetPolicyManagerService"
|
||||
*/
|
||||
public class PullNotificationServiceComponent {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PullNotificationServiceComponent.class);
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void activate(ComponentContext componentContext) {
|
||||
try {
|
||||
//Do nothing
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("pull notification provider implementation bundle has been successfully " +
|
||||
"initialized");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while initializing pull notification provider " +
|
||||
"implementation bundle", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void deactivate(ComponentContext componentContext) {
|
||||
//Do nothing
|
||||
}
|
||||
|
||||
protected void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
|
||||
PullNotificationDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
|
||||
}
|
||||
|
||||
protected void unsetDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
|
||||
PullNotificationDataHolder.getInstance().setDeviceManagementProviderService(null);
|
||||
}
|
||||
|
||||
protected void setPolicyManagerService(PolicyManagerService policyManagerService) {
|
||||
PullNotificationDataHolder.getInstance().setPolicyManagerService(policyManagerService);
|
||||
}
|
||||
|
||||
protected void unsetPolicyManagerService(PolicyManagerService policyManagerService) {
|
||||
PullNotificationDataHolder.getInstance().setPolicyManagerService(null);
|
||||
}
|
||||
|
||||
}
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>device-mgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -57,7 +57,7 @@ public class FCMNotificationStrategy implements NotificationStrategy {
|
||||
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
|
||||
try {
|
||||
Device device =
|
||||
FCMDataHolder.getInstance().getDeviceManagementProviderService().getDevice(ctx.getDeviceId());
|
||||
FCMDataHolder.getInstance().getDeviceManagementProviderService().getDeviceWithTypeProperties(ctx.getDeviceId());
|
||||
this.sendWakeUpCall(ctx.getOperation().getCode(), device);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new PushNotificationExecutionFailedException("Error occurred while retrieving device information", e);
|
||||
|
||||
@ -1,87 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||
~ Version 2.0 (the "License"); you may not use this file except
|
||||
~ in compliance with the License.
|
||||
~ you may obtain a copy of the License at
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<artifactId>dynamic-client-registration</artifactId>
|
||||
<artifactId>device-mgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.dynamic.client.web.app.registration</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.http</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Dynamic client web app registration</name>
|
||||
<description>WSO2 Carbon - Dynamic Client Web-app Registration Service</description>
|
||||
<name>WSO2 Carbon - HTTP Based Push Notification Provider Implementation</name>
|
||||
<description>WSO2 Carbon - HTTP Based Push Notification Provider Implementation</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||
<Bundle-Description>Dynamic Client Web App Registration Bundle</Bundle-Description>
|
||||
<Private-Package>org.wso2.carbon.dynamic.client.web.app.registration.internal</Private-Package>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.dynamic.client.web.app.registration.internal,
|
||||
org.wso2.carbon.dynamic.client.web.app.registration.*
|
||||
</Export-Package>
|
||||
<Import-Package>
|
||||
javax.xml.bind.*,
|
||||
com.google.*,
|
||||
javax.net.ssl,
|
||||
javax.servlet,
|
||||
org.apache.axis2.context,
|
||||
org.apache.catalina,
|
||||
org.apache.catalina.core,
|
||||
org.apache.commons.*,
|
||||
org.apache.http,
|
||||
org.apache.http.*,
|
||||
org.osgi.framework,
|
||||
org.osgi.service.component,
|
||||
org.wso2.carbon.context,
|
||||
org.wso2.carbon.core,
|
||||
org.wso2.carbon.core.security,
|
||||
org.wso2.carbon.dynamic.client.*,
|
||||
org.wso2.carbon.registry.*,
|
||||
org.wso2.carbon.user.*,
|
||||
org.wso2.carbon.utils
|
||||
</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.governance</groupId>
|
||||
<artifactId>org.wso2.carbon.governance.api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.registry.api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.registry.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.commons.axiom.wso2</groupId>
|
||||
<artifactId>axiom</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.orbit.org.scannotation</groupId>
|
||||
<artifactId>scannotation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
@ -90,26 +74,6 @@
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity.framework</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.application.mgt</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.oauth</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity.framework</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.tomcat</groupId>
|
||||
<artifactId>tomcat</artifactId>
|
||||
@ -119,28 +83,65 @@
|
||||
<artifactId>tomcat-servlet-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>jsr311-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.user.core</artifactId>
|
||||
<groupId>org.apache.axis2.wso2</groupId>
|
||||
<artifactId>axis2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.registry.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.dynamic.client.registration</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<groupId>commons-lang.wso2</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json.wso2</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||
<Bundle-Description>MQTT Based Push Notification Provider Bundle</Bundle-Description>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.internal,
|
||||
org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.*
|
||||
</Export-Package>
|
||||
<Import-Package>
|
||||
org.apache.commons.logging,
|
||||
org.osgi.service.component,
|
||||
org.wso2.carbon.context,
|
||||
org.wso2.carbon.device.mgt.common.operation.mgt,
|
||||
org.wso2.carbon.device.mgt.common.push.notification,
|
||||
org.wso2.carbon.device.mgt.common,
|
||||
org.wso2.carbon.device.mgt.core.service,
|
||||
org.osgi.framework,
|
||||
org.wso2.carbon.device.mgt.core.operation.mgt,
|
||||
org.wso2.carbon.core,
|
||||
com.google.gson,
|
||||
org.apache.commons.httpclient.*
|
||||
</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -16,24 +16,22 @@
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.push.notification.provider.http;
|
||||
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
|
||||
|
||||
public class DeviceTypePluginDAOManager {
|
||||
public class HTTPBasedPushNotificationProvider implements PushNotificationProvider {
|
||||
|
||||
private DeviceTypePluginDAO deviceTypePluginDAO;
|
||||
private DeviceTypeDAOHandler deviceTypeDAOHandler;
|
||||
|
||||
public DeviceTypePluginDAOManager(String datasourceName, DeviceDAODefinition deviceDAODefinition) {
|
||||
deviceTypeDAOHandler = new DeviceTypeDAOHandler(datasourceName);
|
||||
deviceTypePluginDAO = new DeviceTypePluginDAO(deviceDAODefinition, deviceTypeDAOHandler);
|
||||
@Override
|
||||
public String getType() {
|
||||
return "HTTP";
|
||||
}
|
||||
|
||||
public DeviceTypePluginDAO getDeviceDAO() {
|
||||
return deviceTypePluginDAO;
|
||||
@Override
|
||||
public NotificationStrategy getNotificationStrategy(PushNotificationConfig config) {
|
||||
return new HTTPNotificationStrategy(config);
|
||||
}
|
||||
|
||||
public DeviceTypeDAOHandler getDeviceTypeDAOHandler() {
|
||||
return deviceTypeDAOHandler;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,94 @@
|
||||
package org.wso2.carbon.device.mgt.extensions.push.notification.provider.http;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.httpclient.HostConfiguration;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
public class HTTPMessageExecutor implements Runnable {
|
||||
|
||||
private String url;
|
||||
private String authorizationHeader;
|
||||
private String payload;
|
||||
private HostConfiguration hostConfiguration;
|
||||
private HttpClient httpClient;
|
||||
private static final String APPLIATION_JSON = "application/json";
|
||||
private static final String AUTHORIZATION_HEADER = "Authorization";
|
||||
private static final Log log = LogFactory.getLog(HTTPMessageExecutor.class);
|
||||
|
||||
public HTTPMessageExecutor(NotificationContext notificationContext, String authorizationHeader, String url
|
||||
, HostConfiguration hostConfiguration, HttpClient httpClient) {
|
||||
this.url = url;
|
||||
this.authorizationHeader = authorizationHeader;
|
||||
Gson gson = new Gson();
|
||||
this.payload = gson.toJson(notificationContext);
|
||||
this.hostConfiguration = hostConfiguration;
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getAuthorizationHeader() {
|
||||
return authorizationHeader;
|
||||
}
|
||||
|
||||
public void setAuthorizationHeader(String authorizationHeader) {
|
||||
this.authorizationHeader = authorizationHeader;
|
||||
}
|
||||
|
||||
public String getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(String payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public HttpClient getHttpClient() {
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
public void setHttpClient(HttpClient httpClient) {
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
EntityEnclosingMethod method = null;
|
||||
|
||||
try {
|
||||
method = new PostMethod(this.getUrl());
|
||||
method.setRequestEntity(new StringRequestEntity(this.getPayload(), APPLIATION_JSON, "UTF-8"));
|
||||
if (authorizationHeader != null && authorizationHeader.isEmpty()) {
|
||||
method.setRequestHeader(AUTHORIZATION_HEADER, authorizationHeader);
|
||||
}
|
||||
|
||||
this.getHttpClient().executeMethod(hostConfiguration, method);
|
||||
|
||||
} catch (UnknownHostException e) {
|
||||
log.error("Push Notification message dropped " + url, e);
|
||||
throw new InvalidConfigurationException("invalid host: url", e);
|
||||
} catch (Throwable e) {
|
||||
log.error("Push Notification message dropped ", e);
|
||||
throw new InvalidConfigurationException("Push Notification message dropped, " + e.getMessage(), e);
|
||||
} finally {
|
||||
if (method != null) {
|
||||
method.releaseConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.push.notification.provider.http;
|
||||
|
||||
import org.apache.commons.httpclient.HostConfiguration;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
public class HTTPNotificationStrategy implements NotificationStrategy {
|
||||
|
||||
private static final Log log = LogFactory.getLog(HTTPNotificationStrategy.class);
|
||||
private final PushNotificationConfig config;
|
||||
private static final String URL_PROPERTY = "url";
|
||||
private static final String AUTHORIZATION_HEADER_PROPERTY = "authorization";
|
||||
private String endpoint;
|
||||
private static ExecutorService executorService;
|
||||
private HttpClient httpClient = null;
|
||||
private HostConfiguration hostConfiguration;
|
||||
private String authorizationHeaderValue;
|
||||
private String uri;
|
||||
|
||||
public HTTPNotificationStrategy(PushNotificationConfig config) {
|
||||
this.config = config;
|
||||
if (this.config == null) {
|
||||
throw new InvalidConfigurationException("Properties Cannot be found");
|
||||
}
|
||||
endpoint = config.getProperties().get(URL_PROPERTY);
|
||||
if (endpoint == null || endpoint.isEmpty()) {
|
||||
throw new InvalidConfigurationException("Property - 'url' cannot be found");
|
||||
}
|
||||
try {
|
||||
this.uri = endpoint;
|
||||
URL url = new URL(endpoint);
|
||||
hostConfiguration = new HostConfiguration();
|
||||
hostConfiguration.setHost(url.getHost(), url.getPort(), url.getProtocol());
|
||||
this.authorizationHeaderValue = config.getProperties().get(AUTHORIZATION_HEADER_PROPERTY);
|
||||
executorService = Executors.newFixedThreadPool(1);
|
||||
httpClient = new HttpClient();
|
||||
} catch (MalformedURLException e) {
|
||||
throw new InvalidConfigurationException("Property - 'url' is malformed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
|
||||
try {
|
||||
executorService.submit(new HTTPMessageExecutor(ctx, authorizationHeaderValue, uri, hostConfiguration
|
||||
, httpClient));
|
||||
} catch (RejectedExecutionException e) {
|
||||
log.error("Failed to publish to external endpoint url: " + endpoint, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NotificationContext buildContext() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undeploy() {
|
||||
executorService.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PushNotificationConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.internal.HTTPPushNotificationServiceComponent" immediate="true"
|
||||
*/
|
||||
public class HTTPPushNotificationServiceComponent {
|
||||
|
||||
private static final Log log = LogFactory.getLog(HTTPPushNotificationServiceComponent.class);
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected void activate(ComponentContext componentContext) {
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Initializing HTTP based push notification provider implementation bundle");
|
||||
}
|
||||
//Do nothing
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("HTTP based push notification provider implementation bundle has been successfully " +
|
||||
"initialized");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while initializing HTTP based push notification provider " +
|
||||
"implementation bundle", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>device-mgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -21,8 +21,8 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||
@ -46,36 +46,52 @@ public class MQTTNotificationStrategy implements NotificationStrategy {
|
||||
private String mqttAdapterName;
|
||||
private static final Log log = LogFactory.getLog(MQTTNotificationStrategy.class);
|
||||
private final PushNotificationConfig config;
|
||||
private final String providerTenantDomain;
|
||||
private static final Object lockObj = new Object();
|
||||
|
||||
public MQTTNotificationStrategy(PushNotificationConfig config) {
|
||||
this.config = config;
|
||||
OutputEventAdapterConfiguration adapterConfig = new OutputEventAdapterConfiguration();
|
||||
adapterConfig.setType(MQTTAdapterConstants.MQTT_ADAPTER_TYPE);
|
||||
mqttAdapterName = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_NAME);
|
||||
adapterConfig.setName(mqttAdapterName);
|
||||
adapterConfig.setMessageFormat(MessageType.TEXT);
|
||||
|
||||
Map<String, String> configProperties = new HashMap<String, String>();
|
||||
String brokerUrl = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL);
|
||||
if (brokerUrl != null && !brokerUrl.isEmpty()) {
|
||||
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL, brokerUrl);
|
||||
if (config.getProperties() != null && config.getProperties().size() > 0) {
|
||||
String brokerUrl = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL);
|
||||
if (brokerUrl != null && !brokerUrl.isEmpty()) {
|
||||
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL, brokerUrl);
|
||||
}
|
||||
mqttAdapterName = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_NAME);
|
||||
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME,
|
||||
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME));
|
||||
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD,
|
||||
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD));
|
||||
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION,
|
||||
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION));
|
||||
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES,
|
||||
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES));
|
||||
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS,
|
||||
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS));
|
||||
} else {
|
||||
mqttAdapterName = "mqtt.adapter." + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()
|
||||
.toLowerCase();
|
||||
}
|
||||
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME,
|
||||
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME));
|
||||
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD,
|
||||
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD));
|
||||
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION,
|
||||
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION));
|
||||
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES,
|
||||
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES));
|
||||
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS,
|
||||
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS));
|
||||
adapterConfig.setName(mqttAdapterName);
|
||||
adapterConfig.setStaticProperties(configProperties);
|
||||
try {
|
||||
MQTTDataHolder.getInstance().getOutputEventAdapterService().create(adapterConfig);
|
||||
synchronized (lockObj) {
|
||||
try {
|
||||
MQTTDataHolder.getInstance().getOutputEventAdapterService().isPolled(mqttAdapterName);
|
||||
} catch (OutputEventAdapterException e) {
|
||||
//event adapter not created
|
||||
MQTTDataHolder.getInstance().getOutputEventAdapterService().create(adapterConfig);
|
||||
}
|
||||
}
|
||||
} catch (OutputEventAdapterException e) {
|
||||
throw new InvalidConfigurationException("Error occurred while initializing MQTT output event adapter", e);
|
||||
}
|
||||
providerTenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,42 +101,73 @@ public class MQTTNotificationStrategy implements NotificationStrategy {
|
||||
|
||||
@Override
|
||||
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
|
||||
String adapterName = mqttAdapterName;
|
||||
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
|
||||
if (!providerTenantDomain.equals(tenantDomain)) {
|
||||
//this is to handle the device type shared with all tenant mode.
|
||||
|
||||
adapterName = "mqtt.adapter." + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()
|
||||
.toLowerCase();
|
||||
try {
|
||||
MQTTDataHolder.getInstance().getOutputEventAdapterService().isPolled(adapterName);
|
||||
} catch (OutputEventAdapterException e) {
|
||||
//event adapter not created
|
||||
synchronized (lockObj) {
|
||||
OutputEventAdapterConfiguration adapterConfig = new OutputEventAdapterConfiguration();
|
||||
adapterConfig.setType(MQTTAdapterConstants.MQTT_ADAPTER_TYPE);
|
||||
adapterConfig.setMessageFormat(MessageType.TEXT);
|
||||
adapterConfig.setName(adapterName);
|
||||
Map<String, String> configProperties = new HashMap<String, String>();
|
||||
adapterConfig.setStaticProperties(configProperties);
|
||||
try {
|
||||
MQTTDataHolder.getInstance().getOutputEventAdapterService().create(adapterConfig);
|
||||
} catch (OutputEventAdapterException e1) {
|
||||
throw new PushNotificationExecutionFailedException
|
||||
("Error occurred while initializing MQTT output event adapter for shared tenant: "
|
||||
+ tenantDomain, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Operation operation = ctx.getOperation();
|
||||
Properties properties = operation.getProperties();
|
||||
if (properties != null && properties.get(MQTT_ADAPTER_TOPIC) != null) {
|
||||
Map<String, String> dynamicProperties = new HashMap<>();
|
||||
dynamicProperties.put("topic", (String) properties.get(MQTT_ADAPTER_TOPIC));
|
||||
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
|
||||
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(adapterName, dynamicProperties,
|
||||
operation.getPayLoad());
|
||||
} else {
|
||||
if (PolicyOperation.POLICY_OPERATION_CODE.equals(operation.getCode())) {
|
||||
PolicyOperation policyOperation = (PolicyOperation) operation;
|
||||
List<ProfileOperation> profileOperations = policyOperation.getProfileOperations();
|
||||
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
|
||||
String deviceType = ctx.getDeviceId().getType();
|
||||
String deviceId = ctx.getDeviceId().getId();
|
||||
for (ProfileOperation profileOperation : profileOperations) {
|
||||
Map<String, String> dynamicProperties = new HashMap<>();
|
||||
String topic = tenantDomain + "/"
|
||||
+ deviceType + "/" + deviceId + "/" + profileOperation.getType()
|
||||
+ deviceType + "/" + deviceId + "/operation/" + profileOperation.getType()
|
||||
.toString().toLowerCase() + "/" + profileOperation.getCode().toLowerCase();
|
||||
dynamicProperties.put("topic", topic);
|
||||
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
|
||||
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(adapterName, dynamicProperties,
|
||||
profileOperation.getPayLoad());
|
||||
}
|
||||
|
||||
} else {
|
||||
Map<String, String> dynamicProperties = new HashMap<>();
|
||||
String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/"
|
||||
+ ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType()
|
||||
.toString().toLowerCase() + "/" + operation.getCode();
|
||||
+ ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/operation/"
|
||||
+ operation.getType().toString().toLowerCase() + "/" + operation.getCode() + "/" + operation.getId();
|
||||
dynamicProperties.put("topic", topic);
|
||||
if (operation.getPayLoad() == null) {
|
||||
operation.setPayLoad("");
|
||||
Object payload;
|
||||
if ("command".equals(operation.getType().toString().toLowerCase())) {
|
||||
payload = operation.getCode();
|
||||
} else {
|
||||
payload = operation.getPayLoad();
|
||||
}
|
||||
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(mqttAdapterName, dynamicProperties,
|
||||
operation.getPayLoad());
|
||||
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(adapterName, dynamicProperties,
|
||||
payload);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>device-mgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.InvalidConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>carbon-devicemgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -34,10 +34,12 @@
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<modules>
|
||||
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.http</module>
|
||||
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm</module>
|
||||
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt</module>
|
||||
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp</module>
|
||||
<module>org.wso2.carbon.device.mgt.extensions.device.type.deployer</module>
|
||||
<module>org.wso2.carbon.device.mgt.extensions.pull.notification</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -66,10 +66,6 @@
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||
<artifactId>org.wso2.carbon.databridge.agent</artifactId>
|
||||
@ -118,6 +114,7 @@
|
||||
org.osgi.framework,
|
||||
org.osgi.service.component,
|
||||
org.apache.commons.logging.*,
|
||||
org.wso2.carbon.utils.multitenancy,
|
||||
org.wso2.carbon.context;version="${carbon.kernel.version.range}",
|
||||
org.wso2.carbon.utils;version="${carbon.kernel.version.range}",
|
||||
org.wso2.carbon.databridge.*;version="${carbon.analytics.common.version.range}",
|
||||
@ -126,14 +123,15 @@
|
||||
org.wso2.carbon.registry.indexing.*; version="${carbon.registry.imp.pkg.version.range}",
|
||||
org.json;version="${commons-json.version}",
|
||||
javax.xml.*,
|
||||
javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional,
|
||||
javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional,
|
||||
org.w3c.dom,
|
||||
org.wso2.carbon.base
|
||||
org.wso2.carbon.base,
|
||||
org.wso2.carbon.utils.multitenancy
|
||||
</Import-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
|
||||
@ -21,10 +21,12 @@ package org.wso2.carbon.device.mgt.analytics.data.publisher.service;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.databridge.agent.DataPublisher;
|
||||
import org.wso2.carbon.databridge.commons.utils.DataBridgeCommonsUtils;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.DeviceDataPublisher;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
/**
|
||||
* This is the implementation of Osgi Service which can be used to publish and retireved
|
||||
@ -39,23 +41,37 @@ public class EventsPublisherServiceImpl implements EventsPublisherService {
|
||||
* @param metaDataArray - meta data that needs to pushed
|
||||
* @param correlationDataArray - correlation data that needs to be pushed
|
||||
* @param payloadDataArray - payload data that needs to be pushed
|
||||
* @return
|
||||
* @return if success returns true
|
||||
* @throws DataPublisherConfigurationException
|
||||
*/
|
||||
@Override
|
||||
public boolean publishEvent(String streamName, String version, Object[] metaDataArray,
|
||||
Object[] correlationDataArray,
|
||||
Object[] payloadDataArray) throws DataPublisherConfigurationException {
|
||||
DataPublisher dataPublisher = DeviceDataPublisher.getInstance().getDataPublisher();
|
||||
if (dataPublisher != null) {
|
||||
String streamId = DataBridgeCommonsUtils.generateStreamId(streamName, version);
|
||||
return dataPublisher.tryPublish(streamId, System.currentTimeMillis(), metaDataArray, correlationDataArray,
|
||||
payloadDataArray);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
||||
if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
||||
if (metaDataArray == null || metaDataArray.length == 0) {
|
||||
throw new DataPublisherConfigurationException("meta data[0] should have the device Id field");
|
||||
} else {
|
||||
metaDataArray[0] = tenantDomain + "@" + metaDataArray[0];
|
||||
}
|
||||
}
|
||||
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
||||
.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
|
||||
try {
|
||||
DataPublisher dataPublisher = DeviceDataPublisher.getInstance().getDataPublisher();
|
||||
if (dataPublisher != null) {
|
||||
String streamId = DataBridgeCommonsUtils.generateStreamId(streamName, version);
|
||||
return dataPublisher.tryPublish(streamId, System.currentTimeMillis(), metaDataArray,
|
||||
correlationDataArray,
|
||||
payloadDataArray);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -22,7 +22,7 @@
|
||||
<parent>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>2.0.63-SNAPSHOT</version>
|
||||
<version>3.0.46-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@ -38,8 +38,8 @@
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
@ -167,6 +167,16 @@
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.analytics.data.publisher</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.extensions</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||
@ -280,34 +290,78 @@
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||
<artifactId>org.wso2.carbon.event.receiver.stub</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||
<artifactId>org.wso2.carbon.event.stream.stub</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.commons</groupId>
|
||||
<artifactId>org.wso2.carbon.application.mgt.stub</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics</groupId>
|
||||
<artifactId>org.wso2.carbon.analytics.api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics</groupId>
|
||||
<artifactId>org.wso2.carbon.analytics.datasource.commons</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.jwt.client.extension</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.registry.core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.registry</groupId>
|
||||
<artifactId>org.wso2.carbon.registry.resource</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.identity.framework</groupId>
|
||||
<artifactId>org.wso2.carbon.identity.user.store.count</artifactId>
|
||||
<version>${carbon.identity.framework.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics</groupId>
|
||||
<artifactId>org.wso2.carbon.analytics.datasource.commons</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics</groupId>
|
||||
<artifactId>org.wso2.carbon.analytics.api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics</groupId>
|
||||
<artifactId>org.wso2.carbon.analytics.dataservice.commons</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||
<artifactId>org.wso2.carbon.event.receiver.stub</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||
<artifactId>org.wso2.carbon.event.stream.stub</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||
<artifactId>org.wso2.carbon.event.publisher.stub</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||
<artifactId>org.wso2.carbon.event.stream.persistence.stub</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "OperationRequest", description = "Operation details together with deviceIdentifier")
|
||||
public class OperationRequest {
|
||||
|
||||
@ApiModelProperty(name = "deviceIdentifiers", value = "list of devices that needs to be verified against the user", required = true)
|
||||
List<String> deviceIdentifiers;
|
||||
@ApiModelProperty(name = "operation", value = "operation data", required = false)
|
||||
Operation operation;
|
||||
|
||||
public List<String> getDeviceIdentifiers() {
|
||||
return deviceIdentifiers;
|
||||
}
|
||||
|
||||
public void setDeviceIdentifiers(List<String> deviceIdentifiers) {
|
||||
this.deviceIdentifiers = deviceIdentifiers;
|
||||
}
|
||||
|
||||
public Operation getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
public void setOperation(Operation operation) {
|
||||
this.operation = operation;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* This hold the attribute definition.
|
||||
*/
|
||||
public class Attribute {
|
||||
|
||||
@ApiModelProperty(value = "Event Attribute Name")
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "Event Attribute Type")
|
||||
@JsonProperty("type")
|
||||
private AttributeType type;
|
||||
|
||||
public Attribute() {
|
||||
|
||||
}
|
||||
|
||||
public Attribute(String name, AttributeType attributeType) {
|
||||
this.name = name;
|
||||
this.type = attributeType;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public AttributeType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(AttributeType type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.beans.analytics;
|
||||
|
||||
/**
|
||||
* This hold the definition of the attribute type for the attributes.
|
||||
*/
|
||||
public enum AttributeType {
|
||||
STRING, LONG, BOOL, INT, FLOAT, DOUBLE;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user