<commit_before><?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
  <class name="com.krishagni.catissueplus.core.auth.domain.LoginAuditLog" table="OS_LOGIN_AUDIT_LOGS">
    
    <id name="id" column="IDENTIFIER">
      <generator class="native">
        <param name="sequence">OS_LOGIN_AUDIT_LOGS_SEQ</param>
      </generator>
    </id>
    
    <many-to-one name="user" column="USER_ID" not-null="true"/>	

    <property name="ipAddress" column="IP_ADDRESS" not-null="true"/>

    <property name="loginTime" column="LOGIN_TIME" not-null="true"/>

    <property name="logoutTime" column="LOGOUT_TIME"/>
    
    <property name="loginSuccessful" column="IS_LOGIN_SUCCESSFUL"/>
    
    <set name="apiLogs" table="OS_USER_API_CALLS_LOG">
      <key column="LOGIN_AUDIT_LOG_ID"/>
      <one-to-many class="com.krishagni.catissueplus.core.audit.domain.UserApiCallLog"/>
    </set>
    
    <query name="getLogsByUserId">
      from LoginAuditLog where user.id = :userId order by id desc
    </query>

    <sql-query name="getActiveUsersCount">
      <return-scalar column="usersCnt" type="int"/>

      select
        count(distinct u.identifier) as usersCnt
      from
        os_user_api_calls_log log
        inner join catissue_user u on u.identifier = log.user_id
      where
        log.call_start_time between :fromDate and :toDate and
        (:instituteId is null or u.institute_id = :instituteId)
    </sql-query>

    <sql-query name="getLoginsCount">
      <return-scalar column="usersCnt" type="int"/>

      select
        count(*) as usersCnt
      from
        os_login_audit_logs log
        inner join catissue_user u on log.user_id = u.identifier
      where
        log.is_login_successful = :loginSuccessful and
        log.login_time between :fromDate and :toDate and
        (:instituteId is null or u.institute_id = :instituteId)
    </sql-query>
  </class>
</hibernate-mapping><commit_msg>OPSMN-5330: Implemented a query to fetch the last API call time of the input login sessions.<commit_after><?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
  <class name="com.krishagni.catissueplus.core.auth.domain.LoginAuditLog" table="OS_LOGIN_AUDIT_LOGS">
    
    <id name="id" column="IDENTIFIER">
      <generator class="native">
        <param name="sequence">OS_LOGIN_AUDIT_LOGS_SEQ</param>
      </generator>
    </id>
    
    <many-to-one name="user" column="USER_ID" not-null="true"/>	

    <property name="ipAddress" column="IP_ADDRESS" not-null="true"/>

    <property name="loginTime" column="LOGIN_TIME" not-null="true"/>

    <property name="logoutTime" column="LOGOUT_TIME"/>
    
    <property name="loginSuccessful" column="IS_LOGIN_SUCCESSFUL"/>
    
    <set name="apiLogs" table="OS_USER_API_CALLS_LOG">
      <key column="LOGIN_AUDIT_LOG_ID"/>
      <one-to-many class="com.krishagni.catissueplus.core.audit.domain.UserApiCallLog"/>
    </set>
    
    <query name="getLogsByUserId">
      from LoginAuditLog where user.id = :userId order by id desc
    </query>

    <sql-query name="getActiveUsersCount">
      <return-scalar column="usersCnt" type="int"/>

      select
        count(distinct u.identifier) as usersCnt
      from
        os_user_api_calls_log log
        inner join catissue_user u on u.identifier = log.user_id
      where
        log.call_start_time between :fromDate and :toDate and
        (:instituteId is null or u.institute_id = :instituteId)
    </sql-query>

    <sql-query name="getLoginsCount">
      <return-scalar column="usersCnt" type="int"/>

      select
        count(*) as usersCnt
      from
        os_login_audit_logs log
        inner join catissue_user u on log.user_id = u.identifier
      where
        log.is_login_successful = :loginSuccessful and
        log.login_time between :fromDate and :toDate and
        (:instituteId is null or u.institute_id = :instituteId)
    </sql-query>

    <sql-query name="getLoginActiveTime">
      <return-scalar column="auditLogId" type="long"/>
      <return-scalar column="lastActiveTime" type="timestamp"/>

      select
        login_audit_log_id as auditLogId, max(call_end_time) as lastActiveTime
      from
        os_user_api_calls_log
      where
        login_audit_log_id in (:auditLogIds)
      group by
        login_audit_log_id
    </sql-query>
  </class>
</hibernate-mapping>
{'fraction_non_alphanumeric': 0.12286763118117038, 'fraction_numerical': 0.003886849492550205, 'mean_word_length': 3.150537634408602, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 2, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '537963', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1519, 'n_words': 307}