-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ignoring properties when updating registry entites
- Loading branch information
1 parent
e2dd23a
commit 569c5cc
Showing
11 changed files
with
244 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...-api/src/main/java/net/croz/nrich/registry/api/core/customizer/ModelMapperCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.croz.nrich.registry.api.core.customizer; | ||
|
||
import org.modelmapper.ModelMapper; | ||
|
||
public interface ModelMapperCustomizer { | ||
|
||
void customize(ModelMapperType type, ModelMapper modelMapper); | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...gistry-api/src/main/java/net/croz/nrich/registry/api/core/customizer/ModelMapperType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.croz.nrich.registry.api.core.customizer; | ||
|
||
public enum ModelMapperType { | ||
BASE, DATA | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
.../main/java/net/croz/nrich/registry/data/customizer/RegistryDataModelMapperCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package net.croz.nrich.registry.data.customizer; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import net.croz.nrich.registry.api.core.customizer.ModelMapperCustomizer; | ||
import net.croz.nrich.registry.api.core.customizer.ModelMapperType; | ||
import net.croz.nrich.registry.api.core.model.RegistryOverrideConfiguration; | ||
import net.croz.nrich.registry.api.core.model.RegistryOverrideConfigurationHolder; | ||
import org.modelmapper.ModelMapper; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@RequiredArgsConstructor | ||
public class RegistryDataModelMapperCustomizer implements ModelMapperCustomizer { | ||
|
||
private final List<RegistryOverrideConfigurationHolder> registryOverrideConfigurationHolderList; | ||
|
||
@Override | ||
public void customize(ModelMapperType type, ModelMapper modelMapper) { | ||
if (type != ModelMapperType.DATA || CollectionUtils.isEmpty(registryOverrideConfigurationHolderList)) { | ||
return; | ||
} | ||
|
||
registryOverrideConfigurationHolderList.forEach(registryOverrideConfigurationHolder -> { | ||
List<String> ignoredPropertyList = Optional.ofNullable(registryOverrideConfigurationHolder.getOverrideConfiguration()) | ||
.map(RegistryOverrideConfiguration::getIgnoredPropertyList) | ||
.orElse(Collections.emptyList()); | ||
|
||
if (ignoredPropertyList.isEmpty()) { | ||
return; | ||
} | ||
|
||
modelMapper.getConfiguration().setPropertyCondition(context -> { | ||
if (context.getParent() != null && registryOverrideConfigurationHolder.getType().equals(context.getParent().getDestinationType())) { | ||
return context.getMapping().getDestinationProperties().stream().noneMatch(property -> ignoredPropertyList.contains(property.getName())); | ||
} | ||
|
||
return true; | ||
}); | ||
}); | ||
} | ||
} |
Oops, something went wrong.