-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ | |
<option name="Make" enabled="true" /> | ||
</method> | ||
</configuration> | ||
</component> | ||
</component> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.folio.linked.data.client; | ||
|
||
import static org.folio.linked.data.util.Constants.Cache.SPEC_RULES; | ||
|
||
import java.util.UUID; | ||
import org.folio.rspec.domain.dto.SpecificationDtoCollection; | ||
import org.folio.rspec.domain.dto.SpecificationRuleDtoCollection; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
|
||
@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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. yes, but for this one it's not necessary is it? |
||
@GetMapping(value = "/specifications?profile=bibliographic&family=MARC") | ||
ResponseEntity<SpecificationDtoCollection> getBibMarcSpecs(); | ||
|
||
@Cacheable(cacheNames = SPEC_RULES, key = "#specId") | ||
@GetMapping(value = "/specifications/{specId}/rules") | ||
ResponseEntity<SpecificationRuleDtoCollection> getSpecRules(@PathVariable("specId") UUID specId); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.folio.linked.data.job; | ||
|
||
import static org.folio.linked.data.util.Constants.Cache.SPEC_RULES; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.cache.annotation.CacheEvict; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Slf4j | ||
public class CacheCleaningJob { | ||
|
||
@CacheEvict(value = SPEC_RULES, allEntries = true) | ||
@Scheduled(fixedRateString = "${mod-linked-data.cache.ttl.spec-rules}") | ||
public void emptySpecRules() { | ||
log.info("Emptying {} cache", SPEC_RULES); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.folio.linked.data.validation.spec; | ||
|
||
import java.util.List; | ||
import org.folio.rspec.domain.dto.SpecificationRuleDto; | ||
|
||
public interface SpecProvider { | ||
|
||
List<SpecificationRuleDto> getSpecRules(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.folio.linked.data.validation.spec.impl; | ||
|
||
import feign.FeignException; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.folio.linked.data.client.SpecClient; | ||
import org.folio.linked.data.validation.spec.SpecProvider; | ||
import org.folio.rspec.domain.dto.SpecificationDto; | ||
import org.folio.rspec.domain.dto.SpecificationDtoCollection; | ||
import org.folio.rspec.domain.dto.SpecificationRuleDto; | ||
import org.folio.rspec.domain.dto.SpecificationRuleDtoCollection; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class SpecProviderImpl implements SpecProvider { | ||
|
||
private final SpecClient client; | ||
|
||
@Override | ||
public List<SpecificationRuleDto> getSpecRules() { | ||
try { | ||
return Optional.ofNullable(client.getBibMarcSpecs().getBody()) | ||
.map(SpecificationDtoCollection::getSpecifications) | ||
.stream() | ||
.flatMap(Collection::stream) | ||
.findFirst() | ||
.map(SpecificationDto::getId) | ||
.map(client::getSpecRules) | ||
.map(ResponseEntity::getBody) | ||
.map(SpecificationRuleDtoCollection::getRules) | ||
.stream() | ||
.flatMap(Collection::stream) | ||
.toList(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do (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 commentThe reason will be displayed to describe this comment to others. Learn more. not actual (caching is on Feign client now) |
||
} 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 commentThe 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 -
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 Update: |
||
} | ||
} | ||
} |
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