Skip to content

Commit

Permalink
MID-7976 conflicts "done" panel ready for use, multiuser conflicts co…
Browse files Browse the repository at this point in the history
…mputation
  • Loading branch information
1azyman committed Jun 23, 2022
1 parent 27c33fb commit 2975de7
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div class="d-flex flex-column gap-3">
<div class="card conflict-item conflict-item-success" wicket:id="doneCard">
<div class="card-body">
<div class="d-flex gap-2 border-bottom border-gray align-items-center pb-3 mb-3">
<h5 class="mb-0"><wicket:message key="ConflictSolverPanel.doneAllTitle"/></h5>
</div>

<wicket:message key="ConflictSolverPanel.doneMessage"/>

<div class="main-button-bar mt-4">
<a class="btn btn-success" wicket:id="backToSummary">
<i class="fas fa-cart-shopping mr-1"></i>
<wicket:message key="ConflictSolverPanel.doneBack"/>
</a>
</div>
</div>
</div>

<div class="align-self-start" wicket:id="toggle"/>

<wicket:container wicket:id="items">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.stream.Collectors;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
Expand All @@ -22,6 +24,7 @@
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.component.Toggle;
import com.evolveum.midpoint.gui.api.component.TogglePanel;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;

/**
* Created by Viliam Repan (lazyman).
Expand All @@ -30,6 +33,8 @@ public class ConflictSolverPanel extends BasePanel<RequestAccess> {

private static final long serialVersionUID = 1L;

private static final String ID_DONE_CARD = "doneCard";
private static final String ID_BACK_TO_SUMMARY = "backToSummary";
private static final String ID_TOGGLE = "toggle";
private static final String ID_ITEMS = "items";
private static final String ID_ITEM = "item";
Expand All @@ -44,6 +49,19 @@ public ConflictSolverPanel(String id, IModel<RequestAccess> model) {

private void initLayout() {
setOutputMarkupId(true);

WebMarkupContainer doneCard = new WebMarkupContainer(ID_DONE_CARD);
doneCard.add(new VisibleBehaviour(() -> true)); // todo fix
add(doneCard);

AjaxLink backToSummary = new AjaxLink<>(ID_BACK_TO_SUMMARY) {
@Override
public void onClick(AjaxRequestTarget target) {
backToSummaryPerformed(target);
}
};
doneCard.add(backToSummary);

IModel<List<Toggle<ConflictState>>> toggleModel = () -> {
List<Toggle<ConflictState>> list = new ArrayList<>();

Expand All @@ -60,6 +78,9 @@ private void initLayout() {
case SOLVED:
badgeCss = Badge.State.SUCCESS.getCss();
break;
case SKIPPED:
badgeCss = Badge.State.PRIMARY.getCss();
break;
}

long count = getModelObject().getConflicts().stream().filter(c -> cs.equals(c.getState())).count();
Expand Down Expand Up @@ -134,4 +155,8 @@ private void solveConflictPerformed(AjaxRequestTarget target, IModel<Conflict> c

target.add(this);
}

private void backToSummaryPerformed(AjaxRequestTarget target) {
// todo implement
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
* Created by Viliam Repan (lazyman).
*/
public enum ConflictState {
UNRESOLVED, SOLVED;//, SKIPPED
UNRESOLVED, SOLVED, SKIPPED
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;

import org.apache.commons.lang3.StringUtils;

import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.api.context.*;
Expand Down Expand Up @@ -48,6 +47,10 @@ public class RequestAccess implements Serializable {

private static final Trace LOGGER = TraceManager.getTrace(RequestAccess.class);

private static final String DOT_CLASS = RequestAccess.class.getName() + ".";
private static final String OPERATION_COMPUTE_ALL_CONFLICTS = DOT_CLASS + "computeAllConflicts";
private static final String OPERATION_COMPUTE_CONFLICT = DOT_CLASS + "computeConflicts";

private Map<ObjectReferenceType, List<AssignmentType>> requestItems = new HashMap<>();

private Map<ObjectReferenceType, List<AssignmentType>> requestItemsExistingToRemove = new HashMap<>();
Expand Down Expand Up @@ -257,13 +260,41 @@ public void computeConflicts(PageBase page) {
return;
}

MidPointApplication mp = MidPointApplication.get();

Task task = page.createSimpleTask("computeConflicts");
OperationResult result = task.getResult();

List<Conflict> allConflicts = new ArrayList<>();
for (ObjectReferenceType ref : getPersonOfInterest()) {
List<Conflict> conflicts = computeConflictsForOnePerson(ref, task, page);
allConflicts.addAll(conflicts);
}

result.computeStatusIfUnknown();
if (!WebComponentUtil.isSuccessOrHandledError(result)) {
page.error(result);
}

this.conflicts = allConflicts;
conflictsDirty = false;
}

private ObjectReferenceType createRef(PrismObject object) {
if (object == null) {
return null;
}

ObjectType obj = (ObjectType) object.asObjectable();

return new ObjectReferenceType()
.oid(object.getOid())
.type(ObjectTypes.getObjectType(obj.getClass()).getTypeQName())
.targetName(obj.getName());
}

public List<Conflict> computeConflictsForOnePerson(ObjectReferenceType ref, Task task, PageBase page) {
OperationResult result = task.getResult().createSubresult(OPERATION_COMPUTE_CONFLICT);
try {
PrismObject<UserType> user = WebModelServiceUtils.loadObject(getPersonOfInterest().get(0), page);
PrismObject<UserType> user = WebModelServiceUtils.loadObject(ref, page);
ObjectDelta<UserType> delta = user.createModifyDelta();

PrismContainerDefinition def = user.getDefinition().findContainerDefinition(UserType.F_ASSIGNMENT);
Expand All @@ -278,6 +309,7 @@ public void computeConflicts(PageBase page) {

ModelExecuteOptions options = ModelExecuteOptions.create().partialProcessing(processing);

MidPointApplication mp = MidPointApplication.get();
ModelContext<UserType> ctx = mp.getModelInteractionService()
.previewChanges(MiscUtil.createCollection(delta), options, task, result);

Expand All @@ -302,30 +334,16 @@ public void computeConflicts(PageBase page) {
String msg = page.getString("PageAssignmentsList.conflictsWarning", getSubresultWarningMessages(result));
page.warn(msg);
}
return new ArrayList(conflicts.values());
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get assignments conflicts. Reason: ", ex);

this.conflicts = new ArrayList<>(conflicts.values());
conflictsDirty = false;
} catch (Exception e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get assignments conflicts. Reason: ", e);
page.error("Couldn't get assignments conflicts. Reason: " + e);
}
}

private ObjectReferenceType createRef(PrismObject object) {
if (object == null) {
return null;
result.recordFatalError("Couldn't get assignments conflicts", ex);
} finally {
result.computeStatusIfUnknown();
}

ObjectType obj = (ObjectType) object.asObjectable();

return new ObjectReferenceType()
.oid(object.getOid())
.type(ObjectTypes.getObjectType(obj.getClass()).getTypeQName())
.targetName(obj.getName());
}

public void computeConflictsForOnePerson() {
// todo implement
return new ArrayList<>();
}

private <F extends FocusType> void createConflicts(ObjectReferenceType userRef, Map<String, Conflict> conflicts, EvaluatedAssignment<UserType> evaluatedAssignment,
Expand Down

0 comments on commit 2975de7

Please sign in to comment.