forked from community/device-mgt-core
commit
bac6e3ba67
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class carries information related to operation log filtering values which will be used in the UI to filter operations.
|
||||||
|
*/
|
||||||
|
public class OperationLogFilters {
|
||||||
|
private List<String> operationCode;
|
||||||
|
private Long createdDayFrom;
|
||||||
|
private Long createdDayTo ;
|
||||||
|
private Long updatedDayFrom;
|
||||||
|
private Long updatedDayTo ;
|
||||||
|
private List<String> status;
|
||||||
|
public OperationLogFilters() {
|
||||||
|
}
|
||||||
|
public OperationLogFilters(List<String> operationCode , Long createdDayFrom, Long createdDayTo,
|
||||||
|
Long updatedDayFrom, Long updatedDayTo, List<String> status) {
|
||||||
|
this.operationCode = operationCode;
|
||||||
|
this.createdDayFrom = createdDayFrom;
|
||||||
|
this.createdDayTo = createdDayTo;
|
||||||
|
this.updatedDayFrom = updatedDayFrom;
|
||||||
|
this.updatedDayTo = updatedDayTo;
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
public List<String> getOperationCode() {
|
||||||
|
return operationCode;
|
||||||
|
}
|
||||||
|
public void setOperationCode(List<String> operationCode) {
|
||||||
|
this.operationCode = operationCode;
|
||||||
|
}
|
||||||
|
public List<String> getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
public void setStatus(List<String> status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
public Long getUpdatedDayFrom() {
|
||||||
|
return updatedDayFrom;
|
||||||
|
}
|
||||||
|
public void setUpdatedDayFrom(Long updatedDayFrom) {
|
||||||
|
this.updatedDayFrom = updatedDayFrom;
|
||||||
|
}
|
||||||
|
public Long getUpdatedDayTo() {
|
||||||
|
return updatedDayTo;
|
||||||
|
}
|
||||||
|
public void setUpdatedDayTo(Long updatedDayTo) {
|
||||||
|
this.updatedDayTo = updatedDayTo;
|
||||||
|
}
|
||||||
|
public Long getCreatedDayFrom() { return createdDayFrom; }
|
||||||
|
public void setCreatedDayFrom(Long createdDayFrom) { this.createdDayFrom = createdDayFrom; }
|
||||||
|
public Long getCreatedDayTo() { return createdDayTo; }
|
||||||
|
public void setCreatedDayTo(Long createdDayTo) { this.createdDayTo = createdDayTo; }
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue