revert-70aa11f8
inosh-perera 10 years ago
commit 8c613539cc

@ -0,0 +1,30 @@
/**
* Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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.common;
public class DefaultOperation implements Operation {
@Override
public void init() {
}
@Override
public void execute() {
}
}

@ -0,0 +1,60 @@
/*
* Copyright (c) 2014, 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.common;
/**
* Created by manoj on 12/22/14.
*/
public class DeviceManagementServiceException extends Exception {
private static final long serialVersionUID = -8933146283800122640L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public DeviceManagementServiceException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public DeviceManagementServiceException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public DeviceManagementServiceException(String msg) {
super(msg);
setErrorMessage(msg);
}
public DeviceManagementServiceException() {
super();
}
public DeviceManagementServiceException(Throwable cause) {
super(cause);
}
}

@ -0,0 +1,33 @@
/**
* Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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.common;
/**
* This class needs to be implemented by all
*/
public interface Operation {
/**
* Initializes any start-up resources required to execute a particular operation
*/
void init();
/**
* Executes the functionality configured within the method implementation
*/
void execute();
}

@ -0,0 +1,75 @@
/**
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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.common;
import java.util.Properties;
public class OperationData {
public enum Type {
CONFIG, MESSAGE, STATE
}
private String name;
private boolean state;
private Properties properties;
private String text;
private Type type;
public OperationData(String name, Type type) {
this.type = type;
this.name = name;
}
public OperationData(String name, boolean state) {
this.name = name;
this.type = Type.STATE;
this.state = state;
}
public OperationData(String name, Properties properties) {
this.name = name;
this.type = Type.CONFIG;
this.properties = properties;
}
public OperationData(String name, String text) {
this.name = name;
this.type = Type.MESSAGE;
this.text = text;
}
public Type getType() {
return type;
}
public boolean getState() {
return state;
}
public String getText() {
return text;
}
public Properties getProperties() {
return properties;
}
public String getName() {
return name;
}
}

@ -0,0 +1,24 @@
/**
* Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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.common;
public class OperationFactory {
public static Operation getOperation(String type) {
return new DefaultOperation();
}
}

@ -15,13 +15,18 @@
*/
package org.wso2.carbon.device.mgt.core;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.util.HashMap;
import java.util.Map;
public class DeviceManagementRepository {
private static final Log log = LogFactory.getLog(DeviceManagerUtil.class);
private Map<String, DeviceManagerService> providers;
public DeviceManagementRepository() {
@ -29,7 +34,13 @@ public class DeviceManagementRepository {
}
public void addDeviceManagementProvider(DeviceManagerService provider) {
providers.put(provider.getProviderType(), provider);
String deviceType = provider.getProviderType();
providers.put(deviceType, provider);
try {
DeviceManagerUtil.registerDeviceType(deviceType);
} catch (DeviceManagementException e) {
log.error("Exception occured while registering the device type.",e);
}
}
public DeviceManagerService getDeviceManagementProvider(String type) {

@ -1,17 +1,19 @@
/**
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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
* 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
* 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.
* 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;

@ -1,17 +1,19 @@
/**
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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
* 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
* 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.
* 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;
@ -29,13 +31,13 @@ import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import java.util.List;
public class DeviceManagerImpl implements DeviceManager{
public class DeviceManagerImpl implements DeviceManager {
private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO;
private DeviceManagementConfig config;
private DeviceManagementRepository pluginRepository;
public DeviceManagerImpl(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) {
this.config = config;
this.pluginRepository = pluginRepository;
@ -45,61 +47,57 @@ public class DeviceManagerImpl implements DeviceManager{
@Override
public boolean enrollDevice(Device device) throws DeviceManagementException {
DeviceManagerService dms =
this.getPluginRepository().getDeviceManagementProvider(device.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
boolean status = dms.enrollDevice(device);
try {
this.getDeviceTypeDAO().getDeviceType();
org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(
device);
org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device);
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
deviceDto.setDeviceType(deviceTypeId);
this.getDeviceDAO().addDevice(deviceDto);
Integer deviceTypeId = this.getDeviceDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
deviceDto.setDeviceType(deviceTypeId);
this.getDeviceDAO().addDevice(deviceDto);
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while enrolling the device '" +
device.getId() + "'", e);
throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'",
e);
}
return status;
}
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
DeviceManagerService dms =
this.getPluginRepository().getDeviceManagementProvider(device.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
boolean status = dms.modifyEnrollment(device);
try {
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while modifying the device '" +
device.getId() + "'", e);
throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + "'",
e);
}
return status;
}
@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManagerService dms =
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
return dms.disenrollDevice(deviceId);
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManagerService dms =
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
return dms.isEnrolled(deviceId);
}
@Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManagerService dms =
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
return dms.isActive(deviceId);
}
@Override
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
public boolean setActive(DeviceIdentifier deviceId, boolean status)
throws DeviceManagementException {
DeviceManagerService dms =
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
return dms.setActive(deviceId, status);
@ -114,28 +112,24 @@ public class DeviceManagerImpl implements DeviceManager{
@Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManagerService dms =
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
return dms.getDevice(deviceId);
}
@Override
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
DeviceManagerService dms =
this.getPluginRepository().getDeviceManagementProvider(device.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
return dms.updateDeviceInfo(device);
}
@Override
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
DeviceManagerService dms =
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
return dms.setOwnership(deviceId, ownershipType);
}
public OperationManager getOperationManager(String type) throws DeviceManagementException {
DeviceManagerService dms =
this.getPluginRepository().getDeviceManagementProvider(type);
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type);
return dms.getOperationManager();
}

@ -1,14 +1,17 @@
/*
* Copyright (c) 2014, 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.
*
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@ -27,14 +30,14 @@ import javax.xml.bind.Unmarshaller;
import java.io.File;
/**
* Class responsible for the rss manager configuration initialization
* Class responsible for the cdm manager configuration initialization
*/
public class DeviceConfigurationManager {
private DeviceManagementConfig currentDeviceConfig;
private static DeviceConfigurationManager deviceConfigManager;
private final String deviceMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
private static final String deviceMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME;
public static DeviceConfigurationManager getInstance() {
@ -49,6 +52,8 @@ public class DeviceConfigurationManager {
}
public synchronized void initConfig() throws DeviceManagementException {
//catch generic exception.if any exception occurs wrap and throw DeviceManagementException
try {
File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);

@ -1,14 +1,17 @@
/*
* Copyright (c) 2014, 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.
*
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

@ -1,21 +1,23 @@
/*
* Copyright (c) 2014, 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.
*
* 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
* 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.config;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@ -1,25 +1,27 @@
/*
* Copyright (c) 2014, 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.
*
* 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
* 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.config.datasource;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Class for holding data source configuration in rss-config.xml at parsing with JAXB
* Class for holding data source configuration in cdm-config.xml at parsing with JAXB
*/
@XmlRootElement(name = "DataSourceConfiguration")
public class DataSourceConfig {

@ -1,14 +1,17 @@
/*
* Copyright (c) 2014, 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.
*
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@ -36,6 +39,4 @@ public interface DeviceDAO {
Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException;
List<Device> getDevices() throws DeviceManagementDAOException;
Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException;
}

@ -1,18 +1,21 @@
/**
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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
* 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
* 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.
* 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.dao;
import org.apache.commons.logging.Log;
@ -22,7 +25,6 @@ import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.device.mgt.core.dao.impl.DeviceDAOImpl;
import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import javax.sql.DataSource;
import java.util.Hashtable;
import java.util.List;
@ -57,8 +59,8 @@ public class DeviceManagementDAOFactory {
private static DataSource resolveDataSource(DataSourceConfig config) {
DataSource dataSource = null;
if (config == null) {
throw new RuntimeException("Device Management Repository data source configuration " +
"is null and thus, is not initialized");
throw new RuntimeException("Device Management Repository data source configuration " + "is null and " +
"thus, is not initialized");
}
JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion();
if (jndiConfig != null) {
@ -66,15 +68,13 @@ public class DeviceManagementDAOFactory {
log.debug("Initializing Device Management Repository data source using the JNDI " +
"Lookup Definition");
}
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
jndiConfig.getJndiProperties();
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = jndiConfig.getJndiProperties();
if (jndiPropertyList != null) {
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
jndiProperties.put(prop.getName(), prop.getValue());
}
dataSource =
DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
} else {
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
}

@ -11,11 +11,10 @@
* 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
* 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.dao;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
@ -36,4 +35,6 @@ public interface DeviceTypeDAO {
DeviceIdentifier getDeviceType() throws DeviceManagementDAOException;
Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException;
}

@ -11,7 +11,7 @@
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@ -102,38 +102,6 @@ public class DeviceDAOImpl implements DeviceDAO {
return null;
}
@Override
public Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet resultSet = null;
Integer deviceTypeId = null;
try {
conn = this.getConnection();
String createDBQuery =
"SELECT * From DM_DEVICE_TYPE DT WHERE DT.NAME=?";
stmt = conn.prepareStatement(createDBQuery);
stmt.setString(1, type);
resultSet = stmt.executeQuery();
while(resultSet.next()){
deviceTypeId = resultSet.getInt(1);
}
} catch (SQLException e) {
String msg = "Error occurred while fetch device type id for device type '" + type + "'";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
}
return deviceTypeId;
}
private Connection getConnection() throws DeviceManagementDAOException {
try {
return dataSource.getConnection();

@ -1,35 +1,42 @@
/**
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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
* 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
* 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.
* 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.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class DeviceTypeDAOImpl implements DeviceTypeDAO {
private DataSource dataSource;
private static final Log log = LogFactory.getLog(DeviceTypeDAOImpl.class);
public DeviceTypeDAOImpl(DataSource dataSource) {
this.dataSource = dataSource;
@ -44,8 +51,9 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
stmt.setString(1, deviceType.getName());
stmt.execute();
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while registering the device type '" +
deviceType.getName() + "'", e);
String msg = "Error occurred while registering the device type '" + deviceType.getName() + "'";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
}
@ -58,21 +66,72 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
@Override
public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
return null;
Connection conn = this.getConnection();
PreparedStatement stmt = null;
List<DeviceType> deviceTypes = new ArrayList<DeviceType>();
try {
stmt = conn.prepareStatement("SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE");
ResultSet results = stmt.executeQuery();
while (results.next()) {
DeviceType deviceType = new DeviceType();
deviceType.setId(results.getLong("DEVICE_TYPE_ID"));
deviceType.setName(results.getString("DEVICE_TYPE"));
deviceTypes.add(deviceType);
}
} catch (SQLException e) {
String msg = "Error occurred while fetching the registered device types";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
}
return deviceTypes;
}
@Override
public DeviceIdentifier getDeviceType() throws DeviceManagementDAOException {
return new DeviceIdentifier();
//TODO:
return null;
}
@Override
public Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException {
Connection conn = this.getConnection();
PreparedStatement stmt = null;
ResultSet resultSet = null;
Integer deviceTypeId = null;
try {
String createDBQuery = "SELECT * From DM_DEVICE_TYPE DT WHERE DT.NAME=?";
stmt = conn.prepareStatement(createDBQuery);
stmt.setString(1, type);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
deviceTypeId = resultSet.getInt(1);
}
} catch (SQLException e) {
String msg = "Error occurred while fetch device type id for device type '" + type + "'";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
}
return deviceTypeId;
}
private Connection getConnection() throws DeviceManagementDAOException {
try {
return dataSource.getConnection();
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while obtaining a connection from the device " +
"management metadata repository datasource", e);
String msg = "Error occurred while obtaining a connection from the device " +
"management metadata repository datasource";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
}

@ -61,6 +61,9 @@ public final class DeviceManagementDAOUtil {
log.warn("Error occurred while closing database connection", e);
}
}
rs = null;
stmt = null;
conn = null;
}
/**
@ -83,8 +86,7 @@ public final class DeviceManagementDAOUtil {
try {
tenantId = tenantManager.getTenantId(tenantDomain);
} catch (UserStoreException e) {
String msg = "Error occurred while retrieving id from the domain of tenant " +
tenantDomain;
String msg = "Error occurred while retrieving id from the domain of tenant " + tenantDomain;
throw new DeviceManagementDAOException(msg);
}
return tenantId;

@ -1,17 +1,19 @@
/**
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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
* 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
* 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.
* 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.internal;
@ -56,7 +58,6 @@ public class DeviceManagementServiceComponent {
try {
/* Initializing Device Management Configuration */
DeviceConfigurationManager.getInstance().initConfig();
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
DataSourceConfig dsConfig = config.getDeviceMgtRepository().getDataSourceConfig();
@ -88,6 +89,8 @@ public class DeviceManagementServiceComponent {
private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException {
DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config);
log.info("Initializing device management repository database schema");
// catch generic exception. If any error occurs wrap and throw DeviceManagementException
try {
initializer.createRegistryDatabase();
} catch (Exception e) {

@ -21,7 +21,11 @@ import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
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.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import javax.sql.DataSource;
import javax.xml.parsers.DocumentBuilder;
@ -47,7 +51,7 @@ public final class DeviceManagerUtil {
}
/**
* Resolve data source from the data source definition
* Resolve data source from the data source definition.
*
* @param config data source configuration
* @return data source resolved from the data source definition
@ -80,4 +84,27 @@ public final class DeviceManagerUtil {
return dataSource;
}
/**
* Adds a new device type to the database if it does not exists.
*
* @param deviceTypeName device type
* @return status of the operation
*/
public static boolean registerDeviceType(String deviceTypeName) throws DeviceManagementException{
boolean status = false;
try {
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceTypeName);
if(deviceTypeId == null){
DeviceType deviceType = new DeviceType();
deviceType.setName(deviceTypeName);
deviceTypeDAO.addDeviceType(deviceType);
}
status = true;
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while registering the device type " + deviceTypeName;
throw new DeviceManagementException(msg, e);
}
return status;
}
}

@ -1,20 +1,20 @@
/*
* Copyright (c) 2014, 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.
*/
* Copyright (c) 2014, 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;

@ -1,14 +1,17 @@
/*
* Copyright (c) 2014, 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.
*
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

@ -1,14 +1,17 @@
/*
* Copyright (c) 2014, 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.
*
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

@ -1,14 +1,17 @@
/*
* Copyright (c) 2014, 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.
*
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

@ -1,14 +1,17 @@
/*
* Copyright (c) 2014, 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.
*
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@ -66,8 +69,8 @@ public class DeviceMgtDAOTestSuite {
}
}
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType)
throws DeviceManagementDAOException, DeviceManagementException {
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws DeviceManagementDAOException,
DeviceManagementException {
File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml");
Document doc = null;

@ -1,4 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2014, 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.
-->
<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">

@ -27,7 +27,7 @@ import javax.xml.bind.Unmarshaller;
import java.io.File;
/**
* Class responsible for the mobile device manager configuration initialization
* Class responsible for the mobile device manager configuration initialization.
*/
public class MobileDeviceConfigurationManager {

@ -21,7 +21,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Class for holding management repository data
* Class for holding management repository data.
*/
@XmlRootElement(name = "ManagementRepository")
public class MobileDeviceManagementRepository {

@ -20,7 +20,7 @@ import javax.xml.bind.annotation.*;
import java.util.List;
/**
* Class for hold JndiLookupDefinition of mobile-config.xml at parsing with JAXB
* Class for hold JndiLookupDefinition of mobile-config.xml at parsing with JAXB.
*/
@XmlRootElement(name = "JndiLookupDefinition")
public class JNDILookupDefinition {

@ -20,7 +20,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Class for holding data source configuration in mobile-config.xml at parsing with JAXB
* Class for holding data source configuration in mobile-config.xml at parsing with JAXB.
*/
@XmlRootElement(name = "DataSourceConfiguration")
public class MobileDataSourceConfig {

@ -49,7 +49,7 @@ public class MobileDeviceManagementDAOException extends Exception {
}
/**
* Constructs a new MobileDeviceManagementDAOException with the specified detail message
* Constructs a new MobileDeviceManagementDAOException with the specified detail message.
*
* @param message the detail message.
*/

@ -40,7 +40,7 @@ public class MobileDeviceManagementDAOUtil {
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOUtil.class);
/**
* Resolve data source from the data source definition
* Resolve data source from the data source definition.
*
* @param config Mobile data source configuration
* @return data source resolved from the data source definition
@ -128,7 +128,7 @@ public class MobileDeviceManagementDAOUtil {
}
/**
* Initializes the creation of mobile device management schema if -Dsetup has provided
* Initializes the creation of mobile device management schema if -Dsetup has provided.
*
* @param dataSource Mobile data source
*/
@ -151,7 +151,7 @@ public class MobileDeviceManagementDAOUtil {
}
/**
* Creates the mobile device management schema
* Creates the mobile device management schema.
*
* @param dataSource Mobile data source
*/

@ -22,7 +22,7 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
import java.util.List;
/**
* This represents the iOS implementation of DeviceManagerService. *
* This represents the iOS implementation of DeviceManagerService.
*/
public class IOSDeviceManagerService implements DeviceManagerService {

@ -1,45 +0,0 @@
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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.mobile.util;
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 javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
public class DeviceManagementUtil {
private static final Log log = LogFactory.getLog(DeviceManagementUtil.class);
public static Document convertToDocument(File file) throws DeviceManagementException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
try {
DocumentBuilder docBuilder = factory.newDocumentBuilder();
return docBuilder.parse(file);
} catch (Exception e) {
throw new DeviceManagementException(
"Error occurred while parsing file, while converting " +
"to a org.w3c.dom.Document : " + e.getMessage(), e);
}
}
}

@ -1,18 +1,20 @@
<!--
~ Copyright 2011-2012 WSO2, Inc. (http://wso2.com)
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ 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.
-->
~ 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"
@ -176,5 +178,4 @@
<cxf.version>2.6.1</cxf.version>
<junit.version>4.8.2</junit.version>
</properties>
</project>

@ -1,33 +1,33 @@
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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
* 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
* 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.
* 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 cdm.api.android;
import cdm.api.android.common.AndroidAgentException;
import cdm.api.android.util.AndroidAPIUtils;
import cdm.api.android.util.AndroidConstants;
import cdm.api.android.util.Message;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManagementServiceException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import java.util.List;
@ -39,107 +39,112 @@ import java.util.List;
@Consumes({ "application/json", "application/xml" })
public class Device {
private static Log log = LogFactory.getLog(Device.class);
@GET
public List<org.wso2.carbon.device.mgt.common.Device> getAllDevices() {
List<org.wso2.carbon.device.mgt.common.Device> devices = null;
String msg = "";
DeviceManagementService dmService;
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
try {
if (dmService != null) {
devices = dmService.getAllDevices(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
Response.status(HttpStatus.SC_OK);
} else {
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
} catch (DeviceManagementException e) {
msg = "Error occurred while fetching the device list.";
log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
return devices;
}
@GET
@Path("{id}")
public org.wso2.carbon.device.mgt.common.Device getDevice(@PathParam("id") String id) {
String msg = "";
DeviceManagementService dmService;
org.wso2.carbon.device.mgt.common.Device device =
new org.wso2.carbon.device.mgt.common.Device();
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
try {
if (dmService != null) {
device = dmService.getDevice(deviceIdentifier);
if (device == null) {
Response.status(HttpStatus.SC_NOT_FOUND);
}
} else {
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
} catch (DeviceManagementException e) {
msg = "Error occurred while fetching the device information.";
log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
return device;
}
@PUT
@Path("{id}")
public Message updateDevice(@PathParam("id") String id,
org.wso2.carbon.device.mgt.common.Device device) {
boolean result = false;
String msg = "";
DeviceManagementService dmService;
Message responseMessage = new Message();
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
try {
if (dmService != null) {
device.setType(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
result = dmService.updateDeviceInfo(device);
if (result) {
Response.status(HttpStatus.SC_OK);
responseMessage.setResponseMessage("Device information has modified successfully.");
} else {
Response.status(HttpStatus.SC_NOT_MODIFIED);
responseMessage.setResponseMessage("Update device has failed.");
}
} else {
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
responseMessage.setResponseMessage(msg);
}
} catch (DeviceManagementException e) {
msg = "Error occurred while modifying the device information.";
log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
responseMessage.setResponseMessage(msg);
}
return responseMessage;
}
private static Log LOG = LogFactory.getLog(Device.class);
@GET
public List<org.wso2.carbon.device.mgt.common.Device> getAllDevices() throws AndroidAgentException {
List<org.wso2.carbon.device.mgt.common.Device> devices;
String msg;
DeviceManagementService dmService;
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
String errorMsg = "Device management service error";
LOG.error(errorMsg, deviceMgtServiceEx);
throw new AndroidAgentException(errorMsg, deviceMgtServiceEx);
}
try {
devices = dmService.getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
Response.status(HttpStatus.SC_OK);
return devices;
} catch (DeviceManagementException e) {
msg = "Error occurred while fetching the device list.";
LOG.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
throw new AndroidAgentException(msg, e);
}
}
@GET
@Path("{id}")
public org.wso2.carbon.device.mgt.common.Device getDevice(@PathParam("id") String id) throws AndroidAgentException {
String msg;
DeviceManagementService dmService;
org.wso2.carbon.device.mgt.common.Device device;
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
String errorMsg = "Device management service error";
LOG.error(errorMsg, deviceMgtServiceEx);
throw new AndroidAgentException(errorMsg, deviceMgtServiceEx);
}
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
try {
device = dmService.getDevice(deviceIdentifier);
if (device == null) {
Response.status(HttpStatus.SC_NOT_FOUND);
}
return device;
} catch (DeviceManagementException deviceMgtEx) {
msg = "Error occurred while fetching the device information.";
LOG.error(msg, deviceMgtEx);
throw new AndroidAgentException(msg, deviceMgtEx);
}
}
@PUT
@Path("{id}")
public Message updateDevice(@PathParam("id") String id, org.wso2.carbon.device.mgt.common.Device device) throws
AndroidAgentException {
DeviceManagementService dmService = null;
Message responseMessage = new Message();
boolean result;
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} catch (DeviceManagementServiceException deviceManagementServiceException) {
String errorMsg = "Device management service error";
LOG.error(errorMsg, deviceManagementServiceException);
}
try {
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
result = dmService.updateDeviceInfo(device);
if (result) {
Response.status(HttpStatus.SC_OK);
responseMessage.setResponseMessage("Device information has modified successfully.");
} else {
Response.status(HttpStatus.SC_NOT_MODIFIED);
responseMessage.setResponseMessage("Device not found for the update.");
}
return responseMessage;
} catch (DeviceManagementException deviceMgtEx) {
String msg = "Error occurred while modifying the device information.";
LOG.error(msg, deviceMgtEx);
throw new AndroidAgentException(msg, deviceMgtEx);
}
}
@POST
@Path("/device/license")
@Produces ("text/plain")
public String getLicense() {
//TODO: need to implement fetch license from core
return "License Agreement";
}
}

@ -1,32 +1,33 @@
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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
* 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
* 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.
* 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 cdm.api.android;
import cdm.api.android.common.AndroidAgentException;
import cdm.api.android.util.AndroidAPIUtils;
import cdm.api.android.util.AndroidConstants;
import cdm.api.android.util.Message;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManagementServiceException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import javax.ws.rs.*;
@ -39,186 +40,147 @@ import javax.ws.rs.core.Response;
@Consumes({ "application/json", "application/xml" })
public class Enrollment {
private static Log log = LogFactory.getLog(Enrollment.class);
/*
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
* "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"},
* {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"},
* {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"},
* {"name":"osVersion","value":"5.0.0"}]}
*
**/
@POST
public Message enrollDevice(Device device) {
boolean result = false;
int status = 0;
String msg = "";
DeviceManagementService dmService;
Message responseMsg = new Message();
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
try {
if (dmService != null) {
device.setType(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
result = dmService.enrollDevice(device);
Response.status(HttpStatus.SC_CREATED);
responseMsg.setResponseMessage("Device enrollment has succeeded");
return responseMsg;
} else {
responseMsg.setResponseMessage(
AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
return responseMsg;
}
} catch (DeviceManagementException e) {
log.error(msg, e);
responseMsg.setResponseMessage("Error occurred while enrolling the device");
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
return responseMsg;
}
}
@GET
@Path("{id}")
public Message isEnrolled(@PathParam("id") String id) {
boolean result = false;
String msg = "";
DeviceManagementService dmService;
Message responseMsg = new Message();
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
try {
if (dmService != null) {
result = dmService.isEnrolled(deviceIdentifier);
if (result) {
Response.status(HttpStatus.SC_OK);
responseMsg.setResponseMessage("Device has already enrolled");
} else {
Response.status(HttpStatus.SC_NOT_FOUND);
responseMsg.setResponseMessage("Device has not enrolled");
}
return responseMsg;
} else {
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
responseMsg.setResponseMessage(
AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
return responseMsg;
}
} catch (DeviceManagementException e) {
msg = "Error occurred while checking the enrollment of the device.";
log.error(msg, e);
responseMsg.setResponseMessage(msg);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
return responseMsg;
}
}
/*
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
* "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"},
* {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"},
* {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"},
* {"name":"osVersion","value":"5.0.0"}]}
*
**/
@PUT
@Path("{id}")
public Message modifyEnrollment(@PathParam("id") String id, Device device) {
boolean result = false;
String msg = "";
DeviceManagementService dmService;
Message responseMsg = new Message();
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
try {
if (dmService != null) {
device.setType(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
result = dmService.modifyEnrollment(device);
if (result) {
responseMsg.setResponseMessage("Device enrollment has updated successfully");
Response.status(HttpStatus.SC_OK);
} else {
responseMsg.setResponseMessage("Update enrollment has failed");
Response.status(HttpStatus.SC_NOT_MODIFIED);
}
} else {
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
responseMsg.setResponseMessage(msg);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
return responseMsg;
} catch (DeviceManagementException e) {
msg = "Error occurred while modifying enrollment of the device";
log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
responseMsg.setResponseMessage(msg);
return responseMsg;
}
}
@DELETE
@Path("{id}")
public Message disenrollDevice(@PathParam("id") String id) {
boolean result = false;
String msg = "";
DeviceManagementService dmService;
Message responseMsg = new Message();
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
try {
if (dmService != null) {
result = dmService.disenrollDevice(deviceIdentifier);
if (result) {
responseMsg.setResponseMessage("Device has disenrolled successfully");
Response.status(HttpStatus.SC_OK);
} else {
responseMsg.setResponseMessage("Device not found");
Response.status(HttpStatus.SC_NOT_FOUND);
}
} else {
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
responseMsg.setResponseMessage(msg);
}
return responseMsg;
} catch (DeviceManagementException e) {
msg = "Error occurred while disenrolling the device";
log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
responseMsg.setResponseMessage(msg);
return responseMsg;
}
}
private static Log log = LogFactory.getLog(Enrollment.class);
@POST
public Message enrollDevice(org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException {
DeviceManagementService dmService;
Message responseMsg = new Message();
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
String errorMsg = "Device management service error";
log.error(errorMsg, deviceServiceMgtEx);
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
}
try {
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
dmService.enrollDevice(device);
Response.status(HttpStatus.SC_CREATED);
responseMsg.setResponseMessage("Device enrollment succeeded");
return responseMsg;
} catch (DeviceManagementException deviceMgtEx) {
String errorMsg = "Error occurred while enrolling the device";
log.error(errorMsg, deviceMgtEx);
throw new AndroidAgentException(errorMsg, deviceMgtEx);
}
}
@GET
@Path("{id}")
public Message isEnrolled(@PathParam("id") String id) throws AndroidAgentException {
boolean result;
DeviceManagementService dmService;
Message responseMsg = new Message();
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
String errorMsg = "Device management service error";
log.error(errorMsg, deviceServiceMgtEx);
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
}
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
try {
result = dmService.isEnrolled(deviceIdentifier);
if (result) {
Response.status(HttpStatus.SC_OK);
responseMsg.setResponseMessage("Device has already enrolled");
} else {
Response.status(HttpStatus.SC_NOT_FOUND);
responseMsg.setResponseMessage("Device not found");
}
return responseMsg;
} catch (DeviceManagementException deviceMgtEx) {
String errormsg = "Error occurred while enrollment of the device.";
log.error(errormsg, deviceMgtEx);
throw new AndroidAgentException(errormsg, deviceMgtEx);
}
}
@PUT
@Path("{id}")
public Message modifyEnrollment(@PathParam("id") String id, org.wso2.carbon.device.mgt.common.Device device)
throws AndroidAgentException {
boolean result;
DeviceManagementService dmService;
Message responseMsg = new Message();
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
String errorMsg = "Device management service error";
log.error(errorMsg, deviceServiceMgtEx);
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
}
try {
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
result = dmService.modifyEnrollment(device);
if (result) {
responseMsg.setResponseMessage("Device enrollment has updated successfully");
Response.status(HttpStatus.SC_OK);
} else {
responseMsg.setResponseMessage("device not found for enrollment");
Response.status(HttpStatus.SC_NOT_MODIFIED);
}
return responseMsg;
} catch (DeviceManagementException deviceMgtEx) {
String errorMsg = "Error occurred while modifying enrollment of the device";
log.error(errorMsg, deviceMgtEx);
throw new AndroidAgentException(errorMsg, deviceMgtEx);
}
}
@DELETE
@Path("{id}")
public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException {
DeviceManagementService dmService;
Message responseMsg = new Message();
boolean result;
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
String errorMsg = "Device management service error";
log.error(errorMsg, deviceServiceMgtEx);
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
}
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
try {
result = dmService.disenrollDevice(deviceIdentifier);
if (result) {
responseMsg.setResponseMessage("Device has disenrolled successfully");
Response.status(HttpStatus.SC_OK);
} else {
responseMsg.setResponseMessage("Device not found");
Response.status(HttpStatus.SC_NOT_FOUND);
}
return responseMsg;
} catch (DeviceManagementException deviceMgtEx) {
String errorMsg = "Error occurred while dis enrolling the device";
log.error(errorMsg, deviceMgtEx);
throw new AndroidAgentException(errorMsg, deviceMgtEx);
}
}
}

@ -0,0 +1,36 @@
package cdm.api.android;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.Device;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
/**
* This is a Test class
*/
@Produces({"application/json", "application/xml"})
@Consumes({"application/json", "application/xml"})
public class Test {
@GET
public List<org.wso2.carbon.device.mgt.common.Device> getAllDevices() throws DeviceManagementException{
Device dev = new Device();
dev.setName("test1");
dev.setDateOfEnrolment(11111111L);
dev.setDateOfLastUpdate(992093209L);
dev.setDescription("sassasaas");
ArrayList<Device> listdevices = new ArrayList<Device>();
listdevices.add(dev);
throw new DeviceManagementException("test ex");
}
}

@ -0,0 +1,58 @@
/*
* Copyright (c) 2014, 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 cdm.api.android.common;
public class AndroidAgentException extends Exception{
private static final long serialVersionUID = 7950151650447893900L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public AndroidAgentException(String msg, Exception nestedEx) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public AndroidAgentException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public AndroidAgentException(String msg) {
super(msg);
setErrorMessage(msg);
}
public AndroidAgentException() {
super();
}
public AndroidAgentException(Throwable cause) {
super(cause);
}
}

@ -1,32 +1,35 @@
/*
* Copyright (c) 2014, 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
* 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
* 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.
* 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 cdm.api.android.common;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
public class ErrorHandler implements ExceptionMapper {
public Response toResponse(Throwable throwable) {
Response.Status status;
status = Response.Status.INTERNAL_SERVER_ERROR;
// return Response.status(status).header("exception", exception.getMessage()).build();
return null;
@Produces({ "application/json", "application/xml" })
public class ErrorHandler implements ExceptionMapper<AndroidAgentException> {
public Response toResponse(AndroidAgentException exception) {
ErrorMessage errorMessage = new ErrorMessage();
errorMessage.setErrorMessage(exception.getErrorMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
}
}

@ -0,0 +1,41 @@
/*
* Copyright (c) 2014, 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 cdm.api.android.common;
public class ErrorMessage {
private String errorMessage;
private String errorCode;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
}

@ -1,34 +1,38 @@
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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
* 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
* 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.
*/
* 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 cdm.api.android.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import java.util.*;
/**
* AndroidAPIUtil class provides utility function used by Android REST-API classes.
*/
public class AndroidAPIUtils {
private static Log log = LogFactory.getLog(AndroidAPIUtils.class);
public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) {
DeviceIdentifier identifier = new DeviceIdentifier();
identifier.setId(deviceId);
identifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
@ -36,14 +40,21 @@ public class AndroidAPIUtils {
}
public static DeviceManagementService getDeviceManagementService() {
public static DeviceManagementService getDeviceManagementService() throws DeviceManagementServiceException{
// until complete login this is use to load super tenant context
DeviceManagementService dmService;
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
dmService = (DeviceManagementService) ctx
.getOSGiService(DeviceManagementService.class, null);
dmService = (DeviceManagementService) ctx.getOSGiService(DeviceManagementService.class, null);
if (dmService == null){
log.error("device management service not initialized");
throw new DeviceManagementServiceException("device management service not initialized");
}
PrivilegedCarbonContext.endTenantFlow();
return dmService;
}
}

@ -1,19 +1,20 @@
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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
* 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.
*/
* 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 cdm.api.android.util;
/**

@ -1,21 +1,20 @@
/*
* Copyright (c) 2014, 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
* 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
* 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.
*/
* 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 cdm.api.android.util;
import javax.xml.bind.annotation.XmlElement;

@ -1,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2014 WSO2, Inc. (http://wso2.com)
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ 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.
-->
~ 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
@ -25,10 +25,11 @@
<jaxrs:server id="customerService" address="/register">
<jaxrs:serviceBeans>
<ref bean="serviceBean"/>
<ref bean="deviceMgtServiceBean"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
<ref bean="errorHandler"/>
</jaxrs:providers>
</jaxrs:server>
<jaxrs:server id="deviceManagementService" address="/devices">
@ -37,6 +38,7 @@
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
<ref bean="errorHandler"/>
</jaxrs:providers>
</jaxrs:server>
<jaxrs:server id="enrollmentService" address="/enrollment">
@ -45,12 +47,22 @@
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
<ref bean="errorHandler"/>
</jaxrs:providers>
</jaxrs:server>
<bean id="serviceBean" class="cdm.api.android.Authentication"/>
<jaxrs:server id="testService" address="/test">
<jaxrs:serviceBeans>
<ref bean="testServiceBean"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
<ref bean="errorHandler"/>
</jaxrs:providers>
</jaxrs:server>
<bean id="deviceMgtServiceBean" class="cdm.api.android.Device"/>
<bean id="enrollmentServiceBean" class="cdm.api.android.Enrollment"/>
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
<bean id="errorHandler" class="cdm.api.android.common.ErrorHandler"/>
</beans>

@ -1,19 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2014 WSO2, Inc. (http://wso2.com)
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ 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
~1-2012
~
~ 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.
-->
~ 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.
-->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>CDM-Android-API</display-name>
<servlet>

@ -1,6 +1,6 @@
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE
(
ID INT(11) NOT NULL,
ID INT(11) auto_increment NOT NULL,
NAME VARCHAR(300) NULL DEFAULT NULL,
PRIMARY KEY (ID)
);
@ -21,6 +21,4 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-- TO:DO - Remove this INSERT sql statement.
Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (1, 'android');
);
Loading…
Cancel
Save