mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Remove package attribute form Application
This commit is contained in:
parent
3908705b68
commit
0e2e0fdd0e
@ -24,7 +24,6 @@ import java.util.Properties;
|
||||
public class Application implements Serializable {
|
||||
|
||||
private int id;
|
||||
private String packageName;
|
||||
private String platform;
|
||||
private String category;
|
||||
private String name;
|
||||
@ -33,6 +32,7 @@ public class Application implements Serializable {
|
||||
private String version;
|
||||
private String type;
|
||||
private Properties appProperties;
|
||||
private String applicationIdentifier;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
@ -85,14 +85,6 @@ public class Application implements Serializable {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public String getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
@ -109,6 +101,14 @@ public class Application implements Serializable {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getApplicationIdentifier() {
|
||||
return applicationIdentifier;
|
||||
}
|
||||
|
||||
public void setApplicationIdentifier(String applicationIdentifier) {
|
||||
this.applicationIdentifier = applicationIdentifier;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
@ -138,9 +138,6 @@ public class Application implements Serializable {
|
||||
if (name != null ? !name.equals(that.name) : that.name != null) {
|
||||
return false;
|
||||
}
|
||||
if (packageName != null ? !packageName.equals(that.packageName) : that.packageName != null) {
|
||||
return false;
|
||||
}
|
||||
if (platform != null ? !platform.equals(that.platform) : that.platform != null) {
|
||||
return false;
|
||||
}
|
||||
@ -150,14 +147,15 @@ public class Application implements Serializable {
|
||||
if (version != null ? !version.equals(that.version) : that.version != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (applicationIdentifier != null ? !applicationIdentifier.equals(that.applicationIdentifier) : that.applicationIdentifier != null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = id;
|
||||
result = 31 * result + (packageName != null ? packageName.hashCode() : 0);
|
||||
result = 31 * result + (platform != null ? platform.hashCode() : 0);
|
||||
result = 31 * result + (category != null ? category.hashCode() : 0);
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
@ -166,6 +164,7 @@ public class Application implements Serializable {
|
||||
result = 31 * result + (version != null ? version.hashCode() : 0);
|
||||
result = 31 * result + (type != null ? type.hashCode() : 0);
|
||||
result = 31 * result + (appProperties != null ? appProperties.hashCode() : 0);
|
||||
result = 31 * result + (applicationIdentifier != null ? applicationIdentifier.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -189,7 +189,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
|
||||
try {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
return applicationMappingDAO.getInstalledApplications(device.getId());
|
||||
return applicationDAO.getInstalledApplications(device.getId());
|
||||
}catch (DeviceManagementDAOException deviceDaoEx) {
|
||||
String errorMsg = "Error occured while fetching the Application List of device : " + device.getId();
|
||||
log.error(errorMsg, deviceDaoEx);
|
||||
|
||||
@ -31,4 +31,6 @@ public interface ApplicationDAO {
|
||||
int removeApplication(String applicationName, int tenantId) throws DeviceManagementDAOException;
|
||||
|
||||
Application getApplication(String identifier, int tenantId) throws DeviceManagementDAOException;
|
||||
|
||||
List<Application> getInstalledApplications(int deviceId) throws DeviceManagementDAOException;
|
||||
}
|
||||
|
||||
@ -30,7 +30,4 @@ public interface ApplicationMappingDAO {
|
||||
int tenantId) throws DeviceManagementDAOException;
|
||||
|
||||
int removeApplicationMapping(int deviceId, int applicationId, int tenantId) throws DeviceManagementDAOException;
|
||||
|
||||
List<Application> getInstalledApplications(int deviceId) throws DeviceManagementDAOException;
|
||||
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ import java.io.ObjectInputStream;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class ApplicationDAOImpl implements ApplicationDAO {
|
||||
|
||||
@ -45,18 +46,20 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
||||
int applicationId = -1;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
stmt = conn.prepareStatement("INSERT INTO DM_APPLICATION (NAME, PACKAGE_NAME, PLATFORM, CATEGORY, " +
|
||||
"VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
Statement.RETURN_GENERATED_KEYS);
|
||||
stmt = conn.prepareStatement("INSERT INTO DM_APPLICATION (NAME, PLATFORM, CATEGORY, " +
|
||||
"VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID,APP_PROPERTIES,APP_IDENTIFIER) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,?)");
|
||||
|
||||
stmt.setString(1, application.getName());
|
||||
stmt.setString(2, application.getPackageName());
|
||||
stmt.setString(3, application.getPlatform());
|
||||
stmt.setString(4, application.getCategory());
|
||||
stmt.setString(5, application.getVersion());
|
||||
stmt.setString(6, application.getType());
|
||||
stmt.setString(7, application.getLocationUrl());
|
||||
stmt.setString(8, application.getImageUrl());
|
||||
stmt.setInt(9, tenantId);
|
||||
stmt.setString(2, application.getPlatform());
|
||||
stmt.setString(3, application.getCategory());
|
||||
stmt.setString(4, application.getVersion());
|
||||
stmt.setString(5, application.getType());
|
||||
stmt.setString(6, application.getLocationUrl());
|
||||
stmt.setString(7, application.getImageUrl());
|
||||
stmt.setInt(8, tenantId);
|
||||
stmt.setObject(9,application.getAppProperties());
|
||||
stmt.setString(10,application.getApplicationIdentifier());
|
||||
stmt.execute();
|
||||
|
||||
rs = stmt.getGeneratedKeys();
|
||||
@ -81,18 +84,22 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
||||
List<Integer> applicationIds = new ArrayList<Integer>();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
stmt = conn.prepareStatement("INSERT INTO DM_APPLICATION (NAME, PACKAGE_NAME, PLATFORM, CATEGORY, " +
|
||||
"VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
stmt = conn.prepareStatement("INSERT INTO DM_APPLICATION (NAME, PLATFORM, CATEGORY, " +
|
||||
"VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID,APP_PROPERTIES,APP_IDENTIFIER) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,?)");
|
||||
|
||||
|
||||
for (Application application : applications) {
|
||||
stmt.setString(1, application.getName());
|
||||
stmt.setString(2, application.getPackageName());
|
||||
stmt.setString(3, application.getPlatform());
|
||||
stmt.setString(4, application.getCategory());
|
||||
stmt.setString(5, application.getVersion());
|
||||
stmt.setString(6, application.getType());
|
||||
stmt.setString(7, application.getLocationUrl());
|
||||
stmt.setString(8, application.getImageUrl());
|
||||
stmt.setInt(9, tenantId);
|
||||
stmt.setString(2, application.getPlatform());
|
||||
stmt.setString(3, application.getCategory());
|
||||
stmt.setString(4, application.getVersion());
|
||||
stmt.setString(5, application.getType());
|
||||
stmt.setString(6, application.getLocationUrl());
|
||||
stmt.setString(7, application.getImageUrl());
|
||||
stmt.setInt(8, tenantId);
|
||||
stmt.setObject(9,application.getAppProperties());
|
||||
stmt.setString(10,application.getApplicationIdentifier());
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
@ -150,8 +157,9 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
||||
Application application = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
stmt = conn.prepareStatement("SELECT ID, NAME, PACKAGE_NAME, CATEGORY, PLATFORM, TYPE, VERSION, IMAGE_URL, " +
|
||||
"LOCATION_URL FROM DM_APPLICATION WHERE PACKAGE_NAME = ? AND TENANT_ID = ?");
|
||||
stmt = conn.prepareStatement("SELECT ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " +
|
||||
"LOCATION_URL, IMAGE_URL, APP_PROPERTIES, TENANT_ID FROM DM_APPLICATION WHERE APP_IDENTIFIER = ? " +
|
||||
"AND TENANT_ID = ?");
|
||||
stmt.setString(1, identifier);
|
||||
stmt.setInt(2, tenantId);
|
||||
rs = stmt.executeQuery();
|
||||
@ -172,17 +180,80 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
||||
return DeviceManagementDAOFactory.getConnection();
|
||||
}
|
||||
|
||||
private Application loadApplication(ResultSet rs) throws SQLException {
|
||||
@Override
|
||||
public List<Application> getInstalledApplications(int deviceId) throws DeviceManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
List<Application> applications = new ArrayList<Application>();
|
||||
Application application;
|
||||
ByteArrayInputStream bais;
|
||||
ObjectInputStream ois;
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
stmt = conn.prepareStatement("Select ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " +
|
||||
"LOCATION_URL, IMAGE_URL, APP_PROPERTIES, TENANT_ID From DM_APPLICATION app " +
|
||||
"INNER JOIN "+
|
||||
"(Select APPLICATION_ID From DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID=?) APPMAP " +
|
||||
"ON "+
|
||||
"app.ID = APPMAP.APPLICATION_ID ");
|
||||
|
||||
stmt.setInt(1,deviceId);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
application = loadApplication(rs);
|
||||
applications.add(application);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceManagementDAOException("SQL Error occurred while retrieving the list of Applications " +
|
||||
"installed in device id '" + deviceId, e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return applications;
|
||||
}
|
||||
|
||||
private Application loadApplication(ResultSet rs) throws DeviceManagementDAOException{
|
||||
|
||||
ByteArrayInputStream bais;
|
||||
ObjectInputStream ois;
|
||||
Properties properties;
|
||||
|
||||
Application application = new Application();
|
||||
application.setId(rs.getInt("ID"));
|
||||
application.setName(rs.getString("NAME"));
|
||||
application.setPackageName(rs.getString("PACKAGE_NAME"));
|
||||
application.setCategory(rs.getString("CATEGORY"));
|
||||
application.setType(rs.getString("TYPE"));
|
||||
application.setVersion(rs.getString("VERSION"));
|
||||
application.setImageUrl(rs.getString("IMAGE_URL"));
|
||||
application.setLocationUrl(rs.getString("LOCATION_URL"));
|
||||
application.setPlatform(rs.getString("PLATFORM"));
|
||||
try {
|
||||
application.setName(rs.getString("NAME"));
|
||||
application.setType(rs.getString("TYPE"));
|
||||
|
||||
if (rs.getBytes("APP_PROPERTIES") !=null) {
|
||||
byte[] appProperties = rs.getBytes("APP_PROPERTIES");
|
||||
bais = new ByteArrayInputStream(appProperties);
|
||||
|
||||
ois = new ObjectInputStream(bais);
|
||||
properties = (Properties) ois.readObject();
|
||||
application.setAppProperties(properties);
|
||||
}
|
||||
application.setCategory(rs.getString("CATEGORY"));
|
||||
application.setImageUrl(rs.getString("IMAGE_URL"));
|
||||
application.setLocationUrl(rs.getString("LOCATION_URL"));
|
||||
application.setPlatform(rs.getString("PLATFORM"));
|
||||
application.setVersion(rs.getString("VERSION"));
|
||||
application.setApplicationIdentifier(rs.getString("APP_IDENTIFIER"));
|
||||
|
||||
}catch (IOException ex){
|
||||
String errorMsg = "IO error occurred fetch at app properties";
|
||||
log.error(errorMsg, ex);
|
||||
throw new DeviceManagementDAOException(errorMsg, ex);
|
||||
}catch (ClassNotFoundException cex){
|
||||
String errorMsg = "Class not found error occurred fetch at app properties";
|
||||
log.error(errorMsg, cex);
|
||||
throw new DeviceManagementDAOException(errorMsg, cex);
|
||||
}catch (SQLException ex){
|
||||
String errorMsg = "SQL error occurred fetch at application";
|
||||
log.error(errorMsg, ex);
|
||||
throw new DeviceManagementDAOException(errorMsg, ex);
|
||||
}
|
||||
|
||||
return application;
|
||||
}
|
||||
|
||||
|
||||
@ -18,11 +18,15 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.ApplicationMappingDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
@ -30,9 +34,11 @@ import java.io.ObjectInputStream;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ApplicationMappingDAOImpl.class);
|
||||
@Override
|
||||
public int addApplicationMapping(int deviceId, int applicationId,
|
||||
int tenantId) throws DeviceManagementDAOException {
|
||||
@ -125,40 +131,5 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
|
||||
return DeviceManagementDAOFactory.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Application> getInstalledApplications(int deviceId) throws DeviceManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
List<Application> applications = new ArrayList<Application>();
|
||||
Application application;
|
||||
ByteArrayInputStream bais;
|
||||
ObjectInputStream ois;
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
stmt = conn.prepareStatement(
|
||||
"SELECT DEVICE_ID, APPLICATIONS FROM DM_DEVICE_APPLICATIONS WHERE DEVICE_ID = ?");
|
||||
stmt.setInt(1, deviceId);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
byte[] applicationDetails = rs.getBytes("APPLICATIONS");
|
||||
bais = new ByteArrayInputStream(applicationDetails);
|
||||
ois = new ObjectInputStream(bais);
|
||||
application = (Application) ois.readObject();
|
||||
applications.add(application);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new DeviceManagementDAOException("IO Error occurred while de serialize the Application object", e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new DeviceManagementDAOException("Class not found error occurred while de serialize the " +
|
||||
"Application object", e);
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceManagementDAOException("SQL Error occurred while retrieving the list of Applications " +
|
||||
"installed in device id '" + deviceId, e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return applications;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,8 @@ import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public class ApplicationPersistenceDAOTests extends BaseDeviceManagementDAOTest {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ApplicationPersistenceDAOTests.class);
|
||||
@ -33,10 +35,11 @@ public class ApplicationPersistenceDAOTests extends BaseDeviceManagementDAOTest
|
||||
@Test
|
||||
public void testAddApplication() {
|
||||
/* Initializing source application bean to be tested */
|
||||
Properties properties = new Properties();
|
||||
Application source = new Application();
|
||||
source.setName("SimpleCalculator");
|
||||
source.setCategory("TestCategory");
|
||||
source.setPackageName("com.simple.calculator");
|
||||
source.setApplicationIdentifier("com.simple.calculator");
|
||||
source.setType("TestType");
|
||||
source.setVersion("1.0.0");
|
||||
source.setImageUrl("http://test.org/image/");
|
||||
@ -58,14 +61,15 @@ public class ApplicationPersistenceDAOTests extends BaseDeviceManagementDAOTest
|
||||
/* Retrieving the application by its name */
|
||||
Application target = null;
|
||||
try {
|
||||
target = this.getApplication(source.getPackageName(), -1234);
|
||||
target = this.getApplication(source.getApplicationIdentifier(), -1234);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving application info";
|
||||
log.error(msg, e);
|
||||
Assert.fail(msg, e);
|
||||
}
|
||||
|
||||
Assert.assertEquals(target.getPackageName(), source.getPackageName(), "Application added is not as same as what's " +
|
||||
Assert.assertEquals(target.getApplicationIdentifier(), source.getApplicationIdentifier(), "Application added is not as same as " +
|
||||
"what's " +
|
||||
"retrieved");
|
||||
}
|
||||
|
||||
|
||||
@ -75,17 +75,17 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
||||
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||
NAME VARCHAR(50) NOT NULL,
|
||||
PACKAGE_NAME VARCHAR(50) NOT NULL,
|
||||
APP_IDENTIFIER VARCHAR(50) NOT NULL,
|
||||
PLATFORM VARCHAR(50) NULL DEFAULT NULL,
|
||||
CATEGORY VARCHAR(50) NULL,
|
||||
VERSION VARCHAR(50) NULL,
|
||||
TYPE VARCHAR(50) NULL,
|
||||
LOCATION_URL VARCHAR(100) NULL DEFAULT NULL,
|
||||
IMAGE_URL VARCHAR(100) NULL DEFAULT NULL,
|
||||
APP_PROPERTIES BLOB NULL,
|
||||
TENANT_ID INTEGER NOT NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
@ -88,15 +88,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
|
||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATIONS (
|
||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||
DEVICE_ID INTEGER NOT NULL,
|
||||
APPLICATIONS BLOB DEFAULT NULL,
|
||||
PRIMARY KEY (ID),
|
||||
CONSTRAINT fk_dm_device_applications_device FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
);
|
||||
|
||||
--- POLICY RELATED TABLES ----
|
||||
|
||||
|
||||
@ -307,13 +298,14 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
||||
CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||
NAME VARCHAR(50) NOT NULL,
|
||||
PACKAGE_NAME VARCHAR(50) NOT NULL,
|
||||
APP_IDENTIFIER VARCHAR(50) NOT NULL,
|
||||
PLATFORM VARCHAR(50) NULL DEFAULT NULL,
|
||||
CATEGORY VARCHAR(50) NULL,
|
||||
VERSION VARCHAR(50) NULL,
|
||||
TYPE VARCHAR(50) NULL,
|
||||
LOCATION_URL VARCHAR(100) NULL DEFAULT NULL,
|
||||
IMAGE_URL VARCHAR(100) NULL DEFAULT NULL,
|
||||
APP_PROPERTIES BLOB NULL,
|
||||
TENANT_ID INTEGER NOT NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user