Merge branch 'master' into 'master'

Refactor Android plugin

See merge request entgra/carbon-device-mgt-plugins!126
revert-dabc3590
Saad Sahibjan 5 years ago
commit cd8b31904d

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
~
~ Entgra (pvt) Ltd. 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>android-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>5.0.7-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.mobile.android.addons</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - Mobile Device Management Android Addons Impl</name>
<description>WSO2 Carbon - Mobile Device Management Android Addons Implementation</description>
<url>https://entgra.io/</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${carbon.devicemgt.plugins.version}</Bundle-Version>
<Bundle-Description>Device Management Mobile Android addons Impl Bundle</Bundle-Description>
<Import-Package>
com.google.gson.*
</Import-Package>
<Export-Package>
org.wso2.carbon.device.mgt.mobile.android.addons.*
</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.logging</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>
</project>

@ -16,9 +16,14 @@
* under the License.
*
*/
package org.wso2.carbon.mdm.services.android.util;
package org.wso2.carbon.device.mgt.mobile.android.addons;
import javax.servlet.*;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@ -15,9 +15,7 @@
* 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;
package org.wso2.carbon.device.mgt.mobile.android.addons;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.common;
package org.wso2.carbon.device.mgt.mobile.android.addons;
public class ErrorMessage {

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.common;
package org.wso2.carbon.device.mgt.mobile.android.addons;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -29,7 +29,11 @@ import org.apache.cxf.message.MessageContentsList;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import javax.validation.*;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import javax.validation.executable.ExecutableValidator;
import java.lang.reflect.Method;
import java.util.List;

@ -49,44 +49,6 @@
<warName>api#device-mgt#android#v1.0</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
<outputDirectory>${basedir}/target/coverage-reports/site</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
@ -99,7 +61,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<version>1.8</version>
<executions>
<execution>
<phase>compile</phase>
@ -118,54 +80,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
<outputDirectory>${basedir}/target/coverage-reports/site</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>client</id>
<build>
<defaultGoal>test</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
@ -176,6 +90,32 @@
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<exclusions>
<exclusion>
<artifactId>asm</artifactId>
<groupId>asm</groupId>
</exclusion>
<exclusion>
<artifactId>neethi</artifactId>
<groupId>org.apache.neethi</groupId>
</exclusion>
<exclusion>
<artifactId>wsdl4j</artifactId>
<groupId>wsdl4j</groupId>
</exclusion>
<exclusion>
<artifactId>xml-resolver</artifactId>
<groupId>xml-resolver</groupId>
</exclusion>
<exclusion>
<artifactId>xmlschema-core</artifactId>
<groupId>org.apache.ws.xmlschema</groupId>
</exclusion>
<exclusion>
<artifactId>stax2-api</artifactId>
<groupId>org.codehaus.woodstox</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
@ -194,6 +134,12 @@
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>commons-lang</artifactId>
<groupId>commons-lang.wso2</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
@ -213,36 +159,16 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
<groupId>commons-httpclient.wso2</groupId>
<artifactId>commons-httpclient</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>org.wso2.carbon.device.mgt.mobile.android</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-httpclient.wso2</groupId>
<artifactId>commons-httpclient</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
@ -256,12 +182,42 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
<exclusion>
<artifactId>neethi</artifactId>
<groupId>org.wso2.orbit.org.apache.neethi</groupId>
</exclusion>
<exclusion>
<artifactId>httpcore</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
<exclusion>
<artifactId>geronimo-javamail_1.4_spec</artifactId>
<groupId>org.apache.geronimo.specs</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wso2.carbon.analytics</groupId>
<artifactId>org.wso2.carbon.analytics.api</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>asm</artifactId>
<groupId>org.ow2.asm</groupId>
</exclusion>
<exclusion>
<artifactId>objenesis</artifactId>
<groupId>org.objenesis</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
@ -285,13 +241,29 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-androidenterprise</artifactId>
<version>v1-rev186-1.25.0</version>
<exclusions>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
@ -299,79 +271,124 @@
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database.wso2</groupId>
<artifactId>h2-database-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.queuing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
<scope>test</scope>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</dependency>
<dependency>
<groupId>commons-dbcp.wso2</groupId>
<artifactId>commons-dbcp</artifactId>
<scope>test</scope>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.application.mgt.common</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
<exclusion>
<artifactId>neethi</artifactId>
<groupId>org.apache.neethi.wso2</groupId>
</exclusion>
<exclusion>
<artifactId>wsdl4j</artifactId>
<groupId>wsdl4j.wso2</groupId>
</exclusion>
<exclusion>
<artifactId>geronimo-stax-api_1.0_spec</artifactId>
<groupId>org.apache.geronimo.specs.wso2</groupId>
</exclusion>
<exclusion>
<artifactId>org.wso2.securevault</artifactId>
<groupId>org.wso2.securevault</groupId>
</exclusion>
<exclusion>
<artifactId>axis2-client</artifactId>
<groupId>org.apache.axis2.wso2</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-pool.wso2</groupId>
<artifactId>commons-pool</artifactId>
<scope>test</scope>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>javax.cache.wso2</artifactId>
<scope>test</scope>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>org.wso2.carbon.device.mgt.mobile.android.common</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<scope>test</scope>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>org.wso2.carbon.device.mgt.mobile.android.addons</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>org.wso2.carbon.device.mgt.mobile.android.core</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>org.wso2.carbon.feature.mgt.core</artifactId>
<groupId>org.wso2.carbon</groupId>
</exclusion>
<exclusion>
<artifactId>commons-lang3</artifactId>
<groupId>org.apache.commons</groupId>
</exclusion>
<exclusion>
<artifactId>annotations</artifactId>
<groupId>com.google.code.findbugs</groupId>
</exclusion>
<exclusion>
<artifactId>stax2-api</artifactId>
<groupId>org.codehaus.woodstox</groupId>
</exclusion>
<exclusion>
<artifactId>jaxb-impl</artifactId>
<groupId>com.sun.xml.bind</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-datatype-joda</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.apimgt.application.extension</artifactId>
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-androidenterprise</artifactId>
<version>v1-rev186-1.25.0</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.application.mgt.common</artifactId>
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
<exclusion>
<artifactId>axis2-client</artifactId>
<groupId>org.apache.axis2.wso2</groupId>
</exclusion>
<exclusion>
<artifactId>neethi</artifactId>
<groupId>org.wso2.orbit.org.apache.neethi</groupId>
</exclusion>
<exclusion>
<artifactId>wsdl4j</artifactId>
<groupId>wsdl4j.wso2</groupId>
</exclusion>
<exclusion>
<artifactId>XmlSchema</artifactId>
<groupId>org.apache.ws.commons.schema.wso2</groupId>
</exclusion>
<exclusion>
<artifactId>axiom-api</artifactId>
<groupId>org.apache.ws.commons.axiom</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

@ -15,9 +15,8 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.services;
package org.wso2.carbon.device.mgt.mobile.android.api;
import com.google.api.services.androidenterprise.model.Device;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -32,22 +31,17 @@ import io.swagger.annotations.Tag;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationPolicyDTO;
import org.wso2.carbon.device.mgt.mobile.android.impl.dto.AndroidEnterpriseManagedConfig;
import org.wso2.carbon.mdm.services.android.bean.DeviceState;
import org.wso2.carbon.mdm.services.android.bean.EnterpriseStoreCluster;
import org.wso2.carbon.mdm.services.android.bean.EnterpriseStorePage;
import org.wso2.carbon.mdm.services.android.bean.EnterpriseStorePageLinks;
import org.wso2.carbon.mdm.services.android.bean.wrapper.EnterpriseInstallPolicy;
import org.wso2.carbon.mdm.services.android.bean.wrapper.EnterpriseUser;
import org.wso2.carbon.mdm.services.android.bean.wrapper.EventBeanWrapper;
import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
import org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseStoreCluster;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseStorePage;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseStorePageLinks;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EnterpriseInstallPolicy;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EnterpriseUser;
import org.wso2.carbon.device.mgt.mobile.android.common.dto.AndroidEnterpriseManagedConfig;
import javax.validation.Valid;
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;
@ -69,10 +63,11 @@ import javax.ws.rs.core.Response;
}
),
tags = {
@Tag(name = "android,device_management", description = "")
@Tag(name = "android,device_management", description = "Android Device Management Service")
}
)
@Api(value = "Android Enterprise Service", description = "Android Enterprise Service ")
@Api(value = "Android Enterprise Service")
@Path("/enterprise")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ -92,7 +87,7 @@ import javax.ws.rs.core.Response;
)
}
)
public interface AndroidEnterpriseService {
public interface AndroidEnterpriseAPI {
@POST
@Path("/user")
@ -148,8 +143,7 @@ public interface AndroidEnterpriseService {
})
Response addUser(@ApiParam(
name = "user",
value = "Enterprise user and device data.")
EnterpriseUser enterpriseUser);
value = "Enterprise user and device data.") EnterpriseUser enterpriseUser);
//######################################################################################################################
//######################################################################################################################
@ -209,8 +203,7 @@ public interface AndroidEnterpriseService {
})
Response updateUser(@ApiParam(
name = "device",
value = "Enterprise user and device data.")
EnterpriseInstallPolicy device);
value = "Enterprise user and device data.") EnterpriseInstallPolicy device);
//######################################################################################################################
//######################################################################################################################
@ -269,43 +262,38 @@ public interface AndroidEnterpriseService {
Response getStoreUrl(
@ApiParam(
name = "approveApps",
value = "Boolean flag indicating whether to permanently delete the device.",
required = false)
value = "Boolean flag indicating whether to permanently delete the device.")
@QueryParam("approveApps") boolean approveApps,
@ApiParam(
name = "searchEnabled",
value = "Boolean flag indicating whether to permanently delete the device.",
required = false)
value = "Boolean flag indicating whether to permanently delete the device.")
@QueryParam("searchEnabled") boolean searchEnabled,
@ApiParam(
name = "isPrivateAppsEnabled",
value = "Boolean flag indicating whether to permanently delete the device.",
required = false) @QueryParam("isPrivateAppsEnabled") boolean isPrivateAppsEnabled,
value = "Boolean flag indicating whether to permanently delete the device.")
@QueryParam("isPrivateAppsEnabled") boolean isPrivateAppsEnabled,
@ApiParam(
name = "isWebAppEnabled",
value = "Boolean flag indicating whether to permanently delete the device.",
required = false) @QueryParam("isWebAppEnabled") boolean isWebAppEnabled,
value = "Boolean flag indicating whether to permanently delete the device.")
@QueryParam("isWebAppEnabled") boolean isWebAppEnabled,
@ApiParam(
name = "isOrganizeAppPageVisible",
value = "Boolean flag indicating whether to permanently delete the device.",
required = false) @QueryParam("isOrganizeAppPageVisible") boolean isOrganizeAppPageVisible,
value = "Boolean flag indicating whether to permanently delete the device.")
@QueryParam("isOrganizeAppPageVisible") boolean isOrganizeAppPageVisible,
@ApiParam(
name = "isManagedConfigEnabled",
value = "Boolean flag indicating whether to permanently delete the device.",
required = false) @QueryParam("isManagedConfigEnabled") boolean isManagedConfigEnabled,
value = "Boolean flag indicating whether to permanently delete the device.")
@QueryParam("isManagedConfigEnabled") boolean isManagedConfigEnabled,
@ApiParam(name = "host",
value = "Boolean flag indicating whether to permanently delete the device.",
required = true) @QueryParam("host") String host);
@GET
@Path("/products/sync")
@ApiOperation(
@ -416,8 +404,7 @@ public interface AndroidEnterpriseService {
})
Response addPage(@ApiParam(
name = "page",
value = "Enterprise page.")
EnterpriseStorePage page);
value = "Enterprise page.") EnterpriseStorePage page);
//######################################################################################################################
//######################################################################################################################
@ -777,8 +764,7 @@ public interface AndroidEnterpriseService {
})
Response addCluster(@ApiParam(
name = "storeCluster",
value = "Enterprise cluster.")
EnterpriseStoreCluster storeCluster);
value = "Enterprise cluster.") EnterpriseStoreCluster storeCluster);
//######################################################################################################################
//######################################################################################################################
@ -965,7 +951,7 @@ public interface AndroidEnterpriseService {
@ApiParam(
name = "pageId",
value = "The unique page pageId")
@PathParam("pageId") String pageId);
@PathParam("id") String pageId);
//######################################################################################################################
//######################################################################################################################
@ -1025,8 +1011,7 @@ public interface AndroidEnterpriseService {
})
Response updateLinks(@ApiParam(
name = "links",
value = "Enterprise page links.")
EnterpriseStorePageLinks links);
value = "Enterprise page links.") EnterpriseStorePageLinks links);
//######################################################################################################################
//######################################################################################################################

@ -32,16 +32,16 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.services;
package org.wso2.carbon.device.mgt.mobile.android.api;
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 org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.AndroidApplication;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.AndroidDevice;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
@ -73,11 +73,10 @@ import java.util.List;
}
),
tags = {
@Tag(name = "android,device_management", description = "")
@Tag(name = "android,device_management", description = "Android Device Management Service")
}
)
@Api(value = "Android Device Management",
description = "This carries all the resources related to the Android device management functionalities.")
@Api(value = "Android Device Management")
@Path("/devices")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ -97,7 +96,7 @@ import java.util.List;
)
}
)
public interface DeviceManagementService {
public interface DeviceManagementAPI {
@PUT
@Path("/{id}/applications")
@ -211,8 +210,7 @@ public interface DeviceManagementService {
Response getPendingOperations(
@ApiParam(
name = "disableGoogleApps",
value = "Specifically disable having Google apps installed.",
required = false)
value = "Specifically disable having Google apps installed.")
@QueryParam("disableGoogleApps") boolean disableGoogleApps,
@ApiParam(
name = "id",
@ -223,8 +221,7 @@ public interface DeviceManagementService {
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)
"Example: Mon, 05 Jan 2014 15:10:00 +0200.")
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@ApiParam(
name = "resultOperations",
@ -339,8 +336,7 @@ public interface DeviceManagementService {
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)
"Example: Mon, 05 Jan 2014 15:10:00 +0200")
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@PUT

@ -33,7 +33,7 @@
* under the License.
*
*/
package org.wso2.carbon.mdm.services.android.services;
package org.wso2.carbon.device.mgt.mobile.android.api;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Info;
@ -49,8 +49,26 @@ 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 org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.ApplicationInstallationBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.ApplicationRestrictionBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.ApplicationUninstallationBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.ApplicationUpdateBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.BlacklistApplicationsBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.CameraBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.DeviceLockBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.DisplayMessageBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EncryptionBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.FileTransferBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.GlobalProxyBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.LockCodeBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.NotificationBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.PasswordPolicyBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.UpgradeFirmwareBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.VpnBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.WebClipBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.WifiBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.WipeDataBeanWrapper;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
@ -75,11 +93,11 @@ import java.util.List;
}
),
tags = {
@Tag(name = "android,device_management", description = "")
@Tag(name = "android,device_management", description = "Android Device Management Admin Service")
}
)
@Path("/admin/devices")
@Api(value = "Android Device Management Administrative Service", description = "Device management related admin APIs.")
@Api(value = "Android Device Management Administrative Service")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Scopes(
@ -266,7 +284,7 @@ import java.util.List;
)
}
)
public interface DeviceManagementAdminService {
public interface DeviceManagementAdminAPI {
@POST
@Path("/file-transfer")
@ -632,8 +650,7 @@ public interface DeviceManagementAdminService {
"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);
required = true) CameraBeanWrapper cameraBeanWrapper);
@POST
@Path("/info")
@ -880,8 +897,7 @@ public interface DeviceManagementAdminService {
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);
required = true) WipeDataBeanWrapper wipeDataBeanWrapper);
@POST
@Path("/applications")
@ -1248,8 +1264,7 @@ public interface DeviceManagementAdminService {
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);
required = true) ApplicationInstallationBeanWrapper applicationInstallationBeanWrapper);
@POST
@Path("/update-application")
@ -1313,8 +1328,7 @@ public interface DeviceManagementAdminService {
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);
required = true) ApplicationUpdateBeanWrapper applicationUpdateBeanWrapper);
@POST
@Path("/uninstall-application")
@ -1375,8 +1389,7 @@ public interface DeviceManagementAdminService {
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);
required = true) ApplicationUninstallationBeanWrapper applicationUninstallationBeanWrapper);
@POST
@Path("/blacklist-applications")
@ -1504,8 +1517,7 @@ public interface DeviceManagementAdminService {
"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);
required = true) UpgradeFirmwareBeanWrapper upgradeFirmwareBeanWrapper);
@POST
@Path("/configure-vpn")
@ -1565,8 +1577,7 @@ public interface DeviceManagementAdminService {
@ApiParam(
name = "vpnBean",
value = "VPN configuration and DeviceIds",
required = true)
VpnBeanWrapper vpnBeanWrapper);
required = true) VpnBeanWrapper vpnBeanWrapper);
@POST
@Path("/send-notification")
@ -1626,8 +1637,7 @@ public interface DeviceManagementAdminService {
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);
required = true) NotificationBeanWrapper notificationBeanWrapper);
@POST
@Path("/configure-wifi")
@ -1688,8 +1698,7 @@ public interface DeviceManagementAdminService {
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);
required = true) WifiBeanWrapper wifiBeanWrapper);
@POST
@Path("/encrypt-storage")
@ -1750,8 +1759,7 @@ public interface DeviceManagementAdminService {
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);
required = true) EncryptionBeanWrapper encryptionBeanWrapper);
@POST
@Path("/change-lock-code")
@ -1812,8 +1820,7 @@ public interface DeviceManagementAdminService {
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);
required = true) LockCodeBeanWrapper lockCodeBeanWrapper);
@POST
@Path("/set-password-policy")
@ -1872,8 +1879,7 @@ public interface DeviceManagementAdminService {
@ApiParam(
name = "passwordPolicy",
value = "The properties required to set a password policy.",
required = true)
PasswordPolicyBeanWrapper passwordPolicyBeanWrapper);
required = true) PasswordPolicyBeanWrapper passwordPolicyBeanWrapper);
@POST
@Path("/set-webclip")
@ -1932,8 +1938,7 @@ public interface DeviceManagementAdminService {
@ApiParam(
name = "webClip",
value = "The properties to set the web clip.",
required = true)
WebClipBeanWrapper webClipBeanWrapper);
required = true) WebClipBeanWrapper webClipBeanWrapper);
@POST
@Path("/send-app-conf")
@ApiOperation(
@ -1994,8 +1999,7 @@ public interface DeviceManagementAdminService {
value = "The properties required to send application restrictions. Provide the restriction you " +
"wish to send and the ID of the Android device. Multiple device IDs can be added by using" +
" comma separated values.",
required = true)
ApplicationRestrictionBeanWrapper applicationRestrictionBeanWrapper);
required = true) ApplicationRestrictionBeanWrapper applicationRestrictionBeanWrapper);
@POST
@Path("/configure-global-proxy")
@ -2056,8 +2060,7 @@ public interface DeviceManagementAdminService {
@ApiParam(
name = "globalProxyInfo",
value = "The properties to set the global proxy settings.",
required = true)
GlobalProxyBeanWrapper globalProxyBeanWrapper);
required = true) GlobalProxyBeanWrapper globalProxyBeanWrapper);
@POST
@Path("/configure-display-message")
@ -2107,6 +2110,5 @@ public interface DeviceManagementAdminService {
name = "display-message",
value = "The properties required to send a messages. 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)
DisplayMessageBeanWrapper displayMessageBeanWrapper);
required = true) DisplayMessageBeanWrapper displayMessageBeanWrapper);
}

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.mdm.services.android.services;
package org.wso2.carbon.device.mgt.mobile.android.api;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Info;
@ -32,9 +32,8 @@ 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 org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.AndroidPlatformConfiguration;
import javax.validation.Valid;
import javax.ws.rs.*;
@ -55,10 +54,10 @@ import javax.ws.rs.core.Response;
}
),
tags = {
@Tag(name = "android,device_management", description = "")
@Tag(name = "android,device_management", description = "Device Type Configuration Service")
}
)
@Api(value = "Android Configuration Management", description = "This API carries all the resource used to mange the Android platform configurations.")
@Api(value = "Android Configuration Management")
@Path("/configuration")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ -84,7 +83,7 @@ import javax.ws.rs.core.Response;
)
}
)
public interface DeviceTypeConfigurationService {
public interface DeviceTypeConfigurationAPI {
@GET
@ApiOperation(
@ -136,8 +135,7 @@ public interface DeviceTypeConfigurationService {
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)
"Example: Mon, 05 Jan 2014 15:10:00 +0200")
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@PUT
@ -245,8 +243,7 @@ public interface DeviceTypeConfigurationService {
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;
"Example: Mon, 05 Jan 2014 15:10:00 +0200.")
@HeaderParam("If-Modified-Since") String ifModifiedSince);
}

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.mdm.services.android.services;
package org.wso2.carbon.device.mgt.mobile.android.api;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Info;
@ -31,9 +31,9 @@ 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 org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.DeviceState;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EventBeanWrapper;
import javax.validation.Valid;
import javax.validation.constraints.Size;
@ -53,12 +53,10 @@ import javax.ws.rs.core.Response;
}
),
tags = {
@Tag(name = "android,device_management", description = "")
@Tag(name = "android,device_management", description = "Android Even Receiver Service")
}
)
@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")
@Api(value = "Event Receiver")
@Path("/events")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ -72,7 +70,7 @@ import javax.ws.rs.core.Response;
)
}
)
public interface EventReceiverService {
public interface EventReceiverAPI {
@POST
@Path("/publish")
@ -131,8 +129,7 @@ public interface EventReceiverService {
@ApiParam(
name = "eventBeanWrapper",
value = "Information of the agent event to be published on DAS.")
@Valid
EventBeanWrapper eventBeanWrapper);
@Valid EventBeanWrapper eventBeanWrapper);
@GET
@ApiOperation(
@ -207,8 +204,7 @@ public interface EventReceiverService {
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)
"Example: Mon, 05 Jan 2014 15:10:00 +0200")
@HeaderParam("If-Modified-Since") String ifModifiedSince);
}

@ -16,9 +16,9 @@
* under the License.
*
*/
package org.wso2.carbon.mdm.services.android.services.impl;
package org.wso2.carbon.device.mgt.mobile.android.api.impl;
import com.google.api.services.androidenterprise.model.AppRestrictionsSchema;
import com.google.api.client.http.HttpStatusCodes;
import com.google.api.services.androidenterprise.model.ProductsListResponse;
import com.google.api.services.androidenterprise.model.StoreCluster;
import com.google.api.services.androidenterprise.model.StoreLayout;
@ -37,34 +37,34 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.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.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.mobile.android.impl.EnterpriseServiceException;
import org.wso2.carbon.device.mgt.mobile.android.impl.dto.AndroidEnterpriseManagedConfig;
import org.wso2.carbon.device.mgt.mobile.android.impl.dto.AndroidEnterpriseUser;
import org.wso2.carbon.mdm.services.android.bean.EnterpriseConfigs;
import org.wso2.carbon.mdm.services.android.bean.EnterpriseStoreCluster;
import org.wso2.carbon.mdm.services.android.bean.EnterpriseStorePackages;
import org.wso2.carbon.mdm.services.android.bean.EnterpriseStorePage;
import org.wso2.carbon.mdm.services.android.bean.EnterpriseStorePageLinks;
import org.wso2.carbon.mdm.services.android.bean.EnterpriseTokenUrl;
import org.wso2.carbon.mdm.services.android.bean.ErrorResponse;
import org.wso2.carbon.mdm.services.android.bean.GoogleAppSyncResponse;
import org.wso2.carbon.mdm.services.android.bean.wrapper.EnterpriseApp;
import org.wso2.carbon.mdm.services.android.bean.wrapper.EnterpriseInstallPolicy;
import org.wso2.carbon.mdm.services.android.bean.wrapper.EnterpriseUser;
import org.wso2.carbon.mdm.services.android.bean.wrapper.TokenWrapper;
import org.wso2.carbon.mdm.services.android.common.GoogleAPIInvoker;
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.services.AndroidEnterpriseService;
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.AndroidEnterpriseUtils;
import org.wso2.carbon.device.mgt.mobile.android.api.AndroidEnterpriseAPI;
import org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants;
import org.wso2.carbon.device.mgt.mobile.android.common.GoogleAPIInvoker;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseConfigs;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseStoreCluster;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseStorePackages;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseStorePage;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseStorePageLinks;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseTokenUrl;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.GoogleAppSyncResponse;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EnterpriseApp;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EnterpriseInstallPolicy;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EnterpriseUser;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.TokenWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.dto.AndroidEnterpriseManagedConfig;
import org.wso2.carbon.device.mgt.mobile.android.common.dto.AndroidEnterpriseUser;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.AndroidDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.EnterpriseServiceException;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.NotFoundException;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidEnterpriseUtils;
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
import javax.ws.rs.Consumes;
@ -85,8 +85,8 @@ import java.util.List;
@Path("/enterprise")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
private static final Log log = LogFactory.getLog(AndroidEnterpriseServiceImpl.class);
public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI {
private static final Log log = LogFactory.getLog(AndroidEnterpriseAPIImpl.class);
@Override
@Produces(MediaType.APPLICATION_JSON)
@ -120,11 +120,24 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
} catch (EnterpriseServiceException e) {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when saving user").build()).build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while adding user";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
return Response.status(Response.Status.OK).entity(token).build();
}
public String insertUser(EnterpriseUser enterpriseUser) throws EnterpriseServiceException {
public String insertUser(EnterpriseUser enterpriseUser)
throws EnterpriseServiceException, AndroidDeviceMgtPluginException {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
String token;
boolean deviceIdExist = false;
@ -174,9 +187,9 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
public Response updateUser(EnterpriseInstallPolicy device) {
boolean sentToDevice = false;
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
List<AndroidEnterpriseUser> enterpriseUserInstances = AndroidAPIUtils.getAndroidPluginService()
.getEnterpriseUser(device.getUsername());
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
@ -193,8 +206,21 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
} catch (EnterpriseServiceException e) {
String errorMessage = "App install failed. No user found for name " + device.getUsername();
log.error(errorMessage);
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage(errorMessage).build());
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND)
.setMessage(errorMessage).build()).build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while updating user";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
if (sentToDevice) {
return Response.status(Response.Status.OK).build();
@ -215,23 +241,24 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
@QueryParam("isOrganizeAppPageVisible") boolean isOrganizeAppPageVisible,
@QueryParam("isManagedConfigEnabled") boolean isManagedConfigEnabled,
@QueryParam("host") String host) {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
EnterpriseTokenUrl enterpriseTokenUrl = new EnterpriseTokenUrl();
if (enterpriseConfigs == null || enterpriseConfigs.getEnterpriseId() == null) {
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Not configured for AFW").build()).build();
}
enterpriseTokenUrl.setEnterpriseId(enterpriseConfigs.getEnterpriseId());
enterpriseTokenUrl.setApproveApps(approveApps);
enterpriseTokenUrl.setSearchEnabled(searchEnabled);
enterpriseTokenUrl.setPrivateAppsEnabled(isPrivateAppsEnabled);
enterpriseTokenUrl.setWebAppEnabled(isWebAppEnabled);
enterpriseTokenUrl.setOrganizeAppPageVisible(isOrganizeAppPageVisible);
enterpriseTokenUrl.setParentHost(host);
enterpriseTokenUrl.setManagedConfigEnabled(isManagedConfigEnabled);
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
EnterpriseTokenUrl enterpriseTokenUrl = new EnterpriseTokenUrl();
if (enterpriseConfigs == null || enterpriseConfigs.getEnterpriseId() == null) {
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Not configured for AFW").build()).build();
}
enterpriseTokenUrl.setEnterpriseId(enterpriseConfigs.getEnterpriseId());
enterpriseTokenUrl.setApproveApps(approveApps);
enterpriseTokenUrl.setSearchEnabled(searchEnabled);
enterpriseTokenUrl.setPrivateAppsEnabled(isPrivateAppsEnabled);
enterpriseTokenUrl.setWebAppEnabled(isWebAppEnabled);
enterpriseTokenUrl.setOrganizeAppPageVisible(isOrganizeAppPageVisible);
enterpriseTokenUrl.setParentHost(host);
enterpriseTokenUrl.setManagedConfigEnabled(isManagedConfigEnabled);
String token = googleAPIInvoker.getAdministratorWebToken(enterpriseTokenUrl);
TokenWrapper tokenWrapper = new TokenWrapper();
tokenWrapper.setToken(token);
@ -240,6 +267,18 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when calling get web token").build())
.build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while getting store url";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
@ -247,9 +286,10 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
@GET
@Path("/products/sync")
public Response syncApps() {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
ProductsListResponse productsListResponse = googleAPIInvoker
.listProduct(enterpriseConfigs.getEnterpriseId(), null);
AndroidEnterpriseUtils.persistApp(productsListResponse);
@ -267,6 +307,18 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when persisting app").build())
.build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while syncing apps";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
@ -300,9 +352,10 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
new ErrorResponse.ErrorResponseBuilder().setMessage("Message body is empty or incorrect").build())
.build();
}
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
String id = googleAPIInvoker.insertPage(enterpriseConfigs.getEnterpriseId(), page);
page.setPageId(id);
return Response.status(Response.Status.OK).entity(page).build();
@ -314,6 +367,18 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when inserting page "
+ page.getPageName() + " , due to an error with ESA").build() ).build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while adding page";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
@ -327,9 +392,10 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
.build();
}
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
String id = googleAPIInvoker.updatePage(enterpriseConfigs.getEnterpriseId(), page);
page.setPageId(id);
return Response.status(Response.Status.OK).entity(page).build();
@ -341,6 +407,18 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating page "
+ page.getPageName() + " , due to an error with ESA").build()).build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while updating page";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
@ -355,9 +433,10 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
.build();
}
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
googleAPIInvoker.deletePage(enterpriseConfigs.getEnterpriseId(), id);
return Response.status(Response.Status.OK).build();
} catch (IOException e) {
@ -368,6 +447,18 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating page "
+ id + " , Due to an error with ESA").build()).build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while deleting page";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
@ -375,9 +466,10 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
@Path("/store-layout/page")
@Override
public Response getPages() {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
StoreLayoutPagesListResponse pages = googleAPIInvoker.listPages(enterpriseConfigs.getEnterpriseId());
return Response.status(Response.Status.OK).entity(pages).build();
} catch (IOException e) {
@ -388,6 +480,18 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching page "
+ " , Due to an error with ESA").build()).build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while getting pages";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
@ -401,9 +505,10 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
new ErrorResponse.ErrorResponseBuilder().setMessage("Id cannot be empty").build())
.build();
}
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
StoreLayout layout = googleAPIInvoker.setStoreLayout(enterpriseConfigs.getEnterpriseId(), id);
return Response.status(Response.Status.OK).entity(layout).build();
} catch (IOException e) {
@ -414,6 +519,18 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when inserting home page "
+ id + " , due to an error with ESA").build() ).build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while setting home";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
@ -421,9 +538,10 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
@Path("/store-layout/home-page")
@Override
public Response getHome() {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
StoreLayout layout = googleAPIInvoker.getStoreLayout(enterpriseConfigs.getEnterpriseId());
return Response.status(Response.Status.OK).entity(layout).build();
} catch (IOException e) {
@ -433,6 +551,18 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching home page.").build() )
.build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while getting home";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
@ -455,9 +585,10 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
new ErrorResponse.ErrorResponseBuilder().setMessage("Cluster order cannot be empty").build()).build();
}
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
String id = googleAPIInvoker.insertCluster(enterpriseConfigs.getEnterpriseId(), storeCluster);
storeCluster.setClusterId(id);
return Response.status(Response.Status.OK).entity(storeCluster).build();
@ -469,6 +600,18 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating cluster "
+ storeCluster.getName() + " , due to an error with ESA").build()).build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while adding cluster";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
@ -491,9 +634,10 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
new ErrorResponse.ErrorResponseBuilder().setMessage("Cluster order cannot be empty").build()).build();
}
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
String id = googleAPIInvoker.updateCluster(enterpriseConfigs.getEnterpriseId(), storeCluster);
storeCluster.setClusterId(id);
return Response.status(Response.Status.OK).entity(storeCluster).build();
@ -505,6 +649,18 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when updating cluster "
+ storeCluster.getName() + " , due to an error with ESA").build()).build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while updating cluster";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
@ -521,9 +677,10 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
new ErrorResponse.ErrorResponseBuilder().setMessage("Page id cannot be empty").build()).build();
}
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
googleAPIInvoker.deleteCluster(enterpriseConfigs.getEnterpriseId(), pageId, clusterId);
return Response.status(Response.Status.OK).build();
} catch (IOException e) {
@ -534,6 +691,18 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when deleting cluster "
+ clusterId + " , due to an error with ESA").build()).build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while deleting cluster";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
@ -546,9 +715,10 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
new ErrorResponse.ErrorResponseBuilder().setMessage("Page id cannot be empty").build()).build();
}
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
StoreLayoutClustersListResponse response = googleAPIInvoker.getClusters(enterpriseConfigs.getEnterpriseId(), pageId);
if (response == null || response.getCluster() == null) {
return Response.status(Response.Status.NOT_FOUND).entity(
@ -603,6 +773,18 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching all details in PageId "
+ pageId).build()).build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while getting clusters in page";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
@ -610,9 +792,10 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
@Path("/store-layout/page-link")
@Override
public Response updateLinks(EnterpriseStorePageLinks link) {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
googleAPIInvoker.addLinks(enterpriseConfigs.getEnterpriseId(),
link.getPageId(), link.getLinks());
return Response.status(Response.Status.OK).build();
@ -624,6 +807,18 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when fetching page "
+ " , Due to an error with ESA").build()).build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while updating links";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
@ -727,11 +922,12 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
public Response updateUser(ApplicationPolicyDTO applicationPolicyDTO) {
boolean sentToDevice = false;
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
for (DeviceIdentifier deviceIdentifier : applicationPolicyDTO.getDeviceIdentifierList()) {
try {
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
GoogleAPIInvoker googleAPIInvoker = new GoogleAPIInvoker(enterpriseConfigs.getEsa());
AndroidEnterpriseUser userDetail = AndroidAPIUtils.getAndroidPluginService()
.getEnterpriseUserByDevice(deviceIdentifier.getId());
@ -761,9 +957,9 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
String errorMessage = "App: " + applicationPolicyDTO.getApplicationDTO()
.getPackageName() + " for device " + deviceIdentifier.getId();
log.error(errorMessage);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(Response.Status.BAD_REQUEST
.getStatusCode()).setMessage(errorMessage).build());
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST)
.setMessage(errorMessage).build()).build();
}
}
googleAPIInvoker.installApps(enterpriseConfigs.getEnterpriseId(), userDetail
@ -785,17 +981,28 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
} catch (EnterpriseServiceException e) {
String errorMessage = "App install failed for device " + deviceIdentifier.getId();
log.error(errorMessage);
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(Response.Status.NOT_FOUND
.getStatusCode()).setMessage(errorMessage).build());
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND)
.setMessage(errorMessage).build()).build();
} catch (FeatureManagementException e) {
String errorMessage = "Could not fetch effective policy for device " + deviceIdentifier.getId();
log.error(errorMessage);
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(Response.Status.INTERNAL_SERVER_ERROR
.getStatusCode()).setMessage(errorMessage).build());
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND)
.setMessage(errorMessage).build()).build();
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while updating user";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
}
if (sentToDevice) {
@ -813,67 +1020,79 @@ public class AndroidEnterpriseServiceImpl implements AndroidEnterpriseService {
@Path("/wipe-device")
public Response wipeEnterprise() {
log.warn("Wiping all devices!!!");
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
try {
// Take all enterprise devices in the DB.
List<AndroidEnterpriseUser> androidEnterpriseUsers = AndroidAPIUtils.getAndroidPluginService()
.getAllEnterpriseDevices(enterpriseConfigs.getEnterpriseId());
// Extract the device identifiers of enterprise devices.
List<String> deviceID = new ArrayList<>();
if (androidEnterpriseUsers != null && !androidEnterpriseUsers.isEmpty()) {
for (AndroidEnterpriseUser userDevice: androidEnterpriseUsers) {
deviceID.add(userDevice.getEmmDeviceId());
try{
EnterpriseConfigs enterpriseConfigs = AndroidEnterpriseUtils.getEnterpriseConfigs();
try {
// Take all enterprise devices in the DB.
List<AndroidEnterpriseUser> androidEnterpriseUsers = AndroidAPIUtils.getAndroidPluginService()
.getAllEnterpriseDevices(enterpriseConfigs.getEnterpriseId());
// Extract the device identifiers of enterprise devices.
List<String> deviceID = new ArrayList<>();
if (androidEnterpriseUsers != null && !androidEnterpriseUsers.isEmpty()) {
for (AndroidEnterpriseUser userDevice: androidEnterpriseUsers) {
deviceID.add(userDevice.getEmmDeviceId());
}
}
}
List<String> byodDevices = new ArrayList<>();
List<String> copeDevices = new ArrayList<>();
// Get all registered device
List<Device> devices = AndroidAPIUtils.getDeviceManagementService().
getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, false);
for (Device device : devices) { // Go through all enrolled devices
if (deviceID.contains(device.getDeviceIdentifier())) { // Filter out only enterprise enrolled devices.
if (EnrolmentInfo.OwnerShip.BYOD.equals(device.getEnrolmentInfo().getOwnership())) {
byodDevices.add(device.getDeviceIdentifier());
} else {
copeDevices.add(device.getDeviceIdentifier());
List<String> byodDevices = new ArrayList<>();
List<String> copeDevices = new ArrayList<>();
// Get all registered device
List<Device> devices = AndroidAPIUtils.getDeviceManagementService().
getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, false);
for (Device device : devices) { // Go through all enrolled devices
if (deviceID.contains(device.getDeviceIdentifier())) { // Filter out only enterprise enrolled devices.
if (device.getEnrolmentInfo().getOwnership().equals(EnrolmentInfo.OwnerShip.BYOD)) {
byodDevices.add(device.getDeviceIdentifier());
} else {
copeDevices.add(device.getDeviceIdentifier());
}
}
}
}
CommandOperation operation = new CommandOperation();
operation.setType(Operation.Type.COMMAND);//TODO: Check if this should be profile
// type when implementing COPE/COSU
if (byodDevices != null && !byodDevices.isEmpty()) { // BYOD devices only needs a data wipe(work profile)
log.warn("Wiping " + byodDevices.size() + " BYOD devices");
operation.setCode(AndroidConstants.OperationCodes.ENTERPRISE_WIPE);
} else if (copeDevices != null && copeDevices.size() > 0) {
log.warn("Wiping " + copeDevices.size() + " COPE/COSU devices");
operation.setCode(AndroidConstants.OperationCodes.WIPE_DATA);
CommandOperation operation = new CommandOperation();
operation.setType(Operation.Type.COMMAND);//TODO: Check if this should be profile
// type when implementing COPE/COSU
if (byodDevices != null && !byodDevices.isEmpty()) { // BYOD devices only needs a data wipe(work profile)
log.warn("Wiping " + byodDevices.size() + " BYOD devices");
operation.setCode(AndroidConstants.OperationCodes.ENTERPRISE_WIPE);
} else if (copeDevices != null && !copeDevices.isEmpty()) {
log.warn("Wiping " + copeDevices.size() + " COPE/COSU devices");
operation.setCode(AndroidConstants.OperationCodes.WIPE_DATA);
}
AndroidDeviceUtils.getOperationResponse(deviceID, operation);
log.warn("Added wipe to all devices");
return Response.status(Response.Status.OK).build();
} catch (EnterpriseServiceException e) {
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("Error when saving configs").build()).build();
} catch (OperationManagementException e) {
String errorMessage = "Could not add wipe command to enterprise " + enterpriseConfigs.getEnterpriseId();
log.error(errorMessage);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (DeviceManagementException e) {
String errorMessage = "Could not add wipe command to enterprise " + enterpriseConfigs.getEnterpriseId() +
" due to an error in device management";
log.error(errorMessage);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Could not add wipe command to enterprise due to invalid device ids";
log.error(errorMessage);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}
AndroidDeviceUtils.getOperationResponse(deviceID, operation);
log.warn("Added wipe to all devices");
return Response.status(Response.Status.OK).build();
} catch (EnterpriseServiceException e) {
String errorMessage = "Error when saving configs for enterprise " + enterpriseConfigs.getEnterpriseId();
log.error(errorMessage);
} catch (NotFoundException e) {
String errorMessage = "Not found";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (OperationManagementException e) {
String errorMessage = "Could not add wipe command to enterprise " + enterpriseConfigs.getEnterpriseId();
log.error(errorMessage);
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Unexpected server error";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (DeviceManagementException e) {
String errorMessage = "Could not add wipe command to enterprise " + enterpriseConfigs.getEnterpriseId() +
" due to an error in device management";
log.error(errorMessage);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Could not add wipe command to enterprise due to invalid device ids";
log.error(errorMessage);
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while executing wipe enterprice command";
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
}

@ -0,0 +1,262 @@
/*
* 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.
*
*
* Copyright (c) 2018, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.mobile.android.api.impl;
import com.google.api.client.http.HttpStatusCodes;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.mobile.android.api.DeviceManagementAPI;
import org.wso2.carbon.device.mgt.mobile.android.common.Message;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.AndroidApplication;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.AndroidDevice;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.*;
import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils;
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.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@Path("/devices")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class DeviceManagementAPIImpl implements DeviceManagementAPI {
private static final Log log = LogFactory.getLog(DeviceManagementAPIImpl.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<AndroidApplication> androidApplications) {
try {
AndroidService androidService = AndroidAPIUtils.getAndroidService();
Message responseMessage = androidService.updateApplicationList(id, androidApplications);
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);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(msg).build()).build();
}
}
@PUT
@Path("/{id}/pending-operations")
@Override
public Response getPendingOperations(@QueryParam("disableGoogleApps") boolean disableGoogleApps,
@PathParam("id") String id,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
List<? extends Operation> 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();
}
try {
AndroidService androidService = AndroidAPIUtils.getAndroidService();
List<? extends Operation> pendingOperations = androidService
.getPendingOperations(id, resultOperations, disableGoogleApps);
return Response.status(Response.Status.CREATED).entity(pendingOperations).build();
} catch (InvalidDeviceException e) {
String msg = "Device identifier is invalid. Device identifier " + id;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while getting pending operations of the device.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(msg).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while executing get pending operations";
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(errorMessage).build()).build();
}
}
@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);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST)
.setMessage(errorMessage).build()).build();
}
try {
AndroidService androidService = AndroidAPIUtils.getAndroidService();
Message message = androidService.enrollDevice(androidDevice);
return Response.status(Integer.parseInt(message.getResponseCode()))
.entity(message.getResponseMessage()).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while enrolling the android, which carries the id '" +
androidDevice.getDeviceIdentifier() + "'";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(msg).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while enrolling device";
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(errorMessage).build()).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 {
AndroidService androidService = AndroidAPIUtils.getAndroidService();
Message responseMessage = androidService.isEnrolled(id, deviceIdentifier);
return Response.status(Integer.parseInt(responseMessage.getResponseCode())).entity(responseMessage).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while checking enrollment status of the device.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(msg).build()).build();
}
}
@PUT
@Path("/{id}")
@Override
public Response modifyEnrollment(@PathParam("id") String id, @Valid AndroidDevice androidDevice) {
try {
AndroidService androidService = AndroidAPIUtils.getAndroidService();
if (androidService.modifyEnrollment(id, androidDevice)) {
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);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(msg).build()).build();
} catch (BadRequestException e){
String errorMessage = "The payload of the android device enrollment is incorrect.";
log.error(errorMessage, e);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST)
.setMessage(errorMessage).build()).build();
} catch (NotFoundException e) {
String errorMessage = "The device to be modified doesn't exist.";
log.error(errorMessage, e);
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND)
.setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while modifying enrollment";
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(errorMessage).build()).build();
}
}
@DELETE
@Path("/{id}")
@Override
public Response disEnrollDevice(@PathParam("id") String id) {
try {
AndroidService androidService = AndroidAPIUtils.getAndroidService();
if (androidService.disEnrollDevice(id)) {
String msg = "Android device that carries id '" + id + "' is successfully ";
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.OK.toString());
responseMessage.setResponseMessage(msg + "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 + "' is not available");
return Response.status(Response.Status.NOT_FOUND).entity(responseMessage).build();
}
} catch (DeviceManagementException e) {
String msg = "Error occurred while %s the Android device that carries the id '" + id + "'";
msg = String.format(msg, "dis-enrolling");
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(msg).build()).build();
}
}
}

@ -0,0 +1,128 @@
/*
* 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.
*
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.mobile.android.api.impl;
import com.google.api.client.http.HttpStatusCodes;
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.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.mobile.android.api.DeviceTypeConfigurationAPI;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.AndroidPlatformConfiguration;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.AndroidDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException;
import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils;
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;
@Path("/configuration")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class DeviceTypeConfigurationAPIImpl implements DeviceTypeConfigurationAPI {
private static final Log log = LogFactory.getLog(DeviceTypeConfigurationAPIImpl.class);
@GET
@Override
public Response getConfiguration(
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
try {
AndroidService androidService = AndroidAPIUtils.getAndroidService();
PlatformConfiguration platformConfiguration = androidService.getPlatformConfig();
return Response.status(Response.Status.OK).entity(platformConfiguration).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while retrieving the Android tenant configuration";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(msg).build()).build();
}
}
@PUT
@Override
public Response updateConfiguration(
@Valid AndroidPlatformConfiguration androidPlatformConfiguration) {
try {
AndroidService androidService = AndroidAPIUtils.getAndroidService();
androidService.updateConfiguration(androidPlatformConfiguration);
return Response.status(Response.Status.OK)
.entity("Android platform configuration has been updated successfully.").build();
} catch (BadRequestException e) {
String msg = "The payload of the android platform configuration is incorrect.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST)
.setMessage(msg).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String msg = "Error occurred while modifying configuration settings of Android platform";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(msg).build()).build();
}
}
@GET
@Path("/license")
@Produces(MediaType.TEXT_PLAIN)
public Response getLicense(
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
try {
License license = AndroidAPIUtils.getDeviceManagementService()
.getLicense(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID,
DeviceManagementConstants.LanguageCodes.LANGUAGE_CODE_ENGLISH_US);
return Response.status(Response.Status.OK).entity((license == null) ? null : license.getText()).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while retrieving the license configured for Android device enrolment";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(msg).build()).build();
}
}
}

@ -0,0 +1,114 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.mobile.android.api.impl;
import com.google.api.client.http.HttpStatusCodes;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.mobile.android.api.EventReceiverAPI;
import org.wso2.carbon.device.mgt.mobile.android.common.Message;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.DeviceState;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EventBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.*;
import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils;
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 EventReceiverAPIImpl implements EventReceiverAPI {
private static final Log log = LogFactory.getLog(EventReceiverAPIImpl.class);
@POST
@Path("/publish")
@Override
public Response publishEvents(@Valid EventBeanWrapper eventBeanWrapper) {
try{
AndroidService androidService = AndroidAPIUtils.getAndroidService();
Message message = androidService.publishEvents(eventBeanWrapper);
return Response.status(Integer.parseInt(message.getResponseCode())).entity(message.getResponseMessage()).build();
} catch (DeviceManagementException e) {
String errorMessage = "Error occurred while checking Operation Analytics is Enabled.";
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(errorMessage).build()).build();
} catch (UnexpectedServerErrorException e) {
String errorMessage = "Error occurred while getting the Data publisher Service instance.";
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e){
String errorMessage = "Error occurred while publishing events.";
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(errorMessage).build()).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) {
try{
AndroidService androidService = AndroidAPIUtils.getAndroidService();
List<DeviceState> deviceStates = androidService.retrieveAlerts(deviceId, from, to, type, ifModifiedSince);
return Response.status(Response.Status.OK).entity(deviceStates).build();
} catch (BadRequestException e){
String errorMessage = "Request must contain " +
"the device identifier. Optionally, both from and to value should be present to get " +
"alerts between times.";
log.error(errorMessage);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST)
.setMessage(errorMessage).build()).build();
} catch (NotFoundException e) {
String errorMessage = "Class not found";
log.error(errorMessage, e);
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND)
.setMessage(errorMessage).build()).build();
} catch (AndroidDeviceMgtPluginException e) {
String errorMessage = "Error occured while retrieving alerts";
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(errorMessage).build()).build();
}
}
}

@ -1,37 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.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());
}
}

@ -1,34 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.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());
}
}

@ -1,51 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.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;
}
}

@ -1,115 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.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();
}
}

@ -1,46 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.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;
}
}

@ -1,56 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.exception;
import org.wso2.carbon.mdm.services.android.util.AndroidConstants;
import org.wso2.carbon.mdm.services.android.util.AndroidDeviceUtils;
import javax.validation.ConstraintViolation;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import java.util.Set;
public class ParameterValidationException extends WebApplicationException {
private String message;
public <T> ParameterValidationException(Set<ConstraintViolation<T>> violations) {
super(Response.status(Response.Status.BAD_REQUEST)
.entity(AndroidDeviceUtils.getConstraintViolationErrorDTO(violations))
.header(AndroidConstants.HEADER_CONTENT_TYPE, AndroidConstants.APPLICATION_JSON)
.build());
//Set the error message
StringBuilder stringBuilder = new StringBuilder();
for (ConstraintViolation violation : violations) {
stringBuilder.append(violation.getRootBeanClass().getSimpleName());
stringBuilder.append(".");
stringBuilder.append(violation.getPropertyPath());
stringBuilder.append(": ");
stringBuilder.append(violation.getMessage());
stringBuilder.append(", ");
}
message = stringBuilder.toString();
}
@Override
public String getMessage() {
return message;
}
}

@ -1,48 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.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;
}
}

@ -1,569 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*
* Copyright (c) 2018, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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.lang.StringUtils;
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.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.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
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.Policy;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
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.device.mgt.mobile.android.impl.EnterpriseServiceException;
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.bean.wrapper.EnterpriseUser;
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.QueryParam;
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);
public static final String GOOGLE_AFW_EMM_ANDROID_ID = "googleEMMAndroidId";
public static final String GOOGLE_AFW_DEVICE_ID = "googleEMMDeviceId";
@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<AndroidApplication> androidApplications) {
Application application;
List<Application> 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(@QueryParam("disableGoogleApps") boolean disableGoogleApps,
@PathParam("id") String id,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
List<? extends Operation> 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<? extends Operation> pendingOperations;
try {
pendingOperations = AndroidDeviceUtils.getPendingOperations(deviceIdentifier, !disableGoogleApps);
} 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<? extends Operation> 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 {
String token = null;
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());
String googleEMMAndroidId = null;
String googleEMMDeviceId = null;
if (androidDevice.getProperties() != null) {
for (Device.Property property : androidDevice.getProperties()) {
if (property.getName().equals(GOOGLE_AFW_EMM_ANDROID_ID)) {
googleEMMAndroidId = property.getValue();
} else if (property.getName().equals(GOOGLE_AFW_DEVICE_ID)) {
googleEMMDeviceId = property.getValue();
}
}
if (googleEMMAndroidId != null && googleEMMDeviceId != null) {
EnterpriseUser user = new EnterpriseUser();
user.setAndroidPlayDeviceId(googleEMMAndroidId);
user.setEmmDeviceIdentifier(googleEMMDeviceId);
AndroidEnterpriseServiceImpl enterpriseService = new AndroidEnterpriseServiceImpl();
token = enterpriseService.insertUser(user);
}
}
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<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
deviceIdentifiers.add(deviceIdentifier);
List<String> 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();
Policy effectivePolicy = policyManagerService.
getEffectivePolicy(new DeviceIdentifier(androidDevice.getDeviceIdentifier(), device.getType()));
if (effectivePolicy != null) {
List<ProfileFeature> effectiveProfileFeatures = effectivePolicy.getProfile().
getProfileFeaturesList();
for (ProfileFeature feature : effectiveProfileFeatures) {
if (AndroidConstants.ApplicationInstall.ENROLLMENT_APP_INSTALL_FEATURE_CODE
.equals(feature.getFeatureCode())) {
AndroidDeviceUtils.installEnrollmentApplications(feature, deviceIdentifier);
break;
}
}
}
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.OK.toString());
if (token == null) {
responseMessage.setResponseMessage("Android device, which carries the id '" +
androidDevice.getDeviceIdentifier() + "' has successfully been enrolled");
} else {
responseMessage.setResponseMessage("Google response token" + token);
}
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());
} catch (EnterpriseServiceException e) {
String msg = "Error occurred while adding user via Google Apis '" +
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 {
AndroidDeviceUtils.updateDisEnrollOperationStatus(deviceIdentifier);
result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier);
if (result) {
String msg = "Android device that carries id '" + id + "' is successfully ";
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.OK.toString());
responseMessage.setResponseMessage(msg + "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 + "' is not available");
return Response.status(Response.Status.NOT_FOUND).entity(responseMessage).build();
}
} catch (DeviceManagementException e) {
String msg = "Error occurred while %s the Android device that carries the id '" + id + "'";
msg = String.format(msg, "dis-enrolling");
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<Device.Property> properties)
throws DeviceManagementException {
DeviceLocation location = null;
String latitude = "", longitude = "", altitude = "", speed = "", bearing = "", distance = "";
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 (propertyName.equals("LONGITUDE")) {
longitude = property.getValue();
}
if (propertyName.equals("ALTITUDE")) {
altitude = property.getValue();
}
if (propertyName.equals("SPEED")) {
speed = property.getValue();
}
if (propertyName.equals("BEARING")) {
bearing = property.getValue();
}
if (propertyName.equals("DISTANCE")) {
distance = property.getValue();
}
}
if (StringUtils.isNotBlank(latitude) && StringUtils.isNotBlank(longitude) &&
StringUtils.isNotBlank(altitude) && StringUtils.isNotBlank(speed) &&
StringUtils.isNotBlank(bearing) && StringUtils.isNotBlank(distance)) {
location = new DeviceLocation();
location.setLatitude(Double.valueOf(latitude));
location.setLongitude(Double.valueOf(longitude));
location.setAltitude(Double.valueOf(altitude));
location.setSpeed(Float.valueOf(speed));
location.setBearing(Float.valueOf(bearing));
location.setDistance(Double.valueOf(distance));
location.setDeviceIdentifier(deviceIdentifier);
Device savedDevice = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier, false);
location.setDeviceId(savedDevice.getId());
}
return location;
}
}

@ -1,238 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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.base.ServerConfiguration;
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.EnrolmentInfo;
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.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
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.bean.NotifierFrequency;
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<ConfigurationEntry> 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 (configs != null) {
ConfigurationEntry versionEntry = new ConfigurationEntry();
versionEntry.setContentType(AndroidConstants.TenantConfigProperties.CONTENT_TYPE_TEXT);
versionEntry.setName(AndroidConstants.TenantConfigProperties.SERVER_VERSION);
versionEntry.setValue(ServerConfiguration.getInstance().getFirstProperty("Version"));
configs.add(versionEntry);
if (license != 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<ConfigurationEntry> configs = configuration.getConfiguration();
NotifierFrequency notifierFrequency = new NotifierFrequency();
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;
} else if (AndroidConstants.TenantConfigProperties.NOTIFIER_FREQUENCY.equals(entry.getName())) {
if (entry.getValue() != null) {
notifierFrequency.setValue(Integer.parseInt(entry.getValue().toString()));
} else {
return Response.status(Response.Status.BAD_REQUEST)
.entity("No value specified for notifierFrequency.").build();
}
} else if (AndroidConstants.TenantConfigProperties.NOTIFIER_TYPE.equals(entry.getName())) {
if (entry.getValue() != null) {
notifierFrequency.setType(Integer.parseInt(entry.getValue().toString()));
} else {
return Response.status(Response.Status.BAD_REQUEST)
.entity("No value specified for notifierType.").build();
}
}
}
if (licenseEntry != null) {
configs.remove(licenseEntry);
}
configuration.setConfiguration(configs);
AndroidAPIUtils.getDeviceManagementService().saveConfiguration(configuration);
notifyDevices(notifierFrequency);
} 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());
} catch (NumberFormatException e) {
msg = "Error occurred while reading notification frequency.";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} catch (OperationManagementException 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());
} catch (InvalidDeviceException e) {
msg = "Error occurred with the device.";
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();
}
private void notifyDevices(NotifierFrequency notifierFrequency) throws DeviceManagementException,
OperationManagementException, InvalidDeviceException {
List<Device> deviceList = AndroidAPIUtils.
getDeviceManagementService().
getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, false);
List<DeviceIdentifier> deviceIdList = new ArrayList<>();
for (Device device : deviceList) {
if (EnrolmentInfo.Status.REMOVED != device.getEnrolmentInfo().getStatus()) {
deviceIdList.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
}
}
if (!deviceIdList.isEmpty()) {
ProfileOperation operation = new ProfileOperation();
operation.setCode(AndroidConstants.OperationCodes.NOTIFIER_FREQUENCY);
operation.setPayLoad(notifierFrequency.toJSON());
operation.setEnabled(true);
AndroidAPIUtils.getDeviceManagementService().addOperation(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID,
operation, deviceIdList);
}
}
@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();
}
}

@ -1,235 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.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.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
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 ALTITUDE = "altitude";
private static final String SPEED = "speed";
private static final String DISTANCE = "distance";
private static final String BEARING = "bearing";
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.");
}
Device device;
try {
if (!DeviceManagerUtil.isPublishLocationResponseEnabled()) {
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 = 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(), device.getEnrolmentInfo().getOwner(),
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(),
jsonObject.get(ALTITUDE).getAsDouble(),
jsonObject.get(SPEED).getAsFloat(),
jsonObject.get(BEARING).getAsFloat(),
jsonObject.get(DISTANCE).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 {
log.warn("Error occurred while trying to publish the event. This could be due to unavailability " +
"of the publishing service. Please make sure that analytics server is running and accessible " +
"by this server");
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(503l).setMessage("Error occurred due to " +
"unavailability of the publishing service.").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<DeviceState> 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<DeviceState> 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<DeviceState> 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());
}
}
}

@ -1,48 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.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<String> errorDeviceIdList;
private List<DeviceIdentifier> validDeviceIDList;
public List<String> getErrorDeviceIdList() {
return errorDeviceIdList;
}
public void setErrorDeviceIdList(List<String> errorDeviceIdList) {
this.errorDeviceIdList = errorDeviceIdList;
}
public List<DeviceIdentifier> getValidDeviceIDList() {
return validDeviceIDList;
}
public void setValidDeviceIDList(List<DeviceIdentifier> validDeviceIDList) {
this.validDeviceIDList = validDeviceIDList;
}
}

@ -34,7 +34,7 @@
<ref bean="jsonProvider"/>
<ref bean="errorHandler"/>
<ref bean="swaggerWriter"/>
<ref bean="GlobalExceptionMapper"/>
<!-- <ref bean="GlobalExceptionMapper"/>-->
</jaxrs:providers>
<jaxrs:properties>
<!-- This is added to catch interceptor level exceptions in GlobalThrowableMapper. -->
@ -44,8 +44,7 @@
<bean id="swaggerWriter" class="io.swagger.jaxrs.listing.SwaggerSerializers" />
<bean id="swaggerResource" class="io.swagger.jaxrs.listing.ApiListingResource" />
<bean id="GlobalExceptionMapper" class="org.wso2.carbon.mdm.services.android.exception.GlobalThrowableMapper"/>
<bean id="ValidationInterceptor" class="org.wso2.carbon.mdm.services.android.common.ValidationInterceptor"/>
<bean id="ValidationInterceptor" class="org.wso2.carbon.device.mgt.mobile.android.addons.ValidationInterceptor"/>
<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">
<property name="resourcePackage" value="org.wso2.carbon.mdm.services.android.services"/>
@ -60,13 +59,13 @@
<property name="scan" value="true"/>
</bean>
<bean id="deviceManagementService" class="org.wso2.carbon.mdm.services.android.services.impl.DeviceManagementServiceImpl"/>
<bean id="deviceManagementAdminService" class="org.wso2.carbon.mdm.services.android.services.impl.DeviceManagementAdminServiceImpl"/>
<bean id="eventReceiverService" class="org.wso2.carbon.mdm.services.android.services.impl.EventReceiverServiceImpl"/>
<bean id="deviceTypeConfigurationService" class="org.wso2.carbon.mdm.services.android.services.impl.DeviceTypeConfigurationServiceImpl"/>
<bean id="androidEnterprise" class="org.wso2.carbon.mdm.services.android.services.impl.AndroidEnterpriseServiceImpl"/>
<bean id="jsonProvider" class="org.wso2.carbon.mdm.services.android.common.GsonMessageBodyHandler"/>
<bean id="errorHandler" class="org.wso2.carbon.mdm.services.android.common.ErrorHandler"/>
<bean id="deviceManagementService" class="org.wso2.carbon.device.mgt.mobile.android.api.impl.DeviceManagementAPIImpl"/>
<bean id="deviceManagementAdminService" class="org.wso2.carbon.device.mgt.mobile.android.api.impl.DeviceManagementAdminAPIImpl"/>
<bean id="eventReceiverService" class="org.wso2.carbon.device.mgt.mobile.android.api.impl.EventReceiverAPIImpl"/>
<bean id="deviceTypeConfigurationService" class="org.wso2.carbon.device.mgt.mobile.android.api.impl.DeviceTypeConfigurationAPIImpl"/>
<bean id="androidEnterprise" class="org.wso2.carbon.device.mgt.mobile.android.api.impl.AndroidEnterpriseAPIImpl"/>
<bean id="jsonProvider" class="org.wso2.carbon.device.mgt.mobile.android.addons.GsonMessageBodyHandler"/>
<bean id="errorHandler" class="org.wso2.carbon.device.mgt.mobile.android.addons.ErrorHandler"/>
<cxf:bus>
<cxf:inInterceptors>
<ref bean="ValidationInterceptor"/>

@ -76,7 +76,7 @@
<filter>
<filter-name>ApiOriginFilter</filter-name>
<filter-class>org.wso2.carbon.mdm.services.android.util.ApiOriginFilter</filter-class>
<filter-class>org.wso2.carbon.device.mgt.mobile.android.addons.ApiOriginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ApiOriginFilter</filter-name>

@ -1,312 +0,0 @@
/*
* 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.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.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 testChangeLockTask()
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
mockDeviceManagementService();
Response response = deviceManagementAdminService.changeLockTask(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());
}
}

@ -1,334 +0,0 @@
/*
* 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.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.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(true, 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(true, "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(true, 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(true, 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(true, 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(true, 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(true, 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(true, 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<Device.Property> 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);
property = new Device.Property();
property.setName("ALTITUDE");
property.setValue("-59.8373726");
properties.add(property);
property = new Device.Property();
property.setName("SPEED");
property.setValue("0.5123423333");
properties.add(property);
property = new Device.Property();
property.setName("BEARING");
property.setValue("44.0");
properties.add(property);
property = new Device.Property();
property.setName("DISTANCE");
property.setValue("44.0");
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());
}
}

@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
~
~ Entgra (pvt) Ltd. 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>android-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<version>5.0.7-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.mobile.android.common</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - Mobile Device Management Android Common Impl</name>
<description>WSO2 Carbon - Mobile Device Management Android Common Implementation</description>
<url>https://entgra.io/</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${carbon.devicemgt.plugins.version}</Bundle-Version>
<Bundle-Description>Device Management Mobile Android Impl Bundle</Bundle-Description>
<Import-Package>
io.swagger.annotations.*;resolution:=optional,
javax.validation.constraints,
javax.xml.bind.annotation.*,
javax.xml,
javax.xml.stream,
javax.xml.bind.*,
javax.xml.parsers; version=0.0.0,
javax.naming,
org.wso2.carbon.context,
org.wso2.carbon.utils.*,
org.wso2.carbon.device.mgt.common.*,
org.wso2.carbon.ndatasource.core,
org.wso2.carbon.policy.mgt.common.*,
org.wso2.carbon.device.mgt.extensions.license.mgt.registry,
com.google.gson.*
</Import-Package>
<Export-Package>
org.wso2.carbon.device.mgt.mobile.android.common.*
</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.logging</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-androidenterprise</artifactId>
<version>v1-rev186-1.25.0</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
<exclusion>
<artifactId>objenesis</artifactId>
<groupId>org.objenesis</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
<exclusions>
<exclusion>
<artifactId>woodstox-core-asl</artifactId>
<groupId>org.codehaus.woodstox</groupId>
</exclusion>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
<exclusion>
<artifactId>axiom-api</artifactId>
<groupId>org.apache.ws.commons.axiom</groupId>
</exclusion>
<exclusion>
<artifactId>geronimo-stax-api_1.0_spec</artifactId>
<groupId>org.apache.geronimo.specs.wso2</groupId>
</exclusion>
<exclusion>
<artifactId>axis2-client</artifactId>
<groupId>org.apache.axis2.wso2</groupId>
</exclusion>
<exclusion>
<artifactId>httpcore</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.common;
package org.wso2.carbon.device.mgt.mobile.android.common;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
@ -49,11 +49,11 @@ import com.google.api.services.androidenterprise.model.User;
import com.google.common.collect.ImmutableList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.mobile.android.impl.EnterpriseServiceException;
import org.wso2.carbon.mdm.services.android.bean.EnterpriseStoreCluster;
import org.wso2.carbon.mdm.services.android.bean.EnterpriseStorePackages;
import org.wso2.carbon.mdm.services.android.bean.EnterpriseStorePage;
import org.wso2.carbon.mdm.services.android.bean.EnterpriseTokenUrl;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseStoreCluster;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseStorePackages;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseStorePage;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseTokenUrl;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.EnterpriseServiceException;
import java.io.ByteArrayInputStream;
import java.io.IOException;

@ -16,9 +16,8 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.util;
package org.wso2.carbon.device.mgt.mobile.android.common;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@ -16,12 +16,11 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.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;

@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -16,11 +16,11 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.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",

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;

@ -15,11 +15,10 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.AndroidOperation;
import java.io.Serializable;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean;
package org.wso2.carbon.device.mgt.mobile.android.common.bean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.Device;

@ -15,11 +15,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.AppRestriction;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.AppRestriction;
import java.util.List;

@ -15,11 +15,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.ApplicationInstallation;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.ApplicationInstallation;
import java.util.List;

@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.ApplicationRestriction;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.ApplicationRestriction;
import java.util.List;

@ -15,11 +15,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.ApplicationUninstallation;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.ApplicationUninstallation;
import java.util.List;

@ -15,11 +15,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.ApplicationUpdate;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.ApplicationUpdate;
import java.util.List;

@ -15,11 +15,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.BlacklistApplications;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.BlacklistApplications;
import javax.validation.Valid;
import java.util.List;

@ -15,11 +15,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.Camera;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.Camera;
import java.util.List;

@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -16,11 +16,11 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.DeviceLock;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.DeviceLock;
import java.util.List;

@ -15,11 +15,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.Disenrollment;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.Disenrollment;
import java.util.List;

@ -16,11 +16,11 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.DisplayMessage;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.DisplayMessage;
import java.util.List;

@ -15,11 +15,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.DeviceEncryption;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.DeviceEncryption;
import java.util.List;

@ -16,7 +16,7 @@
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ -15,11 +15,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.FileTransfer;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.FileTransfer;
import java.util.List;

@ -17,11 +17,11 @@
*
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.GlobalProxy;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.GlobalProxy;
import java.util.List;

@ -15,11 +15,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.LockCode;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.LockCode;
import java.util.List;

@ -15,11 +15,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.mdm.services.android.bean.wrapper;
package org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.mdm.services.android.bean.Notification;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.Notification;
import java.util.List;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save