Skip to content
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

Merged
merged 3 commits into from
Nov 25, 2024
Merged

Conversation

askhat-abishev
Copy link
Contributor

No description provided.

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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()
Copy link
Contributor

@pkjacob pkjacob Nov 21, 2024

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()) {
    ....
}

Copy link
Contributor Author

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"))
Copy link
Contributor

@pkjacob pkjacob Nov 21, 2024

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?

Copy link
Contributor Author

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

@pkjacob pkjacob requested a review from psmagin November 21, 2024 15:41
.map(SpecificationRuleDtoCollection::getRules)
.stream()
.flatMap(Collection::stream)
.toList();
Copy link
Contributor

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)

Copy link
Contributor Author

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();
Copy link
Contributor

@pkjacob pkjacob Nov 21, 2024

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 -

  1. Fail the request. ie, throw an exception here. Nothing will get cached in this case.
  2. 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.
  3. 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.

Copy link
Contributor Author

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)

Copy link
Contributor

@pkjacob pkjacob Nov 22, 2024

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));
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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 |
Copy link
Contributor

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.

Copy link
Contributor Author

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")
Copy link
Contributor

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.

Copy link
Contributor Author

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();
Copy link
Contributor

@pkjacob pkjacob Nov 22, 2024

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.

@askhat-abishev askhat-abishev merged commit 5936126 into master Nov 25, 2024
6 checks passed
@askhat-abishev askhat-abishev deleted the MODLD-599 branch November 25, 2024 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants