Skip to content

Commit

Permalink
Allow overwriting resources re #10798
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed May 7, 2024
1 parent 9f7fe1b commit 1d7a968
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
25 changes: 14 additions & 11 deletions arches/app/etl_modules/base_import_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,13 @@ def get_node_lookup(self, nodes):
return lookup

def run_load_task(self, userid, files, summary, result, temp_dir, loadid):
self.loadid = loadid # currently redundant, but be certain
try:
with connection.cursor() as cursor:
self.stage_files(files, summary, cursor)
cursor.execute("""CALL __arches_check_tile_cardinality_violation_for_load(%s)""", [loadid])
cursor.execute(
"""
INSERT INTO load_errors (type, source, error, loadid, nodegroupid)
SELECT 'tile', source_description, error_message, loadid, nodegroupid
FROM load_staging
WHERE loadid = %s AND passes_validation = false AND error_message IS NOT null
""",
[loadid],
)
self.check_tile_cardinality(cursor)
result["validation"] = self.validate(loadid)
if len(result["validation"]["data"]) == 0:
self.loadid = loadid # currently redundant, but be certain
save_to_tiles(userid, loadid)
cursor.execute("""CALL __arches_update_resource_x_resource_with_graphids();""")
cursor.execute("""SELECT __arches_refresh_spatial_views();""")
Expand Down Expand Up @@ -229,6 +220,18 @@ def stage_files(self, files, summary, cursor):
def stage_excel_file(self, file, summary, cursor):
pass

def check_tile_cardinality(self, cursor):
cursor.execute("""CALL __arches_check_tile_cardinality_violation_for_load(%s)""", [self.loadid])
cursor.execute(
"""
INSERT INTO load_errors (type, source, error, loadid, nodegroupid)
SELECT 'tile', source_description, error_message, loadid, nodegroupid
FROM load_staging
WHERE loadid = %s AND passes_validation = false AND error_message IS NOT null
""",
[self.loadid],
)

### Actions ###

def validate(self, loadid):
Expand Down
10 changes: 9 additions & 1 deletion arches/app/etl_modules/jsonld_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from django.core.files import File
from django.core.files.storage import default_storage
from django.core.management import call_command
from django.db import transaction
from django.utils.translation import gettext as _

from arches.app.utils.data_management.resources.formats.rdffile import ValueErrorWithNodeInfo
from arches.app.etl_modules.base_import_module import BaseImportModule, FileValidationError
from arches.app.etl_modules.decorators import load_data_async
from arches.app.models.models import GraphModel, LoadErrors, LoadEvent, LoadStaging, Node
from arches.app.models.models import GraphModel, LoadErrors, LoadEvent, LoadStaging, Node, ResourceInstance
from arches.app.models.system_settings import settings
from arches.app.utils.file_validator import FileValidator

Expand Down Expand Up @@ -263,6 +264,13 @@ def save_validation_errors(self, validation_errors, tile, source_value, datatype
le.clean_fields()
le.save()

def check_tile_cardinality(self, cursor):
with transaction.atomic():
ResourceInstance.objects.filter(
pk__in=LoadStaging.objects.filter(load_event_id=self.loadid).values("resourceid")
).delete()
return super().check_tile_cardinality(cursor)

@load_data_async
def run_load_task_async(self, request):
raise NotImplementedError
2 changes: 1 addition & 1 deletion arches/app/models/migrations/10798_jsonld_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def add_jsonld_module(apps, schema_editor):
"modulename": "jsonld_importer.py",
"classname": "JSONLDImporter",
"config": {"bgColor": "#726a5b", "circleColor": "#9f9580", "show": True},
"reversible": True,
"reversible": False, # does not support un-overwriting a resource
"slug": "jsonld-importer",
"description": "Import a zip archive of JSON-LD resources to Arches",
"helptemplate": "jsonld-importer-help",
Expand Down

0 comments on commit 1d7a968

Please sign in to comment.