collect validation errors during save

This commit is contained in:
Michael Hoennig 2024-08-08 06:42:19 +02:00
parent 6e5d51384b
commit 855c5e44b0

View File

@ -480,7 +480,7 @@ public class ImportHostingAssets extends ImportOfficeData {
}
private String vmName(final String zonenfileName) {
return zonenfileName.substring(zonenfileName.length()-"vm0000.json".length()).substring(0, 6);
return zonenfileName.substring(zonenfileName.length() - "vm0000.json".length()).substring(0, 6);
}
@Test
@ -783,22 +783,22 @@ public class ImportHostingAssets extends ImportOfficeData {
private void persistHostingAssetsOfType(final HsHostingAssetType... hsHostingAssetTypes) {
final var hsHostingAssetTypeSet = stream(hsHostingAssetTypes).collect(toSet());
// jpaAttempt.transacted(() -> {
hostingAssets.forEach((key, ha) -> {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
if (hsHostingAssetTypeSet.contains(ha.getType())) {
new HostingAssetEntitySaveProcessor(em, ha)
.preprocessEntity()
.validateEntityIgnoring("'EMAIL_ALIAS:.*\\.config\\.target' .*")
.prepareForSave()
.saveUsing(entity -> persist(key, entity))
.validateContext();
}
}).assertSuccessful();
}
);
// }).assertSuccessful();
logError(() ->
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
if (hsHostingAssetTypeSet.contains(ha.getType())) {
new HostingAssetEntitySaveProcessor(em, ha)
.preprocessEntity()
.validateEntityIgnoring("'EMAIL_ALIAS:.*\\.config\\.target' .*")
.prepareForSave()
.saveUsing(entity -> persist(key, entity))
.validateContext();
}
}).assertSuccessful()
);
});
}
private void importIpNumbers(final String[] header, final List<String[]> records) {
@ -1249,14 +1249,18 @@ public class ImportHostingAssets extends ImportOfficeData {
entry("multiviews", options.contains("multiviews")),
entry("subdomains", withDefault(rec.getString("valid_subdomain_names"), "*")
.split(",")),
entry("fcgi-php-bin", withDefault(rec.getString("fcgi_php_bin"),
httpDomainSetupValidator.getProperty("fcgi-php-bin").defaultValue() )),
entry("passenger-nodejs", withDefault(rec.getString("passenger_nodejs"),
httpDomainSetupValidator.getProperty("passenger-nodejs").defaultValue() )),
entry("passenger-python", withDefault(rec.getString("passenger_python"),
httpDomainSetupValidator.getProperty("passenger-python").defaultValue() )),
entry("passenger-ruby", withDefault(rec.getString("passenger_ruby"),
httpDomainSetupValidator.getProperty("passenger-ruby").defaultValue() ))
entry("fcgi-php-bin", withDefault(
rec.getString("fcgi_php_bin"),
httpDomainSetupValidator.getProperty("fcgi-php-bin").defaultValue())),
entry("passenger-nodejs", withDefault(
rec.getString("passenger_nodejs"),
httpDomainSetupValidator.getProperty("passenger-nodejs").defaultValue())),
entry("passenger-python", withDefault(
rec.getString("passenger_python"),
httpDomainSetupValidator.getProperty("passenger-python").defaultValue())),
entry("passenger-ruby", withDefault(
rec.getString("passenger_ruby"),
httpDomainSetupValidator.getProperty("passenger-ruby").defaultValue()))
))
.build();
hostingAssets.put(DOMAIN_HTTP_SETUP_OFFSET + domain_id, domainHttpSetupAsset);
@ -1304,7 +1308,9 @@ public class ImportHostingAssets extends ImportOfficeData {
if (defaultValue instanceof String defaultStringValue) {
return givenValue != null && !givenValue.isBlank() ? givenValue : defaultStringValue;
}
throw new RuntimeException("property default value expected to be of type string, but is of type " + defaultValue.getClass().getSimpleName());
throw new RuntimeException(
"property default value expected to be of type string, but is of type " + defaultValue.getClass()
.getSimpleName());
}
private void importZonefiles(final String vmName, final String zonenfilesJson) {
@ -1317,11 +1323,11 @@ public class ImportHostingAssets extends ImportOfficeData {
final Map<String, Map<String, Object>> zoneData = jsonMapper.readValue(zonenfilesJson, Map.class);
importZonenfile(vmName, zoneData);
} catch (JsonProcessingException e) {
throw new RuntimeException("cannot read zonefile JSON: '"+zonenfilesJson+"'", e);
throw new RuntimeException("cannot read zonefile JSON: '" + zonenfilesJson + "'", e);
}
}
private void importZonenfile( final String vmName, final Map<String, Map<String, Object>> zoneDataForVM) {
private void importZonenfile(final String vmName, final Map<String, Map<String, Object>> zoneDataForVM) {
zoneDataForVM.forEach((domainName, zoneData) -> {
final var domainAsset = domainSetupsByName.get(domainName);
if (domainAsset != null) {
@ -1336,8 +1342,8 @@ public class ImportHostingAssets extends ImportOfficeData {
.getAssignedToAsset();
final var domOwner = zoneData.remove("DOM_OWNER");
final var expectedDomOwner = domUser.getIdentifier();
if ( domOwner.equals(expectedDomOwner) ) {
logError( () -> assertThat(vmName).isEqualTo(domUser.getParentAsset().getParentAsset().getIdentifier() ));
if (domOwner.equals(expectedDomOwner)) {
logError(() -> assertThat(vmName).isEqualTo(domUser.getParentAsset().getParentAsset().getIdentifier()));
//noinspection unchecked
zoneData.put("user-RR", ((ArrayList<ArrayList<Object>>) zoneData.get("user-RR")).stream()
@ -1346,7 +1352,8 @@ public class ImportHostingAssets extends ImportOfficeData {
);
domainDnsSetupAsset.getConfig().putAll(zoneData);
} else {
logError("zonedata dom_owner of " + domainAsset.getIdentifier() + " is " + domOwner + " but expected to be " + expectedDomOwner);
logError("zonedata dom_owner of " + domainAsset.getIdentifier() + " is " + domOwner + " but expected to be "
+ expectedDomOwner);
}
}
});