diff --git a/nrich-registry/build.gradle b/nrich-registry/build.gradle index e16413de6..6e95b70d7 100644 --- a/nrich-registry/build.gradle +++ b/nrich-registry/build.gradle @@ -14,6 +14,7 @@ dependencies { enversImplementation "org.hibernate:hibernate-envers" implementation project(":nrich-search") + implementation "org.apache.commons:commons-lang3" implementation "com.fasterxml.jackson.core:jackson-databind" implementation "org.springframework.data:spring-data-jpa" implementation "org.modelmapper:modelmapper" diff --git a/nrich-registry/src/main/java/net/croz/nrich/registry/configuration/service/DefaultRegistryConfigurationService.java b/nrich-registry/src/main/java/net/croz/nrich/registry/configuration/service/DefaultRegistryConfigurationService.java index 80a44b041..cc1563c32 100644 --- a/nrich-registry/src/main/java/net/croz/nrich/registry/configuration/service/DefaultRegistryConfigurationService.java +++ b/nrich-registry/src/main/java/net/croz/nrich/registry/configuration/service/DefaultRegistryConfigurationService.java @@ -11,12 +11,14 @@ import net.croz.nrich.registry.configuration.comparator.RegistryPropertyComparator; import net.croz.nrich.registry.configuration.constants.RegistryConfigurationConstants; import net.croz.nrich.registry.configuration.util.JavaToJavascriptTypeConversionUtil; +import net.croz.nrich.registry.core.constants.RegistryCoreConstants; import net.croz.nrich.registry.core.constants.RegistryEnversConstants; import net.croz.nrich.registry.core.model.PropertyWithType; import net.croz.nrich.registry.core.model.RegistryGroupDefinitionHolder; import net.croz.nrich.registry.core.model.RegistryHistoryConfigurationHolder; import net.croz.nrich.registry.core.support.ManagedTypeWrapper; import net.croz.nrich.registry.core.util.AnnotationUtil; +import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.Cacheable; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; @@ -30,6 +32,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.function.Predicate; @@ -187,8 +190,9 @@ private RegistryPropertyConfiguration resolveRegistryPropertyConfiguration(Strin JavascriptType javascriptType = JavaToJavascriptTypeConversionUtil.fromJavaType(attributeType); boolean isDecimal = JavaToJavascriptTypeConversionUtil.isDecimal(attributeType); - String formLabel = formLabel(entityTypePrefix, attributeType, attributeName); - String columnHeader = columnHeader(entityTypePrefix, attributeType, attributeName); + String attributeDisplayName = convertToDisplayValue(attributeName); + String formLabel = formLabel(entityTypePrefix, attributeType, attributeName, attributeDisplayName); + String columnHeader = columnHeader(entityTypePrefix, attributeType, attributeName, attributeDisplayName); return RegistryPropertyConfiguration.builder() .name(attributeName) @@ -224,20 +228,20 @@ private String registryDisplayLabel(Class entityType) { return messageSource.getMessage(messageSourceResolvable, LocaleContextHolder.getLocale()); } - private String formLabel(String entityTypePrefix, Class attributeType, String attributeName) { + private String formLabel(String entityTypePrefix, Class attributeType, String attributeName, String attributeDisplayName) { String[] messageCodeList = labelMessageCodeList(entityTypePrefix, attributeType, attributeName).toArray(new String[0]); - DefaultMessageSourceResolvable messageSourceResolvable = new DefaultMessageSourceResolvable(messageCodeList, attributeName); + DefaultMessageSourceResolvable messageSourceResolvable = new DefaultMessageSourceResolvable(messageCodeList, attributeDisplayName); return messageSource.getMessage(messageSourceResolvable, LocaleContextHolder.getLocale()); } - private String columnHeader(String entityTypePrefix, Class attributeType, String attributeName) { + private String columnHeader(String entityTypePrefix, Class attributeType, String attributeName, String attributeDisplayName) { List headerMessageCodeList = new ArrayList<>(); headerMessageCodeList.add(String.format(RegistryConfigurationConstants.REGISTRY_COLUMN_HEADER_FORMAT, entityTypePrefix, attributeName)); headerMessageCodeList.addAll(labelMessageCodeList(entityTypePrefix, attributeType, attributeName)); - DefaultMessageSourceResolvable messageSourceResolvable = new DefaultMessageSourceResolvable(headerMessageCodeList.toArray(new String[0]), attributeName); + DefaultMessageSourceResolvable messageSourceResolvable = new DefaultMessageSourceResolvable(headerMessageCodeList.toArray(new String[0]), attributeDisplayName); return messageSource.getMessage(messageSourceResolvable, LocaleContextHolder.getLocale()); } @@ -265,4 +269,13 @@ private RegistryOverrideConfiguration resolveRegistryOverrideConfiguration(Class return registryOverrideConfigurationMap.get(type); } + + private String convertToDisplayValue(String attributeName) { + List attributeWordList = Arrays.stream(StringUtils.splitByCharacterTypeCamelCase(attributeName)) + .map(value -> value.trim().toLowerCase(Locale.ROOT)) + .filter(value -> !RegistryCoreConstants.DOT.equals(value)) + .collect(Collectors.toList()); + + return StringUtils.capitalize(String.join(RegistryCoreConstants.SPACE, attributeWordList)); + } } diff --git a/nrich-registry/src/main/java/net/croz/nrich/registry/core/constants/RegistryCoreConstants.java b/nrich-registry/src/main/java/net/croz/nrich/registry/core/constants/RegistryCoreConstants.java new file mode 100644 index 000000000..f4ab40b12 --- /dev/null +++ b/nrich-registry/src/main/java/net/croz/nrich/registry/core/constants/RegistryCoreConstants.java @@ -0,0 +1,13 @@ +package net.croz.nrich.registry.core.constants; + +public final class RegistryCoreConstants { + + public static final String BLANK = ""; + + public static final String DOT = "."; + + public static final String SPACE = " "; + + private RegistryCoreConstants() { + } +} diff --git a/nrich-registry/src/main/java/net/croz/nrich/registry/core/constants/RegistryQueryConstants.java b/nrich-registry/src/main/java/net/croz/nrich/registry/core/constants/RegistryQueryConstants.java index 1d5ba0e4f..19b2873a9 100644 --- a/nrich-registry/src/main/java/net/croz/nrich/registry/core/constants/RegistryQueryConstants.java +++ b/nrich-registry/src/main/java/net/croz/nrich/registry/core/constants/RegistryQueryConstants.java @@ -16,8 +16,6 @@ public final class RegistryQueryConstants { public static final String FIND_QUERY_JOIN_FETCH = " left join fetch " + ENTITY_ALIAS + ".%s "; - public static final String QUERY_JOIN_SEPARATOR = " "; - private RegistryQueryConstants() { } } diff --git a/nrich-registry/src/main/java/net/croz/nrich/registry/core/service/DefaultRegistryConfigurationResolverService.java b/nrich-registry/src/main/java/net/croz/nrich/registry/core/service/DefaultRegistryConfigurationResolverService.java index 7614e0f0b..1a9b93f05 100644 --- a/nrich-registry/src/main/java/net/croz/nrich/registry/core/service/DefaultRegistryConfigurationResolverService.java +++ b/nrich-registry/src/main/java/net/croz/nrich/registry/core/service/DefaultRegistryConfigurationResolverService.java @@ -4,6 +4,7 @@ import net.croz.nrich.registry.api.core.model.RegistryConfiguration; import net.croz.nrich.registry.api.core.model.RegistryOverrideConfiguration; import net.croz.nrich.registry.api.core.model.RegistryOverrideConfigurationHolder; +import net.croz.nrich.registry.core.constants.RegistryCoreConstants; import net.croz.nrich.registry.core.constants.RegistryEnversConstants; import net.croz.nrich.registry.core.model.PropertyWithType; import net.croz.nrich.registry.core.model.RegistryDataConfiguration; @@ -172,8 +173,8 @@ private SearchConfiguration> emptySearchConf SearchConfiguration> searchConfiguration = SearchConfiguration.emptyConfigurationMatchingAny(); List>> searchJoinList = Stream.concat( - createSearchJoinStreamFromAssociationList(managedTypeWrapper.getSingularAssociationList(), ""), - createSearchJoinStreamFromAssociationList(managedTypeWrapper.getSingularEmbeddedTypeAssociationList(), managedTypeWrapper.getIdAttributeName() + ".")) + createSearchJoinStreamFromAssociationList(managedTypeWrapper.getSingularAssociationList(), RegistryCoreConstants.BLANK), + createSearchJoinStreamFromAssociationList(managedTypeWrapper.getSingularEmbeddedTypeAssociationList(), managedTypeWrapper.getIdAttributeName() + RegistryCoreConstants.DOT)) .collect(Collectors.toList()); searchConfiguration.setJoinList(searchJoinList); diff --git a/nrich-registry/src/main/java/net/croz/nrich/registry/core/service/EntityManagerRegistryEntityFinderService.java b/nrich-registry/src/main/java/net/croz/nrich/registry/core/service/EntityManagerRegistryEntityFinderService.java index 7a95e0a74..21f2f6778 100644 --- a/nrich-registry/src/main/java/net/croz/nrich/registry/core/service/EntityManagerRegistryEntityFinderService.java +++ b/nrich-registry/src/main/java/net/croz/nrich/registry/core/service/EntityManagerRegistryEntityFinderService.java @@ -3,6 +3,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import net.croz.nrich.registry.api.core.service.RegistryEntityFinderService; +import net.croz.nrich.registry.core.constants.RegistryCoreConstants; import net.croz.nrich.registry.core.constants.RegistryQueryConstants; import net.croz.nrich.registry.core.support.ManagedTypeWrapper; import org.modelmapper.ModelMapper; @@ -33,7 +34,7 @@ public T findEntityInstance(Class type, Object id) { String joinFetchQueryPart = classNameManagedTypeWrapperMap.get(type.getName()).getSingularAssociationList().stream() .map(attribute -> String.format(RegistryQueryConstants.FIND_QUERY_JOIN_FETCH, attribute.getName())) - .collect(Collectors.joining(RegistryQueryConstants.QUERY_JOIN_SEPARATOR)); + .collect(Collectors.joining(RegistryCoreConstants.SPACE)); String entityWithAlias = String.format(RegistryQueryConstants.PROPERTY_SPACE_FORMAT, type.getName(), RegistryQueryConstants.ENTITY_ALIAS); String querySelectPart = String.format(RegistryQueryConstants.PROPERTY_SPACE_FORMAT, entityWithAlias, joinFetchQueryPart.trim()); diff --git a/nrich-registry/src/test/java/net/croz/nrich/registry/configuration/service/DefaultRegistryConfigurationServiceTest.java b/nrich-registry/src/test/java/net/croz/nrich/registry/configuration/service/DefaultRegistryConfigurationServiceTest.java index 422f90aa9..84bcea858 100644 --- a/nrich-registry/src/test/java/net/croz/nrich/registry/configuration/service/DefaultRegistryConfigurationServiceTest.java +++ b/nrich-registry/src/test/java/net/croz/nrich/registry/configuration/service/DefaultRegistryConfigurationServiceTest.java @@ -62,6 +62,12 @@ void shouldResolveConfigurationWithOverrideDefined() { assertThat(registryEntityConfiguration.getPropertyConfigurationList()).hasSize(5); assertThat(registryEntityConfiguration.getPropertyConfigurationList()).extracting("name").containsExactly("name", "id", "nonEditableProperty", "floatNumber", "doubleNumber"); + assertThat(registryEntityConfiguration.getPropertyConfigurationList()).extracting("formLabel").containsExactly( + "Name of property", "Id", "Non editable property", "Float number", "Double number" + ); + assertThat(registryEntityConfiguration.getPropertyConfigurationList()).extracting("columnHeader").containsExactly( + "Header of property", "Id", "Non editable property", "Float number", "Double number" + ); assertThat(registryEntityConfiguration.getPropertyConfigurationList()).extracting("isDecimal").containsExactly(false, false, false, true, true); // and when