<?xml version="1.0"?>
<!-- 

    That is a working ARDB core configuration file.  Produces:
    documents table, collections table, authors table.

    $Id: configuration.xml,v 2.21 2007/06/24 13:52:04 ivan Exp $

-->
<configuration>

  <relation-type name="written-by" reverse="wrote"  default-retrieve="record">
    <view name='nothing' retrieve='nothing' />
    <view name='brief' retrieve="name,handle" />
  </relation-type>

  <relation-type name="wrote" reverse="written-by"  default-retrieve="record">
    <view name="brief" retrieve="title,handle,authors:author/name" />
    <view name="brief-with-creation-date" retrieve="title,handle,authors:author/name,creation-date"/>
  </relation-type>

  <relation-type name="cited-by" reverse="cites"    default-retrieve='title,handle,authors:author/name'>
  </relation-type>
  <relation-type name="cites"    reverse="cited-by" default-retrieve='title,handle,authors:author/name'>
  </relation-type>
  
  <relation-type name='part-of' reverse='has-part'  default-retrieve='nothing'>
    <view name='extended' retrieve='name,title,type,handle' />
  </relation-type>

  <relation-type name='has-part'  reverse='part-of' default-retrieve='nothing'>
    <view name='extended' retrieve='id' />
  </relation-type>
  
  <relation-type name='has-shortid'         default-retrieve='id' />  <!-- reverse='is-shortid-of' -->
  <relation-type name='classified-under'    default-retrieve='id,title' />
  <relation-type name='affiliated-with'     default-retrieve='title,location'/>

  <relation-type name="related" undirected="yes" default-retrieve="handle"/>

  <!--
      A table element configures an SQL table. 
      
      It only defines table structure and SQL details.
      
      What it does not define is mapping from template data to table
      records.
  -->

  <!-- a global objects table -->
  <table name='objects'>
    <field name='id'    sql-type="CHAR(250) NOT NULL PRIMARY KEY" />
    <field name='data'  sql-type='blob' />
  </table>


  <use-perl-module>ARDB::ReDIF::Processing</use-perl-module>

  <!-- ReDIF-Person 1.0 records we don't need to process.  We
       already have acis-record-person, which hold the same
       data. -->

<!-- ReDIF-Institution 1.0 processing -->
  
<!-- institutions table -->

<table name='institutions'>
    <field name='id'       sql-type="VARCHAR(200) NOT NULL PRIMARY KEY" />
    <field name='name'     sql-type="VARCHAR(255) NOT NULL" />
    <field name='location' sql-type="VARCHAR(200)" />
    <field name='data'     sql-type="BLOB NOT NULL" />

    <create-table-sql>
      FULLTEXT INDEX ( name ),
      FULLTEXT INDEX ( location )
    </create-table-sql>
</table>

<field-attribute-mapping name="institution_obj">
     <field-associations
       name="name"
       name_en="name-en"
       email="primary/email,secondary/email,tertiary/email"
       postal="primary/postal,secondary/postal"
       phone='primary/phone,secondary/phone'
       fax="primary/fax,secondary/fax"
       homepage="primary/homepage,secondary/homepage,tertiary/homepage"
       location="primary/location,secondary/location"
       id="handle"
       />
</field-attribute-mapping>


<put-processing record-type='ReDIF-Institution 1.0'>
  <call-perl-function name='ARDB::ReDIF::Processing::process_institution' />
  <call-perl-function name='ARDB::ReDIF::Processing::extract_part_of_relationships' />
</put-processing>

<delete-processing record-type="ReDIF-Institution 1.0">
  <delete-from-table table='institutions' by='id'/>
</delete-processing>



<!-- ReDIF document template-types -->

<table name="resources"> 
        <field name="id"       sql-type=" CHAR(255) NOT NULL PRIMARY KEY" />
        <field name="sid"      sql-type=" CHAR(15) NOT NULL" />
        <field name="type"     sql-type=" CHAR(20) NOT NULL" />
        <field name="title"    sql-type=" VARCHAR(255) NOT NULL"/>
        <field name="authors"  sql-type=" text"/>
        <field name="urlabout" sql-type=" text"/>
        <field name="classif"  sql-type=" CHAR(50)" />

        <field name='location' sql-type=' TEXT'/> 
        <!-- synthetic string containg some other details of
             the document, see doc/citations.html -->

        <create-table-sql>
          FULLTEXT INDEX title_ft ( title ),
          INDEX sid_i ( sid )
        </create-table-sql>
</table>


 <!--  3rd generation authors/editors/... data -->

 <table name='res_creators_bulk'>
   <field name='sid'    sql-type="CHAR(12) NOT NULL" />
   <field name='role'   sql-type='char(15) NOT NULL' />
   <field name='names'  sql-type='VARCHAR(255) NOT NULL'/>

   <create-table-sql>
     PRIMARY KEY ( sid, role ),
     FULLTEXT INDEX creatorsft ( names ),
     index( role(5) )
   </create-table-sql>
 </table>

 <table name='res_creators_separate'>
   <field name='sid'   sql-type="CHAR(12) NOT NULL" />
   <field name='role'  sql-type="char(15) NOT NULL" />
   <field name='name'  sql-type="VARCHAR(255) NOT NULL" />   
   <field name='email' sql-type="VARCHAR(100) " />

   <create-table-sql>
     PRIMARY KEY ( sid, role, name ),
     INDEX( name ),
     fulltext index creatorsft(name),
     INDEX( email(10) )
   </create-table-sql>
 </table>

 <put-processing record-type='ReDIF-Series 1.0,ReDIF-Paper 1.0,ReDIF-Article 1.0,ReDIF-Book 1.0,ReDIF-Chapter 1.0,ReDIF-Software 1.0'>
   <call-perl-function name='ARDB::ReDIF::Processing::process_resource' />
   <call-perl-function name='ARDB::ReDIF::Processing::extract_part_of_relationships' />
 </put-processing>

 <delete-processing 
     record-type=
     'ReDIF-Series 1.0,ReDIF-Paper 1.0,ReDIF-Article 1.0,ReDIF-Book 1.0,ReDIF-Chapter 1.0,ReDIF-Software 1.0,paper,article,book,chapter,software,series'>
   <call-perl-function name='ARDB::ReDIF::Processing::process_resource_lost' />
   <delete-from-table table='resources' by='id'/>
 </delete-processing>


 <!-- end -->



 <!-- ============================================================
        A M F  
      ============================================================  -->


 <use-perl-module>ARDB::AMF::Processing</use-perl-module>
 

 <put-processing record-type='collection,text,organization'>
   <call-perl-function name='ARDB::AMF::Processing::prepare' />
 </put-processing>

 <put-processing record-type='organization'>
   <call-perl-function name='ARDB::AMF::Processing::process_organization' />
 </put-processing>
 
 <delete-processing record-type="organization">
   <delete-from-table table='institutions' by='id'/>
 </delete-processing>
 
 <put-processing record-type='text'>
    <call-perl-function name='ARDB::AMF::Processing::process_text' />
 </put-processing>

 <delete-processing record-type='text'>
   <call-perl-function name='ARDB::AMF::Processing::process_text_lost' />
   <delete-from-table table='resources' by='id'/>
 </delete-processing>

 <put-processing record-type='collection'>
    <call-perl-function name='ARDB::AMF::Processing::process_collection' />
 </put-processing>

 <put-processing record-type='collection,text,organization'>
    <call-perl-function name='ARDB::AMF::Processing::extract_part_of_relationships' />
 </put-processing>


 <!-- adding ReDIF archives for completeness and for RAS' meta/update -->

<put-processing record-type="ReDIF-Archive 1.0">
</put-processing>

