Fixing inconsistencies between what's represented via swagger and the real implementation, and bugs found in admin services

revert-70aa11f8
prabathabey 9 years ago
parent 54f9d02ebb
commit 6e5148a374

@ -46,7 +46,7 @@
<artifactId>maven-war-plugin</artifactId> <artifactId>maven-war-plugin</artifactId>
<configuration> <configuration>
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes> <packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
<warName>api#device-mgt#v1.1</warName> <warName>api#device-mgt#v1.0</warName>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
@ -72,7 +72,7 @@
<tasks> <tasks>
<copy todir="${basedir}/../../../repository/deployment/server/webapps" overwrite="true"> <copy todir="${basedir}/../../../repository/deployment/server/webapps" overwrite="true">
<fileset dir="${basedir}/target"> <fileset dir="${basedir}/target">
<include name="api#device-mgt#v1.1.war" /> <include name="api#device-mgt#v1.0.war" />
</fileset> </fileset>
</copy> </copy>
</tasks> </tasks>
@ -243,6 +243,11 @@
<artifactId>org.wso2.carbon.device.mgt.analytics.dashboard</artifactId> <artifactId>org.wso2.carbon.device.mgt.analytics.dashboard</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -0,0 +1,104 @@
/*
* 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 DeviceList {
private int count;
private String next;
private String previous;
private List<Device> devices = new ArrayList<>();
/**
* Number of Devices returned.
*/
@ApiModelProperty(value = "Number of Devices 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 devices returned")
@JsonProperty("devices")
public List<Device> getList() {
return devices;
}
public void setList(List<Device> devices) {
this.devices = devices;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{\n");
sb.append(" count: ").append(count).append(",\n");
sb.append(" next: ").append(next).append(",\n");
sb.append(" previous: ").append(previous).append(",\n");
sb.append(" devices: [").append(devices).append("\n");
sb.append("]}\n");
return sb.toString();
}
}

@ -0,0 +1,77 @@
/*
* 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.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
@ApiModel(description = "")
public class ErrorListItem {
@NotNull
private String code = null;
@NotNull
private String message = null;
@ApiModelProperty(required = true, value = "")
@JsonProperty("code")
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public ErrorListItem() {}
public ErrorListItem(String code, String msg) {
this.code = code;
this.message = msg;
}
/**
* Description about individual errors occurred
**/
@ApiModelProperty(required = true, value = "Description about individual errors occurred")
@JsonProperty("message")
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("errorItem {\n");
sb.append(" code: ").append(code).append("\n");
sb.append(" message: ").append(message).append("\n");
sb.append("}\n");
return sb.toString();
}
}

@ -0,0 +1,193 @@
/*
* 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.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
@ApiModel(description = "")
public class ErrorResponse {
private Long code = null;
private String message = null;
private String description = null;
private String moreInfo = null;
private List<ErrorListItem> errorItems = new ArrayList<>();
private ErrorResponse() {
}
@JsonProperty(value = "code")
@ApiModelProperty(required = true, value = "")
public Long getCode() {
return code;
}
public void setCode(Long code) {
this.code = code;
}
@JsonProperty(value = "message")
@ApiModelProperty(required = true, value = "ErrorResponse message.")
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@JsonProperty(value = "description")
@ApiModelProperty(value = "A detail description about the error message.")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@JsonProperty(value = "moreInfo")
@ApiModelProperty(value = "Preferably an url with more details about the error.")
public String getMoreInfo() {
return moreInfo;
}
public void setMoreInfo(String moreInfo) {
this.moreInfo = moreInfo;
}
public void addErrorListItem(ErrorListItem item) {
this.errorItems.add(item);
}
/**
* If there are more than one error list them out. \nFor example, list out validation errors by each field.
*/
@JsonProperty(value = "errorItems")
@ApiModelProperty(value = "If there are more than one error list them out. \n" +
"For example, list out validation errors by each field.")
public List<ErrorListItem> getErrorItems() {
return errorItems;
}
public void setErrorItems(List<ErrorListItem> error) {
this.errorItems = error;
}
@Override
public String toString() {
// StringBuilder sb = new StringBuilder();
// sb.append("{");
// boolean cont = false;
// if (code != null) {
// cont = true;
// sb.append(" \"code\": ").append(code);
// }
// if (message != null) {
// if (cont) {
// sb.append(",");
// }
// cont = true;
// sb.append(" \"message\": \"").append(message).append("\"");
// }
// if (description != null) {
// if (cont) {
// sb.append(",");
// }
// cont = true;
// sb.append(" \"description\": ").append(description).append("\"");
// }
// if (moreInfo != null) {
// if (cont) {
// sb.append(",");
// }
// cont = true;
// sb.append(" \"moreInfo\": \"").append(moreInfo).append("\"");
// }
// if (error != null && error.size() > 0) {
// if (cont) {
// sb.append(",");
// }
// sb.append(" \"errorItems\": ").append(error);
// }
// sb.append("}");
// return sb.toString();
return null;
}
public static class ErrorResponseBuilder {
private Long code = null;
private String message = null;
private String description = null;
private String moreInfo = null;
private List<ErrorListItem> error;
public ErrorResponseBuilder() {
this.error = new ArrayList<>();
}
public ErrorResponseBuilder setCode(long code) {
this.code = code;
return this;
}
public ErrorResponseBuilder setMessage(String message) {
this.message = message;
return this;
}
public ErrorResponseBuilder setDescription(String description) {
this.description = description;
return this;
}
public ErrorResponseBuilder setMoreInfo(String moreInfo) {
this.moreInfo = moreInfo;
return this;
}
public ErrorResponseBuilder addErrorItem(String code, String msg) {
ErrorListItem item = new ErrorListItem();
item.setCode(code);
item.setMessage(msg);
this.error.add(item);
return this;
}
public ErrorResponse build() {
ErrorResponse errorResponse = new ErrorResponse();
errorResponse.setCode(code);
errorResponse.setMessage(message);
errorResponse.setErrorItems(error);
errorResponse.setDescription(description);
errorResponse.setMoreInfo(moreInfo);
return errorResponse;
}
}
}

@ -0,0 +1,102 @@
/*
* 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.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import java.util.List;
@ApiModel(value = "notificationList")
public class NotificationList {
private int count;
private String next;
private String previous;
private List<Notification> notifications;
/**
* Number of notifications returned.
*/
@ApiModelProperty(value = "Number of notifications 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;
}
@JsonProperty("notifications")
@ApiModelProperty("notifications")
public List<Notification> getNotifications() {
return notifications;
}
public void setNotifications(List<Notification> notifications) {
this.notifications = notifications;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{");
sb.append(" count: ").append(count).append(",");
sb.append(" next: ").append(next).append(",");
sb.append(" previous: ").append(previous).append(",");
sb.append(" notifications: [").append(notifications).append("");
sb.append("]}");
return sb.toString();
}
}

@ -21,7 +21,6 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission; import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import javax.ws.rs.*; import javax.ws.rs.*;
@ -55,7 +54,7 @@ public interface ActivityInfoProviderService {
code = 200, code = 200,
message = "OK. \n Activity details are successfully fetched", message = "OK. \n Activity details are successfully fetched",
response = Activity.class, response = Activity.class,
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
description = "The content type of the body"), description = "The content type of the body"),
@ -77,7 +76,7 @@ public interface ActivityInfoProviderService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching activity data.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching activity data.")
}) })
@Permission(scope = "activity-view", permissions = {"/permission/admin/device-mgt/admin/activities/view"}) @Permission(scope = "activity-view", permissions = {"/permission/admin/device-mgt/admin/activities/view"})
Response getActivity( Response getActivity(
@ -94,7 +93,6 @@ public interface ActivityInfoProviderService {
@GET @GET
@Path("/")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
@ -102,7 +100,8 @@ public interface ActivityInfoProviderService {
responseContainer = "List", responseContainer = "List",
value = "Retrieve details of a particular activity.", value = "Retrieve details of a particular activity.",
notes = "This will return information of a particular activities i.e. meta information of operations, " + notes = "This will return information of a particular activities i.e. meta information of operations, " +
"etc; including the responses from the devices which happened after given time.") "etc; including the responses from the devices which happened after given time.",
tags = "Activity Info Provider")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
@ -131,7 +130,7 @@ public interface ActivityInfoProviderService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching activity data.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching activity data.")
}) })
@Permission(scope = "activity-view", permissions = {"/permission/admin/device-mgt/admin/activities/view"}) @Permission(scope = "activity-view", permissions = {"/permission/admin/device-mgt/admin/activities/view"})
Response getActivities( Response getActivities(
@ -139,12 +138,22 @@ public interface ActivityInfoProviderService {
name = "timestamp", name = "timestamp",
value = "Validates if the requested variant has not been modified since the time specified, this " + value = "Validates if the requested variant has not been modified since the time specified, this " +
"should be provided in unix format in seconds.", "should be provided in unix format in seconds.",
required = true) required = false)
@QueryParam("timestamp") String timestamp, @QueryParam("timestamp") String timestamp,
@ApiParam( @ApiParam(
name = "If-Modified-Since", name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified", value = "Validates if the requested variant has not been modified since the time specified",
required = false) required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince); @HeaderParam("If-Modified-Since") String ifModifiedSince,
@ApiParam(
name = "offset",
value = "Starting point within the complete list of items qualified.",
required = false)
@QueryParam("offset") int offset,
@ApiParam(
name = "limit",
value = "Maximum size of resource array to return.",
required = false)
@QueryParam("limit") int limit);
} }

