use of de.danielbechler.diff.node.DiffNode in project alf.io by alfio-event.
the class TicketReservationManager method auditUpdateTicket.
private void auditUpdateTicket(Ticket preUpdateTicket, Map<String, String> preUpdateTicketFields, Ticket postUpdateTicket, Map<String, String> postUpdateTicketFields, int eventId) {
DiffNode diffTicket = ObjectDifferBuilder.buildDefault().compare(postUpdateTicket, preUpdateTicket);
DiffNode diffTicketFields = ObjectDifferBuilder.buildDefault().compare(postUpdateTicketFields, preUpdateTicketFields);
FieldChangesSaver diffTicketVisitor = new FieldChangesSaver(preUpdateTicket, postUpdateTicket);
FieldChangesSaver diffTicketFieldsVisitor = new FieldChangesSaver(preUpdateTicketFields, postUpdateTicketFields);
diffTicket.visit(diffTicketVisitor);
diffTicketFields.visit(diffTicketFieldsVisitor);
List<Map<String, Object>> changes = new ArrayList<>(diffTicketVisitor.changes);
changes.addAll(diffTicketFieldsVisitor.changes);
auditingRepository.insert(preUpdateTicket.getTicketsReservationId(), null, eventId, Audit.EventType.UPDATE_TICKET, new Date(), Audit.EntityType.TICKET, Integer.toString(preUpdateTicket.getId()), changes);
}
use of de.danielbechler.diff.node.DiffNode in project winery by eclipse.
the class VersionSupport method calculateDifferences.
public static <T extends TExtensibleElements> ToscaDiff calculateDifferences(T oldVersion, T newVersion) {
IdentityStrategy identityStrategy = (o, o1) -> {
if (o instanceof HasIdInIdOrNameField && o1 instanceof HasIdInIdOrNameField) {
return Objects.equals(((HasIdInIdOrNameField) o).getIdFromIdOrNameField(), ((HasIdInIdOrNameField) o1).getIdFromIdOrNameField());
} else {
return Objects.equals(o, o1);
}
};
DiffNode diffNode = ObjectDifferBuilder.startBuilding().categories().ofType(TRelationshipTemplate.SourceOrTargetElement.class).toBe(REFERENCING_OBJECT).and().inclusion().exclude().propertyName("nodeTemplateOrRelationshipTemplate").propertyName("fakeJacksonType").propertyName("any").propertyName("internalAny").propertyName("prefix").propertyName("elementName").propertyName("namespace").category(REFERENCING_OBJECT).and().identity().setDefaultCollectionItemIdentityStrategy(identityStrategy).and().build().compare(newVersion, oldVersion);
return ToscaDiff.convertDiffToToscaDiff(diffNode, oldVersion, newVersion);
}
use of de.danielbechler.diff.node.DiffNode in project modesti by jlsalmon.
the class RequestDiffer method diff.
public static ChangeEvent diff(Request modified, Request original, String idProperty) {
List<Point> originalPointsStillPresentCurrently = deleteRemovedPoints(original.getPoints(), modified.getPoints(), idProperty);
original.setPoints(originalPointsStillPresentCurrently);
ChangeEvent event = new ChangeEvent(new DateTime(DateTimeZone.UTC));
Request modifiedClone = new RequestImpl();
Request originalClone = new RequestImpl();
ChangeVisitor visitor = new ChangeVisitor(event, modifiedClone, originalClone);
Map<Object, Point> modifiedPointMap = getPointsMap(modified.getPoints(), idProperty);
for (Point originalPoint : original.getPoints()) {
Point modifiedPoint = modifiedPointMap.get(originalPoint.getValueByPropertyName(idProperty));
originalClone.setPoints(Arrays.asList((Point[]) new Point[] { originalPoint }));
if (modifiedPoint != null) {
modifiedClone.setPoints(Arrays.asList((Point[]) new Point[] { modifiedPoint }));
}
ObjectDiffer differ = ObjectDifferBuilder.startBuilding().identity().ofCollectionItems(NodePath.with("points")).via(new PointIdentityStrategy(idProperty)).and().build();
DiffNode root = differ.compare(modifiedClone, originalClone);
if (root.hasChanges()) {
root.visit(visitor);
}
}
return event;
}
Aggregations