-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA2RepoSwordDeposit.inc.php
222 lines (194 loc) · 7.1 KB
/
A2RepoSwordDeposit.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
/**
* @file plugins/generic/ejme/EjmeSwordDeposit.inc.php
*
* Copyright (c) 2003-2011 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class EjmeSwordDeposit
* @ingroup sword
*
* @brief Class providing a SWORD deposit wrapper for a supplemental file
*/
//loosely derived from the OJSSwordDeposit class (./classes/sword/OJSSwordDeposit.inc.php)
require_once('./lib/pkp/lib/swordapp/swordappclient.php');
require_once('./lib/pkp/lib/swordapp/swordappentry.php');
class A2RepoSwordDeposit {
/** @var $package SWORD deposit package */
var $package;
/** @var $outPath Complete path and directory name to use for package creation files */
var $outPath;
/** @var $journal */
var $journal;
/** @var $article */
var $article;
/** @var $depositPoint */
var $depositPoint;
/**
* Constructor.
* Create a SWORD deposit object for a supplemental file.
*/
function A2RepoSwordDeposit($journalId, &$article, &$depositPoint) {
// Create a directory for deposit contents
$this->outPath = tempnam('/tmp', 'sword');
unlink($this->outPath);
mkdir($this->outPath);
mkdir($this->outPath . '/files');
// Create a package
$this->package = new EPrintsPackager(
$this->outPath,
'files',
$this->outPath,
'deposit.zip'
);
$journalDao =& DAORegistry::getDAO('JournalDAO');
$this->journal =& $journalDao->getJournal($journalId);
$this->depositPoint = $depositPoint;
$this->article =& $article;
}
/**
* Register the SuppFile's metadata with the SWORD deposit.
*/
function setMetadata($ejme_urn=false) {
//PackagerMetsSwap class
$locale = $this->journal->getPrimaryLocale();
$this->package->setCustodian($this->journal->getSetting('contactName'));
$a = $this->article->getArticleTitle($locale);
$this->package->setTitle(html_entity_decode($a, ENT_QUOTES, 'UTF-8'));
$a = $this->article->getArticleAbstract($locale);
$issueDao =& DAORegistry::getDAO('IssueDAO');
$issuesResultSet =& $issueDao->getIssues($this->journal->getId());
#I was unaware we could have more than one.
while (!$issuesResultSet->eof())
{
$issue = $issuesResultSet->next();
}
if(isset($issue)){
# error_log("Volume: ".$issue->getVolume());
# error_log("Number: ".$issue->getNumber());
# error_log("Date: ".$issue->getYear());
$this->package->setVolume(html_entity_decode($issue->getVolume(), ENT_QUOTES, 'UTF-8'));
$this->package->setNumber(html_entity_decode($issue->getNumber(), ENT_QUOTES, 'UTF-8'));
$this->package->setDate(html_entity_decode($issue->getYear(), ENT_QUOTES, 'UTF-8'));
}else{
error_log("No issue set");
}
$this->package->setPublication(html_entity_decode($this->journal->getLocalizedTitle()));
$this->package->setAbstract(html_entity_decode(strip_tags($a), ENT_QUOTES, 'UTF-8'));
$this->package->setType($this->article->getType($locale));
foreach($this->article->getAuthors($locale) as $author){
$this->package->addEPCreator(array(
"given" => $author->getFirstName().' '.$author->getMiddleName() . '', // make non-null
"family" => $author->getLastName(),
#UCL discovery don't have creator-id "id" => $author->getEmail()
));
}
if($ejme_urn){
# error_log("~~~~~ I'm going to send this eprints id!!! : ".$ejme_urn);
$this->package->setURN(html_entity_decode($ejme_urn, ENT_QUOTES, 'UTF-8'));
}
//EjmePackager extensions
$a = $this->article->getSubject($locale);
$this->package->setSubject(html_entity_decode($a, ENT_QUOTES, 'UTF-8'));
$this->package->setDateCreated($this->article->getDateSubmitted());
# $a = $this->article->getSource(null);
# $this->package->setSource(html_entity_decode($a[$locale], ENT_QUOTES, 'UTF-8'));
$a = $this->article->getSponsor($locale);
$this->package->setSponsor(html_entity_decode($a, ENT_QUOTES, 'UTF-8'));
# $a = $this->article->getPublisher(null);
# $this->package->setPublisher(html_entity_decode($a[$locale], ENT_QUOTES, 'UTF-8'));
$a = $this->article->getLanguage();
switch ($a) {
case 'eng':
case 'en': $this->package->setLanguage('eng'); break;
case 'fre':
case 'fra':
case 'fr': $this->package->setLanguage('fre/fra'); break;
case 'dut':
case 'nld':
case 'nl': $this->package->setLanguage('dut/nld'); break;
case 'ger':
case 'deu':
case 'de': $this->package->setLanguage('ger/deu'); break;
case 'ita':
case 'it': $this->package->setLanguage('ita'); break;
case 'spa':
case 'es':
case 'sp': $this->package->setLanguage('spa'); break;
default: $this->package->setLanguage(''); break;
}
//additional EJME metadata
switch ($this->article->getData('ejme_access')) {
case '1': $this->package->setAccess('REQUEST_PERMISSION'); break;
case '2': $this->package->setAccess('NO_ACCESS'); break;
default : $this->package->setAccess('OPEN_ACCESS');
}
$this->package->setDateAvailable($this->article->getData('ejme_date_available'));
if (isset($this->depositPoint['audience']) && $this->depositPoint['audience'] != '') {
$this->package->setDiscipline('easy-discipline:' . $this->depositPoint['audience']);
}
}
/**
* $article->getFilePath() contains a bug caused by the fact that
* ArticleFile::getType() is overridden by SuppFile::getType()
*
*/
function getFilePath (&$file) {
$journalId = $this->journal->getJournalId();
return Config::getVar('files', 'files_dir') . '/journals/' . $journalId .
'/articles/' . $file->getArticleId() . '/submission/original/' . $file->getFileName();
}
/**
* Add a file to a package. Used internally.
*/
function _addFile(&$file) {
$targetFilename = $this->outPath . '/files/' . $file->getFilename();
copy($this->getFilePath($file), $targetFilename);
$this->package->addFile($file->getFilename(), $file->getFileType());
}
/**
* Add suppl.file to the deposit package.
*/
function addArticleFile() {
$this->_addFile($this->article->articleFile);
}
/**
* Build the package.
*/
function createPackage() {
return $this->package->create();
}
/**
* Deposit the package.
* @param $url string SWORD deposit URL
* @param $username string SWORD deposit username (i.e. email address for DSPACE)
* @param $password string SWORD deposit password
*/
function deposit($url, $username, $password) {
try {
$client = new SWORDAPPClient();
# error_log("Trying to deposit: ".$this->outPath."/deposit.zip");
$response = $client->deposit( //url, un, pw, obo, fname, packaging, contenttype, noop, verbose
$url, $username, $password,
'',
$this->outPath . '/deposit.zip',
# 'http://purl.org/net/sword-types/bagit', //or: 'http://purl.org/net/sword-types/METSDSpaceSIP',
# 'application/zip', false, true
'http://purl.org/net/sword/package/SimpleZip',
'application/zip', false, true
);
} catch (Exception $e) {
return FALSE;
}
return $response; //return deposit object or errordocument
}
/**
* Clean up after a deposit, i.e. removing all created files.
*/
function cleanup() {
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$fileManager->rmtree($this->outPath);
}
}
?>