<commit_before><?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2015 <NAME>
    etdpub: https://github.com/ewg118/etdpub
    Apache License 2.0
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ev="http://www.w3.org/2001/xml-events"
	xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
	xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:exist="http://exist.sourceforge.net/NS/exist"
	xmlns:mods="http://www.loc.gov/mods/v3" xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<head>
		<title>etdpub Administration</title>
		<link rel="stylesheet" href="/fr/style/bootstrap/css/bootstrap.css" type="text/css" />
		<link rel="stylesheet" href="/fr/style/form-runner-bootstrap-override.css" type="text/css" />

		<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
		<script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
		<link rel="shortcut icon" href="/ops/images/orbeon-icon-16.ico" />
		<link rel="icon" href="/ops/images/orbeon-icon-16.png" type="image/png" />
		<link rel="stylesheet" href="/apps/etdpub/xforms/css/style.css" />

		<xforms:model>
			<xforms:instance id="control-instance" xxforms:exclude-result-prefixes="#all">
				<controls xmlns="">
					<id></id>
					<media_url></media_url>
					<stream_url></stream_url>
					<type></type>
					<template></template>
					<action></action>
					<working>false</working>
					<internetMediaType></internetMediaType>
					<interface></interface>
					<status></status>
					<crossref-api>https://test.crossref.org/servlet/deposit</crossref-api>
				</controls>
			</xforms:instance>

			<!-- exist URL is stored in an XML file -->
			<xforms:instance id="exist-config" xxforms:exclude-result-prefixes="#all">
				<xi:include href="../exist-config.xml"></xi:include>
			</xforms:instance>

			<!-- crossref authentication stored in XML file -->
			<xforms:instance id="crossref-config" xxforms:exclude-result-prefixes="#all">
				<xi:include href="../crossref-config.xml"></xi:include>
			</xforms:instance>

			<xforms:instance id="config" xxforms:exclude-result-prefixes="#all">
				<config></config>
			</xforms:instance>

			<xforms:instance id="config-template" xxforms:exclude-result-prefixes="#all">
				<config version="2017-08-01">
					<title>etdpub</title>
					<url>http://localhost:8080/orbeon/etdpub/</url>
					<xeac></xeac>
					<solr>
						<url>http://localhost:8080/solr/etdpub/</url>
						<rows>20</rows>
					</solr>
					<sparql>
						<update></update>
						<query></query>
						<store></store>
					</sparql>
					<ark enabled="false">
						<naan></naan>
					</ark>
					<crossref enabled="false">
						<depositor_name></depositor_name>
						<depositor_email></depositor_email>
						<doi_prefix></doi_prefix>
					</crossref>
					<logo></logo>
					<style>default</style>
					<geonames_api_key></geonames_api_key>
					<google_analytics></google_analytics>
					<absolute_path>/usr/local/projects/etdpub/</absolute_path>
				</config>
			</xforms:instance>

			<xforms:instance id="doc" xxforms:exclude-result-prefixes="#all">
				<xml xmlns=""></xml>
			</xforms:instance>

			<!-- instance templates -->
			<xforms:instance id="templates">
				<xi:include href="instances/templates.xml"></xi:include>
			</xforms:instance>

			<!-- xquery -->
			<xforms:instance id="eXist-xquery">
				<exist:query xmlns="">
					<exist:text></exist:text>
				</exist:query>
			</xforms:instance>

			<xforms:instance id="xqueries">
				<queries xmlns="">
					<query id="collection-count">&lt;report&gt;{count(collection())}&lt;/report&gt;</query>
					<query id="get-objects">
						<![CDATA[declare namespace mods="http://www.loc.gov/mods/v3";
						declare namespace tei="http://www.tei-c.org/ns/1.0";
						
						 <report> { for $record in collection() let
						 	$type := $record/*/local-name() return
						 	if ($type='modsCollection') then 
						 		<record>
							 		<id>{ data($record//mods:recordIdentifier) }</id>
							 		<title>{data($record//mods:mods/mods:titleInfo/mods:title) }</title>
							 		<author>{ string-join($record//mods:mods/mods:name/mods:namePart, ',') }</author>
							 		<date>{ if ($record//mods:dateIssued) then string-join($record//mods:dateIssued, '-') else data($record//descendant::mods:part/mods:date) }</date>
							 		<media_url>{ data($record//mods:location/mods:url) }</media_url>
							 		<internetMediaType>{data($record//mods:physicalDescription/mods:internetMediaType)}</internetMediaType>
							 		<type>MODS</type>
							 		<genre>{data($record//mods:mods/mods:genre)}</genre>
							 		<orcid>{if ($record//mods:name[mods:nameIdentifier[matches(., 'https?://orcid.org/[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[X0-9]{1}')]]) then true() else false()}</orcid>
							 		<doi>{data($record//mods:identifier[@type='DOI'])}</doi>
							 		<published>false</published>
						 		</record>
						 	else if ($type='TEI') then
							 	<record>
							 		<id>{ data($record/*[local-name()='TEI']/@xml:id) }</id>
							 		<title>{ data($record//tei:titleStmt/tei:title)}</title>
							 		<author>{string-join($record//tei:titleStmt/tei:author/tei:name, ', ')}</author>
							 		<date>{data($record//tei:publicationStmt/tei:date)}</date>
							 		<type>TEI</type>
							 		<orcid>{if ($record//tei:titleStmt/*[tei:idno[@type='URI'][matches(., 'https?://orcid.org/[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[X0-9]{1}')]]) then true() else false()}</orcid>
							 		<doi>{data($record//tei:fileDesc/tei:sourceDesc/tei:bibl[tei:idno[@type='DOI']]/tei:idno[@type='DOI'])}</doi>
							 		<published>false</published>
							 	</record>
							 else '' } 
						 </report>]]></query>
				</queries>
			</xforms:instance>

			<xforms:instance id="pagination-result">
				<exist:result></exist:result>
			</xforms:instance>

			<xforms:instance id="xquery-result">
				<exist:result></exist:result>
			</xforms:instance>

			<!-- file operations (for deleting the document from the filesystem -->
			<xforms:instance id="delete-config">
				<config xmlns="">
					<delete>
						<url></url>
					</delete>
				</config>
			</xforms:instance>

			<xforms:instance id="dump">
				<dump xmlns=""></dump>
			</xforms:instance>

			<!-- ***** Solr instances ***** -->
			<xforms:instance id="addIndex" xxforms:exclude-result-prefixes="#all">
				<add xmlns=""></add>
			</xforms:instance>

			<xforms:instance id="sendCommit" xxforms:exclude-result-prefixes="#all">
				<commit></commit>
			</xforms:instance>

			<!-- delete from Solr -->
			<xforms:instance id="deleteId" xxforms:exclude-result-prefixes="#all">
				<delete xmlns="">
					<query></query>
				</delete>
			</xforms:instance>

			<xforms:instance id="published-response">
				<response xmlns=""></response>
			</xforms:instance>

			<!-- DOI/Crossref templates -->
			<xforms:instance id="crossref" xxforms:exclude-result-prefixes="#all">
				<doi_batch xmlns=""></doi_batch>
			</xforms:instance>

			<xforms:instance id="crossref-form-data" xxforms:exclude-result-prefixes="#all">
				<formData xmlns="">
					<operation>doMDUpload</operation>
					<login_id></login_id>
					<login_passwd></login_passwd>
					<fname filename="" mediatype="" size=""></fname>
					<!--					<fname/>-->
				</formData>
			</xforms:instance>

			<xforms:instance id="save-crossref-config">
				<config xmlns="">
					<url></url>
					<content-type>text/plain</content-type>
					<make-directories>false</make-directories>
					<append>false</append>
				</config>
			</xforms:instance>

			<xforms:instance id="sourceDesc-template" xxforms:exclude-result-prefixes="#all">
				<sourceDesc xmlns="http://www.tei-c.org/ns/1.0"></sourceDesc>
			</xforms:instance>

			<xforms:instance id="tei-doi-template" xxforms:exclude-result-prefixes="#all">
				<bibl xmlns="http://www.tei-c.org/ns/1.0">
					<title>DOI</title>
					<idno type="DOI"></idno>
				</bibl>
			</xforms:instance>

			<xforms:instance id="mods-doi-template" xxforms:exclude-result-prefixes="#all">
				<identifier type="DOI" xmlns="http://www.loc.gov/mods/v3"></identifier>
			</xforms:instance>

			<!-- LOD CRUD instances -->
			<xforms:instance id="rdf" xxforms:exclude-result-prefixes="#all">
				<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"></rdf:RDF>
			</xforms:instance>

			<xforms:instance id="sparqlUpdate-template">
				<query><![CDATA[PREFIX rdf:	<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms:	<http://purl.org/dc/terms/>
PREFIX dcmitype:	<http://purl.org/dc/dcmitype/>
PREFIX oa:	<http://www.w3.org/ns/oa#>
PREFIX schema:	<http://schema.org/>
DELETE {?s ?p ?o} WHERE { 
{<URI> schema:exampleOfWork ?s . ?s ?p ?o }
UNION {<URI> dcterms:temporal ?s . ?s ?p ?o }
UNION { ?parts dcterms:source <URI> ; rdf:type dcmitype:Text . ?s oa:hasTarget ?parts . ?s ?p ?o }
UNION { ?s dcterms:source <URI> ; rdf:type dcmitype:Text . ?s ?p ?o }
UNION {<URI> ?p ?o . ?s ?p ?o . FILTER (?s = <URI>) }
}]]>
				</query>
			</xforms:instance>

			<xforms:instance id="sparqlUpdate">
				<query></query>
			</xforms:instance>

			<!-- ************* BINDINGS **************** -->
			<xforms:bind nodeset="instance('control-instance')">
				<xforms:bind nodeset="working" type="xs:boolean"></xforms:bind>
			</xforms:bind>

			<xforms:bind nodeset="instance('pagination-result')">
				<xforms:bind nodeset="//record">
					<xforms:bind nodeset="published" type="xs:boolean"></xforms:bind>
				</xforms:bind>
			</xforms:bind>

			<xforms:bind nodeset="instance('crossref-form-data')">
				<xforms:bind nodeset="fname" as="xs:anyURI"></xforms:bind>
			</xforms:bind>

			<!-- ************* SUBMISSIONS **************** -->
			<xforms:submission id="load-config" serialization="none" method="get" action="{instance('exist-config')/url}etdpub/config.xml" replace="instance" instance="config"
				xxforms:username="{instance('exist-config')/username}" xxforms:password="{instance('exist-config')/password}">
				<xforms:action ev:event="xforms-submit-done">
					<xforms:setvalue ref="instance('eXist-xquery')/exist:text" value="instance('xqueries')/query[@id='get-objects']"></xforms:setvalue>
					<xforms:send submission="xquery-pagination"></xforms:send>
				</xforms:action>
				<xforms:message ev:event="xforms-submit-error" level="modal">Error loading config from eXist database.</xforms:message>
			</xforms:submission>

			<!--***************** XQUERY ******************-->
			<!-- xquery for getting and processing query results into pages of items -->
			<xforms:submission id="xquery-pagination" ref="instance('eXist-xquery')" action="{instance('exist-config')/url}etdpub/records" method="post" replace="instance"
				instance="pagination-result" xxforms:username="{instance('exist-config')/username}" xxforms:password="{instance('exist-config')/password}">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error querying eXist database.</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<!--iterate through docs, check for publication -->
					<xforms:action xxforms:iterate="instance('pagination-result')//record">
						<xforms:var name="position" select="position()"></xforms:var>
						<xforms:setvalue ref="instance('control-instance')/id" value="context()/id"></xforms:setvalue>
						<xforms:send submission="query-solr-for-publication"></xforms:send>
					</xforms:action>
				</xforms:action>
			</xforms:submission>

			<xforms:submission id="xquery-collection" ref="instance('eXist-xquery')" action="{instance('exist-config')/url}etdpub/records" method="post" replace="instance"
				instance="xquery-result" xxforms:username="{instance('exist-config')/username}" xxforms:password="{instance('exist-config')/password}">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error querying eXist database.</xforms:message>
			</xforms:submission>

			<!--***************** EXIST-DB ******************-->
			<xforms:submission id="load-doc" serialization="none" method="get" action="{instance('exist-config')/url}etdpub/records/{instance('control-instance')/id}.xml"
				replace="instance" instance="doc" xxforms:username="{instance('exist-config')/username}" xxforms:password="{instance('exist-config')/password}">
				<xforms:message ev:event="xforms-submit-error" level="modal">Unable to load MODS or TEI record from eXist.</xforms:message>

				<!-- after load, insert the relevant template DOI template in either TEI or MODS -->
				<xforms:action ev:event="xforms-submit-done">
					<xforms:var name="doi" select="concat(instance('config')/crossref/doi_prefix, '/', instance('control-instance')/id)"></xforms:var>

					<xforms:action if="instance('doc')/namespace-uri()='http://www.loc.gov/mods/v3'">
						<xforms:insert context="instance('doc')//mods:mods" nodeset="./child::node()[last()]" origin="instance('mods-doi-template')"></xforms:insert>
						<xforms:setvalue ref="instance('doc')//mods:mods/mods:identifier[@type='DOI']" value="$doi"></xforms:setvalue>
					</xforms:action>
					<xforms:action if="instance('doc')/namespace-uri()='http://www.tei-c.org/ns/1.0'">
						<xforms:insert context="instance('doc')/tei:teiHeader/tei:fileDesc" nodeset="./child::node()[last()]" origin="instance('sourceDesc-template')"
							if="not(instance('doc')/tei:teiHeader/tei:fileDesc/tei:sourceDesc)"></xforms:insert>
						<xforms:insert context="instance('doc')/tei:teiHeader/tei:fileDesc/tei:sourceDesc" nodeset="./child::node()[last()]" origin="instance('tei-doi-template')"></xforms:insert>
						<xforms:setvalue ref="instance('doc')/tei:teiHeader/tei:fileDesc/tei:sourceDesc/tei:bibl[tei:idno[@type='DOI']]/tei:idno" value="$doi"></xforms:setvalue>
					</xforms:action>
					
					<!-- save the doc back to exist -->
					<xforms:send submission="save-doc"/>
				</xforms:action>
			</xforms:submission>

			<xforms:submission id="save-doc" ref="instance('doc')" action="{instance('exist-config')/url}etdpub/records/{instance('control-instance')/id}.xml" method="put"
				replace="none" xxforms:username="{instance('exist-config')/username}" xxforms:password="{instance('exist-config')/password}">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error Saving Document</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:setvalue ref="instance('control-instance')/status">Successfully saved record to eXist.</xforms:setvalue>

					<!-- only index the Document file for a MODS file that is not of the journal template -->
					<xforms:action if="instance('control-instance')/type='MODS'">
						<!-- first put the associated document, which then calls the MODS indexing afterwards -->
						<xforms:send submission="put-document" if="not(instance('control-instance')/template = 'journal')"></xforms:send>
					</xforms:action>
					<!-- otherwise, get the TEI-to-Solr document directly -->
					<xforms:action if="instance('control-instance')/type = 'TEI'">
						<xforms:send submission="to-solr"></xforms:send>
					</xforms:action>
					<!-- delete triples from triplestore, if applicable. Then re-post RDF document -->
					<xforms:action ev:event="xforms-submit-done" if="string(instance('config')/sparql/update) and string(instance('config')/sparql/store)">
						<xforms:var name="uri"
							select="if (instance('config')/ark/@enabled='true') then concat(instance('config')/url, 'ark:/', instance('config')/ark/naan, '/', instance('control-instance')/id) else concat(instance('config')/url, 'id/', instance('control-instance')/id)"></xforms:var>
						<xforms:setvalue ref="instance('sparqlUpdate')" value="replace(instance('sparqlUpdate-template'), 'URI', $uri)"></xforms:setvalue>
						<xforms:send submission="delete-graph"></xforms:send>
						<xforms:send submission="get-rdf"></xforms:send>
					</xforms:action>
				</xforms:action>
			</xforms:submission>

			<xforms:submission id="delete-doc" action="{instance('exist-config')/url}etdpub/records/{instance('control-instance')/id}.xml" method="delete" replace="none"
				xxforms:username="{instance('exist-config')/username}" xxforms:password="{instance('exist-config')/password}">
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('control-instance')/status">MODS/TEI document successfully deleted.</xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Error deleting document from eXist database.</xforms:message>
			</xforms:submission>

			<!--***************** CROSSREF ******************-->
			<!-- serialize MODS/TEI into Crossref XML -->
			<xforms:submission id="load-crossref" method="get" replace="instance" instance="crossref" serialization="none"
				resource="/etdpub/id/{instance('control-instance')/id}.xref">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error transforming record to Crossref XML document.</xforms:message>

				<xforms:action ev:event="xforms-submit-done">
					<!-- set crossref credentials for form data -->
					<xforms:setvalue ref="instance('crossref-form-data')/login_id" value="instance('crossref-config')/username"></xforms:setvalue>
					<xforms:setvalue ref="instance('crossref-form-data')/login_passwd" value="instance('crossref-config')/password"></xforms:setvalue>
					<xforms:setvalue ref="instance('crossref-form-data')/fname" value="concat(instance('control-instance')/id, '.xml')"></xforms:setvalue>

					<!-- serialize the instance XML into a file in /tmp -->
					<xforms:setvalue ref="instance('save-crossref-config')/url" value="concat('file:///tmp/',  instance('control-instance')/id, '.xml')"></xforms:setvalue>
					<xforms:insert nodeset="instance('dump')"
						origin="xxforms:call-xpl('oxf:/apps/etdpub/xpl/xforms/save-crossref.xpl', ('doc', 'configuration'), (instance('crossref'), instance('save-crossref-config')), 'data')"></xforms:insert>

					<!-- post data to Crossref API -->
					<xforms:send submission="post-crossref"></xforms:send>
				</xforms:action>
			</xforms:submission>

			<!-- POST to Crossref deposition API -->
			<!--<xforms:submission id="post-crossref" action="{instance('control-instance')/crossref-api}" ref="instance('crossref-form-data')" instance="crossref-form-data" replace="instance"
				method="form-data-post" serialization="multipart/form-data">
				<xforms:message ev:event="xforms-submit-error" level="modal" value="event('response-body')"></xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:message level="modal" value="event('response-body')"></xforms:message>
				</xforms:action>
			</xforms:submission>-->

			<!-- interact with PHP script in CGI to run multipart/form-data -->
			<xforms:submission id="post-crossref" serialization="none" method="get" action="/etdpub/admin/attach-metadata?file={instance('crossref-form-data')/fname}"
				instance="dump" replace="instance">
				<xforms:header>
					<xforms:name>User-Agent</xforms:name>
					<xforms:value>ETDPub/XForms</xforms:value>
				</xforms:header>
				<xforms:message ev:event="xforms-submit-error" level="modal" value="event('response-body')"></xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<!-- after success, load the doc, insert DOI, and save it -->
					<xforms:send submission="load-doc"/>
					
					<!-- set DOI in the pagination metadata in order to prevent re-submission -->
					<xforms:var name="doi" select="concat(instance('config')/crossref/doi_prefix, '/', instance('control-instance')/id)"></xforms:var>
					<xforms:setvalue ref="instance('pagination-result')//record[id = instance('control-instance')/id]/doi" value="$doi"/>
				</xforms:action>
			</xforms:submission>

			<!-- ************************* SOLR ************************** -->
			<xforms:submission id="to-solr" method="get" replace="instance" instance="addIndex" serialization="none" resource="/etdpub/id/{instance('control-instance')/id}.solr">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error transforming record to Solr document.</xforms:message>
				<xforms:send ev:event="xforms-submit-done" submission="post-solr-doc"></xforms:send>
			</xforms:submission>

			<xforms:submission id="post-solr-doc" action="{instance('config')/solr/url}update" ref="instance('addIndex')" instance="addIndex" replace="instance" method="post">
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr. Index may be offline or URL is incorrect.</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:send submission="submit-commit"></xforms:send>
				</xforms:action>
			</xforms:submission>

			<xforms:submission id="put-document" ref="instance('dump')" method="post" replace="none"
				resource="{instance('config')/solr/url}update/extract?literal.id={instance('control-instance')/id}&amp;stream.url={instance('control-instance')/stream_url}&amp;fmap.content=text&amp;fmap.date=timestamp&amp;commit=true">
				<xforms:header>
					<xforms:name>Content-type</xforms:name>
					<xforms:value ref="instance('control-instance')/internetMediaType"></xforms:value>
				</xforms:header>
				<xforms:setvalue ev:event="xforms-submit" ref="instance('control-instance')/working" value="true()"></xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Unable to index the document file.</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:setvalue ref="instance('control-instance')/status">Document successfully saved to Solr.</xforms:setvalue>
					<xforms:setvalue ref="instance('control-instance')/working" value="false()"></xforms:setvalue>
					<xforms:send submission="to-solr"></xforms:send>
				</xforms:action>
			</xforms:submission>

			<!-- delete from Solr -->
			<xforms:submission id="delete-solr-doc" action="{instance('config')/solr/url}update" ref="instance('deleteId')" instance="deleteId" replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"></xforms:send>
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr.</xforms:message>
			</xforms:submission>

			<!-- send commit -->
			<xforms:submission id="submit-commit" action="{instance('config')/solr/url}update" ref="instance('sendCommit')" instance="sendCommit" replace="none" method="post">
				<xforms:message ev:event="xforms-submit-error" level="modal">Solr commit failed.</xforms:message>
			</xforms:submission>

			<!-- evaluating whether a document is published -->
			<xforms:submission id="query-solr-for-publication" serialization="none" method="get"
				action="{instance('config')/solr/url}select/?q=id:{instance('control-instance')/id}&amp;rows=0&amp;facet=false" replace="instance" instance="published-response">
				<!-- if the document is found in solr, get the updated solr doc -->
				<xforms:action ev:event="xforms-submit-done">
					<xforms:setvalue if="instance('published-response')/result[@name='response']/@numFound = '1'"
						ref="instance('pagination-result')//record[id=instance('control-instance')/id]/published" value="true()"></xforms:setvalue>
				</xforms:action>
			</xforms:submission>

			<!--********************** SPARQL SUBMISSIONS **********************-->
			<xforms:submission id="get-rdf" serialization="none" method="get" action="/etdpub/id/{instance('control-instance')/id}.rdf" replace="instance" instance="rdf">
				<xforms:message ev:event="xforms-submit-error" level="modal">Unable to get RDF/XML serialization.</xforms:message>
				<xforms:send submission="post-rdf" ev:event="xforms-submit-done"></xforms:send>
			</xforms:submission>

			<xforms:submission id="delete-graph" action="{instance('config')/sparql/update}" ref="instance('sparqlUpdate')" serialization="text/plain" replace="none" method="post"
				mediatype="application/sparql-update">
				<xforms:message level="modal" ev:event="xforms-submit-error">SPARQL update failed.</xforms:message>
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('control-instance')/status">Object has been removed from triplestore.</xforms:setvalue>
			</xforms:submission>

			<xforms:submission id="post-rdf" action="{instance('config')/sparql/store}?default" ref="instance('rdf')" replace="none" method="post" mediatype="application/rdf+xml">
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('control-instance')/status">Successfully posted to endpoint.</xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Post to endpoint failed.</xforms:message>
			</xforms:submission>

			<!-- ******************* XFORMS-MODEL-CONSTRUCT-DONE **********************-->
			<xforms:action ev:event="xforms-model-construct-done">
				<xforms:send submission="load-config"></xforms:send>
			</xforms:action>
		</xforms:model>
	</head>

	<body>
		<xforms:var name="display_path"></xforms:var>
		<div class="container-fluid">
			<div class="row">
				<div class="col-md-12">
					<div id="form">
						<!-- progress/status boxes -->
						<xforms:group ref=".[instance('control-instance')/working=true()]">
							<div class="bg-info alert-box">
								<span class="glyphicon glyphicon-info-sign"></span>
								<strong>Working:</strong> Indexing document...</div>
						</xforms:group>
						<xforms:group ref=".[string-length(instance('control-instance')/status) &gt; 0]">
							<div class="bg-info alert-box">
								<span class="glyphicon glyphicon-info-sign"></span>
								<strong>Status:</strong>
								<xforms:output ref="instance('control-instance')/status"></xforms:output>
							</div>
						</xforms:group>
						<h1>etdpub Administration</h1>
						<p><a href="{instance('config')/url}" target="_blank">View Pubic Interface <span class="glyphicon glyphicon-new-window"></span></a><br /><a
								href="{$display_path}logout"><span class="glyphicon glyphicon-log-out"></span> Logout</a></p>
						<h3>Create New Documents</h3>
						<ul>
							<xforms:repeat nodeset="xxforms:sort(instance('templates')/template, @label, 'text', 'ascending')">
								<li><a href="edit/?template={@id}"><span class="glyphicon glyphicon-file"></span><xforms:output ref="@label"></xforms:output></a></li>
							</xforms:repeat>
						</ul>
						<xforms:group ref=".[count(instance('pagination-result')//record) &gt; 0]">
							<div>
								<h3>List of Records</h3>
								<!-- pagination variables -->
								<xforms:var name="numFound" select="number(instance('control-instance')/numFound)"></xforms:var>
								<table class="table">
									<thead>
										<tr>
											<th>Type</th>
											<th>Title</th>
											<th style="width:10%">View</th>
											<th style="width:10%">Crossref</th>
											<th style="width:5%">Publish</th>
											<th style="width:5%">Delete</th>
										</tr>
									</thead>
									<tbody>
										<xforms:repeat nodeset="instance('pagination-result')//record">
											<xforms:var name="id" select="id"></xforms:var>
											<xforms:var name="media_url" select="media_url"></xforms:var>
											<xforms:var name="genre" select="genre"></xforms:var>
											<xforms:var name="type" select="type"></xforms:var>
											<xforms:var name="internetMediaType" select="internetMediaType"></xforms:var>

											<tr>
												<td><xforms:output value="$type"></xforms:output>
												</td>
												<td>
													<h4>
														<xforms:group ref=".[type='MODS']">
															<xforms:trigger appearance="minimal">
																<xforms:label ref="title"></xforms:label>
																<xforms:action ev:event="DOMActivate">
																	<xforms:load show="replace" resource="edit/?id={$id}"></xforms:load>
																</xforms:action>
															</xforms:trigger>
														</xforms:group>
														<xforms:group ref=".[type='TEI']">
															<xforms:output ref="title"></xforms:output>
														</xforms:group>
													</h4>
													<div>
														<xforms:output ref="id">
															<xforms:label>ID</xforms:label>
														</xforms:output>
													</div>
													<xforms:group ref="doi[string-length(.) &gt; 0]">
														<div>
															<xforms:output ref=".">
																<xforms:label>DOI</xforms:label>
															</xforms:output>
														</div>
													</xforms:group>
													<div>
														<xforms:output ref="author">
															<xforms:label>Author</xforms:label>
														</xforms:output>
													</div>
													<div>
														<xforms:output ref="date">
															<xforms:label>Date</xforms:label>
														</xforms:output>
													</div>
													
													<xforms:group ref="genre">
														<div>
															<xforms:output ref=".">
																<xforms:label>Genre</xforms:label>
															</xforms:output>
														</div>
													</xforms:group>
												</td>
												<td class="text-center">
													<a href="{instance('config')/url}id/{$id}.xml" target="_blank">xml</a> | <a href="{instance('config')/url}id/{$id}"
														target="_blank">html</a>
												</td>
												<td class="text-center">
													<!-- only display link to post to Crossref when there's an orcid and it is already published and there isn't a DOI already -->
													<xforms:group ref=".[orcid = true() and published = true()]">
														<xforms:group ref=".[string-length(doi) &gt; 0]">
															<span class="glyphicon glyphicon-ok"/>
														</xforms:group>
														<xforms:group ref=".[not(string(doi))]">
															<xforms:trigger appearance="minimal">
																<xforms:label><span class="glyphicon glyphicon-unchecked"></span></xforms:label>
																<xforms:action ev:event="DOMActivate">
																	<xforms:setvalue ref="instance('control-instance')/id" value="$id"></xforms:setvalue>
																	<xforms:setvalue ref="instance('control-instance')/type" value="$type"></xforms:setvalue>
																	<!-- set the document URL and other variables -->
																	<xforms:setvalue ref="instance('control-instance')/stream_url"
																		value="if (matches($media_url, '^https?://')) then $media_url else concat(instance('config')/url, $media_url)"></xforms:setvalue>
																	<xforms:setvalue ref="instance('control-instance')/template" value="instance('templates')/template[. = $genre]/@id"></xforms:setvalue>
																	<xforms:setvalue ref="instance('control-instance')/internetMediaType" value="$internetMediaType"></xforms:setvalue>
																	<!-- serialize the record into Crossref XML -->
																	<xforms:send submission="load-crossref"></xforms:send>
																</xforms:action>
															</xforms:trigger>
														</xforms:group>
													</xforms:group>
												</td>
												<td class="text-center">
													<xforms:group ref=".[not(genre='journals (periodicals)')]">
														<xforms:group ref="published[. = true()]">
															<xforms:trigger appearance="minimal">
																<xforms:label><span class="glyphicon glyphicon-{if (.=true()) then 'ok' else 'unchecked'}"></span></xforms:label>
																<xforms:action ev:event="DOMActivate">
																	<xforms:var name="val" select="." as="xs:boolean"></xforms:var>
																	<xforms:setvalue ref="instance('control-instance')/id" value="$id"></xforms:setvalue>
																	<!-- delete the doc from eXist and Solr -->
																	<xforms:setvalue ref="instance('deleteId')/query"
																		value="concat('id:&#x022;', instance('control-instance')/id, '&#x022;')"></xforms:setvalue>
																	<xforms:send submission="delete-solr-doc"></xforms:send>
																	<!-- delete triples from triplestore, if applicable -->
																	<xforms:action ev:event="xforms-submit-done"
																		if="string(instance('config')/sparql/update) and string(instance('config')/sparql/store)">
																		<!-- set URI for object, execute SPARQL/Update query to purge triples -->
																		<xforms:var name="uri"
																			select="if (instance('config')/ark/@enabled='true') then concat(instance('config')/url, 'ark:/', instance('config')/ark/naan, '/', $id) else concat(instance('config')/url, 'id/', $id)"></xforms:var>
																		<xforms:setvalue ref="instance('sparqlUpdate')"
																			value="replace(instance('sparqlUpdate-template'), 'URI', $uri)"></xforms:setvalue>
																		<xforms:send submission="delete-graph"></xforms:send>
																	</xforms:action>
																	<xforms:setvalue ref="." value="false()"></xforms:setvalue>
																</xforms:action>
															</xforms:trigger>
														</xforms:group>
														<xforms:group ref="published[. = false()]">
															<xforms:trigger appearance="minimal">
																<xforms:label><span class="glyphicon glyphicon-{if (.=true()) then 'ok' else 'unchecked'}"></span></xforms:label>
																<xforms:action ev:event="DOMActivate">
																	<xforms:var name="val" select="." as="xs:boolean"></xforms:var>
																	<xforms:setvalue ref="instance('control-instance')/id" value="$id"></xforms:setvalue>
																	<xforms:setvalue ref="instance('control-instance')/type" value="$type"></xforms:setvalue>
																	<!-- only index the Document file for a MODS file that is not of the journal template -->
																	<xforms:action if="instance('control-instance')/type='MODS'">
																		<!-- set the document URL and other variables -->
																		<xforms:setvalue ref="instance('control-instance')/stream_url"
																			value="if (matches($media_url, '^https?://')) then $media_url else concat(instance('config')/url, $media_url)"></xforms:setvalue>
																		<xforms:setvalue ref="instance('control-instance')/template"
																			value="instance('templates')/template[. = $genre]/@id"></xforms:setvalue>
																		<xforms:setvalue ref="instance('control-instance')/internetMediaType" value="$internetMediaType"></xforms:setvalue>
																		<!-- first put the associated document, which then calls the MODS indexing afterwards -->
																		<xforms:send submission="put-document" if="not(instance('control-instance')/template = 'journal')"
																		></xforms:send>
																	</xforms:action>
																	<!-- otherwise, get the TEI-to-Solr document directly -->
																	<xforms:action if="instance('control-instance')/type = 'TEI'">
																		<xforms:send submission="to-solr"></xforms:send>
																	</xforms:action>
																	<!-- delete triples from triplestore, if applicable. Then re-post RDF document -->
																	<xforms:action ev:event="xforms-submit-done"
																		if="string(instance('config')/sparql/update) and string(instance('config')/sparql/store)">
																		<xforms:var name="uri"
																			select="if (instance('config')/ark/@enabled='true') then concat(instance('config')/url, 'ark:/', instance('config')/ark/naan, '/', $id) else concat(instance('config')/url, 'id/', $id)"></xforms:var>
																		<xforms:setvalue ref="instance('sparqlUpdate')"
																			value="replace(instance('sparqlUpdate-template'), 'URI', $uri)"></xforms:setvalue>
																		<xforms:send submission="get-rdf"></xforms:send>
																	</xforms:action>
																	<xforms:setvalue ref="." value="true()"></xforms:setvalue>
																</xforms:action>
															</xforms:trigger>
														</xforms:group>
													</xforms:group>
												</td>
												<td class="text-center">
													<xforms:trigger appearance="minimal">
														<xforms:label><span class="glyphicon glyphicon-remove"></span></xforms:label>
														<xforms:hint>Delete Document</xforms:hint>
														<xforms:action ev:event="DOMActivate">
															<xforms:setvalue ref="instance('control-instance')/id" value="$id"></xforms:setvalue>
															<xforms:setvalue ref="instance('control-instance')/media_url" value="$media_url"></xforms:setvalue>
															<xforms:dispatch target="delete" name="fr-show"></xforms:dispatch>
														</xforms:action>
													</xforms:trigger>
												</td>
											</tr>
										</xforms:repeat>
									</tbody>
								</table>
							</div>
						</xforms:group>
						<xforms:group ref=".[count(instance('pagination-result')//record)=0]">
							<h1>No records in collection.</h1>
						</xforms:group>
					</div>
					<!-- dialogs -->
					<fr:alert-dialog id="delete">
						<fr:label>Delete</fr:label>
						<fr:message>Are you sure you want to delete this object?</fr:message>
						<fr:negative-choice>
							<fr:label>No</fr:label>
						</fr:negative-choice>
						<fr:positive-choice>
							<fr:label>Yes</fr:label>
							<xforms:action ev:event="DOMActivate">
								<!-- first delete the uploaded media -->
								<xforms:setvalue ref="instance('delete-config')/delete/url" value="concat('oxf:/apps/etdpub/', instance('control-instance')/media_url)"></xforms:setvalue>
								<xforms:insert nodeset="instance('dump')"
									origin="xxforms:call-xpl('oxf:/apps/etdpub/xpl/xforms/delete-document.xpl', 'configuration', instance('delete-config'), 'data')"></xforms:insert>
								<!-- delete the doc from eXist and Solr -->
								<xforms:send submission="delete-doc"></xforms:send>
								<xforms:setvalue ref="instance('deleteId')/query" value="concat('id:&#x022;', instance('control-instance')/id, '&#x022;')"></xforms:setvalue>
								<xforms:send submission="delete-solr-doc"></xforms:send>
								<!-- delete triples from triplestore, if applicable -->
								<xforms:action if="string(instance('config')/sparql/update) and string(instance('config')/sparql/store)">
									<!-- set URI for object, execute SPARQL/Update query to purge triples -->
									<xforms:var name="uri"
										select="if (instance('config')/ark/@enabled='true') then concat(instance('config')/url, 'ark:/', instance('config')/ark/naan, '/', $id) else concat(instance('config')/url, 'id/', $id)"></xforms:var>
									<xforms:setvalue ref="instance('sparqlUpdate')" value="replace(instance('sparqlUpdate-template'), 'URI', $uri)"></xforms:setvalue>
									<xforms:send submission="delete-graph"></xforms:send>
								</xforms:action>
								<!-- reload table -->
								<xforms:setvalue ref="instance('eXist-xquery')/exist:text" value="instance('xqueries')/query[@id='get-objects']"></xforms:setvalue>
								<xforms:send submission="xquery-pagination"></xforms:send>
							</xforms:action>
						</fr:positive-choice>
					</fr:alert-dialog>
					<!--<xforms:upload ref="instance('crossref-form-data')/fname">
						<xforms:filename ref="@filename"/>
						<xforms:mediatype ref="@mediatype"/>
						<xxforms:size ref="@size"/>
					</xforms:upload>
					
					<xforms:trigger>
						<xforms:label>Submit</xforms:label>
						<xforms:action ev:event="DOMActivate">
							<xforms:setvalue ref="instance('crossref-form-data')/login_id" value="instance('crossref-config')/username"/>
							<xforms:setvalue ref="instance('crossref-form-data')/login_passwd" value="instance('crossref-config')/password"/>
							<xforms:send submission="post-crossref"/>
						</xforms:action>
						
					</xforms:trigger>-->
					<!--<fr:xforms-inspector id="orbeon-xforms-inspector"></fr:xforms-inspector>-->
				</div>
			</div>
		</div>
	</body>
</html>
<commit_msg>minor tweak to placement of DOI into publicationStmt instead of sourceDesc<commit_after><?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2015 <NAME>
    etdpub: https://github.com/ewg118/etdpub
    Apache License 2.0
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ev="http://www.w3.org/2001/xml-events"
	xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
	xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:exist="http://exist.sourceforge.net/NS/exist"
	xmlns:mods="http://www.loc.gov/mods/v3" xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<head>
		<title>etdpub Administration</title>
		<link rel="stylesheet" href="/fr/style/bootstrap/css/bootstrap.css" type="text/css" />
		<link rel="stylesheet" href="/fr/style/form-runner-bootstrap-override.css" type="text/css" />

		<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
		<script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
		<link rel="shortcut icon" href="/ops/images/orbeon-icon-16.ico" />
		<link rel="icon" href="/ops/images/orbeon-icon-16.png" type="image/png" />
		<link rel="stylesheet" href="/apps/etdpub/xforms/css/style.css" />

		<xforms:model>
			<xforms:instance id="control-instance" xxforms:exclude-result-prefixes="#all">
				<controls xmlns="">
					<id></id>
					<media_url></media_url>
					<stream_url></stream_url>
					<type></type>
					<template></template>
					<action></action>
					<working>false</working>
					<internetMediaType></internetMediaType>
					<interface></interface>
					<status></status>
					<crossref-api>https://test.crossref.org/servlet/deposit</crossref-api>
				</controls>
			</xforms:instance>

			<!-- exist URL is stored in an XML file -->
			<xforms:instance id="exist-config" xxforms:exclude-result-prefixes="#all">
				<xi:include href="../exist-config.xml"></xi:include>
			</xforms:instance>

			<!-- crossref authentication stored in XML file -->
			<xforms:instance id="crossref-config" xxforms:exclude-result-prefixes="#all">
				<xi:include href="../crossref-config.xml"></xi:include>
			</xforms:instance>

			<xforms:instance id="config" xxforms:exclude-result-prefixes="#all">
				<config></config>
			</xforms:instance>

			<xforms:instance id="config-template" xxforms:exclude-result-prefixes="#all">
				<config version="2017-08-01">
					<title>etdpub</title>
					<url>http://localhost:8080/orbeon/etdpub/</url>
					<xeac></xeac>
					<solr>
						<url>http://localhost:8080/solr/etdpub/</url>
						<rows>20</rows>
					</solr>
					<sparql>
						<update></update>
						<query></query>
						<store></store>
					</sparql>
					<ark enabled="false">
						<naan></naan>
					</ark>
					<crossref enabled="false">
						<depositor_name></depositor_name>
						<depositor_email></depositor_email>
						<doi_prefix></doi_prefix>
					</crossref>
					<logo></logo>
					<style>default</style>
					<geonames_api_key></geonames_api_key>
					<google_analytics></google_analytics>
					<absolute_path>/usr/local/projects/etdpub/</absolute_path>
				</config>
			</xforms:instance>

			<xforms:instance id="doc" xxforms:exclude-result-prefixes="#all">
				<xml xmlns=""></xml>
			</xforms:instance>

			<!-- instance templates -->
			<xforms:instance id="templates">
				<xi:include href="instances/templates.xml"></xi:include>
			</xforms:instance>

			<!-- xquery -->
			<xforms:instance id="eXist-xquery">
				<exist:query xmlns="">
					<exist:text></exist:text>
				</exist:query>
			</xforms:instance>

			<xforms:instance id="xqueries">
				<queries xmlns="">
					<query id="collection-count">&lt;report&gt;{count(collection())}&lt;/report&gt;</query>
					<query id="get-objects">
						<![CDATA[declare namespace mods="http://www.loc.gov/mods/v3";
						declare namespace tei="http://www.tei-c.org/ns/1.0";
						
						 <report> { for $record in collection() let
						 	$type := $record/*/local-name() return
						 	if ($type='modsCollection') then 
						 		<record>
							 		<id>{ data($record//mods:recordIdentifier) }</id>
							 		<title>{data($record//mods:mods/mods:titleInfo/mods:title) }</title>
							 		<author>{ string-join($record//mods:mods/mods:name/mods:namePart, ',') }</author>
							 		<date>{ if ($record//mods:dateIssued) then string-join($record//mods:dateIssued, '-') else data($record//descendant::mods:part/mods:date) }</date>
							 		<media_url>{ data($record//mods:location/mods:url) }</media_url>
							 		<internetMediaType>{data($record//mods:physicalDescription/mods:internetMediaType)}</internetMediaType>
							 		<type>MODS</type>
							 		<genre>{data($record//mods:mods/mods:genre)}</genre>
							 		<orcid>{if ($record//mods:name[mods:nameIdentifier[matches(., 'https?://orcid.org/[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[X0-9]{1}')]]) then true() else false()}</orcid>
							 		<doi>{data($record//mods:identifier[@type='DOI'])}</doi>
							 		<published>false</published>
						 		</record>
						 	else if ($type='TEI') then
							 	<record>
							 		<id>{ data($record/*[local-name()='TEI']/@xml:id) }</id>
							 		<title>{ data($record//tei:titleStmt/tei:title)}</title>
							 		<author>{string-join($record//tei:titleStmt/tei:author/tei:name, ', ')}</author>
							 		<date>{data($record//tei:publicationStmt/tei:date)}</date>
							 		<type>TEI</type>
							 		<orcid>{if ($record//tei:titleStmt/*[tei:idno[@type='URI'][matches(., 'https?://orcid.org/[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[X0-9]{1}')]]) then true() else false()}</orcid>
							 		<doi>{data($record//tei:fileDesc/tei:publicationStmt/tei:idno[@type='DOI'])}</doi>
							 		<published>false</published>
							 	</record>
							 else '' } 
						 </report>]]></query>
				</queries>
			</xforms:instance>

			<xforms:instance id="pagination-result">
				<exist:result></exist:result>
			</xforms:instance>

			<xforms:instance id="xquery-result">
				<exist:result></exist:result>
			</xforms:instance>

			<!-- file operations (for deleting the document from the filesystem -->
			<xforms:instance id="delete-config">
				<config xmlns="">
					<delete>
						<url></url>
					</delete>
				</config>
			</xforms:instance>

			<xforms:instance id="dump">
				<dump xmlns=""></dump>
			</xforms:instance>

			<!-- ***** Solr instances ***** -->
			<xforms:instance id="addIndex" xxforms:exclude-result-prefixes="#all">
				<add xmlns=""></add>
			</xforms:instance>

			<xforms:instance id="sendCommit" xxforms:exclude-result-prefixes="#all">
				<commit></commit>
			</xforms:instance>

			<!-- delete from Solr -->
			<xforms:instance id="deleteId" xxforms:exclude-result-prefixes="#all">
				<delete xmlns="">
					<query></query>
				</delete>
			</xforms:instance>

			<xforms:instance id="published-response">
				<response xmlns=""></response>
			</xforms:instance>

			<!-- DOI/Crossref templates -->
			<xforms:instance id="crossref" xxforms:exclude-result-prefixes="#all">
				<doi_batch xmlns=""></doi_batch>
			</xforms:instance>

			<xforms:instance id="crossref-form-data" xxforms:exclude-result-prefixes="#all">
				<formData xmlns="">
					<operation>doMDUpload</operation>
					<login_id></login_id>
					<login_passwd></login_passwd>
					<fname filename="" mediatype="" size=""></fname>
					<!--					<fname/>-->
				</formData>
			</xforms:instance>

			<xforms:instance id="save-crossref-config">
				<config xmlns="">
					<url></url>
					<content-type>text/plain</content-type>
					<make-directories>false</make-directories>
					<append>false</append>
				</config>
			</xforms:instance>

			<xforms:instance id="sourceDesc-template" xxforms:exclude-result-prefixes="#all">
				<sourceDesc xmlns="http://www.tei-c.org/ns/1.0"></sourceDesc>
			</xforms:instance>

			<xforms:instance id="tei-doi-template" xxforms:exclude-result-prefixes="#all">
				<idno type="DOI" xmlns="http://www.tei-c.org/ns/1.0"></idno>
			</xforms:instance>

			<xforms:instance id="mods-doi-template" xxforms:exclude-result-prefixes="#all">
				<identifier type="DOI" xmlns="http://www.loc.gov/mods/v3"></identifier>
			</xforms:instance>

			<!-- LOD CRUD instances -->
			<xforms:instance id="rdf" xxforms:exclude-result-prefixes="#all">
				<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"></rdf:RDF>
			</xforms:instance>

			<xforms:instance id="sparqlUpdate-template">
				<query><![CDATA[PREFIX rdf:	<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dcterms:	<http://purl.org/dc/terms/>
PREFIX dcmitype:	<http://purl.org/dc/dcmitype/>
PREFIX oa:	<http://www.w3.org/ns/oa#>
PREFIX schema:	<http://schema.org/>
DELETE {?s ?p ?o} WHERE { 
{<URI> schema:exampleOfWork ?s . ?s ?p ?o }
UNION {<URI> dcterms:temporal ?s . ?s ?p ?o }
UNION { ?parts dcterms:source <URI> ; rdf:type dcmitype:Text . ?s oa:hasTarget ?parts . ?s ?p ?o }
UNION { ?s dcterms:source <URI> ; rdf:type dcmitype:Text . ?s ?p ?o }
UNION {<URI> ?p ?o . ?s ?p ?o . FILTER (?s = <URI>) }
}]]>
				</query>
			</xforms:instance>

			<xforms:instance id="sparqlUpdate">
				<query></query>
			</xforms:instance>

			<!-- ************* BINDINGS **************** -->
			<xforms:bind nodeset="instance('control-instance')">
				<xforms:bind nodeset="working" type="xs:boolean"></xforms:bind>
			</xforms:bind>

			<xforms:bind nodeset="instance('pagination-result')">
				<xforms:bind nodeset="//record">
					<xforms:bind nodeset="published" type="xs:boolean"></xforms:bind>
				</xforms:bind>
			</xforms:bind>

			<xforms:bind nodeset="instance('crossref-form-data')">
				<xforms:bind nodeset="fname" as="xs:anyURI"></xforms:bind>
			</xforms:bind>

			<!-- ************* SUBMISSIONS **************** -->
			<xforms:submission id="load-config" serialization="none" method="get" action="{instance('exist-config')/url}etdpub/config.xml" replace="instance" instance="config"
				xxforms:username="{instance('exist-config')/username}" xxforms:password="{instance('exist-config')/password}">
				<xforms:action ev:event="xforms-submit-done">
					<xforms:setvalue ref="instance('eXist-xquery')/exist:text" value="instance('xqueries')/query[@id='get-objects']"></xforms:setvalue>
					<xforms:send submission="xquery-pagination"></xforms:send>
				</xforms:action>
				<xforms:message ev:event="xforms-submit-error" level="modal">Error loading config from eXist database.</xforms:message>
			</xforms:submission>

			<!--***************** XQUERY ******************-->
			<!-- xquery for getting and processing query results into pages of items -->
			<xforms:submission id="xquery-pagination" ref="instance('eXist-xquery')" action="{instance('exist-config')/url}etdpub/records" method="post" replace="instance"
				instance="pagination-result" xxforms:username="{instance('exist-config')/username}" xxforms:password="{instance('exist-config')/password}">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error querying eXist database.</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<!--iterate through docs, check for publication -->
					<xforms:action xxforms:iterate="instance('pagination-result')//record">
						<xforms:var name="position" select="position()"></xforms:var>
						<xforms:setvalue ref="instance('control-instance')/id" value="context()/id"></xforms:setvalue>
						<xforms:send submission="query-solr-for-publication"></xforms:send>
					</xforms:action>
				</xforms:action>
			</xforms:submission>

			<xforms:submission id="xquery-collection" ref="instance('eXist-xquery')" action="{instance('exist-config')/url}etdpub/records" method="post" replace="instance"
				instance="xquery-result" xxforms:username="{instance('exist-config')/username}" xxforms:password="{instance('exist-config')/password}">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error querying eXist database.</xforms:message>
			</xforms:submission>

			<!--***************** EXIST-DB ******************-->
			<xforms:submission id="load-doc" serialization="none" method="get" action="{instance('exist-config')/url}etdpub/records/{instance('control-instance')/id}.xml"
				replace="instance" instance="doc" xxforms:username="{instance('exist-config')/username}" xxforms:password="{instance('exist-config')/password}">
				<xforms:message ev:event="xforms-submit-error" level="modal">Unable to load MODS or TEI record from eXist.</xforms:message>

				<!-- after load, insert the relevant template DOI template in either TEI or MODS -->
				<xforms:action ev:event="xforms-submit-done">
					<xforms:var name="doi" select="concat(instance('config')/crossref/doi_prefix, '/', instance('control-instance')/id)"></xforms:var>

					<xforms:action if="instance('doc')/namespace-uri()='http://www.loc.gov/mods/v3'">
						<xforms:insert context="instance('doc')//mods:mods" nodeset="./child::node()[last()]" origin="instance('mods-doi-template')"></xforms:insert>
						<xforms:setvalue ref="instance('doc')//mods:mods/mods:identifier[@type='DOI']" value="$doi"></xforms:setvalue>
					</xforms:action>
					<xforms:action if="instance('doc')/namespace-uri()='http://www.tei-c.org/ns/1.0'">
						<xforms:insert context="instance('doc')/tei:teiHeader/tei:fileDesc" nodeset="./child::node()[last()]" origin="instance('sourceDesc-template')"
							if="not(instance('doc')/tei:teiHeader/tei:fileDesc/tei:sourceDesc)"></xforms:insert>
						<xforms:insert context="instance('doc')/tei:teiHeader/tei:fileDesc/tei:publicationStmt" nodeset="./child::node()[last()]" origin="instance('tei-doi-template')"></xforms:insert>
						<xforms:setvalue ref="instance('doc')/tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:idno[@type='DOI']" value="$doi"></xforms:setvalue>
					</xforms:action>
					
					<!-- save the doc back to exist -->
					<xforms:send submission="save-doc"/>
				</xforms:action>
			</xforms:submission>

			<xforms:submission id="save-doc" ref="instance('doc')" action="{instance('exist-config')/url}etdpub/records/{instance('control-instance')/id}.xml" method="put"
				replace="none" xxforms:username="{instance('exist-config')/username}" xxforms:password="{instance('exist-config')/password}">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error Saving Document</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:setvalue ref="instance('control-instance')/status">Successfully saved record to eXist.</xforms:setvalue>

					<!-- only index the Document file for a MODS file that is not of the journal template -->
					<xforms:action if="instance('control-instance')/type='MODS'">
						<!-- first put the associated document, which then calls the MODS indexing afterwards -->
						<xforms:send submission="put-document" if="not(instance('control-instance')/template = 'journal')"></xforms:send>
					</xforms:action>
					<!-- otherwise, get the TEI-to-Solr document directly -->
					<xforms:action if="instance('control-instance')/type = 'TEI'">
						<xforms:send submission="to-solr"></xforms:send>
					</xforms:action>
					<!-- delete triples from triplestore, if applicable. Then re-post RDF document -->
					<xforms:action ev:event="xforms-submit-done" if="string(instance('config')/sparql/update) and string(instance('config')/sparql/store)">
						<xforms:var name="uri"
							select="if (instance('config')/ark/@enabled='true') then concat(instance('config')/url, 'ark:/', instance('config')/ark/naan, '/', instance('control-instance')/id) else concat(instance('config')/url, 'id/', instance('control-instance')/id)"></xforms:var>
						<xforms:setvalue ref="instance('sparqlUpdate')" value="replace(instance('sparqlUpdate-template'), 'URI', $uri)"></xforms:setvalue>
						<xforms:send submission="delete-graph"></xforms:send>
						<xforms:send submission="get-rdf"></xforms:send>
					</xforms:action>
				</xforms:action>
			</xforms:submission>

			<xforms:submission id="delete-doc" action="{instance('exist-config')/url}etdpub/records/{instance('control-instance')/id}.xml" method="delete" replace="none"
				xxforms:username="{instance('exist-config')/username}" xxforms:password="{instance('exist-config')/password}">
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('control-instance')/status">MODS/TEI document successfully deleted.</xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Error deleting document from eXist database.</xforms:message>
			</xforms:submission>

			<!--***************** CROSSREF ******************-->
			<!-- serialize MODS/TEI into Crossref XML -->
			<xforms:submission id="load-crossref" method="get" replace="instance" instance="crossref" serialization="none"
				resource="/etdpub/id/{instance('control-instance')/id}.xref">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error transforming record to Crossref XML document.</xforms:message>

				<xforms:action ev:event="xforms-submit-done">
					<!-- set crossref credentials for form data -->
					<xforms:setvalue ref="instance('crossref-form-data')/login_id" value="instance('crossref-config')/username"></xforms:setvalue>
					<xforms:setvalue ref="instance('crossref-form-data')/login_passwd" value="instance('crossref-config')/password"></xforms:setvalue>
					<xforms:setvalue ref="instance('crossref-form-data')/fname" value="concat(instance('control-instance')/id, '.xml')"></xforms:setvalue>

					<!-- serialize the instance XML into a file in /tmp -->
					<xforms:setvalue ref="instance('save-crossref-config')/url" value="concat('file:///tmp/',  instance('control-instance')/id, '.xml')"></xforms:setvalue>
					<xforms:insert nodeset="instance('dump')"
						origin="xxforms:call-xpl('oxf:/apps/etdpub/xpl/xforms/save-crossref.xpl', ('doc', 'configuration'), (instance('crossref'), instance('save-crossref-config')), 'data')"></xforms:insert>

					<!-- post data to Crossref API -->
					<xforms:send submission="post-crossref"></xforms:send>
				</xforms:action>
			</xforms:submission>

			<!-- POST to Crossref deposition API -->
			<!--<xforms:submission id="post-crossref" action="{instance('control-instance')/crossref-api}" ref="instance('crossref-form-data')" instance="crossref-form-data" replace="instance"
				method="form-data-post" serialization="multipart/form-data">
				<xforms:message ev:event="xforms-submit-error" level="modal" value="event('response-body')"></xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:message level="modal" value="event('response-body')"></xforms:message>
				</xforms:action>
			</xforms:submission>-->

			<!-- interact with PHP script in CGI to run multipart/form-data -->
			<xforms:submission id="post-crossref" serialization="none" method="get" action="/etdpub/admin/attach-metadata?file={instance('crossref-form-data')/fname}"
				instance="dump" replace="instance">
				<xforms:header>
					<xforms:name>User-Agent</xforms:name>
					<xforms:value>ETDPub/XForms</xforms:value>
				</xforms:header>
				<xforms:message ev:event="xforms-submit-error" level="modal" value="event('response-body')"></xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<!-- after success, load the doc, insert DOI, and save it -->
					<xforms:send submission="load-doc"/>
					
					<!-- set DOI in the pagination metadata in order to prevent re-submission -->
					<xforms:var name="doi" select="concat(instance('config')/crossref/doi_prefix, '/', instance('control-instance')/id)"></xforms:var>
					<xforms:setvalue ref="instance('pagination-result')//record[id = instance('control-instance')/id]/doi" value="$doi"/>
				</xforms:action>
			</xforms:submission>

			<!-- ************************* SOLR ************************** -->
			<xforms:submission id="to-solr" method="get" replace="instance" instance="addIndex" serialization="none" resource="/etdpub/id/{instance('control-instance')/id}.solr">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error transforming record to Solr document.</xforms:message>
				<xforms:send ev:event="xforms-submit-done" submission="post-solr-doc"></xforms:send>
			</xforms:submission>

			<xforms:submission id="post-solr-doc" action="{instance('config')/solr/url}update" ref="instance('addIndex')" instance="addIndex" replace="instance" method="post">
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr. Index may be offline or URL is incorrect.</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:send submission="submit-commit"></xforms:send>
				</xforms:action>
			</xforms:submission>

			<xforms:submission id="put-document" ref="instance('dump')" method="post" replace="none"
				resource="{instance('config')/solr/url}update/extract?literal.id={instance('control-instance')/id}&amp;stream.url={instance('control-instance')/stream_url}&amp;fmap.content=text&amp;fmap.date=timestamp&amp;commit=true">
				<xforms:header>
					<xforms:name>Content-type</xforms:name>
					<xforms:value ref="instance('control-instance')/internetMediaType"></xforms:value>
				</xforms:header>
				<xforms:setvalue ev:event="xforms-submit" ref="instance('control-instance')/working" value="true()"></xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Unable to index the document file.</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:setvalue ref="instance('control-instance')/status">Document successfully saved to Solr.</xforms:setvalue>
					<xforms:setvalue ref="instance('control-instance')/working" value="false()"></xforms:setvalue>
					<xforms:send submission="to-solr"></xforms:send>
				</xforms:action>
			</xforms:submission>

			<!-- delete from Solr -->
			<xforms:submission id="delete-solr-doc" action="{instance('config')/solr/url}update" ref="instance('deleteId')" instance="deleteId" replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"></xforms:send>
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr.</xforms:message>
			</xforms:submission>

			<!-- send commit -->
			<xforms:submission id="submit-commit" action="{instance('config')/solr/url}update" ref="instance('sendCommit')" instance="sendCommit" replace="none" method="post">
				<xforms:message ev:event="xforms-submit-error" level="modal">Solr commit failed.</xforms:message>
			</xforms:submission>

			<!-- evaluating whether a document is published -->
			<xforms:submission id="query-solr-for-publication" serialization="none" method="get"
				action="{instance('config')/solr/url}select/?q=id:{instance('control-instance')/id}&amp;rows=0&amp;facet=false" replace="instance" instance="published-response">
				<!-- if the document is found in solr, get the updated solr doc -->
				<xforms:action ev:event="xforms-submit-done">
					<xforms:setvalue if="instance('published-response')/result[@name='response']/@numFound = '1'"
						ref="instance('pagination-result')//record[id=instance('control-instance')/id]/published" value="true()"></xforms:setvalue>
				</xforms:action>
			</xforms:submission>

			<!--********************** SPARQL SUBMISSIONS **********************-->
			<xforms:submission id="get-rdf" serialization="none" method="get" action="/etdpub/id/{instance('control-instance')/id}.rdf" replace="instance" instance="rdf">
				<xforms:message ev:event="xforms-submit-error" level="modal">Unable to get RDF/XML serialization.</xforms:message>
				<xforms:send submission="post-rdf" ev:event="xforms-submit-done"></xforms:send>
			</xforms:submission>

			<xforms:submission id="delete-graph" action="{instance('config')/sparql/update}" ref="instance('sparqlUpdate')" serialization="text/plain" replace="none" method="post"
				mediatype="application/sparql-update">
				<xforms:message level="modal" ev:event="xforms-submit-error">SPARQL update failed.</xforms:message>
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('control-instance')/status">Object has been removed from triplestore.</xforms:setvalue>
			</xforms:submission>

			<xforms:submission id="post-rdf" action="{instance('config')/sparql/store}?default" ref="instance('rdf')" replace="none" method="post" mediatype="application/rdf+xml">
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('control-instance')/status">Successfully posted to endpoint.</xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Post to endpoint failed.</xforms:message>
			</xforms:submission>

			<!-- ******************* XFORMS-MODEL-CONSTRUCT-DONE **********************-->
			<xforms:action ev:event="xforms-model-construct-done">
				<xforms:send submission="load-config"></xforms:send>
			</xforms:action>
		</xforms:model>
	</head>

	<body>
		<xforms:var name="display_path"></xforms:var>
		<div class="container-fluid">
			<div class="row">
				<div class="col-md-12">
					<div id="form">
						<!-- progress/status boxes -->
						<xforms:group ref=".[instance('control-instance')/working=true()]">
							<div class="bg-info alert-box">
								<span class="glyphicon glyphicon-info-sign"></span>
								<strong>Working:</strong> Indexing document...</div>
						</xforms:group>
						<xforms:group ref=".[string-length(instance('control-instance')/status) &gt; 0]">
							<div class="bg-info alert-box">
								<span class="glyphicon glyphicon-info-sign"></span>
								<strong>Status:</strong>
								<xforms:output ref="instance('control-instance')/status"></xforms:output>
							</div>
						</xforms:group>
						<h1>etdpub Administration</h1>
						<p><a href="{instance('config')/url}" target="_blank">View Pubic Interface <span class="glyphicon glyphicon-new-window"></span></a><br /><a
								href="{$display_path}logout"><span class="glyphicon glyphicon-log-out"></span> Logout</a></p>
						<h3>Create New Documents</h3>
						<ul>
							<xforms:repeat nodeset="xxforms:sort(instance('templates')/template, @label, 'text', 'ascending')">
								<li><a href="edit/?template={@id}"><span class="glyphicon glyphicon-file"></span><xforms:output ref="@label"></xforms:output></a></li>
							</xforms:repeat>
						</ul>
						<xforms:group ref=".[count(instance('pagination-result')//record) &gt; 0]">
							<div>
								<h3>List of Records</h3>
								<!-- pagination variables -->
								<xforms:var name="numFound" select="number(instance('control-instance')/numFound)"></xforms:var>
								<table class="table">
									<thead>
										<tr>
											<th>Type</th>
											<th>Title</th>
											<th style="width:10%">View</th>
											<th style="width:10%">Crossref</th>
											<th style="width:5%">Publish</th>
											<th style="width:5%">Delete</th>
										</tr>
									</thead>
									<tbody>
										<xforms:repeat nodeset="instance('pagination-result')//record">
											<xforms:var name="id" select="id"></xforms:var>
											<xforms:var name="media_url" select="media_url"></xforms:var>
											<xforms:var name="genre" select="genre"></xforms:var>
											<xforms:var name="type" select="type"></xforms:var>
											<xforms:var name="internetMediaType" select="internetMediaType"></xforms:var>

											<tr>
												<td><xforms:output value="$type"></xforms:output>
												</td>
												<td>
													<h4>
														<xforms:group ref=".[type='MODS']">
															<xforms:trigger appearance="minimal">
																<xforms:label ref="title"></xforms:label>
																<xforms:action ev:event="DOMActivate">
																	<xforms:load show="replace" resource="edit/?id={$id}"></xforms:load>
																</xforms:action>
															</xforms:trigger>
														</xforms:group>
														<xforms:group ref=".[type='TEI']">
															<xforms:output ref="title"></xforms:output>
														</xforms:group>
													</h4>
													<div>
														<xforms:output ref="id">
															<xforms:label>ID</xforms:label>
														</xforms:output>
													</div>
													<xforms:group ref="doi[string-length(.) &gt; 0]">
														<div>
															<xforms:output ref=".">
																<xforms:label>DOI</xforms:label>
															</xforms:output>
														</div>
													</xforms:group>
													<div>
														<xforms:output ref="author">
															<xforms:label>Author</xforms:label>
														</xforms:output>
													</div>
													<div>
														<xforms:output ref="date">
															<xforms:label>Date</xforms:label>
														</xforms:output>
													</div>
													
													<xforms:group ref="genre">
														<div>
															<xforms:output ref=".">
																<xforms:label>Genre</xforms:label>
															</xforms:output>
														</div>
													</xforms:group>
												</td>
												<td class="text-center">
													<a href="{instance('config')/url}id/{$id}.xml" target="_blank">xml</a> | <a href="{instance('config')/url}id/{$id}"
														target="_blank">html</a>
												</td>
												<td class="text-center">
													<!-- only display link to post to Crossref when there's an orcid and it is already published and there isn't a DOI already -->
													<xforms:group ref=".[orcid = true() and published = true()]">
														<xforms:group ref=".[string-length(doi) &gt; 0]">
															<span class="glyphicon glyphicon-ok"/>
														</xforms:group>
														<xforms:group ref=".[not(string(doi))]">
															<xforms:trigger appearance="minimal">
																<xforms:label><span class="glyphicon glyphicon-unchecked"></span></xforms:label>
																<xforms:action ev:event="DOMActivate">
																	<xforms:setvalue ref="instance('control-instance')/id" value="$id"></xforms:setvalue>
																	<xforms:setvalue ref="instance('control-instance')/type" value="$type"></xforms:setvalue>
																	<!-- set the document URL and other variables -->
																	<xforms:setvalue ref="instance('control-instance')/stream_url"
																		value="if (matches($media_url, '^https?://')) then $media_url else concat(instance('config')/url, $media_url)"></xforms:setvalue>
																	<xforms:setvalue ref="instance('control-instance')/template" value="instance('templates')/template[. = $genre]/@id"></xforms:setvalue>
																	<xforms:setvalue ref="instance('control-instance')/internetMediaType" value="$internetMediaType"></xforms:setvalue>
																	<!-- serialize the record into Crossref XML -->
																	<xforms:send submission="load-crossref"></xforms:send>
																</xforms:action>
															</xforms:trigger>
														</xforms:group>
													</xforms:group>
												</td>
												<td class="text-center">
													<xforms:group ref=".[not(genre='journals (periodicals)')]">
														<xforms:group ref="published[. = true()]">
															<xforms:trigger appearance="minimal">
																<xforms:label><span class="glyphicon glyphicon-{if (.=true()) then 'ok' else 'unchecked'}"></span></xforms:label>
																<xforms:action ev:event="DOMActivate">
																	<xforms:var name="val" select="." as="xs:boolean"></xforms:var>
																	<xforms:setvalue ref="instance('control-instance')/id" value="$id"></xforms:setvalue>
																	<!-- delete the doc from eXist and Solr -->
																	<xforms:setvalue ref="instance('deleteId')/query"
																		value="concat('id:&#x022;', instance('control-instance')/id, '&#x022;')"></xforms:setvalue>
																	<xforms:send submission="delete-solr-doc"></xforms:send>
																	<!-- delete triples from triplestore, if applicable -->
																	<xforms:action ev:event="xforms-submit-done"
																		if="string(instance('config')/sparql/update) and string(instance('config')/sparql/store)">
																		<!-- set URI for object, execute SPARQL/Update query to purge triples -->
																		<xforms:var name="uri"
																			select="if (instance('config')/ark/@enabled='true') then concat(instance('config')/url, 'ark:/', instance('config')/ark/naan, '/', $id) else concat(instance('config')/url, 'id/', $id)"></xforms:var>
																		<xforms:setvalue ref="instance('sparqlUpdate')"
																			value="replace(instance('sparqlUpdate-template'), 'URI', $uri)"></xforms:setvalue>
																		<xforms:send submission="delete-graph"></xforms:send>
																	</xforms:action>
																	<xforms:setvalue ref="." value="false()"></xforms:setvalue>
																</xforms:action>
															</xforms:trigger>
														</xforms:group>
														<xforms:group ref="published[. = false()]">
															<xforms:trigger appearance="minimal">
																<xforms:label><span class="glyphicon glyphicon-{if (.=true()) then 'ok' else 'unchecked'}"></span></xforms:label>
																<xforms:action ev:event="DOMActivate">
																	<xforms:var name="val" select="." as="xs:boolean"></xforms:var>
																	<xforms:setvalue ref="instance('control-instance')/id" value="$id"></xforms:setvalue>
																	<xforms:setvalue ref="instance('control-instance')/type" value="$type"></xforms:setvalue>
																	<!-- only index the Document file for a MODS file that is not of the journal template -->
																	<xforms:action if="instance('control-instance')/type='MODS'">
																		<!-- set the document URL and other variables -->
																		<xforms:setvalue ref="instance('control-instance')/stream_url"
																			value="if (matches($media_url, '^https?://')) then $media_url else concat(instance('config')/url, $media_url)"></xforms:setvalue>
																		<xforms:setvalue ref="instance('control-instance')/template"
																			value="instance('templates')/template[. = $genre]/@id"></xforms:setvalue>
																		<xforms:setvalue ref="instance('control-instance')/internetMediaType" value="$internetMediaType"></xforms:setvalue>
																		<!-- first put the associated document, which then calls the MODS indexing afterwards -->
																		<xforms:send submission="put-document" if="not(instance('control-instance')/template = 'journal')"
																		></xforms:send>
																	</xforms:action>
																	<!-- otherwise, get the TEI-to-Solr document directly -->
																	<xforms:action if="instance('control-instance')/type = 'TEI'">
																		<xforms:send submission="to-solr"></xforms:send>
																	</xforms:action>
																	<!-- delete triples from triplestore, if applicable. Then re-post RDF document -->
																	<xforms:action ev:event="xforms-submit-done"
																		if="string(instance('config')/sparql/update) and string(instance('config')/sparql/store)">
																		<xforms:var name="uri"
																			select="if (instance('config')/ark/@enabled='true') then concat(instance('config')/url, 'ark:/', instance('config')/ark/naan, '/', $id) else concat(instance('config')/url, 'id/', $id)"></xforms:var>
																		<xforms:setvalue ref="instance('sparqlUpdate')"
																			value="replace(instance('sparqlUpdate-template'), 'URI', $uri)"></xforms:setvalue>
																		<xforms:send submission="get-rdf"></xforms:send>
																	</xforms:action>
																	<xforms:setvalue ref="." value="true()"></xforms:setvalue>
																</xforms:action>
															</xforms:trigger>
														</xforms:group>
													</xforms:group>
												</td>
												<td class="text-center">
													<xforms:trigger appearance="minimal">
														<xforms:label><span class="glyphicon glyphicon-remove"></span></xforms:label>
														<xforms:hint>Delete Document</xforms:hint>
														<xforms:action ev:event="DOMActivate">
															<xforms:setvalue ref="instance('control-instance')/id" value="$id"></xforms:setvalue>
															<xforms:setvalue ref="instance('control-instance')/media_url" value="$media_url"></xforms:setvalue>
															<xforms:dispatch target="delete" name="fr-show"></xforms:dispatch>
														</xforms:action>
													</xforms:trigger>
												</td>
											</tr>
										</xforms:repeat>
									</tbody>
								</table>
							</div>
						</xforms:group>
						<xforms:group ref=".[count(instance('pagination-result')//record)=0]">
							<h1>No records in collection.</h1>
						</xforms:group>
					</div>
					<!-- dialogs -->
					<fr:alert-dialog id="delete">
						<fr:label>Delete</fr:label>
						<fr:message>Are you sure you want to delete this object?</fr:message>
						<fr:negative-choice>
							<fr:label>No</fr:label>
						</fr:negative-choice>
						<fr:positive-choice>
							<fr:label>Yes</fr:label>
							<xforms:action ev:event="DOMActivate">
								<!-- first delete the uploaded media -->
								<xforms:setvalue ref="instance('delete-config')/delete/url" value="concat('oxf:/apps/etdpub/', instance('control-instance')/media_url)"></xforms:setvalue>
								<xforms:insert nodeset="instance('dump')"
									origin="xxforms:call-xpl('oxf:/apps/etdpub/xpl/xforms/delete-document.xpl', 'configuration', instance('delete-config'), 'data')"></xforms:insert>
								<!-- delete the doc from eXist and Solr -->
								<xforms:send submission="delete-doc"></xforms:send>
								<xforms:setvalue ref="instance('deleteId')/query" value="concat('id:&#x022;', instance('control-instance')/id, '&#x022;')"></xforms:setvalue>
								<xforms:send submission="delete-solr-doc"></xforms:send>
								<!-- delete triples from triplestore, if applicable -->
								<xforms:action if="string(instance('config')/sparql/update) and string(instance('config')/sparql/store)">
									<!-- set URI for object, execute SPARQL/Update query to purge triples -->
									<xforms:var name="uri"
										select="if (instance('config')/ark/@enabled='true') then concat(instance('config')/url, 'ark:/', instance('config')/ark/naan, '/', $id) else concat(instance('config')/url, 'id/', $id)"></xforms:var>
									<xforms:setvalue ref="instance('sparqlUpdate')" value="replace(instance('sparqlUpdate-template'), 'URI', $uri)"></xforms:setvalue>
									<xforms:send submission="delete-graph"></xforms:send>
								</xforms:action>
								<!-- reload table -->
								<xforms:setvalue ref="instance('eXist-xquery')/exist:text" value="instance('xqueries')/query[@id='get-objects']"></xforms:setvalue>
								<xforms:send submission="xquery-pagination"></xforms:send>
							</xforms:action>
						</fr:positive-choice>
					</fr:alert-dialog>
					<!--<xforms:upload ref="instance('crossref-form-data')/fname">
						<xforms:filename ref="@filename"/>
						<xforms:mediatype ref="@mediatype"/>
						<xxforms:size ref="@size"/>
					</xforms:upload>
					
					<xforms:trigger>
						<xforms:label>Submit</xforms:label>
						<xforms:action ev:event="DOMActivate">
							<xforms:setvalue ref="instance('crossref-form-data')/login_id" value="instance('crossref-config')/username"/>
							<xforms:setvalue ref="instance('crossref-form-data')/login_passwd" value="instance('crossref-config')/password"/>
							<xforms:send submission="post-crossref"/>
						</xforms:action>
						
					</xforms:trigger>-->
					<!--<fr:xforms-inspector id="orbeon-xforms-inspector"></fr:xforms-inspector>-->
				</div>
			</div>
		</div>
	</body>
</html>

{'fraction_non_alphanumeric': 0.19843924191750278, 'fraction_numerical': 0.004484361103804191, 'mean_word_length': 3.5976733471550335, 'pattern_counts': {'":': 0, '<': 1771, '<?xml version=': 2, '>': 1771, 'https://': 4, 'lorem ipsum': 0, 'www.': 40, 'xml': 96}, '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': '6843626', 'n_tokens_mistral': 34305, 'n_tokens_neox': 25612, 'n_words': 3655}