Search in sources :

Example 1 with DiffNode

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);
}
Also used : DiffNode(de.danielbechler.diff.node.DiffNode)

Example 2 with DiffNode

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);
}
Also used : IdentityStrategy(de.danielbechler.diff.identity.IdentityStrategy) ObjectDifferBuilder(de.danielbechler.diff.ObjectDifferBuilder) HasIdInIdOrNameField(org.eclipse.winery.model.tosca.HasIdInIdOrNameField) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) Objects(java.util.Objects) DiffNode(de.danielbechler.diff.node.DiffNode) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Matcher(java.util.regex.Matcher) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) VersionUtils(org.eclipse.winery.common.version.VersionUtils) IdentityStrategy(de.danielbechler.diff.identity.IdentityStrategy) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) QName(javax.xml.namespace.QName) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) HasIdInIdOrNameField(org.eclipse.winery.model.tosca.HasIdInIdOrNameField) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) DiffNode(de.danielbechler.diff.node.DiffNode)

Example 3 with DiffNode

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;
}
Also used : Request(cern.modesti.request.Request) DiffNode(de.danielbechler.diff.node.DiffNode) Point(cern.modesti.point.Point) DateTime(org.joda.time.DateTime) RequestImpl(cern.modesti.request.RequestImpl) ObjectDiffer(de.danielbechler.diff.ObjectDiffer)

Aggregations

DiffNode (de.danielbechler.diff.node.DiffNode)3 Point (cern.modesti.point.Point)1 Request (cern.modesti.request.Request)1 RequestImpl (cern.modesti.request.RequestImpl)1 ObjectDiffer (de.danielbechler.diff.ObjectDiffer)1 ObjectDifferBuilder (de.danielbechler.diff.ObjectDifferBuilder)1 IdentityStrategy (de.danielbechler.diff.identity.IdentityStrategy)1 Objects (java.util.Objects)1 Matcher (java.util.regex.Matcher)1 QName (javax.xml.namespace.QName)1 VersionUtils (org.eclipse.winery.common.version.VersionUtils)1 WineryVersion (org.eclipse.winery.common.version.WineryVersion)1 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)1 ArtifactTypeId (org.eclipse.winery.model.ids.definitions.ArtifactTypeId)1 CapabilityTypeId (org.eclipse.winery.model.ids.definitions.CapabilityTypeId)1 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)1 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)1 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)1 PolicyTemplateId (org.eclipse.winery.model.ids.definitions.PolicyTemplateId)1 PolicyTypeId (org.eclipse.winery.model.ids.definitions.PolicyTypeId)1