updated from master branch

remotes/1725333865317989910/tmp_refs/heads/master
Amalka Subasinghe 2 years ago
commit 541e517b46

@ -123,7 +123,6 @@
<dependency> <dependency>
<groupId>io.entgra.device.mgt.core</groupId> <groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.apimgt.extension.rest.api</artifactId> <artifactId>io.entgra.device.mgt.core.apimgt.extension.rest.api</artifactId>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.json.wso2</groupId> <groupId>org.json.wso2</groupId>

@ -517,4 +517,12 @@ public interface ApplicationManager {
String getPlistArtifact(String uuid) throws ApplicationManagementException; String getPlistArtifact(String uuid) throws ApplicationManagementException;
List<ApplicationReleaseDTO> getReleaseByPackageNames(List<String> packageIds) throws ApplicationManagementException; List<ApplicationReleaseDTO> getReleaseByPackageNames(List<String> packageIds) throws ApplicationManagementException;
/**
* @param applicationRelease {@link ApplicationRelease}
* @param oldPackageName Old package name of the application
* @throws ApplicationManagementException Application management exception
*/
void updateAppIconInfo(ApplicationRelease applicationRelease, String oldPackageName)
throws ApplicationManagementException;
} }

@ -1243,6 +1243,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
applicationDTO.setId(appId); applicationDTO.setId(appId);
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
if (applicationDTO.getType().equals("ENTERPRISE") || applicationDTO.getType().equals("PUBLIC") ) {
persistAppIconInfo(applicationReleaseDTO);
}
return APIUtil.appDtoToAppResponse(applicationDTO); return APIUtil.appDtoToAppResponse(applicationDTO);
} }
} catch (LifeCycleManagementDAOException e) { } catch (LifeCycleManagementDAOException e) {
@ -1269,6 +1272,30 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
/**
* Persist application icon information when creating an application
*
* @param applicationReleaseDTO {@link ApplicationReleaseDTO}
* @throws ApplicationManagementException if error occurred while persisting application icon information
*/
private void persistAppIconInfo(ApplicationReleaseDTO applicationReleaseDTO)
throws ApplicationManagementException {
try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String iconPath = APIUtil.createAppIconPath(applicationReleaseDTO, tenantId);
DataHolder.getInstance().getDeviceManagementService().saveApplicationIcon(iconPath,
String.valueOf(applicationReleaseDTO.getPackageName()), applicationReleaseDTO.getVersion(), tenantId);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating iconPath. Application package name : " + applicationReleaseDTO.getPackageName();
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DeviceManagementException e) {
String msg = "Error occurred while saving application icon info. Application package name : " + applicationReleaseDTO.getPackageName();
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
@Override @Override
public <T> ApplicationRelease createRelease(ApplicationDTO applicationDTO, ApplicationReleaseDTO applicationReleaseDTO, public <T> ApplicationRelease createRelease(ApplicationDTO applicationDTO, ApplicationReleaseDTO applicationReleaseDTO,
ApplicationType type, boolean isPublished) ApplicationType type, boolean isPublished)
@ -1874,6 +1901,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
break; break;
} }
} }
try {
deleteAppIconInfo(applicationDTO);
} catch (ApplicationManagementException e) {
String msg = "Error occurred while deleting application icon info. Application package name: " + applicationDTO.getPackageName();
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
} }
@Override @Override
@ -3978,4 +4012,32 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
} }
@Override
public void updateAppIconInfo(ApplicationRelease applicationRelease, String oldPackageName) throws ApplicationManagementException {
try {
DataHolder.getInstance().getDeviceManagementService().updateApplicationIcon(applicationRelease.getIconPath(),
oldPackageName, applicationRelease.getPackageName(), applicationRelease.getVersion());
} catch (DeviceManagementException e) {
String msg = "Error occurred while updating application icon info. Application package name: " + oldPackageName;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
/**
* Delete application icon information when deleting an application
*
* @param applicationDTO {@link ApplicationDTO}
* @throws ApplicationManagementException if error occurred while deleting application icon information
*/
private void deleteAppIconInfo(ApplicationDTO applicationDTO) throws ApplicationManagementException {
try {
DataHolder.getInstance().getDeviceManagementService().deleteApplicationIcon(applicationDTO.getPackageName());
} catch (DeviceManagementException e) {
String msg = "Error occurred while deleting application icon info. Application package name: " + applicationDTO.getPackageName();
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
} }

@ -503,4 +503,18 @@ public class APIUtil {
return mdmConfig.getArtifactDownloadProtocol() + "://" + host + ":" + port return mdmConfig.getArtifactDownloadProtocol() + "://" + host + ":" + port
+ artifactDownloadEndpoint + Constants.FORWARD_SLASH; + artifactDownloadEndpoint + Constants.FORWARD_SLASH;
} }
/**
* To create the application icon path.
*
* @param applicationReleaseDTO {@link ApplicationReleaseDTO}
* @param tenantId tenant ID
* @return iconPath constructed icon path.
*/
public static String createAppIconPath(ApplicationReleaseDTO applicationReleaseDTO, int tenantId) throws ApplicationManagementException {
String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH + applicationReleaseDTO
.getAppHashValue() + Constants.FORWARD_SLASH;
String iconPath = basePath + Constants.ICON_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO.getIconName();
return iconPath;
}
} }

@ -512,6 +512,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
String oldPackageName = applicationManager.getApplicationByUuid(applicationUUID).getPackageName();
applicationManager.updateAppIconInfo(applicationRelease, oldPackageName);
return Response.status(Response.Status.OK).entity(applicationRelease).build(); return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = e.getMessage(); String msg = e.getMessage();
@ -552,6 +554,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
String oldPackageName = applicationManager.getApplicationByUuid(applicationUUID).getPackageName();
applicationManager.updateAppIconInfo(applicationRelease, oldPackageName);
return Response.status(Response.Status.OK).entity(applicationRelease).build(); return Response.status(Response.Status.OK).entity(applicationRelease).build();
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = e.getMessage(); String msg = e.getMessage();

