@ -17,14 +17,15 @@
package cdm.api.android ;
package cdm.api.android ;
import cdm.api.android.util.AndroidAPIUtils ;
import cdm.api.android.util.AndroidAPIUtils ;
import cdm.api.android.util.AndroidConstants ;
import org.apache.commons.logging.Log ;
import org.apache.commons.logging.Log ;
import org.apache.commons.logging.LogFactory ;
import org.apache.commons.logging.LogFactory ;
import org.apache.commons.httpclient.HttpStatus ;
import org.wso2.carbon.context.PrivilegedCarbonContext ;
import org.wso2.carbon.context.PrivilegedCarbonContext ;
import org.wso2.carbon.device.mgt.common.Device ;
import org.wso2.carbon.device.mgt.common.Device ;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier ;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier ;
import org.wso2.carbon.device.mgt.common.DeviceManagementException ;
import org.wso2.carbon.device.mgt.common.DeviceManagementException ;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService ;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService ;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants ;
import javax.ws.rs.* ;
import javax.ws.rs.* ;
import javax.ws.rs.core.Response ;
import javax.ws.rs.core.Response ;
@ -43,12 +44,7 @@ public class Enrollment {
String msg = "" ;
String msg = "" ;
DeviceManagementService dmService ;
DeviceManagementService dmService ;
try {
try {
PrivilegedCarbonContext . startTenantFlow ( ) ;
dmService = AndroidAPIUtils . getDeviceManagementService ( ) ;
PrivilegedCarbonContext ctx = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) ;
ctx . setTenantDomain ( MultitenantConstants . SUPER_TENANT_DOMAIN_NAME ) ;
ctx . setTenantId ( MultitenantConstants . SUPER_TENANT_ID ) ;
dmService = ( DeviceManagementService ) ctx
. getOSGiService ( DeviceManagementService . class , null ) ;
} finally {
} finally {
PrivilegedCarbonContext . endTenantFlow ( ) ;
PrivilegedCarbonContext . endTenantFlow ( ) ;
}
}
@ -59,9 +55,8 @@ public class Enrollment {
status = 1 ;
status = 1 ;
} else {
} else {
status = - 1 ;
status = - 1 ;
msg = "Device Manager service not available" ;
msg = AndroidConstants . Messages . DEVICE_MANAGER_SERVICE_NOT_AVAILABLE ;
}
}
} catch ( DeviceManagementException e ) {
} catch ( DeviceManagementException e ) {
msg = "Error occurred while enrolling the device" ;
msg = "Error occurred while enrolling the device" ;
log . error ( msg , e ) ;
log . error ( msg , e ) ;
@ -70,13 +65,13 @@ public class Enrollment {
switch ( status ) {
switch ( status ) {
case 1 :
case 1 :
if ( result ) {
if ( result ) {
return Response . status ( 201 ) . entity ( "Registration Successful ") . build ( ) ;
return Response . status ( HttpStatus . SC_CREATED ) . entity ( "Device enrollment has succeeded ") . build ( ) ;
}
}
break ;
break ;
case - 1 :
case - 1 :
return Response . status ( 500 ) . entity ( msg ) . build ( ) ;
return Response . status ( HttpStatus . SC_INTERNAL_SERVER_ERROR ) . entity ( msg ) . build ( ) ;
}
}
return Response . status ( 400 ) . entity ( "Registration Failed") . build ( ) ;
return Response . status ( HttpStatus . SC_BAD_REQUEST ) . entity ( "Device enrollment has Failed") . build ( ) ;
}
}
@GET
@GET
@ -87,12 +82,7 @@ public class Enrollment {
String msg = "" ;
String msg = "" ;
DeviceManagementService dmService ;
DeviceManagementService dmService ;
try {
try {
PrivilegedCarbonContext . startTenantFlow ( ) ;
dmService = AndroidAPIUtils . getDeviceManagementService ( ) ;
PrivilegedCarbonContext ctx = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) ;
ctx . setTenantDomain ( MultitenantConstants . SUPER_TENANT_DOMAIN_NAME ) ;
ctx . setTenantId ( MultitenantConstants . SUPER_TENANT_ID ) ;
dmService = ( DeviceManagementService ) ctx
. getOSGiService ( DeviceManagementService . class , null ) ;
} finally {
} finally {
PrivilegedCarbonContext . endTenantFlow ( ) ;
PrivilegedCarbonContext . endTenantFlow ( ) ;
}
}
@ -103,7 +93,7 @@ public class Enrollment {
status = 1 ;
status = 1 ;
} else {
} else {
status = - 1 ;
status = - 1 ;
msg = "Device Manager service not available" ;
msg = AndroidConstants . Messages . DEVICE_MANAGER_SERVICE_NOT_AVAILABLE ;
}
}
} catch ( DeviceManagementException e ) {
} catch ( DeviceManagementException e ) {
msg = "Error occurred while checking enrollment of the device" ;
msg = "Error occurred while checking enrollment of the device" ;
@ -113,13 +103,13 @@ public class Enrollment {
switch ( status ) {
switch ( status ) {
case 1 :
case 1 :
if ( result ) {
if ( result ) {
return Response . status ( 200 ) . entity ( result ) . build ( ) ;
return Response . status ( HttpStatus . SC_OK ) . entity ( result ) . build ( ) ;
}
}
break ;
break ;
case - 1 :
case - 1 :
return Response . status ( 500 ) . entity ( msg ) . build ( ) ;
return Response . status ( HttpStatus . SC_INTERNAL_SERVER_ERROR ) . entity ( msg ) . build ( ) ;
}
}
return Response . status ( 404 ) . entity ( result ) . build ( ) ;
return Response . status ( HttpStatus . SC_NOT_FOUND ) . entity ( result ) . build ( ) ;
}
}
@PUT
@PUT
@ -130,12 +120,7 @@ public class Enrollment {
String msg = "" ;
String msg = "" ;
DeviceManagementService dmService ;
DeviceManagementService dmService ;
try {
try {
PrivilegedCarbonContext . startTenantFlow ( ) ;
dmService = AndroidAPIUtils . getDeviceManagementService ( ) ;
PrivilegedCarbonContext ctx = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) ;
ctx . setTenantDomain ( MultitenantConstants . SUPER_TENANT_DOMAIN_NAME ) ;
ctx . setTenantId ( MultitenantConstants . SUPER_TENANT_ID ) ;
dmService = ( DeviceManagementService ) ctx
. getOSGiService ( DeviceManagementService . class , null ) ;
} finally {
} finally {
PrivilegedCarbonContext . endTenantFlow ( ) ;
PrivilegedCarbonContext . endTenantFlow ( ) ;
}
}
@ -146,7 +131,7 @@ public class Enrollment {
status = 1 ;
status = 1 ;
} else {
} else {
status = - 1 ;
status = - 1 ;
msg = "Device Manager service not available" ;
msg = AndroidConstants . Messages . DEVICE_MANAGER_SERVICE_NOT_AVAILABLE ;
}
}
} catch ( DeviceManagementException e ) {
} catch ( DeviceManagementException e ) {
msg = "Error occurred while modifying enrollment of the device" ;
msg = "Error occurred while modifying enrollment of the device" ;
@ -156,13 +141,13 @@ public class Enrollment {
switch ( status ) {
switch ( status ) {
case 1 :
case 1 :
if ( result ) {
if ( result ) {
return Response . status ( 200 ) . entity ( "Device information modified") . build ( ) ;
return Response . status ( HttpStatus . SC_OK ) . entity ( "Enrollment information has modified") . build ( ) ;
}
}
break ;
break ;
case - 1 :
case - 1 :
return Response . status ( 500 ) . entity ( msg ) . build ( ) ;
return Response . status ( HttpStatus . SC_INTERNAL_SERVER_ERROR ) . entity ( msg ) . build ( ) ;
}
}
return Response . status ( 400 ) . entity ( "Update enrollment failed") . build ( ) ;
return Response . status ( HttpStatus . SC_NOT_MODIFIED ) . entity ( "Update enrollment has failed") . build ( ) ;
}
}
@DELETE
@DELETE
@ -173,12 +158,7 @@ public class Enrollment {
String msg = "" ;
String msg = "" ;
DeviceManagementService dmService ;
DeviceManagementService dmService ;
try {
try {
PrivilegedCarbonContext . startTenantFlow ( ) ;
dmService = AndroidAPIUtils . getDeviceManagementService ( ) ;
PrivilegedCarbonContext ctx = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) ;
ctx . setTenantDomain ( MultitenantConstants . SUPER_TENANT_DOMAIN_NAME ) ;
ctx . setTenantId ( MultitenantConstants . SUPER_TENANT_ID ) ;
dmService = ( DeviceManagementService ) ctx
. getOSGiService ( DeviceManagementService . class , null ) ;
} finally {
} finally {
PrivilegedCarbonContext . endTenantFlow ( ) ;
PrivilegedCarbonContext . endTenantFlow ( ) ;
}
}
@ -189,7 +169,7 @@ public class Enrollment {
status = 1 ;
status = 1 ;
} else {
} else {
status = - 1 ;
status = - 1 ;
msg = "Device Manager service not available" ;
msg = AndroidConstants . Messages . DEVICE_MANAGER_SERVICE_NOT_AVAILABLE ;
}
}
} catch ( DeviceManagementException e ) {
} catch ( DeviceManagementException e ) {
msg = "Error occurred while disenrolling the device" ;
msg = "Error occurred while disenrolling the device" ;
@ -199,12 +179,12 @@ public class Enrollment {
switch ( status ) {
switch ( status ) {
case 1 :
case 1 :
if ( result ) {
if ( result ) {
return Response . status ( 200 ) . entity ( result ) . build ( ) ;
return Response . status ( HttpStatus . SC_OK ) . entity ( result ) . build ( ) ;
}
}
break ;
break ;
case - 1 :
case - 1 :
return Response . status ( 500 ) . entity ( msg ) . build ( ) ;
return Response . status ( HttpStatus . SC_INTERNAL_SERVER_ERROR ) . entity ( msg ) . build ( ) ;
}
}
return Response . status ( 404 ) . entity ( "Device not found" ) . build ( ) ;
return Response . status ( HttpStatus . SC_NOT_FOUND ) . entity ( "Device not found" ) . build ( ) ;
}
}
}
}