forked from community/device-mgt-core
commit
78f8507bf3
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.device.application.mgt.api.services;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.application.mgt.common.Application;
|
||||
import org.wso2.carbon.device.application.mgt.common.InstallationDetails;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* API to handle subscription management related tasks.
|
||||
*/
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
version = "1.0.0",
|
||||
title = "Subscription Management Service",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = "name", value = "SubscriptionManagementService"),
|
||||
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/subscription"),
|
||||
})
|
||||
}
|
||||
),
|
||||
tags = {
|
||||
@Tag(name = "Subscription_management, device_management", description = "Subscription Management " +
|
||||
"related "
|
||||
+ "APIs")
|
||||
}
|
||||
)
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@org.wso2.carbon.apimgt.annotations.api.Scope(
|
||||
name = "Install an Application",
|
||||
description = "Install an application",
|
||||
key = "perm:subscription:install",
|
||||
permissions = {"/device-mgt/subscription/install"}
|
||||
),
|
||||
@org.wso2.carbon.apimgt.annotations.api.Scope(
|
||||
name = "Install an Application",
|
||||
description = "Install an application",
|
||||
key = "perm:application-mgt:login",
|
||||
permissions = {"/device-mgt/application-mgt/login"}
|
||||
)
|
||||
}
|
||||
)
|
||||
@Path("/subscription")
|
||||
@Api(value = "Subscription Management", description = "This API carries all subscription management related " +
|
||||
"operations " +
|
||||
"such as install application to device, uninstall application from device, etc.")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public interface SubscriptionManagementAPI {
|
||||
|
||||
String SCOPE = "scope";
|
||||
|
||||
@POST
|
||||
@Path("/install-application")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Install an application",
|
||||
notes = "This will install an application to a given list of devices/users/roles",
|
||||
tags = "Subscription Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = SCOPE, value = "perm:subscription:install")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully installed the application.",
|
||||
response = Application.class),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n " +
|
||||
"Empty body because the application is already installed."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error occurred while installing the application.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response installApplication(
|
||||
@ApiParam(
|
||||
name = "installationDetails",
|
||||
value = "The application ID and list the devices/users/roles",
|
||||
required = true)
|
||||
@Valid InstallationDetails installationDetails);
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.device.application.mgt.api.services.impl;
|
||||
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.application.mgt.api.APIUtil;
|
||||
import org.wso2.carbon.device.application.mgt.api.services.SubscriptionManagementAPI;
|
||||
import org.wso2.carbon.device.application.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.application.mgt.common.InstallationDetails;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of Subscription Management related APIs.
|
||||
*/
|
||||
@Produces({"application/json"})
|
||||
@Path("/subscription")
|
||||
public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
|
||||
|
||||
private static Log log = LogFactory.getLog(SubscriptionManagementAPIImpl.class);
|
||||
|
||||
@Override
|
||||
public Response installApplication(@ApiParam(name = "installationDetails", value = "The application ID and list" +
|
||||
" the devices/users/roles", required = true) @Valid InstallationDetails installationDetails) {
|
||||
Object response;
|
||||
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
|
||||
try {
|
||||
String applicationUUTD = installationDetails.getApplicationUUID();
|
||||
if (!installationDetails.getDeviceIdentifiers().isEmpty()) {
|
||||
List<DeviceIdentifier> deviceList = installationDetails.getDeviceIdentifiers();
|
||||
response = subscriptionManager.installApplicationForDevices(applicationUUTD, deviceList);
|
||||
} else if (!installationDetails.getUserNameList().isEmpty()) {
|
||||
List<String> userList = installationDetails.getUserNameList();
|
||||
response = subscriptionManager.installApplicationForUsers(applicationUUTD, userList);
|
||||
} else if (!installationDetails.getRoleNameList().isEmpty()) {
|
||||
List<String> roleList = installationDetails.getRoleNameList();
|
||||
response = subscriptionManager.installApplicationForRoles(applicationUUTD, roleList);
|
||||
} else {
|
||||
response = "Missing request data!";
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(response).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(response).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while creating the application";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.application.mgt.common;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
|
||||
@ApiModel(value = "DeviceIdentifier", description = "This contains device details that is used to identify a device " +
|
||||
"uniquely.")
|
||||
public class DeviceIdentifier {
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "id",
|
||||
value = "Identity of the device.",
|
||||
required = true,
|
||||
example = "123456")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "type",
|
||||
value = "Type of the device.",
|
||||
required = true,
|
||||
example = "android")
|
||||
private String type;
|
||||
|
||||
public DeviceIdentifier() {}
|
||||
|
||||
public DeviceIdentifier(String id, String type) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type.trim();
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "deviceId {" +
|
||||
"id='" + id + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.device.application.mgt.common;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class InstallationDetails {
|
||||
@ApiModelProperty(
|
||||
name = "applicationUUID",
|
||||
value = "Application ID",
|
||||
required = true)
|
||||
private String applicationUUID;
|
||||
@ApiModelProperty(
|
||||
name = "userNameList",
|
||||
value = "List of user names.",
|
||||
required = true)
|
||||
private List<String> userNameList;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "roleNameList",
|
||||
value = "List of role names.",
|
||||
required = true)
|
||||
private List<String> roleNameList;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "deviceIdentifiers",
|
||||
value = "List of device identifiers.",
|
||||
required = true,
|
||||
dataType = "List[org.wso2.carbon.device.mgt.common.DeviceIdentifier]")
|
||||
private List<DeviceIdentifier> deviceIdentifiers;
|
||||
|
||||
public String getApplicationUUID() {
|
||||
return applicationUUID;
|
||||
}
|
||||
|
||||
public void setApplicationUUID(String applicationUUID) {
|
||||
this.applicationUUID = applicationUUID;
|
||||
}
|
||||
|
||||
public List<String> getUserNameList() {
|
||||
return userNameList;
|
||||
}
|
||||
|
||||
public void setUserNameList(List<String> userNameList) {
|
||||
this.userNameList = userNameList;
|
||||
}
|
||||
|
||||
public List<String> getRoleNameList() {
|
||||
return roleNameList;
|
||||
}
|
||||
|
||||
public void setRoleNameList(List<String> roleNameList) {
|
||||
this.roleNameList = roleNameList;
|
||||
}
|
||||
|
||||
public List<DeviceIdentifier> getDeviceIdentifiers() {
|
||||
return deviceIdentifiers;
|
||||
}
|
||||
|
||||
public void setDeviceIdentifiers(List<DeviceIdentifier> deviceIdentifiers) {
|
||||
this.deviceIdentifiers = deviceIdentifiers;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue