moved filter ids validation to backend
This commit is contained in:
@@ -93,10 +93,8 @@ async def get_dfg_projects(
|
||||
str | None, Query(description="The openalex institution ID to filter by.")
|
||||
] = None,
|
||||
author_id: Annotated[str | None, Query(description="The openalex author ID to filter by.")] = None,
|
||||
author_filter_ids: Annotated[list[int] | None, Query(description="The dfg author IDs to filter by.")] = None,
|
||||
institution_ids: Annotated[
|
||||
list[int] | None, Query(description="The institution IDs to filter by.")
|
||||
] = None,
|
||||
author_filter_ids: Annotated[list[str] | None, Query(description="The dfg author IDs to filter by.")] = None,
|
||||
institution_ids: Annotated[list[str] | None, Query(description="The institution IDs to filter by.")] = None,
|
||||
title: Annotated[
|
||||
str | None, Query(description="The title to filter by.")
|
||||
] = None,
|
||||
|
||||
@@ -40,6 +40,7 @@ from inse.projects.model import (
|
||||
ProjectType,
|
||||
SortDirection,
|
||||
)
|
||||
from inse.projects.logic import get_dfg_author_names_by_ids
|
||||
from inse.works.logic import get_publication_dois_of_author
|
||||
from fastapi import HTTPException as HttpException
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -156,12 +157,25 @@ async def _get_dfg_project_ids_for_openalex_authors(
|
||||
|
||||
return list(set.intersection(*project_sets))
|
||||
|
||||
def _is_number_list(values: list[str] | None) -> bool:
|
||||
if not values:
|
||||
return True # nothing to validate, treat as valid/empty
|
||||
for value in values:
|
||||
if value is None or value == "":
|
||||
return False
|
||||
try:
|
||||
float(value)
|
||||
except (TypeError, ValueError):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
async def get_dfg_projects(
|
||||
institutions_search_client: InstitutionsSearchClient,
|
||||
raw_oa_institution_id: str | None,
|
||||
author_id: str | None,
|
||||
author_filter_ids: list[int] | None,
|
||||
institution_ids: list[int] | None,
|
||||
author_filter_ids: list[str] | None,
|
||||
institution_ids: list[str] | None,
|
||||
keywords: list[str] | None,
|
||||
topic_ids: list[str] | None,
|
||||
filter_topic_ids: list[str] | None,
|
||||
@@ -195,6 +209,23 @@ async def get_dfg_projects(
|
||||
sort_direction,
|
||||
fuzzy,
|
||||
)
|
||||
|
||||
# Validate author_filter_ids / institution_ids. Return an empty page
|
||||
if not _is_number_list(author_filter_ids) or not _is_number_list(institution_ids):
|
||||
logger.debug(
|
||||
"Invalid author_filter_ids=%s or institution_ids=%s, returning empty page",
|
||||
author_filter_ids,
|
||||
institution_ids,
|
||||
)
|
||||
return DfgProjectPage(elements=[], page=page, size=size, total=0)
|
||||
|
||||
author_filter_ids_int = (
|
||||
[int(float(v)) for v in author_filter_ids] if author_filter_ids else None
|
||||
)
|
||||
institution_ids_int = (
|
||||
[int(float(v)) for v in institution_ids] if institution_ids else None
|
||||
)
|
||||
|
||||
filter_names = []
|
||||
author_project_ids = []
|
||||
if author_id:
|
||||
@@ -207,16 +238,16 @@ async def get_dfg_projects(
|
||||
size=size,
|
||||
total=0)
|
||||
|
||||
if author_filter_ids:
|
||||
if author_filter_ids_int:
|
||||
filter_names = (
|
||||
await get_dfg_author_names_by_ids(author_ids=author_filter_ids)
|
||||
if author_filter_ids
|
||||
await get_dfg_author_names_by_ids(author_ids=author_filter_ids_int)
|
||||
if author_filter_ids_int
|
||||
else []
|
||||
)
|
||||
if author_filter_ids and not filter_names:
|
||||
if author_filter_ids_int and not filter_names:
|
||||
logger.debug(
|
||||
"No author names found for author_filter_ids=%s",
|
||||
author_filter_ids,
|
||||
author_filter_ids_int,
|
||||
)
|
||||
institution_aliases = []
|
||||
if raw_oa_institution_id:
|
||||
@@ -242,7 +273,7 @@ async def get_dfg_projects(
|
||||
institution_aliases=institution_aliases,
|
||||
project_ids=author_project_ids,
|
||||
names=filter_names or [],
|
||||
institution_ids=institution_ids,
|
||||
institution_ids=institution_ids_int,
|
||||
keywords=keywords,
|
||||
topic_ids=topic_ids,
|
||||
filter_topic_ids=filter_topic_ids,
|
||||
|
||||
@@ -86,10 +86,10 @@ export class ProjectsService extends BaseService {
|
||||
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
|
||||
* @param reportProgress flag to report request and response progress.
|
||||
*/
|
||||
public getDfgProjects(rawOaInstitutionId?: string, authorId?: string, authorFilterIds?: Array<number>, institutionIds?: Array<number>, title?: string, keywords?: Array<string>, topicIds?: Array<string>, filterTopicIds?: Array<string>, fundingStartYears?: Array<string>, fundingEndYears?: Array<string>, page?: number, size?: number, sortBy?: string, sortDirection?: string, fuzzy?: boolean, secureFgpAcc?: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<DfgProjectPage>;
|
||||
public getDfgProjects(rawOaInstitutionId?: string, authorId?: string, authorFilterIds?: Array<number>, institutionIds?: Array<number>, title?: string, keywords?: Array<string>, topicIds?: Array<string>, filterTopicIds?: Array<string>, fundingStartYears?: Array<string>, fundingEndYears?: Array<string>, page?: number, size?: number, sortBy?: string, sortDirection?: string, fuzzy?: boolean, secureFgpAcc?: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<DfgProjectPage>>;
|
||||
public getDfgProjects(rawOaInstitutionId?: string, authorId?: string, authorFilterIds?: Array<number>, institutionIds?: Array<number>, title?: string, keywords?: Array<string>, topicIds?: Array<string>, filterTopicIds?: Array<string>, fundingStartYears?: Array<string>, fundingEndYears?: Array<string>, page?: number, size?: number, sortBy?: string, sortDirection?: string, fuzzy?: boolean, secureFgpAcc?: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<DfgProjectPage>>;
|
||||
public getDfgProjects(rawOaInstitutionId?: string, authorId?: string, authorFilterIds?: Array<number>, institutionIds?: Array<number>, title?: string, keywords?: Array<string>, topicIds?: Array<string>, filterTopicIds?: Array<string>, fundingStartYears?: Array<string>, fundingEndYears?: Array<string>, page?: number, size?: number, sortBy?: string, sortDirection?: string, fuzzy?: boolean, secureFgpAcc?: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<any> {
|
||||
public getDfgProjects(rawOaInstitutionId?: string, authorId?: string, authorFilterIds?: Array<string>, institutionIds?: Array<string>, title?: string, keywords?: Array<string>, topicIds?: Array<string>, filterTopicIds?: Array<string>, fundingStartYears?: Array<string>, fundingEndYears?: Array<string>, page?: number, size?: number, sortBy?: string, sortDirection?: string, fuzzy?: boolean, secureFgpAcc?: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<DfgProjectPage>;
|
||||
public getDfgProjects(rawOaInstitutionId?: string, authorId?: string, authorFilterIds?: Array<string>, institutionIds?: Array<string>, title?: string, keywords?: Array<string>, topicIds?: Array<string>, filterTopicIds?: Array<string>, fundingStartYears?: Array<string>, fundingEndYears?: Array<string>, page?: number, size?: number, sortBy?: string, sortDirection?: string, fuzzy?: boolean, secureFgpAcc?: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<DfgProjectPage>>;
|
||||
public getDfgProjects(rawOaInstitutionId?: string, authorId?: string, authorFilterIds?: Array<string>, institutionIds?: Array<string>, title?: string, keywords?: Array<string>, topicIds?: Array<string>, filterTopicIds?: Array<string>, fundingStartYears?: Array<string>, fundingEndYears?: Array<string>, page?: number, size?: number, sortBy?: string, sortDirection?: string, fuzzy?: boolean, secureFgpAcc?: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<DfgProjectPage>>;
|
||||
public getDfgProjects(rawOaInstitutionId?: string, authorId?: string, authorFilterIds?: Array<string>, institutionIds?: Array<string>, title?: string, keywords?: Array<string>, topicIds?: Array<string>, filterTopicIds?: Array<string>, fundingStartYears?: Array<string>, fundingEndYears?: Array<string>, page?: number, size?: number, sortBy?: string, sortDirection?: string, fuzzy?: boolean, secureFgpAcc?: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<any> {
|
||||
|
||||
let localVarQueryParameters = new HttpParams({encoder: this.encoder});
|
||||
localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { ResolveFn } from '@angular/router';
|
||||
import { of } from 'rxjs';
|
||||
import { DfgProjectPage, ProjectsService } from '../api';
|
||||
|
||||
export const dfgProjectQueryParamKeys = {
|
||||
@@ -25,34 +24,6 @@ export const RESOLVING_PROJECT_PAGE_FOR = {
|
||||
KEYWORDS_SEARCH: 'KEYWORDS_SEARCH',
|
||||
} as const;
|
||||
|
||||
// Empty page returned whenever a required numeric param fails to parse.
|
||||
const EMPTY_DFG_PROJECT_PAGE: DfgProjectPage = {
|
||||
page: 0,
|
||||
size: 0,
|
||||
total: 0,
|
||||
elements: [],
|
||||
} as DfgProjectPage;
|
||||
|
||||
function toNumberOrNull(value: unknown): number | null {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return null;
|
||||
}
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
|
||||
function toNumberArrayOrNull(values: string[]): number[] | null {
|
||||
const result: number[] = [];
|
||||
for (const value of values) {
|
||||
const parsed = toNumberOrNull(value);
|
||||
if (parsed === null) {
|
||||
return null;
|
||||
}
|
||||
result.push(parsed);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export const dfgProjectsResolver: ResolveFn<DfgProjectPage> = (
|
||||
route,
|
||||
state,
|
||||
@@ -69,11 +40,10 @@ export const dfgProjectsResolver: ResolveFn<DfgProjectPage> = (
|
||||
);
|
||||
|
||||
const page =
|
||||
toNumberOrNull(route.queryParamMap.get(dfgProjectQueryParamKeys.page)) ?? 0;
|
||||
Number(route.queryParamMap.get(dfgProjectQueryParamKeys.page)) || 0;
|
||||
|
||||
const size =
|
||||
toNumberOrNull(route.queryParamMap.get(dfgProjectQueryParamKeys.size)) ??
|
||||
10;
|
||||
Number(route.queryParamMap.get(dfgProjectQueryParamKeys.size)) || 10;
|
||||
|
||||
const searchTerm =
|
||||
route.queryParamMap.get(dfgProjectQueryParamKeys.title) ?? undefined;
|
||||
@@ -92,15 +62,12 @@ export const dfgProjectsResolver: ResolveFn<DfgProjectPage> = (
|
||||
dfgProjectQueryParamKeys.topicId,
|
||||
);
|
||||
|
||||
const institutionIds = toNumberArrayOrNull(
|
||||
route.queryParamMap.getAll(dfgProjectQueryParamKeys.institutionId),
|
||||
const institutionIds = route.queryParamMap.getAll(
|
||||
dfgProjectQueryParamKeys.institutionId,
|
||||
);
|
||||
const authorIds = toNumberArrayOrNull(
|
||||
route.queryParamMap.getAll(dfgProjectQueryParamKeys.authorId),
|
||||
const authorIds = route.queryParamMap.getAll(
|
||||
dfgProjectQueryParamKeys.authorId,
|
||||
);
|
||||
if (institutionIds === null || authorIds === null) {
|
||||
return of(EMPTY_DFG_PROJECT_PAGE);
|
||||
}
|
||||
|
||||
if (resolvingFor === RESOLVING_PROJECT_PAGE_FOR.PERSON) {
|
||||
const rawAuthorId = route.parent?.parent?.params['id'];
|
||||
|
||||
Reference in New Issue
Block a user