Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modules/weko-authors/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
get_author_affiliation_obj,
check_email_existed,
get_export_status,
get_name_identifiers,
set_export_status,
delete_export_status,
get_export_url,
Expand Down Expand Up @@ -3591,3 +3592,18 @@ def test_check_delete_affiliation():

mock_check.assert_called_once_with(AuthorsAffiliationSettings, "Affiliation ID", 789)
assert result == (True, None)

# .tox/c1/bin/pytest --cov=weko_authors tests/test_utils.py::test_get_name_identifiers -vv -s --cov-branch --cov-report=html --basetemp=/code/modules/weko-authors/.tox/c1/tmp
def test_get_name_identifiers():
data = [
{"nameIdentifiers": [{"nameIdentifierScheme": "ORCID", "nameIdentifier": "0123"}]},
{"nameIdentifiers": [{"nameIdentifierScheme": "ISNI", "nameIdentifier": "2345"}]},
{"nameIdentifiers": [{"nameIdentifierScheme": "researchmap", "nameIdentifier": "4567"}]},
{"nameIdentifiers": []},
{},
"text"
]
scheme = "researchmap"
ids = []
get_name_identifiers(data, scheme, ids)
assert ids == ["4567"]
24 changes: 23 additions & 1 deletion modules/weko-authors/weko_authors/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""Utils for weko-authors."""

import base64
from collections import OrderedDict
import csv
import os
import chardet
Expand Down Expand Up @@ -1814,4 +1815,25 @@ def check_delete_prefix(id):

def check_delete_affiliation(id):
"""Check if the current user can delete the specified affiliation."""
return check_delete_entity(AuthorsAffiliationSettings, _('Affiliation ID'), id)
return check_delete_entity(AuthorsAffiliationSettings, _('Affiliation ID'), id)

def get_name_identifiers(data, scheme, ids):
"""Get name identifiers from data based on scheme and ids.