<delete-processing record-type="ReDIF-Archive 1.0">
</delete-processing>




  <!-- ACIS tables and internal processing -->


  <perl-module name='ARDB::Plugin::Processing::ACIS_UD'/>
  <database alias='acis'/>

  <!--  ############    R E C O R D S    ##################   -->
 
  <table name='acis:records'>
  
    <field name='shortid'   sql-type=' char(10) not null primary key '/>
    <field name='id'        sql-type=' char(130) not null '/>
    <field name='owner'     sql-type=' char(110) not null '/>
    <field name='userdata_file'   
                            sql-type=' char(200) binary not null'/>
    <field name='namelast'  sql-type=' char(70) not null' />
    <field name='namefull'  sql-type=' char(70) not null'/>
    <field name='profile_url' 
                            sql-type='char(100) binary not null default ""'/>
    <field name='homepage'  sql-type='char(130) binary not null default ""'/>
    <field name='emailmd5'  sql-type='char(16) binary not null default ""'/>
   
<create-table-sql>
 index( id ), 
 index( namelast ), 
 index emailmd5_i( emailmd5 )
</create-table-sql>
    
  </table>

  <table name='acis:names'>
    <field name='shortid'   sql-type=' char(10) not null ' />
    <field name='name'      sql-type=' char(255) not null ' />
    <field name='probability' 
                            sql-type='tinyint unsigned not null' />
    <create-table-sql>PRIMARY KEY (shortid, name),
    index namesindex(name)</create-table-sql>

  </table>


  <put-processing record-type='acis-record-person'>

    <store-to-table table='acis:records'>
      <field-attribute-mapping>
        <field-associations
          shortid='sid'
          id='id'
          namelast='ARDB::Plugin::Processing::ACIS_UD::get_name_last'
          namefull='name/full'
          homepage='contact/homepage'
          owner='LOGIN' 
          userdata_file='FILENAME'
          profile_url='profile/url'
          emailmd5='ARDB::Plugin::Processing::ACIS_UD::get_emailmd5'
          />
      </field-attribute-mapping>
    </store-to-table>

    <!-- There is also additional record processing by the plugin
         itself.  See ARDB::Plugin::Processing::ACIS_UD::process_record.  -->

    <build-forward-relation type="affiliated-with" attributes="affiliations"   />
    <build-forward-relation type="reject"          attributes="contributions/refused/id" />
    <build-forward-relation type="accept"          attributes="contributions/accepted/id"/>

  </put-processing>



  <delete-processing record-type='acis-record-person'>
    <delete-from-table table='acis:records' by='id' />
    <call-perl-function name='ARDB::Plugin::Processing::ACIS_UD::record_delete_cleanup' />
    <!--
      <delete-from-table table='acis:names'   by='id' />
    -->
  </delete-processing>



  <!--  ############    U S E R S    ##################   -->


  <table name='acis:users'>
    <field name='login'    sql-type=' varchar(255) not null primary key ' />
    <field name='name'     sql-type=' varchar(255)' />
    <field name='password' sql-type=' char(20) not null '/>
    <field name='userdata_file'
                           sql-type=' char(200) not null ' />
  </table>
  
  <put-processing record-type='acis-user'>
    <store-to-table table='acis:users'>
      <field-attribute-mapping>
        <field-associations
          login='login' 
          name ='name'
          password='password'
          userdata_file='FILENAME'/>
      </field-attribute-mapping>
    </store-to-table>
  </put-processing>

  <delete-processing record-type='acis-user'>
    <delete-from-table table='acis:users' by='login' />
  </delete-processing>



  <!-- #############  SYSTEM'S PROFILES  ################ -->

  <!-- ACIS::Web::SysProf module                          -->

  <table name='acis:sysprof'>
  
    <field name='id'       sql-type=' VARCHAR(255) NOT NULL' />
    <field name='param'    sql-type=' VARCHAR(255) NOT NULL' />
    <field name='data'     sql-type=' BLOB' />
                       
    <create-table-sql> PRIMARY KEY ( id, param )</create-table-sql>

  </table>



  <!--  ########  OTHER SPECIAL ACIS TABLES   ########  -->


  <table name='acis:threads'>
    <field name='psid'      sql-type="CHAR(10) NOT NULL"/>
    <field name='type'      sql-type="CHAR(15) NOT NULL"/>
    <field name='started'   sql-type='DATETIME NOT NULL'/>
    <field name='checkpoint' sql-type='DATETIME'/>
    <create-table-sql> PRIMARY KEY(psid, type)</create-table-sql>
  </table>

  <!-- research profile suggestions -->
  <table name="acis:rp_suggestions">
    <field name="psid"     sql-type="CHAR(15) NOT NULL"/>
    <field name="dsid"     sql-type="CHAR(15) NOT NULL"/>
    <field name="role"     sql-type="CHAR(15) NOT NULL"/><!-- not actually used -->
    <field name="reason"   sql-type="CHAR(30) NOT NULL"/>
    <field name='time'     sql-type='DATETIME NOT NULL'/>
    <create-table-sql> PRIMARY KEY(psid, dsid) </create-table-sql>
  </table>


  <table name='acis:events'>
    <field name='date'  sql-type='datetime not null' />
    <field name='type'  sql-type='varchar(10)' />
           <!-- error, notice, warning -->
    <field name='class' sql-type='varchar(20)' /> 
           <!-- authenticate, session, contributions, ... -->
    <field name='action' sql-type='varchar(30)'/>         
    <field name='descr' sql-type='text'/>
    <field name='data'  sql-type='text'/>
<!--
    <field name='login' sql-type='varchar(100)' />
    <field name='url'   sql-type='varchar(200)' />
    <field name='file'  sql-type='varchar(200)' />
-->
    <field name='chain'    sql-type='char(16)'/><!-- session id -->
    <field name='startend' sql-type='tinyint'/><!-- 1 is session start, -1 is session end -->
    <field name='packed'   sql-type='mediumblob'/>
    <create-table-sql line='index( date, chain )'/>
  </table>    

  <table name='acis:session_history'>
    <field name='date'  sql-type='datetime not null' />
    <field name='sessionid' sql-type='char(16) not null' />
    <field name='login' sql-type='varchar(100) not null' />
    <field name='type'  sql-type='varchar(10) not null' />
    <field name='act'   sql-type='enum("start","stop","discard") not null' />
    <create-table-sql line='primary key(date,sessionid,act), index(login,type)'/>
  </table>



  <!-- APU Queue -->
  
  <table name="acis:apu_queue">
    <field name="what"     sql-type="CHAR(255) PRIMARY KEY"/>
    <field name='position' sql-type='BIGINT DEFAULT 0'/>
    <field name="filed"    sql-type="TIMESTAMP NOT NULL DEFAULT NOW()"/>
                   <!-- this is also default behaviour for the first 
                        timestamp-type field in a table in MySQL -->

    <field name="status"   sql-type="CHAR(20) DEFAULT ''"/>
    <field name="class"    sql-type="SMALLINT DEFAULT 0"/>
                   <!-- maybe we don't really need it
                        anymore and can use position instead: all
                        priority items can have lesser position?  On the
                        other side, class can be used for urgency indicator. -->

    <field name='notes'    sql-type='BLOB'/>
    <field name="worked"   sql-type="TIMESTAMP"/>
    
    <create-table-sql>
     index( position ), index( class ), index( status )
    </create-table-sql>
  </table>

