commented braking changes related to analytics

kernel-4.6.x
Amalka Subasinghe 3 years ago
parent d090fef2ac
commit 51dd72ff79

@ -363,11 +363,11 @@
<version>${carbon.identity.framework.version}</version> <version>${carbon.identity.framework.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <!--<dependency>-->
<groupId>org.wso2.carbon.analytics</groupId> <!--<groupId>org.wso2.carbon.analytics</groupId>-->
<artifactId>org.wso2.carbon.analytics.dataservice.commons</artifactId> <!--<artifactId>org.wso2.carbon.analytics.dataservice.commons</artifactId>-->
<scope>provided</scope> <!--<scope>provided</scope>-->
</dependency> <!--</dependency>-->
<dependency> <dependency>
<groupId>org.wso2.carbon.analytics-common</groupId> <groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.receiver.stub</artifactId> <artifactId>org.wso2.carbon.event.receiver.stub</artifactId>

@ -27,12 +27,12 @@ import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.wso2.carbon.analytics.api.AnalyticsDataAPI; import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
import org.wso2.carbon.analytics.api.AnalyticsDataAPIUtil; import org.wso2.carbon.analytics.api.AnalyticsDataAPIUtil;
import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse; //import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse;
import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry; //import org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry;
import org.wso2.carbon.analytics.dataservice.commons.SortByField; //import org.wso2.carbon.analytics.dataservice.commons.SortByField;
import org.wso2.carbon.analytics.dataservice.commons.SortType; //import org.wso2.carbon.analytics.dataservice.commons.SortType;
import org.wso2.carbon.analytics.datasource.commons.Record; //import org.wso2.carbon.analytics.datasource.commons.Record;
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; //import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
import org.wso2.carbon.context.CarbonContext; 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.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
@ -120,40 +120,40 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
if (from != 0 || to != 0) { if (from != 0 || to != 0) {
query += " AND timeStamp : [" + fromDate + " TO " + toDate + "]"; query += " AND timeStamp : [" + fromDate + " TO " + toDate + "]";
} }
try { // try {
if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized( // if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized(
new DeviceIdentifier(deviceId, deviceType), // new DeviceIdentifier(deviceId, deviceType),
DeviceGroupConstants.Permissions.DEFAULT_STATS_MONITOR_PERMISSIONS)) { // DeviceGroupConstants.Permissions.DEFAULT_STATS_MONITOR_PERMISSIONS)) {
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); // return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
} // }
List<SortByField> sortByFields = new ArrayList<>(); // List<SortByField> sortByFields = new ArrayList<>();
SortByField sortByField = new SortByField("timeStamp", SortType.ASC); // SortByField sortByField = new SortByField("timeStamp", SortType.ASC);
sortByFields.add(sortByField); // sortByFields.add(sortByField);
// this is the user who initiates the request // this is the user who initiates the request
String authorizedUser = MultitenantUtils.getTenantAwareUsername( // String authorizedUser = MultitenantUtils.getTenantAwareUsername(
CarbonContext.getThreadLocalCarbonContext().getUsername()); // CarbonContext.getThreadLocalCarbonContext().getUsername());
try { // try {
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); // String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain); // int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain);
AnalyticsDataAPI analyticsDataAPI = DeviceMgtAPIUtils.getAnalyticsDataAPI(); AnalyticsDataAPI analyticsDataAPI = DeviceMgtAPIUtils.getAnalyticsDataAPI();
List<SearchResultEntry> searchResults = analyticsDataAPI.search(tenantId, tableName, query, // List<SearchResultEntry> searchResults = analyticsDataAPI.search(tenantId, tableName, query,
0, // 0,
100, // 100,
sortByFields); // sortByFields);
List<Event> events = getEventBeans(analyticsDataAPI, tenantId, tableName, new ArrayList<String>(), // List<Event> events = getEventBeans(analyticsDataAPI, tenantId, tableName, new ArrayList<String>(),
searchResults); // searchResults);
return Response.ok().entity(events).build(); // return Response.ok().entity(events).build();
} catch (AnalyticsException | UserStoreException e) { // } catch (AnalyticsException | UserStoreException e) {
log.error("Failed to perform search on table: " + tableName + " : " + e.getMessage(), e); // log.error("Failed to perform search on table: " + tableName + " : " + e.getMessage(), e);
throw DeviceMgtUtil.buildBadRequestException( // throw DeviceMgtUtil.buildBadRequestException(
Constants.ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT); // Constants.ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT);
} // }
} catch (DeviceAccessAuthorizationException e) { // } catch (DeviceAccessAuthorizationException e) {
log.error(e.getErrorMessage()); // log.error(e.getErrorMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
} // }
} }
@Path("stats/device-locations") @Path("stats/device-locations")
@ -559,40 +559,40 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
if (from != 0 || to != 0) { if (from != 0 || to != 0) {
query += " AND timeStamp : [" + fromDate + " TO " + toDate + "]"; query += " AND timeStamp : [" + fromDate + " TO " + toDate + "]";
} }
try { // try {
if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized( // if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized(
new DeviceIdentifier(deviceId, deviceType), // new DeviceIdentifier(deviceId, deviceType),
DeviceGroupConstants.Permissions.DEFAULT_STATS_MONITOR_PERMISSIONS)) { // DeviceGroupConstants.Permissions.DEFAULT_STATS_MONITOR_PERMISSIONS)) {
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); // return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
} // }
List<SortByField> sortByFields = new ArrayList<>(); // List<SortByField> sortByFields = new ArrayList<>();
SortByField sortByField = new SortByField("timeStamp", SortType.ASC); // SortByField sortByField = new SortByField("timeStamp", SortType.ASC);
sortByFields.add(sortByField); // sortByFields.add(sortByField);
// this is the user who initiates the request // this is the user who initiates the request
String authorizedUser = MultitenantUtils.getTenantAwareUsername( // String authorizedUser = MultitenantUtils.getTenantAwareUsername(
CarbonContext.getThreadLocalCarbonContext().getUsername()); // CarbonContext.getThreadLocalCarbonContext().getUsername());
try { // try {
String tenantDomain = MultitenantUtils.getTenantDomain(authorizedUser); // String tenantDomain = MultitenantUtils.getTenantDomain(authorizedUser);
int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain); // int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain);
AnalyticsDataAPI analyticsDataAPI = DeviceMgtAPIUtils.getAnalyticsDataAPI(); // AnalyticsDataAPI analyticsDataAPI = DeviceMgtAPIUtils.getAnalyticsDataAPI();
List<SearchResultEntry> searchResults = analyticsDataAPI.search(tenantId, tableName, query, // List<SearchResultEntry> searchResults = analyticsDataAPI.search(tenantId, tableName, query,
0, // 0,
100, // 100,
sortByFields); // sortByFields);
List<Event> events = getEventBeans(analyticsDataAPI, tenantId, tableName, new ArrayList<String>(), // List<Event> events = getEventBeans(analyticsDataAPI, tenantId, tableName, new ArrayList<String>(),
searchResults); // searchResults);
return Response.ok().entity(events).build(); // return Response.ok().entity(events).build();
} catch (AnalyticsException | UserStoreException e) { // } catch (AnalyticsException | UserStoreException e) {
log.error("Failed to perform search on table: " + tableName + " : " + e.getMessage(), e); // log.error("Failed to perform search on table: " + tableName + " : " + e.getMessage(), e);
throw DeviceMgtUtil.buildBadRequestException( // throw DeviceMgtUtil.buildBadRequestException(
Constants.ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT); // Constants.ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT);
} // }
} catch (DeviceAccessAuthorizationException e) { // } catch (DeviceAccessAuthorizationException e) {
log.error(e.getErrorMessage()); // log.error(e.getErrorMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
} // }
} }
@Path("alerts/history") @Path("alerts/history")
@ -607,80 +607,80 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
if (from != 0 || to != 0) { if (from != 0 || to != 0) {
query = "timeStamp : [" + fromDate + " TO " + toDate + "]"; query = "timeStamp : [" + fromDate + " TO " + toDate + "]";
} }
try { // try {
List<SortByField> sortByFields = new ArrayList<>(); // List<SortByField> sortByFields = new ArrayList<>();
SortByField sortByField = new SortByField("timeStamp", SortType.ASC); // SortByField sortByField = new SortByField("timeStamp", SortType.ASC);
sortByFields.add(sortByField); // sortByFields.add(sortByField);
//
// this is the user who initiates the request // // this is the user who initiates the request
String authorizedUser = MultitenantUtils.getTenantAwareUsername( // String authorizedUser = MultitenantUtils.getTenantAwareUsername(
CarbonContext.getThreadLocalCarbonContext().getUsername()); // CarbonContext.getThreadLocalCarbonContext().getUsername());
//
String tenantDomain = MultitenantUtils.getTenantDomain(authorizedUser); // String tenantDomain = MultitenantUtils.getTenantDomain(authorizedUser);
int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain); // int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain);
AnalyticsDataAPI analyticsDataAPI = DeviceMgtAPIUtils.getAnalyticsDataAPI(); // AnalyticsDataAPI analyticsDataAPI = DeviceMgtAPIUtils.getAnalyticsDataAPI();
List<SearchResultEntry> searchResults = analyticsDataAPI.search(tenantId, tableName, query, // List<SearchResultEntry> searchResults = analyticsDataAPI.search(tenantId, tableName, query,
0, // 0,
100, // 100,
sortByFields); // sortByFields);
List<Event> events = getEventBeans(analyticsDataAPI, tenantId, tableName, new ArrayList<String>(), // List<Event> events = getEventBeans(analyticsDataAPI, tenantId, tableName, new ArrayList<String>(),
searchResults); // searchResults);
return Response.ok().entity(events).build(); // return Response.ok().entity(events).build();
//
} catch (AnalyticsException | UserStoreException e) { // } catch (AnalyticsException | UserStoreException e) {
log.error("Failed to perform search on table: " + tableName + " : " + e.getMessage(), e); // log.error("Failed to perform search on table: " + tableName + " : " + e.getMessage(), e);
throw DeviceMgtUtil.buildBadRequestException( throw DeviceMgtUtil.buildBadRequestException(
Constants.ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT); Constants.ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT);
} // }
} }
private List<Event> getEventBeans(AnalyticsDataAPI analyticsDataAPI, int tenantId, String tableName, // private List<Event> getEventBeans(AnalyticsDataAPI analyticsDataAPI, int tenantId, String tableName,
List<String> columns, // List<String> columns,
List<SearchResultEntry> searchResults) throws AnalyticsException { // List<SearchResultEntry> searchResults) throws AnalyticsException {
List<String> ids = getIds(searchResults); // List<String> ids = getIds(searchResults);
List<String> requiredColumns = (columns == null || columns.isEmpty()) ? null : columns; // List<String> requiredColumns = (columns == null || columns.isEmpty()) ? null : columns;
AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, requiredColumns, ids); // AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, requiredColumns, ids);
List<Record> records = AnalyticsDataAPIUtil.listRecords(analyticsDataAPI, response); // List<Record> records = AnalyticsDataAPIUtil.listRecords(analyticsDataAPI, response);
Map<String, Event> eventBeanMap = getEventBeanKeyedWithIds(records); // Map<String, Event> eventBeanMap = getEventBeanKeyedWithIds(records);
return getSortedEventBeans(eventBeanMap, searchResults); // return getSortedEventBeans(eventBeanMap, searchResults);
} // }
//
private List<Event> getSortedEventBeans(Map<String, Event> eventBeanMap, // private List<Event> getSortedEventBeans(Map<String, Event> eventBeanMap,
List<SearchResultEntry> searchResults) { // List<SearchResultEntry> searchResults) {
List<Event> sortedRecords = new ArrayList<>(); // List<Event> sortedRecords = new ArrayList<>();
for (SearchResultEntry entry : searchResults) { // for (SearchResultEntry entry : searchResults) {
sortedRecords.add(eventBeanMap.get(entry.getId())); // sortedRecords.add(eventBeanMap.get(entry.getId()));
} // }
return sortedRecords; // return sortedRecords;
} // }
//
private Map<String, Event> getEventBeanKeyedWithIds(List<Record> records) { // private Map<String, Event> getEventBeanKeyedWithIds(List<Record> records) {
Map<String, Event> eventBeanMap = new HashMap<>(); // Map<String, Event> eventBeanMap = new HashMap<>();
for (Record record : records) { // for (Record record : records) {
Event event = getEventBean(record); // Event event = getEventBean(record);
eventBeanMap.put(event.getId(), event); // eventBeanMap.put(event.getId(), event);
} // }
return eventBeanMap; // return eventBeanMap;
} // }
//
private List<String> getIds(List<SearchResultEntry> searchResults) { // private List<String> getIds(List<SearchResultEntry> searchResults) {
List<String> ids = new ArrayList<>(); // List<String> ids = new ArrayList<>();
if (searchResults != null) { // if (searchResults != null) {
for (SearchResultEntry resultEntry : searchResults) { // for (SearchResultEntry resultEntry : searchResults) {
ids.add(resultEntry.getId()); // ids.add(resultEntry.getId());
} // }
} // }
return ids; // return ids;
} // }
//
private static Event getEventBean(Record record) { // private static Event getEventBean(Record record) {
Event eventBean = new Event(); // Event eventBean = new Event();
eventBean.setId(record.getId()); // eventBean.setId(record.getId());
eventBean.setTableName(record.getTableName()); // eventBean.setTableName(record.getTableName());
eventBean.setTimestamp(record.getTimestamp()); // eventBean.setTimestamp(record.getTimestamp());
eventBean.setValues(record.getValues()); // eventBean.setValues(record.getValues());
return eventBean; // return eventBean;
} // }
@Path("/geo-fence") @Path("/geo-fence")
@POST @POST

Loading…
Cancel
Save