Add device type specific platform config endpoint

revert-70aa11f8
Charitha Goonetilleke 6 years ago
parent 59e6334a3b
commit e71c362309

@ -15,6 +15,22 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
* *
*
* Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (pvt) Ltd. 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; package org.wso2.carbon.device.mgt.jaxrs.service.api;
@ -31,15 +47,23 @@ import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader; import io.swagger.annotations.ResponseHeader;
import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList; 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.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import javax.ws.rs.*; import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List;
@SwaggerDefinition( @SwaggerDefinition(
info = @Info( info = @Info(
@ -62,13 +86,19 @@ import javax.ws.rs.core.Response;
name = "Getting the Supported Device Platforms", name = "Getting the Supported Device Platforms",
description = "Getting the Supported Device Platforms", description = "Getting the Supported Device Platforms",
key = "perm:device-types:types", key = "perm:device-types:types",
permissions = {"/device-mgt/devices/owning-device/view"} permissions = {"/device-mgt/device-type/view"}
), ),
@Scope( @Scope(
name = "Get Feature Details of a Device Type", name = "Get Feature Details of a Device Type",
description = "Get Feature Details of a Device Type", description = "Get Feature Details of a Device Type",
key = "perm:device-types:features", key = "perm:device-types:features",
permissions = {"/device-mgt/devices/owning-device/view"} permissions = {"/device-mgt/device-type/features/view"}
),
@Scope(
name = "Get Config Details of a Device Type",
description = "Get Config Details of a Device Type",
key = "perm:device-types:configs",
permissions = {"/device-mgt/device-type/config/view"}
) )
} }
) )
@ -84,7 +114,7 @@ public interface DeviceTypeManagementService {
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting the Supported Device Platforms", value = "Getting the Supported Device Platforms",
notes = "Get the list of device platforms supported by WSO2 EMM.", notes = "Get the list of device platforms supported by Entgra IoTS.",
tags = "Device Type Management", tags = "Device Type Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ -133,18 +163,71 @@ public interface DeviceTypeManagementService {
name = "If-Modified-Since", name = "If-Modified-Since",
value = "Checks if the requested variant was modified, since the specified date-time.\n" + value = "Checks if the requested variant was modified, since the specified date-time.\n" +
"Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" + "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" +
"Example: Mon, 05 Jan 2014 15:10:00 +0200", "Example: Mon, 05 Jan 2014 15:10:00 +0200"
required = false) )
@HeaderParam("If-Modified-Since") @HeaderParam("If-Modified-Since")
String ifModifiedSince); String ifModifiedSince);
@GET
@Path("/{type}")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Getting Details of a Device Type",
notes = "Get the details of a device by searching via the device type and the tenant domain.",
response = DeviceType.class,
tags = "Device Type Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:types")
})
}
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device type.",
response = DeviceType.class,
responseContainer = "List",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body")
}),
@ApiResponse(
code = 304,
message = "Not Modified. Empty body because the client already has the latest version of the " +
"requested resource.\n"),
@ApiResponse(
code = 401,
message = "Unauthorized.\n The unauthorized access to the requested resource.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found.\n The specified device does not exist",
response = ErrorResponse.class),
@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 device list.",
response = ErrorResponse.class)
})
Response getDeviceTypeByName(
@ApiParam(
name = "type",
value = "The device type name, such as ios, android, windows or fire-alarm.",
required = true)
@PathParam("type")
@Size(min = 2, max = 45)
String type);
@GET @GET
@Path("/{type}/features") @Path("/{type}/features")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Get Feature Details of a Device Type", value = "Get Feature Details of a Device Type",
notes = "The features in WSO2 EMM enables you to carry out many operations on a given device platform. " + notes = "The features in Entgra IoTS enables you to carry out many operations on a given device platform. " +
"Using this REST API you can get the features that can be carried out on a preferred device type," + "Using this REST API you can get the features that can be carried out on a preferred device type," +
" such as iOS, Android or Windows.", " such as iOS, Android or Windows.",
tags = "Device Type Management", tags = "Device Type Management",
@ -202,108 +285,78 @@ public interface DeviceTypeManagementService {
name = "If-Modified-Since", name = "If-Modified-Since",
value = "Checks if the requested variant was modified, since the specified date-time.\n" + value = "Checks if the requested variant was modified, since the specified date-time.\n" +
"Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" + "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" +
"Example: Mon, 05 Jan 2014 15:10:00 +0200", "Example: Mon, 05 Jan 2014 15:10:00 +0200"
required = false) )
@HeaderParam("If-Modified-Since") @HeaderParam("If-Modified-Since")
String ifModifiedSince); String ifModifiedSince);
@GET @GET
@Path("/all/{type}") @Path("/{type}/configs")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
value = "Getting Details of a Device Type", value = "Get Configuration Details of a Device Type",
notes = "Get the details of a device by searching via the device type and the tenant domain.", notes = "The features in Entgra IoTS enables you to carry out many operations on a given device platform. " +
response = DeviceType.class, "Using this REST API you can get platform configurations that can be carried out on a preferred " +
tags = "Device Type Management Administrative Service", "device type, such as iOS, Android or Windows.",
tags = "Device Type Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:types") @ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:configs")
}) })
} }
) )
@ApiResponses(value = { @ApiResponses(
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device type.", value = {
response = DeviceType.class, @ApiResponse(
responseContainer = "List", code = 200,
responseHeaders = { message = "OK. \n Successfully fetched configurations.",
@ResponseHeader( response = PlatformConfiguration.class,
name = "Content-Type", responseHeaders = {
description = "The content type of the body") @ResponseHeader(
}), name = "Content-Type",
@ApiResponse( description = "The content type of the body"),
code = 304, @ResponseHeader(
message = "Not Modified. Empty body because the client already has the latest version of the " + name = "ETag",
"requested resource.\n"), description = "Entity Tag of the response resource.\n" +
@ApiResponse( "Used by caches, or in conditional requests."),
code = 401, @ResponseHeader(
message = "Unauthorized.\n The unauthorized access to the requested resource.", name = "Last-Modified",
response = ErrorResponse.class), description =
@ApiResponse( "Date and time the resource was last modified.\n" +
code = 404, "Used by caches, or in conditional requests."),
message = "Not Found.\n The specified device does not exist", }
response = ErrorResponse.class), ),
@ApiResponse( @ApiResponse(
code = 406, code = 304,
message = "Not Acceptable.\n The requested media type is not supported"), message =
@ApiResponse( "Not Modified. \n Empty body because the client already has the latest version " +
code = 500, "of the requested resource.\n"),
message = "Internal Server Error. \n Server error occurred while fetching the device list.", @ApiResponse(
response = ErrorResponse.class) code = 406,
}) message = "Not Acceptable.\n The requested media type is not supported"),
Response getDeviceTypeByName( @ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the " +
"list of supported device types.",
response = ErrorResponse.class)
}
)
Response getConfigs(
@ApiParam( @ApiParam(
name = "type", name = "type",
value = "The device type name, such as ios, android, windows or fire-alarm.", value = "The device type name, such as ios, android, windows or fire-alarm.",
required = true) required = true)
@PathParam("type") @PathParam("type")
@Size(min = 2, max = 45) @Size(max = 45)
String type); String type,
@ApiParam(
@GET name = "If-Modified-Since",
@Path("/all") value = "Checks if the requested variant was modified, since the specified date-time.\n" +
@ApiOperation( "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" +
produces = MediaType.APPLICATION_JSON, "Example: Mon, 05 Jan 2014 15:10:00 +0200"
httpMethod = "GET", )
value = "Retrieve device types information", @HeaderParam("If-Modified-Since")
notes = "Retrieve device types information.", String ifModifiedSince);
response = DeviceType.class,
tags = "Device Type Management Administrative Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:types")
})
}
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device type.",
response = DeviceType.class,
responseContainer = "List",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body")
}),
@ApiResponse(
code = 304,
message = "Not Modified. Empty body because the client already has the latest version of the " +
"requested resource.\n"),
@ApiResponse(
code = 401,
message = "Unauthorized.\n The unauthorized access to the requested resource.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found.\n The specified device does not exist",
response = ErrorResponse.class),
@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 device list.",
response = ErrorResponse.class)
})
Response getDeviceTypes();
} }

