Skip to content

Commit

Permalink
Merge pull request 'Ticket #28304: Fehlende inkrementelle Änderung vo…
Browse files Browse the repository at this point in the history
…n "abstract"' (!577) from CWS/CWS_28304 into master

Reviewed-on: http://tl.bos.local:3000/TopLogic/tl-engine-7/pulls/577
Reviewed-by: jenkins <jenkins@top-logic.com>
Reviewed-by: Bernhard Haumacher <bernhard.haumacher@top-logic.com>
  • Loading branch information
dbusche committed Jan 10, 2025
2 parents 958e87c + f564377 commit 3357463
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,10 @@ com.top_logic.element.model.diff.config.RenamePart.part.tooltip = Der qualifizie
com.top_logic.element.model.diff.config.RenamePart.tooltip = Umbenennung eines <i>Modellteils</i>.
com.top_logic.element.model.diff.config.SetAnnotations = Annotationen festlegen
com.top_logic.element.model.diff.config.SetAnnotations.tooltip = Beschreibt die Einstellung von <i>Annotationen</i> zu einem <i>Modellteil</i>.
com.top_logic.element.model.diff.config.UpdateAbstract = Update abstrakt
com.top_logic.element.model.diff.config.UpdateAbstract.abstract = Abstrakt
com.top_logic.element.model.diff.config.UpdateAbstract.abstract.tooltip = Der neue abstrakte Zustand.
com.top_logic.element.model.diff.config.UpdateAbstract.tooltip = Aktualisierung des Zustands <code>abstract</code> eines <i>strukturierten Teils</i>.
com.top_logic.element.model.diff.config.UpdateBag = Update Tasche
com.top_logic.element.model.diff.config.UpdateBag.bag = Tasche
com.top_logic.element.model.diff.config.UpdateBag.bag.tooltip = Der neue Taschenzustand.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,10 @@ com.top_logic.element.model.diff.config.RenamePart.part.tooltip = The qualified
com.top_logic.element.model.diff.config.RenamePart.tooltip = Renaming of a <i>model part</i>.
com.top_logic.element.model.diff.config.SetAnnotations = Set annotations
com.top_logic.element.model.diff.config.SetAnnotations.tooltip = Describes the setting of <i>annotations</i> to a <i>model part</i>.
com.top_logic.element.model.diff.config.UpdateAbstract = Update abstract
com.top_logic.element.model.diff.config.UpdateAbstract.abstract = Abstract
com.top_logic.element.model.diff.config.UpdateAbstract.abstract.tooltip = The new abstract state.
com.top_logic.element.model.diff.config.UpdateAbstract.tooltip = Update of the <code>abstract</code> state of a <i>structured type part</i>.
com.top_logic.element.model.diff.config.UpdateBag = Update bag
com.top_logic.element.model.diff.config.UpdateBag.bag = Bag
com.top_logic.element.model.diff.config.UpdateBag.bag.tooltip = The new bag state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.top_logic.element.model.diff.config.RemoveGeneralization;
import com.top_logic.element.model.diff.config.RenamePart;
import com.top_logic.element.model.diff.config.SetAnnotations;
import com.top_logic.element.model.diff.config.UpdateAbstract;
import com.top_logic.element.model.diff.config.UpdateBag;
import com.top_logic.element.model.diff.config.UpdateMandatory;
import com.top_logic.element.model.diff.config.UpdateMultiplicity;
Expand Down Expand Up @@ -304,6 +305,11 @@ public Priority visit(UpdateOrdered diff, Void arg) throws RuntimeException {
return Priority.CHANGE_TYPE_PART_ORDERED;
}

@Override
public Priority visit(UpdateAbstract diff, Void arg) throws RuntimeException {
return Priority.CHANGE_TYPE_PART_ABSTRACT;
}

