Skip to content

Commit

Permalink
Add helper constructors for MergeCandidate
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwlchan committed Nov 26, 2021
1 parent da1898b commit 43a792f
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@ package weco.pipeline.matcher
import org.scalatest.concurrent.{Eventually, IntegrationPatience}
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
import weco.catalogue.internal_model.identifiers.IdState
import weco.catalogue.internal_model.Implicits._
import weco.catalogue.internal_model.index.IndexFixtures
import weco.catalogue.internal_model.work.DeletedReason.SuppressedFromSource
import weco.catalogue.internal_model.work.MergeCandidate
import weco.catalogue.internal_model.work.generators.SourceWorkGenerators
import weco.catalogue.internal_model.Implicits._
import weco.fixtures.TimeAssertions
import weco.messaging.fixtures.SQS.QueuePair
import weco.messaging.memory.MemoryMessageSender
import weco.fixtures.TimeAssertions
import weco.pipeline.matcher.fixtures.MatcherFixtures
import weco.pipeline.matcher.generators.WorkStubGenerators
import weco.pipeline.matcher.models.MatcherResult._
import weco.pipeline.matcher.models.{
MatchedIdentifiers,
MatcherResult,
WorkIdentifier,
WorkNode,
WorkStub
import weco.pipeline.matcher.generators.{
MergeCandidateGenerators,
WorkStubGenerators
}
import weco.pipeline.matcher.models.MatcherResult._
import weco.pipeline.matcher.models._
import weco.pipeline.matcher.storage.elastic.ElasticWorkStubRetriever
import weco.pipeline_storage.Retriever
import weco.pipeline_storage.memory.MemoryRetriever
Expand All @@ -37,6 +32,7 @@ class MatcherFeatureTest
with IndexFixtures
with WorkStubGenerators
with SourceWorkGenerators
with MergeCandidateGenerators
with TimeAssertions {

it("processes a single Work with nothing linked to it") {
Expand Down Expand Up @@ -121,31 +117,11 @@ class MatcherFeatureTest
val sierraPhysicalBib = sierraPhysicalIdentifiedWork()

val sierraDigitisedBib = sierraDigitalIdentifiedWork()
.mergeCandidates(
List(
MergeCandidate(
id = IdState.Identified(
canonicalId = sierraPhysicalBib.state.canonicalId,
sourceIdentifier = sierraPhysicalBib.state.sourceIdentifier
),
reason = "Physical/digitised Sierra work"
)
)
)
.mergeCandidates(List(createSierraPairMergeCandidateFor(sierraPhysicalBib)))
.deleted(SuppressedFromSource("Sierra"))

val metsRecord = metsIdentifiedWork()
.mergeCandidates(
List(
MergeCandidate(
id = IdState.Identified(
canonicalId = sierraDigitisedBib.state.canonicalId,
sourceIdentifier = sierraDigitisedBib.state.sourceIdentifier
),
reason = "METS work"
)
)
)
.mergeCandidates(List(createMetsMergeCandidateFor(sierraDigitisedBib)))

val works = Seq(sierraPhysicalBib, sierraDigitisedBib, metsRecord)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package weco.pipeline.matcher.generators

import weco.catalogue.internal_model.identifiers.{IdState, IdentifierType}
import weco.catalogue.internal_model.work.{MergeCandidate, Work, WorkState}

trait MergeCandidateGenerators {
def createSierraPairMergeCandidateFor(w: Work[WorkState.Identified]): MergeCandidate[IdState.Identified] = {
require(w.state.sourceIdentifier.identifierType == IdentifierType.SierraSystemNumber)

MergeCandidate(
id = IdState.Identified(
canonicalId = w.state.canonicalId,
sourceIdentifier = w.state.sourceIdentifier
),
reason = "Physical/digitised Sierra work"
)
}

def createMetsMergeCandidateFor(w: Work[WorkState.Identified]): MergeCandidate[IdState.Identified] = {
require(w.state.sourceIdentifier.identifierType == IdentifierType.SierraSystemNumber)

MergeCandidate(
id = IdState.Identified(
canonicalId = w.state.canonicalId,
sourceIdentifier = w.state.sourceIdentifier
),
reason = "METS work"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package weco.pipeline.merger
import org.scalatest.GivenWhenThen
import org.scalatest.featurespec.AnyFeatureSpec
import org.scalatest.matchers.should.Matchers
import weco.catalogue.internal_model.identifiers.IdState
import weco.catalogue.internal_model.work.Format
import weco.catalogue.internal_model.work.generators.SourceWorkGenerators
import weco.catalogue.internal_model.work.{Format, MergeCandidate}
import weco.pipeline.matcher.generators.MergeCandidateGenerators
import weco.pipeline.merger.fixtures.FeatureTestSugar
import weco.pipeline.merger.services.PlatformMerger

Expand All @@ -14,6 +14,7 @@ class MergerScenarioTest
with GivenWhenThen
with Matchers
with FeatureTestSugar
with MergeCandidateGenerators
with SourceWorkGenerators {
val merger = PlatformMerger

Expand Down Expand Up @@ -158,17 +159,7 @@ class MergerScenarioTest
val physicalVideo =
sierraPhysicalIdentifiedWork()
.format(Format.Videos)
.mergeCandidates(
List(
MergeCandidate(
id = IdState.Identified(
sourceIdentifier = digitisedVideo.sourceIdentifier,
canonicalId = digitisedVideo.state.canonicalId
),
reason = "Physical/digitised Sierra work"
)
)
)
.mergeCandidates(List(createSierraPairMergeCandidateFor(digitisedVideo)))

When("the works are merged")
val outcome = merger.merge(Seq(physicalVideo, digitisedVideo))
Expand Down Expand Up @@ -289,32 +280,13 @@ class MergerScenarioTest
.title("A work for an e-bib")
.format(Format.Videos)
.mergeCandidates(
List(
MergeCandidate(
id = IdState.Identified(
canonicalId = workWithPhysicalVideoFormats.state.canonicalId,
sourceIdentifier =
workWithPhysicalVideoFormats.sourceIdentifier
),
reason = "Physical/digitised Sierra work"
)
)
List(createSierraPairMergeCandidateFor(workWithPhysicalVideoFormats))
)

val workForMets =
identifiedWork(sourceIdentifier = createMetsSourceIdentifier)
.title("A METS work")
.mergeCandidates(
List(
MergeCandidate(
id = IdState.Identified(
canonicalId = workForEbib.state.canonicalId,
sourceIdentifier = workForEbib.sourceIdentifier
),
reason = "METS work"
)
)
)
.mergeCandidates(List(createMetsMergeCandidateFor(workForEbib)))
.items(List(createDigitalItem))
.invisible()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import weco.catalogue.internal_model.work.generators.{
SierraWorkGenerators
}
import weco.catalogue.internal_model.work.{Format, MergeCandidate}
import weco.pipeline.matcher.generators.MergeCandidateGenerators

class SourcesTest
extends AnyFunSpec
with Matchers
with CalmWorkGenerators
with SierraWorkGenerators {
with SierraWorkGenerators
with MergeCandidateGenerators {
describe("findFirstLinkedDigitisedSierraWorkFor") {
it("returns None if there are no source Works") {
val physicalWork = sierraPhysicalIdentifiedWork()
Expand All @@ -32,18 +34,8 @@ class SourcesTest
sierraPhysicalIdentifiedWork()
.mergeCandidates(
List(
MergeCandidate(
id = IdState.Identified(
sourceIdentifier = digitisedWork1.sourceIdentifier,
canonicalId = digitisedWork1.state.canonicalId),
reason = "Physical/digitised Sierra work"
),
MergeCandidate(
id = IdState.Identified(
sourceIdentifier = digitisedWork2.sourceIdentifier,
canonicalId = digitisedWork2.state.canonicalId),
reason = "Physical/digitised Sierra work"
)
createSierraPairMergeCandidateFor(digitisedWork1),
createSierraPairMergeCandidateFor(digitisedWork2),
)
)

Expand All @@ -63,14 +55,7 @@ class SourcesTest
val digitisedWork =
sierraDigitalIdentifiedWork()
.mergeCandidates(
List(
MergeCandidate(
id = IdState.Identified(
sourceIdentifier = physicalWork.sourceIdentifier,
canonicalId = physicalWork.state.canonicalId),
reason = "Physical/digitised Sierra work"
)
)
List(createSierraPairMergeCandidateFor(physicalWork))
)

val result =
Expand Down Expand Up @@ -135,14 +120,7 @@ class SourcesTest
val physicalWork =
calmIdentifiedWork()
.mergeCandidates(
List(
MergeCandidate(
id = IdState.Identified(
sourceIdentifier = digitisedWork.sourceIdentifier,
canonicalId = digitisedWork.state.canonicalId),
reason = "Physical/digitised Sierra work"
)
)
List(createSierraPairMergeCandidateFor(digitisedWork))
)

val result =
Expand All @@ -159,14 +137,7 @@ class SourcesTest
val physicalWork =
sierraDigitalIdentifiedWork()
.mergeCandidates(
List(
MergeCandidate(
id = IdState.Identified(
sourceIdentifier = digitisedWork.sourceIdentifier,
canonicalId = digitisedWork.state.canonicalId),
reason = "Physical/digitised Sierra work"
)
)
List(createSierraPairMergeCandidateFor(digitisedWork))
)

val result =
Expand All @@ -184,14 +155,7 @@ class SourcesTest
sierraPhysicalIdentifiedWork()
.format(Format.Videos)
.mergeCandidates(
List(
MergeCandidate(
id = IdState.Identified(
sourceIdentifier = digitisedWork.sourceIdentifier,
canonicalId = digitisedWork.state.canonicalId),
reason = "Physical/digitised Sierra work"
)
)
List(createSierraPairMergeCandidateFor(digitisedWork))
)

val result =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,17 @@ import org.scalatest.Inside
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
import weco.catalogue.internal_model.identifiers.IdState
import weco.catalogue.internal_model.locations.{
AccessCondition,
AccessMethod,
AccessStatus,
DigitalLocation,
LocationType
}
import weco.catalogue.internal_model.locations._
import weco.catalogue.internal_model.work.generators.SourceWorkGenerators
import weco.catalogue.internal_model.work.{
Format,
Item,
MergeCandidate,
Work,
WorkState
}
import weco.catalogue.internal_model.work.{Format, Item, Work, WorkState}
import weco.pipeline.matcher.generators.MergeCandidateGenerators
import weco.pipeline.merger.models.FieldMergeResult

class ItemsRuleTest
extends AnyFunSpec
with Matchers
with SourceWorkGenerators
with MergeCandidateGenerators
with Inside {
val tei: Work.Visible[WorkState.Identified] =
teiIdentifiedWork()
Expand Down Expand Up @@ -129,15 +119,7 @@ class ItemsRuleTest
val physicalWork =
sierraIdentifiedWork()
.mergeCandidates(
List(
MergeCandidate(
id = IdState.Identified(
canonicalId = digitisedWork.state.canonicalId,
sourceIdentifier = digitisedWork.state.sourceIdentifier
),
reason = "Physical/digitised Sierra work"
)
)
List(createSierraPairMergeCandidateFor(digitisedWork))
)
.items(List(createIdentifiedPhysicalItem))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@ import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.{Inside, Inspectors}
import weco.catalogue.internal_model.identifiers.{
IdState,
IdentifierType,
SourceIdentifier
}
import weco.catalogue.internal_model.work.generators.SourceWorkGenerators
import weco.catalogue.internal_model.work.{
Format,
MergeCandidate,
Work,
WorkState
}
import weco.catalogue.internal_model.work.{Format, Work, WorkState}
import weco.pipeline.matcher.generators.MergeCandidateGenerators
import weco.pipeline.merger.models.FieldMergeResult

class OtherIdentifiersRuleTest
extends AnyFunSpec
with Matchers
with SourceWorkGenerators
with MergeCandidateGenerators
with Inside
with Inspectors {
val nothingWork: Work.Visible[WorkState.Identified] = identifiedWork(
Expand Down Expand Up @@ -72,14 +68,7 @@ class OtherIdentifiersRuleTest
sierraPhysicalIdentifiedWork()
.format(Format.Pictures)
.mergeCandidates(
List(
MergeCandidate(
id = IdState.Identified(
sourceIdentifier = mergeCandidate.sourceIdentifier,
canonicalId = mergeCandidate.state.canonicalId),
reason = "Physical/digitised Sierra work"
)
)
List(createSierraPairMergeCandidateFor(mergeCandidate))
)

val sierraWithDigcode: Work.Visible[WorkState.Identified] =
Expand Down
Loading

0 comments on commit 43a792f

Please sign in to comment.