Skip to content

Commit

Permalink
Remove hard-coded sample name on backend #1516
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jan 12, 2024
1 parent 132459f commit ccd4195
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ define([
parentPhysicalThingTileData: koMapping.toJSON(parentPhysicalThing.data),
parentPhysicalThingTileId: parentPhysicalThing.tileid,
transactionId: params.form.workflowId,
analysisAreaName: self.areaName()
};

self.savingTile(true);
Expand Down Expand Up @@ -504,12 +503,12 @@ define([

const data = {
parentPhysicalThingResourceid: self.physicalThingResourceId,
parentPhysicalThingName: self.physicalThingName(),
collectionResourceid: params.projectSet,
partIdentifierAssignmentTileData: koMapping.toJSON(self.selectedAnalysisAreaInstance().data),
partIdentifierAssignmentTileId: self.selectedAnalysisAreaInstance().tileid,
partIdentifierAssignmentResourceId: self.selectedAnalysisAreaInstance().resourceinstance_id,
transactionId: params.form.workflowId,
analysisAreaName: self.areaName(),
};

$.ajax({
Expand Down
20 changes: 11 additions & 9 deletions arches_for_science/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

PHYSICAL_THING_GRAPH_ID = "9519cb4f-b25b-11e9-8c7b-a4d18cec433a"
PART_IDENTIFIER_ASSIGNMENT = "b240c366-8594-11ea-97eb-acde48001122"
PART_IDENTIFIER_ASSIGNMENT_LABEL = "3e541cc6-859b-11ea-97eb-acde48001122"
SAMPLING_ACTIVITY_GRAPH_ID = "03357848-1d9d-11eb-a29f-024e0d439fdb"
COLLECTION_RESOURCE = "54bf1022-a0b8-4f95-a5e9-82c084b2f533" # arbitrary test value

Expand Down Expand Up @@ -58,10 +59,14 @@ def test_create_delete_analysis_area(self):
create_data = {
"transaction_id": transaction_id, # NB: snake_case
"parentPhysicalThingResourceid": str(parent_phys_thing.pk), # NB: lowercase id
"parentPhysicalThingName": "Test Name of Physical Thing",
"collectionResourceid": COLLECTION_RESOURCE,
"partIdentifierAssignmentTileData": JSONSerializer().serialize(
{PART_IDENTIFIER_ASSIGNMENT: []}
),
"partIdentifierAssignmentTileData": JSONSerializer().serialize({
PART_IDENTIFIER_ASSIGNMENT: [],
PART_IDENTIFIER_ASSIGNMENT_LABEL: {
get_language(): {"value": "test value", "direction": "ltr"},
},
}),
"analysisAreaName": "Test Analysis Area",
}
response = client.post(reverse("saveanalysisarea"), create_data)
Expand Down Expand Up @@ -101,14 +106,12 @@ def test_create_delete_sample(self):
part = self.get_resource_instance(PHYSICAL_THING_GRAPH_ID)

# Create
physical_part_of_object_nodeid = "b240c366-8594-11ea-97eb-acde48001122"
part_identifier_assignment_label_nodeid = "3e541cc6-859b-11ea-97eb-acde48001122"
part_identifier_assignment_polygon_identifier_nodeid = "97c30c42-8594-11ea-97eb-acde48001122"
part_identifier_assignment_tile_data = {
part_identifier_assignment_label_nodeid: {
PART_IDENTIFIER_ASSIGNMENT_LABEL: {
get_language(): {"value": "test value", "direction": "ltr"}
},
physical_part_of_object_nodeid: [],
PART_IDENTIFIER_ASSIGNMENT: [],
part_identifier_assignment_polygon_identifier_nodeid: {},
}

Expand All @@ -128,7 +131,7 @@ def test_create_delete_sample(self):

# Delete
result = response.json()['result']
physical_part_of_object_nodeid = "b240c366-8594-11ea-97eb-acde48001122"
physical_part_of_object_nodeid = PART_IDENTIFIER_ASSIGNMENT
physical_part_of_object_resourceid = result['parentPhysicalThing']['physicalPartOfObjectTile']['data'][physical_part_of_object_nodeid][0]['resourceId']
part_identifier_assignment_tile_data = {
**part_identifier_assignment_tile_data,
Expand All @@ -140,7 +143,6 @@ def test_create_delete_sample(self):
delete_data = {
"transactionId": transaction_id, # NB: camelCase
"parentPhysicalThingResourceid": str(parent_phys_thing.pk),
"parentPhysicalThingName": "Test Name of Physical Thing",
"partIdentifierAssignmentTileData": JSONSerializer().serialize(part_identifier_assignment_tile_data),
"samplingActivityResourceId": str(sampling_activity.pk),
"collectionResourceid": COLLECTION_RESOURCE,
Expand Down
26 changes: 12 additions & 14 deletions arches_for_science/views/analysis_area_and_sample_taking.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import logging
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.exceptions import ObjectDoesNotExist
from django.db import transaction
from django.utils.decorators import method_decorator
from django.utils.translation import gettext as _
Expand Down Expand Up @@ -177,18 +176,20 @@ class SaveAnalysisAreaView(SaveAnnotationView):

def post(self, request):
parent_physical_thing_resourceid = request.POST.get("parentPhysicalThingResourceid")
parent_physical_thing_name = request.POST.get("parentPhysicalThingName")
collection_resourceid = request.POST.get("collectionResourceid")
transaction_id = request.POST.get("transactionId")
part_identifier_assignment_tile_data = JSONDeserializer().deserialize(request.POST.get("partIdentifierAssignmentTileData"))
part_identifier_assignment_tile_id = request.POST.get("partIdentifierAssignmentTileId") or None
name = request.POST.get("analysisAreaName")
if not name:
raise ValidationError(_("Name is required."))
part_identifier_assignment_label_nodeid = "3e541cc6-859b-11ea-97eb-acde48001122"
physical_part_of_object_nodeid = "b240c366-8594-11ea-97eb-acde48001122"
analysis_area_physical_thing_resourceid = None
if part_identifier_assignment_tile_data[physical_part_of_object_nodeid]:
analysis_area_physical_thing_resourceid = part_identifier_assignment_tile_data[physical_part_of_object_nodeid][0]["resourceId"]

base_name = part_identifier_assignment_tile_data[part_identifier_assignment_label_nodeid][get_language()]["value"]
name = _("{} [Analysis Area of {}]").format(base_name, parent_physical_thing_name)

try:
with transaction.atomic():
if analysis_area_physical_thing_resourceid is None:
Expand Down Expand Up @@ -359,10 +360,9 @@ def post(self, request):

sample_physical_thing_resourceid = None
sampling_unit_tiles = Tile.objects.filter(resourceinstance=sampling_activity_resourceid, nodegroup=sampling_unit_nodegroupid)
if len(sampling_unit_tiles) > 0:
for sampling_unit_tile in sampling_unit_tiles:
if sampling_unit_tile.data[sampling_area_nodeid][0]["resourceId"] == sample_area_physical_thing_resourceid:
sample_physical_thing_resourceid = sampling_unit_tile.data[sampling_area_sample_created_nodeid][0]["resourceId"]
for sampling_unit_tile in sampling_unit_tiles:
if sampling_unit_tile.data[sampling_area_nodeid][0]["resourceId"] == sample_area_physical_thing_resourceid:
sample_physical_thing_resourceid = sampling_unit_tile.data[sampling_area_sample_created_nodeid][0]["resourceId"]

base_name = part_identifier_assignment_tile_data[part_identifier_assignment_label_nodeid][get_language()]["value"]
sample_name = _("{} [Sample of {}]").format(base_name, parent_physical_thing_name)
Expand Down Expand Up @@ -498,7 +498,6 @@ def post(self, request):
sampling_unit_nodegroupid = "b3e171a7-1d9d-11eb-a29f-024e0d439fdb"

parent_physical_thing_resourceid = data.get("parentPhysicalThingResourceid")
parent_physical_thing_name = data.get("parentPhysicalThingName")
sampling_activity_resourceid = data.get("samplingActivityResourceId")
collection_resourceid = data.get("collectionResourceid")
sample_motivation = data.get("sampleMotivation")
Expand All @@ -515,10 +514,9 @@ def post(self, request):
try:
sample_physical_thing_resourceid = None
sampling_unit_tiles = Tile.objects.filter(resourceinstance_id=sampling_activity_resourceid, nodegroup=sampling_unit_nodegroupid)
if len(sampling_unit_tiles) > 0:
for sampling_unit_tile in sampling_unit_tiles:
if sampling_unit_tile.data[sampling_area_nodeid][0]["resourceId"] == sample_area_physical_thing_resourceid:
sample_physical_thing_resourceid = sampling_unit_tile.data[sampling_area_sample_created_nodeid][0]["resourceId"]
for sampling_unit_tile in sampling_unit_tiles:
if sampling_unit_tile.data[sampling_area_nodeid][0]["resourceId"] == sample_area_physical_thing_resourceid:
sample_physical_thing_resourceid = sampling_unit_tile.data[sampling_area_sample_created_nodeid][0]["resourceId"]

parentPhysicalThingSampleTile = ResourceXResource.objects.get(
nodeid=physical_part_of_object_nodeid,
Expand Down

0 comments on commit ccd4195

Please sign in to comment.