add DomainSetup-HostingAssets for new BookingItem via created-event #111
@ -15,6 +15,7 @@ import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
|||||||
import jakarta.validation.ValidationException;
|
import jakarta.validation.ValidationException;
|
||||||
import java.net.IDN;
|
import java.net.IDN;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_DNS_SETUP;
|
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_DNS_SETUP;
|
||||||
@ -39,47 +40,40 @@ public class DomainSetupHostingAssetFactory extends HostingAssetFactory {
|
|||||||
|
|
||||||
// TODO.legacy: as long as we need to be compatible, we always do all technical domain-setups
|
// TODO.legacy: as long as we need to be compatible, we always do all technical domain-setups
|
||||||
|
|
||||||
final var subHostingAssetResources = getSubHostingAssetResources();
|
final var domainHttpSetupAssetResource = findSubHostingAssetResource(HsHostingAssetTypeResource.DOMAIN_HTTP_SETUP);
|
||||||
|
final var assignedToUnixUserAssetEntity = domainHttpSetupAssetResource
|
||||||
|
.map(HsHostingAssetSubInsertResource::getAssignedToAssetUuid)
|
||||||
|
.map(uuid -> emw.find(HsHostingAssetRealEntity.class, uuid))
|
||||||
|
.orElseThrow(() -> new ValidationException("DOMAIN_HTTP_SETUP subAsset with assignedToAssetUuid required in compatibility mode"));
|
||||||
|
|
||||||
subHostingAssets.add(
|
subHostingAssets.add(
|
||||||
createDomainSubSetupAssetEntity(
|
createDomainSubSetupAssetEntity(
|
||||||
domainSetupAsset,
|
domainSetupAsset,
|
||||||
DOMAIN_HTTP_SETUP,
|
DOMAIN_HTTP_SETUP,
|
||||||
builder -> builder
|
builder -> builder
|
||||||
.assignedToAsset(assignedToUnixUserAsset.getParentAsset())
|
.assignedToAsset(assignedToUnixUserAssetEntity)
|
||||||
.identifier(getDomainName() + "|MBOX")
|
.identifier(getDomainName() + "|HTTP")
|
||||||
.caption("HTTP-Setup für " + IDN.toUnicode(getDomainName())))
|
.caption("HTTP-Setup für " + IDN.toUnicode(getDomainName())))
|
||||||
);
|
);
|
||||||
|
|
||||||
domainHttpSetupAsset.setParentAsset(domainSetupAsset);
|
// Do not add to subHostingAssets in compatibility mode, in this case, DNS setup works via file system.
|
||||||
final var assignedToUnixUserAsset =
|
// The entity is created just for validation purposes.
|
||||||
emw.find(HsHostingAssetRealEntity.class, domainHttpSetupAssetResource.getAssignedToAssetUuid());
|
|
||||||
domainHttpSetupAsset.setAssignedToAsset(assignedToUnixUserAsset);
|
|
||||||
|
|
||||||
|
|
||||||
final var domainHttpSetupAsset = createDomainHttpSetupAssetEntity(
|
|
||||||
subHostingAssetResources,
|
|
||||||
getDomainName(),
|
|
||||||
domainSetupAsset);
|
|
||||||
final var assignedToUnixUserAsset = domainHttpSetupAsset.getAssignedToAsset();
|
|
||||||
|
|
||||||
// do not add to subHostingAssets, in compatibility mode, DNS setup works via file system
|
|
||||||
createDomainSubSetupAssetEntity(
|
createDomainSubSetupAssetEntity(
|
||||||
domainSetupAsset,
|
domainSetupAsset,
|
||||||
DOMAIN_DNS_SETUP,
|
DOMAIN_DNS_SETUP,
|
||||||
builder -> builder
|
builder -> builder
|
||||||
.assignedToAsset(assignedToUnixUserAsset.getParentAsset())
|
.assignedToAsset(assignedToUnixUserAssetEntity.getParentAsset())
|
||||||
.identifier(getDomainName() + "|DNS")
|
.identifier(getDomainName() + "|DNS")
|
||||||
.caption("HTTP-Setup für " + IDN.toUnicode(getDomainName())));
|
.caption("DNS-Setup für " + IDN.toUnicode(getDomainName())));
|
||||||
|
|
||||||
subHostingAssets.add(
|
subHostingAssets.add(
|
||||||
createDomainSubSetupAssetEntity(
|
createDomainSubSetupAssetEntity(
|
||||||
domainSetupAsset,
|
domainSetupAsset,
|
||||||
DOMAIN_MBOX_SETUP,
|
DOMAIN_MBOX_SETUP,
|
||||||
builder -> builder
|
builder -> builder
|
||||||
.assignedToAsset(assignedToUnixUserAsset.getParentAsset())
|
.assignedToAsset(assignedToUnixUserAssetEntity.getParentAsset())
|
||||||
.identifier(getDomainName() + "|MBOX")
|
.identifier(getDomainName() + "|MBOX")
|
||||||
.caption("HTTP-Setup für " + IDN.toUnicode(getDomainName())))
|
.caption("MBOX-Setup für " + IDN.toUnicode(getDomainName())))
|
||||||
);
|
);
|
||||||
|
|
||||||
subHostingAssets.add(
|
subHostingAssets.add(
|
||||||
@ -87,9 +81,9 @@ public class DomainSetupHostingAssetFactory extends HostingAssetFactory {
|
|||||||
domainSetupAsset,
|
domainSetupAsset,
|
||||||
DOMAIN_SMTP_SETUP,
|
DOMAIN_SMTP_SETUP,
|
||||||
builder -> builder
|
builder -> builder
|
||||||
.assignedToAsset(assignedToUnixUserAsset.getParentAsset())
|
.assignedToAsset(assignedToUnixUserAssetEntity.getParentAsset())
|
||||||
.identifier(getDomainName() + "|SMTP")
|
.identifier(getDomainName() + "|SMTP")
|
||||||
.caption("HTTP-Setup für " + IDN.toUnicode(getDomainName())))
|
.caption("SMTP-Setup für " + IDN.toUnicode(getDomainName())))
|
||||||
);
|
);
|
||||||
|
|
||||||
return domainSetupAsset;
|
return domainSetupAsset;
|
||||||
@ -112,9 +106,7 @@ public class DomainSetupHostingAssetFactory extends HostingAssetFactory {
|
|||||||
final Function<HsHostingAssetRealEntity.HsHostingAssetRealEntityBuilder<?, ?>, HsHostingAssetRealEntity.HsHostingAssetRealEntityBuilder<?, ?>> builderTransformer) {
|
final Function<HsHostingAssetRealEntity.HsHostingAssetRealEntityBuilder<?, ?>, HsHostingAssetRealEntity.HsHostingAssetRealEntityBuilder<?, ?>> builderTransformer) {
|
||||||
final var resourceType = HsHostingAssetTypeResource.valueOf(subAssetType.name());
|
final var resourceType = HsHostingAssetTypeResource.valueOf(subAssetType.name());
|
||||||
|
|
||||||
final var subAssetResourceOptional = getSubHostingAssetResources().stream()
|
final var subAssetResourceOptional = findSubHostingAssetResource(resourceType);
|
||||||
.filter(ha -> ha.getType() == resourceType)
|
|
||||||
.reduce(Reducer::toSingleElement);
|
|
||||||
|
|
||||||
subAssetResourceOptional.ifPresentOrElse(
|
subAssetResourceOptional.ifPresentOrElse(
|
||||||
subAssetResource -> verifyNotOverspecified(subAssetResource),
|
subAssetResource -> verifyNotOverspecified(subAssetResource),
|
||||||
@ -128,6 +120,12 @@ public class DomainSetupHostingAssetFactory extends HostingAssetFactory {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Optional<HsHostingAssetSubInsertResource> findSubHostingAssetResource(final HsHostingAssetTypeResource resourceType) {
|
||||||
|
return getSubHostingAssetResources().stream()
|
||||||
|
.filter(ha -> ha.getType() == resourceType)
|
||||||
|
.reduce(Reducer::toSingleElement);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO.legacy: while we need to stay compatible, only default values can be used, thus only the type can be specified
|
// TODO.legacy: while we need to stay compatible, only default values can be used, thus only the type can be specified
|
||||||
private void verifyNotOverspecified(final HsHostingAssetSubInsertResource givenSubAssetResource) {
|
private void verifyNotOverspecified(final HsHostingAssetSubInsertResource givenSubAssetResource) {
|
||||||
final var convert = new ToStringConverter().ignoring("assignedToAssetUuid");
|
final var convert = new ToStringConverter().ignoring("assignedToAssetUuid");
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package net.hostsharing.hsadminng.hs.hosting.asset.factories;
|
package net.hostsharing.hsadminng.hs.hosting.asset.factories;
|
||||||
import net.hostsharing.hsadminng.mapper.Array;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
Loading…
Reference in New Issue
Block a user