Skip to content

Commit

Permalink
Merge branch 'addMetricsImport-784' into 'main'
Browse files Browse the repository at this point in the history
Import journal metrics

See merge request softwares-pkp/plugins_ojs/fullJournalTransfer!53
  • Loading branch information
thiagolepidus committed May 3, 2024
2 parents 203c752 + 11da17f commit 643a749
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 37 deletions.
100 changes: 100 additions & 0 deletions FullJournalImportExportDeployment.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ class FullJournalImportExportDeployment extends NativeImportExportDeployment
private $navigationMenuItemDBIds;
private $reviewFormDBIds;
private $reviewFormElementDBIds;
private $representationDBIds;
private $issueDBIds;
private $issueGalleyDBIds;
private $submissionDBIds;

public function __construct($context, $user = null)
{
parent::__construct($context, $user);
$this->setNavigationMenuItemDBIds([]);
$this->setReviewFormDBIds([]);
$this->setReviewFormElementDBIds([]);
$this->setRepresentationDBIds([]);
$this->setIssueDBIds([]);
$this->setIssueGalleyDBIds([]);
$this->setSubmissionDBIds([]);
}

public function getSchemaFilename()
Expand Down Expand Up @@ -189,4 +197,96 @@ public function setReviewFormElementDBId($reviewFormElementDBId, $DBId)
{
return $this->reviewFormElementDBIds[$reviewFormElementDBId] = $DBId;
}

public function getRepresentationDBIds()
{
return $this->representationDBIds;
}

public function setRepresentationDBIds($representationDBIds)
{
return $this->representationDBIds = $representationDBIds;
}

public function getRepresentationDBId($representationDBId)
{
if (array_key_exists($representationDBId, $this->representationDBIds)) {
return $this->representationDBIds[$representationDBId];
}
return null;
}

public function setRepresentationDBId($representationDBId, $DBId)
{
return $this->representationDBIds[$representationDBId] = $DBId;
}

public function getIssueDBIds()
{
return $this->issueDBIds;
}

public function setIssueDBIds($issueDBIds)
{
return $this->issueDBIds = $issueDBIds;
}

public function getIssueDBId($issueDBId)
{
if (array_key_exists($issueDBId, $this->issueDBIds)) {
return $this->issueDBIds[$issueDBId];
}
return null;
}

public function setIssueDBId($issueDBId, $DBId)
{
return $this->issueDBIds[$issueDBId] = $DBId;
}

public function getIssueGalleyDBIds()
{
return $this->issueGalleyDBIds;
}

public function setIssueGalleyDBIds($issueGalleyDBIds)
{
return $this->issueGalleyDBIds = $issueGalleyDBIds;
}

public function getIssueGalleyDBId($issueGalleyDBId)
{
if (array_key_exists($issueGalleyDBId, $this->issueGalleyDBIds)) {
return $this->issueGalleyDBIds[$issueGalleyDBId];
}
return null;
}

public function setIssueGalleyDBId($issueGalleyDBId, $DBId)
{
return $this->issueGalleyDBIds[$issueGalleyDBId] = $DBId;
}

public function getSubmissionDBIds()
{
return $this->submissionDBIds;
}

public function setSubmissionDBIds($submissionDBIds)
{
return $this->submissionDBIds = $submissionDBIds;
}

public function getSubmissionDBId($submissionDBId)
{
if (array_key_exists($submissionDBId, $this->submissionDBIds)) {
return $this->submissionDBIds[$submissionDBId];
}
return null;
}

public function setSubmissionDBId($submissionDBId, $DBId)
{
return $this->submissionDBIds[$submissionDBId] = $DBId;
}
}
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ php tools/importExport.php FullJournalImportExportPlugin import [targzFileName]
- Stage Assignments
- Editor Decisions
- Discussions

**To Do**:

- Metrics

