<?xml version="1.0" encoding="UTF-8"?>
<!--

  This file is part of the Meeds project (https://meeds.io/).

  Copyright (C) 2020 - 2023 Meeds Lab contact@meedslab.com

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 3 of the License, or (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  You should have received a copy of the GNU Lesser General Public License
  along with this program; if not, write to the Free Software Foundation,
  Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

-->
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd http://www.exoplatform.org/xml/ns/kernel_1_2.xsd"
               xmlns="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd">


  <component>
    <type>io.meeds.gamification.twitter.dao.TwitterAccountDAO</type>
  </component>

  <component>
    <type>io.meeds.gamification.twitter.dao.TwitterTweetDAO</type>
  </component>

  <component>
    <type>io.meeds.gamification.twitter.storage.TwitterAccountStorage</type>
  </component>

  <component>
    <type>io.meeds.gamification.twitter.storage.TwitterTweetStorage</type>
  </component>

  <component>
    <key>io.meeds.gamification.twitter.storage.TwitterConsumerStorage</key>
    <type>io.meeds.gamification.twitter.storage.cached.TwitterConsumerCachedStorage</type>
  </component>

  <component>
    <key>io.meeds.gamification.twitter.service.TwitterConsumerService</key>
    <type>io.meeds.gamification.twitter.service.impl.TwitterConsumerServiceImpl</type>
  </component>

  <component>
    <key>io.meeds.gamification.twitter.service.TwitterTriggerService</key>
    <type>io.meeds.gamification.twitter.service.impl.TwitterTriggerServiceImpl</type>
  </component>

  <component>
    <key>io.meeds.gamification.twitter.service.TwitterService</key>
    <type>io.meeds.gamification.twitter.service.impl.TwitterServiceImpl</type>
  </component>

  <component>
    <type>io.meeds.gamification.twitter.rest.TwitterServiceRest</type>
  </component>

  <external-component-plugins>
    <target-component>io.meeds.gamification.service.ConnectorService</target-component>
    <component-plugin>
      <name>twitter</name>
      <set-method>addPlugin</set-method>
      <type>io.meeds.gamification.twitter.plugin.TwitterConnectorPlugin</type>
    </component-plugin>
  </external-component-plugins>

  <external-component-plugins>
    <target-component>io.meeds.gamification.service.EventService</target-component>
    <component-plugin>
      <name>twitter</name>
      <set-method>addPlugin</set-method>
      <type>io.meeds.gamification.twitter.plugin.TwitterEventPlugin</type>
    </component-plugin>
  </external-component-plugins>

  <external-component-plugins>
    <target-component>org.exoplatform.web.filter.ExtensibleFilter</target-component>
    <component-plugin>
      <name>Twitter Oauth Redirect Filter</name>
      <set-method>addFilterDefinitions</set-method>
      <type>org.exoplatform.web.filter.FilterDefinitionPlugin</type>
      <init-params>
        <object-param>
          <name>Twitter Oauth Redirect Filter</name>
          <object type="org.exoplatform.web.filter.FilterDefinition">
            <field name="filter">
              <object type="io.meeds.gamification.twitter.web.TwitterConnectorFilter"/>
            </field>
            <field name="patterns">
              <collection type="java.util.ArrayList" item-type="java.lang.String">
                <value>
                  <string>/twitterOauth</string>
                </value>
              </collection>
            </field>
          </object>
        </object-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>

  <external-component-plugins>
    <target-component>org.exoplatform.commons.api.persistence.DataInitializer</target-component>
    <component-plugin>
      <name>GamificationChangeLogsPlugin</name>
      <set-method>addChangeLogsPlugin</set-method>
      <type>org.exoplatform.commons.persistence.impl.ChangeLogsPlugin</type>
      <init-params>
        <values-param>
          <name>changelogs</name>
          <description>Change logs of Twitter Connector</description>
          <value>db/changelog/twitter-connector.db.changelog-1.0.0.xml</value>
        </values-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>

  <external-component-plugins>
    <target-component>org.exoplatform.services.scheduler.JobSchedulerService</target-component>
    <component-plugin>
      <name>TwitterAccountRemoteUpdate</name>
      <set-method>addCronJob</set-method>
      <type>org.exoplatform.services.scheduler.CronJob</type>
      <description>Configuration to manage the periodic updating of twitter account events</description>
      <init-params>
        <properties-param>
          <name>cronjob.info</name>
          <description>Configuration to manage the periodic updating of twitter account events</description>
          <property name="jobName" value="TwitterAccountRemoteUpdate"/>
          <property name="groupName" value="Gamification"/>
          <property name="job" value="io.meeds.gamification.twitter.scheduled.TwitterRemoteUpdateJob"/>
          <property name="expression" value="${io.meeds.gamification.TwitterAccountRemoteUpdate.expression:0 */15 * * * ?}"/><!-- Every 15 minutes -->
        </properties-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>

  <external-component-plugins>
  <target-component>org.exoplatform.services.listener.ListenerService</target-component>
    <component-plugin>
      <name>rule.created</name>
      <set-method>addListener</set-method>
      <type>io.meeds.gamification.twitter.listener.RuleUpdateTwitterListener</type>
    </component-plugin>
    <component-plugin>
      <name>rule.deleted</name>
      <set-method>addListener</set-method>
      <type>io.meeds.gamification.twitter.listener.RuleUpdateTwitterListener</type>
    </component-plugin>
    <component-plugin>
      <name>rule.updated</name>
      <set-method>addListener</set-method>
      <type>io.meeds.gamification.twitter.listener.RuleUpdateTwitterListener</type>
    </component-plugin>
  </external-component-plugins>

  <import>jar:/conf/portal/gamification-twitter-connector-configuration.xml</import>

</configuration>