forked from community/device-mgt-core
Fixing inconsistencies between what's represented via swagger and the real implementation, and bugs found in admin services
parent
54f9d02ebb
commit
6e5148a374
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeviceList {
|
||||||
|
|
||||||
|
private int count;
|
||||||
|
private String next;
|
||||||
|
private String previous;
|
||||||
|
|
||||||
|
private List<Device> devices = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of Devices returned.
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "Number of Devices returned.")
|
||||||
|
@JsonProperty("count")
|
||||||
|
public int getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCount(int count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link to the next subset of resources qualified. \nEmpty if no more resources are to be returned.
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "Link to the next subset of resources qualified. \n " +
|
||||||
|
"Empty if no more resources are to be returned.")
|
||||||
|
@JsonProperty("next")
|
||||||
|
public String getNext() {
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNext(String next) {
|
||||||
|
this.next = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link to the previous subset of resources qualified. \nEmpty if current subset is the first subset returned.
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "Link to the previous subset of resources qualified. \n" +
|
||||||
|
"Empty if current subset is the first subset returned.")
|
||||||
|
@JsonProperty("previous")
|
||||||
|
public String getPrevious() {
|
||||||
|
return previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrevious(String previous) {
|
||||||
|
this.previous = previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
**/
|
||||||
|
@ApiModelProperty(value = "List of devices returned")
|
||||||
|
@JsonProperty("devices")
|
||||||
|
public List<Device> getList() {
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setList(List<Device> devices) {
|
||||||
|
this.devices = devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("{\n");
|
||||||
|
|
||||||
|
sb.append(" count: ").append(count).append(",\n");
|
||||||
|
sb.append(" next: ").append(next).append(",\n");
|
||||||
|
sb.append(" previous: ").append(previous).append(",\n");
|
||||||
|
sb.append(" devices: [").append(devices).append("\n");
|
||||||
|
sb.append("]}\n");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@ApiModel(description = "")
|
||||||
|
public class ErrorListItem {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String code = null;
|
||||||
|
@NotNull
|
||||||
|
private String message = null;
|
||||||
|
|
||||||
|
@ApiModelProperty(required = true, value = "")
|
||||||
|
@JsonProperty("code")
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorListItem() {}
|
||||||
|
|
||||||
|
public ErrorListItem(String code, String msg) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description about individual errors occurred
|
||||||
|
**/
|
||||||
|
@ApiModelProperty(required = true, value = "Description about individual errors occurred")
|
||||||
|
@JsonProperty("message")
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("errorItem {\n");
|
||||||
|
|
||||||
|
sb.append(" code: ").append(code).append("\n");
|
||||||
|
sb.append(" message: ").append(message).append("\n");
|
||||||
|
sb.append("}\n");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,193 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ApiModel(description = "")
|
||||||
|
public class ErrorResponse {
|
||||||
|
|
||||||
|
private Long code = null;
|
||||||
|
private String message = null;
|
||||||
|
private String description = null;
|
||||||
|
private String moreInfo = null;
|
||||||
|
private List<ErrorListItem> errorItems = new ArrayList<>();
|
||||||
|
|
||||||
|
private ErrorResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty(value = "code")
|
||||||
|
@ApiModelProperty(required = true, value = "")
|
||||||
|
public Long getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(Long code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty(value = "message")
|
||||||
|
@ApiModelProperty(required = true, value = "ErrorResponse message.")
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty(value = "description")
|
||||||
|
@ApiModelProperty(value = "A detail description about the error message.")
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty(value = "moreInfo")
|
||||||
|
@ApiModelProperty(value = "Preferably an url with more details about the error.")
|
||||||
|
public String getMoreInfo() {
|
||||||
|
return moreInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMoreInfo(String moreInfo) {
|
||||||
|
this.moreInfo = moreInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addErrorListItem(ErrorListItem item) {
|
||||||
|
this.errorItems.add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If there are more than one error list them out. \nFor example, list out validation errors by each field.
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "errorItems")
|
||||||
|
@ApiModelProperty(value = "If there are more than one error list them out. \n" +
|
||||||
|
"For example, list out validation errors by each field.")
|
||||||
|
public List<ErrorListItem> getErrorItems() {
|
||||||
|
return errorItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorItems(List<ErrorListItem> error) {
|
||||||
|
this.errorItems = error;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
// StringBuilder sb = new StringBuilder();
|
||||||
|
// sb.append("{");
|
||||||
|
// boolean cont = false;
|
||||||
|
// if (code != null) {
|
||||||
|
// cont = true;
|
||||||
|
// sb.append(" \"code\": ").append(code);
|
||||||
|
// }
|
||||||
|
// if (message != null) {
|
||||||
|
// if (cont) {
|
||||||
|
// sb.append(",");
|
||||||
|
// }
|
||||||
|
// cont = true;
|
||||||
|
// sb.append(" \"message\": \"").append(message).append("\"");
|
||||||
|
// }
|
||||||
|
// if (description != null) {
|
||||||
|
// if (cont) {
|
||||||
|
// sb.append(",");
|
||||||
|
// }
|
||||||
|
// cont = true;
|
||||||
|
// sb.append(" \"description\": ").append(description).append("\"");
|
||||||
|
// }
|
||||||
|
// if (moreInfo != null) {
|
||||||
|
// if (cont) {
|
||||||
|
// sb.append(",");
|
||||||
|
// }
|
||||||
|
// cont = true;
|
||||||
|
// sb.append(" \"moreInfo\": \"").append(moreInfo).append("\"");
|
||||||
|
// }
|
||||||
|
// if (error != null && error.size() > 0) {
|
||||||
|
// if (cont) {
|
||||||
|
// sb.append(",");
|
||||||
|
// }
|
||||||
|
// sb.append(" \"errorItems\": ").append(error);
|
||||||
|
// }
|
||||||
|
// sb.append("}");
|
||||||
|
// return sb.toString();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ErrorResponseBuilder {
|
||||||
|
|
||||||
|
private Long code = null;
|
||||||
|
private String message = null;
|
||||||
|
private String description = null;
|
||||||
|
private String moreInfo = null;
|
||||||
|
private List<ErrorListItem> error;
|
||||||
|
|
||||||
|
|
||||||
|
public ErrorResponseBuilder() {
|
||||||
|
this.error = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponseBuilder setCode(long code) {
|
||||||
|
this.code = code;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponseBuilder setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponseBuilder setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponseBuilder setMoreInfo(String moreInfo) {
|
||||||
|
this.moreInfo = moreInfo;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponseBuilder addErrorItem(String code, String msg) {
|
||||||
|
ErrorListItem item = new ErrorListItem();
|
||||||
|
item.setCode(code);
|
||||||
|
item.setMessage(msg);
|
||||||
|
this.error.add(item);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponse build() {
|
||||||
|
ErrorResponse errorResponse = new ErrorResponse();
|
||||||
|
errorResponse.setCode(code);
|
||||||
|
errorResponse.setMessage(message);
|
||||||
|
errorResponse.setErrorItems(error);
|
||||||
|
errorResponse.setDescription(description);
|
||||||
|
errorResponse.setMoreInfo(moreInfo);
|
||||||
|
return errorResponse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ApiModel(value = "notificationList")
|
||||||
|
public class NotificationList {
|
||||||
|
|
||||||
|
private int count;
|
||||||
|
private String next;
|
||||||
|
private String previous;
|
||||||
|
private List<Notification> notifications;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of notifications returned.
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "Number of notifications returned.")
|
||||||
|
@JsonProperty("count")
|
||||||
|
public int getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCount(int count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link to the next subset of resources qualified. \nEmpty if no more resources are to be returned.
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "Link to the next subset of resources qualified. \n " +
|
||||||
|
"Empty if no more resources are to be returned.")
|
||||||
|
@JsonProperty("next")
|
||||||
|
public String getNext() {
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNext(String next) {
|
||||||
|
this.next = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link to the previous subset of resources qualified. \nEmpty if current subset is the first subset returned.
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "Link to the previous subset of resources qualified. \n" +
|
||||||
|
"Empty if current subset is the first subset returned.")
|
||||||
|
@JsonProperty("previous")
|
||||||
|
public String getPrevious() {
|
||||||
|
return previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrevious(String previous) {
|
||||||
|
this.previous = previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("notifications")
|
||||||
|
@ApiModelProperty("notifications")
|
||||||
|
public List<Notification> getNotifications() {
|
||||||
|
return notifications;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotifications(List<Notification> notifications) {
|
||||||
|
this.notifications = notifications;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("{");
|
||||||
|
|
||||||
|
sb.append(" count: ").append(count).append(",");
|
||||||
|
sb.append(" next: ").append(next).append(",");
|
||||||
|
sb.append(" previous: ").append(previous).append(",");
|
||||||
|
sb.append(" notifications: [").append(notifications).append("");
|
||||||
|
sb.append("]}");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.service.impl.util;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
|
||||||
|
import javax.ws.rs.BadRequestException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class InputValidationException extends BadRequestException implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 147843579458906890L;
|
||||||
|
|
||||||
|
public InputValidationException(ErrorResponse error) {
|
||||||
|
super(Response.status(Response.Status.BAD_REQUEST).entity(error).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,171 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.service.impl.util;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class RequestValidationUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if multiple criteria are specified in a conditional request.
|
||||||
|
*
|
||||||
|
* @param type Device type upon which the selection is done
|
||||||
|
* @param user Device user upon whom the selection is done
|
||||||
|
* @param roleName Role name upon which the selection is done
|
||||||
|
* @param ownership Ownership type upon which the selection is done
|
||||||
|
* @param status Enrollment status upon which the selection is done
|
||||||
|
*/
|
||||||
|
public static void validateSelectionCriteria(final String type, final String user, final String roleName,
|
||||||
|
final String ownership, final String status) {
|
||||||
|
List<String> inputs = new ArrayList<String>() {{
|
||||||
|
add(type);
|
||||||
|
add(user);
|
||||||
|
add(roleName);
|
||||||
|
add(ownership);
|
||||||
|
add(status);
|
||||||
|
}};
|
||||||
|
|
||||||
|
// boolean hasOneSelection = false;
|
||||||
|
// for (String i : inputs) {
|
||||||
|
// if (i == null) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// hasOneSelection = !hasOneSelection;
|
||||||
|
// if (!hasOneSelection) {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
int count = 0;
|
||||||
|
for (String i : inputs) {
|
||||||
|
if (i == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
if (count > 1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count > 1) {
|
||||||
|
throw new InputValidationException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("The incoming request has " +
|
||||||
|
"more than one selection criteria defined through query parameters").build());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void validateDeviceIdentifier(String type, String id) {
|
||||||
|
boolean isErroneous = false;
|
||||||
|
ErrorResponse.ErrorResponseBuilder error = new ErrorResponse.ErrorResponseBuilder();
|
||||||
|
if (id == null) {
|
||||||
|
isErroneous = true;
|
||||||
|
error.addErrorItem(null, "Device identifier cannot be null");
|
||||||
|
}
|
||||||
|
if (type == null) {
|
||||||
|
isErroneous = true;
|
||||||
|
error.addErrorItem(null, "Device type cannot be null");
|
||||||
|
}
|
||||||
|
if (isErroneous) {
|
||||||
|
throw new InputValidationException(error.setCode(400l).setMessage("Invalid device identifier").build());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void validateStatus(String status) {
|
||||||
|
if (status == null) {
|
||||||
|
throw new InputValidationException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
|
||||||
|
"Enrollment status type cannot be null").build());
|
||||||
|
}
|
||||||
|
switch (status) {
|
||||||
|
case "ACTIVE":
|
||||||
|
case "INACTIVE":
|
||||||
|
case "UNCLAIMED":
|
||||||
|
case "UNREACHABLE":
|
||||||
|
case "SUSPENDED":
|
||||||
|
case "DISENROLLMENT_REQUESTED":
|
||||||
|
case "REMOVED":
|
||||||
|
case "BLOCKED":
|
||||||
|
case "CREATED":
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
throw new InputValidationException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Invalid enrollment status type " +
|
||||||
|
"received. Valid status types are ACTIVE | INACTIVE | " +
|
||||||
|
"UNCLAIMED | UNREACHABLE | SUSPENDED | DISENROLLMENT_REQUESTED | REMOVED | " +
|
||||||
|
"BLOCKED | CREATED").build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void validateOwnershipType(String ownership) {
|
||||||
|
if (ownership == null) {
|
||||||
|
throw new InputValidationException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
|
||||||
|
"Ownership type cannot be null").build());
|
||||||
|
}
|
||||||
|
switch (ownership) {
|
||||||
|
case "BYOD":
|
||||||
|
case "COPE":
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
throw new InputValidationException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
|
||||||
|
"Invalid ownership type received. " +
|
||||||
|
"Valid ownership types are BYOD | COPE").build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void validateNotificationStatus(String status) {
|
||||||
|
if (status == null) {
|
||||||
|
throw new InputValidationException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(
|
||||||
|
"Notification status type cannot be null").build());
|
||||||
|
}
|
||||||
|
switch (status) {
|
||||||
|
case "NEW":
|
||||||
|
case "CHECKED":
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
throw new InputValidationException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Invalid notification status type " +
|
||||||
|
"received. Valid status types are NEW | CHECKED").build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void validateNotificationId(int id) {
|
||||||
|
if (id <= 0) {
|
||||||
|
throw new InputValidationException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Invalid notification id. " +
|
||||||
|
"Only positive integers are accepted as valid notification Ids").build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void validateNotification(Notification notification) {
|
||||||
|
if (notification == null) {
|
||||||
|
throw new InputValidationException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Notification content " +
|
||||||
|
"cannot be null").build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue