<?xml version="1.0" encoding="UTF-8"?>
<!-- DOCTYPE application PUBLIC "-//JOURNEYMAN//DTD ADL 1.4.1//EN"
"http://www.journeyman.cc/adl/stable/adl/schemas/adl-1.4.1.dtd" -->
<application xmlns="http://bowyer.journeyman.cc/adl/1.4.1/" xmlns:adl="http://bowyer.journeyman.cc/adl/1.4.1/" name="youyesyet" version="0.1.1">
  <!--
    ***************************************************************************
    *
    *   Application Description Language Framework
    *
    *	THIS FILE IS AUTOMATICALLY GENERATED AND SHOULD NOT
    *	BE MANUALLY EDITED.
    *
    *   Generated using adl2canonical.xslt 1.10 $
	  *
	  ***************************************************************************
			-->
  <documentation>
    A web-app intended to be used by canvassers campaigning for a 'Yes' vote in the second independence referendum.

    The web-app will be delivered to canvassers out knocking doors primarily through an HTML5/React single-page app designed to work on a mobile phone; it's possible that someone else may do an Android of iPhone native app to address the same back end but at present I have no plans for this.

    There must also be an administrative interface through which privileged users can set the system up and authorise canvassers, and a 'followup' interface through which issue-expert specialist canvassers can address particular electors' queries.
  </documentation>
  <content>
    <head> </head>
    <top> </top>
    <foot> </foot>
  </content>
  <typedef name="postcode" type="string" pattern="^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([AZa-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))[0-9][A-Za-z]{2})$" size="16">
    <documentation>See
      https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/488478/Bulk_Data_Transfer_-_additional_validation_valid_from_12_November_2015.pdf,
      section 3</documentation>
    <help locale="en-GB">A valid postcode.</help>
  </typedef>
  <group name="public">
    <documentation>All users</documentation>
  </group>
  <group name="canvassers" parent="public">
    <documentation>All users of the canvasser app Able to read and add canvassing data in a limited
      radius around their current position. </documentation>
  </group>
  <group name="teamorganiser" parent="canvassers">
    <documentation>Organisers of canvassing teams Able to see and modify data on the canvassers in
      the team(s) they organise; able to add canvassers to their team; able to update canvassers in
      their team, including resetting passwords and locking accounts; able to see canvass data over
      the whole area in which their team operates. </documentation>
  </group>
  <group name="issueexperts" parent="public">
    <documentation>People expert on particular issues. Able to read followup requests, and the electors to which they
      relate; able to access (read/write) the issues wiki; able to write followuop action records.
    </documentation>
  </group>
  <group name="analysts" parent="public">
    <documentation>Users entitled to see an overview of the canvassing data collected. Able to read canvassing data over the whole map, including historical
      data.</documentation>
  </group>
  <group name="issueeditors" parent="analysts">
    <documentation>Users responsible for determining what issues should be current at any time.
      Able to set current issues; able to add issues.</documentation>
  </group>
  <group name="admin" parent="public">
    <documentation>Able to read and update canvasser records, team membership records, team
      organisership records, issue expertise records; able to add and update reference data
      generally.</documentation>
  </group>
  <!--
			entity electors already has a key - not generating one
		-->
  <entity table="electors" name="electors" magnitude="6">
    <key>
      <property required="true" type="integer" name="id" column="id" immutable="true" distinct="system">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
    <property size="64" required="true" type="string" name="name" column="name" distinct="user">
      <prompt prompt="name" locale="en-GB"/>
    </property>
    <property required="true" type="entity" name="dwelling_id" column="dwelling_id" entity="dwelling" farkey="id">
      <prompt prompt="Flat" locale="en-GB"/>
    </property>
    <property size="16" type="string" name="phone" column="phone" distinct="user">
      <prompt prompt="phone" locale="en-GB"/>
    </property>
    <property size="128" type="string" name="email" column="email" distinct="user">
      <prompt prompt="email" locale="en-GB"/>
    </property>
    <property name="gender" type="entity" column="gender" entity="genders" farkey="id" default="Unknown">
      <prompt prompt="gender" locale="en-GB"/>
    </property>
    <list properties="listed" name="Electors"><field property="id"/><field property="name"/><field property="dwelling_id"/><field property="phone"/><field property="email"/><field property="gender"/></list>
    <form properties="listed" name="Elector"><field property="id"/><field property="name"/><field property="dwelling_id"/><field property="phone"/><field property="email"/><field property="gender"/></form>
  </entity>
  <entity table="genders" name="genders" natural-key="id" magnitude="1">
    <key>
      <property name="id" type="string" size="32" distinct="all">
        <prompt prompt="gender" locale="en-GB"/>
      </property>
    </key>
    <permission permission="none" group="public"/>
    <permission permission="none" group="canvassers"/>
    <permission permission="none" group="teamorganiser"/>
    <permission permission="none" group="issueexperts"/>
    <permission permission="none" group="analysts"/>
    <permission permission="none" group="issueeditors"/>
    <permission permission="none" group="admin"/>
    <list properties="listed" name="Genders">
      <field property="id"/>
    </list>
    <form properties="listed" name="Gender">
      <field property="id"/>
    </form>
  </entity>
  <!--
			entity dwellings already has a key - not generating one
		-->
  <entity table="dwellings" name="dwellings" magnitude="6">
    <key>
      <property required="true" type="integer" name="id" column="id" immutable="true" distinct="system">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
    <property required="true" type="entity" name="address_id" column="address_id" entity="address" farkey="id">
      <prompt prompt="Building Address" locale="en-GB"/>
    </property>
    <property required="false" type="string" size="32" name="sub-address"/>
  </entity>
  <!--
			entity addresses already has a key - not generating one
		-->
  <entity table="addresses" name="addresses" magnitude="6">
    <key>
      <property required="true" type="integer" name="id" column="id" immutable="true" distinct="system">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
    <property required="true" type="string" name="address" column="address" size="256" distinct="user">
      <prompt prompt="address" locale="en-GB"/>
    </property>
    <property type="defined" typedef="postcode" name="postcode" column="postcode" size="16" distinct="user">
      <prompt prompt="postcode" locale="en-GB"/>
    </property>
    <property type="string" name="phone" column="phone" size="16">
      <prompt prompt="phone" locale="en-GB"/>
    </property>
    <property type="entity" name="district_id" column="district_id" entity="districts" farkey="id">
      <prompt prompt="district_id" locale="en-GB"/>
    </property>
    <property type="real" name="latitude" column="latitude">
      <prompt prompt="latitude" locale="en-GB"/>
    </property>
    <property type="real" name="longitude" column="longitude">
      <prompt prompt="longitude" locale="en-GB"/>
    </property>
    <permission group="admin" permission="all"/>
    <permission group="canvassers" permission="read"/>
    <permission group="analysts" permission="read"/>
    <list properties="listed" name="Addresses"><field property="id"/><field property="address"/><field property="postcode"/><field property="phone"/><field property="district_id"/><field property="latitude"/><field property="longitude"/></list>
    <form properties="listed" name="Address"><field property="id"/><field property="address"/><field property="postcode"/><field property="phone"/><field property="district_id"/><field property="latitude"/><field property="longitude"/></form>
  </entity>
  <!--
			entity visits already has a key - not generating one
		-->
  <entity table="visits" name="visits" magnitude="7">
    <key>
      <property required="true" type="integer" name="id" column="id" distinct="system">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
    <property required="true" type="integer" name="address_id" column="address_id" entity="addresses" farkey="id">
      <prompt prompt="address_id" locale="en-GB"/>
    </property>
    <property required="true" type="entity" name="canvasser_id" column="canvasser_id" entity="canvassers" farkey="id">
      <prompt prompt="canvasser_id" locale="en-GB"/>
    </property>
    <property required="true" default="" type="timestamp" name="date" column="date">
      <prompt prompt="date" locale="en-GB"/>
    </property>
    <permission group="public" permission="read"/>
    <permission group="canvassers" permission="insert"/>
  </entity>
  <!--
			entity authorities already has a key - not generating one
		-->
  <entity table="authorities" name="authorities" magnitude="2">
    <key>
      <property required="true" type="string" name="id" column="id" size="32" distinct="all">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
  </entity>
  <!--
			entity issues already has a key - not generating one
		-->
  <entity table="issues" name="issues" magnitude="1">
    <documentation>Issues believed to be of interest to electors, about which they may have questions.</documentation>
    <key>
      <property required="true" type="string" name="id" column="id" size="32" immutable="true" distinct="all">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
    <property type="string" name="url" column="url" size="256">
      <prompt prompt="url" locale="en-GB"/>
    </property>
    <property name="current" type="boolean" default="true">
      <prompt prompt="Is current?" locale="en-GB"/>
    </property>
    <list properties="listed" name="Issues"><field property="id"/><field property="url"/><field property="current"/></list>
    <form properties="listed" name="Issue"><field property="id"/><field property="url"/><field property="current"/></form>
  </entity>
  <!--
			entity intentions has no key - generating one
		-->
  <entity magnitude="6" table="intentions" name="intentions">
    <documentation>Link table.</documentation>
    <key>
      <property type="integer" distinct="system" required="true" name="Id">
        <generator action="native"/>
        <documentation>
						Auto-generated abstract primary key
					</documentation>
      </property>
    </key>
    <property required="true" type="entity" entity="visits" farkey="id" name="visit_id" column="visit_id">
      <prompt prompt="visit_id" locale="en-GB"/>
    </property>
    <property required="true" type="entity" entity="electors" farkey="id" name="elector_id" column="elector_id">
      <prompt prompt="elector_id" locale="en-GB"/>
    </property>
    <property required="true" type="entity" entity="options" farkey="id" name="option_id" column="option_id">
      <prompt prompt="option_id" locale="en-GB"/>
    </property>
    <permission permission="none" group="public"/>
    <permission permission="none" group="canvassers"/>
    <permission permission="none" group="teamorganiser"/>
    <permission permission="none" group="issueexperts"/>
    <permission permission="none" group="analysts"/>
    <permission permission="none" group="issueeditors"/>
    <permission permission="none" group="admin"/>
  </entity>
  <!--
			entity canvassers already has a key - not generating one
		-->
  <entity table="canvassers" name="canvassers" magnitude="5">
    <documentation>Primary users of the system: those actually interviewing electors.</documentation>
    <key>
      <property type="integer" name="id" column="id" distinct="system" immutable="true">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
    <property required="true" type="string" name="username" column="username" size="32" distinct="all">
      <prompt prompt="username" locale="en-GB"/>
    </property>
    <property required="true" type="string" name="fullname" column="fullname" size="64" distinct="user">
      <prompt prompt="fullname" locale="en-GB"/>
    </property>
    <property type="entity" name="elector_id" column="elector_id" entity="electors" farkey="id">
      <prompt prompt="elector_id" locale="en-GB"/>
    </property>
    <property required="true" type="integer" name="address_id" column="address_id" entity="addresses" farkey="id">
      <prompt prompt="address_id" locale="en-GB"/>
    </property>
    <property type="string" name="phone" column="phone" size="16">
      <prompt prompt="phone" locale="en-GB"/>
    </property>
    <property type="string" name="email" column="email" size="128" distinct="user">
      <prompt prompt="email" locale="en-GB"/>
    </property>
    <property required="true" type="entity" name="authority_id" entity="authorities" farkey="id">
      <prompt prompt="authority_id" locale="en-GB"/>
    </property>
    <property type="boolean" name="authorised" column="authorised">
      <prompt prompt="authorised" locale="en-GB"/>
    </property>
    <permission group="canvassers" permission="edit">
      <documentation>But only their own record</documentation>
    </permission>
    <permission group="teamleaders" permission="edit">
      <documentation>But only canvassers in their own team.</documentation>
    </permission>
    <permission group="admin" permission="all">
      <documentation>All canvassers</documentation>
    </permission>
  </entity>
  <!--
			entity followuprequests already has a key - not generating one
		-->
  <entity table="followuprequests" name="followuprequests" magnitude="7">
    <documentation>Requests for a followup with an issue expert</documentation>
    <key>
      <property required="true" type="integer" name="id" column="id" distinct="system">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
    <property required="true" type="entity" name="elector_id" column="elector_id" entity="electors" farkey="id">
      <prompt prompt="elector_id" locale="en-GB"/>
    </property>
    <property required="true" type="entity" name="visit_id" column="visit_id" entity="visits" farkey="id">
      <prompt prompt="visit_id" locale="en-GB"/>
    </property>
    <property required="true" type="entity" name="issue_id" column="issue_id" entity="issues" farkey="id">
      <prompt prompt="issue_id" locale="en-GB"/>
    </property>
    <property required="true" type="entity" name="method_id" column="method_id" entity="followupmethods" farkey="id">
      <prompt prompt="method_id" locale="en-GB"/>
    </property>
  </entity>
  <!--
			entity rolememberships has no key - generating one
		-->
  <entity table="rolememberships" name="rolememberships" magnitude="6">
    <documentation>Link table</documentation>
    <key>
      <property type="integer" distinct="system" required="true" name="Id">
        <generator action="native"/>
        <documentation>
						Auto-generated abstract primary key
					</documentation>
      </property>
    </key>
    <property required="true" type="entity" entity="roles" farkey="id" name="role_id" column="role_id">
      <prompt prompt="role_id" locale="en-GB"/>
    </property>
    <property required="true" type="entity" entity="canvassers" farkey="id" name="canvasser_id" column="canvasser_id">
      <prompt prompt="canvasser_id" locale="en-GB"/>
    </property>
    <permission permission="none" group="public"/>
    <permission permission="none" group="canvassers"/>
    <permission permission="none" group="teamorganiser"/>
    <permission permission="none" group="issueexperts"/>
    <permission permission="none" group="analysts"/>
    <permission permission="none" group="issueeditors"/>
    <permission permission="none" group="admin"/>
  </entity>
  <!--
			entity roles already has a key - not generating one
		-->
  <entity table="roles" name="roles" magnitude="1">
    <documentation>A role (essentially, the same as a group, but application layer rather than database layer) of which a user may be a member.</documentation>
    <key>
      <property type="integer" name="id" column="id" immutable="true" distinct="system">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
    <property required="true" type="string" name="name" column="name" size="64" distinct="user" immutable="true">
      <prompt prompt="name" locale="en-GB"/>
    </property>
  </entity>
  <!--
			entity teams already has a key - not generating one
		-->
  <entity table="teams" name="teams" magnitude="4">
    <key>
      <property type="integer" name="id" column="id" distinct="system" immutable="true">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
    <property required="true" type="string" name="name" column="name" size="64" distinct="user">
      <prompt prompt="name" locale="en-GB"/>
    </property>
    <property required="true" type="entity" entity="districts" farkey="id" name="district_id" column="district_id">
      <prompt prompt="district_id" locale="en-GB"/>
    </property>
    <property type="real" name="latitude" column="latitude">
      <prompt prompt="latitude" locale="en-GB"/>
    </property>
    <property type="real" name="longitude" column="longitude">
      <prompt prompt="longitude" locale="en-GB"/>
    </property>
    <permission group="canvassers" permission="read"/>
    <permission group="groupleaders" permission="edit">
      <documentation>But only their own group(s)</documentation>
    </permission>
    <permission group="admin" permission="all">
      <documentation>All groups</documentation>
    </permission>
  </entity>
  <!--
			entity districts already has a key - not generating one
		-->
  <entity table="districts" name="districts" magnitude="4">
    <documentation>Electoral districts</documentation>
    <key>
      <property required="true" type="integer" name="id" column="id" immutable="true" distinct="system">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
    <property required="true" type="string" name="name" column="name" size="64" distinct="user">
      <prompt prompt="name" locale="en-GB"/>
    </property>
    <permission group="public" permission="read"/>
    <permission group="admin" permission="all"/>
  </entity>
  <!--
			entity teamorganiserships has no key - generating one
		-->
  <entity table="teamorganiserships" name="teamorganiserships" magnitude="4">
    <documentation>Link table</documentation>
    <key>
      <property type="integer" distinct="system" required="true" name="Id">
        <generator action="native"/>
        <documentation>
						Auto-generated abstract primary key
					</documentation>
      </property>
    </key>
    <property required="true" type="entity" entity="teams" farkey="id" name="team_id" column="team_id">
      <prompt prompt="team_id" locale="en-GB"/>
    </property>
    <property required="true" type="entity" entity="canvassers" farkey="id" name="canvasser_id" column="canvasser_id">
      <prompt prompt="canvasser_id" locale="en-GB"/>
    </property>
    <permission permission="none" group="public"/>
    <permission permission="none" group="canvassers"/>
    <permission permission="none" group="teamorganiser"/>
    <permission permission="none" group="issueexperts"/>
    <permission permission="none" group="analysts"/>
    <permission permission="none" group="issueeditors"/>
    <permission permission="none" group="admin"/>
  </entity>
  <!--
			entity followupactions already has a key - not generating one
		-->
  <entity table="followupactions" name="followupactions" magnitude="7">
    <documentation>Actions taken on followup requests.</documentation>
    <key>
      <property required="true" type="integer" name="id" column="id" distinct="system">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
    <property required="true" type="entity" name="request_id" column="request_id" entity="followuprequests" farkey="id">
      <prompt prompt="request_id" locale="en-GB"/>
    </property>
    <property required="true" type="integer" name="actor" column="actor" entity="canvassers" farkey="id">
      <prompt prompt="actor" locale="en-GB"/>
    </property>
    <property required="true" default="" type="timestamp" name="date" column="date">
      <prompt prompt="date" locale="en-GB"/>
    </property>
    <property type="text" name="notes" column="notes">
      <prompt prompt="notes" locale="en-GB"/>
    </property>
    <property type="boolean" name="closed" column="closed" default="false">
      <prompt prompt="closed" locale="en-GB"/>
    </property>
    <permission group="issueexperts" permission="insert"/>
    <permission group="canvassers" permission="read">
      <documentation>But only for electors in their immediate vicinity</documentation>
    </permission>
    <permission group="analysts" permission="read"/>
  </entity>
  <!--
			entity issueexpertise has no key - generating one
		-->
  <entity magnitude="6" table="issueexpertise" name="issueexpertise">
    <documentation>Link table</documentation>
    <key>
      <property type="integer" distinct="system" required="true" name="Id">
        <generator action="native"/>
        <documentation>
						Auto-generated abstract primary key
					</documentation>
      </property>
    </key>
    <property required="true" type="integer" name="canvasser_id" column="canvasser_id" entity="canvassers" farkey="id">
        <prompt prompt="canvasser_id" locale="en-GB"/>
      </property>
    <property required="true" type="entity" name="issue_id" column="issue_id" entity="issues" farkey="id">
      <prompt prompt="issue_id" locale="en-GB"/>
    </property>
    <property required="true" type="entity" name="method_id" column="method_id" entity="followupmethods" farkey="id">
      <prompt prompt="method_id" locale="en-GB"/>
    </property>
    <permission permission="none" group="public"/>
    <permission permission="none" group="canvassers"/>
    <permission permission="none" group="teamorganiser"/>
    <permission permission="none" group="issueexperts"/>
    <permission permission="none" group="analysts"/>
    <permission permission="none" group="issueeditors"/>
    <permission permission="none" group="admin"/>
  </entity>
  <!--
			entity options already has a key - not generating one
		-->
  <entity table="options" name="options" magnitude="1">
    <documentation>Options in the election or referendum being canvassed on</documentation>
    <key>
      <property required="true" type="string" name="id" column="id" size="32" immutable="true" distinct="all">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
  </entity>
  <!--
			entity teammemberships has no key - generating one
		-->
  <entity table="teammemberships" name="teammemberships" magnitude="5">
    <documentation>Link table</documentation>
    <key>
      <property type="integer" distinct="system" required="true" name="Id">
        <generator action="native"/>
        <documentation>
						Auto-generated abstract primary key
					</documentation>
      </property>
    </key>
    <property required="true" type="entity" entity="teams" farkey="id" name="team_id" column="team_id">
      <prompt prompt="team_id" locale="en-GB"/>
    </property>
    <property required="true" type="entity" entity="canvassers" farkey="id" name="canvasser_id" column="canvasser_id">
      <prompt prompt="canvasser_id" locale="en-GB"/>
    </property>
    <permission permission="none" group="public"/>
    <permission permission="none" group="canvassers"/>
    <permission permission="none" group="teamorganiser"/>
    <permission permission="none" group="issueexperts"/>
    <permission permission="none" group="analysts"/>
    <permission permission="none" group="issueeditors"/>
    <permission permission="none" group="admin"/>
  </entity>
  <!--
			entity followupmethods already has a key - not generating one
		-->
  <entity table="followupmethods" name="followupmethods" magnitude="1">
    <key>
      <property required="true" type="string" size="32" name="id" column="id" immutable="true" distinct="all">
        <prompt prompt="id" locale="en-GB"/>
      </property>
    </key>
  </entity>
</application>
