Skip to content

Commit

Permalink
Add/update inconsistent variables, #11117
Browse files Browse the repository at this point in the history
  • Loading branch information
njkim committed Jul 26, 2024
1 parent 3f2ccfb commit 30f611e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
44 changes: 27 additions & 17 deletions arches/app/etl_modules/bulk_edit_concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,20 @@ def perth_items(items):


class BulkConceptEditor(BaseBulkEditor):
def editor_log(self, cursor, tile, node_id, resourceid, old_value):
def editor_log(self, cursor, tile, node_id, resourceid, old_value, new_value):
id = uuid.uuid4()
cursor.execute(
"""INSERT INTO edit_log (editlogid, resourceinstanceid, nodegroupid, tileinstanceid, oldvalue, edittype, transactionid) VALUES (%s, %s, %s, %s, %s, %s, %s)""",
(id, resourceid, node_id, tile, old_value, "tile edit", str(self.loadid)),
"""INSERT INTO edit_log (editlogid, resourceinstanceid, nodegroupid, tileinstanceid, oldvalue, newvalue, edittype, transactionid) VALUES (%s, %s, %s, %s, %s, %s, %s)""",
(
id,
resourceid,
node_id,
tile,
old_value,
new_value,
"tile edit",
str(self.loadid),
),
)

def validate_inputs(self, request):
Expand Down Expand Up @@ -277,12 +286,12 @@ def return_value(self, cursor, resource_ids, node_id, old_id, new_id):

return tile_ids, tiles_data, resources

def edit_staged_data(
def stage_data(
self,
cursor,
graphid,
nodeid,
languageold,
language_old,
resource_ids,
language_new,
oldid,
Expand All @@ -298,7 +307,7 @@ def edit_staged_data(
"node": str(nodeid),
"new": str(newid),
"old": tiledata,
"languageold": languageold,
"languageold": language_old,
"languagenew": language_new,
}
operation = "update"
Expand Down Expand Up @@ -846,11 +855,12 @@ def write(self, request):
"languageold": language_old,
"languagenew": language_new,
}
resourcesid = []
resourceids = []
### get all the resourceids and (-) removed resourceids
for resource in table.split(","):
try:
uuid.UUID(resource)
resourcesid.append(resource)
resourceids.append(resource)
except ValueError:
pass

Expand Down Expand Up @@ -902,17 +912,17 @@ def run_load_task_async(self, request):
id_name_pairs = []
id_name_pairs = [[items[i], items[i + 1]] for i in range(0, len(items), 2)]
graphid = next(
(pair for pair in id_name_pairs if pair[1] == selected_grapgh), None
(pair for pair in id_name_pairs if pair[1] == selected_graph), None
)
resourcesid = []
resourceids = []
for resource in table.split(","):
try:
uuid.UUID(resource)
resourcesid.append(resource)
resourceids.append(resource)
except ValueError:
pass
if resourcesid:
resourceids_json_string = json.dumps(resourcesid)
if resourceids:
resourceids_json_string = json.dumps(resourceids)
resourceids = json.loads(resourceids_json_string)
pattern = old
edit_task = edit_bulk_concept_data.apply_async(
Expand Down Expand Up @@ -944,7 +954,7 @@ def run_load_task(
module_id,
graphid,
nodeid,
languageold,
language_old,
resourceids,
language_new,
oldid,
Expand All @@ -954,7 +964,7 @@ def run_load_task(
with connection.cursor() as cursor:
self.log_event_details(cursor, "done|Staging the data for edit...")
# select_query = "SELECT valueid FROM values Where conceptid = %s and languageid = %s and valuetype = 'prefLabel';"
# cursor.execute(select_query, [oldid[0], languageold])
# cursor.execute(select_query, [oldid[0], language_old])
# valueid = cursor.fetchall()
# oldid = valueid[0][0]
# select_query = "SELECT valueid FROM values Where conceptid = %s and languageid = %s and valuetype = 'prefLabel';"
Expand All @@ -964,11 +974,11 @@ def run_load_task(
self.log_event_details(cursor, "done|Editing the data...")
tile = self.return_value(cursor, resourceids, nodeid, oldid, newid)
self.log_event_details(cursor, "done|returm data...")
data_updated = self.edit_staged_data(
data_updated = self.stage_data(
cursor,
graphid[0],
nodeid,
languageold,
language_old,
tile[2],
language_new,
oldid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define([
'select-woo'
], function(ko, $, uuid, arches, JsonErrorAlertViewModel, baseStringEditorTemplate) {
const ViewModel = function(params) {
console.log(params);
const self = this;
this.editHistoryUrl = `${arches.urls.edit_history}?transactionid=${ko.unwrap(params.selectedLoadEvent)?.loadid}`;
this.load_details = params.load_details ?? {};
Expand Down Expand Up @@ -43,7 +44,7 @@ define([
this.selectedLoadEvent = params.selectedLoadEvent || ko.observable();
this.statusDetails = this.selectedLoadEvent()?.load_description?.split("|");
this.timeDifference = params.timeDifference;

this.alert = params.alert || ko.observable();

this.addAllFormData = () => {
if (self.selectedGraph()) { self.formData.append('selectedGraph', self.selectedGraph()); }
Expand Down
2 changes: 1 addition & 1 deletion arches/app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def edit_bulk_concept_data(
load_event.save()
status = _("Failed")
finally:
msg = _("Bulk Data Edit: {} [{}]").format(operation, status)
msg = _("Bulk Concept Editor: [{}]").format(status)
user = User.objects.get(id=userid)
notify_completion(msg, user)

Expand Down

0 comments on commit 30f611e

Please sign in to comment.