## Running Tests
Expand Down
11 changes: 11 additions & 0 deletions filter/filterConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@
description="plugins.importexport.fullJournalTransfer.description"
inputType="xml::schema(plugins/importexport/fullJournalTransfer/fullJournal.xsd)"
outputType="class::classes.submission.Submission[]" />
<!-- Extended Publication native XML input -->
<filterGroup
symbolic="native-xml=>extended-publication"
displayName="plugins.importexport.fullJournalTransfer.displayName"
description="plugins.importexport.fullJournalTransfer.description"
inputType="xml::schema(plugins/importexport/fullJournalTransfer/fullJournal.xsd)"
outputType="class::classes.publication.Publication[]" />
<!-- ExtendedIssue native XML output -->
<filterGroup
symbolic="extended-issue=>native-xml"
Expand Down Expand Up @@ -259,6 +266,10 @@
inGroup="native-xml=>extended-article"
class="plugins.importexport.fullJournalTransfer.filter.import.NativeXmlExtendedArticleFilter"
isTemplate="0" />
<filter
inGroup="native-xml=>extended-publication"
class="plugins.importexport.fullJournalTransfer.filter.import.NativeXmlExtendedPublicationFilter"
isTemplate="0" />
<filter
inGroup="extended-issue=>native-xml"
class="plugins.importexport.fullJournalTransfer.filter.export.ExtendedIssueNativeXmlFilter"
Expand Down
32 changes: 32 additions & 0 deletions filter/import/NativeXmlExtendedArticleFilter.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ public function getClassName()
return 'plugins.importexport.fullJournalTransfer.filter.import.NativeXmlExtendedArticleFilter';
}

public function handleElement($node)
{
$submission = parent::handleElement($node);
$deployment = $this->getDeployment();

if ($submission) {
for ($childNode = $node->firstChild; $childNode !== null; $childNode = $childNode->nextSibling) {
if (
is_a($childNode, 'DOMElement')
&& $childNode->tagName == 'id'
&& $childNode->getAttribute('type') == 'internal'
) {
$deployment->setSubmissionDBId($childNode->textContent, $submission->getId());
}
}
}
}

public function handleChildElement($node, $submission)
{
if ($node->tagName === 'stage') {
Expand Down Expand Up @@ -350,4 +368,18 @@ public function parseArticleFile($node)
$reviewRoundFileDoc->appendChild($reviewRoundFileDoc->importNode($node, true));
return $importFilter->execute($reviewRoundFileDoc);
}

public function getImportFilter($elementName)
{
if ($elementName == 'publication') {
$importClass = 'extended-publication';

$filterDao = DAORegistry::getDAO('FilterDAO');
$importFilters = $filterDao->getObjectsByGroup('native-xml=>' . $importClass);
$importFilter = array_shift($importFilters);
return $importFilter;
}

return parent::getImportFilter($elementName);
}
}
41 changes: 41 additions & 0 deletions filter/import/NativeXmlExtendedIssueFilter.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ public function getSingularElementName()
return 'extended_issue';
}

public function handleElement($node)
{
$issue = parent::handleElement($node);
$deployment = $this->getDeployment();

if ($issue) {
for ($childNode = $node->firstChild; $childNode !== null; $childNode = $childNode->nextSibling) {
if (
is_a($childNode, 'DOMElement')
&& $childNode->tagName == 'id'
&& $childNode->getAttribute('type') == 'internal'
) {
$deployment->setIssueDBId($childNode->textContent, $issue->getId());
}
}
}

return $issue;
}

public function handleChildElement($node, $issue, $processOnlyChildren)
{
$deployment = $this->getDeployment();
Expand Down Expand Up @@ -104,4 +124,25 @@ public function parseArticle($node, $issue)
$articleDoc->appendChild($articleDoc->importNode($node, true));
return $importFilter->execute($articleDoc);
}

