Skip to content

Commit

Permalink
pkp/pkp-lib#10365 update parsing for onix xml format
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitlinnewson committed Oct 11, 2024
1 parent 8de64df commit eeb492e
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 59 deletions.
4 changes: 2 additions & 2 deletions classes/codelist/ONIXCodelistItemDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ public function _getCache(?string $locale = null): array
public function getFilename(string $locale): string
{
$masterLocale = LocaleInterface::DEFAULT_LOCALE;
$localizedFile = "locale/{$locale}/ONIX_BookProduct_CodeLists.xsd";
$localizedFile = "locale/{$locale}/ONIX_BookProduct_CodeLists.xml";
if (Locale::isLocaleValid($locale) && file_exists($localizedFile)) {
return $localizedFile;
}

// Fall back on the version for the master locale.
return "locale/{$masterLocale}/ONIX_BookProduct_CodeLists.xsd";
return "locale/{$masterLocale}/ONIX_BookProduct_CodeLists.xml";
}

/**
Expand Down
10 changes: 5 additions & 5 deletions classes/codelist/ONIXParserDOMHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ public function startElement(PKPXMLParser|XMLParser $parser, string $tag, array
$this->currentData = null;

switch ($tag) {
case 'xs:simpleType':
case 'CodeListNumber':
if ($attributes['name'] == $this->_listName) {
$this->_foundRequestedList = true;
}
break;
case 'xs:enumeration':
case 'CodeValue':
if ($this->_foundRequestedList) {
$this->_currentValue = $attributes['value'];
$this->_listItems[$this->_currentValue] = []; // initialize the array cell
}
break;
case 'xs:documentation':
case 'CodeDescription':
if ($this->_foundRequestedList) {
$this->_insideDocumentation = true;
}
Expand Down Expand Up @@ -109,10 +109,10 @@ public function characterData(PKPXMLParser|XMLParser $parser, string $data)
public function endElement(PKPXMLParser|XMLParser $parser, string $tag)
{
switch ($tag) {
case 'xs:simpleType':
case 'CodeListNumber':
$this->_foundRequestedList = false;
break;
case 'xs:documentation':
case 'CodeDescription':
$this->_insideDocumentation = false;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion classes/components/forms/context/MastheadForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct($action, $locales, $context, $imageUploadUrl)

/** @var ONIXCodelistItemDAO */
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO');
$codeTypes = $onixCodelistItemDao->getCodes('List44');
$codeTypes = $onixCodelistItemDao->getCodes('44');
$codeTypeOptions = array_map(function ($code, $name) {
return ['value' => $code, 'label' => $name];
}, array_keys($codeTypes), $codeTypes);
Expand Down
6 changes: 3 additions & 3 deletions classes/components/forms/submission/AudienceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function __construct($action, $submission)

/** @var ONIXCodelistItemDAO */
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO');
$audienceCodes = $this->getOptions($onixCodelistItemDao->getCodes('List28'));
$audienceRangeQualifiers = $this->getOptions($onixCodelistItemDao->getCodes('List30'));
$audienceRanges = $this->getOptions($onixCodelistItemDao->getCodes('List77'));
$audienceCodes = $this->getOptions($onixCodelistItemDao->getCodes('28'));
$audienceRangeQualifiers = $this->getOptions($onixCodelistItemDao->getCodes('30'));
$audienceRanges = $this->getOptions($onixCodelistItemDao->getCodes('77'));

