2424from invenio_communities .generators import CommunityRoleNeed
2525from invenio_communities .members .errors import AlreadyMemberError
2626from invenio_communities .proxies import current_communities
27- from invenio_pidstore .errors import PersistentIdentifierError
27+ from invenio_pidstore .models import PersistentIdentifier
2828from invenio_records_resources .proxies import current_service_registry
2929from invenio_requests import current_events_service , current_requests_service
3030from invenio_requests .customizations import CommentEventType
31- from invenio_vocabularies .records .api import Vocabulary
3231
3332from ..proxies import current_oaipmh_server_service , current_rdm_records_service
3433from ..requests import CommunitySubmission
@@ -49,19 +48,32 @@ def get_authenticated_identity(user_id):
4948def create_vocabulary_record (service_str , data ):
5049 """Create or update a vocabulary record."""
5150 service = current_service_registry .get (service_str )
51+
52+ # Determine the PID based on vocabulary type
5253 if "type" in data :
53- # We only check non-datastream vocabularies for updates
54- try :
55- pid = (data ["type" ], data ["id" ])
56- # If the entry hasn't been added, this will fail
57- record = Vocabulary .pid .resolve (pid )
58- service .update (system_identity , pid , data = data )
59- current_app .logger .info (f"updated existing fixture with { data } " )
60- except PersistentIdentifierError :
61- service .create (system_identity , data )
62- current_app .logger .info (f"added new fixture with { data } " )
54+ # Generic vocabularies with type field
55+ pid_type = data ["type" ]
56+ pid_value = data ["id" ]
57+ else :
58+ # Special vocabularies like subjects (without type field)
59+ # Use the service_str as the type
60+ pid_type = service_str
61+ pid_value = data ["id" ]
62+
63+ # Check if PID exists in the database
64+ existing_pid = PersistentIdentifier .query .filter_by (
65+ pid_type = pid_type , pid_value = pid_value
66+ ).first ()
67+
68+ if existing_pid :
69+ # Update existing record
70+ pid = (pid_type , pid_value )
71+ service .update (system_identity , pid , data = data )
72+ current_app .logger .debug (f"updated existing fixture with { data } " )
6373 else :
74+ # Create new record
6475 service .create (system_identity , data )
76+ current_app .logger .debug (f"added new fixture with { data } " )
6577
6678
6779@shared_task
@@ -235,4 +247,4 @@ def create_demo_invitation_requests(user_id, n_requests):
235247 # comment_with_type
236248 # )
237249
238- print (f"Created request for user { user_id } and " f" community { community_id } " )
250+ print (f"Created request for user { user_id } and community { community_id } " )
0 commit comments