@ -74,7 +74,7 @@ public interface ConfigurationManagementService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the general platform configuration.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching the general platform configuration.")
}) })
@Permission(scope = "configuration-view", @Permission(scope = "configuration-view",
permissions = {"/permission/admin/device-mgt/admin/platform-configs/view"}) permissions = {"/permission/admin/device-mgt/admin/platform-configs/view"})
@ -123,7 +123,7 @@ public interface ConfigurationManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while modifying general platform configuration.") "Server error occurred while modifying general platform configuration.")
}) })
@Permission(scope = "configuration-modify", @Permission(scope = "configuration-modify",

@ -84,7 +84,7 @@ public interface DeviceManagementService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the device list.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching the device list.")
}) })
@Permission(scope = "device-list", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-list", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDevices( Response getDevices(
@ -95,7 +95,7 @@ public interface DeviceManagementService {
@QueryParam("type") String type, @QueryParam("type") String type,
@ApiParam( @ApiParam(
name = "user", value = "Username of owner of the devices.", name = "user", value = "Username of owner of the devices.",
required = true) required = false)
@QueryParam("user") String user, @QueryParam("user") String user,
@ApiParam( @ApiParam(
name = "roleName", name = "roleName",
@ -177,7 +177,7 @@ public interface DeviceManagementService {
message = "Not Acceptable. \n The requested media type is not supported."), message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving information of the list of the devices submitted.") "Server error occurred while retrieving information of the list of the devices submitted.")
}) })
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
@ -198,69 +198,69 @@ public interface DeviceManagementService {
required = false) required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince); @HeaderParam("If-Modified-Since") String ifModifiedSince);
@POST // @POST
@ApiOperation( // @ApiOperation(
consumes = MediaType.APPLICATION_JSON, // consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, // produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", // httpMethod = "POST",
value = "Retrieve devices information from the supplied device identifies.", // value = "Retrieve devices information from the supplied device identifies.",
notes = "This will return device information such as CPU usage, memory usage etc for supplied device " + // notes = "This will return device information such as CPU usage, memory usage etc for supplied device " +
"identifiers.", // "identifiers.",
response = DeviceInfo.class, // response = DeviceInfo.class,
responseContainer = "List", // responseContainer = "List",
tags = "Device Management") // tags = "Device Management")
@ApiResponses( // @ApiResponses(
value = { // value = {
@ApiResponse( // @ApiResponse(
code = 200, // code = 200,
message = "OK. \n Information of the submitted list of devices is returned", // message = "OK. \n Information of the submitted list of devices is returned",
response = DeviceInfo.class, // response = DeviceInfo.class,
responseContainer = "List", // responseContainer = "List",
responseHeaders = { // responseHeaders = {
@ResponseHeader( // @ResponseHeader(
name = "Content-Type", // name = "Content-Type",
description = "The content type of the body"), // description = "The content type of the body"),
@ResponseHeader( // @ResponseHeader(
name = "ETag", // name = "ETag",
description = "Entity Tag of the response resource.\n" + // description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."), // "Used by caches, or in conditional requests."),
@ResponseHeader( // @ResponseHeader(
name = "Last-Modified", // name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" + // description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests.")}), // "Used by caches, or in conditional requests.")}),
@ApiResponse( // @ApiResponse(
code = 303, // code = 303,
message = "See Other. \n Source can be retrieved from the URL specified at the Location header.", // message = "See Other. \n Source can be retrieved from the URL specified at the Location header.",
responseHeaders = { // responseHeaders = {
@ResponseHeader( // @ResponseHeader(
name = "Content-Location", // name = "Content-Location",
description = "The Source URL of the document.")}), // description = "The Source URL of the document.")}),
@ApiResponse( // @ApiResponse(
code = 304, // code = 304,
message = "Not Modified. \n " + // message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."), // "Empty body because the client already has the latest version of the requested resource."),
@ApiResponse( // @ApiResponse(
code = 400, // code = 400,
message = "Bad Request. \n Invalid request or validation error."), // message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse( // @ApiResponse(
code = 406, // code = 406,
message = "Not Acceptable. \n The requested media type is not supported."), // message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse( // @ApiResponse(
code = 500, // code = 500,
message = "Internal Server Error. \n " + // message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving information of the list of the devices submitted.") // "Server error occurred while retrieving information of the list of the devices submitted.")
}) // })
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) // @Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDevicesInfo( // Response getDevicesInfo(
@ApiParam( // @ApiParam(
name = "deviceIds", // name = "deviceIds",
value = "List of device identifiers", // value = "List of device identifiers",
required = true) List<DeviceIdentifier> deviceIds, // required = true) List<DeviceIdentifier> deviceIds,
@ApiParam( // @ApiParam(
name = "If-Modified-Since", // name = "If-Modified-Since",
value = "Timestamp of the last modified date", // value = "Timestamp of the last modified date",
required = false) // required = false)
@HeaderParam("If-Modified-Since") String timestamp); // @HeaderParam("If-Modified-Since") String timestamp);
@GET @GET
@ -300,7 +300,7 @@ public interface DeviceManagementService {
message = "Not Found. \n No device is found under the provided type and id."), message = "Not Found. \n No device is found under the provided type and id."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving information requested device.") "Server error occurred while retrieving information requested device.")
}) })
@Permission(scope = "device-view", permissions = { @Permission(scope = "device-view", permissions = {
@ -349,7 +349,7 @@ public interface DeviceManagementService {
message = "Location details are not available for the given device."), message = "Location details are not available for the given device."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Error occurred while getting the device location.") message = "ErrorResponse occurred while getting the device location.")
}) })
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDeviceLocation( Response getDeviceLocation(
@ -398,7 +398,7 @@ public interface DeviceManagementService {
message = "Location details are not available for the given devices."), message = "Location details are not available for the given devices."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Error occurred while getting the device location.") message = "ErrorResponse occurred while getting the device location.")
}) })
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDeviceLocations( Response getDeviceLocations(
@ -467,7 +467,7 @@ public interface DeviceManagementService {
message = "Not Acceptable. \n The requested media type is not supported."), message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving feature list of the device.") "Server error occurred while retrieving feature list of the device.")
}) })
@Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/view", @Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/view",
@ -535,7 +535,7 @@ public interface DeviceManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while enrolling the device.") "Server error occurred while enrolling the device.")
}) })
@Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/list"}) @Permission(scope = "device-search", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
@ -608,7 +608,7 @@ public interface DeviceManagementService {
message = "Not Acceptable. \n The requested media type is not supported."), message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving installed application list of the device.") "Server error occurred while retrieving installed application list of the device.")
}) })
@Permission(scope = "operation-view", permissions = { @Permission(scope = "operation-view", permissions = {
@ -696,7 +696,7 @@ public interface DeviceManagementService {
message = "Not Acceptable. \n The requested media type is not supported."), message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving operation list scheduled for the device.") "Server error occurred while retrieving operation list scheduled for the device.")
}) })
@Permission(scope = "operation-view", permissions = { @Permission(scope = "operation-view", permissions = {
@ -731,6 +731,7 @@ public interface DeviceManagementService {
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@GET @GET
@Path("/{type}/{id}/effective-policy")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
@ -781,7 +782,7 @@ public interface DeviceManagementService {
message = "Not Acceptable. \n The requested media type is not supported."), message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving the effective policy calculated for the device.") "Server error occurred while retrieving the effective policy calculated for the device.")
}) })
Response getEffectivePolicyOfDevice( Response getEffectivePolicyOfDevice(
@ -789,12 +790,12 @@ public interface DeviceManagementService {
name = "type", name = "type",
value = "The device type, such as ios, android or windows.", value = "The device type, such as ios, android or windows.",
required = true) required = true)
@QueryParam("type") String type, @PathParam("type") String type,
@ApiParam( @ApiParam(
name = "id", name = "id",
value = "Device Identifier", value = "Device Identifier",
required = true) required = true)
@QueryParam("id") String id, @PathParam("id") String id,
@ApiParam( @ApiParam(
name = "If-Modified-Since", name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified", value = "Validates if the requested variant has not been modified since the time specified",

@ -76,7 +76,7 @@ public interface NotificationManagementService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the notification list.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching the notification list.")
}) })
@Permission(scope = "device-notification-view", permissions = { @Permission(scope = "device-notification-view", permissions = {
"/permission/admin/device-mgt/admin/notifications/view", "/permission/admin/device-mgt/admin/notifications/view",
@ -146,7 +146,7 @@ public interface NotificationManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while modifying status of the notification.") "Server error occurred while modifying status of the notification.")
}) })
@Permission(scope = "device-notification-modify", @Permission(scope = "device-notification-modify",
@ -198,7 +198,7 @@ public interface NotificationManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while adding the notification.") "Server error occurred while adding the notification.")
}) })
@Permission(scope = "device-notification-modify", @Permission(scope = "device-notification-modify",

@ -82,7 +82,7 @@ public interface PolicyManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while adding a new policy.")}) "Server error occurred while adding a new policy.")})
@Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/add"}) @Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/add"})
Response addPolicy( Response addPolicy(
@ -128,7 +128,7 @@ public interface PolicyManagementService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching policies.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching policies.")
}) })
@Permission(scope = "policy-view", permissions = {"/permission/admin/device-mgt/admin/policies/list"}) @Permission(scope = "policy-view", permissions = {"/permission/admin/device-mgt/admin/policies/list"})
Response getPolicies( Response getPolicies(
@ -187,7 +187,7 @@ public interface PolicyManagementService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the policy.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching the policy.")
}) })
@Permission(scope = "policy-view", permissions = {"/permission/admin/device-mgt/admin/policies/list"}) @Permission(scope = "policy-view", permissions = {"/permission/admin/device-mgt/admin/policies/list"})
Response getPolicy( Response getPolicy(
@ -243,7 +243,7 @@ public interface PolicyManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating the policy.") "Server error occurred while updating the policy.")
}) })
@Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/update"}) @Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/update"})
@ -281,7 +281,7 @@ public interface PolicyManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while bulk removing policies.") "Server error occurred while bulk removing policies.")
}) })
@Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/remove"}) @Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/remove"})
@ -304,7 +304,7 @@ public interface PolicyManagementService {
@ApiResponses( @ApiResponses(
value = { value = {
@ApiResponse(code = 200, message = "Policies have been successfully activated."), @ApiResponse(code = 200, message = "Policies have been successfully activated."),
@ApiResponse(code = 500, message = "Error in activating policies.") @ApiResponse(code = 500, message = "ErrorResponse in activating policies.")
}) })
@Permission(scope = "policy-modify", permissions = { @Permission(scope = "policy-modify", permissions = {
"/permission/admin/device-mgt/admin/policies/update", "/permission/admin/device-mgt/admin/policies/update",
@ -325,7 +325,7 @@ public interface PolicyManagementService {
tags = "Device Policy Management") tags = "Device Policy Management")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "Policies have been successfully deactivated."), @ApiResponse(code = 200, message = "Policies have been successfully deactivated."),
@ApiResponse(code = 500, message = "Error in deactivating policies.") @ApiResponse(code = 500, message = "ErrorResponse in deactivating policies.")
}) })
@Permission(scope = "policy-modify", permissions = { @Permission(scope = "policy-modify", permissions = {
"/permission/admin/device-mgt/admin/policies/update", "/permission/admin/device-mgt/admin/policies/update",

@ -76,7 +76,7 @@ public interface RoleManagementService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching requested list of roles.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching requested list of roles.")
}) })
@Permission(scope = "roles-view", permissions = { @Permission(scope = "roles-view", permissions = {
"/permission/admin/device-mgt/admin/roles/list", "/permission/admin/device-mgt/admin/roles/list",
@ -155,7 +155,7 @@ public interface RoleManagementService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the permission list of the requested role.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching the permission list of the requested role.")
}) })
@Permission(scope = "roles-view", permissions = {"/permission/admin/device-mgt/admin/roles/list"}) @Permission(scope = "roles-view", permissions = {"/permission/admin/device-mgt/admin/roles/list"})
Response getPermissionsOfRole( Response getPermissionsOfRole(
@ -209,7 +209,7 @@ public interface RoleManagementService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the requested role.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching the requested role.")
}) })
@Permission(scope = "roles-view", permissions = {"/permission/admin/device-mgt/admin/roles/list"}) @Permission(scope = "roles-view", permissions = {"/permission/admin/device-mgt/admin/roles/list"})
Response getRole( Response getRole(
@ -266,7 +266,7 @@ public interface RoleManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while adding a new role.") "Server error occurred while adding a new role.")
}) })
@Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/add"}) @Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/add"})
@ -316,7 +316,7 @@ public interface RoleManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating the role.") "Server error occurred while updating the role.")
}) })
@Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/update"}) @Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/update"})
@ -348,7 +348,7 @@ public interface RoleManagementService {
message = "Not Found. \n Resource to be deleted does not exist."), message = "Not Found. \n Resource to be deleted does not exist."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while removing the role.") "Server error occurred while removing the role.")
}) })
@Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/remove"}) @Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/remove"})
@ -404,7 +404,7 @@ public interface RoleManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating the user list of the role.") "Server error occurred while updating the user list of the role.")
}) })
@Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/update"}) @Permission(scope = "roles-modify", permissions = {"/permission/admin/device-mgt/admin/roles/update"})

