refactoring
This commit is contained in:
parent
29e9a3d122
commit
e1dfa3f803
@ -121,7 +121,7 @@ public abstract class BaseEntityImportService<I extends EntityId, E extends Expo
|
||||
|
||||
CompareResult compareResult = compare(ctx, exportData, prepared, existingEntity);
|
||||
|
||||
if (compareResult.isNeedUpdate()) {
|
||||
if (compareResult.isUpdateNeeded()) {
|
||||
E savedEntity = saveOrUpdate(ctx, prepared, exportData, idProvider, compareResult);
|
||||
boolean created = existingEntity == null;
|
||||
importResult.setCreated(created);
|
||||
@ -142,8 +142,12 @@ public abstract class BaseEntityImportService<I extends EntityId, E extends Expo
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
protected static class CompareResult {
|
||||
private boolean needUpdate;
|
||||
private boolean updateNeeded;
|
||||
private boolean externalIdChangedOnly;
|
||||
|
||||
public CompareResult(boolean updateNeeded) {
|
||||
this.updateNeeded = updateNeeded;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean updateRelatedEntitiesIfUnmodified(EntitiesImportCtx ctx, E prepared, D exportData, IdProvider idProvider) {
|
||||
@ -162,21 +166,17 @@ public abstract class BaseEntityImportService<I extends EntityId, E extends Expo
|
||||
var existingCopy = deepCopy(existing);
|
||||
cleanupForComparison(newCopy);
|
||||
cleanupForComparison(existingCopy);
|
||||
var needUpdate = !newCopy.equals(existingCopy);
|
||||
var entityChanged = !newCopy.equals(existingCopy);
|
||||
boolean externalIdChangedOnly = false;
|
||||
if (needUpdate) {
|
||||
if (entityChanged) {
|
||||
log.debug("[{}] Found update.", prepared.getId());
|
||||
log.debug("[{}] From: {}", prepared.getId(), newCopy);
|
||||
log.debug("[{}] To: {}", prepared.getId(), existingCopy);
|
||||
externalIdChangedOnly = isExternalIdChangedOnly(newCopy, existingCopy);
|
||||
cleanupExternalId(newCopy);
|
||||
cleanupExternalId(existingCopy);
|
||||
externalIdChangedOnly = newCopy.equals(existingCopy);
|
||||
}
|
||||
return new CompareResult(existing == null || needUpdate, externalIdChangedOnly);
|
||||
}
|
||||
|
||||
private boolean isExternalIdChangedOnly(E newCopy, E existingCopy) {
|
||||
newCopy.setExternalId(null);
|
||||
existingCopy.setExternalId(null);
|
||||
return newCopy.equals(existingCopy);
|
||||
return new CompareResult(existing == null || entityChanged, externalIdChangedOnly);
|
||||
}
|
||||
|
||||
protected abstract E deepCopy(E e);
|
||||
@ -189,6 +189,10 @@ public abstract class BaseEntityImportService<I extends EntityId, E extends Expo
|
||||
}
|
||||
}
|
||||
|
||||
protected void cleanupExternalId(E e) {
|
||||
e.setExternalId(null);
|
||||
}
|
||||
|
||||
protected abstract E saveOrUpdate(EntitiesImportCtx ctx, E entity, D exportData, IdProvider idProvider, CompareResult compareResult);
|
||||
|
||||
|
||||
|
||||
@ -118,7 +118,7 @@ public class DashboardImportService extends BaseEntityImportService<DashboardId,
|
||||
@Override
|
||||
protected CompareResult compare(EntitiesImportCtx ctx, EntityExportData<Dashboard> exportData, Dashboard prepared, Dashboard existing) {
|
||||
CompareResult result = super.compare(ctx, exportData, prepared, existing);
|
||||
result.setNeedUpdate(result.isNeedUpdate() || !prepared.getConfiguration().equals(existing.getConfiguration()));
|
||||
result.setUpdateNeeded(result.isUpdateNeeded() || !prepared.getConfiguration().equals(existing.getConfiguration()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -117,11 +117,11 @@ public class RuleChainImportService extends BaseEntityImportService<RuleChainId,
|
||||
@Override
|
||||
protected CompareResult compare(EntitiesImportCtx ctx, RuleChainExportData exportData, RuleChain prepared, RuleChain existing) {
|
||||
CompareResult result = super.compare(ctx, exportData, prepared, existing);
|
||||
if (!result.isNeedUpdate()) {
|
||||
if (!result.isUpdateNeeded()) {
|
||||
RuleChainMetaData newMD = exportData.getMetaData();
|
||||
RuleChainMetaData existingMD = ruleChainService.loadRuleChainMetaData(ctx.getTenantId(), prepared.getId());
|
||||
existingMD.setRuleChainId(null);
|
||||
result.setNeedUpdate(!newMD.equals(existingMD));
|
||||
result.setUpdateNeeded(!newMD.equals(existingMD));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ public class WidgetTypeImportService extends BaseEntityImportService<WidgetTypeI
|
||||
|
||||
@Override
|
||||
protected CompareResult compare(EntitiesImportCtx ctx, WidgetTypeExportData exportData, WidgetTypeDetails prepared, WidgetTypeDetails existing) {
|
||||
return new CompareResult(true, false);
|
||||
return new CompareResult(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -76,7 +76,7 @@ public class WidgetsBundleImportService extends BaseEntityImportService<WidgetsB
|
||||
|
||||
@Override
|
||||
protected CompareResult compare(EntitiesImportCtx ctx, WidgetsBundleExportData exportData, WidgetsBundle prepared, WidgetsBundle existing) {
|
||||
return new CompareResult(true, false);
|
||||
return new CompareResult(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user