Add new API to perform ent. app installation

feature/appm-store/pbac
lasanthaDLPDS 5 years ago
parent 2757d96c33
commit 4989ac2d0c

@ -175,7 +175,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
} }
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) { if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType()) && !SubscriptionType.DEVICE
.toString().equals(subType)) {
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
deviceTypeName = deviceType.getName(); deviceTypeName = deviceType.getName();
//filter devices by device type //filter devices by device type
@ -334,6 +335,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID); ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
//todo need to check application release status if it is not in installable state send forbidden exception
int applicationReleaseId = applicationReleaseDTO.getId(); int applicationReleaseId = applicationReleaseDTO.getId();
if (!ApplicationType.PUBLIC.toString().equals(applicationDTO.getType())) { if (!ApplicationType.PUBLIC.toString().equals(applicationDTO.getType())) {
String msg = "Application type is not public. Hence you can't perform google ent.install operation on " String msg = "Application type is not public. Hence you can't perform google ent.install operation on "
@ -343,6 +345,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
List<String> categories = getApplicationCategories(applicationDTO.getId());
if (!categories.contains("GooglePlaySyncedApp")) {
String msg = "This is not google play store synced application. Hence can't perform enteprise app "
+ "installation.";
log.error(msg);
throw new BadRequestException(msg);
}
DeviceManagementProviderService deviceManagementProviderService = HelperUtil DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService(); .getDeviceManagementProviderService();
@ -350,9 +360,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<String> subscribers = new ArrayList<>(); List<String> subscribers = new ArrayList<>();
List<Integer> appInstallingDeviceIds; List<Integer> appInstallingDeviceIds;
List<Integer> appReInstallingDeviceIds = new ArrayList<>(); List<Integer> appReInstallingDeviceIds = new ArrayList<>();
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
//todo validate users, groups and roles //todo validate users, groups and roles
if (SubscriptionType.DEVICE.toString().equals(subType)) { if (SubscriptionType.DEVICE.toString().equals(subType)) {
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
for (T param : params) { for (T param : params) {
DeviceIdentifier deviceIdentifier = (DeviceIdentifier) param; DeviceIdentifier deviceIdentifier = (DeviceIdentifier) param;
if (StringUtils.isEmpty(deviceIdentifier.getId()) || StringUtils if (StringUtils.isEmpty(deviceIdentifier.getId()) || StringUtils
@ -361,6 +373,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
+ " device type. Hence ignoring the device identifier. "); + " device type. Hence ignoring the device identifier. ");
continue; continue;
} }
if (!deviceType.getName().equals(deviceIdentifier.getType())) {
log.warn("Found a device identifier which is not matched with the supported device type "
+ "of the application release which has UUID " + applicationUUID + " Application "
+ "supported device type is " + deviceType.getName() + " and the "
+ "identifier of which has a different device type is " + deviceIdentifier.getId());
continue;
}
deviceIdentifiers.add(deviceIdentifier);
devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false)); devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false));
} }
} else if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) { } else if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
@ -397,6 +417,28 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
appInstallingDeviceIds.remove(deviceSubscription.getKey()); appInstallingDeviceIds.remove(deviceSubscription.getKey());
} }
/*If subscription type is not device we need to crete device identifiers object list by referring retrieved
list of devices.*/
if (!SubscriptionType.DEVICE.toString().equalsIgnoreCase(subType)) {
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
String deviceTypeName = deviceType.getName();
//filter devices by device type
devices.removeIf(device -> !deviceTypeName.equals(device.getType()));
devices.forEach(device -> {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(device.getDeviceIdentifier());
deviceIdentifier.setType(device.getType());
deviceIdentifiers.add(deviceIdentifier);
});
}
//Installing the application
ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO();
applicationPolicyDTO.setApplicationDTO(applicationDTO);
applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers);
applicationPolicyDTO.setAction(SubAction.INSTALL.toString());
installEnrollmentApplications(applicationPolicyDTO);
updateSubscriptionsForEntInstall(applicationReleaseId, appInstallingDeviceIds, appReInstallingDeviceIds, updateSubscriptionsForEntInstall(applicationReleaseId, appInstallingDeviceIds, appReInstallingDeviceIds,
subscribers, subType); subscribers, subType);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
@ -569,18 +611,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
entry.getKey(), action); entry.getKey(), action);
activityList.add(activity); activityList.add(activity);
} }
} else if (applicationDTO.getType().equals(ApplicationType.PUBLIC.toString())) {
List<String> categories = getApplicationCategories(applicationDTO.getId());
if (categories.contains("GooglePlaySyncedApp")) {
ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO();
applicationPolicyDTO.setApplicationDTO(applicationDTO);
applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers);
applicationPolicyDTO.setAction(action);
installEnrollmentApplications(applicationPolicyDTO);
} else {
Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action);
activityList.add(activity);
}
} else { } else {
Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action); Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action);
activityList.add(activity); activityList.add(activity);
@ -982,7 +1012,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
String payload = gson.toJson(applicationPolicyDTO); String payload = gson.toJson(applicationPolicyDTO);
StringRequestEntity requestEntity = new StringRequestEntity(payload, MediaType.APPLICATION_JSON StringRequestEntity requestEntity = new StringRequestEntity(payload, MediaType.APPLICATION_JSON
, Constants.ApplicationInstall.ENCODING);; , Constants.ApplicationInstall.ENCODING);
httpClient = new HttpClient(); httpClient = new HttpClient();
request = new PostMethod(requestUrl); request = new PostMethod(requestUrl);
request.addRequestHeader(Constants.ApplicationInstall.AUTHORIZATION request.addRequestHeader(Constants.ApplicationInstall.AUTHORIZATION

@ -185,6 +185,94 @@ public interface SubscriptionManagementAPI {
@QueryParam("timestamp") String timestamp @QueryParam("timestamp") String timestamp
); );
@POST
@Path("/{uuid}/devices/ent-app-install")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Install an application for devices via google enterprise app installing service",
notes = "This will install an application to a given list of devices",
tags = "Subscription Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:subscription:install")
})
}
)
@ApiResponses(
value = {
})
Response performEntAppInstallationOnDevices(
@ApiParam(
name = "UUID",
value = "The application UUID",
required = true
)
@PathParam("uuid") String uuid,
@ApiParam(
name = "installationDetails",
value = "The list of device identifiers",
required = true
)
@Valid List<DeviceIdentifier> deviceIdentifiers,
@ApiParam(
name = "timestamp",
value = "Timestamp of scheduled ent. install operation"
)
@QueryParam("timestamp") String timestamp
);
@POST
@Path("/{uuid}/{subType}/ent-app-install")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Install an application for subscription type via google enterprise install.",
notes = "This will install an application to a given subscription type and this is bulk app installation.",
tags = "Subscription Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:subscription:install")
})
}
)
@ApiResponses(
value = {
})
Response performBulkEntAppInstallation(
@ApiParam(
name = "uuid",
value = "The application release UUID",
required = true
)
@PathParam("uuid") String uuid,
@ApiParam(
name = "subType",
value = "Subscription type of the app installing operation.",
required = true
)
@PathParam("subType") String subType,
@ApiParam(
name = "subscribers",
value = "Subscriber list of the application release.",
required = true
)
@Valid List<String> subscribers,
@ApiParam(
name = "timestamp",
value = "Timestamp of scheduled ent app install operation"
)
@QueryParam("timestamp") String timestamp
);
@GET @GET
@Path("/{uuid}/devices") @Path("/{uuid}/devices")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)

