revert-70aa11f8
geethkokila 9 years ago
commit fcb7530d3d

@ -83,7 +83,9 @@
org.wso2.carbon.identity.oauth.stub,
org.wso2.carbon.identity.oauth.stub.dto,
org.wso2.carbon.ndatasource.core,
org.apache.catalina
org.apache.catalina,
org.apache.catalina.core,
javax.servlet
</Import-Package>
<Export-Package>
!org.wso2.carbon.device.mgt.core.internal,
@ -212,6 +214,10 @@
<groupId>org.wso2.tomcat</groupId>
<artifactId>tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
</dependency>
</dependencies>
</project>

@ -53,6 +53,7 @@ public class APIConfig {
private String version;
private String transports;
private APIProvider provider;
private boolean isSecured;
public void init() throws DeviceManagementException {
try {
@ -126,4 +127,14 @@ public class APIConfig {
this.transports = transports;
}
@XmlElement(name = "isSecured", required = false)
public boolean isSecured() {
return isSecured;
}
@SuppressWarnings("unused")
public void setSecured(boolean secured) {
isSecured = secured;
}
}

@ -1,82 +0,0 @@
/*
* 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.api.mgt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.api.APIProvider;
import org.wso2.carbon.apimgt.api.model.API;
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
import org.wso2.carbon.core.ServerStartupObserver;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.api.mgt.config.APIPublisherConfig;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.util.List;
/**
* This particular class corresponding to the ServerStartupObserver written for publishing the set of APIs used by
* the device management related components.
*
* Note: Using this particular approach is not a must, had there been a proper programming interface provided by the
* underlying API-Management infrastructure for manipulating the APIs. Even though, there's one, its concrete
* implementation consumes a set of OSGi declarative services for initializing some of its internal states, which
* prevents us from, simply, instantiating the APIPublisher implementation and using for device management related
* tasks. The aforesaid complication lead us to go for this alternative approach to get the same done.
*/
public class APIRegistrationStartupObserver implements ServerStartupObserver {
private static final Log log = LogFactory.getLog(APIRegistrationStartupObserver.class);
@Override
public void completingServerStartup() {
}
@Override
public void completedServerStartup() {
/* Publish all mobile device management related JAX-RS services as APIs */
if (log.isDebugEnabled()) {
log.debug("Publishing all mobile device management related JAX-RS services as APIs");
}
List<APIConfig> apiConfigs = APIPublisherConfig.getInstance().getApiConfigs();
for (APIConfig apiConfig : apiConfigs) {
try {
/* API Config is initialized at this point in order to avoid OSGi declarative services which
the APIManagerComponent depend on, are deployed and initialized before invoking methods in
APIManagerFactory */
apiConfig.init();
API api = DeviceManagerUtil.getAPI(apiConfig);
DeviceManagementDataHolder.getInstance().getApiPublisherService().publishAPI(api);
} catch (Throwable e) {
/* Throwable is caught as none of the RuntimeExceptions that can potentially occur at this point
does not seem to be logged anywhere else within the framework */
log.error("Error occurred while publishing API '" + apiConfig.getName() + "' with the context '" +
apiConfig.getContext() + "' and version '" + apiConfig.getVersion() + "'", e);
}
}
if (log.isDebugEnabled()) {
log.debug("End of publishing all mobile device management related JAX-RS services as APIs");
}
}
}

@ -1,110 +0,0 @@
/*
* 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.api.mgt.config;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.api.mgt.APIConfig;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.utils.CarbonUtils;
import org.xml.sax.SAXException;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import java.io.File;
import java.util.List;
/**
* This class carries all API configurations used by device management components, that need to be published within
* the underlying API-Management infrastructure.
*/
@XmlRootElement(name = "APIPublisherConfig")
public class APIPublisherConfig {
private List<APIConfig> apiConfigs;
private static APIPublisherConfig config;
private static final Log log = LogFactory.getLog(APIPublisherConfig.class);
private static final String USER_DEFINED_API_CONFIG_PATH =
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "user-api-publisher-config.xml";
private static final String USER_DEFINED_API_CONFIG_SCHEMA_PATH =
"resources/config/schema/api-publisher-config-schema.xsd";
private static final Object LOCK = new Object();
public static APIPublisherConfig getInstance() {
if (config == null) {
synchronized (LOCK) {
try {
init();
} catch (DeviceManagementException e) {
log.error("Error occurred while initializing API Publisher Config", e);
}
}
}
return config;
}
@XmlElementWrapper(name = "APIs", required = true)
@XmlElement(name = "API", required = true)
public List<APIConfig> getApiConfigs() {
return apiConfigs;
}
@SuppressWarnings("unused")
public void setApiConfigs(List<APIConfig> apiConfigs) {
this.apiConfigs = apiConfigs;
}
private static void init() throws DeviceManagementException {
try {
File publisherConfig = new File(APIPublisherConfig.USER_DEFINED_API_CONFIG_PATH);
Document doc = DeviceManagerUtil.convertToDocument(publisherConfig);
/* Un-marshaling API publisher configuration */
JAXBContext ctx = JAXBContext.newInstance(APIPublisherConfig.class);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
//unmarshaller.setSchema(getSchema());
config = (APIPublisherConfig) unmarshaller.unmarshal(doc);
} catch (JAXBException e) {
throw new DeviceManagementException("Error occurred while un-marshalling API Publisher Config", e);
}
}
private static Schema getSchema() throws DeviceManagementException {
try {
File deviceManagementSchemaConfig = new File(APIPublisherConfig.USER_DEFINED_API_CONFIG_SCHEMA_PATH);
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
return factory.newSchema(deviceManagementSchemaConfig);
} catch (SAXException e) {
throw new DeviceManagementException("Error occurred while initializing the schema of " +
"user-api-publisher-config.xml", e);
}
}
}

@ -0,0 +1,131 @@
/*
* 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.api.mgt.lifecycle.listener;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.core.StandardContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.apimgt.api.model.API;
import org.wso2.carbon.device.mgt.core.api.mgt.APIConfig;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import javax.servlet.ServletContext;
public class APIPublisherLifecycleListener implements LifecycleListener {
private static final String API_CONFIG_DEFAULT_VERSION = "1.0.0";
private static final Log log = LogFactory.getLog(APIPublisherLifecycleListener.class);
@Override
public void lifecycleEvent(LifecycleEvent lifecycleEvent) {
if (Lifecycle.AFTER_START_EVENT.equals(lifecycleEvent.getType())) {
StandardContext context = (StandardContext) lifecycleEvent.getLifecycle();
ServletContext servletContext = context.getServletContext();
String param = servletContext.getInitParameter("managed-api-enabled");
boolean isManagedApi = (param != null && !"".equals(param)) && Boolean.parseBoolean(param);
if (isManagedApi) {
APIConfig apiConfig = this.buildApiConfig(servletContext);
try {
apiConfig.init();
API api = DeviceManagerUtil.getAPI(apiConfig);
DeviceManagementDataHolder.getInstance().getApiPublisherService().publishAPI(api);
} catch (Throwable e) {
/* Throwable is caught as none of the RuntimeExceptions that can potentially occur at this point
does not seem to be logged anywhere else within the framework */
log.error("Error occurred while publishing API '" + apiConfig.getName() + "' with the context '" +
apiConfig.getContext() + "' and version '" + apiConfig.getVersion() + "'", e);
}
}
}
}
private APIConfig buildApiConfig(ServletContext servletContext) {
APIConfig apiConfig = new APIConfig();
String name = servletContext.getInitParameter("managed-api-name");
if (name == null || "".equals(name)) {
if (log.isDebugEnabled()) {
log.debug("'managed-api-name' attribute is not configured. Therefore, using the default, " +
"which is the name of the web application");
}
name = servletContext.getServletContextName();
}
apiConfig.setName(name);
String version = servletContext.getInitParameter("managed-api-version");
if (version == null || "".equals(version)) {
if (log.isDebugEnabled()) {
log.debug("'managed-api-version' attribute is not configured. Therefore, using the " +
"default, which is '1.0.0'");
}
version = API_CONFIG_DEFAULT_VERSION;
}
apiConfig.setVersion(version);
String context = servletContext.getInitParameter("managed-api-context");
if (context == null || "".equals(context)) {
if (log.isDebugEnabled()) {
log.debug("'managed-api-context' attribute is not configured. Therefore, using the default, " +
"which is the original context assigned to the web application");
}
context = servletContext.getContextPath();
}
apiConfig.setContext(context);
String endpoint = servletContext.getInitParameter("managed-api-endpoint");
if (endpoint == null || "".equals(endpoint)) {
if (log.isDebugEnabled()) {
log.debug("'managed-api-endpoint' attribute is not configured");
}
}
apiConfig.setEndpoint(endpoint);
String owner = servletContext.getInitParameter("managed-api-owner");
if (owner == null || "".equals(owner)) {
if (log.isDebugEnabled()) {
log.debug("'managed-api-owner' attribute is not configured");
}
}
apiConfig.setOwner(owner);
String isSecuredParam = servletContext.getInitParameter("managed-api-isSecured");
boolean isSecured =
(isSecuredParam != null && !"".equals(isSecuredParam)) && Boolean.parseBoolean(isSecuredParam);
apiConfig.setSecured(isSecured);
String transports = servletContext.getInitParameter("managed-api-transports");
if (transports == null || "".equals(transports)) {
if (log.isDebugEnabled()) {
log.debug("'managed-api-transports' attribute is not configured. Therefore using the defaults, " +
"which are 'http' and 'https'");
}
transports = "http,https";
}
apiConfig.setTransports(transports);
return apiConfig;
}
}

