Search in sources :

Example 1 with IdentityStrategy

use of de.danielbechler.diff.identity.IdentityStrategy 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)

Aggregations

ObjectDifferBuilder (de.danielbechler.diff.ObjectDifferBuilder)1 IdentityStrategy (de.danielbechler.diff.identity.IdentityStrategy)1 DiffNode (de.danielbechler.diff.node.DiffNode)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 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)1 RelationshipTypeImplementationId (org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)1 RequirementTypeId (org.eclipse.winery.model.ids.definitions.RequirementTypeId)1 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)1