Skip to content

Commit

Permalink
Add support for sorting properties of embedded id
Browse files Browse the repository at this point in the history
  • Loading branch information
agrancaric committed Aug 23, 2024
1 parent d62c7ce commit ce5146c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ private RegistryEntityConfiguration resolveRegistryConfiguration(String groupId,
String registryDisplayName = registryDisplayLabel(entityType);
boolean isHistoryAvailable = registryOverrideConfiguration.isHistoryAvailable() || isAudited(entityType);
List<RegistryPropertyConfiguration> registryPropertyConfigurationList = resolveRegistryPropertyListForType(managedTypeWrapper, registryOverrideConfiguration);
List<RegistryPropertyConfiguration> registryEmbeddedIdPropertyConfigurationList = resolverEmbeddedIdPropertyConfigurationList(managedTypeWrapper, registryOverrideConfiguration);
List<RegistryPropertyConfiguration> registryEmbeddedIdPropertyConfigurationList = resolveEmbeddedIdPropertyConfigurationList(managedTypeWrapper, registryOverrideConfiguration);
List<String> registryPropertyDisplayOrderList = Optional.ofNullable(registryOverrideConfiguration.getPropertyDisplayOrderList()).orElse(Collections.emptyList());

registryPropertyConfigurationList.sort(new RegistryPropertyComparator(registryPropertyDisplayOrderList));
registryEmbeddedIdPropertyConfigurationList.sort(new RegistryPropertyComparator(registryPropertyDisplayOrderList));

return RegistryEntityConfiguration.builder()
.groupId(groupId)
Expand Down Expand Up @@ -137,7 +138,7 @@ private List<RegistryPropertyConfiguration> resolveRegistryPropertyListForType(M
);
}

private List<RegistryPropertyConfiguration> resolverEmbeddedIdPropertyConfigurationList(ManagedTypeWrapper managedTypeWrapper, RegistryOverrideConfiguration registryOverrideConfiguration) {
private List<RegistryPropertyConfiguration> resolveEmbeddedIdPropertyConfigurationList(ManagedTypeWrapper managedTypeWrapper, RegistryOverrideConfiguration registryOverrideConfiguration) {
if (!managedTypeWrapper.isEmbeddedIdentifier()) {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.croz.nrich.registry.configuration.controller.RegistryConfigurationController;
import net.croz.nrich.registry.configuration.service.DefaultRegistryConfigurationService;
import net.croz.nrich.registry.configuration.stub.RegistryConfigurationTestEntity;
import net.croz.nrich.registry.configuration.stub.RegistryConfigurationTestEntityWithAssociationAndEmbeddedId;
import net.croz.nrich.registry.core.model.RegistryDataConfigurationHolder;
import net.croz.nrich.registry.core.model.RegistryGroupDefinitionHolder;
import net.croz.nrich.registry.core.model.RegistryHistoryConfigurationHolder;
Expand Down Expand Up @@ -340,7 +341,17 @@ private List<RegistryOverrideConfigurationHolder> createRegistryOverrideConfigur
RegistryOverrideConfigurationHolder searchConfigurationHolder = RegistryOverrideConfigurationHolder.builder()
.type(RegistryTestEntityWithOverriddenSearchConfiguration.class).overrideSearchConfiguration(searchConfiguration).build();

return Arrays.asList(interceptorTestEntityConfigurationHolder, InterceptorTestNonEntityNonModifiableConfigurationHolder, searchConfigurationHolder, configurationEntityConfigurationHolder);
RegistryOverrideConfiguration embeddedEntityOverrideConfiguration = RegistryOverrideConfiguration.defaultConfiguration();

embeddedEntityOverrideConfiguration.setPropertyDisplayOrderList(List.of("id.secondId", "id.firstId"));

RegistryOverrideConfigurationHolder embeddedEntityOverrideConfigurationHolder = RegistryOverrideConfigurationHolder.builder()
.type(RegistryConfigurationTestEntityWithAssociationAndEmbeddedId.class).overrideConfiguration(embeddedEntityOverrideConfiguration).build();

return Arrays.asList(
interceptorTestEntityConfigurationHolder, InterceptorTestNonEntityNonModifiableConfigurationHolder, searchConfigurationHolder, configurationEntityConfigurationHolder,
embeddedEntityOverrideConfigurationHolder
);
}

private ModelMapper strictModelMapper() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void shouldResolveRegistryConfigurationForComplexEntitiesWithAssociationsAndEmbe
assertThat(registryEntityConfiguration.getPropertyConfigurationList()).extracting("name").containsExactly(
"id", "amount", "registryConfigurationTestEntityManyToOne", "registryConfigurationTestEntityOneToOne"
);
assertThat(registryEntityConfiguration.getEmbeddedIdPropertyConfigurationList()).extracting("name").containsExactlyInAnyOrder("id.firstId", "id.secondId");
assertThat(registryEntityConfiguration.getEmbeddedIdPropertyConfigurationList()).extracting("name").containsExactly("id.secondId", "id.firstId");

// and when
RegistryPropertyConfiguration numberRegistryConfiguration = registryEntityConfiguration.getPropertyConfigurationList().get(1);
Expand Down

0 comments on commit ce5146c

Please sign in to comment.