|
|
@ -37,33 +37,26 @@
|
|
|
|
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
|
|
|
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
|
|
|
import io.entgra.application.mgt.common.ApplicationInstallResponse;
|
|
|
|
|
|
|
|
import io.entgra.application.mgt.common.SubscriptionType;
|
|
|
|
|
|
|
|
import io.entgra.application.mgt.common.exception.SubscriptionManagementException;
|
|
|
|
import io.entgra.application.mgt.common.services.ApplicationManager;
|
|
|
|
import io.entgra.application.mgt.common.services.ApplicationManager;
|
|
|
|
|
|
|
|
import io.entgra.application.mgt.common.services.SubscriptionManager;
|
|
|
|
|
|
|
|
import io.entgra.application.mgt.core.util.HelperUtil;
|
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
|
|
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;
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
import org.wso2.carbon.apimgt.keymgt.extension.DCRResponse;
|
|
|
|
|
|
|
|
import org.wso2.carbon.apimgt.keymgt.extension.TokenRequest;
|
|
|
|
|
|
|
|
import org.wso2.carbon.apimgt.keymgt.extension.TokenResponse;
|
|
|
|
|
|
|
|
import org.wso2.carbon.apimgt.keymgt.extension.exception.KeyMgtException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.apimgt.keymgt.extension.service.KeyMgtService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.apimgt.keymgt.extension.service.KeyMgtServiceImpl;
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import io.entgra.application.mgt.common.ApplicationInstallResponse;
|
|
|
|
import org.wso2.carbon.device.mgt.common.*;
|
|
|
|
import io.entgra.application.mgt.common.SubscriptionType;
|
|
|
|
|
|
|
|
import io.entgra.application.mgt.common.exception.SubscriptionManagementException;
|
|
|
|
|
|
|
|
import io.entgra.application.mgt.common.services.SubscriptionManager;
|
|
|
|
|
|
|
|
import io.entgra.application.mgt.core.util.HelperUtil;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceFilters;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.OperationLogFilters;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.MDMAppConstants;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.Feature;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.TrackerDeviceInfo;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.TrackerPermissionInfo;
|
|
|
|
|
|
|
|
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.authorization.DeviceAccessAuthorizationException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
|
|
@ -72,12 +65,8 @@ import org.wso2.carbon.device.mgt.common.device.details.DeviceData;
|
|
|
|
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.DeviceLocationHistorySnapshotWrapper;
|
|
|
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocationHistorySnapshotWrapper;
|
|
|
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceTypeNotFoundException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.exceptions.InvalidConfigurationException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.exceptions.BadRequestException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.exceptions.BadRequestException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.exceptions.UnAuthorizedException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.exceptions.*;
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
|
@ -91,6 +80,8 @@ import org.wso2.carbon.device.mgt.common.search.PropertyMap;
|
|
|
|
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceStatus;
|
|
|
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceStatus;
|
|
|
|
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
|
|
@ -103,19 +94,10 @@ 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.core.service.GroupManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.traccar.api.service.impl.DeviceAPIClientServiceImpl;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.traccar.common.TraccarHandlerConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.core.traccar.common.TraccarHandlerConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.HttpReportingUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.HttpReportingUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.*;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceCompliance;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationList;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationStatusBean;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ComplianceDeviceList;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationRequest;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationList;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationUninstallation;
|
|
|
|
|
|
|
|
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.RequestValidationUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
|
|
@ -128,29 +110,17 @@ import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerSer
|
|
|
|
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.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.core.service.RealmService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
import javax.validation.Valid;
|
|
|
|
import javax.ws.rs.Consumes;
|
|
|
|
|
|
|
|
import javax.validation.constraints.Size;
|
|
|
|
import javax.validation.constraints.Size;
|
|
|
|
import javax.ws.rs.DELETE;
|
|
|
|
import javax.ws.rs.*;
|
|
|
|
import javax.ws.rs.DefaultValue;
|
|
|
|
|
|
|
|
import javax.ws.rs.GET;
|
|
|
|
|
|
|
|
import javax.ws.rs.HeaderParam;
|
|
|
|
|
|
|
|
import javax.ws.rs.POST;
|
|
|
|
|
|
|
|
import javax.ws.rs.PUT;
|
|
|
|
|
|
|
|
import javax.ws.rs.Path;
|
|
|
|
|
|
|
|
import javax.ws.rs.PathParam;
|
|
|
|
|
|
|
|
import javax.ws.rs.QueryParam;
|
|
|
|
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
|
|
|
|
|
@ -199,10 +169,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
@QueryParam("limit") int limit) {
|
|
|
|
@QueryParam("limit") int limit) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (!StringUtils.isEmpty(name) && !StringUtils.isEmpty(role)) {
|
|
|
|
if (!StringUtils.isEmpty(name) && !StringUtils.isEmpty(role)) {
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
|
|
|
String msg = "Request contains both name and role parameters. Only one is allowed at once.";
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage("Request contains both name and role " +
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
"parameters. Only one is allowed " +
|
|
|
|
|
|
|
|
"at once.").build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// RequestValidationUtil.validateSelectionCriteria(type, user, roleName, ownership, status);
|
|
|
|
// RequestValidationUtil.validateSelectionCriteria(type, user, roleName, ownership, status);
|
|
|
|
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
|
|
|
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
|
|
@ -291,9 +259,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
sinceDate = format.parse(ifModifiedSince);
|
|
|
|
sinceDate = format.parse(ifModifiedSince);
|
|
|
|
} catch (ParseException e) {
|
|
|
|
} catch (ParseException e) {
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
|
|
|
String msg = "Invalid date string is provided in [If-Modified-Since] header";
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage("Invalid date " +
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
"string is provided in 'If-Modified-Since' header").build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
request.setSince(sinceDate);
|
|
|
|
request.setSince(sinceDate);
|
|
|
|
if (requireDeviceInfo) {
|
|
|
|
if (requireDeviceInfo) {
|
|
|
@ -312,9 +279,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
sinceDate = format.parse(since);
|
|
|
|
sinceDate = format.parse(since);
|
|
|
|
} catch (ParseException e) {
|
|
|
|
} catch (ParseException e) {
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
|
|
|
String msg = "Invalid date string is provided in [since] filter";
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage("Invalid date " +
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
"string is provided in 'since' filter").build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
request.setSince(sinceDate);
|
|
|
|
request.setSince(sinceDate);
|
|
|
|
if (requireDeviceInfo) {
|
|
|
|
if (requireDeviceInfo) {
|
|
|
@ -387,103 +353,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
@Path("/traccar-user-token")
|
|
|
|
|
|
|
|
public Response getTraccarUserToken() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (HttpReportingUtil.isTrackerEnabled()) {
|
|
|
|
|
|
|
|
String currentUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
|
|
|
DeviceAPIClientService deviceAPIClientService = DeviceMgtAPIUtils.getDeviceAPIClientService();
|
|
|
|
|
|
|
|
JSONObject obj = new JSONObject(deviceAPIClientService.returnUser(currentUser));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (obj.has("error")) {
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(obj.getString("error")).build();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
int userId = obj.getInt("id");
|
|
|
|
|
|
|
|
List<Integer> traccarValidIdList = new ArrayList<>();
|
|
|
|
|
|
|
|
/*Get Device Id List*/
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
|
|
|
|
DeviceAccessAuthorizationService deviceAccessAuthorizationService =
|
|
|
|
|
|
|
|
DeviceMgtAPIUtils.getDeviceAccessAuthorizationService();
|
|
|
|
|
|
|
|
PaginationRequest request = new PaginationRequest(0, 0);
|
|
|
|
|
|
|
|
PaginationResult result;
|
|
|
|
|
|
|
|
DeviceList devices = new DeviceList();
|
|
|
|
|
|
|
|
List<String> status = new ArrayList<>();
|
|
|
|
|
|
|
|
status.add("ACTIVE");
|
|
|
|
|
|
|
|
status.add("INACTIVE");
|
|
|
|
|
|
|
|
status.add("CREATED");
|
|
|
|
|
|
|
|
status.add("UNREACHABLE");
|
|
|
|
|
|
|
|
request.setStatusList(status);
|
|
|
|
|
|
|
|
// this is the user who initiates the request
|
|
|
|
|
|
|
|
String authorizedUser = MultitenantUtils.getTenantAwareUsername(currentUser);
|
|
|
|
|
|
|
|
// check whether the user is device-mgt admin
|
|
|
|
|
|
|
|
if (!deviceAccessAuthorizationService.isDeviceAdminUser()) {
|
|
|
|
|
|
|
|
request.setOwner(authorizedUser);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = dms.getAllDevicesIds(request);
|
|
|
|
|
|
|
|
if (result == null || result.getData() == null || result.getData().isEmpty()) {
|
|
|
|
|
|
|
|
devices.setList(new ArrayList<Device>());
|
|
|
|
|
|
|
|
devices.setCount(0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
devices.setList((List<Device>) result.getData());
|
|
|
|
|
|
|
|
devices.setCount(result.getRecordsTotal());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
TrackerDeviceInfo trackerDevice;
|
|
|
|
|
|
|
|
for (Device device : devices.getList()) {
|
|
|
|
|
|
|
|
trackerDevice = deviceAPIClientService.getTrackerDevice(device.getId(), tenantId);
|
|
|
|
|
|
|
|
if(trackerDevice != null) {
|
|
|
|
|
|
|
|
int traccarDeviceId = trackerDevice.getTraccarDeviceId();
|
|
|
|
|
|
|
|
boolean getPermission = deviceAPIClientService.getUserIdofPermissionByDeviceIdNUserId(traccarDeviceId, userId);
|
|
|
|
|
|
|
|
traccarValidIdList.add(traccarDeviceId);
|
|
|
|
|
|
|
|
if (!getPermission) {
|
|
|
|
|
|
|
|
deviceAPIClientService.addTrackerUserDevicePermission(userId, traccarDeviceId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Remove necessary
|
|
|
|
|
|
|
|
List<TrackerPermissionInfo> getAllUserDevices =
|
|
|
|
|
|
|
|
deviceAPIClientService.getUserIdofPermissionByUserIdNIdList(userId, traccarValidIdList);
|
|
|
|
|
|
|
|
for (TrackerPermissionInfo getAllUserDevice : getAllUserDevices) {
|
|
|
|
|
|
|
|
deviceAPIClientService.removeTrackerUserDevicePermission(
|
|
|
|
|
|
|
|
getAllUserDevice.getTraccarUserId(),
|
|
|
|
|
|
|
|
getAllUserDevice.getTraccarDeviceId(),
|
|
|
|
|
|
|
|
TraccarHandlerConstants.Types.REMOVE_TYPE_SINGLE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while fetching all enrolled devices. ";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
|
|
|
} catch (DeviceAccessAuthorizationException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while checking device access authorization. ";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
|
|
|
} catch (TrackerManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while mapping with deviceId .";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
|
|
|
} catch (ExecutionException e) {
|
|
|
|
|
|
|
|
String msg = "Execution error occurred handling traccar device permissions";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
|
|
|
String msg = "Interruption error occurred handling traccar device permissions";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*Get Device Id List*/
|
|
|
|
|
|
|
|
return Response.status(Response.Status.OK).entity(obj.getString("token")).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity("Traccar is not enabled").build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Validate group Id and group Id greater than 0 and exist.
|
|
|
|
* Validate group Id and group Id greater than 0 and exist.
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -547,6 +416,10 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
String msg = "Error occurred while retrieving role list of user '" + authorizedUser + "'";
|
|
|
|
String msg = "Error occurred while retrieving role list of user '" + authorizedUser + "'";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
|
|
|
}catch (BadRequestException e){
|
|
|
|
|
|
|
|
String msg = "Error occurred while validating the device group.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PaginationResult result = dms.getAllDevices(request, false);
|
|
|
|
PaginationResult result = dms.getAllDevices(request, false);
|
|
|
@ -563,7 +436,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).entity(devices).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(devices).build();
|
|
|
|
} catch (BadRequestException e) {
|
|
|
|
} catch (BadRequestException e) {
|
|
|
|
String msg = "Invalid type, use either 'path' or 'full'";
|
|
|
|
String msg = "Invalid type, use either [path] or [full]";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
} catch (UnAuthorizedException e) {
|
|
|
|
} catch (UnAuthorizedException e) {
|
|
|
@ -597,12 +470,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
boolean response = deviceManagementProviderService.disenrollDevice(deviceIdentifier);
|
|
|
|
boolean response = deviceManagementProviderService.disenrollDevice(deviceIdentifier);
|
|
|
|
return Response.status(Response.Status.OK).entity(response).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(response).build();
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
String msg = "Error encountered while deleting device of type : " + deviceType + " and " +
|
|
|
|
String msg = "Error encountered while deleting requested device of type : " + deviceType ;
|
|
|
|
"ID : " + deviceId;
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()
|
|
|
|
|
|
|
|
).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -624,11 +494,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
|
|
|
|
|
|
|
|
return Response.status(Response.Status.CREATED).entity(response).build();
|
|
|
|
return Response.status(Response.Status.CREATED).entity(response).build();
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
log.error("Error encountered while updating device of type : " + deviceType + " and " +
|
|
|
|
String msg = "Error encountered while updating requested device of type : " + deviceType ;
|
|
|
|
"ID : " + deviceId);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage("Error while updating " +
|
|
|
|
|
|
|
|
"device of type " + deviceType + " and ID : " + deviceId).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -669,10 +537,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
sinceDate = format.parse(ifModifiedSince);
|
|
|
|
sinceDate = format.parse(ifModifiedSince);
|
|
|
|
deviceData.setLastModifiedDate(sinceDate);
|
|
|
|
deviceData.setLastModifiedDate(sinceDate);
|
|
|
|
} catch (ParseException e) {
|
|
|
|
} catch (ParseException e) {
|
|
|
|
String msg = "Invalid date string is provided in 'If-Modified-Since' header";
|
|
|
|
String msg = "Invalid date string is provided in [If-Modified-Since] header";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -699,9 +566,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity("No device is modified " +
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity("No device is modified " +
|
|
|
|
"after the timestamp provided in 'If-Modified-Since' header").build();
|
|
|
|
"after the timestamp provided in 'If-Modified-Since' header").build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
|
|
|
String msg = "Requested device of type " + type + " does not exist";
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_NOT_FOUND).setMessage("Requested device of type '" +
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
|
|
|
type + "', which carries id '" + id + "' does not exist").build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).entity(device).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(device).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -722,7 +588,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
dms);
|
|
|
|
dms);
|
|
|
|
return Response.status(Response.Status.OK).entity(snapshotWrapper).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(snapshotWrapper).build();
|
|
|
|
} catch (BadRequestException e) {
|
|
|
|
} catch (BadRequestException e) {
|
|
|
|
String msg = "Invalid type, use either 'path' or 'full'";
|
|
|
|
String msg = "Invalid type, use either [path] or [full]";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
} catch (UnAuthorizedException e) {
|
|
|
|
} catch (UnAuthorizedException e) {
|
|
|
@ -768,12 +634,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
sinceDate = format.parse(ifModifiedSince);
|
|
|
|
sinceDate = format.parse(ifModifiedSince);
|
|
|
|
} catch (ParseException e) {
|
|
|
|
} catch (ParseException e) {
|
|
|
|
String message = "Error occurred while parse the since date.Invalid date string is provided in " +
|
|
|
|
String message = "Invalid date string is provided in [If-Modified-Since] header";
|
|
|
|
"'If-Modified-Since' header";
|
|
|
|
|
|
|
|
log.error(message, e);
|
|
|
|
log.error(message, e);
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage("Invalid date " +
|
|
|
|
|
|
|
|
"string is provided in 'If-Modified-Since' header").build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sinceDate != null) {
|
|
|
|
if (sinceDate != null) {
|
|
|
@ -782,16 +645,15 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
String message = "No device is modified after the timestamp provided in 'If-Modified-Since' header";
|
|
|
|
String message = "No device is modified after the timestamp provided in 'If-Modified-Since' header";
|
|
|
|
log.error(message);
|
|
|
|
log.error(message);
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity("No device is modified " +
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity("No device is modified " +
|
|
|
|
"after the timestamp provided in 'If-Modified-Since' header").build();
|
|
|
|
"after the timestamp provided in [If-Modified-Since] header").build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
device = dms.getDevice(id, requireDeviceInfo);
|
|
|
|
device = dms.getDevice(id, requireDeviceInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (device == null) {
|
|
|
|
if (device == null) {
|
|
|
|
String message = "Device does not exist with id '" + id + "'";
|
|
|
|
String message = "Device does not exist";
|
|
|
|
log.error(message);
|
|
|
|
log.error(message);
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage(message).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, device.getType());
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(id, device.getType());
|
|
|
|
// check whether the user is authorized
|
|
|
|
// check whether the user is authorized
|
|
|
@ -816,6 +678,32 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
return Response.status(Response.Status.OK).entity(device).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(device).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
|
|
|
|
@Path("/enrollment/guide")
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Response sendEnrollmentGuide(String enrolmentGuide) {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Sending enrollment invitation mail to existing user.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
|
|
|
|
|
|
|
if (!config.getEnrollmentGuideConfiguration().isEnabled()) {
|
|
|
|
|
|
|
|
String msg = "Sending enrollment guide config is not enabled.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
dms.sendEnrolmentGuide(enrolmentGuide);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build();
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred sending mail to group in enrollment guide";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
@Path("/type/any/list")
|
|
|
|
@Path("/type/any/list")
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -823,7 +711,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService =
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService =
|
|
|
|
DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
if (deviceIds == null || deviceIds.isEmpty()) {
|
|
|
|
if (deviceIds == null || deviceIds.isEmpty()) {
|
|
|
|
String msg = "Required values of device identifiers are not set..";
|
|
|
|
String msg = "Required values of device identifiers are not set.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -887,6 +775,107 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).entity(deviceInfo).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(deviceInfo).build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
|
|
|
@Path("/{type}/{id}/config")
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Response getDeviceConfiguration(
|
|
|
|
|
|
|
|
@PathParam("type") @Size(max = 45) String type,
|
|
|
|
|
|
|
|
@PathParam("id") @Size(max = 45) String id,
|
|
|
|
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceConfig deviceConfig = new DeviceConfig();
|
|
|
|
|
|
|
|
deviceConfig.setDeviceId(id);
|
|
|
|
|
|
|
|
deviceConfig.setType(type);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// find token validity time
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService =
|
|
|
|
|
|
|
|
DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
|
|
|
|
int validityTime = 3600;
|
|
|
|
|
|
|
|
// add scopes for event topics
|
|
|
|
|
|
|
|
List<String> mqttEventTopicStructure = new ArrayList<>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
DeviceType deviceType = deviceManagementProviderService.getDeviceType(type);
|
|
|
|
|
|
|
|
if (deviceType != null) {
|
|
|
|
|
|
|
|
if (deviceType.getDeviceTypeMetaDefinition().isLongLivedToken()) {
|
|
|
|
|
|
|
|
validityTime = Integer.MAX_VALUE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mqttEventTopicStructure = deviceType.getDeviceTypeMetaDefinition().getMqttEventTopicStructures();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String msg = "Device not found, device id : " + id + ", device type : " + type;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while retrieving device, device id : " + id + ", device type : " + type;
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
|
|
|
|
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
|
|
|
String applicationName = type.replace(" ", "").replace("_", "")
|
|
|
|
|
|
|
|
+ "_" + tenantDomain;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KeyMgtService keyMgtService = new KeyMgtServiceImpl();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
DCRResponse dcrResponse = keyMgtService.dynamicClientRegistration(applicationName, username,
|
|
|
|
|
|
|
|
"client_credentials", null, new String[] {"device_management"}, false, validityTime);
|
|
|
|
|
|
|
|
deviceConfig.setClientId(dcrResponse.getClientId());
|
|
|
|
|
|
|
|
deviceConfig.setClientSecret(dcrResponse.getClientSecret());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder scopes = new StringBuilder("device_" + type.replace(" ", "")
|
|
|
|
|
|
|
|
.replace("_", "") + "_" + id);
|
|
|
|
|
|
|
|
for (String topic : mqttEventTopicStructure) {
|
|
|
|
|
|
|
|
if (topic.contains("${deviceId}")) {
|
|
|
|
|
|
|
|
topic = topic.replace("${deviceId}", id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
topic = topic.replace("/",":");
|
|
|
|
|
|
|
|
// scopes.append(" perm:topic:sub:".concat(topic));
|
|
|
|
|
|
|
|
scopes.append(" perm:topic:pub:".concat(topic));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add scopes for retrieve operation topic /tenantDomain/deviceType/deviceId/operation/#
|
|
|
|
|
|
|
|
scopes.append(" perm:topic:sub:" + tenantDomain + ":" + type + ":" + id + ":operation");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add scopes for update operation /tenantDomain/deviceType/deviceId/update/operation
|
|
|
|
|
|
|
|
scopes.append(" perm:topic:pub:" + tenantDomain + ":" + type + ":" + id + ":update:operation");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TokenRequest tokenRequest = new TokenRequest(dcrResponse.getClientId(), dcrResponse.getClientSecret(),
|
|
|
|
|
|
|
|
null, scopes.toString(), "client_credentials", null,
|
|
|
|
|
|
|
|
null, null, null, validityTime);
|
|
|
|
|
|
|
|
TokenResponse tokenResponse = keyMgtService.generateAccessToken(tokenRequest);
|
|
|
|
|
|
|
|
deviceConfig.setAccessToken(tokenResponse.getAccessToken());
|
|
|
|
|
|
|
|
deviceConfig.setRefreshToken(tokenResponse.getRefreshToken());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
deviceConfig.setPlatformConfiguration(deviceManagementProviderService.getConfiguration(type));
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while reading platform configurations token, device id : " + id + ", device type : " + type;
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deviceConfig.setMqttGateway("tcp://" + System.getProperty("mqtt.broker.host") + ":" + System.getProperty("mqtt.broker.port"));
|
|
|
|
|
|
|
|
deviceConfig.setHttpGateway("http://" + System.getProperty("iot.gateway.host") + ":" + System.getProperty("iot.gateway.http.port"));
|
|
|
|
|
|
|
|
deviceConfig.setHttpsGateway("https://" + System.getProperty("iot.gateway.host") + ":" + System.getProperty("iot.gateway.https.port"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (KeyMgtException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while creating oauth application, device id : " + id + ", device type : " + type;
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
} catch (org.wso2.carbon.apimgt.keymgt.extension.exception.BadRequestException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while generating token, device id : " + id + ", device type : " + type;
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Response.status(Response.Status.OK).entity(deviceConfig).build();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
@ -903,9 +892,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
fm = dms.getFeatureManager(type);
|
|
|
|
fm = dms.getFeatureManager(type);
|
|
|
|
} catch (DeviceTypeNotFoundException e) {
|
|
|
|
} catch (DeviceTypeNotFoundException e) {
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
|
|
|
String msg = "No device type found with name : " + type ;
|
|
|
|
new ErrorResponse.ErrorResponseBuilder()
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
|
|
|
.setMessage("No device type found with name '" + type + "'").build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fm != null) {
|
|
|
|
if (fm != null) {
|
|
|
|
features = fm.getFeatures();
|
|
|
|
features = fm.getFeatures();
|
|
|
@ -1126,8 +1114,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
return Response.serverError().entity(
|
|
|
|
return Response.serverError().entity(
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
} catch (InputValidationException e) {
|
|
|
|
} catch (InputValidationException e) {
|
|
|
|
String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " +
|
|
|
|
String msg = "Error occurred while fetching the operations for the type : " + type + " device";
|
|
|
|
"carries the id '" + id + "'";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
@ -1136,7 +1123,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
} catch (DeviceTypeNotFoundException e) {
|
|
|
|
} catch (DeviceTypeNotFoundException e) {
|
|
|
|
String msg = "No device type found with name '" + type + "'";
|
|
|
|
String msg = "No device type found with name : " + type ;
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1246,11 +1233,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
boolean response = deviceManagementProviderService.changeDeviceStatus(deviceIdentifier, newsStatus);
|
|
|
|
boolean response = deviceManagementProviderService.changeDeviceStatus(deviceIdentifier, newsStatus);
|
|
|
|
return Response.status(Response.Status.OK).entity(response).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(response).build();
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
String msg = "Error occurred while changing device status of type : " + type + " and " +
|
|
|
|
String msg = "Error occurred while changing device status of device type : " + type ;
|
|
|
|
"device id : " + id;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1262,7 +1247,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
* @return {@link Response} object
|
|
|
|
* @return {@link Response} object
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Path("/{type}/{id}/getstatushistory")
|
|
|
|
@Path("/{type}/{id}/status-history")
|
|
|
|
public Response getDeviceStatusHistory(@PathParam("type") @Size(max = 45) String type,
|
|
|
|
public Response getDeviceStatusHistory(@PathParam("type") @Size(max = 45) String type,
|
|
|
|
@PathParam("id") @Size(max = 45) String id) {
|
|
|
|
@PathParam("id") @Size(max = 45) String id) {
|
|
|
|
//TODO check authorization for this
|
|
|
|
//TODO check authorization for this
|
|
|
@ -1278,11 +1263,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
List<DeviceStatus> deviceStatusHistory = deviceManagementProviderService.getDeviceStatusHistory(persistedDevice);
|
|
|
|
List<DeviceStatus> deviceStatusHistory = deviceManagementProviderService.getDeviceStatusHistory(persistedDevice);
|
|
|
|
return Response.status(Response.Status.OK).entity(deviceStatusHistory).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(deviceStatusHistory).build();
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
String msg = "Error occurred while retreiving device status history for device of type : " + type + " and " +
|
|
|
|
String msg = "Error occurred while retrieving device status history for device of type : " + type ;
|
|
|
|
"device id : " + id;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1294,7 +1277,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
* @return {@link Response} object
|
|
|
|
* @return {@link Response} object
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Path("/{type}/{id}/getenrolmentstatushistory")
|
|
|
|
@Path("/{type}/{id}/enrolment-status-history")
|
|
|
|
public Response getCurrentEnrolmentDeviceStatusHistory(@PathParam("type") @Size(max = 45) String type,
|
|
|
|
public Response getCurrentEnrolmentDeviceStatusHistory(@PathParam("type") @Size(max = 45) String type,
|
|
|
|
@PathParam("id") @Size(max = 45) String id) {
|
|
|
|
@PathParam("id") @Size(max = 45) String id) {
|
|
|
|
//TODO check authorization for this or current enrolment should be based on for the enrolment associated with the user
|
|
|
|
//TODO check authorization for this or current enrolment should be based on for the enrolment associated with the user
|
|
|
@ -1310,11 +1293,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
List<DeviceStatus> deviceStatusHistory = deviceManagementProviderService.getDeviceCurrentEnrolmentStatusHistory(persistedDevice);
|
|
|
|
List<DeviceStatus> deviceStatusHistory = deviceManagementProviderService.getDeviceCurrentEnrolmentStatusHistory(persistedDevice);
|
|
|
|
return Response.status(Response.Status.OK).entity(deviceStatusHistory).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(deviceStatusHistory).build();
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
String msg = "Error occurred while retreiving device status history for device of type : " + type + " and " +
|
|
|
|
String msg = "Error occurred while retrieving device status history for device of type : " + type;
|
|
|
|
"device id : " + id;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1391,7 +1372,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
String errorMessage = "Issue in retrieving deivce management service instance";
|
|
|
|
String errorMessage = "Issue in retrieving device management service instance";
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
|
|
|
@ -1591,7 +1572,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
DeviceType deviceTypeObj = DeviceManagerUtil.getDeviceType(
|
|
|
|
DeviceType deviceTypeObj = DeviceManagerUtil.getDeviceType(
|
|
|
|
deviceType, tenantId);
|
|
|
|
deviceType, tenantId);
|
|
|
|
if (deviceTypeObj == null) {
|
|
|
|
if (deviceTypeObj == null) {
|
|
|
|
String msg = "Error, device of type: " + deviceType + " does not exist";
|
|
|
|
String msg = "Device of type: " + deviceType + " does not exist";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|