<!-- old:
  <table name="acis:arpm_queue">
    <field name="what"     sql-type="CHAR(100) PRIMARY KEY"/>
    <field name="filed"    sql-type="TIMESTAMP NOT NULL"/>
    <field name="status"   sql-type="CHAR(20)"/>
    <field name="class"    sql-type="SMALLINT"/>
    <field name='notes'    sql-type='BLOB'/>
    <field name="worked"   sql-type="TIMESTAMP"/>
    
    <create-table-sql>
     index( class ), index( status )
    </create-table-sql>
  </table>  -->



  <!-- Stage C: Citations -->

  <table name='acis:citations'>
    <field name='cnid'            sql-type='SERIAL'/> <!-- BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE -->
    <field name='clid'            sql-type='CHAR(38) BINARY NOT NULL'/>
    <field name='srcdocsid'       sql-type='CHAR(15) NOT NULL'/>
    <field name='ostring'         sql-type='TEXT NOT NULL'/>
    <field name='nstring'         sql-type='VARCHAR(255) NOT NULL'/>
    <field name='trgdocid'        sql-type='VARCHAR(255)'/>
    <field name='moretrgdocids'   sql-type='TEXT NULL'/>
    

    <create-table-sql> PRIMARY KEY (clid),
    FULLTEXT INDEX (nstring),
    INDEX (trgdocid)</create-table-sql>
  </table>

  <table name='acis:citations_deleted'>
    <field name='cnid'            sql-type='BIGINT UNSIGNED NOT NULL UNIQUE'/> <!-- a backup for citations.cnid -->
    <field name='clid'            sql-type='CHAR(38) BINARY NOT NULL PRIMARY KEY'/>
  </table>

  <!-- history of citations -->
  <table name='acis:citation_events'>
    <field name='cnid'           sql-type='BIGINT UNSIGNED NOT NULL'/>
    <field name='psid'           sql-type='CHAR(15) NOT NULL'/>
    <field name='dsid'           sql-type='CHAR(15)'/>
    <field name='event'          sql-type='CHAR(15) NOT NULL'/>
    <field name='reason'         sql-type='char(15)'/>
    <field name='time'           sql-type='DATETIME NOT NULL'/>
    <field name='note'           sql-type='text'/>
    <create-table-sql>
      INDEX(time), INDEX(psid)
    </create-table-sql>
  </table>

  <table name='acis:cit_doc_similarity'>
    <field name='cnid'    sql-type='BIGINT UNSIGNED NOT NULL'/>
    <field name='dsid'    sql-type='CHAR(15) NOT NULL'/>
    <field name='similar' sql-type='TINYINT NOT NULL'/>
    <field name='time'    sql-type='DATE NOT NULL'/>
    <create-table-sql>PRIMARY KEY (cnid,dsid), INDEX docind (dsid)</create-table-sql>
  </table>

  <table name='acis:cit_sug'>
    <field name='cnid'   sql-type='BIGINT UNSIGNED NOT NULL'/>
    <field name='dsid'   sql-type='CHAR(15) NOT NULL'/>
    <field name='reason' sql-type='CHAR(20) NOT NULL'/>
    <field name='time'   sql-type='DATETIME NOT NULL'/>
    <create-table-sql> PRIMARY KEY (cnid,dsid,reason), INDEX docind (dsid)</create-table-sql>
  </table>

  <table name='acis:cit_old_sug'>
     <field name='psid'  sql-type='CHAR(15) NOT NULL'/>
     <field name='dsid'  sql-type='CHAR(15) NOT NULL'/>
     <field name='cnid' sql-type='BIGINT UNSIGNED NOT NULL'/>
     <create-table-sql> PRIMARY KEY (psid,dsid,cnid) </create-table-sql>
  </table>


  <!-- stage d: full-text links recognition -->

  <table name='acis:ft_urls'><!-- input data: full-text URLs for documents -->
    <field name='dsid'     sql-type='char(15) not null'/>
    <field name='url'      sql-type='blob not null'/>
    <field name='checksum' sql-type='char(16) binary not null'/>
    <field name='nature'   sql-type="ENUM('authoritative','automatic') not null"/>
    <field name='source'   sql-type='varchar(255) not null'/>
    <create-table-sql> PRIMARY KEY(dsid,checksum,source), index url_i(url(30)), index source_i(source(50))</create-table-sql>
  </table>

  <table name='acis:ft_urls_choices'><!-- users' choices about full-text URLs -->
    <field name='dsid'     sql-type='char(15) not null'/>
    <field name='checksum' sql-type='char(16) binary not null'/>
    <field name='psid'     sql-type='char(15) not null'/>
    <field name='choice'   sql-type='char(2) NOT NULL'/>
    <!-- above: first char: d|y|r|n (corresponding menu items:
         2|4|3|1).  second char: y|c|n (1|2|3) -->
    <field name='time' sql-type='datetime not null'/>
    <create-table-sql> primary key prim(dsid, checksum, psid), index t_i(time), index psid_i(psid) </create-table-sql>
  </table>

</configuration>





