revert-70aa11f8
geethkokila 10 years ago
commit 714ddc51a5

@ -69,5 +69,8 @@ public interface ApplicationManager {
void installApplication(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws ApplicationManagementException;
void updateInstalledApplicationListOfDevice(DeviceIdentifier deviceIdentifier,
List<Application> applications) throws ApplicationManagementException;
}

@ -83,6 +83,8 @@
org.wso2.carbon.identity.oauth.stub,
org.wso2.carbon.identity.oauth.stub.dto,
org.wso2.carbon.ndatasource.core,
org.wso2.carbon.base,
org.wso2.carbon.base.api
</Import-Package>
<Export-Package>
!org.wso2.carbon.device.mgt.core.internal,

@ -116,6 +116,12 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
}
}
@Override
public void updateInstalledApplicationListOfDevice(
DeviceIdentifier deviceIdentifier, List<Application> applications) throws ApplicationManagementException {
}
private OAuthConsumerAppDTO getAppInfo() throws ApplicationManagementException {
OAuthConsumerAppDTO appInfo = null;
try {

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

@ -60,21 +60,5 @@ public interface DeviceDAO {
EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser,
int tenantId) throws DeviceManagementDAOException;
/**
* Get the list of devices that matches with the given device name.
*
* @param id Name of the device
* @param applications List of applications
* @throws DeviceManagementDAOException
*/
void addDeviceApplications(int id, Object applications) throws DeviceManagementDAOException;
/**
* Get the list of devices that matches with the given device name.
*
* @param deviceId device id of the device
* @return List of Applications that are installed on the given device.
* @throws DeviceManagementDAOException
*/
List<Application> getInstalledApplications(int deviceId) throws DeviceManagementDAOException;
}

@ -26,6 +26,9 @@ 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 java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
@ -165,6 +168,43 @@ 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 {
return DeviceManagementDAOFactory.getConnection();
}

@ -24,15 +24,11 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
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 java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
@ -425,48 +421,6 @@ public class DeviceDAOImpl implements DeviceDAO {
}
}
@Override
public void addDeviceApplications(int id, Object applications) throws DeviceManagementDAOException {
}
@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 Device loadDevice(ResultSet rs) throws SQLException {
Device device = new Device();
device.setId(rs.getInt("DEVICE_ID"));

@ -29,6 +29,7 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.core.tenant.TenantManager;
import org.wso2.carbon.utils.ConfigurationContextService;
public class DeviceManagementDataHolder {
@ -42,6 +43,7 @@ public class DeviceManagementDataHolder {
private ApplicationManager appManager;
private AppManagementConfig appManagerConfig;
private OperationManager operationManager;
private ConfigurationContextService configurationContextService;
private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder();
@ -136,4 +138,12 @@ public class DeviceManagementDataHolder {
this.operationManager = operationManager;
}
public ConfigurationContextService getConfigurationContextService() {
return configurationContextService;
}
public void setConfigurationContextService(ConfigurationContextService configurationContextService) {
this.configurationContextService = configurationContextService;
}
}

@ -51,10 +51,12 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.startup.handler.URLPrinterStartupHandler;
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
import org.wso2.carbon.ndatasource.core.DataSourceService;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.ConfigurationContextService;
import java.util.ArrayList;
import java.util.List;
@ -91,6 +93,12 @@ import java.util.List;
* policy="dynamic"
* bind="setDataSourceService"
* unbind="unsetDataSourceService"
* @scr.reference name="config.context.service"
* interface="org.wso2.carbon.utils.ConfigurationContextService"
* cardinality="0..1"
* policy="dynamic"
* bind="setConfigurationContextService"
* unbind="unsetConfigurationContextService"
*/
public class DeviceManagementServiceComponent {
@ -197,6 +205,8 @@ public class DeviceManagementServiceComponent {
} catch (ApplicationManagementException appMgtEx) {
log.error("Application management service not registered.");
}
bundleContext.registerService(ServerStartupObserver.class, new URLPrinterStartupHandler(), null);
}
private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException {
@ -329,4 +339,18 @@ public class DeviceManagementServiceComponent {
//do nothing
}
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {
if (log.isDebugEnabled()) {
log.debug("Setting ConfigurationContextService");
}
DeviceManagementDataHolder.getInstance().setConfigurationContextService(configurationContextService);
}
protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService) {
if (log.isDebugEnabled()) {
log.debug("Un-setting ConfigurationContextService");
}
DeviceManagementDataHolder.getInstance().setConfigurationContextService(null);
}
}

@ -78,26 +78,5 @@ public interface DeviceManagementProviderService extends DeviceManager, LicenseM
*/
List<Device> getDevicesByName(String deviceName) throws DeviceManagementException;
/**
* The method to get application list installed for the device.
*
* @param deviceIdentifier
* @return List of applications installed on the device
* @throws DeviceManagementException
*/
List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException;
/**
* The method to get application list installed for the device.
*
* @param deviceIdentifier device identifier of the device
* @param applications List of installed Applications
*
* @throws DeviceManagementException
*/
void updateInstalledApplicationListOfDevice(DeviceIdentifier deviceIdentifier, List<Application> applications)
throws DeviceManagementException;
void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException;
}

@ -46,7 +46,8 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService, PluginInitializationListener {
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService,
PluginInitializationListener {
private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO;
@ -650,35 +651,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
@Override
public List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier)
throws DeviceManagementException {
Device device = null;
try {
device = this.getDevice(deviceIdentifier);
return deviceDAO.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 DeviceManagementException(errorMsg, deviceDaoEx);
}
}
@Override
public void updateInstalledApplicationListOfDevice(DeviceIdentifier deviceIdentifier,
List<Application> applications)
throws DeviceManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
deviceDAO.addDeviceApplications(device.getId(), applications);
}catch (DeviceManagementDAOException deviceDaoEx){
String errorMsg = "Error occurred saving application list to the device";
log.error(errorMsg+":"+deviceIdentifier.toString());
throw new DeviceManagementException(errorMsg, deviceDaoEx);
}
}
@Override
public void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status status) throws DeviceManagementException {

@ -0,0 +1,61 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.core.startup.handler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.core.ServerStartupObserver;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.ConfigurationContextService;
import org.wso2.carbon.utils.NetworkUtils;
public class URLPrinterStartupHandler implements ServerStartupObserver {
private static final Log log = LogFactory.getLog(URLPrinterStartupHandler.class);
@Override
public void completingServerStartup() {
}
@Override
public void completedServerStartup() {
log.info("EMM Console URL : " + this.getEmmUrl());
}
private String getEmmUrl() {
// Hostname
String hostName = "localhost";
try {
hostName = NetworkUtils.getMgtHostName();
} catch (Exception ignored) {
}
// HTTPS port
String mgtConsoleTransport = CarbonUtils.getManagementTransport();
ConfigurationContextService configContextService =
DeviceManagementDataHolder.getInstance().getConfigurationContextService();
int httpsPort = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport);
int httpsProxyPort =
CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(),
mgtConsoleTransport);
return "https://" + hostName + ":" + httpsPort + "/mdm";
}
}

@ -123,4 +123,10 @@ public class TestDeviceManagementService implements DeviceManagementService {
throws ApplicationManagementException {
}
@Override
public void updateInstalledApplicationListOfDevice(DeviceIdentifier deviceIdentifier,
List<Application> applications) throws ApplicationManagementException {
}
}

@ -191,7 +191,6 @@ public class DeviceManagementDAOTests extends BaseDeviceManagementDAOTest {
@Test(dependsOnMethods = "testAddDeviceTest")
public void testSetEnrolmentStatus() {
System.out.println("ENROLLLLLLLLLLLLLL");
Device device = this.loadDummyDevice();
try {
DeviceManagementDAOFactory.openConnection();

@ -17,7 +17,8 @@
~ 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/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.carbon.devicemgt</groupId>
@ -37,8 +38,8 @@
<modules>
<module>components/device-mgt</module>
<module>components/policy-mgt</module>
<module>components/webapp-authenticator-framework</module>
<module>components/oauth-extensions</module>
<module>components/webapp-authenticator-framework</module>
<module>components/oauth-extensions</module>
<module>features/device-mgt</module>
<module>features/policy-mgt</module>
<module>features/webapp-authenticator-framework</module>
@ -1162,7 +1163,7 @@
<!-- Carbon Device Management -->
<carbon.device.mgt.version>0.9.2-SNAPSHOT</carbon.device.mgt.version>
<!-- Carbon Commons -->
<!-- Carbon Commons -->
<carbon.commons.version>4.4.0</carbon.commons.version>
<!-- Carbon API Management -->

Loading…
Cancel
Save