Subversion Repositories SmartDukaan

Rev

Rev 5563 | Rev 5759 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5519 amar.kumar 1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
3
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
4
 
5
<mapper namespace="in.shop2020.alert.persistence.EntityMapper">
6
<resultMap type="monitored_entity" id="monitored_entityResult">
7
		<id property="id" column="id"/>
8
	</resultMap>
9
 
10
<select id="isEntityMonitorable" parameterType="int" resultType="boolean">
11
	SELECT isActive
12
	FROM entity_monitoring_status
13
	<where>
14
        entityType = #{entityType}
15
	</where>
16
</select>
17
 
18
<insert id="insertEntity" parameterType="monitored_entity" useGeneratedKeys="true" keyProperty="id">
19
	INSERT INTO monitored_entity
20
		(entityType, eventType, entityIdentifier, warnExpiryTime, criticalExpiryTime, entityProperties, entityProcessedState)
21
    VALUES
22
      (#{entityType}, #{eventType}, #{entityIdentifier}, #{warnExpiryTime}, #{criticalExpiryTime}, #{entityProperties}, 1)
23
</insert>
24
 
25
<update id="updateEntity" parameterType="monitored_entity">
26
	UPDATE monitored_entity
27
      SET eventType=#{eventType}, warnExpiryTime=#{warnExpiryTime}, 
28
      	criticalExpiryTime=#{criticalExpiryTime}, 
29
      	entityProperties=#{entityProperties} 
30
	<where>
31
  		id = #{id}
32
  	</where>   	
33
</update>
34
 
35
<!--  select id="isEntityMonitorable" parameterType="int" resultType="int">
36
	SELECT ISNULL((SELECT 1 FROM entity_monitoring_status WHERE entityType = entityType AND isActive = true), 0)
37
</select-->
38
 
39
<select id="getEntity" parameterType="map" resultType="monitored_entity">
40
	SELECT * 
41
	FROM monitored_entity
42
	<where>
43
  		 entityType = #{entityType}
44
  		 AND entityIdentifier = #{entityIdentifier}
45
  	</where>
46
</select>
47
 
5536 amar.kumar 48
<select id="getEntityMonitoringStatus" parameterType="int" resultType="entity_monitoring_status">
49
	SELECT * 
50
	FROM entity_monitoring_status
51
	<where>
52
  		 entityType = #{entityType}
53
  	</where>
54
</select>
55
 
5563 amar.kumar 56
<insert id="insertAlertedEntity" parameterType="alerted_entity" useGeneratedKeys="true" keyProperty="id">
5519 amar.kumar 57
	INSERT INTO alerted_entity
58
      (entityType, eventType, entityIdentifier, lastAlertedTime, entityProperties, entityProcessedState)
59
    VALUES
60
      (#{entityType}, #{eventType}, #{entityIdentifier}, #{lastAlertedTime}, #{entityProperties}, #{entityProcessedState})
61
</insert>
62
 
63
<delete id="removeMonitoredEntity" parameterType="map">
64
	DELETE FROM monitored_entity
65
	<where>
66
  		 entityType = #{entityType}
67
  		 AND entityIdentifier = #{entityIdentifier}
68
  	</where>
69
</delete>
70
 
71
<select id="getEntitiesToBeAlerted" resultType="monitored_entity">
72
	SELECT * 
73
	FROM monitored_entity
74
	<where>
75
  		 (warnExpiryTime &lt;= NOW()
76
  		 AND entityProcessedState &lt; 1)
77
  		 OR (criticalExpiryTime &lt;= NOW()
78
  		 AND entityProcessedState &lt; 2)
79
  	</where>
80
</select>
81
 
5674 amar.kumar 82
<select id="getActiveAlertEntities" resultType="monitored_entity">
83
	SELECT * 
84
	FROM monitored_entity
85
	<where>
86
  		 warnExpiryTime &lt;= NOW()
87
  	</where>
88
</select>
89
 
5519 amar.kumar 90
<update id="updateEntityProcessedState" parameterType="map">
91
	UPDATE monitored_entity
92
      SET entityProcessedState=#{state}
93
	<where>
94
  		id = #{id}
95
  	</where>   	
96
</update>
97
 
98
<select id="getEntities" parameterType="searchFilter" resultType="monitored_entity">
99
	SELECT * from monitored_entity
100
	<where>
101
    <if test="entityType != 0">
102
        AND entityType = #{entityType}
103
    </if>
104
    <if test="eventType != null">
105
        AND eventType = #{eventType}
106
    </if>
107
    <if test="entityIdentifier != null">
108
        AND entityIdentifier = #{entityIdentifier}
109
    </if>
110
    <if test="entityProcessedState != null">
111
        AND entityProcessedState = #{entityProcessedState}
112
    </if>
113
    </where>
114
</select>
115
 
116
<select id="getAlertedEntities" parameterType="searchFilter" resultType="alerted_entity">
117
	SELECT * from alerted_entity
118
	<where>
119
    <if test="entityType != null">
120
        AND entityType = #{entityType}
121
    </if>
122
    <if test="eventType != null">
123
        AND eventType = #{eventType}
124
    </if>
125
    <if test="entityIdentifier != null">
126
        AND entityIdentifier = #{entityIdentifier}
127
    </if>
128
    <if test="entityProcessedState != null">
129
        AND entityProcessedState = #{entityProcessedState}
130
    </if>
131
    </where>
132
</select>
133
 
134
<select id="getAlertMapper" parameterType="map" resultType="alert_mapper">
135
	SELECT * 
136
	FROM alert_mapper
137
	<where>
138
  		 entityType = #{entityType}
139
  		 AND eventType = #{eventType}
140
  	</where>
141
  	LIMIT 1
142
</select>
143
 
144
<update id="activateEntityMonitoring" parameterType="map">
145
	UPDATE entity_monitoring_status 
146
	SET isActive = true
147
	AND defaultAlertGroup = #{userIds}
148
	<where>
149
  		 entityType = #{entityType}
150
  	</where>
151
</update>
152
 
153
<update id="deActivateEntityMonitoring" parameterType="map">
154
	UPDATE entity_monitoring_status 
155
	SET isActive = 0
156
	<where>
157
  		 entityType = #{entityType}
158
  	</where>
159
</update>
160
 
161
<insert id="registerEventType" parameterType="alert_mapper">
162
	INSERT INTO alert_mapper
163
      (entityType, eventType, eventDescription, userIds, alertType)
164
    VALUES
165
      (#{entityType}, #{eventType}, #{eventDescription}, #{userIds}, #{alertType})
166
</insert>
167
 
168
</mapper>