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);
|
CompareResult compareResult = compare(ctx, exportData, prepared, existingEntity);
|
||||||
|
|
||||||
if (compareResult.isNeedUpdate()) {
|
if (compareResult.isUpdateNeeded()) {
|
||||||
E savedEntity = saveOrUpdate(ctx, prepared, exportData, idProvider, compareResult);
|
E savedEntity = saveOrUpdate(ctx, prepared, exportData, idProvider, compareResult);
|
||||||
boolean created = existingEntity == null;
|
boolean created = existingEntity == null;
|
||||||
importResult.setCreated(created);
|
importResult.setCreated(created);
|
||||||
@ -142,8 +142,12 @@ public abstract class BaseEntityImportService<I extends EntityId, E extends Expo
|
|||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
protected static class CompareResult {
|
protected static class CompareResult {
|
||||||
private boolean needUpdate;
|
private boolean updateNeeded;
|
||||||
private boolean externalIdChangedOnly;
|
private boolean externalIdChangedOnly;
|
||||||
|
|
||||||
|
public CompareResult(boolean updateNeeded) {
|
||||||
|
this.updateNeeded = updateNeeded;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean updateRelatedEntitiesIfUnmodified(EntitiesImportCtx ctx, E prepared, D exportData, IdProvider idProvider) {
|
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);
|
var existingCopy = deepCopy(existing);
|
||||||
cleanupForComparison(newCopy);
|
cleanupForComparison(newCopy);
|
||||||
cleanupForComparison(existingCopy);
|
cleanupForComparison(existingCopy);
|
||||||
var needUpdate = !newCopy.equals(existingCopy);
|
var entityChanged = !newCopy.equals(existingCopy);
|
||||||
boolean externalIdChangedOnly = false;
|
boolean externalIdChangedOnly = false;
|
||||||
if (needUpdate) {
|
if (entityChanged) {
|
||||||
log.debug("[{}] Found update.", prepared.getId());
|
log.debug("[{}] Found update.", prepared.getId());
|
||||||
log.debug("[{}] From: {}", prepared.getId(), newCopy);
|
log.debug("[{}] From: {}", prepared.getId(), newCopy);
|
||||||
log.debug("[{}] To: {}", prepared.getId(), existingCopy);
|
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);
|
return new CompareResult(existing == null || entityChanged, externalIdChangedOnly);
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isExternalIdChangedOnly(E newCopy, E existingCopy) {
|
|
||||||
newCopy.setExternalId(null);
|
|
||||||
existingCopy.setExternalId(null);
|
|
||||||
return newCopy.equals(existingCopy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract E deepCopy(E e);
|
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);
|
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
|
@Override
|
||||||
protected CompareResult compare(EntitiesImportCtx ctx, EntityExportData<Dashboard> exportData, Dashboard prepared, Dashboard existing) {
|
protected CompareResult compare(EntitiesImportCtx ctx, EntityExportData<Dashboard> exportData, Dashboard prepared, Dashboard existing) {
|
||||||
CompareResult result = super.compare(ctx, exportData, prepared, 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -117,11 +117,11 @@ public class RuleChainImportService extends BaseEntityImportService<RuleChainId,
|
|||||||
@Override
|
@Override
|
||||||
protected CompareResult compare(EntitiesImportCtx ctx, RuleChainExportData exportData, RuleChain prepared, RuleChain existing) {
|
protected CompareResult compare(EntitiesImportCtx ctx, RuleChainExportData exportData, RuleChain prepared, RuleChain existing) {
|
||||||
CompareResult result = super.compare(ctx, exportData, prepared, existing);
|
CompareResult result = super.compare(ctx, exportData, prepared, existing);
|
||||||
if (!result.isNeedUpdate()) {
|
if (!result.isUpdateNeeded()) {
|
||||||
RuleChainMetaData newMD = exportData.getMetaData();
|
RuleChainMetaData newMD = exportData.getMetaData();
|
||||||
RuleChainMetaData existingMD = ruleChainService.loadRuleChainMetaData(ctx.getTenantId(), prepared.getId());
|
RuleChainMetaData existingMD = ruleChainService.loadRuleChainMetaData(ctx.getTenantId(), prepared.getId());
|
||||||
existingMD.setRuleChainId(null);
|
existingMD.setRuleChainId(null);
|
||||||
result.setNeedUpdate(!newMD.equals(existingMD));
|
result.setUpdateNeeded(!newMD.equals(existingMD));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ public class WidgetTypeImportService extends BaseEntityImportService<WidgetTypeI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CompareResult compare(EntitiesImportCtx ctx, WidgetTypeExportData exportData, WidgetTypeDetails prepared, WidgetTypeDetails existing) {
|
protected CompareResult compare(EntitiesImportCtx ctx, WidgetTypeExportData exportData, WidgetTypeDetails prepared, WidgetTypeDetails existing) {
|
||||||
return new CompareResult(true, false);
|
return new CompareResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -76,7 +76,7 @@ public class WidgetsBundleImportService extends BaseEntityImportService<WidgetsB
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CompareResult compare(EntitiesImportCtx ctx, WidgetsBundleExportData exportData, WidgetsBundle prepared, WidgetsBundle existing) {
|
protected CompareResult compare(EntitiesImportCtx ctx, WidgetsBundleExportData exportData, WidgetsBundle prepared, WidgetsBundle existing) {
|
||||||
return new CompareResult(true, false);
|
return new CompareResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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