forked from community/device-mgt-plugins
parent
18f858ab3a
commit
40a4f54b9f
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 cdm.api.android;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* Android Device Management REST-API implementation.
|
||||
*/
|
||||
@Path("/devices")
|
||||
public class Device {
|
||||
|
||||
@GET
|
||||
public String getAllDevices() {
|
||||
return "License Agreement";
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
public String getDevice(@PathParam("id") String id) {
|
||||
return "License Agreement";
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{id}")
|
||||
public Response updateDevice(@PathParam("id") String id) {
|
||||
return Response.status(201).entity("Registration Successful").build();
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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 cdm.api.android;
|
||||
|
||||
import cdm.api.android.util.AndroidAPIUtil;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* Android Device Enrollment REST-API implementation.
|
||||
*/
|
||||
@Path("/enrollment")
|
||||
public class Enrollment {
|
||||
|
||||
private static Log log = LogFactory.getLog(Enrollment.class);
|
||||
@POST
|
||||
@Consumes("application/json")
|
||||
public Response enrollDevice() {
|
||||
JsonObject result = new JsonObject();
|
||||
result.addProperty("senderId","jwwfowrjwqporqwrpqworpq");
|
||||
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
|
||||
DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null);
|
||||
Device device = AndroidAPIUtil.convertToDeviceDTO(result);
|
||||
try {
|
||||
dmService.enrollDevice(null);
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while enrolling the device";
|
||||
log.error(msg, e);
|
||||
}
|
||||
return Response.status(201).entity("Registration Successful").build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
public String isEnrolled(@PathParam("id") String id) {
|
||||
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
|
||||
DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null);
|
||||
try {
|
||||
Device device = AndroidAPIUtil.convertToDeviceDTO(id);
|
||||
dmService.isRegistered(null);
|
||||
} catch (DeviceManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "true";
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Consumes("application/json")
|
||||
@Path("{id}")
|
||||
public Response modifyEnrollment(@PathParam("id") String id) {
|
||||
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
|
||||
DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null);
|
||||
try {
|
||||
dmService.isRegistered(null);
|
||||
} catch (DeviceManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Response.status(201).entity("Registration Successful").build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
public Response disenrollDevice(@PathParam("id") String id) {
|
||||
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
|
||||
DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null);
|
||||
try {
|
||||
dmService.isRegistered(null);
|
||||
} catch (DeviceManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Response.status(201).entity("Registration Successful").build();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 cdm.api.android.util;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.MobileDeviceManagementConstants;
|
||||
|
||||
/**
|
||||
* AndroidAPIUtil class provides utility function used by Android REST-API classes.
|
||||
*/
|
||||
public class AndroidAPIUtil {
|
||||
|
||||
public static Device convertToDeviceDTO(JsonObject json){
|
||||
Device device = new Device();
|
||||
return device;
|
||||
}
|
||||
|
||||
public static Device convertToDeviceDTO(String deviceId){
|
||||
Device device = new Device();
|
||||
DeviceType type = new DeviceType();
|
||||
device.setId(deviceId);
|
||||
type.setName(MobileDeviceManagementConstants.MOBILE_DEVICE_TYPE_ANDROID);
|
||||
device.setDeviceType(type);
|
||||
return device;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue