hosting-asset-validation-beyond-property-validators #65
@ -29,6 +29,7 @@ import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.PostLoad;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.Transient;
|
||||
import jakarta.persistence.Version;
|
||||
@ -120,12 +121,20 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject {
|
||||
@Transient
|
||||
private PatchableMapWrapper<Object> configWrapper;
|
||||
|
||||
@Transient
|
||||
private boolean isLoaded = false;
|
||||
|
||||
@PostLoad
|
||||
public void markAsLoaded() {
|
||||
this.isLoaded = true;
|
||||
}
|
||||
|
||||
public PatchableMapWrapper<Object> getConfig() {
|
||||
return PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper; }, config );
|
||||
}
|
||||
|
||||
public void putConfig(Map<String, Object> newConfg) {
|
||||
PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper; }, config).assign(newConfg);
|
||||
public void putConfig(Map<String, Object> newConfig) {
|
||||
PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper; }, config).assign(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,6 +17,10 @@ class HsManagedWebspaceHostingAssetValidator extends HsHostingAssetEntityValidat
|
||||
|
||||
@Override
|
||||
protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) {
|
||||
hsh-michaelhoennig marked this conversation as resolved
|
||||
return Pattern.compile("^" + assetEntity.getParentAsset().getBookingItem().getProject().getDebitor().getDefaultPrefix() + "[0-9][0-9]$");
|
||||
final var prefixPattern =
|
||||
!assetEntity.isLoaded()
|
||||
? assetEntity.getParentAsset().getBookingItem().getProject().getDebitor().getDefaultPrefix()
|
||||
: "[a-z][a-z0-9][a-z0-9]";
|
||||
return Pattern.compile("^" + prefixPattern + "[0-9][0-9]$");
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
result.assertSuccessful();
|
||||
assertThat(result.returnedValue()).isNotNull().extracting(HsHostingAssetEntity::getUuid).isNotNull();
|
||||
assertThatAssetIsPersisted(result.returnedValue());
|
||||
assertThat(result.returnedValue().isLoaded()).isFalse();
|
||||
assertThat(assetRepo.count()).isEqualTo(count + 1);
|
||||
}
|
||||
|
||||
@ -413,5 +414,6 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
assertThat(actualResult)
|
||||
.extracting(HsHostingAssetEntity::toString)
|
||||
.contains(serverNames);
|
||||
actualResult.forEach(loadedEntity -> assertThat(loadedEntity.isLoaded()).isTrue());
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,28 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
|
||||
))
|
||||
.build();
|
||||
|
||||
@Test
|
||||
void acceptsAlienIdentifierPrefixForPreExistingEntity() {
|
||||
// given
|
||||
final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE);
|
||||
final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder()
|
||||
.type(MANAGED_WEBSPACE)
|
||||
.bookingItem(HsBookingItemEntity.builder()
|
||||
.type(HsBookingItemType.MANAGED_WEBSPACE)
|
||||
.resources(Map.ofEntries(entry("SSD", 25), entry("Traffic", 250)))
|
||||
.build())
|
||||
.parentAsset(mangedServerAssetEntity)
|
||||
.identifier("xyz00")
|
||||
.isLoaded(true)
|
||||
.build();
|
||||
|
||||
// when
|
||||
final var result = validator.validate(mangedWebspaceHostingAssetEntity);
|
||||
|
||||
// then
|
||||
assertThat(result).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void validatesIdentifierAndReferencedEntities() {
|
||||
// given
|
||||
|
Loading…
Reference in New Issue
Block a user
nur bei neu angelegten Objekten prüfen