|
|
|
@ -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); |
|
|
|
|
|
|
|
|
|
|
|
|