Skip to content

Commit

Permalink
Read license information from licenseNote in premis access condition (#…
Browse files Browse the repository at this point in the history
…2695)

* Read license information from licenseNote in premis access condition

Co-Authored-By: Ashley Ray <a.ray@wellcome.org>

* Apply auto-formatting rules

* remove vestigial test

---------

Co-authored-by: Ashley Ray <a.ray@wellcome.org>
Co-authored-by: Buildkite on behalf of Wellcome Collection <wellcomedigitalplatform@wellcome.ac.uk>
  • Loading branch information
3 people authored Sep 4, 2024
1 parent d98add7 commit 30ecdac
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package weco.pipeline.transformer.mets.transformers
import grizzled.slf4j.Logging
import weco.pipeline.transformer.result.Result

import scala.xml.Node
Expand All @@ -18,7 +19,7 @@ case class PremisAccessConditions(
)
}

object PremisAccessConditions {
object PremisAccessConditions extends Logging {

/** The access conditions are encoded a premis elementin the METS. For
* example:
Expand Down Expand Up @@ -51,14 +52,41 @@ object PremisAccessConditions {
*/
def apply(rightsMd: Node): PremisAccessConditions = {
val rightsStatement = rightsMd \ "mdWrap" \ "xmlData" \ "rightsStatement"

val rightsBasis = (rightsStatement \ "rightsBasis").headOption

// Copyright specific information is held in the copyrightNote element
val copyrightNoteElem =
(rightsStatement \ "copyrightInformation" \ "copyrightNote").headOption

// CC license information is indicated in the licenseNote element
val licenseNoteElem =
(rightsStatement \ "licenseInformation" \ "licenseNote").headOption

// Following discussion with a.ray here:
// https://wellcome.slack.com/archives/C02ANCYL90E/p1725026316294549
val rightsNote = rightsBasis match {
case Some(basis) if basis.text == "Copyright" => copyrightNoteElem
case Some(basis) if basis.text == "License" => licenseNoteElem

// If we don't have a rightsBasis, pick from either copyright or
// license preferring copyright
case _ =>
warn(s"rightsBasis not found in rightsMD!")

List(
copyrightNoteElem,
licenseNoteElem
).flatten.headOption
}

val useRightsElem =
((rightsStatement \ "rightsGranted").filter(
n => (n \ "act").text == "use"
) \ "rightsGrantedNote").headOption

PremisAccessConditions(
copyrightNote = copyrightNoteElem.map(_.text),
copyrightNote = rightsNote.map(_.text),
useRightsGrantedNote = useRightsElem.map(_.text)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,21 @@ import scala.xml.Elem
trait PremisAccessConditionsGenerators {

def rightsMDWith(
copyrightInformation: Option[Elem] = None,
licenceInformation: Option[Elem] = None,
rightsGranted: Seq[Elem] = Nil
): Elem = <mets:rightsMD ID="rightsMD_1">
copyrightInformation: Option[Elem] = None,
licenceInformation: Option[Elem] = None,
rightsGranted: Seq[Elem] = Nil
): Elem = <mets:rightsMD ID="rightsMD_1">
<mets:mdWrap MDTYPE="PREMIS:RIGHTS">
<mets:xmlData>
<premis:rightsStatement xmlns:premis="http://www.loc.gov/premis/v3" xsi:schemaLocation="http://www.loc.gov/premis/v3 http://www.loc.gov/standards/premis/v3/premis.xsd">
<premis:rightsStatementIdentifier>
<premis:rightsStatementIdentifierType>UUID</premis:rightsStatementIdentifierType>
<premis:rightsStatementIdentifierValue>3392668a-4503-462c-ba68-1d17c853f17c</premis:rightsStatementIdentifierValue>
</premis:rightsStatementIdentifier>
<premis:rightsBasis>???</premis:rightsBasis>
{copyrightInformation}
{licenceInformation}
{rightsGranted}
</premis:rightsStatement>
</mets:xmlData>
</mets:mdWrap>
<mets:xmlData>
<premis:rightsStatement xmlns:premis="http://www.loc.gov/premis/v3" xsi:schemaLocation="http://www.loc.gov/premis/v3 http://www.loc.gov/standards/premis/v3/premis.xsd">
<premis:rightsStatementIdentifier>
<premis:rightsStatementIdentifierType>UUID</premis:rightsStatementIdentifierType>
<premis:rightsStatementIdentifierValue>3392668a-4503-462c-ba68-1d17c853f17c</premis:rightsStatementIdentifierValue>
</premis:rightsStatementIdentifier>
<premis:rightsBasis>???</premis:rightsBasis>{copyrightInformation}{licenceInformation}{rightsGranted}
</premis:rightsStatement>
</mets:xmlData>
</mets:mdWrap>
</mets:rightsMD>

lazy val emptyRightsMD = rightsMDWith(None, None, Nil)
Expand Down Expand Up @@ -54,4 +51,64 @@ trait PremisAccessConditionsGenerators {
</mets:xmlData>
</mets:mdWrap>
</mets:rightsMD>

val openCCBYNCRightsMD = <mets:rightsMD ID="rightsMD_1">
<mets:mdWrap MDTYPE="PREMIS:RIGHTS">
<mets:xmlData>
<premis:rightsStatement xmlns:premis="http://www.loc.gov/premis/v3" xsi:schemaLocation="http://www.loc.gov/premis/v3 http://www.loc.gov/standards/premis/v3/premis.xsd">
<premis:rightsStatementIdentifier>
<premis:rightsStatementIdentifierType>UUID</premis:rightsStatementIdentifierType>
<premis:rightsStatementIdentifierValue>a93acc1b-7978-4107-80f7-a4bdf5787a85</premis:rightsStatementIdentifierValue>
</premis:rightsStatementIdentifier>
<premis:rightsBasis>License</premis:rightsBasis>
<premis:licenseInformation>
<premis:licenseTerms/>
<premis:licenseNote>CC-BY-NC</premis:licenseNote>
</premis:licenseInformation>
<premis:rightsGranted>
<premis:act>use</premis:act>
<premis:rightsGrantedNote>Open</premis:rightsGrantedNote>
</premis:rightsGranted>
<premis:linkingObjectIdentifier>
<premis:linkingObjectIdentifierType>UUID</premis:linkingObjectIdentifierType>
<premis:linkingObjectIdentifierValue>433cbf46-4ce1-421d-bf4f-2bc13f9450a7</premis:linkingObjectIdentifierValue>
</premis:linkingObjectIdentifier>
</premis:rightsStatement>
</mets:xmlData>
</mets:mdWrap>
</mets:rightsMD>

// This should never happen in practice, as we should always have a rightsBasis
// but we fail gracefully if it does, preferring copyrightInformation
val openMixedCCBYNCWithCopyrightRightsMD = <mets:rightsMD ID="rightsMD_1">
<mets:mdWrap MDTYPE="PREMIS:RIGHTS">
<mets:xmlData>
<premis:rightsStatement xmlns:premis="http://www.loc.gov/premis/v3" xsi:schemaLocation="http://www.loc.gov/premis/v3 http://www.loc.gov/standards/premis/v3/premis.xsd">
<premis:rightsStatementIdentifier>
<premis:rightsStatementIdentifierType>UUID</premis:rightsStatementIdentifierType>
<premis:rightsStatementIdentifierValue>a93acc1b-7978-4107-80f7-a4bdf5787a85</premis:rightsStatementIdentifierValue>
</premis:rightsStatementIdentifier>
<premis:licenseInformation>
<premis:licenseTerms/>
<premis:licenseNote>CC-BY-NC</premis:licenseNote>
</premis:licenseInformation>
<premis:copyrightInformation>
<premis:copyrightStatus>copyrighted</premis:copyrightStatus>
<premis:copyrightJurisdiction>UK</premis:copyrightJurisdiction>
<premis:copyrightStatusDeterminationDate/>
<premis:copyrightNote>In copyright</premis:copyrightNote>
</premis:copyrightInformation>
<premis:rightsGranted>
<premis:act>use</premis:act>
<premis:rightsGrantedNote>Open</premis:rightsGrantedNote>
</premis:rightsGranted>
<premis:linkingObjectIdentifier>
<premis:linkingObjectIdentifierType>UUID</premis:linkingObjectIdentifierType>
<premis:linkingObjectIdentifierValue>433cbf46-4ce1-421d-bf4f-2bc13f9450a7</premis:linkingObjectIdentifierValue>
</premis:linkingObjectIdentifier>
</premis:rightsStatement>
</mets:xmlData>
</mets:mdWrap>
</mets:rightsMD>
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ class PremisAccessConditionsTest
Some("Open")
).parse.right.get.accessStatus.get shouldBe AccessStatus.Open
}

it("translates the copyrightNote into a Licence") {
PremisAccessConditions(
Some("In Copyright"),
None
).parse.right.get.licence.get shouldBe License.InCopyright
}

it("has no access conditions if none are given") {
val conditions = PremisAccessConditions(
None,
Expand All @@ -50,13 +52,28 @@ class PremisAccessConditionsTest
}

describe("extracting values from a rightsMD section") {
it("pulls out the copyrightNote for the licence") {
it("pulls out the copyrightNote where rightsBasis is 'Copyright'") {
PremisAccessConditions(
openInCopyrightRightsMD
).copyrightNote shouldBe Some(
"In copyright"
)
}

it("pulls out the licenceNote where rightsBasis is 'License'") {
PremisAccessConditions(
openCCBYNCRightsMD
).copyrightNote shouldBe Some("CC-BY-NC")
}

it("pulls out the copyrightNote where rightsBasis is not specified") {
PremisAccessConditions(
openMixedCCBYNCWithCopyrightRightsMD
).copyrightNote shouldBe Some(
"In copyright"
)
}

it("pulls out the rightsGrantedNote for the access status") {
PremisAccessConditions(
openInCopyrightRightsMD
Expand Down

0 comments on commit 30ecdac

Please sign in to comment.