-
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.
delta viewer, password/value change now "simplified"
- Loading branch information
Showing
4 changed files
with
99 additions
and
9 deletions.
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
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
77 changes: 77 additions & 0 deletions
77
...src/main/java/com/evolveum/midpoint/model/impl/visualizer/PasswordDescriptionHandler.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,77 @@ | ||
/* | ||
* Copyright (c) 2010-2023 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.visualizer; | ||
|
||
import com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import com.evolveum.midpoint.model.impl.visualizer.output.VisualizationDeltaItemImpl; | ||
import com.evolveum.midpoint.model.impl.visualizer.output.VisualizationImpl; | ||
import com.evolveum.midpoint.model.impl.visualizer.output.VisualizationItemImpl; | ||
import com.evolveum.midpoint.prism.PrismContainerValue; | ||
import com.evolveum.midpoint.prism.delta.ChangeType; | ||
import com.evolveum.midpoint.prism.path.ItemPath; | ||
import com.evolveum.midpoint.schema.result.OperationResult; | ||
import com.evolveum.midpoint.task.api.Task; | ||
import com.evolveum.midpoint.util.SingleLocalizableMessage; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType; | ||
|
||
/** | ||
* Created by Viliam Repan (lazyman). | ||
*/ | ||
@Component | ||
public class PasswordDescriptionHandler implements VisualizationDescriptionHandler { | ||
|
||
@Override | ||
public boolean match(VisualizationImpl visualization) { | ||
PrismContainerValue value = visualization.getSourceValue(); | ||
if (value == null) { | ||
return false; | ||
} | ||
|
||
if (value.asContainerable() instanceof CredentialsType) { | ||
// if there's password | ||
return value.findContainer(CredentialsType.F_PASSWORD) != null; | ||
} | ||
|
||
if (ItemPath.create(FocusType.F_CREDENTIALS, CredentialsType.F_PASSWORD).equivalent(value.getPath())) { | ||
// we're modifying/deleting password | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public void apply(VisualizationImpl visualization, Task task, OperationResult result) { | ||
ChangeType change = visualization.getChangeType(); | ||
|
||
VisualizationItemImpl item = visualization.getItems().stream() | ||
.filter(i -> { | ||
ItemPath path = i.getSourceRelPath(); | ||
return path != null && PasswordType.F_VALUE.equivalent(path.namedSegmentsOnly()); | ||
}).findFirst().orElse(null); | ||
|
||
if (item instanceof VisualizationDeltaItemImpl) { | ||
VisualizationDeltaItemImpl deltaItem = (VisualizationDeltaItemImpl) item; | ||
if (!deltaItem.getDeletedValues().isEmpty()) { | ||
change = deltaItem.getAddedValues().isEmpty() ? ChangeType.DELETE : ChangeType.MODIFY; | ||
} else { | ||
change = ChangeType.ADD; | ||
} | ||
} | ||
|
||
visualization.getName().setSimpleDescription( | ||
new SingleLocalizableMessage("PasswordDescriptionHandler.password", new Object[] { | ||
new SingleLocalizableMessage("PasswordDescriptionHandler.changeType." + change.name()) | ||
}) | ||
); | ||
} | ||
} |
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