Subversion Repositories SmartDukaan

Rev

Rev 5759 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="in.shop2020.alert.persistence.EntityMapper">
<resultMap type="monitored_entity" id="monitored_entityResult">
                <id property="id" column="id"/>
        </resultMap>

<select id="isEntityMonitorable" parameterType="int" resultType="boolean">
        SELECT isActive
        FROM entity_monitoring_status
        <where>
        entityType = #{entityType}
        </where>
</select>

<insert id="insertEntity" parameterType="monitored_entity" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO monitored_entity
                (entityType, eventType, entityIdentifier, warnExpiryTime, criticalExpiryTime, entityProperties, entityProcessedState)
    VALUES
      (#{entityType}, #{eventType}, #{entityIdentifier}, #{warnExpiryTime}, #{criticalExpiryTime}, #{entityProperties}, 1)
</insert>

<update id="updateEntity" parameterType="monitored_entity">
        UPDATE monitored_entity
      SET eventType=#{eventType}, warnExpiryTime=#{warnExpiryTime}, 
        criticalExpiryTime=#{criticalExpiryTime}, 
        entityProperties=#{entityProperties},
        entityProcessedState = 1 
        <where>
                id = #{id}
        </where>        
</update>

<!--  select id="isEntityMonitorable" parameterType="int" resultType="int">
        SELECT ISNULL((SELECT 1 FROM entity_monitoring_status WHERE entityType = entityType AND isActive = true), 0)
</select-->

<select id="getEntity" parameterType="map" resultType="monitored_entity">
        SELECT * 
        FROM monitored_entity
        <where>
                 entityType = #{entityType}
                 AND entityIdentifier = #{entityIdentifier}
        </where>
</select>

<select id="getEntityMonitoringStatus" parameterType="int" resultType="entity_monitoring_status">
        SELECT * 
        FROM entity_monitoring_status
        <where>
                 entityType = #{entityType}
        </where>
</select>

<insert id="insertAlertedEntity" parameterType="alerted_entity" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO alerted_entity
      (entityType, eventType, entityIdentifier, lastAlertedTime, entityProperties, entityProcessedState)
    VALUES
      (#{entityType}, #{eventType}, #{entityIdentifier}, #{lastAlertedTime}, #{entityProperties}, #{entityProcessedState})
</insert>

<delete id="removeMonitoredEntity" parameterType="map">
        DELETE FROM monitored_entity
        <where>
                 entityType = #{entityType}
                 AND entityIdentifier = #{entityIdentifier}
        </where>
</delete>

<select id="getEntitiesToBeAlerted" resultType="monitored_entity">
        SELECT * 
        FROM monitored_entity
        <where>
                 (warnExpiryTime &lt;= NOW()
                 AND entityProcessedState &lt; 1)
                 OR (criticalExpiryTime &lt;= NOW()
                 AND entityProcessedState &lt; 2)
        </where>
</select>

<select id="getActiveAlertEntities" resultType="monitored_entity">
        SELECT * 
        FROM monitored_entity
        <where>
                 warnExpiryTime &lt;= NOW()
                 OR criticalExpiryTime &lt;= NOW()
        </where>
</select>

<update id="updateEntityProcessedState" parameterType="map">
        UPDATE monitored_entity
      SET entityProcessedState=#{state}
        <where>
                id = #{id}
        </where>        
</update>

<select id="getEntities" parameterType="searchFilter" resultType="monitored_entity">
        SELECT * from monitored_entity
        <where>
    <if test="entityType != 0">
        AND entityType = #{entityType}
    </if>
    <if test="eventType != null">
        AND eventType = #{eventType}
    </if>
    <if test="entityIdentifier != null">
        AND entityIdentifier = #{entityIdentifier}
    </if>
    <if test="entityProcessedState != null">
        AND entityProcessedState = #{entityProcessedState}
    </if>
    </where>
</select>

<select id="getAlertedEntities" parameterType="searchFilter" resultType="alerted_entity">
        SELECT * from alerted_entity
        <where>
    <if test="entityType != null">
        AND entityType = #{entityType}
    </if>
    <if test="eventType != null">
        AND eventType = #{eventType}
    </if>
    <if test="entityIdentifier != null">
        AND entityIdentifier = #{entityIdentifier}
    </if>
    <if test="entityProcessedState != null">
        AND entityProcessedState = #{entityProcessedState}
    </if>
    </where>
</select>

<select id="getAlertMapper" parameterType="map" resultType="alert_mapper">
        SELECT * 
        FROM alert_mapper
        <where>
                 entityType = #{entityType}
                 AND eventType = #{eventType}
        </where>
        LIMIT 1
</select>

<update id="activateEntityMonitoring" parameterType="map">
        UPDATE entity_monitoring_status 
        SET isActive = true
        AND defaultAlertGroup = #{userIds}
        <where>
                 entityType = #{entityType}
        </where>
</update>

<update id="deActivateEntityMonitoring" parameterType="map">
        UPDATE entity_monitoring_status 
        SET isActive = 0
        <where>
                 entityType = #{entityType}
        </where>
</update>

<insert id="registerEventType" parameterType="alert_mapper">
        INSERT INTO alert_mapper
      (entityType, eventType, eventDescription, userIds, alertType)
    VALUES
      (#{entityType}, #{eventType}, #{eventDescription}, #{userIds}, #{alertType})
</insert>

</mapper>