Merge branch 'master' into uddhika-device-mgt

rm-11526
Uddhika Ishara 2 weeks ago
commit 663df92b42

15
.github/stale.yml vendored

@ -1,15 +0,0 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 10
# Don't close isssues or pulls
daysUntilClose: false
# Issues with these labels will never be considered stale
exemptLabels:
- Resolution/Postponed
# Label to use when marking an issue as stale
staleLabel: Resolution/Stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false

@ -1,28 +0,0 @@
image: charithag/docker-mvn-jdk8:latest
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
cache:
paths:
- .m2/repository/
- target/
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS clean install -Dmaven.test.skip=true
test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS test
deploy:
stage: deploy
script:
- mvn $MAVEN_CLI_OPTS deploy -Dmaven.test.skip=true
only:
- master@entgra/carbon-device-mgt
- kernel-4.6.x@entgra/carbon-device-mgt

@ -1,8 +0,0 @@
language: java
jdk:
- oraclejdk8
cache:
directories:
- .autoconf
- $HOME/.m2
script: mvn clean install

127
Jenkinsfile vendored

@ -0,0 +1,127 @@
pipeline {
agent {
label 'node-agent'
}
environment {
def isPendingUpstreamDependenciesExists = false
def triggeredViaPush = false
JAVA_HOME = '/usr/lib/jvm/java-11-openjdk'
PATH = "${JAVA_HOME}/bin:${env.PATH}"
}
stages {
stage('Initialize Variables') {
steps {
script {
// Define swaggerEndPoint as a global variable
swaggerEndPoint = {
def matcher = (env.CHANGE_URL =~ /^(?<host>https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b)(?<path>[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/)
matcher.find()
return matcher.group('host') + '/api/v1/repos' + matcher.group('path')
}
echo "Swagger Endpoint: ${swaggerEndPoint.call()}"
}
}
}
stage('Tool Versioning') {
steps {
script {
sh 'java -version'
sh 'node --version'
sh 'npm --version'
sh 'jq --version'
}
}
}
stage('Check Environment Variables') {
steps {
script {
echo "CHANGE_ID: ${env.CHANGE_ID}"
echo "CHANGE_URL: ${env.CHANGE_URL}"
echo "CHANGE_AUTHOR: ${env.CHANGE_AUTHOR}"
echo "CHANGE_BRANCH: ${env.CHANGE_BRANCH}"
echo "JAVA_HOME: ${JAVA_HOME}"
echo "PATH: ${PATH}"
}
}
}
stage('Fetch Pending Upstream Dependencies') {
steps {
script {
if (env.CHANGE_ID) {
def url = swaggerEndPoint.call()
echo "Fetching from URL: ${url}"
withCredentials([usernamePassword(credentialsId: 'entgra-gitea-credentials', passwordVariable: 'password', usernameVariable: 'username')]) {
def response = sh(script: """curl -X GET "${url}" -H 'accept: application/json' -u \$username:\$password""", returnStdout: true).trim()
echo "API Response: ${response}"
isPendingUpstreamDependenciesExists = sh(script: "echo '${response}' | jq 'contains({\"labels\": [{ \"name\": \"pending upstream\"}]})'", returnStdout: true).trim().toBoolean()
}
} else {
echo '[Jenkinsfile] Triggered via a push request.'
echo '[Jenkinsfile] Skipping dependency checking.'
triggeredViaPush = true
}
}
}
}
stage('Execute Test Suites') {
steps {
script {
if (!isPendingUpstreamDependenciesExists) {
echo '[Jenkinsfile] Pending upstream dependencies do not exist.'
echo '[Jenkinsfile] Entering testing phase.'
try {
checkout scm
withCredentials([usernamePassword(credentialsId: 'builder2-deployer-nexus', passwordVariable: 'password', usernameVariable: 'username')]) {
sh """/opt/scripts/run-test.sh -u \$username -p \$password"""
}
currentBuild.result = 'SUCCESS'
message = 'Tests approved'
} catch (error) {
currentBuild.result = 'FAILURE'
message = 'Tests cannot be approved'
}
} else {
echo '[Jenkinsfile] Pending upstream dependencies exist.'
echo '[Jenkinsfile] Entering waiting phase.'
currentBuild.result = 'NOT_BUILT'
message = 'PR waiting due to pending upstream dependencies'
}
}
}
}
stage('Report Job Status') {
steps {
script {
if (true) {
withCredentials([usernamePassword(credentialsId: 'entgra-gitea-credentials', passwordVariable: 'password', usernameVariable: 'username')]) {
def url = swaggerEndPoint.call() + '/reviews'
echo "[Jenkinsfile] Notifying pull request build status to ${url}"
def response = sh(script: """curl -X POST "${url}" -H 'accept: application/json' -H 'Content-Type: application/json' -u \$username:\$password -d '{ "body": "${message}" }'""", returnStdout: true).trim()
echo "API Response: ${response}"
}
}
def committerEmail = sh(
script: 'git --no-pager show -s --format=\'%ae\'',
returnStdout: true
).trim()
if (currentBuild.result == 'FAILURE') {
emailext(
subject: "${currentBuild.result}: Job ${env.JOB_NAME} [${env.BUILD_NUMBER}]",
body: 'Hi, Please find below.\n<pre>${BUILD_LOG_REGEX, regex="BUILD FAILURE", linesAfter=30, showTruncatedLines=false, escapeHtml=true}</pre>' + "Find more at : ${env.BUILD_URL}",
to: triggeredViaPush ? '$DEFAULT_RECIPIENTS' : committerEmail
)
}
}
}
}
}
}

@ -22,15 +22,15 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>grafana-mgt</artifactId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api</artifactId>
<packaging>war</packaging>
<name>Entgra - Grafana Proxy API</name>
<description>Entgra - Grafana Proxy API</description>
<name>Entgra Device Management - Grafana Proxy API</name>
<description>Entgra Device Management - Grafana Proxy API</description>
<url>http://entgra.io</url>
<build>

@ -22,15 +22,15 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>grafana-mgt</artifactId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common</artifactId>
<packaging>bundle</packaging>
<name>Entgra - Grafana API Handler Common</name>
<description>Entgra - Grafana API Handler Common</description>
<name>Entgra Device Management - Grafana API Handler Common</name>
<description>Entgra Device Management - Grafana API Handler Common</description>
<url>http://entgra.io</url>
<build>

@ -22,15 +22,15 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>grafana-mgt</artifactId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core</artifactId>
<packaging>bundle</packaging>
<name>Entgra - Grafana API Handler Core</name>
<description>Entgra - Grafana API Handler Core</description>
<name>Entgra Device Management - Grafana API Handler Core</name>
<description>Entgra Device Management - Grafana API Handler Core</description>
<url>http://entgra.io</url>
<build>
@ -83,7 +83,7 @@
<Import-Package>
com.google.common.cache;version="[32.1,33)";resolution:=optional,
com.google.gson;version="[2.9,3)",
io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common.exception;version="[5.0,6)",
io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common.exception;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.bean,
io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.config,
io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.config.xml.bean,
@ -96,16 +96,16 @@
io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.sql.query,
io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.sql.query.encoder,
io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.util,
io.entgra.device.mgt.core.application.mgt.common.exception;version="[5.0,6)",
io.entgra.device.mgt.core.application.mgt.core.config;version="[5.0,6)",
io.entgra.device.mgt.core.application.mgt.core.util;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.common.util;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.config;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.config.datasource;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.dao;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.report.mgt.config;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.report.mgt.dao.common;version="[5.0,6)",
io.entgra.device.mgt.core.application.mgt.common.exception;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.application.mgt.core.config;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.application.mgt.core.util;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.common.util;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.config;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.config.datasource;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.dao;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.report.mgt.config;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.report.mgt.dao.common;version="${io.entgra.device.mgt.core.version.range}",
javax.xml.bind;version="[0.0,1)",
javax.xml.bind.annotation;version="[0.0,1)",
javax.xml.parsers,

@ -22,14 +22,14 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>analytics-mgt</artifactId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>grafana-mgt</artifactId>
<packaging>pom</packaging>
<name>Entgra - Grafana API Handler Component</name>
<name>Entgra Device Management - Grafana API Handler Component</name>
<url>http://entgra.io</url>

@ -17,18 +17,19 @@
~ 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">
<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>io.entgra.device.mgt.core.parent</artifactId>
<artifactId>device-mgt-core</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>analytics-mgt</artifactId>
<packaging>pom</packaging>
<name>Entgra - Analytics Management Component</name>
<name>Entgra Device Management - Analytics Management Component</name>
<url>http://entgra.io</url>
<modules>

@ -20,13 +20,13 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.apimgt.analytics.extension</artifactId>
<packaging>bundle</packaging>
<name>Entgra - API mgt analytics extension</name>
<name>Entgra Device Management - API mgt analytics extension</name>
<url>https://entgra.io</url>
<dependencies>

@ -22,15 +22,15 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.apimgt.annotations</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Management Annotations</name>
<description>WSO2 Carbon - API Management Custom Annotation Module</description>
<name>Entgra Device Management - API Management Annotations</name>
<description>Entgra Device Management - API Management Custom Annotation Module</description>
<url>https://entgra.io</url>
<dependencies>

@ -21,14 +21,14 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.apimgt.application.extension.api</artifactId>
<packaging>war</packaging>
<name>WSO2 Carbon - API Application Management API</name>
<name>Entgra Device Management - API Application Management API</name>
<description>This module provides capability to create api manager application.</description>
<url>https://entgra.io</url>

@ -22,14 +22,14 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.apimgt.application.extension</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Application Management</name>
<name>Entgra Device Management - API Application Management</name>
<description>This module provides capability to create api manager application.</description>
<url>https://entgra.io</url>
@ -125,11 +125,11 @@
io.entgra.device.mgt.core.apimgt.application.extension.bean,
io.entgra.device.mgt.core.apimgt.application.extension.dto,
io.entgra.device.mgt.core.apimgt.application.extension.exception,
io.entgra.device.mgt.core.identity.jwt.client.extension;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension.dto;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension.exception;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension.service;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.identity.jwt.client.extension.dto;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.identity.jwt.client.extension.exception;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.identity.jwt.client.extension.service;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common;version="${io.entgra.device.mgt.core.version.range}",
org.apache.commons.lang;version="[2.6,3)",
org.apache.commons.logging;version="[1.2,2)",
org.json.simple;version="[1.1,2)",

@ -257,14 +257,12 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
MetadataManagementService metadataManagementService = APIApplicationManagerExtensionDataHolder.getInstance().getMetadataManagementService();
metadataManagementService.createMetadata(metaData);
return apiApplicationKey;
} catch (MetadataManagementException e) {
String msg = "Error occurred while creating meta data for meta key: " + applicationName;
} catch (MetadataKeyAlreadyExistsException e) {
String msg = "Since meta key:" + applicationName + " already exists, meta data creating process failed.";
log.error(msg, e);
throw new APIManagerException(msg, e);
} catch (MetadataKeyAlreadyExistsException e) {
String msg =
"Since meta key:" + applicationName + " already exists, meta data creating process " +
"failed.";
} catch (MetadataManagementException e) {
String msg = "Error occurred while creating meta data for meta key: " + applicationName;
log.error(msg, e);
throw new APIManagerException(msg, e);
} catch (BadRequestException e) {

@ -22,15 +22,15 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.apimgt.extension.rest.api</artifactId>
<packaging>bundle</packaging>
<name>Entgra - Device Management Extension for APIM REST API</name>
<description>Entgra - Device Management Extension for APIM REST API</description>
<name>Entgra Device Management - Device Management Extension for APIM REST API</name>
<description>Entgra Device Management - Device Management Extension for APIM REST API</description>
<url>https://entgra.io</url>
<dependencies>

@ -21,13 +21,13 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.apimgt.keymgt.extension.api</artifactId>
<packaging>war</packaging>
<name>WSO2 Carbon - API Key Management API</name>
<name>Entgra Device Management - API Key Management API</name>
<description>This module extends the API manager's key management apis.</description>
<url>https://entgra.io</url>

@ -21,14 +21,14 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.apimgt.keymgt.extension</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Key Management</name>
<name>Entgra Device Management - API Key Management</name>
<description>This module extends the API manager's key management.</description>
<url>https://entgra.io</url>
@ -88,10 +88,10 @@
io.entgra.device.mgt.core.apimgt.keymgt.extension,
io.entgra.device.mgt.core.apimgt.keymgt.extension.exception,
io.entgra.device.mgt.core.apimgt.keymgt.extension.service,
io.entgra.device.mgt.core.device.mgt.common.permission.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.config;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.config.keymanager;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.permission.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.permission.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.config;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.config.keymanager;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.permission.mgt;version="${io.entgra.device.mgt.core.version.range}",
javax.cache;version="[1.0,2)",
javax.net.ssl,okhttp3;version="[4.9,5)",
org.apache.commons.lang;version="[2.4,3)",

@ -22,15 +22,15 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.apimgt.webapp.publisher</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - API Management Webapp Publisher</name>
<description>WSO2 Carbon - API Management Webapp Publisher</description>
<name>Entgra Device Management - API Management Webapp Publisher</name>
<description>Entgra Device Management - API Management Webapp Publisher</description>
<url>https://entgra.io</url>
<dependencies>
@ -174,7 +174,7 @@
<Import-Package>
com.google.gson;version="[2.9,3)",
com.google.gson.reflect;version="[2.9,3)",
io.entgra.device.mgt.core.apimgt.annotations;version="[5.0,6)",
io.entgra.device.mgt.core.apimgt.annotations;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.apimgt.extension.rest.api.*,
io.entgra.device.mgt.core.apimgt.webapp.publisher.config,
io.entgra.device.mgt.core.apimgt.webapp.publisher.dto,

@ -196,10 +196,10 @@ public class APIPublisherStartupHandler implements ServerStartupObserver {
APIPublisherDataHolder.getInstance().setPermScopeMapping(permScopeMap);
log.info(Constants.PERM_SCOPE_MAPPING_META_KEY + "entry updated successfully");
} catch (MetadataManagementException e) {
log.error("Error encountered while updating permission scope mapping metadata with default scopes");
} catch (MetadataKeyAlreadyExistsException e) {
log.error("Metadata entry already exists for " + Constants.PERM_SCOPE_MAPPING_META_KEY);
} catch (MetadataManagementException e) {
log.error("Error encountered while updating permission scope mapping metadata with default scopes");
}
}
}

@ -21,15 +21,15 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.2.4-SNAPSHOT</version>
<artifactId>device-mgt-core</artifactId>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apimgt-extensions</artifactId>
<packaging>pom</packaging>
<name>WSO2 Carbon - API Management Extensions Component</name>
<name>Entgra Device Management - API Management Extensions Component</name>
<url>https://entgra.io</url>
<modules>

@ -21,15 +21,15 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>application-mgt</artifactId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.application.mgt.common</artifactId>
<packaging>bundle</packaging>
<name>Entgra - Application Management Common</name>
<description>Entgra - Application Management Common</description>
<name>Entgra Device Management - Application Management Common</name>
<description>Entgra Device Management - Application Management Common</description>
<url>https://entgra.io</url>
<build>
@ -61,10 +61,10 @@
io.entgra.device.mgt.core.application.mgt.common.exception,
io.entgra.device.mgt.core.application.mgt.common.response,
io.entgra.device.mgt.core.application.mgt.common.wrapper,
io.entgra.device.mgt.core.device.mgt.common;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.app.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.operation.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.common.exception;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.app.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.operation.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.common.exception;version="${io.entgra.device.mgt.core.version.range}",
io.swagger.annotations;version="[1.6,2)",
javax.validation.constraints;version="[2.0,3)",
javax.xml.bind.annotation;version="[0.0,1)"

@ -22,7 +22,7 @@ package io.entgra.device.mgt.core.application.mgt.common;
public class ReleaseVersionInfo {
private String version;
private String releaseType;
private String rating;
private double rating;
private String state;
private String uuid;
@ -38,11 +38,11 @@ public class ReleaseVersionInfo {
return releaseType;
}
public String getRating() {
public double getRating() {
return rating;
}
public void setRating(String rating) {
public void setRating(double rating) {
this.rating = rating;
}

@ -187,11 +187,14 @@ public interface SubscriptionManager {
* @param subType subscription type of the application.
* @param offsetValue offset value for get paginated request.
* @param limitValue limit value for get paginated request.
* @param uninstalled a Boolean flag indicating the filter criteria for retrieve subscription data
* @param searchName an optional search term to filter the results by name. If null or empty, no filtering by name is applied.
* @return {@link PaginationResult} pagination result of the category details.
* @throws {@link ApplicationManagementException} Exception of the application management
*/
PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID,
String subType) throws ApplicationManagementException;
String subType, Boolean uninstalled, String searchName)
throws ApplicationManagementException;
/**
* This method is responsible to provide application subscription data for given application release UUID.

@ -21,15 +21,15 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>application-mgt</artifactId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.application.mgt.core</artifactId>
<packaging>bundle</packaging>
<name>Entgra - Application Management Core</name>
<description>Entgra - Application Management Core</description>
<name>Entgra Device Management - Application Management Core</name>
<description>Entgra Device Management - Application Management Core</description>
<url>https://entgra.io</url>
<build>
@ -57,16 +57,16 @@
com.dd.plist;version="[1.21,2)",
com.google.gson;version="[2.9,3)",
com.google.gson.reflect;version="[2.9,3)",
io.entgra.device.mgt.core.apimgt.application.extension;version="[5.0,6)",
io.entgra.device.mgt.core.apimgt.application.extension.dto;version="[5.0,6)",
io.entgra.device.mgt.core.apimgt.application.extension.exception;version="[5.0,6)",
io.entgra.device.mgt.core.application.mgt.common;version="[5.0,6)",
io.entgra.device.mgt.core.application.mgt.common.config;version="[5.0,6)",
io.entgra.device.mgt.core.application.mgt.common.dto;version="[5.0,6)",
io.entgra.device.mgt.core.application.mgt.common.exception;version="[5.0,6)",
io.entgra.device.mgt.core.application.mgt.common.response;version="[5.0,6)",
io.entgra.device.mgt.core.application.mgt.common.services;version="[5.0,6)",
io.entgra.device.mgt.core.application.mgt.common.wrapper;version="[5.0,6)",
io.entgra.device.mgt.core.apimgt.application.extension;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.apimgt.application.extension.dto;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.apimgt.application.extension.exception;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.application.mgt.common;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.application.mgt.common.config;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.application.mgt.common.dto;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.application.mgt.common.exception;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.application.mgt.common.response;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.application.mgt.common.services;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.application.mgt.common.wrapper;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.application.mgt.core.config,
io.entgra.device.mgt.core.application.mgt.core.dao,
io.entgra.device.mgt.core.application.mgt.core.dao.common,
@ -80,25 +80,25 @@
io.entgra.device.mgt.core.application.mgt.core.dao.impl.visibility,
io.entgra.device.mgt.core.application.mgt.core.exception,
io.entgra.device.mgt.core.application.mgt.core.serviceprovider,
io.entgra.device.mgt.core.device.mgt.common;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.app.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.app.mgt.android;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.group.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.operation.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.permission.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.common.exception;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.common.util;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.dto;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.operation.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.permission.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.service;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.task.impl;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.util;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension.dto;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension.exception;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension.service;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.app.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.app.mgt.android;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.group.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.operation.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.permission.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.common.exception;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.common.util;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.dto;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.operation.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.permission.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.service;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.task.impl;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.util;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.identity.jwt.client.extension;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.identity.jwt.client.extension.dto;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.identity.jwt.client.extension.exception;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.identity.jwt.client.extension.service;version="${io.entgra.device.mgt.core.version.range}",
javax.annotation;version="[1.0,2)",
javax.naming,
javax.sql,

@ -198,14 +198,33 @@ public interface SubscriptionDAO {
* @param offsetValue offset value for get paginated result
* @param limitValue limit value for get paginated result
* @param appReleaseId id of the application release.
* @param uninstalled a Boolean flag indicating the filter criteria for getting users:
* - `true` to get only unsubscribed users,
* - `false` to get only subscribed users,
* - `null` to get all users regardless of their unsubscription status.
* @param searchName an optional search term to filter the results by username.
* @return subscribedUsers - list of app subscribed users.
* @throws {@link ApplicationManagementDAOException} if connections establishment fails.
*/
List<String> getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException;
int getSubscribedUserCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
/**
* This method is used to get the count of users who are subscribed or unsubscribed to a specific application release.
*
* @param appReleaseId the ID of the application release for which the user count is to be retrieved.
* @param tenantId the ID of the current tenant.
* @param uninstalled a Boolean flag indicating the filter criteria for counting users:
* - `true` to count only unsubscribed users,
* - `false` to count only subscribed users,
* - `null` to count all users regardless of their unsubscription status.
* @param searchName an optional search term to filter the results by username.
* @return the count of users based on the specified criteria.
* @throws ApplicationManagementDAOException if an error occurs while establishing a database connection or executing the query.
*/
int getSubscribedUserCount(int appReleaseId, int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException;
/**
* This method is used to get the details of roles
@ -214,14 +233,34 @@ public interface SubscriptionDAO {
* @param offsetValue offset value for get paginated request.
* @param limitValue limit value for get paginated request.
* @param appReleaseId id of the application release.
* @param uninstalled a Boolean flag indicating the filter criteria for getting roles:
* - `true` to get only unsubscribed roles,
* - `false` to get only subscribed roles,
* - `null` to get all roles regardless of their unsubscription status.
* @param searchName an optional search term to filter the results by role name.
* @return subscribedRoles - list of app subscribed roles.
* @throws {@link ApplicationManagementDAOException} if connections establishment fails.
*/
List<String> getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException;
int getSubscribedRoleCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
/**
* This method retrieves the count of roles subscribed to a given application release.
* The count can be filtered based on the unsubscription status.
*
* @param appReleaseId the ID of the application release for which the subscribed roles are counted.
* @param tenantId the ID of the current tenant.
* @param uninstalled a Boolean flag indicating the filter criteria for counting roles:
* - `true` to count only unsubscribed roles,
* - `false` to count only subscribed roles,
* - `null` to count all roles regardless of their unsubscription status.
* @param searchName an optional search term to filter the results by role name.
* @return the count of roles that match the specified criteria.
* @throws ApplicationManagementDAOException if there is an error while accessing the database or processing the request.
*/
int getSubscribedRoleCount(int appReleaseId, int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException;
/**
* This method is used to get the details of subscribed groups
@ -230,13 +269,33 @@ public interface SubscriptionDAO {
* @param offsetValue offset value for get paginated request.
* @param limitValue limit value for get paginated request.
* @param appReleaseId id of the application release.
* @param uninstalled a Boolean flag indicating the filter criteria for getting groups:
* - `true` to get only unsubscribed groups,
* - `false` to get only subscribed groups,
* - `null` to get all groups regardless of their unsubscription status.
* @param searchName an optional search term to filter the results by group name.
* @return subscribedGroups - list of app subscribed groups.
* @throws {@link ApplicationManagementDAOException} if connections establishment fails.
*/
List<String> getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId, int tenantId)
List<String> getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId, int tenantId,
Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException;
int getSubscribedGroupCount(int appReleaseId, int tenantId) throws ApplicationManagementDAOException;
/**
* This method is used to get the count of subscribed groups
*
* @param tenantId id of the current tenant
* @param appReleaseId id of the application release.
* @param uninstalled a Boolean flag indicating the filter criteria for counting groups:
* - `true` to count only unsubscribed groups,
* - `false` to count only subscribed groups,
* - `null` to count all groups regardless of their unsubscription status.
* @param searchName an optional search term to filter the results by group name.
* @return subscribedGroups - list of app subscribed groups.
* @throws {@link ApplicationManagementDAOException} if connections establishment fails.
*/
int getSubscribedGroupCount(int appReleaseId, int tenantId,Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException;
/**
* This method is used to get the details of subscribed groups

@ -2075,7 +2075,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
releaseVersionInfo = new ReleaseVersionInfo();
releaseVersionInfo.setVersion(resultSet.getString("VERSION"));
releaseVersionInfo.setReleaseType(resultSet.getString("RELEASE_TYPE"));
releaseVersionInfo.setRating(resultSet.getString("RATING"));
releaseVersionInfo.setRating(resultSet.getDouble("RATING"));
releaseVersionInfo.setState(resultSet.getString("CURRENT_STATE"));
releaseVersionInfo.setUuid(resultSet.getString("UUID"));
releaseVersionInfos.add(releaseVersionInfo);

@ -967,25 +967,37 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
@Override
public List<String> getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed users for " +
"given app release id.");
log.debug("Request received in DAO Layer to get subscribed/unsubscribed users for the given app release ID.");
}
try {
Connection conn = this.getDBConnection();
List<String> subscribedUsers = new ArrayList<>();
String sql = "SELECT "
+ "US.USER_NAME AS USER_NAME "
+ "FROM AP_USER_SUBSCRIPTION US "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ? OFFSET ?";
String sql = "SELECT US.USER_NAME AS USER_NAME " +
"FROM AP_USER_SUBSCRIPTION US " +
"WHERE AP_APP_RELEASE_ID = ? " +
"AND TENANT_ID = ? ";
if (uninstalled != null) {
sql += "AND UNSUBSCRIBED = ? ";
}
if (searchName != null && !searchName.trim().isEmpty()) {
sql += "AND US.USER_NAME LIKE ? ";
}
sql += "LIMIT ? OFFSET ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
stmt.setInt(3, limitValue);
stmt.setInt(4, offsetValue);
int index = 1;
stmt.setInt(index++, appReleaseId);
stmt.setInt(index++, tenantId);
if (uninstalled != null) {
stmt.setBoolean(index++, uninstalled);
}
if (searchName != null && !searchName.trim().isEmpty()) {
stmt.setString(index++, "%" + searchName + "%");
}
stmt.setInt(index++, limitValue);
stmt.setInt(index, offsetValue);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
subscribedUsers.add(rs.getString("USER_NAME"));
@ -994,50 +1006,62 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
return subscribedUsers;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get already " +
"subscribed users for given app release id.";
String msg = "Error occurred while obtaining the DB connection to get subscribed/unsubscribed users for the " +
"given app release ID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting subscribed users for given app release id.";
String msg = "SQL Error occurred while getting subscribed/unsubscribed users for the given app release ID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public int getSubscribedUserCount(int appReleaseId, int tenantId)
public int getSubscribedUserCount(int appReleaseId, int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed users for " +
log.debug("Request received in DAO Layer to get already subscribed/unsubscribed users for " +
"given app release id.");
}
try {
Connection conn = this.getDBConnection();
String sql = "SELECT "
+ "COUNT(US.USER_NAME) AS USER_NAME "
+ "FROM AP_USER_SUBSCRIPTION US "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ?";
String sql = "SELECT COUNT(US.USER_NAME) AS USER_COUNT " +
"FROM AP_USER_SUBSCRIPTION US " +
"WHERE AP_APP_RELEASE_ID = ? " +
"AND TENANT_ID = ?";
if (uninstalled != null) {
sql += " AND UNSUBSCRIBED = ?";
}
if (searchName != null && !searchName.trim().isEmpty()) {
sql += " AND US.USER_NAME LIKE ?";
}
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
int index = 1;
stmt.setInt(index++, appReleaseId);
stmt.setInt(index++, tenantId);
if (uninstalled != null) {
stmt.setBoolean(index++, uninstalled);
}
if (searchName != null && !searchName.trim().isEmpty()) {
stmt.setString(index++, "%" + searchName + "%");
}
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return rs.getInt("USER_NAME");
return rs.getInt("USER_COUNT");
}
}
return 0;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get already " +
"subscribed users count for given app release id.";
"subscribed/unsubscribed users count for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting subscribed users for given app release id.";
String msg = "SQL Error occurred while getting subscribed/unsubscribed users count for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
@ -1151,10 +1175,10 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
@Override
public List<String> getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed roles for " +
log.debug("Request received in DAO Layer to get already subscribed/unsubscribed roles for " +
"given app release id.");
}
try {
@ -1163,13 +1187,28 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
String sql = "SELECT "
+ "RS.ROLE_NAME AS ROLE "
+ "FROM AP_ROLE_SUBSCRIPTION RS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ? OFFSET ?";
+ "WHERE AP_APP_RELEASE_ID = ? "
+ "AND TENANT_ID = ?";
if (uninstalled != null) {
sql += " AND UNSUBSCRIBED = ?";
}
if (searchName != null && !searchName.trim().isEmpty()) {
sql += " AND RS.ROLE_NAME LIKE ?";
}
sql += " LIMIT ? OFFSET ?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, appReleaseId);
ps.setInt(2, tenantId);
ps.setInt(3, limitValue);
ps.setInt(4, offsetValue);
int paramIndex = 1;
ps.setInt(paramIndex++, appReleaseId);
ps.setInt(paramIndex++, tenantId);
if (uninstalled != null) {
ps.setBoolean(paramIndex++, uninstalled);
}
if (searchName != null && !searchName.trim().isEmpty()) {
ps.setString(paramIndex++, "%" + searchName + "%");
}
ps.setInt(paramIndex++, limitValue);
ps.setInt(paramIndex, offsetValue);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
subscribedRoles.add(rs.getString("ROLE"));
@ -1179,49 +1218,61 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get already " +
"subscribed roles for given app release id.";
"subscribed/unsubscribed roles for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting subscribed roles for given app release id.";
String msg = "SQL Error occurred while getting subscribed/unsubscribed roles for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public int getSubscribedRoleCount(int appReleaseId, int tenantId)
public int getSubscribedRoleCount(int appReleaseId, int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed roles for " +
log.debug("Request received in DAO Layer to get already subscribed/unsubscribed roles for " +
"given app release id.");
}
try {
Connection conn = this.getDBConnection();
String sql = "SELECT "
+ "COUNT(RS.ROLE_NAME) AS ROLE_NAME "
+ "COUNT(RS.ROLE_NAME) AS ROLE_COUNT "
+ "FROM AP_ROLE_SUBSCRIPTION RS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ?";
+ "WHERE AP_APP_RELEASE_ID = ? "
+ "AND TENANT_ID = ?";
if (uninstalled != null) {
sql += " AND UNSUBSCRIBED = ?";
}
if (searchName != null && !searchName.trim().isEmpty()) {
sql += " AND RS.ROLE_NAME LIKE ?";
}
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
int paramIndex = 1;
stmt.setInt(paramIndex++, appReleaseId);
stmt.setInt(paramIndex++, tenantId);
if (uninstalled != null) {
stmt.setBoolean(paramIndex++, uninstalled);
}
if (searchName != null && !searchName.trim().isEmpty()) {
stmt.setString(paramIndex++, "%" + searchName + "%");
}
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return rs.getInt("ROLE_NAME");
}
return rs.getInt("ROLE_COUNT");
}
return 0;
}
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get already " +
"subscribed roles count for given app release id.";
"subscribed/unsubscribed roles count for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting subscribed roles for given app release id.";
String msg = "SQL Error occurred while getting subscribed/unsubscribed roles count for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
@ -1269,25 +1320,37 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
@Override
public List<String> getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed groups for " +
log.debug("Request received in DAO Layer to get already subscribed/unsubscribed groups for " +
"given app release id.");
}
try {
Connection conn = this.getDBConnection();
List<String> subscribedGroups = new ArrayList<>();
String sql = "SELECT "
+ "GS.GROUP_NAME AS APP_GROUPS "
+ "FROM AP_GROUP_SUBSCRIPTION GS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ? OFFSET ?";
String sql = "SELECT GS.GROUP_NAME AS APP_GROUPS " +
"FROM AP_GROUP_SUBSCRIPTION GS " +
"WHERE AP_APP_RELEASE_ID = ? AND TENANT_ID = ?";
if (uninstalled != null) {
sql += " AND UNSUBSCRIBED = ?";
}
if (searchName != null && !searchName.trim().isEmpty()) {
sql += " AND GS.GROUP_NAME LIKE ?";
}
sql += " LIMIT ? OFFSET ?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, appReleaseId);
ps.setInt(2, tenantId);
ps.setInt(3, limitValue);
ps.setInt(4, offsetValue);
int paramIndex = 1;
ps.setInt(paramIndex++, appReleaseId);
ps.setInt(paramIndex++, tenantId);
if (uninstalled != null) {
ps.setBoolean(paramIndex++, uninstalled);
}
if (searchName != null && !searchName.trim().isEmpty()) {
ps.setString(paramIndex++, "%" + searchName + "%");
}
ps.setInt(paramIndex++, limitValue);
ps.setInt(paramIndex, offsetValue);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
subscribedGroups.add(rs.getString("APP_GROUPS"));
@ -1297,11 +1360,11 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get already " +
"subscribed groups for given app release id.";
"subscribed/unsubscribed groups for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting subscribed groups for given " +
String msg = "SQL Error occurred while getting subscribed/unsubscribed groups for given " +
"app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
@ -1309,24 +1372,34 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
@Override
public int getSubscribedGroupCount(int appReleaseId, int tenantId)
public int getSubscribedGroupCount(int appReleaseId, int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed groups for " +
log.debug("Request received in DAO Layer to get the count of subscribed/unsubscribed groups for " +
"given app release id.");
}
try {
Connection conn = this.getDBConnection();
String sql = "SELECT "
+ "COUNT(GS.GROUP_NAME) AS APP_GROUPS_COUNT "
+ "FROM AP_GROUP_SUBSCRIPTION GS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ?";
String sql = "SELECT COUNT(GS.GROUP_NAME) AS APP_GROUPS_COUNT " +
"FROM AP_GROUP_SUBSCRIPTION GS " +
"WHERE AP_APP_RELEASE_ID = ? AND TENANT_ID = ?";
if (uninstalled != null) {
sql += " AND UNSUBSCRIBED = ?";
}
if (searchName != null && !searchName.trim().isEmpty()) {
sql += " AND GS.GROUP_NAME LIKE ?";
}
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
int paramIndex = 1;
stmt.setInt(paramIndex++, appReleaseId);
stmt.setInt(paramIndex++, tenantId);
if (uninstalled != null) {
stmt.setBoolean(paramIndex++, uninstalled);
}
if (searchName != null && !searchName.trim().isEmpty()) {
stmt.setString(paramIndex++, "%" + searchName + "%");
}
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return rs.getInt("APP_GROUPS_COUNT");
@ -1335,12 +1408,13 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
return 0;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get already " +
"subscribed groups count for given app release id.";
String msg = "Error occurred while obtaining the DB connection to get the count of " +
"subscribed/unsubscribed groups for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting subscribed groups for given app release id.";
String msg = "SQL Error occurred while getting the count of subscribed/unsubscribed groups for given " +
"app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}

@ -43,10 +43,10 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
@Override
public List<String> getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed users for " +
log.debug("Request received in DAO Layer to get already subscribed/unsubscribed users for " +
"given app release id.");
}
try {
@ -55,13 +55,28 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
String sql = "SELECT "
+ "US.USER_NAME AS USER "
+ "FROM AP_USER_SUBSCRIPTION US "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY US.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "WHERE AP_APP_RELEASE_ID = ? "
+ "AND TENANT_ID = ? ";
if (uninstalled != null) {
sql += "AND UNSUBSCRIBED = ? ";
}
if (searchName != null && !searchName.trim().isEmpty()) {
sql += "AND US.USER_NAME LIKE ? ";
}
sql += "ORDER BY US.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
stmt.setInt(3, offsetValue);
stmt.setInt(4, limitValue);
int index = 1;
stmt.setInt(index++, appReleaseId);
stmt.setInt(index++, tenantId);
if (uninstalled != null) {
stmt.setBoolean(index++, uninstalled);
}
if (searchName != null && !searchName.trim().isEmpty()) {
stmt.setString(index++, "%" + searchName + "%");
}
stmt.setInt(index++, offsetValue);
stmt.setInt(index, limitValue);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
subscribedUsers.add(rs.getString("USER"));
@ -71,11 +86,11 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get already " +
"subscribed users for given app release id.";
"subscribed/unsubscribed users for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting subscribed users for given app release id.";
String msg = "SQL Error occurred while getting subscribed/unsubscribed users for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
@ -83,10 +98,10 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
@Override
public List<String> getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed roles for " +
log.debug("Request received in DAO Layer to get already subscribed/unsubscribed roles for " +
"given app release id.");
}
try {
@ -95,13 +110,27 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
String sql = "SELECT "
+ "RS.ROLE_NAME AS ROLE "
+ "FROM AP_ROLE_SUBSCRIPTION RS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY RS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "WHERE AP_APP_RELEASE_ID = ? "
+ "AND TENANT_ID = ? ";
if (uninstalled != null) {
sql += "AND UNSUBSCRIBED = ? ";
}
if (searchName != null && !searchName.trim().isEmpty()) {
sql += "AND RS.ROLE_NAME LIKE ? ";
}
sql += "ORDER BY RS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, appReleaseId);
ps.setInt(2, tenantId);
ps.setInt(3, offsetValue);
ps.setInt(4, limitValue);
int paramIndex = 1;
ps.setInt(paramIndex++, appReleaseId);
ps.setInt(paramIndex++, tenantId);
if (uninstalled != null) {
ps.setBoolean(paramIndex++, uninstalled);
}
if (searchName != null && !searchName.trim().isEmpty()) {
ps.setString(paramIndex++, "%" + searchName + "%");
}
ps.setInt(paramIndex++, offsetValue);
ps.setInt(paramIndex, limitValue);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
subscribedRoles.add(rs.getString("ROLE"));
@ -111,11 +140,11 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get already " +
"subscribed roles for given app release id.";
"subscribed/unsubscribed roles for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting subscribed roles for given app release id.";
String msg = "SQL Error occurred while getting subscribed/unsubscribed roles for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
@ -123,11 +152,10 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
@Override
public List<String> getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed groups for " +
"given app release id.");
log.debug("Request received in DAO Layer to get subscribed/unsubscribed groups for the given app release ID.");
}
try {
Connection conn = this.getDBConnection();
@ -135,13 +163,26 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
String sql = "SELECT "
+ "GS.GROUP_NAME AS GROUPS "
+ "FROM AP_GROUP_SUBSCRIPTION GS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY GS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "WHERE AP_APP_RELEASE_ID = ? AND TENANT_ID = ?";
if (uninstalled != null) {
sql += " AND UNSUBSCRIBED = ?";
}
if (searchName != null && !searchName.trim().isEmpty()) {
sql += " AND GS.GROUP_NAME LIKE ?";
}
sql += " ORDER BY GS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, appReleaseId);
ps.setInt(2, tenantId);
ps.setInt(3, offsetValue);
ps.setInt(4, limitValue);
int paramIndex = 1;
ps.setInt(paramIndex++, appReleaseId);
ps.setInt(paramIndex++, tenantId);
if (uninstalled != null) {
ps.setBoolean(paramIndex++, uninstalled);
}
if (searchName != null && !searchName.trim().isEmpty()) {
ps.setString(paramIndex++, "%" + searchName + "%");
}
ps.setInt(paramIndex++, offsetValue);
ps.setInt(paramIndex, limitValue);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
subscribedGroups.add(rs.getString("GROUPS"));
@ -150,13 +191,12 @@ public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
return subscribedGroups;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get already " +
"subscribed groups for given app release id.";
String msg = "Error occurred while obtaining the DB connection to get subscribed/unsubscribed groups" +
" for the given app release ID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting subscribed groups for given " +
"app release id.";
String msg = "SQL Error occurred while getting subscribed/unsubscribed groups for the given app release ID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}

@ -39,10 +39,10 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
@Override
public List<String> getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed users for " +
log.debug("Request received in DAO Layer to get already subscribed/unsubscribed users for " +
"given app release id.");
}
try {
@ -51,13 +51,28 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
String sql = "SELECT "
+ "US.USER_NAME AS USER_NAME "
+ "FROM AP_USER_SUBSCRIPTION US "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY US.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "WHERE AP_APP_RELEASE_ID = ? "
+ "AND TENANT_ID = ? ";
if (uninstalled != null) {
sql += "AND UNSUBSCRIBED = ? ";
}
if (searchName != null && !searchName.trim().isEmpty()) {
sql += "AND US.USER_NAME LIKE ? ";
}
sql += "ORDER BY US.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
stmt.setInt(3, offsetValue);
stmt.setInt(4, limitValue);
int index = 1;
stmt.setInt(index++, appReleaseId);
stmt.setInt(index++, tenantId);
if (uninstalled != null) {
stmt.setBoolean(index++, uninstalled);
}
if (searchName != null && !searchName.trim().isEmpty()) {
stmt.setString(index++, "%" + searchName + "%");
}
stmt.setInt(index++, offsetValue);
stmt.setInt(index, limitValue);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
subscribedUsers.add(rs.getString("USER_NAME"));
@ -67,11 +82,11 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get already " +
"subscribed users for given app release id.";
"subscribed/unsubscribed users for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting subscribed users for given app release id.";
String msg = "SQL Error occurred while getting subscribed/unsubscribed users for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
@ -79,10 +94,10 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
@Override
public List<String> getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed roles for " +
log.debug("Request received in DAO Layer to get already subscribed/unsubscribed roles for " +
"given app release id.");
}
try {
@ -91,13 +106,29 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
String sql = "SELECT "
+ "RS.ROLE_NAME AS ROLE "
+ "FROM AP_ROLE_SUBSCRIPTION RS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY RS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "WHERE AP_APP_RELEASE_ID = ? "
+ "AND TENANT_ID = ? ";
if (uninstalled != null) {
sql += "AND UNSUBSCRIBED = ? ";
}
if (searchName != null && !searchName.trim().isEmpty()) {
sql += "AND RS.ROLE_NAME LIKE ? ";
}
sql += "ORDER BY RS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, appReleaseId);
ps.setInt(2, tenantId);
ps.setInt(3, offsetValue);
ps.setInt(4, limitValue);
int paramIndex = 1;
ps.setInt(paramIndex++, appReleaseId);
ps.setInt(paramIndex++, tenantId);
if (uninstalled != null) {
ps.setBoolean(paramIndex++, uninstalled);
}
if (searchName != null && !searchName.trim().isEmpty()) {
ps.setString(paramIndex++, "%" + searchName + "%");
}
ps.setInt(paramIndex++, offsetValue);
ps.setInt(paramIndex, limitValue);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
subscribedRoles.add(rs.getString("ROLE"));
@ -107,11 +138,11 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get already " +
"subscribed roles for given app release id.";
"subscribed/unsubscribed roles for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting subscribed roles for given app release id.";
String msg = "SQL Error occurred while getting subscribed/unsubscribed roles for given app release id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
@ -119,11 +150,10 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
@Override
public List<String> getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId,
int tenantId)
int tenantId, Boolean uninstalled, String searchName)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed groups for " +
"given app release id.");
log.debug("Request received in DAO Layer to get subscribed/unsubscribed groups for the given app release ID.");
}
try {
Connection conn = this.getDBConnection();
@ -131,13 +161,26 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
String sql = "SELECT "
+ "GS.GROUP_NAME AS GROUPS "
+ "FROM AP_GROUP_SUBSCRIPTION GS "
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? ORDER BY GS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
+ "WHERE AP_APP_RELEASE_ID = ? AND TENANT_ID = ?";
if (uninstalled != null) {
sql += " AND UNSUBSCRIBED = ?";
}
if (searchName != null && !searchName.trim().isEmpty()) {
sql += " AND GS.GROUP_NAME LIKE ?";
}
sql += " ORDER BY GS.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, appReleaseId);
ps.setInt(2, tenantId);
ps.setInt(3, offsetValue);
ps.setInt(4, limitValue);
int paramIndex = 1;
ps.setInt(paramIndex++, appReleaseId);
ps.setInt(paramIndex++, tenantId);
if (uninstalled != null) {
ps.setBoolean(paramIndex++, uninstalled);
}
if (searchName != null && !searchName.trim().isEmpty()) {
ps.setString(paramIndex++, "%" + searchName + "%");
}
ps.setInt(paramIndex++, offsetValue);
ps.setInt(paramIndex, limitValue);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
subscribedGroups.add(rs.getString("GROUPS"));
@ -146,13 +189,11 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
return subscribedGroups;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get already " +
"subscribed groups for given app release id.";
String msg = "Error occurred while obtaining the DB connection to get subscribed/unsubscribed groups for the given app release ID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting subscribed groups for given " +
"app release id.";
String msg = "SQL Error occurred while getting subscribed/unsubscribed groups for the given app release ID.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}

@ -1498,7 +1498,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID, String subType)
public PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID, String subType,
Boolean uninstalled, String searchName)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -1513,20 +1514,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
subscriptionList = subscriptionDAO
.getAppSubscribedUsers(offsetValue, limitValue, applicationReleaseId, tenantId);
count = subscriptionDAO.getSubscribedUserCount(applicationReleaseId, tenantId);
} else {
if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
.getAppSubscribedUsers(offsetValue, limitValue, applicationReleaseId, tenantId, uninstalled, searchName);
count = subscriptionDAO.getSubscribedUserCount(applicationReleaseId, tenantId, uninstalled, searchName);
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
subscriptionList = subscriptionDAO
.getAppSubscribedRoles(offsetValue, limitValue, applicationReleaseId, tenantId);
count = subscriptionDAO.getSubscribedRoleCount(applicationReleaseId, tenantId);
} else {
if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
.getAppSubscribedRoles(offsetValue, limitValue, applicationReleaseId, tenantId, uninstalled, searchName);
count = subscriptionDAO.getSubscribedRoleCount(applicationReleaseId, tenantId, uninstalled, searchName);
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
subscriptionList = subscriptionDAO
.getAppSubscribedGroups(offsetValue, limitValue, applicationReleaseId, tenantId);
count = subscriptionDAO.getSubscribedGroupCount(applicationReleaseId, tenantId);
}
}
.getAppSubscribedGroups(offsetValue, limitValue, applicationReleaseId, tenantId, uninstalled, searchName);
count = subscriptionDAO.getSubscribedGroupCount(applicationReleaseId, tenantId, uninstalled, searchName);
}
paginationResult.setData(subscriptionList);

@ -48,6 +48,8 @@ import org.apache.commons.validator.routines.UrlValidator;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import javax.ws.rs.core.Response;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@ -503,31 +505,29 @@ public class APIUtil {
applicationRelease.setSupportedOsVersions(applicationReleaseDTO.getSupportedOsVersions());
applicationRelease.setRating(applicationReleaseDTO.getRating());
applicationRelease.setIconPath(
basePath + Constants.ICON_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO.getIconName());
if (!StringUtils.isEmpty(applicationReleaseDTO.getBannerName())){
basePath + Constants.ICON_ARTIFACT + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getIconName(), StandardCharsets.UTF_8));
if (!StringUtils.isEmpty(applicationReleaseDTO.getBannerName())) {
applicationRelease.setBannerPath(
basePath + Constants.BANNER_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO
.getBannerName());
basePath + Constants.BANNER_ARTIFACT + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getBannerName(), StandardCharsets.UTF_8));
}
applicationRelease.setInstallerPath(constructInstallerPath(applicationReleaseDTO.getInstallerName(),
applicationReleaseDTO.getAppHashValue()));
applicationRelease.setInstallerPath(
constructInstallerPath(applicationReleaseDTO.getInstallerName(), applicationReleaseDTO.getAppHashValue()));
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName1())) {
screenshotPaths
.add(basePath + Constants.SCREENSHOT_ARTIFACT + 1 + Constants.FORWARD_SLASH + applicationReleaseDTO
.getScreenshotName1());
screenshotPaths.add(
basePath + Constants.SCREENSHOT_ARTIFACT + 1 + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getScreenshotName1(), StandardCharsets.UTF_8));
}
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName2())) {
screenshotPaths
.add(basePath + Constants.SCREENSHOT_ARTIFACT + 2 + Constants.FORWARD_SLASH + applicationReleaseDTO
.getScreenshotName2());
screenshotPaths.add(
basePath + Constants.SCREENSHOT_ARTIFACT + 2 + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getScreenshotName2(), StandardCharsets.UTF_8));
}
if (!StringUtils.isEmpty(applicationReleaseDTO.getScreenshotName3())) {
screenshotPaths
.add(basePath + Constants.SCREENSHOT_ARTIFACT + 3 + Constants.FORWARD_SLASH + applicationReleaseDTO
.getScreenshotName3());
screenshotPaths.add(
basePath + Constants.SCREENSHOT_ARTIFACT + 3 + Constants.FILE_NAME_PARAM +
URLEncoder.encode(applicationReleaseDTO.getScreenshotName3(), StandardCharsets.UTF_8));
}
applicationRelease.setScreenshots(screenshotPaths);
return applicationRelease;
@ -543,9 +543,12 @@ public class APIUtil {
public static String constructInstallerPath(String installerName, String appHash) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
UrlValidator urlValidator = new UrlValidator();
String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH + appHash + Constants.FORWARD_SLASH;
return urlValidator.isValid(installerName) ? installerName
: basePath + Constants.APP_ARTIFACT + Constants.FORWARD_SLASH + installerName;
String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH +
appHash + Constants.FORWARD_SLASH;
return urlValidator.isValid(installerName)
? installerName
: basePath + Constants.APP_ARTIFACT + Constants.FILE_NAME_PARAM +
URLEncoder.encode(installerName, StandardCharsets.UTF_8);
}
public static String getArtifactDownloadBaseURL() throws ApplicationManagementException {

@ -140,6 +140,11 @@ public class Constants {
public static final String DB_TYPE_POSTGRESQL = "PostgreSQL";
}
/**
* Query parameter for specifying the filename in the App artifact URL.
*/
public static final String FILE_NAME_PARAM = "?fileName=";
/**
* Directory name of the icon artifact that are saved in the file system.
*/

@ -39,6 +39,7 @@ import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil;
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException;
import io.entgra.device.mgt.core.device.mgt.core.dto.GroupDetailsDTO;
@ -48,6 +49,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@ -119,13 +121,12 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr
} else {
groupDetailsDTO = groupManagementProviderService.getGroupDetailsWithDevices(subscriptionInfo.getIdentifier(),
applicationDTO.getDeviceTypeId(), deviceSubscriptionFilterCriteria.getOwner(), deviceSubscriptionFilterCriteria.getName(),
deviceSubscriptionFilterCriteria.getDeviceStatus(), offset, limit);
List<Integer> paginatedDeviceIdsOwnByGroup = groupDetailsDTO.getDeviceIds();
deviceSubscriptionFilterCriteria.getDeviceStatus(), -1, -1);
List<Integer> nonPaginatedDeviceIdsOwnByGroup = groupDetailsDTO.getDeviceIds();
deviceSubscriptionDTOS = subscriptionDAO.getSubscriptionDetailsByDeviceIds(applicationReleaseDTO.getId(),
isUnsubscribe, tenantId, paginatedDeviceIdsOwnByGroup, dbSubscriptionStatus,
isUnsubscribe, tenantId, nonPaginatedDeviceIdsOwnByGroup, dbSubscriptionStatus,
null, deviceSubscriptionFilterCriteria.getTriggeredBy(), -1, -1);
}
deviceCount = SubscriptionManagementHelperUtil.getTotalDeviceSubscriptionCount(deviceSubscriptionDTOS,
subscriptionInfo.getDeviceSubscriptionFilterCriteria(), applicationDTO.getDeviceTypeId());
@ -146,7 +147,6 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
@ -193,12 +193,14 @@ public class GroupBasedSubscriptionManagementHelperServiceImpl implements Subscr
log.error(msg);
throw new NotFoundException(msg);
}
List<Device> devices = HelperUtil.getGroupManagementProviderService().
getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), false);
List<String> deviceStatuses = Arrays.asList(EnrolmentInfo.Status.ACTIVE.name(),
EnrolmentInfo.Status.INACTIVE.name(), EnrolmentInfo.Status.UNREACHABLE.name());
List<Device> devices = HelperUtil.getGroupManagementProviderService().getAllDevicesOfGroup(subscriptionInfo.getIdentifier(), deviceStatuses, false);
List<Integer> deviceIdsOwnByGroup = devices.stream().map(Device::getId).collect(Collectors.toList());
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.
getSubscriptionStatistic(deviceIdsOwnByGroup, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
int allDeviceCount = HelperUtil.getGroupManagementProviderService().getDeviceCount(subscriptionInfo.getIdentifier());
SubscriptionStatisticDTO subscriptionStatisticDTO = subscriptionDAO.getSubscriptionStatistic
(deviceIdsOwnByGroup, isUnsubscribe, tenantId, applicationReleaseDTO.getId());
int allDeviceCount = HelperUtil.getGroupManagementProviderService().getDeviceCountWithGroup(subscriptionInfo.getIdentifier(),
applicationDAO.getApplication(applicationReleaseDTO.getUuid(), tenantId).getDeviceTypeId());
return SubscriptionManagementHelperUtil.getSubscriptionStatistics(subscriptionStatisticDTO, allDeviceCount);
} catch (ApplicationManagementDAOException e) {
String msg = "Error encountered while getting subscription statistics for group: " + subscriptionInfo.getIdentifier();

@ -40,6 +40,7 @@ import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil;
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
@ -210,7 +211,8 @@ public class RoleBasedSubscriptionManagementHelperServiceImpl implements Subscri
for (String user : usersWithRole) {
PaginationRequest paginationRequest = new PaginationRequest(-1, -1);
paginationRequest.setOwner(user);
paginationRequest.setStatusList(Arrays.asList("ACTIVE", "INACTIVE", "UNREACHABLE"));
paginationRequest.setStatusList(Arrays.asList(EnrolmentInfo.Status.ACTIVE.name(),
EnrolmentInfo.Status.INACTIVE.name(),EnrolmentInfo.Status.UNREACHABLE.name()));
PaginationResult ownDeviceIds = HelperUtil.getDeviceManagementProviderService().
getAllDevicesIdList(paginationRequest);
if (ownDeviceIds.getData() != null) {

@ -39,6 +39,7 @@ import io.entgra.device.mgt.core.application.mgt.core.util.HelperUtil;
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.SubscriptionManagementHelperUtil;
import io.entgra.device.mgt.core.application.mgt.core.util.subscription.mgt.service.SubscriptionManagementHelperService;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
@ -196,7 +197,8 @@ public class UserBasedSubscriptionManagementHelperServiceImpl implements Subscri
List<Device> deviceListOwnByUser = new ArrayList<>();
PaginationRequest paginationRequest = new PaginationRequest(-1, -1);
paginationRequest.setOwner(username);
paginationRequest.setStatusList(Arrays.asList("ACTIVE", "INACTIVE", "UNREACHABLE"));
paginationRequest.setStatusList(Arrays.asList(EnrolmentInfo.Status.ACTIVE.name(),
EnrolmentInfo.Status.INACTIVE.name(),EnrolmentInfo.Status.UNREACHABLE.name()));
PaginationResult ownDeviceIds = HelperUtil.getDeviceManagementProviderService().
getAllDevicesIdList(paginationRequest);
if (ownDeviceIds.getData() != null) {

@ -21,16 +21,16 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.2.4-SNAPSHOT</version>
<artifactId>device-mgt-core</artifactId>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>application-mgt</artifactId>
<packaging>pom</packaging>
<name>WSO2 Carbon - Application Management Component</name>
<description>WSO2 Carbon - Application Management Component</description>
<name>Entgra Device Management - Application Management Component</name>
<description>Entgra Device Management - Application Management Component</description>
<url>https://entgra.io</url>
<modules>

@ -22,15 +22,15 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>cea-mgt</artifactId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.cea.mgt.admin.api</artifactId>
<packaging>war</packaging>
<name>Entgra IoT - CEA Management Admin API</name>
<description>Entgra IoT - Conditional Email Access Management Admin API</description>
<name>Entgra Device Management - CEA Management Admin API</name>
<description>Entgra Device Management - Conditional Email Access Management Admin API</description>
<build>
<plugins>

@ -23,15 +23,15 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>cea-mgt</artifactId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.cea.mgt.common</artifactId>
<packaging>bundle</packaging>
<name>Entgra IoT - CEA Management Common</name>
<description>Entgra IoT - Conditional Email Access Management Common</description>
<name>Entgra Device Management - CEA Management Common</name>
<description>Entgra Device Management - Conditional Email Access Management Common</description>
<build>
<plugins>

@ -22,15 +22,15 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>cea-mgt</artifactId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.cea.mgt.core</artifactId>
<packaging>bundle</packaging>
<name>Entgra IoT - CEA Management Core</name>
<description>Entgra IoT - Conditional Email Access Management Core</description>
<name>Entgra Device Management - CEA Management Core</name>
<description>Entgra Device Management - Conditional Email Access Management Core</description>
<build>
<plugins>

@ -22,15 +22,15 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>cea-mgt</artifactId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>io.entgra.device.mgt.core.cea.mgt.enforce</artifactId>
<modelVersion>4.0.0</modelVersion>
<packaging>bundle</packaging>
<name>Entgra IoT - CEA Management Enforcement Service</name>
<description>Entgra IoT - Conditional Email Access Management Enforcement Service</description>
<name>Entgra Device Management - CEA Management Enforcement Service</name>
<description>Entgra Device Management - Conditional Email Access Management Enforcement Service</description>
<build>
<plugins>

@ -21,16 +21,16 @@
<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>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.2.4-SNAPSHOT</version>
<artifactId>device-mgt-core</artifactId>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cea-mgt</artifactId>
<packaging>pom</packaging>
<name>Entgra IoT - CEA Management Component</name>
<description>Entgra IoT - Conditional Email Access Management Component</description>
<name>Entgra Device Management - CEA Management Component</name>
<description>Entgra Device Management - Conditional Email Access Management Component</description>
<modules>
<module>io.entgra.device.mgt.core.cea.mgt.core</module>

@ -22,15 +22,15 @@
<parent>
<artifactId>certificate-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.certificate.mgt.api</artifactId>
<packaging>war</packaging>
<name>WSO2 Carbon - Certificate Management API</name>
<description>WSO2 Carbon - Certificate Management API</description>
<name>Entgra Device Management - Certificate Management API</name>
<description>Entgra Device Management - Certificate Management API</description>
<url>https://entgra.io</url>
<build>

@ -22,15 +22,15 @@
<parent>
<artifactId>certificate-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.certificate.mgt.cert.admin.api</artifactId>
<packaging>war</packaging>
<name>WSO2 Carbon - Admin Certificate Management API</name>
<description>WSO2 Carbon - Admin Certificate Management API</description>
<name>Entgra Device Management - Admin Certificate Management API</name>
<description>Entgra Device Management - Admin Certificate Management API</description>
<url>https://entgra.io</url>
<build>

@ -21,15 +21,15 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>certificate-mgt</artifactId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.certificate.mgt.core</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - Certificate Management Core</name>
<description>WSO2 Carbon - Certificate Management Core</description>
<name>Entgra Device Management - Certificate Management Core</name>
<description>Entgra Device Management - Certificate Management Core</description>
<url>https://entgra.io</url>
<build>
@ -65,12 +65,12 @@
io.entgra.device.mgt.core.certificate.mgt.core.dao,
io.entgra.device.mgt.core.certificate.mgt.core.dto,
io.entgra.device.mgt.core.certificate.mgt.core.exception,
io.entgra.device.mgt.core.device.mgt.common;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.metadata.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.config;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.config.cache;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.service;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.metadata.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.config;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.config.cache;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.service;version="${io.entgra.device.mgt.core.version.range}",
io.swagger.annotations;version="[1.6,2)",
javax.cache;version="[1.0,2)",
javax.naming,

@ -139,7 +139,7 @@ public class GenericCertificateDAOImpl extends AbstractCertificateDAOImpl {
isCertificateUsernameProvided = true;
}
query += "ORDER BY ID LIMIT ?,?";
query += "ORDER BY ID DESC LIMIT ?,?";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
int paramIdx = 1;

@ -78,7 +78,7 @@ public class OracleCertificateDAOImpl extends AbstractCertificateDAOImpl {
isCertificateUsernameProvided = true;
}
query += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
query += "ORDER BY ID DESC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
int paramIdx = 1;

@ -78,7 +78,7 @@ public class PostgreSQLCertificateDAOImpl extends AbstractCertificateDAOImpl {
isCertificateUsernameProvided = true;
}
query += "ORDER BY ID LIMIT ? OFFSET ?";
query += "ORDER BY ID DESC LIMIT ? OFFSET ?";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
int paramIdx = 1;

@ -78,7 +78,7 @@ public class SQLServerCertificateDAOImpl extends AbstractCertificateDAOImpl {
isCertificateUsernameProvided = true;
}
query += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
query += "ORDER BY ID DESC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
int paramIdx = 1;

@ -29,6 +29,7 @@ import io.entgra.device.mgt.core.certificate.mgt.core.util.CertificateManagement
import io.entgra.device.mgt.core.certificate.mgt.core.util.CommonUtil;
import io.entgra.device.mgt.core.certificate.mgt.core.util.Serializer;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bouncycastle.asn1.ASN1Encodable;
@ -429,20 +430,35 @@ public class CertificateGenerator {
generateCertificate(byteArrayInputStream);
if (reqCert != null && reqCert.getSerialNumber() != null) {
if (log.isDebugEnabled()) {
log.debug("looking up certificate for serial: " + reqCert.getSerialNumber().toString());
CertificateResponse lookUpCertificate = keyStoreReader.getCertificateBySerial(
}
String orgUnit = CommonUtil.getSubjectDnAttribute(reqCert,
CertificateManagementConstants.ORG_UNIT_ATTRIBUTE);
CertificateResponse lookUpCertificate;
if (StringUtils.isNotEmpty(orgUnit)) {
int tenantId = Integer.parseInt(orgUnit.split(("_"))[1]);
lookUpCertificate = keyStoreReader.getCertificateBySerial(reqCert.getSerialNumber().toString(),
tenantId);
} else {
lookUpCertificate = keyStoreReader.getCertificateBySerial(
reqCert.getSerialNumber().toString());
}
if (lookUpCertificate != null && lookUpCertificate.getCertificate() != null) {
if (log.isDebugEnabled()) {
log.debug("certificate found for serial: " + reqCert.getSerialNumber()
.toString());
}
Certificate certificate = (Certificate) Serializer.deserialize(lookUpCertificate.getCertificate());
if (certificate instanceof X509Certificate) {
return (X509Certificate) certificate;
}
} else {
if (log.isDebugEnabled()) {
log.debug("certificate not found for serial: " + reqCert.getSerialNumber()
.toString());
}
}
}
@ -464,7 +480,6 @@ public class CertificateGenerator {
log.error(errorMsg);
throw new KeystoreException(errorMsg, e);
}
return null;
}
@ -823,8 +838,14 @@ public class CertificateGenerator {
}
String subjectDn = joiner.toString();
X500Name issuerName = new X500Name(subjectDn);
String commonName = certificationRequest.getSubject().getRDNs(BCStyle.CN)[0].getFirst()
.getValue().toString();
// CSR sent from a Windows device will have an '!' followed by the device ID in the CN
if (commonName.contains("!")) {
commonName = commonName.split("!")[1];
}
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
X500Name subjectName = new X500Name("O=" + commonName + " ,CN=" +
serialNumber + ", OU=tenant_" + tenantId);

@ -35,6 +35,7 @@ public final class CertificateManagementConstants {
public static final String DES_EDE = "DESede";
public static final String CONF_LOCATION = "conf.location";
public static final String DEFAULT_PRINCIPAL = "O=WSO2, OU=Mobile, C=LK";
public static final String ORG_UNIT_ATTRIBUTE = "OU=";
public static final String RSA_PRIVATE_KEY_BEGIN_TEXT = "-----BEGIN RSA PRIVATE KEY-----\n";
public static final String RSA_PRIVATE_KEY_END_TEXT = "-----END RSA PRIVATE KEY-----";
public static final String EMPTY_TEXT = "";

@ -17,7 +17,10 @@
*/
package io.entgra.device.mgt.core.certificate.mgt.core.util;
import org.apache.commons.lang.StringUtils;
import java.math.BigInteger;
import java.security.cert.X509Certificate;
import java.util.Calendar;
import java.util.Date;
@ -43,4 +46,26 @@ public class CommonUtil {
return BigInteger.valueOf(System.currentTimeMillis());
}
/**
* Returns the value of the given attribute from the subject distinguished name. eg: "entgra.net"
* from "CN=entgra.net"
* @param requestCertificate {@link X509Certificate} that needs to extract an attribute from
* @param attribute the attribute name that needs to be extracted from the cert. eg: "CN="
* @return the value of the attribute
*/
public static String getSubjectDnAttribute(X509Certificate requestCertificate, String attribute) {
String distinguishedName = requestCertificate.getSubjectDN().getName();
if (StringUtils.isNotEmpty(distinguishedName)) {
String[] dnSplits = distinguishedName.split(",");
for (String dnSplit : dnSplits) {
if (dnSplit.contains(attribute)) {
String[] cnSplits = dnSplit.split("=");
if (StringUtils.isNotEmpty(cnSplits[1])) {
return cnSplits[1];
}
}
}
}
return null;
}
}

@ -21,15 +21,15 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.2.4-SNAPSHOT</version>
<artifactId>device-mgt-core</artifactId>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>certificate-mgt</artifactId>
<packaging>pom</packaging>
<name>WSO2 Carbon - Certificate Management Component</name>
<name>Entgra Device Management - Certificate Management Component</name>
<url>https://entgra.io</url>
<modules>

@ -22,15 +22,15 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager</artifactId>
<packaging>bundle</packaging>
<name>Entgra IoT - Default User Roles Management Module</name>
<description>Entgra IoT - Default User Roles Management Module Implementation</description>
<name>Entgra Device Management - Default User Roles Management Module</name>
<description>Entgra Device Management - Default User Roles Management Module Implementation</description>
<url>http://entgra.io</url>
<build>
@ -55,8 +55,8 @@
<Bundle-Description>IoT - User Roles Management Bundle</Bundle-Description>
<Private-Package>io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager.internal</Private-Package>
<Import-Package>
io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager.bean;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager.exception;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager.bean;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager.exception;version="${io.entgra.device.mgt.core.version.range}",
javax.xml.bind;version="[0.0,1)",
javax.xml.bind.annotation;version="[0.0,1)",
javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}",

@ -22,14 +22,14 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.device.organization.api</artifactId>
<packaging>war</packaging>
<name>Entgra IoT - API Device Organization Management API</name>
<name>Entgra Device Management - API Device Organization Management API</name>
<description>This module extends the API manager's device organization management apis.</description>
<url>http://entgra.io</url>

@ -22,15 +22,15 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.device.organization</artifactId>
<packaging>bundle</packaging>
<name>Entgra IoT - Device Organization Module</name>
<description>Entgra IoT - Device Organization Module Implementation</description>
<name>Entgra Device Management - Device Organization Module</name>
<description>Entgra Device Management - Device Organization Module Implementation</description>
<url>http://entgra.io</url>
<dependencies>
<dependency>

@ -22,15 +22,15 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - Device Type Deployer</name>
<description>WSO2 Carbon - Device Type Deployer Implementation</description>
<name>Entgra Device Management - Device Type Deployer</name>
<description>Entgra Device Management - Device Type Deployer Implementation</description>
<url>https://entgra.io</url>
<dependencies>
@ -151,11 +151,11 @@
io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer.*
</Export-Package>
<Import-Package>
io.entgra.device.mgt.core.device.mgt.common.spi;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.spi;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer.util,
io.entgra.device.mgt.core.device.mgt.extensions.device.type.template;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.extensions.device.type.template.config;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.extensions.device.type.template.config.exception;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.extensions.device.type.template;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.extensions.device.type.template.config;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.extensions.device.type.template.config.exception;version="${io.entgra.device.mgt.core.version.range}",
javax.xml.bind;version="[0.0,1)",
javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}",
org.apache.axis2.context;version="[1.6,2)",

@ -21,15 +21,15 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.logger</artifactId>
<packaging>bundle</packaging>
<name>Entgra IoT - Logger Impl</name>
<description>Entgra IoT - Entgra Logger Implementation</description>
<name>Entgra Device Management - Logger Impl</name>
<description>Entgra Device Management - Entgra Logger Implementation</description>
<url>http://entgra.io</url>
<build>

@ -22,15 +22,15 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.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>
<name>Entgra Device Management - Pull Notification Provider Implementation</name>
<description>Entgra Device Management - Pull Notification Provider Implementation</description>
<url>https://entgra.io</url>
<dependencies>
@ -84,14 +84,14 @@
</Export-Package>
<Import-Package>
com.google.gson;version="[2.9,3)",
io.entgra.device.mgt.core.application.mgt.common.exception;version="[5.0,6)",
io.entgra.device.mgt.core.application.mgt.common.services;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.operation.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.policy.mgt.monitor;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.pull.notification;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.service;version="[5.0,6)",
io.entgra.device.mgt.core.policy.mgt.core;version="[5.0,6)",
io.entgra.device.mgt.core.application.mgt.common.exception;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.application.mgt.common.services;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.operation.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.policy.mgt.monitor;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.pull.notification;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.service;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.policy.mgt.core;version="${io.entgra.device.mgt.core.version.range}",
org.apache.commons.logging;version="[1.2,2)",
org.osgi.service.*;version="${imp.package.version.osgi.service}"
</Import-Package>

@ -22,15 +22,15 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - FCM Based Push Notification Provider Implementation</name>
<description>WSO2 Carbon - FCM Based Push Notification Provider Implementation</description>
<name>Entgra Device Management - FCM Based Push Notification Provider Implementation</name>
<description>Entgra Device Management - FCM Based Push Notification Provider Implementation</description>
<url>https://entgra.io</url>
<dependencies>

@ -22,15 +22,15 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - HTTP Based Push Notification Provider Implementation</name>
<description>WSO2 Carbon - HTTP Based Push Notification Provider Implementation</description>
<name>Entgra Device Management - HTTP Based Push Notification Provider Implementation</name>
<description>Entgra Device Management - HTTP Based Push Notification Provider Implementation</description>
<url>https://entgra.io</url>
<dependencies>
@ -127,8 +127,8 @@
</Export-Package>
<Import-Package>
com.google.gson;version="[2.9,3)",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.push.notification;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.push.notification;version="${io.entgra.device.mgt.core.version.range}",
org.apache.commons.httpclient;version="[3.1,4)",
org.apache.commons.httpclient.methods;version="[3.1,4)",
org.apache.commons.logging;version="[1.2,2)",

@ -22,15 +22,15 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - MQTT Based Push Notification Provider Implementation</name>
<description>WSO2 Carbon - MQTT Based Push Notification Provider Implementation</description>
<name>Entgra Device Management - MQTT Based Push Notification Provider Implementation</name>
<description>Entgra Device Management - MQTT Based Push Notification Provider Implementation</description>
<url>https://entgra.io</url>
<dependencies>
@ -158,12 +158,12 @@
io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt.*
</Export-Package>
<Import-Package>
io.entgra.device.mgt.core.device.mgt.common;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.operation.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.push.notification;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.operation.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.service;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.operation.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.push.notification;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.operation.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.service;version="${io.entgra.device.mgt.core.version.range}",
org.apache.commons.logging;version="[1.2,2)",
org.osgi.service.*;version="${imp.package.version.osgi.service}",
org.wso2.carbon.context;version="[4.8,5)",

@ -22,15 +22,15 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - XMPP Based Push Notification Provider Implementation</name>
<description>WSO2 Carbon - XMPP Based Push Notification Provider Implementation</description>
<name>Entgra Device Management - XMPP Based Push Notification Provider Implementation</name>
<description>Entgra Device Management - XMPP Based Push Notification Provider Implementation</description>
<url>https://entgra.io</url>
<dependencies>
@ -135,11 +135,11 @@
io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp.*
</Export-Package>
<Import-Package>
io.entgra.device.mgt.core.device.mgt.common;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.operation.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.push.notification;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.service;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.operation.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.push.notification;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.core.service;version="${io.entgra.device.mgt.core.version.range}",
org.apache.commons.logging;version="[1.2,2)",
org.osgi.service.*;version="${imp.package.version.osgi.service}",
org.wso2.carbon.event.output.adapter.core;version="[5.3,6)",

@ -22,15 +22,15 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.stateengine</artifactId>
<packaging>bundle</packaging>
<name>Entgra IoT - State Engine </name>
<description>Entgra IoT - State Engine Components</description>
<name>Entgra Device Management - State Engine </name>
<description>Entgra Device Management - State Engine Components</description>
<url>http://entgra.io</url>
<build>
@ -54,7 +54,7 @@
<Bundle-Version>${io.entgra.device.mgt.core.version}</Bundle-Version>
<Bundle-Description>IoT Device Management State Engine Bundle</Bundle-Description>
<Import-Package>
io.entgra.device.mgt.core.device.mgt.common;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.extensions.stateengine.dto,
io.entgra.device.mgt.core.device.mgt.extensions.stateengine.exception,
org.apache.commons.logging;version="[1.2,2)",

@ -22,15 +22,15 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.extensions.userstore.role.mapper</artifactId>
<packaging>bundle</packaging>
<name>Entgra IoT - User store role mapping Module</name>
<description>Entgra IoT - User store role mapping Module</description>
<name>Entgra Device Management - User store role mapping Module</name>
<description>Entgra Device Management - User store role mapping Module</description>
<url>http://entgra.io</url>
<build>

@ -20,17 +20,17 @@
<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>io.entgra.device.mgt.core.parent</artifactId>
<artifactId>device-mgt-core</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>device-mgt-extensions</artifactId>
<packaging>pom</packaging>
<name>WSO2 Carbon - Device Management Extensions</name>
<description>WSO2 Carbon - Device Management Extensions</description>
<name>Entgra Device Management - Device Management Extensions</name>
<description>Entgra Device Management - Device Management Extensions</description>
<url>https://entgra.io</url>
<modules>

@ -22,15 +22,15 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.api</artifactId>
<packaging>war</packaging>
<name>WSO2 Carbon - Mobile Device Management API</name>
<description>WSO2 Carbon - Mobile Device Management API</description>
<name>Entgra Device Management - Mobile Device Management API</name>
<description>Entgra Device Management - Mobile Device Management API</description>
<url>https://entgra.io</url>
<build>

@ -115,7 +115,7 @@ public interface DeviceStatusFilterService {
required = true) @PathParam ("device-type") String deviceType);
@GET
@Path("/is-enabled")
@Path("/device-status-check")
@ApiOperation(
httpMethod = HTTPConstants.HEADER_GET,
value = "Get device status filter",
@ -155,7 +155,7 @@ public interface DeviceStatusFilterService {
Response getDeviceStatusCheck();
@PUT
@Path("/toggle-device-status")
@Path("/device-status-check")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_POST,
@ -201,6 +201,7 @@ public interface DeviceStatusFilterService {
@QueryParam("isEnabled") boolean isEnabled);
@PUT
@Path("/{deviceType}")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_POST,
@ -243,10 +244,51 @@ public interface DeviceStatusFilterService {
name = "deviceType",
value = "The device type for which you want to update device status filters.",
required = true)
@QueryParam("deviceType") String deviceType,
@PathParam ("deviceType") String deviceType,
@ApiParam(
name = "deviceStatus",
value = "A list of device status values to update for the given device type.",
required = true)
@QueryParam("deviceStatus") List<String> deviceStatus);
@POST
@Path("/default")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_POST,
value = "Add Default Device status filters",
notes = "Add Default Device status filters",
tags = "Tenant Metadata Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "dm:devicestatusfilter:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully add default device status filters.",
response = Response.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 500,
message = "Internal Server Error. " +
"\n Server error occurred while adding default device status filters.",
response = ErrorResponse.class)
})
Response setDefaultStatusFilterData();
}

