From 245ea2b0d6d0dde46d24878e072e0292889f6c11 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Mon, 19 Sep 2016 14:35:19 +0530 Subject: [PATCH 1/2] Fixing incorrect text formatting --- .../app/units/mdm.unit.device.view/public/js/device-detail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.view/public/js/device-detail.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.view/public/js/device-detail.js index 87d902e44..155c2568e 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.view/public/js/device-detail.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.view/public/js/device-detail.js @@ -44,7 +44,7 @@ var InitiateViewOption = null; // error-callback function () { var defaultInnerHTML = - "

Device data may not have been updated. Please refresh to try again.

"; + "

 Device data may not have been updated. Please refresh to try again.

"; $(".panel-body").append(defaultInnerHTML); } ); From 18e577a84a0cd342ed0b89cf69d09ea498dce979 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Mon, 19 Sep 2016 15:49:16 +0530 Subject: [PATCH 2/2] adding windowsplugin changes --- .../modules/business-controllers/device.js | 2 +- .../enrollments/windows/agent-controller.jag | 2 +- .../enrollments/windows/agent-enroll.jag | 6 +- .../windows/api/common/PluginConstants.java | 8 + .../windows/api/common/beans/ErrorDTO.java | 86 +++++++++ .../api/common/beans/ErrorListItem.java | 77 ++++++++ .../api/common/beans/ErrorResponse.java | 167 ++++++++++++++++++ .../exceptions/BadRequestException.java | 8 +- .../UnexpectedServerErrorException.java | 49 +++++ .../api/common/util/WindowsAPIUtils.java | 45 +++-- .../api/common/util/WindowsDeviceUtils.java | 86 --------- .../api/services/ConfigurationMgtService.java | 149 ++++++++++++++-- .../impl/ConfigurationMgtServiceImpl.java | 74 +++----- .../DeviceManagementAdminServiceImpl.java | 40 ++++- 14 files changed, 615 insertions(+), 184 deletions(-) create mode 100644 components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/beans/ErrorDTO.java create mode 100644 components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/beans/ErrorListItem.java create mode 100644 components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/beans/ErrorResponse.java create mode 100644 components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/exceptions/UnexpectedServerErrorException.java delete mode 100644 components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/util/WindowsDeviceUtils.java diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/business-controllers/device.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/business-controllers/device.js index dbc76aabc..3dce168f4 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/business-controllers/device.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/business-controllers/device.js @@ -312,7 +312,7 @@ deviceModule = function () { var url; var license; if (deviceType == "windows") { - url = devicemgtProps["httpURL"] + "/mdm-windows-agent/services/device/license"; + url = devicemgtProps["httpURL"] + "/api/device-mgt/windows/v1.0/services/configuration/license"; } else if (deviceType == "ios") { url = devicemgtProps["httpsURL"] + "/ios-enrollment/license/"; } diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/enrollments/windows/agent-controller.jag b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/enrollments/windows/agent-controller.jag index f76bcf925..eaa84869e 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/enrollments/windows/agent-controller.jag +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/enrollments/windows/agent-controller.jag @@ -63,7 +63,7 @@ if (platform != "Windows Phone") { var status = restAPIResponse["status"]; if (status == 200) { session.put("authenticatedUser", username); - session.put("windowsBinaryToken", parse(xmlHttpRequest["responseText"]).UserToken); + session.put("windowsBinaryToken", parse(restAPIResponse["responseText"]).UserToken); response.sendRedirect(mdmProps["appContext"] + "enrollments/windows/license-agent"); } else if (status == 403) { response.sendRedirect(mdmProps["appContext"] + "enrollments/windows/login-agent?error=auth-failed"); diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/enrollments/windows/agent-enroll.jag b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/enrollments/windows/agent-enroll.jag index 1ad693001..66a4eed09 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/enrollments/windows/agent-enroll.jag +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/emm-web-agent/app/modules/enrollments/windows/agent-enroll.jag @@ -36,10 +36,10 @@ if (platform != "Windows Phone") { if (!authenticatedUser) { response.sendRedirect(mdmProps["appContext"] + "enrollments/error/unintentional-request"); } else { - var enrollmentUtils = require("/modules/enrollments/util/utils.js")["methods"]; - var Handlebars = require("/lib/handlebars-v2.0.0.js")["Handlebars"]; + var enrollmentUtils = require("/app/modules/enrollments/util/utils.js")["methods"]; + var Handlebars = require("/lib/modules/handlebars/handlebars-v2.0.0.js")["Handlebars"]; var template = Handlebars.compile(enrollmentUtils. - getResource("/modules/enrollments/windows/config/workplace-switch-request-template.hbs")); + getResource("/app/modules/enrollments/windows/config/workplace-switch-request-template.hbs")); var windowsWorkplaceAppID = session.get("windowsWorkplaceAppID"); var windowsBinaryToken = session.get("windowsBinaryToken"); diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java index 6e57b1be1..734c5c901 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/PluginConstants.java @@ -263,6 +263,13 @@ public final class PluginConstants { } public static final int MULTI_STATUS_HTTP_CODE = 207; + + } + + public final class WindowsConstant { + public static final String DEVICE_TYPE_WINDOWS = "windows"; + public static final String HEADER_CONTENT_TYPE = "Content-Type"; + public static final String APPLICATION_JSON = "application/json"; } /** @@ -282,6 +289,7 @@ public final class PluginConstants { public static final String DEFAULT_AUTH_POLICY = "Federated"; } + /** * Policy Configuration related constants. */ diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/beans/ErrorDTO.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/beans/ErrorDTO.java new file mode 100644 index 000000000..84fe7ea49 --- /dev/null +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/beans/ErrorDTO.java @@ -0,0 +1,86 @@ +/* + * 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.mobile.windows.api.common.beans; + +import java.util.ArrayList; +import java.util.List; + +public class ErrorDTO { + + private Long code = null; + private String message = null; + private String description = null; + + public void setMoreInfo(String moreInfo) { + this.moreInfo = moreInfo; + } + + public void setCode(Long code) { + this.code = code; + } + + public void setMessage(String message) { + this.message = message; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setError(List error) { + this.error = error; + } + + private String moreInfo = null; + + public String getMessage() { + return message; + } + + public Long getCode() { + return code; + } + + public String getDescription() { + return description; + } + + public String getMoreInfo() { + return moreInfo; + } + + public List getError() { + return error; + } + + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("class ErrorDTO {\n"); + stringBuilder.append(" code: ").append(code).append("\n"); + stringBuilder.append(" message: ").append(message).append("\n"); + stringBuilder.append(" description: ").append(description).append("\n"); + stringBuilder.append(" moreInfo: ").append(moreInfo).append("\n"); + stringBuilder.append(" error: ").append(error).append("\n"); + stringBuilder.append("}\n"); + return stringBuilder.toString(); + } + + private List error = new ArrayList<>(); + +} diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/beans/ErrorListItem.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/beans/ErrorListItem.java new file mode 100644 index 000000000..45571ced4 --- /dev/null +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/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.mobile.windows.api.common.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/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/beans/ErrorResponse.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/beans/ErrorResponse.java new file mode 100644 index 000000000..e983abd64 --- /dev/null +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/beans/ErrorResponse.java @@ -0,0 +1,167 @@ +package org.wso2.carbon.device.mgt.mobile.windows.api.common.beans; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; + +import java.util.ArrayList; +import java.util.List; + +public class ErrorResponse { + private Long code = null; + private String message = null; + private String description = null; + private String moreInfo = null; + private List errorItems = new ArrayList<>(); + + @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/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/exceptions/BadRequestException.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/exceptions/BadRequestException.java index 5f17627ce..c0f933892 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/exceptions/BadRequestException.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/exceptions/BadRequestException.java @@ -18,10 +18,9 @@ package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions; -import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message; +import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse; import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; /** @@ -29,8 +28,7 @@ import javax.ws.rs.core.Response; */ public class BadRequestException extends WebApplicationException { - public BadRequestException(Message message, MediaType mediaType) { - super(Response.status(Response.Status.BAD_REQUEST).entity(message). - type(mediaType).build()); + public BadRequestException(ErrorResponse error) { + super(Response.status(Response.Status.BAD_REQUEST).entity(error).build()); } } \ No newline at end of file diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/exceptions/UnexpectedServerErrorException.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/exceptions/UnexpectedServerErrorException.java new file mode 100644 index 000000000..6643f01d0 --- /dev/null +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/exceptions/UnexpectedServerErrorException.java @@ -0,0 +1,49 @@ +/* + * 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.mobile.windows.api.common.exceptions; + +import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants; +import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorDTO; +import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; + +public class UnexpectedServerErrorException extends WebApplicationException { + private String message; + private static final long serialVersionUID = 147943579458906890L; + + public UnexpectedServerErrorException(ErrorResponse error) { + super(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build()); + } + public UnexpectedServerErrorException(ErrorDTO errorDTO) { + super(Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity(errorDTO) + .header(PluginConstants.WindowsConstant.HEADER_CONTENT_TYPE, PluginConstants.WindowsConstant.APPLICATION_JSON) + .build()); + message = errorDTO.getDescription(); + } + + @Override + public String getMessage() { + return message; + } + + +} diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/util/WindowsAPIUtils.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/util/WindowsAPIUtils.java index a782272b7..a20d9ba53 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/util/WindowsAPIUtils.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/util/WindowsAPIUtils.java @@ -18,18 +18,24 @@ package org.wso2.carbon.device.mgt.mobile.windows.api.common.util; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; +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; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants; +import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.BadRequestException; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; import org.wso2.carbon.identity.oauth2.OAuth2TokenValidationService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; @@ -42,6 +48,7 @@ import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfig import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.util.ArrayList; import java.util.List; /** @@ -49,6 +56,8 @@ import java.util.List; */ public class WindowsAPIUtils { + private static Log log = LogFactory.getLog(WindowsAPIUtils.class); + public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) { DeviceIdentifier identifier = new DeviceIdentifier(); identifier.setId(deviceId); @@ -87,21 +96,25 @@ public class WindowsAPIUtils { return responseMediaType; } - public static Response getOperationResponse(List deviceIDs, Operation operation, - Message message, MediaType responseMediaType) - throws DeviceManagementException, OperationManagementException { - WindowsDeviceUtils deviceUtils = new WindowsDeviceUtils(); - DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs, - message, responseMediaType); -// getDeviceManagementService().addOperation(operation, deviceIDHolder.getValidDeviceIDList()); - if (!deviceIDHolder.getInvalidDeviceIdList().isEmpty()) { - return Response.status(PluginConstants.StatusCodes. - MULTI_STATUS_HTTP_CODE).type( - responseMediaType).entity(deviceUtils. - convertErrorMapIntoErrorMessage(deviceIDHolder.getInvalidDeviceIdList())).build(); + public static Response getOperationResponse(List deviceIDs, Operation operation) + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + if (deviceIDs == null || deviceIDs.size() == 0) { + String errorMessage = "Device identifier list is empty"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + DeviceIdentifier deviceIdentifier; + List deviceIdentifiers = new ArrayList<>(); + for (String deviceId : deviceIDs) { + deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(PluginConstants.WindowsConstant.DEVICE_TYPE_WINDOWS); + deviceIdentifiers.add(deviceIdentifier); } - return Response.status(Response.Status.CREATED). - type(responseMediaType).build(); + Activity activity = getDeviceManagementService().addOperation( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, operation, deviceIdentifiers); + return Response.status(Response.Status.CREATED).entity(activity).build(); } public static PolicyManagerService getPolicyManagerService() { @@ -126,8 +139,8 @@ public class WindowsAPIUtils { throws OperationManagementException, DeviceManagementException { List pendingDataOperations; pendingDataOperations = org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils. - getDeviceManagementService().getOperationsByDeviceAndStatus( - deviceIdentifier, Operation.Status.PENDING); + getDeviceManagementService().getOperationsByDeviceAndStatus( + deviceIdentifier, Operation.Status.PENDING); return pendingDataOperations; } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/util/WindowsDeviceUtils.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/util/WindowsDeviceUtils.java deleted file mode 100644 index 77d069228..000000000 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/common/util/WindowsDeviceUtils.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.mobile.windows.api.common.util; - -import org.apache.commons.lang.StringUtils; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants; -import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.BadRequestException; - -import javax.ws.rs.core.MediaType; -import java.util.ArrayList; -import java.util.List; - -/** - * Class for get windows device utilities. - */ -public class WindowsDeviceUtils { - - private static final String COMMA_SEPARATION_PATTERN = ", "; - - public DeviceIDHolder validateDeviceIdentifiers(List deviceIDs, - Message message, MediaType responseMediaType) { - if (deviceIDs == null) { - message.setResponseMessage("Device identifier list is empty"); - throw new BadRequestException(message, responseMediaType); - } - List errorDeviceIdList = new ArrayList<>(); - List validDeviceIDList = new ArrayList<>(); - int deviceIDCounter = 0; - - for (String deviceID : deviceIDs) { - deviceIDCounter++; - if (deviceID == null || deviceID.isEmpty()) { - errorDeviceIdList.add(String.format(PluginConstants.DeviceConstants.DEVICE_ID_NOT_FOUND, - deviceIDCounter)); - continue; - } - try { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setId(deviceID); - deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes. - MOBILE_DEVICE_TYPE_WINDOWS); - Device device = WindowsAPIUtils.getDeviceManagementService(). - getDevice(deviceIdentifier); - if (device == null || device.getDeviceIdentifier() == null || - device.getDeviceIdentifier().isEmpty()) { - errorDeviceIdList.add(String.format(PluginConstants.DeviceConstants.DEVICE_ID_NOT_FOUND, - deviceIDCounter)); - continue; - } - validDeviceIDList.add(deviceIdentifier); - } catch (DeviceManagementException e) { - errorDeviceIdList.add(String.format(PluginConstants.DeviceConstants.DEVICE_ID_SERVICE_NOT_FOUND, - deviceIDCounter)); - } - } - DeviceIDHolder deviceIDHolder = new DeviceIDHolder(); - deviceIDHolder.setValidDeviceIDList(validDeviceIDList); - deviceIDHolder.setInvalidDeviceIdList(errorDeviceIdList); - return deviceIDHolder; - } - - public String convertErrorMapIntoErrorMessage(List errorDeviceIdList) { - return StringUtils.join(errorDeviceIdList.iterator(), COMMA_SEPARATION_PATTERN); - } - -} diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/ConfigurationMgtService.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/ConfigurationMgtService.java index b5428ba07..f517f682c 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/ConfigurationMgtService.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/ConfigurationMgtService.java @@ -18,16 +18,17 @@ package org.wso2.carbon.device.mgt.mobile.windows.api.services; -import io.swagger.annotations.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.apimgt.annotations.api.Scope; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsConfigurationException; import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message; import javax.jws.WebService; import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; /** * Windows Platform Configuration REST-API implementation. @@ -44,17 +45,6 @@ import javax.ws.rs.*; @Consumes({"application/json", "application/xml"}) public interface ConfigurationMgtService { - /** - * Save Tenant configurations. - * - * @param configuration Tenant Configurations to be saved. - * @return Message type object for the provide save status. - * @throws WindowsConfigurationException - */ - @POST - @Permission(name = "Manage Configurations", permission = "/device-mgt/configurations/manage") - Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException; - /** * Retrieve Tenant configurations according to the device type. * @@ -62,6 +52,45 @@ public interface ConfigurationMgtService { * @throws WindowsConfigurationException */ @GET + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting Windows Platform Configurations", + notes = "Get the Windows platform configuration details using this REST API", + response = PlatformConfiguration.class, + tags = "Windows Configuration Management" + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched Windows platform configuration.", + response = PlatformConfiguration.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."), + @ApiResponse( + code = 404, + message = "Not Found. \n Resource to be deleted does not exist."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while fetching Windows platform configuration.") + }) @Permission(name = "View Configurations", permission = "/device-mgt/configurations/view") PlatformConfiguration getConfiguration() throws WindowsConfigurationException; @@ -73,6 +102,98 @@ public interface ConfigurationMgtService { * @throws WindowsConfigurationException */ @PUT + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Updating Windows Platform Configuration.", + notes = "Update the Windows platform configurations using this REST API.", + tags = "Windows Configuration Management" + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Windows platform configuration has been updated successfully", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the updated Windows platform configuration."), + @ResponseHeader( + name = "Content-Type", + description = "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 = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 404, + message = "Not Found. \n Resource to be deleted does not exist."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The entity of the request was in a not supported format."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while modifying Windows platform configuration.") + }) @Permission(name = "Manage Configurations", permission = "/device-mgt/configurations/manage") - Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException; + Message updateConfiguration( @ApiParam(name = "configuration", + value = "PlatformConfiguration")PlatformConfiguration configuration) throws WindowsConfigurationException; + + @GET + @Path("license") + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation( + produces = MediaType.TEXT_PLAIN, + httpMethod = "GET", + value = "Getting the License Agreement for Windows Device Registration", + notes = "Use this REST API to retrieve the license agreement that is used for the Windows device " + + "registration process", + response = String.class, + tags = "Windows Configuration Management") + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched Windows license configuration.", + response = String.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."), + @ApiResponse( + code = 404, + message = "Not Found. \n Resource to be deleted does not exist."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while fetching Windows license configuration.") + }) + Response getLicense( + @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) throws WindowsConfigurationException; + } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/ConfigurationMgtServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/ConfigurationMgtServiceImpl.java index 0b911d7e8..1802df8dc 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/ConfigurationMgtServiceImpl.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/ConfigurationMgtServiceImpl.java @@ -26,6 +26,8 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; 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.mobile.windows.api.common.PluginConstants; +import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.UnexpectedServerErrorException; import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsConfigurationException; import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message; import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils; @@ -46,58 +48,6 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { private static Log log = LogFactory.getLog( org.wso2.carbon.device.mgt.mobile.windows.api.services.impl.ConfigurationMgtServiceImpl.class); - /** - * Save Tenant configurations. - * - * @param configuration Tenant Configurations to be saved. - * @return Message type object for the provide save status. - * @throws WindowsConfigurationException - */ - @POST - public Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException { - Message responseMsg = new Message(); - ConfigurationEntry licenseEntry = null; - String message; - - try { - configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - if (!configuration.getConfiguration().isEmpty()) { - List configs = configuration.getConfiguration(); - for (ConfigurationEntry entry : configs) { - if (PluginConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) { - License license = new License(); - license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - license.setLanguage(PluginConstants.TenantConfigProperties.LANGUAGE_US); - license.setVersion("1.0.0"); - license.setText(entry.getValue().toString()); - WindowsAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants. - MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, license); - licenseEntry = entry; - } - } - - if (licenseEntry != null) { - configs.remove(licenseEntry); - } - configuration.setConfiguration(configs); - WindowsAPIUtils.getDeviceManagementService().saveConfiguration(configuration); - Response.status(Response.Status.CREATED); - responseMsg.setResponseMessage("Windows platform configuration saved successfully."); - responseMsg.setResponseCode(Response.Status.CREATED.toString()); - return responseMsg; - } else { - Response.status(Response.Status.BAD_REQUEST); - responseMsg.setResponseMessage("Windows platform configuration can not be saved."); - responseMsg.setResponseCode(Response.Status.CREATED.toString()); - } - } catch (DeviceManagementException e) { - message = "Error Occurred while configuring Windows Platform."; - log.error(message, e); - throw new WindowsConfigurationException(message, e); - } - return responseMsg; - } - /** * Retrieve Tenant configurations according to the device type. * @@ -182,4 +132,24 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService { } return responseMsg; } + + @GET + @Path("/license") + public Response getLicense( + @HeaderParam("If-Modified-Since") String ifModifiedSince) { + License license; + try { + license = + WindowsAPIUtils.getDeviceManagementService().getLicense( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, + DeviceManagementConstants.LanguageCodes.LANGUAGE_CODE_ENGLISH_US); + } catch (DeviceManagementException e) { + String msg = "Error occurred while retrieving the license configured for Windows device enrolment"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + return Response.status(Response.Status.OK).entity(license).build(); + } } + diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementAdminServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementAdminServiceImpl.java index 7cc14838c..5f6e4e082 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementAdminServiceImpl.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/api/services/impl/DeviceManagementAdminServiceImpl.java @@ -22,10 +22,13 @@ import com.ibm.wsdl.OperationImpl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants; +import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.BadRequestException; import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException; import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsOperationsException; import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message; @@ -69,7 +72,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe operation.setCode(PluginConstants.OperationCodes.DEVICE_LOCK); operation.setType(Operation.Type.COMMAND); operation.setEnabled(true); - return WindowsAPIUtils.getOperationResponse(deviceIDs, operation, message, responseMediaType); + return WindowsAPIUtils.getOperationResponse(deviceIDs, operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; message.setResponseMessage(errorMessage); @@ -82,6 +85,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe message.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()); log.error(errorMessage, e); throw new WindowsOperationsException(message, responseMediaType); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } } @@ -105,7 +113,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe operation.setType(Operation.Type.COMMAND); operation.setEnabled(true); try { - return WindowsAPIUtils.getOperationResponse(deviceIDs, operation, message, responseMediaType); + return WindowsAPIUtils.getOperationResponse(deviceIDs, operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; message.setResponseMessage(errorMessage); @@ -118,7 +126,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe message.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()); log.error(errorMessage, e); throw new WindowsOperationsException(message, responseMediaType); - } + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } } /** @@ -143,7 +156,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe operation.setCode(PluginConstants.OperationCodes.WIPE_DATA); operation.setType(Operation.Type.COMMAND); try { - return WindowsAPIUtils.getOperationResponse(deviceids, operation, message, responseMediaType); + return WindowsAPIUtils.getOperationResponse(deviceids, operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; message.setResponseMessage(errorMessage); @@ -156,6 +169,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe message.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()); log.error(errorMessage, e); throw new WindowsOperationsException(message, responseMediaType); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } } @@ -181,7 +199,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe CommandOperation operation = new CommandOperation(); operation.setCode(PluginConstants.OperationCodes.DEVICE_RING); operation.setType(Operation.Type.COMMAND); - return WindowsAPIUtils.getOperationResponse(deviceIDs, operation, message, responseMediaType); + return WindowsAPIUtils.getOperationResponse(deviceIDs, operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; message.setResponseMessage(errorMessage); @@ -194,6 +212,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe message.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()); log.error(errorMessage, e); throw new WindowsOperationsException(message, responseMediaType); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } } @@ -224,7 +247,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe CommandOperation operation = new CommandOperation(); operation.setCode(PluginConstants.OperationCodes.LOCK_RESET); operation.setType(Operation.Type.COMMAND); - return WindowsAPIUtils.getOperationResponse(deviceIDs, operation, message, responseMediaType); + return WindowsAPIUtils.getOperationResponse(deviceIDs, operation); } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; message.setResponseMessage(errorMessage); @@ -237,6 +260,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe message.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()); log.error(errorMessage, e); throw new WindowsOperationsException(message, responseMediaType); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); } } }