mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixing merge conflicts
This commit is contained in:
commit
d32cd96a74
@ -33,7 +33,7 @@
|
||||
<Permission>
|
||||
<name>get certificate in the database</name>
|
||||
<path>/device-mgt/emm-admin/certificate/GetSignCSR</path>
|
||||
<url>/certificates/signcsr</url>
|
||||
<url>/certificates/scep/signcsr</url>
|
||||
<method>POST</method>
|
||||
<scope>emm_admin</scope>
|
||||
</Permission>
|
||||
|
||||
@ -29,38 +29,30 @@
|
||||
-->
|
||||
<PermissionConfiguration>
|
||||
<APIVersion></APIVersion>
|
||||
<!-- Device related APIs -->
|
||||
<Permission>
|
||||
<name>get certificate in the database</name>
|
||||
<path>/device-mgt/emm-admin/certificate/GetSignCSR</path>
|
||||
<url>/certificates/sign-csr</url>
|
||||
<method>POST</method>
|
||||
<scope>emm_admin</scope>
|
||||
</Permission>
|
||||
|
||||
<!-- CertificateManagementAdminService related APIs -->
|
||||
<Permission>
|
||||
<name>Save certificate</name>
|
||||
<path>/device-mgt/admin/certificate/Save</path>
|
||||
<url>/certificates</url>
|
||||
<url>/admin/certificates</url>
|
||||
<method>POST</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Get certificate</name>
|
||||
<path>/device-mgt/admin/certificate/Get</path>
|
||||
<url>/certificates/*</url>
|
||||
<url>/admin/certificates/*</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Get all certificates</name>
|
||||
<path>/device-mgt/admin/certificate/GetAll</path>
|
||||
<url>/certificates</url>
|
||||
<url>/admin/certificates</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Remove certificate</name>
|
||||
<path>/device-mgt/admin/certificate/Remove</path>
|
||||
<url>/certificates/*</url>
|
||||
<url>/admin/certificates/*</url>
|
||||
<method>DELETE</method>
|
||||
</Permission>
|
||||
<!-- End of CertificateManagementAdminService related APIs -->
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "Policy List")
|
||||
public class PolicyList extends BasePaginatedResult {
|
||||
|
||||
private List<Policy> policies;
|
||||
|
||||
@ApiModelProperty(value = "List of policies returned")
|
||||
@JsonProperty("policies")
|
||||
public List<Policy> getList() {
|
||||
return policies;
|
||||
}
|
||||
|
||||
public void setList(List<Policy> policies) {
|
||||
this.policies = policies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{\n");
|
||||
sb.append(" count: ").append(getCount()).append(",\n");
|
||||
sb.append(" next: ").append(getNext()).append(",\n");
|
||||
sb.append(" previous: ").append(getPrevious()).append(",\n");
|
||||
sb.append(" roles: [").append(policies).append("\n");
|
||||
sb.append("]}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@ -43,7 +43,6 @@ public class RoleList extends BasePaginatedResult {
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{\n");
|
||||
|
||||
sb.append(" count: ").append(getCount()).append(",\n");
|
||||
sb.append(" next: ").append(getNext()).append(",\n");
|
||||
sb.append(" previous: ").append(getPrevious()).append(",\n");
|
||||
|
||||
@ -254,15 +254,15 @@ public interface DeviceManagementService {
|
||||
})
|
||||
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
|
||||
Response getDevicesInfo(
|
||||
@ApiParam(
|
||||
name = "deviceIds",
|
||||
value = "List of device identifiers",
|
||||
required = true) List<DeviceIdentifier> deviceIds,
|
||||
@ApiParam(
|
||||
name = "If-Modified-Since",
|
||||
value = "Timestamp of the last modified date",
|
||||
required = false)
|
||||
@HeaderParam("If-Modified-Since") String timestamp);
|
||||
@HeaderParam("If-Modified-Since") String timestamp,
|
||||
@ApiParam(
|
||||
name = "deviceIds",
|
||||
value = "List of device identifiers",
|
||||
required = true) List<DeviceIdentifier> deviceIds);
|
||||
|
||||
|
||||
@GET
|
||||
@ -610,7 +610,7 @@ public interface DeviceManagementService {
|
||||
code = 500,
|
||||
message = "Internal Server ErrorResponse. \n " +
|
||||
"Server error occurred while retrieving installed application list of the device.",
|
||||
response = ErrorResponse.class)
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
@Permission(scope = "operation-view", permissions = {
|
||||
"/permission/admin/device-mgt/admin/devices/view",
|
||||
|
||||
@ -137,10 +137,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/get-info")
|
||||
@Override
|
||||
public Response getDevicesInfo(
|
||||
List<DeviceIdentifier> deviceIds,
|
||||
@HeaderParam("If-Modified-Since") String timestamp) {
|
||||
@HeaderParam("If-Modified-Since") String timestamp,
|
||||
List<DeviceIdentifier> deviceIds) {
|
||||
DeviceInformationManager informationManager;
|
||||
List<DeviceInfo> deviceInfo;
|
||||
try {
|
||||
@ -276,10 +277,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
}
|
||||
if (devices == null) {
|
||||
if (devices == null || devices.size() == 0) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " +
|
||||
"the provided type and id").build();
|
||||
"the provided search filters").build();
|
||||
}
|
||||
|
||||
return Response.status(Response.Status.OK).entity(devices).build();
|
||||
}
|
||||
|
||||
@ -330,8 +332,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||
operations = dms.getOperations(new DeviceIdentifier(id, type));
|
||||
if (operations == null) {
|
||||
Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " +
|
||||
"the provided type and id");
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " +
|
||||
"the provided type and id").build();
|
||||
}
|
||||
} catch (OperationManagementException e) {
|
||||
String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " +
|
||||
|
||||
@ -27,9 +27,10 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyList;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.PolicyManagementService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.PolicyFilteringUtil;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
@ -120,19 +121,27 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
@QueryParam("limit") int limit) {
|
||||
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
|
||||
List<Policy> policies;
|
||||
List<Policy> filteredPolicies;
|
||||
PolicyList targetPolicies = new PolicyList();
|
||||
try {
|
||||
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
|
||||
policies = policyAdministratorPoint.getPolicies();
|
||||
if (policies == null || policies.size() == 0) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("No policies found.").build();
|
||||
}
|
||||
targetPolicies.setCount(policies.size());
|
||||
filteredPolicies = FilteringUtil.getFilteredList(policies, offset, limit);
|
||||
if (filteredPolicies.size() == 0) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("No policies found.").build();
|
||||
}
|
||||
targetPolicies.setList(filteredPolicies);
|
||||
} catch (PolicyManagementException e) {
|
||||
String msg = "ErrorResponse occurred while retrieving all available policies";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(PolicyFilteringUtil.getPolicies(policies, offset, limit))
|
||||
.build();
|
||||
|
||||
return Response.status(Response.Status.OK).entity(targetPolicies).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
|
||||
@ -25,6 +25,7 @@ import org.wso2.carbon.base.MultitenantConstants;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.RoleManagementService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleWrapper;
|
||||
@ -57,14 +58,17 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
|
||||
List<String> filteredRoles;
|
||||
RoleList targetRoles;
|
||||
RoleList targetRoles = new RoleList();
|
||||
try {
|
||||
filteredRoles = getRolesFromUserStore();
|
||||
if (filteredRoles == null) {
|
||||
if (filteredRoles == null || filteredRoles.size() == 0) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("No roles found.").build();
|
||||
}
|
||||
targetRoles = new RoleList();
|
||||
targetRoles.setCount(filteredRoles.size());
|
||||
filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(), offset, limit);
|
||||
if (filteredRoles.size() == 0) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("No roles found.").build();
|
||||
}
|
||||
targetRoles.setList(filteredRoles);
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "Error occurred while retrieving roles from the underlying user stores";
|
||||
@ -181,6 +185,10 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
||||
@POST
|
||||
@Override
|
||||
public Response addRole(RoleWrapper roleWrapper) {
|
||||
if (roleWrapper == null) {
|
||||
log.error("Request body is incorrect or empty");
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
try {
|
||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||
if (log.isDebugEnabled()) {
|
||||
@ -210,6 +218,9 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
||||
@Path("/{roleName}")
|
||||
@Override
|
||||
public Response updateRole(@PathParam("roleName") String roleName, RoleWrapper roleWrapper) {
|
||||
if (roleWrapper == null) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity("Request body is incorrect or empty").build();
|
||||
}
|
||||
String newRoleName = roleWrapper.getRoleName();
|
||||
try {
|
||||
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||
@ -273,10 +284,13 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
||||
"successfully been deleted").build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@PUT
|
||||
@Path("/{roleName}/users")
|
||||
@Override
|
||||
public Response updateUsersOfRole(@PathParam("roleName") String roleName, List<String> users) {
|
||||
if (users == null || users.size() == 0) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity("No users are found in the request").build();
|
||||
}
|
||||
try {
|
||||
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
||||
if (log.isDebugEnabled()) {
|
||||
|
||||
@ -25,9 +25,11 @@ import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnauthorizedAccessException;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
@ -54,24 +56,31 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
||||
int currentTenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
if (MultitenantConstants.SUPER_TENANT_ID != currentTenantId) {
|
||||
throw new UnauthorizedAccessException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(401l).setMessage(
|
||||
"Current logged in user is not authorized to perform this operation").build());
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(401l).setMessage(
|
||||
"Current logged in user is not authorized to perform this operation").build());
|
||||
}
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(DeviceMgtAPIUtils.getTenantId(tenantDomain));
|
||||
|
||||
List<Device> devices = DeviceMgtAPIUtils.getDeviceManagementService().
|
||||
getDevicesByNameAndType(name, type, offset, limit);
|
||||
if (devices == null) {
|
||||
getDevicesByNameAndType(name, type, offset, limit);
|
||||
if (devices == null || devices.size() == 0) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("No device, which carries the name '" +
|
||||
name + "', is currently enrolled in the system").build();
|
||||
name + "', is currently enrolled in the system").build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(devices).build();
|
||||
|
||||
// setting up paginated result
|
||||
DeviceList deviceList = new DeviceList();
|
||||
deviceList.setList(devices);
|
||||
deviceList.setCount(devices.size());
|
||||
|
||||
return Response.status(Response.Status.OK).entity(deviceList).build();
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while fetching the devices that carry the name '" + name + "'";
|
||||
String msg = "Error occurred at server side while fetching device list.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
throw new UnexpectedServerErrorException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
|
||||
@ -18,21 +18,20 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.jaxrs.service.impl.util;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is used instead of filtering from cache.
|
||||
* Todo : need to implement proper pagination support on retrieving policies.
|
||||
*/
|
||||
public class PolicyFilteringUtil {
|
||||
public class FilteringUtil {
|
||||
|
||||
/**
|
||||
* This is used to filter from the cached policies.
|
||||
*/
|
||||
public static List<Policy> getPolicies(List<Policy> sourceList, int offset, int limit) {
|
||||
public static <T> List<T> getFilteredList(List<T> sourceList, int offset, int limit) {
|
||||
if(sourceList == null || sourceList.size() < offset){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@ -252,12 +252,13 @@ public class DeviceMgtAPIUtils {
|
||||
RealmService realmService =
|
||||
(RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(RealmService.class, null);
|
||||
if (realmService == null) {
|
||||
throw new IllegalStateException("");
|
||||
throw new IllegalStateException("Realm service has not been initialized.");
|
||||
}
|
||||
try {
|
||||
return realmService.getTenantManager().getTenantId(tenantDomain);
|
||||
} catch (UserStoreException e) {
|
||||
throw new DeviceManagementException("");
|
||||
throw new DeviceManagementException("Error occured while trying to " +
|
||||
"obtain tenant id of currently logged in user");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,104 +30,7 @@
|
||||
<PermissionConfiguration>
|
||||
<APIVersion></APIVersion>
|
||||
|
||||
<!-- Activity related APIs -->
|
||||
<Permission>
|
||||
<name>Fetch Activity related details</name>
|
||||
<path>/device-mgt/admin/activities/view</path>
|
||||
<url>/activities/*</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Fetch Activity related details</name>
|
||||
<path>/device-mgt/admin/activities/view</path>
|
||||
<url>/activities</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<!-- Activity related APIs -->
|
||||
<!-- Device related APIs -->
|
||||
<Permission>
|
||||
<name>List devices</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/devices</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>List device types</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/devices/types</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>List device types</name>
|
||||
<path>/device-mgt/user/devices/list</path>
|
||||
<url>/devices/types</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>Add policy</name>
|
||||
<path>/device-mgt/admin/policies/add</path>
|
||||
<url>/devices/types</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>Add User policy</name>
|
||||
<path>/device-mgt/user/policies/add</path>
|
||||
<url>/devices/types</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>Edit policy</name>
|
||||
<path>/device-mgt/admin/policies/update</path>
|
||||
<url>/devices/types</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>Edit User policy</name>
|
||||
<path>/device-mgt/user/policies/update</path>
|
||||
<url>/devices/types</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>View device</name>
|
||||
<path>/device-mgt/admin/devices/view</path>
|
||||
<url>/devices/view</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>View user device</name>
|
||||
<path>/device-mgt/user/devices/view</path>
|
||||
<url>/devices/view</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>Modify user device</name>
|
||||
<path>/device-mgt/user/devices/update</path>
|
||||
<url>/devices/type/*/id/*</url>
|
||||
<method>PUT</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>Remove user device</name>
|
||||
<path>/device-mgt/user/devices/remove</path>
|
||||
<url>/devices/type/*/id/*</url>
|
||||
<method>DELETE</method>
|
||||
</Permission>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!--Permission Tree Name-->
|
||||
<Permission>
|
||||
<name>Device Management</name>
|
||||
<path>/device-mgt</path>
|
||||
@ -239,51 +142,90 @@
|
||||
<url>/</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<!--End of Permission Tree-->
|
||||
|
||||
|
||||
|
||||
<!--<Permission>-->
|
||||
<!--<name>Get device</name>-->
|
||||
<!--<path>/device-mgt/devices/view</path>-->
|
||||
<!--<url>/devices/*/*</url>-->
|
||||
<!--<method>GET</method>-->
|
||||
<!--<scope>emm_admin,emm_user</scope>-->
|
||||
<!--</Permission>-->
|
||||
|
||||
<!-- Activity related APIs -->
|
||||
<Permission>
|
||||
<name>View device</name>
|
||||
<path>/device-mgt/admin/devices/view</path>
|
||||
<url>/devices/user/*/*</url>
|
||||
<name>Fetch Activity related details</name>
|
||||
<path>/device-mgt/admin/activities/view</path>
|
||||
<url>/activities/*</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>Devices Count All</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/devices/count</url>
|
||||
<name>Fetch Activity related details</name>
|
||||
<path>/device-mgt/admin/activities/view</path>
|
||||
<url>/activities</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>Device Count</name>
|
||||
<path>/device-mgt/user/devices/list</path>
|
||||
<url>/devices/user/*/count</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<!-- Activity related APIs -->
|
||||
<!-- Device related APIs -->
|
||||
<Permission>
|
||||
<name>List devices</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/devices/name/*/*</url>
|
||||
<url>/devices</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Retrieve device information</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/devices/*/*/info</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Get device</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/devices/*/*</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Get device location</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/devices/*/*/location</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>devices location</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/devices/locations</url>
|
||||
<method>POST</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Get devices feature</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/devices/*/*/features</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>Search devices</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/devices/search-devices</url>
|
||||
<method>POST</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>list device application</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/devices/*/*/applications</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>list device operation</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/devices/*/*/operations</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>list device effective-policy</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/devices/*/*/effective-policy</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<Permission>
|
||||
<name>list devices</name>
|
||||
<path>/device-mgt/admin/devices/list</path>
|
||||
<url>/admin/devices</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>List All Own Devices</name>
|
||||
<path>/device-mgt/user/devices/list</path>
|
||||
<url>/devices/user/*</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<!-- End of Device related APIs -->
|
||||
|
||||
<!-- Notification related APIs -->
|
||||
@ -394,6 +336,20 @@
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>View device</name>
|
||||
<path>/device-mgt/admin/devices/view</path>
|
||||
<url>/devices/*/*/operations</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>View device</name>
|
||||
<path>/device-mgt/user/devices/view</path>
|
||||
<url>/devices/*/*/operations</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<!--<Permission>-->
|
||||
<!--<name>Get Applications For Device Type</name>-->
|
||||
<!--<path>/device-mgt/operations/application/view</path>-->
|
||||
@ -404,34 +360,61 @@
|
||||
<!-- End of Operations related APIs -->
|
||||
|
||||
<!-- Feature related APIs -->
|
||||
<!--<Permission>-->
|
||||
<!--<name>List policies</name>-->
|
||||
<!--<path>/device-mgt/admin/policies/list</path>-->
|
||||
<!--<url>/features/*</url>-->
|
||||
<!--<method>GET</method>-->
|
||||
<!--</Permission>-->
|
||||
|
||||
<!--<Permission>-->
|
||||
<!--<name>View device</name>-->
|
||||
<!--<path>/device-mgt/admin/devices/view</path>-->
|
||||
<!--<url>/features/*</url>-->
|
||||
<!--<method>GET</method>-->
|
||||
<!--</Permission>-->
|
||||
|
||||
<!--<Permission>-->
|
||||
<!--<name>View device</name>-->
|
||||
<!--<path>/device-mgt/user/devices/view</path>-->
|
||||
<!--<url>/features/*</url>-->
|
||||
<!--<method>GET</method>-->
|
||||
<!--</Permission>-->
|
||||
|
||||
<!--<Permission>-->
|
||||
<!--<name>View device</name>-->
|
||||
<!--<path>/device-mgt/user/devices/view</path>-->
|
||||
<!--<url>/features</url>-->
|
||||
<!--<method>GET</method> -->
|
||||
<!--</Permission>-->
|
||||
<Permission>
|
||||
<name>List policies</name>
|
||||
<path>/device-mgt/admin/policies/list</path>
|
||||
<url>/features/*</url>
|
||||
<url>/devices/*/*/features</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>View device</name>
|
||||
<path>/device-mgt/admin/devices/view</path>
|
||||
<url>/features/*</url>
|
||||
<url>/devices/*/*/features</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>View device</name>
|
||||
<path>/device-mgt/user/devices/view</path>
|
||||
<url>/features/*</url>
|
||||
<url>/devices/*/*/features</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>View device</name>
|
||||
<path>/device-mgt/user/devices/view</path>
|
||||
<url>/features</url>
|
||||
<url>/devices/*/*/features</url>
|
||||
<method>GET</method>
|
||||
|
||||
</Permission>
|
||||
|
||||
<!-- End of Feature related APIs -->
|
||||
|
||||
<!-- Role related APIs -->
|
||||
@ -466,7 +449,7 @@
|
||||
<Permission>
|
||||
<name>List roles</name>
|
||||
<path>/device-mgt/admin/roles/list</path>
|
||||
<url>/roles/permissions</url>
|
||||
<url>/roles/*/permissions</url>
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
|
||||
@ -487,22 +470,14 @@
|
||||
<Permission>
|
||||
<name>Update role</name>
|
||||
<path>/device-mgt/admin/roles/update</path>
|
||||
<url>/roles</url>
|
||||
<url>/roles/*</url>
|
||||
<method>PUT</method>
|
||||
</Permission>
|
||||
|
||||
<!--<Permission>-->
|
||||
<!--<name>Update a specific role</name>-->
|
||||
<!--<path>/device-mgt/roles/update</path>-->
|
||||
<!--<url>/roles/*</url>-->
|
||||
<!--<method>PUT</method>-->
|
||||
<!---->
|
||||
<!--</Permission>-->
|
||||
|
||||
<Permission>
|
||||
<name>Update role</name>
|
||||
<path>/device-mgt/admin/roles/update</path>
|
||||
<url>/roles/users</url>
|
||||
<url>/roles/*/users</url>
|
||||
<method>PUT</method>
|
||||
</Permission>
|
||||
|
||||
@ -516,7 +491,7 @@
|
||||
<Permission>
|
||||
<name>Remove role</name>
|
||||
<path>/device-mgt/admin/roles/remove</path>
|
||||
<url>/roles</url>
|
||||
<url>/roles/*</url>
|
||||
<method>DELETE</method>
|
||||
</Permission>
|
||||
|
||||
@ -665,9 +640,9 @@
|
||||
</Permission>
|
||||
|
||||
<Permission>
|
||||
<name>Device Information</name>
|
||||
<name>Get additional information of devices</name>
|
||||
<path>/device-mgt/admin/information/list</path>
|
||||
<url>/information/list</url>
|
||||
<url>/devices/get-info</url>
|
||||
<method>POST</method>
|
||||
</Permission>
|
||||
|
||||
@ -1000,5 +975,4 @@
|
||||
<method>GET</method>
|
||||
</Permission>
|
||||
<!-- End of Dashboard related APIs -->
|
||||
|
||||
</PermissionConfiguration>
|
||||
|
||||
@ -259,7 +259,8 @@ public interface DeviceDAO {
|
||||
* @return returns list of devices.
|
||||
* @throws DeviceManagementDAOException
|
||||
*/
|
||||
List<Device> getDevicesByNameAndType(String deviceName, String type, int tenantId, int offset, int limit) throws DeviceManagementDAOException;
|
||||
List<Device> getDevicesByNameAndType(String deviceName, String type, int tenantId, int offset, int limit)
|
||||
throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to retrieve devices of a given device name as a paginated result.
|
||||
|
||||
@ -619,71 +619,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
||||
return deviceCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of devices that matches with the given device name.
|
||||
*
|
||||
* @param deviceName Name of the device.
|
||||
* @param tenantId Id of the current tenant
|
||||
* @return device list
|
||||
* @throws DeviceManagementDAOException
|
||||
*/
|
||||
@Override
|
||||
public List<Device> getDevicesByNameAndType(String deviceName, String type, int tenantId, int offset, int limit)
|
||||
throws DeviceManagementDAOException {
|
||||
|
||||
String filteringString = "";
|
||||
if (deviceName != null && !deviceName.isEmpty()) {
|
||||
filteringString = filteringString + " AND d.NAME LIKE ?";
|
||||
}
|
||||
|
||||
if (type != null && !type.isEmpty()) {
|
||||
filteringString = filteringString + " AND t.NAME = ?";
|
||||
}
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
List<Device> devices = new ArrayList<>();
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
||||
"d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
||||
") d1 WHERE d1.ID = e.DEVICE_ID LIMIT ?, ?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
|
||||
int i = 1;
|
||||
|
||||
if (deviceName != null && !deviceName.isEmpty()) {
|
||||
stmt.setString(++i, deviceName + "%");
|
||||
}
|
||||
|
||||
if (type != null && !type.isEmpty()) {
|
||||
stmt.setString(++i, type);
|
||||
}
|
||||
|
||||
stmt.setInt(++i, offset);
|
||||
stmt.setInt(++i, limit);
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
||||
devices.add(device);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches " +
|
||||
"'" + deviceName + "'", e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addEnrollment(Device device, int tenantId) throws DeviceManagementDAOException {
|
||||
Connection conn;
|
||||
|
||||
@ -303,6 +303,71 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
||||
return devices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of devices that matches with the given device name and (or) device type.
|
||||
*
|
||||
* @param deviceName Name of the device.
|
||||
* @param tenantId Id of the current tenant
|
||||
* @return device list
|
||||
* @throws DeviceManagementDAOException
|
||||
*/
|
||||
@Override
|
||||
public List<Device> getDevicesByNameAndType(String deviceName, String type, int tenantId, int offset, int limit)
|
||||
throws DeviceManagementDAOException {
|
||||
|
||||
String filteringString = "";
|
||||
if (deviceName != null && !deviceName.isEmpty()) {
|
||||
filteringString = filteringString + " AND d.NAME LIKE ?";
|
||||
}
|
||||
|
||||
if (type != null && !type.isEmpty()) {
|
||||
filteringString = filteringString + " AND t.NAME = ?";
|
||||
}
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
List<Device> devices = new ArrayList<>();
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
||||
"d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
||||
") d1 WHERE d1.ID = e.DEVICE_ID LIMIT ?, ?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
|
||||
int i = 1;
|
||||
|
||||
if (deviceName != null && !deviceName.isEmpty()) {
|
||||
stmt.setString(++i, deviceName + "%");
|
||||
}
|
||||
|
||||
if (type != null && !type.isEmpty()) {
|
||||
stmt.setString(++i, type);
|
||||
}
|
||||
|
||||
stmt.setInt(++i, offset);
|
||||
stmt.setInt(++i, limit);
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
||||
devices.add(device);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices corresponding" +
|
||||
"to the mentioned filtering criteria", e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
return DeviceManagementDAOFactory.getConnection();
|
||||
}
|
||||
|
||||
@ -310,6 +310,71 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
||||
return devices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of devices that matches with the given device name and (or) device type.
|
||||
*
|
||||
* @param deviceName Name of the device.
|
||||
* @param tenantId Id of the current tenant
|
||||
* @return device list
|
||||
* @throws DeviceManagementDAOException
|
||||
*/
|
||||
@Override
|
||||
public List<Device> getDevicesByNameAndType(String deviceName, String type, int tenantId, int offset, int limit)
|
||||
throws DeviceManagementDAOException {
|
||||
|
||||
String filteringString = "";
|
||||
if (deviceName != null && !deviceName.isEmpty()) {
|
||||
filteringString = filteringString + " AND d.NAME LIKE ?";
|
||||
}
|
||||
|
||||
if (type != null && !type.isEmpty()) {
|
||||
filteringString = filteringString + " AND t.NAME = ?";
|
||||
}
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
List<Device> devices = new ArrayList<>();
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String sql = "SELECT * FROM (SELECT ROWNUM offset, rs.* FROM (SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, " +
|
||||
"d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, " +
|
||||
"e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
||||
"(SELECT d.ID, d.NAME, d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
||||
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
||||
") d1 WHERE d1.ID = e.DEVICE_ID) rs) WHERE offset >= ? AND ROWNUM <= ?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
|
||||
int i = 1;
|
||||
|
||||
if (deviceName != null && !deviceName.isEmpty()) {
|
||||
stmt.setString(++i, deviceName + "%");
|
||||
}
|
||||
|
||||
if (type != null && !type.isEmpty()) {
|
||||
stmt.setString(++i, type);
|
||||
}
|
||||
|
||||
stmt.setInt(++i, offset);
|
||||
stmt.setInt(++i, limit);
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
||||
devices.add(device);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices corresponding" +
|
||||
"to the mentioned filtering criteria", e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
return DeviceManagementDAOFactory.getConnection();
|
||||
}
|
||||
|
||||
@ -303,6 +303,71 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
||||
return devices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of devices that matches with the given device name and (or) device type.
|
||||
*
|
||||
* @param deviceName Name of the device.
|
||||
* @param tenantId Id of the current tenant
|
||||
* @return device list
|
||||
* @throws DeviceManagementDAOException
|
||||
*/
|
||||
@Override
|
||||
public List<Device> getDevicesByNameAndType(String deviceName, String type, int tenantId, int offset, int limit)
|
||||
throws DeviceManagementDAOException {
|
||||
|
||||
String filteringString = "";
|
||||
if (deviceName != null && !deviceName.isEmpty()) {
|
||||
filteringString = filteringString + " AND d.NAME LIKE ?";
|
||||
}
|
||||
|
||||
if (type != null && !type.isEmpty()) {
|
||||
filteringString = filteringString + " AND t.NAME = ?";
|
||||
}
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
List<Device> devices = new ArrayList<>();
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
||||
"d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
||||
") d1 WHERE d1.ID = e.DEVICE_ID OFFSET ? LIMIT ?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
|
||||
int i = 1;
|
||||
|
||||
if (deviceName != null && !deviceName.isEmpty()) {
|
||||
stmt.setString(++i, deviceName + "%");
|
||||
}
|
||||
|
||||
if (type != null && !type.isEmpty()) {
|
||||
stmt.setString(++i, type);
|
||||
}
|
||||
|
||||
stmt.setInt(++i, offset);
|
||||
stmt.setInt(++i, limit);
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
||||
devices.add(device);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices corresponding" +
|
||||
"to the mentioned filtering criteria", e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
return DeviceManagementDAOFactory.getConnection();
|
||||
}
|
||||
|
||||
@ -305,6 +305,71 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
||||
return devices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of devices that matches with the given device name and (or) device type.
|
||||
*
|
||||
* @param deviceName Name of the device.
|
||||
* @param tenantId Id of the current tenant
|
||||
* @return device list
|
||||
* @throws DeviceManagementDAOException
|
||||
*/
|
||||
@Override
|
||||
public List<Device> getDevicesByNameAndType(String deviceName, String type, int tenantId, int offset, int limit)
|
||||
throws DeviceManagementDAOException {
|
||||
|
||||
String filteringString = "";
|
||||
if (deviceName != null && !deviceName.isEmpty()) {
|
||||
filteringString = filteringString + " AND d.NAME LIKE ?";
|
||||
}
|
||||
|
||||
if (type != null && !type.isEmpty()) {
|
||||
filteringString = filteringString + " AND t.NAME = ?";
|
||||
}
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
List<Device> devices = new ArrayList<>();
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
||||
"d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
||||
") d1 WHERE d1.ID = e.DEVICE_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, tenantId);
|
||||
|
||||
int i = 1;
|
||||
|
||||
if (deviceName != null && !deviceName.isEmpty()) {
|
||||
stmt.setString(++i, deviceName + "%");
|
||||
}
|
||||
|
||||
if (type != null && !type.isEmpty()) {
|
||||
stmt.setString(++i, type);
|
||||
}
|
||||
|
||||
stmt.setInt(++i, offset);
|
||||
stmt.setInt(++i, limit);
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
||||
devices.add(device);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices corresponding" +
|
||||
"to the mentioned filtering criteria", e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
return DeviceManagementDAOFactory.getConnection();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user