@ -78,7 +78,8 @@ public class DeviceDAOImpl implements DeviceDAO {
int deviceId = -1;
try {
conn = this.getConnection();
String sql = "UPDATE DM_DEVICE SET DESCRIPTION = ?, NAME = ? WHERE DEVICE_IDENTIFICATION = ? AND " +
String sql =
"UPDATE DM_DEVICE SET DESCRIPTION = ?, NAME = ? WHERE DEVICE_IDENTIFICATION = ? AND " +
"DEVICE_TYPE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, device.getDescription());
@ -116,9 +117,11 @@ public class DeviceDAOImpl implements DeviceDAO {
conn = this.getConnection();
String sql =
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT " +
"FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
"t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?";
"t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
"AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceId.getType());
stmt.setString(2, deviceId.getId());
@ -145,8 +148,10 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = null;
try {
conn = this.getConnection();
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME," +
String sql =
"SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " +
"FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME," +
"d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
@ -175,11 +180,13 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = null;
try {
conn = this.getConnection();
String selectDBQueryForType = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION," +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"d.DEVICE_IDENTIFICATION, d.OWNER, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
"WHERE d.DM_DEVICE.DEVICE_TYPE_ID = t.ID AND t.NAME = ? AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt = conn.prepareStatement(selectDBQueryForType);
String sql =
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " +
"FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, d.OWNER, t.NAME " +
"AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " +
"AND d.TENANT_ID = ?) d1 WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, type);
stmt.setInt(2, tenantId);
stmt.setInt(3, tenantId);
@ -204,14 +211,17 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = new ArrayList<Device>();
try {
conn = this.getConnection();
stmt = conn.prepareStatement(
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d.DEVICE_IDENTIFICATION" +
" e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT t.NAME AS DEVICE_TYPE, d.ID, d.DESCRIPTION, " +
"d.NAME, d.DEVICE_IDENTIFICATION FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.OWNER =? AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?");
stmt.setString(1, username);
String sql =
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT t.NAME AS DEVICE_TYPE, d.ID, d.DESCRIPTION, " +
"d.NAME, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 " +
"WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? AND e.OWNER = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId);
stmt.setInt(3, tenantId);
stmt.setString(3, username);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
@ -275,16 +285,16 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = new ArrayList<Device>();
try {
conn = this.getConnection();
stmt = conn.prepareStatement(
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d.DEVICE_IDENTIFICATION " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, d.NAME, d.DESCRIPTION, " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
"AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?");
String sql =
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " +
"FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, d.DESCRIPTION, t.NAME AS DEVICE_TYPE, " +
"d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
"AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceName + "%");
stmt.setInt(2, tenantId);
stmt.setInt(3, tenantId);
stmt.setInt(4, tenantId);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
@ -308,8 +318,9 @@ public class DeviceDAOImpl implements DeviceDAO {
int enrolmentId = -1;
try {
conn = this.getConnection();
String sql = "INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS, " +
"DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE, TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)";
String sql =
"INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS,DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE, " +
"TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
stmt.setInt(1, device.getId());
stmt.setString(2, device.getEnrolmentInfo().getOwner());
@ -339,9 +350,10 @@ public class DeviceDAOImpl implements DeviceDAO {
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String sql = "UPDATE DM_ENROLMENT SET STATUS = ? WHERE DEVICE_ID = " +
"(SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND " +
"d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) AND OWNER = ? AND TENANT_ID = ?";
String sql =
"UPDATE DM_ENROLMENT SET STATUS = ? WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
"AND OWNER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, status.toString());
stmt.setString(2, deviceId.getId());
@ -367,7 +379,8 @@ public class DeviceDAOImpl implements DeviceDAO {
Status status = null;
try {
conn = this.getConnection();
String sql = "SELECT STATUS FROM DM_ENROLMENT WHERE DEVICE_ID = " +
String sql =
"SELECT STATUS FROM DM_ENROLMENT WHERE DEVICE_ID = " +
"(SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND " +
"d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) AND OWNER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
@ -398,10 +411,11 @@ public class DeviceDAOImpl implements DeviceDAO {
EnrolmentInfo enrolmentInfo = null;
try {
conn = this.getConnection();
String sql = "SELECT ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " +
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = " +
"(SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND" +
" d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) AND OWNER = ? AND TENANT_ID = ?";
String sql =
"SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE, " +
"TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
"AND OWNER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceId.getId());
stmt.setString(2, deviceId.getType());
@ -442,18 +456,21 @@ public class DeviceDAOImpl implements DeviceDAO {
return enrolmentInfo;
}
public List<Device> getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException {
public List<Device> getDevicesByStatus(EnrolmentInfo.Status status, int tenantId)
throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
List<Device> devices = new ArrayList<Device>();
try {
conn = this.getConnection();
stmt = conn.prepareStatement("SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
String sql =
"SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " +
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE FROM DM_ENROLMENT e WHERE TENANT_ID = ? " +
"AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_ID = e.DEVICE_ID " +
"AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?");
"AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, status.toString());
stmt.setInt(3, tenantId);

@ -35,7 +35,6 @@ import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository;
import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService;
import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherServiceImpl;
import org.wso2.carbon.device.mgt.core.api.mgt.APIRegistrationStartupObserver;
import org.wso2.carbon.device.mgt.core.api.mgt.ApplicationManagementProviderService;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagerProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
@ -198,8 +197,6 @@ public class DeviceManagementServiceComponent {
DeviceManagementDataHolder.getInstance().setApiPublisherService(publisher);
bundleContext.registerService(APIPublisherService.class, publisher, null);
bundleContext.registerService(ServerStartupObserver.class, new APIRegistrationStartupObserver(), null);
/* Registering App Management service */
try {
AppManagementConfigurationManager.getInstance().initConfig();

@ -1,46 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<APIPublisherConfig>
<APIs>
<API>
<Name>AppManagerController</Name>
<Owner>admin</Owner>
<Context>appmanager</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/appmanager</Endpoint>
<Transports>http,https</Transports>
</API>
<API>
<Name>AndroidAgent</Name>
<Owner>admin</Owner>
<Context>mdm-android-agent</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/mdm-android-agent</Endpoint>
<Transports>http,https</Transports>
</API>
<API>
<Name>MDMAdmin</Name>
<Owner>admin</Owner>
<Context>mdm-admin</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/mdm-admin</Endpoint>
<Transports>http,https</Transports>
</API>
</APIs>
</APIPublisherConfig>

@ -2,7 +2,6 @@ instructions.configure = \
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/notification-messages.xml,target:${installFolder}/../../conf/notification-messages.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/user-api-publisher-config.xml,target:${installFolder}/../../conf/etc/user-api-publisher-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/app-management-config.xml,target:${installFolder}/../../conf/etc/app-management-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\
Loading…
Cancel
Save