@ -15,6 +15,23 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
* *
*
* Copyright (c) 2019, Entgra (pvt) Ltd. (https://entgra.io) All Rights Reserved.
*
* Entgra (pvt) Ltd. 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; package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
@ -31,7 +48,7 @@ import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag; import io.swagger.annotations.Tag;
import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList; 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.beans.ErrorResponse;
@ -40,12 +57,11 @@ import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.PUT; import javax.ws.rs.PUT;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -73,10 +89,22 @@ import javax.ws.rs.core.Response;
@Scopes( @Scopes(
scopes = { scopes = {
@Scope( @Scope(
name = "Getting Details of a Device", name = "Manage a Device Type",
description = "Getting Details of a Device", description = "Add, Edit or View a Device Type",
key = "perm:admin:device-type", key = "perm:admin:device-type",
permissions = {"/device-mgt/admin/device-type"} permissions = {"/device-mgt/admin/device-type"}
),
@Scope(
name = "Getting Details of a Device Type",
description = "Getting Details of a Device Type",
key = "perm:admin:device-type:view",
permissions = {"/device-mgt/admin/device-type/view"}
),
@Scope(
name = "Add Device Type Config",
description = "Add Platform Config of a Device Type",
key = "perm:admin:device-type:configs",
permissions = {"/device-mgt/admin/device-type/config"}
) )
} }
) )
@ -88,10 +116,10 @@ public interface DeviceTypeManagementAdminService {
httpMethod = "GET", httpMethod = "GET",
value = "Getting the Supported Device Type with Meta Definition", value = "Getting the Supported Device Type with Meta Definition",
notes = "Get the list of device types supported by WSO2 IoT.", notes = "Get the list of device types supported by WSO2 IoT.",
tags = "Device Type Management", tags = "Device Type Management Administrative Service",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:admin:device-type") @ExtensionProperty(name = Constants.SCOPE, value = "perm:admin:device-type:view")
}) })
} }
) )
@ -133,6 +161,59 @@ public interface DeviceTypeManagementAdminService {
) )
Response getDeviceTypes(); Response getDeviceTypes();
@GET
@Path("/{type}")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Getting Details of a Device Type",
notes = "Get the details of a device by searching via the device type and the tenant domain.",
response = DeviceType.class,
tags = "Device Type Management Administrative Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:admin:device-type:view")
})
}
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device type.",
response = DeviceType.class,
responseContainer = "List",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body")
}),
@ApiResponse(
code = 304,
message = "Not Modified. Empty body because the client already has the latest version of the " +
"requested resource.\n"),
@ApiResponse(
code = 401,
message = "Unauthorized.\n The unauthorized access to the requested resource.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found.\n The specified device does not exist",
response = ErrorResponse.class),
@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 device list.",
response = ErrorResponse.class)
})
Response getDeviceTypeByName(
@ApiParam(
name = "type",
value = "The device type name, such as ios, android, windows or fire-alarm.",
required = true)
@PathParam("type")
@Size(min = 2, max = 45)
String type);
@POST @POST
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
@ -179,6 +260,7 @@ public interface DeviceTypeManagementAdminService {
required = true)DeviceType deviceType); required = true)DeviceType deviceType);
@PUT @PUT
@Path("/{type}")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
@ -219,9 +301,73 @@ public interface DeviceTypeManagementAdminService {
message = "Internal Server Error. \n Server error occurred while fetching the device list.", message = "Internal Server Error. \n Server error occurred while fetching the device list.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response updateDeviceType(@ApiParam( Response updateDeviceType(
name = "type", @ApiParam(
name = "type",
value = "The device type name, such as ios, android, windows or fire-alarm.",
required = true)
@PathParam("type")
@Size(min = 2, max = 45)
String name,
@ApiParam(
name = "deviceType",
value = "The device type such as ios, android, windows or fire-alarm.", value = "The device type such as ios, android, windows or fire-alarm.",
required = true) DeviceType deviceType); required = true) DeviceType deviceType);
@POST
@Path("/{type}/configs")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Add Configuration Details",
notes = "Add Configuration Details of a Device Type.",
tags = "Device Type Management Administrative Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:admin:device-type:configs")
})
}
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully added the device type config.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body")
}),
@ApiResponse(
code = 304,
message = "Not Modified. Empty body because the client already has the latest version of the " +
"requested resource.\n"),
@ApiResponse(
code = 401,
message = "Unauthorized.\n The unauthorized access to the requested resource.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found.\n The specified device does not exist",
response = ErrorResponse.class),
@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 device list.",
response = ErrorResponse.class)
})
Response addDeviceTypePlatformConfig(
@ApiParam(
name = "type",
value = "The device type name, such as ios, android, windows or fire-alarm.",
required = true)
@PathParam("type")
@Size(min = 2, max = 45)
String type,
@ApiParam(
name = "config",
value = "Platform configuration of specified device type.",
required = true)
PlatformConfiguration config);
} }

