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>
<configuration>
<packagingExcludes>WEB-INF/lib/*cxf*.jar</packagingExcludes>
<warName>api#device-mgt#v1.1</warName>
<warName>api#device-mgt#v1.0</warName>
</configuration>
</plugin>
</plugins>
@ -72,7 +72,7 @@
<tasks>
<copy todir="${basedir}/../../../repository/deployment/server/webapps" overwrite="true">
<fileset dir="${basedir}/target">
<include name="api#device-mgt#v1.1.war" />
<include name="api#device-mgt#v1.0.war" />
</fileset>
</copy>
</tasks>
@ -243,6 +243,11 @@
<artifactId>org.wso2.carbon.device.mgt.analytics.dashboard</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</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 org.wso2.carbon.apimgt.annotations.api.API;
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 javax.ws.rs.*;
@ -77,7 +76,7 @@ public interface ActivityInfoProviderService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
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"})
Response getActivity(
@ -94,7 +93,6 @@ public interface ActivityInfoProviderService {
@GET
@Path("/")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
@ -102,7 +100,8 @@ public interface ActivityInfoProviderService {
responseContainer = "List",
value = "Retrieve details of a particular activity.",
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 = {
@ApiResponse(
code = 200,
@ -131,7 +130,7 @@ public interface ActivityInfoProviderService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
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"})
Response getActivities(
@ -139,12 +138,22 @@ public interface ActivityInfoProviderService {
name = "timestamp",
value = "Validates if the requested variant has not been modified since the time specified, this " +
"should be provided in unix format in seconds.",
required = true)
required = false)
@QueryParam("timestamp") String timestamp,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@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"),
@ApiResponse(
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",
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."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while modifying general platform configuration.")
})
@Permission(scope = "configuration-modify",

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

@ -76,7 +76,7 @@ public interface RoleManagementService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
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/admin/device-mgt/admin/roles/list",
@ -155,7 +155,7 @@ public interface RoleManagementService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the 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"})
Response getPermissionsOfRole(
@ -209,7 +209,7 @@ public interface RoleManagementService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the 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"})
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."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while adding a new role.")
})
@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."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating the role.")
})
@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."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while removing the role.")
})
@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."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating the user list of the role.")
})
@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."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while adding a new user.")
})
@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"),
@ApiResponse(
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"})
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."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating the user.")
})
@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."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while removing the user.")
})
@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"),
@ApiResponse(
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"})
Response getRolesOfUser(
@ -310,7 +310,7 @@ public interface UserManagementService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the 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"})
Response getUsers(
@ -376,7 +376,7 @@ public interface UserManagementService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the 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"})
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."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating credentials of the user.")
})
@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."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while bulk issuing application installation operations upon " +
"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."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while bulk issuing application un-installation operations upon " +
"a given set of devices.")
})

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

@ -69,7 +69,7 @@ public interface GroupManagementAdminService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the 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"})
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."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating credentials of the user.")
})
@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 javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@Path("/activities")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ActivityProviderServiceImpl implements ActivityInfoProviderService {
private static final Log log = LogFactory.getLog(ActivityProviderServiceImpl.class);
@ -47,7 +50,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
operation = dmService.getOperationByActivityId(id);
} 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);
Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -58,14 +61,16 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
@Override
public Response getActivities(
@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;
DeviceManagementProviderService dmService;
try {
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
activities = dmService.getActivitiesUpdatedAfter(Long.parseLong(timestamp));
} 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);
Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}

@ -60,7 +60,7 @@ public class ConfigurationServiceImpl implements ConfigurationManagementService
config.setConfiguration(configList);
return Response.status(Response.Status.OK).entity(config).build();
} catch (ConfigurationManagementException e) {
msg = "Error occurred while retrieving the configurations.";
msg = "ErrorResponse occurred while retrieving the configurations.";
log.error(msg, e);
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)
.entity("Configuration has successfully been updated").build();
} catch (ConfigurationManagementException e) {
String msg = "Error occurred while updating the configuration.";
String msg = "ErrorResponse occurred while updating the configuration.";
log.error(msg, e);
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;
// private static final String REQUIRED_QUERY_PARAM_VALUE_PAGINATION_ENABLED = "Missing required query " +
// "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
// @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.SearchMgtException;
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.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import javax.validation.constraints.NotNull;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Date;
import java.util.List;
@Path("/devices")
@Produces(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);
@ -66,15 +68,33 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
try {
RequestValidationUtil.validateSelectionCriteria(type, user, roleName, ownership, status);
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
PaginationRequest request = new PaginationRequest(offset, limit);
PaginationResult result;
PaginationResult result = dms.getAllDevices(request);
if (result == null || result.getData().size() == 0) {
if (type != null) {
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 " +
"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) {
String msg = "Error occurred while fetching all enrolled devices";
log.error(msg, e);
@ -84,11 +104,13 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
@GET
@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) {
DeviceInformationManager informationManager;
DeviceInfo deviceInfo;
try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(id);
deviceIdentifier.setType(type);
@ -101,30 +123,31 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
}
return Response.status(Response.Status.OK).entity(deviceInfo).build();
}
@POST
@Override
public Response getDevicesInfo(
List<DeviceIdentifier> deviceIds,
@HeaderParam("If-Modified-Since") String timestamp) {
DeviceInformationManager informationManager;
List<DeviceInfo> deviceInfo;
try {
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceInfo = informationManager.getDevicesInfo(deviceIds);
if (deviceInfo == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No device information is available for the " +
"device list submitted").build();
}
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device information.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(deviceInfo).build();
}
//
// @POST
// @Override
// public Response getDevicesInfo(
// List<DeviceIdentifier> deviceIds,
// @HeaderParam("If-Modified-Since") String timestamp) {
// DeviceInformationManager informationManager;
// List<DeviceInfo> deviceInfo;
// try {
// informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
// deviceInfo = informationManager.getDevicesInfo(deviceIds);
// if (deviceInfo == null) {
// return Response.status(Response.Status.NOT_FOUND).entity("No device information is available for the " +
// "device list submitted").build();
// }
// } catch (DeviceDetailsMgtException e) {
// String msg = "Error occurred while getting the device information.";
// log.error(msg, e);
// return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
// }
// return Response.status(Response.Status.OK).entity(deviceInfo).build();
// }
@GET
@Path("/{type}/{id}")
@Override
public Response getDevice(
@PathParam("type") String type,
@ -132,6 +155,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
Device device;
try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
device = dms.getDevice(new DeviceIdentifier(id, type));
} catch (DeviceManagementException e) {
@ -156,6 +181,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
DeviceInformationManager informationManager;
DeviceLocation deviceLocation;
try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceLocation = informationManager.getDeviceLocation(new DeviceIdentifier(id, type));
if (deviceLocation == null || deviceLocation.getLatitude() == null ||
@ -199,6 +226,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
List<Feature> features;
DeviceManagementProviderService dms;
try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
dms = DeviceMgtAPIUtils.getDeviceManagementService();
features = dms.getFeatureManager(type).getFeatures();
} catch (DeviceManagementException e) {
@ -207,9 +236,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
if (features == null || features.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No feature is currently associated " +
"with the '" + type + "' device, which carries the id '" + id + "'").build();
if (features == null) {
return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " +
"the provided type and id").build();
}
return Response.status(Response.Status.OK).entity(features).build();
}
@ -217,7 +246,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
@POST
@Path("/search-devices")
@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;
List<DeviceWrapper> devices;
try {
@ -228,9 +258,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
if (devices == null || devices.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No device can be retrieved upon the provided " +
"selection criteria").build();
if (devices == null) {
return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " +
"the provided type and id").build();
}
return Response.status(Response.Status.OK).entity(devices).build();
}
@ -247,11 +277,13 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
List<Application> applications;
ApplicationManagementProviderService amc;
try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
amc = DeviceMgtAPIUtils.getAppManagementService();
applications = amc.getApplicationListForDevice(new DeviceIdentifier(id, type));
if (applications == null || applications.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No installed applications found on the " +
"device searched").build();
if (applications == null) {
return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon" +
"the provided type and id").build();
}
} catch (ApplicationManagementException e) {
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;
DeviceManagementProviderService dms;
try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
dms = DeviceMgtAPIUtils.getDeviceManagementService();
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) {
String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " +
"carries the id '" + id + "'";
@ -285,11 +323,15 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
return Response.status(Response.Status.OK).entity(operations).build();
}
@GET
@Path("/{type}/{id}/effective-policy")
@Override
public Response getEffectivePolicyOfDevice(@QueryParam("type") String type,
@QueryParam("id") String id,
public Response getEffectivePolicyOfDevice(@PathParam("type") String type,
@PathParam("id") String id,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
try {
RequestValidationUtil.validateDeviceIdentifier(type, id);
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
Policy policy = policyManagementService.getAppliedPolicyToDevice(new DeviceIdentifier(id, type));
if (policy == null) {

@ -64,7 +64,7 @@ public class GroupManagementServiceImpl implements GroupManagementService {
// }
// return Response.status(Response.Status.OK).entity(groupWrappers).build();
// } 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);
// 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.NotificationManagementException;
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 javax.ws.rs.*;
@ -44,16 +45,24 @@ public class NotificationManagementServiceImpl implements NotificationManagement
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
String msg;
List<Notification> notifications;
try {
List<Notification> notifications =
DeviceMgtAPIUtils.getNotificationManagementService().getAllNotifications();
if (status != null) {
RequestValidationUtil.validateNotificationStatus(status);
notifications =
DeviceMgtAPIUtils.getNotificationManagementService().getNotificationsByStatus(
Notification.Status.valueOf(status));
} else {
notifications = DeviceMgtAPIUtils.getNotificationManagementService().getAllNotifications();
}
if (notifications == null || notifications.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No notification is available to be " +
"retrieved").build();
}
return Response.status(Response.Status.OK).entity(notifications).build();
} catch (NotificationManagementException e) {
msg = "Error occurred while retrieving notification info";
msg = "ErrorResponse occurred while retrieving notification info";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -64,11 +73,14 @@ public class NotificationManagementServiceImpl implements NotificationManagement
@Override
public Response updateNotificationStatus(@PathParam("id") int id, String status) {
try {
RequestValidationUtil.validateNotificationId(id);
RequestValidationUtil.validateNotificationStatus(status);
DeviceMgtAPIUtils.getNotificationManagementService().updateNotificationStatus(id,
Notification.Status.valueOf(status));
return Response.status(Response.Status.OK).entity("Notification status has successfully been updated").build();
} catch (NotificationManagementException e) {
String msg = "Error occurred while updating notification status";
String msg = "ErrorResponse occurred while updating notification status";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -78,10 +90,12 @@ public class NotificationManagementServiceImpl implements NotificationManagement
@Override
public Response addNotification(Notification notification) {
try {
RequestValidationUtil.validateNotification(notification);
DeviceMgtAPIUtils.getNotificationManagementService().addNotification(notification);
return Response.status(Response.Status.OK).entity("Notification has successfully been added").build();
} catch (NotificationManagementException e) {
String msg = "Error occurred while updating notification status.";
String msg = "ErrorResponse occurred while updating notification status.";
log.error(msg, e);
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();
}
} 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);
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);
return Response.status(Response.Status.OK).entity("Policy has been added successfully").build();
} catch (PolicyManagementException e) {
String msg = "Error occurred while adding policy";
String msg = "ErrorResponse occurred while adding policy";
log.error(msg, e);
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();
}
} 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);
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();
}
} 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);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -150,7 +150,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
pap.updatePolicy(policy);
return Response.status(Response.Status.OK).entity("Policy has successfully been updated").build();
} catch (PolicyManagementException e) {
String msg = "Error occurred while updating the policy";
String msg = "ErrorResponse occurred while updating the policy";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -170,7 +170,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
}
}
} catch (PolicyManagementException e) {
String msg = "Error occurred while removing policies";
String msg = "ErrorResponse occurred while removing policies";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -193,7 +193,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
pap.activatePolicy(i);
}
} catch (PolicyManagementException e) {
String msg = "Error occurred while activating policies";
String msg = "ErrorResponse occurred while activating policies";
log.error(msg, e);
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();
}
} 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);
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();
} 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);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} 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";
log.error(msg, e);
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));
}
} 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);
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);
} 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);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -228,7 +228,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
}
}
} catch (UserStoreException e) {
String msg = "Error occurred while updating role '" + roleName + "'";
String msg = "ErrorResponse occurred while updating role '" + roleName + "'";
log.error(msg, e);
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
authorizationManager.clearRoleAuthorization(roleName);
} 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);
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);
} 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);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}

@ -87,7 +87,7 @@ public class UserManagementServiceImpl implements UserManagementService {
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} 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);
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();
}
} 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);
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();
} 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);
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();
} 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);
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 " +
"to the device").build();
} 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);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (UnknownApplicationTypeException e) {
@ -103,7 +103,7 @@ public class ApplicationManagementAdminServiceImpl implements ApplicationManagem
return Response.status(Response.Status.ACCEPTED).entity("Application un-installation request has " +
"been sent to the device").build();
} 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);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (UnknownApplicationTypeException e) {

@ -54,7 +54,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
}
return Response.status(Response.Status.OK).entity(devices).build();
} 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);
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();
}
} 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);
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: " +
credentials.getUsername() + " was successfully changed.").build();
} 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);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} 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.service.DeviceManagementProviderService;
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.core.PolicyManagerService;
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
@ -60,7 +62,16 @@ public class DeviceMgtAPIUtils {
if (configEntryList != null && !configEntryList.isEmpty()) {
for (ConfigurationEntry entry : configEntryList) {
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());
}
}
}
@ -151,13 +162,6 @@ public class DeviceMgtAPIUtils {
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() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ApplicationManagementProviderService applicationManagementProviderService =
@ -182,7 +186,7 @@ public class DeviceMgtAPIUtils {
}
public static PlatformConfigurationManagementService getPlatformConfigurationManagementService() {
CarbonContext ctx = CarbonContext.getThreadLocalCarbonContext();
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
PlatformConfigurationManagementService tenantConfigurationManagementService =
(PlatformConfigurationManagementService) ctx.getOSGiService(
PlatformConfigurationManagementService.class, null);
@ -203,29 +207,6 @@ public class DeviceMgtAPIUtils {
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() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
DeviceInformationManager deviceInformationManager =

@ -43,7 +43,7 @@
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
<ref bean="errorHandler"/>
<!--<ref bean="errorHandler"/>-->
<ref bean="swaggerWriter"/>
</jaxrs:providers>
</jaxrs:server>
@ -54,8 +54,8 @@
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
<property name="resourcePackage" value="org.wso2.carbon.device.mgt.jaxrs"/>
<property name="version" value="1.0"/>
<property name="host" value="device-mgt.wso2.com"/>
<property name="basePath" value="/api/device-mgt/admin/v1.0"/>
<property name="host" value="localhost:9443"/>
<property name="basePath" value="/api/device-mgt/v1.0"/>
<property name="title" value="Device Management Admin Service API Definitions"/>
<property name="contact" value="dev@wso2.org"/>
<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="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="errorHandler" class="org.wso2.carbon.device.mgt.jaxrs.common.ErrorHandler"/>
<!--<bean id="errorHandler" class="org.wso2.carbon.device.mgt.jaxrs.common.ErrorHandler"/>-->
</beans>

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

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

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

@ -21,29 +21,16 @@ public class DeviceManagementException extends Exception {
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) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public DeviceManagementException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public DeviceManagementException(String msg) {
super(msg);
setErrorMessage(msg);
}
public DeviceManagementException() {

@ -23,29 +23,16 @@ public class FeatureManagementException extends Exception {
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) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public FeatureManagementException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public FeatureManagementException(String msg) {
super(msg);
setErrorMessage(msg);
}
public FeatureManagementException() {

@ -22,29 +22,16 @@ public class IllegalTransactionStateException extends RuntimeException {
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) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public IllegalTransactionStateException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public IllegalTransactionStateException(String msg) {
super(msg);
setErrorMessage(msg);
}
public IllegalTransactionStateException() {

@ -22,29 +22,16 @@ public class TransactionManagementException extends Exception {
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) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public TransactionManagementException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public TransactionManagementException(String msg) {
super(msg);
setErrorMessage(msg);
}
public TransactionManagementException() {

@ -25,29 +25,16 @@ public class UnsupportedDatabaseEngineException extends RuntimeException {
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) {
super(msg, nestedEx);
setErrorMessage(msg);
}
public UnsupportedDatabaseEngineException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public UnsupportedDatabaseEngineException(String msg) {
super(msg);
setErrorMessage(msg);
}
public UnsupportedDatabaseEngineException() {

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

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

@ -17,10 +17,7 @@
*/
package org.wso2.carbon.device.mgt.common.operation.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
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.*;
import java.util.List;

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

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

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

