Move add application list, get applist methods to applicationServiceProvider

4.x.x
manoj 10 years ago
parent 66afd0be4b
commit cc5dd3baa6

@ -110,11 +110,63 @@ public class Application implements Serializable {
} }
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof Application)) { if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Application that = (Application) o;
if (id != that.id) {
return false;
}
if (appProperties != null ? !appProperties.equals(that.appProperties) : that.appProperties != null) {
return false;
}
if (category != null ? !category.equals(that.category) : that.category != null) {
return false;
}
if (imageUrl != null ? !imageUrl.equals(that.imageUrl) : that.imageUrl != null) {
return false;
}
if (locationUrl != null ? !locationUrl.equals(that.locationUrl) : that.locationUrl != null) {
return false; return false;
} }
Application target = (Application)o; if (name != null ? !name.equals(that.name) : that.name != null) {
return packageName.equals(target.getPackageName()); 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;
}
if (type != null ? !type.equals(that.type) : that.type != null) {
return false;
}
if (version != null ? !version.equals(that.version) : that.version != 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);
result = 31 * result + (locationUrl != null ? locationUrl.hashCode() : 0);
result = 31 * result + (imageUrl != null ? imageUrl.hashCode() : 0);
result = 31 * result + (version != null ? version.hashCode() : 0);
result = 31 * result + (type != null ? type.hashCode() : 0);
result = 31 * result + (appProperties != null ? appProperties.hashCode() : 0);
return result;
} }
public Properties getAppProperties() { public Properties getAppProperties() {

@ -12,4 +12,6 @@ public interface ApplicationManagementProviderService extends ApplicationManager
public void updateApplicationListInstallInDevice(DeviceIdentifier deviceIdentifier, public void updateApplicationListInstallInDevice(DeviceIdentifier deviceIdentifier,
List<Application> applications) throws ApplicationManagementException; List<Application> applications) throws ApplicationManagementException;
public List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier)
throws ApplicationManagementException;
} }

@ -182,6 +182,21 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
} }
} }
@Override
public List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier)
throws ApplicationManagementException {
Device device = null;
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
device = deviceDAO.getDevice(deviceIdentifier, tenantId);
return applicationMappingDAO.getInstalledApplications(device.getId());
}catch (DeviceManagementDAOException deviceDaoEx) {
String errorMsg = "Error occured while fetching the Application List of device : " + device.getId();
log.error(errorMsg, deviceDaoEx);
throw new ApplicationManagementException(errorMsg, deviceDaoEx);
}
}
@Override @Override
public void registerDeviceManagementService(DeviceManagementService deviceManagementService) { public void registerDeviceManagementService(DeviceManagementService deviceManagementService) {
try { try {

@ -31,7 +31,4 @@ public interface ApplicationDAO {
int removeApplication(String applicationName, int tenantId) throws DeviceManagementDAOException; int removeApplication(String applicationName, int tenantId) throws DeviceManagementDAOException;
Application getApplication(String identifier, int tenantId) throws DeviceManagementDAOException; Application getApplication(String identifier, int tenantId) throws DeviceManagementDAOException;
List<Application> getInstalledApplications(int deviceId) throws DeviceManagementDAOException;
} }

@ -18,6 +18,8 @@
*/ */
package org.wso2.carbon.device.mgt.core.dao; package org.wso2.carbon.device.mgt.core.dao;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import java.util.List; import java.util.List;
public interface ApplicationMappingDAO { public interface ApplicationMappingDAO {
@ -29,4 +31,6 @@ public interface ApplicationMappingDAO {
int removeApplicationMapping(int deviceId, int applicationId, int tenantId) throws DeviceManagementDAOException; int removeApplicationMapping(int deviceId, int applicationId, int tenantId) throws DeviceManagementDAOException;
List<Application> getInstalledApplications(int deviceId) throws DeviceManagementDAOException;
} }

@ -168,43 +168,6 @@ public class ApplicationDAOImpl implements ApplicationDAO {
} }
} }
@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;
}
private Connection getConnection() throws DeviceManagementDAOException { private Connection getConnection() throws DeviceManagementDAOException {
return DeviceManagementDAOFactory.getConnection(); return DeviceManagementDAOFactory.getConnection();
} }

@ -18,11 +18,15 @@
*/ */
package org.wso2.carbon.device.mgt.core.dao.impl; package org.wso2.carbon.device.mgt.core.dao.impl;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.core.dao.ApplicationMappingDAO; 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.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; 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.dao.util.DeviceManagementDAOUtil;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -121,4 +125,40 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO {
return DeviceManagementDAOFactory.getConnection(); 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;
}
} }

@ -65,7 +65,8 @@ public class ApplicationPersistenceDAOTests extends BaseDeviceManagementDAOTest
Assert.fail(msg, e); Assert.fail(msg, e);
} }
Assert.assertEquals(target, source, "Application added is not as same as what's retrieved"); Assert.assertEquals(target.getPackageName(), source.getPackageName(), "Application added is not as same as what's " +
"retrieved");
} }
private Application getApplication(String packageName, int tenantId) throws DeviceManagementDAOException { private Application getApplication(String packageName, int tenantId) throws DeviceManagementDAOException {

@ -276,8 +276,6 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
ON UPDATE NO ACTION ON UPDATE NO ACTION
); );
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES ( CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
ID INT NOT NULL AUTO_INCREMENT, ID INT NOT NULL AUTO_INCREMENT,
POLICY_CRITERION_ID INT NOT NULL, POLICY_CRITERION_ID INT NOT NULL,
@ -292,6 +290,45 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
ON UPDATE NO ACTION ON UPDATE NO ACTION
); );
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OWNER VARCHAR(50) NOT NULL,
OWNERSHIP VARCHAR(45) NULL DEFAULT NULL,
STATUS VARCHAR(50) NULL,
DATE_OF_ENROLMENT TIMESTAMP NULL DEFAULT NULL,
DATE_OF_LAST_UPDATE TIMESTAMP NULL DEFAULT NULL,
TENANT_ID INT NOT NULL,
PRIMARY KEY (ID),
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,
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,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
APPLICATION_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-- POLICY RELATED TABLES FINISHED -- -- POLICY RELATED TABLES FINISHED --

Loading…
Cancel
Save