Merge branch 'reporting-sync' into 'reporting'

Add report syncing functionality

See merge request entgra/carbon-device-mgt!556
reporting
Saad Sahibjan 5 years ago
commit 6cd10570b0

@ -168,5 +168,6 @@ public final class DeviceManagementConstants {
public static final String REPORTING_CONTEXT = "/reporting/api/analyticsadmin/v1.0/event";
public static final String DEVICE_INFO_PARAM = "device-info";
public static final String APP_USAGE_ENDPOINT = REPORTING_CONTEXT + "/app-usage";
public static final String ENROLLMENT_INFO_ENDPOINT = REPORTING_CONTEXT + "/enrolment-info";
}
}

@ -57,6 +57,7 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.DevicePropertyInfo;
import org.wso2.carbon.device.mgt.common.configuration.mgt.EnrollmentConfiguration;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.device.details.DeviceData;
import org.wso2.carbon.device.mgt.common.device.details.DeviceDetailsWrapper;
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.DeviceLocationHistorySnapshot;
@ -67,6 +68,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.BadRequestException;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceTypeNotFoundException;
import org.wso2.carbon.device.mgt.common.exceptions.EventPublishingException;
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.UnauthorizedDeviceAccessException;
@ -114,6 +116,7 @@ import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent
import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.device.mgt.core.util.HttpReportingUtil;
import org.wso2.carbon.email.sender.core.ContentProviderInfo;
import org.wso2.carbon.email.sender.core.EmailContext;
import org.wso2.carbon.email.sender.core.EmailSendingFailedException;
@ -395,6 +398,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
addInitialOperations(deviceIdentifier, device.getType());
sendNotification(device);
Runnable task = () -> syncReportingApp(device, tenantId);
new Thread(task).start();
}
extractDeviceLocationToUpdate(device);
try {
@ -4186,4 +4191,26 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection();
}
}
/**
* Sync with reporting App
*
* @param device Enrolling Device
* @param tenantId Tenant Id
*/
private void syncReportingApp (Device device, int tenantId) {
String reportingHost = HttpReportingUtil.getReportingHost();
if (StringUtils.isNotBlank(reportingHost) && HttpReportingUtil.isPublishingEnabledForTenant()) {
DeviceDetailsWrapper deviceDetailsWrapper = new DeviceDetailsWrapper();
deviceDetailsWrapper.setTenantId(tenantId);
deviceDetailsWrapper.setDevice(device);
try {
HttpReportingUtil.invokeApi(deviceDetailsWrapper.getJSONString(),
reportingHost + DeviceManagementConstants.Report.ENROLLMENT_INFO_ENDPOINT);
} catch (EventPublishingException e) {
log.warn("Error occurred while syncing with reporting app");
}
}
}
}

Loading…
Cancel
Save