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

 The contents of this file are subject to the terms of the
 Common Development and Distribution License, Version 1.0 only
 (the "License"). You may not use this file except in compliance
 with the License.

 You can obtain a copy of the license at license/ESCIDOC.LICENSE
 or http://www.escidoc.de/license.
 See the License for the specific language governing permissions
 and limitations under the License.

 When distributing Covered Code, include this CDDL HEADER in each
 file and include the License file at license/ESCIDOC.LICENSE.
 If applicable, add the following below this CDDL HEADER, with the
 fields enclosed by brackets "[]" replaced with your own identifying
 information: Portions Copyright [yyyy] [name of copyright owner]

 CDDL HEADER END


 Copyright 2006-2010 Fachinformationszentrum Karlsruhe Gesellschaft
 für wissenschaftlich-technische Information mbH and Max-Planck-
 Gesellschaft zur Förderung der Wissenschaft e.V.
 All rights reserved. Use is subject to license terms.
-->
<!-- Validation Schema for publication items
	$Author: mfranke $
	$Revision: 120 $ -->
<?identification content-model="escidoc:persistent4" context="escidoc:148" metadata-version="1.0" version="0.1"?>

<iso:schema xmlns:iso="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2" schemaVersion="ISO19757-3" defaultPhase="default">
	
	<iso:ns prefix="item" uri="http://www.escidoc.de/schemas/item/0.3"/>
	<iso:ns prefix="escidocMetadataRecords" uri="http://www.escidoc.de/schemas/metadatarecords/0.3"/>
	<iso:ns prefix="dc" uri="http://purl.org/dc/elements/1.1/"/>
	<iso:ns prefix="dcterms" uri="http://purl.org/dc/terms/"/>
	<iso:ns prefix="escidocMetadataProfile" uri="http://escidoc.mpg.de/metadataprofile/schema/0.1/"/>
	<iso:ns prefix="escidoc" uri="http://purl.org/escidoc/metadata/terms/0.1/"/>
	<iso:ns prefix="escidocComponents" uri="http://www.escidoc.de/schemas/item/0.3/components"/>
	<iso:ns prefix="publication" uri="http://purl.org/escidoc/metadata/profiles/0.1/publication"/>