@ -15,6 +15,23 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
* *
*
* Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (pvt) Ltd. 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; package org.wso2.carbon.device.mgt.jaxrs.service.impl;
@ -23,14 +40,13 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition; import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
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.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceTypeManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceTypeManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
@ -38,7 +54,6 @@ import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam; import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -51,50 +66,6 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
@GET @GET
@Override @Override
public Response getDeviceTypes(@HeaderParam("If-Modified-Since") String ifModifiedSince) { 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();
}
}
@GET
@Override
@Path("/{type}/features")
public Response getFeatures(@PathParam("type") @Size(max = 45) String type, @HeaderParam("If-Modified-Since") String ifModifiedSince) {
List<Feature> features;
DeviceManagementProviderService dms;
try {
dms = DeviceMgtAPIUtils.getDeviceManagementService();
FeatureManager fm = dms.getFeatureManager(type);
if (fm == null) {
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " +
"registered with the given type '" + type + "'").build()).build();
}
features = fm.getFeatures();
} catch (DeviceManagementException e) {
String msg = "Error occurred while retrieving the list of features of '" + type + "' device type";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
return Response.status(Response.Status.OK).entity(features).build();
}
@Override
@GET
@Path("/config")
public Response getDeviceTypes() {
try { try {
List<DeviceType> deviceTypes = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceTypes(); List<DeviceType> deviceTypes = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceTypes();
List<DeviceType> filteredDeviceTypes = new ArrayList<>(); List<DeviceType> filteredDeviceTypes = new ArrayList<>();
@ -111,8 +82,8 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
@Override @Override
@GET @GET
@Path("/config/{type}") @Path("/{type}")
public Response getDeviceTypeByName(@PathParam("type") String type) { public Response getDeviceTypeByName(@PathParam("type") @Size(max = 45) String type) {
if (type != null && type.length() > 0) { if (type != null && type.length() > 0) {
try { try {
DeviceType deviceType = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(type); DeviceType deviceType = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(type);
@ -120,7 +91,7 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
String msg = "Device type does not exist, " + type; String msg = "Device type does not exist, " + type;
return Response.status(Response.Status.NO_CONTENT).entity(msg).build(); return Response.status(Response.Status.NO_CONTENT).entity(msg).build();
} }
return Response.status(Response.Status.OK).entity(deviceType).build(); return Response.status(Response.Status.OK).entity(clearMetaEntryInfo(deviceType)).build();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred at server side while fetching device type."; String msg = "Error occurred at server side while fetching device type.";
log.error(msg, e); log.error(msg, e);
@ -131,10 +102,52 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
} }
} }
@GET
@Override
@Path("/{type}/features")
public Response getFeatures(@PathParam("type") @Size(max = 45) String type,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
List<Feature> features;
DeviceManagementProviderService dms;
try {
dms = DeviceMgtAPIUtils.getDeviceManagementService();
FeatureManager fm = dms.getFeatureManager(type);
if (fm == null) {
features = new ArrayList<>();
} else {
features = fm.getFeatures();
}
} catch (DeviceManagementException e) {
String msg = "Error occurred while retrieving the list of features of '" + type + "' device type";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
return Response.status(Response.Status.OK).entity(features).build();
}
@GET
@Override
@Path("/{type}/configs")
public Response getConfigs(@PathParam("type") @Size(max = 45) String type,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
PlatformConfiguration platformConfiguration;
try {
platformConfiguration = DeviceMgtAPIUtils.getDeviceManagementService().getConfiguration(type);
} catch (DeviceManagementException e) {
String msg = "Error occurred while retrieving the '" + type + "' platform configuration";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
return Response.status(Response.Status.OK).entity(platformConfiguration).build();
}
/** /**
* This cleans up the configs that should not be exposed to iot users. * This cleans up the configs that should not be exposed to iot users.
* @param deviceType *
* @return * @param deviceType device type retrieved from service layer.
* @return sanitized device type.
*/ */
private DeviceType clearMetaEntryInfo(DeviceType deviceType) { private DeviceType clearMetaEntryInfo(DeviceType deviceType) {
DeviceTypeMetaDefinition metaDefinition = deviceType.getDeviceTypeMetaDefinition(); DeviceTypeMetaDefinition metaDefinition = deviceType.getDeviceTypeMetaDefinition();

@ -15,13 +15,31 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
* *
*
* Copyright (c) 2019, Entgra (pvt) Ltd. (https://entgra.io) All Rights Reserved.
*
* Entgra (pvt) Ltd. 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; package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin;
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.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidConfigurationException; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
@ -33,6 +51,7 @@ import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.PUT; import javax.ws.rs.PUT;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -63,6 +82,28 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen
} }
} }
@Override
@GET
@Path("/{type}")
public Response getDeviceTypeByName(@PathParam("type") String type) {
if (type != null && type.length() > 0) {
try {
DeviceType deviceType = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(type);
if (deviceType == null) {
String msg = "Device type does not exist, " + type;
return Response.status(Response.Status.NO_CONTENT).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(deviceType).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred at server side while fetching device type.";
log.error(msg, e);
return Response.serverError().entity(msg).build();
}
} else {
return Response.status(Response.Status.BAD_REQUEST).build();
}
}
@Override @Override
@POST @POST
public Response addDeviceType(DeviceType deviceType) { public Response addDeviceType(DeviceType deviceType) {
@ -81,8 +122,8 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen
DeviceMgtAPIUtils.getDeviceManagementService().registerDeviceType(httpDeviceTypeManagerService); DeviceMgtAPIUtils.getDeviceManagementService().registerDeviceType(httpDeviceTypeManagerService);
return Response.status(Response.Status.OK).build(); return Response.status(Response.Status.OK).build();
} else { } else {
return Response.status(Response.Status.BAD_REQUEST).entity("Device type name does not match the pattern " return Response.status(Response.Status.BAD_REQUEST).entity("Device type name does not match " +
+ DEVICETYPE_REGEX_PATTERN).build(); "the pattern " + DEVICETYPE_REGEX_PATTERN).build();
} }
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred at server side while adding a device type."; String msg = "Error occurred at server side while adding a device type.";
@ -96,11 +137,15 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen
@Override @Override
@PUT @PUT
public Response updateDeviceType(DeviceType deviceType) { public Response updateDeviceType(String type, DeviceType deviceType) {
if (deviceType != null && deviceType.getDeviceTypeMetaDefinition() != null) { if (deviceType != null && deviceType.getDeviceTypeMetaDefinition() != null) {
if (deviceType.getName() == null || !deviceType.getName().equals(type)) {
return Response.status(Response.Status.BAD_REQUEST).entity("Type name mismatch. Expected: '" + type +
"' Found: '"+ deviceType.getName() + "'").build();
}
try { try {
if (DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(deviceType.getName()) == null) { if (DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(type) == null) {
String msg = "Device type does not exist, " + deviceType.getName(); String msg = "Device type does not exist, " + type;
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} }
DeviceManagementService httpDeviceTypeManagerService = DeviceMgtAPIUtils.getDeviceTypeGeneratorService() DeviceManagementService httpDeviceTypeManagerService = DeviceMgtAPIUtils.getDeviceTypeGeneratorService()
@ -116,4 +161,22 @@ public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagemen
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.BAD_REQUEST).build();
} }
} }
@Override
public Response addDeviceTypePlatformConfig(String type, PlatformConfiguration platformConfiguration) {
boolean isSaved;
if (platformConfiguration.getType() == null || !platformConfiguration.getType().equals(type)) {
return Response.status(Response.Status.BAD_REQUEST).entity("Type name mismatch. Expected: '" + type +
"' Found: '"+ platformConfiguration.getType() + "'").build();
}
try {
isSaved = DeviceMgtAPIUtils.getDeviceManagementService().saveConfiguration(platformConfiguration);
} catch (DeviceManagementException e) {
String msg = "Error occurred while retrieving the Android tenant configuration";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
return Response.status(isSaved ? Response.Status.OK : Response.Status.BAD_REQUEST).build();
}
} }

@ -66,7 +66,7 @@
<property name="schemes" value="https" /> <property name="schemes" value="https" />
<property name="basePath" value="/api/device-mgt/v1.0"/> <property name="basePath" value="/api/device-mgt/v1.0"/>
<property name="title" value="Device Management Admin Service API Definitions"/> <property name="title" value="Device Management Admin Service API Definitions"/>
<property name="contact" value="dev@wso2.org"/> <property name="contact" value="dev@entgra.io"/>
<property name="license" value="Apache 2.0"/> <property name="license" value="Apache 2.0"/>
<property name="licenseUrl" value="http://www.apache.org/licenses/LICENSE-2.0.html"/> <property name="licenseUrl" value="http://www.apache.org/licenses/LICENSE-2.0.html"/>
<property name="scan" value="true"/> <property name="scan" value="true"/>

@ -136,6 +136,7 @@
"perm:groups:devices-remove", "perm:groups:devices-remove",
"perm:groups:devices-add", "perm:groups:devices-add",
"perm:groups:assign", "perm:groups:assign",
"perm:device-types:configs",
"perm:device-types:features", "perm:device-types:features",
"perm:device-types:types", "perm:device-types:types",
"perm:applications:install", "perm:applications:install",
@ -154,6 +155,8 @@
"perm:device-types:events", "perm:device-types:events",
"perm:device-types:events:view", "perm:device-types:events:view",
"perm:admin:device-type", "perm:admin:device-type",
"perm:admin:device-type:view",
"perm:admin:device-type:configs",
"perm:device:enroll", "perm:device:enroll",
"perm:geo-service:analytics-view", "perm:geo-service:analytics-view",
"perm:geo-service:alerts-manage", "perm:geo-service:alerts-manage",

@ -303,7 +303,7 @@ deviceModule = function () {
} }
return serviceInvokers.XMLHttp.get( return serviceInvokers.XMLHttp.get(
url, function (responsePayload) { url, function (responsePayload) {
return parse(responsePayload["responseText"])["count"]; return parse(responsePayload["responseText"]).length;
}, },
function (responsePayload) { function (responsePayload) {
log.error(responsePayload["responseText"]); log.error(responsePayload["responseText"]);

@ -56,12 +56,12 @@ function onRequest(context) {
var typesListResponse = deviceModule.getDeviceTypes(); var typesListResponse = deviceModule.getDeviceTypes();
var deviceTypes = []; var deviceTypes = [];
if (typesListResponse["status"] == "success") { if (typesListResponse["status"] == "success") {
var data = typesListResponse.content.deviceTypes; var data = typesListResponse.content;
if (data) { if (data) {
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
var config = utility.getDeviceTypeConfig(data[i]); var config = utility.getDeviceTypeConfig(data[i].name);
var category = "iot"; var category = "iot";
var label = data[i]; var label = data[i].name;
var analyticsEnabled = "false"; var analyticsEnabled = "false";
var groupingEnabled = "true"; var groupingEnabled = "true";
var analyticsView = null; var analyticsView = null;
@ -75,10 +75,10 @@ function onRequest(context) {
} }
deviceTypes.push({ deviceTypes.push({
"type": data[i], "type": data[i].name,
"category": category, "category": category,
"label": label, "label": label,
"thumb": utility.getDeviceThumb(data[i]), "thumb": utility.getDeviceThumb(data[i].name),
"analyticsEnabled": analyticsEnabled, "analyticsEnabled": analyticsEnabled,
"groupingEnabled": groupingEnabled, "groupingEnabled": groupingEnabled,
"analyticsView" : analyticsView "analyticsView" : analyticsView

@ -28,14 +28,14 @@ function onRequest(context) {
var utility = require("/app/modules/utility.js").utility; var utility = require("/app/modules/utility.js").utility;
var typesListResponse = deviceModule.getDeviceTypes(); var typesListResponse = deviceModule.getDeviceTypes();
if (typesListResponse["status"] == "success") { if (typesListResponse["status"] == "success") {
var deviceTypes = typesListResponse.content.deviceTypes; var deviceTypes = typesListResponse.content;
if (deviceTypes) { if (deviceTypes) {
if (deviceTypes.length > 0){ if (deviceTypes.length > 0){
viewModel.hasDeviceTypes = true; viewModel.hasDeviceTypes = true;
} }
var deviceTypesList = [], virtualDeviceTypesList = []; var deviceTypesList = [], virtualDeviceTypesList = [];
for (var i = 0; i < deviceTypes.length; i++) { for (var i = 0; i < deviceTypes.length; i++) {
var deviceType = deviceTypes[i]; var deviceType = deviceTypes[i].name;
var deviceTypeLabel = deviceType; var deviceTypeLabel = deviceType;
var configs = utility.getDeviceTypeConfig(deviceTypeLabel); var configs = utility.getDeviceTypeConfig(deviceTypeLabel);
var deviceCategory = "device"; var deviceCategory = "device";

@ -50,7 +50,7 @@ function onRequest(context) {
types.isAuthorizedViewGroups = userModule.isAuthorized("/permission/admin/device-mgt/groups/view"); types.isAuthorizedViewGroups = userModule.isAuthorized("/permission/admin/device-mgt/groups/view");
types["types"] = []; types["types"] = [];
var typesListResponse = deviceModule.getDeviceTypesConfig(); var typesListResponse = deviceModule.getDeviceTypes();
if (typesListResponse["status"] == "success") { if (typesListResponse["status"] == "success") {
for (var type in typesListResponse["content"]) { for (var type in typesListResponse["content"]) {
var content = {}; var content = {};

@ -27,8 +27,8 @@ function onRequest(context) {
return options.fn(this); return options.fn(this);
} }
}); });
var utility = require("/app/modules/utility.js").utility;
var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; var mdmProps = require("/app/modules/conf-reader/main.js")["conf"];
var constants = require("/app/modules/constants.js"); var constants = require("/app/modules/constants.js");
var uiPermissions = userModule.getUIPermissions(); var uiPermissions = userModule.getUIPermissions();
@ -43,15 +43,10 @@ function onRequest(context) {
"device-mgt": [] "device-mgt": []
}; };
var typesListResponse = deviceModule.getDeviceTypesConfig();
var temp = [];
temp = typesListResponse["content"];
var iosPluginFlag = false; var iosPluginFlag = false;
temp.forEach(function(element) { if (utility.getTenantedDeviceUnitName("ios", "type-view")) {
if (element["name"] == "ios") { iosPluginFlag = true;
iosPluginFlag = true; }
}
});
context["iosPluginFlag"] = iosPluginFlag; context["iosPluginFlag"] = iosPluginFlag;
// following context.link value comes here based on the value passed at the point // following context.link value comes here based on the value passed at the point

Loading…
Cancel
Save