@ -898,6 +898,24 @@ public interface PolicyManagementService {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getPolicyList( Response getPolicyList(
@ApiParam(
name = "name",
value = "The name of the policy that needs filtering.",
required = false)
@QueryParam("name")
String name,
@ApiParam(
name = "type",
value = "The type of the policy that needs filtering.",
required = false)
@QueryParam("type")
String type,
@ApiParam(
name = "status",
value = "The status of the policy that needs filtering.",
required = false)
@QueryParam("status")
String status,
@ApiParam( @ApiParam(
name = "If-Modified-Since", name = "If-Modified-Since",
value = "Checks if the requested variant was modified, since the specified date-time. \n" + value = "Checks if the requested variant was modified, since the specified date-time. \n" +

@ -17,6 +17,22 @@
*/ */
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl; package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.PolicyList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.PolicyWrapper;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.PriorityUpdatedPolicyWrapper;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ProfileFeature;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.*; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.*;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.PolicyManagementService; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.PolicyManagementService;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.FilteringUtil; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.FilteringUtil;
@ -477,6 +493,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@Path("/list") @Path("/list")
@Override @Override
public Response getPolicyList( public Response getPolicyList(
@QueryParam("name") String name,
@QueryParam("type") String type,
@QueryParam("status") String status,
@HeaderParam("If-Modified-Since") String ifModifiedSince, @HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@QueryParam("limit") int limit) { @QueryParam("limit") int limit) {
@ -484,7 +503,16 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
List<Policy> policies; List<Policy> policies;
PolicyList targetPolicies = new PolicyList(); PolicyList targetPolicies = new PolicyList();
PaginationRequest request = new PaginationRequest(offset, limit); PolicyPaginationRequest request = new PolicyPaginationRequest(offset, limit);
if (name != null){
request.setName(name);
}
if (type != null){
request.setType(type);
}
if (status != null){
request.setStatus(status);
}
try { try {
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP(); PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
policies = policyAdministratorPoint.getPolicyList(request); policies = policyAdministratorPoint.getPolicyList(request);

@ -0,0 +1,77 @@
/*
* Copyright (c) 2018 - 2023, Entgra (pvt) Ltd. (https://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.common;
public class PolicyPaginationRequest {
private int startIndex;
private int rowCount;
private String name;
private String type;
private String status;
public PolicyPaginationRequest(int start, int rowCount) {
this.startIndex = start;
this.rowCount = rowCount;
}
public int getStartIndex() {
return startIndex;
}
public void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}
public int getRowCount() {
return rowCount;
}
public void setRowCount(int rowCount) {
this.rowCount = rowCount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
@Override
public String toString() {
return "Group Name '" + this.name + "' num of rows: " + this.rowCount + " start index: " + this.startIndex;
}
}

@ -509,6 +509,18 @@
<artifactId>io.entgra.device.mgt.core.notification.logger</artifactId> <artifactId>io.entgra.device.mgt.core.notification.logger</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.orbit.javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1.wso2v1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.wso2.orbit.javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1.wso2v1</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -62,4 +62,55 @@ public interface ApplicationDAO {
* @throws DeviceManagementDAOException If any database error occured * @throws DeviceManagementDAOException If any database error occured
*/ */
List<String> getAppVersions(int tenantId, String packageName) throws DeviceManagementDAOException; List<String> getAppVersions(int tenantId, String packageName) throws DeviceManagementDAOException;
/**
* This method is used to save application icon information.
* @param iconPath Icon path of the application
* @param packageName Package name of the application
* @param version version of the application
* @throws DeviceManagementDAOException If any database error occurred
*/
void saveApplicationIcon(String iconPath, String packageName, String version, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to check the package existence.
* @param packageName Package name of the application
* @throws DeviceManagementDAOException If any database error occurred
*/
int getApplicationPackageCount(String packageName) throws DeviceManagementDAOException;
/**
* This method is used to update application icon information.
* @param iconPath Icon path of the application
* @param oldPackageName Old package name of the application
* @param newPackageName New package name of the application
* @param version Version of the application
* @throws DeviceManagementDAOException If any database error occurred
*/
void updateApplicationIcon(String iconPath, String oldPackageName, String newPackageName, String version) throws DeviceManagementDAOException;
/**
* This method is used to delete application icon information.
* @param packageName Package name of the application
* @throws DeviceManagementDAOException If any database error occurred
*/
void deleteApplicationIcon(String packageName) throws DeviceManagementDAOException;
/**
* This method is used to get the installed application list of a specific device
* @param deviceId ID of the device
* @param enrolmentId Enrolment ID of the device
* @param tenantId tenant ID
* @throws DeviceManagementDAOException If any database error occurred
*/
List<Application> getInstalledApplicationListOnDevice(int deviceId, int enrolmentId, int offset, int limit, int tenantId)
throws DeviceManagementDAOException;
/**
* This method is used to retrieve the icon info of an installed app in device.
* @param applicationIdentifier application identifier.
* @return returns the application icon path.
* @throws DeviceManagementDAOException
*/
String getIconPath(String applicationIdentifier) throws DeviceManagementDAOException;
} }

@ -26,6 +26,7 @@ import io.entgra.device.mgt.core.device.mgt.core.config.datasource.DataSourceCon
import io.entgra.device.mgt.core.device.mgt.core.config.datasource.JNDILookupDefinition; import io.entgra.device.mgt.core.device.mgt.core.config.datasource.JNDILookupDefinition;
import io.entgra.device.mgt.core.device.mgt.core.dao.impl.event.GenericEventConfigDAOImpl; import io.entgra.device.mgt.core.device.mgt.core.dao.impl.event.GenericEventConfigDAOImpl;
import io.entgra.device.mgt.core.device.mgt.core.dao.impl.event.H2EventConfigDAOImpl; import io.entgra.device.mgt.core.device.mgt.core.dao.impl.event.H2EventConfigDAOImpl;
import io.entgra.device.mgt.core.device.mgt.core.dao.impl.event.SQLServerEventConfigDAOImpl;
import io.entgra.device.mgt.core.device.mgt.core.dao.impl.geofence.GenericGeofenceDAOImpl; import io.entgra.device.mgt.core.device.mgt.core.dao.impl.geofence.GenericGeofenceDAOImpl;
import io.entgra.device.mgt.core.device.mgt.core.dao.impl.geofence.SQLServerGeofenceDAOImpl; import io.entgra.device.mgt.core.device.mgt.core.dao.impl.geofence.SQLServerGeofenceDAOImpl;
import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil; import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@ -68,6 +69,7 @@ public class EventManagementDAOFactory {
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL: case DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL:
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE: case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE:
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL: case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL:
return new SQLServerEventConfigDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL: case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL:
return new GenericEventConfigDAOImpl(); return new GenericEventConfigDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2: case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2:

@ -33,7 +33,9 @@ import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -393,4 +395,178 @@ public class ApplicationDAOImpl implements ApplicationDAO {
return application; return application;
} }
@Override
public void saveApplicationIcon(String iconPath, String packageName, String version, int tenantId)
throws DeviceManagementDAOException{
Connection conn;
String sql = "INSERT INTO DM_APP_ICONS " +
"(ICON_PATH, " +
"PACKAGE_NAME, " +
"VERSION, " +
"CREATED_TIMESTAMP, " +
"TENANT_ID) " +
"VALUES (?, ?, ?, ?, ?)";
try {
conn = this.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1,iconPath);
stmt.setString(2,packageName);
stmt.setString(3,version);
stmt.setTimestamp(4, new Timestamp(new Date().getTime()));
stmt.setInt(5, tenantId);
stmt.executeUpdate();
}
} catch (SQLException e) {
String msg = "Error occurred while saving application icon details";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
@Override
public int getApplicationPackageCount(String packageName) throws DeviceManagementDAOException{
Connection conn;
String sql = "SELECT " +
"COUNT(*) AS APP_PACKAGE_COUNT " +
"FROM DM_APP_ICONS " +
"WHERE PACKAGE_NAME = ?";
try {
conn = this.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, packageName);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return rs.getInt("APP_PACKAGE_COUNT");
}
return 0;
}
}
} catch (SQLException e) {
String msg = "Error occurred while getting application icon details";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
@Override
public void updateApplicationIcon(String iconPath, String oldPackageName, String newPackageName, String version)
throws DeviceManagementDAOException{
Connection conn;
String sql = "UPDATE DM_APP_ICONS " +
"SET " +
"ICON_PATH= ?, " +
"PACKAGE_NAME = ?, " +
"VERSION = ? " +
"WHERE PACKAGE_NAME = ?";
try {
conn = this.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1,iconPath);
stmt.setString(2,newPackageName);
stmt.setString(3,version);
stmt.setString(4,oldPackageName);
stmt.executeUpdate();
}
} catch (SQLException e) {
String msg = "Error occurred while updating application icon details";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
@Override
public void deleteApplicationIcon(String packageName) throws DeviceManagementDAOException {
Connection conn;
String sql = "DELETE " +
"FROM DM_APP_ICONS " +
"WHERE PACKAGE_NAME = ?";
try {
conn = this.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, packageName);
stmt.executeUpdate();
}
} catch (SQLException e) {
String msg = "Error occurred while deleting application icon details";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
@Override
public String getIconPath(String applicationIdentifier) throws DeviceManagementDAOException{
Connection conn;
String sql = "SELECT " +
"ICON_PATH " +
"FROM DM_APP_ICONS " +
"WHERE PACKAGE_NAME = ?";
String iconPath = null;
try {
conn = this.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1,applicationIdentifier);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
iconPath = rs.getString("ICON_PATH");
}
return iconPath;
}
}
} catch (SQLException e) {
String msg = "Error occurred while retrieving app icon path of the application";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
@Override
public List<Application> getInstalledApplicationListOnDevice(int deviceId, int enrolmentId, int offset, int limit, int tenantId)
throws DeviceManagementDAOException {
Connection conn;
List<Application> applicationList = new ArrayList<>();
Application application;
String sql = "SELECT " +
"ID, " +
"NAME, " +
"APP_IDENTIFIER, " +
"PLATFORM, " +
"CATEGORY, " +
"VERSION, " +
"TYPE, " +
"LOCATION_URL, " +
"IMAGE_URL, " +
"APP_PROPERTIES, " +
"MEMORY_USAGE, " +
"IS_ACTIVE, " +
"TENANT_ID " +
"FROM DM_APPLICATION " +
"WHERE DEVICE_ID = ? AND " +
"ENROLMENT_ID = ? AND " +
"TENANT_ID = ? " +
"LIMIT ? " +
"OFFSET ?";
try {
conn = this.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, deviceId);
stmt.setInt(2, enrolmentId);
stmt.setInt(3, tenantId);
stmt.setInt(4, limit);
stmt.setInt(5, offset);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
application = loadApplication(rs);
applicationList.add(application);
}
}
}
} catch (SQLException e) {
String msg = "SQL Error occurred while retrieving the list of Applications " +
"installed in device id '" + deviceId;
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
return applicationList;
}
} }

@ -0,0 +1,82 @@
/*
* 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.dao.impl.event;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.common.event.config.EventConfig;
import io.entgra.device.mgt.core.device.mgt.core.dao.EventManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dao.EventManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.dao.impl.AbstractEventConfigDAO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Calendar;
public class SQLServerEventConfigDAOImpl extends AbstractEventConfigDAO {
private static final Log log = LogFactory.getLog(SQLServerEventConfigDAOImpl.class);
@Override
public List<Integer> storeEventRecords(List<EventConfig> eventConfigList, int tenantId) throws EventManagementDAOException {
try {
Calendar calendar = Calendar.getInstance();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
Connection conn = this.getConnection();
String sql = "INSERT INTO DM_DEVICE_EVENT(" +
"EVENT_SOURCE, " +
"EVENT_LOGIC, " +
"ACTIONS, "+
"CREATED_TIMESTAMP, " +
"TENANT_ID) " +
"VALUES (?, ?, ?, ?, ?)";
List<Integer> generatedIds = new ArrayList<>();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
for (EventConfig eventConfig : eventConfigList) {
stmt.setString(1, eventConfig.getEventSource());
stmt.setString(2, eventConfig.getEventLogic());
stmt.setString(3, eventConfig.getActions());
stmt.setTimestamp(4, timestamp);
stmt.setInt(5, tenantId);
stmt.executeUpdate();
try (ResultSet generatedKeys = stmt.getGeneratedKeys()) {
if (generatedKeys.next()) {
generatedIds.add(generatedKeys.getInt(1));
}
}
}
}
return generatedIds;
} catch (SQLException e) {
String msg = "Error occurred while creating event configurations for the tenant id " + tenantId;
log.error(msg, e);
throw new EventManagementDAOException(msg, e);
}
}
private Connection getConnection() throws SQLException {
return EventManagementDAOFactory.getConnection();
}
}

@ -18,21 +18,24 @@
package io.entgra.device.mgt.core.device.mgt.core.dao.impl.geofence; package io.entgra.device.mgt.core.device.mgt.core.dao.impl.geofence;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants; import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeofenceData; import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeofenceData;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dao.EventManagementDAOFactory; import io.entgra.device.mgt.core.device.mgt.core.dao.EventManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.dao.impl.AbstractGeofenceDAOImpl; import io.entgra.device.mgt.core.device.mgt.core.dao.impl.AbstractGeofenceDAOImpl;
import org.apache.commons.logging.Log; import org.wso2.carbon.context.CarbonContext;
import org.apache.commons.logging.LogFactory;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class SQLServerGeofenceDAOImpl extends AbstractGeofenceDAOImpl { public class SQLServerGeofenceDAOImpl extends AbstractGeofenceDAOImpl {
private static final Log log = LogFactory.getLog(SQLServerGeofenceDAOImpl.class); private static final Log log = LogFactory.getLog(SQLServerGeofenceDAOImpl.class);
@ -106,4 +109,61 @@ public class SQLServerGeofenceDAOImpl extends AbstractGeofenceDAOImpl {
} }
return geofenceDataList; return geofenceDataList;
} }
@Override
public GeofenceData getGeofence(int fenceId, boolean requireGroupData) throws DeviceManagementDAOException {
if (!requireGroupData) {
return getGeofence(fenceId);
}
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
Connection con = this.getConnection();
String sql = "SELECT " +
"G.ID AS FENCE_ID, " +
"FENCE_NAME, " +
"G.DESCRIPTION, " +
"LATITUDE, " +
"LONGITUDE, " +
"RADIUS, " +
"GEO_JSON, " +
"FENCE_SHAPE, " +
"M.GROUP_ID AS GROUP_ID, " +
"GR.GROUP_NAME " +
"FROM DM_GEOFENCE G, DM_GEOFENCE_GROUP_MAPPING M, DM_GROUP GR " +
"WHERE G.ID = M.FENCE_ID " +
"AND M.GROUP_ID = GR.ID " +
"AND G.ID = ? " +
"AND G.TENANT_ID = ?";
try (PreparedStatement stmt = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
stmt.setInt(1, fenceId);
stmt.setInt(2, tenantId);
try (ResultSet rst = stmt.executeQuery()) {
Map<Integer, String> groupMap = new HashMap<>();
GeofenceData geofenceData = null;
while (rst.next()) {
groupMap.put(rst.getInt("GROUP_ID"), rst.getString("GROUP_NAME"));
}
if (!groupMap.isEmpty()) {
rst.beforeFirst();
rst.next();
geofenceData = new GeofenceData();
geofenceData.setId(rst.getInt("FENCE_ID"));
geofenceData.setFenceName(rst.getString("FENCE_NAME"));
geofenceData.setDescription(rst.getString("DESCRIPTION"));
geofenceData.setLatitude(rst.getDouble("LATITUDE"));
geofenceData.setLongitude(rst.getDouble("LONGITUDE"));
geofenceData.setRadius(rst.getFloat("RADIUS"));
geofenceData.setGeoJson(rst.getString("GEO_JSON"));
geofenceData.setFenceShape(rst.getString("FENCE_SHAPE"));
geofenceData.setGroupData(groupMap);
}
return geofenceData;
}
}
} catch (SQLException e) {
String msg = "Error occurred while retrieving Geo fence data " + fenceId;
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
} }

@ -18,6 +18,8 @@
package io.entgra.device.mgt.core.device.mgt.core.service; package io.entgra.device.mgt.core.device.mgt.core.service;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application;
import org.apache.commons.collections.map.SingletonMap;
import io.entgra.device.mgt.core.device.mgt.common.*; import io.entgra.device.mgt.core.device.mgt.common.*;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManagementException; import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManagementException;
import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.*; import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.*;
@ -43,6 +45,7 @@ import org.apache.commons.collections.map.SingletonMap;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -1007,4 +1010,42 @@ public interface DeviceManagementProviderService {
throws DeviceManagementException; throws DeviceManagementException;
Boolean sendDeviceNameChangedNotification(Device device) throws DeviceManagementException; Boolean sendDeviceNameChangedNotification(Device device) throws DeviceManagementException;
/**
* This method is for saving application icon info
* @param iconPath Icon path of the application
* @param packageName Package name of the application
* @param version Version of the application
* @param tenantId Tenant ID of the application created user
* @throws DeviceManagementException if any service level or DAO level error occurs
*/
void saveApplicationIcon(String iconPath, String packageName, String version, int tenantId)
throws DeviceManagementException;
/**
* This method is for updating application icon info
* @param iconPath Icon path of the application
* @param oldPackageName Old package name of the application
* @param newPackageName New package name of the application
* @param version Version of the application
* @throws DeviceManagementException if any service level or DAO level error occurs
*/
void updateApplicationIcon(String iconPath, String oldPackageName, String newPackageName, String version)
throws DeviceManagementException;
/**
* This method is for deleting application icon info
* @param packageName Package name of the application
* @throws DeviceManagementException if any service level or DAO level error occurs
*/
void deleteApplicationIcon(String packageName) throws DeviceManagementException;
/**
* This method is for getting the installed application list of a device
* @param device {@link Device}
* @return list of applications {@link Application}
* @throws DeviceManagementException if any service level or DAO level error occurs
*/
List<Application> getInstalledApplicationsOnDevice(Device device, int offset, int limit)
throws DeviceManagementException;
} }

