Skip to content

Commit

Permalink
Always produce report with split clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
kwahlin committed Apr 25, 2023
1 parent 7e2aab5 commit 6c1f93d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
30 changes: 21 additions & 9 deletions whelktool/src/main/groovy/datatool/scripts/mergeworks/Html.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,39 @@ class Html {
}

static String hubTable(List<Collection<Doc>> docs) {
def mergedWorks = docs*.first()
def ids = docs.collect { group ->
group.drop(1).collectEntries { doc ->
def mergedWorks = []
def derivedFromIds = []

docs.each {
def work = it.head()
def derivedFrom = it.tail()
mergedWorks.add(work)
derivedFromIds.add(derivedFrom.collectEntries { doc ->
[doc.doc.shortId, doc.view.link()]
}
})
}
def clusterId = clusterId(ids*.keySet().flatten())

def clusterId = clusterId(derivedFromIds*.keySet().flatten())

String header = """
<tr>
<th><a id="${clusterId}"><a href="#${clusterId}">${clusterId}</th>
${mergedWorks.collect { "<th></th>" }.join('\n')}
${docs.collect {
def work = it.head()
def derivedFrom = it.tail()
derivedFrom.size() > 1 || it instanceof UpdatedWork
? "<th><a id=\"${work.doc.shortId}\" href=\"${work.view.link()}\">${work.doc.shortId}</a></th>"
: "<th></th>" }
.join('\n')}
</tr>
""".stripIndent()

String derivedFrom =
"""
<tr class="info">
<td>_derivedFrom</td>
${ids.collect { "<td>${it.collect { id, link -> "<a id=\"$id\" href=\"$link\">$id</a>" }.join('<br>')}</td>" }.join('\n')}
</tr>
<td>_instances</td>
${derivedFromIds.collect { "<td>${it.collect { id, link -> "<a id=\"$id\" href=\"$link\">$id</a>" }.join('<br>')}</td>" }.join('\n')}
</tr>
""".stripIndent()

def statuses = WorkComparator.compare(mergedWorks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,19 @@ class WorkToolJob {

void merge() {
def s = statistics.printOnShutdown()
def multiWorkClusters = Collections.synchronizedList([])

run({ cluster ->
return {
def titles = titleClusters(cluster)
def works = mergedWorks(titles)

def needsStore = { it instanceof UpdatedWork || it.derivedFrom.size() > 1 }
def storedWorks = works.findAll(needsStore).each { store(it) }
if (works.size() > 1) {
multiWorkClusters.add(works.collect { [new Doc(whelk, it.doc)] + it.derivedFrom })
}

def multiInstanceWorks = works.findAll { it.derivedFrom.size() > 1 || it instanceof UpdatedWork }
def storedWorks = multiInstanceWorks.each { store(it) }

String report = htmlReport(titles, storedWorks)

Expand All @@ -155,6 +160,14 @@ class WorkToolJob {
}
}
})

new File(reportDir, "multi-work-clusters.html").with {f ->
f.append(Html.START)
multiWorkClusters.each {
f.append(Html.hubTable(it) + Html.HORIZONTAL_RULE)
}
f.append(Html.END)
}
}

void revert() {
Expand Down Expand Up @@ -226,8 +239,7 @@ class WorkToolJob {
LegacyIntegrationTools.determineLegacyCollection(work.doc, whelk.getJsonld()), false)) {
throw new WhelkRuntimeException("Could not store new work: ${work.doc.shortId}")
}
}
else if (work instanceof UpdatedWork) {
} else if (work instanceof UpdatedWork) {
whelk.storeAtomicUpdate(work.doc, !loud, false, changedIn, generationProcess, work.checksum)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Id implements ValuePicker {

@Override
boolean isCompatible(Object a, Object b) {
return !a || !b
return true
}

@Override
Expand Down

0 comments on commit 6c1f93d

Please sign in to comment.