Commit 807fac81 authored by Artem Hrybeniuk's avatar Artem Hrybeniuk
Browse files

Merge branch 'code-value-handling-and-caching' into 'main'

Updated handling of Code Values

See merge request grin-global/grin-global-server!387
parents ca7a16b7 72b5807b
......@@ -50,4 +50,9 @@ public @interface CodeValueField {
* This CV field translated titles should be included in full-text index
*/
boolean indexed() default false;
/**
* The CV must be valid and declared. Set to false to avoid validation check.
*/
boolean strict() default true;
}
......@@ -31,12 +31,18 @@ public class CodeValueValidator implements ConstraintValidator<CodeValueField, S
*/
private String groupName;
/**
* When not strict then validation is skipped.
*/
private boolean strict;
/**
* Initializes the validator.
*/
@Override
public void initialize(CodeValueField constraintAnnotation) {
this.groupName = constraintAnnotation.value();
this.strict = constraintAnnotation.strict();
}
/**
......@@ -45,7 +51,7 @@ public class CodeValueValidator implements ConstraintValidator<CodeValueField, S
*/
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
if (StringUtils.isBlank(value)) {
if (StringUtils.isBlank(value) || !strict) {
return true; // nothing to validate here
}
......
......@@ -80,7 +80,7 @@ public class TaxonomyFamily extends CooperatorOwnedModel implements Copyable<Tax
@Basic
@Column(name = "suprafamily_rank_code", length = 20)
@CodeValueField("TAXONOMY_SUPRAFAMILY")
@CodeValueField(value = "TAXONOMY_SUPRAFAMILY", strict = false)
private String suprafamilyRankCode;
@Basic
......
......@@ -62,7 +62,7 @@ public class TaxonomyGenus extends CooperatorOwnedModel implements Copyable<Taxo
@Basic
@Column(name = "hybrid_code", length = 20)
@CodeValueField("GENUS_HYBRID")
@CodeValueField(value = "GENUS_HYBRID", strict = false)
private String hybridCode;
@Id
......@@ -81,7 +81,7 @@ public class TaxonomyGenus extends CooperatorOwnedModel implements Copyable<Taxo
@Basic
@Column(name = "qualifying_code", length = 20)
@CodeValueField("TAXONOMY_GENUS_QUALIFIER")
@CodeValueField(value = "TAXONOMY_GENUS_QUALIFIER", strict = false)
private String qualifyingCode;
@Basic
......
......@@ -70,7 +70,7 @@ public class TaxonomySpecies extends CooperatorOwnedModel implements Copyable<Ta
@Basic
@Column(name = "common_fertilization_code", length = 20)
@CodeValueField("TAXONOMY_FERTILIZATION_METHOD")
@CodeValueField(value = "TAXONOMY_FERTILIZATION_METHOD", strict = false)
private String commonFertilizationCode;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
......@@ -132,7 +132,7 @@ public class TaxonomySpecies extends CooperatorOwnedModel implements Copyable<Ta
@Basic
@Column(name = "life_form_code", length = 20)
@CodeValueField("ACCESSION_LIFE_FORM")
@CodeValueField(value = "ACCESSION_LIFE_FORM", strict = false)
private String lifeFormCode;
@Basic
......@@ -179,7 +179,7 @@ public class TaxonomySpecies extends CooperatorOwnedModel implements Copyable<Ta
@Basic
@Column(name = "restriction_code", length = 20)
@CodeValueField("TAXONOMY_RESTRICTION")
@CodeValueField(value = "TAXONOMY_RESTRICTION", strict = false)
private String restrictionCode;
@Basic
......@@ -213,7 +213,7 @@ public class TaxonomySpecies extends CooperatorOwnedModel implements Copyable<Ta
@Basic
@Column(name = "synonym_code", length = 20)
@CodeValueField("TAXONOMY_SPECIES_QUALIFIER")
@CodeValueField(value = "TAXONOMY_SPECIES_QUALIFIER", strict = false)
private String synonymCode;
@ManyToOne(fetch = FetchType.EAGER, cascade = {})
......
......@@ -78,6 +78,24 @@ public class CacheController {
return "redirect:/admin/cache/";
}
@RequestMapping(method = RequestMethod.POST, value = "/dump")
public String dumpCache(@RequestParam(required = true, value = "name") String cacheName) {
final Cache cache = cacheManager.getCache(cacheName);
if (cache != null) {
LOG.warn("Inspecting cache {} of type {}", cacheName, cache.getNativeCache().getClass());
var nativeCache = cache.getNativeCache();
if (nativeCache instanceof IMap<?,?>) {
var hzMap = (IMap<?,?>) nativeCache;
hzMap.forEach((key, value) -> {
LOG.warn("Key={} [{}]: [{}]\n\t={}", key, key.getClass(), value.getClass(), value);
});
}
} else {
LOG.info("No such cache: {}", cacheName);
}
return "redirect:/admin/cache/";
}
@RequestMapping("/")
public String cacheStats(Model model) {
List<CacheStats> cacheMaps = new ArrayList<CacheStats>();
......
......@@ -172,9 +172,9 @@ public class CodeValueServiceImpl extends FilteredTranslatedCRUDServiceImpl<Code
}
@Override
@Transactional
@Transactional(propagation = Propagation.REQUIRES_NEW)
@PreAuthorize("hasAuthority('GROUP_ADMINS')")
@CacheEvict(allEntries = true)
@CacheEvict(key = "'codevalue-' + #groupName + '-' + #value")
public CodeValue ensureCodeValue(String groupName, String value, String title, String description) {
CodeValue codeValue = repository.getByGroupNameAndValue(groupName, value);
......@@ -189,13 +189,13 @@ public class CodeValueServiceImpl extends FilteredTranslatedCRUDServiceImpl<Code
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
@Cacheable(key = "'codevalue-' + #groupName + '-' + #value")
@Cacheable(key = "'codevalue-' + #groupName + '-' + #value", sync = true)
public boolean validate(String groupName, String value) {
return repository.existsCodeValueByGroupNameAndValue(groupName, value);
}
@Override
@Cacheable
@Cacheable(key = "'mcpdOfCode-' + #groupName + '-' + #value", sync = true)
public String findMcpdOfCodeValue(String groupName, String value) {
SysLang sl = languageService.getLanguage(MCPD_IETF_TAG);
CodeValue cv = repository.getByGroupNameAndValue(groupName, value);
......@@ -207,7 +207,7 @@ public class CodeValueServiceImpl extends FilteredTranslatedCRUDServiceImpl<Code
}
@Override
@Cacheable
@Cacheable(key = "'codeOfMcpd-' + #groupName + '-' + #mcpd", sync = true)
public String findCodeValueOfMCPD(String groupName, Integer mcpd) {
if (mcpd == null)
return null;
......
......@@ -129,8 +129,9 @@ public class UsdaGeographyUpdater {
// Add missing GEOGRAPHY_COUNTRY_CODE code values
{
ggGeo.stream().map(geo -> geo.countryCode).filter(StringUtils::isNotBlank).distinct().forEach(countryCode -> {
//codeValueService.ensureCodeValue(CommunityCodeValues.GEOGRAPHY_COUNTRY_CODE, countryCode, countryCode, null);
codeValueService.ensureCodeValue(CommunityCodeValues.GEOGRAPHY_COUNTRY_CODE, countryCode, countryCode, null);
if (! codeValueService.validate(CommunityCodeValues.GEOGRAPHY_COUNTRY_CODE, countryCode)) {
codeValueService.ensureCodeValue(CommunityCodeValues.GEOGRAPHY_COUNTRY_CODE, countryCode, countryCode, null);
}
});
}
......@@ -292,6 +293,6 @@ public class UsdaGeographyUpdater {
});
}
LOG.warn("Done.");
LOG.warn("Done. Transaction will now be committed.");
}
}
......@@ -578,7 +578,7 @@ public class UsdaTaxonomyUpdater {
toSave.clear();
}
LOG.warn("Done.");
LOG.warn("Done. Transaction will now be committed.");
}
static void downloadDataIfNeeded(File folder) throws IOException {
......
......@@ -132,6 +132,7 @@
1491 TAXONOMY_SPECIES_QUALIFIER = 2010-01-01 00:00:00 1 2016-04-19 19:11:20 48 1994-08-24 00:00:00 1
1493 TAXONOMY_SPECIES_QUALIFIER B 2010-01-01 00:00:00 1 2011-10-06 00:10:28 48 1993-09-16 00:00:00 1
1494 TAXONOMY_SPECIES_QUALIFIER S 2010-01-01 00:00:00 1 2016-04-19 19:10:42 48 1993-09-15 00:00:00 1
1495 TAXONOMY_SPECIES_QUALIFIER I 2010-01-01 00:00:00 1 2016-04-19 19:10:42 48 1993-09-15 00:00:00 1
1496 DATE_FORMAT dd/MM/yyyy 2010-01-01 00:00:00 1 2014-10-09 17:54:03 48 2005-08-17 00:00:00 1
1497 DATE_FORMAT MM/dd/yyyy 2010-01-01 00:00:00 1 2014-10-09 17:54:03 48 1993-09-21 00:00:00 1
1498 DATE_FORMAT MM/yyyy 2010-01-01 00:00:00 1 2014-10-09 17:54:03 48 1993-09-21 00:00:00 1
......
......@@ -132,6 +132,7 @@
1491 1491 1 Homotypic synonym A synonym based on the same type 2010-01-01 00:00:00 1 2019-06-18 16:09:21 48 2009-01-09 00:00:00 1
1493 1493 1 Basionym The legitimate name that provides the epithet for a new combination or new rank 2010-01-01 00:00:00 1 2019-06-18 16:09:21 48 2009-01-09 00:00:00 1
1494 1494 1 Heterotypic synonym A synonym based on a different type 2010-01-01 00:00:00 1 2019-06-18 16:09:21 48 2009-01-09 00:00:00 1
1495 1495 1 Invalid An associated designation that was not validly published 2010-01-01 00:00:00 1 2019-06-18 16:09:21 48 2009-01-09 00:00:00 1
1496 1496 1 dd/mm/yyyy \N 2010-01-01 00:00:00 1 2014-10-09 17:54:03 48 2009-01-09 00:00:00 1
1497 1497 1 mm/dd/yyyy \N 2010-01-01 00:00:00 1 2014-10-09 17:54:03 48 2009-01-09 00:00:00 1
1498 1498 1 mm/yyyy \N 2010-01-01 00:00:00 1 2014-10-09 17:54:04 48 2009-01-09 00:00:00 1
......
......@@ -32,7 +32,7 @@
<td style="text-align: right;">
Efficiency
</td>
<td class="col-sm-1 col-xs-2">
<td class="col-xs-1">
<form class="form-inline" method="post"
action="<c:url value="/admin/cache/clearCache" />">
<button type="submit" name="clearAll" class="btn btn-warning">Zap!</button>
......@@ -80,8 +80,8 @@
</p>
</c:if>
</td>
<td class="col-sm-1 col-xs-2">
<td class="col-xs-1">
<form method="post"
action="<c:url value="/admin/cache/clearCache" />">
<input type="hidden" name="name" value="${cacheMap.name}" />
......@@ -91,6 +91,17 @@
value="${_csrf.token}" />
</form>
</td>
<td class="col-xs-1">
<form method="post"
action="<c:url value="/admin/cache/dump" />">
<input type="hidden" name="name" value="${cacheMap.name}" />
<button type="submit" class="btn btn-default btn-sm">Dump</button>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}"
value="${_csrf.token}" />
</form>
</td>
</tr>
</c:forEach>
</tbody>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment