parent
8b6fe27cab
commit
4ccf018bb3
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.services.android.bean;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@XmlRootElement(
|
||||||
|
name = "PlatformConfiguration"
|
||||||
|
)
|
||||||
|
@XmlAccessorType(XmlAccessType.NONE)
|
||||||
|
@ApiModel(
|
||||||
|
value = "PlatformConfiguration",
|
||||||
|
description = "This class carries all information related to a Tenant configuration"
|
||||||
|
)
|
||||||
|
public class AndroidPlatformConfiguration implements Serializable {
|
||||||
|
public static final int INVALID_NOTIFIER_FREQUENCY = -1;
|
||||||
|
@XmlElement(
|
||||||
|
name = "type"
|
||||||
|
)
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "type",
|
||||||
|
value = "type of device",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
@NotNull
|
||||||
|
@Size(min = 2, max = 10)
|
||||||
|
@Pattern(regexp = "^[A-Za-z0-9]*$")
|
||||||
|
private String type;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "configuration",
|
||||||
|
value = "List of Configuration Entries",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
@XmlElement(
|
||||||
|
name = "configuration"
|
||||||
|
)
|
||||||
|
private List<ConfigurationEntry> configuration;
|
||||||
|
|
||||||
|
public AndroidPlatformConfiguration() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ConfigurationEntry> getConfiguration() {
|
||||||
|
return this.configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfiguration(List<ConfigurationEntry> configuration) {
|
||||||
|
this.configuration = configuration;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,206 @@
|
|||||||
|
package org.wso2.carbon.mdm.services.android.bean.wrapper;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ApiModel(
|
||||||
|
value = "Application",
|
||||||
|
description = "This class carries all information related application"
|
||||||
|
)
|
||||||
|
public class AndroidApplication implements Serializable{
|
||||||
|
private static final long serialVersionUID = 1998101711L;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "id",
|
||||||
|
value = "The ID given to the application when it is stored in the EMM database",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private int id;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "platform",
|
||||||
|
value = "The mobile device platform. It can be android, ios or windows",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String platform;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "category",
|
||||||
|
value = "The application category",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String category;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "name",
|
||||||
|
value = "The application\'s name",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String name;
|
||||||
|
private String locationUrl;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "imageUrl",
|
||||||
|
value = "The icon url of the application",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String imageUrl;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "version",
|
||||||
|
value = "The application\'s version",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String version;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "type",
|
||||||
|
value = "The application type",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String type;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "appProperties",
|
||||||
|
value = "The properties of the application",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private Properties appProperties;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "applicationIdentifier",
|
||||||
|
value = "The application identifier",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String applicationIdentifier;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "memoryUsage",
|
||||||
|
value = "Amount of memory used by the application",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private int memoryUsage;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "isActive",
|
||||||
|
value = "Is the application actively running",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private boolean isActive;
|
||||||
|
|
||||||
|
public AndroidApplication() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocationUrl() {
|
||||||
|
return this.locationUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocationUrl(String locationUrl) {
|
||||||
|
this.locationUrl = locationUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImageUrl() {
|
||||||
|
return this.imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageUrl(String imageUrl) {
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return this.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(String version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlatform() {
|
||||||
|
return this.platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlatform(String platform) {
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCategory() {
|
||||||
|
return this.category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategory(String category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getApplicationIdentifier() {
|
||||||
|
return this.applicationIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplicationIdentifier(String applicationIdentifier) {
|
||||||
|
this.applicationIdentifier = applicationIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMemoryUsage() {
|
||||||
|
return this.memoryUsage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMemoryUsage(int memoryUsage) {
|
||||||
|
this.memoryUsage = memoryUsage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if(this == o) {
|
||||||
|
return true;
|
||||||
|
} else if(o != null && this.getClass() == o.getClass()) {
|
||||||
|
AndroidApplication that = (AndroidApplication)o;
|
||||||
|
if(this.applicationIdentifier != null) {
|
||||||
|
if(!this.applicationIdentifier.equals(that.applicationIdentifier)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if(that.applicationIdentifier != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
int result = this.id;
|
||||||
|
result = 31 * result + (this.applicationIdentifier != null?this.applicationIdentifier.hashCode():0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Properties getAppProperties() {
|
||||||
|
return this.appProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppProperties(Properties appProperties) {
|
||||||
|
this.appProperties = appProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive() {
|
||||||
|
return this.isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActive(boolean active) {
|
||||||
|
this.isActive = active;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,221 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.services.android.bean.wrapper;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||||
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AndroidDevice implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1998101711L;
|
||||||
|
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "name",
|
||||||
|
value = "The device name that can be set on the device by the device user.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
@Size(min = 2, max = 45)
|
||||||
|
@Pattern(regexp = "^[A-Za-z0-9]*$")
|
||||||
|
private String name;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "type",
|
||||||
|
value = "The OS type of the device.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
@NotNull
|
||||||
|
@Size(min = 2, max = 45)
|
||||||
|
@Pattern(regexp = "^[A-Za-z]*$")
|
||||||
|
private String type;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "description",
|
||||||
|
value = "Additional information on the device.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String description;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "deviceIdentifier",
|
||||||
|
value = "This is a 64-bit number (as a hex string) that is randomly generated when the user first sets up the device and should remain constant for the lifetime of the user\'s device. The value may change if a factory reset is performed on the device.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
@NotNull
|
||||||
|
@Size(min = 2, max = 45)
|
||||||
|
@Pattern(regexp = "^[A-Za-z0-9]*$")
|
||||||
|
private String deviceIdentifier;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "enrolmentInfo",
|
||||||
|
value = "This defines the device registration related information. It is mandatory to define this information.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private EnrolmentInfo enrolmentInfo;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "features",
|
||||||
|
value = "List of features.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private List<Feature> features;
|
||||||
|
private List<Device.Property> properties;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "advanceInfo",
|
||||||
|
value = "This defines the device registration related information. It is mandatory to define this information.",
|
||||||
|
required = false
|
||||||
|
)
|
||||||
|
private DeviceInfo deviceInfo;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "applications",
|
||||||
|
value = "This represents the application list installed into the device",
|
||||||
|
required = false
|
||||||
|
)
|
||||||
|
private List<Application> applications;
|
||||||
|
|
||||||
|
public AndroidDevice() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AndroidDevice(String name, String type, String description, String deviceId, EnrolmentInfo enrolmentInfo, List<Feature> features, List<Device.Property> properties) {
|
||||||
|
this.name = name;
|
||||||
|
this.type = type;
|
||||||
|
this.description = description;
|
||||||
|
this.deviceIdentifier = deviceId;
|
||||||
|
this.enrolmentInfo = enrolmentInfo;
|
||||||
|
this.features = features;
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceIdentifier() {
|
||||||
|
return this.deviceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceIdentifier(String deviceIdentifier) {
|
||||||
|
this.deviceIdentifier = deviceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnrolmentInfo getEnrolmentInfo() {
|
||||||
|
return this.enrolmentInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnrolmentInfo(EnrolmentInfo enrolmentInfo) {
|
||||||
|
this.enrolmentInfo = enrolmentInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Feature> getFeatures() {
|
||||||
|
return this.features;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFeatures(List<Feature> features) {
|
||||||
|
this.features = features;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Device.Property> getProperties() {
|
||||||
|
return this.properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProperties(List<Device.Property> properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceInfo getDeviceInfo() {
|
||||||
|
return this.deviceInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceInfo(DeviceInfo deviceInfo) {
|
||||||
|
this.deviceInfo = deviceInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Application> getApplications() {
|
||||||
|
return this.applications;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplications(List<Application> applications) {
|
||||||
|
this.applications = applications;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "device [name=" + this.name + ";" + "type=" + this.type + ";" + "description=" + this.description + ";" + "identifier=" + this.deviceIdentifier + ";" + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof AndroidDevice)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
AndroidDevice device = (AndroidDevice) o;
|
||||||
|
return this.getDeviceIdentifier().equals(device.getDeviceIdentifier());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
return this.getDeviceIdentifier().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Property {
|
||||||
|
private String name;
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public Property() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,321 @@
|
|||||||
|
package org.wso2.carbon.mdm.services.android.bean.wrapper;
|
||||||
|
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ApiModel(
|
||||||
|
value = "DeviceInfo",
|
||||||
|
description = "This class carries all information related to the device information provided by a device."
|
||||||
|
)
|
||||||
|
public class AndroidDeviceInfo extends DeviceInfo implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1998101733L;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "IMEI",
|
||||||
|
value = "IMEI number of the device.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String IMEI;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "IMSI",
|
||||||
|
value = "IMSI number of the device.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String IMSI;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "deviceModel",
|
||||||
|
value = "Model of the device.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String deviceModel;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "vendor",
|
||||||
|
value = "Vendor of the device.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String vendor;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "osVersion",
|
||||||
|
value = "Operating system version.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String osVersion;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "batteryLevel",
|
||||||
|
value = "Battery level of the device.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private Double batteryLevel;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "internalTotalMemory",
|
||||||
|
value = "Total internal memory of the device.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private Double internalTotalMemory;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "internalAvailableMemory",
|
||||||
|
value = "Total available memory of the device.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private Double internalAvailableMemory;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "externalTotalMemory",
|
||||||
|
value = "Total external memory of the device.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private Double externalTotalMemory;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "externalAvailableMemory",
|
||||||
|
value = "Total external memory avilable of the device.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private Double externalAvailableMemory;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "operator",
|
||||||
|
value = "Mobile operator of the device.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String operator;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "connectionType",
|
||||||
|
value = "How the device is connected to the network.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String connectionType;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "mobileSignalStrength",
|
||||||
|
value = "Current mobile signal strength.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private Double mobileSignalStrength;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "ssid",
|
||||||
|
value = "ssid of the connected WiFi.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private String ssid;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "cpuUsage",
|
||||||
|
value = "Current total cpu usage.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private Double cpuUsage;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "totalRAMMemory",
|
||||||
|
value = "Total Ram memory size.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private Double totalRAMMemory;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "availableRAMMemory",
|
||||||
|
value = "Available total memory of RAM.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private Double availableRAMMemory;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "pluggedIn",
|
||||||
|
value = "Whether the device is plugged into power or not.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private boolean pluggedIn;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "updatedTime",
|
||||||
|
value = "Device updated time.",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private Date updatedTime;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "location",
|
||||||
|
value = "Last updated location of the device",
|
||||||
|
required = false
|
||||||
|
)
|
||||||
|
private DeviceLocation location;
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "deviceDetailsMap",
|
||||||
|
value = ".",
|
||||||
|
required = true
|
||||||
|
)
|
||||||
|
private Map<String, String> deviceDetailsMap = new HashMap();
|
||||||
|
|
||||||
|
public AndroidDeviceInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceLocation getLocation() {
|
||||||
|
return this.location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(DeviceLocation location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIMEI() {
|
||||||
|
return this.IMEI != null?this.IMEI:"";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIMEI(String IMEI) {
|
||||||
|
this.IMEI = IMEI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIMSI() {
|
||||||
|
return this.IMSI != null?this.IMSI:"";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIMSI(String IMSI) {
|
||||||
|
this.IMSI = IMSI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceModel() {
|
||||||
|
return this.deviceModel != null?this.deviceModel:"";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceModel(String deviceModel) {
|
||||||
|
this.deviceModel = deviceModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVendor() {
|
||||||
|
return this.vendor != null?this.vendor:"";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVendor(String vendor) {
|
||||||
|
this.vendor = vendor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOsVersion() {
|
||||||
|
return this.osVersion != null?this.osVersion:"";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOsVersion(String osVersion) {
|
||||||
|
this.osVersion = osVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getBatteryLevel() {
|
||||||
|
return this.batteryLevel != null?this.batteryLevel:Double.valueOf(0.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBatteryLevel(Double batteryLevel) {
|
||||||
|
this.batteryLevel = batteryLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getInternalTotalMemory() {
|
||||||
|
return this.internalTotalMemory != null?this.internalTotalMemory:Double.valueOf(0.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInternalTotalMemory(Double internalTotalMemory) {
|
||||||
|
this.internalTotalMemory = internalTotalMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getInternalAvailableMemory() {
|
||||||
|
return this.internalAvailableMemory != null?this.internalAvailableMemory:Double.valueOf(0.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInternalAvailableMemory(Double internalAvailableMemory) {
|
||||||
|
this.internalAvailableMemory = internalAvailableMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getExternalTotalMemory() {
|
||||||
|
return this.externalTotalMemory != null?this.externalTotalMemory:Double.valueOf(0.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExternalTotalMemory(Double externalTotalMemory) {
|
||||||
|
this.externalTotalMemory = externalTotalMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getExternalAvailableMemory() {
|
||||||
|
return this.externalAvailableMemory != null?this.externalAvailableMemory:Double.valueOf(0.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExternalAvailableMemory(Double externalAvailableMemory) {
|
||||||
|
this.externalAvailableMemory = externalAvailableMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOperator() {
|
||||||
|
return this.operator != null?this.operator:"";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOperator(String operator) {
|
||||||
|
this.operator = operator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConnectionType() {
|
||||||
|
return this.connectionType != null?this.connectionType:"";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnectionType(String connectionType) {
|
||||||
|
this.connectionType = connectionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getMobileSignalStrength() {
|
||||||
|
return this.mobileSignalStrength != null?this.mobileSignalStrength:Double.valueOf(0.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMobileSignalStrength(Double mobileSignalStrength) {
|
||||||
|
this.mobileSignalStrength = mobileSignalStrength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSsid() {
|
||||||
|
return this.ssid != null?this.ssid:"";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSsid(String ssid) {
|
||||||
|
this.ssid = ssid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getCpuUsage() {
|
||||||
|
return this.cpuUsage != null?this.cpuUsage:Double.valueOf(0.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCpuUsage(Double cpuUsage) {
|
||||||
|
this.cpuUsage = cpuUsage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getTotalRAMMemory() {
|
||||||
|
return this.totalRAMMemory != null?this.totalRAMMemory:Double.valueOf(0.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalRAMMemory(Double totalRAMMemory) {
|
||||||
|
this.totalRAMMemory = totalRAMMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getAvailableRAMMemory() {
|
||||||
|
return this.availableRAMMemory != null?this.availableRAMMemory:Double.valueOf(0.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAvailableRAMMemory(Double availableRAMMemory) {
|
||||||
|
this.availableRAMMemory = availableRAMMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPluggedIn() {
|
||||||
|
return this.pluggedIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPluggedIn(boolean pluggedIn) {
|
||||||
|
this.pluggedIn = pluggedIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getUpdatedTime() {
|
||||||
|
if(this.updatedTime.equals((Object)null)) {
|
||||||
|
this.updatedTime = new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.updatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatedTime(Date updatedTime) {
|
||||||
|
this.updatedTime = updatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceDetailsMap(Map<String, String> deviceDetailsMap) {
|
||||||
|
this.deviceDetailsMap = deviceDetailsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getDeviceDetailsMap() {
|
||||||
|
return this.deviceDetailsMap;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.services.android.bean.wrapper;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@ApiModel(value = "EnrolmentInfo", description = "This class carries all information related to a devices enrollment" +
|
||||||
|
" status.")
|
||||||
|
public class DeviceEnrollmentInfo extends EnrolmentInfo implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1998101712L;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "device", value = "Enrolled device.", required = true)
|
||||||
|
private Device device;
|
||||||
|
@ApiModelProperty(name = "dateOfEnrolment", value = "Date of the device enrollment.", required = true)
|
||||||
|
private Long dateOfEnrolment;
|
||||||
|
@ApiModelProperty(name = "dateOfLastUpdate", value = "Date of the device's last update.", required = true)
|
||||||
|
private Long dateOfLastUpdate;
|
||||||
|
@ApiModelProperty(name = "ownership", value = "Defines the ownership details. The ownership type can be any of the" +
|
||||||
|
" following values.\n" +
|
||||||
|
"BYOD - Bring your own device (BYOD).\n" +
|
||||||
|
"COPE - Corporate owned personally enabled (COPE).", required = true)
|
||||||
|
private OwnerShip ownership;
|
||||||
|
@ApiModelProperty(name = "status", value = "Current status of the device, such as whether the device " +
|
||||||
|
"is active, removed etc.", required = true)
|
||||||
|
private Status status;
|
||||||
|
@ApiModelProperty(name = "owner", value = "The device owner's name.", required = true)
|
||||||
|
private String owner;
|
||||||
|
|
||||||
|
public DeviceEnrollmentInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceEnrollmentInfo(Device device, String owner, OwnerShip ownership, Status status) {
|
||||||
|
this.device = device;
|
||||||
|
this.owner = owner;
|
||||||
|
this.ownership = ownership;
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getDateOfEnrolment() {
|
||||||
|
return dateOfEnrolment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDateOfEnrolment(Long dateOfEnrolment) {
|
||||||
|
this.dateOfEnrolment = dateOfEnrolment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getDateOfLastUpdate() {
|
||||||
|
return dateOfLastUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDateOfLastUpdate(Long dateOfLastUpdate) {
|
||||||
|
this.dateOfLastUpdate = dateOfLastUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OwnerShip getOwnership() {
|
||||||
|
return ownership;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwnership(OwnerShip ownership) {
|
||||||
|
this.ownership = ownership;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Status getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Status status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwner(String owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Device getDevice() {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDevice(Device device) {
|
||||||
|
this.device = device;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj instanceof DeviceEnrollmentInfo) {
|
||||||
|
DeviceEnrollmentInfo tempInfo = (DeviceEnrollmentInfo) obj;
|
||||||
|
if (this.owner != null && this.ownership != null) {
|
||||||
|
if (this.owner.equals(tempInfo.getOwner()) && this.ownership.equals(tempInfo.getOwnership())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return owner.hashCode() ^ ownership.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -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.mdm.services.android.exception;
|
||||||
|
|
||||||
|
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<ErrorDTO> 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<ErrorDTO> 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<ErrorDTO> error = new ArrayList<>();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.services.android.exception;
|
||||||
|
|
||||||
|
import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
|
||||||
|
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception class that is corresponding to 401 Forbidden response
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ForbiddenException extends WebApplicationException {
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public ForbiddenException() {
|
||||||
|
super(Response.status(Response.Status.FORBIDDEN)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ForbiddenException(ErrorDTO errorDTO) {
|
||||||
|
super(Response.status(Response.Status.FORBIDDEN)
|
||||||
|
.entity(errorDTO)
|
||||||
|
.header(AndroidConstants.HEADER_CONTENT_TYPE, AndroidConstants.APPLICATION_JSON)
|
||||||
|
.build());
|
||||||
|
message = errorDTO.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.services.android.exception;
|
||||||
|
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils;
|
||||||
|
|
||||||
|
import javax.naming.AuthenticationException;
|
||||||
|
import javax.validation.ConstraintViolationException;
|
||||||
|
import javax.ws.rs.ClientErrorException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.ext.ExceptionMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the cxf level exceptions.
|
||||||
|
*/
|
||||||
|
public class GlobalThrowableMapper implements ExceptionMapper {
|
||||||
|
private static final Log log = LogFactory.getLog(GlobalThrowableMapper.class);
|
||||||
|
|
||||||
|
private ErrorDTO e500 = new ErrorDTO();
|
||||||
|
|
||||||
|
GlobalThrowableMapper() {
|
||||||
|
e500.setCode((long) 500);
|
||||||
|
e500.setMessage("Internal server error.");
|
||||||
|
e500.setMoreInfo("");
|
||||||
|
e500.setDescription("The server encountered an internal error. Please contact administrator.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response toResponse(Throwable e) {
|
||||||
|
|
||||||
|
if (e instanceof JsonParseException) {
|
||||||
|
String errorMessage = "Malformed request body.";
|
||||||
|
log.error(errorMessage);
|
||||||
|
return AndroidDeviceUtils.buildBadRequestException(errorMessage).getResponse();
|
||||||
|
|
||||||
|
}
|
||||||
|
if (e instanceof NotFoundException) {
|
||||||
|
return ((NotFoundException) e).getResponse();
|
||||||
|
}
|
||||||
|
if (e instanceof ConstraintViolationException) {
|
||||||
|
log.error("Constraint violation", e);
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).header("Content-Type", "application/json")
|
||||||
|
.entity(400l).build();
|
||||||
|
}
|
||||||
|
if (e instanceof UnexpectedServerErrorException) {
|
||||||
|
log.error("Unexpected server error", e);
|
||||||
|
return ((UnexpectedServerErrorException) e).getResponse();
|
||||||
|
}
|
||||||
|
if (e instanceof ConstraintViolationException) {
|
||||||
|
return ((ParameterValidationException) e).getResponse();
|
||||||
|
}
|
||||||
|
if (e instanceof IllegalArgumentException) {
|
||||||
|
log.error("Illegal exception.", e);
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).header("Content-Type", "application/json")
|
||||||
|
.entity(400l).build();
|
||||||
|
}
|
||||||
|
if (e instanceof ClientErrorException) {
|
||||||
|
log.error("Client error", e);
|
||||||
|
return ((ClientErrorException) e).getResponse();
|
||||||
|
}
|
||||||
|
if (e instanceof AuthenticationException) {
|
||||||
|
ErrorDTO errorDetail = new ErrorDTO();
|
||||||
|
errorDetail.setCode((long) 401);
|
||||||
|
errorDetail.setMoreInfo("");
|
||||||
|
errorDetail.setMessage("");
|
||||||
|
errorDetail.setDescription(e.getMessage());
|
||||||
|
return Response
|
||||||
|
.status(Response.Status.UNAUTHORIZED)
|
||||||
|
.entity(errorDetail)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
if (e instanceof ForbiddenException) {
|
||||||
|
log.error("Resource forbidden", e);
|
||||||
|
return ((ForbiddenException) e).getResponse();
|
||||||
|
}
|
||||||
|
//unknown exception log and return
|
||||||
|
log.error("An Unknown exception has been captured by global exception mapper.", e);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).header("Content-Type", "application/json")
|
||||||
|
.entity(e500).build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.services.android.exception;
|
||||||
|
|
||||||
|
import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
|
||||||
|
import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ParameterValidationException extends WebApplicationException {
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
public <T> ParameterValidationException(Set<ConstraintViolation<T>> violations) {
|
||||||
|
super(Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity(AndroidDeviceUtils.getConstraintViolationErrorDTO(violations))
|
||||||
|
.header(AndroidConstants.HEADER_CONTENT_TYPE, AndroidConstants.APPLICATION_JSON)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
//Set the error message
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
for (ConstraintViolation violation : violations) {
|
||||||
|
stringBuilder.append(violation.getRootBeanClass().getSimpleName());
|
||||||
|
stringBuilder.append(".");
|
||||||
|
stringBuilder.append(violation.getPropertyPath());
|
||||||
|
stringBuilder.append(": ");
|
||||||
|
stringBuilder.append(violation.getMessage());
|
||||||
|
stringBuilder.append(", ");
|
||||||
|
}
|
||||||
|
message = stringBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* 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.mdm.services.android.exception;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.cxf.interceptor.Fault;
|
||||||
|
import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
|
||||||
|
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
|
||||||
|
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
|
||||||
|
import org.apache.cxf.message.Message;
|
||||||
|
import org.apache.cxf.message.MessageContentsList;
|
||||||
|
import org.apache.cxf.phase.AbstractPhaseInterceptor;
|
||||||
|
import org.apache.cxf.phase.Phase;
|
||||||
|
|
||||||
|
import javax.validation.*;
|
||||||
|
import javax.validation.executable.ExecutableValidator;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ValidationInterceptor extends AbstractPhaseInterceptor<Message> {
|
||||||
|
|
||||||
|
private Log log = LogFactory.getLog(getClass());
|
||||||
|
private Validator validator = null; //validator interface is thread-safe
|
||||||
|
|
||||||
|
public ValidationInterceptor() {
|
||||||
|
super(Phase.PRE_INVOKE);
|
||||||
|
ValidatorFactory defaultFactory = Validation.buildDefaultValidatorFactory();
|
||||||
|
validator = defaultFactory.getValidator();
|
||||||
|
if (validator == null) {
|
||||||
|
log.warn("Bean Validation provider could not be found, no validation will be performed");
|
||||||
|
} else {
|
||||||
|
log.debug("Validation In-Interceptor initialized successfully");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message message) throws Fault {
|
||||||
|
final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
|
||||||
|
if (operationResource == null) {
|
||||||
|
log.info("OperationResourceInfo is not available, skipping validation");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
|
||||||
|
if (classResource == null) {
|
||||||
|
log.info("ClassResourceInfo is not available, skipping validation");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ResourceProvider resourceProvider = classResource.getResourceProvider();
|
||||||
|
if (resourceProvider == null) {
|
||||||
|
log.info("ResourceProvider is not available, skipping validation");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<Object> arguments = MessageContentsList.getContentsList(message);
|
||||||
|
final Method method = operationResource.getAnnotatedMethod();
|
||||||
|
final Object instance = resourceProvider.getInstance(message);
|
||||||
|
if (method != null && arguments != null) {
|
||||||
|
//validate the parameters(arguments) over the invoked method
|
||||||
|
validate(method, arguments.toArray(), instance);
|
||||||
|
|
||||||
|
//validate the fields of each argument
|
||||||
|
for (Object arg : arguments) {
|
||||||
|
if (arg != null)
|
||||||
|
validate(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public <T> void validate(final Method method, final Object[] arguments, final T instance) {
|
||||||
|
if (validator == null) {
|
||||||
|
log.warn("Bean Validation provider could not be found, no validation will be performed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExecutableValidator methodValidator = validator.forExecutables();
|
||||||
|
Set<ConstraintViolation<T>> violations = methodValidator.validateParameters(instance,
|
||||||
|
method, arguments);
|
||||||
|
|
||||||
|
if (!violations.isEmpty()) {
|
||||||
|
throw new ConstraintViolationException(violations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void validate(final T object) {
|
||||||
|
if (validator == null) {
|
||||||
|
log.warn("Bean Validation provider could be found, no validation will be performed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<ConstraintViolation<T>> violations = validator.validate(object);
|
||||||
|
|
||||||
|
if (!violations.isEmpty()) {
|
||||||
|
throw new ConstraintViolationException(violations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleFault(Message messageParam) {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue