Merge pull request #1163 from rasika/fix-1611

Isolating Geo Location Enabling Configuration
revert-70aa11f8
Rasika Perera 7 years ago committed by GitHub
commit a406dd0540
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -70,7 +70,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
@PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
@QueryParam("from") long from, @QueryParam("to") long to) { @QueryParam("from") long from, @QueryParam("to") long to) {
try { try {
if (!DeviceManagerUtil.isPublishOperationResponseEnabled()) { if (!DeviceManagerUtil.isPublishLocationResponseEnabled()) {
return Response.status(Response.Status.BAD_REQUEST.getStatusCode()) return Response.status(Response.Status.BAD_REQUEST.getStatusCode())
.entity("Unable to retrive Geo Device stats. Geo Data publishing does not enabled.").build(); .entity("Unable to retrive Geo Device stats. Geo Data publishing does not enabled.").build();
} }

@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.core.config;
import org.wso2.carbon.device.mgt.core.config.archival.ArchivalConfiguration; import org.wso2.carbon.device.mgt.core.config.archival.ArchivalConfiguration;
import org.wso2.carbon.device.mgt.core.config.cache.CertificateCacheConfiguration; import org.wso2.carbon.device.mgt.core.config.cache.CertificateCacheConfiguration;
import org.wso2.carbon.device.mgt.core.config.geo.location.GeoLocationConfiguration;
import org.wso2.carbon.device.mgt.core.config.geo.location.OperationAnalyticsConfiguration; import org.wso2.carbon.device.mgt.core.config.geo.location.OperationAnalyticsConfiguration;
import org.wso2.carbon.device.mgt.core.config.cache.DeviceCacheConfiguration; import org.wso2.carbon.device.mgt.core.config.cache.DeviceCacheConfiguration;
import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations;
@ -53,6 +54,7 @@ public final class DeviceManagementConfig {
private DeviceCacheConfiguration deviceCacheConfiguration; private DeviceCacheConfiguration deviceCacheConfiguration;
private CertificateCacheConfiguration certificateCacheConfiguration; private CertificateCacheConfiguration certificateCacheConfiguration;
private OperationAnalyticsConfiguration operationAnalyticsConfiguration; private OperationAnalyticsConfiguration operationAnalyticsConfiguration;
private GeoLocationConfiguration geoLocationConfiguration;
private String defaultGroupsConfiguration; private String defaultGroupsConfiguration;
private RemoteSessionConfiguration remoteSessionConfiguration; private RemoteSessionConfiguration remoteSessionConfiguration;
private ArchivalConfiguration archivalConfiguration; private ArchivalConfiguration archivalConfiguration;
@ -167,6 +169,15 @@ public final class DeviceManagementConfig {
this.operationAnalyticsConfiguration = operationAnalyticsConfiguration; this.operationAnalyticsConfiguration = operationAnalyticsConfiguration;
} }
@XmlElement(name = "GeoLocationConfiguration", required = true)
public GeoLocationConfiguration getGeoLocationConfiguration() {
return geoLocationConfiguration;
}
public void setGeoLocationConfiguration(GeoLocationConfiguration geoLocationConfiguration) {
this.geoLocationConfiguration = geoLocationConfiguration;
}
@XmlElement(name = "DefaultGroupsConfiguration", required = true) @XmlElement(name = "DefaultGroupsConfiguration", required = true)
public String getDefaultGroupsConfiguration() { public String getDefaultGroupsConfiguration() {
return defaultGroupsConfiguration; return defaultGroupsConfiguration;

@ -0,0 +1,40 @@
/*
* Copyright (c) 2018, 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.core.config.geo.location;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* This class represents the information related to Geo Location configuration.
*/
@XmlRootElement(name = "GeoLocationConfiguration")
public class GeoLocationConfiguration {
private boolean enabled;
public boolean getEnabled() {
return enabled;
}
@XmlElement(name = "Enabled", required = true)
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

@ -27,24 +27,24 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "OperationAnalyticsConfiguration") @XmlRootElement(name = "OperationAnalyticsConfiguration")
public class OperationAnalyticsConfiguration { public class OperationAnalyticsConfiguration {
private boolean publishOperationResponse; private boolean publishDeviceInfoResponse;
private boolean isEnabled; private boolean publishLocationResponse;
public boolean getPublishOperationResponse() { public boolean getPublishDeviceInfoResponse() {
return publishOperationResponse; return publishDeviceInfoResponse;
} }
@XmlElement(name = "PublishOperationResponse", required = true) @XmlElement(name = "PublishDeviceInfoResponse", required = true)
public void setPublishOperationResponse(boolean publishOperationResponse) { public void setPublishDeviceInfoResponse(boolean publishDeviceInfoResponse) {
this.publishOperationResponse = publishOperationResponse; this.publishDeviceInfoResponse = publishDeviceInfoResponse;
} }
public boolean getIsEnabled() { public boolean getPublishLocationResponse() {
return isEnabled; return publishLocationResponse;
} }
@XmlElement(name = "isEnabled", required = true) @XmlElement(name = "PublishLocationResponse", required = true)
public void setEnabled(boolean enabled) { public void setPublishLocationResponse(boolean publishLocationResponse) {
isEnabled = enabled; this.publishLocationResponse = publishLocationResponse;
} }
} }

@ -74,7 +74,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
deviceDetailsDAO.addDeviceProperties(deviceInfo.getDeviceDetailsMap(), device.getId()); deviceDetailsDAO.addDeviceProperties(deviceInfo.getDeviceDetailsMap(), device.getId());
DeviceManagementDAOFactory.commitTransaction(); DeviceManagementDAOFactory.commitTransaction();
if (DeviceManagerUtil.isPublishOperationResponseEnabled()) { if (DeviceManagerUtil.isPublishDeviceInfoResponseEnabled()) {
Object[] metaData = {device.getDeviceIdentifier(), device.getType()}; Object[] metaData = {device.getDeviceIdentifier(), device.getType()};
Object[] payload = new Object[]{ Object[] payload = new Object[]{
Calendar.getInstance().getTimeInMillis(), Calendar.getInstance().getTimeInMillis(),
@ -192,7 +192,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
deviceDAO.updateDevice(device, CarbonContext.getThreadLocalCarbonContext().getTenantId()); deviceDAO.updateDevice(device, CarbonContext.getThreadLocalCarbonContext().getTenantId());
deviceDetailsDAO.deleteDeviceLocation(deviceLocation.getDeviceId()); deviceDetailsDAO.deleteDeviceLocation(deviceLocation.getDeviceId());
deviceDetailsDAO.addDeviceLocation(deviceLocation); deviceDetailsDAO.addDeviceLocation(deviceLocation);
if (DeviceManagerUtil.isPublishOperationResponseEnabled()) { if (DeviceManagerUtil.isPublishLocationResponseEnabled()) {
Object[] metaData = {device.getDeviceIdentifier(), device.getType()}; Object[] metaData = {device.getDeviceIdentifier(), device.getType()};
Object[] payload = new Object[]{ Object[] payload = new Object[]{
deviceLocation.getUpdatedTime().getTime(), deviceLocation.getUpdatedTime().getTime(),

@ -31,7 +31,6 @@ import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.TransactionManagementException; import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
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.notification.mgt.NotificationManagementException; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
@ -416,23 +415,22 @@ public final class DeviceManagerUtil {
return limit; return limit;
} }
public static boolean isOperationAnalyticsEnabled() throws DeviceManagementException { public static boolean isPublishLocationResponseEnabled() throws DeviceManagementException {
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().
getDeviceManagementConfig(); getDeviceManagementConfig();
if (deviceManagementConfig != null) { if (deviceManagementConfig != null) {
return deviceManagementConfig.getOperationAnalyticsConfiguration().getIsEnabled(); return deviceManagementConfig.getOperationAnalyticsConfiguration().getPublishLocationResponse();
} else { } else {
throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " + throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " +
"cdm-config.xml file."); "cdm-config.xml file.");
} }
} }
public static boolean isPublishOperationResponseEnabled() throws DeviceManagementException { public static boolean isPublishDeviceInfoResponseEnabled() throws DeviceManagementException {
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().
getDeviceManagementConfig(); getDeviceManagementConfig();
if (deviceManagementConfig != null) { if (deviceManagementConfig != null) {
return isOperationAnalyticsEnabled() return deviceManagementConfig.getOperationAnalyticsConfiguration().getPublishDeviceInfoResponse();
&& deviceManagementConfig.getOperationAnalyticsConfiguration().getPublishOperationResponse();
} else { } else {
throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " + throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " +
"cdm-config.xml file."); "cdm-config.xml file.");

@ -88,9 +88,24 @@
<Enable>false</Enable> <Enable>false</Enable>
<ExpiryTime>86400</ExpiryTime> <ExpiryTime>86400</ExpiryTime>
</CertificateCacheConfiguration> </CertificateCacheConfiguration>
<GeoLocationConfiguration>
<Enabled>false</Enabled>
</GeoLocationConfiguration>
<OperationAnalyticsConfiguration> <OperationAnalyticsConfiguration>
<isEnabled>false</isEnabled> <PublishLocationResponse>false</PublishLocationResponse>
<PublishOperationResponse>false</PublishOperationResponse> <PublishDeviceInfoResponse>false</PublishDeviceInfoResponse>
<PublishOperationResponse>
<Enabled>false</Enabled>
<Operations>
<!-- Publish specific operation responses -->
<!--
<Operation>BATTERY_LEVEL</Operation>
<Operation>CHECK_LOCK_STATUS</Operation>
-->
<!-- use wildcard '*' to publish all responses -->
<Operation>*</Operation>
</Operations>
</PublishOperationResponse>
</OperationAnalyticsConfiguration> </OperationAnalyticsConfiguration>
<DefaultGroupsConfiguration>BYOD,COPE</DefaultGroupsConfiguration> <DefaultGroupsConfiguration>BYOD,COPE</DefaultGroupsConfiguration>
</DeviceMgtConfiguration> </DeviceMgtConfiguration>

@ -73,7 +73,7 @@ deviceModule = function () {
} }
var userName = carbonUser.username + "@" + carbonUser.domain; var userName = carbonUser.username + "@" + carbonUser.domain;
var locationHistory = []; var locationHistory = [];
var geoServicesEnabled = devicemgtProps.serverConfig.operationAnalyticsConfiguration.isEnabled; var geoServicesEnabled = devicemgtProps.serverConfig.geoLocationConfiguration.enabled;
if (geoServicesEnabled) { if (geoServicesEnabled) {
try { try {
var fromDate = new Date(); var fromDate = new Date();

@ -60,6 +60,6 @@ function onRequest(context) {
} else { } else {
viewModel.lastLocation = stringify({}); viewModel.lastLocation = stringify({});
} }
viewModel.geoServicesEnabled = devicemgtProps.serverConfig.operationAnalyticsConfiguration.isEnabled; viewModel.geoServicesEnabled = devicemgtProps.serverConfig.geoLocationConfiguration.enabled;
return viewModel; return viewModel;
} }

@ -70,7 +70,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
@PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
@QueryParam("from") long from, @QueryParam("to") long to) { @QueryParam("from") long from, @QueryParam("to") long to) {
try { try {
if (!DeviceManagerUtil.isPublishOperationResponseEnabled()) { if (!DeviceManagerUtil.isPublishLocationResponseEnabled()) {
return Response.status(Response.Status.BAD_REQUEST.getStatusCode()) return Response.status(Response.Status.BAD_REQUEST.getStatusCode())
.entity("Unable to retrive Geo Device stats. Geo Data publishing does not enabled.").build(); .entity("Unable to retrive Geo Device stats. Geo Data publishing does not enabled.").build();
} }

@ -118,9 +118,24 @@
</PurgingTask> </PurgingTask>
</ArchivalTask> </ArchivalTask>
</ArchivalConfiguration> </ArchivalConfiguration>
<GeoLocationConfiguration>
<Enabled>false</Enabled>
</GeoLocationConfiguration>
<OperationAnalyticsConfiguration> <OperationAnalyticsConfiguration>
<isEnabled>false</isEnabled> <PublishLocationResponse>false</PublishLocationResponse>
<PublishOperationResponse>false</PublishOperationResponse> <PublishDeviceInfoResponse>false</PublishDeviceInfoResponse>
<PublishOperationResponse>
<Enabled>false</Enabled>
<Operations>
<!-- Publish specific operation responses -->
<!--
<Operation>BATTERY_LEVEL</Operation>
<Operation>CHECK_LOCK_STATUS</Operation>
-->
<!-- use wildcard '*' to publish all responses -->
<Operation>*</Operation>
</Operations>
</PublishOperationResponse>
</OperationAnalyticsConfiguration> </OperationAnalyticsConfiguration>
<!--This configuration used to configure the options for remote device control feature --> <!--This configuration used to configure the options for remote device control feature -->
<RemoteSessionConfiguration> <RemoteSessionConfiguration>

Loading…
Cancel
Save