public function parseIssueGalley($n, $issue)
{
$deployment = $this->getDeployment();
$importedObjects = parent::parseIssueGalley($n, $issue);

$issueGalley = array_shift($importedObjects);
if (is_a($issueGalley, 'IssueGalley')) {
for ($childNode = $n->firstChild; $childNode !== null; $childNode = $childNode->nextSibling) {
if (
is_a($childNode, 'DOMElement')
&& $childNode->tagName == 'id'
&& $childNode->getAttribute('type') == 'internal'
) {
$deployment->setIssueGalleyDBId($childNode->textContent, $issueGalley->getId());
}
}
}

return $importedObjects;
}
}
40 changes: 40 additions & 0 deletions filter/import/NativeXmlExtendedPublicationFilter.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Copyright (c) 2014-2024 Lepidus Tecnologia
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*/

import('plugins.importexport.native.filter.NativeXmlPublicationFilter');

class NativeXmlExtendedPublicationFilter extends NativeXmlPublicationFilter
{
public function getClassName()
{
return 'plugins.importexport.fullJournalTransfer.filter.import.NativeXmlExtendedPublicationFilter';
}

public function handleChildElement($n, $publication)
{
$deployment = $this->getDeployment();
if ($n->tagName == 'article_galley') {
$articleGalleys = $this->parseArticleGalley($n, $publication);
$articleGalley = array_shift($articleGalleys);
if (is_a($articleGalley, 'ArticleGalley')) {
for ($childNode = $n->firstChild; $childNode !== null; $childNode = $childNode->nextSibling) {
if (
is_a($childNode, 'DOMElement')
&& $childNode->tagName == 'id'
&& $childNode->getAttribute('type') == 'internal'
) {
$deployment->setRepresentationDBId($childNode->textContent, $articleGalley->getId());
}
}
}
return;
}
parent::handleChildElement($n, $publication);
}
}
43 changes: 43 additions & 0 deletions filter/import/NativeXmlJournalFilter.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function handleChildElement($node, $journal)
'extended_issues' => 'parseIssues',
'extended_issue' => 'parseIssue',
'extended_articles' => 'parseArticles',
'metrics' => 'parseMetrics'
];

if ($node instanceof DOMElement) {
Expand Down Expand Up @@ -427,6 +428,48 @@ public function parseArticle($node, $journal)
return $importFilter->execute($articleDoc);
}

public function parseMetrics($node, $journal)
{
$deployment = $this->getDeployment();

$metricKeys = [
'assoc_type', 'day', 'country_id', 'region', 'city', 'file_type', 'metric', 'metric_type', 'load_id'
];

for ($childNode = $node->firstChild; $childNode !== null; $childNode = $childNode->nextSibling) {
if (is_a($childNode, 'DOMElement') && $childNode->tagName === 'metric') {
$record = [];
foreach ($metricKeys as $key) {
$record[$key] = $childNode->getAttribute($key);
}
$oldAssocId = $childNode->getAttribute('assoc_id');
switch ($record['assoc_type']) {
case ASSOC_TYPE_SUBMISSION_FILE:
case ASSOC_TYPE_SUBMISSION_FILE_COUNTER_OTHER:
$record['assoc_id'] = $deployment->getSubmissionFileDBId($oldAssocId);
break;
case ASSOC_TYPE_REPRESENTATION:
$record['assoc_id'] = $deployment->getRepresentationDBId($oldAssocId);
break;
case ASSOC_TYPE_SUBMISSION:
$record['assoc_id'] = $deployment->getSubmissionDBId($oldAssocId);
break;
case Application::getContextAssocType():
$record['assoc_id'] = $journal->getId();
break;
case ASSOC_TYPE_ISSUE_GALLEY:
$record['assoc_id'] = $deployment->getIssueGalleyDBId($oldAssocId);
break;
case ASSOC_TYPE_ISSUE:
$record['assoc_id'] = $deployment->getIssueDBId($oldAssocId);
break;
}
$metricsDAO = DAORegistry::getDAO('MetricsDAO');
$metricsDAO->insertRecord($record);
}
}
}

private function getSimpleJournalNodeMapping()
{
return [
Expand Down
Loading

0 comments on commit 643a749

Please sign in to comment.