hosting-asset-validation-beyond-property-validators #65
@ -29,6 +29,7 @@ import jakarta.persistence.JoinColumn;
|
|||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
import jakarta.persistence.OneToOne;
|
import jakarta.persistence.OneToOne;
|
||||||
|
import jakarta.persistence.PostLoad;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import jakarta.persistence.Transient;
|
import jakarta.persistence.Transient;
|
||||||
import jakarta.persistence.Version;
|
import jakarta.persistence.Version;
|
||||||
@ -120,12 +121,20 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject {
|
|||||||
@Transient
|
@Transient
|
||||||
private PatchableMapWrapper<Object> configWrapper;
|
private PatchableMapWrapper<Object> configWrapper;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private boolean isLoaded = false;
|
||||||
|
|
||||||
|
@PostLoad
|
||||||
|
public void markAsLoaded() {
|
||||||
|
this.isLoaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
public PatchableMapWrapper<Object> getConfig() {
|
public PatchableMapWrapper<Object> getConfig() {
|
||||||
return PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper; }, config );
|
return PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper; }, config );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putConfig(Map<String, Object> newConfg) {
|
public void putConfig(Map<String, Object> newConfig) {
|
||||||
PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper; }, config).assign(newConfg);
|
PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper; }, config).assign(newConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,6 +17,10 @@ class HsManagedWebspaceHostingAssetValidator extends HsHostingAssetEntityValidat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) {
|
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();
|
result.assertSuccessful();
|
||||||
assertThat(result.returnedValue()).isNotNull().extracting(HsHostingAssetEntity::getUuid).isNotNull();
|
assertThat(result.returnedValue()).isNotNull().extracting(HsHostingAssetEntity::getUuid).isNotNull();
|
||||||
assertThatAssetIsPersisted(result.returnedValue());
|
assertThatAssetIsPersisted(result.returnedValue());
|
||||||
|
assertThat(result.returnedValue().isLoaded()).isFalse();
|
||||||
assertThat(assetRepo.count()).isEqualTo(count + 1);
|
assertThat(assetRepo.count()).isEqualTo(count + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,5 +414,6 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
assertThat(actualResult)
|
assertThat(actualResult)
|
||||||
.extracting(HsHostingAssetEntity::toString)
|
.extracting(HsHostingAssetEntity::toString)
|
||||||
.contains(serverNames);
|
.contains(serverNames);
|
||||||
|
actualResult.forEach(loadedEntity -> assertThat(loadedEntity.isLoaded()).isTrue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,28 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
|
|||||||
))
|
))
|
||||||
.build();
|
.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
|
@Test
|
||||||
void validatesIdentifierAndReferencedEntities() {
|
void validatesIdentifierAndReferencedEntities() {
|
||||||
// given
|
// given
|
||||||
|
Loading…
Reference in New Issue
Block a user
nur bei neu angelegten Objekten prüfen