@ -4844,4 +4844,130 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
} }
@Override
public void saveApplicationIcon(String iconPath, String packageName, String version, int tenantId) throws DeviceManagementException{
try{
DeviceManagementDAOFactory.beginTransaction();
if(applicationDAO.getApplicationPackageCount(packageName) == 0){
applicationDAO.saveApplicationIcon(iconPath, packageName, version, tenantId);
}
DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while saving app icon. Icon Path: " + iconPath +
" Package Name: " + packageName +
" Version: " + version +
" Tenant Id: " + tenantId;
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Override
public void updateApplicationIcon(String iconPath, String oldPackageName, String newPackageName, String version)
throws DeviceManagementException{
try {
DeviceManagementDAOFactory.beginTransaction();
applicationDAO.updateApplicationIcon(iconPath, oldPackageName, newPackageName, version);
DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while updating app icon info." +
" Package Name: " + oldPackageName;
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Override
public void deleteApplicationIcon(String packageName)
throws DeviceManagementException {
try {
DeviceManagementDAOFactory.beginTransaction();
applicationDAO.deleteApplicationIcon(packageName);
DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while deleting app icon info." +
" Package Name: " + packageName ;
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
private List<Application> getInstalledAppIconInfo(List<Application> applications) throws DeviceManagementException {
String iconPath;
try {
DeviceManagementDAOFactory.openConnection();
for (Application app : applications) {
iconPath = applicationDAO.getIconPath(app.getApplicationIdentifier());
app.setImageUrl(iconPath);
}
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while retrieving installed app icon info";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while opening a connection to the data source";
log.error(msg);
throw new DeviceManagementException(msg, e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
return applications;
}
@Override
public List<Application> getInstalledApplicationsOnDevice(Device device, int offset, int limit) throws DeviceManagementException {
List<Application> applications;
try {
DeviceManagementDAOFactory.openConnection();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
applications = applicationDAO.getInstalledApplicationListOnDevice(device.getId(),
device.getEnrolmentInfo().getId(), offset, limit, tenantId);
if (applications == null) {
String msg = "Couldn't found applications for device identifier '" + device.getId() + "'";
log.error(msg);
throw new DeviceManagementException(msg);
}
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while retrieving the application list of android device, " +
"which carries the id '" + device.getId() + "'";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
List<Application> newApplicationList;
newApplicationList = this.getInstalledAppIconInfo(applications);
if (newApplicationList == null) {
String msg = "Error occurred while getting app icon info for device identifier '" + device.getId() + "'";
log.error(msg);
throw new DeviceManagementException(msg);
}
return newApplicationList;
}
} }

@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.policy.mgt.common;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy; import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Profile; import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Profile;
@ -167,10 +168,10 @@ public interface PolicyAdministratorPoint {
/** /**
* Returns a list of policies filtered by offset and limit * Returns a list of policies filtered by offset and limit
* @param request {@link PaginationRequest} contains offset and limit * @param request {@link PolicyPaginationRequest} contains offset and limit and filters
* @return {@link List<Policy>} - list of policies for current tenant * @return {@link List<Policy>} - list of policies for current tenant
* @throws PolicyManagementException when there is an error while retrieving the policies from database or * @throws PolicyManagementException when there is an error while retrieving the policies from database or
* while retrieving device groups * while retrieving device groups
*/ */
List<Policy> getPolicyList(PaginationRequest request) throws PolicyManagementException; List<Policy> getPolicyList(PolicyPaginationRequest request) throws PolicyManagementException;
} }

@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.policy.mgt.core.dao;
import io.entgra.device.mgt.core.device.mgt.common.Device; import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.CorrectiveAction; import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.CorrectiveAction;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.DeviceGroupWrapper; import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.DeviceGroupWrapper;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy; import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
@ -202,9 +203,9 @@ public interface PolicyDAO {
/** /**
* This method is used to retrieve policies from the database based on the offset and limit * This method is used to retrieve policies from the database based on the offset and limit
* sent through the PaginationRequest * sent through the PaginationRequest
* @param request {@link PaginationRequest} contains offset and limit * @param request {@link PolicyPaginationRequest} contains offset and limit and filters
* @return {@link List<Policy>} - list of policies for current tenant * @return {@link List<Policy>} - list of policies for current tenant
* @throws PolicyManagerDAOException when there is an error while retrieving the policies from database * @throws PolicyManagerDAOException when there is an error while retrieving the policies from database
*/ */
List<Policy> getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException; List<Policy> getAllPolicies(PolicyPaginationRequest request) throws PolicyManagerDAOException;
} }

@ -18,13 +18,14 @@
package io.entgra.device.mgt.core.policy.mgt.core.dao.impl.policy; package io.entgra.device.mgt.core.policy.mgt.core.dao.impl.policy;
import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy; import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagementDAOFactory; import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagementDAOFactory;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagerDAOException; import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagerDAOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -41,21 +42,57 @@ public class GenericPolicyDAOImpl extends AbstractPolicyDAOImpl {
} }
@Override @Override
public List<Policy> getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException { public List<Policy> getAllPolicies(PolicyPaginationRequest request) throws PolicyManagerDAOException {
Connection conn; Connection conn;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String name = request.getName();
String type = request.getType();
String status = request.getStatus();
int statusValue = 0;
boolean isPolicyNameProvided = false;
boolean isPolicyTypeProvided = false;
boolean isPolicyStatusProvided = false;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "SELECT * " + String query = "SELECT * " +
"FROM DM_POLICY " + "FROM DM_POLICY " +
"WHERE TENANT_ID = ? " + "WHERE TENANT_ID = ? ";
"ORDER BY ID LIMIT ?,?";
if (name != null && !name.isEmpty()) {
query += "AND NAME LIKE ? " ;
isPolicyNameProvided = true;
}
if (type != null && !type.isEmpty()) {
query += "AND POLICY_TYPE = ? " ;
isPolicyTypeProvided = true;
}
if (status != null && !status.isEmpty()) {
if (status.equals("ACTIVE")) {
statusValue = 1;
}
query += "AND ACTIVE = ? " ;
isPolicyStatusProvided = true;
}
query += "ORDER BY ID LIMIT ?,?";
try (PreparedStatement stmt = conn.prepareStatement(query)) { try (PreparedStatement stmt = conn.prepareStatement(query)) {
stmt.setInt(1, tenantId); int paramIdx = 1;
stmt.setInt(2, request.getStartIndex()); stmt.setInt(paramIdx++, tenantId);
stmt.setInt(3, request.getRowCount()); if (isPolicyNameProvided) {
stmt.setString(paramIdx++, "%" + name + "%");
}
if (isPolicyTypeProvided) {
stmt.setString(paramIdx++, type);
}
if (isPolicyStatusProvided) {
stmt.setInt(paramIdx++, statusValue);
}
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx++, request.getRowCount());
try (ResultSet resultSet = stmt.executeQuery()) { try (ResultSet resultSet = stmt.executeQuery()) {
return this.extractPolicyListFromDbResult(resultSet, tenantId); return this.extractPolicyListFromDbResult(resultSet, tenantId);
} }

@ -18,13 +18,14 @@
package io.entgra.device.mgt.core.policy.mgt.core.dao.impl.policy; package io.entgra.device.mgt.core.policy.mgt.core.dao.impl.policy;
import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy; import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagementDAOFactory; import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagementDAOFactory;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagerDAOException; import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagerDAOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -40,21 +41,57 @@ public class OraclePolicyDAOImpl extends AbstractPolicyDAOImpl {
} }
@Override @Override
public List<Policy> getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException { public List<Policy> getAllPolicies(PolicyPaginationRequest request) throws PolicyManagerDAOException {
Connection conn; Connection conn;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String name = request.getName();
String type = request.getType();
String status = request.getStatus();
int statusValue = 0;
boolean isPolicyNameProvided = false;
boolean isPolicyTypeProvided = false;
boolean isPolicyStatusProvided = false;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "SELECT * " + String query = "SELECT * " +
"FROM DM_POLICY " + "FROM DM_POLICY " +
"WHERE TENANT_ID = ? " + "WHERE TENANT_ID = ? ";
"ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
if (name != null && !name.isEmpty()) {
query += "AND NAME LIKE ? " ;
isPolicyNameProvided = true;
}
if (type != null && !type.isEmpty()) {
query += "AND POLICY_TYPE = ? " ;
isPolicyTypeProvided = true;
}
if (status != null && !status.isEmpty()) {
if (status.equals("ACTIVE")) {
statusValue = 1;
}
query += "AND ACTIVE = ? " ;
isPolicyStatusProvided = true;
}
query += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement stmt = conn.prepareStatement(query)) { try (PreparedStatement stmt = conn.prepareStatement(query)) {
stmt.setInt(1, tenantId); int paramIdx = 1;
stmt.setInt(2, request.getStartIndex()); stmt.setInt(paramIdx++, tenantId);
stmt.setInt(3, request.getRowCount()); if (isPolicyNameProvided) {
stmt.setString(paramIdx++, "%" + name + "%");
}
if (isPolicyTypeProvided) {
stmt.setString(paramIdx++, type);
}
if (isPolicyStatusProvided) {
stmt.setInt(paramIdx++, statusValue);
}
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx++, request.getRowCount());
try (ResultSet resultSet = stmt.executeQuery()) { try (ResultSet resultSet = stmt.executeQuery()) {
return this.extractPolicyListFromDbResult(resultSet, tenantId); return this.extractPolicyListFromDbResult(resultSet, tenantId);
} }

@ -18,13 +18,14 @@
package io.entgra.device.mgt.core.policy.mgt.core.dao.impl.policy; package io.entgra.device.mgt.core.policy.mgt.core.dao.impl.policy;
import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy; import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagementDAOFactory; import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagementDAOFactory;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagerDAOException; import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagerDAOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -40,21 +41,57 @@ public class PostgreSQLPolicyDAOImpl extends AbstractPolicyDAOImpl {
} }
@Override @Override
public List<Policy> getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException { public List<Policy> getAllPolicies(PolicyPaginationRequest request) throws PolicyManagerDAOException {
Connection conn; Connection conn;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String name = request.getName();
String type = request.getType();
String status = request.getStatus();
int statusValue = 0;
boolean isPolicyNameProvided = false;
boolean isPolicyTypeProvided = false;
boolean isPolicyStatusProvided = false;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "SELECT * " + String query = "SELECT * " +
"FROM DM_POLICY " + "FROM DM_POLICY " +
"WHERE TENANT_ID = ? " + "WHERE TENANT_ID = ? ";
"ORDER BY ID LIMIT ? OFFSET ?";
if (name != null && !name.isEmpty()) {
query += "AND NAME LIKE ? " ;
isPolicyNameProvided = true;
}
if (type != null && !type.isEmpty()) {
query += "AND POLICY_TYPE = ? " ;
isPolicyTypeProvided = true;
}
if (status != null && !status.isEmpty()) {
if (status.equals("ACTIVE")) {
statusValue = 1;
}
query += "AND ACTIVE = ? " ;
isPolicyStatusProvided = true;
}
query += "ORDER BY ID LIMIT ? OFFSET ?";
try (PreparedStatement stmt = conn.prepareStatement(query)) { try (PreparedStatement stmt = conn.prepareStatement(query)) {
stmt.setInt(1, tenantId); int paramIdx = 1;
stmt.setInt(2, request.getRowCount()); stmt.setInt(paramIdx++, tenantId);
stmt.setInt(3, request.getStartIndex()); if (isPolicyNameProvided) {
stmt.setString(paramIdx++, "%" + name + "%");
}
if (isPolicyTypeProvided) {
stmt.setString(paramIdx++, type);
}
if (isPolicyStatusProvided) {
stmt.setInt(paramIdx++, statusValue);
}
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx++, request.getRowCount());
try (ResultSet resultSet = stmt.executeQuery()) { try (ResultSet resultSet = stmt.executeQuery()) {
return this.extractPolicyListFromDbResult(resultSet, tenantId); return this.extractPolicyListFromDbResult(resultSet, tenantId);
} }

@ -18,13 +18,14 @@
package io.entgra.device.mgt.core.policy.mgt.core.dao.impl.policy; package io.entgra.device.mgt.core.policy.mgt.core.dao.impl.policy;
import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy; import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagementDAOFactory; import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagementDAOFactory;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagerDAOException; import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagerDAOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -40,20 +41,57 @@ public class SQLServerPolicyDAOImpl extends AbstractPolicyDAOImpl {
} }
@Override @Override
public List<Policy> getAllPolicies(PaginationRequest request) throws PolicyManagerDAOException { public List<Policy> getAllPolicies(PolicyPaginationRequest request) throws PolicyManagerDAOException {
Connection conn; Connection conn;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String name = request.getName();
String type = request.getType();
String status = request.getStatus();
int statusValue = 0;
boolean isPolicyNameProvided = false;
boolean isPolicyTypeProvided = false;
boolean isPolicyStatusProvided = false;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String query = "SELECT * " + String query = "SELECT * " +
"FROM DM_POLICY " + "FROM DM_POLICY " +
"WHERE TENANT_ID = ? " + "WHERE TENANT_ID = ? ";
"ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
if (name != null && !name.isEmpty()) {
query += "AND NAME LIKE ? " ;
isPolicyNameProvided = true;
}
if (type != null && !type.isEmpty()) {
query += "AND POLICY_TYPE = ? " ;
isPolicyTypeProvided = true;
}
if (status != null && !status.isEmpty()) {
if (status.equals("ACTIVE")) {
statusValue = 1;
}
query += "AND ACTIVE = ? " ;
isPolicyStatusProvided = true;
}
query += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement stmt = conn.prepareStatement(query)) { try (PreparedStatement stmt = conn.prepareStatement(query)) {
stmt.setInt(1, tenantId); int paramIdx = 1;
stmt.setInt(2, request.getStartIndex()); stmt.setInt(paramIdx++, tenantId);
stmt.setInt(3, request.getRowCount()); if (isPolicyNameProvided) {
stmt.setString(paramIdx++, "%" + name + "%");
}
if (isPolicyTypeProvided) {
stmt.setString(paramIdx++, type);
}
if (isPolicyStatusProvided) {
stmt.setInt(paramIdx++, statusValue);
}
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx++, request.getRowCount());
try (ResultSet resultSet = stmt.executeQuery()) { try (ResultSet resultSet = stmt.executeQuery()) {
return this.extractPolicyListFromDbResult(resultSet, tenantId); return this.extractPolicyListFromDbResult(resultSet, tenantId);
} }

@ -18,6 +18,10 @@
package io.entgra.device.mgt.core.policy.mgt.core.impl; package io.entgra.device.mgt.core.policy.mgt.core.impl;
import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy; import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
@ -336,7 +340,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
} }
@Override @Override
public List<Policy> getPolicyList(PaginationRequest request) throws PolicyManagementException { public List<Policy> getPolicyList(PolicyPaginationRequest request) throws PolicyManagementException {
return policyManager.getPolicyList(request); return policyManager.getPolicyList(request);
} }
} }

@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.policy.mgt.core.mgt;
import io.entgra.device.mgt.core.device.mgt.common.Device; import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy; import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
import io.entgra.device.mgt.core.policy.mgt.common.PolicyManagementException; import io.entgra.device.mgt.core.policy.mgt.common.PolicyManagementException;
import io.entgra.device.mgt.core.policy.mgt.core.mgt.bean.UpdatedPolicyDeviceListBean; import io.entgra.device.mgt.core.policy.mgt.core.mgt.bean.UpdatedPolicyDeviceListBean;
@ -92,10 +93,10 @@ public interface PolicyManager {
/** /**
* Returns list of policies with users, roles and groups attached to that policy * Returns list of policies with users, roles and groups attached to that policy
* @param request {@link PaginationRequest} contains offset and limit * @param request {@link PolicyPaginationRequest} contains offset and limit and filters
* @return {@link List<Policy>} - list of policies for current tenant * @return {@link List<Policy>} - list of policies for current tenant
* @throws PolicyManagementException when there is an error while retrieving the policies from database or * @throws PolicyManagementException when there is an error while retrieving the policies from database or
* while retrieving device groups * while retrieving device groups
*/ */
List<Policy> getPolicyList(PaginationRequest request) throws PolicyManagementException; List<Policy> getPolicyList(PolicyPaginationRequest request) throws PolicyManagementException;
} }

@ -20,7 +20,7 @@ package io.entgra.device.mgt.core.policy.mgt.core.mgt.impl;
import io.entgra.device.mgt.core.device.mgt.common.Device; import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.InvalidDeviceException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.InvalidDeviceException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup;
@ -1471,7 +1471,7 @@ public class PolicyManagerImpl implements PolicyManager {
} }
@Override @Override
public List<Policy> getPolicyList(PaginationRequest request) throws PolicyManagementException { public List<Policy> getPolicyList(PolicyPaginationRequest request) throws PolicyManagementException {
List<Policy> policyList; List<Policy> policyList;
try { try {
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<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>apimgt-extensions-feature</artifactId>
<version>5.0.26-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>io.entgra.device.mgt.core.apimgt.extension.rest.api.feature</artifactId>
<packaging>pom</packaging>
<name>Entgra - API management REST API feature</name>
<description>This feature contains an implementation of API manager REST API extension</description>
<url>http://entgra.io</url>
<dependencies>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.apimgt.extension.rest.api</artifactId>
<version>${io.entgra.device.mgt.core.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src/main/resources</outputDirectory>
<resources>
<resource>
<directory>resources</directory>
<includes>
<include>build.properties</include>
<include>p2.inf</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>carbon-p2-plugin</artifactId>
<version>${carbon.p2.plugin.version}</version>
<executions>
<execution>
<id>p2-feature-generation</id>
<phase>package</phase>
<goals>
<goal>p2-feature-gen</goal>
</goals>
<configuration>
<id>io.entgra.device.mgt.core.apimgt.extension.rest.api</id>
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
<adviceFile>
<properties>
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
</properties>
</adviceFile>
<bundles>
<bundleDef>
io.entgra.device.mgt.core:io.entgra.device.mgt.core.apimgt.extension.rest.api:${io.entgra.device.mgt.core.version}
</bundleDef>
</bundles>
<importFeatures>
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
</importFeatures>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -51,10 +51,6 @@
<groupId>io.swagger</groupId> <groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId> <artifactId>swagger-annotations</artifactId>
</dependency> </dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.apimgt.extension.rest.api</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -146,9 +142,6 @@
<bundleDef> <bundleDef>
io.swagger:swagger-annotations:${swagger.version} io.swagger:swagger-annotations:${swagger.version}
</bundleDef> </bundleDef>
<bundleDef>
io.entgra.device.mgt.core:io.entgra.device.mgt.core.apimgt.extension.rest.api:${io.entgra.device.mgt.core.version}
</bundleDef>
</bundles> </bundles>
<importFeatures> <importFeatures>
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef> <importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>

@ -38,6 +38,7 @@
<module>io.entgra.device.mgt.core.apimgt.application.extension.feature</module> <module>io.entgra.device.mgt.core.apimgt.application.extension.feature</module>
<module>io.entgra.device.mgt.core.apimgt.keymgt.extension.feature</module> <module>io.entgra.device.mgt.core.apimgt.keymgt.extension.feature</module>
<module>io.entgra.device.mgt.core.apimgt.analytics.extension.feature</module> <module>io.entgra.device.mgt.core.apimgt.analytics.extension.feature</module>
<module>io.entgra.device.mgt.core.apimgt.extension.rest.api.feature</module>
</modules> </modules>
</project> </project>

@ -417,6 +417,16 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
-- POLICY RELATED TABLES FINISHED -- -- POLICY RELATED TABLES FINISHED --
CREATE TABLE IF NOT EXISTS DM_APP_ICONS (
ID INTEGER AUTO_INCREMENT NOT NULL,
ICON_PATH VARCHAR(150) DEFAULT NULL,
PACKAGE_NAME VARCHAR(150) NOT NULL,
VERSION VARCHAR(50) DEFAULT '1.1.0',
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)
);
-- NOTIFICATION TABLE -- -- NOTIFICATION TABLE --
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL, NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL,

@ -462,6 +462,17 @@ CREATE INDEX IDX_DM_APPLICATION ON DM_APPLICATION(DEVICE_ID, ENROLMENT_ID, TENAN
-- POLICY RELATED TABLES FINISHED -- -- POLICY RELATED TABLES FINISHED --
IF NOT EXISTS (SELECT * SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_APP_ICONS]') AND TYPE IN (N'U'))
CREATE TABLE DM_APP_ICONS (
ID INTEGER IDENTITY(1,1) NOT NULL,
ICON_PATH VARCHAR(150) DEFAULT NULL,
PACKAGE_NAME VARCHAR(150) NOT NULL,
VERSION VARCHAR(50) DEFAULT '1.1.0',
CREATED_TIMESTAMP DATETIME2 NOT NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)
);
-- POLICY AND DEVICE GROUP MAPPING -- -- POLICY AND DEVICE GROUP MAPPING --
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_GROUP_POLICY]') AND TYPE IN (N'U')) IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_GROUP_POLICY]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_GROUP_POLICY ( CREATE TABLE DM_DEVICE_GROUP_POLICY (
@ -775,7 +786,7 @@ CREATE TABLE DM_DEVICE_EVENT (
EVENT_SOURCE VARCHAR(100) NOT NULL, EVENT_SOURCE VARCHAR(100) NOT NULL,
EVENT_LOGIC VARCHAR(100) NOT NULL, EVENT_LOGIC VARCHAR(100) NOT NULL,
ACTIONS TEXT DEFAULT NULL, ACTIONS TEXT DEFAULT NULL,
CREATED_TIMESTAMP TIMESTAMP NOT NULL, CREATED_TIMESTAMP DATETIME2(0) NOT NULL,
TENANT_ID INTEGER DEFAULT 0, TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );

@ -458,6 +458,16 @@ CREATE INDEX IDX_DM_APPLICATION ON DM_APPLICATION(DEVICE_ID, ENROLMENT_ID, TENAN
-- END OF POLICY RELATED TABLES -- -- END OF POLICY RELATED TABLES --
CREATE TABLE IF NOT EXISTS DM_APP_ICONS (
ID INTEGER AUTO_INCREMENT NOT NULL,
ICON_PATH VARCHAR(150) DEFAULT NULL,
PACKAGE_NAME VARCHAR(150) NOT NULL,
VERSION VARCHAR(50) DEFAULT '1.1.0',
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)
)ENGINE = InnoDB;
-- POLICY AND DEVICE GROUP MAPPING -- -- POLICY AND DEVICE GROUP MAPPING --
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY ( CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (

@ -748,6 +748,28 @@ WHEN (NEW.ID IS NULL)
-- POLICY RELATED TABLES FINISHED -- -- POLICY RELATED TABLES FINISHED --
CREATE TABLE DM_APP_ICONS (
ID NUMBER(10) NOT NULL,
ICON_PATH VARCHAR2(150) DEFAULT NULL,
PACKAGE_NAME VARCHAR2(150) NOT NULL,
VERSION VARCHAR2(50) DEFAULT '1.1.0',
CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
TENANT_ID NUMBER(10) NOT NULL,
PRIMARY KEY (ID)
)
/
-- Generate ID using sequence and trigger
CREATE SEQUENCE DM_APP_ICONS_seq START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER DM_APP_ICONS_seq_tr
BEFORE INSERT ON DM_APP_ICONS FOR EACH ROW
WHEN (NEW.ID IS NULL)
BEGIN
SELECT DM_APP_ICONS_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END;
/
-- NOTIFICATION TABLE -- -- NOTIFICATION TABLE --
CREATE TABLE DM_NOTIFICATION ( CREATE TABLE DM_NOTIFICATION (
NOTIFICATION_ID NUMBER(10) NOT NULL, NOTIFICATION_ID NUMBER(10) NOT NULL,

@ -490,6 +490,19 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
-- END OF POLICY RELATED TABLES -- -- END OF POLICY RELATED TABLES --
CREATE SEQUENCE DM_APP_ICONS_seq;
CREATE TABLE IF NOT EXISTS DM_APP_ICONS (
ID INTEGER DEFAULT NEXTVAL ('DM_APP_ICONS_seq') NOT NULL,
ICON_PATH VARCHAR(150) DEFAULT NULL,
PACKAGE_NAME VARCHAR(150) NOT NULL,
VERSION VARCHAR(50) DEFAULT '1.1.0',
CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)
)
;
-- POLICY AND DEVICE GROUP MAPPING -- -- POLICY AND DEVICE GROUP MAPPING --
CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq; CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq;

Loading…
Cancel
Save