From 89808cecf70479e59e73ae2f55c4741d2f44867e Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 31 Jul 2024 12:13:55 +0200 Subject: [PATCH] use HsHostingAssetRawEntity for ImportHostingAssets --- .../hs/hosting/asset/HsHostingAsset.java | 69 ++++++++ .../hosting/asset/HsHostingAssetEntity.java | 50 +----- .../asset/HsHostingAssetRepository.java | 2 +- .../hs/hosting/asset/HsHostingAssetType.java | 16 +- .../HostingAssetEntitySaveProcessor.java | 14 +- .../HostingAssetEntityValidator.java | 50 +++--- .../HostingAssetEntityValidatorRegistry.java | 9 +- .../HsCloudServerHostingAssetValidator.java | 4 +- ...HsDomainDnsSetupHostingAssetValidator.java | 12 +- ...sDomainHttpSetupHostingAssetValidator.java | 6 +- ...sDomainMboxSetupHostingAssetValidator.java | 6 +- .../HsDomainSetupHostingAssetValidator.java | 6 +- ...sDomainSmtpSetupHostingAssetValidator.java | 6 +- .../HsEMailAddressHostingAssetValidator.java | 8 +- .../HsEMailAliasHostingAssetValidator.java | 6 +- .../HsIPv4NumberHostingAssetValidator.java | 4 +- .../HsIPv6NumberHostingAssetValidator.java | 6 +- .../HsManagedServerHostingAssetValidator.java | 4 +- ...sManagedWebspaceHostingAssetValidator.java | 4 +- ...sMariaDbDatabaseHostingAssetValidator.java | 4 +- ...sMariaDbInstanceHostingAssetValidator.java | 6 +- .../HsMariaDbUserHostingAssetValidator.java | 4 +- ...stgreSqlDatabaseHostingAssetValidator.java | 4 +- ...greSqlDbInstanceHostingAssetValidator.java | 6 +- ...HsPostgreSqlUserHostingAssetValidator.java | 4 +- .../HsUnixUserHostingAssetValidator.java | 6 +- .../hs/hosting/asset/validators/README.md | 10 +- .../hsadminng/stringify/Stringify.java | 27 ++- ...DnsSetupHostingAssetValidatorUnitTest.java | 6 +- ...ailAliasHostingAssetValidatorUnitTest.java | 6 +- ...iaDbUserHostingAssetValidatorUnitTest.java | 2 +- ...eSqlUserHostingAssetValidatorUnitTest.java | 2 +- ...UnixUserHostingAssetValidatorUnitTest.java | 43 +++-- .../hsadminng/hs/migration/CsvDataImport.java | 23 +++ .../hs/migration/HsHostingAssetRawEntity.java | 114 +++++++++++++ .../hs/migration/ImportHostingAssets.java | 159 ++++++++++-------- 36 files changed, 461 insertions(+), 247 deletions(-) create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java create mode 100644 src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetRawEntity.java diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java new file mode 100644 index 00000000..afa3b0e9 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java @@ -0,0 +1,69 @@ +package net.hostsharing.hsadminng.hs.hosting.asset; + +import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; +import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; +import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; +import net.hostsharing.hsadminng.stringify.Stringify; +import net.hostsharing.hsadminng.stringify.Stringifyable; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static java.util.Collections.emptyMap; +import static net.hostsharing.hsadminng.stringify.Stringify.stringify; + +public interface HsHostingAsset extends Stringifyable, RbacObject, PropertiesProvider { + + Stringify stringify = stringify(HsHostingAsset.class) + .withProp(HsHostingAsset::getType) + .withProp(HsHostingAsset::getIdentifier) + .withProp(HsHostingAsset::getCaption) + .withProp(HsHostingAsset::getParentAsset) + .withProp(HsHostingAsset::getAssignedToAsset) + .withProp(HsHostingAsset::getBookingItem) + .withProp(HsHostingAsset::getConfig) + .quotedValues(false); + + HsHostingAssetType getType(); + HsHostingAsset getParentAsset(); + void setIdentifier(String s); + String getIdentifier(); + HsBookingItemEntity getBookingItem(); + HsHostingAsset getAssignedToAsset(); + HsOfficeContactEntity getAlarmContact(); + List getSubHostingAssets(); + String getCaption(); + Map getConfig(); + + default HsBookingProjectEntity getRelatedProject() { + return Optional.ofNullable(getBookingItem()) + .map(HsBookingItemEntity::getRelatedProject) + .orElseGet(() -> Optional.ofNullable(getParentAsset()) + .map(HsHostingAsset::getRelatedProject) + .orElse(null)); + } + + @Override + default Object getContextValue(final String propName) { + final var v = directProps().get(propName); + if (v != null) { + return v; + } + + if (getBookingItem() != null) { + return getBookingItem().getResources().get(propName); + } + if (getParentAsset() != null && getParentAsset().getBookingItem() != null) { + return getParentAsset().getBookingItem().getResources().get(propName); + } + return emptyMap(); + } + + @Override + default String toShortString() { + return getType() + ":" + getIdentifier(); + } +} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java index 6965d82f..ceb27238 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java @@ -8,15 +8,10 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; -import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; -import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; -import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject; -import net.hostsharing.hsadminng.stringify.Stringify; -import net.hostsharing.hsadminng.stringify.Stringifyable; import org.hibernate.annotations.Type; import jakarta.persistence.CascadeType; @@ -39,10 +34,8 @@ import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.UUID; -import static java.util.Collections.emptyMap; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inCaseOf; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Column.dependsOnColumn; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.ColumnValue.usingDefaultCase; @@ -70,17 +63,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @Setter @NoArgsConstructor @AllArgsConstructor -public class HsHostingAssetEntity implements Stringifyable, RbacObject, PropertiesProvider { - - private static Stringify stringify = stringify(HsHostingAssetEntity.class) - .withProp(HsHostingAssetEntity::getType) - .withProp(HsHostingAssetEntity::getIdentifier) - .withProp(HsHostingAssetEntity::getCaption) - .withProp(HsHostingAssetEntity::getParentAsset) - .withProp(HsHostingAssetEntity::getAssignedToAsset) - .withProp(HsHostingAssetEntity::getBookingItem) - .withProp(HsHostingAssetEntity::getConfig) - .quotedValues(false); +public class HsHostingAssetEntity implements HsHostingAsset { @Id @GeneratedValue @@ -136,14 +119,6 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject Optional.ofNullable(parentAsset) - .map(HsHostingAssetEntity::getRelatedProject) - .orElse(null)); - } - public PatchableMapWrapper getConfig() { return PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper;}, config); } @@ -157,30 +132,9 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject { " *==> "); } - static EntityTypeRelation optionalParent(final HsHostingAssetType hostingAssetType) { + static EntityTypeRelation optionalParent(final HsHostingAssetType hostingAssetType) { return new EntityTypeRelation<>( OPTIONAL, PARENT_ASSET, - HsHostingAssetEntity::getParentAsset, + HsHostingAsset::getParentAsset, hostingAssetType, " o..> "); } - static EntityTypeRelation requiredParent(final HsHostingAssetType hostingAssetType) { + static EntityTypeRelation requiredParent(final HsHostingAssetType hostingAssetType) { return new EntityTypeRelation<>( REQUIRED, PARENT_ASSET, - HsHostingAssetEntity::getParentAsset, + HsHostingAsset::getParentAsset, hostingAssetType, " *==> "); } - static EntityTypeRelation assignedTo(final HsHostingAssetType hostingAssetType) { + static EntityTypeRelation assignedTo(final HsHostingAssetType hostingAssetType) { return new EntityTypeRelation<>( REQUIRED, ASSIGNED_TO_ASSET, - HsHostingAssetEntity::getAssignedToAsset, + HsHostingAsset::getAssignedToAsset, hostingAssetType, " o--> "); } @@ -416,11 +416,11 @@ class EntityTypeRelation { return this; } - static EntityTypeRelation optionallyAssignedTo(final HsHostingAssetType hostingAssetType) { + static EntityTypeRelation optionallyAssignedTo(final HsHostingAssetType hostingAssetType) { return new EntityTypeRelation<>( OPTIONAL, ASSIGNED_TO_ASSET, - HsHostingAssetEntity::getAssignedToAsset, + HsHostingAsset::getAssignedToAsset, hostingAssetType, " o..> "); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntitySaveProcessor.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntitySaveProcessor.java index 9495340e..5d7b9ddd 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntitySaveProcessor.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntitySaveProcessor.java @@ -1,7 +1,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; import net.hostsharing.hsadminng.errors.MultiValidationException; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetResource; import net.hostsharing.hsadminng.hs.validation.HsEntityValidator; @@ -10,17 +10,17 @@ import java.util.Map; import java.util.function.Function; /** - * Wraps the steps of the pararation, validation, mapping and revamp around saving of a HsHostingAssetEntity into a readable API. + * Wraps the steps of the pararation, validation, mapping and revamp around saving of a HsHostingAsset into a readable API. */ public class HostingAssetEntitySaveProcessor { - private final HsEntityValidator validator; + private final HsEntityValidator validator; private String expectedStep = "preprocessEntity"; private final EntityManager em; - private HsHostingAssetEntity entity; + private HsHostingAsset entity; private HsHostingAssetResource resource; - public HostingAssetEntitySaveProcessor(final EntityManager em, final HsHostingAssetEntity entity) { + public HostingAssetEntitySaveProcessor(final EntityManager em, final HsHostingAsset entity) { this.em = em; this.entity = entity; this.validator = HostingAssetEntityValidatorRegistry.forType(entity.getType()); @@ -59,7 +59,7 @@ public class HostingAssetEntitySaveProcessor { return this; } - public HostingAssetEntitySaveProcessor saveUsing(final Function saveFunction) { + public HostingAssetEntitySaveProcessor saveUsing(final Function saveFunction) { step("saveUsing", "validateContext"); entity = saveFunction.apply(entity); return this; @@ -74,7 +74,7 @@ public class HostingAssetEntitySaveProcessor { /// maps entity to JSON resource representation public HostingAssetEntitySaveProcessor mapUsing( - final Function mapFunction) { + final Function mapFunction) { step("mapUsing", "revampProperties"); resource = mapFunction.apply(entity); return this; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java index 6433814c..b6747ff8 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java @@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; import net.hostsharing.hsadminng.hs.booking.item.validators.HsBookingItemEntityValidatorRegistry; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.validation.HsEntityValidator; @@ -23,13 +23,13 @@ import static java.util.Arrays.stream; import static java.util.Collections.emptyList; import static java.util.Optional.ofNullable; -public abstract class HostingAssetEntityValidator extends HsEntityValidator { +public abstract class HostingAssetEntityValidator extends HsEntityValidator { static final ValidatableProperty[] NO_EXTRA_PROPERTIES = new ValidatableProperty[0]; private final ReferenceValidator bookingItemReferenceValidation; - private final ReferenceValidator parentAssetReferenceValidation; - private final ReferenceValidator assignedToAssetReferenceValidation; + private final ReferenceValidator parentAssetReferenceValidation; + private final ReferenceValidator assignedToAssetReferenceValidation; private final HostingAssetEntityValidator.AlarmContact alarmContactValidation; HostingAssetEntityValidator( @@ -40,23 +40,23 @@ public abstract class HostingAssetEntityValidator extends HsEntityValidator( assetType.bookingItemPolicy(), assetType.bookingItemTypes(), - HsHostingAssetEntity::getBookingItem, + HsHostingAsset::getBookingItem, HsBookingItemEntity::getType); this.parentAssetReferenceValidation = new ReferenceValidator<>( assetType.parentAssetPolicy(), assetType.parentAssetTypes(), - HsHostingAssetEntity::getParentAsset, - HsHostingAssetEntity::getType); + HsHostingAsset::getParentAsset, + HsHostingAsset::getType); this.assignedToAssetReferenceValidation = new ReferenceValidator<>( assetType.assignedToAssetPolicy(), assetType.assignedToAssetTypes(), - HsHostingAssetEntity::getAssignedToAsset, - HsHostingAssetEntity::getType); + HsHostingAsset::getAssignedToAsset, + HsHostingAsset::getType); this.alarmContactValidation = alarmContactValidation; } @Override - public List validateEntity(final HsHostingAssetEntity assetEntity) { + public List validateEntity(final HsHostingAsset assetEntity) { return sequentiallyValidate( () -> validateEntityReferencesAndProperties(assetEntity), () -> validateIdentifierPattern(assetEntity) @@ -64,7 +64,7 @@ public abstract class HostingAssetEntityValidator extends HsEntityValidator validateContext(final HsHostingAssetEntity assetEntity) { + public List validateContext(final HsHostingAsset assetEntity) { return sequentiallyValidate( () -> optionallyValidate(assetEntity.getBookingItem()), () -> optionallyValidate(assetEntity.getParentAsset()), @@ -72,7 +72,7 @@ public abstract class HostingAssetEntityValidator extends HsEntityValidator validateEntityReferencesAndProperties(final HsHostingAssetEntity assetEntity) { + private List validateEntityReferencesAndProperties(final HsHostingAsset assetEntity) { return Stream.of( validateReferencedEntity(assetEntity, "bookingItem", bookingItemReferenceValidation::validate), validateReferencedEntity(assetEntity, "parentAsset", parentAssetReferenceValidation::validate), @@ -86,17 +86,17 @@ public abstract class HostingAssetEntityValidator extends HsEntityValidator validateReferencedEntity( - final HsHostingAssetEntity assetEntity, + final HsHostingAsset assetEntity, final String referenceFieldName, - final BiFunction> validator) { + final BiFunction> validator) { return enrich(prefix(assetEntity.toShortString()), validator.apply(assetEntity, referenceFieldName)); } - private List validateProperties(final HsHostingAssetEntity assetEntity) { + private List validateProperties(final HsHostingAsset assetEntity) { return enrich(prefix(assetEntity.toShortString(), "config"), super.validateProperties(assetEntity)); } - private static List optionallyValidate(final HsHostingAssetEntity assetEntity) { + private static List optionallyValidate(final HsHostingAsset assetEntity) { return assetEntity != null ? enrich( prefix(assetEntity.toShortString(), "parentAsset"), @@ -112,7 +112,7 @@ public abstract class HostingAssetEntityValidator extends HsEntityValidator validateAgainstSubEntities(final HsHostingAssetEntity assetEntity) { + protected List validateAgainstSubEntities(final HsHostingAsset assetEntity) { return enrich( prefix(assetEntity.toShortString(), "config"), stream(propertyValidators) @@ -124,7 +124,7 @@ public abstract class HostingAssetEntityValidator extends HsEntityValidator propDef) { final var propName = propDef.propertyName(); final var propUnit = ofNullable(propDef.unit()).map(u -> " " + u).orElse(""); @@ -140,7 +140,7 @@ public abstract class HostingAssetEntityValidator extends HsEntityValidator validateIdentifierPattern(final HsHostingAssetEntity assetEntity) { + private List validateIdentifierPattern(final HsHostingAsset assetEntity) { final var expectedIdentifierPattern = identifierPattern(assetEntity); if (assetEntity.getIdentifier() == null || !expectedIdentifierPattern.matcher(assetEntity.getIdentifier()).matches()) { @@ -151,19 +151,19 @@ public abstract class HostingAssetEntityValidator extends HsEntityValidator { private final HsHostingAssetType.RelationPolicy policy; private final Set referencedEntityTypes; - private final Function referencedEntityGetter; + private final Function referencedEntityGetter; private final Function referencedEntityTypeGetter; public ReferenceValidator( final HsHostingAssetType.RelationPolicy policy, final Set referencedEntityTypes, - final Function referencedEntityGetter, + final Function referencedEntityGetter, final Function referencedEntityTypeGetter) { this.policy = policy; this.referencedEntityTypes = referencedEntityTypes; @@ -173,14 +173,14 @@ public abstract class HostingAssetEntityValidator extends HsEntityValidator referencedEntityGetter) { + final Function referencedEntityGetter) { this.policy = policy; this.referencedEntityTypes = Set.of(); this.referencedEntityGetter = referencedEntityGetter; this.referencedEntityTypeGetter = e -> null; } - List validate(final HsHostingAssetEntity assetEntity, final String referenceFieldName) { + List validate(final HsHostingAsset assetEntity, final String referenceFieldName) { final var actualEntity = referencedEntityGetter.apply(assetEntity); final var actualEntityType = actualEntity != null ? referencedEntityTypeGetter.apply(actualEntity) : null; @@ -216,7 +216,7 @@ public abstract class HostingAssetEntityValidator extends HsEntityValidator> { AlarmContact(final HsHostingAssetType.RelationPolicy policy) { - super(policy, HsHostingAssetEntity::getAlarmContact); + super(policy, HsHostingAsset::getAlarmContact); } // hostmaster alert address is implicitly added where neccessary diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java index 696beafe..20fef401 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java @@ -1,6 +1,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetResource; import net.hostsharing.hsadminng.hs.validation.HsEntityValidator; @@ -12,7 +13,7 @@ import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.*; public class HostingAssetEntityValidatorRegistry { - private static final Map, HsEntityValidator> validators = new HashMap<>(); + private static final Map, HsEntityValidator> validators = new HashMap<>(); static { // HOWTO: add (register) new HsHostingAssetType-specific validators register(CLOUD_SERVER, new HsCloudServerHostingAssetValidator()); @@ -36,14 +37,14 @@ public class HostingAssetEntityValidatorRegistry { register(IPV6_NUMBER, new HsIPv6NumberHostingAssetValidator()); } - private static void register(final Enum type, final HsEntityValidator validator) { + private static void register(final Enum type, final HsEntityValidator validator) { stream(validator.propertyValidators).forEach( entry -> { entry.verifyConsistency(Map.entry(type, validator)); }); validators.put(type, validator); } - public static HsEntityValidator forType(final Enum type) { + public static HsEntityValidator forType(final Enum type) { if ( validators.containsKey(type)) { return validators.get(type); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidator.java index 840e5841..b9719a54 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.regex.Pattern; @@ -16,7 +16,7 @@ class HsCloudServerHostingAssetValidator extends HostingAssetEntityValidator { } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { return Pattern.compile("^vm[0-9][0-9][0-9][0-9]$"); } } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidator.java index 97c44ce2..052db872 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidator.java @@ -1,7 +1,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; import lombok.SneakyThrows; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.system.SystemProcess; import java.util.List; @@ -59,12 +59,12 @@ class HsDomainDnsSetupHostingAssetValidator extends HostingAssetEntityValidator } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { return Pattern.compile("^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + IDENTIFIER_SUFFIX) + "$"); } @Override - public void preprocessEntity(final HsHostingAssetEntity entity) { + public void preprocessEntity(final HsHostingAsset entity) { super.preprocessEntity(entity); if (entity.getIdentifier() == null) { ofNullable(entity.getParentAsset()).ifPresent(pa -> entity.setIdentifier(pa.getIdentifier() + IDENTIFIER_SUFFIX)); @@ -73,7 +73,7 @@ class HsDomainDnsSetupHostingAssetValidator extends HostingAssetEntityValidator @Override @SneakyThrows - public List validateContext(final HsHostingAssetEntity assetEntity) { + public List validateContext(final HsHostingAsset assetEntity) { final var result = super.validateContext(assetEntity); // TODO.spec: define which checks should get raised to error level @@ -87,7 +87,7 @@ class HsDomainDnsSetupHostingAssetValidator extends HostingAssetEntityValidator return result; } - String toZonefileString(final HsHostingAssetEntity assetEntity) { + String toZonefileString(final HsHostingAsset assetEntity) { // TODO.spec: we need to expand the templates (auto-...) in the same way as in Saltstack return """ $ORIGIN {domain}. @@ -104,7 +104,7 @@ class HsDomainDnsSetupHostingAssetValidator extends HostingAssetEntityValidator .replace("{userRRs}", getPropertyValues(assetEntity, "user-RR") ); } - private String fqdn(final HsHostingAssetEntity assetEntity) { + private String fqdn(final HsHostingAsset assetEntity) { return assetEntity.getIdentifier().substring(0, assetEntity.getIdentifier().length()-IDENTIFIER_SUFFIX.length()); } } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidator.java index 32a2cb30..37bed650 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.regex.Pattern; @@ -42,12 +42,12 @@ class HsDomainHttpSetupHostingAssetValidator extends HostingAssetEntityValidator } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { return Pattern.compile("^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + IDENTIFIER_SUFFIX) + "$"); } @Override - public void preprocessEntity(final HsHostingAssetEntity entity) { + public void preprocessEntity(final HsHostingAsset entity) { super.preprocessEntity(entity); if (entity.getIdentifier() == null) { ofNullable(entity.getParentAsset()).ifPresent(pa -> entity.setIdentifier(pa.getIdentifier() + IDENTIFIER_SUFFIX)); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainMboxSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainMboxSetupHostingAssetValidator.java index 0172fda4..41c1aa52 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainMboxSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainMboxSetupHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.regex.Pattern; @@ -20,12 +20,12 @@ class HsDomainMboxSetupHostingAssetValidator extends HostingAssetEntityValidator } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { return Pattern.compile("^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + IDENTIFIER_SUFFIX) + "$"); } @Override - public void preprocessEntity(final HsHostingAssetEntity entity) { + public void preprocessEntity(final HsHostingAsset entity) { super.preprocessEntity(entity); if (entity.getIdentifier() == null) { ofNullable(entity.getParentAsset()).ifPresent(pa -> entity.setIdentifier(pa.getIdentifier() + IDENTIFIER_SUFFIX)); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java index 17031c5e..cec021a2 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.List; import java.util.regex.Pattern; @@ -22,7 +22,7 @@ class HsDomainSetupHostingAssetValidator extends HostingAssetEntityValidator { } @Override - public List validateEntity(final HsHostingAssetEntity assetEntity) { + public List validateEntity(final HsHostingAsset assetEntity) { // TODO.impl: for newly created entities, check the permission of setting up a domain // // reject, if the domain is any of these: @@ -51,7 +51,7 @@ class HsDomainSetupHostingAssetValidator extends HostingAssetEntityValidator { } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { return identifierPattern; } } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSmtpSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSmtpSetupHostingAssetValidator.java index e92eba10..bc422029 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSmtpSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSmtpSetupHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.regex.Pattern; @@ -20,12 +20,12 @@ class HsDomainSmtpSetupHostingAssetValidator extends HostingAssetEntityValidator } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { return Pattern.compile("^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + IDENTIFIER_SUFFIX) + "$"); } @Override - public void preprocessEntity(final HsHostingAssetEntity entity) { + public void preprocessEntity(final HsHostingAsset entity) { super.preprocessEntity(entity); if (entity.getIdentifier() == null) { ofNullable(entity.getParentAsset()).ifPresent(pa -> entity.setIdentifier(pa.getIdentifier() + IDENTIFIER_SUFFIX)); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidator.java index cfaa5eda..3ee8f3d3 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import java.util.regex.Pattern; @@ -29,7 +29,7 @@ class HsEMailAddressHostingAssetValidator extends HostingAssetEntityValidator { } @Override - public void preprocessEntity(final HsHostingAssetEntity entity) { + public void preprocessEntity(final HsHostingAsset entity) { super.preprocessEntity(entity); super.preprocessEntity(entity); if (entity.getIdentifier() == null) { @@ -38,11 +38,11 @@ class HsEMailAddressHostingAssetValidator extends HostingAssetEntityValidator { } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { return Pattern.compile("^"+ Pattern.quote(combineIdentifier(assetEntity)) + "$"); } - private static String combineIdentifier(final HsHostingAssetEntity emailAddressAssetEntity) { + private static String combineIdentifier(final HsHostingAsset emailAddressAssetEntity) { return emailAddressAssetEntity.getDirectValue("local-part", String.class) + ofNullable(emailAddressAssetEntity.getDirectValue("sub-domain", String.class)).map(s -> "." + s).orElse("") + "@" + diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAliasHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAliasHostingAssetValidator.java index 5fdb2fb3..ab0cb77c 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAliasHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAliasHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import java.util.regex.Pattern; @@ -13,7 +13,7 @@ class HsEMailAliasHostingAssetValidator extends HostingAssetEntityValidator { private static final String UNIX_USER_REGEX = "^[a-z][a-z0-9]{2}[0-9]{2}(-[a-z0-9][a-z0-9\\._-]*)?$"; // also accepts legacy pac-names private static final String EMAIL_ADDRESS_REGEX = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$"; // RFC 5322 private static final String INCLUDE_REGEX = "^:include:/.*$"; - private static final String PIPE_REGEX = "^|.*$"; + private static final String PIPE_REGEX = "^\\|.*$"; public static final int EMAIL_ADDRESS_MAX_LENGTH = 320; // according to RFC 5321 and RFC 5322 HsEMailAliasHostingAssetValidator() { @@ -26,7 +26,7 @@ class HsEMailAliasHostingAssetValidator extends HostingAssetEntityValidator { } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { final var webspaceIdentifier = assetEntity.getParentAsset().getIdentifier(); return Pattern.compile("^"+webspaceIdentifier+"$|^"+webspaceIdentifier+"-[a-z0-9][a-z0-9\\._-]*$"); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv4NumberHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv4NumberHostingAssetValidator.java index 235a32c2..b237729e 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv4NumberHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv4NumberHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.regex.Pattern; @@ -20,7 +20,7 @@ class HsIPv4NumberHostingAssetValidator extends HostingAssetEntityValidator { } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { return IPV4_REGEX; } } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv6NumberHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv6NumberHostingAssetValidator.java index b910ea82..873a73eb 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv6NumberHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv6NumberHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.net.InetAddress; import java.net.UnknownHostException; @@ -24,7 +24,7 @@ class HsIPv6NumberHostingAssetValidator extends HostingAssetEntityValidator { } @Override - public List validateEntity(final HsHostingAssetEntity assetEntity) { + public List validateEntity(final HsHostingAsset assetEntity) { final var violations = super.validateEntity(assetEntity); if (!isValidIPv6Address(assetEntity.getIdentifier())) { @@ -35,7 +35,7 @@ class HsIPv6NumberHostingAssetValidator extends HostingAssetEntityValidator { } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { return IPV6_REGEX; } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedServerHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedServerHostingAssetValidator.java index 732c0285..99138e0e 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedServerHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedServerHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.regex.Pattern; @@ -54,7 +54,7 @@ class HsManagedServerHostingAssetValidator extends HostingAssetEntityValidator { } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { return Pattern.compile("^vm[0-9][0-9][0-9][0-9]$"); } } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedWebspaceHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedWebspaceHostingAssetValidator.java index b962e655..dc0ece36 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedWebspaceHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedWebspaceHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.regex.Pattern; @@ -15,7 +15,7 @@ class HsManagedWebspaceHostingAssetValidator extends HostingAssetEntityValidator } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { final var prefixPattern = !assetEntity.isLoaded() ? assetEntity.getRelatedProject().getDebitor().getDefaultPrefix() diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbDatabaseHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbDatabaseHostingAssetValidator.java index 197dc9b6..48618be3 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbDatabaseHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbDatabaseHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.regex.Pattern; @@ -18,7 +18,7 @@ class HsMariaDbDatabaseHostingAssetValidator extends HostingAssetEntityValidator } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { final var webspaceIdentifier = assetEntity.getParentAsset().getParentAsset().getIdentifier(); return Pattern.compile("^"+webspaceIdentifier+"$|^"+webspaceIdentifier+"_[a-z0-9_]+$"); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbInstanceHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbInstanceHostingAssetValidator.java index 74acd9e6..d9509906 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbInstanceHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbInstanceHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.regex.Pattern; @@ -19,7 +19,7 @@ class HsMariaDbInstanceHostingAssetValidator extends HostingAssetEntityValidator } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { return Pattern.compile( "^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + DEFAULT_INSTANCE_IDENTIFIER_SUFFIX) @@ -27,7 +27,7 @@ class HsMariaDbInstanceHostingAssetValidator extends HostingAssetEntityValidator } @Override - public void preprocessEntity(final HsHostingAssetEntity entity) { + public void preprocessEntity(final HsHostingAsset entity) { super.preprocessEntity(entity); if (entity.getIdentifier() == null) { ofNullable(entity.getParentAsset()).ifPresent(pa -> entity.setIdentifier( diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbUserHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbUserHostingAssetValidator.java index 8e749e44..15ae0b45 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbUserHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbUserHostingAssetValidator.java @@ -1,7 +1,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; import net.hostsharing.hsadminng.hash.HashGenerator; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.regex.Pattern; @@ -26,7 +26,7 @@ class HsMariaDbUserHostingAssetValidator extends HostingAssetEntityValidator { } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { final var webspaceIdentifier = assetEntity.getParentAsset().getIdentifier(); return Pattern.compile("^"+webspaceIdentifier+"$|^"+webspaceIdentifier+"_[a-z0-9_]+$"); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlDatabaseHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlDatabaseHostingAssetValidator.java index 86e9900e..57d302d0 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlDatabaseHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlDatabaseHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.regex.Pattern; @@ -21,7 +21,7 @@ class HsPostgreSqlDatabaseHostingAssetValidator extends HostingAssetEntityValida } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { final var webspaceIdentifier = assetEntity.getParentAsset().getParentAsset().getIdentifier(); return Pattern.compile("^"+webspaceIdentifier+"$|^"+webspaceIdentifier+"_[a-z0-9_]+$"); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlDbInstanceHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlDbInstanceHostingAssetValidator.java index ecdd5441..36365597 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlDbInstanceHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlDbInstanceHostingAssetValidator.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.regex.Pattern; @@ -21,7 +21,7 @@ class HsPostgreSqlDbInstanceHostingAssetValidator extends HostingAssetEntityVali } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { return Pattern.compile( "^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + DEFAULT_INSTANCE_IDENTIFIER_SUFFIX) @@ -29,7 +29,7 @@ class HsPostgreSqlDbInstanceHostingAssetValidator extends HostingAssetEntityVali } @Override - public void preprocessEntity(final HsHostingAssetEntity entity) { + public void preprocessEntity(final HsHostingAsset entity) { super.preprocessEntity(entity); if (entity.getIdentifier() == null) { ofNullable(entity.getParentAsset()).ifPresent(pa -> entity.setIdentifier( diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlUserHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlUserHostingAssetValidator.java index 8c91427d..7d527892 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlUserHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlUserHostingAssetValidator.java @@ -1,7 +1,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; import net.hostsharing.hsadminng.hash.HashGenerator; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import java.util.regex.Pattern; @@ -26,7 +26,7 @@ class HsPostgreSqlUserHostingAssetValidator extends HostingAssetEntityValidator } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { final var webspaceIdentifier = assetEntity.getParentAsset().getIdentifier(); return Pattern.compile("^"+webspaceIdentifier+"$|^"+webspaceIdentifier+"_[a-z0-9_]+$"); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidator.java index 965c2d1b..a53b536f 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidator.java @@ -1,7 +1,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; import net.hostsharing.hsadminng.hash.HashGenerator; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; @@ -40,13 +40,13 @@ class HsUnixUserHostingAssetValidator extends HostingAssetEntityValidator { } @Override - protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + protected Pattern identifierPattern(final HsHostingAsset assetEntity) { final var webspaceIdentifier = assetEntity.getParentAsset().getIdentifier(); return Pattern.compile("^"+webspaceIdentifier+"$|^"+webspaceIdentifier+"-[a-z0-9\\._-]+$"); } private static String computeHomedir(final EntityManager em, final PropertiesProvider propertiesProvider) { - final var entity = (HsHostingAssetEntity) propertiesProvider; + final var entity = (HsHostingAsset) propertiesProvider; final var webspaceName = entity.getParentAsset().getIdentifier(); return "/home/pacs/" + webspaceName + "/users/" + entity.getIdentifier().substring(webspaceName.length()+DASH_LENGTH); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/README.md b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/README.md index 52e03058..72470290 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/README.md +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/README.md @@ -1,9 +1,9 @@ -### HsHostingAssetEntity-Validation +### HsHostingAsset-Validation -There is just a single `HsHostingAssetEntity` class for all types of hosting assets like Managed-Server, Managed-Webspace, Unix-Users, Databases etc. These are distinguished by `HsHostingAssetType HsHostingAssetEntity.type`. +There is just a single `HsHostingAsset` interface and `HsHostingAssetEntity` entity for all types of hosting assets like Managed-Server, Managed-Webspace, Unix-Users, Databases etc. These are distinguished by `HsHostingAssetType HsHostingAsset.type`. For each of these types, a distinct validator has to be -implemented as a subclass of `HsHostingAssetEntityValidator` which needs to be registered (see `HsHostingAssetEntityValidatorRegistry`) for the relevant type(s). +implemented as a subclass of `HsHostingAssetValidator` which needs to be registered (see `HsHostingAssetValidatorRegistry`) for the relevant type(s). ### Kinds of Validations @@ -21,7 +21,7 @@ References in this context are: - the Assigned-To-Hosting-Asset and - the Contact. -The first parameters of the `HsHostingAssetEntityValidator` superclass take rule descriptors for these references. These are all Subclasses fo +The first parameters of the `HsHostingAssetValidator` superclass take rule descriptors for these references. These are all Subclasses fo ### Validation Order @@ -37,4 +37,4 @@ In general, the validation es executed in this order: 2. the limits of the parent entity (parent asset + booking item) 3. limits against the own own-sub-entities -This implementation can be found in `HsHostingAssetEntityValidator.validate`. +This implementation can be found in `HsHostingAssetValidator.validate`. diff --git a/src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java b/src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java index ffdb7a5a..b410465f 100644 --- a/src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java +++ b/src/main/java/net/hostsharing/hsadminng/stringify/Stringify.java @@ -16,9 +16,8 @@ import static java.lang.Boolean.TRUE; public final class Stringify { - private final Class clazz; private final String name; - private Function idProp; + private Function idProp; private final List> props = new ArrayList<>(); private String separator = ", "; private Boolean quotedValues = null; @@ -31,8 +30,16 @@ public final class Stringify { return new Stringify<>(clazz, null); } + public Stringify using(final Class subClass) { + //noinspection unchecked + return (Stringify) new Stringify(subClass, null) + .withIdProp(cast(idProp)) + .withProps(cast(props)) + .withSeparator(separator) + .quotedValues(quotedValues); + } + private Stringify(final Class clazz, final String name) { - this.clazz = clazz; if (name != null) { this.name = name; } else { @@ -45,7 +52,7 @@ public final class Stringify { } } - public Stringify withIdProp(final Function getter) { + public Stringify withIdProp(final Function getter) { idProp = getter; return this; } @@ -60,6 +67,11 @@ public final class Stringify { return this; } + private Stringify withProps(final List> props) { + this.props.addAll(props); + return this; + } + public String apply(@NotNull B object) { final var propValues = props.stream() .map(prop -> PropertyValue.of(prop, prop.getter.apply(object))) @@ -74,7 +86,7 @@ public final class Stringify { .map(propVal -> propName(propVal, "=") + optionallyQuoted(propVal)) .collect(Collectors.joining(separator)); return idProp != null - ? name + "(" + idProp.apply(object) + ": " + propValues + ")" + ? name + "(" + idProp.apply(cast(object)) + ": " + propValues + ")" : name + "(" + propValues + ")"; } @@ -106,6 +118,11 @@ public final class Stringify { return this; } + private T cast(final Object object) { + //noinspection unchecked + return (T)object; + } + private record Property(String name, Function getter) {} private record PropertyValue(Property prop, Object rawValue, String value) { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java index cfe99ae7..7f66379c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java @@ -68,7 +68,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { "{type=boolean, propertyName=auto-WILDCARD-AAAA-RR, defaultValue=true}", "{type=boolean, propertyName=auto-WILDCARD-DKIM-RR, defaultValue=true}", "{type=boolean, propertyName=auto-WILDCARD-SPF-RR, defaultValue=true}", - "{type=string[], propertyName=user-RR, elementsOf={type=string, propertyName=user-RR, matchesRegEx=[([a-z0-9\\._-]+|@)\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*IN\\s+[A-Z]+\\s+[^;].*(;.*)*, ([a-z0-9\\._-]+|@)\\s+IN\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*[A-Z]+\\s+[^;].*(;.*)*], required=true}}" + "{type=string[], propertyName=user-RR, elementsOf={type=string, propertyName=user-RR, matchesRegEx=[([a-z0-9\\.-]+|@)\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*IN\\s+[A-Z]+\\s+[^;].*(;.*)*, ([a-z0-9\\.-]+|@)\\s+IN\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*[A-Z]+\\s+[^;].*(;.*)*], required=true}}" ); } @@ -166,8 +166,8 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( "'DOMAIN_DNS_SETUP:example.org|DNS.config.TTL' is expected to be of type Integer, but is of type String", - "'DOMAIN_DNS_SETUP:example.org|DNS.config.user-RR' is expected to match any of [([a-z0-9\\._-]+|@)\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*IN\\s+[A-Z]+\\s+[^;].*(;.*)*, ([a-z0-9\\._-]+|@)\\s+IN\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*[A-Z]+\\s+[^;].*(;.*)*] but '@ 1814400 IN 1814400 BAD1 TTL only allowed once' does not match any", - "'DOMAIN_DNS_SETUP:example.org|DNS.config.user-RR' is expected to match any of [([a-z0-9\\._-]+|@)\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*IN\\s+[A-Z]+\\s+[^;].*(;.*)*, ([a-z0-9\\._-]+|@)\\s+IN\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*[A-Z]+\\s+[^;].*(;.*)*] but 'www BAD1 Record-Class missing / not enough columns' does not match any"); + "'DOMAIN_DNS_SETUP:example.org|DNS.config.user-RR' is expected to match any of [([a-z0-9\\.-]+|@)\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*IN\\s+[A-Z]+\\s+[^;].*(;.*)*, ([a-z0-9\\.-]+|@)\\s+IN\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*[A-Z]+\\s+[^;].*(;.*)*] but '@ 1814400 IN 1814400 BAD1 TTL only allowed once' does not match any", + "'DOMAIN_DNS_SETUP:example.org|DNS.config.user-RR' is expected to match any of [([a-z0-9\\.-]+|@)\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*IN\\s+[A-Z]+\\s+[^;].*(;.*)*, ([a-z0-9\\.-]+|@)\\s+IN\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*[A-Z]+\\s+[^;].*(;.*)*] but 'www BAD1 Record-Class missing / not enough columns' does not match any"); } @Test diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAliasHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAliasHostingAssetValidatorUnitTest.java index 19e50d24..9d9422ab 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAliasHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAliasHostingAssetValidatorUnitTest.java @@ -22,7 +22,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest { // then assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder( - "{type=string[], propertyName=target, elementsOf={type=string, propertyName=target, matchesRegEx=[^[a-z][a-z0-9]{2}[0-9]{2}(-[a-z0-9][a-z0-9\\._-]*)?$, ^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$, ^:include:/.*$, ^|.*$], maxLength=320}, required=true, minLength=1}"); + "{type=string[], propertyName=target, elementsOf={type=string, propertyName=target, matchesRegEx=[^[a-z][a-z0-9]{2}[0-9]{2}(-[a-z0-9][a-z0-9\\._-]*)?$, ^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$, ^:include:/.*$, ^\\|.*$], maxLength=320}, required=true, minLength=1}"); } @Test @@ -63,7 +63,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( - "'EMAIL_ALIAS:xyz00-office.config.target' is expected to match any of [^[a-z][a-z0-9]{2}[0-9]{2}(-[a-z0-9]+)?$, ^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$] but 'garbage' does not match any"); + "'EMAIL_ALIAS:xyz00-office.config.target' is expected to match any of [^[a-z][a-z0-9]{2}[0-9]{2}(-[a-z0-9][a-z0-9\\._-]*)?$, ^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$, ^:include:/.*$, ^\\|.*$] but 'garbage' does not match any"); } @Test @@ -84,7 +84,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( - "'identifier' expected to match '^xyz00$|^xyz00-[a-z0-9]+$', but is 'abc00-office'"); + "'identifier' expected to match '^xyz00$|^xyz00-[a-z0-9][a-z0-9\\._-]*$', but is 'abc00-office'"); } @Test diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbUserHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbUserHostingAssetValidatorUnitTest.java index 259d980e..97c8429b 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbUserHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbUserHostingAssetValidatorUnitTest.java @@ -49,7 +49,7 @@ class HsMariaDbUserHostingAssetValidatorUnitTest { // then assertThat(props).extracting(Object::toString).containsExactlyInAnyOrder( - "{type=password, propertyName=password, minLength=8, maxLength=40, writeOnly=true, computed=true, hashedUsing=MYSQL_NATIVE, undisclosed=true}" + "{type=password, propertyName=password, minLength=8, maxLength=40, writeOnly=true, computed=IN_PREP, hashedUsing=MYSQL_NATIVE, undisclosed=true}" ); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlUserHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlUserHostingAssetValidatorUnitTest.java index 4b48dc5e..588631c2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlUserHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlUserHostingAssetValidatorUnitTest.java @@ -52,7 +52,7 @@ class HsPostgreSqlUserHostingAssetValidatorUnitTest { // then assertThat(props).extracting(Object::toString).containsExactlyInAnyOrder( - "{type=password, propertyName=password, minLength=8, maxLength=40, writeOnly=true, computed=true, hashedUsing=SCRAM_SHA256, undisclosed=true}" + "{type=password, propertyName=password, minLength=8, maxLength=40, writeOnly=true, computed=IN_PREP, hashedUsing=SCRAM_SHA256, undisclosed=true}" ); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidatorUnitTest.java index 7a27db88..7ae081c2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidatorUnitTest.java @@ -3,9 +3,14 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; import net.hostsharing.hsadminng.hash.HashGenerator; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import jakarta.persistence.EntityManager; +import jakarta.persistence.Query; import java.util.HashMap; import java.util.stream.Stream; @@ -16,7 +21,10 @@ import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANA import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.UNIX_USER; import static net.hostsharing.hsadminng.mapper.PatchMap.entry; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.mock; +@ExtendWith(MockitoExtension.class) class HsUnixUserHostingAssetValidatorUnitTest { private final HsHostingAssetEntity TEST_MANAGED_SERVER_HOSTING_ASSET = HsHostingAssetEntity.builder() @@ -44,7 +52,17 @@ class HsUnixUserHostingAssetValidatorUnitTest { ))) .build(); - private EntityManager em = null; // not actually needed in these test cases + @Mock + EntityManager em; + + @BeforeEach + void initMocks() { + final var nativeQueryMock = mock(Query.class); + lenient().when(nativeQueryMock.getSingleResult()).thenReturn(12345678); + lenient().when(em.createNativeQuery("SELECT nextval('hs_hosting_asset_unixuser_system_id_seq')", Integer.class)) + .thenReturn(nativeQueryMock); + + } @Test void preparesUnixUser() { @@ -61,7 +79,8 @@ class HsUnixUserHostingAssetValidatorUnitTest { entry("SSD hard quota", 50), entry("SSD soft quota", 40), entry("totpKey", "0x123456789abcdef01234"), - entry("password", "$6$Ly3LbsArtL5u4EVt$i/ayIEvm0y4bjkFB6wbg8imbRIaw4mAA4gqYRVyoSkj.iIxJKS3KiRkSjP8gweNcpKL0Q0N31EadT8fCnWErL.") + entry("password", "$6$Ly3LbsArtL5u4EVt$i/ayIEvm0y4bjkFB6wbg8imbRIaw4mAA4gqYRVyoSkj.iIxJKS3KiRkSjP8gweNcpKL0Q0N31EadT8fCnWErL."), + entry("userid", 12345678) )); } @@ -107,11 +126,9 @@ class HsUnixUserHostingAssetValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( - "'UNIX_USER:abc00-temp.config.SSD hard quota' is expected to be at most 50 but is 100", "'UNIX_USER:abc00-temp.config.SSD soft quota' is expected to be at most 100 but is 200", "'UNIX_USER:abc00-temp.config.HDD hard quota' is expected to be at most 0 but is 100", "'UNIX_USER:abc00-temp.config.HDD soft quota' is expected to be at most 100 but is 200", - "'UNIX_USER:abc00-temp.config.shell' is expected to be one of [/bin/false, /bin/bash, /bin/csh, /bin/dash, /usr/bin/tcsh, /usr/bin/zsh, /usr/bin/passwd] but is '/is/invalid'", "'UNIX_USER:abc00-temp.config.homedir' is readonly but given as '/is/read-only'", "'UNIX_USER:abc00-temp.config.totpKey' is expected to match any of [^0x([0-9A-Fa-f]{2})+$] but provided value does not match", "'UNIX_USER:abc00-temp.config.password' length is expected to be at min 8 but length of provided value is 5", @@ -134,7 +151,7 @@ class HsUnixUserHostingAssetValidatorUnitTest { // then assertThat(result).containsExactly( - "'identifier' expected to match '^abc00$|^abc00-[a-z0-9]+$', but is 'xyz99-temp'"); + "'identifier' expected to match '^abc00$|^abc00-[a-z0-9\\._-]+$', but is 'xyz99-temp'"); } @Test @@ -165,14 +182,16 @@ class HsUnixUserHostingAssetValidatorUnitTest { // then assertThat(props).extracting(Object::toString).containsExactlyInAnyOrder( - "{type=integer, propertyName=SSD hard quota, unit=GB, maxFrom=SSD}", - "{type=integer, propertyName=SSD soft quota, unit=GB, maxFrom=SSD hard quota}", - "{type=integer, propertyName=HDD hard quota, unit=GB, maxFrom=HDD}", - "{type=integer, propertyName=HDD soft quota, unit=GB, maxFrom=HDD hard quota}", - "{type=enumeration, propertyName=shell, values=[/bin/false, /bin/bash, /bin/csh, /bin/dash, /usr/bin/tcsh, /usr/bin/zsh, /usr/bin/passwd], defaultValue=/bin/false}", - "{type=string, propertyName=homedir, readOnly=true, computed=true}", + "{type=boolean, propertyName=locked, readOnly=true}", + "{type=integer, propertyName=userid, readOnly=true, computed=IN_INIT}", + "{type=integer, propertyName=SSD hard quota, unit=MB, maxFrom=SSD}", + "{type=integer, propertyName=SSD soft quota, unit=MB, maxFrom=SSD hard quota}", + "{type=integer, propertyName=HDD hard quota, unit=MB, maxFrom=HDD}", + "{type=integer, propertyName=HDD soft quota, unit=MB, maxFrom=HDD hard quota}", + "{type=string, propertyName=shell, provided=[/bin/false, /bin/bash, /bin/csh, /bin/dash, /usr/bin/tcsh, /usr/bin/zsh, /usr/bin/passwd], defaultValue=/bin/false}", + "{type=string, propertyName=homedir, readOnly=true, computed=IN_REVAMP}", "{type=string, propertyName=totpKey, matchesRegEx=[^0x([0-9A-Fa-f]{2})+$], minLength=20, maxLength=256, writeOnly=true, undisclosed=true}", - "{type=password, propertyName=password, minLength=8, maxLength=40, writeOnly=true, computed=true, hashedUsing=LINUX_SHA512, undisclosed=true}" + "{type=password, propertyName=password, minLength=8, maxLength=40, writeOnly=true, computed=IN_PREP, hashedUsing=LINUX_SHA512, undisclosed=true}" ); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java index b124c08a..b0f77302 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java @@ -31,12 +31,14 @@ import java.lang.annotation.RetentionPolicy; import java.math.BigDecimal; import java.time.LocalDate; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.TreeMap; import java.util.stream.Collectors; import static java.lang.Boolean.parseBoolean; +import static java.util.Arrays.asList; import static java.util.Arrays.stream; import static java.util.Objects.requireNonNull; import static java.util.Optional.ofNullable; @@ -234,6 +236,27 @@ public class CsvDataImport extends ContextBasedTest { void logErrors() { assertThat(errors).isEmpty(); } + + void expectErrors(final String... expectedErrors) { + assertContainsExactlyInAnyOrderIgnoringWhitespace(errors, expectedErrors); + } + + private static class IgnoringWhitespaceComparator implements Comparator { + @Override + public int compare(String s1, String s2) { + return s1.replaceAll("\\s", "").compareTo(s2.replaceAll("\\s", "")); + } + } + + public static void assertContainsExactlyInAnyOrderIgnoringWhitespace(final List expected, final List actual) { + final var sortedExpected = expected.stream().map(m -> m.replaceAll("\\s", "")).toList(); + final var sortedActual = actual.stream().map(m -> m.replaceAll("\\s", "")).toArray(String[]::new); + assertThat(sortedExpected).containsExactlyInAnyOrder(sortedActual); + } + + public static void assertContainsExactlyInAnyOrderIgnoringWhitespace(final List expected, final String... actual) { + assertContainsExactlyInAnyOrderIgnoringWhitespace(expected, asList(actual)); + } } class Columns { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetRawEntity.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetRawEntity.java new file mode 100644 index 00000000..33e632d5 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetRawEntity.java @@ -0,0 +1,114 @@ +package net.hostsharing.hsadminng.hs.migration; + +import io.hypersistence.utils.hibernate.type.json.JsonType; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; +import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; +import org.hibernate.annotations.Type; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +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; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +@Builder +@Entity +@Table(name = "hs_hosting_asset") +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class HsHostingAssetRawEntity implements HsHostingAsset { + + @Id + @GeneratedValue + private UUID uuid; + + @Version + private int version; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "bookingitemuuid") + private HsBookingItemEntity bookingItem; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "parentassetuuid") + private HsHostingAssetRawEntity parentAsset; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "assignedtoassetuuid") + private HsHostingAssetRawEntity assignedToAsset; + + @Column(name = "type") + @Enumerated(EnumType.STRING) + private HsHostingAssetType type; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "alarmcontactuuid") + private HsOfficeContactEntity alarmContact; + + @OneToMany(cascade = CascadeType.REFRESH, orphanRemoval = true, fetch = FetchType.LAZY) + @JoinColumn(name = "parentassetuuid", referencedColumnName = "uuid") + private List subHostingAssets; + + @Column(name = "identifier") + private String identifier; // e.g. vm1234, xyz00, example.org, xyz00_abc + + @Column(name = "caption") + private String caption; + + @Builder.Default + @Setter(AccessLevel.NONE) + @Type(JsonType.class) + @Column(columnDefinition = "config") + private Map config = new HashMap<>(); + + @Transient + private PatchableMapWrapper configWrapper; + + @Transient + private boolean isLoaded; + + @PostLoad + public void markAsLoaded() { + this.isLoaded = true; + } + + public PatchableMapWrapper getConfig() { + return PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper;}, config); + } + + @Override + public Map directProps() { + return config; + } + + @Override + public String toString() { + return stringify.using(HsHostingAssetRawEntity.class).apply(this); + } +} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java index ddcf27da..4c152eb5 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java @@ -6,7 +6,6 @@ import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; import net.hostsharing.hsadminng.hs.booking.item.validators.HsBookingItemEntityValidatorRegistry; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntitySaveProcessor; import net.hostsharing.hsadminng.rbac.test.JpaAttempt; @@ -99,12 +98,12 @@ public class ImportHostingAssets extends ImportOfficeData { static final Integer UNIXUSER_ID_OFFSET = 4000000; static final Integer EMAILALIAS_ID_OFFSET = 5000000; - record Hive(int hive_id, String hive_name, int inet_addr_id, AtomicReference serverRef) {} + record Hive(int hive_id, String hive_name, int inet_addr_id, AtomicReference serverRef) {} static Map bookingProjects = new WriteOnceMap<>(); static Map bookingItems = new WriteOnceMap<>(); static Map hives = new WriteOnceMap<>(); - static Map hostingAssets = new WriteOnceMap<>(); // TODO.impl: separate maps for each type? + static Map hostingAssets = new WriteOnceMap<>(); // TODO.impl: separate maps for each type? @Test @Order(11010) @@ -136,11 +135,11 @@ public class ImportHostingAssets extends ImportOfficeData { // no contacts yet => mostly null values assertThat(firstOfEachType(5, IPV4_NUMBER)).isEqualToIgnoringWhitespace(""" { - 1000363=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.34), - 1000381=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.52), - 1000402=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.73), - 1000433=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.104), - 1000457=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.128) + 1000363=HsHostingAssetRawEntity(IPV4_NUMBER, 83.223.95.34), + 1000381=HsHostingAssetRawEntity(IPV4_NUMBER, 83.223.95.52), + 1000402=HsHostingAssetRawEntity(IPV4_NUMBER, 83.223.95.73), + 1000433=HsHostingAssetRawEntity(IPV4_NUMBER, 83.223.95.104), + 1000457=HsHostingAssetRawEntity(IPV4_NUMBER, 83.223.95.128) } """); } @@ -191,13 +190,13 @@ public class ImportHostingAssets extends ImportOfficeData { assertThat(firstOfEachType(3, CLOUD_SERVER, MANAGED_SERVER, MANAGED_WEBSPACE)).isEqualToIgnoringWhitespace(""" { - 3000630=HsHostingAssetEntity(MANAGED_WEBSPACE, hsh00, HA hsh00, MANAGED_SERVER:vm1050, D-1000000:hsh default project:BI hsh00), - 3000968=HsHostingAssetEntity(MANAGED_SERVER, vm1061, HA vm1061, D-1015200:rar default project:BI vm1061), - 3000978=HsHostingAssetEntity(MANAGED_SERVER, vm1050, HA vm1050, D-1000000:hsh default project:BI vm1050), - 3001061=HsHostingAssetEntity(MANAGED_SERVER, vm1068, HA vm1068, D-1000300:mim default project:BI vm1068), - 3001094=HsHostingAssetEntity(MANAGED_WEBSPACE, lug00, HA lug00, MANAGED_SERVER:vm1068, D-1000300:mim default project:BI lug00), - 3001112=HsHostingAssetEntity(MANAGED_WEBSPACE, mim00, HA mim00, MANAGED_SERVER:vm1068, D-1000300:mim default project:BI mim00), - 3023611=HsHostingAssetEntity(CLOUD_SERVER, vm2097, HA vm2097, D-1101800:wws default project:BI vm2097) + 3000630=HsHostingAssetRawEntity(MANAGED_WEBSPACE, hsh00, HA hsh00, MANAGED_SERVER:vm1050, D-1000000:hsh default project:BI hsh00), + 3000968=HsHostingAssetRawEntity(MANAGED_SERVER, vm1061, HA vm1061, D-1015200:rar default project:BI vm1061), + 3000978=HsHostingAssetRawEntity(MANAGED_SERVER, vm1050, HA vm1050, D-1000000:hsh default project:BI vm1050), + 3001061=HsHostingAssetRawEntity(MANAGED_SERVER, vm1068, HA vm1068, D-1000300:mim default project:BI vm1068), + 3001094=HsHostingAssetRawEntity(MANAGED_WEBSPACE, lug00, HA lug00, MANAGED_SERVER:vm1068, D-1000300:mim default project:BI lug00), + 3001112=HsHostingAssetRawEntity(MANAGED_WEBSPACE, mim00, HA mim00, MANAGED_SERVER:vm1068, D-1000300:mim default project:BI mim00), + 3023611=HsHostingAssetRawEntity(CLOUD_SERVER, vm2097, HA vm2097, D-1101800:wws default project:BI vm2097) } """); assertThat(firstOfEachType( @@ -237,15 +236,15 @@ public class ImportHostingAssets extends ImportOfficeData { assertThat(firstOfEachType(5, CLOUD_SERVER, MANAGED_SERVER, MANAGED_WEBSPACE)) .isEqualToIgnoringWhitespace(""" { - 3000630=HsHostingAssetEntity(MANAGED_WEBSPACE, hsh00, HA hsh00, MANAGED_SERVER:vm1050, D-1000000:hsh default project:BI hsh00), - 3000968=HsHostingAssetEntity(MANAGED_SERVER, vm1061, HA vm1061, D-1015200:rar default project:BI vm1061), - 3000978=HsHostingAssetEntity(MANAGED_SERVER, vm1050, HA vm1050, D-1000000:hsh default project:BI vm1050), - 3001061=HsHostingAssetEntity(MANAGED_SERVER, vm1068, HA vm1068, D-1000300:mim default project:BI vm1068), - 3001094=HsHostingAssetEntity(MANAGED_WEBSPACE, lug00, HA lug00, MANAGED_SERVER:vm1068, D-1000300:mim default project:BI lug00), - 3001112=HsHostingAssetEntity(MANAGED_WEBSPACE, mim00, HA mim00, MANAGED_SERVER:vm1068, D-1000300:mim default project:BI mim00), - 3001447=HsHostingAssetEntity(MANAGED_SERVER, vm1093, HA vm1093, D-1000000:hsh default project:BI vm1093), - 3019959=HsHostingAssetEntity(MANAGED_WEBSPACE, dph00, HA dph00, MANAGED_SERVER:vm1093, D-1101900:dph default project:BI dph00), - 3023611=HsHostingAssetEntity(CLOUD_SERVER, vm2097, HA vm2097, D-1101800:wws default project:BI vm2097) + 3000630=HsHostingAssetRawEntity(MANAGED_WEBSPACE, hsh00, HA hsh00, MANAGED_SERVER:vm1050, D-1000000:hsh default project:BI hsh00), + 3000968=HsHostingAssetRawEntity(MANAGED_SERVER, vm1061, HA vm1061, D-1015200:rar default project:BI vm1061), + 3000978=HsHostingAssetRawEntity(MANAGED_SERVER, vm1050, HA vm1050, D-1000000:hsh default project:BI vm1050), + 3001061=HsHostingAssetRawEntity(MANAGED_SERVER, vm1068, HA vm1068, D-1000300:mim default project:BI vm1068), + 3001094=HsHostingAssetRawEntity(MANAGED_WEBSPACE, lug00, HA lug00, MANAGED_SERVER:vm1068, D-1000300:mim default project:BI lug00), + 3001112=HsHostingAssetRawEntity(MANAGED_WEBSPACE, mim00, HA mim00, MANAGED_SERVER:vm1068, D-1000300:mim default project:BI mim00), + 3001447=HsHostingAssetRawEntity(MANAGED_SERVER, vm1093, HA vm1093, D-1000000:hsh default project:BI vm1093), + 3019959=HsHostingAssetRawEntity(MANAGED_WEBSPACE, dph00, HA dph00, MANAGED_SERVER:vm1093, D-1101900:dph default project:BI dph00), + 3023611=HsHostingAssetRawEntity(CLOUD_SERVER, vm2097, HA vm2097, D-1101800:wws default project:BI vm2097) } """); assertThat(firstOfEachType( @@ -287,20 +286,20 @@ public class ImportHostingAssets extends ImportOfficeData { // no contacts yet => mostly null values assertThat(firstOfEachType(15, UNIX_USER)).isEqualToIgnoringWhitespace(""" { - 4005803=HsHostingAssetEntity(UNIX_USER, lug00, LUGs, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 102090}), - 4005805=HsHostingAssetEntity(UNIX_USER, lug00-wla.1, Paul Klemm, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 102091}), - 4005809=HsHostingAssetEntity(UNIX_USER, lug00-wla.2, Walter Müller, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 8, "SSD soft quota": 4, "locked": false, "shell": "/bin/bash", "userid": 102093}), - 4005811=HsHostingAssetEntity(UNIX_USER, lug00-ola.a, LUG OLA - POP a, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/usr/bin/passwd", "userid": 102094}), - 4005813=HsHostingAssetEntity(UNIX_USER, lug00-ola.b, LUG OLA - POP b, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/usr/bin/passwd", "userid": 102095}), - 4005835=HsHostingAssetEntity(UNIX_USER, lug00-test, Test, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 1024, "SSD soft quota": 1024, "locked": false, "shell": "/usr/bin/passwd", "userid": 102106}), - 4005964=HsHostingAssetEntity(UNIX_USER, mim00, Michael Mellis, MANAGED_WEBSPACE:mim00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 102147}), - 4005966=HsHostingAssetEntity(UNIX_USER, mim00-1981, Jahrgangstreffen 1981, MANAGED_WEBSPACE:mim00, { "SSD hard quota": 256, "SSD soft quota": 128, "locked": false, "shell": "/bin/bash", "userid": 102148}), - 4005990=HsHostingAssetEntity(UNIX_USER, mim00-mail, Mailbox, MANAGED_WEBSPACE:mim00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 102160}), - 4100705=HsHostingAssetEntity(UNIX_USER, hsh00-mim, Michael Mellis, MANAGED_WEBSPACE:hsh00, { "HDD hard quota": 0, "HDD soft quota": 0, "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/false", "userid": 10003}), - 4100824=HsHostingAssetEntity(UNIX_USER, hsh00, Hostsharing Paket, MANAGED_WEBSPACE:hsh00, { "HDD hard quota": 0, "HDD soft quota": 0, "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 10000}), - 4167846=HsHostingAssetEntity(UNIX_USER, hsh00-dph, hsh00-uph, MANAGED_WEBSPACE:hsh00, { "HDD hard quota": 0, "HDD soft quota": 0, "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/false", "userid": 110568}), - 4169546=HsHostingAssetEntity(UNIX_USER, dph00, Reinhard Wiese, MANAGED_WEBSPACE:dph00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 110593}), - 4169596=HsHostingAssetEntity(UNIX_USER, dph00-uph, Domain admin, MANAGED_WEBSPACE:dph00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 110594}) + 4005803=HsHostingAssetRawEntity(UNIX_USER, lug00, LUGs, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 102090}), + 4005805=HsHostingAssetRawEntity(UNIX_USER, lug00-wla.1, Paul Klemm, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 102091}), + 4005809=HsHostingAssetRawEntity(UNIX_USER, lug00-wla.2, Walter Müller, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 8, "SSD soft quota": 4, "locked": false, "shell": "/bin/bash", "userid": 102093}), + 4005811=HsHostingAssetRawEntity(UNIX_USER, lug00-ola.a, LUG OLA - POP a, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/usr/bin/passwd", "userid": 102094}), + 4005813=HsHostingAssetRawEntity(UNIX_USER, lug00-ola.b, LUG OLA - POP b, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/usr/bin/passwd", "userid": 102095}), + 4005835=HsHostingAssetRawEntity(UNIX_USER, lug00-test, Test, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 1024, "SSD soft quota": 1024, "locked": false, "shell": "/usr/bin/passwd", "userid": 102106}), + 4005964=HsHostingAssetRawEntity(UNIX_USER, mim00, Michael Mellis, MANAGED_WEBSPACE:mim00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 102147}), + 4005966=HsHostingAssetRawEntity(UNIX_USER, mim00-1981, Jahrgangstreffen 1981, MANAGED_WEBSPACE:mim00, { "SSD hard quota": 256, "SSD soft quota": 128, "locked": false, "shell": "/bin/bash", "userid": 102148}), + 4005990=HsHostingAssetRawEntity(UNIX_USER, mim00-mail, Mailbox, MANAGED_WEBSPACE:mim00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 102160}), + 4100705=HsHostingAssetRawEntity(UNIX_USER, hsh00-mim, Michael Mellis, MANAGED_WEBSPACE:hsh00, { "HDD hard quota": 0, "HDD soft quota": 0, "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/false", "userid": 10003}), + 4100824=HsHostingAssetRawEntity(UNIX_USER, hsh00, Hostsharing Paket, MANAGED_WEBSPACE:hsh00, { "HDD hard quota": 0, "HDD soft quota": 0, "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 10000}), + 4167846=HsHostingAssetRawEntity(UNIX_USER, hsh00-dph, hsh00-uph, MANAGED_WEBSPACE:hsh00, { "HDD hard quota": 0, "HDD soft quota": 0, "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/false", "userid": 110568}), + 4169546=HsHostingAssetRawEntity(UNIX_USER, dph00, Reinhard Wiese, MANAGED_WEBSPACE:dph00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 110593}), + 4169596=HsHostingAssetRawEntity(UNIX_USER, dph00-uph, Domain admin, MANAGED_WEBSPACE:dph00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "shell": "/bin/bash", "userid": 110594}) } """); } @@ -324,16 +323,16 @@ public class ImportHostingAssets extends ImportOfficeData { // no contacts yet => mostly null values assertThat(firstOfEachType(15, EMAIL_ALIAS)).isEqualToIgnoringWhitespace(""" { - 5002403=HsHostingAssetEntity(EMAIL_ALIAS, lug00, lug00, MANAGED_WEBSPACE:lug00, { "target": "[michael.mellis@example.com]"}), - 5002405=HsHostingAssetEntity(EMAIL_ALIAS, lug00-wla-listar, lug00-wla-listar, MANAGED_WEBSPACE:lug00, { "target": "[|/home/pacs/lug00/users/in/mailinglist/listar]"}), - 5002429=HsHostingAssetEntity(EMAIL_ALIAS, mim00, mim00, MANAGED_WEBSPACE:mim00, { "target": "[mim12-mi@mim12.hostsharing.net]"}), - 5002431=HsHostingAssetEntity(EMAIL_ALIAS, mim00-abruf, mim00-abruf, MANAGED_WEBSPACE:mim00, { "target": "[michael.mellis@hostsharing.net]"}), - 5002449=HsHostingAssetEntity(EMAIL_ALIAS, mim00-hhfx, mim00-hhfx, MANAGED_WEBSPACE:mim00, { "target": "[mim00-hhfx, |/usr/bin/formail -I 'Reply-To: hamburger-fx@example.net' | /usr/lib/sendmail mim00-hhfx-l]"}), - 5002451=HsHostingAssetEntity(EMAIL_ALIAS, mim00-hhfx-l, mim00-hhfx-l, MANAGED_WEBSPACE:mim00, { "target": "[:include:/home/pacs/mim00/etc/hhfx.list]"}), - 5002452=HsHostingAssetEntity(EMAIL_ALIAS, mim00-empty, mim00-empty, MANAGED_WEBSPACE:mim00, { "target": "[]"}), - 5002453=HsHostingAssetEntity(EMAIL_ALIAS, mim00-0_entries, mim00-0_entries, MANAGED_WEBSPACE:mim00, { "target": "[]"}), - 5002454=HsHostingAssetEntity(EMAIL_ALIAS, mim00-dev.null, mim00-dev.null, MANAGED_WEBSPACE:mim00, { "target": "[/dev/null]"}), - 5002455=HsHostingAssetEntity(EMAIL_ALIAS, mim00-1_with_space, mim00-1_with_space, MANAGED_WEBSPACE:mim00, { "target": "[|/home/pacs/mim00/install/corpslistar/listar]"}) + 5002403=HsHostingAssetRawEntity(EMAIL_ALIAS, lug00, lug00, MANAGED_WEBSPACE:lug00, { "target": "[michael.mellis@example.com]"}), + 5002405=HsHostingAssetRawEntity(EMAIL_ALIAS, lug00-wla-listar, lug00-wla-listar, MANAGED_WEBSPACE:lug00, { "target": "[|/home/pacs/lug00/users/in/mailinglist/listar]"}), + 5002429=HsHostingAssetRawEntity(EMAIL_ALIAS, mim00, mim00, MANAGED_WEBSPACE:mim00, { "target": "[mim12-mi@mim12.hostsharing.net]"}), + 5002431=HsHostingAssetRawEntity(EMAIL_ALIAS, mim00-abruf, mim00-abruf, MANAGED_WEBSPACE:mim00, { "target": "[michael.mellis@hostsharing.net]"}), + 5002449=HsHostingAssetRawEntity(EMAIL_ALIAS, mim00-hhfx, mim00-hhfx, MANAGED_WEBSPACE:mim00, { "target": "[mim00-hhfx, |/usr/bin/formail -I 'Reply-To: hamburger-fx@example.net' | /usr/lib/sendmail mim00-hhfx-l]"}), + 5002451=HsHostingAssetRawEntity(EMAIL_ALIAS, mim00-hhfx-l, mim00-hhfx-l, MANAGED_WEBSPACE:mim00, { "target": "[:include:/home/pacs/mim00/etc/hhfx.list]"}), + 5002452=HsHostingAssetRawEntity(EMAIL_ALIAS, mim00-empty, mim00-empty, MANAGED_WEBSPACE:mim00, { "target": "[]"}), + 5002453=HsHostingAssetRawEntity(EMAIL_ALIAS, mim00-0_entries, mim00-0_entries, MANAGED_WEBSPACE:mim00, { "target": "[]"}), + 5002454=HsHostingAssetRawEntity(EMAIL_ALIAS, mim00-dev.null, mim00-dev.null, MANAGED_WEBSPACE:mim00, { "target": "[/dev/null]"}), + 5002455=HsHostingAssetRawEntity(EMAIL_ALIAS, mim00-1_with_space, mim00-1_with_space, MANAGED_WEBSPACE:mim00, { "target": "[|/home/pacs/mim00/install/corpslistar/listar]"}) } """); } @@ -359,7 +358,7 @@ public class ImportHostingAssets extends ImportOfficeData { try { new HostingAssetEntitySaveProcessor(em, ha) .preprocessEntity() - .validateEntityIgnoring("'EMAIL_ALIAS:.*\\.config\\.target' .*") + .validateEntity() .prepareForSave(); } catch (final Exception exc) { errors.add("validation failed for id:" + id + "( " + ha + "): " + exc.getMessage()); @@ -371,7 +370,7 @@ public class ImportHostingAssets extends ImportOfficeData { @Order(18999) @ContinueOnFailure void logValidationErrors() { - super.logErrors(); + this.logErrors(); } // -------------------------------------------------------------------------------------------- @@ -409,20 +408,20 @@ public class ImportHostingAssets extends ImportOfficeData { // no contacts yet => mostly null value assertThat(firstOfEachType(15, UNIX_USER)).isEqualToIgnoringWhitespace(""" { - 4005803=HsHostingAssetEntity(UNIX_USER, lug00, LUGs, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 102090}), - 4005805=HsHostingAssetEntity(UNIX_USER, lug00-wla.1, Paul Klemm, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 102091}), - 4005809=HsHostingAssetEntity(UNIX_USER, lug00-wla.2, Walter Müller, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 8, "SSD soft quota": 4, "locked": false, "password": null, "shell": "/bin/bash", "userid": 102093}), - 4005811=HsHostingAssetEntity(UNIX_USER, lug00-ola.a, LUG OLA - POP a, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/usr/bin/passwd", "userid": 102094}), - 4005813=HsHostingAssetEntity(UNIX_USER, lug00-ola.b, LUG OLA - POP b, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/usr/bin/passwd", "userid": 102095}), - 4005835=HsHostingAssetEntity(UNIX_USER, lug00-test, Test, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 1024, "SSD soft quota": 1024, "locked": false, "password": null, "shell": "/usr/bin/passwd", "userid": 102106}), - 4005964=HsHostingAssetEntity(UNIX_USER, mim00, Michael Mellis, MANAGED_WEBSPACE:mim00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 102147}), - 4005966=HsHostingAssetEntity(UNIX_USER, mim00-1981, Jahrgangstreffen 1981, MANAGED_WEBSPACE:mim00, { "SSD hard quota": 256, "SSD soft quota": 128, "locked": false, "password": null, "shell": "/bin/bash", "userid": 102148}), - 4005990=HsHostingAssetEntity(UNIX_USER, mim00-mail, Mailbox, MANAGED_WEBSPACE:mim00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 102160}), - 4100705=HsHostingAssetEntity(UNIX_USER, hsh00-mim, Michael Mellis, MANAGED_WEBSPACE:hsh00, { "HDD hard quota": 0, "HDD soft quota": 0, "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/false", "userid": 10003}), - 4100824=HsHostingAssetEntity(UNIX_USER, hsh00, Hostsharing Paket, MANAGED_WEBSPACE:hsh00, { "HDD hard quota": 0, "HDD soft quota": 0, "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 10000}), - 4167846=HsHostingAssetEntity(UNIX_USER, hsh00-dph, hsh00-uph, MANAGED_WEBSPACE:hsh00, { "HDD hard quota": 0, "HDD soft quota": 0, "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/false", "userid": 110568}), - 4169546=HsHostingAssetEntity(UNIX_USER, dph00, Reinhard Wiese, MANAGED_WEBSPACE:dph00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 110593}), - 4169596=HsHostingAssetEntity(UNIX_USER, dph00-uph, Domain admin, MANAGED_WEBSPACE:dph00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 110594}) + 4005803=HsHostingAssetRawEntity(UNIX_USER, lug00, LUGs, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 102090}), + 4005805=HsHostingAssetRawEntity(UNIX_USER, lug00-wla.1, Paul Klemm, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 102091}), + 4005809=HsHostingAssetRawEntity(UNIX_USER, lug00-wla.2, Walter Müller, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 8, "SSD soft quota": 4, "locked": false, "password": null, "shell": "/bin/bash", "userid": 102093}), + 4005811=HsHostingAssetRawEntity(UNIX_USER, lug00-ola.a, LUG OLA - POP a, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/usr/bin/passwd", "userid": 102094}), + 4005813=HsHostingAssetRawEntity(UNIX_USER, lug00-ola.b, LUG OLA - POP b, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/usr/bin/passwd", "userid": 102095}), + 4005835=HsHostingAssetRawEntity(UNIX_USER, lug00-test, Test, MANAGED_WEBSPACE:lug00, { "SSD hard quota": 1024, "SSD soft quota": 1024, "locked": false, "password": null, "shell": "/usr/bin/passwd", "userid": 102106}), + 4005964=HsHostingAssetRawEntity(UNIX_USER, mim00, Michael Mellis, MANAGED_WEBSPACE:mim00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 102147}), + 4005966=HsHostingAssetRawEntity(UNIX_USER, mim00-1981, Jahrgangstreffen 1981, MANAGED_WEBSPACE:mim00, { "SSD hard quota": 256, "SSD soft quota": 128, "locked": false, "password": null, "shell": "/bin/bash", "userid": 102148}), + 4005990=HsHostingAssetRawEntity(UNIX_USER, mim00-mail, Mailbox, MANAGED_WEBSPACE:mim00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 102160}), + 4100705=HsHostingAssetRawEntity(UNIX_USER, hsh00-mim, Michael Mellis, MANAGED_WEBSPACE:hsh00, { "HDD hard quota": 0, "HDD soft quota": 0, "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/false", "userid": 10003}), + 4100824=HsHostingAssetRawEntity(UNIX_USER, hsh00, Hostsharing Paket, MANAGED_WEBSPACE:hsh00, { "HDD hard quota": 0, "HDD soft quota": 0, "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 10000}), + 4167846=HsHostingAssetRawEntity(UNIX_USER, hsh00-dph, hsh00-uph, MANAGED_WEBSPACE:hsh00, { "HDD hard quota": 0, "HDD soft quota": 0, "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/false", "userid": 110568}), + 4169546=HsHostingAssetRawEntity(UNIX_USER, dph00, Reinhard Wiese, MANAGED_WEBSPACE:dph00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 110593}), + 4169596=HsHostingAssetRawEntity(UNIX_USER, dph00-uph, Domain admin, MANAGED_WEBSPACE:dph00, { "SSD hard quota": 0, "SSD soft quota": 0, "locked": false, "password": null, "shell": "/bin/bash", "userid": 110594}) } """); } @@ -432,7 +431,25 @@ public class ImportHostingAssets extends ImportOfficeData { @Test @Order(99999) void logErrors() { - super.logErrors(); + if (isImportingControlledTestData()) { + super.expectErrors(""" + validation failed for id:5002452( HsHostingAssetRawEntity(EMAIL_ALIAS, mim00-empty, mim00-empty, MANAGED_WEBSPACE:mim00, { + "target": "[]" + } + )): ['EMAIL_ALIAS:mim00-empty.config.target' length is expected to be at min 1 but length of [[]] is 0]""", + """ + validation failed for id:5002453( HsHostingAssetRawEntity(EMAIL_ALIAS, mim00-0_entries, mim00-0_entries, MANAGED_WEBSPACE:mim00, { + "target": "[]" + } + )): ['EMAIL_ALIAS:mim00-0_entries.config.target' length is expected to be at min 1 but length of [[]] is 0]""", + """ + validation failed for id:5002454( HsHostingAssetRawEntity(EMAIL_ALIAS, mim00-dev.null, mim00-dev.null, MANAGED_WEBSPACE:mim00, { + "target": "[/dev/null]" + })): ['EMAIL_ALIAS:mim00-dev.null.config.target' is expected to match any of [^[a-z][a-z0-9]{2}[0-9]{2}(-[a-z0-9][a-z0-9\\._-]*)?$,^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$,^:include:/.*$,^\\|.*$] but '/dev/null' does not match any]""" + ); + } else { + super.logErrors(); + } } private void persistRecursively(final Integer key, final HsBookingItemEntity bi) { @@ -467,7 +484,7 @@ public class ImportHostingAssets extends ImportOfficeData { .map(this::trimAll) .map(row -> new Record(columns, row)) .forEach(rec -> { - final var ipNumber = HsHostingAssetEntity.builder() + final var ipNumber = HsHostingAssetRawEntity.builder() .type(IPV4_NUMBER) .identifier(rec.getString("inet_addr")) .caption(rec.getString("description")) @@ -531,7 +548,7 @@ public class ImportHostingAssets extends ImportOfficeData { + packet_name) .isTrue()); - final var asset = HsHostingAssetEntity.builder() + final var asset = HsHostingAssetRawEntity.builder() // this turns off identifier validation to accept former default prefixes .isLoaded(haType == MANAGED_WEBSPACE) .type(haType) @@ -671,7 +688,7 @@ public class ImportHostingAssets extends ImportOfficeData { .forEach(rec -> { final var unixuser_id = rec.getInteger("unixuser_id"); final var packet_id = rec.getInteger("packet_id"); - final var unixUserAsset = HsHostingAssetEntity.builder() + final var unixUserAsset = HsHostingAssetRawEntity.builder() .type(UNIX_USER) .parentAsset(hostingAssets.get(PACKET_ID_OFFSET + packet_id)) .identifier(rec.getString("name")) @@ -728,7 +745,7 @@ public class ImportHostingAssets extends ImportOfficeData { final var unixuser_id = rec.getInteger("emailalias_id"); final var packet_id = rec.getInteger("pac_id"); final var targets = parseCsvLine(rec.getString("target")); - final var unixUserAsset = HsHostingAssetEntity.builder() + final var unixUserAsset = HsHostingAssetRawEntity.builder() .type(EMAIL_ALIAS) .parentAsset(hostingAssets.get(PACKET_ID_OFFSET + packet_id)) .identifier(rec.getString("name")) @@ -770,7 +787,7 @@ public class ImportHostingAssets extends ImportOfficeData { }; } - private static HsHostingAssetEntity ipNumber(final Integer inet_addr_id) { + private static HsHostingAssetRawEntity ipNumber(final Integer inet_addr_id) { return inet_addr_id != null ? hostingAssets.get(IP_NUMBER_ID_OFFSET + inet_addr_id) : null; } @@ -778,7 +795,7 @@ public class ImportHostingAssets extends ImportOfficeData { return hive_id != null ? hives.get(HIVE_ID_OFFSET + hive_id) : null; } - private static HsHostingAssetEntity pac(final Integer packet_id) { + private static HsHostingAssetRawEntity pac(final Integer packet_id) { return packet_id != null ? hostingAssets.get(PACKET_ID_OFFSET + packet_id) : null; }