Args:
data (list): List of name identifier dictionaries.
scheme (str): The scheme to filter by.
ids (list): List of IDs to filter by.
"""
if type(data) is list:
for item in data:
get_name_identifiers(item, scheme, ids)
elif type(data) is dict or type(data) is OrderedDict:
nameIdentifiers = data.get("nameIdentifiers", [])
if nameIdentifiers:
for item in nameIdentifiers:
if item.get("nameIdentifierScheme") and item.get("nameIdentifierScheme") == scheme:
ids.append(item.get("nameIdentifier"))
else:
for key, value in data.items():
get_name_identifiers(value, scheme, ids)
49 changes: 47 additions & 2 deletions modules/weko-items-autofill/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from invenio_accounts.testutils import login_user_via_session
from weko_admin.models import ApiCertificate
from weko_records.models import ItemTypeName
from weko_items_ui.models import LinkageItems

from weko_items_autofill.views import dbsession_clean

Expand Down Expand Up @@ -167,7 +168,6 @@ def test_get_auto_fill_record_data(client_api,db,users,mocker):
assert json.loads(res.data) == {"result":"","items":"","error":"not_exist_type is NOT support autofill feature.",'resource_type' : '' }

# api_type is CrossRef

mock_crossref_record = mocker.patch("weko_items_autofill.views.get_crossref_record_data",return_value="return_crossref_record_data")
data = {
"api_type":"CrossRef",
Expand All @@ -179,6 +179,11 @@ def test_get_auto_fill_record_data(client_api,db,users,mocker):
assert json.loads(res.data) == {"result":"return_crossref_record_data","items":"","error":"",'resource_type' : '' }
mock_crossref_record.assert_called_with("test_crf@test.org","data","1", False)

mocker.patch("weko_items_autofill.views.get_current_api_certification",return_value={"cert_data":""})
res = client_api.post(url,json=data)
assert res.status_code == 200
assert json.loads(res.data) == {"result":[],"items":"","error":"","resource_type" : "" }

# api_type is CiNii
data = {
"api_type":"CiNii",
Expand All @@ -203,6 +208,18 @@ def test_get_auto_fill_record_data(client_api,db,users,mocker):
assert json.loads(res.data) == {"result":"return_weko_record_data","items":"","error":"",'resource_type' : '' }
mock_weko_record.assert_called_with("data","1")

# api_type is DOI
data = {
"api_type":"DOI",
"search_data":"data",
"item_type_id":"1"
}
mock_doi_record = mocker.patch("weko_items_autofill.views.get_doi_record_data",return_value="return_doi_record_data")
res = client_api.post(url,json=data)
assert res.status_code == 200
assert json.loads(res.data) == {"result":"return_doi_record_data","items":"","error":"","resource_type" : "" }
mock_doi_record.assert_called_with("data","1","")

# api_type is researchmap
data = {
"api_type":"researchmap",
Expand All @@ -214,9 +231,37 @@ def test_get_auto_fill_record_data(client_api,db,users,mocker):
mock_researchmapid_record = mocker.patch("weko_items_autofill.views.get_researchmapid_record_data",return_value=("return_researchmapid_record_data","return_researchmapid_resource_type"))
res = client_api.post(url,json=data)
assert res.status_code == 200
assert json.loads(res.data) == {"result":"return_researchmapid_record_data","items":"","error":"",'resource_type' : "return_researchmapid_resource_type" }
assert json.loads(res.data) == {"result":"return_researchmapid_record_data","items":"","error":"",'resource_type' : "return_researchmapid_resource_type", "type_data": []}
mock_researchmapid_record.assert_called_with("test_parmalink","test_achievement_type","test_achievement_id","1")

data["enable_item_achievement_link"] = True
mock_get_by_external_item_id = mocker.patch(
"weko_items_autofill.views.LinkageItems.get_by_external_item_id",
return_value=[]
)
res = client_api.post(url,json=data)
assert res.status_code == 200
assert json.loads(res.data) == {
"result":"return_researchmapid_record_data","items":"","error":"",'resource_type':"return_researchmapid_resource_type",
"type_data": [{'msg':'The used achievement ID must specify the permlink as a linkage destination in the metadata.','ok': False}],
}
mock_get_by_external_item_id.assert_called_with("test_achievement_id", LinkageItems.ExternalSystem.RM)

mock_get_by_external_item_id = mocker.patch(
"weko_items_autofill.views.LinkageItems.get_by_external_item_id",
return_value=[mocker.MagicMock()]
)
res = client_api.post(url,json=data)
assert res.status_code == 200
assert json.loads(res.data) == {
"result":"return_researchmapid_record_data","items":"","error":"",'resource_type':"return_researchmapid_resource_type",
"type_data": [
{'msg':'This researchmap ID is already linked to other items.','ok': False},
{'msg':'The used achievement ID must specify the permlink as a linkage destination in the metadata.','ok': False},
],
}
mock_get_by_external_item_id.assert_called_with("test_achievement_id", LinkageItems.ExternalSystem.RM)

# raise Exception
data = {
"api_type":"WEKOID",
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: weko-items-autofill 1.0.0.dev20190000\n"
"Report-Msgid-Bugs-To: wekosoftware@nii.ac.jp\n"
"POT-Creation-Date: 2025-04-25 17:15+0900\n"
"POT-Creation-Date: 2026-07-09 14:54+0900\n"
"PO-Revision-Date: 2019-03-13 13:54+0700\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
Expand All @@ -32,22 +32,32 @@ msgstr ""
msgid "A translation string"
msgstr ""

#: weko_items_autofill/utils.py:1431
#: weko_items_autofill/utils.py:1557
msgid "The item cannot be copied because you do not have permission to view it."
msgstr ""

#: weko_items_autofill/views.py:43
#: weko_items_autofill/views.py:45
msgid "WEKO-Items-Autofill"
msgstr ""

#: weko_items_autofill/views.py:54
#: weko_items_autofill/views.py:56
msgid "Select the ID"
msgstr ""

#: weko_items_autofill/views.py:90
#: weko_items_autofill/views.py:93
msgid "Header Error"
msgstr ""

#: weko_items_autofill/views.py:139
msgid "This researchmap ID is already linked to other items."
msgstr ""

#: weko_items_autofill/views.py:140
msgid ""
"The used achievement ID must specify the permlink as a linkage "
"destination in the metadata."
Comment on lines +56 to +58
msgstr ""

#: weko_items_autofill/templates/weko_items_autofill/index.html:12
#, python-format
msgid "Welcome to %(module_name)s"
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: weko-items-autofill 1.0.0.dev20190000\n"
"Report-Msgid-Bugs-To: wekosoftware@nii.ac.jp\n"
"POT-Creation-Date: 2025-04-25 17:15+0900\n"
"POT-Creation-Date: 2026-07-09 14:54+0900\n"
"PO-Revision-Date: 2019-03-13 13:54+0700\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: ja\n"
Expand All @@ -32,22 +32,32 @@ msgstr "DOIが指定されていません。"
msgid "A translation string"
msgstr "翻訳文字列"

#: weko_items_autofill/utils.py:1431
#: weko_items_autofill/utils.py:1557
msgid "The item cannot be copied because you do not have permission to view it."
msgstr ""

#: weko_items_autofill/views.py:43
#: weko_items_autofill/views.py:45
msgid "WEKO-Items-Autofill"
msgstr "WEKOアイテムの自動入力"

#: weko_items_autofill/views.py:54
#: weko_items_autofill/views.py:56
msgid "Select the ID"
msgstr "ID選択"

#: weko_items_autofill/views.py:90
#: weko_items_autofill/views.py:93
msgid "Header Error"
msgstr "ヘッダエラー"

#: weko_items_autofill/views.py:139
msgid "This researchmap ID is already linked to other items."
msgstr "指定した業績IDは他のアイテムに紐づけられているため、紐づけられません"

#: weko_items_autofill/views.py:140
msgid ""
"The used achievement ID must specify the permlink as a linkage "
"destination in the metadata."
msgstr "使用した業績IDの紐づけには、連携先としてpermlinkをメタデータ内で指定する必要があります"

#: weko_items_autofill/templates/weko_items_autofill/index.html:12
#, python-format
msgid "Welcome to %(module_name)s"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Translations template for weko-items-autofill.
# Copyright (C) 2025 National Institute of Informatics
# Copyright (C) 2026 National Institute of Informatics
# This file is distributed under the same license as the weko-items-autofill
# project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2026.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: weko-items-autofill 1.0.0.dev20190000\n"
"Report-Msgid-Bugs-To: wekosoftware@nii.ac.jp\n"
"POT-Creation-Date: 2025-04-25 17:15+0900\n"
"POT-Creation-Date: 2026-07-09 14:54+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -31,22 +31,32 @@ msgstr ""
msgid "A translation string"
msgstr ""

#: weko_items_autofill/utils.py:1431
#: weko_items_autofill/utils.py:1557
msgid "The item cannot be copied because you do not have permission to view it."
msgstr ""

#: weko_items_autofill/views.py:43
#: weko_items_autofill/views.py:45
msgid "WEKO-Items-Autofill"
msgstr ""

#: weko_items_autofill/views.py:54
#: weko_items_autofill/views.py:56
msgid "Select the ID"
msgstr ""

#: weko_items_autofill/views.py:90
#: weko_items_autofill/views.py:93
msgid "Header Error"
msgstr ""

#: weko_items_autofill/views.py:139
msgid "This researchmap ID is already linked to other items."
msgstr ""

#: weko_items_autofill/views.py:140
msgid ""
"The used achievement ID must specify the permlink as a linkage "
"destination in the metadata."
Comment on lines +55 to +57
msgstr ""

#: weko_items_autofill/templates/weko_items_autofill/index.html:12
#, python-format
msgid "Welcome to %(module_name)s"
Expand Down
13 changes: 11 additions & 2 deletions modules/weko-items-autofill/weko_items_autofill/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from invenio_db import db
from weko_accounts.utils import login_required_customize
from weko_admin.utils import get_current_api_certification
from weko_items_ui.signals import cris_researchmap_linkage_request
from weko_items_ui.models import LinkageItems

from .utils import get_cinii_record_data, get_crossref_record_data, get_doi_record_data, \
get_researchmapid_record_data, get_title_pubdate_path, get_wekoid_record_data, get_workflow_journal
Expand Down Expand Up @@ -102,6 +102,7 @@ def get_auto_fill_record_data():
parmalink = data.get('parmalink', '')
achievement_type = data.get('achievement_type', '')
achievement_id = data.get('achievement_id', '')
enable_item_achievement_link = data.get('enable_item_achievement_link', False)

try:
if api_type == 'CrossRef':
Expand Down Expand Up @@ -129,7 +130,15 @@ def get_auto_fill_record_data():
result['result'] = doi_response
elif api_type == 'researchmap':
result['result'] , result['resource_type'] = get_researchmapid_record_data(
parmalink, achievement_type ,achievement_id , item_type_id)
parmalink, achievement_type, achievement_id, item_type_id
)
type_data = []
if enable_item_achievement_link:
linkage_items = LinkageItems.get_by_external_item_id(achievement_id, LinkageItems.ExternalSystem.RM)
if linkage_items:
type_data.append(dict(ok=False, msg=_('This researchmap ID is already linked to other items.')))
type_data.append(dict(ok=False, msg=_('The used achievement ID must specify the permlink as a linkage destination in the metadata.')))
result['type_data'] = type_data
else:
result['error'] = api_type + ' is NOT support autofill feature.'
except Exception as e:
Expand Down
Loading