@ -89,13 +89,13 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = "Found invalid payload for installing application which has UUID: " + uuid String msg = "Found invalid payload for installing application which has UUID: " + uuid + ". Hence verify "
+ ". Hence verify the payload"; + "the payload";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) { } catch (ForbiddenException e) {
String msg = "Application release is not in the installable state. Hence you are not permitted to install " String msg = "Application release is not in the installable state. Hence you are not permitted to perform "
+ "the application."; + "the action on the application.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
@ -132,13 +132,13 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = "Found invalid payload for installing application which has UUID: " + uuid String msg = "Found invalid payload for installing application which has UUID: " + uuid + ". Hence verify "
+ ". Hence verify the payload"; + "the payload";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) { } catch (ForbiddenException e) {
String msg = "Application release is not in the installable state. Hence you are not permitted to install " String msg = "Application release is not in the installable state. Hence you are not permitted to perform "
+ "the application."; + "the action on the application.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
@ -149,6 +149,91 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
} }
} }
@Override
@POST
@Path("/{uuid}/devices/ent-app-install")
public Response performEntAppInstallationOnDevices(
@PathParam("uuid") String uuid,
@Valid List<DeviceIdentifier> deviceIdentifiers,
@QueryParam("timestamp") String timestamp) {
try {
if (StringUtils.isEmpty(timestamp)) {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
subscriptionManager
.performEntAppInstall(uuid, deviceIdentifiers, SubscriptionType.DEVICE.toString());
String msg = "Application release which has UUID " + uuid + " is installed to given valid device "
+ "identifiers.";
return Response.status(Response.Status.OK).entity(msg).build();
} else {
return scheduleApplicationOperationTask(uuid, deviceIdentifiers, SubscriptionType.DEVICE,
SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp);
}
} catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUI: " + uuid + " to perform ent app installation "
+ "on subscriber's devices";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found invalid payload when performing ent app installation on application which has UUID: "
+ uuid + ". Hence verify the payload of the request.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "Application release is not in the installable state. Hence you are not permitted to install "
+ "the application.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg =
"Error occurred while performing ent app installation on the application release which has UUID: "
+ uuid + " for devices";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@POST
@Path("/{uuid}/{subType}/ent-app-install")
public Response performBulkEntAppInstallation(
@PathParam("uuid") String uuid,
@PathParam("subType") String subType,
@Valid List<String> subscribers,
@QueryParam("timestamp") String timestamp) {
try {
if (StringUtils.isEmpty(timestamp)) {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
subscriptionManager.performEntAppInstall(uuid, subscribers, subType);
String msg = "Application release which has UUID " + uuid + " is installed to subscriber's valid device"
+ " identifiers.";
return Response.status(Response.Status.OK).entity(msg).build();
} else {
return scheduleApplicationOperationTask(uuid, subscribers,
SubscriptionType.valueOf(subType.toUpperCase()),
SubAction.valueOf(SubAction.INSTALL.toString().toUpperCase()), timestamp);
}
} catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found invalid payload when performing ent app installation on application which has UUID: "
+ uuid + ". Hence verify the payload of the request.";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "Application release is not in the installable state. Hence you are not permitted to install "
+ "the application.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while performing ent app installation on the application release which has "
+ "UUID: " + uuid + " for user devices";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
/** /**
* Schedule the application subscription for the given timestamp * Schedule the application subscription for the given timestamp
* *
@ -183,13 +268,13 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
@Consumes("application/json") @Consumes("application/json")
@Produces("application/json") @Produces("application/json")
@Path("/{uuid}/devices") @Path("/{uuid}/devices")
public Response getAppInstalledDevices(@PathParam("uuid") String uuid, public Response getAppInstalledDevices(
@DefaultValue("0") @PathParam("uuid") String uuid,
@QueryParam("offset") int offset, @DefaultValue("0")
@DefaultValue("5") @QueryParam("offset") int offset,
@QueryParam("limit") int limit, @DefaultValue("5")
@QueryParam("status") String status) { @QueryParam("limit") int limit,
@QueryParam("status") String status) {
try { try {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
@ -228,13 +313,13 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
@Consumes("application/json") @Consumes("application/json")
@Produces("application/json") @Produces("application/json")
@Path("/{uuid}/{subType}") @Path("/{uuid}/{subType}")
public Response getAppInstalledCategories(@PathParam("uuid") String uuid, public Response getAppInstalledCategories(
@PathParam("subType") String subType, @PathParam("uuid") String uuid,
@DefaultValue("0") @PathParam("subType") String subType,
@QueryParam("offset") int offset, @DefaultValue("0")
@DefaultValue("5") @QueryParam("offset") int offset,
@QueryParam("limit") int limit) { @DefaultValue("5")
@QueryParam("limit") int limit) {
try { try {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();

Loading…
Cancel
Save