@ -719,7 +719,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null;
ResultSet rs = null;
Operation operation;
List<Operation> operations = new ArrayList<Operation>();
List<Operation> operations = new ArrayList<>();
try {
Connection conn = OperationManagementDAOFactory.getConnection();
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;
ResultSet rs = null;
Operation operation;
List<Operation> operations = new ArrayList<Operation>();
List<Operation> operations = new ArrayList<>();
try {
Connection conn = OperationManagementDAOFactory.getConnection();
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;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
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.*;
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.OperationManagementException;
@ -58,7 +55,8 @@ public class PushNotificationBasedOperationManager implements OperationManager {
}
@Override
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
public List<? extends Operation> getOperations(
DeviceIdentifier deviceId) throws OperationManagementException {
return this.operationManager.getOperations(deviceId);
}

@ -17,13 +17,7 @@
*/
package org.wso2.carbon.device.mgt.core.service;
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.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.*;
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.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.LogFactory;
import org.wso2.carbon.context.CarbonContext;
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.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.*;
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.LicenseManagementException;
@ -823,7 +814,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
@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);
}

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

@ -168,7 +168,8 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
}
@Override
public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
public Policy getAppliedPolicyToDevice(
DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
return policyManager.getAppliedPolicyToDevice(deviceIdentifier);
}
@ -184,10 +185,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
List<ComplianceFeature> complianceFeatures =
monitoringManager.checkPolicyCompliance(deviceIdentifier, response);
if (complianceFeatures == null || complianceFeatures.isEmpty()) {
return false;
}
return true;
return !(complianceFeatures == null || complianceFeatures.isEmpty());
}
@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.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import java.util.HashMap;
import java.util.List;

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

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

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

@ -199,7 +199,7 @@ public class PolicyManagerUtil {
public static int getMonitoringFequency() {
PlatformConfigurationManagementService configMgtService = new TenantConfigurationManagementServiceImpl();
PlatformConfiguration tenantConfiguration = null;
PlatformConfiguration tenantConfiguration;
int monitoringFrequency = 0;
try {
tenantConfiguration = configMgtService.getConfiguration(GENERAL_CONFIG_RESOURCE_PATH);
@ -208,7 +208,10 @@ public class PolicyManagerUtil {
if (configuration != null && !configuration.isEmpty()) {
for (ConfigurationEntry cEntry : configuration) {
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;
import junit.framework.Assert;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.annotations.BeforeClass;
@ -87,7 +88,10 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
public void getDeviceAppliedPolicy() throws PolicyManagementException {
PolicyManager manager = new PolicyManagerImpl();
Policy policy = manager.getAppliedPolicyToDevice(identifier);
Policy policy = null;
policy = manager.getAppliedPolicyToDevice(identifier);
if (policy != null) {
@ -107,7 +111,10 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
log.debug("Compliance operations adding started.");
PolicyManager manager = new PolicyManagerImpl();
Policy policy = manager.getAppliedPolicyToDevice(identifier);
Policy policy = null;
policy = manager.getAppliedPolicyToDevice(identifier);
OperationManager operationManager = new OperationManagerImpl();
DeviceManagementDataHolder.getInstance().setOperationManager(operationManager);
@ -154,9 +161,11 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
monitoringServiceTest.notifyDevices(devices);
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();
monitoringServiceTest.checkPolicyCompliance(identifier, policy, ob);
@ -188,8 +197,10 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
log.debug(identifier.getId());
log.debug(identifier.getType());
monitoringManager.checkPolicyCompliance(identifier, ob);
}
}

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

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

Loading…
Cancel
Save