diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/pom.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/pom.xml new file mode 100644 index 000000000..f22c2e2a8 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/pom.xml @@ -0,0 +1,360 @@ + + + + + + android-plugin + org.wso2.carbon.devicemgt-plugins + 4.0.102-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.mobile.android.v09.api + WSO2 Carbon - Android JAX-RS v09 API + Android JAX-RS v09 API + war + + + + + maven-compiler-plugin + + 1.8 + 1.8 + + 2.3.2 + + + maven-war-plugin + 2.2 + + WEB-INF/lib/*cxf*.jar + api#device-mgt#android#v0.9 + + + + org.jacoco + jacoco-maven-plugin + + ${basedir}/target/coverage-reports/jacoco-unit.exec + + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + ${basedir}/target/coverage-reports/jacoco-unit.exec + ${basedir}/target/coverage-reports/site + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + file:src/test/resources/log4j.properties + + + src/test/resources/testng.xml + + + + + + + + + deploy + + compile + + + org.apache.maven.plugins + maven-antrun-plugin + 1.7 + + + compile + + run + + + + + + + + + + + + + + + org.jacoco + jacoco-maven-plugin + + ${basedir}/target/coverage-reports/jacoco-unit.exec + + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + ${basedir}/target/coverage-reports/jacoco-unit.exec + ${basedir}/target/coverage-reports/site + + + + + + + + + + client + + test + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + test + + java + + + + + + + + + + + + + org.apache.cxf + cxf-rt-frontend-jaxws + + + org.apache.cxf + cxf-rt-frontend-jaxrs + + + org.apache.cxf + cxf-rt-transports-http + + + javax.ws.rs + jsr311-api + provided + + + org.wso2.carbon + org.wso2.carbon.utils + provided + + + org.wso2.carbon + org.wso2.carbon.logging + provided + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + provided + + + org.slf4j + slf4j-api + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.mgt.common + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.mgt.core + provided + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.mobile.android + provided + + + commons-httpclient.wso2 + commons-httpclient + provided + + + com.google.code.gson + gson + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics.data.publisher + provided + + + org.slf4j + slf4j-api + + + + + org.wso2.carbon.analytics + org.wso2.carbon.analytics.api + provided + + + io.swagger + swagger-annotations + + + io.swagger + swagger-core + + + org.slf4j + slf4j-api + + + + + io.swagger + swagger-jaxrs + + + org.slf4j + slf4j-api + + + + + javax.servlet + servlet-api + provided + + + org.hibernate + hibernate-validator + + + javax.ws.rs + javax.ws.rs-api + + + org.testng + testng + test + + + org.powermock + powermock-module-testng + test + + + org.powermock + powermock-api-mockito + test + + + com.h2database.wso2 + h2-database-engine + test + + + org.wso2.carbon + org.wso2.carbon.queuing + test + + + org.wso2.carbon + org.wso2.carbon.ndatasource.core + test + + + commons-dbcp.wso2 + commons-dbcp + test + + + commons-pool.wso2 + commons-pool + test + + + org.wso2.carbon + javax.cache.wso2 + test + + + javassist + javassist + test + + + org.codehaus.jackson + jackson-core-asl + + + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AndroidOperation.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AndroidOperation.java new file mode 100644 index 000000000..3361b90dc --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AndroidOperation.java @@ -0,0 +1,36 @@ +/* + * 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 com.google.gson.Gson; +/* +* This abstract class is used for extending generic functions with regard to operation. +*/ +public abstract class AndroidOperation { + + /* + * This method is used to convert operation object to a json format. + * + * @return json formatted String. + */ + public String toJSON() { + Gson gson = new Gson(); + return gson.toJson(this); + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AndroidPlatformConfiguration.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AndroidPlatformConfiguration.java new file mode 100644 index 000000000..9832c3f03 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AndroidPlatformConfiguration.java @@ -0,0 +1,81 @@ +/* + * 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.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 the information related to Android platform configurations." +) +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 + ) + @Size(min = 2, max = 10) + private String type; + @ApiModelProperty( + name = "configuration", + value = "List of Configuration Entries", + required = true + ) + @XmlElement( + name = "configuration" + ) + private List configuration; + + public AndroidPlatformConfiguration() { + } + + public String getType() { + return this.type; + } + + public void setType(String type) { + this.type = type; + } + + public List getConfiguration() { + return this.configuration; + } + + public void setConfiguration(List configuration) { + this.configuration = configuration; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AppRestriction.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AppRestriction.java new file mode 100644 index 000000000..2c8d8c93d --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/AppRestriction.java @@ -0,0 +1,54 @@ +/* + * 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 java.io.Serializable; +import java.util.List; + +/** + * This class represents information of configuring App Restriction ex: White list and Black list + */ +@ApiModel(value = "AppRestriction", + description = "This class carries all information related to application restriction.") +public class AppRestriction extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "restrictionType", value = "Restriction type of the application.", required = true) + private String restrictionType; + @ApiModelProperty(name = "restrictedList", value = "Device id list of the operation to be executed.", required = true) + private List restrictedList; + + public String getRestrictionType() { + return restrictionType; + } + + public void setRestrictionType(String restrictionType) { + this.restrictionType = restrictionType; + } + + public List getRestrictedList() { + return restrictedList; + } + + public void setRestrictedList(List restrictedList) { + this.restrictedList = restrictedList; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationInstallation.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationInstallation.java new file mode 100644 index 000000000..4c90d42cb --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationInstallation.java @@ -0,0 +1,84 @@ +/* + * 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 javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; +import java.io.Serializable; + +/** + * This class represents the information of install application operation. + */ +@ApiModel(value = "ApplicationInstallation", + description = "This class carries all information related to install application") +public class ApplicationInstallation extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "appIdentifier", value = "Application Identifier", required = true) + @Size(min = 2, max = 45) + @Pattern(regexp = "^[A-Za-z0-9]*$") + private String appIdentifier; + + @ApiModelProperty(name = "type", value = "Application type(Enterprise/Web/public)", required = true) + @Size(min = 2, max = 12) + @Pattern(regexp = "^[A-Za-z]*$") + private String type; + + @ApiModelProperty(name = "url", value = "Application URL", required = true) + private String url; + + @ApiModelProperty(name = "schedule", value = "Schedule of the App installation.") + private String schedule; + + public String getAppIdentifier() { + return appIdentifier; + } + + public void setAppIdentifier(String appIdentifier) { + this.appIdentifier = appIdentifier; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + @SuppressWarnings("unused") + public String getSchedule() { + return schedule; + } + + @SuppressWarnings("unused") + public void setSchedule(String schedule) { + this.schedule = schedule; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUninstallation.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUninstallation.java new file mode 100644 index 000000000..a5356ae59 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUninstallation.java @@ -0,0 +1,62 @@ +/* + * 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 javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; +import java.io.Serializable; + +/** + * This class represents the information of uninstall application operation. + */ +@ApiModel(value = "ApplicationUninstallation", + description = "This class carries all information related to application uninstallation.") +public class ApplicationUninstallation extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "appIdentifier", value = "The package name of the application to be uninstalled.", required = true) + @Size(min = 2, max = 45) + @Pattern(regexp = "^[A-Za-z0-9]*$") + private String appIdentifier; + + @ApiModelProperty(name = "type", value = "The type of the application. The following types of applications " + + "are supported: enterprise, public and webapp.", required = true) + @Size(min = 2, max = 12) + @Pattern(regexp = "^[A-Za-z]*$") + private String type; + + public String getAppIdentifier() { + return appIdentifier; + } + + public void setAppIdentifier(String appIdentifier) { + this.appIdentifier = appIdentifier; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUpdate.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUpdate.java new file mode 100644 index 000000000..95241b444 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ApplicationUpdate.java @@ -0,0 +1,81 @@ +/* + * 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 javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; +import java.io.Serializable; + +/** + * This class represents the information of Update application operation. + */ +@ApiModel(value = "ApplicationUpdate", + description = "This class carries all information related to application update.") +public class ApplicationUpdate extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "appIdentifier", value = "The package name of the application " + + "to be update.", required = true) + @Size(min = 2, max = 45) + @Pattern(regexp = "^[A-Za-z0-9]*$") + private String appIdentifier; + @ApiModelProperty(name = "type", value = "The type of the application. The following types of applications " + + "are supported: enterprise, public and webapp.", required = true) + @Size(min = 2, max = 12) + @Pattern(regexp = "^[A-Za-z]*$") + private String type; + @ApiModelProperty(name = "url", value = "The URL of the application.", required = true) + private String url; + @ApiModelProperty(name = "schedule", value = "Application update schedule.", required = false) + private String schedule; + + public String getAppIdentifier() { + return appIdentifier; + } + + public void setAppIdentifier(String appIdentifier) { + this.appIdentifier = appIdentifier; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getSchedule() { + return schedule; + } + + public void setSchedule(String schedule) { + this.schedule = schedule; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/BlacklistApplications.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/BlacklistApplications.java new file mode 100644 index 000000000..b7db28976 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/BlacklistApplications.java @@ -0,0 +1,48 @@ +/* + * 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 javax.validation.constraints.Size; +import java.io.Serializable; +import java.util.List; + +/** + * This class represents the blacklist applications information. + */ +@ApiModel(value = "BlacklistApplications", + description = "This class represents the blacklist applications information.") +public class BlacklistApplications extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "appIdentifiers", value = "A list of application package names to be blacklisted.", + required = true) + @Size(min = 1, max = 45) + private List appIdentifiers; + + public List getAppIdentifier() { + return appIdentifiers; + } + + public void setAppIdentifier(List appIdentifiers) { + this.appIdentifiers = appIdentifiers; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Camera.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Camera.java new file mode 100644 index 000000000..0dad70364 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Camera.java @@ -0,0 +1,44 @@ +/* + * 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 java.io.Serializable; + +/** + * This class represents the information of camera operation. + */ +@ApiModel(value = "Camera", + description = "This class represents the information of camera operation.") +public class Camera extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "enabled", value = "Disable the camera on the device by assigning false as the value or " + + "enable the camera on the device to function by defining true as the value.", required = true) + private boolean enabled; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceEncryption.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceEncryption.java new file mode 100644 index 000000000..68ab6ae94 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceEncryption.java @@ -0,0 +1,44 @@ +/* + * 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 java.io.Serializable; + +/** + * This class represents the information of encrypt operation. + */ + +@ApiModel(value = "DeviceEncryption", + description = "Details related device encryption.") +public class DeviceEncryption extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "encrypted", value = "Whether to enable encryption or not.", required = true) + private boolean encrypted; + + public boolean isEncrypted() { + return encrypted; + } + + public void setEncrypted(boolean encrypted) { + this.encrypted = encrypted; + } +} \ No newline at end of file diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceLock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceLock.java new file mode 100644 index 000000000..e76ff6f1a --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceLock.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.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; +@ApiModel(value = "DeviceLock", + description = "This class carries all information related to device lock operation.") +public class DeviceLock extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "message", value = "Pop up message of the lock operation.", required = false) + private String message; + @ApiModelProperty(name = "isHardLockEnabled", value = "Hard lock enable status of the Device", required = true) + private boolean isHardLockEnabled; + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isHardLockEnabled() { + return isHardLockEnabled; + } + + public void setHardLockEnabled(boolean hardLockEnabled) { + isHardLockEnabled = hardLockEnabled; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceState.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceState.java new file mode 100644 index 000000000..fb23b0fcc --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/DeviceState.java @@ -0,0 +1,92 @@ +/* + * 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.codehaus.jackson.annotate.JsonIgnoreProperties; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@XmlRootElement +/** + * Store Device state event/data for androidDevice. + */ +@ApiModel(value = "DeviceState", + description = "This class carries all information related to device state.") +@JsonIgnoreProperties(ignoreUnknown = true) +public class DeviceState { + + @XmlElementWrapper(required = true, name = "values") + @ApiModelProperty(name = "values", value = "Device and its statuses.", required = true) + private Map values; + + /** The id. */ + @XmlElement(required = false, name = "id") + @ApiModelProperty(name = "id", value = "Identification code.", required = true) + private String id; + + /** + * Gets the values. + * @return the values + */ + public Map getValues() { + return values; + } + + /** + * Sets the values. + * @param values the values + */ + public void setValues(Map values) { + this.values = values; + } + + /** + * Sets the id. + * @param id the new id + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the id. + * @return the id + */ + public String getId() { + return id; + } + + @Override + public String toString(){ + List valueList = new ArrayList(); + for (Map.Entry entry : values.entrySet()) { + valueList.add(entry.getKey() + ":" + entry.getValue()); + } + return valueList.toString(); + + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Disenrollment.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Disenrollment.java new file mode 100644 index 000000000..c591d2ae0 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Disenrollment.java @@ -0,0 +1,40 @@ +/* + * 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.operation.mgt.Operation; +import java.io.Serializable; + +@ApiModel(value = "Disenrollment", + description = "Details related to disenrolling a device.") +public class Disenrollment extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "enabled", value = "Whether to enable disenrollment or not.", required = true) + private boolean enabled; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ErrorListItem.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ErrorListItem.java new file mode 100644 index 000000000..1e48b0183 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/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.mdm.services.android.bean; + +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/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ErrorResponse.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ErrorResponse.java new file mode 100644 index 000000000..457782ade --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/ErrorResponse.java @@ -0,0 +1,190 @@ +/* + * 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 com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.ArrayList; +import java.util.List; + +@ApiModel(description = "") +public class ErrorResponse { + + private Long code = null; + private String message = null; + private String description = null; + private String moreInfo = null; + private List errorItems = new ArrayList<>(); + + @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/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/FileTransfer.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/FileTransfer.java new file mode 100644 index 000000000..2e8af23a7 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/FileTransfer.java @@ -0,0 +1,76 @@ +/* +* Copyright (c) 2017, 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.mdm.services.android.bean.AndroidOperation; + +import java.io.Serializable; + +/** + * This class represents the information of file transfer operation payload. + */ +@ApiModel(value = "FileTransfer", + description = "This class carries all information related to file transfer operation.") +public class FileTransfer extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "fileURL", value = "File URL", required = true) + private String fileURL; + + @ApiModelProperty(name = "userName", value = "User Name", required = true) + private String userName; + + @ApiModelProperty(name = "ftpPassword", value = "FTP password", required = true) + private String ftpPassword; + + @ApiModelProperty(name = "fileLocation", value = "fileLocation", required = true) + private String fileLocation; + + public String getFileURL() { + return fileURL; + } + + public void setFileURL(String fileURL) { + this.fileURL = fileURL; + } + + public String getFtpPassword() { + return ftpPassword; + } + + public void setFtpPassword(String ftpPassword) { + this.ftpPassword = ftpPassword; + } + + public String getFileLocation() { + return fileLocation; + } + + public void setFileLocation(String fileLocation) { + this.fileLocation = fileLocation; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/LockCode.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/LockCode.java new file mode 100644 index 000000000..4c2764dad --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/LockCode.java @@ -0,0 +1,43 @@ +/* + * 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 java.io.Serializable; + +/** + * This class represents the information of changing lock code operation. + */ +@ApiModel(value = "LockCode", + description = "Details related to lock code sent on device.") +public class LockCode extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "lockCode", value = "The lock code to be sent to the device.", required = true) + private String lockCode; + + public String getLockCode() { + return lockCode; + } + + public void setLockCode(String lockCode) { + this.lockCode = lockCode; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Notification.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Notification.java new file mode 100644 index 000000000..7cc4d4627 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Notification.java @@ -0,0 +1,54 @@ +/* + * 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 java.io.Serializable; + +/** + * This class represents the information of sending notification operation. + */ +@ApiModel(value = "Notification", + description = "Details related to notifications passed to device.") +public class Notification extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "messageText", value = "The message text to be sent to the device.", required = true) + private String messageText; + + @ApiModelProperty(name = "messageTitle", value = "The message title to be sent to the device.", required = true) + private String messageTitle; + + public String getMessageText() { + return messageText; + } + + public void setMessageText(String messageText) { + this.messageText = messageText; + } + + public String getMessageTitle() { + return messageTitle; + } + + public void setMessageTitle(String messageTitle) { + this.messageTitle = messageTitle; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/PasscodePolicy.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/PasscodePolicy.java new file mode 100644 index 000000000..c2e48ce70 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/PasscodePolicy.java @@ -0,0 +1,121 @@ +/* + * 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 javax.validation.constraints.Max; +import java.io.Serializable; + +/** + * This class represents the information of setting up password policy. + */ +@ApiModel(value = "PasscodePolicy", description = "This class represents the information of setting up " + + "password policy") +public class PasscodePolicy extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "maxFailedAttempts", value = "The maximum number of times the end-user can enter" + + " his/her device passcode incorrectly. EMM will take different courses of action based on the" + + " OS when the failed attempts exceed the maximum failed attempts. Android devices will be " + + "automatically reset to the original factory settings", required = true) + + @Max(10) + private int maxFailedAttempts; + @ApiModelProperty(name = "minLength", value = "The minimum number of alphanumerical values that the " + + "end-user can enter as his/her passcode", required = true) + @Max(15) + private int minLength; + @ApiModelProperty(name = "pinHistory", value = "The end-user will not be allowed to reuse a passcode that" + + " he/she previously entered until he/she exceeds the set pin history length", required = true) + @Max(50) + private int pinHistory; + @ApiModelProperty(name = "minComplexChars", value = "The minimum number of special characters that the " + + "end-user will have to enter in his/her passcode", required = true) + @Max(5) + private int minComplexChars; + @ApiModelProperty(name = "maxPINAgeInDays", value = "The number of days after which the device owner has" + + " to change his/her passcode", required = true) + @Max(730) + private int maxPINAgeInDays; + @ApiModelProperty(name = "requireAlphanumeric", value = "Whether or not it is mandatory for the end-user" + + " to have a mix of digits and characters in his/her passcode", required = true) + private boolean requireAlphanumeric; + @ApiModelProperty(name = "allowSimple", value = "If this field is set to 'true', the device owner will be" + + " able to have a simple passcode and the following criteria in the passcode policy will not be" + + " applicable:\n" + + "Minimum length\n" + "Minimum complex characters", required = true) + private boolean allowSimple; + + public int getMaxFailedAttempts() { + return maxFailedAttempts; + } + + public void setMaxFailedAttempts(int maxFailedAttempts) { + this.maxFailedAttempts = maxFailedAttempts; + } + + public int getMinLength() { + return minLength; + } + + public void setMinLength(int minLength) { + this.minLength = minLength; + } + + public int getPinHistory() { + return pinHistory; + } + + public void setPinHistory(int pinHistory) { + this.pinHistory = pinHistory; + } + + public int getMinComplexChars() { + return minComplexChars; + } + + public void setMinComplexChars(int minComplexChars) { + this.minComplexChars = minComplexChars; + } + + public int getMaxPINAgeInDays() { + return maxPINAgeInDays; + } + + public void setMaxPINAgeInDays(int maxPINAgeInDays) { + this.maxPINAgeInDays = maxPINAgeInDays; + } + + public boolean isRequireAlphanumeric() { + return requireAlphanumeric; + } + + public void setRequireAlphanumeric(boolean requireAlphanumeric) { + this.requireAlphanumeric = requireAlphanumeric; + } + + public boolean isAllowSimple() { + return allowSimple; + } + + public void setAllowSimple(boolean allowSimple) { + this.allowSimple = allowSimple; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java new file mode 100644 index 000000000..748ee0e59 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/UpgradeFirmware.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015, 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 java.io.Serializable; + +/** + * This class represents the information of sending Upgrade Firmware operation. + */ +@ApiModel(value = "UpgradeFirmware", + description = "This class carries all information related to UpgradeFirmware.") +public class UpgradeFirmware extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "schedule", value = "Schedule of the UpgradeFirmware.") + private String schedule; + + @ApiModelProperty(name = "server", value = "Firmware package server.") + private String server; + + @SuppressWarnings("unused") + public String getSchedule() { + return schedule; + } + + @SuppressWarnings("unused") + public void setSchedule(String schedule) { + this.schedule = schedule; + } + + @SuppressWarnings("unused") + public String getServer() { + return server; + } + + @SuppressWarnings("unused") + public void setServer(String server) { + this.server = server; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Vpn.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Vpn.java new file mode 100644 index 000000000..188d44f8f --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Vpn.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2015, 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 java.io.Serializable; + +/** + * This class represents the information of configuring VPN operation. + */ +@ApiModel(value = "Vpn", + description = "This class carries all information related to VPN.") +public class Vpn extends AndroidOperation implements Serializable { + @ApiModelProperty(name = "serverAddress", value = "Server Address.", required = true) + private String serverAddress; + @ApiModelProperty(name = "serverPort", value = "Server Port.", required = true) + private String serverPort; + @ApiModelProperty(name = "sharedSecret", value = "Shared secret.", required = true) + private String sharedSecret; + @ApiModelProperty(name = "dnsServer", value = "DNS server.", required = true) + private String dnsServer; + + public String getServerAddress() { + return serverAddress; + } + + public void setServerAddress(String serverAddress) { + this.serverAddress = serverAddress; + } + + public String getServerPort() { + return serverPort; + } + + public void setServerPort(String serverPort) { + this.serverPort = serverPort; + } + + public String getSharedSecret() { + return sharedSecret; + } + + public void setSharedSecret(String sharedSecret) { + this.sharedSecret = sharedSecret; + } + + public String getDnsServer() { + return dnsServer; + } + + public void setDnsServer(String dnsServer) { + this.dnsServer = dnsServer; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/WebClip.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/WebClip.java new file mode 100644 index 000000000..cf39b1070 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/WebClip.java @@ -0,0 +1,64 @@ +/* + * 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 java.io.Serializable; + +/** + * This class represents the information of setting up webclip. + */ +@ApiModel(value = "WebClip", description = "This class represents the information of setting up webclip") +public class WebClip extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "identity", value = "The URL of the application", required = true) + private String identity; + @ApiModelProperty(name = "title", value = "The name of the web application", required = true) + private String title; + @ApiModelProperty(name = "type", value = "The type of the operation. Following are the possible operation" + + " types: install and uninstall. If the operation type is install, the web clip is added, and " + + "if the operation type is uninstall, the existing web clip is removed", required = true) + private String type; + + public String getIdentity() { + return identity; + } + + public void setIdentity(String identity) { + this.identity = identity; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Wifi.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Wifi.java new file mode 100644 index 000000000..8cdf3c58b --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/Wifi.java @@ -0,0 +1,54 @@ +/* + * 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 java.io.Serializable; + +/** + * This class represents the information of configuring wifi operation. + */ +@ApiModel(value = "Wifi", description = "This class represents the information of configuring wifi operation") +public class Wifi extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "ssid", value = "The name of the Wifi network that you wish to configure", + required = true) + private String ssid; + @ApiModelProperty(name = "password", value = "The password to connect to the specified Wifi network", + required = true) + private String password; + + public String getSsid() { + return ssid; + } + + public void setSsid(String ssid) { + this.ssid = ssid; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/WipeData.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/WipeData.java new file mode 100644 index 000000000..83efddc12 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/WipeData.java @@ -0,0 +1,42 @@ +/* + * 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 java.io.Serializable; + +/** + * This class represents the information of wipedata operation. + */ +@ApiModel(value = "WipeData", description = "This class represents the information of wipedata operation") +public class WipeData extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "pin", value = "PIN number to proceed with the data wipe", required = true) + private String pin; + + public String getPin() { + return pin; + } + + public void setPin(String pin) { + this.pin = pin; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AndroidApplication.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AndroidApplication.java new file mode 100644 index 000000000..8dee1a60d --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AndroidApplication.java @@ -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; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AndroidDevice.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AndroidDevice.java new file mode 100644 index 000000000..6c5fcec34 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AndroidDevice.java @@ -0,0 +1,201 @@ +/* + * 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) + private String name; + @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) + 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 features; + private List 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 applications; + + public AndroidDevice() { + } + + public AndroidDevice(String name, String description, String deviceId, EnrolmentInfo enrolmentInfo, List features, List properties) { + this.name = name; + 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 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 getFeatures() { + return this.features; + } + + public void setFeatures(List features) { + this.features = features; + } + + public List getProperties() { + return this.properties; + } + + public void setProperties(List properties) { + this.properties = properties; + } + + public DeviceInfo getDeviceInfo() { + return this.deviceInfo; + } + + public void setDeviceInfo(DeviceInfo deviceInfo) { + this.deviceInfo = deviceInfo; + } + + public List getApplications() { + return this.applications; + } + + public void setApplications(List applications) { + this.applications = applications; + } + + public String toString() { + return "device [name=" + this.name + ";" + ";" + "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; + } + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AndroidDeviceInfo.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AndroidDeviceInfo.java new file mode 100644 index 000000000..41fbb5857 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AndroidDeviceInfo.java @@ -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 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 == null) { + this.updatedTime = new Date(); + } + + return this.updatedTime; + } + + public void setUpdatedTime(Date updatedTime) { + this.updatedTime = updatedTime; + } + + public void setDeviceDetailsMap(Map deviceDetailsMap) { + this.deviceDetailsMap = deviceDetailsMap; + } + + public Map getDeviceDetailsMap() { + return this.deviceDetailsMap; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AppRestrictionBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AppRestrictionBeanWrapper.java new file mode 100644 index 000000000..64412336e --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/AppRestrictionBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * 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.mdm.services.android.bean.AppRestriction; + +import java.util.List; + +/** + * This class is used to wrap AppRestriction bean with devices + */ +@ApiModel(value = "AppRestrictionBeanWrapper", + description = "Application Restriction related information.") +public class AppRestrictionBeanWrapper { + + @ApiModelProperty(name = "operation", value = "AppRestriction related information.", required = true) + private AppRestriction operation; + @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true) + private List deviceIDs; + + public AppRestriction getOperation() { + return operation; + } + + public void setOperation(AppRestriction operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationInstallationBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationInstallationBeanWrapper.java new file mode 100644 index 000000000..b0bd54cf3 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationInstallationBeanWrapper.java @@ -0,0 +1,54 @@ +/* + * 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.mdm.services.android.bean.ApplicationInstallation; + +import java.util.List; + +/** + * This class is used to wrap the InstallApplication bean with devices. + */ + +@ApiModel(value = "ApplicationInstallationBeanWrapper", + description = "This class carries all information related to a InstallApplication") +public class ApplicationInstallationBeanWrapper { + + @ApiModelProperty(name = "deviceIDs", value = "List of Devices", required = true) + private List deviceIDs; + @ApiModelProperty(name = "operation", value = "App Installation property", required = true) + private ApplicationInstallation operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public ApplicationInstallation getOperation() { + return operation; + } + + public void setOperation(ApplicationInstallation operation) { + this.operation = operation; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationUninstallationBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationUninstallationBeanWrapper.java new file mode 100644 index 000000000..28c72c6cd --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationUninstallationBeanWrapper.java @@ -0,0 +1,54 @@ +/* + * 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.mdm.services.android.bean.ApplicationUninstallation; + +import java.util.List; + +/** + * This class is used to wrap the UninstallApplication bean with devices. + */ +@ApiModel(value = "ApplicationUninstallationBeanWrapper", + description = "This class carries all information related to Uninstall Application") +public class ApplicationUninstallationBeanWrapper { + + @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) + private List deviceIDs; + + @ApiModelProperty(name = "operation", value = "Name of the device", required = true) + private ApplicationUninstallation operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public ApplicationUninstallation getOperation() { + return operation; + } + + public void setOperation(ApplicationUninstallation operation) { + this.operation = operation; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationUpdateBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationUpdateBeanWrapper.java new file mode 100644 index 000000000..b202bf883 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/ApplicationUpdateBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * 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.mdm.services.android.bean.ApplicationUpdate; + +import java.util.List; + +/** + * This class is used to wrap the UpdateApplication bean with devices. + */ +@ApiModel(value = "ApplicationUpdateBeanWrapper", + description = "Application Update related Info.") +public class ApplicationUpdateBeanWrapper { + + @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true) + private List deviceIDs; + @ApiModelProperty(name = "operation", value = "Application Update related information.", required = true) + private ApplicationUpdate operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public ApplicationUpdate getOperation() { + return operation; + } + + public void setOperation(ApplicationUpdate operation) { + this.operation = operation; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/BlacklistApplicationsBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/BlacklistApplicationsBeanWrapper.java new file mode 100644 index 000000000..32b107bf4 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/BlacklistApplicationsBeanWrapper.java @@ -0,0 +1,54 @@ +/* + * 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.mdm.services.android.bean.BlacklistApplications; + +import javax.validation.Valid; +import java.util.List; + +/** + * This class is used to wrap the BlacklistApplications bean with devices. + */ +@ApiModel(value = "BlacklistApplicationsBeanWrapper", + description = "Mapping between blacklist application and the device ids.") +public class BlacklistApplicationsBeanWrapper { + + @ApiModelProperty(name = "operation", value = "Blacklist applications information", required = true) + private @Valid BlacklistApplications operation; + @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) + private List deviceIDs; + + public @Valid BlacklistApplications getOperation() { + return operation; + } + + public void setOperation(@Valid BlacklistApplications operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/CameraBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/CameraBeanWrapper.java new file mode 100644 index 000000000..9f9a014f2 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/CameraBeanWrapper.java @@ -0,0 +1,54 @@ +/* + * 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.mdm.services.android.bean.Camera; + +import java.util.List; + +/** + * This class is used to wrap the Camera bean with devices. + */ + +@ApiModel(value = "CameraBeanWrapper", + description = "Mapping between camera operation and device list to be applied.") +public class CameraBeanWrapper { + + @ApiModelProperty(name = "operation", value = "Information of camera operation", required = true) + private Camera operation; + @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) + private List deviceIDs; + + public Camera getOperation() { + return operation; + } + + public void setOperation(Camera operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceEnrollmentInfo.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceEnrollmentInfo.java new file mode 100644 index 000000000..b2f77cc31 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceEnrollmentInfo.java @@ -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(); + } + + +} \ No newline at end of file diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceLockBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceLockBeanWrapper.java new file mode 100644 index 000000000..bd668faba --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DeviceLockBeanWrapper.java @@ -0,0 +1,55 @@ +/* + * 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.mdm.services.android.bean.DeviceLock; + +import java.util.List; + +/** + * This class is used to wrap the Notification bean with devices. + */ +@ApiModel(value = "DeviceLockBeanWrapper", + description = "DeviceLock related Information.") +public class DeviceLockBeanWrapper { + + @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true) + private List deviceIDs; + @ApiModelProperty(name = "operation", value = "Information of the Device lock operation.", required = true) + private DeviceLock operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public DeviceLock getOperation() { + return operation; + } + + public void setOperation(DeviceLock operation) { + this.operation = operation; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DisenrollmentBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DisenrollmentBeanWrapper.java new file mode 100644 index 000000000..fdcab0120 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/DisenrollmentBeanWrapper.java @@ -0,0 +1,50 @@ +/* + * 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.mdm.services.android.bean.Disenrollment; + +import java.util.List; + +@ApiModel(value = "DisenrollmentBeanWrapper", description = "Disenrollment details are mapped to devices list.") +public class DisenrollmentBeanWrapper { + + @ApiModelProperty(name = "operation", value = "Disenrollment operation.", required = true) + private Disenrollment operation; + @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true) + private List deviceIDs; + + public Disenrollment getOperation() { + return operation; + } + + public void setOperation(Disenrollment operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EncryptionBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EncryptionBeanWrapper.java new file mode 100644 index 000000000..aeb01400a --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EncryptionBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * 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.mdm.services.android.bean.DeviceEncryption; + +import java.util.List; + +/** + * This class is used to wrap the Encrypt bean with devices. + */ +@ApiModel(value = "EncryptionBeanWrapper", + description = "Mapping between encryption operation and device list to be applied.") +public class EncryptionBeanWrapper { + + @ApiModelProperty(name = "operation", value = "The information of encrypt operation", required = true) + private DeviceEncryption operation; + @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) + private List deviceIDs; + + public DeviceEncryption getOperation() { + return operation; + } + + public void setOperation(DeviceEncryption operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EventBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EventBeanWrapper.java new file mode 100644 index 000000000..c4fb13e07 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/EventBeanWrapper.java @@ -0,0 +1,66 @@ +/* + * 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 javax.validation.constraints.Size; + +/** + * This class is used to wrap the events which receive from the agent application. + */ +@ApiModel(value = "EventBeanWrapper", + description = "Android agent's event related Information.") +public class EventBeanWrapper { + + @ApiModelProperty(name = "deviceIdentifier", value = "DeviceIdentifier to be need to retrieve/publish Event.", required = true) + @Size(min = 2, max = 45) + private String deviceIdentifier; + @ApiModelProperty(name = "payload", value = "Event payload.", required = true) + private String payload; + @ApiModelProperty(name = "type", value = "Type of the event.", required = true) + @Size(min = 2, max = 20) + private String type; + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } + + public String getDeviceIdentifier() { + return deviceIdentifier; + } + + public void setDeviceIdentifier(String deviceIdentifier) { + this.deviceIdentifier = deviceIdentifier; + } + + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/FileTransferBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/FileTransferBeanWrapper.java new file mode 100644 index 000000000..d34b00e66 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/FileTransferBeanWrapper.java @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2017, 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.mdm.services.android.bean.FileTransfer; + +import java.util.List; + +/** + * This class is used to wrap the File Transfer bean with devices. + */ +@ApiModel(value = "FileTransferBeanWrapper", + description = "FileTransfer related Information.") +public class FileTransferBeanWrapper { + + @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true) + private List deviceIDs; + + @ApiModelProperty(name = "upload", value = "Upload / Download w.r.t device.", + notes = "upload = true , If file is to be uploaded to the device.", required = true) + private boolean upload; + + @ApiModelProperty(name = "operation", value = "Information of the File Transfer Operation.", required = true) + private FileTransfer operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public FileTransfer getOperation() { + return operation; + } + + public void setOperation(FileTransfer operation) { + this.operation = operation; + } + + public boolean isUpload() { + return upload; + } + + public void setUpload(boolean upload) { + this.upload = upload; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/LockCodeBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/LockCodeBeanWrapper.java new file mode 100644 index 000000000..364fd39d2 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/LockCodeBeanWrapper.java @@ -0,0 +1,54 @@ +/* + * 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.mdm.services.android.bean.LockCode; + +import java.util.List; + +/** + * This class is used to wrap the LockCode bean with devices. + */ + +@ApiModel(value = "LockCodeBeanWrapper", + description = "Mapping between lock operation and device list to be applied.") +public class LockCodeBeanWrapper { + + @ApiModelProperty(name = "operation", value = "The information of device lock operation", required = true) + private LockCode operation; + @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) + private List deviceIDs; + + public LockCode getOperation() { + return operation; + } + + public void setOperation(LockCode operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/NotificationBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/NotificationBeanWrapper.java new file mode 100644 index 000000000..eb82e49ee --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/NotificationBeanWrapper.java @@ -0,0 +1,55 @@ +/* + * 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.mdm.services.android.bean.Notification; + +import java.util.List; + +/** + * This class is used to wrap the Notification bean with devices. + */ + +@ApiModel(value = "NotificationBeanWrapper", + description = "Mapping between notification operation and device list to be applied.") +public class NotificationBeanWrapper { + + @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) + private List deviceIDs; + @ApiModelProperty(name = "operation", value = "The information of notification operation", required = true) + private Notification operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public Notification getOperation() { + return operation; + } + + public void setOperation(Notification operation) { + this.operation = operation; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/PasswordPolicyBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/PasswordPolicyBeanWrapper.java new file mode 100644 index 000000000..e47ece1c5 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/PasswordPolicyBeanWrapper.java @@ -0,0 +1,54 @@ +/* + * 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.mdm.services.android.bean.PasscodePolicy; + +import java.util.List; + +/** + * This class is used to wrap the PasswordPolicy bean with devices. + */ + +@ApiModel(value = "PasswordPolicyBeanWrapper", + description = "Mapping between passcode policy and device list to be applied.") +public class PasswordPolicyBeanWrapper { + + @ApiModelProperty(name = "operation", value = "The information of setting up password policy", required = true) + private PasscodePolicy operation; + @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) + private List deviceIDs; + + public PasscodePolicy getOperation() { + return operation; + } + + public void setOperation(PasscodePolicy operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/UpgradeFirmwareBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/UpgradeFirmwareBeanWrapper.java new file mode 100644 index 000000000..b881422c2 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/UpgradeFirmwareBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, 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.mdm.services.android.bean.UpgradeFirmware; + +import java.util.List; + +/** + * This class is used to wrap the UpgradeFirmware bean with devices. + */ +@ApiModel(value = "UpgradeFirmwareBeanWrapper", + description = "Information related to UpgradeFirmware.") +public class UpgradeFirmwareBeanWrapper { + @ApiModelProperty(name = "deviceIDs", + value = "List of device Ids to be need to execute UpgradeFirmware operation.", required = true) + private List deviceIDs; + @ApiModelProperty(name = "operation", value = "Information related to UpgradeFirmware operation.", required = true) + private UpgradeFirmware operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public UpgradeFirmware getOperation() { + return operation; + } + + public void setOperation(UpgradeFirmware operation) { + this.operation = operation; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/VpnBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/VpnBeanWrapper.java new file mode 100644 index 000000000..e71270d22 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/VpnBeanWrapper.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, 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.mdm.services.android.bean.Vpn; + +import java.util.List; + +/** + * This class is used to wrap the Vpn bean with devices. + */ +@ApiModel(value = "VpnBeanWrapper", + description = "Information related to VPN Configuration.") +public class VpnBeanWrapper { + @ApiModelProperty(name = "operation", + value = "List of device Ids to be need to execute VPN operation.", required = true) + private Vpn operation; + @ApiModelProperty(name = "deviceIDs", + value = "List of device Ids to be need to execute VPN operation.", required = true) + private List deviceIDs; + + public Vpn getOperation() { + return operation; + } + + public void setOperation(Vpn operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WebClipBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WebClipBeanWrapper.java new file mode 100644 index 000000000..fb2edc239 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WebClipBeanWrapper.java @@ -0,0 +1,54 @@ +/* + * 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.mdm.services.android.bean.WebClip; + +import java.util.List; + +/** + * This class is used to wrap the WebClip bean with devices. + */ + +@ApiModel(value = "WebClipBeanWrapper", + description = "Mapping between web clip operation and device list to be applied.") +public class WebClipBeanWrapper { + + @ApiModelProperty(name = "operation", value = "the information of setting up webclip.", required = true) + private WebClip operation; + @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) + private List deviceIDs; + + public WebClip getOperation() { + return operation; + } + + public void setOperation(WebClip operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WifiBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WifiBeanWrapper.java new file mode 100644 index 000000000..2d63a27d9 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WifiBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * 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.mdm.services.android.bean.Wifi; + +import java.util.List; + +/** + * This class is used to wrap the Wifi bean with devices. + */ +@ApiModel(value = "WifiBeanWrapper", + description = "Mapping between wifi operation and device list to be applied.") +public class WifiBeanWrapper { + + @ApiModelProperty(name = "operation", value = "Information of configuring wifi operation", required = true) + private Wifi operation; + @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) + private List deviceIDs; + + public Wifi getOperation() { + return operation; + } + + public void setOperation(Wifi operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WipeDataBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WipeDataBeanWrapper.java new file mode 100644 index 000000000..b7ebb2903 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/WipeDataBeanWrapper.java @@ -0,0 +1,53 @@ +/* + * 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.mdm.services.android.bean.WipeData; + +import java.util.List; + +/** + * This class is used to wrap the WipeData bean with devices. + */ +@ApiModel(value = "WipeDataBeanWrapper", + description = "Mapping between wipe operation and device list to be applied.") +public class WipeDataBeanWrapper { + + @ApiModelProperty(name = "operation", value = "The information of wipedata operation", required = true) + private WipeData operation; + @ApiModelProperty(name = "deviceIDs", value = "List of device Ids", required = true) + private List deviceIDs; + + public WipeData getOperation() { + return operation; + } + + public void setOperation(WipeData operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/common/ErrorHandler.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/common/ErrorHandler.java new file mode 100644 index 000000000..542cd6078 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/common/ErrorHandler.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.mdm.services.android.common; + +import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; + +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; + + +@Produces({ "application/json", "application/xml" }) +public class ErrorHandler implements ExceptionMapper { + + public Response toResponse(AndroidAgentException exception) { + ErrorMessage errorMessage = new ErrorMessage(); + errorMessage.setErrorMessage(exception.getErrorMessage()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/common/ErrorMessage.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/common/ErrorMessage.java new file mode 100644 index 000000000..fd880c04c --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/common/ErrorMessage.java @@ -0,0 +1,41 @@ +/* + * 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.common; + + +public class ErrorMessage { + + private String errorMessage; + private String errorCode; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/common/GsonMessageBodyHandler.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/common/GsonMessageBodyHandler.java new file mode 100644 index 000000000..297630029 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/common/GsonMessageBodyHandler.java @@ -0,0 +1,91 @@ +/* + * 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.common; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.MessageBodyWriter; +import javax.ws.rs.ext.Provider; + +import java.io.*; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; + +@Provider +@Produces(APPLICATION_JSON) +@Consumes(APPLICATION_JSON) +public class GsonMessageBodyHandler implements MessageBodyWriter, MessageBodyReader { + + private Gson gson; + private static final String UTF_8 = "UTF-8"; + + public boolean isReadable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType) { + return true; + } + + private Gson getGson() { + if (gson == null) { + final GsonBuilder gsonBuilder = new GsonBuilder(); + gson = gsonBuilder.create(); + } + return gson; + } + + public Object readFrom(Class objectClass, Type type, Annotation[] annotations, MediaType mediaType, + MultivaluedMap stringStringMultivaluedMap, InputStream entityStream) + throws IOException, WebApplicationException { + + InputStreamReader reader = new InputStreamReader(entityStream, "UTF-8"); + + try { + return getGson().fromJson(reader, type); + } finally { + reader.close(); + } + } + + public boolean isWriteable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType) { + return true; + } + + public long getSize(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType) { + return -1; + } + + public void writeTo(Object object, Class aClass, Type type, Annotation[] annotations, MediaType mediaType, + MultivaluedMap stringObjectMultivaluedMap, OutputStream entityStream) + throws IOException, WebApplicationException { + + OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8); + try { + getGson().toJson(object, type, writer); + } finally { + writer.close(); + } + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/common/ValidationInterceptor.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/common/ValidationInterceptor.java new file mode 100644 index 000000000..a563f09d1 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/common/ValidationInterceptor.java @@ -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.common; + +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 { + + 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 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 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> violations = methodValidator.validateParameters(instance, + method, arguments); + + if (!violations.isEmpty()) { + throw new ConstraintViolationException(violations); + } + } + + public void validate(final T object) { + if (validator == null) { + log.warn("Bean Validation provider could be found, no validation will be performed"); + return; + } + + Set> violations = validator.validate(object); + + if (!violations.isEmpty()) { + throw new ConstraintViolationException(violations); + } + } + + public void handleFault(Message messageParam) { + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/AndroidAgentException.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/AndroidAgentException.java new file mode 100644 index 000000000..c12d03538 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/AndroidAgentException.java @@ -0,0 +1,63 @@ +/* + * 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; + +/** + * + * Custom exception class for Android API related exceptions. + * + */ +public class AndroidAgentException extends Exception{ + + private static final long serialVersionUID = 7950151650447893900L; + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public AndroidAgentException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public AndroidAgentException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public AndroidAgentException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public AndroidAgentException() { + super(); + } + + public AndroidAgentException(Throwable cause) { + super(cause); + } + + + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/AndroidOperationException.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/AndroidOperationException.java new file mode 100644 index 000000000..8c68866d8 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/AndroidOperationException.java @@ -0,0 +1,37 @@ +/* + * 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.Message; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +/** + * Custom exception class for wrapping Android Operation related exceptions. + */ +public class AndroidOperationException extends WebApplicationException { + + public AndroidOperationException(Message message, MediaType mediaType) { + super(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message). + type(mediaType).build()); + } +} + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/BadRequestException.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/BadRequestException.java new file mode 100644 index 000000000..5fa5ededc --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/BadRequestException.java @@ -0,0 +1,34 @@ +/* + * 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.bean.ErrorResponse; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; + +/** + * Custom exception class for wrapping BadRequest related exceptions. + */ +public class BadRequestException extends WebApplicationException { + + 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/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/ErrorDTO.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/ErrorDTO.java new file mode 100644 index 000000000..ebd5ec8fc --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/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.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 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/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/ForbiddenException.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/ForbiddenException.java new file mode 100644 index 000000000..75113f850 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/ForbiddenException.java @@ -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; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/GlobalThrowableMapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/GlobalThrowableMapper.java new file mode 100644 index 000000000..31370bd88 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/GlobalThrowableMapper.java @@ -0,0 +1,115 @@ +/* + * 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."; + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); + } + return AndroidDeviceUtils.buildBadRequestException(errorMessage).getResponse(); + } + if (e instanceof NotFoundException) { + return ((NotFoundException) e).getResponse(); + } + if (e instanceof BadRequestException) { + return ((BadRequestException) e).getResponse(); + } + if (e instanceof UnexpectedServerErrorException) { + if (log.isDebugEnabled()) { + log.debug("Unexpected server error", e); + } + return ((UnexpectedServerErrorException) e).getResponse(); + } + if (e instanceof ConstraintViolationException) { + if (log.isDebugEnabled()) { + log.debug("Constraint violation issue.", e); + return ((ParameterValidationException) e).getResponse(); + } + } + if (e instanceof IllegalArgumentException) { + ErrorDTO errorDetail = new ErrorDTO(); + errorDetail.setCode((long) 400); + errorDetail.setMoreInfo(""); + errorDetail.setMessage(""); + errorDetail.setDescription(e.getMessage()); + return Response + .status(Response.Status.BAD_REQUEST) + .entity(errorDetail) + .build(); + } + if (e instanceof ClientErrorException) { + if (log.isDebugEnabled()) { + log.debug("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) { + if (log.isDebugEnabled()) { + log.debug("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(); + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/NotFoundException.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/NotFoundException.java new file mode 100644 index 000000000..53863c3ac --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/NotFoundException.java @@ -0,0 +1,46 @@ +/* + * 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.bean.ErrorResponse; +import org.wso2.carbon.mdm.services.android.util.AndroidConstants; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; + +public class NotFoundException extends WebApplicationException { + private String message; + private static final long serialVersionUID = 147943572342342340L; + + public NotFoundException(ErrorResponse error) { + super(Response.status(Response.Status.NOT_FOUND).entity(error).build()); + } + public NotFoundException(ErrorDTO errorDTO) { + super(Response.status(Response.Status.NOT_FOUND) + .entity(errorDTO) + .header(AndroidConstants.HEADER_CONTENT_TYPE, AndroidConstants.APPLICATION_JSON) + .build()); + message = errorDTO.getDescription(); + } + + @Override + public String getMessage() { + return message; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/OperationConfigurationException.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/OperationConfigurationException.java new file mode 100644 index 000000000..1300b1481 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/OperationConfigurationException.java @@ -0,0 +1,37 @@ +/* + * 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; + +/** + * + * Custom exception class for operation configuration related exceptions. + * + */ +public class OperationConfigurationException extends Exception { + + private static final long serialVersionUID = 7435543643747623629L; + + public OperationConfigurationException(String errorMessage) { + super(errorMessage); + } + + public OperationConfigurationException(String errorMessage, Throwable throwable) { + super(errorMessage, throwable); + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/ParameterValidationException.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/ParameterValidationException.java new file mode 100644 index 000000000..efb38a3d7 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/ParameterValidationException.java @@ -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 ParameterValidationException(Set> 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; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/UnexpectedServerErrorException.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/UnexpectedServerErrorException.java new file mode 100644 index 000000000..a66c2f506 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/UnexpectedServerErrorException.java @@ -0,0 +1,48 @@ +/* + * 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.bean.ErrorResponse; +import org.wso2.carbon.mdm.services.android.util.AndroidConstants; + +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(AndroidConstants.HEADER_CONTENT_TYPE, AndroidConstants.APPLICATION_JSON) + .build()); + message = errorDTO.getDescription(); + } + + @Override + public String getMessage() { + return message; + } + + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java new file mode 100644 index 000000000..492d8ae69 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java @@ -0,0 +1,1839 @@ +/* + * + * Copyright (c) ${date}, 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.services; + +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Info; +import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.Extension; +import io.swagger.annotations.Tag; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.ResponseHeader; +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; +import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; +import org.wso2.carbon.mdm.services.android.bean.wrapper.*; +import org.wso2.carbon.mdm.services.android.util.AndroidConstants; + +import javax.validation.Valid; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; + +@SwaggerDefinition( + info = @Info( + version = "0.9.0", + title = "", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "name", + value = "Android Device Management Administrative Service"), + @ExtensionProperty(name = "context", + value = "/api/device-mgt/android/v0.9/admin/devices"), + }) + } + ), + tags = { + @Tag(name = "android,device_management", description = "") + } +) +@Path("/admin/devices") +@Api(value = "Android Device Management Administrative Service", description = "Device management related admin APIs.") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +@Scopes( + scopes = { + @Scope( + name = "Lock Device", + description = "Hard lock own device", + key = "perm:android:lock-devices", + permissions = {"/device-mgt/devices/owning-device/operations/android/lock"} + ), + @Scope( + name = "Unlock Device", + description = "Unlock permanently locked device", + key = "perm:android:unlock-devices", + permissions = {"/device-mgt/devices/owning-device/operations/android/unlock"} + ), + @Scope( + name = "Get Location", + description = "Request device location coordinates", + key = "perm:android:location", + permissions = {"/device-mgt/devices/owning-device/operations/android/location"} + ), + @Scope( + name = "Clear Password", + description = "Clear the password on Android devices", + key = "perm:android:clear-password", + permissions = {"/device-mgt/devices/owning-device/operations/android/clear-password"} + ), + @Scope( + name = "Control Camera", + description = "Enabling or Disabling the Camera on Android Devices", + key = "perm:android:control-camera", + permissions = {"/device-mgt/devices/owning-device/operations/android/camera"} + ), + @Scope( + name = "Get Info", + description = "Requesting device information from Android Devices", + key = "perm:android:info", + permissions = {"/device-mgt/devices/owning-device/operations/android/info"} + ), + @Scope( + name = "Get Logs", + description = "Requesting Logcat Details from Android Devices", + key = "perm:android:logcat", + permissions = {"/device-mgt/devices/owning-device/operations/android/logcat"} + ), + @Scope( + name = "Enterprise Wipe", + description = "Enterprise Wiping Android Devices", + key = "perm:android:enterprise-wipe", + permissions = {"/device-mgt/devices/owning-device/operations/android/enterprise-wipe"} + ), + @Scope( + name = "Factory Reset", + description = "Factory Resetting Android Devices", + key = "perm:android:wipe", + permissions = {"/device-mgt/devices/owning-device/operations/android/wipe"} + ), + @Scope( + name = "Get Installed Applications", + description = "Get list of installed applications", + key = "perm:android:applications", + permissions = {"/device-mgt/devices/owning-device/operations/android/applications"} + ), + @Scope( + name = "Ring Device", + description = "Ring Android devices", + key = "perm:android:ring", + permissions = {"/device-mgt/devices/owning-device/operations/android/ring"} + ), + @Scope( + name = "Reboot Device", + description = "Reboot Android devices", + key = "perm:android:reboot", + permissions = {"/device-mgt/devices/owning-device/operations/android/reboot"} + ), + @Scope( + name = "Mute Device", + description = "Mute Android devices", + key = "perm:android:mute", + permissions = {"/device-mgt/devices/owning-device/operations/android/mute"} + ), + @Scope( + name = "Install Applications", + description = "Installing an Application on Android Devices", + key = "perm:android:install-application", + permissions = {"/device-mgt/devices/owning-device/operations/android/install-app"} + ), + @Scope( + name = "Update Applications", + description = "Updating an Application on Android Devices", + key = "perm:android:update-application", + permissions = {"/device-mgt/devices/owning-device/operations/android/update-app"} + ), + @Scope( + name = "Uninstall Applications", + description = "Uninstalling an Application on Android Devices", + key = "perm:android:uninstall-application", + permissions = {"/device-mgt/devices/owning-device/operations/android/uninstall-app"} + ), + @Scope( + name = "Blacklist Applications", + description = "Blacklisting applications on Android Devices", + key = "perm:android:blacklist-applications", + permissions = {"/device-mgt/devices/owning-device/operations/android/blacklist-app"} + ), + @Scope( + name = "Upgrade Firmware", + description = "Upgrading Firmware of Android Devices", + key = "perm:android:upgrade-firmware", + permissions = {"/device-mgt/devices/owning-device/operations/android/upgrade"} + ), + @Scope( + name = "Configure VPN", + description = "Configure VPN on Android Device", + key = "perm:android:configure-vpn", + permissions = {"/device-mgt/devices/owning-device/operations/android/vpn"} + ), + @Scope( + name = "Send Notification", + description = "Sending a notification to Android Device", + key = "perm:android:send-notification", + permissions = {"/device-mgt/devices/owning-device/operations/android/send-notification"} + ), + @Scope( + name = "Configure Wi-Fi", + description = "Configure Wi-Fi on Android Device", + key = "perm:android:configure-wifi", + permissions = {"/device-mgt/devices/owning-device/operations/android/wifi"} + ), + @Scope( + name = "Encrypt Storage", + description = "Encrypting storage on Android Device", + key = "perm:android:encrypt-storage", + permissions = {"/device-mgt/devices/owning-device/operations/android/encrypt"} + ), + @Scope( + name = "Change Password", + description = "Changing the lock code of an Android Device", + key = "perm:android:change-lock-code", + permissions = {"/device-mgt/devices/owning-device/operations/android/change-lock-code"} + ), + @Scope( + name = "Password Policy", + description = "Set password policy of an Android Device", + key = "perm:android:set-password-policy", + permissions = {"/device-mgt/devices/owning-device/operations/android/password-policy"} + ), + @Scope( + name = "Add Web clip", + description = "Setting a Web Clip on Android Devices", + key = "perm:android:set-webclip", + permissions = {"/device-mgt/devices/owning-device/operations/android/webclip"} + ), + @Scope( + name = "File Transfer", + description = "Transferring a file to android devices", + key = "perm:android:file-transfer", + permissions = {"/device-mgt/devices/owning-device/operations/android/file-transfer"} + ) + } +) +public interface DeviceManagementAdminService { + + @POST + @Path("/file-transfer") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Transferring file to the device.", + notes = "Using this API you have the option to transfer a file from SFTP/FTP server or using an " + + "HTTP link to the device or retrieve file from the device to FTP/SFTP server .", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:file-transfer") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "File transferred.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified. \n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported.\n"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while file transfer operation.") + }) + Response fileTransfer( + @ApiParam( + name = "fileTransfer", + value = "Provide the ID of the Android device. Multiple device IDs can be added by using " + + "comma separated values.", + required = true) FileTransferBeanWrapper fileTransferBeanWrapper); + + @POST + @Path("/lock-devices") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Adding a Screen Lock on Android devices", + notes = "Using this API you have the option of hard locking an Android device, where the Administrator " + + "permanently locks the device or screen locking an Android device.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:lock-devices") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the device lock operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified. \n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported.\n"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while locking the device.") + }) + Response configureDeviceLock( + @ApiParam( + name = "deviceLock", + value = "Provide the ID of the Android device, the message that needs to be sent out when locking the device, " + + "and define true as the value if you need to hard lock the device or define false as the value to " + + "screen lock the device." + + "Multiple device IDs can be added by using comma separated values. ", + required = true) DeviceLockBeanWrapper deviceLockBeanWrapper); + + @POST + @Path("/unlock-devices") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Unlocking Android Devices", + responseContainer = "List", + notes = "Unlock devices that were locked permanently using the hard lock operation. Devices that are hard locked can only be unlocked by the EMM administrator.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:unlock-devices") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the device unlock operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while unlocking the device.") + }) + Response configureDeviceUnlock( + @ApiParam( + name = "deviceIDs", + value = "Provide the ID of the Android device. Multiple device IDs can be added by using comma separated values. ", + required = true) + List deviceIDs); + + + @POST + @Path("/location") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Requesting Location Coordinates", + responseContainer = "List", + notes = "Request location coordinates of Android devices. \n" + + "Example: In situations where you have lost your device and need to find out where it is, you can use this REST API to get the location of the device.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:location") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Get-location operation has successfully been scheduled", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new get-location operation.")}) + Response getDeviceLocation( + @ApiParam( + name = "deviceIDs", + value = "Provide the ID of the Android device. Multiple device IDs can be added by using comma separated values. ", + required = true) + List deviceIDs); + + @POST + @Path("/clear-password") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Clearing the Password on Android Devices", + notes = "Clear the password on Android devices", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:clear-password") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the clear password operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.\n", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new clear password operation.") + }) + Response removePassword( + @ApiParam(name = "deviceIDs", + value = "Provide the ID of the Android device. Multiple device IDs can be added by using comma separated values. ", + required = true) List deviceIDs); + + @POST + @Path("/control-camera") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Enabling or Disabling the Camera on Android Devices", + notes = "Enable or disable the camera on Android devices.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:control-camera") + }) + }) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the camera control operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding the new camera control operation.") + }) + Response configureCamera( + @ApiParam( + name = "cameraControl", + value = "Define the properties to enable/disable the camera. " + + "Disable the camera on the device by assigning true as the value or enable the " + + "camera on the device to function by defining false as the value and the ID of the Android device. " + + "Multiple device IDs can be added by using comma separated values. ", + required = true) + CameraBeanWrapper cameraBeanWrapper); + + @POST + @Path("/info") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Requesting Information from Android Devices", + notes = "Using this REST API you are able to request for Android device details. Once this REST API is" + + " executed it will be in the Android operation queue until the device calls the server to retrieve " + + "the list of operations that needs to be executed on the device", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:info") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the device info operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new device info operation.") + }) + Response getDeviceInformation( + @ApiParam( + name = "deviceIds", + value = "Provide the device ID of the Android device. Multiple device IDs can be added by using comma separated values.", + required = true) + List deviceIDs); + + @POST + @Path("/logcat") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Requesting Logcat Details from Android Devices", + notes = "Using this REST API you are able to request for Android device log details. Once this REST API is" + + " executed it will be in the Android operation queue until the device calls the server to retrieve " + + "the list of operations that needs to be executed on the device.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:logcat") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the operation to get the logcat details.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new device logcat operation.") + }) + Response getDeviceLogcat( + @ApiParam( + name = "deviceIds", + value = "Provide the ID of the Android device. Multiple device IDs can be added by using comma separated values.", + required = true) + List deviceIDs); + + @POST + @Path("/enterprise-wipe") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Enterprise Wiping Android Devices", + notes = "Enterprise wipe is the process of deleting enterprise related data on a device while keeping the " + + "personal data intact. You are able to enterprise wipe Android devices using this REST API.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:enterprise-wipe") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the enterprise wipe operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified." + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.\n", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding the enterprise wipe operation.")}) + Response wipeDevice( + @ApiParam( + name = "deviceIDs", + value = "Provide the ID of the Android device. Multiple device IDs can be added by using comma separated values. ", + required = true) + List deviceIDs); + + @POST + @Path("/wipe") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Factory Resetting an Android Device", + notes = "Factory rest or erase all the data stored on the Android devices " + + "to restore them back to the original system.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:wipe") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the device wipe/factory reset operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding the device wipe operation.")}) + Response wipeData( + @ApiParam( + name = "wipeData", + value = "Provide the the passcode, which is the passcode that the Android agent prompts the device owner to set at the time of device enrollment, " + + "to enable the factory reset operation, and the ID of the Android device. Multiple device IDs can be added by using comma separated values. ", + required = true) + WipeDataBeanWrapper wipeDataBeanWrapper); + + @POST + @Path("/applications") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Getting the List of Installed Applications on Android Devices", + notes = "Using this REST API the server requests for the list of applications that are installed on" + + " the Android devices. Once this REST API is executed it will be in the Android operation queue " + + "until the device calls the server to retrieve the list of operations that needs to be executed " + + "on the device.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:applications") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the get-applications operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding the new get-applications operation.") + }) + Response getApplications( + @ApiParam( + name = "deviceIDs", + value = "Provide the ID of the Android device. Multiple device IDs can be added using comma separated values.", + required = true) + List deviceIDs); + + @POST + @Path("/ring") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Ringing Android Devices", + notes = "Ring Android devices.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:ring") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the device ring operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported.\n"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new device ring operation.") + }) + Response ringDevice( + @ApiParam( + name = "deviceIDs", + value = "Provide the ID of the Android device. Multiple device IDs can be added using comma separated values.", + required = true) + List deviceIDs); + + @POST + @Path("/reboot") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Rebooting Android Devices", + notes = "Reboot or restart your Android devices.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:reboot") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the device reboot operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.\n", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported.\n"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding the new device reboot operation.") + }) + Response rebootDevice( + @ApiParam( + name = "deviceIDs", + value = "Provide the ID of the Android device. Multiple device IDs can be added using comma separated values. ", + required = true) + List deviceIDs); + + @POST + @Path("/mute") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Muting Android Devices", + notes = "Mute or enable a silent profile for Android devices.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:mute") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the device mute operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new device mute operation.") + }) + Response muteDevice( + @ApiParam( + name = "deviceIDs", + value = "Provide the ID of the Android device. Multiple device IDs can be added using comma separated values. ", + required = true) + List deviceIDs); + + @POST + @Path("/install-application") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Installing an Application on Android Devices", + notes = "Install an application on an Android device. If the device you are installing the application has the WSO2 system service application installed," + + " the application installation will happen in silent mode, else the device user's consent will be required.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:install-application") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the install application operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported.\n"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new install-application operation.") + }) + Response installApplication( + @ApiParam( + name = "applicationInstallation", + value = "Properties required to install an application on Android devices. Provide the the package name, type," + + " URL and name of the application, the date and time for the scheduled installation, and the ID of the " + + "Android device. Multiple device IDs can be added by using comma separated values.", + required = true) + ApplicationInstallationBeanWrapper applicationInstallationBeanWrapper); + + @POST + @Path("/update-application") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Updating an Application on Android Devices", + notes = "Update an application on an Android device. If the device" + + " has the WSO2 system service application installed, the application update will happen in silent " + + "mode, else the device user's consent is required.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:update-application") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the update-application operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding the new update-application operation.") + }) + Response updateApplication( + @ApiParam( + name = "applicationUpdate", + value = "Properties required to update an application on Android devices. Provide the the package name, type," + + "URL and name of the application, the date and time for the scheduled installation, and the ID of the" + + "Android device. Multiple device IDs can be added by using comma separated values.", + required = true) + ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper); + + @POST + @Path("/uninstall-application") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Uninstalling an Application from Android Devices", + notes = "Uninstall an application from Android devices.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:uninstall-application") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the uninstall-application operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new uninstall-application operation.") + }) + Response uninstallApplication( + @ApiParam( + name = "applicationUninstallation", + value = "Properties required to uninstall an application. Provide the the package name, type," + + "URL and name of the application, the date and time for the scheduled installation, and the ID of the" + + "Android device. Multiple device IDs can be added by using comma separated values.", + required = true) + ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper); + + @POST + @Path("/blacklist-applications") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "BlackListing Applications for Android Devices", + notes = "Prevents you from using specific applications. For Android operation systems before Lollipop," + + " when a blacklisted application is clicked a screen is displayed to prevent you from using the app. For the Lollipop" + + " Android operating systems and after, the blacklisted apps will be hidden. Blacklisting can be used on both BYOD and " + + "COPE devices. Applications can be blacklisted via the application restriction policy too.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:blacklist-applications") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the application blacklist operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding the new blacklist-applications operation.") + }) + Response blacklistApplications( + @ApiParam( + name = "blacklistApplications", + value = "The properties required to blacklist applications. Provide the package name of the application to be blacklisted," + + " and the ID of the Android device. Multiple device IDs can be added by using comma separated values. ", + required = true) + @Valid BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper); + + @POST + @Path("/upgrade-firmware") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Upgrading Firmware of Android Devices", + notes = "Upgrade the firmware of Android devices.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:upgrade-firmware") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the firmware upgrade operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new upgrade firmware operation.") + }) + Response upgradeFirmware( + @ApiParam( + name = "upgradeFirmware", + value = "Properties required to upgrade the firmware. Provide the date and time to schedule the firmware update in the " + + "yyyy-MM-dd'T'HH:mm:ss.SSSXXX format, the OTA upgrade server URL in one of the following formats " + + "(example: http//abc.com, http://abc.com/ota), " + + "and the ID of the Android device. Multiple device IDs can be added by using comma separated values.", + required = true) + UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper); + + @POST + @Path("/configure-vpn") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Configuring VPN on Android devices", + notes = "Configure VPN on Android devices.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:configure-vpn") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the configure VPN operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The URL of the activity instance that refers to the scheduled operation."), + @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 was last modified." + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while configuring the VPN.") + }) + Response configureVPN( + @ApiParam( + name = "vpnBean", + value = "VPN configuration and DeviceIds", + required = true) + VpnBeanWrapper vpnBeanWrapper); + + @POST + @Path("/send-notification") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Sending a Notification to Android Devices", + notes = "Send a notification or message to Android devices.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:send-notification") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully sent the notification.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new send notification operation.") + }) + Response sendNotification( + @ApiParam( + name = "notification", + value = "The properties required to send a notification. Provide the message you wish to send and the ID of the " + + "Android device. Multiple device IDs can be added by using comma separated values.", + required = true) + NotificationBeanWrapper notificationBeanWrapper); + + @POST + @Path("/configure-wifi") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Configuring Wi-Fi on Android Devices", + notes = "Configure Wi-Fi on Android devices.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:configure-wifi") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the configure Wi-Fi operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified." + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while configuring Wi-Fi.") + }) + Response configureWifi( + @ApiParam( + name = "wifi", + value = "The properties required to configure Wi-Fi. Provide the password to connect to the specified Wi-Fi network," + + "the ssid or the name of the Wi-Fi network that you wish to configure and the ID of the Android device." + + " Multiple device IDs can be added by using comma separated values.", + required = true) + WifiBeanWrapper wifiBeanWrapper); + + @POST + @Path("/encrypt-storage") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Encrypting Storage on Android Devices", + notes = "Encrypt the data stored on Android devices.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:encrypt-storage") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the encrypt storage operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified." + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.\n", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new encrypt storage operation.") + }) + Response encryptStorage( + @ApiParam( + name = "encryption", + value = "Properties required to encrypt the storage. Encrypt the storage on the device by assigning " + + "true as the value or do not encrypt the storage on the device by assigning false as the value and " + + "provide the ID of the Android device. Multiple device IDs can be added by using comma separated values.", + required = true) + EncryptionBeanWrapper encryptionBeanWrapper); + + @POST + @Path("/change-lock-code") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Changing the Lock Code on Android Devices", + notes = "Change the lock code on Android devices.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:change-lock-code") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the change lock code operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new change lock code operation.") + }) + Response changeLockCode( + @ApiParam( + name = "lockCode", + value = "The properties to change th lock code. Provide the lock code that will replace the current lock code on Android devices and " + + "the ID of the Android device. Multiple device IDs can be added by using comma separated values. " + + "If a passcode policy has been set in EMM, the lock code should comply to the passcode policy.\t", + required = true) + LockCodeBeanWrapper lockCodeBeanWrapper); + + @POST + @Path("/set-password-policy") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Setting a Password Policy on Android Devices", + notes = "Set a password policy on Android devices.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:set-password-policy") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the set password policy operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @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 adding a new set password policy operation.") + }) + Response setPasswordPolicy( + @ApiParam( + name = "passwordPolicy", + value = "The properties required to set a password policy.", + required = true) + PasswordPolicyBeanWrapper passwordPolicyBeanWrapper); + + @POST + @Path("/set-webclip") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Setting a Web Clip on Android Devices", + notes = "Set a web clip on Android devices. A web clip is used to add a bookmark to a web application.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:set-webclip") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the set web clip operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.\n", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding adding a the set web clip operation.") + }) + Response setWebClip( + @ApiParam( + name = "webClip", + value = "The properties to set the web clip.", + required = true) + WebClipBeanWrapper webClipBeanWrapper); + + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java new file mode 100644 index 000000000..2ae1fcfd0 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementService.java @@ -0,0 +1,412 @@ +/* + * + * Copyright (c) ${date}, 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.services; + +import io.swagger.annotations.*; + +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidApplication; +import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidDevice; +import org.wso2.carbon.mdm.services.android.util.AndroidConstants; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.List; + +@SwaggerDefinition( + info = @Info( + version = "0.9.0", + title = "", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "name", value = "Android Device Management"), + @ExtensionProperty(name = "context", value = "/api/device-mgt/android/v0.9/devices"), + }) + } + ), + tags = { + @Tag(name = "android,device_management", description = "") + } +) +@Api(value = "Android Device Management", + description = "This carries all the resources related to the Android device management functionalities.") +@Path("/devices") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +@Scopes( + scopes = { + @Scope( + name = "Enroll Device", + description = "Register an Android device", + key = "perm:android:enroll", + permissions = {"/device-mgt/devices/enroll/android"} + ), + @Scope( + name = "Un-enroll Device", + description = "Unregister an Android device", + key = "perm:android:disenroll", + permissions = {"/device-mgt/devices/disenroll/android"} + ) + } +) +public interface DeviceManagementService { + + @PUT + @Path("/{id}/applications") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + consumes = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Updating the Application Details on Android Devices", + notes = "Update the details of the applications that are installed on Android devices.", + tags = "Android Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:enroll") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully updated the application details.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The URL of the updated application list."), + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\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 The specified resource does not exist."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while updating the application list.") + }) + Response updateApplicationList( + @ApiParam( + name = "id", + value = "The unique device identifier.") + @NotNull + @Size(min = 2 , max = 45) + @Pattern(regexp = "^[A-Za-z0-9]*$") + @PathParam("id") String id, + @ApiParam( + name = "applications", + value = "The properties to update application details. Multiple applications can be updated using comma separated values.") + List androidApplications); + + @PUT + @Path("/{id}/pending-operations") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Getting the Pending Operation List", + responseContainer = "List", + notes = "The Android agent communicates with the server to get the operations that are queued up " + + "at the server end via this REST API." + + " While getting the pending operations the details of the operations executed at the device end is shared with the server. " + + "The server then updates the status of the operations that were carried out on the device.", + response = Operation.class, + tags = "Android Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:enroll") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the pending operations of the Android device.", + response = Operation.class, + responseContainer = "List", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests.") + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource."), + @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 the list of pending operations.") + }) + Response getPendingOperations( + @ApiParam( + name = "id", + value = "The unique device identifier.", + required = true) + @PathParam("id") String id, + @ApiParam( + name = "If-Modified-Since", + value = "Checks if the requested variant was modified, since the specified date-time.\n" + + "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" + + "Example: Mon, 05 Jan 2014 15:10:00 +0200.", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince, + @ApiParam( + name = "resultOperations", + value = "Properties to update the device operations and their status.") + List resultOperations); + + @POST + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Registering an Android Device", + notes = "When registering an Android device, you need to install" + + " the Android Agent on the device, before being able to register the device with WSO2 EMM. Instead," + + " you can use this REST API to register an Android device with WSO2 EMM, without having to install" + + " an Android Agent. This API can be mainly used to test the device enrollment process.", + tags = "Android Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:enroll") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully created an instance of the device.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the added device enrollment."), + @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 was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported.\n"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding a new device.") + }) + Response enrollDevice(@ApiParam( + name = "device", + value = "The properties required to enroll a device.") + @Valid AndroidDevice device); + + @GET + @Path("/{id}/status") + @ApiOperation( + httpMethod = "GET", + value = "Getting the Registration Status of an Android Device", + notes = "Use this REST API to retrieve the registration status of an Android device.", + tags = "Android Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:enroll") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the status of the Android device enrollment.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource."), + @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 the enrollment status of the Android device.") + }) + Response isEnrolled( + @ApiParam( + name = "id", + value = "The unique device identifier") + @PathParam("id") String id, + @ApiParam( + name = "If-Modified-Since", + value = "Checks if the requested variant was modified, since the specified date-time.\n" + + "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" + + "Example: Mon, 05 Jan 2014 15:10:00 +0200", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince); + + @PUT + @Path("/{id}") + @ApiOperation( + httpMethod = "PUT", + value = "Updating the Registration Details of an Android Device", + notes = "Use this REST API to update the registration details of an Android device.", + tags = "Android Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:enroll") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully updated the device enrollment details.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the updated device enrollment."), + @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 was last modified.\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 The specified resource does not exist."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while updating the device enrollment.") + }) + Response modifyEnrollment( + @ApiParam( + name = "id", + value = "The unique device identifier.") + @PathParam("id") String id, + @ApiParam( + name = "device", + value = "The properties of required to update device enrollment details.") @Valid AndroidDevice androidDevice); + + @DELETE + @Path("/{id}") + @ApiOperation( + httpMethod = "DELETE", + value = "Unregistering an Android Device", + notes = "Use this REST API to unregister an Android device.", + tags = "Android Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:disenroll") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully disenrolled the device."), + @ApiResponse( + code = 404, + message = "Not Found. \n The specified resource does not exist."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while dis-enrolling the device.") + }) + Response disEnrollDevice( + @ApiParam( + name = "id", + value = "The unique device identifier.") + @PathParam("id") String id); + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java new file mode 100644 index 000000000..040e98e5e --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceTypeConfigurationService.java @@ -0,0 +1,253 @@ +/* + * + * Copyright (c) ${date}, 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.services; + +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Info; +import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.Extension; +import io.swagger.annotations.Tag; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.ResponseHeader; +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; +import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; +import org.wso2.carbon.mdm.services.android.bean.AndroidPlatformConfiguration; +import org.wso2.carbon.mdm.services.android.exception.AndroidAgentException; +import org.wso2.carbon.mdm.services.android.util.AndroidConstants; + +import javax.validation.Valid; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@SwaggerDefinition( + info = @Info( + version = "0.9.0", + title = "", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "name", + value = "Android Configuration Management"), + @ExtensionProperty(name = "context", + value = "/api/device-mgt/android/v0.9/configuration"), + }) + } + ), + tags = { + @Tag(name = "android,device_management", description = "") + } +) +@Api(value = "Android Configuration Management", description = "This API carries all the resource used to mange the Android platform configurations.") +@Path("/configuration") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +@Scopes( + scopes = { + @Scope( + name = "Enroll Device", + description = "Register an Android device", + key = "perm:android:enroll", + permissions = {"/device-mgt/devices/enroll/android"} + ), + @Scope( + name = "View Configurations", + description = "Getting Android Platform Configurations", + key = "perm:android:view-configuration", + permissions = {"/device-mgt/devices/enroll/android"} + ), + @Scope( + name = "Manage Configurations", + description = "Updating Android Platform Configurations", + key = "perm:android:manage-configuration", + permissions = {"/device-mgt/platform-configurations/manage"} + ) + } +) +public interface DeviceTypeConfigurationService { + + @GET + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting Android Platform Configurations", + notes = "Get the Android platform configuration details using this REST API.", + response = PlatformConfiguration.class, + tags = "Android Configuration Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:view-configuration") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the Android platform configurations.", + 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 was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource."), + @ApiResponse( + code = 404, + message = "Not Found. \n The specified resource 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 the Android platform configuration.") + }) + Response getConfiguration( + @ApiParam( + name = "If-Modified-Since", + value = "Checks if the requested variant was modified, since the specified date-time.\n" + + "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" + + "Example: Mon, 05 Jan 2014 15:10:00 +0200", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince); + + @PUT + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Updating Android Platform Configurations", + notes = "Update the Android platform configurations using this REST API.", + tags = "Android Configuration Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:manage-configuration") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully updated the Android platform configurations.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the updated Android 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 was last modified.\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 The specified resource does not exist."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while modifying the Android platform configuration.") + }) + Response updateConfiguration( + @ApiParam(name = "configuration", + value = "The properties to update the Android platform configurations.") + @Valid AndroidPlatformConfiguration androidPlatformConfiguration); + + @GET + @Path("license") + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation( + produces = MediaType.TEXT_PLAIN, + httpMethod = "GET", + value = "Getting the License Agreement for the Android Device Registration", + notes = "Use this REST API to retrieve the license agreement that is used for the Android device " + + "registration process.", + response = String.class, + tags = "Android Configuration Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:enroll") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched Android 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 was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource."), + @ApiResponse( + code = 404, + message = "Not Found. \n The specified resource 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 the Android license configuration.") + }) + Response getLicense( + @ApiParam( + name = "If-Modified-Since", + value = "Checks if the requested variant was modified, since the specified date-time.\n" + + "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" + + "Example: Mon, 05 Jan 2014 15:10:00 +0200.", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince) throws AndroidAgentException; + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java new file mode 100644 index 000000000..21c5e9023 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/EventReceiverService.java @@ -0,0 +1,215 @@ +/* + * + * Copyright (c) ${date}, 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.services; + +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Info; +import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.Extension; +import io.swagger.annotations.Tag; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.ResponseHeader; +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; +import org.wso2.carbon.mdm.services.android.bean.DeviceState; +import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; +import org.wso2.carbon.mdm.services.android.util.AndroidConstants; + +import javax.validation.Valid; +import javax.validation.constraints.Size; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@SwaggerDefinition( + info = @Info( + version = "0.9.0", + title = "", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "name", value = "Android Event Receiver"), + @ExtensionProperty(name = "context", value = "/api/device-mgt/android/v0.9/events"), + }) + } + ), + tags = { + @Tag(name = "android,device_management", description = "") + } +) +@Api(value = "Event Receiver", description = "Event publishing/retrieving related APIs. To enable event publishing/retrieving you need to" + + " configure WSO2 EMM as explained in https://docs.wso2.com/display/EMM220/Managing+Event+Publishing+with+WSO2+Data+Analytics+Server, " + + "https://docs.wso2.com/display/EMM220/Creating+a+New+Event+Stream+and+Receiver") +@Path("/events") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +@Scopes( + scopes = { + @Scope( + name = "Enroll Device", + description = "Register an Android device", + key = "perm:android:enroll", + permissions = {"/device-mgt/devices/enroll/android"} + ) + } +) +public interface EventReceiverService { + + @POST + @Path("/publish") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Publishing Events", + notes = "Publish events received by the WSO2 EMM Android client to the WSO2 Data Analytics Server (DAS) using this API.", + tags = "Event Receiver", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:enroll") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse(code = 201, message = "Created. \n Successfully published the event. Location header " + + "contains URL of newly enrolled device", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The URL of the added policy."), + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests.") + }), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while publishing events.") + }) + Response publishEvents( + @ApiParam( + name = "eventBeanWrapper", + value = "Information of the agent event to be published on DAS.") + @Valid + EventBeanWrapper eventBeanWrapper); + + @GET + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting event details for a given time period.", + notes = "Get the event details of a device for a given time duration using this API. The request must contain " + + "the device identifier. Optionally, both date from and date to value should be present to get " + + "alerts between a specified time. Filtering can also be done based on the device type and the device identifier." + + "(This cannot be combined with the to and from parameters).", + response = DeviceState.class, + responseContainer = "List", + tags = "Event Receiver", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:enroll") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the event details of the specified device for a given time duration.", + response = DeviceState.class, responseContainer = "List"), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader(name = "Content-Location", description = "Source URL of the document.") + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n " + + "Empty body because the client already has the latest version of the requested resource."), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error. You must provide" + + " the device identifier. Additionally, the device identifier can be combined with either the device type" + + " OR the from and to date."), + @ApiResponse( + code = 404, + message = "Not Found. \n The specified resource does not exist."), + @ApiResponse( + code = 500, + message = "Error occurred while getting the published events for the specified device.") + }) + Response retrieveAlerts( + @ApiParam( + name = "id", + value = "The unique device identifier.", + required = true) + @Size(min = 2, max = 45) + @QueryParam("id") String deviceId, + @ApiParam( + name = "from", + value = "Specify the time and date from when you want to get the data." + + "Provide the time and date format in the unix/epoch format as the value for {unixTimestamp}. Use a Epoch convertor, to convert the time and date to this format.") + @QueryParam("from") long from, + @ApiParam( + name = "to", + value = "Specify the time and date up to when you require the data." + + "Provide the time and date format in the unix/epoch format as the value for {unixTimestamp}. Use a Epoch convertor, to convert the time and date to this format.") + @QueryParam("to") long to, + @ApiParam( + name = "type", + value = "The alert type to retrieve the events." + + "Provide APPLICATION_STATE or RUNTIME_STATE as the value.") + @Size(min = 2, max = 45) + @QueryParam("type") String type, + @ApiParam( + name = "If-Modified-Since", + value = "Checks if the requested variant was modified, since the specified date-time.\n" + + "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" + + "Example: Mon, 05 Jan 2014 15:10:00 +0200", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince); + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java new file mode 100644 index 000000000..b50e4b4ad --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java @@ -0,0 +1,1017 @@ +/* + * 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.services.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONException; +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.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.operation.mgt.CommandOperation; +import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; +import org.wso2.carbon.mdm.services.android.bean.ApplicationInstallation; +import org.wso2.carbon.mdm.services.android.bean.ApplicationUninstallation; +import org.wso2.carbon.mdm.services.android.bean.ApplicationUpdate; +import org.wso2.carbon.mdm.services.android.bean.BlacklistApplications; +import org.wso2.carbon.mdm.services.android.bean.Camera; +import org.wso2.carbon.mdm.services.android.bean.DeviceEncryption; +import org.wso2.carbon.mdm.services.android.bean.DeviceLock; +import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; +import org.wso2.carbon.mdm.services.android.bean.FileTransfer; +import org.wso2.carbon.mdm.services.android.bean.LockCode; +import org.wso2.carbon.mdm.services.android.bean.Notification; +import org.wso2.carbon.mdm.services.android.bean.PasscodePolicy; +import org.wso2.carbon.mdm.services.android.bean.UpgradeFirmware; +import org.wso2.carbon.mdm.services.android.bean.Vpn; +import org.wso2.carbon.mdm.services.android.bean.WebClip; +import org.wso2.carbon.mdm.services.android.bean.Wifi; +import org.wso2.carbon.mdm.services.android.bean.WipeData; +import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationInstallationBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUninstallationBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUpdateBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.BlacklistApplicationsBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.CameraBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.DeviceLockBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.EncryptionBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.FileTransferBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.LockCodeBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.NotificationBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.PasswordPolicyBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.UpgradeFirmwareBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.VpnBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.WebClipBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.WifiBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.WipeDataBeanWrapper; +import org.wso2.carbon.mdm.services.android.exception.BadRequestException; +import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; +import org.wso2.carbon.mdm.services.android.services.DeviceManagementAdminService; +import org.wso2.carbon.mdm.services.android.util.AndroidConstants; +import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils; + +import javax.validation.Valid; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.List; + +@Path("/admin/devices") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminService { + + private static final Log log = LogFactory.getLog(DeviceManagementAdminServiceImpl.class); + private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; + + @POST + @Path("/file-transfer") + @Override + public Response fileTransfer(FileTransferBeanWrapper fileTransferBeanWrapper) { + try { + if (fileTransferBeanWrapper == null || fileTransferBeanWrapper.getOperation() == null + || fileTransferBeanWrapper.getDeviceIDs() == null) { + String errorMessage = "The payload of the file transfer operation is incorrect."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + if (log.isDebugEnabled()) { + log.debug("Invoking Android file transfer operation for " + fileTransferBeanWrapper.getDeviceIDs()); + } + FileTransfer file = fileTransferBeanWrapper.getOperation(); + ProfileOperation operation = new ProfileOperation(); + if (fileTransferBeanWrapper.isUpload()) { + operation.setCode(AndroidConstants.OperationCodes.FILE_DOWNLOAD); + } else { + operation.setCode(AndroidConstants.OperationCodes.FILE_UPLOAD); + } + operation.setType(Operation.Type.PROFILE); + operation.setEnabled(true); + operation.setPayLoad(file.toJSON()); + Activity activity = AndroidDeviceUtils.getOperationResponse(fileTransferBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers ( " + fileTransferBeanWrapper.getDeviceIDs() + " ) found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance for file transfer operation"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/lock-devices") + @Override + public Response configureDeviceLock(DeviceLockBeanWrapper deviceLockBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking Android device lock operation"); + } + + try { + if (deviceLockBeanWrapper == null || deviceLockBeanWrapper.getOperation() == null) { + String errorMessage = "Lock bean is empty."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + DeviceLock lock = deviceLockBeanWrapper.getOperation(); + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCK); + operation.setType(Operation.Type.PROFILE); + operation.setEnabled(true); + operation.setPayLoad(lock.toJSON()); + Activity activity = AndroidDeviceUtils.getOperationResponse(deviceLockBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/unlock-devices") + @Override + public Response configureDeviceUnlock(List deviceIDs) { + if (log.isDebugEnabled()) { + log.debug("Invoking Android device unlock operation."); + } + + try { + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.DEVICE_UNLOCK); + operation.setType(Operation.Type.COMMAND); + operation.setEnabled(true); + Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/location") + @Override + public Response getDeviceLocation(List deviceIDs) { + if (log.isDebugEnabled()) { + log.debug("Invoking Android device location operation."); + } + + try { + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCATION); + operation.setType(Operation.Type.COMMAND); + Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/clear-password") + @Override + public Response removePassword(List deviceIDs) { + if (log.isDebugEnabled()) { + log.debug("Invoking Android clear password operation."); + } + + try { + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.CLEAR_PASSWORD); + operation.setType(Operation.Type.COMMAND); + Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance."; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/control-camera") + @Override + public Response configureCamera(CameraBeanWrapper cameraBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking Android Camera operation"); + } + + try { + if (cameraBeanWrapper == null || cameraBeanWrapper.getOperation() == null) { + String errorMessage = "The payload of the configure camera operation is incorrect."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + Camera camera = cameraBeanWrapper.getOperation(); + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.CAMERA); + operation.setType(Operation.Type.COMMAND); + operation.setEnabled(camera.isEnabled()); + Activity activity = AndroidDeviceUtils.getOperationResponse(cameraBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/info") + @Override + public Response getDeviceInformation(List deviceIDs) { + if (log.isDebugEnabled()) { + log.debug("Invoking get Android device information operation"); + } + + try { + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO); + operation.setType(Operation.Type.COMMAND); + Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + } + } + + @POST + @Path("/logcat") + @Override + public Response getDeviceLogcat(List deviceIDs) { + if (log.isDebugEnabled()) { + log.debug("Invoking get Android device logcat operation"); + } + + try { + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.LOGCAT); + operation.setType(Operation.Type.COMMAND); + Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + } + } + + @POST + @Path("/enterprise-wipe") + @Override + public Response wipeDevice(List deviceIDs) { + if (log.isDebugEnabled()) { + log.debug("Invoking enterprise-wipe device operation"); + } + + try { + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.ENTERPRISE_WIPE); + operation.setType(Operation.Type.COMMAND); + Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/wipe") + @Override + public Response wipeData(WipeDataBeanWrapper wipeDataBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking Android wipe-data device operation"); + } + + try { + if (wipeDataBeanWrapper == null || wipeDataBeanWrapper.getOperation() == null) { + String errorMessage = "WipeData bean is empty."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + WipeData wipeData = wipeDataBeanWrapper.getOperation(); + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.WIPE_DATA); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(wipeData.toJSON()); + Activity activity = AndroidDeviceUtils.getOperationResponse(wipeDataBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/applications") + @Override + public Response getApplications(List deviceIDs) { + if (log.isDebugEnabled()) { + log.debug("Invoking Android getApplicationList device operation"); + } + + try { + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.APPLICATION_LIST); + operation.setType(Operation.Type.COMMAND); + Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/ring") + @Override + public Response ringDevice(List deviceIDs) { + if (log.isDebugEnabled()) { + log.debug("Invoking Android ring-device device operation"); + } + + try { + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.DEVICE_RING); + operation.setType(Operation.Type.COMMAND); + Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/reboot") + @Override + public Response rebootDevice(List deviceIDs) { + if (log.isDebugEnabled()) { + log.debug("Invoking Android reboot-device device operation"); + } + + try { + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.DEVICE_REBOOT); + operation.setType(Operation.Type.COMMAND); + Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/mute") + @Override + public Response muteDevice(List deviceIDs) { + if (log.isDebugEnabled()) { + log.debug("Invoking mute device operation"); + } + + try { + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.DEVICE_MUTE); + operation.setType(Operation.Type.COMMAND); + operation.setEnabled(true); + Activity activity = AndroidDeviceUtils.getOperationResponse(deviceIDs, operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/install-application") + @Override + public Response installApplication(ApplicationInstallationBeanWrapper applicationInstallationBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking 'InstallApplication' operation"); + } + + try { + if (applicationInstallationBeanWrapper == null || applicationInstallationBeanWrapper.getOperation() == + null) { + String errorMessage = "The payload of the application installing operation is incorrect"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + + ApplicationInstallation applicationInstallation = applicationInstallationBeanWrapper.getOperation(); + validateApplicationUrl(applicationInstallation.getUrl()); + validateApplicationType(applicationInstallation.getType()); + validateScheduleDate(applicationInstallation.getSchedule()); + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.INSTALL_APPLICATION); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(applicationInstallation.toJSON()); + Activity activity = AndroidDeviceUtils + .getOperationResponse(applicationInstallationBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (JSONException e) { + String errorMessage = "Invalid payload for the operation."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/update-application") + @Override + public Response updateApplication(ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking 'UpdateApplication' operation"); + } + + try { + if (applicationUpdateBeanWrapper == null || applicationUpdateBeanWrapper.getOperation() == null) { + String errorMessage = "The payload of the application update operation is incorrect"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + ApplicationUpdate applicationUpdate = applicationUpdateBeanWrapper.getOperation(); + validateApplicationUrl(applicationUpdate.getUrl()); + validateApplicationType(applicationUpdate.getType()); + validateScheduleDate(applicationUpdate.getSchedule()); + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.UPDATE_APPLICATION); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(applicationUpdate.toJSON()); + + Activity activity = AndroidDeviceUtils + .getOperationResponse(applicationUpdateBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/uninstall-application") + @Override + public Response uninstallApplication(ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking 'UninstallApplication' operation"); + } + + try { + if (applicationUninstallationBeanWrapper == null || + applicationUninstallationBeanWrapper.getOperation() == null) { + String errorMessage = "The payload of the application uninstalling operation is incorrect"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + ApplicationUninstallation applicationUninstallation = applicationUninstallationBeanWrapper.getOperation(); + validateApplicationType(applicationUninstallation.getType()); + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.UNINSTALL_APPLICATION); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(applicationUninstallation.toJSON()); + Activity activity = AndroidDeviceUtils + .getOperationResponse(applicationUninstallationBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/blacklist-applications") + @Override + public Response blacklistApplications(@Valid BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking 'Blacklist-Applications' operation"); + } + + try { + if (blacklistApplicationsBeanWrapper == null || blacklistApplicationsBeanWrapper.getOperation() == null) { + String errorMessage = "The payload of the blacklisting apps operation is incorrect"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + BlacklistApplications blacklistApplications = blacklistApplicationsBeanWrapper.getOperation(); + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.BLACKLIST_APPLICATIONS); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(blacklistApplications.toJSON()); + Activity activity = AndroidDeviceUtils + .getOperationResponse(blacklistApplicationsBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/upgrade-firmware") + @Override + public Response upgradeFirmware(UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking Android upgrade-firmware device operation"); + } + + try { + if (upgradeFirmwareBeanWrapper == null || upgradeFirmwareBeanWrapper.getOperation() == null) { + String errorMessage = "The payload of the upgrade firmware operation is incorrect"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + UpgradeFirmware upgradeFirmware = upgradeFirmwareBeanWrapper.getOperation(); + validateScheduleDate(upgradeFirmware.getSchedule()); + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.UPGRADE_FIRMWARE); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(upgradeFirmware.toJSON()); + Activity activity = AndroidDeviceUtils + .getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/configure-vpn") + @Override + public Response configureVPN(VpnBeanWrapper vpnConfiguration) { + if (log.isDebugEnabled()) { + log.debug("Invoking Android VPN device operation"); + } + + try { + if (vpnConfiguration == null || vpnConfiguration.getOperation() == null) { + String errorMessage = "The payload of the VPN operation is incorrect"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + Vpn vpn = vpnConfiguration.getOperation(); + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.VPN); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(vpn.toJSON()); + Activity activity = AndroidDeviceUtils.getOperationResponse(vpnConfiguration.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/send-notification") + @Override + public Response sendNotification(NotificationBeanWrapper notificationBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking 'notification' operation"); + } + + try { + if (notificationBeanWrapper == null || notificationBeanWrapper.getOperation() == null) { + String errorMessage = "The payload of the notification operation is incorrect"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + Notification notification = notificationBeanWrapper.getOperation(); + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.NOTIFICATION); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(notification.toJSON()); + Activity activity = AndroidDeviceUtils.getOperationResponse(notificationBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/configure-wifi") + @Override + public Response configureWifi(WifiBeanWrapper wifiBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking 'configure wifi' operation"); + } + + try { + if (wifiBeanWrapper == null || wifiBeanWrapper.getOperation() == null) { + String errorMessage = "The payload of the wifi operation is incorrect"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + Wifi wifi = wifiBeanWrapper.getOperation(); + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.WIFI); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(wifi.toJSON()); + + Activity activity = AndroidDeviceUtils.getOperationResponse(wifiBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/encrypt-storage") + @Override + public Response encryptStorage(EncryptionBeanWrapper encryptionBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking 'encrypt' operation"); + } + + try { + if (encryptionBeanWrapper == null || encryptionBeanWrapper.getOperation() == null) { + String errorMessage = "The payload of the device encryption operation is incorrect"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + DeviceEncryption deviceEncryption = encryptionBeanWrapper.getOperation(); + CommandOperation operation = new CommandOperation(); + operation.setCode(AndroidConstants.OperationCodes.ENCRYPT_STORAGE); + operation.setType(Operation.Type.COMMAND); + operation.setEnabled(deviceEncryption.isEncrypted()); + Activity activity = AndroidDeviceUtils.getOperationResponse(encryptionBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/change-lock-code") + @Override + public Response changeLockCode(LockCodeBeanWrapper lockCodeBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking 'change lock code' operation"); + } + + try { + if (lockCodeBeanWrapper == null || lockCodeBeanWrapper.getOperation() == null) { + String errorMessage = "The payload of the change lock code operation is incorrect"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + LockCode lockCode = lockCodeBeanWrapper.getOperation(); + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.CHANGE_LOCK_CODE); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(lockCode.toJSON()); + Activity activity = AndroidDeviceUtils.getOperationResponse(lockCodeBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("/set-password-policy") + @Override + public Response setPasswordPolicy(PasswordPolicyBeanWrapper passwordPolicyBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking 'password policy' operation"); + } + + try { + if (passwordPolicyBeanWrapper == null || passwordPolicyBeanWrapper.getOperation() == null) { + String errorMessage = "The payload of the change password policy operation is incorrect"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + PasscodePolicy passcodePolicy = passwordPolicyBeanWrapper.getOperation(); + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.PASSCODE_POLICY); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(passcodePolicy.toJSON()); + + Activity activity = AndroidDeviceUtils + .getOperationResponse(passwordPolicyBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + @POST + @Path("set-webclip") + @Override + public Response setWebClip(WebClipBeanWrapper webClipBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking 'webclip' operation"); + } + + try { + + if (webClipBeanWrapper == null || webClipBeanWrapper.getOperation() == null) { + String errorMessage = "The payload of the add webclip operation is incorrect"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + WebClip webClip = webClipBeanWrapper.getOperation(); + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.WEBCLIP); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(webClip.toJSON()); + + Activity activity = AndroidDeviceUtils.getOperationResponse(webClipBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } + } + + private static void validateApplicationUrl(String apkUrl) { + try { + URL url = new URL(apkUrl); + URLConnection conn = url.openConnection(); + if (((HttpURLConnection) conn).getResponseCode() != HttpURLConnection.HTTP_OK) { + String errorMessage = "URL is not pointed to a downloadable file."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } catch (MalformedURLException e) { + String errorMessage = "Malformed application url."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } catch (IOException e) { + String errorMessage = "Invalid application url."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } + + private static void validateApplicationType(String type) { + if (type != null) { + if (!"enterprise".equalsIgnoreCase(type) + && !"public".equalsIgnoreCase(type) + && !"webapp".equalsIgnoreCase(type)) { + String errorMessage = "Invalid application type."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } else { + String errorMessage = "Application type is missing."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } + + private static void validateScheduleDate(String dateString) { + try { + if (dateString != null && !dateString.isEmpty()) { + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); + sdf.setLenient(false); + sdf.parse(dateString); + } + } catch (ParseException e) { + String errorMessage = "Issue in validating the schedule date"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java new file mode 100644 index 000000000..9990421f7 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java @@ -0,0 +1,481 @@ +/* + * 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.services.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; +import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; +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.common.policy.mgt.monitor.PolicyComplianceException; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; +import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; +import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; +import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidApplication; +import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidDevice; +import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; +import org.wso2.carbon.mdm.services.android.services.DeviceManagementService; +import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; +import org.wso2.carbon.mdm.services.android.util.AndroidConstants; +import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils; +import org.wso2.carbon.mdm.services.android.util.Message; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.core.PolicyManagerService; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +@Path("/devices") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class DeviceManagementServiceImpl implements DeviceManagementService { + + private static final String OPERATION_ERROR_STATUS = "ERROR"; + private static final Log log = LogFactory.getLog(DeviceManagementServiceImpl.class); + + @PUT + @Path("/{id}/applications") + @Override + public Response updateApplicationList(@PathParam("id") + @NotNull + @Size(min = 2, max = 45) + @Pattern(regexp = "^[A-Za-z0-9]*$") + String id, List androidApplications) { + Application application; + List applications = new ArrayList<>(); + for (AndroidApplication androidApplication : androidApplications) { + application = new Application(); + application.setPlatform(androidApplication.getPlatform()); + application.setCategory(androidApplication.getCategory()); + application.setName(androidApplication.getName()); + application.setLocationUrl(androidApplication.getLocationUrl()); + application.setImageUrl(androidApplication.getImageUrl()); + application.setVersion(androidApplication.getVersion()); + application.setType(androidApplication.getType()); + application.setAppProperties(androidApplication.getAppProperties()); + application.setApplicationIdentifier(androidApplication.getApplicationIdentifier()); + application.setMemoryUsage(androidApplication.getMemoryUsage()); + applications.add(application); + } + Message responseMessage = new Message(); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(id); + deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + try { + AndroidAPIUtils.getApplicationManagerService(). + updateApplicationListInstalledInDevice(deviceIdentifier, applications); + responseMessage.setResponseMessage("Device information has modified successfully."); + return Response.status(Response.Status.ACCEPTED).entity(responseMessage).build(); + } catch (ApplicationManagementException e) { + String msg = "Error occurred while modifying the application list."; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + } + + @PUT + @Path("/{id}/pending-operations") + @Override + public Response getPendingOperations(@PathParam("id") String id, + @HeaderParam("If-Modified-Since") String ifModifiedSince, + List resultOperations) { + if (id == null || id.isEmpty()) { + String msg = "Device identifier is null or empty, hence returning device not found"; + log.error(msg); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } + DeviceIdentifier deviceIdentifier = AndroidDeviceUtils.convertToDeviceIdentifierObject(id); + try { + if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) { + String msg = "Device not found for identifier '" + id + "'"; + log.error(msg); + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); + } + if (log.isDebugEnabled()) { + log.debug("Invoking Android pending operations:" + id); + } + if (resultOperations != null && !resultOperations.isEmpty()) { + updateOperations(id, resultOperations); + } + } catch (OperationManagementException e) { + String msg = "Issue in retrieving operation management service instance"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } catch (PolicyComplianceException e) { + String msg = "Issue in updating Monitoring operation"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } catch (DeviceManagementException e) { + String msg = "Issue in retrieving device management service instance"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } catch (ApplicationManagementException e) { + String msg = "Issue in retrieving application management service instance"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } catch (NotificationManagementException e) { + String msg = "Issue in retrieving Notification management service instance"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + + List pendingOperations; + try { + pendingOperations = AndroidDeviceUtils.getPendingOperations(deviceIdentifier); + } catch (OperationManagementException e) { + String msg = "Issue in retrieving operation management service instance"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + return Response.status(Response.Status.CREATED).entity(pendingOperations).build(); + } + + private void updateOperations(String deviceId, List operations) + throws OperationManagementException, PolicyComplianceException, + ApplicationManagementException, NotificationManagementException, DeviceManagementException { + for (org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation : operations) { + AndroidDeviceUtils.updateOperation(deviceId, operation); + if (OPERATION_ERROR_STATUS.equals(operation.getStatus().toString())) { + org.wso2.carbon.device.mgt.common.notification.mgt.Notification notification = new + org.wso2.carbon.device.mgt.common.notification.mgt.Notification(); + DeviceIdentifier id = new DeviceIdentifier(); + id.setId(deviceId); + id.setType(AndroidConstants.DEVICE_TYPE_ANDROID); + String deviceName = AndroidAPIUtils.getDeviceManagementService().getDevice(id, false).getName(); + notification.setOperationId(operation.getId()); + notification.setStatus(org.wso2.carbon.device.mgt.common.notification.mgt.Notification. + Status.NEW.toString()); + notification.setDescription(operation.getCode() + " operation failed to execute on device " + + deviceName + " (ID: " + deviceId + ")"); + AndroidAPIUtils.getNotificationManagementService().addNotification(id, notification); + } + if (log.isDebugEnabled()) { + log.debug("Updating operation '" + operation.toString() + "'"); + } + } + } + + @POST + @Override + public Response enrollDevice(@Valid AndroidDevice androidDevice) { + if (androidDevice == null) { + String errorMessage = "The payload of the android device enrollment is incorrect."; + log.error(errorMessage); + throw new org.wso2.carbon.mdm.services.android.exception.BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + try { + Device device = new Device(); + device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + device.setEnrolmentInfo(androidDevice.getEnrolmentInfo()); + device.getEnrolmentInfo().setOwner(AndroidAPIUtils.getAuthenticatedUser()); + device.setDeviceInfo(androidDevice.getDeviceInfo()); + device.setDeviceIdentifier(androidDevice.getDeviceIdentifier()); + device.setDescription(androidDevice.getDescription()); + device.setName(androidDevice.getName()); + device.setFeatures(androidDevice.getFeatures()); + device.setProperties(androidDevice.getProperties()); + + boolean status = AndroidAPIUtils.getDeviceManagementService().enrollDevice(device); + if (status) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(androidDevice.getDeviceIdentifier(), + device.getType()); + + //Immediately update location information from initial payload + DeviceLocation deviceLocation = extractLocation(deviceIdentifier, androidDevice.getProperties()); + if (deviceLocation != null) { + try { + DeviceInformationManager informationManager = AndroidAPIUtils + .getDeviceInformationManagerService(); + informationManager.addDeviceLocation(deviceLocation); + } catch (DeviceDetailsMgtException e) { + String msg = "Error occurred while updating the device location upon android " + + "', which carries the id '" + androidDevice.getDeviceIdentifier() + "'"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + } + + //Adding Tasks to get device information + List deviceIdentifiers = new ArrayList<>(); + deviceIdentifiers.add(deviceIdentifier); + + List taskOperaions = new ArrayList<>(); + taskOperaions.add(AndroidConstants.OperationCodes.APPLICATION_LIST); + taskOperaions.add(AndroidConstants.OperationCodes.DEVICE_INFO); + taskOperaions.add(AndroidConstants.OperationCodes.DEVICE_LOCATION); + + for (String str : taskOperaions) { + CommandOperation operation = new CommandOperation(); + operation.setEnabled(true); + operation.setType(Operation.Type.COMMAND); + operation.setCode(str); + AndroidAPIUtils.getDeviceManagementService(). + addOperation(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, + operation, deviceIdentifiers); + } + PolicyManagerService policyManagerService = AndroidAPIUtils.getPolicyManagerService(); + policyManagerService.getEffectivePolicy(new DeviceIdentifier(androidDevice.getDeviceIdentifier(), device.getType())); + + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.OK.toString()); + responseMessage.setResponseMessage("Android device, which carries the id '" + + androidDevice.getDeviceIdentifier() + "' has successfully been enrolled"); + return Response.status(Response.Status.OK).entity(responseMessage).build(); + } else { + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString()); + responseMessage.setResponseMessage("Failed to enroll '" + + device.getType() + "' device, which carries the id '" + + androidDevice.getDeviceIdentifier() + "'"); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(responseMessage).build(); + } + } catch (DeviceManagementException e) { + String msg = "Error occurred while enrolling the android, which carries the id '" + + androidDevice.getDeviceIdentifier() + "'"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } catch (PolicyManagementException e) { + String msg = "Error occurred while enforcing default enrollment policy upon android " + + "', which carries the id '" + + androidDevice.getDeviceIdentifier() + "'"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } catch (OperationManagementException e) { + String msg = "Error occurred while enforcing default enrollment policy upon android " + + "', which carries the id '" + + androidDevice.getDeviceIdentifier() + "'"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } catch (InvalidDeviceException e) { + String msg = "Error occurred while enforcing default enrollment policy upon android " + + "', which carries the id '" + + androidDevice.getDeviceIdentifier() + "'"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + } + + @GET + @Path("/{id}/status") + @Override + public Response isEnrolled(@PathParam("id") String id, @HeaderParam("If-Modified-Since") String ifModifiedSince) { + DeviceIdentifier deviceIdentifier = AndroidDeviceUtils.convertToDeviceIdentifierObject(id); + try { + Device device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier); + if (device != null) { + String status = String.valueOf(device.getEnrolmentInfo().getStatus()); + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.OK.toString()); + responseMessage + .setResponseMessage("Status of android device that carries the id '" + id + "' is " + status); + return Response.status(Response.Status.OK).entity(responseMessage).build(); + } else { + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.NOT_FOUND.toString()); + responseMessage.setResponseMessage("No Android device is found upon the id '" + id + "'"); + return Response.status(Response.Status.NOT_FOUND).entity(responseMessage).build(); + } + } catch (DeviceManagementException e) { + String msg = "Error occurred while checking enrollment status of the device."; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + } + + @PUT + @Path("/{id}") + @Override + public Response modifyEnrollment(@PathParam("id") String id, @Valid AndroidDevice androidDevice) { + Device device; + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(id); + deviceIdentifier.setType(AndroidConstants.DEVICE_TYPE_ANDROID); + try { + device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier); + } catch (DeviceManagementException e) { + String msg = "Error occurred while getting enrollment details of the Android device that carries the id '" + + id + "'"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + + if (androidDevice == null) { + String errorMessage = "The payload of the android device enrollment is incorrect."; + log.error(errorMessage); + throw new org.wso2.carbon.mdm.services.android.exception.BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + if (device == null) { + String errorMessage = "The device to be modified doesn't exist."; + log.error(errorMessage); + throw new org.wso2.carbon.mdm.services.android.exception.NotFoundException( + new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage(errorMessage).build()); + } + if(androidDevice.getEnrolmentInfo() != null){ + device.setEnrolmentInfo(device.getEnrolmentInfo()); + } + device.getEnrolmentInfo().setOwner(AndroidAPIUtils.getAuthenticatedUser()); + if(androidDevice.getDeviceInfo() != null) { + device.setDeviceInfo(androidDevice.getDeviceInfo()); + } + device.setDeviceIdentifier(androidDevice.getDeviceIdentifier()); + if(androidDevice.getDescription() != null) { + device.setDescription(androidDevice.getDescription()); + } + if(androidDevice.getName() != null) { + device.setName(androidDevice.getName()); + } + if(androidDevice.getFeatures() != null) { + device.setFeatures(androidDevice.getFeatures()); + } + if(androidDevice.getProperties() != null) { + device.setProperties(androidDevice.getProperties()); + } + boolean result; + try { + device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + result = AndroidAPIUtils.getDeviceManagementService().modifyEnrollment(device); + if (result) { + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.ACCEPTED.toString()); + responseMessage.setResponseMessage("Enrollment of Android device that " + + "carries the id '" + id + "' has successfully updated"); + return Response.status(Response.Status.ACCEPTED).entity(responseMessage).build(); + } else { + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.NOT_MODIFIED.toString()); + responseMessage.setResponseMessage("Enrollment of Android device that " + + "carries the id '" + id + "' has not been updated"); + return Response.status(Response.Status.NOT_MODIFIED).entity(responseMessage).build(); + } + } catch (DeviceManagementException e) { + String msg = "Error occurred while modifying enrollment of the Android device that carries the id '" + + id + "'"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + } + + @DELETE + @Path("/{id}") + @Override + public Response disEnrollDevice(@PathParam("id") String id) { + boolean result; + DeviceIdentifier deviceIdentifier = AndroidDeviceUtils.convertToDeviceIdentifierObject(id); + try { + result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); + if (result) { + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.OK.toString()); + responseMessage.setResponseMessage("Android device that carries id '" + id + + "' has successfully dis-enrolled"); + return Response.status(Response.Status.OK).entity(responseMessage).build(); + } else { + Message responseMessage = new Message(); + responseMessage.setResponseCode(Response.Status.NOT_FOUND.toString()); + responseMessage.setResponseMessage("Android device that carries id '" + id + + "' has not been dis-enrolled"); + return Response.status(Response.Status.NOT_FOUND).entity(responseMessage).build(); + } + } catch (DeviceManagementException e) { + String msg = "Error occurred while dis-enrolling the Android device that carries the id '" + id + "'"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + } + + /** + * Extracts the device location + * + * @param deviceIdentifier + * @param properties + * @return returns null when location not found + */ + private DeviceLocation extractLocation(DeviceIdentifier deviceIdentifier, List properties) + throws DeviceManagementException { + + DeviceLocation location = null; + String latitude = "", longitude = ""; + + if (properties == null) return null; + + for (Device.Property property : properties) { + String propertyName = property.getName(); + if (propertyName == null) continue; + if (propertyName.equals("LATITUDE")) { + latitude = property.getValue(); + if (!longitude.isEmpty()) break; + } else if (propertyName.equals("LONGITUDE")) { + longitude = property.getValue(); + if (!latitude.isEmpty()) break; + } + } + + if (!latitude.isEmpty() && !longitude.isEmpty()) { + location = new DeviceLocation(); + location.setLatitude(Double.valueOf(latitude)); + location.setLongitude(Double.valueOf(longitude)); + location.setDeviceIdentifier(deviceIdentifier); + Device savedDevice = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier, false); + location.setDeviceId(savedDevice.getId()); + } + return location; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java new file mode 100644 index 000000000..dad6cb454 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceTypeConfigurationServiceImpl.java @@ -0,0 +1,156 @@ +/* + * 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.services.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +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.mdm.services.android.bean.AndroidPlatformConfiguration; +import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; +import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; +import org.wso2.carbon.mdm.services.android.services.DeviceTypeConfigurationService; +import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; +import org.wso2.carbon.mdm.services.android.util.AndroidConstants; + +import javax.validation.Valid; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +@Path("/configuration") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class DeviceTypeConfigurationServiceImpl implements DeviceTypeConfigurationService { + + private static final Log log = LogFactory.getLog(DeviceTypeConfigurationServiceImpl.class); + + @GET + @Override + public Response getConfiguration( + @HeaderParam("If-Modified-Since") String ifModifiedSince) { + String msg; + PlatformConfiguration platformConfiguration; + List configs; + try { + platformConfiguration = AndroidAPIUtils.getDeviceManagementService(). + getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + if (platformConfiguration != null) { + configs = platformConfiguration.getConfiguration(); + } else { + platformConfiguration = new PlatformConfiguration(); + configs = new ArrayList<>(); + } + ConfigurationEntry entry = new ConfigurationEntry(); + License license = AndroidAPIUtils.getDeviceManagementService().getLicense( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, AndroidConstants. + TenantConfigProperties.LANGUAGE_US); + + if (license != null && configs != null) { + entry.setContentType(AndroidConstants.TenantConfigProperties.CONTENT_TYPE_TEXT); + entry.setName(AndroidConstants.TenantConfigProperties.LICENSE_KEY); + entry.setValue(license.getText()); + configs.add(entry); + platformConfiguration.setConfiguration(configs); + } + } catch (DeviceManagementException e) { + msg = "Error occurred while retrieving the Android tenant configuration"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + return Response.status(Response.Status.OK).entity(platformConfiguration).build(); + } + + @PUT + @Override + public Response updateConfiguration(@Valid AndroidPlatformConfiguration androidPlatformConfiguration) { + String msg; + ConfigurationEntry licenseEntry = null; + PlatformConfiguration configuration = new PlatformConfiguration(); + if (androidPlatformConfiguration == null) { + String errorMessage = "The payload of the android platform configuration is incorrect."; + log.error(errorMessage); + throw new org.wso2.carbon.mdm.services.android.exception.BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + configuration.setConfiguration(androidPlatformConfiguration.getConfiguration()); + try { + configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + List configs = configuration.getConfiguration(); + for (ConfigurationEntry entry : configs) { + if (AndroidConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) { + License license = new License(); + license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + license.setLanguage(AndroidConstants.TenantConfigProperties.LANGUAGE_US); + license.setVersion("1.0.0"); + license.setText(entry.getValue().toString()); + AndroidAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants. + MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, license); + licenseEntry = entry; + } + } + + if (licenseEntry != null) { + configs.remove(licenseEntry); + } + configuration.setConfiguration(configs); + AndroidAPIUtils.getDeviceManagementService().saveConfiguration(configuration); + //AndroidAPIUtils.getGCMService().resetTenantConfigCache(); + } catch (DeviceManagementException e) { + msg = "Error occurred while modifying configuration settings of Android platform"; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + return Response.status(Response.Status.OK).entity("Android platform configuration has been updated successfully.").build(); + } + + + @GET + @Path("/license") + @Produces(MediaType.TEXT_PLAIN) + public Response getLicense( + @HeaderParam("If-Modified-Since") String ifModifiedSince) { + License license; + try { + license = + AndroidAPIUtils.getDeviceManagementService().getLicense( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, + DeviceManagementConstants.LanguageCodes.LANGUAGE_CODE_ENGLISH_US); + } catch (DeviceManagementException e) { + String msg = "Error occurred while retrieving the license configured for Android 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 == null) ? null : license.getText()).build(); + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java new file mode 100644 index 000000000..5616e571f --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java @@ -0,0 +1,222 @@ +/* + * 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.services.impl; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; +import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; +import org.wso2.carbon.mdm.services.android.bean.DeviceState; +import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; +import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper; +import org.wso2.carbon.mdm.services.android.exception.BadRequestException; +import org.wso2.carbon.mdm.services.android.exception.NotFoundException; +import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; +import org.wso2.carbon.mdm.services.android.services.EventReceiverService; +import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; +import org.wso2.carbon.mdm.services.android.util.AndroidConstants; +import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils; +import org.wso2.carbon.mdm.services.android.util.Message; + +import javax.validation.Valid; +import javax.validation.constraints.Size; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; +import java.util.List; + +@Path("/events") +public class EventReceiverServiceImpl implements EventReceiverService { + private static final String EVENT_STREAM_DEFINITION = "org.wso2.iot.LocationStream"; + private static final Log log = LogFactory.getLog(EventReceiverServiceImpl.class); + private Gson gson = new Gson(); + + private static final String LONGITUDE = "longitude"; + private static final String LATITUDE = "latitude"; + private static final String TIME_STAMP = "timeStamp"; + private static final String LOCATION_EVENT_TYPE = "location"; + + @POST + @Path("/publish") + @Override + public Response publishEvents(@Valid EventBeanWrapper eventBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking Android device event logging."); + } + try { + if (!DeviceManagerUtil.isOperationAnalyticsEnabled()) { + return Response.status(Response.Status.ACCEPTED).entity("Event is publishing has not enabled.").build(); + } + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(eventBeanWrapper.getDeviceIdentifier(), + AndroidConstants.DEVICE_TYPE_ANDROID); + Device device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier); + if (device != null && EnrolmentInfo.Status.ACTIVE != device.getEnrolmentInfo().getStatus()){ + return Response.status(Response.Status.ACCEPTED).entity("Device is not in Active state.").build(); + } else if (device == null){ + return Response.status(Response.Status.ACCEPTED).entity("Device is not enrolled yet.").build(); + } + } catch (DeviceManagementException e) { + log.error("Error occurred while checking Operation Analytics is Enabled.", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); + } + String eventType = eventBeanWrapper.getType(); + if (!LOCATION_EVENT_TYPE.equals(eventType)) { + String msg = "Dropping Android " + eventType + " Event.Only Location Event Type is supported."; + log.warn(msg); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } + Message message = new Message(); + Object[] metaData = {eventBeanWrapper.getDeviceIdentifier(), AndroidConstants.DEVICE_TYPE_ANDROID}; + String eventPayload = eventBeanWrapper.getPayload(); + JsonObject jsonObject = gson.fromJson(eventPayload, JsonObject.class); + Object[] payload = { + jsonObject.get(TIME_STAMP).getAsLong(), + jsonObject.get(LATITUDE).getAsDouble(), + jsonObject.get(LONGITUDE).getAsDouble() + }; + try { + if (AndroidAPIUtils.getEventPublisherService().publishEvent( + EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload)) { + message.setResponseCode("Event is published successfully."); + return Response.status(Response.Status.CREATED).entity(message).build(); + } else { + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage("Error occurred while " + + "publishing the event.").build()); + } + } catch (DataPublisherConfigurationException e) { + String msg = "Error occurred while getting the Data publisher Service instance."; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + } + + @GET + @Override + public Response retrieveAlerts(@QueryParam("id") + @Size(min = 2, max = 45) + String deviceId, + @QueryParam("from") long from, + @QueryParam("to") long to, + @Size(min = 2, max = 45) + @QueryParam("type") String type, + @HeaderParam("If-Modified-Since") String ifModifiedSince) { + + if (from != 0l && to != 0l && deviceId != null) { + return retrieveAlertFromDate(deviceId, from, to); + } else if (deviceId != null && type != null) { + return retrieveAlertByType(deviceId, type); + } else if (deviceId != null) { + return retrieveAlert(deviceId); + } else { + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request must contain " + + "the device identifier. Optionally, both from and to value should be present to get " + + "alerts between times.").build()); + } + } + + private Response retrieveAlert(String deviceId) { + if (log.isDebugEnabled()) { + log.debug("Retrieving events for given device Identifier."); + } + String query = "deviceIdentifier:" + deviceId; + List deviceStates; + try { + deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); + if (deviceStates == null) { + throw new NotFoundException( + new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + + "published for Device: " + deviceId + ".").build()); + } else { + return Response.status(Response.Status.OK).entity(deviceStates).build(); + } + } catch (AnalyticsException e) { + String msg = "Error occurred while getting published events for specific device: " + deviceId + "."; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + } + + private Response retrieveAlertFromDate(String deviceId, long from, long to) { + String fromDate = String.valueOf(from); + String toDate = String.valueOf(to); + if (log.isDebugEnabled()) { + log.debug("Retrieving events for given device Identifier and time period."); + } + + String query = "deviceIdentifier:" + deviceId + " AND _timestamp: [" + fromDate + " TO " + toDate + "]"; + List deviceStates; + try { + deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); + if (deviceStates == null) { + throw new NotFoundException( + new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + + "published on given date for given Device: " + deviceId + ".").build()); + + } else { + return Response.status(Response.Status.OK).entity(deviceStates).build(); + } + } catch (AnalyticsException e) { + String msg = "Error occurred while getting published events for specific " + + "Device: " + deviceId + " on given Date."; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + } + + private Response retrieveAlertByType(String deviceId, String type) { + if (log.isDebugEnabled()) { + log.debug("Retrieving events for given device identifier and type."); + } + String query = "deviceIdentifier:" + deviceId + " AND type:" + type; + List deviceStates; + try { + deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); + if (deviceStates == null) { + throw new NotFoundException( + new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + + "published for given Device: '" + deviceId + "' and given specific Type.").build()); + + } else { + return Response.status(Response.Status.OK).entity(deviceStates).build(); + } + } catch (AnalyticsException e) { + String msg = "Error occurred while getting published events for specific " + + "Device: " + deviceId + "and given specific Type."; + log.error(msg, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + } + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java new file mode 100644 index 000000000..f8c37fe5f --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidAPIUtils.java @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2015, 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.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.analytics.api.AnalyticsDataAPI; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService; +import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; +import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.policy.mgt.core.PolicyManagerService; + +/** + * AndroidAPIUtil class provides utility functions used by Android REST-API classes. + */ +public class AndroidAPIUtils { + + private static Log log = LogFactory.getLog(AndroidAPIUtils.class); + + private AndroidAPIUtils(){ + throw new IllegalStateException("Utility class"); + } + + public static String getAuthenticatedUser() { + PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + String username = threadLocalCarbonContext.getUsername(); + String tenantDomain = threadLocalCarbonContext.getTenantDomain(); + if (username != null && username.endsWith(tenantDomain)) { + return username.substring(0, username.lastIndexOf("@")); + } + return username; + } + + public static DeviceManagementProviderService getDeviceManagementService() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + DeviceManagementProviderService deviceManagementProviderService = + (DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null); + if (deviceManagementProviderService == null) { + String msg = "Device Management service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return deviceManagementProviderService; + } + + public static DeviceInformationManager getDeviceInformationManagerService() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + DeviceInformationManager informationManager = + (DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null); + if (informationManager == null) { + String msg = "Information Manager service not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return informationManager; + } + + public static PolicyManagerService getPolicyManagerService() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + PolicyManagerService policyManagerService = (PolicyManagerService) ctx.getOSGiService( + PolicyManagerService.class, null); + if (policyManagerService == null) { + String msg = "Policy Manager service has not initialized"; + log.error(msg); + throw new IllegalStateException(msg); + } + return policyManagerService; + } + + public static ApplicationManagementProviderService getApplicationManagerService() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ApplicationManagementProviderService applicationManagementProviderService = + (ApplicationManagementProviderService) ctx.getOSGiService(ApplicationManagementProviderService.class, null); + if (applicationManagementProviderService == null) { + String msg = "Application Management provider service has not initialized"; + log.error(msg); + throw new IllegalStateException(msg); + } + return applicationManagementProviderService; + } + + public static NotificationManagementService getNotificationManagementService() { + NotificationManagementService notificationManagementService; + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + notificationManagementService = (NotificationManagementService) ctx.getOSGiService( + NotificationManagementService.class, null); + if (notificationManagementService == null) { + String msg = "Notification Management service not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return notificationManagementService; + } + + public static EventsPublisherService getEventPublisherService() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + EventsPublisherService eventsPublisherService = + (EventsPublisherService) ctx.getOSGiService(EventsPublisherService.class, null); + if (eventsPublisherService == null) { + String msg = "Event Publisher service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return eventsPublisherService; + } + + public static AnalyticsDataAPI getAnalyticsDataAPI() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + AnalyticsDataAPI analyticsDataAPI = + (AnalyticsDataAPI) ctx.getOSGiService(AnalyticsDataAPI.class, null); + if (analyticsDataAPI == null) { + String msg = "Analytics api service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return analyticsDataAPI; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java new file mode 100644 index 000000000..3a93305bd --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2015, 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.util; + +/** + * Defines constants used in Android-REST API bundle. + */ +public final class AndroidConstants { + + public static final String DEVICE_TYPE_ANDROID = "android"; + public static final String HEADER_CONTENT_TYPE = "Content-Type"; + public static final String APPLICATION_JSON = "application/json"; + public static final String SCOPE = "scope"; + + public final class DeviceProperties { + private DeviceProperties() { + throw new AssertionError(); + } + + public static final String PROPERTY_USER_KEY = "username"; + public static final String PROPERTY_DEVICE_KEY = "device"; + } + + public final class DeviceFeatures { + private DeviceFeatures() { + throw new AssertionError(); + } + } + + public final class DeviceConstants { + private DeviceConstants() { + throw new AssertionError(); + } + + public static final String DEVICE_MAC_KEY = "mac"; + public static final String DEVICE_DESCRIPTION_KEY = "description"; + public static final String DEVICE_OWNERSHIP_KEY = "ownership"; + public static final String DEVICE_PROPERTIES_KEY = "properties"; + public static final String DEVICE_FEATURES_KEY = "features"; + public static final String DEVICE_DATA = "data"; + public static final String DEVICE_ID_NOT_FOUND = "Device not found for device id: %s"; + public static final String DEVICE_ID_SERVICE_NOT_FOUND = + "Issue in retrieving device management service instance for device found at %s"; + } + + public final class Messages { + private Messages() { + throw new AssertionError(); + } + + public static final String DEVICE_MANAGER_SERVICE_NOT_AVAILABLE = + "Device Manager service not available"; + } + + public final class OperationCodes { + private OperationCodes() { + throw new AssertionError(); + } + + public static final String DEVICE_LOCK = "DEVICE_LOCK"; + public static final String FILE_DOWNLOAD = "FILE_UPLOAD_TO_THE_DEVICE"; + public static final String FILE_UPLOAD = "FILE_DOWNLOAD_FROM_THE_DEVICE"; + public static final String DEVICE_UNLOCK = "DEVICE_UNLOCK"; + public static final String DEVICE_LOCATION = "DEVICE_LOCATION"; + public static final String WIFI = "WIFI"; + public static final String CAMERA = "CAMERA"; + public static final String DEVICE_MUTE = "DEVICE_MUTE"; + public static final String PASSCODE_POLICY = "PASSCODE_POLICY"; + public static final String DEVICE_INFO = "DEVICE_INFO"; + public static final String ENTERPRISE_WIPE = "ENTERPRISE_WIPE"; + public static final String CLEAR_PASSWORD = "CLEAR_PASSWORD"; + public static final String WIPE_DATA = "WIPE_DATA"; + public static final String APPLICATION_LIST = "APPLICATION_LIST"; + public static final String CHANGE_LOCK_CODE = "CHANGE_LOCK_CODE"; + public static final String INSTALL_APPLICATION = "INSTALL_APPLICATION"; + public static final String UPDATE_APPLICATION = "UPDATE_APPLICATION"; + public static final String UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION"; + public static final String BLACKLIST_APPLICATIONS = "BLACKLIST_APPLICATIONS"; + public static final String ENCRYPT_STORAGE = "ENCRYPT_STORAGE"; + public static final String DEVICE_RING = "DEVICE_RING"; + public static final String DEVICE_REBOOT = "REBOOT"; + public static final String UPGRADE_FIRMWARE = "UPGRADE_FIRMWARE"; + public static final String NOTIFICATION = "NOTIFICATION"; + public static final String WEBCLIP = "WEBCLIP"; + public static final String DISENROLL = "DISENROLL"; + public static final String MONITOR = "MONITOR"; + public static final String VPN = "VPN"; + public static final String LOGCAT = "LOGCAT"; + public static final String APP_RESTRICTION = "APP-RESTRICTION"; + public static final String WORK_PROFILE = "WORK_PROFILE"; + } + + public final class StatusCodes { + private StatusCodes() { + throw new AssertionError(); + } + + public static final int MULTI_STATUS_HTTP_CODE = 207; + } + + public final class TenantConfigProperties { + private TenantConfigProperties() { + throw new AssertionError(); + } + + public static final String LICENSE_KEY = "androidEula"; + public static final String LANGUAGE_US = "en_US"; + public static final String CONTENT_TYPE_TEXT = "text"; + } + + public final class ApplicationProperties { + private ApplicationProperties() { + throw new AssertionError(); + } + + public static final String NAME = "name"; + public static final String IDENTIFIER = "package"; + public static final String USS = "USS"; + public static final String VERSION = "version"; + public static final String ICON = "icon"; + public static final String IS_ACTIVE = "isActive"; + } + + public final class ErrorMessages { + private ErrorMessages () { throw new AssertionError(); } + + public static final String STATUS_BAD_REQUEST_MESSAGE_DEFAULT = "Bad Request"; + + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java new file mode 100644 index 000000000..ad5f65f8d --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidDeviceUtils.java @@ -0,0 +1,463 @@ +/* + * 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.util; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.analytics.api.AnalyticsDataAPI; +import org.wso2.carbon.analytics.api.AnalyticsDataAPIUtil; +import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse; +import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry; +import org.wso2.carbon.analytics.datasource.commons.Record; +import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; +import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.context.PrivilegedCarbonContext; +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.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; +import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; +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.common.policy.mgt.monitor.ComplianceFeature; +import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; +import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils; +import org.wso2.carbon.mdm.services.android.bean.DeviceState; +import org.wso2.carbon.mdm.services.android.bean.ErrorListItem; +import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; +import org.wso2.carbon.mdm.services.android.exception.BadRequestException; + +import javax.validation.ConstraintViolation; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Util class for holding Android device related util methods. + */ +public class AndroidDeviceUtils { + + private static Log log = LogFactory.getLog(AndroidDeviceUtils.class); + + private AndroidDeviceUtils() { + throw new IllegalStateException("Utility class"); + } + + public static boolean isValidDeviceIdentifier(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + Device device = AndroidAPIUtils.getDeviceManagementService(). + getDevice(deviceIdentifier, false); + return !(device == null || device.getDeviceIdentifier() == null || + device.getDeviceIdentifier().isEmpty() || + device.getEnrolmentInfo() == null || + EnrolmentInfo.Status.REMOVED.equals(device.getEnrolmentInfo().getStatus())); + } + + public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) { + DeviceIdentifier identifier = new DeviceIdentifier(); + identifier.setId(deviceId); + identifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + return identifier; + } + + public static Activity getOperationResponse(List deviceIDs, Operation operation) + throws OperationManagementException, InvalidDeviceException { + if (deviceIDs == null || deviceIDs.isEmpty()) { + 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(AndroidConstants.DEVICE_TYPE_ANDROID); + deviceIdentifiers.add(deviceIdentifier); + } + return AndroidAPIUtils.getDeviceManagementService().addOperation( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, operation, deviceIdentifiers); + } + + public static List getAllEventsForDevice(String tableName, String query) throws AnalyticsException { + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + AnalyticsDataAPI analyticsDataAPI = AndroidAPIUtils.getAnalyticsDataAPI(); + int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query); + if (eventCount == 0) { + return null; + } + List resultEntries = analyticsDataAPI.search(tenantId, tableName, query, 0, eventCount); + List recordIds = getRecordIds(resultEntries); + AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds); + Map deviceStateses = createDeviceStatusData(AnalyticsDataAPIUtil.listRecords( + analyticsDataAPI, response)); + return getSortedDeviceStateData(deviceStateses, resultEntries); + } + + private static List getRecordIds(List searchResults) { + List ids = new ArrayList<>(); + for (SearchResultEntry searchResult : searchResults) { + ids.add(searchResult.getId()); + } + return ids; + } + + public static Map createDeviceStatusData(List records) { + Map deviceStatuses = new HashMap<>(); + for (Record record : records) { + DeviceState deviceState = createDeviceStatusData(record); + deviceStatuses.put(deviceState.getId(), deviceState); + } + return deviceStatuses; + } + + private static DeviceState createDeviceStatusData(Record record) { + DeviceState deviceState = new DeviceState(); + deviceState.setId(record.getId()); + deviceState.setValues(record.getValues()); + return deviceState; + } + + public static List getSortedDeviceStateData(Map sensorDatas, + List searchResults) { + List sortedRecords = new ArrayList<>(); + for (SearchResultEntry searchResultEntry : searchResults) { + sortedRecords.add(sensorDatas.get(searchResultEntry.getId())); + } + return sortedRecords; + } + + public static void updateOperation(String deviceId, Operation operation) + throws OperationManagementException, PolicyComplianceException, ApplicationManagementException { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + + if (!Operation.Status.ERROR.equals(operation.getStatus()) && + AndroidConstants.OperationCodes.MONITOR.equals(operation.getCode())) { + if (log.isDebugEnabled()) { + log.debug("Received compliance status from MONITOR operation ID: " + operation.getId()); + } + AndroidAPIUtils.getPolicyManagerService().checkPolicyCompliance(deviceIdentifier, + getComplianceFeatures(operation.getPayLoad())); + } else if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants. + OperationCodes.APPLICATION_LIST.equals(operation.getCode())) { + if (log.isDebugEnabled()) { + log.debug("Received applications list from device '" + deviceId + "'"); + } + updateApplicationList(operation, deviceIdentifier); + + } else if (!Operation.Status.ERROR.equals(operation.getStatus()) && AndroidConstants. + OperationCodes.DEVICE_INFO.equals(operation.getCode())) { + + try { + if (log.isDebugEnabled()) { + log.debug("Operation response: " + operation.getOperationResponse()); + } + Device device = new Gson().fromJson(operation.getOperationResponse(), Device.class); + org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo = convertDeviceToInfo(device); + updateDeviceInfo(deviceIdentifier, deviceInfo); + } catch (DeviceDetailsMgtException e) { + throw new OperationManagementException("Error occurred while updating the device information.", e); + } + + } else if (!Operation.Status.ERROR.equals(operation.getStatus()) && + AndroidConstants.OperationCodes.DEVICE_LOCATION.equals(operation.getCode())) { + try { + DeviceLocation location = new Gson().fromJson(operation.getOperationResponse(), DeviceLocation.class); + // reason for checking "location.getLatitude() != null" because when device fails to provide + // device location and send status instead, above Gson converter create new location object + // with null attributes + if (location != null && location.getLatitude() != null) { + location.setDeviceIdentifier(deviceIdentifier); + updateDeviceLocation(location); + } + } catch (DeviceDetailsMgtException e) { + throw new OperationManagementException("Error occurred while updating the device location.", e); + } + } + AndroidAPIUtils.getDeviceManagementService().updateOperation(deviceIdentifier, operation); + } + + public static List getPendingOperations + (DeviceIdentifier deviceIdentifier) throws OperationManagementException { + + List operations; + operations = AndroidAPIUtils.getDeviceManagementService().getPendingOperations(deviceIdentifier); + return operations; + } + + private static void updateApplicationList(Operation operation, DeviceIdentifier deviceIdentifier) + throws ApplicationManagementException { + // Parsing json string to get applications list. + if (operation.getOperationResponse() != null) { + JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse()); + JsonArray jsonArray = jsonElement.getAsJsonArray(); + Application app; + List applications = new ArrayList<>(jsonArray.size()); + for (JsonElement element : jsonArray) { + app = new Application(); + app.setName(element.getAsJsonObject(). + get(AndroidConstants.ApplicationProperties.NAME).getAsString()); + app.setApplicationIdentifier(element.getAsJsonObject(). + get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString()); + app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS) != null) { + app.setMemoryUsage(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS).getAsInt()); + } + if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) { + app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString()); + } + if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.IS_ACTIVE) != null) { + app.setActive(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.IS_ACTIVE).getAsBoolean()); + } + applications.add(app); + } + AndroidAPIUtils.getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications); + } else { + if (log.isDebugEnabled()) { + log.debug("Operation Response is null."); + } + } + + } + + private static void updateDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtException { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + DeviceInformationManager informationManager = + (DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null); + + informationManager.addDeviceLocation(deviceLocation); + } + + private static void updateDeviceInfo(DeviceIdentifier deviceId, DeviceInfo deviceInfo) + throws DeviceDetailsMgtException { + DeviceInformationManager informationManager = AndroidAPIUtils.getDeviceInformationManagerService(); + informationManager.addDeviceInfo(deviceId, deviceInfo); + } + + private static org.wso2.carbon.device.mgt.common.device.details.DeviceInfo convertDeviceToInfo(Device device) { + + org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo = + new org.wso2.carbon.device.mgt.common.device.details.DeviceInfo(); + if (deviceInfo.getDeviceDetailsMap() == null) { + deviceInfo.setDeviceDetailsMap(new HashMap<>()); + } + List props = device.getProperties(); + + for (Device.Property prop : props) { + if (Utils.getDeviceDetailsColumnNames().containsValue(prop.getName())) { + extractDefinedProperties(deviceInfo, prop); + } else { + extractMapProperties(deviceInfo, prop); + } + } + return deviceInfo; + } + + private static void extractMapProperties(DeviceInfo deviceInfo, Device.Property prop) { + if (prop.getName().equalsIgnoreCase("CPU_INFO")) { + deviceInfo.getDeviceDetailsMap().put("cpuUser", getProperty(prop.getValue(), "User")); + deviceInfo.getDeviceDetailsMap().put("cpuSystem", getProperty(prop.getValue(), "System")); + deviceInfo.getDeviceDetailsMap().put("IOW", getProperty(prop.getValue(), "IOW")); + deviceInfo.getDeviceDetailsMap().put("IRQ", getProperty(prop.getValue(), "IRQ")); + } else if (prop.getName().equalsIgnoreCase("RAM_INFO")) { + deviceInfo.setTotalRAMMemory(Double.parseDouble(getProperty(prop.getValue(), "TOTAL_MEMORY"))); + deviceInfo.setAvailableRAMMemory(Double.parseDouble( + getProperty(prop.getValue(), "AVAILABLE_MEMORY"))); + deviceInfo.getDeviceDetailsMap().put("ramThreshold", getProperty(prop.getValue(), "THRESHOLD")); + deviceInfo.getDeviceDetailsMap().put("ramLowMemory", getProperty(prop.getValue(), "LOW_MEMORY")); + } else if (prop.getName().equalsIgnoreCase("BATTERY_INFO")) { + deviceInfo.setPluggedIn(Boolean.parseBoolean(getProperty(prop.getValue(), "PLUGGED"))); + + deviceInfo.getDeviceDetailsMap().put("batteryLevel", getProperty(prop.getValue(), "BATTERY_LEVEL")); + deviceInfo.getDeviceDetailsMap().put("batteryScale", getProperty(prop.getValue(), "SCALE")); + deviceInfo.getDeviceDetailsMap().put("batteryVoltage", + getProperty(prop.getValue(), "BATTERY_VOLTAGE")); + deviceInfo.getDeviceDetailsMap().put("batteryTemperature", + getProperty(prop.getValue(), "TEMPERATURE")); + deviceInfo.getDeviceDetailsMap().put("batteryCurrentTemperature", + getProperty(prop.getValue(), "CURRENT_AVERAGE")); + deviceInfo.getDeviceDetailsMap().put("batteryTechnology", + getProperty(prop.getValue(), "TECHNOLOGY")); + deviceInfo.getDeviceDetailsMap().put("batteryHealth", getProperty(prop.getValue(), "HEALTH")); + deviceInfo.getDeviceDetailsMap().put("batteryStatus", getProperty(prop.getValue(), "STATUS")); + } else if (prop.getName().equalsIgnoreCase("NETWORK_INFO")) { + deviceInfo.setSsid(getProperty(prop.getValue(), "WIFI_SSID")); + deviceInfo.setConnectionType(getProperty(prop.getValue(), "CONNECTION_TYPE")); + + deviceInfo.getDeviceDetailsMap().put("mobileSignalStrength", + getProperty(prop.getValue(), "MOBILE_SIGNAL_STRENGTH")); + deviceInfo.getDeviceDetailsMap().put("wifiSignalStrength", + getProperty(prop.getValue(), "WIFI_SIGNAL_STRENGTH")); + } else if (prop.getName().equalsIgnoreCase("DEVICE_INFO")) { + deviceInfo.setBatteryLevel(Double.parseDouble( + getProperty(prop.getValue(), "BATTERY_LEVEL"))); + deviceInfo.setInternalTotalMemory(Double.parseDouble( + getProperty(prop.getValue(), "INTERNAL_TOTAL_MEMORY"))); + deviceInfo.setInternalAvailableMemory(Double.parseDouble( + getProperty(prop.getValue(), "INTERNAL_AVAILABLE_MEMORY"))); + deviceInfo.setExternalTotalMemory(Double.parseDouble( + getProperty(prop.getValue(), "EXTERNAL_TOTAL_MEMORY"))); + deviceInfo.setExternalAvailableMemory(Double.parseDouble( + getProperty(prop.getValue(), "EXTERNAL_AVAILABLE_MEMORY"))); + + deviceInfo.getDeviceDetailsMap().put("encryptionEnabled", + getProperty(prop.getValue(), "ENCRYPTION_ENABLED")); + deviceInfo.getDeviceDetailsMap().put("passcodeEnabled", + getProperty(prop.getValue(), "PASSCODE_ENABLED")); + deviceInfo.getDeviceDetailsMap().put("operator", + getProperty(prop.getValue(), "OPERATOR")); + deviceInfo.getDeviceDetailsMap().put("PhoneNumber", + getProperty(prop.getValue(), "PHONE_NUMBER")); + } else if (prop.getName().equalsIgnoreCase("IMEI")) { + deviceInfo.getDeviceDetailsMap().put("IMEI", prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("IMSI")) { + deviceInfo.getDeviceDetailsMap().put("IMSI", prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("MAC")) { + deviceInfo.getDeviceDetailsMap().put("mac", prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("SERIAL")) { + deviceInfo.getDeviceDetailsMap().put("serial", prop.getValue()); + } + } + + private static void extractDefinedProperties(DeviceInfo deviceInfo, Device.Property prop) { + if (prop.getName().equalsIgnoreCase("DEVICE_MODEL")) { + deviceInfo.setDeviceModel(prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("VENDOR")) { + deviceInfo.setVendor(prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("OS_VERSION")) { + deviceInfo.setOsVersion(prop.getValue()); + } else if (prop.getName().equalsIgnoreCase("OS_BUILD_DATE")) { + deviceInfo.setOsBuildDate(prop.getValue()); + } + } + + private static String getProperty(String properties, String needed) { + // This is not a key value pair. value is the immediate element to its filed name. + // Ex: + // [{"name":"ENCRYPTION_ENABLED","value":"false"},{"name":"PASSCODE_ENABLED","value":"true"}, + // {"name":"BATTERY_LEVEL","value":"100"},{"name":"INTERNAL_TOTAL_MEMORY","value":"0.76"}] + JsonElement jsonElement = new JsonParser().parse(properties); + JsonArray jsonArray = jsonElement.getAsJsonArray(); + for (JsonElement element : jsonArray) { + if (element.isJsonObject()) { + JsonObject jsonObject = element.getAsJsonObject(); + if (jsonObject.has("name") + && jsonObject.get("name").getAsString().equalsIgnoreCase(needed)) { + if (jsonObject.has("value") && jsonObject.get("value") != JsonNull.INSTANCE) { + return jsonObject.get("value").getAsString().replace("%", ""); + } else { + return ""; + } + } + } + } + return ""; + } + + private static List getComplianceFeatures(Object compliancePayload) + throws PolicyComplianceException { + String compliancePayloadString = new Gson().toJson(compliancePayload); + if (compliancePayload == null) { + return null; + } + // Parsing json string to get compliance features. + JsonElement jsonElement; + if (compliancePayloadString instanceof String) { + jsonElement = new JsonParser().parse(compliancePayloadString); + } else { + throw new PolicyComplianceException("Invalid policy compliance payload"); + } + + JsonArray jsonArray = jsonElement.getAsJsonArray(); + Gson gson = new Gson(); + ComplianceFeature complianceFeature; + List complianceFeatures = new ArrayList(jsonArray.size()); + + for (JsonElement element : jsonArray) { + complianceFeature = gson.fromJson(element, ComplianceFeature.class); + complianceFeatures.add(complianceFeature); + } + return complianceFeatures; + } + + /** + * Returns a new BadRequestException + * + * @param description description of the exception + * @return a new BadRequestException with the specified details as a response DTO + */ + public static BadRequestException buildBadRequestException(String description) { + ErrorResponse errorResponse = getErrorResponse(AndroidConstants. + ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT, 400l, description); + return new BadRequestException(errorResponse); + } + + /** + * Returns generic ErrorResponse. + * + * @param message specific error message + * @param code error code + * @param description error description + * @return generic Response with error specific details. + */ + public static ErrorResponse getErrorResponse(String message, Long code, String description) { + ErrorResponse errorResponse = new ErrorResponse(); + errorResponse.setCode(code); + errorResponse.setMoreInfo(""); + errorResponse.setMessage(message); + errorResponse.setDescription(description); + return errorResponse; + } + + public static ErrorResponse getConstraintViolationErrorDTO(Set> violations) { + ErrorResponse errorResponse = new ErrorResponse(); + errorResponse.setDescription("Validation Error"); + errorResponse.setMessage("Bad Request"); + errorResponse.setCode(400l); + errorResponse.setMoreInfo(""); + List errorListItems = new ArrayList<>(); + for (ConstraintViolation violation : violations) { + ErrorListItem errorListItemDTO = new ErrorListItem(); + errorListItemDTO.setCode(400 + "_" + violation.getPropertyPath()); + errorListItemDTO.setMessage(violation.getPropertyPath() + ": " + violation.getMessage()); + errorListItems.add(errorListItemDTO); + } + errorResponse.setErrorItems(errorListItems); + return errorResponse; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/ApiOriginFilter.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/ApiOriginFilter.java new file mode 100644 index 000000000..455d582bb --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/ApiOriginFilter.java @@ -0,0 +1,44 @@ +/* + * 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.util; + +import javax.servlet.*; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class ApiOriginFilter implements Filter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + HttpServletResponse res = (HttpServletResponse) response; + res.addHeader("Access-Control-Allow-Origin", "*"); + res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); + res.addHeader("Access-Control-Allow-Headers", "Content-Type"); + chain.doFilter(request, response); + } + + public void destroy() { + //do nothing + } + + public void init(FilterConfig filterConfig) throws ServletException { + //do nothing + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/DeviceIDHolder.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/DeviceIDHolder.java new file mode 100644 index 000000000..7b09fc700 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/DeviceIDHolder.java @@ -0,0 +1,48 @@ +/* + * 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.util; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; + +import java.util.List; + +/** + * Holder class for storing valid & invalid device-ids. + */ +public class DeviceIDHolder { + + private List errorDeviceIdList; + private List validDeviceIDList; + + public List getErrorDeviceIdList() { + return errorDeviceIdList; + } + + public void setErrorDeviceIdList(List errorDeviceIdList) { + this.errorDeviceIdList = errorDeviceIdList; + } + + public List getValidDeviceIDList() { + return validDeviceIDList; + } + + public void setValidDeviceIDList(List validDeviceIDList) { + this.validDeviceIDList = validDeviceIDList; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/Message.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/Message.java new file mode 100644 index 000000000..8cb5f6d14 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/java/org/wso2/carbon/mdm/services/android/util/Message.java @@ -0,0 +1,88 @@ +/* + * 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.util; + +import javax.ws.rs.core.MediaType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * This class contains the information of response message. + */ +@XmlRootElement +public class Message { + + private String responseCode; + private String responseMessage; + + @XmlElement + public String getResponseMessage() { + return responseMessage; + } + + public void setResponseMessage(String responseMessage) { + this.responseMessage = responseMessage; + } + + @XmlElement + public String getResponseCode() { + return responseCode; + } + + public void setResponseCode(String responseCode) { + this.responseCode = responseCode; + } + + private Message.MessageBuilder getBuilder() { + return new Message.MessageBuilder(); + } + + public static Message.MessageBuilder responseCode(String responseCode) { + Message message = new Message(); + return message.getBuilder().responseCode(responseCode); + } + + public static Message.MessageBuilder responseMessage(String responseMessage) { + Message message = new Message(); + return message.getBuilder().responseMessage(responseMessage); + } + + public class MessageBuilder { + + private String responseCode; + private String responseMessage; + + public MessageBuilder responseCode(String responseCode) { + this.responseCode = responseCode; + return this; + } + + public MessageBuilder responseMessage(String responseMessage) { + this.responseMessage = responseMessage; + return this; + } + + public Message build() { + Message message = new Message(); + message.setResponseCode(responseCode); + message.setResponseMessage(responseMessage); + return message; + } + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/META-INF/permissions.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/META-INF/permissions.xml new file mode 100644 index 000000000..1c3c034b8 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/META-INF/permissions.xml @@ -0,0 +1,317 @@ + + + + + + + + + + + View Tenant configuration + /device-mgt/admin/platform-configs/view + /configuration + GET + + + + Modify Tenant configuration + /device-mgt/admin/platform-configs/add + /configuration + PUT + + + + Add Tenant configuration + /device-mgt/admin/platform-configs/add + /configuration + PUT + + + + Enroll + /device-mgt/user/device/enroll/android + /configuration/license + GET + + + + + + + + Enroll + /device-mgt/user/device/enroll/android + /devices + POST + + + + Enroll + /device-mgt/user/device/enroll/android + /devices/* + DELETE + + + + Enroll + /device-mgt/user/device/enroll/android + /devices/* + PUT + + + + Enroll + /device-mgt/user/device/enroll/android + /devices/*/applications + PUT + + + + Enroll + /device-mgt/user/device/enroll/android + /devices/*/pending-operations + PUT + + + + Enroll + /device-mgt/user/device/enroll/android + /devices/*/status + GET + + + + + + + + Enroll + /device-mgt/user/device/enroll/android + /events/publish + POST + + + + View Events + /device-mgt/admin/events/view + /events/publish + POST + + + + GET Events + /device-mgt/admin/events/get + /events + GET + + + + + + + + + + Get installed applications + /device-mgt/admin/device/android/operation/get-installed-applications + /admin/devices/applications + POST + + + + Blacklist applications + /device-mgt/admin/device/android/operation/blacklist-applications + /admin/devices/blacklist-applications + POST + + + + Change lock code + /device-mgt/admin/device/android/operation/change-lock-code + /admin/devices/change-lock-code + POST + + + + Clear password + /device-mgt/admin/device/android/operation/clear-password + /admin/devices/clear-password + POST + + + + Logcat + /device-mgt/admin/device/android/operation/logcat + /admin/devices/logcat + POST + + + + Configure VPN + /device-mgt/admin/device/android/operation/configure-vpn + /admin/devices/configure-vpn + POST + + + + Configure WiFi + /device-mgt/admin/device/android/operation/configure-wifi + /admin/devices/configure-wifi + POST + + + + Control camera + /device-mgt/admin/device/android/operation/control-camera + /admin/devices/control-camera + POST + + + + Encrypt storage + /device-mgt/admin/device/android/operation/encrypt-storage + /admin/devices/encrypt-storage + POST + + + + Enterprise wipe + /device-mgt/admin/device/android/operation/enterprise-wipe + /admin/devices/enterprise-wipe + POST + + + + Get device info + /device-mgt/admin/device/android/operation/get-info + /admin/devices/info + POST + + + + Install application + /device-mgt/admin/device/android/operation/install-application + /admin/devices/install-application + POST + + + + Get location details + /device-mgt/admin/device/android/operation/location + /admin/devices/location + POST + + + + Lock device + /device-mgt/admin/device/android/operation/lock-device + /admin/devices/lock-devices + POST + + + + Mute device + /device-mgt/admin/device/android/operation/mute + /admin/devices/mute + POST + + + + Reboot device + /device-mgt/admin/device/android/operation/reboot + /admin/devices/reboot + POST + + + + Ring device + /device-mgt/admin/device/android/operation/ring + /admin/devices/ring + POST + + + + Send notification + /device-mgt/admin/device/android/operation/send-notification + /admin/devices/send-notification + POST + + + + Set password policy + /device-mgt/admin/device/android/operation/set-password-policy + /admin/devices/set-password-policy + POST + + + + Set web clip + /device-mgt/admin/device/android/operation/set-webclip + /admin/devices/set-webclip + POST + + + + Uninstall application + /device-mgt/admin/device/android/operation/uninstall-application + /admin/devices/uninstall-application + POST + + + + Unlock device + /device-mgt/admin/device/android/operation/unlock-device + /admin/devices/unlock-devices + POST + + + + Update applications + /device-mgt/admin/device/android/operation/update-application + /admin/devices/update-application + POST + + + + Upgrade firmware + /device-mgt/admin/device/android/operation/upgrade-firmware + /admin/devices/upgrade-firmware + POST + + + + Wipe device + /device-mgt/admin/device/android/operation/wipe + /admin/devices/wipe + POST + + + + + \ No newline at end of file diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/META-INF/webapp-classloading.xml new file mode 100644 index 000000000..185de22d4 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/META-INF/webapp-classloading.xml @@ -0,0 +1,35 @@ + + + + + + + + + false + + + CXF,Carbon + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/WEB-INF/cxf-servlet.xml new file mode 100644 index 000000000..0f47d488f --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/WEB-INF/web.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..8cedb6a41 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,90 @@ + + + + Android-Agent-Webapp + + JAX-WS/JAX-RS MDM Android Endpoint + JAX-WS/JAX-RS Servlet + CXFServlet + + org.apache.cxf.transport.servlet.CXFServlet + + + + swagger.security.filter + ApiAuthorizationFilterImpl + + 1 + + + CXFServlet + /* + + + 60 + + + managed-api-enabled + true + + + doAuthentication + true + + + isSharedWithAllTenants + true + + + isDefault + false + + + + + + + + + + + + + + + ApiOriginFilter + org.wso2.carbon.mdm.services.android.util.ApiOriginFilter + + + ApiOriginFilter + /* + + + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/servicelist.css b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/servicelist.css new file mode 100644 index 000000000..0b3081c44 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/main/webapp/servicelist.css @@ -0,0 +1,135 @@ +/* + * 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. + */ + +@CHARSET "ISO-8859-1"; + +/* http://meyerweb.com/eric/tools/css/reset/ + v2.0 | 20110126 + License: none (public domain) +*/ + +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, +menu, nav, output, ruby, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} +/* HTML5 display-role reset for older browsers */ +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} + +html { + background: #efefef; +} + +body { + line-height: 1; + width:960px; + margin:auto; + background:white; + padding:10px; + box-shadow:0px 0px 5px #CCC; + font-family:"Lucida Grande","Lucida Sans","Microsoft Sans Serif", "Lucida Sans Unicode","Verdana","Sans-serif","trebuchet ms" !important; + +} +ol, ul { + list-style: none; +} +blockquote, q { + quotes: none; +} +blockquote:before, blockquote:after, +q:before, q:after { + content: ''; + content: none; +} +table { + border-collapse: collapse; + border-spacing: 0; + width:960px; + border:solid 1px #ccc; +} + +table a { + font-size:12px; + color:#1e90ff; + padding:7px; +float:left; +; +} + +.heading { + font-size: 18px; + margin-top: 20px; + float:left; + color:#0067B1; + margin-bottom:20px; + padding-top:20px; +} + +.field { + font-weight: normal; + width:120px; + font-size:12px; + float:left; + padding:7px; + clear:left; +} +.value { + font-weight: bold; + font-size:12px; + float:left; + padding:7px; + clear:right; +} +.porttypename { + font-weight: bold; + font-size:14px; +} +UL { + margin-top: 0; +} +LI { + font-weight: normal; + font-size:12px; + margin-top:10px; +} + +TD { + border:1px solid #ccc; + vertical-align: text-top; + padding: 5px; +} + + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementAdminServiceTests.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementAdminServiceTests.java new file mode 100644 index 000000000..c60de18bc --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementAdminServiceTests.java @@ -0,0 +1,303 @@ +/* + * Copyright (c) 2017, 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; + +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.testng.PowerMockObjectFactory; +import org.testng.Assert; +import org.testng.IObjectFactory; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.ObjectFactory; +import org.testng.annotations.Test; +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.OperationManagementException; +import org.wso2.carbon.mdm.services.android.mocks.DeviceManagementProviderServiceMock; +import org.wso2.carbon.mdm.services.android.services.impl.DeviceManagementAdminServiceImpl; +import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; +import org.wso2.carbon.mdm.services.android.utils.TestUtils; + +import javax.ws.rs.core.Response; + +@PowerMockIgnore({"javax.ws.rs.*", "org.apache.log4j.*"}) +@PrepareForTest(AndroidAPIUtils.class) +public class DeviceManagementAdminServiceTests { + + private DeviceManagementAdminServiceImpl deviceManagementAdminService; + + @ObjectFactory + public IObjectFactory getObjectFactory() { + return new PowerMockObjectFactory(); + } + + @BeforeClass + public void init() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + MockitoAnnotations.initMocks(this); + deviceManagementAdminService = new DeviceManagementAdminServiceImpl(); + } + + private void mockDeviceManagementService() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceManagementService")) + .toReturn(new DeviceManagementProviderServiceMock()); + } + + @Test + public void testConfigureDeviceLock() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.configureDeviceLock(TestUtils.getDeviceLockBeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testConfigureDeviceUnlock() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.configureDeviceUnlock(TestUtils.getDeviceIds()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testGetDeviceLocation() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.getDeviceLocation(TestUtils.getDeviceIds()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testRemovePassword() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.removePassword(TestUtils.getDeviceIds()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testConfigureCamera() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.configureCamera(TestUtils.getCamerabeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testGetDeviceInformation() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.getDeviceInformation(TestUtils.getDeviceIds()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testGetDeviceLogcat() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.getDeviceLogcat(TestUtils.getDeviceIds()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testWipeDevice() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.wipeDevice(TestUtils.getDeviceIds()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testWipeData() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.wipeData(TestUtils.getWipeDataBeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testGetApplications() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.getApplications(TestUtils.getDeviceIds()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testRingDevice() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.ringDevice(TestUtils.getDeviceIds()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testRebootDevice() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.rebootDevice(TestUtils.getDeviceIds()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testMuteDevice() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.muteDevice(TestUtils.getDeviceIds()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testInstallApplication() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService + .installApplication(TestUtils.getApplicationInstallationBeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testUpdateApplication() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.updateApplication(TestUtils.getApplicationUpdateBeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testUninstallApplicationPublic() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService + .uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperPublic()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testUninstallApplicationWebApp() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService + .uninstallApplication(TestUtils.getApplicationUninstallationBeanWrapperWebApp()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testBlacklistApplications() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService + .blacklistApplications(TestUtils.getBlacklistApplicationsBeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testUpgradeFirmware() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.upgradeFirmware(TestUtils.getUpgradeFirmwareBeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testConfigureVPN() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.configureVPN(TestUtils.getVpnBeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testSendNotification() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.sendNotification(TestUtils.getNotificationBeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testConfigureWifi() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.configureWifi(TestUtils.getWifiBeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testEncryptStorage() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.encryptStorage(TestUtils.getEncryptionBeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testChangeLockCode() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.changeLockCode(TestUtils.getLockCodeBeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testSetPasswordPolicy() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.setPasswordPolicy(TestUtils.getPasswordPolicyBeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testSetWebClip() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementAdminService.setWebClip(TestUtils.getWebClipBeanWrapper()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + +} + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementServiceTests.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementServiceTests.java new file mode 100644 index 000000000..dc16b5d43 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/DeviceManagementServiceTests.java @@ -0,0 +1,318 @@ +/* + * Copyright (c) 2017, 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; + +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.testng.PowerMockObjectFactory; +import org.testng.Assert; +import org.testng.IObjectFactory; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.ObjectFactory; +import org.testng.annotations.Test; +import org.wso2.carbon.device.mgt.common.Device; +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.OperationManagementException; +import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidDevice; +import org.wso2.carbon.mdm.services.android.mocks.ApplicationManagementProviderServiceMock; +import org.wso2.carbon.mdm.services.android.mocks.DeviceInformationManagerServiceMock; +import org.wso2.carbon.mdm.services.android.mocks.DeviceManagementProviderServiceMock; +import org.wso2.carbon.mdm.services.android.mocks.NotificationManagementServiceMock; +import org.wso2.carbon.mdm.services.android.mocks.PolicyManagerServiceMock; +import org.wso2.carbon.mdm.services.android.services.impl.DeviceManagementServiceImpl; +import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; +import org.wso2.carbon.mdm.services.android.utils.TestUtils; + +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +@PowerMockIgnore({"javax.ws.rs.*", "org.apache.log4j.*"}) +@PrepareForTest(AndroidAPIUtils.class) +public class DeviceManagementServiceTests { + + private DeviceManagementServiceImpl deviceManagementService; + + @ObjectFactory + public IObjectFactory getObjectFactory() { + return new PowerMockObjectFactory(); + } + + @BeforeClass + public void init() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + MockitoAnnotations.initMocks(this); + deviceManagementService = new DeviceManagementServiceImpl(); + } + + private void mockDeviceManagementService() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceManagementService")) + .toReturn(new DeviceManagementProviderServiceMock()); + } + + private void mockApplicationManagerService() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getApplicationManagerService")) + .toReturn(new ApplicationManagementProviderServiceMock()); + } + + private void mockPolicyManagerService() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getPolicyManagerService")) + .toReturn(new PolicyManagerServiceMock()); + } + + private void mockDeviceInformationManagerService() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getDeviceInformationManagerService")) + .toReturn(new DeviceInformationManagerServiceMock()); + } + + private void mockNotificationManagementService() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getNotificationManagementService")) + .toReturn(new NotificationManagementServiceMock()); + } + + private void mockUser() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + PowerMockito.stub(PowerMockito.method(AndroidAPIUtils.class, "getAuthenticatedUser")) + .toReturn("admin"); + } + + @Test + public void testUpdateApplicationList() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockApplicationManagerService(); + Response response = deviceManagementService + .updateApplicationList(TestUtils.getDeviceId(), TestUtils.getAndroidApplications()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode()); + } + + @Test + public void testGetPendingOperationsForNullDevice() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + Response response = deviceManagementService + .getPendingOperations(null, null, null); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode()); + } + + @Test + public void testGetPendingOperationsInvalidDevice() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementService + .getPendingOperations("1234", null, null); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); + } + + @Test + public void testGetPendingOperationsNullResponse() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementService + .getPendingOperations(TestUtils.getDeviceId(), null, null); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testGetPendingOperationsWithMonitorResponse() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + mockPolicyManagerService(); + Response response = deviceManagementService + .getPendingOperations(TestUtils.getDeviceId(), null, + TestUtils.getSuccessMonitorOperationResponse()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testGetPendingOperationsWithApplicationResponse() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + mockApplicationManagerService(); + Response response = deviceManagementService + .getPendingOperations(TestUtils.getDeviceId(), null, + TestUtils.getSuccessApplicationOperationResponse()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testGetPendingOperationsWithDeviceInfoResponse() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + mockDeviceInformationManagerService(); + Response response = deviceManagementService + .getPendingOperations(TestUtils.getDeviceId(), null, + TestUtils.getSuccessInfoOperationResponse()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testGetPendingOperationsWithInProgressResponse() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementService + .getPendingOperations(TestUtils.getDeviceId(), null, + TestUtils.getInProgressOperationResponse()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testGetPendingOperationsWithErrorResponse() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + mockNotificationManagementService(); + Response response = deviceManagementService + .getPendingOperations(TestUtils.getDeviceId(), null, + TestUtils.getErrorOperationResponse()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + } + + @Test + public void testEnrollDeviceWithoutLocationSuccess() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + mockPolicyManagerService(); + mockUser(); + Response response = deviceManagementService.enrollDevice(TestUtils.getBasicAndroidDevice()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); + } + + @Test + public void testEnrollDeviceWithLocationSuccess() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + mockDeviceInformationManagerService(); + mockPolicyManagerService(); + mockUser(); + AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice(); + + List properties = new ArrayList<>(); + Device.Property property = new Device.Property(); + property.setName("LATITUDE"); + property.setValue("79.5"); + properties.add(property); + property = new Device.Property(); + property.setName("LONGITUDE"); + property.setValue("6.9"); + properties.add(property); + androidDevice.setProperties(properties); + + Response response = deviceManagementService.enrollDevice(androidDevice); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); + } + + @Test + public void testEnrollDeviceUnSuccess() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + mockUser(); + AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice(); + androidDevice.setDeviceIdentifier("1234"); + Response response = deviceManagementService.enrollDevice(androidDevice); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + @Test + public void testIsEnrolledExists() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementService.isEnrolled(TestUtils.getDeviceId(), null); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); + } + + @Test + public void testIsEnrolledNonExist() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementService.isEnrolled("1234", null); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); + } + + @Test + public void testIsEnrolledNull() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementService.isEnrolled(null, null); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); + } + + @Test + public void testModifyEnrollmentSuccess() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + mockUser(); + Response response = deviceManagementService + .modifyEnrollment(TestUtils.getDeviceId(), TestUtils.getBasicAndroidDevice()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode()); + } + + @Test + public void testModifyEnrollmentUnSuccess() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + mockUser(); + AndroidDevice androidDevice = TestUtils.getBasicAndroidDevice(); + androidDevice.setDeviceIdentifier("1234"); + Response response = deviceManagementService + .modifyEnrollment(TestUtils.getDeviceId(), androidDevice); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.NOT_MODIFIED.getStatusCode()); + } + + @Test + public void testDisEnrollDeviceSuccess() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementService.disEnrollDevice(TestUtils.getDeviceId()); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); + } + + @Test + public void testDisenrollUnSuccess() + throws DeviceManagementException, OperationManagementException, InvalidDeviceException { + mockDeviceManagementService(); + Response response = deviceManagementService.disEnrollDevice("1234"); + Assert.assertNotNull(response); + Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); + } + +} + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/ApplicationManagementProviderServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/ApplicationManagementProviderServiceMock.java new file mode 100644 index 000000000..563258b3c --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/ApplicationManagementProviderServiceMock.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2017, 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.mocks; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; + +import java.util.List; + +public class ApplicationManagementProviderServiceMock implements ApplicationManagementProviderService { + @Override + public void updateApplicationListInstalledInDevice(DeviceIdentifier deviceIdentifier, List list) + throws ApplicationManagementException { + + } + + @Override + public List getApplicationListForDevice(DeviceIdentifier deviceIdentifier) + throws ApplicationManagementException { + return null; + } + + @Override + public Application[] getApplications(String s, int i, int i1) throws ApplicationManagementException { + return new Application[0]; + } + + @Override + public void updateApplicationStatus(DeviceIdentifier deviceIdentifier, Application application, String s) + throws ApplicationManagementException { + + } + + @Override + public String getApplicationStatus(DeviceIdentifier deviceIdentifier, Application application) + throws ApplicationManagementException { + return null; + } + + @Override + public Activity installApplicationForDevices(Operation operation, List list) + throws ApplicationManagementException { + return null; + } + + @Override + public Activity installApplicationForUsers(Operation operation, List list) + throws ApplicationManagementException { + return null; + } + + @Override + public Activity installApplicationForUserRoles(Operation operation, List list) + throws ApplicationManagementException { + return null; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceInformationManagerServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceInformationManagerServiceMock.java new file mode 100644 index 000000000..368c78a86 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceInformationManagerServiceMock.java @@ -0,0 +1,42 @@ +package org.wso2.carbon.mdm.services.android.mocks; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; +import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; + +import java.util.List; + +public class DeviceInformationManagerServiceMock implements DeviceInformationManager { + @Override + public void addDeviceInfo(DeviceIdentifier deviceIdentifier, DeviceInfo deviceInfo) + throws DeviceDetailsMgtException { + + } + + @Override + public DeviceInfo getDeviceInfo(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException { + return null; + } + + @Override + public List getDevicesInfo(List list) throws DeviceDetailsMgtException { + return null; + } + + @Override + public void addDeviceLocation(DeviceLocation deviceLocation) throws DeviceDetailsMgtException { + + } + + @Override + public DeviceLocation getDeviceLocation(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException { + return null; + } + + @Override + public List getDeviceLocations(List list) throws DeviceDetailsMgtException { + return null; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java new file mode 100644 index 000000000..bf1240169 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java @@ -0,0 +1,516 @@ +/* + * Copyright (c) 2017, 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.mocks; + +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.common.FeatureManager; +import org.wso2.carbon.device.mgt.common.InvalidDeviceException; +import org.wso2.carbon.device.mgt.common.MonitoringOperation; +import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; +import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; +import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; +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.common.policy.mgt.PolicyMonitoringManager; +import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException; +import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; +import org.wso2.carbon.device.mgt.core.geo.GeoCluster; +import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo; +import org.wso2.carbon.mdm.services.android.utils.TestUtils; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; + +public class DeviceManagementProviderServiceMock implements DeviceManagementProviderService { + @Override + public List getAllDevices(String s) throws DeviceManagementException { + return null; + } + + @Override + public List getAllDevices(String s, boolean b) throws DeviceManagementException { + return null; + } + + @Override + public List getAllDevices() throws DeviceManagementException { + return null; + } + + @Override + public List getAllDevices(boolean b) throws DeviceManagementException { + return null; + } + + @Override + public List getDevices(Date date) throws DeviceManagementException { + return null; + } + + @Override + public List getDevices(Date date, boolean b) throws DeviceManagementException { + return null; + } + + @Override + public PaginationResult getDevicesByType(PaginationRequest paginationRequest) throws DeviceManagementException { + return null; + } + + @Override + public PaginationResult getDevicesByType(PaginationRequest paginationRequest, boolean b) + throws DeviceManagementException { + return null; + } + + @Override + public PaginationResult getAllDevices(PaginationRequest paginationRequest) throws DeviceManagementException { + return null; + } + + @Override + public PaginationResult getAllDevices(PaginationRequest paginationRequest, boolean b) + throws DeviceManagementException { + return null; + } + + @Override + public Device getDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + if (TestUtils.getDeviceId().equals(deviceIdentifier.getId())) { + return TestUtils.getDevice(); + } else { + return null; + } + } + + @Override + public Device getDeviceWithTypeProperties(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + return null; + } + + @Override + public Device getDevice(DeviceIdentifier deviceIdentifier, boolean b) throws DeviceManagementException { + if (TestUtils.getDeviceId().equals(deviceIdentifier.getId())) { + return TestUtils.getDevice(); + } else { + return null; + } + } + + @Override + public Device getDevice(DeviceIdentifier deviceIdentifier, String s, boolean b) throws DeviceManagementException { + return null; + } + + @Override + public Device getDevice(DeviceIdentifier deviceIdentifier, Date date) throws DeviceManagementException { + return null; + } + + @Override + public Device getDevice(DeviceIdentifier deviceIdentifier, Date date, boolean b) throws DeviceManagementException { + return null; + } + + @Override + public Device getDevice(DeviceIdentifier deviceIdentifier, String s, Date date, boolean b) + throws DeviceManagementException { + return null; + } + + @Override + public Device getDevice(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status status) + throws DeviceManagementException { + return null; + } + + @Override + public Device getDevice(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status status, boolean b) + throws DeviceManagementException { + return null; + } + + @Override + public PaginationResult getDevicesOfUser(PaginationRequest paginationRequest) throws DeviceManagementException { + return null; + } + + @Override + public PaginationResult getDevicesOfUser(PaginationRequest paginationRequest, boolean b) + throws DeviceManagementException { + return null; + } + + @Override + public PaginationResult getDevicesByOwnership(PaginationRequest paginationRequest) + throws DeviceManagementException { + return null; + } + + @Override + public PaginationResult getDevicesByOwnership(PaginationRequest paginationRequest, boolean b) + throws DeviceManagementException { + return null; + } + + @Override + public List getDevicesOfUser(String s) throws DeviceManagementException { + return null; + } + + @Override + public List getDevicesOfUser(String s, boolean b) throws DeviceManagementException { + return null; + } + + @Override + public List getDevicesOfUser(String s, String s1) throws DeviceManagementException { + return null; + } + + @Override + public List getDevicesOfUser(String s, String s1, boolean b) throws DeviceManagementException { + return null; + } + + @Override + public List getAllDevicesOfRole(String s) throws DeviceManagementException { + return null; + } + + @Override + public List getAllDevicesOfRole(String s, boolean b) throws DeviceManagementException { + return null; + } + + @Override + public PaginationResult getDevicesByStatus(PaginationRequest paginationRequest) throws DeviceManagementException { + return null; + } + + @Override + public PaginationResult getDevicesByStatus(PaginationRequest paginationRequest, boolean b) + throws DeviceManagementException { + return null; + } + + @Override + public List getDevicesByNameAndType(PaginationRequest paginationRequest, boolean b) + throws DeviceManagementException { + return null; + } + + @Override + public PaginationResult getDevicesByName(PaginationRequest paginationRequest) throws DeviceManagementException { + return null; + } + + @Override + public PaginationResult getDevicesByName(PaginationRequest paginationRequest, boolean b) + throws DeviceManagementException { + return null; + } + + @Override + public List getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException { + return null; + } + + @Override + public List getDevicesByStatus(EnrolmentInfo.Status status, boolean b) throws DeviceManagementException { + return null; + } + + @Override + public int getDeviceCount(String s) throws DeviceManagementException { + return 0; + } + + @Override + public int getDeviceCount() throws DeviceManagementException { + return 0; + } + + @Override + public HashMap getTenantedDevice(DeviceIdentifier deviceIdentifier) + throws DeviceManagementException { + return null; + } + + @Override + public void sendEnrolmentInvitation(String s, EmailMetaInfo emailMetaInfo) + throws DeviceManagementException, ConfigurationManagementException { + + } + + @Override + public void sendRegistrationEmail(EmailMetaInfo emailMetaInfo) + throws DeviceManagementException, ConfigurationManagementException { + + } + + @Override + public FeatureManager getFeatureManager(String s) throws DeviceManagementException { + return null; + } + + @Override + public PlatformConfiguration getConfiguration(String s) throws DeviceManagementException { + return null; + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceIdentifier, String s) throws DeviceManagementException { + return false; + } + + @Override + public NotificationStrategy getNotificationStrategyByDeviceType(String s) throws DeviceManagementException { + return null; + } + + @Override + public License getLicense(String s, String s1) throws DeviceManagementException { + return null; + } + + @Override + public void addLicense(String s, License license) throws DeviceManagementException { + + } + + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + return TestUtils.getDeviceId().equals(device.getDeviceIdentifier()); + } + + @Override + public boolean enrollDevice(Device device) throws DeviceManagementException { + return TestUtils.getDeviceId().equals(device.getDeviceIdentifier()); + } + + @Override + public boolean saveConfiguration(PlatformConfiguration platformConfiguration) throws DeviceManagementException { + return false; + } + + @Override + public boolean disenrollDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + return TestUtils.getDeviceId().equals(deviceIdentifier.getId()); + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + return false; + } + + @Override + public boolean isActive(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + return false; + } + + @Override + public boolean setActive(DeviceIdentifier deviceIdentifier, boolean b) throws DeviceManagementException { + return false; + } + + @Override + public List getAvailableDeviceTypes() throws DeviceManagementException { + return null; + } + + @Override + public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { + return false; + } + + @Override + public boolean setOwnership(DeviceIdentifier deviceIdentifier, String s) throws DeviceManagementException { + return false; + } + + @Override + public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + return false; + } + + @Override + public boolean setStatus(DeviceIdentifier deviceIdentifier, String s, EnrolmentInfo.Status status) + throws DeviceManagementException { + return false; + } + + @Override + public boolean setStatus(String s, EnrolmentInfo.Status status) throws DeviceManagementException { + return false; + } + + @Override + public void notifyOperationToDevices(Operation operation, List list) + throws DeviceManagementException { + + } + + @Override + public Activity addOperation(String s, Operation operation, List list) + throws OperationManagementException, InvalidDeviceException { + return TestUtils.getActivity(); + } + + @Override + public List getOperations(DeviceIdentifier deviceIdentifier) + throws OperationManagementException { + return null; + } + + @Override + public PaginationResult getOperations(DeviceIdentifier deviceIdentifier, PaginationRequest paginationRequest) + throws OperationManagementException { + return null; + } + + @Override + public List getPendingOperations(DeviceIdentifier deviceIdentifier) + throws OperationManagementException { + return null; + } + + @Override + public Operation getNextPendingOperation(DeviceIdentifier deviceIdentifier) throws OperationManagementException { + return null; + } + + @Override + public void updateOperation(DeviceIdentifier deviceIdentifier, Operation operation) + throws OperationManagementException { + + } + + @Override + public boolean updateProperties(DeviceIdentifier deviceIdentifier, List list) throws DeviceManagementException { + return false; + } + + @Override + public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceIdentifier, int i) + throws OperationManagementException { + return null; + } + + @Override + public List getOperationsByDeviceAndStatus(DeviceIdentifier deviceIdentifier, + Operation.Status status) + throws OperationManagementException, DeviceManagementException { + return null; + } + + @Override + public Operation getOperation(String s, int i) throws OperationManagementException { + return null; + } + + @Override + public Activity getOperationByActivityId(String s) throws OperationManagementException { + return null; + } + + @Override + public Activity getOperationByActivityIdAndDevice(String s, DeviceIdentifier deviceIdentifier) + throws OperationManagementException { + return null; + } + + @Override + public List getActivitiesUpdatedAfter(long l, int i, int i1) throws OperationManagementException { + return null; + } + + @Override + public int getActivityCountUpdatedAfter(long l) throws OperationManagementException { + return 0; + } + + @Override + public List getMonitoringOperationList(String s) { + return null; + } + + @Override + public int getDeviceMonitoringFrequency(String s) { + return 0; + } + + @Override + public boolean isDeviceMonitoringEnabled(String s) { + return false; + } + + @Override + public PolicyMonitoringManager getPolicyMonitoringManager(String s) { + return null; + } + + @Override + public boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status status) + throws DeviceManagementException { + return false; + } + + @Override + public void registerDeviceType(DeviceManagementService deviceManagementService) throws DeviceManagementException { + + } + + @Override + public DeviceType getDeviceType(String s) throws DeviceManagementException { + return null; + } + + @Override + public List getDeviceTypes() throws DeviceManagementException { + return null; + } + + @Override + public void notifyPullNotificationSubscriber(DeviceIdentifier deviceIdentifier, Operation operation) + throws PullNotificationExecutionFailedException { + + } + + @Override + public List getDeviceEnrolledTenants() throws DeviceManagementException { + return null; + } + + @Override + public List findGeoClusters(GeoCoordinate geoCoordinate, GeoCoordinate geoCoordinate1, int i) throws DeviceManagementException { + return null; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/NotificationManagementServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/NotificationManagementServiceMock.java new file mode 100644 index 000000000..53b210668 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/NotificationManagementServiceMock.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017, 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.mocks; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.notification.mgt.Notification; +import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; +import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; + +import java.util.List; + +public class NotificationManagementServiceMock implements NotificationManagementService { + @Override + public boolean addNotification(DeviceIdentifier deviceIdentifier, Notification notification) + throws NotificationManagementException { + return false; + } + + @Override + public boolean updateNotification(Notification notification) throws NotificationManagementException { + return false; + } + + @Override + public boolean updateNotificationStatus(int i, Notification.Status status) throws NotificationManagementException { + return false; + } + + @Override + public List getAllNotifications() throws NotificationManagementException { + return null; + } + + @Override + public Notification getNotification(int i) throws NotificationManagementException { + return null; + } + + @Override + public PaginationResult getAllNotifications(PaginationRequest paginationRequest) + throws NotificationManagementException { + return null; + } + + @Override + public List getNotificationsByStatus(Notification.Status status) + throws NotificationManagementException { + return null; + } + + @Override + public PaginationResult getNotificationsByStatus(Notification.Status status, PaginationRequest paginationRequest) + throws NotificationManagementException { + return null; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/PolicyManagerServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/PolicyManagerServiceMock.java new file mode 100644 index 000000000..a71dafebf --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/PolicyManagerServiceMock.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2017, 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.mocks; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.Feature; +import org.wso2.carbon.device.mgt.common.policy.mgt.Policy; +import org.wso2.carbon.device.mgt.common.policy.mgt.Profile; +import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature; +import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.ComplianceFeature; +import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData; +import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; +import org.wso2.carbon.policy.mgt.common.FeatureManagementException; +import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; +import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException; +import org.wso2.carbon.policy.mgt.core.PolicyManagerService; +import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService; + +import java.util.List; + +public class PolicyManagerServiceMock implements PolicyManagerService { + + @Override + public Profile addProfile(Profile profile) throws PolicyManagementException { + return null; + } + + @Override + public Profile updateProfile(Profile profile) throws PolicyManagementException { + return null; + } + + @Override + public Policy addPolicy(Policy policy) throws PolicyManagementException { + return null; + } + + @Override + public Policy updatePolicy(Policy policy) throws PolicyManagementException { + return null; + } + + @Override + public boolean deletePolicy(Policy policy) throws PolicyManagementException { + return false; + } + + @Override + public boolean deletePolicy(int i) throws PolicyManagementException { + return false; + } + + @Override + public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { + return null; + } + + @Override + public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) + throws FeatureManagementException { + return null; + } + + @Override + public List getPolicies(String s) throws PolicyManagementException { + return null; + } + + @Override + public List getFeatures() throws FeatureManagementException { + return null; + } + + @Override + public PolicyAdministratorPoint getPAP() throws PolicyManagementException { + return null; + } + + @Override + public PolicyInformationPoint getPIP() throws PolicyManagementException { + return null; + } + + @Override + public PolicyEvaluationPoint getPEP() throws PolicyManagementException { + return null; + } + + @Override + public TaskScheduleService getTaskScheduleService() throws PolicyMonitoringTaskException { + return null; + } + + @Override + public int getPolicyCount() throws PolicyManagementException { + return 0; + } + + @Override + public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { + return null; + } + + @Override + public List checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Object o) + throws PolicyComplianceException { + return null; + } + + @Override + public boolean checkCompliance(DeviceIdentifier deviceIdentifier, Object o) throws PolicyComplianceException { + return false; + } + + @Override + public NonComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { + return null; + } + + @Override + public boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { + return false; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/utils/TestUtils.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/utils/TestUtils.java new file mode 100644 index 000000000..cff3d8ca2 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/utils/TestUtils.java @@ -0,0 +1,425 @@ +/* + * Copyright (c) 2017, 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.utils; + +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; +import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; +import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; +import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.mdm.services.android.bean.ApplicationInstallation; +import org.wso2.carbon.mdm.services.android.bean.ApplicationUninstallation; +import org.wso2.carbon.mdm.services.android.bean.ApplicationUpdate; +import org.wso2.carbon.mdm.services.android.bean.BlacklistApplications; +import org.wso2.carbon.mdm.services.android.bean.Camera; +import org.wso2.carbon.mdm.services.android.bean.DeviceEncryption; +import org.wso2.carbon.mdm.services.android.bean.DeviceLock; +import org.wso2.carbon.mdm.services.android.bean.LockCode; +import org.wso2.carbon.mdm.services.android.bean.Notification; +import org.wso2.carbon.mdm.services.android.bean.PasscodePolicy; +import org.wso2.carbon.mdm.services.android.bean.UpgradeFirmware; +import org.wso2.carbon.mdm.services.android.bean.Vpn; +import org.wso2.carbon.mdm.services.android.bean.WebClip; +import org.wso2.carbon.mdm.services.android.bean.Wifi; +import org.wso2.carbon.mdm.services.android.bean.WipeData; +import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidApplication; +import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidDevice; +import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationInstallationBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUninstallationBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUpdateBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.BlacklistApplicationsBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.CameraBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.DeviceLockBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.EncryptionBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.LockCodeBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.NotificationBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.PasswordPolicyBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.UpgradeFirmwareBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.VpnBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.WebClipBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.WifiBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.WipeDataBeanWrapper; +import org.wso2.carbon.mdm.services.android.util.AndroidConstants; +import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils; + +import java.util.ArrayList; +import java.util.List; + +public class TestUtils { + + public static Activity getActivity() { + Activity activity = new Activity(); + activity.setActivityId("ACTIVITY_1"); + activity.setCode("CODE"); + return activity; + } + + public static String getDeviceId() { + return "1a2b3c4d5e"; + } + + public static List getDeviceIds() { + List deviceIds = new ArrayList<>(); + deviceIds.add(getDeviceId()); + return deviceIds; + } + + public static Device getDevice() { + Device device = new Device(); + device.setId(1); + device.setName("Test"); + device.setDeviceIdentifier(getDeviceId()); + device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); + enrolmentInfo.setId(1); + enrolmentInfo.setOwner("admin"); + enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); + enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); + device.setEnrolmentInfo(enrolmentInfo); + return device; + } + + public static DeviceLockBeanWrapper getDeviceLockBeanWrapper() { + DeviceLockBeanWrapper deviceLockBeanWrapper = new DeviceLockBeanWrapper(); + deviceLockBeanWrapper.setDeviceIDs(getDeviceIds()); + DeviceLock deviceLockOperation = new DeviceLock(); + deviceLockOperation.setHardLockEnabled(true); + deviceLockOperation.setMessage("Test Operation"); + deviceLockBeanWrapper.setOperation(deviceLockOperation); + return deviceLockBeanWrapper; + } + + public static CameraBeanWrapper getCamerabeanWrapper() { + CameraBeanWrapper cameraBeanWrapper = new CameraBeanWrapper(); + cameraBeanWrapper.setDeviceIDs(getDeviceIds()); + Camera camera = new Camera(); + camera.setEnabled(false); + cameraBeanWrapper.setOperation(camera); + return cameraBeanWrapper; + } + + public static WipeDataBeanWrapper getWipeDataBeanWrapper() { + WipeDataBeanWrapper wipeDataBeanWrapper = new WipeDataBeanWrapper(); + wipeDataBeanWrapper.setDeviceIDs(getDeviceIds()); + WipeData wipeData = new WipeData(); + wipeData.setPin("1234"); + wipeDataBeanWrapper.setOperation(wipeData); + return wipeDataBeanWrapper; + } + + public static ApplicationInstallationBeanWrapper getApplicationInstallationBeanWrapper() { + ApplicationInstallationBeanWrapper applicationInstallationBeanWrapper = new ApplicationInstallationBeanWrapper(); + applicationInstallationBeanWrapper.setDeviceIDs(getDeviceIds()); + ApplicationInstallation applicationInstallation = new ApplicationInstallation(); + applicationInstallation.setAppIdentifier("org.wso2.iot.agent"); + applicationInstallation.setUrl("https://github.com/wso2/cdmf-agent-android/releases/download/v3.1.21/client-standalone.apk"); + applicationInstallation.setType("enterprise"); + applicationInstallation.setSchedule("2017-10-11T18:46:19-0530"); + applicationInstallationBeanWrapper.setOperation(applicationInstallation); + return applicationInstallationBeanWrapper; + } + + public static ApplicationUpdateBeanWrapper getApplicationUpdateBeanWrapper() { + ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper = new ApplicationUpdateBeanWrapper(); + applicationUpdateBeanWrapper.setDeviceIDs(getDeviceIds()); + ApplicationUpdate applicationUpdate = new ApplicationUpdate(); + applicationUpdate.setAppIdentifier("org.wso2.iot.agent"); + applicationUpdate.setUrl("https://github.com/wso2/cdmf-agent-android/releases/download/v3.1.21/client-standalone.apk"); + applicationUpdate.setType("enterprise"); + applicationUpdate.setSchedule("2017-10-11T18:46:19-0530"); + applicationUpdateBeanWrapper.setOperation(applicationUpdate); + return applicationUpdateBeanWrapper; + } + + public static ApplicationUninstallationBeanWrapper getApplicationUninstallationBeanWrapperPublic() { + ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper = new ApplicationUninstallationBeanWrapper(); + applicationUninstallationBeanWrapper.setDeviceIDs(getDeviceIds()); + ApplicationUninstallation applicationUninstallation = new ApplicationUninstallation(); + applicationUninstallation.setAppIdentifier("org.wso2.iot.agent"); + applicationUninstallation.setType("public"); + applicationUninstallationBeanWrapper.setOperation(applicationUninstallation); + return applicationUninstallationBeanWrapper; + } + + public static ApplicationUninstallationBeanWrapper getApplicationUninstallationBeanWrapperWebApp() { + ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper = new ApplicationUninstallationBeanWrapper(); + applicationUninstallationBeanWrapper.setDeviceIDs(getDeviceIds()); + ApplicationUninstallation applicationUninstallation = new ApplicationUninstallation(); + applicationUninstallation.setAppIdentifier("org.wso2.iot.agent"); + applicationUninstallation.setType("webapp"); + applicationUninstallationBeanWrapper.setOperation(applicationUninstallation); + return applicationUninstallationBeanWrapper; + } + + public static BlacklistApplicationsBeanWrapper getBlacklistApplicationsBeanWrapper() { + BlacklistApplicationsBeanWrapper blacklistApplicationsBeanWrapper = new BlacklistApplicationsBeanWrapper(); + blacklistApplicationsBeanWrapper.setDeviceIDs(getDeviceIds()); + BlacklistApplications blacklistApplications = new BlacklistApplications(); + List appIds = new ArrayList<>(); + appIds.add("org.wso2.iot.agent"); + blacklistApplications.setAppIdentifier(appIds); + blacklistApplicationsBeanWrapper.setOperation(blacklistApplications); + return blacklistApplicationsBeanWrapper; + } + + public static UpgradeFirmwareBeanWrapper getUpgradeFirmwareBeanWrapper() { + UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper = new UpgradeFirmwareBeanWrapper(); + upgradeFirmwareBeanWrapper.setDeviceIDs(getDeviceIds()); + UpgradeFirmware upgradeFirmware = new UpgradeFirmware(); + upgradeFirmware.setServer("https://github.com/wso2/cdmf-agent-android/releases/download/"); + upgradeFirmware.setSchedule("2017-10-11T18:46:19-0530"); + upgradeFirmwareBeanWrapper.setOperation(upgradeFirmware); + return upgradeFirmwareBeanWrapper; + } + + public static VpnBeanWrapper getVpnBeanWrapper() { + VpnBeanWrapper vpnBeanWrapper = new VpnBeanWrapper(); + vpnBeanWrapper.setDeviceIDs(getDeviceIds()); + Vpn vpn = new Vpn(); + vpnBeanWrapper.setOperation(vpn); + return vpnBeanWrapper; + } + + public static NotificationBeanWrapper getNotificationBeanWrapper() { + NotificationBeanWrapper notificationBeanWrapper = new NotificationBeanWrapper(); + notificationBeanWrapper.setDeviceIDs(getDeviceIds()); + Notification notification = new Notification(); + notification.setMessageText("Message"); + notification.setMessageTitle("Title"); + notificationBeanWrapper.setOperation(notification); + return notificationBeanWrapper; + } + + public static WifiBeanWrapper getWifiBeanWrapper() { + WifiBeanWrapper wifiBeanWrapper = new WifiBeanWrapper(); + wifiBeanWrapper.setDeviceIDs(getDeviceIds()); + Wifi wifi = new Wifi(); + wifiBeanWrapper.setOperation(wifi); + return wifiBeanWrapper; + } + + public static EncryptionBeanWrapper getEncryptionBeanWrapper() { + EncryptionBeanWrapper encryptionBeanWrapper = new EncryptionBeanWrapper(); + encryptionBeanWrapper.setDeviceIDs(getDeviceIds()); + DeviceEncryption deviceEncryption = new DeviceEncryption(); + deviceEncryption.setEncrypted(true); + encryptionBeanWrapper.setOperation(deviceEncryption); + return encryptionBeanWrapper; + } + + public static LockCodeBeanWrapper getLockCodeBeanWrapper() { + LockCodeBeanWrapper lockCodeBeanWrapper = new LockCodeBeanWrapper(); + lockCodeBeanWrapper.setDeviceIDs(getDeviceIds()); + LockCode lockCode = new LockCode(); + lockCode.setLockCode("1234"); + lockCodeBeanWrapper.setOperation(lockCode); + return lockCodeBeanWrapper; + } + + public static PasswordPolicyBeanWrapper getPasswordPolicyBeanWrapper() { + PasswordPolicyBeanWrapper passwordPolicyBeanWrapper = new PasswordPolicyBeanWrapper(); + passwordPolicyBeanWrapper.setDeviceIDs(getDeviceIds()); + PasscodePolicy passcodePolicy = new PasscodePolicy(); + passwordPolicyBeanWrapper.setOperation(passcodePolicy); + return passwordPolicyBeanWrapper; + } + + public static WebClipBeanWrapper getWebClipBeanWrapper() { + WebClipBeanWrapper webClipBeanWrapper = new WebClipBeanWrapper(); + webClipBeanWrapper.setDeviceIDs(getDeviceIds()); + WebClip webClip = new WebClip(); + webClipBeanWrapper.setOperation(webClip); + return webClipBeanWrapper; + } + + public static List getAndroidApplications() { + List androidApplications = new ArrayList<>(); + AndroidApplication androidApplication = new AndroidApplication(); + androidApplications.add(androidApplication); + return androidApplications; + } + + public static List getSuccessMonitorOperationResponse() { + List operations = new ArrayList<>(); + Operation operation = new Operation(); + operation.setActivityId(getActivity().getActivityId()); + operation.setCode(AndroidConstants.OperationCodes.MONITOR); + operation.setId(1); + operation.setOperationResponse("Operation success."); + operation.setStatus(Operation.Status.COMPLETED); + operations.add(operation); + return operations; + } + + public static List getSuccessApplicationOperationResponse() { + List operations = new ArrayList<>(); + Operation operation = new Operation(); + operation.setActivityId(getActivity().getActivityId()); + operation.setCode(AndroidConstants.OperationCodes.APPLICATION_LIST); + operation.setId(1); + operation.setOperationResponse("[{\"name\":\"Widget%20Preview\",\"package\":\"com.android.widgetpreview\"," + + "\"version\":\"7.1.1\",\"isSystemApp\":false,\"isActive\":false}," + + "{\"name\":\"com.android.gesture.builder\"," + + "\"package\":\"com.android.gesture.builder\",\"version\":\"7.1.1\"," + + "\"isSystemApp\":false,\"isActive\":false},{\"name\":\"API%20Demos\"," + + "\"package\":\"com.example.android.apis\",\"version\":\"7.1.1\"," + + "\"isSystemApp\":false,\"isActive\":false}," + + "{\"name\":\"WSO2%20Device%20Management%20Agent\"," + + "\"package\":\"org.wso2.iot.agent\",\"version\":\"3.1.21\"," + + "\"isSystemApp\":false,\"isActive\":true}," + + "{\"name\":\"com.android.smoketest.tests\"," + + "\"package\":\"com.android.smoketest.tests\",\"version\":\"7.1.1\"," + + "\"isSystemApp\":false,\"isActive\":false}," + + "{\"name\":\"Sample%20Soft%20Keyboard\"," + + "\"package\":\"com.example.android.softkeyboard\",\"version\":\"7.1.1\"," + + "\"isSystemApp\":false,\"isActive\":false},{\"name\":\"Example%20Wallpapers\"," + + "\"package\":\"com.example.android.livecubes\",\"version\":\"7.1.1\"," + + "\"isSystemApp\":false,\"isActive\":false},{\"name\":\"com.android.smoketest\"," + + "\"package\":\"com.android.smoketest\",\"version\":\"7.1.1\"," + + "\"isSystemApp\":false,\"isActive\":false}]"); + operation.setStatus(Operation.Status.COMPLETED); + operations.add(operation); + return operations; + } + + public static List getSuccessInfoOperationResponse() { + List operations = new ArrayList<>(); + Operation operation = new Operation(); + operation.setActivityId(getActivity().getActivityId()); + operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO); + operation.setId(1); + operation.setOperationResponse("{\"description\":\"generic_x86\",\"deviceIdentifier\":\"1d9612def9d205f9\"," + + "\"enrolmentInfo\":null,\"name\":\"generic_x86\",\"properties\":[" + + "{\"name\":\"SERIAL\",\"value\":\"unknown\"}," + + "{\"name\":\"IMEI\",\"value\":null}," + + "{\"name\":\"IMSI\",\"value\":\"310260000000000\"}," + + "{\"name\":\"MAC\",\"value\":\"02:00:00:00:00:00\"}," + + "{\"name\":\"DEVICE_MODEL\",\"value\":\"Android SDK built for x86\"}," + + "{\"name\":\"VENDOR\",\"value\":\"unknown\"}," + + "{\"name\":\"OS_VERSION\",\"value\":\"7.1.1\"}," + + "{\"name\":\"OS_BUILD_DATE\",\"value\":\"1487782847000\"}," + + "{\"name\":\"DEVICE_NAME\",\"value\":\"generic_x86\"}," + + "{\"name\":\"LATITUDE\",\"value\":\"6.90988\"}," + + "{\"name\":\"LONGITUDE\",\"value\":\"79.85249999999999\"}," + + "{\"name\":\"NETWORK_INFO\",\"value\":\"[" + + "{\\\"name\\\":\\\"CONNECTION_TYPE\\\",\\\"value\\\":\\\"MOBILE\\\"}," + + "{\\\"name\\\":\\\"MOBILE_CONNECTION_TYPE\\\",\\\"value\\\":\\\"LTE\\\"}," + + "{\\\"name\\\":\\\"MOBILE_SIGNAL_STRENGTH\\\",\\\"value\\\":\\\"-89\\\"}]\"}," + + "{\"name\":\"CPU_INFO\",\"value\":\"[]\"},{\"name\":\"RAM_INFO\",\"value\":\"[" + + "{\\\"name\\\":\\\"TOTAL_MEMORY\\\",\\\"value\\\":\\\"1055113216\\\"}," + + "{\\\"name\\\":\\\"AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"708997120\\\"}," + + "{\\\"name\\\":\\\"THRESHOLD\\\",\\\"value\\\":\\\"150994944\\\"}," + + "{\\\"name\\\":\\\"LOW_MEMORY\\\",\\\"value\\\":\\\"false\\\"}]\"}," + + "{\"name\":\"BATTERY_INFO\",\"value\":\"[" + + "{\\\"name\\\":\\\"BATTERY_LEVEL\\\",\\\"value\\\":\\\"100\\\"}," + + "{\\\"name\\\":\\\"SCALE\\\",\\\"value\\\":\\\"100\\\"}," + + "{\\\"BATTERY_VOLTAGE\\\":\\\"0\\\"}," + + "{\\\"name\\\":\\\"HEALTH\\\",\\\"value\\\":\\\"GOOD_CONDITION\\\"}," + + "{\\\"name\\\":\\\"STATUS\\\"}," + + "{\\\"name\\\":\\\"PLUGGED\\\",\\\"value\\\":\\\"AC\\\"}]\"}," + + "{\"name\":\"DEVICE_INFO\",\"value\":\"[" + + "{\\\"name\\\":\\\"ENCRYPTION_ENABLED\\\",\\\"value\\\":\\\"false\\\"}," + + "{\\\"name\\\":\\\"PASSCODE_ENABLED\\\",\\\"value\\\":\\\"true\\\"}," + + "{\\\"name\\\":\\\"BATTERY_LEVEL\\\",\\\"value\\\":\\\"100\\\"}," + + "{\\\"name\\\":\\\"INTERNAL_TOTAL_MEMORY\\\",\\\"value\\\":\\\"0.76\\\"}," + + "{\\\"name\\\":\\\"INTERNAL_AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"0.67\\\"}," + + "{\\\"name\\\":\\\"EXTERNAL_TOTAL_MEMORY\\\",\\\"value\\\":\\\"0.1\\\"}," + + "{\\\"name\\\":\\\"EXTERNAL_AVAILABLE_MEMORY\\\",\\\"value\\\":\\\"0.1\\\"}," + + "{\\\"name\\\":\\\"OPERATOR\\\",\\\"value\\\":\\\"Android\\\"}," + + "{\\\"name\\\":\\\"PHONE_NUMBER\\\",\\\"value\\\":\\\"15555215554\\\"}]\"}]}"); + operation.setStatus(Operation.Status.COMPLETED); + operations.add(operation); + return operations; + } + + public static List getInProgressOperationResponse() { + List operations = new ArrayList<>(); + Operation operation = new Operation(); + operation.setActivityId(getActivity().getActivityId()); + operation.setCode(AndroidConstants.OperationCodes.NOTIFICATION); + operation.setId(1); + operation.setOperationResponse("Operation in progress."); + operation.setStatus(Operation.Status.IN_PROGRESS); + operations.add(operation); + return operations; + } + + public static List getErrorOperationResponse() { + List operations = new ArrayList<>(); + Operation operation = new Operation(); + operation.setActivityId(getActivity().getActivityId()); + operation.setCode(AndroidConstants.OperationCodes.DEVICE_INFO); + operation.setId(1); + operation.setOperationResponse("Operation failure."); + operation.setStatus(Operation.Status.ERROR); + operations.add(operation); + return operations; + } + + public static DeviceLocation getDeviceLocation() { + DeviceLocation location = new DeviceLocation(); + location.setCity("Colombo"); + location.setCountry("Sri Lanka"); + location.setLatitude(6.9); + location.setLongitude(79.5); + location.setDeviceIdentifier(AndroidDeviceUtils.convertToDeviceIdentifierObject(getDeviceId())); + return location; + } + + public static DeviceInfo getDeviceInfo() { + DeviceInfo deviceInfo = new DeviceInfo(); + deviceInfo.setDeviceModel("nexus"); + deviceInfo.setAvailableRAMMemory(2.0); + deviceInfo.setBatteryLevel(100.0); + deviceInfo.setConnectionType("4G"); + deviceInfo.setCpuUsage(1.0); + deviceInfo.setExternalAvailableMemory(2.3); + deviceInfo.setExternalTotalMemory(4.0); + deviceInfo.setInternalAvailableMemory(1.0); + deviceInfo.setInternalTotalMemory(4.0); + deviceInfo.setLocation(getDeviceLocation()); + return deviceInfo; + } + + public static List getApplications() { + List applications = new ArrayList<>(); + Application app = new Application(); + app.setName("WSO2 IoT Agent"); + app.setApplicationIdentifier("org.wos2.iot.agent"); + app.setVersion("1.0.0"); + app.setPlatform("Android"); + applications.add(app); + return applications; + } + + public static AndroidDevice getBasicAndroidDevice() { + AndroidDevice androidDevice = new AndroidDevice(); + androidDevice.setName(getDevice().getName()); + androidDevice.setDescription(getDevice().getDescription()); + androidDevice.setDeviceIdentifier(getDeviceId()); + androidDevice.setDeviceInfo(getDeviceInfo()); + androidDevice.setApplications(getApplications()); + androidDevice.setEnrolmentInfo(getDevice().getEnrolmentInfo()); + return androidDevice; + } + +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/resources/log4j.properties b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/resources/log4j.properties new file mode 100644 index 000000000..90c5d0edc --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/resources/log4j.properties @@ -0,0 +1,34 @@ +# +# Copyright (c) 2017, 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. +# + +# +# This is the log4j configuration file used by WSO2 Carbon +# +# IMPORTANT : Please do not remove or change the names of any +# of the Appender defined here. The layout pattern & log file +# can be changed using the WSO2 Carbon Management Console, and those +# settings will override the settings in this file. +# + +log4j.rootLogger=DEBUG, STD_OUT + +# Redirect log messages to console +log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender +log4j.appender.STD_OUT.Target=System.out +log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout +log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/resources/testng.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/resources/testng.xml new file mode 100644 index 000000000..865a1e85b --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/resources/testng.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + diff --git a/components/mobile-plugins/android-plugin/pom.xml b/components/mobile-plugins/android-plugin/pom.xml index 2011bdb4d..e1e5444db 100644 --- a/components/mobile-plugins/android-plugin/pom.xml +++ b/components/mobile-plugins/android-plugin/pom.xml @@ -35,6 +35,7 @@ org.wso2.carbon.device.mgt.mobile.android org.wso2.carbon.device.mgt.mobile.android.api + org.wso2.carbon.device.mgt.mobile.android.v09.api org.wso2.carbon.device.mgt.mobile.android.emulator org.wso2.carbon.device.mgt.mobile.android.ui diff --git a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml index 98917b023..e7781ad39 100644 --- a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml +++ b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/pom.xml @@ -141,6 +141,27 @@ + + copy-v09-jaxrs-war + package + + copy + + + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.mobile.android.v09.api + ${project.version} + war + true + ${project.build.directory}/maven-shared-archive-resources/webapps/ + + api#device-mgt#android#v0.9.war + + + + @@ -258,7 +279,6 @@ - diff --git a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf index f9deb6ee1..2da1d8f51 100644 --- a/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf +++ b/features/mobile-plugins-feature/android-plugin-feature/org.wso2.carbon.device.mgt.mobile.android.feature/src/main/resources/p2.inf @@ -1,5 +1,6 @@ instructions.configure = \ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/webapps/api#device-mgt#android#v1.0.war,target:${installFolder}/../../deployment/server/webapps/api#device-mgt#android#v1.0.war,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/webapps/api#device-mgt#android#v0.9.war,target:${installFolder}/../../deployment/server/webapps/api#device-mgt#android#v0.9.war,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/jaggeryapps/devicemgt,target:${installFolder}/../../deployment/server/jaggeryapps/devicemgt,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/jaggeryapps/android-web-agent,target:${installFolder}/../../deployment/server/jaggeryapps/android-web-agent,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.mobile.android_${feature.version}/datasources/,target:${installFolder}/../../conf/datasources/,overwrite:true);\ diff --git a/pom.xml b/pom.xml index 3b6134525..42fa2ea4d 100644 --- a/pom.xml +++ b/pom.xml @@ -1215,7 +1215,7 @@ 1.1.1 - 3.0.184 + 3.0.185-SNAPSHOT [3.0.0, 4.0.0)