9996: add year date range filter + minor fix
This commit is contained in:
parent
f23acfff89
commit
60cc376d40
|
@ -9,9 +9,6 @@ import jakarta.validation.constraints.Pattern;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
import static eu.openaire.api.mappers.Utils.API_CURSOR_DESC;
|
import static eu.openaire.api.mappers.Utils.API_CURSOR_DESC;
|
||||||
import static eu.openaire.api.mappers.Utils.API_PAGE_DESC;
|
import static eu.openaire.api.mappers.Utils.API_PAGE_DESC;
|
||||||
|
@ -77,32 +74,28 @@ public class ProjectRequest implements PaginatedRequest {
|
||||||
private String[] fundingStreamId;
|
private String[] fundingStreamId;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
description = "Gets the projects with start date greater than or equal to the given date. Please provide a date formatted as YYYY-MM-DD",
|
description = "Gets the projects with start date greater than or equal to the given date. Provide a date in YYYY or YYYY-MM-DD format",
|
||||||
schema = @Schema(type = "string", format = "date")
|
schema = @Schema(type = "string")
|
||||||
)
|
)
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
private String fromStartDate;
|
||||||
private LocalDate fromStartDate;
|
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
description = "Gets the projects with start date less than or equal to the given date. Please provide a date formatted as YYYY-MM-DD",
|
description = "Gets the projects with start date less than or equal to the given date. Provide a date in YYYY or YYYY-MM-DD format",
|
||||||
schema = @Schema(type = "string", format = "date")
|
schema = @Schema(type = "string")
|
||||||
)
|
)
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
private String toStartDate;
|
||||||
private LocalDate toStartDate;
|
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
description = "Gets the projects with end date greater than or equal to the given date. Please provide a date formatted as YYYY-MM-DD",
|
description = "Gets the projects with end date greater than or equal to the given date. Provide a date in YYYY or YYYY-MM-DD format",
|
||||||
schema = @Schema(type = "string", format = "date")
|
schema = @Schema(type = "string")
|
||||||
)
|
)
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
private String fromEndDate;
|
||||||
private LocalDate fromEndDate;
|
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
description = "Gets the projects with end date less than or equal to the given date. Please provide a date formatted as YYYY-MM-DD",
|
description = "Gets the projects with end date less than or equal to the given date. Provide a date in YYYY or YYYY-MM-DD format",
|
||||||
schema = @Schema(type = "string", format = "date")
|
schema = @Schema(type = "string")
|
||||||
)
|
)
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
private String toEndDate;
|
||||||
private LocalDate toEndDate;
|
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
description = "The name or short name of the related organization",
|
description = "The name or short name of the related organization",
|
||||||
|
|
|
@ -9,9 +9,6 @@ import jakarta.validation.constraints.Pattern;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
import static eu.openaire.api.mappers.Utils.API_CURSOR_DESC;
|
import static eu.openaire.api.mappers.Utils.API_CURSOR_DESC;
|
||||||
import static eu.openaire.api.mappers.Utils.API_PAGE_DESC;
|
import static eu.openaire.api.mappers.Utils.API_PAGE_DESC;
|
||||||
|
@ -76,18 +73,14 @@ public class ResearchProductsRequest implements PaginatedRequest {
|
||||||
private String[] type;
|
private String[] type;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
description = "Gets the research products whose publication date is greater than or equal to he given date. Please provide a date formatted as YYYY-MM-DD",
|
description = "Gets the research products whose publication date is greater than or equal to he given date. Provide a date in YYYY or YYYY-MM-DD format",
|
||||||
schema = @Schema(type = "string", format = "date")
|
schema = @Schema(type = "string"))
|
||||||
)
|
private String fromPublicationDate;
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
|
||||||
private LocalDate fromPublicationDate;
|
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
description = "Gets the research products whose publication date is less than or equal to the given date. Please provide a date formatted as YYYY-MM-DD",
|
description = "Gets the research products whose publication date is less than or equal to the given date. Provide a date in YYYY or YYYY-MM-DD format",
|
||||||
schema = @Schema(type = "string", format = "date")
|
schema = @Schema(type = "string"))
|
||||||
)
|
private String toPublicationDate;
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
|
||||||
private LocalDate toPublicationDate;
|
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
description = "List of subjects associated to the research product",
|
description = "List of subjects associated to the research product",
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.time.LocalDateTime;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.format.DateTimeParseException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
@ -38,7 +39,7 @@ public class Utils {
|
||||||
indicating that there are no more results.
|
indicating that there are no more results.
|
||||||
""";
|
""";
|
||||||
|
|
||||||
static public String escapeAndJoin(String[] tokens, String predicate, boolean addQuotes, String suffix) {
|
public static String escapeAndJoin(String[] tokens, String predicate, boolean addQuotes, String suffix) {
|
||||||
|
|
||||||
tokens = Arrays.stream(tokens)
|
tokens = Arrays.stream(tokens)
|
||||||
// remove empty tokens
|
// remove empty tokens
|
||||||
|
@ -51,7 +52,7 @@ public class Utils {
|
||||||
return String.join(" " + predicate + " ", tokens);
|
return String.join(" " + predicate + " ", tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public String handleInput(String token, boolean addQuotes, String suffix) {
|
public static String handleInput(String token, boolean addQuotes, String suffix) {
|
||||||
|
|
||||||
boolean hasLogicalOperator = containsLogicalOperator(token);
|
boolean hasLogicalOperator = containsLogicalOperator(token);
|
||||||
|
|
||||||
|
@ -73,11 +74,11 @@ public class Utils {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
static private boolean containsLogicalOperator(String input) {
|
private static boolean containsLogicalOperator(String input) {
|
||||||
return input.contains("AND") || input.contains("OR") || input.contains("NOT");
|
return input.contains("AND") || input.contains("OR") || input.contains("NOT");
|
||||||
}
|
}
|
||||||
|
|
||||||
static public String escapeInput(String input, String suffix) {
|
public static String escapeInput(String input, String suffix) {
|
||||||
|
|
||||||
// Split the input into tokens at whitespace or parentheses or quotes
|
// Split the input into tokens at whitespace or parentheses or quotes
|
||||||
String[] tokens = input.split("(\\s+|(?=[()\\\"]|(?<=[()\\\"])))");
|
String[] tokens = input.split("(\\s+|(?=[()\\\"]|(?<=[()\\\"])))");
|
||||||
|
@ -163,24 +164,66 @@ public class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static private void removeLastElementIfSpace(List<String> list) {
|
private static void removeLastElementIfSpace(List<String> list) {
|
||||||
if (list.get(list.size() - 1).equals(" ")) {
|
if (list.get(list.size() - 1).equals(" ")) {
|
||||||
list.remove(list.size() - 1);
|
list.remove(list.size() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public boolean isNullOrEmpty(String str) {
|
public static boolean isNullOrEmpty(String str) {
|
||||||
return str == null || str.isBlank();
|
return str == null || str.isBlank();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public boolean isNullOrEmpty(String[] str) {
|
public static boolean isNullOrEmpty(String[] str) {
|
||||||
return str == null || str.length == 0;
|
return str == null || str.length == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static private String formatDate(LocalDate date) {
|
public static String formatSolrDateRange(String fieldName, String fromDate, String toDate) {
|
||||||
|
|
||||||
|
if (fromDate != null && toDate != null) {
|
||||||
|
return String.format(fieldName,
|
||||||
|
appendHHMMSS(appendMMDD(fromDate, "-01-01")),
|
||||||
|
appendHHMMSS(appendMMDD(toDate, "-12-31")));
|
||||||
|
} else {
|
||||||
|
if (fromDate != null) {
|
||||||
|
return String.format(fieldName,
|
||||||
|
appendHHMMSS(appendMMDD(fromDate, "-01-01")), "*");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toDate != null) {
|
||||||
|
return String.format(fieldName, "*",
|
||||||
|
appendHHMMSS(appendMMDD(toDate, "-12-31")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Append -mm-dd if date came in yyyy format
|
||||||
|
* @return LocalDate in yyyy-mm-dd format
|
||||||
|
*/
|
||||||
|
private static LocalDate appendMMDD(String date, String monthDaySuffix) {
|
||||||
|
try {
|
||||||
|
if (date.length() == 10) { //yyyy-mm-dd
|
||||||
|
return LocalDate.parse(date);
|
||||||
|
} else if (date.length() == 4) { //yyyy
|
||||||
|
return LocalDate.parse(date + monthDaySuffix);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Invalid date format");
|
||||||
|
}
|
||||||
|
} catch (DateTimeParseException e) {
|
||||||
|
throw new IllegalArgumentException("Failed to parse date: " + date, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* The incoming date comes in yyyy-mm-dd, so we have to append hh-mm-ss, also.
|
||||||
|
* @return String in yyyy-MM-dd'T'HH:mm:ss'Z' format
|
||||||
|
*/
|
||||||
|
private static String appendHHMMSS(LocalDate date) {
|
||||||
|
|
||||||
// IMPORTANT: all dates are indexed in 12:00:00 in the index (not sure why)
|
// IMPORTANT: all dates are indexed in 12:00:00 in the index (not sure why)
|
||||||
// so we need to set this time to the date (this should change if dates are indexed in a different way)
|
// so we need to set this time to the date (this should change if dates are indexed in a different way)
|
||||||
|
@ -200,23 +243,7 @@ public class Utils {
|
||||||
return zdt.format(formatter);
|
return zdt.format(formatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public String formatSolrDateRange(String fieldName, LocalDate fromDate, LocalDate toDate) {
|
public static List<SolrQuery.SortClause> formatSortByParam(String sortBy, Map<String, String> fieldMapping) {
|
||||||
|
|
||||||
if (fromDate != null && toDate != null) {
|
|
||||||
return String.format(fieldName, Utils.formatDate(fromDate), Utils.formatDate(toDate));
|
|
||||||
} else {
|
|
||||||
if (fromDate != null) {
|
|
||||||
return String.format(fieldName, Utils.formatDate(fromDate), "*");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toDate != null) {
|
|
||||||
return String.format(fieldName, "*", Utils.formatDate(toDate));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
static public List<SolrQuery.SortClause> formatSortByParam(String sortBy, Map<String, String> fieldMapping) {
|
|
||||||
|
|
||||||
if (Utils.isNullOrEmpty(sortBy)) {
|
if (Utils.isNullOrEmpty(sortBy)) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -139,11 +139,8 @@ public interface ResearchProductMapper {
|
||||||
return null;
|
return null;
|
||||||
List<Pid> orcid = authorPidList
|
List<Pid> orcid = authorPidList
|
||||||
.stream()
|
.stream()
|
||||||
.filter(
|
.filter(ap -> ModelConstants.ORCID.equals(ap.getTypeCode()))
|
||||||
ap -> ap
|
.toList();
|
||||||
.getTypeCode()
|
|
||||||
.equals(ModelConstants.ORCID))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
if (orcid.size() == 1) {
|
if (orcid.size() == 1) {
|
||||||
return getAuthorPid(orcid.get(0));
|
return getAuthorPid(orcid.get(0));
|
||||||
}
|
}
|
||||||
|
@ -151,11 +148,8 @@ public interface ResearchProductMapper {
|
||||||
return null;
|
return null;
|
||||||
orcid = authorPidList
|
orcid = authorPidList
|
||||||
.stream()
|
.stream()
|
||||||
.filter(
|
.filter(ap -> ModelConstants.ORCID_PENDING.equals(ap.getTypeCode()))
|
||||||
ap -> ap
|
.toList();
|
||||||
.getTypeCode()
|
|
||||||
.equals(ModelConstants.ORCID_PENDING))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
if (orcid.size() == 1) {
|
if (orcid.size() == 1) {
|
||||||
return getAuthorPid(orcid.get(0));
|
return getAuthorPid(orcid.get(0));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue