Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve IPT sync view #9

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions grails-app/controllers/au/org/ala/collectory/IptController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class IptController {
def collectoryAuthService
def iptService
def providerGroupService
def dataResourceService

/**
* Scan an IPT instance described by a data provider and provide a list of datasets that need to be updated.
Expand Down Expand Up @@ -230,8 +231,6 @@ class IptController {
def syncView() {

def provider = providerGroupService._get(params.uid)
def sortBy = params.sort ?: "title"
def sortDirection = params.order ?: "asc"
def onlyUnsynced = Boolean.parseBoolean(params.onlyUnsynced ?: "false")
def result = []
def iptTotalCount = 0
Expand All @@ -244,6 +243,8 @@ class IptController {
dataResourceMap.put(it.gbifRegistryKey, it)
}

def dataResourceRecordCountMap = dataResourceService.getDataresourceRecordCounts()

def iptInventory = new JsonSlurper().parse(new URL(provider.websiteUrl + "/inventory/dataset"))
iptInventory.registeredResources.each {

Expand All @@ -262,9 +263,7 @@ class IptController {
if (dataResource) {
row.uid = dataResource.uid
row.atlasPublished = dataResource.dataCurrency.toLocalDateTime().toLocalDate().toString()
def countUrl = grailsApplication.config.biocacheServicesUrl + "/occurrences/search?pageSize=0&fq=data_resource_uid:" + dataResource.uid
def countJson = new JsonSlurper().parse(new URL(countUrl))
row.atlasCount = it.type == "CHECKLIST" ? null : countJson.totalRecords
row.atlasCount = it.type == "CHECKLIST" ? null : dataResourceRecordCountMap.getOrDefault(row.uid, 0)
}

iptTotalCount += (row.iptCount ?: 0)
Expand All @@ -276,18 +275,15 @@ class IptController {
}
}

result.sort { it[sortBy] }
if (sortDirection == "desc") {
result = result.reverse()
}
result.sort { it["title"] }
}

[result: result,
iptTotalCount: iptTotalCount,
atlasTotalCount: atlasTotalCount,
instance: provider,
sortBy: sortBy,
sortDirection: sortDirection,
onlyUnsynced: onlyUnsynced]
[
result: result,
iptTotalCount: iptTotalCount,
atlasTotalCount: atlasTotalCount,
instance: provider,
onlyUnsynced: onlyUnsynced
]
}
}
158 changes: 75 additions & 83 deletions grails-app/views/ipt/syncView.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -10,105 +10,97 @@
/>
<title>${instance.name} vs Atlas</title>
<asset:stylesheet src="application.css" />
<asset:javascript src="application-pages.js"/>
</head>
<body>
<div class="body">
<h1>${instance.name} vs Atlas</h1>
<div>
${result.size} <g:if test="${onlyUnsynced}">unsynced</g:if> datasets &bull;
<a href="/ipt/syncView?uid=${instance.uid}&sort=${sortBy}&order=${sortDirection}&onlyUnsynced=${!onlyUnsynced}">
<a href="/ipt/syncView?uid=${instance.uid}&onlyUnsynced=${!onlyUnsynced}">
Show <g:if test="${onlyUnsynced}">all</g:if><g:else>only unsynced</g:else> datasets
</a>
</div>
<table style="margin-top: 8px">
<tr>
<th>
<a href="/ipt/syncView?uid=${instance.uid}&onlyUnsynced=${onlyUnsynced}&sort=title&order=${sortBy=="title" && sortDirection=="asc" ? "desc" : "asc"}">
Title
</a>
</th>
<th>
<a href="/ipt/syncView?uid=${instance.uid}&onlyUnsynced=${onlyUnsynced}&sort=uid&order=${sortBy=="uid" && sortDirection=="asc" ? "desc" : "asc"}">
UID
</a>
</th>
<th>
<a href="/ipt/syncView?uid=${instance.uid}&onlyUnsynced=${onlyUnsynced}&sort=type&order=${sortBy=="type" && sortDirection=="asc" ? "desc" : "asc"}">
Type
</a>
</th>
<th style="xtext-align: right">
<a href="/ipt/syncView?uid=${instance.uid}&onlyUnsynced=${onlyUnsynced}&sort=iptPublished&order=${sortBy=="iptPublished" && sortDirection=="asc" ? "desc" : "asc"}">
IPT date
</a>
</th>
<th style="xtext-align: right">
<a href="/ipt/syncView?uid=${instance.uid}&onlyUnsynced=${onlyUnsynced}&sort=atlasPublished&order=${sortBy=="atlasPublished" && sortDirection=="asc" ? "desc" : "asc"}">
Atlas date
</a>
</th>
<th style="text-align: right">
<a href="/ipt/syncView?uid=${instance.uid}&onlyUnsynced=${onlyUnsynced}&sort=iptCount&order=${sortBy=="iptCount" && sortDirection=="asc" ? "desc" : "asc"}">
IPT count
</a>
</th>
<th style="text-align: right">
<a href="/ipt/syncView?uid=${instance.uid}&onlyUnsynced=${onlyUnsynced}&sort=atlasCount&order=${sortBy=="atlasCount" && sortDirection=="asc" ? "desc" : "asc"}">
Atlas count
</a>
</th>
</tr>
<g:each in="${result}" var="item">
<table id="dataset-table" class="table">
<thead>
<tr>
<td>
${item.title}<br>
<a href="${item.iptUrl}">IPT</a>&nbsp;&nbsp;
<a href="/public/showDataResource/${item.uid}">Atlas</a>
</td>
<td>
${item.uid}
</td>
<td>
${item.type}
</td>
<td>
${item.iptPublished}
<th>Title</th>
<th>UID</th>
<th>Type</th>
<th>IPT date</th>
<th>Atlas date</th>
<th style="text-align: right">IPT count</th>
<th style="text-align: right">Atlas count</th>
<th style="text-align: right">Diff</th>
</tr>
</thead>
<tbody>
<g:each in="${result}" var="item">
<tr>
<td>
${item.title}<br>
<a href="${item.iptUrl}">IPT</a>&nbsp;&nbsp;
<a href="/public/showDataResource/${item.uid}">Atlas</a>
</td>
<td>
${item.uid}
</td>
<td>
${item.type}
</td>
<td>
${item.iptPublished}
</td>
<td <g:if test="${item.iptPublished != item.atlasPublished}">style="color: red"</g:if>>
${item.atlasPublished}
</td>
<td style="text-align: right;">
<g:formatNumber number="${item.iptCount}" format="###,###,##0" />
</td>
<td style="text-align: right; <g:if test="${item.iptCount != item.atlasCount}">color: red</g:if>">
<g:formatNumber number="${item.atlasCount}" format="###,###,##0" />
</td>
<td style="text-align: right; color: red">
<g:if test="${item.iptCount != item.atlasCount}">
<g:formatNumber number="${item.atlasCount - item.iptCount}" format="+###,###,##0;-###,###,##0" />
</g:if>
</td>
</tr>
</g:each>
</tbody>
<tfoot>
<tr>
<td style="font-style: italic">
Total all datasets
</td>
<td <g:if test="${item.iptPublished != item.atlasPublished}">style="color: red"</g:if>>
${item.atlasPublished}
<td></td>
<td></td>
<td></td>
<td></td>
<td style="text-align: right">
<em><g:formatNumber number="${iptTotalCount}" format="###,###,##0" /></em>
</td>
<td style="text-align: right;">
<g:formatNumber number="${item.iptCount}" format="###,###,##0" />
<td style="text-align: right; <g:if test="${iptTotalCount != atlasTotalCount}">color: red</g:if>">
<em><g:formatNumber number="${atlasTotalCount}" format="###,###,##0" /></em>
</td>
<td style="text-align: right; <g:if test="${item.iptCount != item.atlasCount}">color: red</g:if>">
<g:formatNumber number="${item.atlasCount}" format="###,###,##0" />
<g:if test="${item.iptCount != item.atlasCount}">
<br>
(<g:formatNumber number="${item.atlasCount - item.iptCount}" format="+###,###,##0;-###,###,##0" />)
<td style="text-align: right; color: red">
<g:if test="${iptTotalCount != atlasTotalCount}">
<em><g:formatNumber number="${atlasTotalCount - iptTotalCount}" format="+###,###,##0;-###,###,##0" /></em>
</g:if>
</td>
</tr>
</g:each>
<tr>
<td style="font-style: italic">
Total all datasets
</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td style="text-align: right">
<em><g:formatNumber number="${iptTotalCount}" format="###,###,##0" /></em>
</td>
<td style="text-align: right; font-style: italic; <g:if test="${iptTotalCount != atlasTotalCount}">color: red</g:if>">
<em><g:formatNumber number="${atlasTotalCount}" format="###,###,##0" /></em>
<g:if test="${iptTotalCount != atlasTotalCount}">
<br>
(<g:formatNumber number="${atlasTotalCount - iptTotalCount}" format="+###,###,##0;-###,###,##0" />)
</g:if>
</td>
</tr>
</tfoot>
</table>

</div>
<script type="text/javascript">
$(document).ready(function() {
$('#dataset-table').DataTable({
paging: false,
searching: false,
info: false,
columnDefs: [{ type: 'num-fmt', targets: [5, 6, 7] }],
});
});
</script>
</body>
</html>