Script to modify DC datastream dc:date

  • Main script:
#!/bin/bash
#
# 1 fedoraAdmin password
while read line; do
	lline=${#line}
	if [ $lline -gt 0 ]
	then
	  pid="${line%%,*}"
	  datepages="${line#*,}"
	  date="${datepages%%,*}"
	  pages="${datepages#*,}"
          echo "$pid $date $pages"
          ./modificaDSbookepage.sh $pid $date $pages $1
        fi
done < "elenco.txt"
exit
  • modificaDSbookepage.sh
#!/bin/bash
#
# 1 Book PID
# 2 New date
# 3 N pages
# 4 fedoraAdmin password
#
#es. ./modificaDSbookepage.sh fgramsci:TO024-00001 1984-01 52 password
#
PID=$1
NEWDATE=$2
PAGES=$3
./modificaDCdate.php $PID $NEWDATE
risultato=$(./fedora-modify.sh fc1.to.cnr.it:8080 fedoraAdmin $4 bmodify.xml ../logs/log http)
if [[ "$risultato" == *Valid* ]]
then 
   echo "Is Valid ..."	
   ./fedora-modify.sh fc1.to.cnr.it:8080 fedoraAdmin $4 bmodify.xml ../logs/log http YES
else 
   echo "ERROR XML: $risultato"
   exit
fi
for (( npage=1; npage<=$PAGES; npage++ ))
do
   snpage=$(printf "%04d" $npage)
   pagePID="$PID""-""$snpage"
   echo $pagePID
   ./modificaDCdate.php $pagePID $NEWDATE
   risultato=$(./fedora-modify.sh fc1.to.cnr.it:8080 fedoraAdmin $4 bmodify.xml ../logs/log http)
   if [[ "$risultato" == *Valid* ]]
   then 
      echo "Is Valid ..."	
      ./fedora-modify.sh fc1.to.cnr.it:8080 fedoraAdmin $4 bmodify.xml ../logs/log http YES
   else 
      echo "ERROR XML: $risultato"
      exit
   fi
done
exit
  • modificaDCdate.php
#!/usr/bin/php
<?php
if ($argc != 3 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>
 
This is a command line PHP script with two options.
 
  Usage:
  <?php
    echo $argv[0]; ?> <option>
 
  <option> can be some word you would like
  to print out. With the --help, -help, -h,
  or -? options, you can get this help.
 
<?php
    exit;
} else {
    $PID = $argv[1];
    $Nuovadata = $argv[2];
}
$indoc = new DOMDocument();
$indoc->formatOutput = true;
$indoc->preserveWhiteSpace = false;
$indoc->load('http://fc1.to.cnr.it:8080/fedora/objects/' . $PID . '/datastreams/DC/content');
$innode = $indoc->getElementsByTagNameNS('http://www.openarchives.org/OAI/2.0/oai_dc/', 'dc')->item(0);
$dcdate = $innode->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/', 'date')->item(0);
$olddcdate = $innode->removeChild($dcdate);
print_r($dcdate->nodeValue . " <- " . $Nuovadata . "\n");
$newdate = $indoc->createElement('dc:date', $Nuovadata);
$innode->appendChild($newdate);
$dom = new DOMDocument('1.0', 'utf-8');
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$element = $dom->createElement('fbm:batchModify');
$element->setAttribute('xmlns:fbm', 'http://www.fedora.info/definitions/');
$element->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$element->setAttribute('xsi:schemaLocation', 'http://www.fedora.info/definitions/ http://www.fedora-commons.org/definitions/1/0/api/batchModify-1.1.xsd');
$dom->appendChild($element);
$element1 = $dom->createElement('fbm:modifyDatastream');
$element1->setAttribute('pid', $PID);
$element1->setAttribute('dsID', 'DC');
$element1->setAttribute('dsControlGroupType', 'X');
$element1->setAttribute('logMessage', 'BatchModify - modifyDatastream');
$element->appendChild($element1);
$element2 = $dom->createElement('fbm:xmlData');
$element1->appendChild($element2);
$newnode = $dom->importNode($innode, true);
$element2->appendChild($newnode);
//	print $dom->saveXML()."\n";
//	print "======================"."\n";
print 'Wrote: ' . $dom->save("bmodify.xml") . ' bytes' . "\n";
?>
  • bmodify.xml example
<?xml version="1.0" encoding="utf-8"?>
<fbm:batchModify xmlns:fbm="http://www.fedora.info/definitions/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.fedora.info/definitions/ http://www.fedora-commons.org/definitions/1/0/api/batchModify-1.1.xsd">
  <fbm:modifyDatastream pid="fgramsci:TO024-00008-0056" dsID="DC" dsControlGroupType="X" logMessage="BatchModify - modifyDatastream">
    <fbm:xmlData>
      <oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
        <dc:title>Sisifo  8 - page 0056</dc:title>
        <dc:creator>Istituto Gramsci piemontese</dc:creator>
        <dc:subject>sviluppo; industria; welfare; lavoro; sociale; ricerca; innovazione; cultura, Piemonte, Torino</dc:subject>
        <dc:description>idee, ricerche, programmi dell'Istituto Gramsci piemontese. Settembre 1986</dc:description>
        <dc:publisher>Istituto Gramsci piemontese</dc:publisher>
        <dc:type>Text</dc:type>
        <dc:format/>
        <dc:identifier>fgramsci:TO024-00008-0056</dc:identifier>
        <dc:language>it</dc:language>
        <dc:date>1986-09</dc:date>
      </oai_dc:dc>
    </fbm:xmlData>
  </fbm:modifyDatastream>
</fbm:batchModify>
  • elenco.txt example
openbess:TO095-00001,1984-12,4
openbess:TO095-00002,1985-04,4
openbess:TO095-00003,1985-06,4
openbess:TO095-00004,1985-10,4
openbess:TO095-00005,1986-02,4
openbess:TO095-00006,1986,16
openbess:TO095-00007,1987,12
openbess:TO095-00008,1987,16
openbess:TO095-00009,1987,16
openbess:TO095-00010,1988,16
openbess:TO095-00011,1988,16
openbess:TO095-00012,1989,16
openbess:TO095-00013,1989,16
openbess:TO095-00014,1990,16
openbess:TO095-00015,1991-05,24
openbess:TO095-00016,1991-11,24
openbess:TO095-00017,1992-04,24
  • list books and number of page for collection (ITQL):
select $member3
count(select $pagine from <#ri>
where $pagine <fedora-rels-ext:isMemberOf> $member3
)
from <#ri>
where walk($object <fedora-rels-ext:isMemberOfCollection> <info:fedora/openbess:cognetti-C002>
and $member3 <fedora-rels-ext:isMemberOfCollection> $object)
and $member3 <fedora-model:hasModel> <info:fedora/islandora:bookCModel>
order by $member3
 
 
repo/dcdate.txt ยท Last modified: 2012/07/12 15:11 by giancarlo

Developers: CNR IRCrES IT Office and Library
Giancarlo Birello (giancarlo.birello _@_ ircres.cnr.it) and Anna Perin (anna.perin _@_ ircres.cnr.it)
DigiBess is licensed under: Creative Commons License
Recent changes RSS feed Creative Commons License Valid XHTML 1.0 Valid CSS Driven by DokuWiki
Drupal Garland Theme for Dokuwiki