$this->addField(new FieldSelect('audience', [
'label' => __('monograph.audience'),
Expand Down
2 changes: 1 addition & 1 deletion classes/publicationFormat/IdentificationCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getCode()
public function getNameForONIXCode()
{
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO'); /** @var ONIXCodelistItemDAO $onixCodelistItemDao */
$codes = & $onixCodelistItemDao->getCodes('List5'); // List5 is for ISBN, GTIN-13, etc.
$codes = & $onixCodelistItemDao->getCodes('5'); // List5 is for ISBN, GTIN-13, etc.
return $codes[$this->getCode()];
}

Expand Down
6 changes: 3 additions & 3 deletions classes/publicationFormat/PublicationDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PublicationDate extends DataObject
public function __construct()
{
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO'); /** @var ONIXCodelistItemDAO $onixCodelistItemDao */
$this->dateFormats = & $onixCodelistItemDao->getCodes('List55');
$this->dateFormats = & $onixCodelistItemDao->getCodes('55');

parent::__construct();
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public function getDateFormat()
public function getNameForONIXCode()
{
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO'); /** @var ONIXCodelistItemDAO $onixCodelistItemDao */
$codes = & $onixCodelistItemDao->getCodes('List163'); // List163 is for Publication date, Embargo date, Announcement date, etc
$codes = & $onixCodelistItemDao->getCodes('163'); // List163 is for Publication date, Embargo date, Announcement date, etc
return $codes[$this->getRole()];
}

Expand Down Expand Up @@ -206,7 +206,7 @@ public function getReadableDates()
$separator = '-';
$containsMonth = false;

for ($i = 0 ; $i < count($formatCharacters) ; $i ++) {
for ($i = 0 ; $i < count($formatCharacters) ; $i++) {
switch ($formatCharacters[$i]) {
// if there is a Time included, change the separator.
// Do not include the number, add a space instead.
Expand Down
8 changes: 4 additions & 4 deletions classes/publicationFormat/PublicationFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @file classes/publicationFormat/PublicationFormat.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class PublicationFormat
Expand Down Expand Up @@ -85,7 +85,7 @@ public function setEntryKey($entryKey)
public function getNameForONIXCode()
{
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO'); /** @var ONIXCodelistItemDAO $onixCodelistItemDao */
$codes = $onixCodelistItemDao->getCodes('List7'); // List7 is for object formats
$codes = $onixCodelistItemDao->getCodes('150'); // List150 is for object formats
return $codes[$this->getEntryKey()];
}

Expand Down Expand Up @@ -270,7 +270,7 @@ public function setWeight($weight)
}

/**
* Get the weight unit code (ONIX value) of the monograph format (List95).
* Get the weight unit code (ONIX value) of the monograph format (List50).
*
* @return string
*/
Expand Down
2 changes: 1 addition & 1 deletion classes/publicationFormat/SalesRights.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getType()
public function getNameForONIXCode()
{
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO'); /** @var ONIXCodelistItemDAO $onixCodelistItemDao */
$codes = & $onixCodelistItemDao->getCodes('List46'); // List46 is for things like 'unrestricted sale with exclusive rights', etc.
$codes = & $onixCodelistItemDao->getCodes('46'); // List46 is for things like 'unrestricted sale with exclusive rights', etc.
return $codes[$this->getType()];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function fetch($request, $template = null, $display = false)
if ($context->areDoisEnabled()) {
$assignedCodes[] = '06'; // 06 is DOI in ONIX-speak.
}
$codes = $onixCodelistItemDao->getCodes('List5', $assignedCodes); // ONIX list for these
$codes = $onixCodelistItemDao->getCodes('5', $assignedCodes); // ONIX list for these
$templateMgr->assign('identificationCodes', $codes);
} else {
throw new \Exception('Format not in authorized submission');
Expand Down
18 changes: 9 additions & 9 deletions controllers/grid/catalogEntry/form/MarketForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ public function fetch($request, $template = null, $display = false)
$market = $this->getMarket();
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO'); /** @var ONIXCodelistItemDAO $onixCodelistItemDao */
$templateMgr->assign([
'countryCodes' => $onixCodelistItemDao->getCodes('List91'), // countries (CA, US, GB, etc)
'regionCodes' => $onixCodelistItemDao->getCodes('List49'), // regions (British Columbia, England, etc)
'publicationDateFormats' => $onixCodelistItemDao->getCodes('List55'), // YYYYMMDD, YYMMDD, etc
'publicationDateRoles' => $onixCodelistItemDao->getCodes('List163'),
'currencyCodes' => $onixCodelistItemDao->getCodes('List96'), // GBP, USD, CAD, etc
'priceTypeCodes' => $onixCodelistItemDao->getCodes('List58'), // without tax, with tax, etc
'extentTypeCodes' => $onixCodelistItemDao->getCodes('List23'), // word count, FM page count, BM page count, main page count, etc
'taxRateCodes' => $onixCodelistItemDao->getCodes('List62'), // higher rate, standard rate, zero rate
'taxTypeCodes' => $onixCodelistItemDao->getCodes('List171'), // VAT, GST
'countryCodes' => $onixCodelistItemDao->getCodes('91'), // countries (CA, US, GB, etc)
'regionCodes' => $onixCodelistItemDao->getCodes('49'), // regions (British Columbia, England, etc)
'publicationDateFormats' => $onixCodelistItemDao->getCodes('55'), // YYYYMMDD, YYMMDD, etc
'publicationDateRoles' => $onixCodelistItemDao->getCodes('163'),
'currencyCodes' => $onixCodelistItemDao->getCodes('96'), // GBP, USD, CAD, etc
'priceTypeCodes' => $onixCodelistItemDao->getCodes('58'), // without tax, with tax, etc
'extentTypeCodes' => $onixCodelistItemDao->getCodes('23'), // word count, FM page count, BM page count, main page count, etc
'taxRateCodes' => $onixCodelistItemDao->getCodes('62'), // higher rate, standard rate, zero rate
'taxTypeCodes' => $onixCodelistItemDao->getCodes('171'), // VAT, GST
]);

/** @var RepresentativeDAO */
Expand Down
6 changes: 3 additions & 3 deletions controllers/grid/catalogEntry/form/PublicationDateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function ($date) use ($form) {
if (!$dateFormat) {
return false;
}
$dateFormats = $onixCodelistItemDao->getCodes('List55');
$dateFormats = $onixCodelistItemDao->getCodes('55');
$format = $dateFormats[$dateFormat];
if (stristr($format, 'string') && $date != '') {
return true;
Expand Down Expand Up @@ -201,11 +201,11 @@ public function fetch($request, $template = null, $display = false)
$assignedRoles = array_diff($assignedRoles, [$publicationDate->getRole()]);
} // allow existing roles to keep their value
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO'); /** @var ONIXCodelistItemDAO $onixCodelistItemDao */
$roles = $onixCodelistItemDao->getCodes('List163', $assignedRoles); // ONIX list for these
$roles = $onixCodelistItemDao->getCodes('163', $assignedRoles); // ONIX list for these
$templateMgr->assign('publicationDateRoles', $roles);

//load our date formats
$dateFormats = $onixCodelistItemDao->getCodes('List55');
$dateFormats = $onixCodelistItemDao->getCodes('55');
$templateMgr->assign('publicationDateFormats', $dateFormats);
} else {
throw new Exception('Format not in authorized submission');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function fetch($request, $template = null, $display = false)
{
$templateMgr = TemplateManager::getManager($request);
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO'); /** @var ONIXCodelistItemDAO $onixCodelistItemDao */
$templateMgr->assign('entryKeys', $onixCodelistItemDao->getCodes('List7')); // List7 is for object formats
$templateMgr->assign('entryKeys', $onixCodelistItemDao->getCodes('150')); // List150 is for object formats

$monograph = $this->getMonograph();
$templateMgr->assign('submissionId', $monograph->getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @file controllers/grid/catalogEntry/form/PublicationFormatMetadataForm.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2003-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class PublicationFormatMetadataForm
Expand All @@ -26,6 +26,10 @@
use Exception;
use PKP\db\DAORegistry;
use PKP\form\Form;
use PKP\form\validation\FormValidator;
use PKP\form\validation\FormValidatorCSRF;
use PKP\form\validation\FormValidatorPost;
use PKP\form\validation\FormValidatorRegExp;
use PKP\notification\Notification;
use PKP\plugins\PKPPubIdPluginHelper;
use PKP\plugins\PluginRegistry;
Expand Down Expand Up @@ -86,11 +90,11 @@ public function __construct($submission, $publication, $representation, $isPhysi
$this->_remoteURL = $remoteURL;
$this->_formParams = $formParams;

$this->addCheck(new \PKP\form\validation\FormValidator($this, 'productAvailabilityCode', 'required', 'grid.catalogEntry.productAvailabilityRequired'));
$this->addCheck(new \PKP\form\validation\FormValidatorRegExp($this, 'directSalesPrice', 'optional', 'grid.catalogEntry.validPriceRequired', '/^[0-9]*(\.[0-9]+)?$/'));
$this->addCheck(new \PKP\form\validation\FormValidator($this, 'productCompositionCode', 'required', 'grid.catalogEntry.productCompositionRequired'));
$this->addCheck(new \PKP\form\validation\FormValidatorPost($this));
$this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));
$this->addCheck(new FormValidator($this, 'productAvailabilityCode', 'required', 'grid.catalogEntry.productAvailabilityRequired'));
$this->addCheck(new FormValidatorRegExp($this, 'directSalesPrice', 'optional', 'grid.catalogEntry.validPriceRequired', '/^[0-9]*(\.[0-9]+)?$/'));
$this->addCheck(new FormValidator($this, 'productCompositionCode', 'required', 'grid.catalogEntry.productCompositionRequired'));
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
}

/**
Expand Down Expand Up @@ -126,15 +130,15 @@ public function fetch($request, $template = null, $display = false)

// get the lists associated with the select elements on these publication format forms.
$codes = [
'productCompositionCodes' => 'List2', // single item, multiple item, trade-only, etc
'measurementUnitCodes' => 'List50', // grams, inches, millimeters
'weightUnitCodes' => 'List95', // pounds, grams, ounces
'measurementTypeCodes' => 'List48', // height, width, depth
'productFormDetailCodes' => 'List175', // refinement of product form (SACD, Mass market (rack) paperback, etc)
'productAvailabilityCodes' => 'List65', // Available, In Stock, Print On Demand, Not Yet Available, etc
'technicalProtectionCodes' => 'List144', // None, DRM, Apple DRM, etc
'returnableIndicatorCodes' => 'List66', // No, not returnable, Yes, full copies only, (required for physical items only)
'countriesIncludedCodes' => 'List91', // country region codes
'productCompositionCodes' => '2', // single item, multiple item, trade-only, etc
'measurementUnitCodes' => '50', // grams, inches, millimeters
'weightUnitCodes' => '50', // pounds, grams, ounces
'measurementTypeCodes' => '48', // height, width, depth
'productFormDetailCodes' => '175', // refinement of product form (SACD, Mass market (rack) paperback, etc)
'productAvailabilityCodes' => '65', // Available, In Stock, Print On Demand, Not Yet Available, etc
'technicalProtectionCodes' => '144', // None, DRM, Apple DRM, etc
'returnableIndicatorCodes' => '66', // No, not returnable, Yes, full copies only, (required for physical items only)
'countriesIncludedCodes' => '91', // country region codes
];

foreach ($codes as $templateVarName => $list) {
Expand Down Expand Up @@ -166,7 +170,7 @@ public function initData()

$this->_data = [
'fileSize' => (bool) $publicationFormat->getFileSize() ? $publicationFormat->getFileSize() : $publicationFormat->getCalculatedFileSize(),
'override' => (bool) $publicationFormat->getData('fileSize') ? true : false,
'override' => (bool) $publicationFormat->getData('fileSize'),
'frontMatter' => $publicationFormat->getFrontMatter(),
'backMatter' => $publicationFormat->getBackMatter(),
'height' => $publicationFormat->getHeight(),
Expand Down
6 changes: 3 additions & 3 deletions controllers/grid/catalogEntry/form/RepresentativeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public function fetch($request, $template = null, $display = false)
$representative = $this->getRepresentative();
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO'); /** @var ONIXCodelistItemDAO $onixCodelistItemDao */
$templateMgr->assign([
'idTypeCodes' => $onixCodelistItemDao->getCodes('List92'), // GLN, etc
'agentRoleCodes' => $onixCodelistItemDao->getCodes('List69'), // Sales Agent, etc
'supplierRoleCodes' => $onixCodelistItemDao->getCodes('List93'), // wholesaler, publisher to retailer, etc
'idTypeCodes' => $onixCodelistItemDao->getCodes('92'), // GLN, etc
'agentRoleCodes' => $onixCodelistItemDao->getCodes('69'), // Sales Agent, etc
'supplierRoleCodes' => $onixCodelistItemDao->getCodes('93'), // wholesaler, publisher to retailer, etc
'isSupplier' => true,
]); // default to 'supplier' on the form.

Expand Down
4 changes: 2 additions & 2 deletions controllers/grid/catalogEntry/form/SalesRightsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ public function fetch($request, $template = null, $display = false)
$templateMgr->assign('publicationId', $this->getPublication()->getId());
$salesRights = $this->getSalesRights();
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO'); /** @var ONIXCodelistItemDAO $onixCodelistItemDao */
$templateMgr->assign('countryCodes', $onixCodelistItemDao->getCodes('List91')); // countries (CA, US, GB, etc)
$templateMgr->assign('regionCodes', $onixCodelistItemDao->getCodes('List49')); // regions (British Columbia, England, etc)
$templateMgr->assign('countryCodes', $onixCodelistItemDao->getCodes('91')); // countries (CA, US, GB, etc)
$templateMgr->assign('regionCodes', $onixCodelistItemDao->getCodes('49')); // regions (British Columbia, England, etc)

if ($salesRights) {
$templateMgr->assign('salesRightsId', $salesRights->getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @file plugins/metadata/dc11/filter/Dc11SchemaPublicationFormatAdapter.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2000-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class Dc11SchemaPublicationFormatAdapter
Expand Down Expand Up @@ -147,7 +147,7 @@ public function extractMetadataFromDataObject(&$publicationFormat)

// Format
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO'); /** @var ONIXCodelistItemDAO $onixCodelistItemDao */
$entryKeys = $onixCodelistItemDao->getCodes('List7'); // List7 is for object formats
$entryKeys = $onixCodelistItemDao->getCodes('150'); // List150 is for object formats
if ($publicationFormat->getEntryKey()) {
$formatName = $entryKeys[$publicationFormat->getEntryKey()];
$dc11Description->addStatement('dc:format', $formatName);
Expand Down

0 comments on commit eeb492e

Please sign in to comment.