Skip to content

Commit

Permalink
pkp#3261 Import/Export Review related files
Browse files Browse the repository at this point in the history
  • Loading branch information
defstat committed May 21, 2018
1 parent ffde508 commit 5a6a08a
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 0 deletions.
21 changes: 21 additions & 0 deletions classes/submission/ReviewFilesDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ function check($reviewId, $fileId) {
$result->Close();
return $returner;
}

/**
* Select Review file ids by reviewId
* @param $reviewId integer
* @return array
*/
function getByReviewId($reviewId) {
$result = $this->retrieve(
'SELECT review_id, file_id FROM review_files WHERE review_id = ?',
array((int) $reviewId)
);

$fileIds = array();
while (!$result->EOF) {
$row = $result->getRowAssoc(false);
$fileIds[] = $row['file_id'];
$result->MoveNext();
}
$result->Close();
return $fileIds;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,49 @@ function handleElement($node) {
$reviewAssignmentDao->insertObject($reviewAssignment);
}

// Handle subelements
for ($n = $node->firstChild; $n !== null; $n=$n->nextSibling) {
if (is_a($n, 'DOMElement')) {
switch($n->tagName) {
case 'reviewFiles':
$this->parseReviewFiles($n, $reviewAssignment);
break;
}
}
}

return $reviewAssignment;
}

/**
* Parse an reviewAssignments element
* @param $node DOMElement
* @param $reviewRound ReviewRound
*/
function parseReviewFiles($node, $reviewAssignment) {
for ($n = $node->firstChild; $n !== null; $n=$n->nextSibling) {
if (is_a($n, 'DOMElement')) {
assert($n->tagName == 'reviewFile');
$this->parseReviewFile($n, $reviewAssignment);
}
}
}

/**
* Parse an author and add it to the submission.
* @param $n DOMElement
* @param $reviewRound ReviewRound
*/
function parseReviewFile($n, $reviewAssignment) {
$deployment = $this->getDeployment();

$oldFileId = $n->getAttribute('oldFileId');

$newFileId = $deployment->getFileDBId($oldFileId);

$reviewFileDao = DAORegistry::getDAO('ReviewFilesDAO');
$reviewFileDao->grant($reviewAssignment->getId(), $newFileId);
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ function handleElement($node) {
case 'reviewAssignments':
$this->parseReviewAssignments($n, $reviewRound);
break;
case 'reviewRoundFiles':
$this->parseReviewRoundFiles($n, $reviewRound);
break;
}
}
}
Expand Down Expand Up @@ -121,6 +124,40 @@ function parseReviewAssignment($n, $reviewRound) {
$reviewAssignmentDoc->appendChild($reviewAssignmentDoc->importNode($n, true));
return $importFilter->execute($reviewAssignmentDoc);
}

/**
* Parse an reviewAssignments element
* @param $node DOMElement
* @param $reviewRound ReviewRound
*/
function parseReviewRoundFiles($node, $reviewRound) {
for ($n = $node->firstChild; $n !== null; $n=$n->nextSibling) {
if (is_a($n, 'DOMElement')) {
assert($n->tagName == 'reviewRoundFile');
$this->parseReviewRoundFile($n, $reviewRound);
}
}
}