@ -20,13 +20,20 @@ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.DeviceStatusFilterService;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataKeyNotFoundException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import javax.ws.rs.*;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
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;
import java.util.List;
@ -42,15 +49,14 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
@GET
@Path("/{deviceType}")
public Response getDeviceStatusFilters(@PathParam("deviceType") String deviceType) {
List<String> result;
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
result = deviceManagementProviderService.getDeviceStatusFilters(deviceType, tenantId);
if (result != null) {
return Response.status(Response.Status.OK).entity(result).build();
}
return Response.status(Response.Status.NO_CONTENT).entity(false).build();
return Response.status(Response.Status.OK).entity(deviceManagementProviderService
.getDeviceStatusFilters(deviceType)).build();
} catch (MetadataKeyNotFoundException e) {
String msg = "Couldn't find the device status filter details for device type: " + deviceType;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (MetadataManagementException e) {
String msg = "Error occurred while getting device status filter of the tenant.";
log.error(msg, e);
@ -59,7 +65,7 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
}
@GET
@Path("/is-enabled")
@Path("/device-status-check")
@Override
public Response getDeviceStatusCheck() {
boolean result;
@ -68,8 +74,12 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
result = deviceManagementProviderService.getDeviceStatusCheck(tenantId);
return Response.status(Response.Status.OK).entity(result).build();
} catch (MetadataKeyNotFoundException e) {
String msg = "Couldn't find the device status check metadata for tenant ID: " + tenantId;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (MetadataManagementException e) {
String msg = "Error occurred while getting device status filter of the tenant.";
String msg = "Error occurred while getting device status check for the tenant.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -77,15 +87,14 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
@Override
@PUT
@Path("/toggle-device-status")
@Path("/device-status-check")
public Response updateDeviceStatusCheck(
@QueryParam("isEnabled")
boolean isEnabled) {
boolean result;
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
result = deviceManagementProviderService.updateDefaultDeviceStatusCheck(tenantId, isEnabled);
result = deviceManagementProviderService.updateDefaultDeviceStatusCheck(isEnabled);
if (result) {
return Response.status(Response.Status.OK).entity("Successfully updated device status check.").build();
} else {
@ -100,16 +109,14 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
@Override
@PUT
@Path("/{deviceType}")
public Response updateDeviceStatusFilters(
@QueryParam("deviceType")
String deviceType,
@QueryParam("deviceStatus")
List<String> deviceStatus
@PathParam("deviceType") String deviceType,
@QueryParam("deviceStatus") List<String> deviceStatus
) {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
deviceManagementProviderService.updateDefaultDeviceStatusFilters(tenantId, deviceType, deviceStatus);
deviceManagementProviderService.updateDefaultDeviceStatusFilters(deviceType, deviceStatus);
return Response.status(Response.Status.OK).entity("Successfully updated device status filters for " + deviceType).build();
} catch (MetadataManagementException e) {
String msg = "Error occurred while updating device status for " + deviceType;
@ -117,4 +124,18 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
public Response setDefaultStatusFilterData() {
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
try {
deviceManagementProviderService.resetToDefaultDeviceStatusFilter();
return Response.status(Response.Status.OK).entity("Successfully updated device status filters to " +
"default values that is configured in the product").build();
} catch (MetadataManagementException e) {
String msg = "Error occurred while updating device status for default values that is configured in the product";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -36,8 +36,6 @@ import org.apache.commons.logging.LogFactory;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;
/**
@ -147,21 +145,4 @@ public class MetadataServiceImpl implements MetadataService {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
/**
* Useful to send files as application/octet-stream responses
*/
private Response sendFileStream(byte[] content) throws IOException {
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
Response.ResponseBuilder response = Response
.ok(binaryDuplicate, MediaType.APPLICATION_OCTET_STREAM);
response.status(Response.Status.OK);
response.header("Content-Length", content.length);
return response.build();
} catch (IOException e) {
String msg = "Error occurred while creating input stream from buffer array. ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -21,15 +21,15 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.common</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - Device Management Commons</name>
<description>WSO2 Carbon - Device Management Commons</description>
<name>Entgra Device Management - Device Management Commons</name>
<description>Entgra Device Management - Device Management Commons</description>
<url>https://entgra.io</url>
<build>

@ -58,6 +58,13 @@ public class Feature implements Serializable {
)
private String description;
@ApiModelProperty(
name = "tooltip",
value = "Provides a tooltip for the features.",
required = false
)
private String tooltip;
@ApiModelProperty(
name = "type",
value = "Type of the feature.",
@ -86,6 +93,20 @@ public class Feature implements Serializable {
)
private List<MetadataEntry> metadataEntries;
@ApiModelProperty(
name = "confirmationTexts",
value = "Disenroll delete confirmation modal texts.",
required = false
)
private ConfirmationTexts confirmationTexts;
@ApiModelProperty(
name = "dangerZoneTooltipTexts",
value = "Danger zone tooltip texts.",
required = false
)
private DangerZoneTooltipTexts dangerZoneTooltipTexts;
@XmlElement
public int getId() {
return id;
@ -139,6 +160,16 @@ public class Feature implements Serializable {
this.description = description;
}
@XmlElement
public String getTooltip() {
return tooltip;
}
public void setTooltip(String tooltip) {
this.tooltip = tooltip;
}
@XmlAttribute
public String getType() {
return type;
@ -156,6 +187,24 @@ public class Feature implements Serializable {
this.hidden = hidden;
}
@XmlElement
public ConfirmationTexts getConfirmationTexts() {
return confirmationTexts;
}
public void setConfirmationTexts(ConfirmationTexts confirmationTexts) {
this.confirmationTexts = confirmationTexts;
}
@XmlElement
public DangerZoneTooltipTexts getDangerZoneTooltipTexts() {
return dangerZoneTooltipTexts;
}
public void setDangerZoneTooltipTexts(DangerZoneTooltipTexts dangerZoneTooltipTexts) {
this.dangerZoneTooltipTexts = dangerZoneTooltipTexts;
}
public static class MetadataEntry implements Serializable {
private int id;
@ -186,4 +235,136 @@ public class Feature implements Serializable {
this.value = value;
}
}
public static class ConfirmationTexts implements Serializable {
private int id;
private String deleteConfirmModalTitle;
private String deleteConfirmModalText;
private String deleteConfirmationTextDescribe;
private String deleteConfirmationText;
private String cancelText;
private String confirmText;
private String inputLabel;
private String inputRequireMessage;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCancelText() {
return cancelText;
}
public void setCancelText(String cancelText) {
this.cancelText = cancelText;
}
public String getConfirmText() {
return confirmText;
}
public void setConfirmText(String confirmText) {
this.confirmText = confirmText;
}
public String getInputLabel() {
return inputLabel;
}
public void setInputLabel(String inputLabel) {
this.inputLabel = inputLabel;
}
public String getInputRequireMessage() {
return inputRequireMessage;
}
public void setInputRequireMessage(String inputRequireMessage) {
this.inputRequireMessage = inputRequireMessage;
}
public String getDeleteConfirmModalTitle() {
return deleteConfirmModalTitle;
}
public void setDeleteConfirmModalTitle(String deleteConfirmModalTitle) {
this.deleteConfirmModalTitle = deleteConfirmModalTitle;
}
public String getDeleteConfirmModalText() {
return deleteConfirmModalText;
}
public void setDeleteConfirmModalText(String deleteConfirmModalText) {
this.deleteConfirmModalText = deleteConfirmModalText;
}
public String getDeleteConfirmationTextDescribe() {
return deleteConfirmationTextDescribe;
}
public void setDeleteConfirmationTextDescribe(String deleteConfirmationTextDescribe) {
this.deleteConfirmationTextDescribe = deleteConfirmationTextDescribe;
}
public String getDeleteConfirmationText() {
return deleteConfirmationText;
}
public void setDeleteConfirmationText(String deleteConfirmationText) {
this.deleteConfirmationText = deleteConfirmationText;
}
}
public static class DangerZoneTooltipTexts implements Serializable {
private String toolTipTitle;
private String toolTipPopConfirmText;
private String confirmText;
private String cancelText;
private String toolTipAvailable;
public String getToolTipAvailable() {
return toolTipAvailable;
}
public void setToolTipAvailable(String toolTipAvailable) {
this.toolTipAvailable = toolTipAvailable;
}
public String getToolTipTitle() {
return toolTipTitle;
}
public void setToolTipTitle(String toolTipTitle) {
this.toolTipTitle = toolTipTitle;
}
public String getToolTipPopConfirmText() {
return toolTipPopConfirmText;
}
public void setToolTipPopConfirmText(String toolTipPopConfirmText) {
this.toolTipPopConfirmText = toolTipPopConfirmText;
}
public String getConfirmText() {
return confirmText;
}
public void setConfirmText(String confirmText) {
this.confirmText = confirmText;
}
public String getCancelText() {
return cancelText;
}
public void setCancelText(String cancelText) {
this.cancelText = cancelText;
}
}
}

@ -21,7 +21,7 @@ package io.entgra.device.mgt.core.device.mgt.common.exceptions;
/**
* Custom exception class to be used in MetadataMgmt related functionalities.
*/
public class MetadataKeyAlreadyExistsException extends Exception {
public class MetadataKeyAlreadyExistsException extends MetadataManagementException {
private static final long serialVersionUID = -1814347544027733436L;
private String errorMessage;

@ -21,7 +21,7 @@ package io.entgra.device.mgt.core.device.mgt.common.exceptions;
/**
* Custom exception class to be used in MetadataMgmt related functionalities.
*/
public class MetadataKeyNotFoundException extends Exception {
public class MetadataKeyNotFoundException extends MetadataManagementException {
private static final long serialVersionUID = 5260831982626354815L;
private String errorMessage;

@ -34,18 +34,19 @@ public interface DeviceStatusManagementService {
void addDefaultDeviceStatusFilterIfNotExist(int tenantId) throws MetadataManagementException;
/**
* This method is useful to reset existing device status to default values in xml
* This method is useful to reset existing device status to default values and device status check value to
* default value that is defined in the ui-config
*
* @throws MetadataManagementException if error while resetting default device status
*/
void resetToDefaultDeviceStausFilter() throws MetadataManagementException;
void resetToDefaultDeviceStatusFilter() throws MetadataManagementException;
/**
* This method is useful to update existing allowed device status
*
* @throws MetadataManagementException if error while updating existing device status
*/
void updateDefaultDeviceStatusFilters(int tenantId, String deviceType, List<String> deviceStatus)
void updateDefaultDeviceStatusFilters(String deviceType, List<String> deviceStatus)
throws MetadataManagementException;
/**
@ -53,21 +54,21 @@ public interface DeviceStatusManagementService {
*
* @throws MetadataManagementException if error while updating existing device status
*/
boolean updateDefaultDeviceStatusCheck(int tenantId, boolean isChecked)
boolean updateDefaultDeviceStatusCheck(boolean isChecked)
throws MetadataManagementException;
/**
* This method is useful to get existing device status filters
*
* @throws MetadataManagementException if error while getting existing device status
*/
List<AllowedDeviceStatus> getDeviceStatusFilters(int tenantId) throws MetadataManagementException;
List<AllowedDeviceStatus> getDeviceStatusFilters() throws MetadataManagementException;
/**
* This method is useful to get existing device status filters by device type and tenant id
*
* @throws MetadataManagementException if error while getting existing device status
*/
List<String> getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException;
List<String> getDeviceStatusFilters(String deviceType) throws MetadataManagementException;
/**
* This method is useful to get existing device status filters

@ -24,6 +24,7 @@ public class WhiteLabelTheme {
private WhiteLabelImage logoIconImage;
private String footerText;
private String appTitle;
private String docUrl;
public String getFooterText() {
return footerText;
@ -64,4 +65,12 @@ public class WhiteLabelTheme {
public void setLogoIconImage(WhiteLabelImage logoIconImage) {
this.logoIconImage = logoIconImage;
}
public String getDocUrl() {
return docUrl;
}
public void setDocUrl(String docUrl) {
this.docUrl = docUrl;
}
}

@ -24,6 +24,7 @@ public class WhiteLabelThemeCreateRequest {
private WhiteLabelImageRequestPayload logoIcon;
private String footerText;
private String appTitle;
private String docUrl;
public WhiteLabelImageRequestPayload getFavicon() {
return favicon;
@ -64,4 +65,12 @@ public class WhiteLabelThemeCreateRequest {
public void setLogoIcon(WhiteLabelImageRequestPayload logoIcon) {
this.logoIcon = logoIcon;
}
public String getDocUrl() {
return docUrl;
}
public void setDocUrl(String docUrl) {
this.docUrl = docUrl;
}
}

@ -22,15 +22,15 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.config.api</artifactId>
<packaging>war</packaging>
<name>Entgra Carbon - Mobile Device Management Configuration API</name>
<description>Entgra Carbon - Mobile Device Management Configuration API</description>
<name>Entgra Device Management - Device Management Configuration API</name>
<description>Entgra Device Management - Device Management Configuration API</description>
<url>https://entgra.io</url>
<build>

@ -25,6 +25,7 @@ import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.DeviceConfi
import io.entgra.device.mgt.core.device.mgt.common.general.TenantDetail;
import io.entgra.device.mgt.core.device.mgt.config.api.beans.ErrorResponse;
import io.swagger.annotations.*;
import io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.dto.OperationConfig;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@ -77,6 +78,13 @@ import java.util.List;
key = "admin:permissions:add",
roles = {"Internal/devicemgt-user"},
permissions = {"/permissions/add"}
),
@Scope(
name = "Manage operation configuration",
description = "Add or update operation configuration",
key = "admin:operation_config:manage",
roles = {"Internal/devicemgt-user"},
permissions = {"/operation-configuration/manage"}
)
}
)
@ -319,4 +327,173 @@ public interface DeviceManagementConfigService {
})
@Produces(MediaType.APPLICATION_JSON)
Response addPermission(List<String> permissions);
@GET
@Path("/operation-configuration")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HttpMethod.GET,
value = "Getting operation configuration",
notes = "Retrieve the operation configuration",
tags = "Device Management Configuration",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "scope", value = "admin:operation_config:manage")
})
}
)
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully fetched the operation configuration.",
response = OperationConfig.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 400,
message = "Bad Request.",
response = ErrorResponse.class),
@ApiResponse(
code = 401,
message = "Unauthorized. \n Unauthorized operation! Only admin role can perform this operation."),
@ApiResponse(
code = 404,
message = "Not Found. \n No operation found",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while adding operation configuration.",
response = ErrorResponse.class)
})
Response getOperationConfiguration();
@POST
@Path("/operation-configuration")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HttpMethod.POST,
value = "Add operation configuration",
notes = "Add operation configuration.",
tags = "Device Management Configuration",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "scope", value =
"admin:operation_config:manage")
})
}
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully added the operation configuration.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 400,
message = "The incoming request has wrong operation configuration.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while adding operation configuration",
response = ErrorResponse.class)
})
@Produces(MediaType.APPLICATION_JSON)
Response addOperationConfiguration(OperationConfig config);
@PUT
@Path("/operation-configuration")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HttpMethod.PUT,
value = "Update operation configuration",
notes = "Update operation configuration.",
tags = "Device Management Configuration",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "scope", value = "admin:operation_config:manage")
})
}
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully Update the operation configuration.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 400,
message = "The incoming request has wrong operation configuration.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while adding operation configuration.",
response = ErrorResponse.class)
})
@Produces(MediaType.APPLICATION_JSON)
Response updateOperationConfiguration(OperationConfig config);
@DELETE
@Path("/operation-configuration")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HttpMethod.DELETE,
value = "Delete operation configuration",
notes = "Delete operation configuration",
tags = {"Device Management Configuration"},
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "scope", value = "admin:operation_config:manage")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deleted the operation configuration",
response = Response.class),
@ApiResponse(
code = 400,
message = "Bad Request.",
response = Response.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Operation configuration not provided",
response = Response.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while deleting the operation configuration.",
response = Response.class)
}
)
Response deleteOperationConfiguration();
}

@ -22,6 +22,12 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.OTPManagementException;
import io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.OperationConfigurationService;
import io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.dto.OperationConfig;
import io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.exceptions.OperationConfigAlreadyExistsException;
import io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.exceptions.OperationConfigException;
import io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.exceptions.OperationConfigNotFoundException;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
@ -61,6 +67,7 @@ import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.DELETE;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
@ -313,4 +320,89 @@ public class DeviceManagementConfigServiceImpl implements DeviceManagementConfig
return Response.status(Response.Status.OK).build();
}
@GET
@Path("/operation-configuration")
@Produces({MediaType.APPLICATION_JSON})
public Response getOperationConfiguration() {
OperationConfig config;
try {
config = OperationConfigurationService.getOperationConfig();
} catch (OperationConfigException e) {
String msg = "Error occurred getting operation configuration";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
if (config == null) {
String msg = "Operation configuration not provided";
log.error(msg);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} else {
return Response.status(Response.Status.OK).entity(config).build();
}
}
@POST
@Path("/operation-configuration")
@Produces({MediaType.APPLICATION_JSON})
public Response addOperationConfiguration(OperationConfig config) {
try {
if (config != null) {
OperationConfigurationService.addOperationConfiguration(config);
} else {
String msg = "Operation configuration not provided";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
} catch (OperationConfigException e) {
String msg = "Error occurred adding operation configuration";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (OperationConfigAlreadyExistsException e) {
String msg = "Operation configuration already exists";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(config).build();
}
@PUT
@Path("/operation-configuration")
@Produces({MediaType.APPLICATION_JSON})
public Response updateOperationConfiguration(OperationConfig config) {
try {
if (config != null) {
OperationConfigurationService.updateOperationConfiguration(config);
} else {
String msg = "Operation configuration body not provided";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
} catch (OperationConfigException e) {
String msg = "Error occurred adding operation configuration";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(config).build();
}
@DELETE
@Path("/operation-configuration")
@Produces({MediaType.APPLICATION_JSON})
public Response deleteOperationConfiguration() {
String msg;
try {
OperationConfigurationService.deleteOperationConfiguration();
} catch (OperationConfigException e) {
msg = "Error occurred while deleting operation configuration";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (OperationConfigNotFoundException e) {
msg = "Operation configuration not provided";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
msg = "Operation configuration deleted successfully";
log.info(msg);
return Response.status(Response.Status.OK).entity(msg).build();
}
}

@ -22,15 +22,15 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>device-mgt</artifactId>
<version>5.2.4-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.device.mgt.core</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - Device Management Core</name>
<description>WSO2 Carbon - Device Management Core</description>
<name>Entgra Device Management - Device Management Core</name>
<description>Entgra Device Management - Device Management Core</description>
<url>https://entgra.io</url>
<build>
@ -86,135 +86,55 @@
com.google.common.reflect;version="[32.1,33)";resolution:=optional,
com.google.gson;version="[2.9,3)",
com.google.gson.reflect;version="[2.9,3)",
io.entgra.device.mgt.core.apimgt.annotations;version="[5.0,6)",
io.entgra.device.mgt.core.apimgt.extension.rest.api;version="[5.0,6)",
io.entgra.device.mgt.core.apimgt.extension.rest.api.dto;version="[5.0,6)",
io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;version="[5.0,6)",
io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions;version="[5.0,6)",
io.entgra.device.mgt.core.apimgt.extension.rest.api.util;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.app.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.app.mgt.android;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.app.mgt.ios;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.authorization;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.configuration.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.cost.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.device.details;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.enrollment.notification;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.event.config;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.general;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.geo.service;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.group.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.invitation.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.license.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.metadata.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.notification.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.operation.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.otp.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.otp.mgt.dto;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.permission.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.policy.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.pull.notification;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.push.notification;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.report.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.roles.config;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.search;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.spi;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.type.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.app.mgt.config,
io.entgra.device.mgt.core.device.mgt.core.archival,
io.entgra.device.mgt.core.device.mgt.core.archival.dao,
io.entgra.device.mgt.core.device.mgt.core.archival.dao.impl,
io.entgra.device.mgt.core.device.mgt.core.cache,
io.entgra.device.mgt.core.device.mgt.core.cache.impl,
io.entgra.device.mgt.core.device.mgt.core.common.exception,
io.entgra.device.mgt.core.device.mgt.core.common.util,
io.entgra.device.mgt.core.device.mgt.core.config,
io.entgra.device.mgt.core.device.mgt.core.config.analytics,
io.entgra.device.mgt.core.device.mgt.core.config.analytics.operation,
io.entgra.device.mgt.core.device.mgt.core.config.archival,
io.entgra.device.mgt.core.device.mgt.core.config.cache,
io.entgra.device.mgt.core.device.mgt.core.config.datasource,
io.entgra.device.mgt.core.device.mgt.core.config.enrollment.guide,
io.entgra.device.mgt.core.device.mgt.core.config.geo.location,
io.entgra.device.mgt.core.device.mgt.core.config.identity,
io.entgra.device.mgt.core.device.mgt.core.config.keymanager,
io.entgra.device.mgt.core.device.mgt.core.config.license,
io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt,
io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt.documentation,
io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt.whitelabel,
io.entgra.device.mgt.core.device.mgt.core.config.operation.timeout,
io.entgra.device.mgt.core.device.mgt.core.config.pagination,
io.entgra.device.mgt.core.device.mgt.core.config.permission,
io.entgra.device.mgt.core.device.mgt.core.config.policy,
io.entgra.device.mgt.core.device.mgt.core.config.pull.notification,
io.entgra.device.mgt.core.device.mgt.core.config.push.notification,
io.entgra.device.mgt.core.device.mgt.core.config.remote.session,
io.entgra.device.mgt.core.device.mgt.core.config.status.task,
io.entgra.device.mgt.core.device.mgt.core.config.task,
io.entgra.device.mgt.core.device.mgt.core.config.tenant,
io.entgra.device.mgt.core.device.mgt.core.config.ui,
io.entgra.device.mgt.core.device.mgt.core.dao,
io.entgra.device.mgt.core.device.mgt.core.dao.impl,
io.entgra.device.mgt.core.device.mgt.core.dao.impl.device,
io.entgra.device.mgt.core.device.mgt.core.dao.impl.enrolment,
io.entgra.device.mgt.core.device.mgt.core.dao.impl.event,
io.entgra.device.mgt.core.device.mgt.core.dao.impl.geofence,
io.entgra.device.mgt.core.device.mgt.core.dao.impl.group,
io.entgra.device.mgt.core.device.mgt.core.dao.impl.tracker,
io.entgra.device.mgt.core.device.mgt.core.device.details.mgt,
io.entgra.device.mgt.core.device.mgt.core.device.details.mgt.dao,
io.entgra.device.mgt.core.device.mgt.core.device.details.mgt.dao.impl,
io.entgra.device.mgt.core.device.mgt.core.dto,
io.entgra.device.mgt.core.device.mgt.core.dto.event.config,
io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt,
io.entgra.device.mgt.core.device.mgt.core.geo.geoHash,
io.entgra.device.mgt.core.device.mgt.core.geo.task,
io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao,
io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.impl,
io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.util,
io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.util,
io.entgra.device.mgt.core.device.mgt.core.notification.mgt.dao,
io.entgra.device.mgt.core.device.mgt.core.notification.mgt.dao.impl,
io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao,
io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.impl,
io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.impl.operation,
io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.util,
io.entgra.device.mgt.core.device.mgt.core.operation.mgt.util,
io.entgra.device.mgt.core.device.mgt.core.operation.timeout.task,
io.entgra.device.mgt.core.device.mgt.core.otp.mgt.dao,
io.entgra.device.mgt.core.device.mgt.core.otp.mgt.dao.impl,
io.entgra.device.mgt.core.device.mgt.core.otp.mgt.exception,
io.entgra.device.mgt.core.device.mgt.core.otp.mgt.util,
io.entgra.device.mgt.core.device.mgt.core.privacy,
io.entgra.device.mgt.core.device.mgt.core.privacy.dao,
io.entgra.device.mgt.core.device.mgt.core.privacy.dao.impl,
io.entgra.device.mgt.core.device.mgt.core.report.mgt,
io.entgra.device.mgt.core.device.mgt.core.report.mgt.config,
io.entgra.device.mgt.core.device.mgt.core.search.mgt,
io.entgra.device.mgt.core.device.mgt.core.search.mgt.dao,
io.entgra.device.mgt.core.device.mgt.core.status.task,
io.entgra.device.mgt.core.device.mgt.core.task,
io.entgra.device.mgt.core.device.mgt.core.traccar.api.service,
io.entgra.device.mgt.core.device.mgt.core.traccar.api.service.impl,
io.entgra.device.mgt.core.device.mgt.core.traccar.common.beans,
io.entgra.device.mgt.core.device.mgt.core.traccar.common.config,
io.entgra.device.mgt.core.device.mgt.core.traccar.common.util,
io.entgra.device.mgt.core.device.mgt.core.traccar.core.config,
io.entgra.device.mgt.core.device.mgt.extensions.logger;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.extensions.logger.spi;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension.dto;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension.exception;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension.service;version="[5.0,6)",
io.entgra.device.mgt.core.notification.logger;version="[5.0,6)",
io.entgra.device.mgt.core.notification.logger.impl;version="[5.0,6)",
io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.exception;version="[5.0,6)",
io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service;version="[5.0,6)",
io.entgra.device.mgt.core.transport.mgt.email.sender.core;version="[5.0,6)",
io.entgra.device.mgt.core.transport.mgt.email.sender.core.service;version="[5.0,6)",
io.entgra.device.mgt.core.apimgt.annotations;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.apimgt.extension.rest.api;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.apimgt.extension.rest.api.dto;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.apimgt.extension.rest.api.util;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.app.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.app.mgt.android;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.app.mgt.ios;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.authorization;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.configuration.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.cost.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.device.details;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.enrollment.notification;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.event.config;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.general;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.geo.service;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.group.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.invitation.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.license.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.metadata.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.notification.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.operation.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.otp.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.otp.mgt.dto;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.permission.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.policy.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.pull.notification;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.push.notification;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.report.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.roles.config;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.search;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.spi;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.common.type.mgt;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.extensions.logger;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.device.mgt.extensions.logger.spi;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.identity.jwt.client.extension;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.identity.jwt.client.extension.dto;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.identity.jwt.client.extension.exception;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.identity.jwt.client.extension.service;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.notification.logger;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.notification.logger.impl;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.exception;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.transport.mgt.email.sender.core;version="${io.entgra.device.mgt.core.version.range}",
io.entgra.device.mgt.core.transport.mgt.email.sender.core.service;version="${io.entgra.device.mgt.core.version.range}",
io.swagger.annotations;version="[1.6,2)",
javax.cache;version="[1.0,2)",
javax.naming,

@ -18,7 +18,6 @@
package io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt;
import io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt.documentation.DocConfiguration;
import io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt.whitelabel.WhiteLabelConfiguration;
import javax.xml.bind.annotation.XmlElement;
@ -27,7 +26,6 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "MetaDataConfiguration")
public class MetaDataConfiguration {
private WhiteLabelConfiguration whiteLabelConfiguration;
private DocConfiguration docConfiguration;
@XmlElement(name = "WhiteLabelConfiguration", required = true)
public WhiteLabelConfiguration getWhiteLabelConfiguration() {
@ -37,13 +35,4 @@ public class MetaDataConfiguration {
public void setWhiteLabelConfiguration(WhiteLabelConfiguration whiteLabelConfiguration) {
this.whiteLabelConfiguration = whiteLabelConfiguration;
}
@XmlElement(name = "DocConfiguration", required = true)
public DocConfiguration getDocConfiguration() {
return docConfiguration;
}
public void setDocConfiguration(DocConfiguration docConfiguration) {
this.docConfiguration = docConfiguration;
}
}

@ -1,36 +0,0 @@
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt.documentation;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "DocConfiguration")
public class DocConfiguration {
private String docUrl;
@XmlElement(name = "DocUrl", required = true)
public String getDocUrl() {
return docUrl;
}
public void setDocUrl(String docUrl) {
this.docUrl = docUrl;
}
}

@ -26,6 +26,16 @@ public class WhiteLabelConfiguration {
private String footerText;
private String appTitle;
private WhiteLabelImages whiteLabelImages;
private String docUrl;
@XmlElement(name = "DocUrl", required = true)
public String getDocUrl() {
return docUrl;
}
public void setDocUrl(String docUrl) {
this.docUrl = docUrl;
}
@XmlElement(name = "FooterText", required = true)
public String getFooterText() {

@ -489,4 +489,15 @@ public interface GroupDAO {
throws GroupManagementDAOException;
int getDeviceCount(String groupName, int tenantId) throws GroupManagementDAOException;
/**
* Retrieves the count of devices for a specific group, device type, and tenant.
*
* @param groupName the name of the group
* @param deviceTypeId the ID of the device type (e.g., Android, iOS, Windows)
* @param tenantId the ID of the tenant
* @return the count of devices for the given group, device type, and tenant
* @throws GroupManagementDAOException if an error occurs during the retrieval of the device count
*/
int getDeviceCountWithGroup(String groupName, int deviceTypeId, int tenantId) throws GroupManagementDAOException;
}

@ -1584,4 +1584,37 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
throw new GroupManagementDAOException(msg, e);
}
}
@Override
public int getDeviceCountWithGroup(String groupName, int deviceTypeId, int tenantId) throws GroupManagementDAOException {
int deviceCount = 0;
try {
Connection connection = GroupManagementDAOFactory.getConnection();
String sql = "SELECT COUNT(e.ID) AS COUNT " +
"FROM DM_GROUP d " +
"INNER JOIN DM_DEVICE_GROUP_MAP m ON d.ID = m.GROUP_ID " +
"INNER JOIN DM_ENROLMENT e ON m.DEVICE_ID = e.DEVICE_ID " +
"INNER JOIN DM_DEVICE r ON e.DEVICE_ID = r.ID " +
"WHERE d.TENANT_ID = ? " +
"AND d.GROUP_NAME = ? " +
"AND r.DEVICE_TYPE_ID = ? " +
"AND e.STATUS NOT IN ('REMOVED', 'DELETED')";
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
preparedStatement.setInt(1, tenantId);
preparedStatement.setString(2, groupName);
preparedStatement.setInt(3, deviceTypeId);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
deviceCount = resultSet.getInt("COUNT");
}
}
}
return deviceCount;
} catch (SQLException e) {
String msg = "Error occurred while retrieving device count for the group: " + groupName;
log.error(msg, e);
throw new GroupManagementDAOException(msg, e);
}
}
}

@ -250,11 +250,11 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
try {
Connection conn = getConnection();
String sql = "SELECT d.ID AS DEVICE_ID, " +
"DEVICE_IDENTIFICATION, " +
"d.DEVICE_IDENTIFICATION, " +
"DESCRIPTION, " +
"NAME, " +
"DATE_OF_ENROLMENT, " +
"LAST_UPDATED_TIMESTAMP, " +
"d.LAST_UPDATED_TIMESTAMP, " +
"STATUS, " +
"DATE_OF_LAST_UPDATE, " +
"TIMESTAMPDIFF(DAY, ?, DATE_OF_ENROLMENT) as DAYS_SINCE_ENROLLED " +
@ -291,12 +291,12 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
try {
conn = this.getConnection();
String sql = "select d.ID AS DEVICE_ID, " +
"DEVICE_IDENTIFICATION, " +
"d.DEVICE_IDENTIFICATION, " +
"DESCRIPTION, " +
"NAME, " +
"DATE_OF_ENROLMENT, " +
"DATE_OF_LAST_UPDATE, " +
"d1.LAST_UPDATED_TIMESTAMP, " +
"d.LAST_UPDATED_TIMESTAMP, " +
"STATUS, " +
"TIMESTAMPDIFF(DAY, DATE_OF_LAST_UPDATE, DATE_OF_ENROLMENT) AS DAYS_USED " +
"from DM_DEVICE d, DM_ENROLMENT e " +
@ -336,11 +336,11 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
try {
conn = this.getConnection();
String sql = "select d.ID AS DEVICE_ID, " +
"DEVICE_IDENTIFICATION, " +
"d.DEVICE_IDENTIFICATION, " +
"DESCRIPTION, " +
"NAME, " +
"DATE_OF_ENROLMENT, " +
"LAST_UPDATED_TIMESTAMP, " +
"d.LAST_UPDATED_TIMESTAMP, " +
"STATUS, " +
"DATE_OF_LAST_UPDATE, " +
"TIMESTAMPDIFF(DAY, ?, ?) as DAYS_SINCE_ENROLLED " +
@ -377,12 +377,12 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
try {
conn = this.getConnection();
String sql = "select d.ID AS DEVICE_ID, " +
"DEVICE_IDENTIFICATION, " +
"d.DEVICE_IDENTIFICATION, " +
"DESCRIPTION, " +
"NAME, " +
"DATE_OF_ENROLMENT, " +
"DATE_OF_LAST_UPDATE, " +
"LAST_UPDATED_TIMESTAMP, " +
"d.LAST_UPDATED_TIMESTAMP, " +
"STATUS, " +
"TIMESTAMPDIFF(DAY, DATE_OF_LAST_UPDATE, ?) AS DAYS_USED " +
"from DM_DEVICE d, DM_ENROLMENT e " +
@ -425,9 +425,9 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
conn = this.getConnection();
String sql = "SELECT " +
"DM_DEVICE.ID AS DEVICE_ID, " +
"DEVICE_IDENTIFICATION, " +
"d.DEVICE_IDENTIFICATION, " +
"DESCRIPTION, " +
"LAST_UPDATED_TIMESTAMP, " +
"d.LAST_UPDATED_TIMESTAMP, " +
"DM_DEVICE.NAME AS DEVICE_NAME, " +
"DEVICE_TYPE, " +
"DM_ENROLMENT.ID AS ENROLMENT_ID, " +
@ -1365,7 +1365,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
query += " AND i.VALUE_FIELD LIKE ?" ;
}
if (user != null && !user.isEmpty()) {
query += " AND e.OWNER = ?";
query += " AND e.OWNER LIKE ?";
isOwnerProvided = true;
}
if (status != null && !status.isEmpty()) {
@ -1395,7 +1395,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString());
ps.setString(index++, EnrolmentInfo.Status.DELETED.toString());
if (isDeviceNameProvided) {
ps.setString(index++, name + "%");
ps.setString(index++, "%" + name + "%");
}
if (isOwnershipProvided) {
ps.setString(index++, ownership);
@ -1404,7 +1404,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
ps.setString(index++, "%" + serial + "%");
}
if (isOwnerProvided) {
ps.setString(index++, user);
ps.setString(index++, "%" + user + "%");
}
if (isStatusProvided) {
for (String deviceStatus : status) {

@ -1105,7 +1105,7 @@ public class PostgreSQLDeviceDAOImpl extends GenericDeviceDAOImpl {
isOwnershipProvided = true;
}
if (user != null && !user.isEmpty()) {
query += " AND e.OWNER = ?";
query += " AND e.OWNER LIKE ?";
isOwnerProvided = true;
}
if (status != null && !status.isEmpty()) {
@ -1136,13 +1136,13 @@ public class PostgreSQLDeviceDAOImpl extends GenericDeviceDAOImpl {
ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString());
ps.setString(index++, EnrolmentInfo.Status.DELETED.toString());
if (isDeviceNameProvided) {
ps.setString(index++, name + "%");
ps.setString(index++, "%" + name + "%");
}
if (isOwnershipProvided) {
ps.setString(index++, ownership);
}
if (isOwnerProvided) {
ps.setString(index++, user);
ps.setString(index++, "%" + user + "%");
}
if (isStatusProvided) {
for (String deviceStatus : status) {

@ -977,7 +977,7 @@ public class SQLServerDeviceDAOImpl extends GenericDeviceDAOImpl {
isOwnershipProvided = true;
}
if (user != null && !user.isEmpty()) {
query += " AND e.OWNER = ?";
query += " AND e.OWNER LIKE ?";
isOwnerProvided = true;
}
if (status != null && !status.isEmpty()) {
@ -1008,13 +1008,13 @@ public class SQLServerDeviceDAOImpl extends GenericDeviceDAOImpl {
ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString());
ps.setString(index++, EnrolmentInfo.Status.DELETED.toString());
if (isDeviceNameProvided) {
ps.setString(index++, name + "%");
ps.setString(index++, "%" + name + "%");
}
if (isOwnershipProvided) {
ps.setString(index++, ownership);
}
if (isOwnerProvided) {
ps.setString(index++, user);
ps.setString(index++, "%" + user + "%");
}
if (isStatusProvided) {
for (String deviceStatus : status) {

@ -100,6 +100,7 @@ public class DeviceManagementDataHolder {
private DeviceStatusManagementService deviceStatusManagementService;
private APIApplicationServices apiApplicationServices;
private PublisherRESTAPIServices publisherRESTAPIServices;
private DeviceManagementStartupHandler deviceManagementStartupHandler;
private final Map<DeviceType, DeviceStatusTaskPluginConfig> deviceStatusTaskPluginConfigs = Collections.synchronizedMap(
new HashMap<>());
@ -457,4 +458,12 @@ public class DeviceManagementDataHolder {
public void setGroupAccessAuthorizationService(GroupAccessAuthorizationService groupAccessAuthorizationService) {
this.groupAccessAuthorizationService = groupAccessAuthorizationService;
}
public DeviceManagementStartupHandler getDeviceManagementStartupHandler() {
return deviceManagementStartupHandler;
}
public void setDeviceManagementStartupHandler(DeviceManagementStartupHandler deviceManagementStartupHandler) {
this.deviceManagementStartupHandler = deviceManagementStartupHandler;
}
}

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.device.mgt.core.internal;
import io.entgra.device.mgt.core.device.mgt.common.authorization.GroupAccessAuthorizationService;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.device.mgt.core.authorization.GroupAccessAuthorizationServiceImpl;
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.DeviceStatusManagementServiceImpl;
@ -259,8 +260,10 @@ public class DeviceManagementServiceComponent {
TenantCreateObserver listener = new TenantCreateObserver();
bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), listener, null);
UserRoleCreateObserver userRoleCreateObserver = new UserRoleCreateObserver();
bundleContext.registerService(ServerStartupObserver.class.getName(), userRoleCreateObserver, null);
/* Registering Device Management Startup Handler */
DeviceManagementStartupHandler deviceManagementStartupHandler = new DeviceManagementStartupHandler();
DeviceManagementDataHolder.getInstance().setDeviceManagementStartupHandler(deviceManagementStartupHandler);
bundleContext.registerService(ServerStartupObserver.class.getName(), deviceManagementStartupHandler, null);
/* Registering Device Management Service */
DeviceManagementProviderService deviceManagementProvider = new DeviceManagementProviderServiceImpl();
@ -333,26 +336,25 @@ public class DeviceManagementServiceComponent {
bundleContext.registerService(MetadataManagementService.class.getName(), metadataManagementService, null);
/* Registering Whitelabel Service */
try {
WhiteLabelManagementService whiteLabelManagementService = new WhiteLabelManagementServiceImpl();
DeviceManagementDataHolder.getInstance().setWhiteLabelManagementService(whiteLabelManagementService);
try {
whiteLabelManagementService.addDefaultWhiteLabelThemeIfNotExist(tenantId);
} catch (Throwable e) {
log.error("Error occurred while adding default tenant white label theme", e);
}
bundleContext.registerService(WhiteLabelManagementService.class.getName(), whiteLabelManagementService, null);
} catch (MetadataManagementException e) {
log.error("Error occurred while initializing the white label management service", e);
}
/* Registering DeviceState Filter Service */
DeviceStatusManagementService deviceStatusManagemntService = new DeviceStatusManagementServiceImpl();
DeviceManagementDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagemntService);
DeviceStatusManagementService deviceStatusManagementService = new DeviceStatusManagementServiceImpl();
DeviceManagementDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagementService);
try {
deviceStatusManagemntService.addDefaultDeviceStatusFilterIfNotExist(tenantId);
deviceStatusManagementService.addDefaultDeviceStatusFilterIfNotExist(tenantId);
} catch (Throwable e) {
log.error("Error occurred while adding default tenant device status", e);
}
bundleContext.registerService(DeviceStatusManagementService.class.getName(), deviceStatusManagemntService, null);
bundleContext.registerService(DeviceStatusManagementService.class.getName(), deviceStatusManagementService, null);
/* Registering Event Configuration Service */
EventConfigurationProviderService eventConfigurationService = new EventConfigurationProviderServiceImpl();

@ -0,0 +1,149 @@
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.internal;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
import io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.dto.OperationConfig;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationDAO;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.core.ServerStartupObserver;
import org.wso2.carbon.user.api.AuthorizationManager;
import org.wso2.carbon.user.api.Permission;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
public class DeviceManagementStartupHandler implements ServerStartupObserver {
private static final Log log = LogFactory.getLog(DeviceManagementStartupHandler.class);
private static final Gson gson = new Gson();
private static final String OPERATION_CONFIG = "OPERATION_CONFIG";
private static final String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
@Override
public void completingServerStartup() {
}
@Override
public void completedServerStartup() {
userRoleCreateObserver();
operationStatusChangeObserver();
}
private void userRoleCreateObserver() {
try {
UserStoreManager userStoreManager =
DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
MultitenantConstants.SUPER_TENANT_ID).getUserStoreManager();
String tenantAdminName =
DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
MultitenantConstants.SUPER_TENANT_ID).getRealmConfiguration().getAdminUserName();
AuthorizationManager authorizationManager = DeviceManagementDataHolder.getInstance().getRealmService()
.getTenantUserRealm(MultitenantConstants.SUPER_TENANT_ID).getAuthorizationManager();
if (!userStoreManager.isExistingRole(DeviceManagementConstants.User.DEFAULT_DEVICE_ADMIN)) {
userStoreManager.addRole(
DeviceManagementConstants.User.DEFAULT_DEVICE_ADMIN,
null,
DeviceManagementConstants.User.PERMISSIONS_FOR_DEVICE_ADMIN);
} else {
for (Permission permission : DeviceManagementConstants.User.PERMISSIONS_FOR_DEVICE_ADMIN) {
authorizationManager.authorizeRole(DeviceManagementConstants.User.DEFAULT_DEVICE_ADMIN,
permission.getResourceId(), permission.getAction());
}
}
if (!userStoreManager.isExistingRole(DeviceManagementConstants.User.DEFAULT_DEVICE_USER)) {
userStoreManager.addRole(
DeviceManagementConstants.User.DEFAULT_DEVICE_USER,
null,
DeviceManagementConstants.User.PERMISSIONS_FOR_DEVICE_USER);
} else {
for (Permission permission : DeviceManagementConstants.User.PERMISSIONS_FOR_DEVICE_USER) {
authorizationManager.authorizeRole(DeviceManagementConstants.User.DEFAULT_DEVICE_USER,
permission.getResourceId(), permission.getAction());
}
}
userStoreManager.updateRoleListOfUser(tenantAdminName, null,
new String[]{DeviceManagementConstants.User.DEFAULT_DEVICE_ADMIN,
DeviceManagementConstants.User.DEFAULT_DEVICE_USER});
if (log.isDebugEnabled()) {
log.debug("Device management roles: " + DeviceManagementConstants.User.DEFAULT_DEVICE_USER + ", " +
DeviceManagementConstants.User.DEFAULT_DEVICE_ADMIN + " created for the tenant:" + tenantDomain + "."
);
log.debug("Tenant administrator: " + tenantAdminName + "@" + tenantDomain +
" is assigned to the role:" + DeviceManagementConstants.User.DEFAULT_DEVICE_ADMIN + "."
);
}
} catch (UserStoreException e) {
log.error("Error occurred while creating roles for the tenant: " + tenantDomain + ".");
}
}
private void operationStatusChangeObserver () {
MetadataManagementService metadataManagementService = DeviceManagementDataHolder
.getInstance().getMetadataManagementService();
OperationDAO operationDAO = OperationManagementDAOFactory.getOperationDAO();
Metadata metadata;
int numOfRecordsUpdated;
try {
metadata = metadataManagementService.retrieveMetadata(OPERATION_CONFIG);
if (metadata != null) {
OperationConfig operationConfiguration = gson.fromJson(metadata.getMetaValue(), OperationConfig.class);
String[] deviceTypes = operationConfiguration.getDeviceTypes();
String initialOperationStatus = operationConfiguration.getInitialOperationStatus();
String requiredStatusChange = operationConfiguration.getRequiredStatusChange();
for (String deviceType : deviceTypes) {
try {
OperationManagementDAOFactory.beginTransaction();
try {
numOfRecordsUpdated = operationDAO.updateOperationByDeviceTypeAndInitialStatus(deviceType,
initialOperationStatus, requiredStatusChange);
log.info(numOfRecordsUpdated + " operations updated successfully for the" + deviceType);
OperationManagementDAOFactory.commitTransaction();
} catch (OperationManagementDAOException e) {
OperationManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while updating operation status. DeviceType : " + deviceType + ", " +
"Initial operation status: " + initialOperationStatus + ", Required status:" + requiredStatusChange;
log.error(msg, e);
}
} catch (TransactionManagementException e) {
String msg = "Transactional error occurred while updating the operation status";
log.error(msg, e);
} finally {
OperationManagementDAOFactory.closeConnection();
}
}
} else {
log.info("Operation configuration not provided");
}
} catch (MetadataManagementException e) {
String msg = "Error occurred while retrieving the operation configuration";
log.error(msg, e);
}
}
}

@ -1,89 +0,0 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.internal;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.core.ServerStartupObserver;
import org.wso2.carbon.user.api.AuthorizationManager;
import org.wso2.carbon.user.api.Permission;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
public class UserRoleCreateObserver implements ServerStartupObserver {
private static final Log log = LogFactory.getLog(UserRoleCreateObserver.class);
@Override
public void completingServerStartup() {
}
@Override
public void completedServerStartup() {
String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
try {
UserStoreManager userStoreManager =
DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
MultitenantConstants.SUPER_TENANT_ID).getUserStoreManager();
String tenantAdminName =
DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
MultitenantConstants.SUPER_TENANT_ID).getRealmConfiguration().getAdminUserName();
AuthorizationManager authorizationManager = DeviceManagementDataHolder.getInstance().getRealmService()
.getTenantUserRealm(MultitenantConstants.SUPER_TENANT_ID).getAuthorizationManager();
if (!userStoreManager.isExistingRole(DeviceManagementConstants.User.DEFAULT_DEVICE_ADMIN)) {
userStoreManager.addRole(
DeviceManagementConstants.User.DEFAULT_DEVICE_ADMIN,
null,
DeviceManagementConstants.User.PERMISSIONS_FOR_DEVICE_ADMIN);
} else {
for (Permission permission : DeviceManagementConstants.User.PERMISSIONS_FOR_DEVICE_ADMIN) {
authorizationManager.authorizeRole(DeviceManagementConstants.User.DEFAULT_DEVICE_ADMIN,
permission.getResourceId(), permission.getAction());
}
}
if (!userStoreManager.isExistingRole(DeviceManagementConstants.User.DEFAULT_DEVICE_USER)) {
userStoreManager.addRole(
DeviceManagementConstants.User.DEFAULT_DEVICE_USER,
null,
DeviceManagementConstants.User.PERMISSIONS_FOR_DEVICE_USER);
} else {
for (Permission permission : DeviceManagementConstants.User.PERMISSIONS_FOR_DEVICE_USER) {
authorizationManager.authorizeRole(DeviceManagementConstants.User.DEFAULT_DEVICE_USER,
permission.getResourceId(), permission.getAction());
}
}
userStoreManager.updateRoleListOfUser(tenantAdminName, null,
new String[] {DeviceManagementConstants.User.DEFAULT_DEVICE_ADMIN,
DeviceManagementConstants.User.DEFAULT_DEVICE_USER});
if (log.isDebugEnabled()) {
log.debug("Device management roles: " + DeviceManagementConstants.User.DEFAULT_DEVICE_USER + ", " +
DeviceManagementConstants.User.DEFAULT_DEVICE_ADMIN + " created for the tenant:" + tenantDomain + "."
);
log.debug("Tenant administrator: " + tenantAdminName + "@" + tenantDomain +
" is assigned to the role:" + DeviceManagementConstants.User.DEFAULT_DEVICE_ADMIN + "."
);
}
} catch (UserStoreException e) {
log.error("Error occurred while creating roles for the tenant: " + tenantDomain + ".");
}
}
}

@ -21,6 +21,7 @@ package io.entgra.device.mgt.core.device.mgt.core.metadata.mgt;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataKeyNotFoundException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.AllowedDeviceStatus;
@ -35,6 +36,7 @@ import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataManage
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.util.MetadataConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import java.lang.reflect.Type;
import java.sql.SQLException;
@ -42,12 +44,12 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class DeviceStatusManagementServiceImpl implements DeviceStatusManagementService {
private static final Log log = LogFactory.getLog(DeviceStatusManagementServiceImpl.class);
private final MetadataDAO metadataDAO;
private static final Gson gson = new Gson();
public DeviceStatusManagementServiceImpl() {
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
@ -57,12 +59,11 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
public void addDefaultDeviceStatusFilterIfNotExist(int tenantId) throws MetadataManagementException {
try {
MetadataManagementDAOFactory.beginTransaction();
if (!metadataDAO.isExist(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY) && !metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) {
Metadata defaultDeviceStatusMetadata = constructDeviceStatusMetadata(getDefaultDeviceStatus());
Metadata defaultDeviceStatusCheckMetadata = constructDeviceStatusCheckMetadata(getDefaultDeviceStatusCheck());
// Add default device status and device status check metadata entries
addMetadataEntry(tenantId, defaultDeviceStatusMetadata, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
addMetadataEntry(tenantId, defaultDeviceStatusCheckMetadata, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
if (!metadataDAO.isExist(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY)) {
metadataDAO.addMetadata(tenantId, constructDeviceStatusMetadata(getDefaultDeviceStatus()));
}
if (!metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) {
metadataDAO.addMetadata(tenantId, constructDeviceStatusCheckMetadata(getDefaultDeviceStatusCheck()));
}
MetadataManagementDAOFactory.commitTransaction();
} catch (MetadataManagementDAOException e) {
@ -80,18 +81,38 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
}
@Override
public void resetToDefaultDeviceStausFilter() throws MetadataManagementException {
public void resetToDefaultDeviceStatusFilter() throws MetadataManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
MetadataManagementDAOFactory.beginTransaction();
Metadata defaultDeviceStatusMetadata = constructDeviceStatusMetadata(getDefaultDeviceStatus());
Metadata defaultDeviceStatusCheckMetadata = constructDeviceStatusCheckMetadata(getDefaultDeviceStatusCheck());
// Add default device status and device status check metadata entries
metadataDAO.addMetadata(tenantId, defaultDeviceStatusMetadata);
metadataDAO.addMetadata(tenantId, defaultDeviceStatusCheckMetadata);
MetadataManagementDAOFactory.commitTransaction();
} catch (MetadataManagementDAOException e) {
MetadataManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while inserting default device status metadata entries.";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while starting the transaction to reset default device status filters.";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
}
}
@Override
public void updateDefaultDeviceStatusFilters(int tenantId, String deviceType, List<String> deviceStatus) throws MetadataManagementException {
public void updateDefaultDeviceStatusFilters(String deviceType, List<String> deviceStatus) throws MetadataManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
MetadataManagementDAOFactory.beginTransaction();
// Retrieve the current device status metadata
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
if (metadata != null) {
Gson gson = new Gson();
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
}.getType();
List<AllowedDeviceStatus> currentStatusList = gson.fromJson(metadata.getMetaValue(), listType);
@ -105,7 +126,7 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
}
}
metadata.setMetaValue(gson.toJson(currentStatusList));
updateMetadataEntry(tenantId, metadata, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
metadataDAO.updateMetadata(tenantId, metadata);
}
MetadataManagementDAOFactory.commitTransaction();
} catch (MetadataManagementDAOException e) {
@ -123,17 +144,16 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
}
@Override
public boolean updateDefaultDeviceStatusCheck(int tenantId, boolean isChecked) throws MetadataManagementException {
boolean success = false;
public boolean updateDefaultDeviceStatusCheck(boolean isChecked) throws MetadataManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
MetadataManagementDAOFactory.beginTransaction();
if (metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) {
Metadata isDeviceStatusChecked = constructDeviceStatusCheckMetadata(isChecked);
// Add default device status check metadata entries
updateMetadataEntry(tenantId, isDeviceStatusChecked, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
success = true;
}
metadataDAO.updateMetadata(tenantId, constructDeviceStatusCheckMetadata(isChecked));
MetadataManagementDAOFactory.commitTransaction();
return true;
}
} catch (MetadataManagementDAOException e) {
MetadataManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while updating device status check metadata entry.";
@ -146,19 +166,24 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
} finally {
MetadataManagementDAOFactory.closeConnection();
}
return success;
return false;
}
@Override
public List<AllowedDeviceStatus> getDeviceStatusFilters(int tenantId) throws MetadataManagementException {
public List<AllowedDeviceStatus> getDeviceStatusFilters() throws MetadataManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
Gson gson = new Gson();
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {}.getType();
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
return statusList;
if (metadata == null) {
String msg =
"Couldn't find the meta data value for meta key: " + MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY;
log.error(msg);
throw new MetadataKeyNotFoundException(msg);
}
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
}.getType();
return gson.fromJson(metadata.getMetaValue(), listType);
} catch (MetadataManagementDAOException e) {
String msg = "Error occurred while retrieving device status meta data for tenant:" + tenantId;
log.error(msg, e);
@ -173,12 +198,19 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
}
public List<String> getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException {
public List<String> getDeviceStatusFilters(String deviceType) throws MetadataManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
Gson gson = new Gson();
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {}.getType();
if (metadata == null) {
String msg = "Couldn't find the meta details of meta Key: "
+ MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY + " and tenant Id: " + tenantId;
log.error(msg);
throw new MetadataKeyNotFoundException(msg);
}
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
}.getType();
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
for (AllowedDeviceStatus status : statusList) {
@ -207,6 +239,12 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
try {
MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
if (metadata == null) {
String msg = "Couldn't find the meta data value for meta key: "
+ MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY + " and tenant Id: " + tenantId;
log.error(msg);
throw new MetadataKeyNotFoundException(msg);
}
String metaValue = metadata.getMetaValue();
return Boolean.parseBoolean(metaValue);
} catch (MetadataManagementDAOException e) {
@ -227,8 +265,13 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
try {
MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
if (metadata == null) {
String msg = "Couldn't find the meta data value for meta key: "
+ MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY + " and tenant Id: " + tenantId;
log.error(msg);
throw new MetadataKeyNotFoundException(msg);
}
Gson gson = new Gson();
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
}.getType();
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
@ -254,22 +297,13 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
}
}
private void addMetadataEntry(int tenantId, Metadata metadata, String key) throws MetadataManagementDAOException {
metadataDAO.addMetadata(tenantId, metadata);
if (log.isDebugEnabled()) {
log.debug(key + " metadata entry has been inserted successfully");
}
}
private void updateMetadataEntry(int tenantId, Metadata metadata, String key) throws MetadataManagementDAOException {
metadataDAO.updateMetadata(tenantId, metadata);
if (log.isDebugEnabled()) {
log.debug(key + " metadata entry has been updated successfully");
}
}
/**
* To construct device status Meta data by using received device status items
*
* @param deviceStatusItems {@link List<DeviceStatusItem>}
* @return {@link Metadata}
*/
private Metadata constructDeviceStatusMetadata(List<DeviceStatusItem> deviceStatusItems) {
Gson gson = new Gson();
String deviceStatusItemsJsonString = gson.toJson(deviceStatusItems);
Metadata metadata = new Metadata();
@ -279,6 +313,12 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
return metadata;
}
/**
* To construct device status check Meta data to either enable it or disable it.
*
* @param deviceStatusCheck True or False
* @return {@link Metadata}
*/
private Metadata constructDeviceStatusCheckMetadata(boolean deviceStatusCheck) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("deviceStatusCheck", String.valueOf(deviceStatusCheck));
@ -289,6 +329,11 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
return metadata;
}
/**
* Get default list of device status items from the configuration.
*
* @return List of device status items
*/
private List<DeviceStatusItem> getDefaultDeviceStatus() {
DeviceStatusConfigurations deviceStatusConfigurations = UIConfigurationManager.getInstance().getUIConfig().getDeviceStatusConfigurations();
List<DeviceStatusItem> deviceStatusItems = new ArrayList<>();
@ -305,6 +350,11 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
return deviceStatusItems;
}
/**
* Get Default device status check from the configuration.
*
* @return default status check value, it will be either 'True' or 'False'
*/
private boolean getDefaultDeviceStatusCheck() {
DeviceStatusConfigurations deviceStatusConfigurations = UIConfigurationManager.getInstance().getUIConfig().getDeviceStatusConfigurations();
boolean deviceStatusCheck = false;

@ -60,8 +60,53 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
private final MetadataDAO metadataDAO;
public WhiteLabelManagementServiceImpl() {
public WhiteLabelManagementServiceImpl() throws MetadataManagementException {
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
initializeWhiteLabelThemes();
}
/**
* Initializes white label theme for a tenant by retrieving white label metadata and updating it if necessary.
* If the white label metadata is found and the DocUrl is missing,it updates the metadata with the default value
* for DocUrl.
*
* @throws MetadataManagementException if an error occurs while managing metadata or transactions.
*/
private void initializeWhiteLabelThemes() throws MetadataManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
WhiteLabelTheme defaultTheme = getDefaultWhiteLabelTheme();
Metadata whiteLabelMetadata = getWhiteLabelMetaData(tenantId);
if (whiteLabelMetadata != null) {
WhiteLabelTheme whiteLabelTheme = new Gson().fromJson(whiteLabelMetadata.getMetaValue(),
WhiteLabelTheme.class);
if (whiteLabelTheme.getDocUrl() == null) {
whiteLabelTheme.setDocUrl(defaultTheme.getDocUrl());
Metadata updatedMetadata = constructWhiteLabelThemeMetadata(whiteLabelTheme);
try {
MetadataManagementDAOFactory.beginTransaction();
metadataDAO.updateMetadata(tenantId, updatedMetadata);
MetadataManagementDAOFactory.commitTransaction();
if (log.isDebugEnabled()) {
log.debug("WhiteLabel theme's DocUrl was missing and has been updated to the default value " +
"for tenant: " + tenantId);
}
} catch (MetadataManagementDAOException e) {
MetadataManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while fetching white label metadata for tenant: " + tenantId;
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Transaction failed while updating white label theme for tenant: "
+ tenantId;
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
}
}
} else {
addDefaultWhiteLabelThemeIfNotExist(tenantId);
}
}
@Override
@ -128,7 +173,7 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
*/
private FileResponse getImageFileResponseFromUrl(String url) throws IOException, NotFoundException {
FileResponse fileResponse = new FileResponse();
try(CloseableHttpClient client = HttpClients.createDefault()) {
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpGet imageGetRequest = new HttpGet(url);
HttpResponse response = client.execute(imageGetRequest);
InputStream imageStream = response.getEntity().getContent();
@ -183,6 +228,16 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
WhiteLabelStorageUtil.deleteWhiteLabelImageForTenantIfExists(tenantId);
}
/**
* Get default metaDataConfiguration DocUrl from config
*/
private String getDefaultDocUrl() {
MetaDataConfiguration metaDataConfiguration = DeviceConfigurationManager.getInstance().
getDeviceManagementConfig().getMetaDataConfiguration();
WhiteLabelConfiguration whiteLabelConfiguration = metaDataConfiguration.getWhiteLabelConfiguration();
return whiteLabelConfiguration.getDocUrl();
}
/**
* Construct and return default whitelabel detail bean {@link WhiteLabelImage}
*/
@ -193,11 +248,13 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
WhiteLabelImage logo = constructDefaultLogoImage();
WhiteLabelImage logoIcon = constructDefaultLogoIconImage();
WhiteLabelTheme defaultTheme = new WhiteLabelTheme();
String docUrl = getDefaultDocUrl();
defaultTheme.setFooterText(footerText);
defaultTheme.setAppTitle(appTitle);
defaultTheme.setLogoImage(logo);
defaultTheme.setLogoIconImage(logoIcon);
defaultTheme.setFaviconImage(favicon);
defaultTheme.setDocUrl(docUrl);
return defaultTheme;
}
@ -386,6 +443,7 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
whiteLabelTheme.setLogoIconImage(logoIconImage);
whiteLabelTheme.setFooterText(whiteLabelThemeCreateRequest.getFooterText());
whiteLabelTheme.setAppTitle(whiteLabelThemeCreateRequest.getAppTitle());
whiteLabelTheme.setDocUrl(whiteLabelThemeCreateRequest.getDocUrl());
return whiteLabelTheme;
}
@ -418,6 +476,38 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
return metadata;
}
/**
* updates the given WhiteLabelTheme with default value for docUrl
*
* @param whiteLabelTheme the WhiteLabelTheme to be updated with defaults if necessary.
* @param tenantId the ID of the tenant whose metadata is being updated.
* @throws MetadataManagementException exception for an error occurs during the update or transaction commit.
*/
private void updateWhiteLabelThemeWithDefaults(WhiteLabelTheme whiteLabelTheme, int tenantId)
throws MetadataManagementException {
WhiteLabelTheme defaultTheme = getDefaultWhiteLabelTheme();
if (whiteLabelTheme.getDocUrl() == null) {
whiteLabelTheme.setDocUrl(defaultTheme.getDocUrl());
}
Metadata updatedMetadata = constructWhiteLabelThemeMetadata(whiteLabelTheme);
try {
MetadataManagementDAOFactory.beginTransaction();
metadataDAO.updateMetadata(tenantId, updatedMetadata);
MetadataManagementDAOFactory.commitTransaction();
} catch (MetadataManagementDAOException e) {
MetadataManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while updating metadata for tenant: " + tenantId;
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while committing the transaction for tenant: " + tenantId;
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
}
}
@Override
public WhiteLabelTheme getWhiteLabelTheme(String tenantDomain) throws MetadataManagementException, DeviceManagementException {
int tenantId = DeviceManagerUtil.getTenantId(tenantDomain);
@ -435,17 +525,22 @@ public class WhiteLabelManagementServiceImpl implements WhiteLabelManagementServ
throw new MetadataManagementException(msg);
}
}
return new Gson().fromJson(metadata.getMetaValue(), WhiteLabelTheme.class);
WhiteLabelTheme whiteLabelTheme = new Gson().fromJson(metadata.getMetaValue(), WhiteLabelTheme.class);
if (whiteLabelTheme.getDocUrl() == null) {
updateWhiteLabelThemeWithDefaults(whiteLabelTheme, tenantId);
}
return whiteLabelTheme;
}
/**
* Load White label Meta Data for given tenant Id.
*
* @param tenantId Id of the tenant
* @return {@link Metadata}
* @throws MetadataManagementException if an error occurred while getting Meta-Data info from Database for a
* given tenant ID.
*/
private Metadata getWhiteLabelMetaData (int tenantId) throws MetadataManagementException {
private Metadata getWhiteLabelMetaData(int tenantId) throws MetadataManagementException {
try {
MetadataManagementDAOFactory.openConnection();
return metadataDAO.getMetadata(tenantId, MetadataConstants.WHITELABEL_META_KEY);

@ -0,0 +1,113 @@
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataKeyAlreadyExistsException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataKeyNotFoundException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder;
import io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.dto.OperationConfig;
import io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.exceptions.OperationConfigAlreadyExistsException;
import io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.exceptions.OperationConfigException;
import io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.exceptions.OperationConfigNotFoundException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class OperationConfigurationService {
private static final Log log = LogFactory.getLog(OperationConfigurationService.class);
private static final Gson gson = new Gson();
private static final String STRING = "STRING";
private static final String OPERATION_CONFIG = "OPERATION_CONFIG";
static MetadataManagementService metadataManagementService = DeviceManagementDataHolder.getInstance().getMetadataManagementService();
public static OperationConfig getOperationConfig() throws OperationConfigException {
Metadata metadata;
try {
metadata = metadataManagementService.retrieveMetadata(OPERATION_CONFIG);
} catch (MetadataManagementException e) {
String msg = "Error occurred while retrieving operation configuration";
log.error(msg, e);
throw new OperationConfigException(msg, e);
}
if (metadata != null) {
return gson.fromJson(metadata.getMetaValue(), OperationConfig.class);
} else {
return null;
}
}
public static void addOperationConfiguration(OperationConfig config) throws OperationConfigException,
OperationConfigAlreadyExistsException {
Metadata metadata = new Metadata();
metadata.setDataType(STRING);
metadata.setMetaKey(OPERATION_CONFIG);
metadata.setMetaValue(gson.toJson(config));
try {
metadataManagementService.createMetadata(metadata);
} catch (MetadataKeyAlreadyExistsException e) {
String msg = "Operation configuration already exists";
log.error(msg, e);
throw new OperationConfigAlreadyExistsException(msg, e);
} catch (MetadataManagementException e) {
String msg = "Error occurred while adding operation configuration";
log.error(msg, e);
throw new OperationConfigException(msg, e);
}
}
public static void updateOperationConfiguration(OperationConfig config) throws OperationConfigException {
Metadata metadata = new Metadata();
metadata.setDataType(STRING);
metadata.setMetaKey(OPERATION_CONFIG);
metadata.setMetaValue(gson.toJson(config));
try {
metadataManagementService.updateMetadata(metadata);
} catch (MetadataManagementException e) {
String msg = "Error occurred while updating operation configuration";
log.error(msg, e);
throw new OperationConfigException(msg, e);
}
}
public static void deleteOperationConfiguration() throws OperationConfigException, OperationConfigNotFoundException {
try {
metadataManagementService.deleteMetadata(OPERATION_CONFIG);
} catch (MetadataKeyNotFoundException e) {
String msg = "Operation configuration already exists";
log.error(msg, e);
throw new OperationConfigNotFoundException(msg, e);
} catch (MetadataManagementException e) {
String msg = "Error occurred while deleting operation configuration";
log.error(msg, e);
throw new OperationConfigException(msg, e);
}
}
}

@ -0,0 +1,55 @@
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.dto;
/**
* DTO for Operation configuration.
*/
public class OperationConfig {
private String[] deviceTypes;
private String initialOperationStatus;
private String requiredStatusChange;
public String[] getDeviceTypes() {
return deviceTypes;
}
public void setDeviceTypes(String[] deviceTypes) {
this.deviceTypes = deviceTypes;
}
public String getInitialOperationStatus() {
return initialOperationStatus;
}
public void setInitialOperationStatus(String initialOperationStatus) {
this.initialOperationStatus = initialOperationStatus;
}
public String getRequiredStatusChange() {
return requiredStatusChange;
}
public void setRequiredStatusChange(String requiredStatusChange) {
this.requiredStatusChange = requiredStatusChange;
}
}

@ -0,0 +1,60 @@
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.exceptions;
/**
* Custom exception class to be used in operation configuration service related functionalities.
*/
public class OperationConfigAlreadyExistsException extends Exception {
private static final long serialVersionUID = -1814347544027733436L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public OperationConfigAlreadyExistsException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public OperationConfigAlreadyExistsException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public OperationConfigAlreadyExistsException(String msg) {
super(msg);
setErrorMessage(msg);
}
public OperationConfigAlreadyExistsException() {
super();
}
public OperationConfigAlreadyExistsException(Throwable cause) {
super(cause);
}
}

@ -0,0 +1,60 @@
/*
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.exceptions;
/**
* Custom exception class to be used in operation configuration related functionalities.
*/
public class OperationConfigException extends Exception {
private static final long serialVersionUID = -8933146283800122661L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public OperationConfigException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public OperationConfigException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public OperationConfigException(String msg) {
super(msg);
setErrorMessage(msg);
}
public OperationConfigException() {
super();
}
public OperationConfigException(Throwable cause) {
super(cause);
}
}

@ -0,0 +1,60 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.core.operation.change.status.task.exceptions;
/**
* Custom exception class to be used in Operation configuration related functionalities.
*/
public class OperationConfigNotFoundException extends Exception {
private static final long serialVersionUID = 5260831982626354815L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public OperationConfigNotFoundException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public OperationConfigNotFoundException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public OperationConfigNotFoundException(String msg) {
super(msg);
setErrorMessage(msg);
}
public OperationConfigNotFoundException() {
super();
}
public OperationConfigNotFoundException(Throwable cause) {
super(cause);
}
}

@ -61,6 +61,9 @@ public interface OperationDAO {
boolean updateOperationStatus(int enrolmentId, int operationId,Operation.Status status)
throws OperationManagementDAOException;
int updateOperationByDeviceTypeAndInitialStatus(String deiceType, String initialStatus, String requiredStatus)
throws OperationManagementDAOException;
void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus,
Operation.Status newStatus) throws OperationManagementDAOException;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save