forked from community/device-mgt-core
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
commit
e52fed0b2d
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.jaxrs.beans;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeviceTypeList {
|
||||||
|
|
||||||
|
private int count;
|
||||||
|
private String next;
|
||||||
|
private String previous;
|
||||||
|
private List<String> deviceTypes = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of Devices Types returned.
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "Number of resources returned.")
|
||||||
|
@JsonProperty("count")
|
||||||
|
public int getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCount(int count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link to the next subset of resources qualified. \nEmpty if no more resources are to be returned.
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "Link to the next subset of resources qualified. \n " +
|
||||||
|
"Empty if no more resources are to be returned.")
|
||||||
|
@JsonProperty("next")
|
||||||
|
public String getNext() {
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNext(String next) {
|
||||||
|
this.next = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link to the previous subset of resources qualified. \nEmpty if current subset is the first subset returned.
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "Link to the previous subset of resources qualified. \n" +
|
||||||
|
"Empty if current subset is the first subset returned.")
|
||||||
|
@JsonProperty("previous")
|
||||||
|
public String getPrevious() {
|
||||||
|
return previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrevious(String previous) {
|
||||||
|
this.previous = previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "List of device types returned")
|
||||||
|
@JsonProperty("devicesTypes")
|
||||||
|
public List<String> getList() {
|
||||||
|
return deviceTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setList(List<String> deviceTypes) {
|
||||||
|
this.deviceTypes = deviceTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("{\n");
|
||||||
|
|
||||||
|
sb.append(" count: ").append(getCount()).append(",\n");
|
||||||
|
sb.append(" next: ").append(getNext()).append(",\n");
|
||||||
|
sb.append(" previous: ").append(getPrevious()).append(",\n");
|
||||||
|
sb.append(" deviceTypes: [").append(deviceTypes).append("\n");
|
||||||
|
sb.append("]}\n");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.jaxrs.service.api.admin;
|
||||||
|
|
||||||
|
import io.swagger.annotations.*;
|
||||||
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
|
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@API(name = "Device Type Management", version = "1.0.0", context = "/admin/device-types", tags = {"devicemgt_admin"})
|
||||||
|
|
||||||
|
@Path("/admin/device-types")
|
||||||
|
@Api(value = "Device Type Management", description = "This API corresponds to all tasks related to device " +
|
||||||
|
"type management")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public interface DeviceTypeManagementService {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@ApiOperation(
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "GET",
|
||||||
|
value = "Get the list of device types registered.",
|
||||||
|
notes = "Retrieves the list of device types of which the devices intended to be managed.",
|
||||||
|
tags = "Device Type Management")
|
||||||
|
@ApiResponses(
|
||||||
|
value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 200,
|
||||||
|
message = "OK. \n Successfully fetched the list of supported device types.",
|
||||||
|
response = DeviceTypeList.class,
|
||||||
|
responseHeaders = {
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Content-Type",
|
||||||
|
description = "The content type of the body"),
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "ETag",
|
||||||
|
description = "Entity Tag of the response resource.\n" +
|
||||||
|
"Used by caches, or in conditional requests."),
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Last-Modified",
|
||||||
|
description = "Date and time the resource has been modified the last time.\n" +
|
||||||
|
"Used by caches, or in conditional requests."),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 304,
|
||||||
|
message = "Not Modified. \n Empty body because the client has already the latest version of " +
|
||||||
|
"the requested resource."),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 406,
|
||||||
|
message = "Not Acceptable.\n The requested media type is not supported"),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n Server error occurred while fetching the " +
|
||||||
|
"list of supported device types.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@Permission(
|
||||||
|
scope = "read:device-types",
|
||||||
|
permissions = {"/permission/admin/device-mgt/admin/device-types/view"}
|
||||||
|
)
|
||||||
|
Response getDeviceTypes(
|
||||||
|
@ApiParam(
|
||||||
|
name = "If-Modified-Since",
|
||||||
|
value = "Validates if the requested variant has not been modified since the time specified",
|
||||||
|
required = false)
|
||||||
|
@HeaderParam("If-Modified-Since")
|
||||||
|
String ifModifiedSince);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.jaxrs.service.impl.admin;
|
||||||
|
|
||||||
|
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.jaxrs.beans.DeviceTypeList;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceTypeManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
|
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.HeaderParam;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Path("/admin/device-types")
|
||||||
|
public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementService {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(DeviceTypeManagementServiceImpl.class);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Override
|
||||||
|
public Response getDeviceTypes(@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
||||||
|
List<String> deviceTypes;
|
||||||
|
try {
|
||||||
|
deviceTypes = DeviceMgtAPIUtils.getDeviceManagementService().getAvailableDeviceTypes();
|
||||||
|
|
||||||
|
DeviceTypeList deviceTypeList = new DeviceTypeList();
|
||||||
|
deviceTypeList.setCount(deviceTypes.size());
|
||||||
|
deviceTypeList.setList(deviceTypes);
|
||||||
|
return Response.status(Response.Status.OK).entity(deviceTypeList).build();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while fetching the list of device types.";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.serverError().entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue