das-cli 1.5.0__tar.gz → 1.5.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {das_cli-1.5.0/das_cli.egg-info → das_cli-1.5.1}/PKG-INFO +1 -1
  2. {das_cli-1.5.0 → das_cli-1.5.1}/das/managers/entries_manager.py +64 -33
  3. {das_cli-1.5.0 → das_cli-1.5.1/das_cli.egg-info}/PKG-INFO +1 -1
  4. {das_cli-1.5.0 → das_cli-1.5.1}/pyproject.toml +1 -1
  5. {das_cli-1.5.0 → das_cli-1.5.1}/LICENSE +0 -0
  6. {das_cli-1.5.0 → das_cli-1.5.1}/MANIFEST.in +0 -0
  7. {das_cli-1.5.0 → das_cli-1.5.1}/README.md +0 -0
  8. {das_cli-1.5.0 → das_cli-1.5.1}/das/__init__.py +0 -0
  9. {das_cli-1.5.0 → das_cli-1.5.1}/das/ai/plugins/dasai.py +0 -0
  10. {das_cli-1.5.0 → das_cli-1.5.1}/das/ai/plugins/entries/entries_plugin.py +0 -0
  11. {das_cli-1.5.0 → das_cli-1.5.1}/das/app.py +0 -0
  12. {das_cli-1.5.0 → das_cli-1.5.1}/das/authentication/auth.py +0 -0
  13. {das_cli-1.5.0 → das_cli-1.5.1}/das/authentication/oauth.py +0 -0
  14. {das_cli-1.5.0 → das_cli-1.5.1}/das/authentication/secure_input.py +0 -0
  15. {das_cli-1.5.0 → das_cli-1.5.1}/das/cli.py +0 -0
  16. {das_cli-1.5.0 → das_cli-1.5.1}/das/common/api.py +0 -0
  17. {das_cli-1.5.0 → das_cli-1.5.1}/das/common/config.py +0 -0
  18. {das_cli-1.5.0 → das_cli-1.5.1}/das/common/entry_fields_constants.py +0 -0
  19. {das_cli-1.5.0 → das_cli-1.5.1}/das/common/enums.py +0 -0
  20. {das_cli-1.5.0 → das_cli-1.5.1}/das/common/file_utils.py +0 -0
  21. {das_cli-1.5.0 → das_cli-1.5.1}/das/managers/__init__.py +0 -0
  22. {das_cli-1.5.0 → das_cli-1.5.1}/das/managers/digital_objects_manager.py +0 -0
  23. {das_cli-1.5.0 → das_cli-1.5.1}/das/managers/download_manager.py +0 -0
  24. {das_cli-1.5.0 → das_cli-1.5.1}/das/managers/search_manager.py +0 -0
  25. {das_cli-1.5.0 → das_cli-1.5.1}/das/services/attributes.py +0 -0
  26. {das_cli-1.5.0 → das_cli-1.5.1}/das/services/cache.py +0 -0
  27. {das_cli-1.5.0 → das_cli-1.5.1}/das/services/das_elastic_search.py +0 -0
  28. {das_cli-1.5.0 → das_cli-1.5.1}/das/services/digital_objects.py +0 -0
  29. {das_cli-1.5.0 → das_cli-1.5.1}/das/services/downloads.py +0 -0
  30. {das_cli-1.5.0 → das_cli-1.5.1}/das/services/entries.py +0 -0
  31. {das_cli-1.5.0 → das_cli-1.5.1}/das/services/entry_fields.py +0 -0
  32. {das_cli-1.5.0 → das_cli-1.5.1}/das/services/hangfire.py +0 -0
  33. {das_cli-1.5.0 → das_cli-1.5.1}/das/services/search.py +0 -0
  34. {das_cli-1.5.0 → das_cli-1.5.1}/das/services/service_base.py +0 -0
  35. {das_cli-1.5.0 → das_cli-1.5.1}/das/services/users.py +0 -0
  36. {das_cli-1.5.0 → das_cli-1.5.1}/das_cli.egg-info/SOURCES.txt +0 -0
  37. {das_cli-1.5.0 → das_cli-1.5.1}/das_cli.egg-info/dependency_links.txt +0 -0
  38. {das_cli-1.5.0 → das_cli-1.5.1}/das_cli.egg-info/entry_points.txt +0 -0
  39. {das_cli-1.5.0 → das_cli-1.5.1}/das_cli.egg-info/requires.txt +0 -0
  40. {das_cli-1.5.0 → das_cli-1.5.1}/das_cli.egg-info/top_level.txt +0 -0
  41. {das_cli-1.5.0 → das_cli-1.5.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: das-cli
3
- Version: 1.5.0
3
+ Version: 1.5.1
4
4
  Summary: DAS api client.
5
5
  Author: Royal Netherlands Institute for Sea Research
6
6
  License-Expression: MIT
@@ -382,44 +382,75 @@ class EntryManager:
382
382
  if "tag" in customdata:
383
383
  tag = customdata.get("tag")
384
384
  if "relations" in customdata:
385
- relations = customdata.get("relations")
385
+ relations = [
386
+ {str(k).lower(): v for k, v in rel.items()}
387
+ for rel in customdata.get("relations")
388
+ if isinstance(rel, dict)
389
+ ]
386
390
  except json.JSONDecodeError:
387
391
  raise ValueError(f"Invalid customdata JSON: {field.get('customdata')}")
388
392
 
389
393
  result_list = []
390
394
  for value in values:
391
- response = self.das_elastic_search.search_item(field="identifier", value=value)
392
- if response.get('item') is not None and isinstance(response.get('item'), dict):
393
- if response.get('item').get('source') is not None and isinstance(response.get('item').get('source'), dict):
394
- source = response.get('item').get('source', {})
395
- # find the attribute id in the relation.attributeid using lambda and check if its the same as the source.attributeid, if not raise an error
396
- if relations and not any(rel.get('attributeid') == source.get('attributeid') for rel in relations):
397
- raise ValueError(f"Attribute ID {source.get('attributeid')} for value '{value}' is not allowed in the relations list")
398
- item = {
399
- "id": source.get('id'),
400
- "name": source.get('title'),
401
- "code": source.get('code'),
402
- "attributeId": source.get('attributeid'),
403
- "tag": tag,
404
- "acronym": None,
405
- "order": 0
406
- }
407
- # get the attribute name from the relations where the attribute id is the same as the source.attributeid using lambda
408
- attribute_name = next((attr.get('attributealias') for attr in relations if attr.get('attributeid') == source.get('attributeid')), None)
409
-
410
- # We need to check if the relation item already exists in the result list, if it does we need to append the item to the relations list of that item, if not we need to create a new item in the result list
411
- existing_item = next((i for i in result_list if i.get('attribute') == attribute_name), None)
412
- if existing_item:
413
- existing_item.get('relations', []).append(item)
414
- continue
415
-
416
- item_relation = {
417
- "attribute": attribute_name,
418
- "relations": [item],
419
- "tag": tag
420
- }
421
-
422
- result_list.append(item_relation)
395
+ response = self.entry_service.get_entry(value)
396
+ if response is None:
397
+ raise ValueError(f"No results found for {field.get('displayname')}: {value}")
398
+
399
+ if not isinstance(response, dict):
400
+ raise ValueError(f"Invalid response: {response}")
401
+
402
+ # response shape: { "entry": { ... }, "attributeId": <int> }
403
+ response = {str(k).lower(): v for k, v in response.items()}
404
+ attribute_id = response.get('attributeid')
405
+ try:
406
+ attribute_id = int(attribute_id) if attribute_id is not None else None
407
+ except (TypeError, ValueError):
408
+ pass
409
+
410
+ # check that the entry's attributeId is allowed in the relations list
411
+ if relations and not any(
412
+ int(rel.get('attributeid')) == attribute_id
413
+ for rel in relations
414
+ if rel.get('attributeid') is not None and attribute_id is not None
415
+ ):
416
+ raise ValueError(f"Attribute ID {attribute_id} for value '{value}' is not allowed in the relations list")
417
+
418
+ entry = response.get('entry', {})
419
+ if isinstance(entry, dict):
420
+ entry = {str(k).lower(): v for k, v in entry.items()}
421
+
422
+ item = {
423
+ "id": entry.get('id'),
424
+ "name": entry.get('displayname'),
425
+ "code": entry.get('code'),
426
+ "attributeId": attribute_id,
427
+ "tag": tag,
428
+ "acronym": entry.get('acronym'),
429
+ "order": entry.get('order', 0)
430
+ }
431
+
432
+ # get the attribute name from the relations where the attribute id matches the entry's attributeId
433
+ attribute_name = next(
434
+ (attr.get('attributealias') for attr in relations
435
+ if attr.get('attributeid') is not None and attribute_id is not None
436
+ and int(attr.get('attributeid')) == attribute_id),
437
+ None
438
+ ) if attribute_id is not None else None
439
+
440
+ # We need to check if the relation item already exists in the result list, if it does we need to append the item to the relations list of that item, if not we need to create a new item in the result list
441
+ existing_item = next((i for i in result_list if i.get('attribute') == attribute_name), None)
442
+ if existing_item:
443
+ existing_item.get('relations', []).append(item)
444
+ continue
445
+
446
+ item_relation = {
447
+ "attribute": attribute_name,
448
+ "relations": [item],
449
+ "tag": tag
450
+ }
451
+
452
+ result_list.append(item_relation)
453
+
423
454
 
424
455
  return json.dumps(result_list) if result_list else source
425
456
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: das-cli
3
- Version: 1.5.0
3
+ Version: 1.5.1
4
4
  Summary: DAS api client.
5
5
  Author: Royal Netherlands Institute for Sea Research
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "das-cli"
7
- version = "1.5.0"
7
+ version = "1.5.1"
8
8
  authors = [
9
9
  { name="Royal Netherlands Institute for Sea Research" },
10
10
  ]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes