From 2ee8c95eb39d012b5cde6e5950077af43f737029 Mon Sep 17 00:00:00 2001 From: bkoschicek Date: Thu, 2 Nov 2023 16:30:10 +0100 Subject: [PATCH 1/4] added multiple files to loud as represents --- openatlas/api/formats/loud.py | 48 +++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/openatlas/api/formats/loud.py b/openatlas/api/formats/loud.py index 9f5efdbbc..c19320897 100644 --- a/openatlas/api/formats/loud.py +++ b/openatlas/api/formats/loud.py @@ -4,11 +4,11 @@ from flask import url_for from openatlas import app -from openatlas.display.util import get_file_path -from openatlas.models.gis import Gis from openatlas.api.resources.util import remove_spaces_dashes, date_to_str, \ get_crm_relation, get_crm_code +from openatlas.display.util import get_file_path from openatlas.models.entity import Entity +from openatlas.models.gis import Gis from openatlas.models.type import Type @@ -40,7 +40,7 @@ def get_domain_links() -> dict[str, Any]: property_ = { 'id': url_for('api.entity', id_=link_.domain.id, _external=True), 'type': loud[get_crm_code(link_, True).replace(' ', '_')], - '_label': link_.domain.name, } + '_label': link_.domain.name} if type_ := get_standard_type_loud(link_.domain.types): property_['classified_as'] = get_type_property(type_) return property_ @@ -61,6 +61,7 @@ def get_domain_links() -> dict[str, Any]: base_property = get_range_links() properties_set[property_name].append(base_property) + image_links = [] for link_ in data['links_inverse']: if link_.property.code in ['OA7', 'OA8', 'OA9']: continue @@ -78,21 +79,36 @@ def get_domain_links() -> dict[str, Any]: base_property = get_domain_links() properties_set[property_name].append(base_property) - if image_id := Entity.get_profile_image_id(data['entity']): - label = '' - for item in properties_set["referred_to_by"]: - if int(item['id'].split("/")[-1]) == image_id: - label = item['_label'] - path = get_file_path(image_id) - properties_set['representation'].append({ + if link_.domain.class_.name == 'file': + image_links.append(link_) + + if image_links: + representation = { "type": "VisualItem", - "digitally_shown_by": [{ + "digitally_shown_by": []} + for link_ in image_links: + id_ = link_.domain.id + # if image_id := Entity.get_profile_image_id(data['entity']): + path = get_file_path(id_) + image = { "id": url_for( - 'api.display', - filename=path.stem, - _external=True) if path else "N/A", - "_label": label, - "type": "DigitalObject"}]}) + 'api.entity', + id_=id_, + _external=True), + "_label": link_.domain.name, + "type": "DigitalObject", + "access_point": [{ + "id": url_for( + 'api.display', + filename=path.stem, + _external=True) if path else "N/A", + "type": "DigitalObject"}]} + + if type_ := get_standard_type_loud(link_.domain.types): + image['classified_as'] = get_type_property(type_) + representation['digitally_shown_by'].append(image) + + properties_set['representation'].append(representation) return {'@context': app.config['API_CONTEXT']['LOUD']} | \ base_entity_dict() | properties_set From 685415bac2adda118a88f723b636a3eb175c0f8c Mon Sep 17 00:00:00 2001 From: bkoschicek Date: Thu, 2 Nov 2023 16:44:12 +0100 Subject: [PATCH 2/4] added image mime type list --- config/api.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/config/api.py b/config/api.py index 19fb8547c..62bfd65df 100644 --- a/config/api.py +++ b/config/api.py @@ -42,3 +42,38 @@ # Used to connect to password protected Vocabs systems VOCABS_PASS = '' API_VERSIONS = ['0.3'] + +IMAGE_FORMATS = { + "jpg": "image/jpeg", + "jpeg": "image/jpeg", + "jpe": "image/jpeg", + "jfif": "image/jpeg", + "pjpeg": "image/pjpeg", + "pjp": "image/pjpeg", + "png": "image/png", + "gif": "image/gif", + "bmp": "image/bmp", + "ico": "image/x-icon", + "tiff": "image/tiff", + "tif": "image/tiff", + "webp": "image/webp", + "svg": "image/svg+xml", + "svgz": "image/svg+xml", + "apng": "image/apng", + "wbmp": "image/vnd.wap.wbmp", + "xbm": "image/x-xbitmap", + "avif": "image/avif", + "heic": "image/heic", + "heif": "image/heif", + "jp2": "image/jp2", + "jpx": "image/jpx", + "jpm": "image/jpm", + "jxr": "image/jxr", + "wdp": "image/vnd.ms-photo", + "hdp": "image/vnd.ms-photo", + "bpg": "image/bpg", + "dib": "image/bmp", + "jpeg2000": "image/jpeg2000", + "exr": "image/aces", + "hdr": "image/vnd.radiance", +} From d91f9c0ee1df4fe9ffe4236c24bb50e503de2f53 Mon Sep 17 00:00:00 2001 From: bkoschicek Date: Thu, 2 Nov 2023 16:45:06 +0100 Subject: [PATCH 3/4] added 0.4 --- config/api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/api.py b/config/api.py index 19fb8547c..a43a03b9a 100644 --- a/config/api.py +++ b/config/api.py @@ -1,3 +1,5 @@ +API_VERSIONS = ['0.3', '0.4'] + API_CONTEXT = { 'LPF': 'https://raw.githubusercontent.com/LinkedPasts/linked-places/' 'master/linkedplaces-context-v1.1.jsonld', @@ -40,5 +42,4 @@ ARCHE = {'id': None, 'url': None} # Used to connect to password protected Vocabs systems -VOCABS_PASS = '' -API_VERSIONS = ['0.3'] +VOCABS_PASS = '' \ No newline at end of file From 76291334098fe4593e6696d0abb64a40e076ce4a Mon Sep 17 00:00:00 2001 From: bkoschicek Date: Thu, 2 Nov 2023 17:38:17 +0100 Subject: [PATCH 4/4] added format, access_point and profile image --- config/api.py | 74 +++++++++++++++++------------------ openatlas/api/formats/loud.py | 26 +++++++----- 2 files changed, 54 insertions(+), 46 deletions(-) diff --git a/config/api.py b/config/api.py index 3f462fa83..960261f01 100644 --- a/config/api.py +++ b/config/api.py @@ -24,12 +24,12 @@ LOGICAL_OPERATOR: list[str] = ['and', 'or'] STR_CATEGORIES: list[str] = [ - "entityName", "entityDescription", "entityAliases", "entityCidocClass", - "entitySystemClass", "typeName", "typeNameWithSubs", - "beginFrom", "beginTo", "endFrom", "endTo"] + 'entityName', 'entityDescription', 'entityAliases', 'entityCidocClass', + 'entitySystemClass', 'typeName', 'typeNameWithSubs', + 'beginFrom', 'beginTo', 'endFrom', 'endTo'] INT_CATEGORIES: list[str] = [ - "entityID", "typeID", "typeIDWithSubs", "relationToID"] -SET_CATEGORIES: list[str] = ["valueTypeID"] + 'entityID', 'typeID', 'typeIDWithSubs', 'relationToID'] +SET_CATEGORIES: list[str] = ['valueTypeID'] VALID_CATEGORIES: list[str] = [ *STR_CATEGORIES, *INT_CATEGORIES, @@ -45,36 +45,36 @@ VOCABS_PASS = '' IMAGE_FORMATS = { - "jpg": "image/jpeg", - "jpeg": "image/jpeg", - "jpe": "image/jpeg", - "jfif": "image/jpeg", - "pjpeg": "image/pjpeg", - "pjp": "image/pjpeg", - "png": "image/png", - "gif": "image/gif", - "bmp": "image/bmp", - "ico": "image/x-icon", - "tiff": "image/tiff", - "tif": "image/tiff", - "webp": "image/webp", - "svg": "image/svg+xml", - "svgz": "image/svg+xml", - "apng": "image/apng", - "wbmp": "image/vnd.wap.wbmp", - "xbm": "image/x-xbitmap", - "avif": "image/avif", - "heic": "image/heic", - "heif": "image/heif", - "jp2": "image/jp2", - "jpx": "image/jpx", - "jpm": "image/jpm", - "jxr": "image/jxr", - "wdp": "image/vnd.ms-photo", - "hdp": "image/vnd.ms-photo", - "bpg": "image/bpg", - "dib": "image/bmp", - "jpeg2000": "image/jpeg2000", - "exr": "image/aces", - "hdr": "image/vnd.radiance", + 'jpg': 'image/jpeg', + 'jpeg': 'image/jpeg', + 'jpe': 'image/jpeg', + 'jfif': 'image/jpeg', + 'pjpeg': 'image/pjpeg', + 'pjp': 'image/pjpeg', + 'png': 'image/png', + 'gif': 'image/gif', + 'bmp': 'image/bmp', + 'ico': 'image/x-icon', + 'tiff': 'image/tiff', + 'tif': 'image/tiff', + 'webp': 'image/webp', + 'svg': 'image/svg+xml', + 'svgz': 'image/svg+xml', + 'apng': 'image/apng', + 'wbmp': 'image/vnd.wap.wbmp', + 'xbm': 'image/x-xbitmap', + 'avif': 'image/avif', + 'heic': 'image/heic', + 'heif': 'image/heif', + 'jp2': 'image/jp2', + 'jpx': 'image/jpx', + 'jpm': 'image/jpm', + 'jxr': 'image/jxr', + 'wdp': 'image/vnd.ms-photo', + 'hdp': 'image/vnd.ms-photo', + 'bpg': 'image/bpg', + 'dib': 'image/bmp', + 'jpeg2000': 'image/jpeg2000', + 'exr': 'image/aces', + 'hdr': 'image/vnd.radiance', } diff --git a/openatlas/api/formats/loud.py b/openatlas/api/formats/loud.py index c19320897..ca42167d7 100644 --- a/openatlas/api/formats/loud.py +++ b/openatlas/api/formats/loud.py @@ -1,11 +1,11 @@ from collections import defaultdict from typing import Any, Optional -from flask import url_for +from flask import url_for, g from openatlas import app -from openatlas.api.resources.util import remove_spaces_dashes, date_to_str, \ - get_crm_relation, get_crm_code +from openatlas.api.resources.util import ( + remove_spaces_dashes, date_to_str, get_crm_relation, get_crm_code) from openatlas.display.util import get_file_path from openatlas.models.entity import Entity from openatlas.models.gis import Gis @@ -41,8 +41,8 @@ def get_domain_links() -> dict[str, Any]: 'id': url_for('api.entity', id_=link_.domain.id, _external=True), 'type': loud[get_crm_code(link_, True).replace(' ', '_')], '_label': link_.domain.name} - if type_ := get_standard_type_loud(link_.domain.types): - property_['classified_as'] = get_type_property(type_) + if standard_type := get_standard_type_loud(link_.domain.types): + property_['classified_as'] = get_type_property(standard_type) return property_ for link_ in data['links']: @@ -79,16 +79,22 @@ def get_domain_links() -> dict[str, Any]: base_property = get_domain_links() properties_set[property_name].append(base_property) - if link_.domain.class_.name == 'file': + if link_.domain.class_.name == 'file' and g.files.get(link_.domain.id): image_links.append(link_) if image_links: + profile_image = Entity.get_profile_image_id(data['entity']) + print(profile_image) representation = { "type": "VisualItem", "digitally_shown_by": []} for link_ in image_links: id_ = link_.domain.id - # if image_id := Entity.get_profile_image_id(data['entity']): + suffix = g.files[id_].suffix.replace('.', '') + + if not app.config['IMAGE_FORMATS'].get(suffix): + continue + path = get_file_path(id_) image = { "id": url_for( @@ -97,12 +103,14 @@ def get_domain_links() -> dict[str, Any]: _external=True), "_label": link_.domain.name, "type": "DigitalObject", + "format": app.config['IMAGE_FORMATS'][suffix], "access_point": [{ "id": url_for( 'api.display', filename=path.stem, - _external=True) if path else "N/A", - "type": "DigitalObject"}]} + _external=True), + "type": "DigitalObject", + "_label": "ProfileImage" if id_ == profile_image else ''}]} if type_ := get_standard_type_loud(link_.domain.types): image['classified_as'] = get_type_property(type_)