Version control - not rollback on error option
This commit is contained in:
parent
92cd231034
commit
eb50685108
@ -101,7 +101,11 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
|
||||
ctx.putInternalId(exportData.getExternalId(), importResult.getSavedEntity().getId());
|
||||
|
||||
ctx.addReferenceCallback(exportData.getExternalId(), importResult.getSaveReferencesCallback());
|
||||
ctx.addEventCallback(importResult.getSendEventsCallback());
|
||||
if (ctx.isRollbackOnError()) {
|
||||
ctx.addEventCallback(importResult.getSendEventsCallback());
|
||||
} else {
|
||||
importResult.getSendEventsCallback().run();
|
||||
}
|
||||
return importResult;
|
||||
}
|
||||
|
||||
|
||||
@ -246,16 +246,18 @@ public class DefaultEntitiesVersionControlService implements EntitiesVersionCont
|
||||
switch (request.getType()) {
|
||||
case SINGLE_ENTITY: {
|
||||
SingleEntityVersionLoadRequest versionLoadRequest = (SingleEntityVersionLoadRequest) request;
|
||||
ctx.setRollbackOnError(true);
|
||||
VersionLoadConfig config = versionLoadRequest.getConfig();
|
||||
ListenableFuture<EntityExportData> future = gitServiceQueue.getEntity(user.getTenantId(), request.getVersionId(), versionLoadRequest.getExternalEntityId());
|
||||
DonAsynchron.withCallback(future,
|
||||
entityData -> doInTemplate(ctx, request, c -> loadSingleEntity(c, config, entityData)),
|
||||
entityData -> load(ctx, request, c -> loadSingleEntity(c, config, entityData)),
|
||||
e -> processLoadError(ctx, e), executor);
|
||||
break;
|
||||
}
|
||||
case ENTITY_TYPE: {
|
||||
EntityTypeVersionLoadRequest versionLoadRequest = (EntityTypeVersionLoadRequest) request;
|
||||
executor.submit(() -> doInTemplate(ctx, request, c -> loadMultipleEntities(c, versionLoadRequest)));
|
||||
ctx.setRollbackOnError(versionLoadRequest.isRollbackOnError());
|
||||
executor.submit(() -> load(ctx, request, c -> loadMultipleEntities(c, versionLoadRequest)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -265,19 +267,24 @@ public class DefaultEntitiesVersionControlService implements EntitiesVersionCont
|
||||
return ctx.getRequestId();
|
||||
}
|
||||
|
||||
private <R> VersionLoadResult doInTemplate(EntitiesImportCtx ctx, VersionLoadRequest request, Function<EntitiesImportCtx, VersionLoadResult> function) {
|
||||
private <R> VersionLoadResult load(EntitiesImportCtx ctx, VersionLoadRequest request, Function<EntitiesImportCtx, VersionLoadResult> loadFunction) {
|
||||
try {
|
||||
VersionLoadResult result = transactionTemplate.execute(status -> {
|
||||
try {
|
||||
return function.apply(ctx);
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e); // to prevent UndeclaredThrowableException
|
||||
VersionLoadResult result;
|
||||
if (ctx.isRollbackOnError()) {
|
||||
result = transactionTemplate.execute(status -> {
|
||||
try {
|
||||
return loadFunction.apply(ctx);
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e); // to prevent UndeclaredThrowableException
|
||||
}
|
||||
});
|
||||
for (ThrowingRunnable eventCallback : ctx.getEventCallbacks()) {
|
||||
eventCallback.run();
|
||||
}
|
||||
});
|
||||
for (ThrowingRunnable throwingRunnable : ctx.getEventCallbacks()) {
|
||||
throwingRunnable.run();
|
||||
} else {
|
||||
result = loadFunction.apply(ctx);
|
||||
}
|
||||
result.setDone(true);
|
||||
return cachePut(ctx.getRequestId(), result);
|
||||
|
||||
@ -58,6 +58,7 @@ public class EntitiesImportCtx {
|
||||
private boolean finalImportAttempt = false;
|
||||
private EntityImportSettings settings;
|
||||
private EntityImportResult<?> currentImportResult;
|
||||
private boolean rollbackOnError;
|
||||
|
||||
public EntitiesImportCtx(UUID requestId, User user, String versionId) {
|
||||
this(requestId, user, versionId, null);
|
||||
|
||||
@ -26,6 +26,7 @@ import java.util.Map;
|
||||
public class EntityTypeVersionLoadRequest extends VersionLoadRequest {
|
||||
|
||||
private Map<EntityType, EntityTypeVersionLoadConfig> entityTypes;
|
||||
private boolean rollbackOnError;
|
||||
|
||||
@Override
|
||||
public VersionLoadRequestType getType() {
|
||||
|
||||
@ -99,3 +99,8 @@
|
||||
</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div [formGroup]="entityTypesVersionLoadFormGroup" fxLayout="row">
|
||||
<mat-checkbox formControlName="rollbackOnError">
|
||||
{{ 'version-control.rollback-on-error' | translate }}
|
||||
</mat-checkbox>
|
||||
</div>
|
||||
|
||||
@ -4915,7 +4915,9 @@
|
||||
"device-credentials-conflict": "Failed to load the device with external id <b>{{entityId}}</b><br/>due to the same credentials are already present in the database for another device.<br/>Please consider disabling the <b>load credentials</b> setting in the restore form.",
|
||||
"missing-referenced-entity": "Failed to load the <b>{{sourceEntityTypeName}}</b> with external id <b>{{sourceEntityId}}</b><br/>because it references missing <b>{{targetEntityTypeName}}</b> with id <b>{{targetEntityId}}</b>.",
|
||||
"runtime-failed": "<b>Failed:</b> {{message}}",
|
||||
"auto-commit-settings-read-only-hint": "Auto-commit feature doesn't work with enabled read-only option in Repository settings."
|
||||
"auto-commit-settings-read-only-hint": "Auto-commit feature doesn't work with enabled read-only option in Repository settings.",
|
||||
"rollback-on-error": "Rollback on error",
|
||||
"rollback-on-error-hint": "If you have a large amount of entities to restore, consider disabling this option to increase performance.<br><b>Note</b>, if an error occurs over the course of version loading, already persisted entities (with relations, attributes, etc.) will stay as is"
|
||||
},
|
||||
"widget": {
|
||||
"widget-library": "Widgets library",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user