Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Kateryna Honchar committed Aug 17, 2022
2 parents 32098c2 + 1f37008 commit 93fd0ec
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.evolveum.midpoint.gui.impl.page.self.requestAccess;

import java.io.Serializable;
import java.util.Objects;

import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;

Expand All @@ -16,6 +17,8 @@
*/
public class Conflict implements Serializable {

private String shortMessage;

private ObjectReferenceType personOfInterest;

private ConflictItem added;
Expand All @@ -28,11 +31,14 @@ public class Conflict implements Serializable {

private boolean warning;

public Conflict(ObjectReferenceType personOfInterest, ConflictItem added, ConflictItem exclusion, String message, boolean warning) {
private ConflictItem toBeRemoved;

public Conflict(ObjectReferenceType personOfInterest, ConflictItem added, ConflictItem exclusion, String shortMessage, String message, boolean warning) {
this.personOfInterest = personOfInterest;
this.added = added;
this.exclusion = exclusion;
this.warning = warning;
this.shortMessage = shortMessage;
this.message = message;
}

Expand Down Expand Up @@ -63,4 +69,20 @@ public boolean isWarning() {
public String getMessage() {
return message;
}

public ConflictItem getToBeRemoved() {
return toBeRemoved;
}

public void setToBeRemoved(ConflictItem toBeRemoved) {
if (!Objects.equals(toBeRemoved, added) && !Objects.equals(toBeRemoved, exclusion)) {
return;
}

this.toBeRemoved = toBeRemoved;
}

public String getShortMessage() {
return shortMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;

import java.util.Objects;

/**
* Created by Viliam Repan (lazyman).
*/
Expand All @@ -51,30 +53,71 @@ public class ConflictItemPanel extends BasePanel<Conflict> {
private static final String ID_FORM = "form";
private static final String ID_TITLE = "title";

private IModel<ConflictItem> selectedOption = Model.of((ConflictItem) null);
private IModel<ConflictItem> selectedOption;

public ConflictItemPanel(String id, IModel<Conflict> model) {
super(id, model);

initModels();
initLayout();
}

private void initModels() {
selectedOption = new IModel<>() {

@Override
public ConflictItem getObject() {
Conflict conflict = getModelObject();
if (conflict.getToBeRemoved() == null) {
return null;
}

return Objects.equals(conflict.getToBeRemoved(), conflict.getAdded()) ?
conflict.getExclusion() :
conflict.getAdded();
}

@Override
public void setObject(ConflictItem toKeep) {
Conflict conflict = getModelObject();
if (toKeep == null) {
conflict.setToBeRemoved(null);
return;
}

ConflictItem toRemove = Objects.equals(toKeep, conflict.getAdded()) ?
conflict.getExclusion() :
conflict.getAdded();

conflict.setToBeRemoved(toRemove);
}
};
}

private void initLayout() {
add(AttributeAppender.append("class", "card conflict-item"));
add(AttributeAppender.append("class", () -> {
Conflict c = getModelObject();
switch (c.getState()) {
// case SKIPPED:
// return "conflict-item-secondary";
case SKIPPED:
return "conflict-item-secondary";
case SOLVED:
return "conflict-item-success";
}

return c.isWarning() ? "conflict-item-warning" : "conflict-item-danger";
}));

Label title = new Label(ID_TITLE, () -> getString("ConflictItemPanel.duplicationConflict",
WebComponentUtil.getName(getModelObject().getPersonOfInterest())));
Label title = new Label(ID_TITLE, () -> {
String poiName = WebComponentUtil.getName(getModelObject().getPersonOfInterest());

String shortMsg = getModelObject().getShortMessage();
if (shortMsg != null) {
return getString("ConflictItemPanel.conflictTitle", shortMsg, poiName);
}

return getString("ConflictItemPanel.defaultConflictTitle", poiName);
});
add(title);

BadgePanel badge = new BadgePanel(ID_BADGE, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.common.LocalizationService;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -449,13 +451,20 @@ private <F extends FocusType> void createConflicts(ObjectReferenceType userRef,
ConflictItem exclusion = new ConflictItem(conflictingAssignment.getAssignment(), WebComponentUtil.getDisplayNameOrName(exclusionTargetObj),
conflictingAssignment.getAssignment(true) != null);

MidPointApplication mp = MidPointApplication.get();
LocalizationService localizationService = mp.getLocalizationService();

String message = null;
if (trigger.getMessage() != null) {
MidPointApplication mp = MidPointApplication.get();
message = mp.getLocalizationService().translate(trigger.getMessage());
message = localizationService.translate(trigger.getMessage());
}

String shortMessage = null;
if (trigger.getShortMessage() != null) {
shortMessage = localizationService.translate(trigger.getShortMessage());
}

Conflict conflict = new Conflict(userRef, added, exclusion, message, warning);
Conflict conflict = new Conflict(userRef, added, exclusion, shortMessage, message, warning);

if (!conflicts.containsKey(key) && !conflicts.containsKey(alternateKey)) {
conflicts.put(key, conflict);
Expand Down Expand Up @@ -557,6 +566,7 @@ public void solveConflict(Conflict conflict, ConflictItem toRemove) {
assignments.remove(toRemove.getAssignment());

conflict.setState(ConflictState.SOLVED);
conflict.setToBeRemoved(toRemove);

markConflictsDirty();
}
Expand Down

0 comments on commit 93fd0ec

Please sign in to comment.