diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index e8a4ffbf9a..e4be5c03ff 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -46,7 +46,7 @@ maven-war-plugin WEB-INF/lib/*cxf*.jar - api#device-mgt#v1.1 + api#device-mgt#v1.0 @@ -72,7 +72,7 @@ - + @@ -243,6 +243,11 @@ org.wso2.carbon.device.mgt.analytics.dashboard provided + + com.fasterxml.jackson.core + jackson-annotations + provided + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/DeviceList.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/DeviceList.java new file mode 100644 index 0000000000..a14de34ded --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/DeviceList.java @@ -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 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 getList() { + return devices; + } + + public void setList(List 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(); + } + +} + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ErrorListItem.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ErrorListItem.java new file mode 100644 index 0000000000..bc63ac10b1 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ErrorListItem.java @@ -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(); + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ErrorResponse.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ErrorResponse.java new file mode 100644 index 0000000000..8804fa3add --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ErrorResponse.java @@ -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 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 getErrorItems() { + return errorItems; + } + + public void setErrorItems(List 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 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; + } + } + +} + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/NotificationList.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/NotificationList.java new file mode 100644 index 0000000000..9309555af9 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/NotificationList.java @@ -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 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 getNotifications() { + return notifications; + } + + public void setNotifications(List 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(); + } + + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java index 301bb0f45f..027dfbed52 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java @@ -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.*; @@ -55,7 +54,7 @@ public interface ActivityInfoProviderService { code = 200, message = "OK. \n Activity details are successfully fetched", response = Activity.class, - responseHeaders = { + responseHeaders = { @ResponseHeader( name = "Content-Type", description = "The content type of the body"), @@ -77,7 +76,7 @@ public interface ActivityInfoProviderService { message = "Not Acceptable.\n The requested media type is not supported"), @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); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java index 9346089231..3dae98bf7f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java @@ -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", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index 7ebb168634..7e12f306e7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -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 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 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", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java index c7a9766144..8cc6f7a916 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java @@ -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", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java index 27960f4e9a..53ec37550c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java @@ -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", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java index d24381aa62..2db6620784 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java @@ -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"}) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java index 34e36ed2e7..1631eeaa28 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java @@ -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"}) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java index 744ef787fd..27156015be 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java @@ -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.") }) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java index ce0bcac4fa..3a70fe6890 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java @@ -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( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java index ac26479b47..f730dd5720 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java @@ -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( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java index d6e748aa77..4b156e0d6e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java @@ -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"}) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java index 1664f31591..e16a92e6d0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java @@ -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 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(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ConfigurationServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ConfigurationServiceImpl.java index 122e07054e..067b0c4269 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ConfigurationServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ConfigurationServiceImpl.java @@ -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(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DashboardImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DashboardImpl.java index 46ef0fec8c..3bf8332bdb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DashboardImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DashboardImpl.java @@ -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") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 01d45f3eac..81f5bedb3c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -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) 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 deviceIds, - @HeaderParam("If-Modified-Since") String timestamp) { - DeviceInformationManager informationManager; - List 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 deviceIds, +// @HeaderParam("If-Modified-Since") String timestamp) { +// DeviceInformationManager informationManager; +// List 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 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 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 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 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) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java index dd8529f322..0b12ebb687 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GroupManagementServiceImpl.java @@ -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(); // } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java index e1a1a2c234..6ec55c73bb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java @@ -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 notifications; try { - List 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(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java index 09409fc2ea..faf2b02b1e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java @@ -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(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index f4f8662dcb..2007821939 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -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(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index 0ab4ab55ff..260b4df291 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -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(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/ApplicationManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/ApplicationManagementAdminServiceImpl.java index 34d90fe7cc..2b5be724e9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/ApplicationManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/ApplicationManagementAdminServiceImpl.java @@ -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) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java index d20d465a36..8709c0875e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java @@ -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(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java index aaf8307131..bc22e7b955 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java @@ -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(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/InputValidationException.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/InputValidationException.java new file mode 100644 index 0000000000..353131c9da --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/InputValidationException.java @@ -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()); + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java new file mode 100644 index 0000000000..9622abde7c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java @@ -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 inputs = new ArrayList() {{ + 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()); + } + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/CredentialManagementResponseBuilder.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/CredentialManagementResponseBuilder.java index 2431be65d9..dfdc187e16 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/CredentialManagementResponseBuilder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/CredentialManagementResponseBuilder.java @@ -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) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java index 0d89dbc9a6..53ec73b841 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java @@ -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()); } } } @@ -104,7 +115,7 @@ public class DeviceMgtAPIUtils { } return groupManagementProviderService; } - + public static UserStoreManager getUserStoreManager() throws UserStoreException { RealmService realmService; UserStoreManager userStoreManager; @@ -150,13 +161,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(); @@ -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); @@ -202,29 +206,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(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index b4127cc289..7bb3dd412e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -43,7 +43,7 @@ - + @@ -54,8 +54,8 @@ - - + + @@ -77,6 +77,6 @@ - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml index 14c8072106..61b317b468 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml @@ -49,6 +49,7 @@ javax.xml.bind.annotation, + com.fasterxml.jackson.annotation, io.swagger.annotations.*;resolution:=optional @@ -63,6 +64,10 @@ swagger-annotations provided + + com.fasterxml.jackson.core + jackson-annotations + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java index 51c206f6cc..b5a6c834ae 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java @@ -154,7 +154,7 @@ public class Device implements Serializable { @Override public String toString() { - return "Device[" + + return "device [" + "name=" + name + ";" + "type=" + type + ";" + "description=" + description + ";" + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java index a88bcb465a..44219d31df 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java @@ -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 + '\'' + '}'; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java index 082413a92b..3a304a3b71 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementException.java @@ -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() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManagementException.java index f4949af077..8552c6b815 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManagementException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManagementException.java @@ -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() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/IllegalTransactionStateException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/IllegalTransactionStateException.java index 049d7e166c..3d007fbf77 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/IllegalTransactionStateException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/IllegalTransactionStateException.java @@ -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() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/TransactionManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/TransactionManagementException.java index 72cfb87f74..d96d462077 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/TransactionManagementException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/TransactionManagementException.java @@ -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() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/UnsupportedDatabaseEngineException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/UnsupportedDatabaseEngineException.java index 14586153ea..8e1d33ec4b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/UnsupportedDatabaseEngineException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/UnsupportedDatabaseEngineException.java @@ -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() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/configuration/mgt/PlatformConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/configuration/mgt/PlatformConfiguration.java index b7e8a0fd02..54309a3c7e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/configuration/mgt/PlatformConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/configuration/mgt/PlatformConfiguration.java @@ -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; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/Notification.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/Notification.java index c49e5014a4..2b92a3b9b5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/Notification.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/Notification.java @@ -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() + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java index a27ca502f2..82cd262ab9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java @@ -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; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java index 0ea859a140..0cf17d53a2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java @@ -25,7 +25,7 @@ import java.util.List; public interface ApplicationManagementProviderService extends ApplicationManager{ void updateApplicationListInstalledInDevice(DeviceIdentifier deviceIdentifier, - List applications) throws ApplicationManagementException; + List applications) throws ApplicationManagementException; List getApplicationListForDevice(DeviceIdentifier deviceIdentifier) throws ApplicationManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index 78782e55d9..61eb2669fe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -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 applications) throws ApplicationManagementException { + DeviceIdentifier deviceIdentifier, + List applications) throws ApplicationManagementException { List installedAppList = getApplicationListForDevice(deviceIdentifier); try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java index bb269cc975..e1033cc3ee 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java @@ -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 getDevicesInfo(List deviceIdentifiers) throws DeviceDetailsMgtException { - List deviceInfos = new ArrayList<>(); Map 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()); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 637e81cda4..821276398f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -185,7 +185,8 @@ public class OperationManagerImpl implements OperationManager { } @Override - public List getOperations(DeviceIdentifier deviceId) throws OperationManagementException { + public List getOperations( + DeviceIdentifier deviceId) throws OperationManagementException { int enrolmentId; List 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 operationList = operationDAO.getOperationsForDevice(enrolmentId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index 4848d090d9..332bfe842e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -719,7 +719,7 @@ public class GenericOperationDAOImpl implements OperationDAO { PreparedStatement stmt = null; ResultSet rs = null; Operation operation; - List operations = new ArrayList(); + List 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 operations = new ArrayList(); + List operations = new ArrayList<>(); try { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java index d83a94939f..46e382616d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java @@ -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 getOperations(DeviceIdentifier deviceId) throws OperationManagementException { + public List getOperations( + DeviceIdentifier deviceId) throws OperationManagementException { return this.operationManager.getOperations(deviceId); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index e5a096fb1e..b07e1ebf51 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -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; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 4c10e1bee7..5f3cad82f2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -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 getOperations(DeviceIdentifier deviceId) throws OperationManagementException { + public List getOperations( + DeviceIdentifier deviceId) throws OperationManagementException { return DeviceManagementDataHolder.getInstance().getOperationManager().getOperations(deviceId); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java index f4514a2c0d..81ccf0eca4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java @@ -67,7 +67,8 @@ public interface PolicyManagerService { int getPolicyCount() throws PolicyManagementException; - Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; + Policy getAppliedPolicyToDevice( + DeviceIdentifier deviceIdentifier) throws PolicyManagementException; List checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Object deviceResponse) throws PolicyComplianceException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java index 24bfc8294d..4564e4ba5e 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java @@ -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 complianceFeatures = monitoringManager.checkPolicyCompliance(deviceIdentifier, response); - if (complianceFeatures == null || complianceFeatures.isEmpty()) { - return false; - } - return true; + return !(complianceFeatures == null || complianceFeatures.isEmpty()); } @Override diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java index 6ac0e6b50b..fb8a8df5bf 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java @@ -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; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java index 25bb2709d8..ba63452b90 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java @@ -77,8 +77,9 @@ public class MonitoringManagerImpl implements MonitoringManager { } @Override - public List checkPolicyCompliance(DeviceIdentifier deviceIdentifier, - Object deviceResponse) throws PolicyComplianceException { + public List checkPolicyCompliance( + DeviceIdentifier deviceIdentifier, + Object deviceResponse) throws PolicyComplianceException { List complianceFeatures = new ArrayList<>(); try { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index d2907ceef6..45258a5851 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -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(); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java index 9be3b71b96..5ed2bf0f65 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java @@ -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); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java index c047c8cb92..c4ff1d8db8 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java @@ -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()); } } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/MonitoringTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/MonitoringTestCase.java index f0943c6f8c..49fe8c062c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/MonitoringTestCase.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/MonitoringTestCase.java @@ -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); @@ -123,7 +130,7 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest { DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); List devices = service.getAllDevices(ANDROID); - // monitoringManager.addMonitoringOperation(devices); + // monitoringManager.addMonitoringOperation(devices); log.debug("Compliance operations adding done."); @@ -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); + } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml index b29b528d4c..46a7fe98c8 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml @@ -120,6 +120,9 @@ org.wso2.carbon.identity:org.wso2.carbon.identity.oauth.stub:${carbon.identity.version} + + com.fasterxml.jackson.core:jackson-annotations:${jackson-annotations.version} + diff --git a/pom.xml b/pom.xml index 1ac139acd5..07073f316d 100644 --- a/pom.xml +++ b/pom.xml @@ -1501,6 +1501,12 @@ org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp ${carbon.device.mgt.version} + + com.fasterxml.jackson.core + jackson-annotations + ${jackson-annotations.version} + + @@ -1866,6 +1872,8 @@ 2.0.1 1.5.8 2.5 + + 2.7.4