/**
* Parse an author and add it to the submission.
* @param $n DOMElement
* @param $reviewRound ReviewRound
*/
function parseReviewRoundFile($n, $reviewRound) {
$deployment = $this->getDeployment();
$context = $deployment->getContext();
$submission = $deployment->getSubmission();
assert(is_a($submission, 'Submission'));

$oldFileId = $n->getAttribute('oldFileId');
$revision = $n->getAttribute('revision');

$newFileId = $deployment->getFileDBId($oldFileId, $revision);

$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
$submissionFileDao->assignRevisionToReviewRound($newFileId, $revision, $reviewRound);
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,66 @@ function createReviewAssignmentsNode($doc, $reviewAssignment) {
assert(isset($reviewerUser));
$reviewAssignmentNode->setAttribute('reviewer', $reviewerUser->getUsername());

$this->addReviewFiles($doc, $reviewAssignmentNode, $reviewAssignment);

return $reviewAssignmentNode;
}

/**
* Add the ReviewRoundFiles for a review round to its DOM element.
* @param $doc DOMDocument
* @param $reviewRoundNode DOMElement
* @param $reviewAssignment ReviewAssignment
*/
function addReviewFiles($doc, $reviewAssignmentNode, $reviewAssignment) {
$fileDao = DAORegistry::getDAO('ReviewFilesDAO');

$reviewFiles = $fileDao->getByReviewId($reviewAssignment->getId());

$reviewFilesNode = $this->processReviewFiles($reviewFiles, $reviewAssignment);
if ($reviewFilesNode->documentElement instanceof DOMElement) {
$clone = $doc->importNode($reviewFilesNode->documentElement, true);
$reviewAssignmentNode->appendChild($clone);
}
}

function processReviewFiles($reviewFiles, $reviewAssignment) {
$doc = new DOMDocument('1.0');
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$deployment = $this->getDeployment();

$rootNode = $doc->createElementNS($deployment->getNamespace(), 'reviewFiles');
foreach ($reviewFiles as $reviewFile) {
$rootNode->appendChild($this->createReviewFileNode($doc, $reviewFile, $reviewAssignment));
}
$doc->appendChild($rootNode);
$rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$rootNode->setAttribute('xsi:schemaLocation', $deployment->getNamespace() . ' ' . $deployment->getSchemaFilename());

return $doc;
}

/**
* Create and return an reviewAssignment node.
* @param $doc DOMDocument
* @param $reviewFile SubmissionFile
* @param $reviewRound ReviewRound
* @return DOMElement
*/
function createReviewFileNode($doc, $reviewFileId) {
$deployment = $this->getDeployment();
$context = $deployment->getContext();

// Create the reviewAssignment node
$reviewFileNode = $doc->createElementNS($deployment->getNamespace(), 'reviewFile');

if ($reviewFileId) {
$reviewFileNode->setAttribute('oldFileId', $reviewFileId);
}

return $reviewFileNode;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function createReviewRoundNode($doc, $reviewRound) {
$reviewRoundNode->setAttribute('status', $reviewRound->getStatus());

$this->addReviewAssignments($doc, $reviewRoundNode, $reviewRound);
$this->addReviewRoundFiles($doc, $reviewRoundNode, $reviewRound);

return $reviewRoundNode;
}
Expand All @@ -111,6 +112,67 @@ function addReviewAssignments($doc, $reviewRoundNode, $reviewRound) {
$reviewRoundNode->appendChild($clone);
}
}

/**
* Add the ReviewRoundFiles for a review round to its DOM element.
* @param $doc DOMDocument
* @param $reviewRoundNode DOMElement
* @param $reviewRound ReviewRound
*/
function addReviewRoundFiles($doc, $reviewRoundNode, $reviewRound) {
$fileDao = DAORegistry::getDAO('SubmissionFileDAO');

$reviewFiles = $fileDao->getRevisionsByReviewRound($reviewRound);

$reviewRoundFilesNode = $this->processReviewRoundFiles($reviewFiles, $reviewRound);
if ($reviewRoundFilesNode->documentElement instanceof DOMElement) {
$clone = $doc->importNode($reviewRoundFilesNode->documentElement, true);
$reviewRoundNode->appendChild($clone);
}
}

function processReviewRoundFiles($reviewFiles, $reviewRound) {
$doc = new DOMDocument('1.0');
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$deployment = $this->getDeployment();

$rootNode = $doc->createElementNS($deployment->getNamespace(), 'reviewRoundFiles');
foreach ($reviewFiles as $reviewFile) {
$rootNode->appendChild($this->createReviewRoundFileNode($doc, $reviewFile, $reviewRound));
}
$doc->appendChild($rootNode);
$rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$rootNode->setAttribute('xsi:schemaLocation', $deployment->getNamespace() . ' ' . $deployment->getSchemaFilename());

return $doc;
}

/**
* Create and return an reviewAssignment node.
* @param $doc DOMDocument
* @param $reviewFile SubmissionFile
* @param $reviewRound ReviewRound
* @return DOMElement
*/
function createReviewRoundFileNode($doc, $reviewFile, $reviewRound) {
$deployment = $this->getDeployment();
$context = $deployment->getContext();

// Create the reviewAssignment node
$reviewRoundFileNode = $doc->createElementNS($deployment->getNamespace(), 'reviewRoundFile');
// if ($reviewAssignment->getPrimaryContact()) $reviewAssignmentNode->setAttribute('primary_contact', 'true');

if ($revision = $reviewFile->getRevision()) {
$reviewRoundFileNode->setAttribute('revision', $revision);
}

if ($oldFileId = $reviewFile->getFileId()) {
$reviewRoundFileNode->setAttribute('oldFileId', $oldFileId);
}

return $reviewRoundFileNode;
}
}

?>
29 changes: 29 additions & 0 deletions plugins/importexport/native/pkp-native.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,17 @@
<complexType name="reviewRound">
<sequence>
<element ref="pkp:reviewAssignments" maxOccurs="1" />
<element ref="pkp:reviewRoundFiles" maxOccurs="1" />
</sequence>
<attribute name="stage_id" type="int" />
<attribute name="round" type="int" />
<attribute name="status" type="int" />
</complexType>

<complexType name="reviewAssignment">
<sequence>
<element ref="pkp:reviewFiles" minOccurs="0" maxOccurs="1" />
</sequence>
<attribute name="date_assigned" type="date" use="optional" />
<attribute name="date_notified" type="date" use="optional" />
<attribute name="date_completed" type="date" use="optional" />
Expand All @@ -271,6 +275,15 @@
<attribute name="step" type="int" use="optional" />
<attribute name="reviewer" type="string" />
</complexType>

<complexType name="reviewRoundFile">
<attribute name="revision" type="int" />
<attribute name="oldFileId" type="int" />
</complexType>

<complexType name="reviewFile">
<attribute name="oldFileId" type="int" />
</complexType>

<!-- ************
- * Elements *
Expand Down Expand Up @@ -385,6 +398,22 @@
</complexType>
</element>

<element name="reviewRoundFiles">
<complexType>
<sequence>
<element name="reviewRoundFile" type="pkp:reviewRoundFile" minOccurs="0" maxOccurs="unbounded" />
</sequence>
</complexType>
</element>

<element name="reviewFiles">
<complexType>
<sequence>
<element name="reviewFile" type="pkp:reviewFile" minOccurs="0" maxOccurs="unbounded" />
</sequence>
</complexType>
</element>

<!-- Permit "reviewRound" as a root element -->
<element name="reviewRound" type="pkp:reviewRound" />

Expand Down

0 comments on commit 5a6a08a

Please sign in to comment.