Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 20 additions & 12 deletions modules/weko-index-tree/weko_index_tree/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,21 +931,21 @@ def delete(self, **kwargs):

def get_v1(self, **kwargs):
"""Get index tree."""

def json_serialize(obj):
"""Serialize object to JSON.

Args:
obj: The object to serialize.

Returns:
str: The serialized JSON string.
"""
if isinstance(obj, (datetime, date)):
return obj.strftime("%Y%m%d")
else:
return str(obj)

try:
pid = kwargs.get('index_id')

Expand Down Expand Up @@ -1228,17 +1228,21 @@ def put_v1(self, index_id, **kwargs):
}} if "contribute_group" in index_info else {})
}

source_index = self.record_class.get_index(index_id)
parent = index_data.get("parent") \
if index_data.get("parent") is not None else source_index.parent
position = index_data.get("position") \
if index_data.get("position") is not None else source_index.position
index = self.record_class.get_index(index_id)
parent = (
index_data.get("parent")
if index_data.get("parent") is not None else index.parent
)
position = (
index_data.get("position")
if index_data.get("position") is not None else index.position
)

if parent != source_index.parent or position != source_index.position:
if parent != index.parent or position != index.position:
# Move index if parent or position changed
# Change int to string if parent is root node
arg_parent = parent if parent > 0 else "0"
arg_pre_parent = source_index.parent if source_index.parent > 0 else "0"
arg_pre_parent = index.parent if index.parent > 0 else "0"
moved = self.record_class.move(
index_id, pre_parent=arg_pre_parent,
parent=arg_parent, position=position
Expand Down Expand Up @@ -1308,7 +1312,11 @@ def put_v1(self, index_id, **kwargs):


def delete_v1(self, index_id, **kwargs):
"""Delete an existing index tree node."""
"""Delete an existing index tree node.

Args:
index_id (int): The ID of the index to be deleted.
"""
try:
index_obj = self.record_class.get_index(index_id)
if not index_obj:
Expand Down
8 changes: 4 additions & 4 deletions modules/weko-items-ui/weko_items_ui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3976,10 +3976,10 @@ def check_duplicate(data, is_item=True, exclude_ids=[]):
is_item (bool): True if checking an item, False if checking a record.

Returns:
tuple:
- bool: True if duplicate exists, False otherwise.
- list: List of duplicate record IDs.
- list: List of duplicate record URLs.
tuple(bool, list, list):
- True if duplicate exists, False otherwise.
- List of duplicate record IDs.
- List of duplicate record URLs.
"""
if isinstance(data, str):
try:
Expand Down
4 changes: 3 additions & 1 deletion modules/weko-notifications/weko_notifications/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ def _get_params_for_registrant(target_id, actor_id, shared_id):
shared_id (int): The shared ID.

Returns:
tuple: The parameters for registrant.
tuple(set, str):
- str: Set of target IDs.
- str: The actor's name.
"""
set_target_id = {target_id}
is_shared = shared_id != -1
Expand Down
20 changes: 12 additions & 8 deletions modules/weko-records/weko_records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def get_by_id(cls, id_, with_deleted=False):
with_deleted (bool): If `True` then it includes deleted item types.

Returns:
ItemTypes: Item type model instance.
ItemType: Item type model instance.
"""
with db.session.no_autoflush:
query = ItemType.query.filter_by(id=id_)
Expand All @@ -663,11 +663,14 @@ def get_by_id(cls, id_, with_deleted=False):

@classmethod
def get_by_name(cls, name_, with_deleted=False):
"""Retrieve the item type by id.
"""Retrieve the item type by item type name.

:param name_: Name of item type.
:param with_deleted: If `True` then it includes deleted item types.
:returns: The :class:`ItemTypes` instance.
Args:
name_ (str): Name of item type.
with_deleted (bool): If `True` then it includes deleted item types.

Returns:
ItemType: Item type model instance.
"""
with db.session.no_autoflush:
query = ItemTypeName.query.filter_by(name=name_)
Expand All @@ -677,7 +680,8 @@ def get_by_name(cls, name_, with_deleted=False):
query = ItemType.query.filter_by(name_id=itemTypeName.id)
if not with_deleted:
query = query.filter(ItemType.is_deleted.is_(False)) # noqa
return query.one_or_none()
obj = query.one_or_none()
return obj if isinstance(obj, ItemType) else None

@classmethod
def get_by_name_id(cls, name_id, with_deleted=False):
Expand Down Expand Up @@ -1522,7 +1526,7 @@ def delete(cls, id):
Returns:
ItemTypeJsonldMapping: Deleted mapping object.
"""
obj = JsonldMapping.get_mapping_by_id(id)
obj = cls.get_mapping_by_id(id)
if not isinstance(obj, ItemTypeJsonldMapping):
return None
obj.is_deleted = True
Expand Down Expand Up @@ -1576,7 +1580,7 @@ def get_by_itemtype_id(cls, item_type_id, with_deleted=False):
.filter_by(item_type_id=item_type_id)
.order_by(ItemTypeJsonldMapping.updated.desc())
)
if with_deleted:
if not with_deleted:
query = query.filter_by(is_deleted=False)

return [
Expand Down
29 changes: 15 additions & 14 deletions modules/weko-records/weko_records/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,21 @@ class ItemTypeMapping(db.Model, Timestamp):
class ItemTypeJsonldMapping(db.Model, Timestamp):
"""Jsonld Mapping Model

Mapping for JSON-LD matadata to WEKO item type.
Mapping for JSON-LD matadata to WEKO item type. <br>
When updating the mapping, the verion_id is incremented and the previous
mapping moves to the history table.

Operation methods are defined in api.py.

Columns:
`id` (int): ID of the mapping. Primary key, autoincrement.
`name` (str): Name of the mapping.
`mapping` (JSON): Mapping in JSON format.
`item_type_id` (str): Target itemtype of the mapping.\
Attributes:
id (int): ID of the mapping. Primary key, autoincrement.
name (str): Name of the mapping.
mapping (dict): Mapping in JSON format.
item_type_id (str): Target itemtype of the mapping.
Foreign key referencing `ItemType.id`.
`version_id` (int): Version ID of the mapping.
`is_deleted` (bool): Sofr-delete status of the mapping.
item_type (ItemType): Relationship to the ItemType.
version_id (int): Version ID of the mapping.
is_deleted (bool): Sofr-delete status of the mapping.
"""

# Enables SQLAlchemy-Continuum versioning
Expand All @@ -342,10 +343,10 @@ class ItemTypeJsonldMapping(db.Model, Timestamp):
unique=True,
autoincrement=True
)
"""ID of the mapping."""
"""int: ID of the mapping."""

name = db.Column(db.String(255), nullable=False)
"""Name of the mapping."""
"""str: Name of the mapping."""

mapping = db.Column(
db.JSON().with_variant(
Expand All @@ -361,13 +362,13 @@ class ItemTypeJsonldMapping(db.Model, Timestamp):
default=lambda: {},
nullable=False
)
"""Mapping in JSON format. Foreign key from ItemType."""
"""dict: Mapping in JSON format. Foreign key from ItemType."""

item_type_id = db.Column(
db.Integer(),
db.ForeignKey(ItemType.id),
nullable=False)
"""Target itemtype of the mapping."""
"""int: Target itemtype of the mapping."""

item_type = db.relationship(
'ItemType',
Expand All @@ -377,13 +378,13 @@ class ItemTypeJsonldMapping(db.Model, Timestamp):
"""Relationship to the ItemType."""

version_id = db.Column(db.Integer, nullable=False)
"""Version id of the mapping."""
"""int: Version id of the mapping."""

is_deleted = db.Column(
db.Boolean(name='is_deleted'),
nullable=False,
default=False)
"""Sofr-delete status of the mapping."""
"""bool: Sofr-delete status of the mapping."""

__mapper_args__ = {
'version_id_col': version_id
Expand Down
Loading