<iso:ns prefix="person" uri="http://purl.org/escidoc/metadata/profiles/0.1/person"/>
<iso:ns prefix="source" uri="http://purl.org/escidoc/metadata/profiles/0.1/source"/>
<iso:ns prefix="event" uri="http://purl.org/escidoc/metadata/profiles/0.1/event"/>
<iso:ns prefix="organization" uri="http://purl.org/escidoc/metadata/profiles/0.1/organization"/>
	<iso:ns prefix="xlink" uri="http://www.w3.org/1999/xlink"/>
	
	<!-- Validation points -->
	<iso:phase id="default">
		<iso:active pattern="publisher_name_required"/>
		<iso:active pattern="organization_name_required"/>
		<iso:active pattern="event_title_required"/>
		<iso:active pattern="source_title_required"/>
		<iso:active pattern="creator_role_required"/>
		<iso:active pattern="genre_required"/>
		<iso:active pattern="title_required"/>
		<iso:active pattern="creator_required"/>
		<iso:active pattern="correct_date_format"/>
		<iso:active pattern="component_data_required"/>
	</iso:phase>

	<iso:phase id="submit_item">
		<iso:active pattern="publisher_name_required"/>
		<iso:active pattern="organization_name_required"/>
		<iso:active pattern="event_title_required"/>
		<iso:active pattern="source_title_required"/>
		<iso:active pattern="creator_role_required"/>
		<iso:active pattern="genre_required"/>
		<iso:active pattern="title_required"/>
		<iso:active pattern="creator_required"/>
		<iso:active pattern="correct_date_format"/>
		<iso:active pattern="component_data_required"/>
		
		<iso:active pattern="date_required"/>
		<iso:active pattern="source_required"/>
		<iso:active pattern="review_method_required"/>
	</iso:phase>

	<iso:phase id="accept_item">
		<iso:active pattern="publisher_name_required"/>
		<iso:active pattern="organization_name_required"/>
		<iso:active pattern="event_title_required"/>
		<iso:active pattern="source_title_required"/>
		<iso:active pattern="creator_role_required"/>
		<iso:active pattern="genre_required"/>
		<iso:active pattern="title_required"/>
		<iso:active pattern="creator_required"/>
		<iso:active pattern="correct_date_format"/>
		<iso:active pattern="component_data_required"/>
		
		<iso:active pattern="date_required"/>
		<iso:active pattern="source_required"/>
		<iso:active pattern="review_method_required"/>
	</iso:phase>

	<!-- Validation rules -->
	
	<!-- Default rules -->
	 
	 <!-- if any fields at "Event" are filled, "Title" of the event has to be filled also. -->
	<iso:pattern name="event_title_required" id="event_title_required">
		<iso:rule context="event:event">
			<iso:assert test="dc:title != '' or not(* != '' or @xml:lang != '')">EventTitleNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>
	 
	 <!-- if any fields at "Source" are filled, "Title" of the source has to be filled also. -->
	<iso:pattern name="source_title_required" id="source_title_required">
		<iso:rule context="source:source">
			<iso:assert test="dc:title != '' or not(normalize-space(.) != '' or .//*/@* != '')">SourceTitleNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>
	 
	 <!-- if any fields at "P" are filled, "Title" of the source has to be filled also. -->
	<iso:pattern name="creator_role_required" id="creator_role_required">
		<iso:rule context="source:source">
			<iso:assert test="escidoc:creator/@role != '' or not(normalize-space(escidoc:creator) != '' or escidoc:creator//*/@* != '')">SourceCreatorRoleNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>
	
	<!-- Entered dates have to be in the format YYYY, YYYY-MM or YYYY-MM-DD -->
	<iso:pattern name="correct_date_format" id="correct_date_format">
		<!-- Publication dates -->
		<iso:rule context="dcterms:created|dcterms:modified|dcterms:issued|dcterms:dateAccepted|dcterms:dateSubmitted">
			<iso:assert test=". = '' or (matches(., '^\\d\\d\\d\\d(-\\d\\d){0,2}$') and substring(concat(., '-01-01'), 1, 10) castable as xs:date)">DateFormatIncorrect</iso:assert>
		</iso:rule>
		<!-- Event dates -->
		<iso:rule context="escidoc:start-date">
			<iso:assert test=". = '' or (matches(., '^\\d\\d\\d\\d(-\\d\\d){0,2}$') and substring(concat(., '-01-01'), 1, 10) castable as xs:date)">DateFormatIncorrect</iso:assert>
		</iso:rule>
		<iso:rule context="escidoc:end-date">
			<iso:assert test=". = '' or (matches(., '^\\d\\d\\d\\d(-\\d\\d){0,2}$') and substring(concat(., '-01-01'), 1, 10) castable as xs:date)">DateFormatIncorrect</iso:assert>
			<iso:assert test=". = '' or ../escidoc:start-date != ''">EndDateWithoutStartDate</iso:assert>
		</iso:rule>
	</iso:pattern>
	
	<!-- If a file is given, the filename is mandatory. -->
	<iso:pattern name="component_data_required" id="component_data_required">
		<iso:rule context="escidocComponents:component">
			<iso:assert test="not(escidocComponents:content/@xlink:href != '') or escidocComponents:properties/escidocComponents:file-name != ''">ComponentFileNameNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>

	<!-- If a file is given, the content type is mandatory. -->
	<iso:pattern name="component_data_required" id="component_data_required">
		<iso:rule context="escidocComponents:component">
			<iso:assert test="not(escidocComponents:content/@xlink:href != '') or escidocComponents:properties/escidocComponents:content-category != ''">ComponentContentCategoryNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>

	<!-- If a file is given, the mime type is mandatory. -->
	<iso:pattern name="component_data_required" id="component_data_required">
		<iso:rule context="escidocComponents:component">
			<iso:assert test="not(escidocComponents:content/@xlink:href != '') or escidocComponents:properties/escidocComponents:mime-type != ''">ComponentMimeTypeNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>

	<!-- If a file is given, the visibility is mandatory. -->
	<iso:pattern name="component_data_required" id="component_data_required">
		<iso:rule context="escidocComponents:component">
			<iso:assert test="not(escidocComponents:content/@xlink:href != '') or escidocComponents:properties/escidocComponents:visibility != ''">ComponentVisibilityNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>

	<!-- Validation point specific -->	
	
	<!-- Title is required -->
	<iso:pattern name="title_required" id="title_required">
		<iso:rule context="publication:publication">
			<iso:assert test="dc:title != ''">TitleNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>
	
	<!-- Genre is required -->
	<iso:pattern name="genre_required" id="genre_required">
		<iso:rule context="publication:publication">
			<iso:assert test="@type != ''">GenreNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>
	
	<!-- Genre must not be manuscript. -->
	<iso:pattern name="genre_constraint" id="genre_constraint">
		<iso:rule context="publication:publication">
			<iso:assert test="@type != 'manuscript'">GenreNotSuitable</iso:assert>
		</iso:rule>
	</iso:pattern>
	
	<!-- At least one creator with an organizational unit provided is required -->
	<iso:pattern name="creator_required" id="creator_required">
		<iso:rule context="publication:publication">
			<iso:assert test="escidoc:creator/person:person/escidoc:family-name != '' or escidoc:creator/organization:organization/dc:title != ''">CreatorNotProvided</iso:assert>
			<iso:assert test="escidoc:creator/@role != ''">CreatorRoleNotProvided</iso:assert>
			<iso:assert test="escidoc:creator/person:person/organization:organization/dc:title != '' or escidoc:creator/organization:organization/dc:title != ''">OrganizationalMetadataNotProvided</iso:assert>
		</iso:rule>
		<iso:rule context="publication:publication/escidoc:creator/person:person">
			<iso:assert test="escidoc:family-name != ''">CreatorFamilyNameNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>
	
	<!-- if "Publisher place" or "Publisher edition" is filled, "Publisher name" has to be filled also -->
	<iso:pattern name="publisher_name_required" id="publisher_name_required">
		<iso:rule context="escidoc:publishing-info">
			<iso:assert test="dc:publisher != '' or not(* != '')">PublisherNameNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>
	 
	<!-- if the field "Address of an Organization" within a creator of type "Person" is filled, "Name of the Organization" has to be filled also. -->
	<iso:pattern name="organization_name_required" id="organization_name_required">
		<iso:rule context="organization:organization">
			<iso:assert test="dc:title != '' or not(escidoc:address) or escidoc:address = ''">OrganizationNameNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>

	<!-- If genre is not equal to "Series" or "Journal" or "Other" or "Manuscript" at least one date has to be provided -->
	<iso:pattern name="date_required" id="date_required">
		<iso:rule context="publication:publication">
			<iso:assert test="(@type = 'series' or @type = 'journal' or @type = 'manuscript' or @type = 'other') or ((dcterms:created != '') or (dcterms:modified != '') or (dcterms:dateSubmitted != '') or (dcterms:dateAccepted != '') or (dcterms:issued != ''))">DateNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>
	
	<!-- If genre is equal to "Article", "Book Chapter" or "Conference Paper" at least one source has to be provided -->
	<iso:pattern name="source_required" id="source_required" flag="restrictive">
		<iso:rule context="publication:publication">
			<iso:assert test="not(@type = 'article' or @type = 'book-item' or @type = 'conference-paper') or (source:source/dc:title != '')">SourceNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>
	
	<!-- If a date of type "dcterms:dateIssued" is given, the ReviewType has to be provided -->
	<iso:pattern name="review_method_required" id="review_method_required">
		<iso:rule context="publication:publication">
			<iso:assert test="not(dcterms:issued != '') or (publication:review-method != '')">ReviewMethodNotProvided</iso:assert>
		</iso:rule>
	</iso:pattern>

</iso:schema>
