-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(instance-search): create computed field for sorting and filterin…
…g Date1 (#646) * feat(instance-search): create computed field for sorting and filtering Date1
- Loading branch information
1 parent
bbeb037
commit f68cd51
Showing
15 changed files
with
241 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/org/folio/search/service/setter/instance/Date1FieldProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.folio.search.service.setter.instance; | ||
|
||
import java.util.regex.Pattern; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.folio.search.domain.dto.Dates; | ||
import org.folio.search.domain.dto.Instance; | ||
import org.folio.search.service.setter.FieldProcessor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class Date1FieldProcessor implements FieldProcessor<Instance, Short> { | ||
|
||
private static final Pattern NUMERIC_REGEX = Pattern.compile("^\\d{1,4}$"); | ||
private static final String ZERO = "0"; | ||
private static final String ALPHA_U = "u"; | ||
|
||
@Override | ||
public Short getFieldValue(Instance instance) { | ||
Dates dates = instance.getDates(); | ||
if (dates != null && StringUtils.isNotEmpty(dates.getDate1())) { | ||
return normalizeDate1(dates.getDate1()); | ||
} | ||
return 0; | ||
} | ||
|
||
public Short normalizeDate1(String value) { | ||
String date1 = value.replace(ALPHA_U, ZERO); | ||
var matcher = NUMERIC_REGEX.matcher(date1); | ||
if (matcher.find()) { | ||
return Short.valueOf(matcher.group()); | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/resources/swagger.api/schemas/dto/instance/dates.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
type: object | ||
description: "Instance Dates" | ||
additionalProperties: false | ||
properties: | ||
dateTypeId: | ||
type: string | ||
description: "Date type ID" | ||
date1: | ||
type: string | ||
description: "Date1 value" | ||
date2: | ||
type: string | ||
description: "Date2 value" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.