mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/geethkokila/product-cdm
This commit is contained in:
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;
|
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.common.spi.DeviceManagerService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class DeviceManagementRepository {
|
public class DeviceManagementRepository {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceManagerUtil.class);
|
||||||
private Map<String, DeviceManagerService> providers;
|
private Map<String, DeviceManagerService> providers;
|
||||||
|
|
||||||
public DeviceManagementRepository() {
|
public DeviceManagementRepository() {
|
||||||
@ -29,7 +34,13 @@ public class DeviceManagementRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addDeviceManagementProvider(DeviceManagerService provider) {
|
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) {
|
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");
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* you may not use this file except in compliance with the License.
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* You may obtain a copy of the License at
|
* 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
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* software distributed under the License is distributed on an
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* See the License for the specific language governing permissions and
|
* KIND, either express or implied. See the License for the
|
||||||
* limitations under the License.
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core;
|
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");
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* you may not use this file except in compliance with the License.
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* You may obtain a copy of the License at
|
* 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
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* software distributed under the License is distributed on an
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* See the License for the specific language governing permissions and
|
* KIND, either express or implied. See the License for the
|
||||||
* limitations under the License.
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core;
|
package org.wso2.carbon.device.mgt.core;
|
||||||
|
|
||||||
@ -29,7 +31,7 @@ import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DeviceManagerImpl implements DeviceManager{
|
public class DeviceManagerImpl implements DeviceManager {
|
||||||
|
|
||||||
private DeviceDAO deviceDAO;
|
private DeviceDAO deviceDAO;
|
||||||
private DeviceTypeDAO deviceTypeDAO;
|
private DeviceTypeDAO deviceTypeDAO;
|
||||||
@ -45,61 +47,57 @@ public class DeviceManagerImpl implements DeviceManager{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||||
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
||||||
boolean status = dms.enrollDevice(device);
|
boolean status = dms.enrollDevice(device);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.getDeviceTypeDAO().getDeviceType();
|
this.getDeviceTypeDAO().getDeviceType();
|
||||||
org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(
|
org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device);
|
||||||
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) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
throw new DeviceManagementException("Error occurred while enrolling the device '" +
|
throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'",
|
||||||
device.getId() + "'", e);
|
e);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||||
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
||||||
boolean status = dms.modifyEnrollment(device);
|
boolean status = dms.modifyEnrollment(device);
|
||||||
try {
|
try {
|
||||||
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
|
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
throw new DeviceManagementException("Error occurred while modifying the device '" +
|
throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + "'",
|
||||||
device.getId() + "'", e);
|
e);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
||||||
return dms.disenrollDevice(deviceId);
|
return dms.disenrollDevice(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
||||||
return dms.isEnrolled(deviceId);
|
return dms.isEnrolled(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
||||||
return dms.isActive(deviceId);
|
return dms.isActive(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||||
|
throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms =
|
||||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
return dms.setActive(deviceId, status);
|
return dms.setActive(deviceId, status);
|
||||||
@ -114,28 +112,24 @@ public class DeviceManagerImpl implements DeviceManager{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
||||||
return dms.getDevice(deviceId);
|
return dms.getDevice(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||||
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
|
||||||
return dms.updateDeviceInfo(device);
|
return dms.updateDeviceInfo(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
|
||||||
return dms.setOwnership(deviceId, ownershipType);
|
return dms.setOwnership(deviceId, ownershipType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OperationManager getOperationManager(String type) throws DeviceManagementException {
|
public OperationManager getOperationManager(String type) throws DeviceManagementException {
|
||||||
DeviceManagerService dms =
|
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type);
|
||||||
this.getPluginRepository().getDeviceManagementProvider(type);
|
|
||||||
return dms.getOperationManager();
|
return dms.getOperationManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
@ -27,14 +30,14 @@ import javax.xml.bind.Unmarshaller;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class responsible for the rss manager configuration initialization
|
* Class responsible for the cdm manager configuration initialization
|
||||||
*/
|
*/
|
||||||
public class DeviceConfigurationManager {
|
public class DeviceConfigurationManager {
|
||||||
|
|
||||||
private DeviceManagementConfig currentDeviceConfig;
|
private DeviceManagementConfig currentDeviceConfig;
|
||||||
private static DeviceConfigurationManager deviceConfigManager;
|
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;
|
DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME;
|
||||||
|
|
||||||
public static DeviceConfigurationManager getInstance() {
|
public static DeviceConfigurationManager getInstance() {
|
||||||
@ -49,6 +52,8 @@ public class DeviceConfigurationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void initConfig() throws DeviceManagementException {
|
public synchronized void initConfig() throws DeviceManagementException {
|
||||||
|
|
||||||
|
//catch generic exception.if any exception occurs wrap and throw DeviceManagementException
|
||||||
try {
|
try {
|
||||||
File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
|
File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
|
||||||
Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
|
Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
|
||||||
|
|||||||
@ -1,14 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,21 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.config;
|
package org.wso2.carbon.device.mgt.core.config;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
|||||||
@ -1,25 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.config.datasource;
|
package org.wso2.carbon.device.mgt.core.config.datasource;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
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")
|
@XmlRootElement(name = "DataSourceConfiguration")
|
||||||
public class DataSourceConfig {
|
public class DataSourceConfig {
|
||||||
|
|||||||
@ -1,14 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
@ -36,6 +39,4 @@ public interface DeviceDAO {
|
|||||||
Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException;
|
Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
List<Device> getDevices() 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");
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* you may not use this file except in compliance with the License.
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* You may obtain a copy of the License at
|
* 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
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* software distributed under the License is distributed on an
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* See the License for the specific language governing permissions and
|
* KIND, either express or implied. See the License for the
|
||||||
* limitations under the License.
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.dao;
|
package org.wso2.carbon.device.mgt.core.dao;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
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.DeviceDAOImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl;
|
import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -57,8 +59,8 @@ public class DeviceManagementDAOFactory {
|
|||||||
private static DataSource resolveDataSource(DataSourceConfig config) {
|
private static DataSource resolveDataSource(DataSourceConfig config) {
|
||||||
DataSource dataSource = null;
|
DataSource dataSource = null;
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
throw new RuntimeException("Device Management Repository data source configuration " +
|
throw new RuntimeException("Device Management Repository data source configuration " + "is null and " +
|
||||||
"is null and thus, is not initialized");
|
"thus, is not initialized");
|
||||||
}
|
}
|
||||||
JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion();
|
JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion();
|
||||||
if (jndiConfig != null) {
|
if (jndiConfig != null) {
|
||||||
@ -66,15 +68,13 @@ public class DeviceManagementDAOFactory {
|
|||||||
log.debug("Initializing Device Management Repository data source using the JNDI " +
|
log.debug("Initializing Device Management Repository data source using the JNDI " +
|
||||||
"Lookup Definition");
|
"Lookup Definition");
|
||||||
}
|
}
|
||||||
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
|
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = jndiConfig.getJndiProperties();
|
||||||
jndiConfig.getJndiProperties();
|
|
||||||
if (jndiPropertyList != null) {
|
if (jndiPropertyList != null) {
|
||||||
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
|
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
|
||||||
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
||||||
jndiProperties.put(prop.getName(), prop.getValue());
|
jndiProperties.put(prop.getName(), prop.getValue());
|
||||||
}
|
}
|
||||||
dataSource =
|
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
||||||
DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
|
||||||
} else {
|
} else {
|
||||||
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,11 +11,10 @@
|
|||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.dao;
|
package org.wso2.carbon.device.mgt.core.dao;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
@ -36,4 +35,6 @@ public interface DeviceTypeDAO {
|
|||||||
|
|
||||||
DeviceIdentifier getDeviceType() throws DeviceManagementDAOException;
|
DeviceIdentifier getDeviceType() throws DeviceManagementDAOException;
|
||||||
|
|
||||||
|
Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
@ -102,38 +102,6 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|||||||
return null;
|
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 {
|
private Connection getConnection() throws DeviceManagementDAOException {
|
||||||
try {
|
try {
|
||||||
return dataSource.getConnection();
|
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");
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* you may not use this file except in compliance with the License.
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* You may obtain a copy of the License at
|
* 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
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* software distributed under the License is distributed on an
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* See the License for the specific language governing permissions and
|
* KIND, either express or implied. See the License for the
|
||||||
* limitations under the License.
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.dao.impl;
|
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.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.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 org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
||||||
|
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceTypeDAOImpl.class);
|
||||||
|
|
||||||
public DeviceTypeDAOImpl(DataSource dataSource) {
|
public DeviceTypeDAOImpl(DataSource dataSource) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
@ -44,8 +51,9 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
stmt.setString(1, deviceType.getName());
|
stmt.setString(1, deviceType.getName());
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while registering the device type '" +
|
String msg = "Error occurred while registering the device type '" + deviceType.getName() + "'";
|
||||||
deviceType.getName() + "'", e);
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||||
}
|
}
|
||||||
@ -58,21 +66,72 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
|
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
|
@Override
|
||||||
public DeviceIdentifier getDeviceType() throws DeviceManagementDAOException {
|
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 {
|
private Connection getConnection() throws DeviceManagementDAOException {
|
||||||
try {
|
try {
|
||||||
return dataSource.getConnection();
|
return dataSource.getConnection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while obtaining a connection from the device " +
|
String msg = "Error occurred while obtaining a connection from the device " +
|
||||||
"management metadata repository datasource", e);
|
"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);
|
log.warn("Error occurred while closing database connection", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rs = null;
|
||||||
|
stmt = null;
|
||||||
|
conn = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,8 +86,7 @@ public final class DeviceManagementDAOUtil {
|
|||||||
try {
|
try {
|
||||||
tenantId = tenantManager.getTenantId(tenantDomain);
|
tenantId = tenantManager.getTenantId(tenantDomain);
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while retrieving id from the domain of tenant " +
|
String msg = "Error occurred while retrieving id from the domain of tenant " + tenantDomain;
|
||||||
tenantDomain;
|
|
||||||
throw new DeviceManagementDAOException(msg);
|
throw new DeviceManagementDAOException(msg);
|
||||||
}
|
}
|
||||||
return tenantId;
|
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");
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* you may not use this file except in compliance with the License.
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* You may obtain a copy of the License at
|
* 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
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* software distributed under the License is distributed on an
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* See the License for the specific language governing permissions and
|
* KIND, either express or implied. See the License for the
|
||||||
* limitations under the License.
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.internal;
|
package org.wso2.carbon.device.mgt.core.internal;
|
||||||
|
|
||||||
@ -56,7 +58,6 @@ public class DeviceManagementServiceComponent {
|
|||||||
try {
|
try {
|
||||||
/* Initializing Device Management Configuration */
|
/* Initializing Device Management Configuration */
|
||||||
DeviceConfigurationManager.getInstance().initConfig();
|
DeviceConfigurationManager.getInstance().initConfig();
|
||||||
|
|
||||||
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
||||||
|
|
||||||
DataSourceConfig dsConfig = config.getDeviceMgtRepository().getDataSourceConfig();
|
DataSourceConfig dsConfig = config.getDeviceMgtRepository().getDataSourceConfig();
|
||||||
@ -88,6 +89,8 @@ public class DeviceManagementServiceComponent {
|
|||||||
private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException {
|
private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException {
|
||||||
DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config);
|
DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config);
|
||||||
log.info("Initializing device management repository database schema");
|
log.info("Initializing device management repository database schema");
|
||||||
|
|
||||||
|
// catch generic exception. If any error occurs wrap and throw DeviceManagementException
|
||||||
try {
|
try {
|
||||||
initializer.createRegistryDatabase();
|
initializer.createRegistryDatabase();
|
||||||
} catch (Exception e) {
|
} 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.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
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.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.dao.util.DeviceManagementDAOUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
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
|
* @param config data source configuration
|
||||||
* @return data source resolved from the data source definition
|
* @return data source resolved from the data source definition
|
||||||
@ -80,4 +84,27 @@ public final class DeviceManagerUtil {
|
|||||||
return dataSource;
|
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.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core;
|
package org.wso2.carbon.device.mgt.core;
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,14 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,14 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,14 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
@ -66,8 +69,8 @@ public class DeviceMgtDAOTestSuite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType)
|
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws DeviceManagementDAOException,
|
||||||
throws DeviceManagementDAOException, DeviceManagementException {
|
DeviceManagementException {
|
||||||
|
|
||||||
File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml");
|
File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml");
|
||||||
Document doc = null;
|
Document doc = null;
|
||||||
|
|||||||
@ -1,4 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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;
|
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 {
|
public class MobileDeviceConfigurationManager {
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import javax.xml.bind.annotation.XmlElement;
|
|||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for holding management repository data
|
* Class for holding management repository data.
|
||||||
*/
|
*/
|
||||||
@XmlRootElement(name = "ManagementRepository")
|
@XmlRootElement(name = "ManagementRepository")
|
||||||
public class MobileDeviceManagementRepository {
|
public class MobileDeviceManagementRepository {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import javax.xml.bind.annotation.*;
|
|||||||
import java.util.List;
|
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")
|
@XmlRootElement(name = "JndiLookupDefinition")
|
||||||
public class JNDILookupDefinition {
|
public class JNDILookupDefinition {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import javax.xml.bind.annotation.XmlElement;
|
|||||||
import javax.xml.bind.annotation.XmlRootElement;
|
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")
|
@XmlRootElement(name = "DataSourceConfiguration")
|
||||||
public class MobileDataSourceConfig {
|
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.
|
* @param message the detail message.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public class MobileDeviceManagementDAOUtil {
|
|||||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOUtil.class);
|
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
|
* @param config Mobile data source configuration
|
||||||
* @return data source resolved from the data source definition
|
* @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
|
* @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
|
* @param dataSource Mobile data source
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This represents the iOS implementation of DeviceManagerService. *
|
* This represents the iOS implementation of DeviceManagerService.
|
||||||
*/
|
*/
|
||||||
public class IOSDeviceManagerService implements 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");
|
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
~ you may not use this file except in compliance with the 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
|
~ 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
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
~ software distributed under the License is distributed on an
|
||||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
~ See the License for the specific language governing permissions and
|
~ KIND, either express or implied. See the License for the
|
||||||
~ limitations under the License.
|
~ specific language governing permissions and limitations
|
||||||
-->
|
~ under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
@ -176,5 +178,4 @@
|
|||||||
<cxf.version>2.6.1</cxf.version>
|
<cxf.version>2.6.1</cxf.version>
|
||||||
<junit.version>4.8.2</junit.version>
|
<junit.version>4.8.2</junit.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -1,33 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
* 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");
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* you may not use this file except in compliance with the License.
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* You may obtain a copy of the License at
|
* 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
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* software distributed under the License is distributed on an
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* See the License for the specific language governing permissions and
|
* KIND, either express or implied. See the License for the
|
||||||
* limitations under the License.
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cdm.api.android;
|
package cdm.api.android;
|
||||||
|
|
||||||
|
import cdm.api.android.common.AndroidAgentException;
|
||||||
import cdm.api.android.util.AndroidAPIUtils;
|
import cdm.api.android.util.AndroidAPIUtils;
|
||||||
import cdm.api.android.util.AndroidConstants;
|
|
||||||
import cdm.api.android.util.Message;
|
import cdm.api.android.util.Message;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
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 org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -39,107 +39,112 @@ import java.util.List;
|
|||||||
@Consumes({ "application/json", "application/xml" })
|
@Consumes({ "application/json", "application/xml" })
|
||||||
public class Device {
|
public class Device {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Device.class);
|
private static Log LOG = LogFactory.getLog(Device.class);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
public List<org.wso2.carbon.device.mgt.common.Device> getAllDevices() {
|
public List<org.wso2.carbon.device.mgt.common.Device> getAllDevices() throws AndroidAgentException {
|
||||||
List<org.wso2.carbon.device.mgt.common.Device> devices = null;
|
|
||||||
String msg = "";
|
|
||||||
DeviceManagementService dmService;
|
|
||||||
|
|
||||||
try {
|
List<org.wso2.carbon.device.mgt.common.Device> devices;
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
String msg;
|
||||||
} finally {
|
DeviceManagementService dmService;
|
||||||
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
|
try {
|
||||||
@Path("{id}")
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
||||||
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 {
|
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
String errorMsg = "Device management service error";
|
||||||
} finally {
|
LOG.error(errorMsg, deviceMgtServiceEx);
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
throw new AndroidAgentException(errorMsg, deviceMgtServiceEx);
|
||||||
}
|
}
|
||||||
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
||||||
try {
|
|
||||||
if (dmService != null) {
|
|
||||||
device = dmService.getDevice(deviceIdentifier);
|
|
||||||
if (device == null) {
|
|
||||||
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
try {
|
||||||
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
devices = dmService.getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||||
}
|
Response.status(HttpStatus.SC_OK);
|
||||||
|
return devices;
|
||||||
|
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
msg = "Error occurred while fetching the device information.";
|
msg = "Error occurred while fetching the device list.";
|
||||||
log.error(msg, e);
|
LOG.error(msg, e);
|
||||||
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
}
|
throw new AndroidAgentException(msg, e);
|
||||||
return device;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public Message updateDevice(@PathParam("id") String id,
|
public org.wso2.carbon.device.mgt.common.Device getDevice(@PathParam("id") String id) throws AndroidAgentException {
|
||||||
org.wso2.carbon.device.mgt.common.Device device) {
|
|
||||||
boolean result = false;
|
|
||||||
String msg = "";
|
|
||||||
DeviceManagementService dmService;
|
|
||||||
Message responseMessage = new Message();
|
|
||||||
|
|
||||||
try {
|
String msg;
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
DeviceManagementService dmService;
|
||||||
} finally {
|
org.wso2.carbon.device.mgt.common.Device device;
|
||||||
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) {
|
try {
|
||||||
msg = "Error occurred while modifying the device information.";
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
||||||
log.error(msg, e);
|
|
||||||
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
||||||
responseMessage.setResponseMessage(msg);
|
|
||||||
|
|
||||||
}
|
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
|
||||||
return responseMessage;
|
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.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* you may not use this file except in compliance with the License.
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* You may obtain a copy of the License at
|
* 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
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* software distributed under the License is distributed on an
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* See the License for the specific language governing permissions and
|
* KIND, either express or implied. See the License for the
|
||||||
* limitations under the License.
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cdm.api.android;
|
package cdm.api.android;
|
||||||
|
|
||||||
|
import cdm.api.android.common.AndroidAgentException;
|
||||||
import cdm.api.android.util.AndroidAPIUtils;
|
import cdm.api.android.util.AndroidAPIUtils;
|
||||||
import cdm.api.android.util.AndroidConstants;
|
|
||||||
import cdm.api.android.util.Message;
|
import cdm.api.android.util.Message;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
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 org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
@ -39,186 +40,147 @@ import javax.ws.rs.core.Response;
|
|||||||
@Consumes({ "application/json", "application/xml" })
|
@Consumes({ "application/json", "application/xml" })
|
||||||
public class Enrollment {
|
public class Enrollment {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Enrollment.class);
|
private static Log log = LogFactory.getLog(Enrollment.class);
|
||||||
|
|
||||||
/*
|
@POST
|
||||||
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
|
public Message enrollDevice(org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException {
|
||||||
* "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;
|
DeviceManagementService dmService;
|
||||||
int status = 0;
|
Message responseMsg = new Message();
|
||||||
String msg = "";
|
|
||||||
DeviceManagementService dmService;
|
|
||||||
Message responseMsg = new Message();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
||||||
} finally {
|
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
||||||
if (dmService != null) {
|
String errorMsg = "Device management service error";
|
||||||
device.setType(
|
log.error(errorMsg, deviceServiceMgtEx);
|
||||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
|
||||||
result = dmService.enrollDevice(device);
|
}
|
||||||
Response.status(HttpStatus.SC_CREATED);
|
|
||||||
responseMsg.setResponseMessage("Device enrollment has succeeded");
|
|
||||||
return responseMsg;
|
|
||||||
|
|
||||||
} else {
|
try {
|
||||||
responseMsg.setResponseMessage(
|
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||||
AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
|
dmService.enrollDevice(device);
|
||||||
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
Response.status(HttpStatus.SC_CREATED);
|
||||||
return responseMsg;
|
responseMsg.setResponseMessage("Device enrollment succeeded");
|
||||||
}
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
} catch (DeviceManagementException deviceMgtEx) {
|
||||||
|
String errorMsg = "Error occurred while enrolling the device";
|
||||||
|
log.error(errorMsg, deviceMgtEx);
|
||||||
|
throw new AndroidAgentException(errorMsg, deviceMgtEx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public Message isEnrolled(@PathParam("id") String id) {
|
public Message isEnrolled(@PathParam("id") String id) throws AndroidAgentException {
|
||||||
|
|
||||||
boolean result = false;
|
boolean result;
|
||||||
String msg = "";
|
DeviceManagementService dmService;
|
||||||
DeviceManagementService dmService;
|
Message responseMsg = new Message();
|
||||||
Message responseMsg = new Message();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
||||||
|
String errorMsg = "Device management service error";
|
||||||
|
log.error(errorMsg, deviceServiceMgtEx);
|
||||||
|
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
||||||
* 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 {
|
try {
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
result = dmService.isEnrolled(deviceIdentifier);
|
||||||
} finally {
|
if (result) {
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
@PUT
|
||||||
if (dmService != null) {
|
@Path("{id}")
|
||||||
device.setType(
|
public Message modifyEnrollment(@PathParam("id") String id, org.wso2.carbon.device.mgt.common.Device device)
|
||||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
throws AndroidAgentException {
|
||||||
result = dmService.modifyEnrollment(device);
|
|
||||||
|
|
||||||
if (result) {
|
boolean result;
|
||||||
responseMsg.setResponseMessage("Device enrollment has updated successfully");
|
DeviceManagementService dmService;
|
||||||
Response.status(HttpStatus.SC_OK);
|
Message responseMsg = new Message();
|
||||||
} 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
try {
|
||||||
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
||||||
|
|
||||||
@DELETE
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
||||||
@Path("{id}")
|
String errorMsg = "Device management service error";
|
||||||
public Message disenrollDevice(@PathParam("id") String id) {
|
log.error(errorMsg, deviceServiceMgtEx);
|
||||||
|
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
|
||||||
|
}
|
||||||
|
|
||||||
boolean result = false;
|
try {
|
||||||
String msg = "";
|
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||||
DeviceManagementService dmService;
|
result = dmService.modifyEnrollment(device);
|
||||||
Message responseMsg = new Message();
|
|
||||||
|
|
||||||
try {
|
if (result) {
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
responseMsg.setResponseMessage("Device enrollment has updated successfully");
|
||||||
} finally {
|
Response.status(HttpStatus.SC_OK);
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
} else {
|
||||||
}
|
responseMsg.setResponseMessage("device not found for enrollment");
|
||||||
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
Response.status(HttpStatus.SC_NOT_MODIFIED);
|
||||||
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;
|
return responseMsg;
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
msg = "Error occurred while disenrolling the device";
|
} catch (DeviceManagementException deviceMgtEx) {
|
||||||
log.error(msg, e);
|
String errorMsg = "Error occurred while modifying enrollment of the device";
|
||||||
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
log.error(errorMsg, deviceMgtEx);
|
||||||
responseMsg.setResponseMessage(msg);
|
throw new AndroidAgentException(errorMsg, deviceMgtEx);
|
||||||
return responseMsg;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cdm.api.android.common;
|
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.core.Response;
|
||||||
import javax.ws.rs.ext.ExceptionMapper;
|
import javax.ws.rs.ext.ExceptionMapper;
|
||||||
|
|
||||||
public class ErrorHandler implements ExceptionMapper {
|
|
||||||
|
|
||||||
public Response toResponse(Throwable throwable) {
|
@Produces({ "application/json", "application/xml" })
|
||||||
Response.Status status;
|
public class ErrorHandler implements ExceptionMapper<AndroidAgentException> {
|
||||||
status = Response.Status.INTERNAL_SERVER_ERROR;
|
|
||||||
// return Response.status(status).header("exception", exception.getMessage()).build();
|
public Response toResponse(AndroidAgentException exception) {
|
||||||
return null;
|
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.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* you may not use this file except in compliance with the License.
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* You may obtain a copy of the License at
|
* 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
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* software distributed under the License is distributed on an
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* See the License for the specific language governing permissions and
|
* KIND, either express or implied. See the License for the
|
||||||
* limitations under the License.
|
* specific language governing permissions and limitations
|
||||||
*/
|
* under the License.
|
||||||
|
*/
|
||||||
package cdm.api.android.util;
|
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.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.*;
|
import org.wso2.carbon.device.mgt.common.*;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AndroidAPIUtil class provides utility function used by Android REST-API classes.
|
* AndroidAPIUtil class provides utility function used by Android REST-API classes.
|
||||||
*/
|
*/
|
||||||
public class AndroidAPIUtils {
|
public class AndroidAPIUtils {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(AndroidAPIUtils.class);
|
||||||
|
|
||||||
public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) {
|
public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) {
|
||||||
|
|
||||||
DeviceIdentifier identifier = new DeviceIdentifier();
|
DeviceIdentifier identifier = new DeviceIdentifier();
|
||||||
identifier.setId(deviceId);
|
identifier.setId(deviceId);
|
||||||
identifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
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;
|
DeviceManagementService dmService;
|
||||||
PrivilegedCarbonContext.startTenantFlow();
|
PrivilegedCarbonContext.startTenantFlow();
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
||||||
ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||||
dmService = (DeviceManagementService) ctx
|
dmService = (DeviceManagementService) ctx.getOSGiService(DeviceManagementService.class, null);
|
||||||
.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;
|
return dmService;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* 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");
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* you may not use this file except in compliance with the 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
|
* 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
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* software distributed under the License is distributed on an
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* See the License for the specific language governing permissions and
|
* KIND, either express or implied. See the License for the
|
||||||
* limitations under the License.
|
* specific language governing permissions and limitations
|
||||||
*/
|
* under the License.
|
||||||
|
*/
|
||||||
package cdm.api.android.util;
|
package cdm.api.android.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,21 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cdm.api.android.util;
|
package cdm.api.android.util;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
|||||||
@ -1,21 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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");
|
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
~ you may not use this file except in compliance with the 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
|
~ 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
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
~ software distributed under the License is distributed on an
|
||||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
~ See the License for the specific language governing permissions and
|
~ KIND, either express or implied. See the License for the
|
||||||
~ limitations under the License.
|
~ specific language governing permissions and limitations
|
||||||
-->
|
~ under the License.
|
||||||
|
-->
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
||||||
@ -25,10 +25,11 @@
|
|||||||
|
|
||||||
<jaxrs:server id="customerService" address="/register">
|
<jaxrs:server id="customerService" address="/register">
|
||||||
<jaxrs:serviceBeans>
|
<jaxrs:serviceBeans>
|
||||||
<ref bean="serviceBean"/>
|
<ref bean="deviceMgtServiceBean"/>
|
||||||
</jaxrs:serviceBeans>
|
</jaxrs:serviceBeans>
|
||||||
<jaxrs:providers>
|
<jaxrs:providers>
|
||||||
<ref bean="jsonProvider"/>
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
</jaxrs:providers>
|
</jaxrs:providers>
|
||||||
</jaxrs:server>
|
</jaxrs:server>
|
||||||
<jaxrs:server id="deviceManagementService" address="/devices">
|
<jaxrs:server id="deviceManagementService" address="/devices">
|
||||||
@ -37,6 +38,7 @@
|
|||||||
</jaxrs:serviceBeans>
|
</jaxrs:serviceBeans>
|
||||||
<jaxrs:providers>
|
<jaxrs:providers>
|
||||||
<ref bean="jsonProvider"/>
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
</jaxrs:providers>
|
</jaxrs:providers>
|
||||||
</jaxrs:server>
|
</jaxrs:server>
|
||||||
<jaxrs:server id="enrollmentService" address="/enrollment">
|
<jaxrs:server id="enrollmentService" address="/enrollment">
|
||||||
@ -45,12 +47,22 @@
|
|||||||
</jaxrs:serviceBeans>
|
</jaxrs:serviceBeans>
|
||||||
<jaxrs:providers>
|
<jaxrs:providers>
|
||||||
<ref bean="jsonProvider"/>
|
<ref bean="jsonProvider"/>
|
||||||
|
<ref bean="errorHandler"/>
|
||||||
</jaxrs:providers>
|
</jaxrs:providers>
|
||||||
</jaxrs:server>
|
</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="deviceMgtServiceBean" class="cdm.api.android.Device"/>
|
||||||
<bean id="enrollmentServiceBean" class="cdm.api.android.Enrollment"/>
|
<bean id="enrollmentServiceBean" class="cdm.api.android.Enrollment"/>
|
||||||
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
|
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
|
||||||
|
<bean id="errorHandler" class="cdm.api.android.common.ErrorHandler"/>
|
||||||
</beans>
|
</beans>
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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");
|
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
~ you may not use this file except in compliance with the 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
|
~ You may obtain a copy of the License at
|
||||||
~1-2012
|
~
|
||||||
~ 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
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
~ software distributed under the License is distributed on an
|
||||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
~ See the License for the specific language governing permissions and
|
~ KIND, either express or implied. See the License for the
|
||||||
~ limitations under the License.
|
~ 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">
|
<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>
|
<display-name>CDM-Android-API</display-name>
|
||||||
<servlet>
|
<servlet>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE
|
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,
|
NAME VARCHAR(300) NULL DEFAULT NULL,
|
||||||
PRIMARY KEY (ID)
|
PRIMARY KEY (ID)
|
||||||
);
|
);
|
||||||
@ -22,5 +22,3 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE
|
|||||||
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_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
|
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…
Reference in New Issue
Block a user