-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MODLD-599: LCCN validation configuration #51
Conversation
src/main/java/org/folio/linked/data/configuration/CacheConfiguration.java
Outdated
Show resolved
Hide resolved
src/main/resources/application.yml
Outdated
@@ -79,6 +79,9 @@ mod-linked-data: | |||
topic: | |||
work-search-index: ${KAFKA_WORK_SEARCH_INDEX_TOPIC:linked-data.work} | |||
instance-ingress: ${KAFKA_INVENTORY_INSTANCE_INGRESS_EVENT_TOPIC:inventory.instance_ingress} | |||
caching: | |||
ttl: | |||
specRules: 18000000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us add an environment variable for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@Override | ||
public boolean isValid(LccnRequest lccnRequest, ConstraintValidatorContext constraintValidatorContext) { | ||
if (isCurrent(lccnRequest)) { | ||
var isEnabled = specProvider.getSpecRules() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do this only if the given LCCN is current? If the LCCN is not current, then there is no need to check the configuration.
ie
if (isCurrent(lccnRequest) && isLccnFormatValidationEnabled()) {
....
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if (isCurrent(lccnRequest)) { | ||
var isEnabled = specProvider.getSpecRules() | ||
.stream() | ||
.filter(rule -> rule.getCode().equals("invalidLccnSubfieldValue")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us define a constant for "invalidLccnSubfieldValue"
Another better option is to move MarcRuleCode.java to mod-record-specifications-dto project so that we can directly refer MarcRuleCode.INVALID_LCCN_SUBFIELD.getCode()
here. @psmagin Are you ok with such an option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defined a constant for now
.map(SpecificationRuleDtoCollection::getRules) | ||
.stream() | ||
.flatMap(Collection::stream) | ||
.toList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do .filter(rule -> rule.getCode().equals("invalidLccnSubfieldValue"))
here so that we are caching only the required rule.
(This may not be possible if we implement the suggestion that @PBobylev provided. Not a big deal as the number of rules is not that big)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not actual (caching is on Feign client now)
.toList(); | ||
} catch (FeignException e) { | ||
log.error("Unexpected exception during specification rules retrieval", e); | ||
return Collections.emptyList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem with returning empty list here is that it will get cached for the next XXX hours if there is a network glitch when this call is made.
Let us check with Doug what we need to do in this case. These are the options I can think about -
- Fail the request. ie, throw an exception here. Nothing will get cached in this case.
- Process this request assuming that the LCCN format validation is not enabled. However, do not cache the empty list so that we will check the configuration again for the next request.
- Process this request assuming that the LCCN format validation is enabled. However, do not cache the empty list so that we will check the configuration again for the next request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not actual (caching is on Feign client now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us ask Doug on Monday what we should do in this case
Fail the request or process the request assuming that lccn validation is disabled.
Update:
Never mind. I see the following line in ticket
If the microservice is down, assume that the value is disabled / turned off.
var specRule = new SpecificationRuleDto(); | ||
specRule.setCode("invalidLccnSubfieldValue"); | ||
specRule.setEnabled(true); | ||
specRules.setRules(List.of(specRule)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess we can extract data preparation to separate method to make the test shorter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
private LccnRequest createLccnRequest(String value, String link) { | ||
return new LccnRequest() | ||
.value(List.of(value)) | ||
.status(link == null ? emptyList() : List.of(new Status().link(List.of(link)))); | ||
} | ||
|
||
private static SpecificationRuleDto createSpecRule(boolean enabled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can return List here, so no need to explicitly wrap spec rule each time in arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
193cf5e
to
d1e344a
Compare
@@ -61,6 +61,7 @@ To run mod-linked-data in standalone mode, set the value of the environment vari | |||
| KAFKA_WORK_SEARCH_INDEX_TOPIC_PARTITIONS`*` | 1 | Custom Work Search Index topic partitions number | | |||
| KAFKA_WORK_SEARCH_INDEX_TOPIC_REPLICATION_FACTOR`*` | - | Custom Work Search Index topic replication factor | | |||
| KAFKA_INVENTORY_INSTANCE_INGRESS_EVENT_TOPIC`*` | inventory.instance_ingress | Custom Inventory Instance Ingress Event topic name | | |||
| CACHE_TTL_SPEC_RULES_MS | 18000000 | Specifies time to live for `spec-rules` cache | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us define this in the module descriptor file also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@FeignClient(name = "specification-storage") | ||
public interface SpecClient { | ||
|
||
@Cacheable(cacheNames = "bib-marc-specs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this cache is not evicted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but for this one it's not necessary is it?
.toList(); | ||
} catch (FeignException e) { | ||
log.error("Unexpected exception during specification rules retrieval", e); | ||
return Collections.emptyList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us ask Doug on Monday what we should do in this case
Fail the request or process the request assuming that lccn validation is disabled.
Update:
Never mind. I see the following line in ticket
If the microservice is down, assume that the value is disabled / turned off.
5956bf8
to
7116ad0
Compare
Quality Gate passedIssues Measures |
No description provided.