-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MID-8432: Fixed definition annotations in shallow clones
Annotations were not properly stored in shallow Transformable*Definitions and changes to annotations were made on underlying shared schema. This fix intruduces shallow definitions also for annotations.
- Loading branch information
1 parent
62be02f
commit 475a7c8
Showing
3 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
.../main/java/com/evolveum/midpoint/model/impl/schema/transform/TransformableDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2021 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
package com.evolveum.midpoint.model.impl.schema.transform; | ||
|
||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.xml.namespace.QName; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.evolveum.midpoint.prism.Definition; | ||
import com.evolveum.midpoint.prism.deleg.DefinitionDelegator; | ||
import com.evolveum.midpoint.prism.util.CloneUtil; | ||
|
||
public abstract class TransformableDefinition implements DefinitionDelegator { | ||
|
||
private enum NullObject { | ||
VALUE | ||
} | ||
private Map<QName, Object> annotations; | ||
|
||
public TransformableDefinition(Definition delegate) { | ||
if (delegate instanceof TransformableDefinition) { | ||
// Shallow copy overriden annotations | ||
Map<QName, Object> maybe = ((TransformableDefinition) delegate).annotationsOverrides(); | ||
if (maybe != null) { | ||
annotations = new HashMap<>(); | ||
annotations.putAll(maybe); | ||
} | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public <A> A getAnnotation(QName qname) { | ||
if (annotations != null) { | ||
Object maybe = annotations.get(qname); | ||
if (maybe != null) { | ||
// If we NullObject.VALUE it is actually null, we store it to hide original annotation | ||
// in parent item. | ||
return maybe != NullObject.VALUE ? (A) maybe : null; | ||
} | ||
} | ||
return DefinitionDelegator.super.getAnnotation(qname); | ||
} | ||
|
||
@Override | ||
public <A> void setAnnotation(QName qname, A value) { | ||
Object newVal = value != null ? value : NullObject.VALUE; | ||
if (annotations == null) { | ||
annotations = new HashMap<>(); | ||
} | ||
annotations.put(qname, newVal); | ||
} | ||
|
||
protected Map<QName, Object> annotationsOverrides() { | ||
return annotations; | ||
} | ||
|
||
@Override | ||
public Definition clone() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters