|
|
@ -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
|
|
|
|
* 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.common.AndroidAgentException;
|
|
|
@ -38,7 +39,7 @@ 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() throws AndroidAgentException {
|
|
|
|
public List<org.wso2.carbon.device.mgt.common.Device> getAllDevices() throws AndroidAgentException {
|
|
|
@ -52,28 +53,27 @@ public class Device {
|
|
|
|
|
|
|
|
|
|
|
|
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
|
|
|
|
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
log.error(errorMsg, deviceMgtServiceEx);
|
|
|
|
LOG.error(errorMsg, deviceMgtServiceEx);
|
|
|
|
throw new AndroidAgentException();
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceMgtServiceEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
devices = dmService.getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
devices = dmService.getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
|
|
|
|
return devices;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
msg = "Error occurred while fetching the device list.";
|
|
|
|
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);
|
|
|
|
throw new AndroidAgentException(msg, e);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return devices;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Path("{id}")
|
|
|
|
@Path("{id}")
|
|
|
|
public org.wso2.carbon.device.mgt.common.Device getDevice(@PathParam("id") String id) throws AndroidAgentException {
|
|
|
|
public org.wso2.carbon.device.mgt.common.Device getDevice(@PathParam("id") String id) throws AndroidAgentException {
|
|
|
|
|
|
|
|
|
|
|
|
String msg;
|
|
|
|
String msg;
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
org.wso2.carbon.device.mgt.common.Device device;
|
|
|
|
org.wso2.carbon.device.mgt.common.Device device;
|
|
|
@ -83,21 +83,23 @@ public class Device {
|
|
|
|
|
|
|
|
|
|
|
|
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
|
|
|
|
} catch (DeviceManagementServiceException deviceMgtServiceEx) {
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
log.error(errorMsg, deviceMgtServiceEx);
|
|
|
|
LOG.error(errorMsg, deviceMgtServiceEx);
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceMgtServiceEx);
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceMgtServiceEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
device = dmService.getDevice(deviceIdentifier);
|
|
|
|
device = dmService.getDevice(deviceIdentifier);
|
|
|
|
if (device == null) {
|
|
|
|
if (device == null) {
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return device;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (DeviceManagementException deviceMgtEx) {
|
|
|
|
} catch (DeviceManagementException deviceMgtEx) {
|
|
|
|
msg = "Error occurred while fetching the device information.";
|
|
|
|
msg = "Error occurred while fetching the device information.";
|
|
|
|
log.error(msg, deviceMgtEx);
|
|
|
|
LOG.error(msg, deviceMgtEx);
|
|
|
|
throw new AndroidAgentException(msg, deviceMgtEx);
|
|
|
|
throw new AndroidAgentException(msg, deviceMgtEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return device;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
@PUT
|
|
|
@ -115,7 +117,7 @@ public class Device {
|
|
|
|
|
|
|
|
|
|
|
|
} catch (DeviceManagementServiceException deviceManagementServiceException) {
|
|
|
|
} catch (DeviceManagementServiceException deviceManagementServiceException) {
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
log.error(errorMsg, deviceManagementServiceException);
|
|
|
|
LOG.error(errorMsg, deviceManagementServiceException);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -133,9 +135,16 @@ public class Device {
|
|
|
|
|
|
|
|
|
|
|
|
} catch (DeviceManagementException deviceMgtEx) {
|
|
|
|
} catch (DeviceManagementException deviceMgtEx) {
|
|
|
|
String msg = "Error occurred while modifying the device information.";
|
|
|
|
String msg = "Error occurred while modifying the device information.";
|
|
|
|
log.error(msg, deviceMgtEx);
|
|
|
|
LOG.error(msg, deviceMgtEx);
|
|
|
|
throw new AndroidAgentException(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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|