@Override
public Priority visit(UpdateBag diff, Void arg) throws RuntimeException {
return Priority.CHANGE_TYPE_PART_BAG;
Expand Down Expand Up @@ -1488,6 +1494,46 @@ public Void visit(UpdateBag diff, Void arg) throws RuntimeException {
return null;
}

@Override
public Void visit(UpdateAbstract diff, Void arg) throws RuntimeException {
TLStructuredTypePart part;
try {
part = (TLStructuredTypePart) resolveQName(diff.getPart());
} catch (TopLogicException ex) {
log().info(
"Merge conflict: Updating abstract state of '" + diff.getPart() + "' to '" + diff.isAbstract()
+ "', but part does not exist.",
Log.WARN);
return null;
}
log().info("Updating abstract state of '" + diff.getPart() + "' to '" + diff.isAbstract() + "'.");
part.setAbstract(diff.isAbstract());

if (createProcessors()) {
if (part instanceof TLProperty) {
UpdateTLPropertyProcessor.Config config = newConfigItem(UpdateTLPropertyProcessor.Config.class);
config.setName(qTypePartName(diff.getPart()));
config.setAbstract(diff.isAbstract());
addProcessor(config);
} else if (part instanceof TLReference) {
UpdateTLReferenceProcessor.Config config = newConfigItem(UpdateTLReferenceProcessor.Config.class);
config.setName(qTypePartName(diff.getPart()));
config.setAbstract(diff.isAbstract());
addProcessor(config);
} else if (part instanceof TLAssociationEnd) {
UpdateTLAssociationEndProcessor.Config config =
newConfigItem(UpdateTLAssociationEndProcessor.Config.class);
config.setName(qTypePartName(diff.getPart()));
config.setAbstract(diff.isAbstract());
addProcessor(config);
} else {
throw new UnsupportedOperationException("No update for '" + diff.getPart() + "' of type '"
+ part.getClass().getName() + "' possible.");
}
}
return null;
}

@Override
public Void visit(MoveClassifier diff, Void arg) throws RuntimeException {
TLClassifier moved;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ enum Priority {
*/
UPDATE_TYPE_PART_TYPE,

/**
* Change of {@link TLStructuredTypePart#isAbstract()}.
*/
CHANGE_TYPE_PART_ABSTRACT,

/**
* Change of {@link TLStructuredTypePart#isMandatory()}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.top_logic.element.model.diff.config.MoveStructuredTypePart;
import com.top_logic.element.model.diff.config.RemoveAnnotation;
import com.top_logic.element.model.diff.config.RemoveGeneralization;
import com.top_logic.element.model.diff.config.UpdateAbstract;
import com.top_logic.element.model.diff.config.RenamePart;
import com.top_logic.element.model.diff.config.UpdateBag;
import com.top_logic.element.model.diff.config.UpdateMandatory;
Expand Down Expand Up @@ -662,6 +663,14 @@ private void addPartChanges(TLStructuredTypePart left, TLStructuredTypePart righ
update.setMandatory(newMandatory);
addDiff(update);
}
boolean oldAbstract = left.isAbstract();
boolean newAbstract = right.isAbstract();
if (oldAbstract != newAbstract) {
UpdateAbstract update = TypedConfiguration.newConfigItem(UpdateAbstract.class);
update.setPart(TLModelUtil.qualifiedName(left));
update.setAbstract(newAbstract);
addDiff(update);
}
}

private boolean isEquivalent(TLType left, TLType right) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* SPDX-FileCopyrightText: 2024 (c) Business Operation Systems GmbH <info@top-logic.com>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-BOS-TopLogic-1.0
*/
package com.top_logic.element.model.diff.config;

import com.top_logic.basic.config.annotation.Label;
import com.top_logic.basic.config.annotation.TagName;
import com.top_logic.model.TLStructuredTypePart;

/**
* Update of the <code>abstract</code> state of a {@link TLStructuredTypePart}.
*
* @author <a href="mailto:daniel.busche@top-logic.com">Daniel Busche</a>
*/
@TagName("update-abstract")
@Label("Update abstract")
public interface UpdateAbstract extends PartUpdate {

/**
* The new {@link TLStructuredTypePart#isAbstract() abstract} state.
*/
boolean isAbstract();

/** @see #isAbstract() */
void setAbstract(boolean value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.top_logic.element.model.diff.config.RenamePart;
import com.top_logic.element.model.diff.config.SetAnnotations;
import com.top_logic.element.model.diff.config.UpdateBag;
import com.top_logic.element.model.diff.config.UpdateAbstract;
import com.top_logic.element.model.diff.config.UpdateMandatory;
import com.top_logic.element.model.diff.config.UpdateMultiplicity;
import com.top_logic.element.model.diff.config.UpdateOrdered;
Expand Down Expand Up @@ -104,6 +105,9 @@ public interface DiffVisitor<R, A, E extends Throwable> {
/** Visit case for {@link UpdateBag}. */
R visit(UpdateBag diff, A arg) throws E;

/** Visit case for {@link UpdateAbstract}. */
R visit(UpdateAbstract diff, A arg) throws E;

/** Visit case for {@link MoveClassifier}. */
R visit(MoveClassifier diff, A arg) throws E;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ public void testOverrideAbstract() {
assertFalse("Attribute override is not declared as 'abstract'.", ext2.getPartOrFail("b").isAbstract());
}

public void testMakeAttributeAbstract() {
TLModel model;
try (Transaction tx = kb().beginTransaction()) {
model = loadModel("test-make-abstract-left.model.xml");
tx.commit();
}
TLClass baseA = (TLClass) model.getModule("m0").getType("A");
TLClass baseB = (TLClass) model.getModule("m0").getType("B");
assertFalse(baseA.getPartOrFail("a").isAbstract());
assertFalse(baseB.getPartOrFail("a").isAbstract());

TLModel newModel = loadModelTransient("test-make-abstract-right.model.xml");
try (Transaction tx = kb().beginTransaction()) {
applyDiff(model, newModel);
tx.commit();
}

TLClass incrementedA = (TLClass) model.getModule("m0").getType("A");
TLClass incrementedB = (TLClass) model.getModule("m0").getType("B");
assertTrue(incrementedA.getPartOrFail("a").isAbstract());
assertFalse(incrementedB.getPartOrFail("a").isAbstract());
}

public static Test suite() {
return KBSetup.getSingleKBTest(TestOverrideAttributes.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>

<model>
<module name="m0">
<datatype name="D"
db_type="varchar"
kind="String"
>
<storage-mapping class="com.top_logic.element.meta.kbbased.storage.mappings.DirectMapping"
application-type="java.lang.String"
/>
</datatype>

<class name="A">
<attributes>
<property name="a"
type="D"
/>
</attributes>
</class>

<class name="B">
<generalizations>
<generalization type="A"/>
</generalizations>
</class>
</module>
</model>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>

<model>
<module name="m0">
<datatype name="D"
db_type="varchar"
kind="String"
>
<storage-mapping class="com.top_logic.element.meta.kbbased.storage.mappings.DirectMapping"
application-type="java.lang.String"
/>
</datatype>

<class name="A">
<attributes>
<property name="a"
abstract="true"
type="D"
/>
</attributes>
</class>

<class name="B">
<attributes>
<property name="a"
override="true"
type="D"
/>
</attributes>
<generalizations>
<generalization type="A"/>
</generalizations>
</class>
</module>
</model>

0 comments on commit 3357463

Please sign in to comment.