mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'corrective-policy' into 'master'
Add Corrective Policy and Geo-Fence Features Closes product-iots#656 See merge request entgra/carbon-device-mgt!660
This commit is contained in:
commit
b7b8bf6b96
@ -17,5 +17,5 @@
|
||||
package org.wso2.carbon.device.application.mgt.common;
|
||||
|
||||
public enum DeviceTypes {
|
||||
ANDROID, IOS
|
||||
ANDROID, IOS, WINDOWS
|
||||
}
|
||||
|
||||
@ -31,6 +31,10 @@ public class Application {
|
||||
required = true)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(name = "installerName",
|
||||
value = "Application Installer Name")
|
||||
private String installerName;
|
||||
|
||||
@ApiModelProperty(name = "description",
|
||||
value = "Description of the application",
|
||||
required = true)
|
||||
@ -173,4 +177,8 @@ public class Application {
|
||||
public boolean isAndroidEnterpriseApp() { return isAndroidEnterpriseApp; }
|
||||
|
||||
public void setAndroidEnterpriseApp(boolean androidEnterpriseApp) { isAndroidEnterpriseApp = androidEnterpriseApp; }
|
||||
|
||||
public String getInstallerName() { return installerName; }
|
||||
|
||||
public void setInstallerName(String installerName) { this.installerName = installerName; }
|
||||
}
|
||||
|
||||
@ -87,6 +87,10 @@ public class ApplicationRelease {
|
||||
value = "Application Rating")
|
||||
private double rating;
|
||||
|
||||
@ApiModelProperty(name = "packageName",
|
||||
value = "package name of the application")
|
||||
private String packageName;
|
||||
|
||||
public String getReleaseType() {
|
||||
return releaseType;
|
||||
}
|
||||
@ -162,4 +166,8 @@ public class ApplicationRelease {
|
||||
public List<String> getScreenshots() { return screenshots; }
|
||||
|
||||
public void setScreenshots(List<String> screenshots) { this.screenshots = screenshots; }
|
||||
|
||||
public String getPackageName() { return packageName; }
|
||||
|
||||
public void setPackageName(String packageName) { this.packageName = packageName; }
|
||||
}
|
||||
|
||||
@ -281,6 +281,16 @@ public interface ApplicationManager {
|
||||
|
||||
String getInstallableLifecycleState() throws ApplicationManagementException;
|
||||
|
||||
/**
|
||||
* Check if there are subscription devices for operations
|
||||
*
|
||||
* @param operationId Id of the operation
|
||||
* @param deviceId deviceId of the relevant device
|
||||
* @return boolean value either true or false according to the situation
|
||||
* @throws ApplicationManagementException
|
||||
*/
|
||||
boolean checkSubDeviceIdsForOperations(int operationId, int deviceId) throws ApplicationManagementException;
|
||||
|
||||
void updateSubsStatus (int deviceId, int operationId, String status) throws ApplicationManagementException;
|
||||
|
||||
|
||||
|
||||
@ -60,6 +60,14 @@ public class EntAppReleaseWrapper {
|
||||
@NotNull
|
||||
private String supportedOsVersions;
|
||||
|
||||
@ApiModelProperty(name = "version",
|
||||
value = "Version number of the applications installer specifically for windows")
|
||||
private String version;
|
||||
|
||||
@ApiModelProperty(name = "packageName",
|
||||
value = "PackageName of the application installer specifically for windows")
|
||||
private String packageName;
|
||||
|
||||
public String getReleaseType() {
|
||||
return releaseType;
|
||||
}
|
||||
@ -99,4 +107,20 @@ public class EntAppReleaseWrapper {
|
||||
public String getSupportedOsVersions() { return supportedOsVersions; }
|
||||
|
||||
public void setSupportedOsVersions(String supportedOsVersions) { this.supportedOsVersions = supportedOsVersions; }
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,14 +173,14 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
||||
if (deviceTypeId != -1) {
|
||||
sql += "AND AP_APP.DEVICE_TYPE_ID = ? ";
|
||||
}
|
||||
sql += "GROUP BY AP_APP.ID ";
|
||||
sql += "GROUP BY AP_APP.ID ORDER BY AP_APP.ID ";
|
||||
if (StringUtils.isNotEmpty(filter.getSortBy())) {
|
||||
sql += "ORDER BY ID " + filter.getSortBy() +" ";
|
||||
sql += filter.getSortBy() +" ";
|
||||
}
|
||||
if (filter.getLimit() != -1) {
|
||||
sql += "LIMIT ? OFFSET ? ";
|
||||
}
|
||||
sql += ") AS app_data ON app_data.ID = AP_APP.ID WHERE AP_APP.TENANT_ID = ?";
|
||||
sql += ") AS app_data ON app_data.ID = AP_APP.ID WHERE AP_APP.TENANT_ID = ? ORDER BY AP_APP.ID";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
|
||||
@ -118,15 +118,14 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl {
|
||||
if (deviceTypeId != -1) {
|
||||
sql += "AND AP_APP.DEVICE_TYPE_ID = ? ";
|
||||
}
|
||||
sql += "GROUP BY AP_APP.ID ";
|
||||
sql += "GROUP BY AP_APP.ID ORDER BY AP_APP.ID ";
|
||||
if (StringUtils.isNotEmpty(filter.getSortBy())) {
|
||||
sql += "ORDER BY ID " + filter.getSortBy() + " ";
|
||||
sql += filter.getSortBy() +" ";
|
||||
}
|
||||
if (filter.getLimit() != -1) {
|
||||
sql += "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY ";
|
||||
}
|
||||
sql += ") AS app_data ON app_data.ID = AP_APP.ID " +
|
||||
"WHERE AP_APP.TENANT_ID = ?";
|
||||
sql += ") AS app_data ON app_data.ID = AP_APP.ID WHERE AP_APP.TENANT_ID = ? ORDER BY AP_APP.ID";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
|
||||
@ -117,15 +117,14 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl {
|
||||
if (deviceTypeId != -1) {
|
||||
sql += "AND AP_APP.DEVICE_TYPE_ID = ? ";
|
||||
}
|
||||
sql += "GROUP BY AP_APP.ID ";
|
||||
sql += "GROUP BY AP_APP.ID ORDER BY AP_APP.ID ";
|
||||
if (StringUtils.isNotEmpty(filter.getSortBy())) {
|
||||
sql += "ORDER BY ID " + filter.getSortBy() + " ";
|
||||
sql += filter.getSortBy() +" ";
|
||||
}
|
||||
if (filter.getLimit() != -1) {
|
||||
sql += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY ";
|
||||
}
|
||||
sql += ") AS app_data ON app_data.ID = AP_APP.ID " +
|
||||
"WHERE AP_APP.TENANT_ID = ?";
|
||||
sql += ") AS app_data ON app_data.ID = AP_APP.ID WHERE AP_APP.TENANT_ID = ? ORDER BY AP_APP.ID";
|
||||
try {
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
|
||||
@ -141,6 +141,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
}
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper);
|
||||
|
||||
//uploading application artifacts
|
||||
ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts(
|
||||
applicationDTO.getApplicationReleaseDTOs().get(0), applicationArtifact,
|
||||
@ -338,24 +339,36 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
|
||||
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
|
||||
try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
|
||||
if (!DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
|
||||
ApplicationInstaller applicationInstaller = applicationStorageManager
|
||||
.getAppInstallerData(binary, deviceType);
|
||||
String packagename = applicationInstaller.getPackageName();
|
||||
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
|
||||
applicationReleaseDTO.setPackageName(applicationInstaller.getPackageName());
|
||||
} else {
|
||||
String windowsInstallerName = applicationArtifact.getInstallerName();
|
||||
String extension = windowsInstallerName.substring(windowsInstallerName.lastIndexOf(".") + 1);
|
||||
if (!extension.equalsIgnoreCase(Constants.MSI) &&
|
||||
!extension.equalsIgnoreCase(Constants.APPX)) {
|
||||
String msg = "Application Type doesn't match with supporting application types of " +
|
||||
deviceType + "platform which are APPX and MSI";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
String packageName = applicationReleaseDTO.getPackageName();
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
if (!isNewRelease && applicationReleaseDAO
|
||||
.isActiveReleaseExisitForPackageName(packagename, tenantId,
|
||||
.isActiveReleaseExisitForPackageName(packageName, tenantId,
|
||||
lifecycleStateManager.getEndState())) {
|
||||
String msg = "Application release is already exist for the package name: " + packagename
|
||||
+ ". Either you can delete all application releases for package " + packagename + " or "
|
||||
String msg = "Application release is already exist for the package name: " + packageName
|
||||
+ ". Either you can delete all application releases for package " + packageName + " or "
|
||||
+ "you can add this app release as an new application release, under the existing "
|
||||
+ "application.";
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
|
||||
applicationReleaseDTO.setPackageName(packagename);
|
||||
String md5OfApp = StorageManagementUtil.getMD5(new ByteArrayInputStream(content));
|
||||
if (md5OfApp == null) {
|
||||
String msg = "Error occurred while md5sum value retrieving process: application UUID "
|
||||
@ -1012,6 +1025,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
|
||||
ApplicationReleaseDTO applicationReleaseDTO = uploadEntAppReleaseArtifacts(
|
||||
APIUtil.releaseWrapperToReleaseDTO(entAppReleaseWrapper), applicationArtifact, deviceType.getName(),
|
||||
tenantId, true);
|
||||
@ -1909,13 +1923,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
int deviceTypeId;
|
||||
if (!deviceTypeName.equals(Constants.ALL)) {
|
||||
DeviceType deviceType = deviceManagementProviderService.getDeviceType(deviceTypeName);
|
||||
deviceTypeId = deviceType.getId();
|
||||
if (deviceType == null) {
|
||||
String msg = "Device type doesn't exist. Hence check the application name existence with valid "
|
||||
+ "device type name.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
deviceTypeId = deviceType.getId();
|
||||
} else {
|
||||
//For web-clips device type = 'ALL'
|
||||
deviceTypeId = 0;
|
||||
@ -2662,6 +2676,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(releaseUuid, tenantId);
|
||||
DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
||||
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
|
||||
applicationDTO.getApplicationReleaseDTOs().get(0));
|
||||
validateAppReleaseUpdating(entAppReleaseWrapper, applicationDTO, applicationArtifact,
|
||||
@ -2681,9 +2696,18 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
applicationReleaseDTO.get().setMetaData(entAppReleaseWrapper.getMetaData());
|
||||
}
|
||||
|
||||
//If the application device type is WINDOWS, it is allowed to modify version number and package name.
|
||||
if (DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceTypeObj.getName())) {
|
||||
if (!StringUtils.isEmpty(entAppReleaseWrapper.getVersion())) {
|
||||
applicationReleaseDTO.get().setVersion(entAppReleaseWrapper.getVersion());
|
||||
}
|
||||
if (!StringUtils.isEmpty(entAppReleaseWrapper.getPackageName())) {
|
||||
applicationReleaseDTO.get().setPackageName(entAppReleaseWrapper.getPackageName());
|
||||
}
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(applicationArtifact.getInstallerName())
|
||||
&& applicationArtifact.getInstallerStream() != null) {
|
||||
DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
||||
applicationReleaseDTO
|
||||
.set(updateEntAppReleaseArtifact(deviceTypeObj.getName(), applicationReleaseDTO.get(),
|
||||
applicationArtifact));
|
||||
@ -3326,6 +3350,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
//Validating the version number and the packageName of the Windows new applications releases
|
||||
if (DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
|
||||
if (entAppReleaseWrapper.get().getVersion() == null || entAppReleaseWrapper.get().getPackageName() == null) {
|
||||
String msg = "Application Version number or/and PackageName..both are required only when the app type is " +
|
||||
deviceType + " platform type";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
} else if (param instanceof WebAppReleaseWrapper) {
|
||||
WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param;
|
||||
UrlValidator urlValidator = new UrlValidator();
|
||||
@ -3414,18 +3447,31 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkSubDeviceIdsForOperations(int operationId, int deviceId) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
List<Integer> deviceSubIds = subscriptionDAO.getDeviceSubIdsForOperation(operationId, deviceId, tenantId);
|
||||
if (deviceSubIds.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg = "Error occurred while getting the device sub ids for the operations";
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementException(msg, e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSubsStatus (int deviceId, int operationId, String status) throws ApplicationManagementException {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
List<Integer> deviceSubIds = subscriptionDAO.getDeviceSubIdsForOperation(operationId, deviceId, tenantId);
|
||||
if (deviceSubIds.isEmpty()){
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Couldn't find device subscription for operation id " + operationId;
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
if (!subscriptionDAO.updateDeviceSubStatus(deviceId, deviceSubIds, status, tenantId)){
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
String msg = "Didn't update an any app subscription of device for operation Id: " + operationId;
|
||||
|
||||
@ -82,6 +82,7 @@ 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.util.MDMAndroidOperationUtil;
|
||||
import org.wso2.carbon.device.mgt.core.util.MDMIOSOperationUtil;
|
||||
import org.wso2.carbon.device.mgt.core.util.MDMWindowsOperationUtil;
|
||||
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
@ -108,7 +109,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
private LifecycleStateManager lifecycleStateManager;
|
||||
|
||||
public SubscriptionManagerImpl() {
|
||||
lifecycleStateManager = DataHolder.getInstance().getLifecycleStateManager();
|
||||
this.lifecycleStateManager = DataHolder.getInstance().getLifecycleStateManager();
|
||||
this.subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO();
|
||||
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
||||
}
|
||||
@ -549,7 +550,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
boolean isValidSubType = Arrays.stream(SubscriptionType.values())
|
||||
.anyMatch(sub -> sub.name().equalsIgnoreCase(subType));
|
||||
if (!isValidSubType) {
|
||||
String msg = "Found invalid subscription type " + subType+ " to install application release" ;
|
||||
String msg = "Found invalid subscription type " + subType+ " to subscribe application release" ;
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
@ -579,8 +580,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
ApplicationDTO applicationDTO, String subType, List<String> subscribers, String action)
|
||||
throws ApplicationManagementException {
|
||||
|
||||
//Get app subscribing info of each device
|
||||
SubscribingDeviceIdHolder subscribingDeviceIdHolder = getSubscribingDeviceIdHolder(devices,
|
||||
applicationDTO.getApplicationReleaseDTOs().get(0).getId());
|
||||
|
||||
List<Activity> activityList = new ArrayList<>();
|
||||
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
||||
List<DeviceIdentifier> ignoredDeviceIdentifiers = new ArrayList<>();
|
||||
@ -1020,6 +1023,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
} else if (DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
|
||||
app.setType(mobileAppType);
|
||||
app.setIdentifier(application.getPackageName());
|
||||
app.setMetaData(application.getApplicationReleases().get(0).getMetaData());
|
||||
app.setName(application.getInstallerName());
|
||||
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
||||
return MDMWindowsOperationUtil.createInstallAppOperation(app);
|
||||
} else {
|
||||
String msg = "Invalid Action is found. Action: " + action;
|
||||
log.error(msg);
|
||||
throw new ApplicationManagementException(msg);
|
||||
}
|
||||
} else {
|
||||
String msg = "Invalid device type is found. Device Type: " + deviceType;
|
||||
log.error(msg);
|
||||
|
||||
@ -304,6 +304,10 @@ public class APIUtil {
|
||||
applicationReleaseDTO.setIsSharedWithAllTenants(entAppReleaseWrapper.getIsSharedWithAllTenants());
|
||||
applicationReleaseDTO.setMetaData(entAppReleaseWrapper.getMetaData());
|
||||
applicationReleaseDTO.setSupportedOsVersions(entAppReleaseWrapper.getSupportedOsVersions());
|
||||
//Setting version number value specifically for windows type and in an instance of android and ios it will be null
|
||||
applicationReleaseDTO.setVersion(entAppReleaseWrapper.getVersion());
|
||||
//Setting package name value specifically for windows type and in an instance of android and ios it will be null
|
||||
applicationReleaseDTO.setPackageName(entAppReleaseWrapper.getPackageName());
|
||||
} else if (param instanceof WebAppReleaseWrapper){
|
||||
WebAppReleaseWrapper webAppReleaseWrapper = (WebAppReleaseWrapper) param;
|
||||
applicationReleaseDTO.setDescription(webAppReleaseWrapper.getDescription());
|
||||
@ -358,6 +362,7 @@ public class APIUtil {
|
||||
application.setTags(applicationDTO.getTags());
|
||||
application.setUnrestrictedRoles(applicationDTO.getUnrestrictedRoles());
|
||||
application.setRating(applicationDTO.getAppRating());
|
||||
application.setInstallerName(applicationDTO.getApplicationReleaseDTOs().get(0).getInstallerName());
|
||||
List<ApplicationRelease> applicationReleases = new ArrayList<>();
|
||||
if (ApplicationType.PUBLIC.toString().equals(applicationDTO.getType()) && application.getCategories()
|
||||
.contains("GooglePlaySyncedApp")) {
|
||||
@ -384,6 +389,7 @@ public class APIUtil {
|
||||
|
||||
applicationRelease.setDescription(applicationReleaseDTO.getDescription());
|
||||
applicationRelease.setVersion(applicationReleaseDTO.getVersion());
|
||||
applicationRelease.setPackageName(applicationReleaseDTO.getPackageName());
|
||||
applicationRelease.setUuid(applicationReleaseDTO.getUuid());
|
||||
applicationRelease.setReleaseType(applicationReleaseDTO.getReleaseType());
|
||||
applicationRelease.setPrice(applicationReleaseDTO.getPrice());
|
||||
|
||||
@ -65,6 +65,10 @@ public class Constants {
|
||||
public static final String SUBSCRIBED = "SUBSCRIBED";
|
||||
public static final String UNSUBSCRIBED = "UNSUBSCRIBED";
|
||||
|
||||
//App type constants related to window device type
|
||||
public static final String MSI = "MSI";
|
||||
public static final String APPX = "APPX";
|
||||
|
||||
private static final Map<String, String> AGENT_DATA = new HashMap<>();
|
||||
static {
|
||||
AGENT_DATA.put("android", "android-agent.apk");
|
||||
|
||||
@ -334,7 +334,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while creating a costom application";
|
||||
String msg = "Error occurred while creating a custom application";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (RequestValidatingException e) {
|
||||
@ -373,6 +373,10 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
log.error("ApplicationDTO Creation Failed");
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
} catch (BadRequestException e) {
|
||||
String msg = "Found incompatible payload with enterprise app release creating request.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (ApplicationManagementException e) {
|
||||
String msg = "Error occurred while creating the application";
|
||||
log.error(msg, e);
|
||||
@ -716,7 +720,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
.changeLifecycleState(applicationUuid, lifecycleChanger);
|
||||
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
|
||||
} catch (BadRequestException e) {
|
||||
String msg = "Request payload contains invalid data, hence veryfy the request payload.";
|
||||
String msg = "Request payload contains invalid data, hence verify the request payload.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
} catch (ForbiddenException e) {
|
||||
@ -1005,10 +1009,10 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
}
|
||||
|
||||
if (attachmentList != null && !attachmentList.isEmpty()) {
|
||||
Map<String, InputStream> scrrenshotData = new TreeMap<>();
|
||||
Map<String, InputStream> screenshotData = new TreeMap<>();
|
||||
for (Attachment sc : attachmentList) {
|
||||
dataHandler = sc.getDataHandler();
|
||||
String screenshotrFileName = dataHandler.getName();
|
||||
String screenshotFileName = dataHandler.getName();
|
||||
InputStream screenshotStream = dataHandler.getInputStream();
|
||||
if (screenshotStream == null) {
|
||||
String msg =
|
||||
@ -1017,16 +1021,16 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (screenshotrFileName == null) {
|
||||
if (screenshotFileName == null) {
|
||||
String msg =
|
||||
"Screenshot file name retrieving is failed for one screenshot. Hence can't proceed. "
|
||||
+ "Please verify the screenshots.";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
scrrenshotData.put(screenshotrFileName, screenshotStream);
|
||||
screenshotData.put(screenshotFileName, screenshotStream);
|
||||
}
|
||||
applicationArtifact.setScreenshots(scrrenshotData);
|
||||
applicationArtifact.setScreenshots(screenshotData);
|
||||
}
|
||||
return applicationArtifact;
|
||||
} catch (IOException e) {
|
||||
|
||||
@ -85,6 +85,12 @@
|
||||
}
|
||||
},
|
||||
"deviceTypes": {
|
||||
"mobileTypes": ["android", "ios"]
|
||||
"mobileTypes": ["android", "ios", "windows"]
|
||||
},
|
||||
"windowsDeviceType": {
|
||||
"appType": ["msi", "appx"]
|
||||
},
|
||||
"windowsAppxMsiKeyValueForMetaData": {
|
||||
"metaKeyArray": ["Package_Url", "Dependency_Package_Url", "Certificate_Hash", "Encoded_Cert_Content", "Package_Family_Name", "Product_Id", "Content_Uri", "File_Hash"]
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +46,7 @@ class NewAppDetailsForm extends React.Component {
|
||||
categories: [],
|
||||
tags: [],
|
||||
deviceTypes: [],
|
||||
selectedValue: null,
|
||||
fetching: false,
|
||||
roleSearchValue: [],
|
||||
unrestrictedRoles: [],
|
||||
@ -312,12 +313,33 @@ class NewAppDetailsForm extends React.Component {
|
||||
});
|
||||
};
|
||||
|
||||
// Event handler for selecting the device type
|
||||
handleSelect = event => {
|
||||
this.setState({
|
||||
selectedValue: event,
|
||||
});
|
||||
if (this.props.selectedValueHandler) {
|
||||
this.props.selectedValueHandler(event);
|
||||
}
|
||||
};
|
||||
|
||||
// Event handler for selecting the windows app type
|
||||
handleSelectForAppType = event => {
|
||||
if (this.props.selectedAppTypeHandler) {
|
||||
this.props.selectedAppTypeHandler(event);
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const config = this.props.context;
|
||||
// Windows installation app types
|
||||
const appTypes = config.windowsDeviceType.appType;
|
||||
const { formConfig } = this.props;
|
||||
const {
|
||||
categories,
|
||||
tags,
|
||||
deviceTypes,
|
||||
selectedValue,
|
||||
fetching,
|
||||
unrestrictedRoles,
|
||||
} = this.state;
|
||||
@ -358,6 +380,7 @@ class NewAppDetailsForm extends React.Component {
|
||||
<Select
|
||||
style={{ width: '100%' }}
|
||||
placeholder="select device type"
|
||||
onSelect={this.handleSelect.bind(this)}
|
||||
>
|
||||
{deviceTypes.map(deviceType => {
|
||||
return (
|
||||
@ -396,6 +419,31 @@ class NewAppDetailsForm extends React.Component {
|
||||
})(<Input placeholder="ex: Lorem App" />)}
|
||||
</Form.Item>
|
||||
|
||||
{/* App Type only shown for windows device types for enterprise apps */}
|
||||
{selectedValue === 'windows' &&
|
||||
this.props.formConfig.installationType === 'ENTERPRISE' && (
|
||||
<Form.Item {...formItemLayout} label="App Type">
|
||||
{getFieldDecorator('appType', {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: 'Please select app type',
|
||||
},
|
||||
],
|
||||
})(
|
||||
<Select
|
||||
style={{ width: '100%' }}
|
||||
placeholder="select application type"
|
||||
onSelect={this.handleSelectForAppType}
|
||||
>
|
||||
{appTypes.map(appType => {
|
||||
return <Option key={appType}>{appType}</Option>;
|
||||
})}
|
||||
</Select>,
|
||||
)}
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{/* description*/}
|
||||
<Form.Item {...formItemLayout} label="Description">
|
||||
{getFieldDecorator('description', {
|
||||
|
||||
@ -33,6 +33,7 @@ import {
|
||||
} from 'antd';
|
||||
import '@babel/polyfill';
|
||||
import Authorized from '../../../../../../../../components/Authorized/Authorized';
|
||||
import { withConfigContext } from '../../../../../../../../components/ConfigContext';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
@ -59,6 +60,12 @@ function getBase64(file) {
|
||||
});
|
||||
}
|
||||
|
||||
// function for access the full name of the binary file using the installation path
|
||||
function extractBinaryFileName(installationPath) {
|
||||
let UploadedBinaryName = installationPath.split('/');
|
||||
return UploadedBinaryName[UploadedBinaryName.length - 1];
|
||||
}
|
||||
|
||||
class NewAppUploadForm extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@ -77,6 +84,7 @@ class NewAppUploadForm extends React.Component {
|
||||
osVersionsHelperText: '',
|
||||
osVersionsValidateStatus: 'validating',
|
||||
metaData: [],
|
||||
appType: null,
|
||||
};
|
||||
this.lowerOsVersion = null;
|
||||
this.upperOsVersion = null;
|
||||
@ -93,6 +101,8 @@ class NewAppUploadForm extends React.Component {
|
||||
e.preventDefault();
|
||||
const { formConfig } = this.props;
|
||||
const { specificElements } = formConfig;
|
||||
let windowsAppTypeMetaArray = [];
|
||||
let metaValue = [];
|
||||
|
||||
this.props.form.validateFields((err, values) => {
|
||||
if (!err) {
|
||||
@ -107,6 +117,19 @@ class NewAppUploadForm extends React.Component {
|
||||
releaseType,
|
||||
} = values;
|
||||
|
||||
/**
|
||||
* To save the metaData value that receive from
|
||||
* metaData UI In an windows app type creation
|
||||
*/
|
||||
if (
|
||||
((this.props.formConfig.installationType === 'ENTERPRISE' &&
|
||||
this.props.selectedValue === 'windows') ||
|
||||
this.props.deviceType === 'windows') &&
|
||||
this.state.metaData.length !== 0
|
||||
) {
|
||||
metaValue = [...this.state.metaData];
|
||||
}
|
||||
|
||||
// add release data
|
||||
const release = {
|
||||
description: releaseDescription,
|
||||
@ -116,6 +139,90 @@ class NewAppUploadForm extends React.Component {
|
||||
releaseType: releaseType,
|
||||
};
|
||||
|
||||
const data = new FormData();
|
||||
const config = this.props.context;
|
||||
// Accessing the Meta Key value for windows device type from the config.json file
|
||||
const metaKeyValues =
|
||||
config.windowsAppxMsiKeyValueForMetaData.metaKeyArray;
|
||||
|
||||
/*
|
||||
Setting up the app type specific values to the
|
||||
metaData state field and Setting up the version
|
||||
and the packageName for windows type
|
||||
*/
|
||||
if (
|
||||
(this.props.formConfig.installationType === 'ENTERPRISE' &&
|
||||
this.props.selectedValue === 'windows') ||
|
||||
this.props.deviceType === 'windows'
|
||||
) {
|
||||
// Setting up the version and packageName
|
||||
release.version = values.version;
|
||||
release.packageName = values.packageName;
|
||||
// setting the metaData value for appx type
|
||||
if (
|
||||
this.props.selectedAppType === 'appx' ||
|
||||
this.state.appType === 'appx'
|
||||
) {
|
||||
windowsAppTypeMetaArray = [
|
||||
{
|
||||
key: metaKeyValues[0],
|
||||
value: values.packageUrl,
|
||||
},
|
||||
{
|
||||
key: metaKeyValues[1],
|
||||
value: values.dependencyPackageUrl,
|
||||
},
|
||||
{
|
||||
key: metaKeyValues[2],
|
||||
value: values.certificateHash,
|
||||
},
|
||||
{
|
||||
key: metaKeyValues[3],
|
||||
value: values.encodedCertContent,
|
||||
},
|
||||
{
|
||||
key: metaKeyValues[4],
|
||||
value: values.packageName,
|
||||
},
|
||||
];
|
||||
windowsAppTypeMetaArray = [
|
||||
...windowsAppTypeMetaArray,
|
||||
...metaValue,
|
||||
];
|
||||
} else if (
|
||||
this.props.selectedAppType === 'msi' ||
|
||||
this.state.appType === 'msi'
|
||||
) {
|
||||
windowsAppTypeMetaArray = [
|
||||
{
|
||||
key: metaKeyValues[5],
|
||||
value: values.productId,
|
||||
},
|
||||
{
|
||||
key: metaKeyValues[6],
|
||||
value: values.contentUri,
|
||||
},
|
||||
{
|
||||
key: metaKeyValues[7],
|
||||
value: values.fileHash,
|
||||
},
|
||||
];
|
||||
windowsAppTypeMetaArray = [
|
||||
...windowsAppTypeMetaArray,
|
||||
...metaValue,
|
||||
];
|
||||
}
|
||||
this.setState(
|
||||
{
|
||||
metaData: windowsAppTypeMetaArray,
|
||||
},
|
||||
() => {
|
||||
release.metaData = JSON.stringify(this.state.metaData);
|
||||
this.props.onSuccessReleaseData({ data, release });
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (specificElements.hasOwnProperty('version')) {
|
||||
release.version = values.version;
|
||||
}
|
||||
@ -126,7 +233,6 @@ class NewAppUploadForm extends React.Component {
|
||||
release.packageName = values.packageName;
|
||||
}
|
||||
|
||||
const data = new FormData();
|
||||
let isFormValid = true; // flag to check if this form is valid
|
||||
|
||||
if (
|
||||
@ -187,9 +293,18 @@ class NewAppUploadForm extends React.Component {
|
||||
if (specificElements.hasOwnProperty('binaryFile')) {
|
||||
data.append('binaryFile', binaryFile[0].originFileObj);
|
||||
}
|
||||
// Condition to check is it not an Enterprise windows app creation or release
|
||||
if (
|
||||
!(
|
||||
this.props.selectedValue === 'windows' &&
|
||||
this.props.formConfig.installationType === 'ENTERPRISE'
|
||||
) &&
|
||||
this.props.deviceType !== 'windows'
|
||||
) {
|
||||
this.props.onSuccessReleaseData({ data, release });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -203,13 +318,44 @@ class NewAppUploadForm extends React.Component {
|
||||
icons: fileList,
|
||||
});
|
||||
};
|
||||
|
||||
handleBinaryFileChange = ({ fileList }) => {
|
||||
let validity = true;
|
||||
// To set the app type of windows by using the binary file in an new app release
|
||||
if (this.props.formConfig.isNewRelease && fileList.length !== 0) {
|
||||
let firstUploadedBinaryFileName = extractBinaryFileName(
|
||||
this.props.uploadedInstalltionAppType,
|
||||
);
|
||||
let FirstFileExtension = firstUploadedBinaryFileName.substr(
|
||||
firstUploadedBinaryFileName.lastIndexOf('.') + 1,
|
||||
);
|
||||
let LastFileExtension = fileList[0].name.substr(
|
||||
fileList[0].name.lastIndexOf('.') + 1,
|
||||
);
|
||||
if (FirstFileExtension !== LastFileExtension) {
|
||||
validity = false;
|
||||
} else if (LastFileExtension === 'msi' || LastFileExtension === 'appx') {
|
||||
this.setState({
|
||||
appType: LastFileExtension,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (fileList.length === 1) {
|
||||
this.setState({
|
||||
binaryFileHelperText: '',
|
||||
});
|
||||
}
|
||||
this.setState({ binaryFiles: fileList });
|
||||
|
||||
if (validity) {
|
||||
this.setState({
|
||||
binaryFiles: fileList,
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
binaryFileHelperText: 'Upload Correct Binary File extension',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
handleScreenshotChange = ({ fileList }) => {
|
||||
@ -266,6 +412,7 @@ class NewAppUploadForm extends React.Component {
|
||||
render() {
|
||||
const { formConfig, supportedOsVersions } = this.props;
|
||||
const { getFieldDecorator } = this.props.form;
|
||||
const config = this.props.context;
|
||||
const {
|
||||
icons,
|
||||
screenshots,
|
||||
@ -399,7 +546,12 @@ class NewAppUploadForm extends React.Component {
|
||||
</Text>
|
||||
</Col>
|
||||
</Row>
|
||||
{formConfig.specificElements.hasOwnProperty('packageName') && (
|
||||
|
||||
{/* Package Name field for windows device type and other specific scene using it */}
|
||||
{(formConfig.specificElements.hasOwnProperty('packageName') ||
|
||||
(this.props.formConfig.installationType === 'ENTERPRISE' &&
|
||||
this.props.selectedValue === 'windows') ||
|
||||
this.props.deviceType === 'windows') && (
|
||||
<Form.Item {...formItemLayout} label="Package Name">
|
||||
{getFieldDecorator('packageName', {
|
||||
rules: [
|
||||
@ -425,7 +577,11 @@ class NewAppUploadForm extends React.Component {
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{formConfig.specificElements.hasOwnProperty('version') && (
|
||||
{/* Version field for windows device type and other specific scene using it */}
|
||||
{(formConfig.specificElements.hasOwnProperty('version') ||
|
||||
(this.props.formConfig.installationType === 'ENTERPRISE' &&
|
||||
this.props.selectedValue === 'windows') ||
|
||||
this.props.deviceType === 'windows') && (
|
||||
<Form.Item {...formItemLayout} label="Version">
|
||||
{getFieldDecorator('version', {
|
||||
rules: [
|
||||
@ -438,6 +594,127 @@ class NewAppUploadForm extends React.Component {
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{/* Windows Appx App Type Fields */}
|
||||
{/* For Windows appx app type only -> Package Url */}
|
||||
{((this.props.formConfig.installationType === 'ENTERPRISE' &&
|
||||
this.props.selectedValue === 'windows' &&
|
||||
this.props.selectedAppType === 'appx') ||
|
||||
this.state.appType === 'appx') && (
|
||||
<Form.Item {...formItemLayout} label="Package Url">
|
||||
{getFieldDecorator('packageUrl', {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: 'Please input the package url',
|
||||
},
|
||||
],
|
||||
})(<Input placeholder="Package Url" />)}
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{/* For Windows appx app type only -> Dependency Package Url */}
|
||||
{((this.props.formConfig.installationType === 'ENTERPRISE' &&
|
||||
this.props.selectedValue === 'windows' &&
|
||||
this.props.selectedAppType === 'appx') ||
|
||||
this.state.appType === 'appx') && (
|
||||
<Form.Item {...formItemLayout} label="Dependency Package Url">
|
||||
{getFieldDecorator('dependencyPackageUrl', {})(
|
||||
<Input placeholder="Dependency Package Url" />,
|
||||
)}
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{/* For Windows appx app type only -> Certificate Hash */}
|
||||
{((this.props.formConfig.installationType === 'ENTERPRISE' &&
|
||||
this.props.selectedValue === 'windows' &&
|
||||
this.props.selectedAppType === 'appx') ||
|
||||
this.state.appType === 'appx') && (
|
||||
<Form.Item {...formItemLayout} label="Certificate Hash">
|
||||
{getFieldDecorator('certificateHash', {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: 'Please input the certificate hash',
|
||||
},
|
||||
],
|
||||
})(<Input placeholder="Certificate Hash" />)}
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{/* For Windows appx app type only -> Encoded Certificate Content */}
|
||||
{((this.props.formConfig.installationType === 'ENTERPRISE' &&
|
||||
this.props.selectedValue === 'windows' &&
|
||||
this.props.selectedAppType === 'appx') ||
|
||||
this.state.appType === 'appx') && (
|
||||
<Form.Item {...formItemLayout} label="Encoded Cert Content">
|
||||
{getFieldDecorator('encodedCertContent', {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: 'Give the encoded cert content',
|
||||
},
|
||||
],
|
||||
})(
|
||||
<TextArea
|
||||
placeholder="Enter a encoded certificate content"
|
||||
rows={5}
|
||||
/>,
|
||||
)}
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{/* Windows MSI App Type Fields */}
|
||||
{/* For Windows msi app type only -> Product Id */}
|
||||
{((this.props.formConfig.installationType === 'ENTERPRISE' &&
|
||||
this.props.selectedValue === 'windows' &&
|
||||
this.props.selectedAppType === 'msi') ||
|
||||
this.state.appType === 'msi') && (
|
||||
<Form.Item {...formItemLayout} label="Product Id">
|
||||
{getFieldDecorator('productId', {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: 'Please input the product id',
|
||||
},
|
||||
],
|
||||
})(<Input placeholder="Product Id" />)}
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{/* For Windows msi app type only -> Content URI */}
|
||||
{((this.props.formConfig.installationType === 'ENTERPRISE' &&
|
||||
this.props.selectedValue === 'windows' &&
|
||||
this.props.selectedAppType === 'msi') ||
|
||||
this.state.appType === 'msi') && (
|
||||
<Form.Item {...formItemLayout} label="Content URI">
|
||||
{getFieldDecorator('contentUri', {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: 'Please input the content uri',
|
||||
},
|
||||
],
|
||||
})(<Input placeholder="Content Uri" />)}
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{/* For Windows msi app type only -> File Hash */}
|
||||
{((this.props.formConfig.installationType === 'ENTERPRISE' &&
|
||||
this.props.selectedValue === 'windows' &&
|
||||
this.props.selectedAppType === 'msi') ||
|
||||
this.state.appType === 'msi') && (
|
||||
<Form.Item {...formItemLayout} label="File Hash">
|
||||
{getFieldDecorator('fileHash', {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: 'Please input the file hash',
|
||||
},
|
||||
],
|
||||
})(<Input placeholder="File Hash" />)}
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
<Form.Item {...formItemLayout} label="Release Type">
|
||||
{getFieldDecorator('releaseType', {
|
||||
rules: [
|
||||
@ -547,6 +824,15 @@ class NewAppUploadForm extends React.Component {
|
||||
{getFieldDecorator('meta', {})(
|
||||
<div>
|
||||
{metaData.map((data, index) => {
|
||||
/*
|
||||
Exclude showing the values related to
|
||||
windows app type variables in meta Data UI
|
||||
*/
|
||||
if (
|
||||
!config.windowsAppxMsiKeyValueForMetaData.metaKeyArray.includes(
|
||||
data.key,
|
||||
)
|
||||
) {
|
||||
return (
|
||||
<InputGroup key={index}>
|
||||
<Row gutter={8}>
|
||||
@ -567,7 +853,8 @@ class NewAppUploadForm extends React.Component {
|
||||
placeholder="value"
|
||||
value={data.value}
|
||||
onChange={e => {
|
||||
metaData[index].value = e.currentTarget.value;
|
||||
metaData[index].value =
|
||||
e.currentTarget.value;
|
||||
this.setState({
|
||||
metaData,
|
||||
});
|
||||
@ -590,6 +877,7 @@ class NewAppUploadForm extends React.Component {
|
||||
</Row>
|
||||
</InputGroup>
|
||||
);
|
||||
}
|
||||
})}
|
||||
<Button
|
||||
type="dashed"
|
||||
@ -633,4 +921,6 @@ class NewAppUploadForm extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
export default Form.create({ name: 'app-upload-form' })(NewAppUploadForm);
|
||||
export default withConfigContext(
|
||||
Form.create({ name: 'app-upload-form' })(NewAppUploadForm),
|
||||
);
|
||||
|
||||
@ -44,6 +44,8 @@ class AddNewAppFormComponent extends React.Component {
|
||||
release: null,
|
||||
isError: false,
|
||||
deviceType: null,
|
||||
selectedValue: null,
|
||||
selectedAppType: null,
|
||||
supportedOsVersions: [],
|
||||
errorText: '',
|
||||
forbiddenErrors: {
|
||||
@ -157,6 +159,20 @@ class AddNewAppFormComponent extends React.Component {
|
||||
});
|
||||
};
|
||||
|
||||
// For passing the device type as the prop for other component
|
||||
selectedValueHandler = selectedValue => {
|
||||
this.setState({
|
||||
selectedValue,
|
||||
});
|
||||
};
|
||||
|
||||
// For passing the app type as the prop for other component
|
||||
selectedAppTypeHandler = selectedAppType => {
|
||||
this.setState({
|
||||
selectedAppType,
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const {
|
||||
loading,
|
||||
@ -164,6 +180,8 @@ class AddNewAppFormComponent extends React.Component {
|
||||
isError,
|
||||
supportedOsVersions,
|
||||
errorText,
|
||||
selectedValue,
|
||||
selectedAppType,
|
||||
} = this.state;
|
||||
const { formConfig } = this.props;
|
||||
return (
|
||||
@ -180,18 +198,21 @@ class AddNewAppFormComponent extends React.Component {
|
||||
<div style={{ display: current === 0 ? 'unset' : 'none' }}>
|
||||
<NewAppDetailsForm
|
||||
formConfig={formConfig}
|
||||
selectedValueHandler={this.selectedValueHandler}
|
||||
selectedAppTypeHandler={this.selectedAppTypeHandler}
|
||||
onSuccessApplicationData={this.onSuccessApplicationData}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ display: current === 1 ? 'unset' : 'none' }}>
|
||||
<NewAppUploadForm
|
||||
formConfig={formConfig}
|
||||
selectedValue={selectedValue}
|
||||
selectedAppType={selectedAppType}
|
||||
supportedOsVersions={supportedOsVersions}
|
||||
onSuccessReleaseData={this.onSuccessReleaseData}
|
||||
onClickBackButton={this.onClickBackButton}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style={{ display: current === 2 ? 'unset' : 'none' }}>
|
||||
{!isError && (
|
||||
<Result
|
||||
|
||||
@ -27,6 +27,7 @@ import { handleApiError } from '../../../../../../services/utils/errorHandler';
|
||||
import NewAppUploadForm from '../../../AddNewApp/components/AddNewAppForm/components/NewAppUploadForm';
|
||||
|
||||
const formConfig = {
|
||||
isNewRelease: true,
|
||||
specificElements: {
|
||||
binaryFile: {
|
||||
required: true,
|
||||
@ -163,6 +164,11 @@ class AddNewReleaseFormComponent extends React.Component {
|
||||
<NewAppUploadForm
|
||||
forbiddenErrors={forbiddenErrors}
|
||||
formConfig={formConfig}
|
||||
deviceType={this.props.deviceType}
|
||||
// Takes the first upload app type installation path
|
||||
uploadedInstalltionAppType={
|
||||
this.props.location.state.appDetails.installerPath
|
||||
}
|
||||
supportedOsVersions={supportedOsVersions}
|
||||
onSuccessReleaseData={this.onSuccessReleaseData}
|
||||
onClickBackButton={this.onClickBackButton}
|
||||
|
||||
@ -783,6 +783,7 @@ class AppDetailsDrawer extends React.Component {
|
||||
to={{
|
||||
pathname: `/publisher/apps/${app.deviceType}/${app.id}/add-release`,
|
||||
state: {
|
||||
appDetails: app.applicationReleases[0],
|
||||
fullAppDetails: app.applicationReleases,
|
||||
},
|
||||
}}
|
||||
|
||||
@ -65,6 +65,12 @@ function getBase64(file) {
|
||||
reader.onerror = error => reject(error);
|
||||
});
|
||||
}
|
||||
// function for access the name of the binary file using the installation path
|
||||
function extractBinaryFileName(installationPath) {
|
||||
let UploadedBinaryName = installationPath.split('/');
|
||||
let binaryFileName = UploadedBinaryName[UploadedBinaryName.length - 1];
|
||||
return binaryFileName.substr(binaryFileName.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
class EditReleaseModal extends React.Component {
|
||||
// To add subscription type & tenancy sharing, refer https://gitlab.com/entgra/carbon-device-mgt/merge_requests/331
|
||||
@ -156,7 +162,6 @@ class EditReleaseModal extends React.Component {
|
||||
const { formConfig } = this.state;
|
||||
const { specificElements } = formConfig;
|
||||
let metaData = [];
|
||||
|
||||
try {
|
||||
metaData = JSON.parse(release.metaData);
|
||||
} catch (e) {
|
||||
@ -185,7 +190,23 @@ class EditReleaseModal extends React.Component {
|
||||
},
|
||||
});
|
||||
}
|
||||
if (specificElements.hasOwnProperty('version')) {
|
||||
// Showing the packageName value in the edit form UI
|
||||
if (
|
||||
formConfig.specificElements.hasOwnProperty('packageName') ||
|
||||
(this.props.type === 'ENTERPRISE' && this.props.deviceType === 'windows')
|
||||
) {
|
||||
this.props.form.setFields({
|
||||
packageName: {
|
||||
value: release.packageName,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Showing the version value in the edit form UI
|
||||
if (
|
||||
formConfig.specificElements.hasOwnProperty('version') ||
|
||||
(this.props.type === 'ENTERPRISE' && this.props.deviceType === 'windows')
|
||||
) {
|
||||
this.props.form.setFields({
|
||||
version: {
|
||||
value: release.version,
|
||||
@ -201,14 +222,6 @@ class EditReleaseModal extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
if (specificElements.hasOwnProperty('packageName')) {
|
||||
this.props.form.setFields({
|
||||
packageName: {
|
||||
value: release.packageName,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({
|
||||
visible: true,
|
||||
metaData,
|
||||
@ -248,6 +261,10 @@ class EditReleaseModal extends React.Component {
|
||||
|
||||
const { formConfig } = this.state;
|
||||
const { specificElements } = formConfig;
|
||||
// Accessing the extension type of the current uploaded binary file
|
||||
const appTypeExtension = extractBinaryFileName(
|
||||
this.props.release.installerPath,
|
||||
);
|
||||
|
||||
this.props.form.validateFields((err, values) => {
|
||||
if (!err) {
|
||||
@ -280,10 +297,38 @@ class EditReleaseModal extends React.Component {
|
||||
data.append('binaryFile', binaryFiles[0].originFileObj);
|
||||
}
|
||||
|
||||
if (specificElements.hasOwnProperty('version')) {
|
||||
if (
|
||||
specificElements.hasOwnProperty('version') ||
|
||||
(this.props.type === 'ENTERPRISE' &&
|
||||
this.props.deviceType === 'windows')
|
||||
) {
|
||||
release.version = values.version;
|
||||
}
|
||||
|
||||
// Accessing the Meta Key value for windows device type from the config.json file
|
||||
const metaKeyValues =
|
||||
config.windowsAppxMsiKeyValueForMetaData.metaKeyArray;
|
||||
|
||||
if (
|
||||
specificElements.hasOwnProperty('packageName') ||
|
||||
(this.props.type === 'ENTERPRISE' &&
|
||||
this.props.deviceType === 'windows')
|
||||
) {
|
||||
release.packageName = values.packageName;
|
||||
// Setting up the packageName to the package_Family_Name key in an appx app type instance
|
||||
if (appTypeExtension === config.windowsDeviceType.appType[1]) {
|
||||
let metaDataArray = this.state.metaData;
|
||||
let filterMetaArray = metaDataArray.filter(
|
||||
obj => obj.key !== metaKeyValues[4],
|
||||
);
|
||||
filterMetaArray.push({
|
||||
key: metaKeyValues[4],
|
||||
value: values.packageName,
|
||||
});
|
||||
release.metaData = JSON.stringify(filterMetaArray);
|
||||
}
|
||||
}
|
||||
|
||||
if (specificElements.hasOwnProperty('url')) {
|
||||
release.url = values.url;
|
||||
}
|
||||
@ -335,7 +380,6 @@ class EditReleaseModal extends React.Component {
|
||||
message: 'Done!',
|
||||
description: 'Saved!',
|
||||
});
|
||||
// console.log(updatedRelease);
|
||||
this.props.updateRelease(updatedRelease);
|
||||
}
|
||||
})
|
||||
@ -463,7 +507,6 @@ class EditReleaseModal extends React.Component {
|
||||
)}
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{formConfig.specificElements.hasOwnProperty('url') && (
|
||||
<Form.Item {...formItemLayout} label="URL">
|
||||
{getFieldDecorator('url', {
|
||||
@ -477,19 +520,6 @@ class EditReleaseModal extends React.Component {
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{formConfig.specificElements.hasOwnProperty('version') && (
|
||||
<Form.Item {...formItemLayout} label="Version">
|
||||
{getFieldDecorator('version', {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: 'Please input the version',
|
||||
},
|
||||
],
|
||||
})(<Input placeholder="Version" />)}
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
<Form.Item {...formItemLayout} label="Icon">
|
||||
{getFieldDecorator('icon', {
|
||||
valuePropName: 'icon',
|
||||
@ -528,6 +558,38 @@ class EditReleaseModal extends React.Component {
|
||||
)}
|
||||
</Form.Item>
|
||||
|
||||
{/* Package Name field for windows device type and other specific scene using it */}
|
||||
{(formConfig.specificElements.hasOwnProperty('packageName') ||
|
||||
(this.props.type === 'ENTERPRISE' &&
|
||||
this.props.deviceType === 'windows')) && (
|
||||
<Form.Item {...formItemLayout} label="Package Name">
|
||||
{getFieldDecorator('packageName', {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: 'Please input the package name',
|
||||
},
|
||||
],
|
||||
})(<Input placeholder="Package Name" />)}
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{/* Version field for windows device type and other specific scene using it */}
|
||||
{(formConfig.specificElements.hasOwnProperty('version') ||
|
||||
(this.props.type === 'ENTERPRISE' &&
|
||||
this.props.deviceType === 'windows')) && (
|
||||
<Form.Item {...formItemLayout} label="Version">
|
||||
{getFieldDecorator('version', {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: 'Please input the version',
|
||||
},
|
||||
],
|
||||
})(<Input placeholder="Version" />)}
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
<Form.Item {...formItemLayout} label="Release Type">
|
||||
{getFieldDecorator('releaseType', {
|
||||
rules: [
|
||||
@ -650,6 +712,13 @@ class EditReleaseModal extends React.Component {
|
||||
})(
|
||||
<div>
|
||||
{metaData.map((data, index) => {
|
||||
if (
|
||||
!(
|
||||
data.key ===
|
||||
config.windowsAppxMsiKeyValueForMetaData
|
||||
.metaKeyArray[4]
|
||||
)
|
||||
) {
|
||||
return (
|
||||
<InputGroup key={index}>
|
||||
<Row gutter={8}>
|
||||
@ -658,7 +727,8 @@ class EditReleaseModal extends React.Component {
|
||||
placeholder="key"
|
||||
value={data.key}
|
||||
onChange={e => {
|
||||
metaData[index].key = e.currentTarget.value;
|
||||
metaData[index].key =
|
||||
e.currentTarget.value;
|
||||
this.setState({
|
||||
metaData,
|
||||
});
|
||||
@ -694,6 +764,7 @@ class EditReleaseModal extends React.Component {
|
||||
</Row>
|
||||
</InputGroup>
|
||||
);
|
||||
}
|
||||
})}
|
||||
<Button
|
||||
type="dashed"
|
||||
|
||||
@ -41,6 +41,8 @@ class ReleaseView extends React.Component {
|
||||
const { app, release } = this.props;
|
||||
const config = this.props.context;
|
||||
const { lifecycle, currentLifecycleStatus } = this.props;
|
||||
let isKeyInclude = false;
|
||||
let metaArrayWithOutWindowsKey = [];
|
||||
if (release == null) {
|
||||
return null;
|
||||
}
|
||||
@ -169,6 +171,14 @@ class ReleaseView extends React.Component {
|
||||
<Text>META DATA</Text>
|
||||
<Row>
|
||||
{metaData.map((data, index) => {
|
||||
// Exclude showing the values related to windows app type variables in the metaData UI
|
||||
if (
|
||||
!config.windowsAppxMsiKeyValueForMetaData.metaKeyArray.includes(
|
||||
data.key,
|
||||
)
|
||||
) {
|
||||
isKeyInclude = false;
|
||||
metaArrayWithOutWindowsKey.push(data);
|
||||
return (
|
||||
<Col
|
||||
key={index}
|
||||
@ -182,8 +192,10 @@ class ReleaseView extends React.Component {
|
||||
<Text type="secondary">{data.value}</Text>
|
||||
</Col>
|
||||
);
|
||||
}
|
||||
})}
|
||||
{metaData.length === 0 && (
|
||||
{(metaData.length === 0 ||
|
||||
(!isKeyInclude && metaArrayWithOutWindowsKey.length === 0)) && (
|
||||
<Text type="secondary">No meta data available.</Text>
|
||||
)}
|
||||
</Row>
|
||||
|
||||
@ -27,14 +27,12 @@ import io.swagger.annotations.ExtensionProperty;
|
||||
import io.swagger.annotations.Info;
|
||||
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.application.mgt.common.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
@ -64,7 +62,7 @@ import java.util.List;
|
||||
)
|
||||
@Scopes(
|
||||
scopes = {
|
||||
@org.wso2.carbon.apimgt.annotations.api.Scope(
|
||||
@Scope(
|
||||
name = "View Application Subscriptions",
|
||||
description = "View Application Subscriptions.",
|
||||
key = "perm:admin:app:subscription:view",
|
||||
|
||||
@ -40,5 +40,8 @@
|
||||
"color": "#008cc4",
|
||||
"theme": "filled"
|
||||
}
|
||||
},
|
||||
"windowsAppxMsiKeyValueForMetaData": {
|
||||
"metaKeyArray": ["Package_Url", "Dependency_Package_Url", "Certificate_Hash", "Encoded_Cert_Content", "Package_Family_Name", "Product_Id", "Content_Uri", "File_Hash"]
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,6 +148,8 @@ class ReleaseView extends React.Component {
|
||||
const config = this.props.context;
|
||||
const release = app.applicationReleases[0];
|
||||
|
||||
let isKeyInclude = false;
|
||||
let metaArrayWithOutWindowsKey = [];
|
||||
let metaData = [];
|
||||
try {
|
||||
metaData = JSON.parse(release.metaData);
|
||||
@ -270,9 +272,15 @@ class ReleaseView extends React.Component {
|
||||
</div>
|
||||
<Divider />
|
||||
<Text>META DATA</Text>
|
||||
|
||||
<Row>
|
||||
{metaData.map((data, index) => {
|
||||
if (
|
||||
!config.windowsAppxMsiKeyValueForMetaData.metaKeyArray.includes(
|
||||
data.key,
|
||||
)
|
||||
) {
|
||||
isKeyInclude = false;
|
||||
metaArrayWithOutWindowsKey.push(data);
|
||||
return (
|
||||
<Col
|
||||
key={index}
|
||||
@ -286,22 +294,20 @@ class ReleaseView extends React.Component {
|
||||
<Text type="secondary">{data.value}</Text>
|
||||
</Col>
|
||||
);
|
||||
}
|
||||
})}
|
||||
{metaData.length === 0 && (
|
||||
{(metaData.length === 0 ||
|
||||
(!isKeyInclude &&
|
||||
metaArrayWithOutWindowsKey.length === 0)) && (
|
||||
<Text type="secondary">No meta data available.</Text>
|
||||
)}
|
||||
</Row>
|
||||
<Divider />
|
||||
<ReviewContainer uuid={release.uuid} />
|
||||
</TabPane>
|
||||
<Authorized
|
||||
permission="/permission/admin/app-mgt/store/admin/subscription/view"
|
||||
yes={
|
||||
<TabPane tab="Subscription Details" key="2">
|
||||
<SubscriptionDetails uuid={release.uuid} />
|
||||
</TabPane>
|
||||
}
|
||||
/>
|
||||
</Tabs>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -96,10 +96,10 @@ class Login extends React.Component {
|
||||
const config = this.props.context;
|
||||
return (
|
||||
<div className="login">
|
||||
<div className="background"></div>
|
||||
<div className="background" />
|
||||
<div className="content">
|
||||
<Row>
|
||||
<Col xs={3} sm={3} md={10}></Col>
|
||||
<Col xs={3} sm={3} md={10} />
|
||||
<Col xs={18} sm={18} md={4}>
|
||||
<Row style={{ marginBottom: 20 }}>
|
||||
<Col
|
||||
@ -174,7 +174,7 @@ class Login extends React.Component {
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col span={4} offset={10}></Col>
|
||||
<Col span={4} offset={10} />
|
||||
</Row>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.jaxrs.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
public class EventAction {
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "actionType",
|
||||
value = "Type of the event action to be triggered in the device level",
|
||||
required = true)
|
||||
private String actionType;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "payload",
|
||||
value = "Payload of the event action",
|
||||
required = true)
|
||||
private Object payload;
|
||||
|
||||
public String getActionType() {
|
||||
return actionType;
|
||||
}
|
||||
|
||||
public void setActionType(String actionType) {
|
||||
this.actionType = actionType;
|
||||
}
|
||||
|
||||
public Object getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(Object payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.jaxrs.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EventConfig {
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "id",
|
||||
value = "id of the event entry")
|
||||
private int id;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "eventLogic",
|
||||
value = "Logic of the event should be handled at the device level",
|
||||
required = true)
|
||||
private String eventLogic;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "actions",
|
||||
value = "List of actions to be triggered according to the logic",
|
||||
required = true)
|
||||
private List<EventAction> actions;
|
||||
|
||||
public String getEventLogic() {
|
||||
return eventLogic;
|
||||
}
|
||||
|
||||
public void setEventLogic(String eventLogic) {
|
||||
this.eventLogic = eventLogic;
|
||||
}
|
||||
|
||||
public List<EventAction> getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
public void setActions(List<EventAction> actions) {
|
||||
this.actions = actions;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.jaxrs.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GeofenceList extends BasePaginatedResult {
|
||||
private List<GeofenceWrapper> geofenceList = new ArrayList<>();
|
||||
|
||||
@ApiModelProperty(value = "List of geofences returned")
|
||||
@JsonProperty("geofences")
|
||||
public List<GeofenceWrapper> getGeofenceList() {
|
||||
return geofenceList;
|
||||
}
|
||||
|
||||
public void setGeofenceList(List<GeofenceWrapper> geofenceList) {
|
||||
this.geofenceList = geofenceList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{\n");
|
||||
sb.append(" count: ").append(getCount()).append(",\n");
|
||||
sb.append(" geofences: [").append(geofenceList).append("\n");
|
||||
sb.append("]}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.jaxrs.beans;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class GeofenceWrapper {
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "id",
|
||||
value = "Id of the geo fence")
|
||||
private int id;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "fenceName",
|
||||
value = "Name of the geo fence",
|
||||
required = true)
|
||||
private String fenceName;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "description",
|
||||
value = "Description of the geo fence")
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "latitude",
|
||||
value = "Latitude of center of the geo fence")
|
||||
private double latitude;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "longitude",
|
||||
value = "Longitude of center of the geo fence")
|
||||
private double longitude;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "radius",
|
||||
value = "Radius from the center")
|
||||
private float radius;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "geoJson",
|
||||
value = "JSON data set of the polygon fence")
|
||||
private String geoJson;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "fenceShape",
|
||||
value = "Shape of the fence",
|
||||
required = true)
|
||||
private String fenceShape;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "eventConfig",
|
||||
value = "Event configuration of the geofence",
|
||||
required = true)
|
||||
private List<EventConfig> eventConfig;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "groupIds",
|
||||
value = "Group ids mapped with geo fences",
|
||||
required = true)
|
||||
private List<Integer> groupIds;
|
||||
|
||||
private Map<Integer, String> groupNames;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFenceName() {
|
||||
return fenceName;
|
||||
}
|
||||
|
||||
public void setFenceName(String fenceName) {
|
||||
this.fenceName = fenceName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public float getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public void setRadius(float radius) {
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
public String getGeoJson() {
|
||||
return geoJson;
|
||||
}
|
||||
|
||||
public void setGeoJson(String geoJson) {
|
||||
this.geoJson = geoJson;
|
||||
}
|
||||
|
||||
public String getFenceShape() {
|
||||
return fenceShape;
|
||||
}
|
||||
|
||||
public void setFenceShape(String fenceShape) {
|
||||
this.fenceShape = fenceShape;
|
||||
}
|
||||
|
||||
public List<EventConfig> getEventConfig() {
|
||||
return eventConfig;
|
||||
}
|
||||
|
||||
public void setEventConfig(List<EventConfig> eventConfig) {
|
||||
this.eventConfig = eventConfig;
|
||||
}
|
||||
|
||||
public List<Integer> getGroupIds() {
|
||||
return groupIds;
|
||||
}
|
||||
|
||||
public void setGroupIds(List<Integer> groupIds) {
|
||||
this.groupIds = groupIds;
|
||||
}
|
||||
|
||||
public Map<Integer, String> getGroupNames() {
|
||||
return groupNames;
|
||||
}
|
||||
|
||||
public void setGroupNames(Map<Integer, String> groupNames) {
|
||||
this.groupNames = groupNames;
|
||||
}
|
||||
}
|
||||
@ -49,6 +49,12 @@ import java.util.List;
|
||||
+ "Wrappers")
|
||||
public class PolicyWrapper {
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "payloadVersion",
|
||||
value = "Payload version of the Policy")
|
||||
@Size(max = 45)
|
||||
private String payloadVersion;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "policyName",
|
||||
value = "The name of the policy",
|
||||
@ -126,12 +132,18 @@ public class PolicyWrapper {
|
||||
@NotNull
|
||||
private String policyType;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "correctiveActions",
|
||||
value = "List of corrective actions to be applied when the policy is violated"
|
||||
)
|
||||
@ApiModelProperty(name = "correctiveActions",
|
||||
value = "List of corrective actions to be applied when the policy is violated")
|
||||
private List<CorrectiveAction> correctiveActions;
|
||||
|
||||
public String getPayloadVersion() {
|
||||
return payloadVersion;
|
||||
}
|
||||
|
||||
public void setPayloadVersion(String payloadVersion) {
|
||||
this.payloadVersion = payloadVersion;
|
||||
}
|
||||
|
||||
public String getPolicyType() {
|
||||
return policyType;
|
||||
}
|
||||
|
||||
@ -21,8 +21,10 @@ package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||
import com.google.gson.Gson;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.CorrectiveAction;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "ProfileFeature", description = "This class carries all information related to profile "
|
||||
+ "features")
|
||||
@ -57,6 +59,9 @@ public class ProfileFeature implements Serializable {
|
||||
value = "The payload which is submitted to each feature",
|
||||
required = true)
|
||||
private String payLoad;
|
||||
@ApiModelProperty(name = "correctiveActions",
|
||||
value = "List of corrective actions to be applied when the policy is violated")
|
||||
private List<CorrectiveAction> correctiveActions;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
@ -109,4 +114,12 @@ public class ProfileFeature implements Serializable {
|
||||
public void setContent(Object content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public List<CorrectiveAction> getCorrectiveActions() {
|
||||
return correctiveActions;
|
||||
}
|
||||
|
||||
public void setCorrectiveActions(List<CorrectiveAction> correctiveActions) {
|
||||
this.correctiveActions = correctiveActions;
|
||||
}
|
||||
}
|
||||
|
||||
@ -393,6 +393,96 @@ public interface DeviceManagementService {
|
||||
@QueryParam("limit")
|
||||
int limit);
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/{groupId}/location-history")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Getting the Location Details of Devices in the group",
|
||||
notes = "Get the location details of devices in the group during a define time period.",
|
||||
response = Response.class,
|
||||
tags = "Device Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:details")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully fetched the details of the device.",
|
||||
response = Device.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body"),
|
||||
@ResponseHeader(
|
||||
name = "ETag",
|
||||
description = "Entity Tag of the response resource.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
@ResponseHeader(
|
||||
name = "Last-Modified",
|
||||
description = "Date and time the resource was last modified.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. Empty body because the client already has the latest version" +
|
||||
" of the requested resource.\n"),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. \n Location history details for the devices with the specified group id was not found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n " +
|
||||
"Server error occurred while retrieving the devices location history details.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response getDevicesGroupLocationInfo(
|
||||
@ApiParam(
|
||||
name = "groupId",
|
||||
value = "The group ID.",
|
||||
required = true)
|
||||
@PathParam("groupId") int groupId,
|
||||
@ApiParam(
|
||||
name = "from",
|
||||
value = "Define the time to start getting the geo location history of the device in " +
|
||||
"milliseconds.",
|
||||
required = true)
|
||||
@QueryParam("from") long from,
|
||||
@ApiParam(
|
||||
name = "to",
|
||||
value = "Define the time to finish getting the geo location history of the device in " +
|
||||
"milliseconds.",
|
||||
required = true)
|
||||
@QueryParam("to") long to,
|
||||
@ApiParam(
|
||||
name = "type",
|
||||
value = "Defines how the output should be.",
|
||||
required = true)
|
||||
@QueryParam("type") String type,
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "The starting pagination index for the complete list of qualified items.",
|
||||
required = false,
|
||||
defaultValue = "0")
|
||||
@QueryParam("offset") int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Provide how many device details you require from the starting pagination index/offset.",
|
||||
required = false,
|
||||
defaultValue = "100")
|
||||
@QueryParam("limit") int limit
|
||||
);
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/{type}/{id}")
|
||||
@ -551,7 +641,12 @@ public interface DeviceManagementService {
|
||||
value = "Define the time to finish getting the geo location history of the device in " +
|
||||
"milliseconds.",
|
||||
required = true)
|
||||
@QueryParam("to") long to);
|
||||
@QueryParam("to") long to,
|
||||
@ApiParam(
|
||||
name = "type",
|
||||
value = "Defines how the output should be.",
|
||||
required = true)
|
||||
@QueryParam("type") String type);
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
|
||||
@ -33,12 +33,15 @@ 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.common.geo.service.Alert;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.GeofenceWrapper;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
@ -46,7 +49,9 @@ import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@SwaggerDefinition(
|
||||
info = @Info(
|
||||
@ -76,6 +81,12 @@ import javax.ws.rs.core.Response;
|
||||
description = "",
|
||||
key = "perm:geo-service:alerts-manage",
|
||||
permissions = {"/device-mgt/devices/owning-device/manage-alerts"}
|
||||
),
|
||||
@Scope(
|
||||
name = "Manage Geo Fences",
|
||||
description = "",
|
||||
key = "perm:geo-service:geo-fence",
|
||||
permissions = {"/device-mgt/devices/owning-device/manage-geo-fence"}
|
||||
)
|
||||
}
|
||||
)
|
||||
@ -833,5 +844,247 @@ public interface GeoLocationBasedService {
|
||||
value = "The query name.",
|
||||
required = true)
|
||||
@QueryParam("queryName") String queryName);
|
||||
|
||||
@POST
|
||||
@Path("/geo-fence")
|
||||
@ApiOperation(
|
||||
consumes = "application/json",
|
||||
produces = "application/json",
|
||||
httpMethod = "POST",
|
||||
value = "Create Geo fence",
|
||||
notes = "Create a new geo fence",
|
||||
response = Response.class,
|
||||
tags = "Geo Service Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:geo-fence")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 201,
|
||||
message = "Created.",
|
||||
response = Response.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body")
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid Geofence data found.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 401,
|
||||
message = "Unauthorized. \n Unauthorized request.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error on retrieving stats",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response createGeofence(@ApiParam(name = "fence", value = "Geo fence data")GeofenceWrapper geofenceWrapper);
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/geo-fence/{fenceId}")
|
||||
@ApiOperation(
|
||||
consumes = "application/json",
|
||||
produces = "application/json",
|
||||
httpMethod = "GET",
|
||||
value = "Get Geo fence",
|
||||
notes = "Get existing geo fence",
|
||||
response = Response.class,
|
||||
tags = "Geo Service Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:geo-fence")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK.",
|
||||
response = Response.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body")
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not found. \n No Geofence found for the Id",
|
||||
response = Response.class),
|
||||
@ApiResponse(
|
||||
code = 401,
|
||||
message = "Unauthorized. \n Unauthorized request."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error on retrieving stats",
|
||||
response = Response.class)
|
||||
})
|
||||
Response getGeofence(
|
||||
@ApiParam(
|
||||
name = "fenceId",
|
||||
value = "Id of the fence",
|
||||
required = true)
|
||||
@PathParam("fenceId") int fenceId,
|
||||
@ApiParam(
|
||||
name = "requireEventData",
|
||||
value = "Require geofence event data")
|
||||
@QueryParam("requireEventData") boolean requireEventData);
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/geo-fence")
|
||||
@ApiOperation(
|
||||
consumes = "application/json",
|
||||
produces = "application/json",
|
||||
httpMethod = "GET",
|
||||
value = "Get Geo fences",
|
||||
notes = "Get all geo fence",
|
||||
response = Response.class,
|
||||
tags = "Geo Service Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:geo-fence")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK.",
|
||||
response = Response.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body")
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 401,
|
||||
message = "Unauthorized. \n Unauthorized request."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error on retrieving stats",
|
||||
response = Response.class)
|
||||
})
|
||||
Response getGeofence(
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "The starting pagination index for the complete list of qualified items.")
|
||||
@QueryParam("offset") int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Provide how many device details you require from the starting pagination index/offset.")
|
||||
@QueryParam("limit") int limit,
|
||||
@ApiParam(
|
||||
name = "name",
|
||||
value = "Geo Fence name")
|
||||
@QueryParam("name") String name,
|
||||
@ApiParam(
|
||||
name = "requireEventData",
|
||||
value = "Require geofence event data")
|
||||
@QueryParam("requireEventData") boolean requireEventData);
|
||||
|
||||
|
||||
@DELETE
|
||||
@Path("/geo-fence/{fenceId}")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "DELETE",
|
||||
value = "Delete Geo fence",
|
||||
notes = "Delete an existing geo fence",
|
||||
response = Response.class,
|
||||
tags = "Geo Service Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:geo-fence")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK.",
|
||||
response = Response.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body")
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not found. \n No geofences found for the Id",
|
||||
response = Response.class),
|
||||
@ApiResponse(
|
||||
code = 401,
|
||||
message = "Unauthorized. \n Unauthorized request."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error on retrieving stats",
|
||||
response = Response.class)
|
||||
})
|
||||
Response deleteGeofence(
|
||||
@ApiParam(
|
||||
name = "fenceId",
|
||||
value = "Id of the fence",
|
||||
required = true)
|
||||
@PathParam("fenceId") int fenceId);
|
||||
|
||||
|
||||
@PUT
|
||||
@Path("/geo-fence/{fenceId}")
|
||||
@ApiOperation(
|
||||
consumes = "application/json",
|
||||
produces = "application/json",
|
||||
httpMethod = "PUT",
|
||||
value = "Update Geo fence",
|
||||
notes = "Update an existing geo fence",
|
||||
response = Response.class,
|
||||
tags = "Geo Service Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:geo-fence")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK.",
|
||||
response = Response.class,
|
||||
responseHeaders = {
|
||||
@ResponseHeader(
|
||||
name = "Content-Type",
|
||||
description = "The content type of the body")
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid Geofence data found.",
|
||||
response = Response.class),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not found. \n No Geofence found for the Id",
|
||||
response = Response.class),
|
||||
@ApiResponse(
|
||||
code = 401,
|
||||
message = "Unauthorized. \n Unauthorized request."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n Error on retrieving stats",
|
||||
response = Response.class)
|
||||
})
|
||||
Response updateGeofence(
|
||||
@ApiParam(name = "fence", value = "Geo fence data")
|
||||
GeofenceWrapper geofenceWrapper,
|
||||
@ApiParam(
|
||||
name = "fenceId",
|
||||
value = "Id of the fence",
|
||||
required = true)
|
||||
@PathParam("fenceId") int fenceId,
|
||||
@ApiParam(name = "eventIds", value = "Event id list to be removed") @QueryParam("eventIds") int[] eventIds);
|
||||
}
|
||||
|
||||
|
||||
@ -57,8 +57,10 @@ import javax.validation.constraints.Size;
|
||||
import javax.ws.rs.Consumes;
|
||||
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.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
@ -359,4 +361,63 @@ public interface DeviceManagementAdminService {
|
||||
required = true)
|
||||
List<String> deviceIdentifiers);
|
||||
|
||||
@POST
|
||||
@Path("/{deviceId}/{featureCode}")
|
||||
@ApiOperation(
|
||||
consumes = MediaType.APPLICATION_JSON,
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "POST",
|
||||
value = "Trigger the given corrective action",
|
||||
notes = "When violation happens it is possible to trigger a corrective action.",
|
||||
tags = "Device Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:android:enroll")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully triggered the action."),
|
||||
@ApiResponse(
|
||||
code = 400,
|
||||
message = "Bad Request. \n Invalid request or validation error.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 404,
|
||||
message = "Not Found. \n The specified resource does not exist.",
|
||||
response = ErrorResponse.class),
|
||||
@ApiResponse(
|
||||
code = 415,
|
||||
message = "Unsupported media type. \n The format of the requested entity was not " +
|
||||
"supported.\n "
|
||||
+ "supported format."),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server Error. \n " +
|
||||
"Server error occurred while triggering the corrective action.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response triggerCorrectiveActions(
|
||||
@ApiParam(
|
||||
name = "deviceId",
|
||||
value = "Device Identifier.",
|
||||
required = true)
|
||||
@PathParam("deviceId")
|
||||
String deviceId,
|
||||
@ApiParam(
|
||||
name = "featureCode",
|
||||
value = "Policy Feature Code.",
|
||||
required = true)
|
||||
@PathParam("featureCode")
|
||||
String featureCode,
|
||||
@ApiParam(
|
||||
name = "actions",
|
||||
value = "The list of actions to trigger when violation happens.",
|
||||
required = true)
|
||||
List<String> actions
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
|
||||
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
||||
|
||||
import java.text.DateFormat;
|
||||
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
@ -48,9 +46,7 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.Feature;
|
||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
||||
import org.wso2.carbon.device.mgt.common.OperationLogFilters;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceFilters;
|
||||
@ -62,14 +58,13 @@ import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorization
|
||||
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.DeviceLocation;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocationHistory;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocationHistorySnapshot;
|
||||
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.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.UnAuthorizedException;
|
||||
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.Operation;
|
||||
@ -81,7 +76,6 @@ import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
||||
import org.wso2.carbon.device.mgt.common.search.PropertyMap;
|
||||
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
||||
@ -92,8 +86,8 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
||||
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.GroupManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceCompliance;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
@ -102,7 +96,6 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.OperationRequest;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ComplianceDeviceList;
|
||||
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.service.api.DeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
||||
@ -114,7 +107,6 @@ import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerSer
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.user.api.UserStoreManager;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
||||
|
||||
import javax.validation.Valid;
|
||||
@ -131,13 +123,9 @@ import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import java.util.Calendar;
|
||||
|
||||
@Path("/devices")
|
||||
public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
@ -225,29 +213,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
|
||||
if (groupId != 0) {
|
||||
try {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getRealmService()
|
||||
.getTenantUserRealm(tenantId).getUserStoreManager();
|
||||
String[] userRoles = userStoreManager.getRoleListOfUser(authorizedUser);
|
||||
boolean isPermitted = false;
|
||||
if (deviceAccessAuthorizationService.isDeviceAdminUser()) {
|
||||
isPermitted = true;
|
||||
} else {
|
||||
List<String> roles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(groupId);
|
||||
for (String userRole : userRoles) {
|
||||
if (roles.contains(userRole)) {
|
||||
isPermitted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isPermitted) {
|
||||
DeviceGroup deviceGroup = DeviceMgtAPIUtils.getGroupManagementProviderService()
|
||||
.getGroup(groupId, false);
|
||||
if (deviceGroup != null && authorizedUser.equals(deviceGroup.getOwner())) {
|
||||
isPermitted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean isPermitted = DeviceMgtAPIUtils.checkPermission(groupId, authorizedUser);
|
||||
if (isPermitted) {
|
||||
request.setGroupId(groupId);
|
||||
} else {
|
||||
@ -390,6 +356,103 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate group Id and group Id greater than 0 and exist.
|
||||
*
|
||||
* @param groupId Group ID of the group
|
||||
* @param from time to start getting DeviceLocationHistorySnapshotWrapper in milliseconds
|
||||
* @param to time to end getting DeviceLocationHistorySnapshotWrapper in milliseconds
|
||||
*/
|
||||
private static void validateGroupId(int groupId, long from, long to) throws GroupManagementException, BadRequestException {
|
||||
if (from == 0 || to == 0) {
|
||||
String msg = "Invalid values for from/to";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
if (groupId <= 0) {
|
||||
String msg = "Invalid group ID '" + groupId + "'";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService();
|
||||
if (service.getGroup(groupId, false) == null) {
|
||||
String msg = "Invalid group ID '" + groupId + "'";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Override
|
||||
@Path("/{groupId}/location-history")
|
||||
public Response getDevicesGroupLocationInfo(@PathParam("groupId") int groupId,
|
||||
@QueryParam("from") long from,
|
||||
@QueryParam("to") long to,
|
||||
@QueryParam("type") String type,
|
||||
@DefaultValue("0") @QueryParam("offset") int offset,
|
||||
@DefaultValue("100") @QueryParam("limit") int limit){
|
||||
try {
|
||||
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
||||
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||
PaginationRequest request = new PaginationRequest(offset, limit);
|
||||
DeviceList devices = new DeviceList();
|
||||
|
||||
// this is the user who initiates the request
|
||||
String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
try {
|
||||
validateGroupId(groupId, from, to);
|
||||
boolean isPermitted = DeviceMgtAPIUtils.checkPermission(groupId, authorizedUser);
|
||||
if (isPermitted) {
|
||||
request.setGroupId(groupId);
|
||||
} else {
|
||||
String msg = "Current user '" + authorizedUser
|
||||
+ "' doesn't have enough privileges to list devices of group '"
|
||||
+ groupId + "'";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
|
||||
}
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "Error occurred while getting the data using '" + groupId + "'";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (UserStoreException e){
|
||||
String msg = "Error occurred while retrieving role list of user '" + authorizedUser + "'";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
|
||||
PaginationResult result = dms.getAllDevices(request, false);
|
||||
|
||||
if(!result.getData().isEmpty()){
|
||||
devices.setList((List<Device>) result.getData());
|
||||
|
||||
for (Device device : devices.getList()) {
|
||||
DeviceLocationHistorySnapshotWrapper snapshotWrapper = DeviceMgtAPIUtils.getDeviceHistorySnapshots(
|
||||
device.getType(), device.getDeviceIdentifier(), authorizedUser, from, to, type,
|
||||
dms);
|
||||
device.setHistorySnapshot(snapshotWrapper);
|
||||
}
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(devices).build();
|
||||
} catch (BadRequestException e) {
|
||||
String msg = "Invalid type, use either 'path' or 'full'";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (UnAuthorizedException e) {
|
||||
String msg = "Current user doesn't have enough privileges to list devices of group '" + groupId + "'";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while fetching the device information.";
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Override
|
||||
@Path("/type/{deviceType}/id/{deviceId}")
|
||||
@ -511,97 +574,43 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
return Response.status(Response.Status.OK).entity(device).build();
|
||||
}
|
||||
|
||||
@Path("/{deviceType}/{deviceId}/location-history")
|
||||
@GET
|
||||
public Response getDeviceLocationInfo(@PathParam("deviceType") String deviceType,
|
||||
@Path("/{deviceType}/{deviceId}/location-history")
|
||||
public Response getDeviceLocationInfo(
|
||||
@PathParam("deviceType") String deviceType,
|
||||
@PathParam("deviceId") String deviceId,
|
||||
@QueryParam("from") long from, @QueryParam("to") long to) {
|
||||
|
||||
String errorMessage;
|
||||
DeviceLocationHistory deviceLocationHistory = new DeviceLocationHistory();
|
||||
|
||||
@QueryParam("from") long from,
|
||||
@QueryParam("to") long to,
|
||||
@QueryParam("type") String type) {
|
||||
try {
|
||||
RequestValidationUtil.validateDeviceIdentifier(deviceType, deviceId);
|
||||
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||
DeviceAccessAuthorizationService deviceAccessAuthorizationService =
|
||||
DeviceMgtAPIUtils.getDeviceAccessAuthorizationService();
|
||||
String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType);
|
||||
deviceIdentifier.setId(deviceId);
|
||||
deviceIdentifier.setType(deviceType);
|
||||
|
||||
if (!deviceAccessAuthorizationService.isUserAuthorized(deviceIdentifier, authorizedUser)) {
|
||||
String msg = "User '" + authorizedUser + "' is not authorized to retrieve the given device id '" +
|
||||
deviceId + "'";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.UNAUTHORIZED).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(401l).setMessage(msg).build()).build();
|
||||
}
|
||||
if (from == 0 || to == 0) {
|
||||
errorMessage = "Invalid values for from/to";
|
||||
log.error(errorMessage);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage)).build();
|
||||
}
|
||||
|
||||
List<List<DeviceLocationHistorySnapshot>> locationHistorySnapshotList = new ArrayList<>();
|
||||
// Get the location history snapshots for the given period
|
||||
List<DeviceLocationHistorySnapshot> deviceLocationHistorySnapshots = dms.getDeviceLocationInfo(deviceIdentifier, from, to);
|
||||
|
||||
OperationMonitoringTaskConfig operationMonitoringTaskConfig = dms.getDeviceMonitoringConfig(deviceType);
|
||||
int taskFrequency = operationMonitoringTaskConfig.getFrequency();
|
||||
int operationRecurrentTimes = 0;
|
||||
|
||||
List<MonitoringOperation> monitoringOperations = operationMonitoringTaskConfig.getMonitoringOperation();
|
||||
for (MonitoringOperation monitoringOperation :
|
||||
monitoringOperations) {
|
||||
if (monitoringOperation.getTaskName().equals("DEVICE_LOCATION")) {
|
||||
operationRecurrentTimes = monitoringOperation.getRecurrentTimes();
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Device Location operation frequency in milliseconds. Adding 100000 ms as an error
|
||||
long operationFrequency = taskFrequency * operationRecurrentTimes + 100000;
|
||||
|
||||
Queue<DeviceLocationHistorySnapshot> deviceLocationHistorySnapshotsQueue = new LinkedList<>(deviceLocationHistorySnapshots);
|
||||
|
||||
while (deviceLocationHistorySnapshotsQueue.size() > 0) {
|
||||
List<DeviceLocationHistorySnapshot> snapshots = new ArrayList<>();
|
||||
// Make a copy of remaining snapshots
|
||||
List<DeviceLocationHistorySnapshot> cachedSnapshots = new ArrayList<>(deviceLocationHistorySnapshotsQueue);
|
||||
|
||||
for (int i = 0; i < cachedSnapshots.size(); i++) {
|
||||
DeviceLocationHistorySnapshot currentSnapshot = deviceLocationHistorySnapshotsQueue.poll();
|
||||
snapshots.add(currentSnapshot);
|
||||
if (deviceLocationHistorySnapshotsQueue.size() > 0) {
|
||||
DeviceLocationHistorySnapshot nextSnapshot = deviceLocationHistorySnapshotsQueue.peek();
|
||||
if (nextSnapshot.getUpdatedTime().getTime() - currentSnapshot.getUpdatedTime().getTime() > operationFrequency) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
locationHistorySnapshotList.add(snapshots);
|
||||
}
|
||||
deviceLocationHistory.setLocationHistorySnapshots(locationHistorySnapshotList);
|
||||
|
||||
|
||||
DeviceLocationHistorySnapshotWrapper snapshotWrapper = DeviceMgtAPIUtils.getDeviceHistorySnapshots(
|
||||
deviceType, deviceId, authorizedUser, from, to, type,
|
||||
dms);
|
||||
return Response.status(Response.Status.OK).entity(snapshotWrapper).build();
|
||||
} catch (BadRequestException e) {
|
||||
String msg = "Invalid type, use either 'path' or 'full'";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (UnAuthorizedException e) {
|
||||
String msg = "Current user doesn't have enough privileges to retrieve the given device id '"
|
||||
+ deviceId + "'";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
|
||||
} catch (DeviceManagementException e) {
|
||||
errorMessage = "Error occurred while fetching the device information.";
|
||||
log.error(errorMessage, e);
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()).build();
|
||||
} catch (DeviceAccessAuthorizationException e) {
|
||||
errorMessage = "Error occurred while checking the device authorization.";
|
||||
log.error(errorMessage, e);
|
||||
return Response.serverError().entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()).build();
|
||||
String msg = "Error occurred while fetching the device information.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (InputValidationException e) {
|
||||
errorMessage = "Invalid device Id or device type";
|
||||
log.error(errorMessage, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage)).build();
|
||||
String msg = "Invalid device Id or device type";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.BAD_REQUEST).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();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(deviceLocationHistory).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
|
||||
@ -18,8 +18,13 @@
|
||||
|
||||
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
|
||||
import org.wso2.carbon.analytics.api.AnalyticsDataAPIUtil;
|
||||
import org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse;
|
||||
@ -31,10 +36,21 @@ import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoServices;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.*;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfig;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.Alert;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.AlertAlreadyExistException;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.Event;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoFence;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationBasedServiceException;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
|
||||
import org.wso2.carbon.device.mgt.core.geo.GeoCluster;
|
||||
import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate;
|
||||
@ -42,15 +58,29 @@ import org.wso2.carbon.device.mgt.core.geo.geoHash.geoHashStrategy.GeoHashLength
|
||||
import org.wso2.carbon.device.mgt.core.geo.geoHash.geoHashStrategy.ZoomGeoHashLengthStrategy;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.EventAction;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.GeofenceWrapper;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.GeoLocationBasedService;
|
||||
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.util.Constants;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -577,4 +607,271 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
|
||||
eventBean.setValues(record.getValues());
|
||||
return eventBean;
|
||||
}
|
||||
|
||||
@Path("/geo-fence")
|
||||
@POST
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public Response createGeofence(GeofenceWrapper geofenceWrapper) {
|
||||
RequestValidationUtil.validateGeofenceData(geofenceWrapper);
|
||||
RequestValidationUtil.validateEventConfigurationData(geofenceWrapper.getEventConfig());
|
||||
try {
|
||||
GeofenceData geofenceData = mapRequestGeofenceData(geofenceWrapper);
|
||||
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
|
||||
if (!geoService.createGeofence(geofenceData)) {
|
||||
String msg = "Failed to create geofence";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
return Response.status(Response.Status.CREATED).entity("Geo Fence record created successfully").build();
|
||||
} catch (GeoLocationBasedServiceException e) {
|
||||
String msg = "Failed to create geofence";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
} catch (EventConfigurationException e) {
|
||||
String msg = "Failed to create event configuration for Geo Fence";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract request event data from the payload and attach it to the DTO
|
||||
* @param eventConfig request event payload
|
||||
* @return generated event beans list according to the payload data
|
||||
*/
|
||||
private List<EventConfig> mapRequestEvent(List<org.wso2.carbon.device.mgt.jaxrs.beans.EventConfig> eventConfig) {
|
||||
List<EventConfig> savingEventList = new ArrayList<>();
|
||||
for (org.wso2.carbon.device.mgt.jaxrs.beans.EventConfig event : eventConfig) {
|
||||
EventConfig savingConfig = new EventConfig();
|
||||
if (event.getId() > 0) {
|
||||
savingConfig.setEventId(event.getId());
|
||||
} else {
|
||||
savingConfig.setEventId(-1);
|
||||
}
|
||||
savingConfig.setEventLogic(event.getEventLogic());
|
||||
String eventJson = new Gson().toJson(event.getActions());
|
||||
savingConfig.setActions(eventJson);
|
||||
savingEventList.add(savingConfig);
|
||||
}
|
||||
return savingEventList;
|
||||
}
|
||||
|
||||
@Path("/geo-fence/{fenceId}")
|
||||
@GET
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public Response getGeofence(@PathParam("fenceId") int fenceId,
|
||||
@QueryParam("requireEventData") boolean requireEventData) {
|
||||
try {
|
||||
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
|
||||
GeofenceData geofenceData = geoService.getGeoFences(fenceId);
|
||||
if (geofenceData == null) {
|
||||
String msg = "No valid Geofence found for ID " + fenceId;
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
||||
}
|
||||
if (requireEventData) {
|
||||
List<EventConfig> eventsOfGeoFence = geoService.getEventsOfGeoFence(geofenceData.getId());
|
||||
geofenceData.setEventConfig(eventsOfGeoFence);
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(getMappedResponseBean(geofenceData)).build();
|
||||
} catch (GeoLocationBasedServiceException e) {
|
||||
String msg = "Server error occurred while retrieving Geofence for Id " + fenceId;
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap geofence data retrieved from DB into Response Bean
|
||||
* @param geofenceData retrieved data fromDB
|
||||
* @return Response bean with geofence data
|
||||
*/
|
||||
private GeofenceWrapper getMappedResponseBean(GeofenceData geofenceData) {
|
||||
GeofenceWrapper geofenceWrapper = new GeofenceWrapper();
|
||||
geofenceWrapper.setId(geofenceData.getId());
|
||||
geofenceWrapper.setFenceName(geofenceData.getFenceName());
|
||||
geofenceWrapper.setDescription(geofenceData.getDescription());
|
||||
geofenceWrapper.setLatitude(geofenceData.getLatitude());
|
||||
geofenceWrapper.setLongitude(geofenceData.getLongitude());
|
||||
geofenceWrapper.setRadius(geofenceData.getRadius());
|
||||
geofenceWrapper.setGeoJson(geofenceData.getGeoJson());
|
||||
geofenceWrapper.setFenceShape(geofenceData.getFenceShape());
|
||||
if (geofenceData.getGroupIds() != null && !geofenceData.getGroupIds().isEmpty()) {
|
||||
geofenceWrapper.setGroupIds(geofenceData.getGroupIds());
|
||||
}
|
||||
if (geofenceData.getGroupData() != null && !geofenceData.getGroupData().isEmpty()) {
|
||||
geofenceWrapper.setGroupNames(geofenceData.getGroupData());
|
||||
}
|
||||
if (geofenceData.getEventConfig() != null) {
|
||||
geofenceWrapper.setEventConfig(getEventConfigBean(geofenceData.getEventConfig()));
|
||||
}
|
||||
return geofenceWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event list to send with the response
|
||||
* @param eventConfig event list retrieved
|
||||
* @return list of response event beans
|
||||
*/
|
||||
private List<org.wso2.carbon.device.mgt.jaxrs.beans.EventConfig> getEventConfigBean(List<EventConfig> eventConfig) {
|
||||
List<org.wso2.carbon.device.mgt.jaxrs.beans.EventConfig> eventList = new ArrayList<>();
|
||||
org.wso2.carbon.device.mgt.jaxrs.beans.EventConfig eventData;
|
||||
for (EventConfig event : eventConfig) {
|
||||
eventData = new org.wso2.carbon.device.mgt.jaxrs.beans.EventConfig();
|
||||
eventData.setId(event.getEventId());
|
||||
eventData.setEventLogic(event.getEventLogic());
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
try {
|
||||
List<EventAction> eventActions = mapper.readValue(event.getActions(), mapper.getTypeFactory().
|
||||
constructCollectionType(List.class, EventAction.class));
|
||||
eventData.setActions(eventActions);
|
||||
} catch (IOException e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.warn("Error occurred while parsing event actions of the event with ID " + event.getEventId());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
eventList.add(eventData);
|
||||
}
|
||||
return eventList;
|
||||
}
|
||||
|
||||
@Path("/geo-fence")
|
||||
@GET
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public Response getGeofence(@QueryParam("offset") int offset,
|
||||
@QueryParam("limit") int limit,
|
||||
@QueryParam("name") String name,
|
||||
@QueryParam("requireEventData") boolean requireEventData) {
|
||||
try {
|
||||
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
|
||||
if (offset >= 0 && limit != 0) {
|
||||
PaginationRequest request = new PaginationRequest(offset, limit);
|
||||
if (name != null && !name.isEmpty()) {
|
||||
request.setProperty(DeviceManagementConstants.GeoServices.FENCE_NAME, name);
|
||||
}
|
||||
List<GeofenceData> geoFences = geoService.getGeoFences(request);
|
||||
if (!geoFences.isEmpty() && requireEventData) {
|
||||
geoFences = geoService.attachEventObjects(geoFences);
|
||||
}
|
||||
return buildResponse(geoFences);
|
||||
}
|
||||
if (name != null && !name.isEmpty()) {
|
||||
List<GeofenceData> geoFences = geoService.getGeoFences(name);
|
||||
if (requireEventData) {
|
||||
geoFences = geoService.attachEventObjects(geoFences);
|
||||
}
|
||||
return buildResponse(geoFences);
|
||||
}
|
||||
return buildResponse(geoService.getGeoFences());
|
||||
} catch (GeoLocationBasedServiceException e) {
|
||||
String msg = "Failed to retrieve geofence data";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the response payload from the data retrieved from the database
|
||||
* @param fencesList retrieved geofence data to send in response
|
||||
* @return HttpResponse object
|
||||
*/
|
||||
private Response buildResponse(List<GeofenceData> fencesList) {
|
||||
List<GeofenceWrapper> geofenceList = new ArrayList<>();
|
||||
for (GeofenceData geofenceData : fencesList) {
|
||||
geofenceList.add(getMappedResponseBean(geofenceData));
|
||||
}
|
||||
PaginationResult paginationResult = new PaginationResult();
|
||||
paginationResult.setData(geofenceList);
|
||||
paginationResult.setRecordsTotal(geofenceList.size());
|
||||
return Response.status(Response.Status.OK).entity(paginationResult).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Override
|
||||
@Path("/geo-fence/{fenceId}")
|
||||
public Response deleteGeofence(@PathParam("fenceId") int fenceId) {
|
||||
try {
|
||||
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
|
||||
if (!geoService.deleteGeofenceData(fenceId)) {
|
||||
String msg = "No valid Geofence found for ID " + fenceId;
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).build();
|
||||
} catch (GeoLocationBasedServiceException e) {
|
||||
String msg = "Failed to delete geofence data";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Path("/geo-fence/{fenceId}")
|
||||
@PUT
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public Response updateGeofence(GeofenceWrapper geofenceWrapper,
|
||||
@PathParam("fenceId") int fenceId,
|
||||
@QueryParam("eventIds") int[] eventIds) {
|
||||
RequestValidationUtil.validateGeofenceData(geofenceWrapper);
|
||||
RequestValidationUtil.validateEventConfigurationData(geofenceWrapper.getEventConfig());
|
||||
try {
|
||||
GeofenceData geofenceData = mapRequestGeofenceData(geofenceWrapper);
|
||||
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
|
||||
if (!geoService.updateGeofence(geofenceData, fenceId)) {
|
||||
String msg = "No valid Geofence found for ID " + fenceId;
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
||||
}
|
||||
List<Integer> eventsToRemove = new ArrayList<>();
|
||||
for (int eventId : eventIds) {
|
||||
eventsToRemove.add(eventId);
|
||||
}
|
||||
geoService.updateGeoEventConfigurations(geofenceData, eventsToRemove,
|
||||
geofenceData.getGroupIds(), fenceId);
|
||||
return Response.status(Response.Status.CREATED).entity("Geo Fence update successfully").build();
|
||||
} catch (GeoLocationBasedServiceException e) {
|
||||
String msg = "Failed to update geofence";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (EventConfigurationException e) {
|
||||
String msg = "Failed to update geofence events";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse geofence data from the request payload to the GeofenceData DTO
|
||||
* @param geofenceWrapper request payload data
|
||||
* @return GeofenceData object built from the request data
|
||||
*/
|
||||
private GeofenceData mapRequestGeofenceData(GeofenceWrapper geofenceWrapper) {
|
||||
GeofenceData geofenceData = new GeofenceData();
|
||||
geofenceData.setFenceName(geofenceWrapper.getFenceName());
|
||||
geofenceData.setDescription(geofenceWrapper.getDescription());
|
||||
geofenceData.setLatitude(geofenceWrapper.getLatitude());
|
||||
geofenceData.setLongitude(geofenceWrapper.getLongitude());
|
||||
geofenceData.setRadius(geofenceWrapper.getRadius());
|
||||
geofenceData.setFenceShape(geofenceWrapper.getFenceShape());
|
||||
geofenceData.setGeoJson(geofenceWrapper.getGeoJson());
|
||||
if (geofenceWrapper.getGroupIds() == null || geofenceWrapper.getGroupIds().isEmpty()) {
|
||||
String msg = "Group ID / IDs are mandatory, since cannot be null or empty";
|
||||
log.error(msg);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST)
|
||||
.setMessage(msg).build());
|
||||
}
|
||||
geofenceData.setGroupIds(geofenceWrapper.getGroupIds());
|
||||
geofenceData.setEventConfig(mapRequestEvent(geofenceWrapper.getEventConfig()));
|
||||
return geofenceData;
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,12 +136,19 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GEt {@link Policy} from {@link PolicyWrapper}
|
||||
*
|
||||
* @param policyWrapper {@link PolicyWrapper}
|
||||
* @return {@link Policy}
|
||||
* @throws DeviceManagementException if error occurred while creating {@link Policy} object from
|
||||
* {@link PolicyWrapper}
|
||||
*/
|
||||
private Policy getPolicyFromWrapper(@Valid PolicyWrapper policyWrapper) throws DeviceManagementException {
|
||||
Policy policy = new Policy();
|
||||
policy.setPolicyName(policyWrapper.getPolicyName());
|
||||
policy.setDescription(policyWrapper.getDescription());
|
||||
policy.setProfile(DeviceMgtUtil.convertProfile(policyWrapper.getProfile()));
|
||||
policy.setCorrectiveActions(policyWrapper.getCorrectiveActions());
|
||||
policy.setOwnershipType(policyWrapper.getOwnershipType());
|
||||
policy.setActive(policyWrapper.isActive());
|
||||
policy.setRoles(policyWrapper.getRoles());
|
||||
@ -149,8 +156,10 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
|
||||
policy.setCompliance(policyWrapper.getCompliance());
|
||||
policy.setDeviceGroups(policyWrapper.getDeviceGroups());
|
||||
policy.setPolicyType(policyWrapper.getPolicyType());
|
||||
policy.setPolicyPayloadVersion(policyWrapper.getPayloadVersion());
|
||||
policy.setCorrectiveActions(policyWrapper.getCorrectiveActions());
|
||||
//TODO iterates the device identifiers to create the object. need to implement a proper DAO layer here.
|
||||
List<Device> devices = new ArrayList<Device>();
|
||||
List<Device> devices = new ArrayList<>();
|
||||
List<DeviceIdentifier> deviceIdentifiers = policyWrapper.getDeviceIdentifiers();
|
||||
if (deviceIdentifiers != null) {
|
||||
for (DeviceIdentifier id : deviceIdentifiers) {
|
||||
|
||||
@ -41,8 +41,15 @@ import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.MDMAppConstants;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
|
||||
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.InvalidDeviceException;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
@ -56,8 +63,10 @@ import javax.validation.constraints.Size;
|
||||
import javax.ws.rs.Consumes;
|
||||
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.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
@ -190,4 +199,38 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/{deviceId}/{featureCode}")
|
||||
@Override
|
||||
public Response triggerCorrectiveActions(
|
||||
@PathParam("deviceId") String deviceIdentifier,
|
||||
@PathParam("featureCode") String featureCode,
|
||||
List<String> actions){
|
||||
DeviceManagementProviderService deviceManagementService = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||
PlatformConfigurationManagementService platformConfigurationManagementService = DeviceMgtAPIUtils
|
||||
.getPlatformConfigurationManagementService();
|
||||
try {
|
||||
PlatformConfiguration config = platformConfigurationManagementService
|
||||
.getConfiguration(MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
|
||||
List<ConfigurationEntry> configList = config.getConfiguration();
|
||||
deviceManagementService.triggerCorrectiveActions(deviceIdentifier, featureCode, actions, configList);
|
||||
} catch (ConfigurationManagementException e) {
|
||||
String msg = "Error occurred while processing platform configuration.";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (BadRequestException e) {
|
||||
String msg = "Bad request, can't proceed. Hence verify the request and re-try";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while getting device data which has ID: " + deviceIdentifier;
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
} catch (DeviceNotFoundException e) {
|
||||
String msg = "Couldn't find an device for device identifier: " + deviceIdentifier;
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity("Triggered action successfully").build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +35,8 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationWrapper;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.EventConfig;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.GeofenceWrapper;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ProfileFeature;
|
||||
@ -682,4 +684,73 @@ public class RequestValidationUtil {
|
||||
&& StringUtils.isEmpty(emailAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the request payload attributes are correct for create a geofence
|
||||
* @param geofenceWrapper request payload data
|
||||
*/
|
||||
public static void validateGeofenceData(GeofenceWrapper geofenceWrapper) {
|
||||
boolean isGeoJsonExists = false;
|
||||
if (geofenceWrapper.getFenceName() == null || geofenceWrapper.getFenceName().trim().isEmpty()) {
|
||||
String msg = "Geofence name should not be null or empty";
|
||||
log.error(msg);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
|
||||
}
|
||||
if (geofenceWrapper.getGeoJson() != null && !geofenceWrapper.getGeoJson().trim().isEmpty()) {
|
||||
isGeoJsonExists = true;
|
||||
}
|
||||
if ((geofenceWrapper.getLatitude() < -90 || geofenceWrapper.getLatitude() > 90) && !isGeoJsonExists) {
|
||||
String msg = "Latitude should be a value between -90 and 90";
|
||||
log.error(msg);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
|
||||
}
|
||||
if ((geofenceWrapper.getLongitude() < -180 || geofenceWrapper.getLongitude() > 180) && !isGeoJsonExists) {
|
||||
String msg = "Longitude should be a value between -180 and 180";
|
||||
log.error(msg);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
|
||||
}
|
||||
if (geofenceWrapper.getRadius() < 1 && !isGeoJsonExists) {
|
||||
String msg = "Minimum radius of the fence should be 1m";
|
||||
log.error(msg);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
|
||||
}
|
||||
if (geofenceWrapper.getFenceShape().trim().isEmpty()) {
|
||||
String msg = "Fence shape should not be empty";
|
||||
log.error(msg);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the request payload attributes are correct for create an event record
|
||||
* @param eventConfig request payload data
|
||||
*/
|
||||
public static void validateEventConfigurationData(List<EventConfig> eventConfig) {
|
||||
if (eventConfig == null ||eventConfig.isEmpty()) {
|
||||
String msg = "Event configuration is mandatory, since should not be null or empty";
|
||||
log.error(msg);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
|
||||
}
|
||||
|
||||
for (EventConfig config : eventConfig) {
|
||||
if (config.getActions() == null || config.getActions().isEmpty()) {
|
||||
String msg = "Event actions are mandatory, since should not be null or empty";
|
||||
log.error(msg);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
|
||||
}
|
||||
|
||||
if (config.getEventLogic() == null || config.getEventLogic().trim().isEmpty()) {
|
||||
String msg = "Event logic is mandatory, since should not be null or empty";
|
||||
log.error(msg);
|
||||
throw new InputValidationException(
|
||||
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,16 +53,26 @@ import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.core.util.Utils;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
||||
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocationHistory;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocationHistorySnapshot;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocationHistorySnapshotWrapper;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationProviderService;
|
||||
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.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.UnAuthorizedException;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.metadata.mgt.MetadataManagementService;
|
||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
@ -82,6 +92,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationStatusBean;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.beans.analytics.EventAttributeList;
|
||||
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.event.processor.stub.EventProcessorAdminServiceStub;
|
||||
import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub;
|
||||
import org.wso2.carbon.event.receiver.stub.EventReceiverAdminServiceStub;
|
||||
@ -123,7 +134,9 @@ import java.security.NoSuchAlgorithmException;
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* MDMAPIUtils class provides utility function used by CDM REST-API classes.
|
||||
@ -940,4 +953,149 @@ public class DeviceMgtAPIUtils {
|
||||
claimPropertyDTO.setPropertyValue(propertyValue);
|
||||
return claimPropertyDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getting Device History Snapshots for given Device Type and Identifier.
|
||||
*
|
||||
* @param deviceType Device type of the device
|
||||
* @param identifier Device identifier of the device
|
||||
* @param authorizedUser user who initiates the request
|
||||
* @param from time to start getting DeviceLocationHistorySnapshotWrapper in milliseconds
|
||||
* @param to time to end getting DeviceLocationHistorySnapshotWrapper in milliseconds
|
||||
* @param type output type should be for DeviceLocationHistorySnapshotWrapper
|
||||
* @param dms DeviceManagementService instance
|
||||
*
|
||||
* @return DeviceLocationHistorySnapshotWrapper instance
|
||||
* @throws DeviceManagementException if device information cannot be fetched
|
||||
* @throws DeviceAccessAuthorizationException if device authorization get failed
|
||||
*/
|
||||
public static DeviceLocationHistorySnapshotWrapper getDeviceHistorySnapshots(String deviceType,
|
||||
String identifier,
|
||||
String authorizedUser,
|
||||
long from,
|
||||
long to,
|
||||
String type,
|
||||
DeviceManagementProviderService dms)
|
||||
throws DeviceManagementException, DeviceAccessAuthorizationException {
|
||||
RequestValidationUtil.validateDeviceIdentifier(deviceType, identifier);
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(identifier, deviceType);
|
||||
|
||||
if (!getDeviceAccessAuthorizationService().isUserAuthorized(deviceIdentifier, authorizedUser)) {
|
||||
String msg = "User '" + authorizedUser + "' is not authorized to retrieve the given device id '" +
|
||||
identifier + "'";
|
||||
log.error(msg);
|
||||
throw new UnAuthorizedException(msg);
|
||||
}
|
||||
|
||||
// Get the location history snapshots for the given period
|
||||
List<DeviceLocationHistorySnapshot> deviceLocationHistorySnapshots = dms.getDeviceLocationInfo(deviceIdentifier, from, to);
|
||||
|
||||
OperationMonitoringTaskConfig operationMonitoringTaskConfig = dms.getDeviceMonitoringConfig(deviceType);
|
||||
int taskFrequency = operationMonitoringTaskConfig.getFrequency();
|
||||
int operationRecurrentTimes = 0;
|
||||
|
||||
List<MonitoringOperation> monitoringOperations = operationMonitoringTaskConfig.getMonitoringOperation();
|
||||
for (MonitoringOperation monitoringOperation : monitoringOperations) {
|
||||
if (monitoringOperation.getTaskName().equals("DEVICE_LOCATION")) {
|
||||
operationRecurrentTimes = monitoringOperation.getRecurrentTimes();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Device Location operation frequency in milliseconds. Adding 100000 ms as an error
|
||||
long operationFrequency = taskFrequency * operationRecurrentTimes + 100000;
|
||||
Queue<DeviceLocationHistorySnapshot> deviceLocationHistorySnapshotsQueue = new LinkedList<>(
|
||||
deviceLocationHistorySnapshots);
|
||||
List<List<DeviceLocationHistorySnapshot>> locationHistorySnapshotList = new ArrayList<>();
|
||||
|
||||
List<Object> pathsArray = new ArrayList<>();
|
||||
DeviceLocationHistorySnapshotWrapper snapshotWrapper = new DeviceLocationHistorySnapshotWrapper();
|
||||
while (!deviceLocationHistorySnapshotsQueue.isEmpty()) {
|
||||
List<DeviceLocationHistorySnapshot> snapshots = new ArrayList<>();
|
||||
// Make a copy of remaining snapshots
|
||||
List<DeviceLocationHistorySnapshot> cachedSnapshots = new ArrayList<>(
|
||||
deviceLocationHistorySnapshotsQueue);
|
||||
|
||||
List<Object> locationPoint = new ArrayList<>();
|
||||
for (int i = 0; i < cachedSnapshots.size(); i++) {
|
||||
DeviceLocationHistorySnapshot currentSnapshot = deviceLocationHistorySnapshotsQueue.poll();
|
||||
snapshots.add(currentSnapshot);
|
||||
if (currentSnapshot != null) {
|
||||
locationPoint.add(currentSnapshot.getLatitude());
|
||||
locationPoint.add(currentSnapshot.getLongitude());
|
||||
locationPoint.add(currentSnapshot.getUpdatedTime());
|
||||
pathsArray.add(new ArrayList<>(locationPoint));
|
||||
locationPoint.clear();
|
||||
}
|
||||
if (!deviceLocationHistorySnapshotsQueue.isEmpty()) {
|
||||
DeviceLocationHistorySnapshot nextSnapshot = deviceLocationHistorySnapshotsQueue.peek();
|
||||
locationPoint.add(nextSnapshot.getLatitude());
|
||||
locationPoint.add(nextSnapshot.getLongitude());
|
||||
locationPoint.add(nextSnapshot.getUpdatedTime());
|
||||
pathsArray.add(new ArrayList<>(locationPoint));
|
||||
locationPoint.clear();
|
||||
if (nextSnapshot.getUpdatedTime().getTime() - currentSnapshot.getUpdatedTime().getTime()
|
||||
> operationFrequency) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
locationHistorySnapshotList.add(snapshots);
|
||||
}
|
||||
DeviceLocationHistory deviceLocationHistory = new DeviceLocationHistory();
|
||||
deviceLocationHistory.setLocationHistorySnapshots(locationHistorySnapshotList);
|
||||
if (type != null) {
|
||||
if (type.equals("path")) {
|
||||
snapshotWrapper.setPathSnapshot(pathsArray);
|
||||
} else if (type.equals("full")) {
|
||||
snapshotWrapper.setFullSnapshot(deviceLocationHistory);
|
||||
} else {
|
||||
String msg = "Invalid type, use either 'path' or 'full'";
|
||||
log.error(msg);
|
||||
throw new BadRequestException(msg);
|
||||
}
|
||||
} else {
|
||||
snapshotWrapper.setFullSnapshot(deviceLocationHistory);
|
||||
}
|
||||
return snapshotWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check user who initiates the request has permission to list devices from given group Id.
|
||||
*
|
||||
* @param groupId Group ID of the group
|
||||
* @param authorizedUser user who initiates the request
|
||||
*
|
||||
* @return boolean instance
|
||||
* @throws UserStoreException if roles list of authorizedUser cannot be fetched
|
||||
* @throws DeviceAccessAuthorizationException if device authorization get failed.
|
||||
* @throws GroupManagementException if group or roles cannot be fetched using groupId
|
||||
*/
|
||||
public static boolean checkPermission(int groupId, String authorizedUser) throws UserStoreException, DeviceAccessAuthorizationException, GroupManagementException {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getRealmService()
|
||||
.getTenantUserRealm(tenantId).getUserStoreManager();
|
||||
String[] userRoles = userStoreManager.getRoleListOfUser(authorizedUser);
|
||||
boolean isPermitted = false;
|
||||
if (getDeviceAccessAuthorizationService().isDeviceAdminUser()) {
|
||||
isPermitted = true;
|
||||
} else {
|
||||
List<String> roles = DeviceMgtAPIUtils.getGroupManagementProviderService().getRoles(groupId);
|
||||
for (String userRole : userRoles) {
|
||||
if (roles.contains(userRole)) {
|
||||
isPermitted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isPermitted) {
|
||||
DeviceGroup deviceGroup = DeviceMgtAPIUtils.getGroupManagementProviderService()
|
||||
.getGroup(groupId, false);
|
||||
if (deviceGroup != null && authorizedUser.equals(deviceGroup.getOwner())) {
|
||||
isPermitted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isPermitted;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -60,6 +60,7 @@ public class DeviceMgtUtil {
|
||||
profileFeature.setDeviceType(mdmProfileFeature.getDeviceTypeId());
|
||||
profileFeature.setFeatureCode(mdmProfileFeature.getFeatureCode());
|
||||
profileFeature.setId(mdmProfileFeature.getId());
|
||||
profileFeature.setCorrectiveActions(mdmProfileFeature.getCorrectiveActions());
|
||||
return profileFeature;
|
||||
|
||||
}
|
||||
|
||||
@ -20,8 +20,10 @@ package org.wso2.carbon.device.mgt.common;
|
||||
import com.google.gson.Gson;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocationHistorySnapshotWrapper;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
@ -70,6 +72,12 @@ public class Device implements Serializable {
|
||||
required = false)
|
||||
private List<Application> applications;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "historySnapshot",
|
||||
value = "device history snapshots")
|
||||
@JsonProperty(value = "historySnapshot")
|
||||
private DeviceLocationHistorySnapshotWrapper historySnapshot;
|
||||
|
||||
public Device() {
|
||||
}
|
||||
|
||||
@ -164,6 +172,14 @@ public class Device implements Serializable {
|
||||
this.applications = applications;
|
||||
}
|
||||
|
||||
public DeviceLocationHistorySnapshotWrapper getHistorySnapshot() {
|
||||
return historySnapshot;
|
||||
}
|
||||
|
||||
public void setHistorySnapshot(DeviceLocationHistorySnapshotWrapper historySnapshot) {
|
||||
this.historySnapshot = historySnapshot;
|
||||
}
|
||||
|
||||
public static class Property {
|
||||
|
||||
private String name;
|
||||
|
||||
@ -58,6 +58,7 @@ public class DeviceIdentifier implements Serializable{
|
||||
public void setType(String type) {
|
||||
this.type = type.trim();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -124,6 +124,7 @@ public final class DeviceManagementConstants {
|
||||
public static final String DAS_HOST_NAME = "${iot.analytics.host}";
|
||||
public static final String DEFAULT_HTTP_PROTOCOL = "https";
|
||||
public static final String DAS_URL = DEFAULT_HTTP_PROTOCOL + "://" + DAS_HOST_NAME + ":" + DAS_PORT;
|
||||
public static final String FENCE_NAME = "name";
|
||||
}
|
||||
|
||||
public static final class OTPProperties {
|
||||
@ -135,4 +136,10 @@ public final class DeviceManagementConstants {
|
||||
public static final String TENANT_ADMIN_PASSWORD = "tenant-admin-password";
|
||||
}
|
||||
|
||||
public static final class EventServices {
|
||||
private EventServices() { throw new AssertionError(); }
|
||||
|
||||
public static final String GEOFENCE = "GEOFENCE";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
/**
|
||||
* This class holds all the constants used for IOS and Android.
|
||||
* This class holds all the constants used for IOS, Android, Windows.
|
||||
*/
|
||||
public class MDMAppConstants {
|
||||
|
||||
@ -49,6 +49,29 @@ public class MDMAppConstants {
|
||||
public static final String OPCODE_UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION";
|
||||
}
|
||||
|
||||
public class WindowsConstants {
|
||||
|
||||
private WindowsConstants() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
public static final String INSTALL_ENTERPRISE_APPLICATION = "INSTALL_ENTERPRISE_APPLICATION";
|
||||
//App type constants related to window device type
|
||||
public static final String MSI = "MSI";
|
||||
public static final String APPX = "APPX";
|
||||
|
||||
//MSI Meta Key Constant
|
||||
public static final String MSI_PRODUCT_ID = "Product_Id";
|
||||
public static final String MSI_CONTENT_URI = "Content_Uri";
|
||||
public static final String MSI_FILE_HASH = "File_Hash";
|
||||
|
||||
//APPX Meta Key Constant
|
||||
public static final String APPX_PACKAGE_URI = "Package_Url";
|
||||
public static final String APPX_DEPENDENCY_PACKAGE_URL = "Dependency_Package_Url";
|
||||
public static final String APPX_CERTIFICATE_HASH = "Certificate_Hash";
|
||||
public static final String APPX_ENCODED_CERT_CONTENT = "Encoded_Cert_Content";
|
||||
public static final String APPX_PACKAGE_FAMILY_NAME = "Package_Family_Name";
|
||||
}
|
||||
|
||||
public class RegistryConstants {
|
||||
|
||||
private RegistryConstants() {
|
||||
|
||||
@ -62,6 +62,10 @@ public class App {
|
||||
private String location;
|
||||
@ApiModelProperty(name = "properties", value = "List of meta data.", required = true)
|
||||
private Properties properties;
|
||||
@ApiModelProperty(name = "metaData",
|
||||
value = "Meta data of the application release",
|
||||
required = true)
|
||||
private String metaData;
|
||||
|
||||
public MobileAppTypes getType() {
|
||||
return type;
|
||||
@ -142,4 +146,8 @@ public class App {
|
||||
public void setProperties(Properties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public String getMetaData() { return metaData; }
|
||||
|
||||
public void setMetaData(String metaData) { this.metaData = metaData; }
|
||||
}
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 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.common.app.mgt.windows;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class represents the Windows Enterprise App Types information.
|
||||
*/
|
||||
public class EnterpriseApplication implements Serializable {
|
||||
|
||||
private HostedAppxApplication hostedAppxApplication;
|
||||
private HostedMSIApplication hostedMSIApplication;
|
||||
|
||||
public HostedAppxApplication getHostedAppxApplication() {
|
||||
return hostedAppxApplication;
|
||||
}
|
||||
|
||||
public void setHostedAppxApplication(HostedAppxApplication hostedAppxApplication) {
|
||||
this.hostedAppxApplication = hostedAppxApplication;
|
||||
}
|
||||
|
||||
public HostedMSIApplication getHostedMSIApplication() {
|
||||
return hostedMSIApplication;
|
||||
}
|
||||
|
||||
public void setHostedMSIApplication(HostedMSIApplication hostedMSIApplication) {
|
||||
this.hostedMSIApplication = hostedMSIApplication;
|
||||
}
|
||||
|
||||
public String toJSON() {
|
||||
Gson gson = new Gson();
|
||||
return gson.toJson(this);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 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.common.app.mgt.windows;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HostedAppxApplication {
|
||||
|
||||
private String packageUri;
|
||||
private String packageFamilyName;
|
||||
private List<String> dependencyPackageUri;
|
||||
private String certificateHash;
|
||||
private String encodedCertificate;
|
||||
|
||||
public String getPackageUri() {
|
||||
return packageUri;
|
||||
}
|
||||
|
||||
public void setPackageUri(String packageUri) {
|
||||
this.packageUri = packageUri;
|
||||
}
|
||||
|
||||
public String getPackageFamilyName() {
|
||||
return packageFamilyName;
|
||||
}
|
||||
|
||||
public void setPackageFamilyName(String packageFamilyName) {
|
||||
this.packageFamilyName = packageFamilyName;
|
||||
}
|
||||
|
||||
public List<String> getDependencyPackageUri() {
|
||||
return dependencyPackageUri;
|
||||
}
|
||||
|
||||
public void setDependencyPackageUri(List<String> dependencyPackageUri) {
|
||||
this.dependencyPackageUri = dependencyPackageUri;
|
||||
}
|
||||
|
||||
public String getCertificateHash() {
|
||||
return certificateHash;
|
||||
}
|
||||
|
||||
public void setCertificateHash(String certificateHash) {
|
||||
this.certificateHash = certificateHash;
|
||||
}
|
||||
|
||||
public String getEncodedCertificate() {
|
||||
return encodedCertificate;
|
||||
}
|
||||
|
||||
public void setEncodedCertificate(String encodedCertificate) {
|
||||
this.encodedCertificate = encodedCertificate;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 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.common.app.mgt.windows;
|
||||
|
||||
|
||||
public class HostedMSIApplication {
|
||||
|
||||
private String productId;
|
||||
private String contentUrl;
|
||||
private String fileHash;
|
||||
|
||||
public String getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(String productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public String getContentUrl() {
|
||||
return contentUrl;
|
||||
}
|
||||
|
||||
public void setContentUrl(String contentUrl) {
|
||||
this.contentUrl = contentUrl;
|
||||
}
|
||||
|
||||
public String getFileHash() {
|
||||
return fileHash;
|
||||
}
|
||||
|
||||
public void setFileHash(String fileHash) {
|
||||
this.fileHash = fileHash;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
/* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.common.configuration.mgt;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CorrectiveActionConfig {
|
||||
|
||||
private List<String> mailReceivers;
|
||||
private String mailSubject;
|
||||
private String mailBody;
|
||||
private List<String> actionTypes;
|
||||
|
||||
public List<String> getMailReceivers() {
|
||||
return mailReceivers;
|
||||
}
|
||||
|
||||
public void setMailReceivers(List<String> mailReceivers) {
|
||||
this.mailReceivers = mailReceivers;
|
||||
}
|
||||
|
||||
public String getMailSubject() {
|
||||
return mailSubject;
|
||||
}
|
||||
|
||||
public void setMailSubject(String mailSubject) {
|
||||
this.mailSubject = mailSubject;
|
||||
}
|
||||
|
||||
public String getMailBody() {
|
||||
return mailBody;
|
||||
}
|
||||
|
||||
public void setMailBody(String mailBody) {
|
||||
this.mailBody = mailBody;
|
||||
}
|
||||
|
||||
public List<String> getActionTypes() {
|
||||
return actionTypes;
|
||||
}
|
||||
|
||||
public void setActionTypes(List<String> actionTypes) {
|
||||
this.actionTypes = actionTypes;
|
||||
}
|
||||
}
|
||||
@ -33,15 +33,6 @@ public class DeviceInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1998101733L;
|
||||
|
||||
// @ApiModelProperty(name = "deviceId", value = "Device Id.", required = false)
|
||||
// private int deviceId;
|
||||
//
|
||||
// @ApiModelProperty(name = "deviceType", value = "Type of the device.", required = true)
|
||||
// private String deviceType;
|
||||
//
|
||||
// @ApiModelProperty(name = "deviceId", value = "Device identifier.", required = true)
|
||||
// private DeviceIdentifier deviceIdentifier;
|
||||
|
||||
@ApiModelProperty(name = "IMEI", value = "IMEI number of the device.", required = true)
|
||||
private String IMEI;
|
||||
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (pvt) Ltd. 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.common.device.details;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceLocationHistorySnapshotWrapper {
|
||||
|
||||
private DeviceLocationHistory fullSnapshot;
|
||||
private List<Object> pathSnapshot;
|
||||
|
||||
public DeviceLocationHistory getFullSnapshot() {
|
||||
return fullSnapshot;
|
||||
}
|
||||
|
||||
public void setFullSnapshot(DeviceLocationHistory fullSnapshot) {
|
||||
this.fullSnapshot = fullSnapshot;
|
||||
}
|
||||
|
||||
public List<Object> getPathSnapshot() {
|
||||
return pathSnapshot;
|
||||
}
|
||||
|
||||
public void setPathSnapshot(List<Object> pathSnapshot) {
|
||||
this.pathSnapshot = pathSnapshot;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (pvt) Ltd. 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.common.device.details;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(
|
||||
value = "LocationBean",
|
||||
description = "This class carries all information related IOS Device location."
|
||||
)
|
||||
public class LocationBean {
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "latitude",
|
||||
value = "Latitude of the IOS device Location.",
|
||||
required = true
|
||||
)
|
||||
private float latitude;
|
||||
@ApiModelProperty(
|
||||
name = "longitude",
|
||||
value = "Longitude of the IOS device Location.",
|
||||
required = true
|
||||
)
|
||||
private float longitude;
|
||||
@ApiModelProperty(
|
||||
name = "operationId",
|
||||
value = "Specific Id of the Location operation.",
|
||||
required = true
|
||||
)
|
||||
private String operationId;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "locationEvents",
|
||||
value = "If this is a device initiated location publishing."
|
||||
)
|
||||
private List<LocationEventBean> locations;
|
||||
|
||||
public List<LocationEventBean> getLocationEvents() {
|
||||
return locations;
|
||||
}
|
||||
|
||||
public void setLocationEvents(List<LocationEventBean> locationEvents) {
|
||||
this.locations = locationEvents;
|
||||
}
|
||||
|
||||
public String getOperationId() {
|
||||
return operationId;
|
||||
}
|
||||
|
||||
public void setOperationId(String operationId) {
|
||||
this.operationId = operationId;
|
||||
}
|
||||
|
||||
|
||||
public float getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(float latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public float getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(float longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (pvt) Ltd. 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.common.device.details;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
public class LocationEventBean {
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "latitude",
|
||||
value = "Latitude of the IOS device Location.",
|
||||
required = true
|
||||
)
|
||||
private String latitude;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "longitude",
|
||||
value = "Longitude of the IOS device Location.",
|
||||
required = true
|
||||
)
|
||||
private String longitude;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "timestamp",
|
||||
value = "Device Location time.",
|
||||
required = true
|
||||
)
|
||||
private String timestamp;
|
||||
|
||||
public String getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(String latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public String getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(String longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public String getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(String timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.common.event.config;
|
||||
|
||||
public class EventAction {
|
||||
private String actionType;
|
||||
private Object payload;
|
||||
|
||||
public String getActionType() {
|
||||
return actionType;
|
||||
}
|
||||
|
||||
public void setActionType(String actionType) {
|
||||
this.actionType = actionType;
|
||||
}
|
||||
|
||||
public Object getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(Object payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.common.event.config;
|
||||
|
||||
public class EventConfig {
|
||||
private int eventId;
|
||||
private String eventSource;
|
||||
private String eventLogic;
|
||||
private String actions;
|
||||
|
||||
public String getEventLogic() {
|
||||
return eventLogic;
|
||||
}
|
||||
|
||||
public void setEventLogic(String eventLogic) {
|
||||
this.eventLogic = eventLogic;
|
||||
}
|
||||
|
||||
public String getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
public void setActions(String actions) {
|
||||
this.actions = actions;
|
||||
}
|
||||
|
||||
public int getEventId() {
|
||||
return eventId;
|
||||
}
|
||||
|
||||
public void setEventId(int eventId) {
|
||||
this.eventId = eventId;
|
||||
}
|
||||
|
||||
public String getEventSource() {
|
||||
return eventSource;
|
||||
}
|
||||
|
||||
public void setEventSource(String eventSource) {
|
||||
this.eventSource = eventSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof EventConfig) {
|
||||
EventConfig eventConfig = (EventConfig) obj;
|
||||
return this.eventSource.equalsIgnoreCase(eventConfig.getEventSource()) &&
|
||||
this.eventLogic.equalsIgnoreCase(eventConfig.getEventLogic());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{eventId=" + eventId +
|
||||
", eventSource='" + eventSource + '\'' +
|
||||
", eventLogic='" + eventLogic + '\'' +
|
||||
", actions='" + actions + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.common.event.config;
|
||||
|
||||
public class EventConfigurationException extends Exception {
|
||||
public EventConfigurationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EventConfigurationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public EventConfigurationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public EventConfigurationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.common.event.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EventConfigurationProviderService {
|
||||
/**
|
||||
* Create event configuration records
|
||||
*
|
||||
* @param eventConfigList event list to be added
|
||||
* @param groupIds group ids of the events are mapped
|
||||
* @return generated event ids
|
||||
* @throws EventConfigurationException errors thrown while creating event configuration
|
||||
*/
|
||||
List<Integer> createEventsOfDeviceGroup(List<EventConfig> eventConfigList, List<Integer> groupIds)
|
||||
throws EventConfigurationException;
|
||||
|
||||
/**
|
||||
* Update event configuration records
|
||||
*
|
||||
* @param eventConfig updated event configuration list. event ids should be present for
|
||||
* the updating events and event ids should be -1 for the newly creating events
|
||||
* @param removedEventIdList event ids of removed while updating the event configuration
|
||||
* @param groupIds group ids to be mapped with updated events
|
||||
* @return Newly created event Ids
|
||||
* @throws EventConfigurationException
|
||||
*/
|
||||
List<Integer> updateEventsOfDeviceGroup(List<EventConfig> eventConfig, List<Integer> removedEventIdList,
|
||||
List<Integer> groupIds) throws EventConfigurationException;
|
||||
|
||||
/**
|
||||
* Retrieve event list using event IDs
|
||||
*
|
||||
* @param createdEventIds event ids
|
||||
* @return {@link EventConfig} List of events of defined IDs
|
||||
* @throws EventConfigurationException
|
||||
*/
|
||||
List<EventConfig> getEvents(List<Integer> createdEventIds) throws EventConfigurationException;
|
||||
|
||||
/**
|
||||
* Get event sources attached to a specific group
|
||||
*
|
||||
* @param groupId mapped group id of events
|
||||
* @param tenantId event owning tenant
|
||||
* @return Event sources of the group
|
||||
* @throws EventConfigurationException error thrown while retrieving event sources
|
||||
*/
|
||||
List<String> getEventsSourcesOfGroup(int groupId, int tenantId) throws EventConfigurationException;
|
||||
|
||||
/**
|
||||
* Delete events by event Ids
|
||||
*
|
||||
* @param eventList event list to be deleted
|
||||
* @throws EventConfigurationException error thrown while deleting event records
|
||||
*/
|
||||
void deleteEvents(List<EventConfig> eventList) throws EventConfigurationException;
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.common.event.config;
|
||||
|
||||
public interface EventMetaData {}
|
||||
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.common.event.config;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EventOperation {
|
||||
private String eventSource;
|
||||
private EventMetaData eventDefinition;
|
||||
private String eventTriggers;
|
||||
|
||||
public String getEventSource() {
|
||||
return eventSource;
|
||||
}
|
||||
|
||||
public void setEventSource(String eventSource) {
|
||||
this.eventSource = eventSource;
|
||||
}
|
||||
|
||||
public EventMetaData getEventDefinition() {
|
||||
return eventDefinition;
|
||||
}
|
||||
|
||||
public void setEventDefinition(EventMetaData eventDefinition) {
|
||||
this.eventDefinition = eventDefinition;
|
||||
}
|
||||
|
||||
public String getEventTriggers() {
|
||||
return eventTriggers;
|
||||
}
|
||||
|
||||
public void setEventTriggers(List<EventConfig> eventList) {
|
||||
JsonArray eventTriggers = new JsonArray();
|
||||
JsonObject eventTrigger;
|
||||
for (EventConfig eventConfig : eventList) {
|
||||
eventTrigger = new JsonObject();
|
||||
eventTrigger.addProperty("eventId", eventConfig.getEventId());
|
||||
eventTrigger.addProperty("eventLogic", eventConfig.getEventLogic());
|
||||
eventTrigger.addProperty("actions", eventConfig.getActions());
|
||||
eventTriggers.add(eventTrigger);
|
||||
}
|
||||
this.eventTriggers = eventTriggers.toString();
|
||||
}
|
||||
|
||||
public String toJSON() {
|
||||
Gson gson = new Gson();
|
||||
return gson.toJson(this);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.common.event.config;
|
||||
public class EventRevokeOperation {
|
||||
private String eventSource;
|
||||
private int id;
|
||||
|
||||
public String getEventSource() {
|
||||
return eventSource;
|
||||
}
|
||||
|
||||
public void setEventSource(String eventSource) {
|
||||
this.eventSource = eventSource;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.common.geo.service;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventMetaData;
|
||||
|
||||
public class GeoFenceEventMeta implements EventMetaData {
|
||||
private int id;
|
||||
private String fenceName;
|
||||
private String description;
|
||||
private double latitude;
|
||||
private double longitude;
|
||||
private float radius;
|
||||
private String geoJson;
|
||||
private String fenceShape;
|
||||
|
||||
public GeoFenceEventMeta() {
|
||||
}
|
||||
|
||||
public GeoFenceEventMeta(GeofenceData geofenceData) {
|
||||
this.id = geofenceData.getId();
|
||||
this.fenceName = geofenceData.getFenceName();
|
||||
this.description = geofenceData.getDescription();
|
||||
this.latitude = geofenceData.getLatitude();
|
||||
this.longitude = geofenceData.getLongitude();
|
||||
this.radius = geofenceData.getRadius();
|
||||
this.geoJson = geofenceData.getGeoJson();
|
||||
this.fenceShape = geofenceData.getFenceShape();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFenceName() {
|
||||
return fenceName;
|
||||
}
|
||||
|
||||
public void setFenceName(String fenceName) {
|
||||
this.fenceName = fenceName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public float getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public void setRadius(float radius) {
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
public String getGeoJson() {
|
||||
return geoJson;
|
||||
}
|
||||
|
||||
public void setGeoJson(String geoJson) {
|
||||
this.geoJson = geoJson;
|
||||
}
|
||||
|
||||
public String getFenceShape() {
|
||||
return fenceShape;
|
||||
}
|
||||
|
||||
public void setFenceShape(String fenceShape) {
|
||||
this.fenceShape = fenceShape;
|
||||
}
|
||||
}
|
||||
@ -19,7 +19,12 @@
|
||||
package org.wso2.carbon.device.mgt.common.geo.service;
|
||||
|
||||
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.event.config.EventConfig;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -69,4 +74,101 @@ public interface GeoLocationProviderService {
|
||||
List<GeoFence> getTrafficAlerts(DeviceIdentifier identifier, String owner) throws GeoLocationBasedServiceException;
|
||||
|
||||
List<GeoFence> getTrafficAlerts() throws GeoLocationBasedServiceException;
|
||||
|
||||
/**
|
||||
* Create new GeoFence
|
||||
* @param geofenceData fence data
|
||||
* @return true if the fence creation success
|
||||
* @throws GeoLocationBasedServiceException error occurs while creating a geofence
|
||||
* @throws EventConfigurationException for errors occur while creating event configuration for the geofence
|
||||
*/
|
||||
boolean createGeofence(GeofenceData geofenceData) throws GeoLocationBasedServiceException, EventConfigurationException;
|
||||
|
||||
/**
|
||||
* Get geofence by ID
|
||||
* @param fenceId id of the fence which should be retrieved
|
||||
* @return {@link GeofenceData} Extracted geofence data
|
||||
* @throws GeoLocationBasedServiceException error occurs while retrieving a geofence
|
||||
*/
|
||||
GeofenceData getGeoFences(int fenceId) throws GeoLocationBasedServiceException;
|
||||
|
||||
/**
|
||||
* Get paginated geofence list
|
||||
* @param request Pagination Request
|
||||
* @return {@link GeofenceData} List of Geofences retrieved
|
||||
* @throws GeoLocationBasedServiceException error occurs while retrieving geofences
|
||||
*/
|
||||
List<GeofenceData> getGeoFences(PaginationRequest request) throws GeoLocationBasedServiceException;
|
||||
|
||||
/**
|
||||
* Search geo fences using the fence name
|
||||
* @param name searching name of the fence
|
||||
* @return {@link GeofenceData} list of fences found for the specific name
|
||||
* @throws GeoLocationBasedServiceException for errors occur while querying geo fences
|
||||
*/
|
||||
List<GeofenceData> getGeoFences(String name) throws GeoLocationBasedServiceException;
|
||||
|
||||
/**
|
||||
* Get all geo fences of the tenant
|
||||
* @return {@link GeofenceData} list of the all geo fences of the tenant
|
||||
* @throws GeoLocationBasedServiceException for errors occur while querying geo fences
|
||||
*/
|
||||
List<GeofenceData> getGeoFences() throws GeoLocationBasedServiceException;
|
||||
|
||||
/**
|
||||
* Delete Geofence with ID
|
||||
* @param fenceId Id of the fence which should be deleted
|
||||
* @return true if deletion success. false if not record found for the used Id
|
||||
* @throws GeoLocationBasedServiceException for errors occur while deleting geo fences
|
||||
*/
|
||||
boolean deleteGeofenceData(int fenceId) throws GeoLocationBasedServiceException;
|
||||
|
||||
/**
|
||||
* Update a Geofence. Will not be updated tenantId and owner
|
||||
* @param geofenceData Bean with updated geofence data
|
||||
* @param fenceId Id of the fence which should be updated
|
||||
* @return true if update success. false if not a record found for the used Id
|
||||
* @throws GeoLocationBasedServiceException for errors occur while updating geo fences
|
||||
* @throws EventConfigurationException for errors occur while updating event records of the geofence
|
||||
*/
|
||||
boolean updateGeofence(GeofenceData geofenceData, int fenceId)
|
||||
throws GeoLocationBasedServiceException, EventConfigurationException;
|
||||
|
||||
/**
|
||||
* Update geofence event configuration
|
||||
* @param geofenceData updated GeoFenceData object
|
||||
* @param removedEventIdList removed event ids
|
||||
* @param groupIds newly added group ids to be mapped with event records
|
||||
* @param fenceId updating fence id
|
||||
* @return true for successful update of geofence event data
|
||||
* @throws GeoLocationBasedServiceException any errors occurred while updating event records of the fence
|
||||
*/
|
||||
boolean updateGeoEventConfigurations(GeofenceData geofenceData, List<Integer> removedEventIdList,
|
||||
List<Integer> groupIds, int fenceId) throws GeoLocationBasedServiceException;
|
||||
|
||||
/**
|
||||
* Attach event data into geofence objects
|
||||
* @param geoFences list of GeofenceData to attach corresponding event data
|
||||
* @return {@link GeofenceData} events attached geofence object list
|
||||
* @throws GeoLocationBasedServiceException any errors occurred while attaching event records to geofences
|
||||
*/
|
||||
List<GeofenceData> attachEventObjects(List<GeofenceData> geoFences) throws GeoLocationBasedServiceException;
|
||||
|
||||
/**
|
||||
* Get Geofence records of groups. Attaching with corresponding event data of fences
|
||||
* @param groupId Id of the group geo which fences attached
|
||||
* @param tenantId Id of the tenant which geo fences attached
|
||||
* @param requireEventData use true for attach event records with the geo fence data
|
||||
* @return {@link GeofenceData} Queried geo fence data using group Id
|
||||
* @throws GeoLocationBasedServiceException any errors occurred while getting geofences of group
|
||||
*/
|
||||
List<GeofenceData> getGeoFencesOfGroup(int groupId, int tenantId, boolean requireEventData) throws GeoLocationBasedServiceException;
|
||||
|
||||
/**
|
||||
* Get event records mapped with specific geo fence
|
||||
* @param geoFenceId Id of the Geofence to retrieve mapped events
|
||||
* @return {@link EventConfig} Event records of the geofence
|
||||
* @throws GeoLocationBasedServiceException any errors occurred while reading event records to geofence
|
||||
*/
|
||||
List<EventConfig> getEventsOfGeoFence(int geoFenceId) throws GeoLocationBasedServiceException;
|
||||
}
|
||||
|
||||
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.common.geo.service;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfig;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventMetaData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class GeofenceData {
|
||||
private int id;
|
||||
private String fenceName;
|
||||
private String description;
|
||||
private double latitude;
|
||||
private double longitude;
|
||||
private float radius;
|
||||
private int tenantId;
|
||||
private String owner;
|
||||
private String geoJson;
|
||||
private String fenceShape;
|
||||
private List<EventConfig> eventConfig;
|
||||
private List<Integer> groupIds;
|
||||
private Map<Integer, String> groupData;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFenceName() {
|
||||
return fenceName;
|
||||
}
|
||||
|
||||
public void setFenceName(String fenceName) {
|
||||
this.fenceName = fenceName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public float getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public void setRadius(float radius) {
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
public int getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public String getGeoJson() {
|
||||
return geoJson;
|
||||
}
|
||||
|
||||
public void setGeoJson(String geoJson) {
|
||||
this.geoJson = geoJson;
|
||||
}
|
||||
|
||||
public String getFenceShape() {
|
||||
return fenceShape;
|
||||
}
|
||||
|
||||
public void setFenceShape(String fenceShape) {
|
||||
this.fenceShape = fenceShape;
|
||||
}
|
||||
|
||||
public List<EventConfig> getEventConfig() {
|
||||
return eventConfig;
|
||||
}
|
||||
|
||||
public void setEventConfig(List<EventConfig> eventConfig) {
|
||||
this.eventConfig = eventConfig;
|
||||
}
|
||||
|
||||
public List<Integer> getGroupIds() {
|
||||
return groupIds;
|
||||
}
|
||||
|
||||
public void setGroupIds(List<Integer> groupIds) {
|
||||
this.groupIds = groupIds;
|
||||
}
|
||||
|
||||
public Map<Integer, String> getGroupData() {
|
||||
return groupData;
|
||||
}
|
||||
|
||||
public void setGroupData(Map<Integer, String> groupData) {
|
||||
this.groupData = groupData;
|
||||
}
|
||||
}
|
||||
@ -55,6 +55,16 @@ public class CorrectiveAction implements Serializable {
|
||||
)
|
||||
private List<ProfileFeature> operations;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "isReactive",
|
||||
value = "Declare the action as a reactive action"
|
||||
)
|
||||
private boolean isReactive;
|
||||
|
||||
private Integer featureId;
|
||||
|
||||
private Integer associatedGeneralPolicyId;
|
||||
|
||||
public String getActionType() {
|
||||
return actionType;
|
||||
}
|
||||
@ -78,4 +88,28 @@ public class CorrectiveAction implements Serializable {
|
||||
public void setOperations(List<ProfileFeature> operations) {
|
||||
this.operations = operations;
|
||||
}
|
||||
|
||||
public Integer getFeatureId() {
|
||||
return featureId;
|
||||
}
|
||||
|
||||
public void setFeatureId(Integer featureId) {
|
||||
this.featureId = featureId;
|
||||
}
|
||||
|
||||
public Integer getAssociatedGeneralPolicyId() {
|
||||
return associatedGeneralPolicyId;
|
||||
}
|
||||
|
||||
public void setAssociatedGeneralPolicyId(Integer associatedGeneralPolicyId) {
|
||||
this.associatedGeneralPolicyId = associatedGeneralPolicyId;
|
||||
}
|
||||
|
||||
public boolean isReactive() {
|
||||
return isReactive;
|
||||
}
|
||||
|
||||
public void setReactive(boolean reactive) {
|
||||
isReactive = reactive;
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,6 +53,12 @@ public class Policy implements Comparable<Policy>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 19981017L;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "payloadVersion",
|
||||
value = "Payload version of the Policy",
|
||||
example = "1")
|
||||
private String policyPayloadVersion;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "id",
|
||||
value = "The policy ID",
|
||||
@ -201,13 +207,19 @@ public class Policy implements Comparable<Policy>, Serializable {
|
||||
example = "GENERAL")
|
||||
private String policyType;
|
||||
|
||||
@ApiModelProperty(
|
||||
name = "correctiveActions",
|
||||
value = "List of corrective actions to be applied when the policy is violated",
|
||||
example = "[{'actionType': 'POLICY', 'policyId': 1}]"
|
||||
)
|
||||
@ApiModelProperty(name = "correctiveActions",
|
||||
value = "List of corrective actions to be applied when the policy is violated")
|
||||
private List<CorrectiveAction> correctiveActions;
|
||||
|
||||
@XmlElement
|
||||
public String getPolicyPayloadVersion() {
|
||||
return policyPayloadVersion;
|
||||
}
|
||||
|
||||
public void setPolicyPayloadVersion(String policyPayloadVersion) {
|
||||
this.policyPayloadVersion = policyPayloadVersion;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getId() {
|
||||
return id;
|
||||
@ -379,13 +391,11 @@ public class Policy implements Comparable<Policy>, Serializable {
|
||||
this.policyType = policyType;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<CorrectiveAction> getCorrectiveActions() {
|
||||
return correctiveActions;
|
||||
}
|
||||
|
||||
public void setCorrectiveActions(
|
||||
List<CorrectiveAction> correctiveActions) {
|
||||
public void setCorrectiveActions(List<CorrectiveAction> correctiveActions) {
|
||||
this.correctiveActions = correctiveActions;
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@
|
||||
package org.wso2.carbon.device.mgt.common.policy.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "ProfileFeature", description = "This class carries all information related to profile "
|
||||
+ "features")
|
||||
@ -64,6 +65,11 @@ public class ProfileFeature implements Serializable {
|
||||
example = "{\\\"enabled\\\":false}")
|
||||
private Object content;
|
||||
|
||||
@ApiModelProperty(name = "correctiveActions",
|
||||
value = "List of corrective actions to be applied when the policy is violated",
|
||||
required = true)
|
||||
private List<CorrectiveAction> correctiveActions;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
@ -103,4 +109,12 @@ public class ProfileFeature implements Serializable {
|
||||
public void setContent(Object content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public List<CorrectiveAction> getCorrectiveActions() {
|
||||
return correctiveActions;
|
||||
}
|
||||
|
||||
public void setCorrectiveActions(List<CorrectiveAction> correctiveActions) {
|
||||
this.correctiveActions = correctiveActions;
|
||||
}
|
||||
}
|
||||
@ -28,6 +28,9 @@ public class Input {
|
||||
private String type;
|
||||
private String placeholderValue;
|
||||
private List<Rule> rules;
|
||||
private String apiUrl;
|
||||
private String arrayPath;
|
||||
private String dataKey;
|
||||
|
||||
@XmlElement(name = "Type")
|
||||
public String getType() {
|
||||
@ -52,4 +55,31 @@ public class Input {
|
||||
public List<Rule> getRules() { return rules; }
|
||||
|
||||
public void setRules(List<Rule> rules) { this.rules = rules; }
|
||||
|
||||
@XmlElement(name = "Url")
|
||||
public String getUrl() {
|
||||
return apiUrl;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.apiUrl = url;
|
||||
}
|
||||
|
||||
@XmlElement(name = "ArrayPath")
|
||||
public String getArrayPath() {
|
||||
return arrayPath;
|
||||
}
|
||||
|
||||
public void setArrayPath(String arrayPath) {
|
||||
this.arrayPath = arrayPath;
|
||||
}
|
||||
|
||||
@XmlElement(name = "DataKey")
|
||||
public String getDataKey() {
|
||||
return dataKey;
|
||||
}
|
||||
|
||||
public void setDataKey(String dataKey) {
|
||||
this.dataKey = dataKey;
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,6 +45,7 @@ public class Item {
|
||||
private InputList inputList;
|
||||
private String nullableValue;
|
||||
private String divider;
|
||||
private boolean isHidden;
|
||||
|
||||
@XmlElement(name = "Label")
|
||||
public String getLabel() {
|
||||
@ -207,4 +208,13 @@ public class Item {
|
||||
public void setDivider(String divider) {
|
||||
this.divider = divider;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Hidden")
|
||||
public boolean isHidden() {
|
||||
return isHidden;
|
||||
}
|
||||
|
||||
public void setHidden(boolean hidden) {
|
||||
isHidden = hidden;
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,6 +28,10 @@ public class Select {
|
||||
private String valueType;
|
||||
private List<Option> options;
|
||||
private String mode;
|
||||
private String apiUrl;
|
||||
private String defineValueKey;
|
||||
private String displayValueKey;
|
||||
private String arrayPath;
|
||||
|
||||
@XmlElement(name = "ValueType", required = true)
|
||||
public String getValueType() {
|
||||
@ -56,4 +60,40 @@ public class Select {
|
||||
public void setMode(String mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Url")
|
||||
public String getUrl() {
|
||||
return apiUrl;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.apiUrl = url;
|
||||
}
|
||||
|
||||
@XmlElement(name = "DefineValueKey")
|
||||
public String getDefineValueKey() {
|
||||
return defineValueKey;
|
||||
}
|
||||
|
||||
public void setDefineValueKey(String defineValueKey) {
|
||||
this.defineValueKey = defineValueKey;
|
||||
}
|
||||
|
||||
@XmlElement(name = "DisplayValueKey")
|
||||
public String getDisplayValueKey() {
|
||||
return displayValueKey;
|
||||
}
|
||||
|
||||
public void setDisplayValueKey(String displayValueKey) {
|
||||
this.displayValueKey = displayValueKey;
|
||||
}
|
||||
|
||||
@XmlElement(name = "ArrayPath")
|
||||
public String getArrayPath() {
|
||||
return arrayPath;
|
||||
}
|
||||
|
||||
public void setArrayPath(String arrayPath) {
|
||||
this.arrayPath = arrayPath;
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@ public final class DeviceManagementConstants {
|
||||
|
||||
public static final String DM_CACHE_MANAGER = "DM_CACHE_MANAGER";
|
||||
public static final String DEVICE_CACHE = "DEVICE_CACHE";
|
||||
public static final String GEOFENCE_CACHE = "GEOFENCE_CACHE";
|
||||
public static final String ENROLLMENT_NOTIFICATION_API_ENDPOINT = "/api/device-mgt/enrollment-notification";
|
||||
public static final String URL_SEPERATOR = "/";
|
||||
|
||||
@ -97,6 +98,14 @@ public final class DeviceManagementConstants {
|
||||
public static final String MONITOR_OPERATION_CODE = "MONITOR";
|
||||
public static final String POLICY_OPERATION_CODE = PolicyOperation.POLICY_OPERATION_CODE;
|
||||
public static final String POLICY_REVOKE_OPERATION_CODE = OperationMgtConstants.OperationCodes.POLICY_REVOKE;
|
||||
public static final String EVENT_CONFIG_OPERATION_CODE = OperationMgtConstants.OperationCodes.EVENT_CONFIG;
|
||||
public static final String EVENT_REVOKE_OPERATION_CODE = OperationMgtConstants.OperationCodes.EVENT_REVOKE;
|
||||
}
|
||||
|
||||
public static final class CorrectiveActions {
|
||||
private CorrectiveActions() {throw new AssertionError();}
|
||||
|
||||
public static final String E_MAIL = "MAIL";
|
||||
}
|
||||
|
||||
public static final class EmailAttributes {
|
||||
@ -117,6 +126,7 @@ public final class DeviceManagementConstants {
|
||||
public static final String USER_REGISTRATION_TEMPLATE = "user-registration";
|
||||
public static final String USER_ENROLLMENT_TEMPLATE = "user-enrollment";
|
||||
public static final String USER_VERIFY_TEMPLATE = "user-verify";
|
||||
public static final String POLICY_VIOLATE_TEMPLATE = "policy-violating-notifier";
|
||||
public static final String USER_WELCOME_TEMPLATE = "user-welcome";
|
||||
public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation";
|
||||
}
|
||||
|
||||
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.cache;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class GeoCacheKey {
|
||||
private int fenceId;
|
||||
private int tenantId;
|
||||
private volatile int hashCode;
|
||||
|
||||
public GeoCacheKey(int fenceId, int tenantId) {
|
||||
this.fenceId = fenceId;
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
public GeoCacheKey() {
|
||||
}
|
||||
|
||||
public int getFenceId() {
|
||||
return fenceId;
|
||||
}
|
||||
|
||||
public void setFenceId(int fenceId) {
|
||||
this.fenceId = fenceId;
|
||||
}
|
||||
|
||||
public int getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!GeoCacheKey.class.isAssignableFrom(obj.getClass())) {
|
||||
return false;
|
||||
}
|
||||
final GeoCacheKey other = (GeoCacheKey) obj;
|
||||
String thisId = this.fenceId + "-" + "_" + this.tenantId;
|
||||
String otherId = other.fenceId + "-" + "_" + other.tenantId;
|
||||
return thisId.equals(otherId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (hashCode == 0) {
|
||||
hashCode = Objects.hash(fenceId, tenantId);
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.cache;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData;
|
||||
|
||||
public interface GeoCacheManager {
|
||||
/**
|
||||
* Add geo fences to the cache
|
||||
* @param geofenceData adding fence object
|
||||
* @param fenceId id of the fence
|
||||
* @param tenantId id of the tenant
|
||||
*/
|
||||
void addFenceToCache(GeofenceData geofenceData, int fenceId, int tenantId);
|
||||
|
||||
/**
|
||||
* Update geo fences already in cache
|
||||
* @param geofenceData updating geo fence object
|
||||
* @param fenceId id of the fence
|
||||
* @param tenantId id of the tenant
|
||||
*/
|
||||
void updateGeoFenceInCache(GeofenceData geofenceData, int fenceId, int tenantId);
|
||||
|
||||
/**
|
||||
* Remove geo fence from cache
|
||||
* @param fenceId id of the fence
|
||||
* @param tenantId id of the tenant
|
||||
*/
|
||||
void removeFenceFromCache(int fenceId, int tenantId);
|
||||
|
||||
/**
|
||||
* Get geo fence data from the cache
|
||||
* @param fenceId id of the retrieving fence object
|
||||
* @param tenantId tenant id of the fence created
|
||||
* @return GeofenceData object if the cache have the specific object or null if there is no entry
|
||||
*/
|
||||
GeofenceData getGeoFenceFromCache(int fenceId, int tenantId);
|
||||
}
|
||||
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.cache.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData;
|
||||
import org.wso2.carbon.device.mgt.core.cache.GeoCacheKey;
|
||||
import org.wso2.carbon.device.mgt.core.cache.GeoCacheManager;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
|
||||
import javax.cache.Cache;
|
||||
|
||||
public class GeoCacheManagerImpl implements GeoCacheManager {
|
||||
|
||||
private static GeoCacheManager geoCacheManager;
|
||||
private GeoCacheManagerImpl() {}
|
||||
|
||||
public static GeoCacheManager getInstance() {
|
||||
if (geoCacheManager == null) {
|
||||
synchronized (GeoCacheManagerImpl.class) {
|
||||
if (geoCacheManager == null) {
|
||||
geoCacheManager = new GeoCacheManagerImpl();
|
||||
}
|
||||
}
|
||||
}
|
||||
return geoCacheManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFenceToCache(GeofenceData geofenceData, int fenceId, int tenantId) {
|
||||
Cache<GeoCacheKey, GeofenceData> lCache = DeviceManagerUtil.getGeoCache();
|
||||
if (lCache != null) {
|
||||
GeoCacheKey cacheKey = getCacheKey(fenceId, tenantId);
|
||||
if (lCache.containsKey(cacheKey)) {
|
||||
this.updateGeoFenceInCache(geofenceData, fenceId, tenantId);
|
||||
} else {
|
||||
lCache.put(cacheKey, geofenceData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFenceFromCache(int fenceId, int tenantId) {
|
||||
Cache<GeoCacheKey, GeofenceData> lCache = DeviceManagerUtil.getGeoCache();
|
||||
if (lCache != null) {
|
||||
GeoCacheKey cacheKey = getCacheKey(fenceId, tenantId);
|
||||
if (lCache.containsKey(cacheKey)) {
|
||||
lCache.remove(cacheKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateGeoFenceInCache(GeofenceData geofenceData, int fenceId, int tenantId) {
|
||||
Cache<GeoCacheKey, GeofenceData> lCache = DeviceManagerUtil.getGeoCache();
|
||||
if (lCache != null) {
|
||||
GeoCacheKey cacheKey = getCacheKey(fenceId, tenantId);
|
||||
if (lCache.containsKey(cacheKey)) {
|
||||
lCache.replace(cacheKey, geofenceData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeofenceData getGeoFenceFromCache(int fenceId, int tenantId) {
|
||||
GeofenceData geofenceData = null;
|
||||
Cache<GeoCacheKey, GeofenceData> lCache = DeviceManagerUtil.getGeoCache();
|
||||
if (lCache != null) {
|
||||
geofenceData = lCache.get(getCacheKey(fenceId, tenantId));
|
||||
}
|
||||
return geofenceData;
|
||||
}
|
||||
|
||||
private GeoCacheKey getCacheKey(int fenceId, int tenantId) {
|
||||
GeoCacheKey geoCacheKey = new GeoCacheKey();
|
||||
geoCacheKey.setFenceId(fenceId);
|
||||
geoCacheKey.setTenantId(tenantId);
|
||||
return geoCacheKey;
|
||||
}
|
||||
}
|
||||
@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.core.config.analytics.OperationAnalyticsConfig
|
||||
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.DeviceCacheConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.config.cache.GeoFenceCacheConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.config.geo.location.GeoLocationConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations;
|
||||
import org.wso2.carbon.device.mgt.core.config.keymanager.KeyManagerConfigurations;
|
||||
@ -54,6 +55,7 @@ public final class DeviceManagementConfig {
|
||||
private PullNotificationConfiguration pullNotificationConfiguration;
|
||||
private DeviceStatusTaskConfig deviceStatusTaskConfig;
|
||||
private DeviceCacheConfiguration deviceCacheConfiguration;
|
||||
private GeoFenceCacheConfiguration geoFenceCacheConfiguration;
|
||||
private CertificateCacheConfiguration certificateCacheConfiguration;
|
||||
private OperationAnalyticsConfiguration operationAnalyticsConfiguration;
|
||||
private GeoLocationConfiguration geoLocationConfiguration;
|
||||
@ -154,6 +156,15 @@ public final class DeviceManagementConfig {
|
||||
this.deviceCacheConfiguration = deviceCacheConfiguration;
|
||||
}
|
||||
|
||||
@XmlElement(name = "GeoFenceCacheConfiguration", required = true)
|
||||
public GeoFenceCacheConfiguration getGeoFenceCacheConfiguration() {
|
||||
return geoFenceCacheConfiguration;
|
||||
}
|
||||
|
||||
public void setGeoFenceCacheConfiguration(GeoFenceCacheConfiguration geoFenceCacheConfiguration) {
|
||||
this.geoFenceCacheConfiguration = geoFenceCacheConfiguration;
|
||||
}
|
||||
|
||||
@XmlElement(name = "CertificateCacheConfiguration", required = true)
|
||||
public CertificateCacheConfiguration getCertificateCacheConfiguration() {
|
||||
return certificateCacheConfiguration;
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.cache;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "GeoFenceCacheConfiguration")
|
||||
public class GeoFenceCacheConfiguration {
|
||||
|
||||
private boolean isEnabled;
|
||||
private int expiryTime;
|
||||
private long capacity;
|
||||
|
||||
@XmlElement(name = "Enable", required = true)
|
||||
public boolean isEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
isEnabled = enabled;
|
||||
}
|
||||
|
||||
@XmlElement(name = "ExpiryTime", required = true)
|
||||
public int getExpiryTime() {
|
||||
return expiryTime;
|
||||
}
|
||||
|
||||
public void setExpiryTime(int expiryTime) {
|
||||
this.expiryTime = expiryTime;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Capacity", required = true)
|
||||
public long getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public void setCapacity(long capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
}
|
||||
@ -29,10 +29,13 @@ import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.ApplicationDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.EnrollmentDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.event.GenericEventConfigDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.GeofenceDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.device.GenericDeviceDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.device.OracleDeviceDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.device.PostgreSQLDeviceDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.device.SQLServerDeviceDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.event.H2EventConfigDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO;
|
||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.impl.DeviceDetailsDAOImpl;
|
||||
@ -149,6 +152,27 @@ public class DeviceManagementDAOFactory {
|
||||
return new PrivacyComplianceDAOImpl();
|
||||
}
|
||||
|
||||
public static GeofenceDAO getGeofenceDAO() {
|
||||
return new GeofenceDAOImpl();
|
||||
}
|
||||
|
||||
public static EventConfigDAO getEventConfigDAO() {
|
||||
if (databaseEngine != null) {
|
||||
switch (databaseEngine) {
|
||||
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL:
|
||||
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE:
|
||||
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL:
|
||||
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||
return new GenericEventConfigDAOImpl();
|
||||
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2:
|
||||
return new H2EventConfigDAOImpl();
|
||||
default:
|
||||
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Database engine has not initialized properly.");
|
||||
}
|
||||
|
||||
public static void init(DataSourceConfig config) {
|
||||
dataSource = resolveDataSource(config);
|
||||
try {
|
||||
|
||||
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EventConfigDAO {
|
||||
|
||||
/**
|
||||
* Create event configuration entries of the db for a selected tenant
|
||||
* @param eventConfigList event list to be created
|
||||
* @param tenantId corresponding tenant id of the events
|
||||
* @return generated event ids while storing geofence data
|
||||
* @throws EventManagementDAOException error occurred while creating event records
|
||||
*/
|
||||
List<Integer> storeEventRecords(List<EventConfig> eventConfigList, int tenantId) throws EventManagementDAOException;
|
||||
|
||||
/**
|
||||
* Cerate even-group mapping records
|
||||
* @param eventIds event ids to be mapped with groups
|
||||
* @param groupIds group ids of the event attached with
|
||||
* @return true for the successful creation
|
||||
* @throws EventManagementDAOException error occurred while creating event-group mapping records
|
||||
*/
|
||||
boolean addEventGroupMappingRecords(List<Integer> eventIds, List<Integer> groupIds) throws EventManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get events owned by a specific device group
|
||||
* @param groupIds group ids of the events
|
||||
* @param tenantId tenant of the events owning
|
||||
* @return list of event configuration filtered by tenant id and group ids
|
||||
* @throws EventManagementDAOException error occurred while reading event records
|
||||
*/
|
||||
List<EventConfig> getEventsOfGroups(List<Integer> groupIds, int tenantId) throws EventManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get events of groups using group Id
|
||||
* @param groupId id of the group
|
||||
* @param tenantId id of the tenant
|
||||
* @return EventConfig list of specific group
|
||||
* @throws EventManagementDAOException errors occur while retrieving events of groups
|
||||
*/
|
||||
List<EventConfig> getEventsOfGroups(int groupId, int tenantId) throws EventManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete event group mapping records using the group ids
|
||||
* @param groupIdsToDelete id of groups
|
||||
* @throws EventManagementDAOException error occurred while deleting event-group mapping records
|
||||
*/
|
||||
void deleteEventGroupMappingRecordsByGroupIds(List<Integer> groupIdsToDelete) throws EventManagementDAOException;
|
||||
|
||||
/**
|
||||
* Update event records of the tenant
|
||||
* @param eventsToUpdate updating event records
|
||||
* @throws EventManagementDAOException error occurred while updating events
|
||||
*/
|
||||
void updateEventRecords(List<EventConfig> eventsToUpdate) throws EventManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete events using event ids
|
||||
* @param eventsIdsToDelete ids of the events which should be deleted
|
||||
* @throws EventManagementDAOException error occurred while deleting event records
|
||||
*/
|
||||
void deleteEventRecords(List<Integer> eventsIdsToDelete) throws EventManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get event records by event ids
|
||||
* @param eventIds filtering event ids
|
||||
* @return filtered event configuration list
|
||||
* @throws EventManagementDAOException error occurred while reading events
|
||||
*/
|
||||
List<EventConfig> getEventsById(List<Integer> eventIds) throws EventManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get group ids belong to events using event ids
|
||||
* @param eventIds Ids of the events mapped with group
|
||||
* @return Group Id list
|
||||
* @throws EventManagementDAOException thrown errors while retrieving group Ids of events
|
||||
*/
|
||||
List<Integer> getGroupsOfEvents(List<Integer> eventIds) throws EventManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete event group mapping records using event Ids
|
||||
* @param eventIds Ids of the events
|
||||
* @throws EventManagementDAOException thrown errors while deleting event group mappings
|
||||
*/
|
||||
void deleteEventGroupMappingRecordsByEventIds(List<Integer> eventIds) throws EventManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve event sources mapped with specific groups and tenant
|
||||
* @param groupId Id of the group
|
||||
* @param tenantId Id of the tenant
|
||||
* @return Event source list belong to
|
||||
* @throws EventManagementDAOException thrown errors while retrieving event sources
|
||||
*/
|
||||
List<String> getEventSourcesOfGroups(int groupId, int tenantId) throws EventManagementDAOException;
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.dao;
|
||||
|
||||
public class EventManagementDAOException extends Exception{
|
||||
public EventManagementDAOException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EventManagementDAOException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public EventManagementDAOException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public EventManagementDAOException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfig;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData;
|
||||
import org.wso2.carbon.device.mgt.core.dto.event.config.GeoFenceGroupMap;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Use to manage geofence data in DB
|
||||
*/
|
||||
public interface GeofenceDAO {
|
||||
|
||||
/**
|
||||
* Create new record of GeoFence
|
||||
* @param geofenceData GeoFence record data
|
||||
* @return created row count
|
||||
* @throws DeviceManagementDAOException error occurs while saving the data
|
||||
*/
|
||||
GeofenceData saveGeofence(GeofenceData geofenceData) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve a geofence record for specified Id
|
||||
* @param fenceId Id of the fence which should be queried
|
||||
* @return Retrieved geofence data with tenant and owner info
|
||||
* @throws DeviceManagementDAOException error occurs while reading the data
|
||||
*/
|
||||
GeofenceData getGeofence(int fenceId) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve a paginated list of geofence data for a specific tenant
|
||||
* @param request pagination request with offset and limit
|
||||
* @param tenantId Id of the tenant which fences owned
|
||||
* @return List of geofences retrieved
|
||||
* @throws DeviceManagementDAOException error occurs while reading the data
|
||||
*/
|
||||
List<GeofenceData> getGeoFencesOfTenant(PaginationRequest request, int tenantId)
|
||||
throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Search geofence by fence name of a specific tenant
|
||||
* @param fenceName searching name
|
||||
* @param tenantId searching tenant
|
||||
* @return list of found fences
|
||||
* @throws DeviceManagementDAOException
|
||||
*/
|
||||
List<GeofenceData> getGeoFencesOfTenant(String fenceName, int tenantId)
|
||||
throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get all fences of the specific tenant
|
||||
* @param tenantId tenant id of the fences
|
||||
* @return list of the fences owned by the tenant
|
||||
* @throws DeviceManagementDAOException
|
||||
*/
|
||||
List<GeofenceData> getGeoFencesOfTenant(int tenantId)
|
||||
throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete a geofence using the geofence Id
|
||||
* @param fenceId Id of the fence which should be deleted
|
||||
* @return Affected row count
|
||||
* @throws DeviceManagementDAOException error occurs while deleting the data
|
||||
*/
|
||||
int deleteGeofenceById(int fenceId) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Update a geofence record using fence id
|
||||
* @param geofenceData updated geofence data
|
||||
* @param fenceId id of the fence which should be updated
|
||||
* @return affected row count
|
||||
* @throws DeviceManagementDAOException error occurs while updating the data
|
||||
*/
|
||||
int updateGeofence(GeofenceData geofenceData, int fenceId) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Create geofence-group mapping records for the fence associated groups
|
||||
* @param geofenceData geofence data to be mapped with device group
|
||||
* @param groupIds group ids of the geofence
|
||||
* @return true for the successful record creation
|
||||
* @throws DeviceManagementDAOException error occurred while saving event records
|
||||
*/
|
||||
boolean createGeofenceGroupMapping(GeofenceData geofenceData, List<Integer> groupIds) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get associated group ids of a geofence mapped with
|
||||
* @param fenceId id of the fence
|
||||
* @return list of group ids mapped with the specified fence
|
||||
* @throws DeviceManagementDAOException error occurred while reading group id records
|
||||
*/
|
||||
List<Integer> getGroupIdsOfGeoFence(int fenceId) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete geofence-group mapping records
|
||||
* @param groupIdsToDelete group ids to be removed from the mapping table
|
||||
* @throws DeviceManagementDAOException error occurred while deleting group id mapping records
|
||||
*/
|
||||
void deleteGeofenceGroupMapping(List<Integer> groupIdsToDelete) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Create geofence-event mapping records
|
||||
* @param fenceId geofence id of the mapping records to be placed
|
||||
* @param eventIds generated event ids for the geofence event configuration
|
||||
* @throws DeviceManagementDAOException error occurred while creating geofence event mapping records
|
||||
*/
|
||||
void createGeofenceEventMapping(int fenceId, List<Integer> eventIds) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Remove geofence-event mapping records
|
||||
* @param removedEventIdList event ids should be removed from the records
|
||||
* @throws DeviceManagementDAOException error occurred deleting geofence event mapping
|
||||
*/
|
||||
void deleteGeofenceEventMapping(List<Integer> removedEventIdList) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get events of the geofence using fence ids
|
||||
* @param geofenceIds ids of geo fences to be queried
|
||||
* @return Event config list mapped with fence id
|
||||
* @throws DeviceManagementDAOException error occurred while retrieving geo fence event map
|
||||
*/
|
||||
Map<Integer, List<EventConfig>> getEventsOfGeoFences(List<Integer> geofenceIds) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get events of a particular geofence
|
||||
* @param geofenceId id of the fence to be queried
|
||||
* @return EventConfig list of the particular geofence
|
||||
* @throws DeviceManagementDAOException thrown errors while getting events of geofence
|
||||
*/
|
||||
List<EventConfig> getEventsOfGeoFence(int geofenceId) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get group Ids mapped with fence ids
|
||||
* @param fenceIds fence id list to be queried
|
||||
* @return GroupIds mapped with geofence id
|
||||
* @throws DeviceManagementDAOException thrown errors while retrieving group Ids of geo fence
|
||||
*/
|
||||
Set<GeoFenceGroupMap> getGroupIdsOfGeoFences(List<Integer> fenceIds) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get geo fences of the specific group and tenant
|
||||
* @param groupId id of the group
|
||||
* @param tenantId tenant id of the geo fences
|
||||
* @return List of geofence data mapped with specific group and tenant
|
||||
* @throws DeviceManagementDAOException
|
||||
*/
|
||||
List<GeofenceData> getGeoFences(int groupId, int tenantId) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Get geofence using fence id and attached group Ids
|
||||
* @param fenceId id of the fence
|
||||
* @param requireGroupData true if mapped group data needed
|
||||
* @return Geofence data
|
||||
* @throws DeviceManagementDAOException
|
||||
*/
|
||||
GeofenceData getGeofence(int fenceId, boolean requireGroupData) throws DeviceManagementDAOException;
|
||||
}
|
||||
@ -1874,41 +1874,46 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceLocationHistorySnapshot> getDeviceLocationInfo(DeviceIdentifier deviceIdentifier, long from, long to)
|
||||
throws DeviceManagementDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
public List<DeviceLocationHistorySnapshot> getDeviceLocationInfo(DeviceIdentifier deviceIdentifier, long from,
|
||||
long to) throws DeviceManagementDAOException {
|
||||
List<DeviceLocationHistorySnapshot> deviceLocationHistories = new ArrayList<>();
|
||||
String sql = "SELECT "
|
||||
+ "DEVICE_ID, "
|
||||
+ "TENANT_ID, "
|
||||
+ "DEVICE_ID_NAME, "
|
||||
+ "DEVICE_TYPE_NAME, "
|
||||
+ "LATITUDE, "
|
||||
+ "LONGITUDE, "
|
||||
+ "SPEED, "
|
||||
+ "HEADING, "
|
||||
+ "TIMESTAMP, "
|
||||
+ "GEO_HASH, "
|
||||
+ "DEVICE_OWNER, "
|
||||
+ "DEVICE_ALTITUDE, "
|
||||
+ "DISTANCE "
|
||||
+ "FROM DM_DEVICE_HISTORY_LAST_SEVEN_DAYS "
|
||||
+ "WHERE "
|
||||
+ "DEVICE_ID_NAME = ? AND "
|
||||
+ "DEVICE_TYPE_NAME = ? AND "
|
||||
+ "TIMESTAMP BETWEEN ? AND ? "
|
||||
+ "ORDER BY timestamp";
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
|
||||
String sql =
|
||||
"SELECT DEVICE_ID, TENANT_ID, DEVICE_ID_NAME, DEVICE_TYPE_NAME, LATITUDE, LONGITUDE, SPEED, " +
|
||||
"HEADING, TIMESTAMP, GEO_HASH, DEVICE_OWNER, DEVICE_ALTITUDE, DISTANCE " +
|
||||
"FROM DM_DEVICE_HISTORY_LAST_SEVEN_DAYS " +
|
||||
"WHERE DEVICE_ID_NAME = ? " +
|
||||
"AND DEVICE_TYPE_NAME = ? " +
|
||||
"AND TIMESTAMP >= ? " +
|
||||
"AND TIMESTAMP <= ?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
Connection conn = this.getConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setString(1, deviceIdentifier.getId());
|
||||
stmt.setString(2, deviceIdentifier.getType());
|
||||
stmt.setLong(3, from);
|
||||
stmt.setLong(4, to);
|
||||
rs = stmt.executeQuery();
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
deviceLocationHistories.add(DeviceManagementDAOUtil.loadDeviceLocation(rs));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String errMessage = "Error occurred while obtaining the DB connection to get device location information";
|
||||
log.error(errMessage, e);
|
||||
throw new DeviceManagementDAOException(errMessage, e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
String msg = "Error occurred while obtaining the DB connection to get device location information";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
return deviceLocationHistories;
|
||||
}
|
||||
|
||||
@ -0,0 +1,329 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfig;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.EventConfigDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOException;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractEventConfigDAO implements EventConfigDAO {
|
||||
private static final Log log = LogFactory.getLog(AbstractEventConfigDAO.class);
|
||||
|
||||
@Override
|
||||
public boolean addEventGroupMappingRecords(List<Integer> eventIds, List<Integer> groupIds) throws EventManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "INSERT INTO DM_DEVICE_EVENT_GROUP_MAPPING(" +
|
||||
"EVENT_ID ," +
|
||||
"GROUP_ID) " +
|
||||
"VALUES (?, ?)";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
for (Integer groupId : groupIds) {
|
||||
for (Integer eventId : eventIds) {
|
||||
stmt.setInt(1, eventId);
|
||||
stmt.setInt(2, groupId);
|
||||
stmt.addBatch();
|
||||
}
|
||||
}
|
||||
return stmt.executeBatch().length > 0;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while creating event group mapping records";
|
||||
log.error(msg, e);
|
||||
throw new EventManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EventConfig> getEventsOfGroups(List<Integer> groupIds, int tenantId) throws EventManagementDAOException {
|
||||
try {
|
||||
List<EventConfig> eventList = new ArrayList<>();
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT " +
|
||||
"E.ID AS EVENT_ID, " +
|
||||
"EVENT_SOURCE, " +
|
||||
"EVENT_LOGIC, " +
|
||||
"ACTIONS " +
|
||||
"FROM DM_DEVICE_EVENT E, DM_DEVICE_EVENT_GROUP_MAPPING G " +
|
||||
"WHERE G.EVENT_ID = E.ID " +
|
||||
"AND G.GROUP_ID IN (%s) " +
|
||||
"AND E.TENANT_ID = ? " +
|
||||
"GROUP BY E.ID";
|
||||
String inClause = String.join(", ", Collections.nCopies(groupIds.size(), "?"));
|
||||
sql = String.format(sql, inClause);
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
int index = 1;
|
||||
for (Integer groupId : groupIds) {
|
||||
stmt.setInt(index++, groupId);
|
||||
}
|
||||
stmt.setInt(index, tenantId);
|
||||
ResultSet rst = stmt.executeQuery();
|
||||
while (rst.next()) {
|
||||
EventConfig event = new EventConfig();
|
||||
event.setEventId(rst.getInt("EVENT_ID"));
|
||||
event.setEventSource(rst.getString("EVENT_SOURCE"));
|
||||
event.setEventLogic(rst.getString("EVENT_LOGIC"));
|
||||
event.setActions(rst.getString("ACTIONS"));
|
||||
eventList.add(event);
|
||||
}
|
||||
return eventList;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while creating event group mapping records";
|
||||
log.error(msg, e);
|
||||
throw new EventManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EventConfig> getEventsOfGroups(int groupId, int tenantId) throws EventManagementDAOException {
|
||||
try {
|
||||
List<EventConfig> eventList = new ArrayList<>();
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT " +
|
||||
"E.ID AS EVENT_ID, " +
|
||||
"EVENT_SOURCE, " +
|
||||
"EVENT_LOGIC, " +
|
||||
"ACTIONS " +
|
||||
"FROM DM_DEVICE_EVENT E, DM_DEVICE_EVENT_GROUP_MAPPING G " +
|
||||
"WHERE G.EVENT_ID = E.ID " +
|
||||
"AND G.GROUP_ID = ? " +
|
||||
"AND E.TENANT_ID = ? " +
|
||||
"GROUP BY E.ID";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setInt(1, groupId);
|
||||
stmt.setInt(2, tenantId);
|
||||
ResultSet rst = stmt.executeQuery();
|
||||
while (rst.next()) {
|
||||
EventConfig event = new EventConfig();
|
||||
event.setEventId(rst.getInt("EVENT_ID"));
|
||||
event.setEventSource(rst.getString("EVENT_SOURCE"));
|
||||
event.setEventLogic(rst.getString("EVENT_LOGIC"));
|
||||
event.setActions(rst.getString("ACTIONS"));
|
||||
eventList.add(event);
|
||||
}
|
||||
return eventList;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving event records of group " + groupId
|
||||
+ " and tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new EventManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteEventGroupMappingRecordsByEventIds(List<Integer> eventsIdsToDelete) throws EventManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "DELETE FROM DM_DEVICE_EVENT_GROUP_MAPPING WHERE EVENT_ID IN (%s)";
|
||||
String inClause = String.join(", ", Collections.nCopies(eventsIdsToDelete.size(), "?"));
|
||||
sql = String.format(sql, inClause);
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
int index = 1;
|
||||
for (Integer eventId : eventsIdsToDelete) {
|
||||
stmt.setInt(index++, eventId);
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting event group mapping records";
|
||||
log.error(msg, e);
|
||||
throw new EventManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteEventGroupMappingRecordsByGroupIds(List<Integer> groupIdsToDelete) throws EventManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "DELETE FROM DM_DEVICE_EVENT_GROUP_MAPPING WHERE GROUP_ID IN (%s)";
|
||||
String inClause = String.join(", ", Collections.nCopies(groupIdsToDelete.size(), "?"));
|
||||
sql = String.format(sql, inClause);
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
int index = 1;
|
||||
for (Integer groupId : groupIdsToDelete) {
|
||||
stmt.setInt(index++, groupId);
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting event group mapping records";
|
||||
log.error(msg, e);
|
||||
throw new EventManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEventRecords(List<EventConfig> eventsToUpdate) throws EventManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "UPDATE DM_DEVICE_EVENT SET " +
|
||||
"ACTIONS = ? " +
|
||||
"WHERE ID = ?";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
for (EventConfig updatingEvent : eventsToUpdate) {
|
||||
stmt.setString(1, updatingEvent.getActions());
|
||||
stmt.setInt(2, updatingEvent.getEventId());
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating event records";
|
||||
log.error(msg, e);
|
||||
throw new EventManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteEventRecords(List<Integer> eventsIdsToDelete) throws EventManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "DELETE FROM DM_DEVICE_EVENT WHERE ID = ?";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
for (Integer eventId : eventsIdsToDelete) {
|
||||
stmt.setInt(1, eventId);
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting event records of tenant";
|
||||
log.error(msg, e);
|
||||
throw new EventManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EventConfig> getEventsById(List<Integer> eventIdList) throws EventManagementDAOException {
|
||||
try {
|
||||
List<EventConfig> eventList = new ArrayList<>();
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT " +
|
||||
"ID AS EVENT_ID, " +
|
||||
"EVENT_SOURCE, " +
|
||||
"EVENT_LOGIC, " +
|
||||
"ACTIONS " +
|
||||
"FROM DM_DEVICE_EVENT " +
|
||||
"WHERE ID IN (%s) ";
|
||||
String inClause = String.join(", ", Collections.nCopies(eventIdList.size(), "?"));
|
||||
sql = String.format(sql, inClause);
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
int index = 1;
|
||||
for (Integer eventId : eventIdList) {
|
||||
if (eventId != -1) {
|
||||
stmt.setInt(index++, eventId);
|
||||
}
|
||||
}
|
||||
ResultSet rst = stmt.executeQuery();
|
||||
while (rst.next()) {
|
||||
EventConfig event = new EventConfig();
|
||||
event.setEventId(rst.getInt("EVENT_ID"));
|
||||
event.setEventSource(rst.getString("EVENT_SOURCE"));
|
||||
event.setEventLogic(rst.getString("EVENT_LOGIC"));
|
||||
event.setActions(rst.getString("ACTIONS"));
|
||||
eventList.add(event);
|
||||
}
|
||||
return eventList;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while creating event group mapping records";
|
||||
log.error(msg, e);
|
||||
throw new EventManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getGroupsOfEvents(List<Integer> eventIdList) throws EventManagementDAOException {
|
||||
try {
|
||||
List<Integer> groupIdList = new ArrayList<>();
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT " +
|
||||
"GROUP_ID " +
|
||||
"FROM DM_DEVICE_EVENT_GROUP_MAPPING " +
|
||||
"WHERE EVENT_ID IN (%s) " +
|
||||
"GROUP BY GROUP_ID";
|
||||
String inClause = String.join(", ", Collections.nCopies(eventIdList.size(), "?"));
|
||||
sql = String.format(sql, inClause);
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
int index = 1;
|
||||
for (Integer eventId : eventIdList) {
|
||||
if (eventId != -1) {
|
||||
stmt.setInt(index++, eventId);
|
||||
}
|
||||
}
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
groupIdList.add(resultSet.getInt("GROUP_ID"));
|
||||
}
|
||||
return groupIdList;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while creating event group mapping records";
|
||||
log.error(msg, e);
|
||||
throw new EventManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getEventSourcesOfGroups(int groupId, int tenantId) throws EventManagementDAOException {
|
||||
try {
|
||||
List<String> eventSourceList = new ArrayList<>();
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT " +
|
||||
"EVENT_SOURCE " +
|
||||
"FROM DM_DEVICE_EVENT E, DM_DEVICE_EVENT_GROUP_MAPPING G " +
|
||||
"WHERE G.EVENT_ID = E.ID " +
|
||||
"AND G.GROUP_ID = ? " +
|
||||
"AND E.TENANT_ID = ? " +
|
||||
"GROUP BY EVENT_SOURCE";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setInt(1, groupId);
|
||||
stmt.setInt(2, tenantId);
|
||||
ResultSet rst = stmt.executeQuery();
|
||||
while (rst.next()) {
|
||||
eventSourceList.add(rst.getString("EVENT_SOURCE"));
|
||||
}
|
||||
return eventSourceList;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving event records of group " + groupId
|
||||
+ " and tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new EventManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
return DeviceManagementDAOFactory.getConnection();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,640 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfig;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.GeofenceDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dto.event.config.GeoFenceGroupMap;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class GeofenceDAOImpl implements GeofenceDAO {
|
||||
private static final Log log = LogFactory.getLog(GeofenceDAOImpl.class);
|
||||
@Override
|
||||
public GeofenceData saveGeofence(GeofenceData geofenceData) throws DeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "INSERT INTO DM_GEOFENCE(" +
|
||||
"FENCE_NAME, " +
|
||||
"DESCRIPTION, " +
|
||||
"LATITUDE, " +
|
||||
"LONGITUDE, " +
|
||||
"RADIUS, " +
|
||||
"GEO_JSON, " +
|
||||
"FENCE_SHAPE, " +
|
||||
"CREATED_TIMESTAMP, " +
|
||||
"OWNER, " +
|
||||
"TENANT_ID) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
stmt.setString(1, geofenceData.getFenceName());
|
||||
stmt.setString(2, geofenceData.getDescription());
|
||||
stmt.setDouble(3, geofenceData.getLatitude());
|
||||
stmt.setDouble(4, geofenceData.getLongitude());
|
||||
stmt.setFloat(5, geofenceData.getRadius());
|
||||
stmt.setString(6, geofenceData.getGeoJson());
|
||||
stmt.setString(7, geofenceData.getFenceShape());
|
||||
stmt.setTimestamp(8, new Timestamp(new Date().getTime()));
|
||||
stmt.setString(9, geofenceData.getOwner());
|
||||
stmt.setInt(10, geofenceData.getTenantId());
|
||||
if (stmt.executeUpdate() > 0) {
|
||||
ResultSet generatedKeys = stmt.getGeneratedKeys();
|
||||
if (generatedKeys.next()) {
|
||||
geofenceData.setId(generatedKeys.getInt(1));
|
||||
}
|
||||
}
|
||||
return geofenceData;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while creating Geofence for the tenant id "+geofenceData.getTenantId();
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeofenceData getGeofence(int fenceId) throws DeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
GeofenceData geofenceData = null;
|
||||
String sql = "SELECT " +
|
||||
"ID, " +
|
||||
"FENCE_NAME, " +
|
||||
"DESCRIPTION, " +
|
||||
"LATITUDE, " +
|
||||
"LONGITUDE, " +
|
||||
"RADIUS, " +
|
||||
"GEO_JSON, " +
|
||||
"FENCE_SHAPE, " +
|
||||
"OWNER, " +
|
||||
"TENANT_ID " +
|
||||
"FROM DM_GEOFENCE " +
|
||||
"WHERE ID = ?";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setInt(1, fenceId);
|
||||
try (ResultSet rst = stmt.executeQuery()) {
|
||||
List<GeofenceData> geofenceDataList = extractGeofenceData(rst);
|
||||
if (!geofenceDataList.isEmpty()) {
|
||||
geofenceData = geofenceDataList.get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return geofenceData;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving Geofence with id "+fenceId;
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeofenceData> getGeoFencesOfTenant(PaginationRequest request, int tenantId)
|
||||
throws DeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
boolean isNameProvided = false;
|
||||
List<GeofenceData> geofenceData;
|
||||
String sql = "SELECT " +
|
||||
"ID, " +
|
||||
"FENCE_NAME, " +
|
||||
"DESCRIPTION, " +
|
||||
"LATITUDE, " +
|
||||
"LONGITUDE, " +
|
||||
"RADIUS, " +
|
||||
"GEO_JSON, " +
|
||||
"FENCE_SHAPE, " +
|
||||
"OWNER, " +
|
||||
"TENANT_ID " +
|
||||
"FROM DM_GEOFENCE " +
|
||||
"WHERE TENANT_ID = ? ";
|
||||
|
||||
if (request.getProperty(DeviceManagementConstants.GeoServices.FENCE_NAME) != null) {
|
||||
sql += "AND FENCE_NAME LIKE ?";
|
||||
isNameProvided = true;
|
||||
}
|
||||
sql += "LIMIT ? OFFSET ?";
|
||||
int index = 1;
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setInt(index++, tenantId);
|
||||
if (isNameProvided) {
|
||||
stmt.setString(index++, request.getProperty(DeviceManagementConstants.GeoServices.FENCE_NAME).toString() + "%");
|
||||
}
|
||||
stmt.setInt(index++, request.getRowCount());
|
||||
stmt.setInt(index, request.getStartIndex());
|
||||
try (ResultSet rst = stmt.executeQuery()) {
|
||||
geofenceData = extractGeofenceData(rst);
|
||||
}
|
||||
}
|
||||
return geofenceData;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving Geofence of the tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeofenceData> getGeoFencesOfTenant(String fenceName, int tenantId)
|
||||
throws DeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
List<GeofenceData> geofenceData;
|
||||
String sql = "SELECT " +
|
||||
"ID, " +
|
||||
"FENCE_NAME, " +
|
||||
"DESCRIPTION, " +
|
||||
"LATITUDE, " +
|
||||
"LONGITUDE, " +
|
||||
"RADIUS, " +
|
||||
"GEO_JSON, " +
|
||||
"FENCE_SHAPE, " +
|
||||
"OWNER, " +
|
||||
"TENANT_ID " +
|
||||
"FROM DM_GEOFENCE " +
|
||||
"WHERE FENCE_NAME LIKE ?" +
|
||||
"AND TENANT_ID = ? ";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setString(1, fenceName + "%");
|
||||
stmt.setInt(2, tenantId);
|
||||
try (ResultSet rst = stmt.executeQuery()) {
|
||||
geofenceData = extractGeofenceData(rst);
|
||||
}
|
||||
}
|
||||
return geofenceData;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving Geofence of the tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeofenceData> getGeoFencesOfTenant(int tenantId)
|
||||
throws DeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
List<GeofenceData> geofenceData;
|
||||
String sql = "SELECT " +
|
||||
"ID, " +
|
||||
"FENCE_NAME, " +
|
||||
"DESCRIPTION, " +
|
||||
"LATITUDE, " +
|
||||
"LONGITUDE, " +
|
||||
"RADIUS, " +
|
||||
"GEO_JSON, " +
|
||||
"FENCE_SHAPE, " +
|
||||
"OWNER, " +
|
||||
"TENANT_ID " +
|
||||
"FROM DM_GEOFENCE " +
|
||||
"WHERE TENANT_ID = ? ";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setInt(1, tenantId);
|
||||
try (ResultSet rst = stmt.executeQuery()) {
|
||||
geofenceData = extractGeofenceData(rst);
|
||||
}
|
||||
}
|
||||
return geofenceData;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving Geofence of the tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteGeofenceById(int fenceId) throws DeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "DELETE FROM DM_GEOFENCE WHERE ID = ?";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setInt(1, fenceId);
|
||||
return stmt.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting Geofence with ID " + fenceId;
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateGeofence(GeofenceData geofenceData, int fenceId) throws DeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "UPDATE DM_GEOFENCE SET " +
|
||||
"FENCE_NAME = ?, " +
|
||||
"DESCRIPTION = ?, " +
|
||||
"LATITUDE = ?, " +
|
||||
"LONGITUDE = ?, " +
|
||||
"RADIUS = ?, " +
|
||||
"GEO_JSON = ?, " +
|
||||
"FENCE_SHAPE = ? " +
|
||||
"WHERE ID = ?";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setString(1, geofenceData.getFenceName());
|
||||
stmt.setString(2, geofenceData.getDescription());
|
||||
stmt.setDouble(3, geofenceData.getLatitude());
|
||||
stmt.setDouble(4, geofenceData.getLongitude());
|
||||
stmt.setFloat(5, geofenceData.getRadius());
|
||||
stmt.setString(6, geofenceData.getGeoJson());
|
||||
stmt.setString(7, geofenceData.getFenceShape());
|
||||
stmt.setInt(8, fenceId);
|
||||
return stmt.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating Geofence record with id " + fenceId;
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createGeofenceGroupMapping(GeofenceData geofenceData, List<Integer> groupIds) throws DeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "INSERT INTO DM_GEOFENCE_GROUP_MAPPING(" +
|
||||
"FENCE_ID, " +
|
||||
"GROUP_ID) " +
|
||||
"VALUES (?, ?)";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
for (Integer groupId : groupIds) {
|
||||
stmt.setInt(1, geofenceData.getId());
|
||||
stmt.setInt(2, groupId);
|
||||
stmt.addBatch();
|
||||
}
|
||||
return stmt.executeBatch().length > 0;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while creating geofence group mapping records";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
return DeviceManagementDAOFactory.getConnection();
|
||||
}
|
||||
|
||||
private List<GeofenceData> extractGeofenceData(ResultSet rst) throws SQLException {
|
||||
List <GeofenceData> geofenceDataList = new ArrayList<>();
|
||||
while (rst.next()) {
|
||||
GeofenceData geofenceData = new GeofenceData();
|
||||
geofenceData.setId(rst.getInt("ID"));
|
||||
geofenceData.setFenceName(rst.getString("FENCE_NAME"));
|
||||
geofenceData.setDescription(rst.getString("DESCRIPTION"));
|
||||
geofenceData.setLatitude(rst.getDouble("LATITUDE"));
|
||||
geofenceData.setLongitude(rst.getDouble("LONGITUDE"));
|
||||
geofenceData.setRadius(rst.getFloat("RADIUS"));
|
||||
geofenceData.setGeoJson(rst.getString("GEO_JSON"));
|
||||
geofenceData.setFenceShape(rst.getString("FENCE_SHAPE"));
|
||||
geofenceData.setOwner(rst.getString("OWNER"));
|
||||
geofenceData.setTenantId(rst.getInt("TENANT_ID"));
|
||||
geofenceDataList.add(geofenceData);
|
||||
}
|
||||
return geofenceDataList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getGroupIdsOfGeoFence(int fenceId) throws DeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT " +
|
||||
"GROUP_ID " +
|
||||
"FROM DM_GEOFENCE_GROUP_MAPPING " +
|
||||
"WHERE FENCE_ID = ? ";
|
||||
List<Integer> groupIds = new ArrayList<>();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setInt(1, fenceId);
|
||||
try (ResultSet rst = stmt.executeQuery()) {
|
||||
while (rst.next()) {
|
||||
groupIds.add(rst.getInt(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
return groupIds;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching group IDs of the fence " + fenceId;
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteGeofenceGroupMapping(List<Integer> groupIdsToDelete) throws DeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "DELETE FROM DM_GEOFENCE_GROUP_MAPPING WHERE GROUP_ID = ?";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
for (Integer groupId : groupIdsToDelete) {
|
||||
stmt.setInt(1, groupId);
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting Geofence group mapping records";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createGeofenceEventMapping(int fenceId, List<Integer> eventIds) throws DeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "INSERT INTO DM_GEOFENCE_EVENT_MAPPING(" +
|
||||
"FENCE_ID, "+
|
||||
"EVENT_ID) " +
|
||||
"VALUES (?, ?)";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
for (Integer createdEventId : eventIds) {
|
||||
stmt.setInt(1, fenceId);
|
||||
stmt.setInt(2, createdEventId);
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while creating geofence event group mapping records";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteGeofenceEventMapping(List<Integer> removedEventIdList) throws DeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "DELETE FROM DM_GEOFENCE_EVENT_MAPPING WHERE EVENT_ID = ?";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
for (Integer eventId : removedEventIdList) {
|
||||
stmt.setInt(1, eventId);
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting Geofence event mapping records";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, List<EventConfig>> getEventsOfGeoFences(List<Integer> geofenceIds) throws DeviceManagementDAOException {
|
||||
try {
|
||||
Map<Integer, List<EventConfig>> geoFenceEventMap = new HashMap<>();
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT " +
|
||||
"E.ID AS EVENT_ID, " +
|
||||
"M.FENCE_ID AS FENCE_ID, " +
|
||||
"EVENT_SOURCE, " +
|
||||
"EVENT_LOGIC, " +
|
||||
"ACTIONS " +
|
||||
"FROM DM_DEVICE_EVENT E, DM_GEOFENCE_EVENT_MAPPING M " +
|
||||
"WHERE E.ID = M.EVENT_ID " +
|
||||
"AND M.FENCE_ID IN (%s)";
|
||||
String inClause = String.join(", ", Collections.nCopies(geofenceIds.size(), "?"));
|
||||
sql = String.format(sql, inClause);
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
int index = 1;
|
||||
for (Integer geofenceId : geofenceIds) {
|
||||
stmt.setInt(index++, geofenceId);
|
||||
}
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
int fenceId = resultSet.getInt("FENCE_ID");
|
||||
List<EventConfig> eventConfigList = geoFenceEventMap.get(fenceId);
|
||||
if (eventConfigList == null) {
|
||||
eventConfigList = new ArrayList<>();
|
||||
}
|
||||
EventConfig event = new EventConfig();
|
||||
event.setEventId(resultSet.getInt("EVENT_ID"));
|
||||
event.setEventSource(resultSet.getString("EVENT_SOURCE"));
|
||||
event.setEventLogic(resultSet.getString("EVENT_LOGIC"));
|
||||
event.setActions(resultSet.getString("ACTIONS"));
|
||||
eventConfigList.add(event);
|
||||
geoFenceEventMap.put(fenceId, eventConfigList);
|
||||
}
|
||||
return geoFenceEventMap;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating Geofence record with id ";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EventConfig> getEventsOfGeoFence(int geofenceId) throws DeviceManagementDAOException {
|
||||
try {
|
||||
List<EventConfig> eventList = new ArrayList<>();
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT " +
|
||||
"E.ID AS EVENT_ID, " +
|
||||
"EVENT_SOURCE, " +
|
||||
"EVENT_LOGIC, " +
|
||||
"ACTIONS " +
|
||||
"FROM DM_DEVICE_EVENT E, DM_GEOFENCE_EVENT_MAPPING G " +
|
||||
"WHERE E.ID = G.EVENT_ID " +
|
||||
"AND G.FENCE_ID = ?";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setInt(1, geofenceId);
|
||||
return getEventConfigs(stmt);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating Geofence record with id ";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<GeoFenceGroupMap> getGroupIdsOfGeoFences(List<Integer> fenceIds) throws DeviceManagementDAOException {
|
||||
try {
|
||||
Set<GeoFenceGroupMap> geoFenceGroupSet = new HashSet<>();
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT " +
|
||||
"FENCE_ID, " +
|
||||
"M.GROUP_ID, " +
|
||||
"G.GROUP_NAME " +
|
||||
"FROM DM_GEOFENCE_GROUP_MAPPING M, DM_GROUP G " +
|
||||
"WHERE M.GROUP_ID = G.ID " +
|
||||
"AND FENCE_ID IN (%s)";
|
||||
String inClause = String.join(", ", Collections.nCopies(fenceIds.size(), "?"));
|
||||
sql = String.format(sql, inClause);
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
int index = 1;
|
||||
for (Integer fenceId : fenceIds) {
|
||||
stmt.setInt(index++, fenceId);
|
||||
}
|
||||
ResultSet rst = stmt.executeQuery();
|
||||
while (rst.next()) {
|
||||
GeoFenceGroupMap geoFenceGroupMap = new GeoFenceGroupMap();
|
||||
geoFenceGroupMap.setFenceId(rst.getInt("FENCE_ID"));
|
||||
geoFenceGroupMap.setGroupId(rst.getInt("GROUP_ID"));
|
||||
geoFenceGroupMap.setGroupName(rst.getString("GROUP_NAME"));
|
||||
geoFenceGroupSet.add(geoFenceGroupMap);
|
||||
}
|
||||
}
|
||||
return geoFenceGroupSet;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching group IDs of the fences";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the geofence event extracted from the DB
|
||||
* @param stmt prepared statement to retrieve data from the DB
|
||||
* @return Retrieved Event list from the DB
|
||||
* @throws SQLException for the errors occur while accessing the DB
|
||||
*/
|
||||
private List<EventConfig> getEventConfigs(PreparedStatement stmt) throws SQLException {
|
||||
List<EventConfig> eventList = new ArrayList<>();
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
EventConfig event;
|
||||
while (resultSet.next()) {
|
||||
event = new EventConfig();
|
||||
event.setEventId(resultSet.getInt("EVENT_ID"));
|
||||
event.setEventSource(resultSet.getString("EVENT_SOURCE"));
|
||||
event.setEventLogic(resultSet.getString("EVENT_LOGIC"));
|
||||
event.setActions(resultSet.getString("ACTIONS"));
|
||||
eventList.add(event);
|
||||
}
|
||||
return eventList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeofenceData> getGeoFences(int groupId, int tenantId) throws DeviceManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "SELECT " +
|
||||
"G.ID AS FENCE_ID, " +
|
||||
"FENCE_NAME, " +
|
||||
"DESCRIPTION, " +
|
||||
"LATITUDE," +
|
||||
"LONGITUDE, " +
|
||||
"RADIUS, " +
|
||||
"GEO_JSON, " +
|
||||
"FENCE_SHAPE " +
|
||||
"FROM DM_GEOFENCE G, DM_GEOFENCE_GROUP_MAPPING M " +
|
||||
"WHERE M.GROUP_ID = ? AND TENANT_ID = ? " +
|
||||
"GROUP BY G.ID";
|
||||
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
stmt.setInt(1, groupId);
|
||||
stmt.setInt(2, tenantId);
|
||||
ResultSet rst = stmt.executeQuery();
|
||||
List <GeofenceData> geofenceDataList = new ArrayList<>();
|
||||
while (rst.next()) {
|
||||
GeofenceData geofenceData = new GeofenceData();
|
||||
geofenceData.setId(rst.getInt("FENCE_ID"));
|
||||
geofenceData.setFenceName(rst.getString("FENCE_NAME"));
|
||||
geofenceData.setDescription(rst.getString("DESCRIPTION"));
|
||||
geofenceData.setLatitude(rst.getDouble("LATITUDE"));
|
||||
geofenceData.setLongitude(rst.getDouble("LONGITUDE"));
|
||||
geofenceData.setRadius(rst.getFloat("RADIUS"));
|
||||
geofenceData.setGeoJson(rst.getString("GEO_JSON"));
|
||||
geofenceData.setFenceShape(rst.getString("FENCE_SHAPE"));
|
||||
geofenceDataList.add(geofenceData);
|
||||
}
|
||||
return geofenceDataList;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving Geo fences of group " + groupId
|
||||
+ " and tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeofenceData getGeofence(int fenceId, boolean requireGroupData) throws DeviceManagementDAOException {
|
||||
if (!requireGroupData) {
|
||||
return getGeofence(fenceId);
|
||||
}
|
||||
|
||||
try {
|
||||
Connection con = this.getConnection();
|
||||
String sql = "SELECT " +
|
||||
"G.ID AS FENCE_ID, " +
|
||||
"FENCE_NAME, " +
|
||||
"G.DESCRIPTION, " +
|
||||
"LATITUDE, " +
|
||||
"LONGITUDE, " +
|
||||
"RADIUS, " +
|
||||
"GEO_JSON, " +
|
||||
"FENCE_SHAPE, " +
|
||||
"M.GROUP_ID AS GROUP_ID, " +
|
||||
"GR.GROUP_NAME " +
|
||||
"FROM DM_GEOFENCE G, DM_GEOFENCE_GROUP_MAPPING M, DM_GROUP GR " +
|
||||
"WHERE G.ID = M.FENCE_ID " +
|
||||
"AND M.GROUP_ID = GR.ID " +
|
||||
"AND G.ID = ?";
|
||||
try (PreparedStatement stmt = con.prepareStatement(sql)){
|
||||
stmt.setInt(1, fenceId);
|
||||
ResultSet rst = stmt.executeQuery();
|
||||
Map<Integer, String> groupMap = new HashMap<>();
|
||||
GeofenceData geofenceData = null;
|
||||
while (rst.next()) {
|
||||
groupMap.put(rst.getInt("GROUP_ID"), rst.getString("GROUP_NAME"));
|
||||
if (rst.isLast()) {
|
||||
geofenceData = new GeofenceData();
|
||||
geofenceData.setId(rst.getInt("FENCE_ID"));
|
||||
geofenceData.setFenceName(rst.getString("FENCE_NAME"));
|
||||
geofenceData.setDescription(rst.getString("DESCRIPTION"));
|
||||
geofenceData.setLatitude(rst.getDouble("LATITUDE"));
|
||||
geofenceData.setLongitude(rst.getDouble("LONGITUDE"));
|
||||
geofenceData.setRadius(rst.getFloat("RADIUS"));
|
||||
geofenceData.setGeoJson(rst.getString("GEO_JSON"));
|
||||
geofenceData.setFenceShape(rst.getString("FENCE_SHAPE"));
|
||||
geofenceData.setGroupData(groupMap);
|
||||
}
|
||||
}
|
||||
return geofenceData;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving Geo fence data " + fenceId;
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -30,8 +30,6 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.AbstractDeviceDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.core.geo.GeoCluster;
|
||||
import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate;
|
||||
import org.wso2.carbon.device.mgt.core.report.mgt.Constants;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.dao.impl.event;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfig;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.EventConfigDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.AbstractEventConfigDAO;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class GenericEventConfigDAOImpl extends AbstractEventConfigDAO {
|
||||
private static final Log log = LogFactory.getLog(GenericEventConfigDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public List<Integer> storeEventRecords(List<EventConfig> eventConfigList, int tenantId) throws EventManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String sql = "INSERT INTO DM_DEVICE_EVENT(" +
|
||||
"EVENT_SOURCE, " +
|
||||
"EVENT_LOGIC, " +
|
||||
"ACTIONS, "+
|
||||
"CREATED_TIMESTAMP, " +
|
||||
"TENANT_ID) " +
|
||||
"VALUES (?, ?, ?, ?, ?)";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
for (EventConfig eventConfig : eventConfigList) {
|
||||
stmt.setString(1, eventConfig.getEventSource());
|
||||
stmt.setString(2, eventConfig.getEventLogic());
|
||||
stmt.setString(3, eventConfig.getActions());
|
||||
stmt.setTimestamp(4, new Timestamp(new Date().getTime()));
|
||||
stmt.setInt(5, tenantId);
|
||||
stmt.addBatch();
|
||||
}
|
||||
int[] createdRowCount = stmt.executeBatch();
|
||||
List<Integer> generatedIds = new ArrayList<>();
|
||||
ResultSet generatedKeys = stmt.getGeneratedKeys();
|
||||
for (int i = 0; i < createdRowCount.length; i++) {
|
||||
if (generatedKeys.next()) {
|
||||
generatedIds.add(generatedKeys.getInt(1));
|
||||
}
|
||||
}
|
||||
return generatedIds;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while creating event configurations for the tenant id " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new EventManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
return DeviceManagementDAOFactory.getConnection();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.dao.impl.event;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfig;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.AbstractEventConfigDAO;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class H2EventConfigDAOImpl extends AbstractEventConfigDAO {
|
||||
private static final Log log = LogFactory.getLog(H2EventConfigDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public List<Integer> storeEventRecords(List<EventConfig> eventConfigList, int tenantId) throws EventManagementDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
List<Integer> generatedIds = new ArrayList<>();
|
||||
String sql = "INSERT INTO DM_DEVICE_EVENT(" +
|
||||
"EVENT_SOURCE, " +
|
||||
"EVENT_LOGIC, " +
|
||||
"ACTIONS, "+
|
||||
"CREATED_TIMESTAMP, " +
|
||||
"TENANT_ID) " +
|
||||
"VALUES (?, ?, ?, ?, ?)";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
for (EventConfig eventConfig : eventConfigList) {
|
||||
stmt.setString(1, eventConfig.getEventSource());
|
||||
stmt.setString(2, eventConfig.getEventLogic());
|
||||
stmt.setString(3, eventConfig.getActions());
|
||||
stmt.setTimestamp(4, new Timestamp(new Date().getTime()));
|
||||
stmt.setInt(5, tenantId);
|
||||
int affectedRawCount = stmt.executeUpdate();
|
||||
if (affectedRawCount > 0) {
|
||||
ResultSet generatedKeys = stmt.getGeneratedKeys();
|
||||
if (generatedKeys.next()) {
|
||||
generatedIds.add(generatedKeys.getInt(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
return generatedIds;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while creating event configurations for the tenant id " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new EventManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
private Connection getConnection() throws SQLException {
|
||||
return DeviceManagementDAOFactory.getConnection();
|
||||
}
|
||||
}
|
||||
@ -129,26 +129,4 @@ public interface DeviceDetailsDAO {
|
||||
void updateDeviceInformation(int deviceId, int enrollmentId, DeviceInfo newDeviceInfo) throws DeviceDetailsMgtDAOException;
|
||||
|
||||
void updateDeviceLocation(DeviceLocation deviceLocation, int enrollmentId) throws DeviceDetailsMgtDAOException;
|
||||
|
||||
// /**
|
||||
// * This method will add device application to database.
|
||||
// * @param deviceApplication - Device application
|
||||
// * @throws DeviceDetailsMgtDAOException
|
||||
// */
|
||||
// void addDeviceApplications(DeviceApplication deviceApplication) throws DeviceDetailsMgtDAOException;
|
||||
//
|
||||
// /**
|
||||
// * This method will return the device application list once device id is provided.
|
||||
// * @param deviceId
|
||||
// * @return
|
||||
// * @throws DeviceDetailsMgtDAOException
|
||||
// */
|
||||
// DeviceApplication getDeviceApplications(int deviceId) throws DeviceDetailsMgtDAOException;
|
||||
//
|
||||
// /**
|
||||
// * This method will delete the application list from the database.
|
||||
// * @param deviceId - Integer
|
||||
// * @throws DeviceDetailsMgtDAOException
|
||||
// */
|
||||
// void deleteDeviceApplications(int deviceId) throws DeviceDetailsMgtDAOException;
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ import java.util.Map;
|
||||
|
||||
public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceDetailsDAOImpl.class);
|
||||
private static final Log log = LogFactory.getLog(DeviceDetailsDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public void addDeviceInformation(int deviceId, int enrolmentId, DeviceInfo deviceInfo)
|
||||
@ -168,8 +168,6 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
// deviceInfo.setIMEI(rs.getString("IMEI"));
|
||||
// deviceInfo.setIMSI(rs.getString("IMSI"));
|
||||
deviceInfo = new DeviceInfo();
|
||||
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
|
||||
deviceInfo.setVendor(rs.getString("VENDOR"));
|
||||
@ -180,9 +178,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
|
||||
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
|
||||
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
|
||||
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
|
||||
// deviceInfo.setOperator(rs.getString("OPERATOR"));
|
||||
deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE"));
|
||||
// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH"));
|
||||
deviceInfo.setSsid(rs.getString("SSID"));
|
||||
deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE"));
|
||||
deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY"));
|
||||
@ -190,7 +186,6 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
|
||||
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
|
||||
deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP")));
|
||||
}
|
||||
|
||||
return deviceInfo;
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceDetailsMgtDAOException("Error occurred while fetching the details of the registered devices.", e);
|
||||
@ -447,7 +442,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
|
||||
stmt.setDouble(6, location.getLongitude());
|
||||
stmt.setFloat(7, location.getSpeed());
|
||||
stmt.setFloat(8, location.getBearing());
|
||||
stmt.setLong(9, System.currentTimeMillis());
|
||||
stmt.setLong(9, location.getUpdatedTime().getTime());
|
||||
stmt.setString(10, GeoHashGenerator.encodeGeohash(location));
|
||||
stmt.setString(11, device.getEnrolmentInfo().getOwner());
|
||||
stmt.setDouble(12, location.getAltitude());
|
||||
@ -508,21 +503,5 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
|
||||
private Connection getConnection() throws SQLException {
|
||||
return DeviceManagementDAOFactory.getConnection();
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public void addDeviceApplications(DeviceApplication deviceApplication) throws DeviceDetailsMgtDAOException {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public DeviceApplication getDeviceApplications(int deviceId) throws DeviceDetailsMgtDAOException {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void deleteDeviceApplications(int deviceId) throws DeviceDetailsMgtDAOException {
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.dto.event.config;
|
||||
|
||||
public class GeoFenceGroupMap {
|
||||
private int fenceId;
|
||||
private int groupId;
|
||||
private String groupName;
|
||||
|
||||
public int getFenceId() {
|
||||
return fenceId;
|
||||
}
|
||||
|
||||
public void setFenceId(int fenceId) {
|
||||
this.fenceId = fenceId;
|
||||
}
|
||||
|
||||
public int getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(int groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
public void setGroupName(String groupName) {
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof GeoFenceGroupMap) {
|
||||
GeoFenceGroupMap map = (GeoFenceGroupMap)obj;
|
||||
return map.getFenceId() == this.getFenceId()
|
||||
&& map.getGroupId() == this.getGroupId()
|
||||
&& map.getGroupName().equals(this.getGroupName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.event.config;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfig;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationProviderService;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.EventConfigDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class EventConfigurationProviderServiceImpl implements EventConfigurationProviderService {
|
||||
private static final Log log = LogFactory.getLog(EventConfigurationProviderServiceImpl.class);
|
||||
private final EventConfigDAO eventConfigDAO;
|
||||
|
||||
public EventConfigurationProviderServiceImpl() {
|
||||
eventConfigDAO = DeviceManagementDAOFactory.getEventConfigDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> createEventsOfDeviceGroup(List<EventConfig> eventConfigList, List<Integer> groupIds)
|
||||
throws EventConfigurationException {
|
||||
int tenantId;
|
||||
try {
|
||||
tenantId = DeviceManagementDAOUtil.getTenantId();
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving tenant Id";
|
||||
log.error(msg, e);
|
||||
throw new EventConfigurationException(msg, e);
|
||||
}
|
||||
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Creating event records of tenant " + tenantId);
|
||||
}
|
||||
List<Integer> generatedEventIds = eventConfigDAO.storeEventRecords(eventConfigList, tenantId);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Created events with event ids : " + generatedEventIds.toString());
|
||||
log.debug("Creating event group mapping for created events with group ids : " + groupIds.toString());
|
||||
}
|
||||
eventConfigDAO.addEventGroupMappingRecords(generatedEventIds, groupIds);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Event configuration added successfully for the tenant " + tenantId);
|
||||
}
|
||||
return generatedEventIds;
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Failed to start/open transaction to store device event configurations";
|
||||
throw new EventConfigurationException(msg, e);
|
||||
} catch (EventManagementDAOException e) {
|
||||
String msg = "Error occurred while saving event records";
|
||||
log.error(msg, e);
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
throw new EventConfigurationException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> updateEventsOfDeviceGroup(List<EventConfig> newEventList, List<Integer> removedEventIdList,
|
||||
List<Integer> groupIds) throws EventConfigurationException {
|
||||
//todo when concerning about other event types, all of this steps might not necessary.
|
||||
// so divide them into separate service methods
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Updating event configurations of tenant");
|
||||
}
|
||||
List<EventConfig> eventsToAdd;
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
eventsToAdd = new ArrayList<>();
|
||||
List<EventConfig> eventsToUpdate = new ArrayList<>();
|
||||
List<Integer> updateEventIdList = new ArrayList<>();
|
||||
for (EventConfig newEvent : newEventList) {
|
||||
if (newEvent.getEventId() == -1) {
|
||||
eventsToAdd.add(newEvent);
|
||||
continue;
|
||||
}
|
||||
eventsToUpdate.add(newEvent);
|
||||
updateEventIdList.add(newEvent.getEventId());
|
||||
}
|
||||
List<Integer> savedGroups = eventConfigDAO.getGroupsOfEvents(updateEventIdList);
|
||||
List<Integer> groupIdsToAdd = new ArrayList<>();
|
||||
List<Integer> groupIdsToDelete = new ArrayList<>();
|
||||
for (Integer savedGroup : savedGroups) {
|
||||
if (!groupIds.contains(savedGroup)) {
|
||||
groupIdsToDelete.add(savedGroup);
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer newGroupId : groupIds) {
|
||||
if (!savedGroups.contains(newGroupId)) {
|
||||
groupIdsToAdd.add(newGroupId);
|
||||
}
|
||||
}
|
||||
|
||||
if (!eventsToUpdate.isEmpty()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Updating event records ");
|
||||
}
|
||||
eventConfigDAO.updateEventRecords(eventsToUpdate);
|
||||
}
|
||||
|
||||
if (!groupIdsToDelete.isEmpty()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Deleting event group mapping records of groups");
|
||||
}
|
||||
eventConfigDAO.deleteEventGroupMappingRecordsByGroupIds(groupIdsToDelete);
|
||||
}
|
||||
|
||||
if (!groupIdsToAdd.isEmpty()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Creating event group mapping records for updated events");
|
||||
}
|
||||
eventConfigDAO.addEventGroupMappingRecords(updateEventIdList, groupIdsToAdd);
|
||||
}
|
||||
|
||||
if (!removedEventIdList.isEmpty()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Deleting event group mapping records of removing events");
|
||||
}
|
||||
eventConfigDAO.deleteEventGroupMappingRecordsByEventIds(removedEventIdList);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Deleting removed event records");
|
||||
}
|
||||
eventConfigDAO.deleteEventRecords(removedEventIdList);
|
||||
}
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Failed to start/open transaction to store device event configurations";
|
||||
log.error(msg, e);
|
||||
throw new EventConfigurationException(msg, e);
|
||||
} catch (EventManagementDAOException e) {
|
||||
String msg = "Error occurred while saving event records";
|
||||
log.error(msg, e);
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
throw new EventConfigurationException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Adding new events while updating event");
|
||||
}
|
||||
return createEventsOfDeviceGroup(eventsToAdd, groupIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EventConfig> getEvents(List<Integer> createdEventIds) throws EventConfigurationException {
|
||||
try {
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
return eventConfigDAO.getEventsById(createdEventIds);
|
||||
} catch (EventManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving event by IDs : " + Arrays.toString(createdEventIds.toArray());
|
||||
log.error(msg, e);
|
||||
throw new EventConfigurationException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Failed to open connection while retrieving event by IDs";
|
||||
log.error(msg, e);
|
||||
throw new EventConfigurationException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getEventsSourcesOfGroup(int groupId, int tenantId) throws EventConfigurationException {
|
||||
try {
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
return eventConfigDAO.getEventSourcesOfGroups(groupId, tenantId);
|
||||
} catch (EventManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving events of group " + groupId + " and tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new EventConfigurationException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Failed to open connection while retrieving event by IDs";
|
||||
log.error(msg, e);
|
||||
throw new EventConfigurationException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteEvents(List<EventConfig> events) throws EventConfigurationException {
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
Set<Integer> eventIdSet = new HashSet<>();
|
||||
for (EventConfig eventConfig : events) {
|
||||
eventIdSet.add(eventConfig.getEventId());
|
||||
}
|
||||
if (!eventIdSet.isEmpty()) {
|
||||
eventConfigDAO.deleteEventGroupMappingRecordsByEventIds(Lists.newArrayList(eventIdSet));
|
||||
eventConfigDAO.deleteEventRecords(Lists.newArrayList(eventIdSet));
|
||||
}
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Failed to start/open transaction to delete device event configurations";
|
||||
log.error(msg, e);
|
||||
throw new EventConfigurationException(msg, e);
|
||||
} catch (EventManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while deleting event records";
|
||||
log.error(msg, e);
|
||||
throw new EventConfigurationException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.event.config;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfig;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventMetaData;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventOperation;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventRevokeOperation;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoFenceEventMeta;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationBasedServiceException;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.geo.task.EventCreateCallback;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Event create/revoke operation creation task.
|
||||
* Use at the time of single event create, update, delete
|
||||
*/
|
||||
public class EventOperationExecutor implements Runnable {
|
||||
private static final Log log = LogFactory.getLog(EventOperationExecutor.class);
|
||||
|
||||
private final List<Integer> groupIds;
|
||||
private final String eventSource;
|
||||
private final EventMetaData eventMetaData;
|
||||
private final int tenantId;
|
||||
private final String operationCode;
|
||||
private final GroupManagementProviderService groupManagementService;
|
||||
private EventCreateCallback callback;
|
||||
|
||||
public EventOperationExecutor(EventMetaData eventMetaData, List<Integer> groupIds, int tenantId,
|
||||
String eventSource, String operationCode) {
|
||||
this.eventMetaData = eventMetaData;
|
||||
this.groupIds = groupIds;
|
||||
this.tenantId = tenantId;
|
||||
this.eventSource = eventSource;
|
||||
this.operationCode = operationCode;
|
||||
this.groupManagementService = DeviceManagementDataHolder.getInstance().getGroupManagementProviderService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
log.info("Starting event operation creation task");
|
||||
if (operationCode == null) {
|
||||
log.error("Failed to start event operation task. Operation code is null");
|
||||
return;
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.info("Starting " + operationCode + " operation creation task for event " + eventSource
|
||||
+ " tenant " + tenantId + " group Ids "+ Arrays.toString(groupIds.toArray()));
|
||||
}
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
|
||||
ProfileOperation operation = new ProfileOperation();
|
||||
operation.setType(Operation.Type.PROFILE);
|
||||
try {
|
||||
if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_CONFIG)) {
|
||||
operation.setCode(OperationMgtConstants.OperationCodes.EVENT_CONFIG);
|
||||
buildEventConfigOperation(operation);
|
||||
} else if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_REVOKE)){
|
||||
operation.setCode(OperationMgtConstants.OperationCodes.EVENT_REVOKE);
|
||||
buildEventRevokeOperation(operation);
|
||||
}
|
||||
} catch (EventConfigurationException e) {
|
||||
log.error("Event creation failed with message : " + e.getMessage(), e);
|
||||
return;
|
||||
}
|
||||
Set<Device> devices = new HashSet<>();
|
||||
for (Integer groupId : groupIds) {
|
||||
DeviceGroup group;
|
||||
try {
|
||||
group = groupManagementService.getGroup(groupId, false);
|
||||
} catch (GroupManagementException e) {
|
||||
log.error("Failed to retrieve group with group ID " + groupId, e);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
if (group != null) {
|
||||
List<Device> allDevicesOfGroup = groupManagementService.getAllDevicesOfGroup(group.getName(), false);
|
||||
if (allDevicesOfGroup == null || allDevicesOfGroup.isEmpty()) {
|
||||
log.warn("No devices found in group " + group.getName());
|
||||
} else {
|
||||
devices.addAll(allDevicesOfGroup);
|
||||
}
|
||||
}
|
||||
} catch (GroupManagementException e) {
|
||||
log.error("Failed to retrieve devices of group with ID " + groupId + " and name " + group.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
if (devices.isEmpty()) {
|
||||
log.warn("No devices found for the specified groups " + Arrays.toString(groupIds.toArray()));
|
||||
return;
|
||||
}
|
||||
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
||||
for (Device device : devices) {
|
||||
if (device.getType().equalsIgnoreCase("android")) {
|
||||
//TODO introduce a proper mechanism for event handling for each device types
|
||||
deviceIdentifiers.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
||||
}
|
||||
}
|
||||
DeviceManagementProviderService deviceManagementProvider = DeviceManagementDataHolder
|
||||
.getInstance().getDeviceManagementProvider();
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Creating event operations stared for devices" + Arrays.toString(deviceIdentifiers.toArray()));
|
||||
}
|
||||
deviceManagementProvider.addOperation("android", operation, deviceIdentifiers);
|
||||
//TODO introduce a proper mechanism
|
||||
} catch (OperationManagementException e) {
|
||||
log.error("Creating event operation failed with error ", e);
|
||||
return;
|
||||
} catch (InvalidDeviceException e) {
|
||||
log.error("Creating event operation failed.\n" +
|
||||
"Could not found device/devices for the defined device identifiers.", e);
|
||||
return;
|
||||
}
|
||||
log.info("Event operation creation task completed");
|
||||
if (callback != null) {
|
||||
callback.onCompleteEventOperation(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build operation to create EVENT_REVOKE operation.
|
||||
* @param operation Operation object to build
|
||||
*/
|
||||
private void buildEventRevokeOperation(ProfileOperation operation) {
|
||||
if (eventSource.equalsIgnoreCase(DeviceManagementConstants.EventServices.GEOFENCE)) {
|
||||
createGeoFenceRevokeOperation(operation);
|
||||
} //extend with another cases to handle other types of events
|
||||
}
|
||||
|
||||
/**
|
||||
* Build operation to create EVENT_CONFIG operation.
|
||||
* @param operation Operation object to build
|
||||
* @throws EventConfigurationException Failed while build the operation object
|
||||
*/
|
||||
private void buildEventConfigOperation(ProfileOperation operation) throws EventConfigurationException {
|
||||
if (eventSource.equalsIgnoreCase(DeviceManagementConstants.EventServices.GEOFENCE)) {
|
||||
createGeoFenceConfigOperation(operation);
|
||||
} //extend with another cases to handle other types of events
|
||||
}
|
||||
|
||||
/**
|
||||
* Create EVENT_CONFIG operation object and attach payload to configure geo fence events
|
||||
* @param operation operation object to set the payload
|
||||
* @throws EventConfigurationException Failed while retrieving event list of geo fence
|
||||
*/
|
||||
private void createGeoFenceConfigOperation(ProfileOperation operation) throws EventConfigurationException {
|
||||
GeoFenceEventMeta geoFenceMeta = (GeoFenceEventMeta) eventMetaData;
|
||||
try {
|
||||
GeoLocationProviderService geoLocationProviderService = DeviceManagementDataHolder
|
||||
.getInstance().getGeoLocationProviderService();
|
||||
List<EventConfig> eventConfigList = geoLocationProviderService.getEventsOfGeoFence(geoFenceMeta.getId());
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Retrieved event records of Geo Fence " + geoFenceMeta.getId() +
|
||||
". events " + Arrays.toString(eventConfigList.toArray()));
|
||||
}
|
||||
List<EventOperation> eventOperations = new ArrayList<>();
|
||||
EventOperation eventOperation = new EventOperation();
|
||||
eventOperation.setEventDefinition(eventMetaData);
|
||||
eventOperation.setEventSource(eventSource);
|
||||
eventOperation.setEventTriggers(eventConfigList);
|
||||
eventOperations.add(eventOperation);
|
||||
operation.setPayLoad(new Gson().toJson(eventOperations));
|
||||
}catch (GeoLocationBasedServiceException e) {
|
||||
throw new EventConfigurationException("Failed to retrieve event data of Geo fence " + geoFenceMeta.getId()
|
||||
+ " : " + geoFenceMeta.getFenceName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create EVENT_REVOKE operation object and attach payload to configure geo fence events
|
||||
* @param operation operation object to set the payload
|
||||
*/
|
||||
private void createGeoFenceRevokeOperation(ProfileOperation operation) {
|
||||
GeoFenceEventMeta geoFenceMeta = (GeoFenceEventMeta) eventMetaData;
|
||||
EventRevokeOperation eventRevokeOperation = new EventRevokeOperation();
|
||||
eventRevokeOperation.setEventSource(eventSource);
|
||||
eventRevokeOperation.setId(geoFenceMeta.getId());
|
||||
operation.setPayLoad(new Gson().toJson(eventRevokeOperation));
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to set the task callback to call after the task completed successfully
|
||||
* @param callback Event callback object implemented inside the task starting class
|
||||
*/
|
||||
public void setCallback(EventCreateCallback callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,224 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.event.config;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationProviderService;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventOperation;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventRevokeOperation;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoFenceEventMeta;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationBasedServiceException;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.geo.task.EventCreateCallback;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Event create/revoke operation creation task.
|
||||
* Use at the time of devices assign into group, remove from group.
|
||||
*/
|
||||
public class GroupEventOperationExecutor implements Runnable {
|
||||
private static final Log log = LogFactory.getLog(GroupEventOperationExecutor.class);
|
||||
|
||||
private final int groupId;
|
||||
private final List<DeviceIdentifier> deviceIdentifiers;
|
||||
private final int tenantId;
|
||||
private final String operationCode;
|
||||
private final GeoLocationProviderService geoLocationProviderService;
|
||||
private final EventConfigurationProviderService eventConfigurationService;
|
||||
private EventCreateCallback callback;
|
||||
|
||||
public GroupEventOperationExecutor(int groupId, List<DeviceIdentifier> deviceIdentifiers, int tenantId, String operationCode) {
|
||||
this.groupId = groupId;
|
||||
this.deviceIdentifiers = deviceIdentifiers;
|
||||
this.tenantId = tenantId;
|
||||
this.operationCode = operationCode;
|
||||
this.geoLocationProviderService = DeviceManagementDataHolder.getInstance().getGeoLocationProviderService();
|
||||
this.eventConfigurationService = DeviceManagementDataHolder.getInstance().getEventConfigurationService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
log.info("Starting event operation creation task for devices in group " + groupId + " tenant " + tenantId);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Event creation operation started for devices with IDs " + Arrays.toString(deviceIdentifiers.toArray()));
|
||||
log.debug("Starting tenant flow for tenant with ID : " + tenantId);
|
||||
}
|
||||
ProfileOperation operation = new ProfileOperation();
|
||||
if (operationCode != null) {
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
|
||||
try {
|
||||
operation.setCode(operationCode);
|
||||
operation.setType(Operation.Type.PROFILE);
|
||||
if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_CONFIG)) {
|
||||
buildEventConfigOperationObject(operation);
|
||||
} else if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_REVOKE)) {
|
||||
buildEventRevokeOperation(operation);
|
||||
}
|
||||
|
||||
} catch (EventConfigurationException e) {
|
||||
log.error("Failed to retrieve event sources of group " + groupId + ". Event creation operation failed.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
DeviceManagementProviderService deviceManagementProvider = DeviceManagementDataHolder
|
||||
.getInstance().getDeviceManagementProvider();
|
||||
try {
|
||||
if (!deviceIdentifiers.isEmpty()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Creating event operations stared");
|
||||
}
|
||||
deviceManagementProvider.addOperation("android", operation, deviceIdentifiers); //TODO introduce a proper mechanism
|
||||
} else {
|
||||
log.info("Device identifiers are empty, Hence ignoring adding event operation");
|
||||
}
|
||||
} catch (OperationManagementException e) {
|
||||
log.error("Creating event operation failed with error ", e);
|
||||
} catch (InvalidDeviceException e) {
|
||||
log.error("Creating event operation failed.\n" +
|
||||
"Could not found device/devices for the defined device identifiers.", e);
|
||||
}
|
||||
log.info("Event operation creation succeeded");
|
||||
if (callback != null) {
|
||||
callback.onCompleteEventOperation(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build EVENT_REVOKE operation attaching event payload
|
||||
* @param operation operation object to build
|
||||
* @throws EventConfigurationException if not events found for the specific group
|
||||
*/
|
||||
private void buildEventRevokeOperation(ProfileOperation operation) throws EventConfigurationException {
|
||||
List<String> eventSources = eventConfigurationService.getEventsSourcesOfGroup(groupId, tenantId);
|
||||
if (eventSources == null || eventSources.isEmpty()) {
|
||||
String msg = "No events applied for queried group with ID " + groupId;
|
||||
log.info(msg);
|
||||
throw new EventConfigurationException(msg);
|
||||
}
|
||||
for (String eventSource : eventSources) {
|
||||
if (eventSource.equalsIgnoreCase(DeviceManagementConstants.EventServices.GEOFENCE)) {
|
||||
setGeoFenceRevokeOperationContent(operation);
|
||||
} //extend with another cases to handle other types of events
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build EVENT_CONFIG operation attaching event payload
|
||||
* @param operation operation object to build
|
||||
* @throws EventConfigurationException if not events found for the specific group
|
||||
*/
|
||||
private void buildEventConfigOperationObject(ProfileOperation operation) throws EventConfigurationException {
|
||||
List<String> eventSources = eventConfigurationService.getEventsSourcesOfGroup(groupId, tenantId);
|
||||
if (eventSources == null || eventSources.isEmpty()) {
|
||||
String msg = "No events applied for queried group with ID " + groupId;
|
||||
log.info(msg);
|
||||
throw new EventConfigurationException(msg);
|
||||
}
|
||||
for (String eventSource : eventSources) {
|
||||
if (eventSource.equalsIgnoreCase(DeviceManagementConstants.EventServices.GEOFENCE)) {
|
||||
setGeoFenceConfigOperationContent(operation);
|
||||
} //extend with another cases to handle other types of events
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set operation payload GeoFence for EVENT_CONFIG operation
|
||||
* @param operation operation object to attach payload
|
||||
* @throws EventConfigurationException failed while getting events of group
|
||||
*/
|
||||
private void setGeoFenceConfigOperationContent(ProfileOperation operation) throws EventConfigurationException {
|
||||
log.info("Geo fence events found attached with group " + groupId + ", Started retrieving geo fences");
|
||||
List<GeofenceData> geoFencesOfGroup = getGeoFencesOfGroup();
|
||||
List<EventOperation> eventOperationList = new ArrayList<>();
|
||||
for (GeofenceData geofenceData : geoFencesOfGroup) {
|
||||
GeoFenceEventMeta geoFenceEventMeta = new GeoFenceEventMeta(geofenceData);
|
||||
EventOperation eventOperation = new EventOperation();
|
||||
eventOperation.setEventDefinition(geoFenceEventMeta);
|
||||
eventOperation.setEventSource(DeviceManagementConstants.EventServices.GEOFENCE);
|
||||
eventOperation.setEventTriggers(geofenceData.getEventConfig());
|
||||
eventOperationList.add(eventOperation);
|
||||
}
|
||||
operation.setPayLoad(new Gson().toJson(eventOperationList));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get geo fence list of the group
|
||||
* @return {@link GeofenceData} geofence data list of the geo fence
|
||||
* @throws EventConfigurationException error occurred while querying geo fences of group
|
||||
*/
|
||||
private List<GeofenceData> getGeoFencesOfGroup() throws EventConfigurationException {
|
||||
List<GeofenceData> geoFencesOfGroup;
|
||||
try {
|
||||
geoFencesOfGroup = geoLocationProviderService.getGeoFencesOfGroup(groupId, tenantId, true);
|
||||
} catch (GeoLocationBasedServiceException e) {
|
||||
String msg = "Failed to get geo fences of the group";
|
||||
log.error(msg, e);
|
||||
throw new EventConfigurationException(msg, e);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Retrieved " + geoFencesOfGroup.size() + " geo fences defined for the group " + groupId);
|
||||
}
|
||||
return geoFencesOfGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set operation payload GeoFence for EVENT_REVOKE operation
|
||||
* @param operation operation object to attach payload
|
||||
* @throws EventConfigurationException failed while getting events of group
|
||||
*/
|
||||
private void setGeoFenceRevokeOperationContent(ProfileOperation operation) throws EventConfigurationException {
|
||||
List<GeofenceData> geoFencesOfGroup = getGeoFencesOfGroup();
|
||||
List<EventRevokeOperation> revokeOperationList = new ArrayList<>();
|
||||
for (GeofenceData geofenceData : geoFencesOfGroup) {
|
||||
EventRevokeOperation eventRevokeOperation = new EventRevokeOperation();
|
||||
eventRevokeOperation.setEventSource(DeviceManagementConstants.EventServices.GEOFENCE);
|
||||
eventRevokeOperation.setId(geofenceData.getId());
|
||||
revokeOperationList.add(eventRevokeOperation);
|
||||
}
|
||||
operation.setPayLoad(new Gson().toJson(revokeOperationList));
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to set the task callback to call after the task completed successfully
|
||||
* @param callback Event callback object implemented inside the task starting class
|
||||
*/
|
||||
public void setCallback(EventCreateCallback callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
}
|
||||
@ -36,13 +36,28 @@ import org.wso2.carbon.base.ServerConfiguration;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.core.util.Utils;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoServices;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfig;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationProviderService;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.Alert;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoFence;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationBasedServiceException;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.AlertAlreadyExistException;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData;
|
||||
import org.wso2.carbon.device.mgt.core.cache.impl.GeoCacheManagerImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.GeofenceDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.core.dto.event.config.GeoFenceGroupMap;
|
||||
import org.wso2.carbon.device.mgt.core.geo.task.GeoFenceEventOperationManager;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants;
|
||||
import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub;
|
||||
import org.wso2.carbon.event.processor.stub.types.ExecutionPlanConfigurationDto;
|
||||
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
||||
@ -68,12 +83,17 @@ import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoServices.DAS_PORT;
|
||||
import static org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoServices.DEFAULT_HTTP_PROTOCOL;
|
||||
@ -113,6 +133,12 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
||||
|
||||
private static final String SSLV3 = "SSLv3";
|
||||
|
||||
private final GeofenceDAO geofenceDAO;
|
||||
|
||||
public GeoLocationProviderServiceImpl() {
|
||||
this.geofenceDAO = DeviceManagementDAOFactory.getGeofenceDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeoFence> getWithinAlerts(DeviceIdentifier identifier, String owner) throws GeoLocationBasedServiceException {
|
||||
|
||||
@ -1231,4 +1257,533 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
||||
}
|
||||
return jwtClientManagerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createGeofence(GeofenceData geofenceData) throws GeoLocationBasedServiceException, EventConfigurationException {
|
||||
int tenantId;
|
||||
try {
|
||||
tenantId = DeviceManagementDAOUtil.getTenantId();
|
||||
geofenceData.setTenantId(tenantId);
|
||||
geofenceData.setOwner(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername());
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving tenant Id";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
}
|
||||
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
geofenceData = geofenceDAO.saveGeofence(geofenceData);
|
||||
GeoCacheManagerImpl.getInstance()
|
||||
.addFenceToCache(geofenceData, geofenceData.getId(), tenantId);
|
||||
geofenceDAO.createGeofenceGroupMapping(geofenceData, geofenceData.getGroupIds());
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Failed to begin transaction for saving geofence";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while saving geofence";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
List<Integer> createdEventIds;
|
||||
try {
|
||||
setEventSource(geofenceData.getEventConfig());
|
||||
EventConfigurationProviderService eventConfigService = DeviceManagementDataHolder
|
||||
.getInstance().getEventConfigurationService();
|
||||
createdEventIds = eventConfigService.createEventsOfDeviceGroup(geofenceData.getEventConfig(), geofenceData.getGroupIds());
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
geofenceDAO.createGeofenceEventMapping(geofenceData.getId(), createdEventIds);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
} catch (EventConfigurationException e) {
|
||||
String msg = "Failed to store Geofence event configurations";
|
||||
log.error(msg, e);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Deleting the geofence record with ID " + geofenceData.getId()
|
||||
+ " since the associated event or event group mapping couldn't save successfully");
|
||||
}
|
||||
this.deleteGeofenceData(geofenceData.getId());
|
||||
throw new EventConfigurationException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Failed to begin transaction for saving geofence";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while creating geofence event mapping records";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
createEventTask(OperationMgtConstants.OperationCodes.EVENT_CONFIG, geofenceData, tenantId);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create event revoke task at the time of geofence edit.
|
||||
* @param geofenceData updated geofence object
|
||||
* @param tenantId id of the fence owning tenant
|
||||
*/
|
||||
private void createEventRevokeTask(GeofenceData geofenceData, int tenantId) {
|
||||
GeoFenceEventOperationManager eventManager =
|
||||
new GeoFenceEventOperationManager(OperationMgtConstants.OperationCodes.EVENT_REVOKE, tenantId,
|
||||
values -> createEventTask(OperationMgtConstants.OperationCodes.EVENT_CONFIG, geofenceData, tenantId));
|
||||
ScheduledExecutorService eventOperationExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||
eventOperationExecutor.schedule(eventManager
|
||||
.getEventOperationExecutor(geofenceData), 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create event config operation at the time of geofence edit, geofence delete
|
||||
* @param operationCode code of the creating event (EVENT_CONFIG / EVENT_REVOKE)
|
||||
* @param geofenceData creating/deleting geofence object
|
||||
* @param tenantId id of the fence owning tenant
|
||||
*/
|
||||
private void createEventTask(String operationCode, GeofenceData geofenceData, int tenantId) {
|
||||
GeoFenceEventOperationManager eventManager = new GeoFenceEventOperationManager(operationCode, tenantId, null);
|
||||
ScheduledExecutorService eventOperationExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||
eventOperationExecutor.schedule(eventManager
|
||||
.getEventOperationExecutor(geofenceData), 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set source of the event to GEOFENCE
|
||||
* @param eventConfig event list to be set event source
|
||||
*/
|
||||
private void setEventSource(List<EventConfig> eventConfig) {
|
||||
for (EventConfig eventConfigEntry : eventConfig) {
|
||||
eventConfigEntry.setEventSource(DeviceManagementConstants.EventServices.GEOFENCE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeofenceData getGeoFences(int fenceId) throws GeoLocationBasedServiceException {
|
||||
int tenantId;
|
||||
try {
|
||||
tenantId = DeviceManagementDAOUtil.getTenantId();
|
||||
GeofenceData geofenceData = GeoCacheManagerImpl.getInstance()
|
||||
.getGeoFenceFromCache(fenceId, tenantId);
|
||||
if (geofenceData != null) {
|
||||
return geofenceData;
|
||||
}
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving tenant Id";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
}
|
||||
|
||||
try {
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
GeofenceData geofence = geofenceDAO.getGeofence(fenceId, true);
|
||||
if (geofence != null) {
|
||||
GeoCacheManagerImpl.getInstance().addFenceToCache(geofence, fenceId, tenantId);
|
||||
}
|
||||
return geofence;
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving Geofence data with ID "+fenceId;
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Failed to open the DB connection to retrieve Geofence";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeofenceData> getGeoFences(PaginationRequest request) throws GeoLocationBasedServiceException {
|
||||
int tenantId;
|
||||
try {
|
||||
tenantId = DeviceManagementDAOUtil.getTenantId();
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving tenant id while get geofence data";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
}
|
||||
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Retrieving geofence data for the tenant " + tenantId);
|
||||
}
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
return geofenceDAO.getGeoFencesOfTenant(request, tenantId);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving geofence data for the tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Failed to open the DB connection to retrieve Geofence";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeofenceData> getGeoFences(String fenceName) throws GeoLocationBasedServiceException {
|
||||
int tenantId;
|
||||
try {
|
||||
tenantId = DeviceManagementDAOUtil.getTenantId();
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving tenant id while get geofence data";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
}
|
||||
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Retrieving geofence data for the tenant " + tenantId);
|
||||
}
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
return geofenceDAO.getGeoFencesOfTenant(fenceName, tenantId);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving geofence data for the tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Failed to open the DB connection to retrieve Geofence";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeofenceData> getGeoFences() throws GeoLocationBasedServiceException {
|
||||
int tenantId;
|
||||
try {
|
||||
tenantId = DeviceManagementDAOUtil.getTenantId();
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving tenant id while get geofence data";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
}
|
||||
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Retrieving all fence data for the tenant " + tenantId);
|
||||
}
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
List<GeofenceData> geoFencesOfTenant = geofenceDAO.getGeoFencesOfTenant(tenantId);
|
||||
for (GeofenceData geofenceData : geoFencesOfTenant) {
|
||||
GeoCacheManagerImpl.getInstance()
|
||||
.addFenceToCache(geofenceData, geofenceData.getId(), tenantId);
|
||||
}
|
||||
return geoFencesOfTenant;
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving geofence data for the tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Failed to open the DB connection to retrieve Geofence";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteGeofenceData(int fenceId) throws GeoLocationBasedServiceException {
|
||||
int tenantId;
|
||||
GeofenceData geofence;
|
||||
List<EventConfig> eventsOfGeoFence;
|
||||
try {
|
||||
tenantId = DeviceManagementDAOUtil.getTenantId();
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving tenant id while get geofence data";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
}
|
||||
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
geofence = geofenceDAO.getGeofence(fenceId, true);
|
||||
if (geofence == null) {
|
||||
return false;
|
||||
}
|
||||
eventsOfGeoFence = geofenceDAO.getEventsOfGeoFence(fenceId);
|
||||
List<Integer> eventIds = new ArrayList<>();
|
||||
for (EventConfig config : eventsOfGeoFence) {
|
||||
eventIds.add(config.getEventId());
|
||||
}
|
||||
if (!eventIds.isEmpty()) {
|
||||
geofenceDAO.deleteGeofenceEventMapping(eventIds);
|
||||
}
|
||||
List<Integer> groupIdsOfGeoFence = geofenceDAO.getGroupIdsOfGeoFence(fenceId);
|
||||
if (!groupIdsOfGeoFence.isEmpty()) {
|
||||
geofenceDAO.deleteGeofenceGroupMapping(groupIdsOfGeoFence);
|
||||
}
|
||||
geofenceDAO.deleteGeofenceById(fenceId);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
GeoCacheManagerImpl.getInstance().removeFenceFromCache(fenceId, tenantId);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while deleting geofence";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Failed to begin transaction to delete geofence";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
this.deleteGeoFenceEvents(geofence, eventsOfGeoFence);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateGeofence(GeofenceData geofenceData, int fenceId)
|
||||
throws GeoLocationBasedServiceException, EventConfigurationException {
|
||||
int tenantId;
|
||||
try {
|
||||
tenantId = DeviceManagementDAOUtil.getTenantId();
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving tenant id while get geofence data";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
}
|
||||
|
||||
List<Integer> savedGroupIds;
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
int updatedRowCount = geofenceDAO.updateGeofence(geofenceData, fenceId);
|
||||
savedGroupIds = geofenceDAO.getGroupIdsOfGeoFence(fenceId);
|
||||
geofenceData.setId(fenceId);
|
||||
List<Integer> groupIdsToDelete = new ArrayList<>();
|
||||
List<Integer> groupIdsToAdd = new ArrayList<>();
|
||||
for (Integer savedGroupId : savedGroupIds) {
|
||||
if (!geofenceData.getGroupIds().contains(savedGroupId)) {
|
||||
groupIdsToDelete.add(savedGroupId);
|
||||
}
|
||||
}
|
||||
for (Integer newGroupId : geofenceData.getGroupIds()) {
|
||||
if (!savedGroupIds.contains(newGroupId)) {
|
||||
groupIdsToAdd.add(newGroupId);
|
||||
}
|
||||
}
|
||||
geofenceDAO.deleteGeofenceGroupMapping(groupIdsToDelete);
|
||||
geofenceDAO.createGeofenceGroupMapping(geofenceData, groupIdsToAdd);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
if (updatedRowCount > 0) {
|
||||
GeoCacheManagerImpl.getInstance().updateGeoFenceInCache(geofenceData, fenceId, tenantId);
|
||||
}
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Failed to begin transaction for saving geofence";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while saving geofence";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateGeoEventConfigurations(GeofenceData geofenceData,
|
||||
List<Integer> removedEventIdList, List<Integer> groupIds, int fenceId)
|
||||
throws GeoLocationBasedServiceException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Updating event configuration of geofence " + fenceId);
|
||||
}
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Deleting geofence event mapping records of geofence " + fenceId);
|
||||
}
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
geofenceDAO.deleteGeofenceEventMapping(removedEventIdList);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while deleting geofence event mapping of fence " + fenceId;
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Failed to begin transaction deleting geofence event mapping of fence " + fenceId;
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
|
||||
List<Integer> createdEventIds;
|
||||
int tenantId;
|
||||
try {
|
||||
tenantId = DeviceManagementDAOUtil.getTenantId();
|
||||
setEventSource(geofenceData.getEventConfig());
|
||||
EventConfigurationProviderService eventConfigService = DeviceManagementDataHolder
|
||||
.getInstance().getEventConfigurationService();
|
||||
if (eventConfigService == null) {
|
||||
String msg = "Failed to load EventConfigurationProviderService osgi service of tenant " + tenantId;
|
||||
log.error(msg);
|
||||
throw new GeoLocationBasedServiceException(msg);
|
||||
}
|
||||
createdEventIds = eventConfigService.updateEventsOfDeviceGroup(geofenceData.getEventConfig(), removedEventIdList, groupIds);
|
||||
} catch (EventConfigurationException e) {
|
||||
String msg = "Error occurred while updating event configuration data";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving tenant id while update geofence data";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Creating geofence event mapping records of geofence "
|
||||
+ fenceId + ". created events " + createdEventIds.toString());
|
||||
}
|
||||
try {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
geofenceDAO.createGeofenceEventMapping(fenceId, createdEventIds);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Error occurred while creating geofence event mapping records of geofence " + fenceId;
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
String msg = "Failed to begin transaction while creating geofence event mapping of fence " + fenceId;
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Update geofence event completed.");
|
||||
}
|
||||
createEventRevokeTask(geofenceData, tenantId);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeofenceData> attachEventObjects(List<GeofenceData> geoFences) throws GeoLocationBasedServiceException {
|
||||
try {
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
List<Integer> fenceIds = new ArrayList<>();
|
||||
for (GeofenceData geoFence : geoFences) {
|
||||
fenceIds.add(geoFence.getId());
|
||||
}
|
||||
if (!fenceIds.isEmpty()) {
|
||||
Map<Integer, List<EventConfig>> eventsOfGeoFences = geofenceDAO.getEventsOfGeoFences(fenceIds);
|
||||
Set<GeoFenceGroupMap> groupIdsOfGeoFences = geofenceDAO.getGroupIdsOfGeoFences(fenceIds);
|
||||
for (GeofenceData geoFence : geoFences) {
|
||||
geoFence.setEventConfig(eventsOfGeoFences.get(geoFence.getId()));
|
||||
for (GeoFenceGroupMap geoFenceGroupMap : groupIdsOfGeoFences) {
|
||||
if (geoFenceGroupMap.getFenceId() == geoFence.getId()) {
|
||||
Map<Integer, String> groupData = geoFence.getGroupData();
|
||||
if (groupData == null) {
|
||||
groupData = new HashMap<>();
|
||||
}
|
||||
groupData.put(geoFenceGroupMap.getGroupId(), geoFenceGroupMap.getGroupName());
|
||||
geoFence.setGroupData(groupData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return geoFences;
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving geo fence events/groups data";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Failed open DB connection while getting geo fence event data";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeofenceData> getGeoFencesOfGroup(int groupId, int tenantId, boolean requireEventData) throws GeoLocationBasedServiceException {
|
||||
try {
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
List<GeofenceData> geofenceDataList = geofenceDAO.getGeoFences(groupId, tenantId);
|
||||
if (requireEventData) {
|
||||
for (GeofenceData geoFenceData : geofenceDataList) {
|
||||
List<EventConfig> eventsOfGeoFence = geofenceDAO.getEventsOfGeoFence(geoFenceData.getId());
|
||||
geoFenceData.setEventConfig(eventsOfGeoFence);
|
||||
}
|
||||
}
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
return geofenceDataList;
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving geo fences of group " + groupId
|
||||
+ " and tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Failed to obtain connection while retrieving geofence data of group "
|
||||
+ groupId + " and tenant " + tenantId;
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EventConfig> getEventsOfGeoFence(int geoFenceId) throws GeoLocationBasedServiceException {
|
||||
try {
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
return geofenceDAO.getEventsOfGeoFence(geoFenceId);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Failed to obtain connection while retrieving event data of geo fence "
|
||||
+ geoFenceId;
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving event data of geo fence " + geoFenceId;
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete events of geofence
|
||||
* @param geofenceData geofence mapped with deleting events
|
||||
* @param eventList events to be deleted
|
||||
*/
|
||||
private void deleteGeoFenceEvents(GeofenceData geofenceData, List<EventConfig> eventList)
|
||||
throws GeoLocationBasedServiceException {
|
||||
int tenantId;
|
||||
try {
|
||||
tenantId = DeviceManagementDAOUtil.getTenantId();
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving tenant id while get geofence data";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
}
|
||||
|
||||
try {
|
||||
EventConfigurationProviderService eventConfigService = DeviceManagementDataHolder
|
||||
.getInstance().getEventConfigurationService();
|
||||
eventConfigService.deleteEvents(eventList);
|
||||
createEventTask(OperationMgtConstants.OperationCodes.EVENT_REVOKE, geofenceData, tenantId);
|
||||
} catch (EventConfigurationException e) {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
String msg = "Failed to delete Geofence event configurations";
|
||||
log.error(msg, e);
|
||||
throw new GeoLocationBasedServiceException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.geo.task;
|
||||
public interface EventCreateCallback {
|
||||
void onCompleteEventOperation(Object values);
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. 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.geo.task;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoFenceEventMeta;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData;
|
||||
import org.wso2.carbon.device.mgt.core.event.config.GroupEventOperationExecutor;
|
||||
import org.wso2.carbon.device.mgt.core.event.config.EventOperationExecutor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Responsible for Event operation task creation management.
|
||||
* Wrap event operation executor creation
|
||||
*/
|
||||
public class GeoFenceEventOperationManager {
|
||||
private final int tenantId;
|
||||
private final String eventOperationCode;
|
||||
private final EventCreateCallback callback;
|
||||
|
||||
public GeoFenceEventOperationManager(String eventOperationCode, int tenantId, EventCreateCallback callback) {
|
||||
this.eventOperationCode = eventOperationCode;
|
||||
this.tenantId = tenantId;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get executor for create EVENT_CONFIG / EVENT_REVOKE operations at the time of a geofence
|
||||
* created, updated or deleted
|
||||
* @param geofenceData created geofence data object
|
||||
* @return {@link EventOperationExecutor} Created executor to create operations
|
||||
*/
|
||||
public EventOperationExecutor getEventOperationExecutor(GeofenceData geofenceData) {
|
||||
GeoFenceEventMeta geoFenceEventMeta = new GeoFenceEventMeta(geofenceData);
|
||||
EventOperationExecutor executor = new EventOperationExecutor(geoFenceEventMeta, geofenceData.getGroupIds(),
|
||||
tenantId, DeviceManagementConstants.EventServices.GEOFENCE, eventOperationCode);
|
||||
executor.setCallback(callback);
|
||||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get executor for create EVENT_CONFIG / EVENT_REVOKE operations at the time of a device/s
|
||||
* assigned into a group or removed from a group
|
||||
* @param groupId Id of the assigned / removed group
|
||||
* @param deviceIdentifiers Device identifiers assigned to / removed from the group
|
||||
* @return {@link GroupEventOperationExecutor} Created executor to create operations
|
||||
*/
|
||||
public GroupEventOperationExecutor getEventOperationExecutor(int groupId, List<DeviceIdentifier> deviceIdentifiers) {
|
||||
GroupEventOperationExecutor executor = new GroupEventOperationExecutor(groupId, deviceIdentifiers, tenantId, eventOperationCode);
|
||||
executor.setCallback(callback);
|
||||
return executor;
|
||||
}
|
||||
}
|
||||
@ -22,6 +22,8 @@ import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
|
||||
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationProviderService;
|
||||
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
|
||||
@ -71,6 +73,9 @@ public class DeviceManagementDataHolder {
|
||||
private DeviceStatusTaskManagerService deviceStatusTaskManagerService;
|
||||
private DeviceTypeGeneratorService deviceTypeGeneratorService;
|
||||
private PrivacyComplianceProvider privacyComplianceProvider;
|
||||
private EventConfigurationProviderService eventConfigurationService;
|
||||
private GeoLocationProviderService geoLocationProviderService;
|
||||
|
||||
private final Map<DeviceType, DeviceStatusTaskPluginConfig> deviceStatusTaskPluginConfigs = Collections.synchronizedMap(
|
||||
new HashMap<>());
|
||||
|
||||
@ -286,4 +291,20 @@ public class DeviceManagementDataHolder {
|
||||
public void setDeviceInformationManager(DeviceInformationManager deviceInformationManager) {
|
||||
this.deviceInformationManager = deviceInformationManager;
|
||||
}
|
||||
|
||||
public void setEventConfigurationProviderService(EventConfigurationProviderService eventConfigurationService) {
|
||||
this.eventConfigurationService = eventConfigurationService;
|
||||
}
|
||||
|
||||
public EventConfigurationProviderService getEventConfigurationService() {
|
||||
return eventConfigurationService;
|
||||
}
|
||||
|
||||
public GeoLocationProviderService getGeoLocationProviderService() {
|
||||
return geoLocationProviderService;
|
||||
}
|
||||
|
||||
public void setGeoLocationProviderService(GeoLocationProviderService geoLocationProviderService) {
|
||||
this.geoLocationProviderService = geoLocationProviderService;
|
||||
}
|
||||
}
|
||||
@ -21,6 +21,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationProviderService;
|
||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
||||
@ -50,6 +51,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl;
|
||||
import org.wso2.carbon.device.mgt.core.event.config.EventConfigurationProviderServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.geo.service.GeoLocationProviderServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.metadata.mgt.MetadataManagementServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOFactory;
|
||||
@ -328,12 +330,18 @@ public class DeviceManagementServiceComponent {
|
||||
|
||||
/* Registering Geo Service */
|
||||
GeoLocationProviderService geoService = new GeoLocationProviderServiceImpl();
|
||||
DeviceManagementDataHolder.getInstance().setGeoLocationProviderService(geoService);
|
||||
bundleContext.registerService(GeoLocationProviderService.class.getName(), geoService, null);
|
||||
|
||||
/* Registering Metadata Service */
|
||||
MetadataManagementService metadataManagementService = new MetadataManagementServiceImpl();
|
||||
bundleContext.registerService(MetadataManagementService.class.getName(), metadataManagementService, null);
|
||||
|
||||
/* Registering Event Configuration Service */
|
||||
EventConfigurationProviderService eventConfigurationService = new EventConfigurationProviderServiceImpl();
|
||||
DeviceManagementDataHolder.getInstance().setEventConfigurationProviderService(eventConfigurationService);
|
||||
bundleContext.registerService(EventConfigurationProviderService.class.getName(), eventConfigurationService, null);
|
||||
|
||||
OTPManagementService otpManagementService = new OTPManagementServiceImpl();
|
||||
bundleContext.registerService(OTPManagementService.class.getName(), otpManagementService, null);
|
||||
|
||||
|
||||
@ -165,28 +165,29 @@ public class OperationManagerImpl implements OperationManager {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("operation:[" + operation.toString() + "]");
|
||||
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
||||
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" +
|
||||
deviceIdentifier.getType() + "]");
|
||||
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + deviceIdentifier.getType()
|
||||
+ "]");
|
||||
}
|
||||
}
|
||||
try {
|
||||
|
||||
DeviceIDHolder deviceValidationResult = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds);
|
||||
List<DeviceIdentifier> validDeviceIds = deviceValidationResult.getValidDeviceIDList();
|
||||
if (validDeviceIds.size() > 0) {
|
||||
if (!validDeviceIds.isEmpty()) {
|
||||
DeviceIDHolder deviceAuthorizationResult = this.authorizeDevices(operation, validDeviceIds);
|
||||
List<DeviceIdentifier> authorizedDeviceIds = deviceAuthorizationResult.getValidDeviceIDList();
|
||||
if (authorizedDeviceIds.size() <= 0) {
|
||||
if (authorizedDeviceIds.isEmpty()) {
|
||||
log.warn("User : " + getUser() + " is not authorized to perform operations on given device-list.");
|
||||
Activity activity = new Activity();
|
||||
//Send the operation statuses only for admin triggered operations
|
||||
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult,
|
||||
deviceAuthorizationResult));
|
||||
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult));
|
||||
return activity;
|
||||
}
|
||||
|
||||
boolean isScheduledOperation = this.isTaskScheduledOperation(operation);
|
||||
String initiatedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
if (initiatedBy == null && isScheduledOperation) {
|
||||
if (initiatedBy == null && (isScheduledOperation
|
||||
|| operation.getCode().equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_CONFIG)
|
||||
|| operation.getCode().equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_REVOKE))) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("initiatedBy : " + SYSTEM);
|
||||
}
|
||||
@ -198,8 +199,8 @@ public class OperationManagerImpl implements OperationManager {
|
||||
operation.setInitiatedBy(initiatedBy);
|
||||
}
|
||||
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
|
||||
OperationDAOUtil.convertOperation(operation);
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto = OperationDAOUtil
|
||||
.convertOperation(operation);
|
||||
String operationCode = operationDto.getCode();
|
||||
Map<Integer, Device> enrolments = new HashMap<>();
|
||||
Device device;
|
||||
@ -208,9 +209,10 @@ public class OperationManagerImpl implements OperationManager {
|
||||
enrolments.put(device.getEnrolmentInfo().getId(), device);
|
||||
}
|
||||
|
||||
try {
|
||||
OperationManagementDAOFactory.beginTransaction();
|
||||
if (operationDto.getControl() ==
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) {
|
||||
if (operationDto.getControl()
|
||||
== org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) {
|
||||
Map<Integer, Integer> pendingOperationIDs = operationDAO
|
||||
.getExistingOperationIDs(enrolments.keySet().toArray(new Integer[0]), operationCode);
|
||||
for (Integer enrolmentId : pendingOperationIDs.keySet()) {
|
||||
@ -227,8 +229,8 @@ public class OperationManagerImpl implements OperationManager {
|
||||
+ operationCode);
|
||||
}
|
||||
Activity activity = new Activity();
|
||||
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult,
|
||||
deviceAuthorizationResult));
|
||||
activity.setActivityStatus(
|
||||
this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult));
|
||||
return activity;
|
||||
}
|
||||
}
|
||||
@ -242,21 +244,25 @@ public class OperationManagerImpl implements OperationManager {
|
||||
activity.setType(Activity.Type.valueOf(operationDto.getType().toString()));
|
||||
//For now set the operation statuses only for admin triggered operations
|
||||
if (!isScheduledOperation) {
|
||||
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult,
|
||||
deviceAuthorizationResult));
|
||||
activity.setActivityStatus(
|
||||
this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult));
|
||||
}
|
||||
return activity;
|
||||
} else {
|
||||
throw new InvalidDeviceException("Invalid device Identifiers found.");
|
||||
}
|
||||
} catch (OperationManagementDAOException e) {
|
||||
OperationManagementDAOFactory.rollbackTransaction();
|
||||
throw new OperationManagementException("Error occurred while adding operation", e);
|
||||
String msg = "Error occurred while adding operation";
|
||||
log.error(msg, e);
|
||||
throw new OperationManagementException(msg, e);
|
||||
} catch (TransactionManagementException e) {
|
||||
throw new OperationManagementException("Error occurred while initiating the transaction", e);
|
||||
String msg = "Error occurred while initiating the transaction";
|
||||
log.error(msg, e);
|
||||
throw new OperationManagementException(msg, e);
|
||||
} finally {
|
||||
OperationManagementDAOFactory.closeConnection();
|
||||
}
|
||||
} else {
|
||||
throw new InvalidDeviceException("Invalid device Identifiers found.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -627,7 +633,7 @@ public class OperationManagerImpl implements OperationManager {
|
||||
operations.add(operation);
|
||||
}
|
||||
paginationResult = new PaginationResult();
|
||||
int count = operationDAO.getOperationCountForDevice(enrolmentId);
|
||||
int count = operationDAO.getOperationCountForDevice(enrolmentId, request);
|
||||
paginationResult.setData(operations);
|
||||
paginationResult.setRecordsTotal(count);
|
||||
paginationResult.setRecordsFiltered(count);
|
||||
@ -1331,12 +1337,10 @@ public class OperationManagerImpl implements OperationManager {
|
||||
boolean status;
|
||||
switch (operation.getCode()) {
|
||||
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_OPERATION_CODE:
|
||||
status = true;
|
||||
break;
|
||||
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE:
|
||||
status = true;
|
||||
break;
|
||||
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.EVENT_CONFIG_OPERATION_CODE:
|
||||
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.EVENT_REVOKE_OPERATION_CODE:
|
||||
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_REVOKE_OPERATION_CODE:
|
||||
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE:
|
||||
status = true;
|
||||
break;
|
||||
default:
|
||||
|
||||
@ -25,5 +25,7 @@ public class OperationMgtConstants {
|
||||
}
|
||||
|
||||
public static final String POLICY_REVOKE = "POLICY_REVOKE";
|
||||
public static final String EVENT_CONFIG = "EVENT_CONFIG";
|
||||
public static final String EVENT_REVOKE = "EVENT_REVOKE";
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user