Merge pull request #308 from madhawap/rest-api-improvements

added priorities end-point to PolicyManagement
revert-70aa11f8
Dilan U. Ariyaratne 9 years ago committed by GitHub
commit a278b788d6

@ -0,0 +1,68 @@
/*
* 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 io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ApiModel(value = "BasicUserInfo", description = "Basic user information and the roles of the user.")
public class BasicUserInfo {
private String username;
@ApiModelProperty(name = "firstname", value = "The first name of the user.", required = true )
private String firstname;
@ApiModelProperty(name = "lastname", value = "The last name of the user.", required = true )
private String lastname;
@ApiModelProperty(name = "emailAddress", value = "The email address of the user.", required = true )
private String emailAddress;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
}

@ -0,0 +1,57 @@
/*
* 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 java.util.ArrayList;
import java.util.List;
@ApiModel(value = "BasicUserInfoList", description = "This contains basic details of a set of users that matches " +
"a given criteria as a collection")
public class BasicUserInfoList extends BasePaginatedResult {
private List<BasicUserInfo> users = new ArrayList<>();
@ApiModelProperty(value = "List of devices returned")
@JsonProperty("users")
public List<BasicUserInfo> getList() {
return users;
}
public void setList(List<BasicUserInfo> users) {
this.users = users;
}
@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(" users: [").append(users).append("\n");
sb.append("]}\n");
return sb.toString();
}
}

@ -0,0 +1,52 @@
/*
* 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.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import java.util.List;
public class OperationList extends BasePaginatedResult {
private List<? extends Operation> operations;
@ApiModelProperty(value = "List of operations returned")
@JsonProperty("operations")
public List<? extends Operation> getList() {
return operations;
}
public void setList(List<? extends Operation> operations) {
this.operations = operations;
}
@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(" operations: [").append(operations).append("\n");
sb.append("]}\n");
return sb.toString();
}
}

@ -47,7 +47,7 @@ public class PolicyList extends BasePaginatedResult {
sb.append(" count: ").append(getCount()).append(",\n"); sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n"); sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n"); sb.append(" previous: ").append(getPrevious()).append(",\n");
sb.append(" roles: [").append(policies).append("\n"); sb.append(" policies: [").append(policies).append("\n");
sb.append("]}\n"); sb.append("]}\n");
return sb.toString(); return sb.toString();
} }

@ -21,60 +21,23 @@ package org.wso2.carbon.device.mgt.jaxrs.beans;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ApiModel(value = "UserWrapper", description = "User details and the roles of the user.") @ApiModel(value = "UserInfo", description = "User details and the roles of the user.")
public class UserWrapper { public class UserInfo extends BasicUserInfo {
private String username;
/*
Base64 encoded password
*/
@ApiModelProperty(name = "password", value = "Base64 encoded password.", required = true ) @ApiModelProperty(name = "password", value = "Base64 encoded password.", required = true )
private String password; private String password;
@ApiModelProperty(name = "firstname", value = "The first name of the user.", required = true )
private String firstname;
@ApiModelProperty(name = "lastname", value = "The last name of the user.", required = true )
private String lastname;
@ApiModelProperty(name = "emailAddress", value = "The email address of the user.", required = true )
private String emailAddress;
@ApiModelProperty(name = "roles", value = "List of roles.", required = true ) @ApiModelProperty(name = "roles", value = "List of roles.", required = true )
private String[] roles; private String[] roles;
public String getUsername() { public String getPassword() {
return username; return password;
}
public void setUsername(String username) {
this.username = username;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmailAddress() {
return emailAddress;
} }
public void setEmailAddress(String emailAddress) { public void setPassword(String password) {
this.emailAddress = emailAddress; this.password = password;
} }
/*
Giving a clone of the array since arrays are mutable
*/
public String[] getRoles() { public String[] getRoles() {
String[] copiedRoles = roles; String[] copiedRoles = roles;
if (roles != null){ if (roles != null){
@ -87,11 +50,4 @@ public class UserWrapper {
this.roles = roles; this.roles = roles;
} }
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
} }

@ -27,17 +27,17 @@ import java.util.List;
@ApiModel(value = "List of users", description = "This contains a set of users that matches a given " + @ApiModel(value = "List of users", description = "This contains a set of users that matches a given " +
"criteria as a collection") "criteria as a collection")
public class UserList extends BasePaginatedResult { public class UserInfoList extends BasePaginatedResult {
private List<UserWrapper> users = new ArrayList<>(); private List<UserInfo> users = new ArrayList<>();
@ApiModelProperty(value = "List of devices returned") @ApiModelProperty(value = "List of devices returned")
@JsonProperty("users") @JsonProperty("users")
public List<UserWrapper> getList() { public List<UserInfo> getList() {
return users; return users;
} }
public void setList(List<UserWrapper> users) { public void setList(List<UserInfo> users) {
this.users = users; this.users = users;
} }
@ -45,7 +45,6 @@ public class UserList extends BasePaginatedResult {
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("{\n"); sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n"); sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n"); sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n"); sb.append(" previous: ").append(getPrevious()).append(",\n");
@ -54,5 +53,4 @@ public class UserList extends BasePaginatedResult {
return sb.toString(); return sb.toString();
} }
} }

@ -24,7 +24,6 @@ import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
@ -298,8 +297,7 @@ public interface DeviceManagementService {
code = 200, code = 200,
message = "OK. \n Device list searched for has successfully been retrieved. Location header " + message = "OK. \n Device list searched for has successfully been retrieved. Location header " +
"contains URL of newly enrolled device", "contains URL of newly enrolled device",
response = DeviceWrapper.class, response = DeviceList.class,
responseContainer = "List",
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",

@ -23,6 +23,7 @@ import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -386,5 +387,58 @@ public interface PolicyManagementService {
@ApiParam(name = "policyIds", value = "Policy ID list to be deactivated.", @ApiParam(name = "policyIds", value = "Policy ID list to be deactivated.",
required = true) List<Integer> policyIds); required = true) List<Integer> policyIds);
@PUT
@Produces("application/json")
@Path("apply-changes")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Applying Changes on Policies.",
notes = "Policies in the active state will be applied to new device that register with WSO2 EMM based on" +
" the policy enforcement criteria . In a situation where you need to make changes to existing" +
" policies (removing, activating, deactivating and updating) or add new policies, the existing" +
" devices will not receive these changes immediately. Once all the required changes are made" +
" you need to apply the changes to push the policy changes to the existing devices.")
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "Changes have been successfully updated."),
@ApiResponse(
code = 500,
message = "ErrorResponse in deactivating policies.",
response = ErrorResponse.class)
})
@Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/update"})
Response applyChanges();
@PUT
@Path("/priorities")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Prioritizing policies.",
notes = "",
tags = "Device Policy Management"
)
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "Policy Priorities successfully updated."),
@ApiResponse(
code = 400,
message = "Policy priorities did not update. Bad Request.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Exception in updating policy priorities.",
response = ErrorResponse.class)
})
@Permission(scope = "", permissions = {})
Response updatePolicyPriorities(@ApiParam(name = "priorityUpdatedPolicies", value = "",
required = true) List<PriorityUpdatedPolicyWrapper> priorityUpdatedPolicies);
} }

@ -21,10 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission; import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.*;
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserList;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserWrapper;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -95,7 +92,7 @@ public interface UserManagementService {
@ApiParam( @ApiParam(
name = "user", name = "user",
value = "User related details.", value = "User related details.",
required = true) UserWrapper user); required = true) UserInfo user);
@GET @GET
@Path("/{username}") @Path("/{username}")
@ -105,13 +102,13 @@ public interface UserManagementService {
value = "Getting details of a user.", value = "Getting details of a user.",
notes = "If you wish to get the details of a specific user that is registered with EMM," notes = "If you wish to get the details of a specific user that is registered with EMM,"
+ " you can do so using the REST API.", + " you can do so using the REST API.",
response = UserWrapper.class, response = BasicUserInfo.class,
tags = "User Management") tags = "User Management")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
message = "OK. \n Successfully fetched the requested role.", message = "OK. \n Successfully fetched the requested role.",
response = UserWrapper.class, response = BasicUserInfo.class,
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
@ -209,7 +206,7 @@ public interface UserManagementService {
@ApiParam( @ApiParam(
name = "userData", name = "userData",
value = "User related details.", value = "User related details.",
required = true) UserWrapper userData); required = true) UserInfo userData);
@DELETE @DELETE
@Path("/{username}") @Path("/{username}")
@ -247,15 +244,12 @@ public interface UserManagementService {
value = "Get the role list of a user.", value = "Get the role list of a user.",
notes = "A user can be assigned to one or more role in EMM. Using this REST API you are " notes = "A user can be assigned to one or more role in EMM. Using this REST API you are "
+ "able to get the role/roles a user is assigned to.", + "able to get the role/roles a user is assigned to.",
response = String.class,
responseContainer = "List",
tags = "User Management") tags = "User Management")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
message = "OK. \n Successfully fetched the role list assigned to the user.", message = "OK. \n Successfully fetched the role list assigned to the user.",
response = String.class, response = RoleList.class,
responseContainer = "List",
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
@ -297,15 +291,12 @@ public interface UserManagementService {
value = "Get user list", value = "Get user list",
notes = "If you wish to get the details of all the users registered with EMM, you can do so " notes = "If you wish to get the details of all the users registered with EMM, you can do so "
+ "using the REST API", + "using the REST API",
response = UserList.class,
responseContainer = "List",
tags = "User Management") tags = "User Management")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
message = "OK. \n Successfully fetched the requested role.", message = "OK. \n Successfully fetched the requested role.",
response = UserList.class, response = UserInfoList.class,
responseContainer = "List",
responseHeaders = { responseHeaders = {
@ResponseHeader( @ResponseHeader(
name = "Content-Type", name = "Content-Type",
@ -364,8 +355,6 @@ public interface UserManagementService {
+ "search for that user by giving a character or a few characters in the username. " + "search for that user by giving a character or a few characters in the username. "
+ "You will be given a list of users having the user name with the exact order of the " + "You will be given a list of users having the user name with the exact order of the "
+ "characters you provided.", + "characters you provided.",
response = String.class,
responseContainer = "List",
tags = "User Management") tags = "User Management")
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse( @ApiResponse(

@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.Application; 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.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; 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.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.common.search.SearchContext;
@ -34,6 +33,7 @@ import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; 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.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationList;
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.NotFoundException; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.NotFoundException;
@ -77,6 +77,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
PaginationRequest request = new PaginationRequest(offset, limit); PaginationRequest request = new PaginationRequest(offset, limit);
PaginationResult result; PaginationResult result;
DeviceList devices = new DeviceList();
if (type != null) { if (type != null) {
request.setDeviceType(type); request.setDeviceType(type);
@ -129,13 +130,10 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
result = dms.getAllDevices(request); result = dms.getAllDevices(request);
int resultCount = result.getRecordsTotal(); int resultCount = result.getRecordsTotal();
if (resultCount == 0) { if (resultCount == 0) {
throw new NotFoundException( Response.status(Response.Status.OK).entity(devices).build();
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No device is currently" +
" enrolled with the server").build());
} }
} }
DeviceList devices = new DeviceList();
devices.setList((List<Device>) result.getData()); devices.setList((List<Device>) result.getData());
devices.setCount(result.getRecordsTotal()); devices.setCount(result.getRecordsTotal());
return Response.status(Response.Status.OK).entity(devices).build(); return Response.status(Response.Status.OK).entity(devices).build();
@ -210,7 +208,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
public Response searchDevices(@QueryParam("offset") int offset, public Response searchDevices(@QueryParam("offset") int offset,
@QueryParam("limit") int limit, SearchContext searchContext) { @QueryParam("limit") int limit, SearchContext searchContext) {
SearchManagerService searchManagerService; SearchManagerService searchManagerService;
List<DeviceWrapper> devices; List<Device> devices;
DeviceList deviceList = new DeviceList();
try { try {
searchManagerService = DeviceMgtAPIUtils.getSearchManagerService(); searchManagerService = DeviceMgtAPIUtils.getSearchManagerService();
devices = searchManagerService.search(searchContext); devices = searchManagerService.search(searchContext);
@ -221,11 +220,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
if (devices == null || devices.size() == 0) { if (devices == null || devices.size() == 0) {
throw new NotFoundException( Response.status(Response.Status.OK).entity(deviceList);
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("It is likely that no device is found upon " +
"the provided search filters").build());
} }
return Response.status(Response.Status.OK).entity(devices).build();
deviceList.setList(devices);
return Response.status(Response.Status.OK).entity(deviceList).build();
} }
@GET @GET
@ -268,14 +267,18 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@HeaderParam("If-Modified-Since") String ifModifiedSince, @HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset, @QueryParam("offset") int offset,
@QueryParam("limit") int limit) { @QueryParam("limit") int limit) {
List<? extends Operation> operations; OperationList operationsList = new OperationList();
PaginationRequest request = new PaginationRequest(offset, limit);
PaginationResult result;
DeviceManagementProviderService dms; DeviceManagementProviderService dms;
try { try {
RequestValidationUtil.validateDeviceIdentifier(type, id); RequestValidationUtil.validateDeviceIdentifier(type, id);
dms = DeviceMgtAPIUtils.getDeviceManagementService(); dms = DeviceMgtAPIUtils.getDeviceManagementService();
operations = dms.getOperations(new DeviceIdentifier(id, type)); result = dms.getOperations(new DeviceIdentifier(id, type),request);
if (operations == null) { int resultCount = result.getRecordsTotal();
if (resultCount == 0) {
throw new NotFoundException( throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("It is likely that" + new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("It is likely that" +
" no operation is found upon the provided type and id").build()); " no operation is found upon the provided type and id").build());
@ -287,7 +290,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
throw new UnexpectedServerErrorException( throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
return Response.status(Response.Status.OK).entity(operations).build(); operationsList.setList((List<? extends Operation>) result.getData());
operationsList.setCount(result.getRecordsTotal());
return Response.status(Response.Status.OK).entity(operationsList).build();
} }
@GET @GET

@ -40,10 +40,12 @@ import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Path("/policies") @Path("/policies")
@ -301,4 +303,55 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
} }
} }
@Override
@PUT
@Produces("application/json")
@Path("apply-changes")
public Response applyChanges() {
try {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
PolicyAdministratorPoint pap = policyManagementService.getPAP();
pap.publishChanges();
} catch (PolicyManagementException e) {
String msg = "Exception in applying changes.";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
}
return Response.status(Response.Status.OK).entity("Changes have been successfully updated.").build();
}
@PUT
@Path("/priorities")
public Response updatePolicyPriorities(List<PriorityUpdatedPolicyWrapper> priorityUpdatedPolicies) {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
List<Policy> policiesToUpdate = new ArrayList<>(priorityUpdatedPolicies.size());
int i;
for (i = 0; i < priorityUpdatedPolicies.size(); i++) {
Policy policyObj = new Policy();
policyObj.setId(priorityUpdatedPolicies.get(i).getId());
policyObj.setPriorityId(priorityUpdatedPolicies.get(i).getPriority());
policiesToUpdate.add(policyObj);
}
boolean policiesUpdated;
try {
PolicyAdministratorPoint pap = policyManagementService.getPAP();
policiesUpdated = pap.updatePolicyPriorities(policiesToUpdate);
} catch (PolicyManagementException e) {
String error = "Exception in updating policy priorities.";
log.error(error, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(error).build());
}
if (policiesUpdated) {
return Response.status(Response.Status.OK).entity("Policy Priorities successfully "
+ "updated.").build();
} else {
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Policy priorities did "
+ "not update. Bad Request.").build());
}
}
} }

@ -18,7 +18,6 @@
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.impl; package org.wso2.carbon.device.mgt.jaxrs.service.impl;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -26,12 +25,9 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo; import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.*;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserWrapper;
import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.*; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.*;
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserList;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.NotFoundException; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.NotFoundException;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder; import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder;
@ -55,7 +51,7 @@ public class UserManagementServiceImpl implements UserManagementService {
@POST @POST
@Override @Override
public Response addUser(UserWrapper userWrapper) { public Response addUser(UserInfo userWrapper) {
try { try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (userStoreManager.isExistingUser(userWrapper.getUsername())) { if (userStoreManager.isExistingUser(userWrapper.getUsername())) {
@ -172,7 +168,7 @@ public class UserManagementServiceImpl implements UserManagementService {
try { try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (userStoreManager.isExistingUser(username)) { if (userStoreManager.isExistingUser(username)) {
UserWrapper user = new UserWrapper(); BasicUserInfo user = new BasicUserInfo();
user.setUsername(username); user.setUsername(username);
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
@ -203,7 +199,7 @@ public class UserManagementServiceImpl implements UserManagementService {
@PUT @PUT
@Path("/{username}") @Path("/{username}")
@Override @Override
public Response updateUser(@PathParam("username") String username, UserWrapper userWrapper) { public Response updateUser(@PathParam("username") String username, UserInfo userWrapper) {
try { try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (userStoreManager.isExistingUser(userWrapper.getUsername())) { if (userStoreManager.isExistingUser(userWrapper.getUsername())) {
@ -316,8 +312,9 @@ public class UserManagementServiceImpl implements UserManagementService {
try { try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (userStoreManager.isExistingUser(username)) { if (userStoreManager.isExistingUser(username)) {
return Response.status(Response.Status.OK).entity(Collections.singletonList( RoleList result = new RoleList();
getFilteredRoles(userStoreManager, username))).build(); result.setList(getFilteredRoles(userStoreManager, username));
return Response.status(Response.Status.OK).entity(result).build();
} else { } else {
// Outputting debug message upon trying to remove non-existing user // Outputting debug message upon trying to remove non-existing user
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -343,7 +340,7 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting the list of users with all user-related information"); log.debug("Getting the list of users with all user-related information");
} }
List<UserWrapper> userList, offsetList; List<BasicUserInfo> userList, offsetList;
String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter); String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter);
int appliedLimit = (limit <= 0) ? -1 : (limit + offset); int appliedLimit = (limit <= 0) ? -1 : (limit + offset);
@ -353,9 +350,9 @@ public class UserManagementServiceImpl implements UserManagementService {
//As the listUsers function accepts limit only to accommodate offset we are passing offset + limit //As the listUsers function accepts limit only to accommodate offset we are passing offset + limit
String[] users = userStoreManager.listUsers(appliedFilter, appliedLimit); String[] users = userStoreManager.listUsers(appliedFilter, appliedLimit);
userList = new ArrayList<>(users.length); userList = new ArrayList<>(users.length);
UserWrapper user; BasicUserInfo user;
for (String username : users) { for (String username : users) {
user = new UserWrapper(); user = new BasicUserInfo();
user.setUsername(username); user.setUsername(username);
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
@ -368,12 +365,7 @@ public class UserManagementServiceImpl implements UserManagementService {
} else { } else {
offsetList = new ArrayList<>(); offsetList = new ArrayList<>();
} }
BasicUserInfoList result = new BasicUserInfoList();
// if (offsetList.size() <= 0) {
// return Response.status(Response.Status.NOT_FOUND).entity("No users available for retrieval").build();
// }
UserList result = new UserList();
result.setList(offsetList); result.setList(offsetList);
result.setCount(offsetList.size()); result.setCount(offsetList.size());
@ -394,14 +386,14 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting the list of users with all user-related information using the filter : " + filter); log.debug("Getting the list of users with all user-related information using the filter : " + filter);
} }
List<UserWrapper> userList; List<UserInfo> userList;
try { try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
String[] users = userStoreManager.listUsers(filter + "*", -1); String[] users = userStoreManager.listUsers(filter + "*", -1);
userList = new ArrayList<>(users.length); userList = new ArrayList<>(users.length);
UserWrapper user; UserInfo user;
for (String username : users) { for (String username : users) {
user = new UserWrapper(); user = new UserInfo();
user.setUsername(username); user.setUsername(username);
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));

@ -1,86 +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.device.mgt.common.device.details;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import java.util.List;
@ApiModel(value = "DeviceWrapper", description = "This contains device details including, " +
"location and device meta information.")
public class DeviceWrapper {
@ApiModelProperty(name = "device", value = "Device's basic information", required = true)
private Device device;
@ApiModelProperty(name = "deviceIdentifier", value = "Device identifier used to identify a device.",
required = true)
private DeviceIdentifier deviceIdentifier;
@ApiModelProperty(name = "deviceInfo", value = "Device's runtime information", required = true)
private DeviceInfo deviceInfo;
@ApiModelProperty(name = "deviceLocation", value = "Device's current location", required = true)
private DeviceLocation deviceLocation;
@ApiModelProperty(name = "applications", value = "Application list of devices", required = true)
private List<Application> applications;
public Device getDevice() {
return device;
}
public void setDevice(Device device) {
this.device = device;
}
public DeviceIdentifier getDeviceIdentifier() {
return deviceIdentifier;
}
public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) {
this.deviceIdentifier = deviceIdentifier;
}
public DeviceInfo getDeviceInfo() {
return deviceInfo;
}
public void setDeviceInfo(DeviceInfo deviceInfo) {
this.deviceInfo = deviceInfo;
}
public DeviceLocation getDeviceLocation() {
return deviceLocation;
}
public void setDeviceLocation(DeviceLocation deviceLocation) {
this.deviceLocation = deviceLocation;
}
public List<Application> getApplications() {
return applications;
}
public void setApplications(List<Application> applications) {
this.applications = applications;
}
}

@ -834,7 +834,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
} }
@Override @Override
public List<? extends Operation> getOperationsForDevice(int enrolmentId) throws OperationManagementDAOException { public List<? extends Operation> getOperationsForDevice(int enrolmentId)
throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
@ -844,9 +845,12 @@ public class GenericOperationDAOImpl implements OperationDAO {
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " + String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
"OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " + "OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC"; "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC"
+ "LIMIT ?,?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
/*stmt.setInt(2, request.getStartIndex());
stmt.setInt(3, request.getRowCount());*/
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {

@ -19,15 +19,15 @@
package org.wso2.carbon.device.mgt.core.search.mgt; package org.wso2.carbon.device.mgt.core.search.mgt;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.search.Condition;
import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.common.search.SearchContext;
import java.util.List; import java.util.List;
public interface Processor { public interface Processor {
List<DeviceWrapper> execute(SearchContext searchContext) throws SearchMgtException; List<Device> execute(SearchContext searchContext) throws SearchMgtException;
List<Device> getUpdatedDevices(long epochTime) throws SearchMgtException;
List<DeviceWrapper> getUpdatedDevices(long epochTime) throws SearchMgtException;
} }

@ -19,13 +19,13 @@
package org.wso2.carbon.device.mgt.core.search.mgt; package org.wso2.carbon.device.mgt.core.search.mgt;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.common.Device;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public interface ResultSetAggregator { public interface ResultSetAggregator {
List<DeviceWrapper> aggregate(Map<String, List<DeviceWrapper>> deviceWrappers); List<Device> aggregate(Map<String, List<Device>> devices);
} }

@ -19,15 +19,15 @@
package org.wso2.carbon.device.mgt.core.search.mgt; package org.wso2.carbon.device.mgt.core.search.mgt;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.common.search.SearchContext;
import java.util.List; import java.util.List;
public interface SearchManagerService { public interface SearchManagerService {
List<DeviceWrapper> search(SearchContext searchContext) throws SearchMgtException; List<Device> search(SearchContext searchContext) throws SearchMgtException;
List<DeviceWrapper> getUpdated(long epochTime) throws SearchMgtException; List<Device> getUpdated(long epochTime) throws SearchMgtException;
} }

@ -19,13 +19,14 @@
package org.wso2.carbon.device.mgt.core.search.mgt.dao; package org.wso2.carbon.device.mgt.core.search.mgt.dao;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.common.Device;
import java.util.List; import java.util.List;
public interface SearchDAO { public interface SearchDAO {
List<DeviceWrapper> searchDeviceDetailsTable(String query) throws SearchDAOException; List<Device> searchDeviceDetailsTable(String query) throws SearchDAOException;
List<Device> searchDevicePropertyTable(String query) throws SearchDAOException;
List<DeviceWrapper> searchDevicePropertyTable(String query) throws SearchDAOException;
} }

@ -25,7 +25,6 @@ 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.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.search.mgt.dao.SearchDAO; import org.wso2.carbon.device.mgt.core.search.mgt.dao.SearchDAO;
@ -38,22 +37,19 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class SearchDAOImpl implements SearchDAO { public class SearchDAOImpl implements SearchDAO {
private static final Log log = LogFactory.getLog(SearchDAOImpl.class); private static final Log log = LogFactory.getLog(SearchDAOImpl.class);
@Override @Override
public List<DeviceWrapper> searchDeviceDetailsTable(String query) throws SearchDAOException { public List<Device> searchDeviceDetailsTable(String query) throws SearchDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Query : " + query); log.debug("Query : " + query);
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs; ResultSet rs;
List<DeviceWrapper> devices = new ArrayList<>(); List<Device> devices = new ArrayList<>();
Map<Integer, Integer> devs = new HashMap<>(); Map<Integer, Integer> devs = new HashMap<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
@ -101,15 +97,11 @@ public class SearchDAOImpl implements SearchDAO {
deviceLocation.setDeviceId(rs.getInt("ID")); deviceLocation.setDeviceId(rs.getInt("ID"));
deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP"))); deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP")));
DeviceWrapper wrapper = new DeviceWrapper(); deviceInfo.setLocation(deviceLocation);
wrapper.setDevice(device); device.setDeviceInfo(deviceInfo);
wrapper.setDeviceInfo(deviceInfo); devices.add(device);
wrapper.setDeviceLocation(deviceLocation);
wrapper.setDeviceIdentifier(identifier);
devices.add(wrapper);
devs.put(device.getId(), device.getId()); devs.put(device.getId(), device.getId());
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new SearchDAOException("Error occurred while acquiring the device details.", e); throw new SearchDAOException("Error occurred while acquiring the device details.", e);
@ -126,8 +118,7 @@ public class SearchDAOImpl implements SearchDAO {
} }
@Override @Override
public List<DeviceWrapper> searchDevicePropertyTable(String query) throws SearchDAOException { public List<Device> searchDevicePropertyTable(String query) throws SearchDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Query : " + query); log.debug("Query : " + query);
} }
@ -135,7 +126,7 @@ public class SearchDAOImpl implements SearchDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs; ResultSet rs;
List<DeviceWrapper> devices = new ArrayList<>(); List<Device> devices = new ArrayList<>();
Map<Integer, Integer> devs = new HashMap<>(); Map<Integer, Integer> devs = new HashMap<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
@ -183,13 +174,9 @@ public class SearchDAOImpl implements SearchDAO {
deviceLocation.setDeviceId(rs.getInt("ID")); deviceLocation.setDeviceId(rs.getInt("ID"));
deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP"))); deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP")));
DeviceWrapper wrapper = new DeviceWrapper(); deviceInfo.setLocation(deviceLocation);
wrapper.setDevice(device); device.setDeviceInfo(deviceInfo);
wrapper.setDeviceInfo(deviceInfo); devices.add(device);
wrapper.setDeviceLocation(deviceLocation);
wrapper.setDeviceIdentifier(identifier);
devices.add(wrapper);
devs.put(device.getId(), device.getId()); devs.put(device.getId(), device.getId());
} }
@ -214,8 +201,7 @@ public class SearchDAOImpl implements SearchDAO {
return DeviceManagementDAOFactory.getConnection(); return DeviceManagementDAOFactory.getConnection();
} }
private List<DeviceWrapper> fillPropertiesOfDevices(List<DeviceWrapper> devices) throws SearchDAOException { private List<Device> fillPropertiesOfDevices(List<Device> devices) throws SearchDAOException {
if (devices.isEmpty()) { if (devices.isEmpty()) {
return null; return null;
} }
@ -249,14 +235,13 @@ public class SearchDAOImpl implements SearchDAO {
return devices; return devices;
} }
private DeviceInfo getDeviceInfo(List<DeviceWrapper> devices, int deviceId) { private DeviceInfo getDeviceInfo(List<Device> devices, int deviceId) {
for (Device device : devices) {
for (DeviceWrapper dw : devices) { if (device.getId() == deviceId) {
if (dw.getDevice().getId() == deviceId) { if (device.getDeviceInfo() == null) {
if (dw.getDeviceInfo() == null) { device.setDeviceInfo(new DeviceInfo());
dw.setDeviceInfo(new DeviceInfo());
} }
return dw.getDeviceInfo(); return device.getDeviceInfo();
} }
} }
return null; return null;

@ -19,10 +19,7 @@
package org.wso2.carbon.device.mgt.core.search.mgt.impl; package org.wso2.carbon.device.mgt.core.search.mgt.impl;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
@ -48,13 +45,13 @@ public class ProcessorImpl implements Processor {
} }
@Override @Override
public List<DeviceWrapper> execute(SearchContext searchContext) throws SearchMgtException { public List<Device> execute(SearchContext searchContext) throws SearchMgtException {
QueryBuilder queryBuilder = new QueryBuilderImpl(); QueryBuilder queryBuilder = new QueryBuilderImpl();
List<DeviceWrapper> generalDevices = new ArrayList<>(); List<Device> generalDevices = new ArrayList<>();
List<List<DeviceWrapper>> allANDDevices = new ArrayList<>(); List<List<Device>> allANDDevices = new ArrayList<>();
List<List<DeviceWrapper>> allORDevices = new ArrayList<>(); List<List<Device>> allORDevices = new ArrayList<>();
List<DeviceWrapper> locationDevices = new ArrayList<>(); List<Device> locationDevices = new ArrayList<>();
try { try {
Map<String, List<String>> queries = queryBuilder.buildQueries(searchContext.getConditions()); Map<String, List<String>> queries = queryBuilder.buildQueries(searchContext.getConditions());
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
@ -64,13 +61,13 @@ public class ProcessorImpl implements Processor {
} }
if (queries.containsKey(Constants.PROP_AND)) { if (queries.containsKey(Constants.PROP_AND)) {
for (String query : queries.get(Constants.PROP_AND)) { for (String query : queries.get(Constants.PROP_AND)) {
List<DeviceWrapper> andDevices = searchDAO.searchDevicePropertyTable(query); List<Device> andDevices = searchDAO.searchDevicePropertyTable(query);
allANDDevices.add(andDevices); allANDDevices.add(andDevices);
} }
} }
if (queries.containsKey(Constants.PROP_OR)) { if (queries.containsKey(Constants.PROP_OR)) {
for (String query : queries.get(Constants.PROP_OR)) { for (String query : queries.get(Constants.PROP_OR)) {
List<DeviceWrapper> orDevices = searchDAO.searchDevicePropertyTable(query); List<Device> orDevices = searchDAO.searchDevicePropertyTable(query);
allORDevices.add(orDevices); allORDevices.add(orDevices);
} }
} }
@ -88,23 +85,22 @@ public class ProcessorImpl implements Processor {
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
ResultSetAggregator aggregator = new ResultSetAggregatorImpl(); ResultSetAggregator aggregator = new ResultSetAggregatorImpl();
Map<String, List<DeviceWrapper>> deviceWrappers = new HashMap<>(); Map<String, List<Device>> devices = new HashMap<>();
deviceWrappers.put(Constants.GENERAL, generalDevices); devices.put(Constants.GENERAL, generalDevices);
deviceWrappers.put(Constants.PROP_AND, this.processANDSearch(allANDDevices)); devices.put(Constants.PROP_AND, this.processANDSearch(allANDDevices));
deviceWrappers.put(Constants.PROP_OR, this.processORSearch(allORDevices)); devices.put(Constants.PROP_OR, this.processORSearch(allORDevices));
deviceWrappers.put(Constants.LOCATION, locationDevices); devices.put(Constants.LOCATION, locationDevices);
List<DeviceWrapper> finalDeviceWrappers = aggregator.aggregate(deviceWrappers); List<Device> finalDevices = aggregator.aggregate(devices);
this.setApplicationListOfDevices(finalDeviceWrappers); this.setApplicationListOfDevices(finalDevices);
return finalDeviceWrappers; return finalDevices;
} }
@Override @Override
public List<DeviceWrapper> getUpdatedDevices(long epochTime) throws SearchMgtException { public List<Device> getUpdatedDevices(long epochTime) throws SearchMgtException {
if((1 + (int)Math.floor(Math.log10(epochTime))) <=10 ) { if((1 + (int)Math.floor(Math.log10(epochTime))) <=10 ) {
epochTime = epochTime * 1000; epochTime = epochTime * 1000;
@ -126,15 +122,14 @@ public class ProcessorImpl implements Processor {
} }
private List<DeviceWrapper> processANDSearch(List<List<DeviceWrapper>> deLists) { private List<Device> processANDSearch(List<List<Device>> deLists) {
List<Device> deviceList = new ArrayList<>();
List<DeviceWrapper> devices = new ArrayList<>(); List<Device> smallestDeviceList = this.findListWithLowestItems(deLists);
List<DeviceWrapper> smallestDeviceList = this.findListWithLowestItems(deLists); List<Map<Integer, Device>> maps = this.convertDeviceListToMap(deLists);
List<Map<Integer, DeviceWrapper>> maps = this.convertDeviceListToMap(deLists);
boolean valueExist = false; boolean valueExist = false;
for (DeviceWrapper dw : smallestDeviceList) { for (Device device : smallestDeviceList) {
for (Map<Integer, DeviceWrapper> deviceWrapperMap : maps) { for (Map<Integer, Device> devices : maps) {
if (deviceWrapperMap.containsKey(dw.getDevice().getId())) { if (devices.containsKey(device.getId())) {
valueExist = true; valueExist = true;
} else { } else {
valueExist = false; valueExist = false;
@ -142,63 +137,61 @@ public class ProcessorImpl implements Processor {
} }
} }
if (valueExist) { if (valueExist) {
devices.add(dw); deviceList.add(device);
} }
} }
return devices; return deviceList;
} }
private List<DeviceWrapper> processORSearch(List<List<DeviceWrapper>> deLists) { private List<Device> processORSearch(List<List<Device>> deLists) {
List<DeviceWrapper> devices = new ArrayList<>(); List<Device> devices = new ArrayList<>();
Map<Integer, DeviceWrapper> map = new HashMap<>(); Map<Integer, Device> map = new HashMap<>();
for (List<DeviceWrapper> list : deLists) { for (List<Device> list : deLists) {
for (DeviceWrapper dw : list) { for (Device device : list) {
if (!map.containsKey(dw.getDevice().getId())) { if (!map.containsKey(device.getId())) {
map.put(dw.getDevice().getId(), dw); map.put(device.getId(), device);
devices.add(dw); devices.add(device);
} }
} }
} }
return devices; return devices;
} }
private List<DeviceWrapper> findListWithLowestItems(List<List<DeviceWrapper>> deLists) { private List<Device> findListWithLowestItems(List<List<Device>> deLists) {
int size = 0; int size = 0;
List<DeviceWrapper> deviceWrappers = new ArrayList<>(); List<Device> devices = new ArrayList<>();
for (List<DeviceWrapper> list : deLists) { for (List<Device> list : deLists) {
if (size == 0) { if (size == 0) {
size = list.size(); size = list.size();
deviceWrappers = list; devices = list;
continue;
} else { } else {
if (list.size() < size) { if (list.size() < size) {
deviceWrappers = list; devices = list;
} }
} }
} }
return deviceWrappers; return devices;
} }
private List<Map<Integer, DeviceWrapper>> convertDeviceListToMap(List<List<DeviceWrapper>> deLists) { private List<Map<Integer, Device>> convertDeviceListToMap(List<List<Device>> deLists) {
List<Map<Integer, Device>> maps = new ArrayList<>();
List<Map<Integer, DeviceWrapper>> maps = new ArrayList<>(); for (List<Device> devices : deLists) {
for (List<DeviceWrapper> deviceWrapperList : deLists) { Map<Integer, Device> deviceMap = new HashMap<>();
Map<Integer, DeviceWrapper> deviceWrapperMap = new HashMap<>();
for (DeviceWrapper dw : deviceWrapperList) { for (Device device: devices) {
deviceWrapperMap.put(dw.getDevice().getId(), dw); deviceMap.put(device.getId(), device);
} }
maps.add(deviceWrapperMap); maps.add(deviceMap);
} }
return maps; return maps;
} }
private void setApplicationListOfDevices(List<DeviceWrapper> deviceWrappers) throws SearchMgtException {
private void setApplicationListOfDevices(List<Device> devices) throws SearchMgtException {
try { try {
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
for (DeviceWrapper wrapper : deviceWrappers) { for (Device device : devices) {
wrapper.setApplications(applicationDAO.getInstalledApplications(wrapper.getDevice().getId())); device.setApplications(applicationDAO.getInstalledApplications(device.getId()));
} }
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new SearchMgtException("Error occurred while fetching the Application List of devices ", e); throw new SearchMgtException("Error occurred while fetching the Application List of devices ", e);

@ -19,23 +19,26 @@
package org.wso2.carbon.device.mgt.core.search.mgt.impl; package org.wso2.carbon.device.mgt.core.search.mgt.impl;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.core.search.mgt.Constants; import org.wso2.carbon.device.mgt.core.search.mgt.Constants;
import org.wso2.carbon.device.mgt.core.search.mgt.ResultSetAggregator; import org.wso2.carbon.device.mgt.core.search.mgt.ResultSetAggregator;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ResultSetAggregatorImpl implements ResultSetAggregator { public class ResultSetAggregatorImpl implements ResultSetAggregator {
@Override @Override
public List<DeviceWrapper> aggregate(Map<String, List<DeviceWrapper>> deviceWrappers) { public List<Device> aggregate(Map<String, List<Device>> devices) {
Map<Integer, DeviceWrapper> generalQueryMap = this.convertToMap(deviceWrappers.get(Constants.GENERAL)); Map<Integer, Device> generalQueryMap = this.convertToMap(devices.get(Constants.GENERAL));
Map<Integer, DeviceWrapper> andMap = this.convertToMap(deviceWrappers.get(Constants.PROP_AND)); Map<Integer, Device> andMap = this.convertToMap(devices.get(Constants.PROP_AND));
Map<Integer, DeviceWrapper> orMap = this.convertToMap(deviceWrappers.get(Constants.PROP_OR)); Map<Integer, Device> orMap = this.convertToMap(devices.get(Constants.PROP_OR));
Map<Integer, DeviceWrapper> locationMap = this.convertToMap(deviceWrappers.get(Constants.LOCATION)); Map<Integer, Device> locationMap = this.convertToMap(devices.get(Constants.LOCATION));
Map<Integer, DeviceWrapper> finalMap = new HashMap<>(); Map<Integer, Device> finalMap = new HashMap<>();
List<DeviceWrapper> finalResult = new ArrayList<>(); List<Device> finalResult = new ArrayList<>();
if (andMap.isEmpty()) { if (andMap.isEmpty()) {
finalMap = generalQueryMap; finalMap = generalQueryMap;
@ -70,24 +73,23 @@ public class ResultSetAggregatorImpl implements ResultSetAggregator {
return finalResult; return finalResult;
} }
private Map<Integer, DeviceWrapper> convertToMap(List<DeviceWrapper> deviceWrappers) { private Map<Integer, Device> convertToMap(List<Device> devices) {
if (devices == null) {
if (deviceWrappers == null) {
return null; return null;
} }
Map<Integer, DeviceWrapper> deviceWrapperMap = new HashMap<>(); Map<Integer, Device> deviceWrapperMap = new HashMap<>();
for (DeviceWrapper dw : deviceWrappers) { for (Device device : devices) {
deviceWrapperMap.put(dw.getDevice().getId(), dw); deviceWrapperMap.put(device.getId(), device);
} }
return deviceWrapperMap; return deviceWrapperMap;
} }
private List<DeviceWrapper> convertDeviceMapToList(Map<Integer, DeviceWrapper> map) { private List<Device> convertDeviceMapToList(Map<Integer, Device> map) {
List<DeviceWrapper> list = new ArrayList<>(); List<Device> list = new ArrayList<>();
for (Integer a : map.keySet()) { for (Integer a : map.keySet()) {
list.add(map.get(a)); list.add(map.get(a));
} }
return list; return list;
} }
} }

@ -19,7 +19,7 @@
package org.wso2.carbon.device.mgt.core.search.mgt.impl; package org.wso2.carbon.device.mgt.core.search.mgt.impl;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.core.search.mgt.Processor; import org.wso2.carbon.device.mgt.core.search.mgt.Processor;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService; import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
@ -29,7 +29,6 @@ import java.util.List;
public class SearchManagerServiceImpl implements SearchManagerService { public class SearchManagerServiceImpl implements SearchManagerService {
private Processor processor; private Processor processor;
public SearchManagerServiceImpl() { public SearchManagerServiceImpl() {
@ -37,13 +36,14 @@ public class SearchManagerServiceImpl implements SearchManagerService {
} }
@Override @Override
public List<DeviceWrapper> search(SearchContext searchContext) throws SearchMgtException { public List<Device> search(SearchContext searchContext) throws SearchMgtException {
return processor.execute(searchContext); return processor.execute(searchContext);
} }
@Override @Override
public List<DeviceWrapper> getUpdated(long epochTime) throws SearchMgtException { public List<Device> getUpdated(long epochTime) throws SearchMgtException {
return processor.getUpdatedDevices(epochTime); return processor.getUpdatedDevices(epochTime);
} }
} }

@ -19,7 +19,7 @@
package org.wso2.carbon.device.mgt.core.search.mgt.impl; package org.wso2.carbon.device.mgt.core.search.mgt.impl;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.common.Device;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -32,7 +32,6 @@ public class Utils {
private static Map<String, String> locationColumnsMap = new HashMap<>(); private static Map<String, String> locationColumnsMap = new HashMap<>();
static { static {
genericColumnsMap.put("deviceModel", "DEVICE_MODEL"); genericColumnsMap.put("deviceModel", "DEVICE_MODEL");
genericColumnsMap.put("vendor", "VENDOR"); genericColumnsMap.put("vendor", "VENDOR");
genericColumnsMap.put("osVersion", "OS_VERSION"); genericColumnsMap.put("osVersion", "OS_VERSION");
@ -65,22 +64,23 @@ public class Utils {
boolean bool = false; boolean bool = false;
switch (column) { switch (column) {
case "deviceModel": case "deviceModel":
bool = true; bool = true;
break; break;
case "vendor": case "vendor":
bool = true; bool = true;
break; break;
case "osVersion": case "osVersion":
bool = true; bool = true;
break; break;
case "connectionType": case "connectionType":
bool = true; bool = true;
break; break;
case "ssid": case "ssid":
bool = true; bool = true;
break; break;
default: bool =false; default:
bool = false;
break; break;
} }
@ -89,9 +89,9 @@ public class Utils {
public static String getConvertedValue(String column, String value) { public static String getConvertedValue(String column, String value) {
if(checkColumnType(column)){ if (checkColumnType(column)) {
return "\'" + value + "\'"; return "\'" + value + "\'";
} else return value; } else return value;
} }
@ -104,23 +104,11 @@ public class Utils {
} }
public static boolean checkDeviceDetailsColumns(String str) { public static boolean checkDeviceDetailsColumns(String str) {
if (genericColumnsMap.containsKey(str)) { return genericColumnsMap.containsKey(str) || genericColumnsMap.containsValue(str);
return true;
}
if (genericColumnsMap.containsValue(str)) {
return true;
}
return false;
} }
public static boolean checkDeviceLocationColumns(String str) { public static boolean checkDeviceLocationColumns(String str) {
if (locationColumnsMap.containsKey(str)) { return locationColumnsMap.containsKey(str) || locationColumnsMap.containsValue(str);
return true;
}
if (locationColumnsMap.containsValue(str)) {
return true;
}
return false;
} }
public static List<String> convertStringToList(String str) { public static List<String> convertStringToList(String str) {
@ -130,28 +118,28 @@ public class Utils {
return stList; return stList;
} }
public static Integer[] getArrayOfDeviceIds(List<DeviceWrapper> deviceWrappers) { public static Integer[] getArrayOfDeviceIds(List<Device> devices) {
Integer[] arr = new Integer[devices.size()];
Integer[] arr = new Integer[deviceWrappers.size()];
int x = 0; int x = 0;
for (DeviceWrapper dw : deviceWrappers) { for (Device device : devices) {
arr[x] = dw.getDevice().getId(); arr[x] = device.getId();
x++; x++;
} }
return arr; return arr;
} }
public static String getDeviceIdsAsString(List<DeviceWrapper> deviceWrappers) { public static String getDeviceIdsAsString(List<Device> devices) {
String str = ""; String str = "";
for (DeviceWrapper dw : deviceWrappers) { for (Device device : devices) {
str += dw.getDevice().getId() + ","; str += device.getId() + ",";
} }
if (deviceWrappers.isEmpty()) { if (devices.isEmpty()) {
return null; return null;
} }
return str.substring(0, str.length() - 1); return str.substring(0, str.length() - 1);
} }
} }

@ -24,7 +24,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.search.Condition; import org.wso2.carbon.device.mgt.common.search.Condition;
import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest; import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
@ -79,22 +79,22 @@ public class SearchDevice extends BaseDeviceManagementTest {
context.setConditions(conditions); context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl(); SearchManagerService service = new SearchManagerServiceImpl();
List<DeviceWrapper> deviceWrappers = service.search(context); List<Device> devices = service.search(context);
Gson gson = new Gson(); Gson gson = new Gson();
String bbbb = gson.toJson(deviceWrappers); String bbbb = gson.toJson(devices);
log.info(bbbb); log.info(bbbb);
for (DeviceWrapper dw : deviceWrappers) { for (Device device : devices) {
log.debug(dw.getDevice().getDescription()); log.debug(device.getDescription());
log.debug(dw.getDevice().getDeviceIdentifier()); log.debug(device.getDeviceIdentifier());
} }
} }
@Test @Test
public void doValidLocationSearch() throws Exception{ public void doValidLocationSearch() throws Exception {
SearchContext context = new SearchContext(); SearchContext context = new SearchContext();
List<Condition> conditions = new ArrayList<>(); List<Condition> conditions = new ArrayList<>();
@ -109,21 +109,21 @@ public class SearchDevice extends BaseDeviceManagementTest {
context.setConditions(conditions); context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl(); SearchManagerService service = new SearchManagerServiceImpl();
List<DeviceWrapper> deviceWrappers = service.search(context); List<Device> devices = service.search(context);
Gson gson = new Gson(); Gson gson = new Gson();
String bbbb = gson.toJson(deviceWrappers); String bbbb = gson.toJson(devices);
log.info("Valid Search " + bbbb); log.info("Valid Search " + bbbb);
for (DeviceWrapper dw : deviceWrappers) { for (Device device : devices) {
log.debug(dw.getDevice().getDescription()); log.debug(device.getDescription());
log.debug(dw.getDevice().getDeviceIdentifier()); log.debug(device.getDeviceIdentifier());
} }
} }
@Test @Test
public void doInvalidLocationSearch() throws Exception{ public void doInvalidLocationSearch() throws Exception {
SearchContext context = new SearchContext(); SearchContext context = new SearchContext();
List<Condition> conditions = new ArrayList<>(); List<Condition> conditions = new ArrayList<>();
@ -138,21 +138,21 @@ public class SearchDevice extends BaseDeviceManagementTest {
context.setConditions(conditions); context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl(); SearchManagerService service = new SearchManagerServiceImpl();
List<DeviceWrapper> deviceWrappers = service.search(context); List<Device> devices = service.search(context);
Gson gson = new Gson(); Gson gson = new Gson();
String bbbb = gson.toJson(deviceWrappers); String bbbb = gson.toJson(devices);
log.info("Invalid Search " + bbbb); log.info("Invalid Search " + bbbb);
for (DeviceWrapper dw : deviceWrappers) { for (Device device : devices) {
log.debug(dw.getDevice().getDescription()); log.debug(device.getDescription());
log.debug(dw.getDevice().getDeviceIdentifier()); log.debug(device.getDeviceIdentifier());
} }
} }
@Test @Test
public void doStringSearch() throws Exception{ public void doStringSearch() throws Exception {
SearchContext context = new SearchContext(); SearchContext context = new SearchContext();
List<Condition> conditions = new ArrayList<>(); List<Condition> conditions = new ArrayList<>();
@ -167,16 +167,16 @@ public class SearchDevice extends BaseDeviceManagementTest {
context.setConditions(conditions); context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl(); SearchManagerService service = new SearchManagerServiceImpl();
List<DeviceWrapper> deviceWrappers = service.search(context); List<Device> devices = service.search(context);
Gson gson = new Gson(); Gson gson = new Gson();
String bbbb = gson.toJson(deviceWrappers); String bbbb = gson.toJson(devices);
log.info("Invalid Search " + bbbb); log.info("Invalid Search " + bbbb);
for (DeviceWrapper dw : deviceWrappers) { for (Device device : devices) {
log.debug(dw.getDevice().getDescription()); log.debug(device.getDescription());
log.debug(dw.getDevice().getDeviceIdentifier()); log.debug(device.getDeviceIdentifier());
} }
} }
} }

Loading…
Cancel
Save