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

Added title field to the Harvest Error Record Report page with block view #131

Merged
merged 21 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
21 changes: 19 additions & 2 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,17 @@ def get_harvest_job(job_id=None):
page = request.args.get("page")
db_page = int(page) - 1
record_errors = db.get_harvest_record_errors_by_job(job_id, page=db_page)
record_errors_dict = [
{
"error": db._to_dict(row.HarvestRecordError),
"identifier": row.identifier,
"title": json.loads(row.source_raw).get("title", None),
}
for row in record_errors
]
data = {
"harvest_job_id": job_id,
"record_errors": db._to_dict(record_errors),
"record_errors": record_errors_dict,
"htmx_vars": htmx_vars,
}
pagination.update_current(page)
Expand All @@ -668,14 +676,23 @@ def get_harvest_job(job_id=None):
if job_id:
job = db.get_harvest_job(job_id)
record_errors = db.get_harvest_record_errors_by_job(job_id)
record_errors_dict = [
{
"error": db._to_dict(row.HarvestRecordError),
"identifier": row.identifier,
"title": json.loads(row.source_raw).get("title", None),
}
for row in record_errors
]

if request.args.get("type") and request.args.get("type") == "json":
return db._to_dict(job) if job else ("Not Found", 404)
else:
data = {
"harvest_job_id": job_id,
"harvest_job": job,
"harvest_job_dict": db._to_dict(job),
"record_errors": db._to_dict(record_errors),
"record_errors": record_errors_dict,
"htmx_vars": htmx_vars,
}
return render_template(
Expand Down
131 changes: 112 additions & 19 deletions app/templates/view_job_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,41 +73,65 @@ <h2>Job Error Table</h2>
</div>
{% endif %}
</div>

<div class="section">
<h2>Record Error Table</h2>
<h2>Record Error Details</h2>
{% if not data.record_errors %}
No record errors found
<p>No record errors found</p>
{% else %}
{% set error_type = "record" %}
<a href="{{ url_for('harvest.download_harvest_errors_by_job', job_id=data.harvest_job_id, error_type=error_type)}}">
<button class="btn btn-primary">download record errors as .csv</button>
</a>
<button id="toggleViewBtn" onclick="toggleView()">Switch to Table View</button>
Jin-Sun-tts marked this conversation as resolved.
Show resolved Hide resolved
<div class="usa-table-container--scrollable" tabindex="0">
{% block record_errors_table %}
<div id="error_results_pagination">
<div id="blockView" class="error-list">
{% for record_error in data.record_errors %}
<div class="error-block">
<h3>{{ record_error.error.id }}</h3>
<p><strong>Identifier:</strong> {{ record_error.identifier }}</p>
<p><strong>Title:</strong> {{ record_error.title }}</p>
<p><strong>Harvest Record ID:</strong>
<a href="{{ url_for('harvest.get_harvest_record', record_id=record_error.error.harvest_record_id) }}">
Jin-Sun-tts marked this conversation as resolved.
Show resolved Hide resolved
{{ record_error.error.harvest_record_id }}
</a>
</p>
<p><strong>Error Message:</strong> {{ record_error.error.message }}</p>
<p><strong>Type:</strong> {{ record_error.error.type }}</p>
<p><strong>Date Created:</strong> {{ record_error.error.date_created }}</p>

<table class="usa-table usa-table--striped">
</div>
{% endfor %}
</div>
<table id="tableView" class="usa-table usa-table--striped" style="display: none;">
{% set error_type = "record" %}
<a href="{{ url_for('harvest.download_harvest_errors_by_job', job_id=data.harvest_job_id, error_type=error_type)}}">
<button class="btn btn-primary">download record errors as .csv</button>
</a>
<caption> Harvest Record Errors for {{data.harvest_job_id}}</caption>
<thead>
<tr>
<th data-sortable scope="col" role="columnheader">Date Created</th>
<th data-sortable scope="col" role="columnheader">Id</th>
<th data-sortable scope="col" role="columnheader">ID</th>
<th data-sortable scope="col" role="columnheader">Title</th>
<th data-sortable scope="col" role="columnheader">Identifier</th>
<th data-sortable scope="col" role="columnheader">Harvest Record Id</th>
<th data-sortable scope="col" role="columnheader">Message</th>
<th data-sortable scope="col" role="columnheader">Type</th>
</tr>
</thead>
<tbody>
{% for errors in data.record_errors %}
{% for record_error in data.record_errors %}
<tr>
<td data-sort-value={errors.date_created}> {{errors.date_created}}</td>
<td data-sort-value={errors.id}>{{errors.id}}</td>
<td data-sort-value={errors.harvest_record_id}>
<a
href="{{ url_for('harvest.get_harvest_record', record_id=errors.harvest_record_id) }}">
{{errors.harvest_record_id}} </td>
<td data-sort-value={errors.message}>{{errors.message}}</td>
<td data-sort-value={errors.type}>{{errors.type}}</td>
<td data-sort-value="{{ record_error.error.date_created }}"> {{ record_error.error.date_created }}</td>
<td>{{ record_error.error.id }}</td>
<td>{{ record_error.title }}</td>
<td>{{ record_error.identifier }}</td>
<td data-sort-value="{{ record_error.error.harvest_record_id }}">
<a href="{{ url_for('harvest.get_harvest_record', record_id=record_error.error.harvest_record_id) }}">
{{ record_error.error.harvest_record_id }}
</a>
</td>
<td data-sort-value="{{ record_error.error.message }}"> {{ record_error.error.message }}</td>
<td data-sort-value="{{ record_error.error.type }}"> {{ record_error.error.type }}</td>
</tr>
{% endfor %}
{% if pagination.per_page > data.record_errors|count and pagination.count > data.record_errors|count %}
Expand All @@ -124,11 +148,80 @@ <h2>Record Error Table</h2>
{% if pagination.count > data.record_errors|count %}
{% include '/components/pagination/pagination.html' %}
{%endif%}
<script>
document.addEventListener("DOMContentLoaded", function() {
Jin-Sun-tts marked this conversation as resolved.
Show resolved Hide resolved
setTimeout(function() {
let savedView = localStorage.getItem("errorView");
console.log("Applying saved view:", savedView);
if (!savedView) {
localStorage.setItem("errorView", "block");
}
applyView(savedView || "block");
}, 100);
});

function toggleView() {
var currentView = localStorage.getItem("errorView") === "table" ? "block" : "table";
localStorage.setItem("errorView", currentView);
console.log("View changed to:", currentView);
applyView(currentView);
}

function applyView(view) {
console.log("Applying view:", view);

var blockView = document.getElementById("blockView");
var tableView = document.getElementById("tableView");
var toggleBtn = document.getElementById("toggleViewBtn");

if (view === "table") {
blockView.style.display = "none";
tableView.style.display = "block";
toggleBtn.textContent = "Switch to Block View";
} else {
blockView.style.display = "block";
tableView.style.display = "none";
toggleBtn.textContent = "Switch to Table View";
}
}
</script>


<style>
.error-list {
display: flex;
flex-direction: column;
gap: 15px;
}
.error-block {
border: 1px solid #ccc;
padding: 15px;
border-radius: 5px;
background-color: #f9f9f9;
}
.error-block h3 {
margin: 0;
font-size: 1.2em;
font-weight: 900;
}
.error-block p {
margin: 5px 0;
font-size: 1em;
text-indent: 20px;
}
.error-block a {
color: #0071bc;
text-decoration: none;
}
.error-block a:hover {
text-decoration: underline;
}
</style>
Jin-Sun-tts marked this conversation as resolved.
Show resolved Hide resolved
</div>

{% endblock %}
<div class="usa-sr-only usa-table__announcement-region" aria-live="polite"></div>
</div>
<div class="usa-sr-only usa-table__announcement-region" aria-live="polite"></div>
</div>
{% endif %}
</div>
{% endif %}
Expand Down
11 changes: 9 additions & 2 deletions database/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,15 @@ def get_harvest_record_errors_by_job(self, job_id: str, **kwargs):
.filter(HarvestRecord.harvest_job_id == job_id)
.subquery()
)
query = self.db.query(HarvestRecordError).filter(
HarvestRecordError.harvest_record_id.in_(select(subquery))
query = (
self.db.query(
HarvestRecordError,
Jin-Sun-tts marked this conversation as resolved.
Show resolved Hide resolved
Jin-Sun-tts marked this conversation as resolved.
Show resolved Hide resolved
HarvestRecord.identifier,
HarvestRecord.source_raw
)
.join(HarvestRecord,
HarvestRecord.id == HarvestRecordError.harvest_record_id)
.filter(HarvestRecord.id.in_(select(subquery)))
)
return query

Expand Down
9 changes: 7 additions & 2 deletions tests/integration/harvest/test_exception_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,15 @@ def test_validate_nested_exception_handling(
]
job_err = interface.get_harvest_job_errors_by_job(job_id)
record_err = interface.get_harvest_record_errors_by_job(job_id)

record_error, identifier, source_raw = record_err[0]
title = json.loads(source_raw).get("title", None)
assert len(job_err) == 0
assert len(record_err) == 1
assert record_err[0].type == "SynchronizeException"
assert record_err[0].harvest_record_id == records_with_errors[0].id
assert record_error.type == "SynchronizeException"
assert identifier == "cftc-dc2"
assert title == "Commitment of Traders"
assert record_error.harvest_record_id == records_with_errors[0].id
assert (
harvest_records[1].id == records_with_errors[0].id
) ## assert it's the second record that threw the exception, which validates our package_create mock
4 changes: 2 additions & 2 deletions tests/integration/harvest/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def test_invalid_transform_iso19115_2(

job_errors = interface.get_harvest_record_errors_by_job(harvest_job.id)
assert len(job_errors) == 1
assert job_errors[0].message == expected_error_msg
assert job_errors[0][0].message == expected_error_msg
Jin-Sun-tts marked this conversation as resolved.
Show resolved Hide resolved

record = interface.get_harvest_record(job_errors[0].record.id)
record = interface.get_harvest_record(job_errors[0][0].record.id)
assert record.status == "error"

def test_valid_transform_iso19115_2(
Expand Down
Loading