From e33f28bf8a378290edbd7186c488fbd54a771da2 Mon Sep 17 00:00:00 2001 From: Turcy Date: Mon, 9 Sep 2019 23:49:24 +0530 Subject: [PATCH 1/2] Sort device analytics data --- .../jaxrs/service/impl/DeviceEventManagementServiceImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java index 2bbcee2d43a..44ea053b346 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java @@ -106,7 +106,9 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe List recordIds = getRecordIds(resultEntries); AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds); eventRecords.setCount(eventCount); - eventRecords.setList(AnalyticsDataAPIUtil.listRecords(analyticsDataAPI, response)); + List records = AnalyticsDataAPIUtil.listRecords(analyticsDataAPI, response); + records.sort((Record r1, Record r2) -> Long.compare(r2.getTimestamp(), r1.getTimestamp())); + eventRecords.setList(records); return eventRecords; } From cebc18bef695eea7790f8321007a6489113fd28e Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 12 Sep 2019 16:19:36 +0530 Subject: [PATCH 2/2] Fix server starting issue This issue is occurred as a result of having java8 codes in the source. Hence remove and replace the code. --- .../api/DeviceEventManagementService.java | 30 ++++++++----------- .../DeviceEventManagementServiceImpl.java | 7 ++++- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java index c49f9698c1b..a1356ab436f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceEventManagementService.java @@ -13,19 +13,15 @@ import io.swagger.annotations.SwaggerDefinition; import io.swagger.annotations.Tag; import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; -import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.DeviceTypeEvent; -import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventAttributeList; import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventRecords; -import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.TransportType; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -66,8 +62,7 @@ import javax.ws.rs.core.Response; } ) @Path("/events") -@Api(value = "Device Event Management", description = "This API corresponds to all tasks related to device " + - "event management") +@Api(value = "Device Event Management") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public interface DeviceEventManagementService { @@ -120,13 +115,14 @@ public interface DeviceEventManagementService { response = ErrorResponse.class) } ) - Response deployDeviceTypeEventDefinition(@ApiParam(name = "type", value = "The device type, such as android, ios," + - " and windows.", required = false) - @PathParam("type")String deviceType, - @QueryParam("skipPersist")boolean skipPersist, - @ApiParam(name = "deviceTypeEvent", value = "Add the data to complete " + - "the DeviceTypeEvent object.", required = true) - @Valid DeviceTypeEvent deviceTypeEvent); + Response deployDeviceTypeEventDefinition( + @ApiParam(name = "type", value = "The device type, such as android, ios, and windows.") + @PathParam("type")String deviceType, + @ApiParam(name = "skipPersist", value = "Is it required to persist the data or not") + @QueryParam("skipPersist") boolean skipPersist, + @ApiParam(name = "deviceTypeEvent", value = "Add the data to complete the DeviceTypeEvent object.", + required = true) + @Valid DeviceTypeEvent deviceTypeEvent); @DELETE @Path("/{type}") @@ -358,7 +354,6 @@ public interface DeviceEventManagementService { @QueryParam("max") double max ); - @GET @Path("/{type}") @ApiOperation( @@ -408,8 +403,7 @@ public interface DeviceEventManagementService { response = ErrorResponse.class) } ) - Response getDeviceTypeEventDefinition(@ApiParam(name = "type", value = "The type of the device, such as android," + - " ios, or windows.", required = false) - @PathParam("type")String deviceType) ; - + Response getDeviceTypeEventDefinition( + @ApiParam(name = "type", value = "The type of the device, such as android, ios, or windows.") + @PathParam("type")String deviceType) ; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java index b33d044d22a..0d711ed0976 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceEventManagementServiceImpl.java @@ -54,6 +54,7 @@ import javax.ws.rs.core.Response; import java.rmi.RemoteException; import java.util.ArrayList; import java.util.Calendar; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -107,7 +108,11 @@ public class DeviceEventManagementServiceImpl implements DeviceEventManagementSe AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds); eventRecords.setCount(eventCount); List records = AnalyticsDataAPIUtil.listRecords(analyticsDataAPI, response); - records.sort((Record r1, Record r2) -> Long.compare(r2.getTimestamp(), r1.getTimestamp())); + records.sort(new Comparator() { + @Override public int compare(Record r1, Record r2) { + return Long.compare(r2.getTimestamp(), r1.getTimestamp()); + } + }); eventRecords.setList(records); return eventRecords; }