Skip to content

Commit

Permalink
Merge pull request #480 from folio-org/release_5.0.6
Browse files Browse the repository at this point in the history
fix: Identifier mapping
  • Loading branch information
EthanFreestone authored Nov 12, 2021
2 parents 6c00a51 + 7185fdf commit 740df5d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 5.0.6 2021-11-12
* ERM-1917 Duplicate title instance created on package import in Kiwi bugfest (incoming issn now maps to eissn in system)

## 5.0.5 2021-11-10
* ERM-1917 Duplicate title instance created on package import in Kiwi bugfest

Expand Down
2 changes: 1 addition & 1 deletion service/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ gradleWrapperVersion=5.4

# Application
appName=mod-agreements
appVersion=5.0.5
appVersion=5.0.6
dockerTagSuffix=
dockerRepo=folioci
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,37 @@ class TitleInstanceResolverService implements DataBinder{
identifiers?.findAll( { IdentifierSchema id -> class_one_namespaces?.contains( id.namespace.toLowerCase() ) })?.size() ?: 0
}


// On the rare chance that we have `eissn` in our db (From before Kiwi namespace flattening)
// We attempt to map an incoming `issn` -> `eissn` in our DB
private String mapNamespaceToElectronic(final String incomingNs) {
String ouput;
switch (incomingNs.toLowerCase()) {
case 'issn':
ouput = 'eissn'
break;
case 'isbn':
ouput = 'eisbn'
default:
break;
}
}

// On the rare chance that we have `pissn` in our db (From before Kiwi namespace flattening)
// We attempt to map an incoming `issn` -> `pissn` in our DB
private String mapNamespaceToPrint(final String incomingNs) {
String ouput;
switch (incomingNs.toLowerCase()) {
case 'issn':
ouput = 'pissn'
break;
case 'isbn':
ouput = 'pisbn'
default:
break;
}
}

/**
* Being passed a map of namespace, value pair maps, attempt to locate any title instances with class 1 identifiers (ISSN, ISBN, DOI)
*/
Expand Down Expand Up @@ -532,9 +563,32 @@ class TitleInstanceResolverService implements DataBinder{
* We have to know that eissn == issn etc... Use namespaceMapping function
*/

// TODO we have the possibility for Kiwi that an existing TI is in place with namespace eissn, since cleanup is a complicated matter
// For the time being, allow matching BOTH of `eissn` to `issn` (As per the story), but also `issn` to `eissn` in our db
final List<Identifier> id_matches = Identifier.executeQuery('select id from Identifier as id where id.value = :value and (id.ns.value = :mns or id.ns.value = :ns)',[value:id.value, ns:id.namespace, mns:namespaceMapping(id.namespace)], [max:2])
/* NOTE: We have the possibility for Kiwi that an existing TI is in place with namespace eissn,
* since cleanup is a complicated matter.
* For the time being, allow matching BOTH of `eissn` -> `issn` (As per the story),
* but also `eissn` -> `eissn` AND `issn` -> `eissn` in our db.
* To allow for `eissn` -> `eissn` the (ns:id.namespace) case is sufficient.
* To allow for `issn` -> `eissn` we also need
*/
final List<Identifier> id_matches = Identifier.executeQuery("""
SELECT id FROM Identifier AS id
WHERE
id.value = :value AND
(
id.ns.value = :nsm OR
id.ns.value = :ns OR
id.ns.value = :ens OR
id.ns.value = :pns
)""".toString(),
[
value:id.value,
ns:id.namespace.toLowerCase(),
nsm:namespaceMapping(id.namespace),
ens:mapNamespaceToElectronic(id.namespace),
pns:mapNamespaceToPrint(id.namespace)
],
[max:2]
)

if (id_matches.size() > 1) {
throw new RuntimeException("Multiple (${id_matches.size()}) class one matches found for identifier ${id.namespace}::${id.value}");
Expand Down
15 changes: 12 additions & 3 deletions service/src/main/groovy/org/olf/export/KBart.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ public class KBart implements Serializable {
return header as String[]
}

// This method assumes it is being called on identifiers from within our database. Therefore any eissn or pissn will have been flattened to just issn
// This method assumes it is being called on identifiers from within our database.
// Therefore any eissn or pissn *should* have been flattened to just issn, but may not have been
static String getIdentifierValue(Object identifiers) {
if (identifiers) {
Iterator iter = identifiers.iterator();
Expand All @@ -224,9 +225,17 @@ public class KBart implements Serializable {
while (iter.hasNext()) {
IdentifierOccurrence thisIdent = iter.next()
Identifier ident = thisIdent.identifier
if (ident?.ns?.value == "issn") {
if (
ident?.ns?.value == "issn" ||
ident?.ns?.value == "eissn" ||
ident?.ns?.value == "pissn"
) {
issn = ident.value
} else if (ident?.ns?.value == "isbn") {
} else if (
ident?.ns?.value == "isbn" ||
ident?.ns?.value == "eisbn" ||
ident?.ns?.value == "pisbn"
) {
isbn = ident.value
} else if (ident?.ns?.value == "doi") {
doi = ident.value
Expand Down

0 comments on commit 740df5d

Please sign in to comment.