@ -81,7 +81,7 @@ public interface UserManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while adding a new user.") "Server error occurred while adding a new user.")
}) })
@Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/add"}) @Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/add"})
@ -130,7 +130,7 @@ public interface UserManagementService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the requested user.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching the requested user.")
}) })
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/view"}) @Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/view"})
Response getUser( Response getUser(
@ -185,7 +185,7 @@ public interface UserManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating the user.") "Server error occurred while updating the user.")
}) })
@Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/update"}) @Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/update"})
@ -217,7 +217,7 @@ public interface UserManagementService {
message = "Not Found. \n Resource to be deleted does not exist."), message = "Not Found. \n Resource to be deleted does not exist."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while removing the user.") "Server error occurred while removing the user.")
}) })
@Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/remove"}) @Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/remove"})
@ -266,7 +266,7 @@ public interface UserManagementService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the role list assigned to the user.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching the role list assigned to the user.")
}) })
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/view"}) @Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/view"})
Response getRolesOfUser( Response getRolesOfUser(
@ -310,7 +310,7 @@ public interface UserManagementService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the user list.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching the user list.")
}) })
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"}) @Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"})
Response getUsers( Response getUsers(
@ -376,7 +376,7 @@ public interface UserManagementService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the username list that matches the given filter.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching the username list that matches the given filter.")
}) })
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"}) @Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"})
Response getUserNames( Response getUserNames(
@ -425,7 +425,7 @@ public interface UserManagementService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating credentials of the user.") "Server error occurred while updating credentials of the user.")
}) })
@Permission(scope = "user-modify", permissions = {"/permission/admin/login"}) @Permission(scope = "user-modify", permissions = {"/permission/admin/login"})

@ -63,7 +63,7 @@ public interface ApplicationManagementAdminService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while bulk issuing application installation operations upon " + "Server error occurred while bulk issuing application installation operations upon " +
"a given set of devices.") "a given set of devices.")
}) })
@ -97,7 +97,7 @@ public interface ApplicationManagementAdminService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while bulk issuing application un-installation operations upon " + "Server error occurred while bulk issuing application un-installation operations upon " +
"a given set of devices.") "a given set of devices.")
}) })

@ -70,7 +70,7 @@ public interface DeviceManagementAdminService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the device list.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching the device list.")
}) })
Response getDevicesByName( Response getDevicesByName(
@ApiParam( @ApiParam(

@ -69,7 +69,7 @@ public interface GroupManagementAdminService {
message = "Not Acceptable.\n The requested media type is not supported"), message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the group list.") message = "Internal Server ErrorResponse. \n Server error occurred while fetching the group list.")
}) })
@Permission(scope = "group-view", permissions = {"/permission/admin/device-mgt/user/groups/list"}) @Permission(scope = "group-view", permissions = {"/permission/admin/device-mgt/user/groups/list"})
Response getGroupsOfUser( Response getGroupsOfUser(

@ -58,7 +58,7 @@ public interface UserManagementAdminService {
message = "Unsupported media type. \n The entity of the request was in a not supported format."), message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n " + message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating credentials of the user.") "Server error occurred while updating credentials of the user.")
}) })
@Permission(scope = "user-modify", permissions = {"/permission/admin/login"}) @Permission(scope = "user-modify", permissions = {"/permission/admin/login"})

@ -27,10 +27,13 @@ import org.wso2.carbon.device.mgt.jaxrs.service.api.ActivityInfoProviderService;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
@Path("/activities")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ActivityProviderServiceImpl implements ActivityInfoProviderService { public class ActivityProviderServiceImpl implements ActivityInfoProviderService {
private static final Log log = LogFactory.getLog(ActivityProviderServiceImpl.class); private static final Log log = LogFactory.getLog(ActivityProviderServiceImpl.class);
@ -47,7 +50,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
dmService = DeviceMgtAPIUtils.getDeviceManagementService(); dmService = DeviceMgtAPIUtils.getDeviceManagementService();
operation = dmService.getOperationByActivityId(id); operation = dmService.getOperationByActivityId(id);
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
String msg = "Error occurred while fetching the activity for the supplied id."; String msg = "ErrorResponse occurred while fetching the activity for the supplied id.";
log.error(msg, e); log.error(msg, e);
Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -58,14 +61,16 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
@Override @Override
public Response getActivities( public Response getActivities(
@QueryParam("timestamp") String timestamp, @QueryParam("timestamp") String timestamp,
@HeaderParam("If-Modified-Since") String ifModifiedSince) { @HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
List<Activity> activities = null; List<Activity> activities = null;
DeviceManagementProviderService dmService; DeviceManagementProviderService dmService;
try { try {
dmService = DeviceMgtAPIUtils.getDeviceManagementService(); dmService = DeviceMgtAPIUtils.getDeviceManagementService();
activities = dmService.getActivitiesUpdatedAfter(Long.parseLong(timestamp)); activities = dmService.getActivitiesUpdatedAfter(Long.parseLong(timestamp));
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
String msg = "Error occurred while fetching the activities updated after given time stamp."; String msg = "ErrorResponse occurred while fetching the activities updated after given time stamp.";
log.error(msg, e); log.error(msg, e);
Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }

@ -60,7 +60,7 @@ public class ConfigurationServiceImpl implements ConfigurationManagementService
config.setConfiguration(configList); config.setConfiguration(configList);
return Response.status(Response.Status.OK).entity(config).build(); return Response.status(Response.Status.OK).entity(config).build();
} catch (ConfigurationManagementException e) { } catch (ConfigurationManagementException e) {
msg = "Error occurred while retrieving the configurations."; msg = "ErrorResponse occurred while retrieving the configurations.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -77,7 +77,7 @@ public class ConfigurationServiceImpl implements ConfigurationManagementService
return Response.status(Response.Status.CREATED) return Response.status(Response.Status.CREATED)
.entity("Configuration has successfully been updated").build(); .entity("Configuration has successfully been updated").build();
} catch (ConfigurationManagementException e) { } catch (ConfigurationManagementException e) {
String msg = "Error occurred while updating the configuration."; String msg = "ErrorResponse occurred while updating the configuration.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }

@ -70,7 +70,7 @@ public class DashboardImpl implements Dashboard {
// "parameter : " + NON_COMPLIANT_FEATURE_CODE; // "parameter : " + NON_COMPLIANT_FEATURE_CODE;
// private static final String REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED = "Missing required query " + // private static final String REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED = "Missing required query " +
// "parameter : " + PAGINATION_ENABLED; // "parameter : " + PAGINATION_ENABLED;
// private static final String ERROR_IN_RETRIEVING_REQUESTED_DATA = "Error in retrieving requested data."; // private static final String ERROR_IN_RETRIEVING_REQUESTED_DATA = "ErrorResponse in retrieving requested data.";
// //
// @GET // @GET
// @Path("device-count-overview") // @Path("device-count-overview")

@ -35,22 +35,24 @@ import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManag
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService; import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException; import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
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.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
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 org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import javax.validation.constraints.NotNull;
import javax.ws.rs.*; import javax.ws.rs.*;
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.Date;
import java.util.List; import java.util.List;
@Path("/devices") @Path("/devices")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public class DeviceManagementServiceImpl implements DeviceManagementService{ public class DeviceManagementServiceImpl implements DeviceManagementService {
private static final Log log = LogFactory.getLog(DeviceManagementServiceImpl.class); private static final Log log = LogFactory.getLog(DeviceManagementServiceImpl.class);
@ -66,15 +68,33 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@QueryParam("limit") int limit) { @QueryParam("limit") int limit) {
try { try {
RequestValidationUtil.validateSelectionCriteria(type, user, roleName, ownership, status);
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
PaginationRequest request = new PaginationRequest(offset, limit); PaginationRequest request = new PaginationRequest(offset, limit);
PaginationResult result;
PaginationResult result = dms.getAllDevices(request); if (type != null) {
if (result == null || result.getData().size() == 0) { result = dms.getDevicesByType(request);
} else if (user != null) {
result = dms.getDevicesOfUser(request);
} else if (ownership != null) {
RequestValidationUtil.validateOwnershipType(ownership);
result = dms.getDevicesByOwnership(request);
} else if (status != null) {
RequestValidationUtil.validateStatus(status);
result = dms.getDevicesByStatus(request);
} else {
result = dms.getAllDevices(request);
}
if (result == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No device is currently enrolled " + return Response.status(Response.Status.NOT_FOUND).entity("No device is currently enrolled " +
"with the server").build(); "with the server").build();
} }
return Response.status(Response.Status.OK).entity(result.getData()).build(); DeviceList devices = new DeviceList();
devices.setList((List<Device>) result.getData());
devices.setCount(result.getRecordsTotal());
return Response.status(Response.Status.OK).entity(devices).build();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred while fetching all enrolled devices"; String msg = "Error occurred while fetching all enrolled devices";
log.error(msg, e); log.error(msg, e);
@ -84,11 +104,13 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
@GET @GET
@Path("{type}/{id}/info") @Path("{type}/{id}/info")
public Response getDeviceInfo(@PathParam("type") String type, @PathParam("id") String id, public Response getDeviceInfo(@PathParam("type") String type, @NotNull @PathParam("id") String id,
@HeaderParam("If-Modified-Since") String timestamp) { @HeaderParam("If-Modified-Since") String timestamp) {
DeviceInformationManager informationManager; DeviceInformationManager informationManager;
DeviceInfo deviceInfo; DeviceInfo deviceInfo;
try { try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(id); deviceIdentifier.setId(id);
deviceIdentifier.setType(type); deviceIdentifier.setType(type);
@ -101,30 +123,31 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
} }
return Response.status(Response.Status.OK).entity(deviceInfo).build(); return Response.status(Response.Status.OK).entity(deviceInfo).build();
} }
//
@POST // @POST
@Override // @Override
public Response getDevicesInfo( // public Response getDevicesInfo(
List<DeviceIdentifier> deviceIds, // List<DeviceIdentifier> deviceIds,
@HeaderParam("If-Modified-Since") String timestamp) { // @HeaderParam("If-Modified-Since") String timestamp) {
DeviceInformationManager informationManager; // DeviceInformationManager informationManager;
List<DeviceInfo> deviceInfo; // List<DeviceInfo> deviceInfo;
try { // try {
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService(); // informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceInfo = informationManager.getDevicesInfo(deviceIds); // deviceInfo = informationManager.getDevicesInfo(deviceIds);
if (deviceInfo == null) { // if (deviceInfo == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No device information is available for the " + // return Response.status(Response.Status.NOT_FOUND).entity("No device information is available for the " +
"device list submitted").build(); // "device list submitted").build();
} // }
} catch (DeviceDetailsMgtException e) { // } catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device information."; // String msg = "Error occurred while getting the device information.";
log.error(msg, e); // log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); // return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} // }
return Response.status(Response.Status.OK).entity(deviceInfo).build(); // return Response.status(Response.Status.OK).entity(deviceInfo).build();
} // }
@GET @GET
@Path("/{type}/{id}")
@Override @Override
public Response getDevice( public Response getDevice(
@PathParam("type") String type, @PathParam("type") String type,
@ -132,6 +155,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
@HeaderParam("If-Modified-Since") String ifModifiedSince) { @HeaderParam("If-Modified-Since") String ifModifiedSince) {
Device device; Device device;
try { try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
device = dms.getDevice(new DeviceIdentifier(id, type)); device = dms.getDevice(new DeviceIdentifier(id, type));
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
@ -156,6 +181,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
DeviceInformationManager informationManager; DeviceInformationManager informationManager;
DeviceLocation deviceLocation; DeviceLocation deviceLocation;
try { try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService(); informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceLocation = informationManager.getDeviceLocation(new DeviceIdentifier(id, type)); deviceLocation = informationManager.getDeviceLocation(new DeviceIdentifier(id, type));
if (deviceLocation == null || deviceLocation.getLatitude() == null || if (deviceLocation == null || deviceLocation.getLatitude() == null ||
@ -199,6 +226,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
List<Feature> features; List<Feature> features;
DeviceManagementProviderService dms; DeviceManagementProviderService dms;
try { try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
dms = DeviceMgtAPIUtils.getDeviceManagementService(); dms = DeviceMgtAPIUtils.getDeviceManagementService();
features = dms.getFeatureManager(type).getFeatures(); features = dms.getFeatureManager(type).getFeatures();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
@ -207,9 +236,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
if (features == null || features.size() == 0) { if (features == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No feature is currently associated " + return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " +
"with the '" + type + "' device, which carries the id '" + id + "'").build(); "the provided type and id").build();
} }
return Response.status(Response.Status.OK).entity(features).build(); return Response.status(Response.Status.OK).entity(features).build();
} }
@ -217,7 +246,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
@POST @POST
@Path("/search-devices") @Path("/search-devices")
@Override @Override
public Response searchDevices(@QueryParam("offset") int offset, @QueryParam("limit") int limit, SearchContext searchContext) { public Response searchDevices(@QueryParam("offset") int offset,
@QueryParam("limit") int limit, SearchContext searchContext) {
SearchManagerService searchManagerService; SearchManagerService searchManagerService;
List<DeviceWrapper> devices; List<DeviceWrapper> devices;
try { try {
@ -228,9 +258,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
if (devices == null || devices.size() == 0) { if (devices == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No device can be retrieved upon the provided " + return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " +
"selection criteria").build(); "the provided type and id").build();
} }
return Response.status(Response.Status.OK).entity(devices).build(); return Response.status(Response.Status.OK).entity(devices).build();
} }
@ -247,11 +277,13 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
List<Application> applications; List<Application> applications;
ApplicationManagementProviderService amc; ApplicationManagementProviderService amc;
try { try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
amc = DeviceMgtAPIUtils.getAppManagementService(); amc = DeviceMgtAPIUtils.getAppManagementService();
applications = amc.getApplicationListForDevice(new DeviceIdentifier(id, type)); applications = amc.getApplicationListForDevice(new DeviceIdentifier(id, type));
if (applications == null || applications.size() == 0) { if (applications == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No installed applications found on the " + return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon" +
"device searched").build(); "the provided type and id").build();
} }
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while fetching the apps of the '" + type + "' device, which carries " + String msg = "Error occurred while fetching the apps of the '" + type + "' device, which carries " +
@ -274,8 +306,14 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
List<? extends Operation> operations; List<? extends Operation> operations;
DeviceManagementProviderService dms; DeviceManagementProviderService dms;
try { try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
dms = DeviceMgtAPIUtils.getDeviceManagementService(); dms = DeviceMgtAPIUtils.getDeviceManagementService();
operations = dms.getOperations(new DeviceIdentifier(id, type)); operations = dms.getOperations(new DeviceIdentifier(id, type));
if (operations == null) {
Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " +
"the provided type and id");
}
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " + String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " +
"carries the id '" + id + "'"; "carries the id '" + id + "'";
@ -285,11 +323,15 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
return Response.status(Response.Status.OK).entity(operations).build(); return Response.status(Response.Status.OK).entity(operations).build();
} }
@GET
@Path("/{type}/{id}/effective-policy")
@Override @Override
public Response getEffectivePolicyOfDevice(@QueryParam("type") String type, public Response getEffectivePolicyOfDevice(@PathParam("type") String type,
@QueryParam("id") String id, @PathParam("id") String id,
@HeaderParam("If-Modified-Since") String ifModifiedSince) { @HeaderParam("If-Modified-Since") String ifModifiedSince) {
try { try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
Policy policy = policyManagementService.getAppliedPolicyToDevice(new DeviceIdentifier(id, type)); Policy policy = policyManagementService.getAppliedPolicyToDevice(new DeviceIdentifier(id, type));
if (policy == null) { if (policy == null) {

@ -64,7 +64,7 @@ public class GroupManagementServiceImpl implements GroupManagementService {
// } // }
// return Response.status(Response.Status.OK).entity(groupWrappers).build(); // return Response.status(Response.Status.OK).entity(groupWrappers).build();
// } catch (GroupManagementException e) { // } catch (GroupManagementException e) {
// String error = "Error occurred while getting the groups related to users for policy."; // String error = "ErrorResponse occurred while getting the groups related to users for policy.";
// log.error(error, e); // log.error(error, e);
// return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); // return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
// } // }

@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification; import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.jaxrs.service.api.NotificationManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.NotificationManagementService;
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.ws.rs.*; import javax.ws.rs.*;
@ -44,16 +45,24 @@ public class NotificationManagementServiceImpl implements NotificationManagement
@HeaderParam("If-Modified-Since") String ifModifiedSince, @HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset, @QueryParam("limit") int limit) { @QueryParam("offset") int offset, @QueryParam("limit") int limit) {
String msg; String msg;
List<Notification> notifications;
try { try {
List<Notification> notifications = if (status != null) {
DeviceMgtAPIUtils.getNotificationManagementService().getAllNotifications(); RequestValidationUtil.validateNotificationStatus(status);
notifications =
DeviceMgtAPIUtils.getNotificationManagementService().getNotificationsByStatus(
Notification.Status.valueOf(status));
} else {
notifications = DeviceMgtAPIUtils.getNotificationManagementService().getAllNotifications();
}
if (notifications == null || notifications.size() == 0) { if (notifications == null || notifications.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No notification is available to be " + return Response.status(Response.Status.NOT_FOUND).entity("No notification is available to be " +
"retrieved").build(); "retrieved").build();
} }
return Response.status(Response.Status.OK).entity(notifications).build(); return Response.status(Response.Status.OK).entity(notifications).build();
} catch (NotificationManagementException e) { } catch (NotificationManagementException e) {
msg = "Error occurred while retrieving notification info"; msg = "ErrorResponse occurred while retrieving notification info";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -64,11 +73,14 @@ public class NotificationManagementServiceImpl implements NotificationManagement
@Override @Override
public Response updateNotificationStatus(@PathParam("id") int id, String status) { public Response updateNotificationStatus(@PathParam("id") int id, String status) {
try { try {
RequestValidationUtil.validateNotificationId(id);
RequestValidationUtil.validateNotificationStatus(status);
DeviceMgtAPIUtils.getNotificationManagementService().updateNotificationStatus(id, DeviceMgtAPIUtils.getNotificationManagementService().updateNotificationStatus(id,
Notification.Status.valueOf(status)); Notification.Status.valueOf(status));
return Response.status(Response.Status.OK).entity("Notification status has successfully been updated").build(); return Response.status(Response.Status.OK).entity("Notification status has successfully been updated").build();
} catch (NotificationManagementException e) { } catch (NotificationManagementException e) {
String msg = "Error occurred while updating notification status"; String msg = "ErrorResponse occurred while updating notification status";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -78,10 +90,12 @@ public class NotificationManagementServiceImpl implements NotificationManagement
@Override @Override
public Response addNotification(Notification notification) { public Response addNotification(Notification notification) {
try { try {
RequestValidationUtil.validateNotification(notification);
DeviceMgtAPIUtils.getNotificationManagementService().addNotification(notification); DeviceMgtAPIUtils.getNotificationManagementService().addNotification(notification);
return Response.status(Response.Status.OK).entity("Notification has successfully been added").build(); return Response.status(Response.Status.OK).entity("Notification has successfully been added").build();
} catch (NotificationManagementException e) { } catch (NotificationManagementException e) {
String msg = "Error occurred while updating notification status."; String msg = "ErrorResponse occurred while updating notification status.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }

@ -67,7 +67,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
"not authorized to add policies").build(); "not authorized to add policies").build();
} }
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
String msg = "Error occurred while checking if the current user is authorized to add a policy"; String msg = "ErrorResponse occurred while checking if the current user is authorized to add a policy";
log.error(msg, e); log.error(msg, e);
return javax.ws.rs.core.Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return javax.ws.rs.core.Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -77,7 +77,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
pap.addPolicy(policy); pap.addPolicy(policy);
return Response.status(Response.Status.OK).entity("Policy has been added successfully").build(); return Response.status(Response.Status.OK).entity("Policy has been added successfully").build();
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
String msg = "Error occurred while adding policy"; String msg = "ErrorResponse occurred while adding policy";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -112,7 +112,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
return Response.status(Response.Status.NOT_FOUND).entity("No policies found.").build(); return Response.status(Response.Status.NOT_FOUND).entity("No policies found.").build();
} }
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
String msg = "Error occurred while retrieving all available policies"; String msg = "ErrorResponse occurred while retrieving all available policies";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -132,7 +132,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
return Response.status(Response.Status.NOT_FOUND).entity("Policy not found.").build(); return Response.status(Response.Status.NOT_FOUND).entity("Policy not found.").build();
} }
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
String msg = "Error occurred while retrieving policy corresponding to the id '" + id + "'"; String msg = "ErrorResponse occurred while retrieving policy corresponding to the id '" + id + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -150,7 +150,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
pap.updatePolicy(policy); pap.updatePolicy(policy);
return Response.status(Response.Status.OK).entity("Policy has successfully been updated").build(); return Response.status(Response.Status.OK).entity("Policy has successfully been updated").build();
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
String msg = "Error occurred while updating the policy"; String msg = "ErrorResponse occurred while updating the policy";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -170,7 +170,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
} }
} }
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
String msg = "Error occurred while removing policies"; String msg = "ErrorResponse occurred while removing policies";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -193,7 +193,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
pap.activatePolicy(i); pap.activatePolicy(i);
} }
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
String msg = "Error occurred while activating policies"; String msg = "ErrorResponse occurred while activating policies";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }

@ -60,7 +60,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
return Response.status(Response.Status.NOT_FOUND).entity("No roles found.").build(); return Response.status(Response.Status.NOT_FOUND).entity("No roles found.").build();
} }
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while retrieving roles from the underlying user stores"; String msg = "ErrorResponse occurred while retrieving roles from the underlying user stores";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -88,11 +88,11 @@ public class RoleManagementServiceImpl implements RoleManagementService {
} }
return Response.status(Response.Status.OK).entity(rolePermissions).build(); return Response.status(Response.Status.OK).entity(rolePermissions).build();
} catch (UserAdminException e) { } catch (UserAdminException e) {
String msg = "Error occurred while retrieving the permissions of role '" + roleName + "'"; String msg = "ErrorResponse occurred while retrieving the permissions of role '" + roleName + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while retrieving the underlying user realm attached to the " + String msg = "ErrorResponse occurred while retrieving the underlying user realm attached to the " +
"current logged in user"; "current logged in user";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
@ -150,7 +150,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
roleWrapper.setPermissions(permList.toArray(permListAr)); roleWrapper.setPermissions(permList.toArray(permListAr));
} }
} catch (UserStoreException | UserAdminException e) { } catch (UserStoreException | UserAdminException e) {
String msg = "Error occurred while retrieving the user role '" + roleName + "'"; String msg = "ErrorResponse occurred while retrieving the user role '" + roleName + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -186,7 +186,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
} }
userStoreManager.addRole(roleWrapper.getRoleName(), roleWrapper.getUsers(), permissions); userStoreManager.addRole(roleWrapper.getRoleName(), roleWrapper.getUsers(), permissions);
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while adding role '" + roleWrapper.getRoleName() + "'"; String msg = "ErrorResponse occurred while adding role '" + roleWrapper.getRoleName() + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -228,7 +228,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
} }
} }
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while updating role '" + roleName + "'"; String msg = "ErrorResponse occurred while updating role '" + roleName + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -249,7 +249,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
// Delete all authorizations for the current role before deleting // Delete all authorizations for the current role before deleting
authorizationManager.clearRoleAuthorization(roleName); authorizationManager.clearRoleAuthorization(roleName);
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while deleting the role '" + roleName + "'"; String msg = "ErrorResponse occurred while deleting the role '" + roleName + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -275,7 +275,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
userStoreManager.updateUserListOfRole(roleName, usersToDelete, usersToAdd); userStoreManager.updateUserListOfRole(roleName, usersToDelete, usersToAdd);
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while updating the users of the role '" + roleName + "'"; String msg = "ErrorResponse occurred while updating the users of the role '" + roleName + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }

@ -87,7 +87,7 @@ public class UserManagementServiceImpl implements UserManagementService {
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred while inviting user to enroll the device"; String msg = "ErrorResponse occurred while inviting user to enroll the device";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -185,7 +185,7 @@ public class UserManagementServiceImpl implements UserManagementService {
"User by username: " + username + " does not exist").build(); "User by username: " + username + " does not exist").build();
} }
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while retrieving information of the user '" + username + "'"; String msg = "ErrorResponse occurred while retrieving information of the user '" + username + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -348,7 +348,7 @@ public class UserManagementServiceImpl implements UserManagementService {
} }
return Response.status(Response.Status.OK).entity(userList).build(); return Response.status(Response.Status.OK).entity(userList).build();
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while retrieving the list of users"; String msg = "ErrorResponse occurred while retrieving the list of users";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -381,7 +381,7 @@ public class UserManagementServiceImpl implements UserManagementService {
} }
return Response.status(Response.Status.OK).entity(userList).build(); return Response.status(Response.Status.OK).entity(userList).build();
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while retrieving the list of users using the filter : " + filter; String msg = "ErrorResponse occurred while retrieving the list of users using the filter : " + filter;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }

@ -70,7 +70,7 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
return Response.status(Response.Status.ACCEPTED).entity("Application installation request has been sent " + return Response.status(Response.Status.ACCEPTED).entity("Application installation request has been sent " +
"to the device").build(); "to the device").build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while processing application installation request"; String msg = "ErrorResponse occurred while processing application installation request";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (UnknownApplicationTypeException e) { } catch (UnknownApplicationTypeException e) {
@ -103,7 +103,7 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
return Response.status(Response.Status.ACCEPTED).entity("Application un-installation request has " + return Response.status(Response.Status.ACCEPTED).entity("Application un-installation request has " +
"been sent to the device").build(); "been sent to the device").build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occurred while processing application un-installation request"; String msg = "ErrorResponse occurred while processing application un-installation request";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (UnknownApplicationTypeException e) { } catch (UnknownApplicationTypeException e) {

@ -54,7 +54,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
} }
return Response.status(Response.Status.OK).entity(devices).build(); return Response.status(Response.Status.OK).entity(devices).build();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred while fetching the devices that carry the name '" + name + "'"; String msg = "ErrorResponse occurred while fetching the devices that carry the name '" + name + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }

@ -53,7 +53,7 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ
return Response.status(Response.Status.NOT_FOUND).build(); return Response.status(Response.Status.NOT_FOUND).build();
} }
} catch (GroupManagementException e) { } catch (GroupManagementException e) {
String msg = "Error occurred while retrieving the groups of user '" + username + "'"; String msg = "ErrorResponse occurred while retrieving the groups of user '" + username + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }

@ -0,0 +1,35 @@
/*
* 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.util;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.core.Response;
import java.io.Serializable;
public class InputValidationException extends BadRequestException implements Serializable {
private static final long serialVersionUID = 147843579458906890L;
public InputValidationException(ErrorResponse error) {
super(Response.status(Response.Status.BAD_REQUEST).entity(error).build());
}
}

@ -0,0 +1,171 @@
/*
* 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.util;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import java.util.ArrayList;
import java.util.List;
public class RequestValidationUtil {
/**
* Checks if multiple criteria are specified in a conditional request.
*
* @param type Device type upon which the selection is done
* @param user Device user upon whom the selection is done
* @param roleName Role name upon which the selection is done
* @param ownership Ownership type upon which the selection is done
* @param status Enrollment status upon which the selection is done
*/
public static void validateSelectionCriteria(final String type, final String user, final String roleName,
final String ownership, final String status) {
List<String> inputs = new ArrayList<String>() {{
add(type);
add(user);
add(roleName);
add(ownership);
add(status);
}};
// boolean hasOneSelection = false;
// for (String i : inputs) {
// if (i == null) {
// continue;
// }
// hasOneSelection = !hasOneSelection;
// if (!hasOneSelection) {
// break;
// }
// }
int count = 0;
for (String i : inputs) {
if (i == null) {
continue;
}
count++;
if (count > 1) {
break;
}
}
if (count > 1) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("The incoming request has " +
"more than one selection criteria defined through query parameters").build());
}
}
public static void validateDeviceIdentifier(String type, String id) {
boolean isErroneous = false;
ErrorResponse.ErrorResponseBuilder error = new ErrorResponse.ErrorResponseBuilder();
if (id == null) {
isErroneous = true;
error.addErrorItem(null, "Device identifier cannot be null");
}
if (type == null) {
isErroneous = true;
error.addErrorItem(null, "Device type cannot be null");
}
if (isErroneous) {
throw new InputValidationException(error.setCode(400l).setMessage("Invalid device identifier").build());
}
}
public static void validateStatus(String status) {
if (status == null) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
"Enrollment status type cannot be null").build());
}
switch (status) {
case "ACTIVE":
case "INACTIVE":
case "UNCLAIMED":
case "UNREACHABLE":
case "SUSPENDED":
case "DISENROLLMENT_REQUESTED":
case "REMOVED":
case "BLOCKED":
case "CREATED":
return;
default:
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Invalid enrollment status type " +
"received. Valid status types are ACTIVE | INACTIVE | " +
"UNCLAIMED | UNREACHABLE | SUSPENDED | DISENROLLMENT_REQUESTED | REMOVED | " +
"BLOCKED | CREATED").build());
}
}
public static void validateOwnershipType(String ownership) {
if (ownership == null) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
"Ownership type cannot be null").build());
}
switch (ownership) {
case "BYOD":
case "COPE":
return;
default:
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
"Invalid ownership type received. " +
"Valid ownership types are BYOD | COPE").build());
}
}
public static void validateNotificationStatus(String status) {
if (status == null) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
"Notification status type cannot be null").build());
}
switch (status) {
case "NEW":
case "CHECKED":
return;
default:
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Invalid notification status type " +
"received. Valid status types are NEW | CHECKED").build());
}
}
public static void validateNotificationId(int id) {
if (id <= 0) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Invalid notification id. " +
"Only positive integers are accepted as valid notification Ids").build());
}
}
public static void validateNotification(Notification notification) {
if (notification == null) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Notification content " +
"cannot be null").build());
}
}
}

@ -74,7 +74,7 @@ public class CredentialManagementResponseBuilder {
return Response.status(Response.Status.CREATED).entity("UserImpl password by username: " + return Response.status(Response.Status.CREATED).entity("UserImpl password by username: " +
credentials.getUsername() + " was successfully changed.").build(); credentials.getUsername() + " was successfully changed.").build();
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while updating the credentials of user '" + credentials.getUsername() + "'"; String msg = "ErrorResponse occurred while updating the credentials of user '" + credentials.getUsername() + "'";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {

@ -34,6 +34,8 @@ import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManag
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService; import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException;
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException; import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService; import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
@ -60,7 +62,16 @@ public class DeviceMgtAPIUtils {
if (configEntryList != null && !configEntryList.isEmpty()) { if (configEntryList != null && !configEntryList.isEmpty()) {
for (ConfigurationEntry entry : configEntryList) { for (ConfigurationEntry entry : configEntryList) {
if (NOTIFIER_FREQUENCY.equals(entry.getName())) { if (NOTIFIER_FREQUENCY.equals(entry.getName())) {
return Integer.parseInt((String) entry.getValue()); if (entry.getValue() == null) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
"Notifier frequency cannot be null. Please specify a valid non-negative " +
"integer value to successfully set up notification frequency. " +
"Should the service be stopped, use '0' as the notification " +
"frequency.").build()
);
}
return Integer.parseInt(entry.getValue().toString());
} }
} }
} }
@ -104,7 +115,7 @@ public class DeviceMgtAPIUtils {
} }
return groupManagementProviderService; return groupManagementProviderService;
} }
public static UserStoreManager getUserStoreManager() throws UserStoreException { public static UserStoreManager getUserStoreManager() throws UserStoreException {
RealmService realmService; RealmService realmService;
UserStoreManager userStoreManager; UserStoreManager userStoreManager;
@ -150,13 +161,6 @@ public class DeviceMgtAPIUtils {
return authorizationManager; return authorizationManager;
} }
public static DeviceIdentifier instantiateDeviceIdentifier(String deviceType, String deviceId) {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setType(deviceType);
deviceIdentifier.setId(deviceId);
return deviceIdentifier;
}
public static ApplicationManagementProviderService getAppManagementService() { public static ApplicationManagementProviderService getAppManagementService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
@ -182,7 +186,7 @@ public class DeviceMgtAPIUtils {
} }
public static PlatformConfigurationManagementService getPlatformConfigurationManagementService() { public static PlatformConfigurationManagementService getPlatformConfigurationManagementService() {
CarbonContext ctx = CarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
PlatformConfigurationManagementService tenantConfigurationManagementService = PlatformConfigurationManagementService tenantConfigurationManagementService =
(PlatformConfigurationManagementService) ctx.getOSGiService( (PlatformConfigurationManagementService) ctx.getOSGiService(
PlatformConfigurationManagementService.class, null); PlatformConfigurationManagementService.class, null);
@ -202,29 +206,6 @@ public class DeviceMgtAPIUtils {
} }
return notificationManagementService; return notificationManagementService;
} }
public static CertificateManagementService getCertificateManagementService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
CertificateManagementService certificateManagementService = (CertificateManagementService)
ctx.getOSGiService(CertificateManagementService.class, null);
if (certificateManagementService == null) {
throw new IllegalStateException("CertificateImpl Management service is not initialized.");
}
return certificateManagementService;
}
public static MediaType getResponseMediaType(String acceptHeader) {
MediaType responseMediaType;
if (acceptHeader == null || MediaType.WILDCARD.equals(acceptHeader)) {
responseMediaType = DEFAULT_CONTENT_TYPE;
} else {
responseMediaType = MediaType.valueOf(acceptHeader);
}
return responseMediaType;
}
public static DeviceInformationManager getDeviceInformationManagerService() { public static DeviceInformationManager getDeviceInformationManagerService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();

@ -43,7 +43,7 @@
</jaxrs:serviceBeans> </jaxrs:serviceBeans>
<jaxrs:providers> <jaxrs:providers>
<ref bean="jsonProvider"/> <ref bean="jsonProvider"/>
<ref bean="errorHandler"/> <!--<ref bean="errorHandler"/>-->
<ref bean="swaggerWriter"/> <ref bean="swaggerWriter"/>
</jaxrs:providers> </jaxrs:providers>
</jaxrs:server> </jaxrs:server>
@ -54,8 +54,8 @@
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig"> <bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
<property name="resourcePackage" value="org.wso2.carbon.device.mgt.jaxrs"/> <property name="resourcePackage" value="org.wso2.carbon.device.mgt.jaxrs"/>
<property name="version" value="1.0"/> <property name="version" value="1.0"/>
<property name="host" value="device-mgt.wso2.com"/> <property name="host" value="localhost:9443"/>
<property name="basePath" value="/api/device-mgt/admin/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@wso2.org"/>
<property name="license" value="Apache 2.0"/> <property name="license" value="Apache 2.0"/>
@ -77,6 +77,6 @@
<bean id="userManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.UserManagementAdminServiceImpl"/> <bean id="userManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.UserManagementAdminServiceImpl"/>
<bean id="dashboardServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DashboardImpl"/> <bean id="dashboardServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DashboardImpl"/>
<bean id="jsonProvider" class="org.wso2.carbon.device.mgt.jaxrs.common.GsonMessageBodyHandler"/> <bean id="jsonProvider" class="org.wso2.carbon.device.mgt.jaxrs.common.GsonMessageBodyHandler"/>
<bean id="errorHandler" class="org.wso2.carbon.device.mgt.jaxrs.common.ErrorHandler"/> <!--<bean id="errorHandler" class="org.wso2.carbon.device.mgt.jaxrs.common.ErrorHandler"/>-->
</beans> </beans>

@ -49,6 +49,7 @@
</Export-Package> </Export-Package>
<Import-Package> <Import-Package>
javax.xml.bind.annotation, javax.xml.bind.annotation,
com.fasterxml.jackson.annotation,
io.swagger.annotations.*;resolution:=optional io.swagger.annotations.*;resolution:=optional
</Import-Package> </Import-Package>
</instructions> </instructions>
@ -63,6 +64,10 @@
<artifactId>swagger-annotations</artifactId> <artifactId>swagger-annotations</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -154,7 +154,7 @@ public class Device implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "Device[" + return "device [" +
"name=" + name + ";" + "name=" + name + ";" +
"type=" + type + ";" + "type=" + type + ";" +
"description=" + description + ";" + "description=" + description + ";" +

@ -17,6 +17,7 @@
*/ */
package org.wso2.carbon.device.mgt.common; package org.wso2.carbon.device.mgt.common;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -27,8 +28,11 @@ import java.io.Serializable;
"uniquely.") "uniquely.")
public class DeviceIdentifier implements Serializable{ public class DeviceIdentifier implements Serializable{
@JsonProperty(value = "id", required = true)
@ApiModelProperty(name = "id", value = "Identity of the device.", required = true) @ApiModelProperty(name = "id", value = "Identity of the device.", required = true)
private String id; private String id;
@JsonProperty(value = "type", required = true)
@ApiModelProperty(name = "type", value = "Type of the device.", required = true) @ApiModelProperty(name = "type", value = "Type of the device.", required = true)
private String type; private String type;
@ -56,7 +60,7 @@ public class DeviceIdentifier implements Serializable{
@Override @Override
public String toString() { public String toString() {
return "DeviceIdentifier{" + return "deviceId {" +
"id='" + id + '\'' + "id='" + id + '\'' +
", type='" + type + '\'' + ", type='" + type + '\'' +
'}'; '}';

@ -21,29 +21,16 @@ public class DeviceManagementException extends Exception {
private static final long serialVersionUID = -3151279311929070297L; private static final long serialVersionUID = -3151279311929070297L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public DeviceManagementException(String msg, Exception nestedEx) { public DeviceManagementException(String msg, Exception nestedEx) {
super(msg, nestedEx); super(msg, nestedEx);
setErrorMessage(msg);
} }
public DeviceManagementException(String message, Throwable cause) { public DeviceManagementException(String message, Throwable cause) {
super(message, cause); super(message, cause);
setErrorMessage(message);
} }
public DeviceManagementException(String msg) { public DeviceManagementException(String msg) {
super(msg); super(msg);
setErrorMessage(msg);
} }
public DeviceManagementException() { public DeviceManagementException() {

@ -23,29 +23,16 @@ public class FeatureManagementException extends Exception {
private static final long serialVersionUID = 4527364660451105710L; private static final long serialVersionUID = 4527364660451105710L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public FeatureManagementException(String msg, Exception nestedEx) { public FeatureManagementException(String msg, Exception nestedEx) {
super(msg, nestedEx); super(msg, nestedEx);
setErrorMessage(msg);
} }
public FeatureManagementException(String message, Throwable cause) { public FeatureManagementException(String message, Throwable cause) {
super(message, cause); super(message, cause);
setErrorMessage(message);
} }
public FeatureManagementException(String msg) { public FeatureManagementException(String msg) {
super(msg); super(msg);
setErrorMessage(msg);
} }
public FeatureManagementException() { public FeatureManagementException() {

@ -22,29 +22,16 @@ public class IllegalTransactionStateException extends RuntimeException {
private static final long serialVersionUID = -3151279331929070297L; private static final long serialVersionUID = -3151279331929070297L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public IllegalTransactionStateException(String msg, Exception nestedEx) { public IllegalTransactionStateException(String msg, Exception nestedEx) {
super(msg, nestedEx); super(msg, nestedEx);
setErrorMessage(msg);
} }
public IllegalTransactionStateException(String message, Throwable cause) { public IllegalTransactionStateException(String message, Throwable cause) {
super(message, cause); super(message, cause);
setErrorMessage(message);
} }
public IllegalTransactionStateException(String msg) { public IllegalTransactionStateException(String msg) {
super(msg); super(msg);
setErrorMessage(msg);
} }
public IllegalTransactionStateException() { public IllegalTransactionStateException() {

@ -22,29 +22,16 @@ public class TransactionManagementException extends Exception {
private static final long serialVersionUID = -3151279321929070297L; private static final long serialVersionUID = -3151279321929070297L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public TransactionManagementException(String msg, Exception nestedEx) { public TransactionManagementException(String msg, Exception nestedEx) {
super(msg, nestedEx); super(msg, nestedEx);
setErrorMessage(msg);
} }
public TransactionManagementException(String message, Throwable cause) { public TransactionManagementException(String message, Throwable cause) {
super(message, cause); super(message, cause);
setErrorMessage(message);
} }
public TransactionManagementException(String msg) { public TransactionManagementException(String msg) {
super(msg); super(msg);
setErrorMessage(msg);
} }
public TransactionManagementException() { public TransactionManagementException() {

@ -25,29 +25,16 @@ public class UnsupportedDatabaseEngineException extends RuntimeException {
private static final long serialVersionUID = -3151279311929070297L; private static final long serialVersionUID = -3151279311929070297L;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public UnsupportedDatabaseEngineException(String msg, Exception nestedEx) { public UnsupportedDatabaseEngineException(String msg, Exception nestedEx) {
super(msg, nestedEx); super(msg, nestedEx);
setErrorMessage(msg);
} }
public UnsupportedDatabaseEngineException(String message, Throwable cause) { public UnsupportedDatabaseEngineException(String message, Throwable cause) {
super(message, cause); super(message, cause);
setErrorMessage(message);
} }
public UnsupportedDatabaseEngineException(String msg) { public UnsupportedDatabaseEngineException(String msg) {
super(msg); super(msg);
setErrorMessage(msg);
} }
public UnsupportedDatabaseEngineException() { public UnsupportedDatabaseEngineException() {

@ -38,6 +38,8 @@ import java.util.List;
description = "This class carries all information related to a Tenant configuration") description = "This class carries all information related to a Tenant configuration")
public class PlatformConfiguration implements Serializable { public class PlatformConfiguration implements Serializable {
public static final int INVALID_NOTIFIER_FREQUENCY = -1;
@XmlElement(name = "type") @XmlElement(name = "type")
@ApiModelProperty(name = "type", value = "type of device", required = true) @ApiModelProperty(name = "type", value = "type of device", required = true)
private String type; private String type;

@ -18,6 +18,7 @@
package org.wso2.carbon.device.mgt.common.notification.mgt; package org.wso2.carbon.device.mgt.common.notification.mgt;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
@ -34,19 +35,28 @@ public class Notification {
} }
public enum Type { public enum Type {
ALERT, ALERT
} }
@ApiModelProperty(name = "notificationId", value = "Defines the notification ID.", required = true) @JsonProperty(value = "notificationId", required = false)
@ApiModelProperty(name = "notificationId", value = "Defines the notification ID.", required = false)
private int notificationId; private int notificationId;
@JsonProperty(value = "deviceIdentifier", required = true)
@ApiModelProperty(name = "deviceIdentifier", value = "Defines the device identification properties.", @ApiModelProperty(name = "deviceIdentifier", value = "Defines the device identification properties.",
required = true) required = true)
private DeviceIdentifier deviceIdentifier; private DeviceIdentifier deviceIdentifier;
@JsonProperty(value = "description", required = false)
@ApiModelProperty(name = "description", value = "Provides the message you want to send to the user.", @ApiModelProperty(name = "description", value = "Provides the message you want to send to the user.",
required = true) required = true)
private String description; private String description;
@JsonProperty(value = "operationId", required = true)
@ApiModelProperty(name = "operationId", value = "Provides the operationID.", required = true) @ApiModelProperty(name = "operationId", value = "Provides the operationID.", required = true)
private int operationId; private int operationId;
@JsonProperty(value = "status", required = true)
@ApiModelProperty(name = "status", value = "Provides the status of the message." + @ApiModelProperty(name = "status", value = "Provides the status of the message." +
"The following values can be assigned for the status.\n" + "The following values can be assigned for the status.\n" +
"NEW: The message is in the unread state.\n" + "NEW: The message is in the unread state.\n" +
@ -95,7 +105,7 @@ public class Notification {
@Override @Override
public String toString() { public String toString() {
return "Notification{" + return "notification {" +
"notificationId='" + notificationId + '\'' + "notificationId='" + notificationId + '\'' +
", deviceId=" + deviceIdentifier.getId() + ", deviceId=" + deviceIdentifier.getId() +
", deviceType=" + deviceIdentifier.getType() + ", deviceType=" + deviceIdentifier.getType() +

@ -17,10 +17,7 @@
*/ */
package org.wso2.carbon.device.mgt.common.operation.mgt; package org.wso2.carbon.device.mgt.common.operation.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import java.util.List; import java.util.List;

@ -25,7 +25,7 @@ import java.util.List;
public interface ApplicationManagementProviderService extends ApplicationManager{ public interface ApplicationManagementProviderService extends ApplicationManager{
void updateApplicationListInstalledInDevice(DeviceIdentifier deviceIdentifier, void updateApplicationListInstalledInDevice(DeviceIdentifier deviceIdentifier,
List<Application> applications) throws ApplicationManagementException; List<Application> applications) throws ApplicationManagementException;
List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier) List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier)
throws ApplicationManagementException; throws ApplicationManagementException;

@ -24,10 +24,7 @@ import org.apache.axis2.context.ConfigurationContextFactory;
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.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
@ -140,10 +137,9 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
if (deviceIdentifierList.size() > 0) { if (deviceIdentifierList.size() > 0) {
type = deviceIdentifierList.get(0).getType(); type = deviceIdentifierList.get(0).getType();
} }
Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.addOperation(type, operation, deviceIdentifierList);
return activity; return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.addOperation(type, operation, deviceIdentifierList);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new ApplicationManagementException("Error in get devices for user: " + userName + throw new ApplicationManagementException("Error in get devices for user: " + userName +
" in app installation", e); " in app installation", e);
@ -181,9 +177,8 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
if (deviceIdentifierList.size() > 0) { if (deviceIdentifierList.size() > 0) {
type = deviceIdentifierList.get(0).getType(); type = deviceIdentifierList.get(0).getType();
} }
Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(type, operation, return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(type, operation,
deviceIdentifierList); deviceIdentifierList);
return activity;
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new ApplicationManagementException("Error in get devices for user role " + userRole + throw new ApplicationManagementException("Error in get devices for user role " + userRole +
" in app installation", e); " in app installation", e);
@ -196,7 +191,8 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
@Override @Override
public void updateApplicationListInstalledInDevice( public void updateApplicationListInstalledInDevice(
DeviceIdentifier deviceIdentifier, List<Application> applications) throws ApplicationManagementException { DeviceIdentifier deviceIdentifier,
List<Application> applications) throws ApplicationManagementException {
List<Application> installedAppList = getApplicationListForDevice(deviceIdentifier); List<Application> installedAppList = getApplicationListForDevice(deviceIdentifier);
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();

@ -19,17 +19,12 @@
package org.wso2.carbon.device.mgt.core.device.details.mgt.impl; package org.wso2.carbon.device.mgt.core.device.details.mgt.impl;
import org.apache.commons.logging.Log; import org.wso2.carbon.device.mgt.common.*;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO; import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO;
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException; import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
@ -42,8 +37,6 @@ import java.util.Map;
public class DeviceInformationManagerImpl implements DeviceInformationManager { public class DeviceInformationManagerImpl implements DeviceInformationManager {
private static Log log = LogFactory.getLog(DeviceInformationManagerImpl.class);
private DeviceDetailsDAO deviceDetailsDAO; private DeviceDetailsDAO deviceDetailsDAO;
public DeviceInformationManagerImpl() { public DeviceInformationManagerImpl() {
@ -79,7 +72,8 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
} }
@Override @Override
public DeviceInfo getDeviceInfo(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException { public DeviceInfo getDeviceInfo(
DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException {
try { try {
Device device = DeviceManagementDataHolder.getInstance(). Device device = DeviceManagementDataHolder.getInstance().
@ -103,7 +97,6 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
@Override @Override
public List<DeviceInfo> getDevicesInfo(List<DeviceIdentifier> deviceIdentifiers) throws DeviceDetailsMgtException { public List<DeviceInfo> getDevicesInfo(List<DeviceIdentifier> deviceIdentifiers) throws DeviceDetailsMgtException {
List<DeviceInfo> deviceInfos = new ArrayList<>(); List<DeviceInfo> deviceInfos = new ArrayList<>();
Map<String, DeviceIdentifier> identifierMap = new HashMap<>(); Map<String, DeviceIdentifier> identifierMap = new HashMap<>();
@ -116,7 +109,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
getDeviceManagementProvider().getAllDevices(); getDeviceManagementProvider().getAllDevices();
for (Device device : devices) { for (Device device : devices) {
if (identifierMap.containsKey(device.getDeviceIdentifier()) && if (identifierMap.containsKey(device.getDeviceIdentifier()) &&
device.getType().equals(identifierMap.get(device.getDeviceIdentifier()))) { device.getType().equals(identifierMap.get(device.getDeviceIdentifier()).getType())) {
deviceIds.add(device.getId()); deviceIds.add(device.getId());
} }
} }

@ -185,7 +185,8 @@ public class OperationManagerImpl implements OperationManager {
} }
@Override @Override
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException { public List<? extends Operation> getOperations(
DeviceIdentifier deviceId) throws OperationManagementException {
int enrolmentId; int enrolmentId;
List<Operation> operations = new ArrayList<>(); List<Operation> operations = new ArrayList<>();
try { try {
@ -200,13 +201,10 @@ public class OperationManagerImpl implements OperationManager {
} finally { } finally {
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
OperationManagementDAOFactory.openConnection();
if (enrolmentId < 0) { if (enrolmentId < 0) {
throw new OperationManagementException("Device not found for given device " + return null;
"Identifier:" + deviceId.getId() + " and given type" +
deviceId.getType());
} }
OperationManagementDAOFactory.openConnection();
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList = List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
operationDAO.getOperationsForDevice(enrolmentId); operationDAO.getOperationsForDevice(enrolmentId);

@ -719,7 +719,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " + String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " +
@ -769,7 +769,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " + String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +

@ -18,10 +18,7 @@
*/ */
package org.wso2.carbon.device.mgt.core.push.notification.mgt; package org.wso2.carbon.device.mgt.core.push.notification.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
@ -58,7 +55,8 @@ public class PushNotificationBasedOperationManager implements OperationManager {
} }
@Override @Override
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException { public List<? extends Operation> getOperations(
DeviceIdentifier deviceId) throws OperationManagementException {
return this.operationManager.getOperations(deviceId); return this.operationManager.getOperations(deviceId);
} }

@ -17,13 +17,7 @@
*/ */
package org.wso2.carbon.device.mgt.core.service; package org.wso2.carbon.device.mgt.core.service;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;

@ -20,16 +20,7 @@ package org.wso2.carbon.device.mgt.core.service;
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.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
@ -823,7 +814,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException { public List<? extends Operation> getOperations(
DeviceIdentifier deviceId) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperations(deviceId); return DeviceManagementDataHolder.getInstance().getOperationManager().getOperations(deviceId);
} }

@ -67,7 +67,8 @@ public interface PolicyManagerService {
int getPolicyCount() throws PolicyManagementException; int getPolicyCount() throws PolicyManagementException;
Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; Policy getAppliedPolicyToDevice(
DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
List<ComplianceFeature> checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Object List<ComplianceFeature> checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Object
deviceResponse) throws PolicyComplianceException; deviceResponse) throws PolicyComplianceException;

@ -168,7 +168,8 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
} }
@Override @Override
public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { public Policy getAppliedPolicyToDevice(
DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
return policyManager.getAppliedPolicyToDevice(deviceIdentifier); return policyManager.getAppliedPolicyToDevice(deviceIdentifier);
} }
@ -184,10 +185,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
List<ComplianceFeature> complianceFeatures = List<ComplianceFeature> complianceFeatures =
monitoringManager.checkPolicyCompliance(deviceIdentifier, response); monitoringManager.checkPolicyCompliance(deviceIdentifier, response);
if (complianceFeatures == null || complianceFeatures.isEmpty()) { return !(complianceFeatures == null || complianceFeatures.isEmpty());
return false;
}
return true;
} }
@Override @Override

@ -22,7 +22,6 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;

@ -77,8 +77,9 @@ public class MonitoringManagerImpl implements MonitoringManager {
} }
@Override @Override
public List<ComplianceFeature> checkPolicyCompliance(DeviceIdentifier deviceIdentifier, public List<ComplianceFeature> checkPolicyCompliance(
Object deviceResponse) throws PolicyComplianceException { DeviceIdentifier deviceIdentifier,
Object deviceResponse) throws PolicyComplianceException {
List<ComplianceFeature> complianceFeatures = new ArrayList<>(); List<ComplianceFeature> complianceFeatures = new ArrayList<>();
try { try {

@ -977,7 +977,8 @@ public class PolicyManagerImpl implements PolicyManager {
} }
@Override @Override
public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { public Policy getAppliedPolicyToDevice(
DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
Policy policy; Policy policy;
try { try {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();

@ -117,7 +117,8 @@ public class PolicyManagementService implements PolicyManagerService {
} }
@Override @Override
public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { public Policy getAppliedPolicyToDevice(
DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
return policyManagerService.getAppliedPolicyToDevice(deviceIdentifier); return policyManagerService.getAppliedPolicyToDevice(deviceIdentifier);
} }

@ -199,7 +199,7 @@ public class PolicyManagerUtil {
public static int getMonitoringFequency() { public static int getMonitoringFequency() {
PlatformConfigurationManagementService configMgtService = new TenantConfigurationManagementServiceImpl(); PlatformConfigurationManagementService configMgtService = new TenantConfigurationManagementServiceImpl();
PlatformConfiguration tenantConfiguration = null; PlatformConfiguration tenantConfiguration;
int monitoringFrequency = 0; int monitoringFrequency = 0;
try { try {
tenantConfiguration = configMgtService.getConfiguration(GENERAL_CONFIG_RESOURCE_PATH); tenantConfiguration = configMgtService.getConfiguration(GENERAL_CONFIG_RESOURCE_PATH);
@ -208,7 +208,10 @@ public class PolicyManagerUtil {
if (configuration != null && !configuration.isEmpty()) { if (configuration != null && !configuration.isEmpty()) {
for (ConfigurationEntry cEntry : configuration) { for (ConfigurationEntry cEntry : configuration) {
if (cEntry.getName().equalsIgnoreCase(MONITORING_FREQUENCY)) { if (cEntry.getName().equalsIgnoreCase(MONITORING_FREQUENCY)) {
monitoringFrequency = Integer.parseInt((String)cEntry.getValue()); if (cEntry.getValue() == null) {
throw new PolicyManagementException("Invalid ")
}
monitoringFrequency = Integer.parseInt(cEntry.getValue().toString());
} }
} }
} }

@ -19,6 +19,7 @@
package org.wso2.carbon.policy.mgt.core; package org.wso2.carbon.policy.mgt.core;
import junit.framework.Assert;
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.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
@ -87,7 +88,10 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
public void getDeviceAppliedPolicy() throws PolicyManagementException { public void getDeviceAppliedPolicy() throws PolicyManagementException {
PolicyManager manager = new PolicyManagerImpl(); PolicyManager manager = new PolicyManagerImpl();
Policy policy = manager.getAppliedPolicyToDevice(identifier); Policy policy = null;
policy = manager.getAppliedPolicyToDevice(identifier);
if (policy != null) { if (policy != null) {
@ -107,7 +111,10 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
log.debug("Compliance operations adding started."); log.debug("Compliance operations adding started.");
PolicyManager manager = new PolicyManagerImpl(); PolicyManager manager = new PolicyManagerImpl();
Policy policy = manager.getAppliedPolicyToDevice(identifier); Policy policy = null;
policy = manager.getAppliedPolicyToDevice(identifier);
OperationManager operationManager = new OperationManagerImpl(); OperationManager operationManager = new OperationManagerImpl();
DeviceManagementDataHolder.getInstance().setOperationManager(operationManager); DeviceManagementDataHolder.getInstance().setOperationManager(operationManager);
@ -123,7 +130,7 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
List<Device> devices = service.getAllDevices(ANDROID); List<Device> devices = service.getAllDevices(ANDROID);
// monitoringManager.addMonitoringOperation(devices); // monitoringManager.addMonitoringOperation(devices);
log.debug("Compliance operations adding done."); log.debug("Compliance operations adding done.");
@ -154,9 +161,11 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
monitoringServiceTest.notifyDevices(devices); monitoringServiceTest.notifyDevices(devices);
PolicyManager manager = new PolicyManagerImpl(); PolicyManager manager = new PolicyManagerImpl();
Policy policy = manager.getAppliedPolicyToDevice(identifier); Policy policy = null;
if(policy != null) { policy = manager.getAppliedPolicyToDevice(identifier);
if (policy != null) {
Object ob = new Object(); Object ob = new Object();
monitoringServiceTest.checkPolicyCompliance(identifier, policy, ob); monitoringServiceTest.checkPolicyCompliance(identifier, policy, ob);
@ -188,8 +197,10 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
log.debug(identifier.getId()); log.debug(identifier.getId());
log.debug(identifier.getType()); log.debug(identifier.getType());
monitoringManager.checkPolicyCompliance(identifier, ob); monitoringManager.checkPolicyCompliance(identifier, ob);
} }
} }

@ -120,6 +120,9 @@
<bundleDef> <bundleDef>
org.wso2.carbon.identity:org.wso2.carbon.identity.oauth.stub:${carbon.identity.version} org.wso2.carbon.identity:org.wso2.carbon.identity.oauth.stub:${carbon.identity.version}
</bundleDef> </bundleDef>
<bundleDef>
com.fasterxml.jackson.core:jackson-annotations:${jackson-annotations.version}
</bundleDef>
<!-- Below should be bundled with the email verification --> <!-- Below should be bundled with the email verification -->
</bundles> </bundles>
<importFeatures> <importFeatures>

@ -1501,6 +1501,12 @@
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp</artifactId> <artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp</artifactId>
<version>${carbon.device.mgt.version}</version> <version>${carbon.device.mgt.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson-annotations.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
@ -1866,6 +1872,8 @@
<javax.ws.rs.version>2.0.1</javax.ws.rs.version> <javax.ws.rs.version>2.0.1</javax.ws.rs.version>
<swagger.version>1.5.8</swagger.version> <swagger.version>1.5.8</swagger.version>
<servlet-api.version>2.5</servlet-api.version> <servlet-api.version>2.5</servlet-api.version>
<jackson-annotations.version>2.7.4</jackson-annotations.version>
</properties> </properties>
</project> </project>

Loading…
Cancel
Save