Skip to content

Commit

Permalink
first changes for redesigned preview changes page
Browse files Browse the repository at this point in the history
# Conflicts:
#	gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AbstractRoleAssignmentPanel.html
  • Loading branch information
KaterynaHonchar committed Aug 23, 2018
1 parent 013a246 commit 72a3107
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 161 deletions.
Expand Up @@ -37,16 +37,16 @@
</div>
</div>
<div wicket:id="details">
<div wicket:id="assignmentsDetails">
<div wicket:id="assignmentDetails" />
</div>

<div class="row">
<div class="container-fluid prism-container">
<div class="btn btn-default" wicket:id="cancelButton"/>
<div class="btn btn-primary" wicket:id="doneButton"/>
<div wicket:id="assignmentsDetails">
<div wicket:id="assignmentDetails" />
</div>

<div class="row">
<div class="container-fluid prism-container">
<div class="btn btn-default" wicket:id="cancelButton"/>
<div class="btn btn-primary" wicket:id="doneButton"/>
</div>
</div>
</div>
</div>
</wicket:panel>
</html>
Expand Up @@ -19,39 +19,7 @@
<body>
<wicket:extend>
<form wicket:id="mainForm" class="form-horizontal">
<div class="row" style="padding-bottom: 20px">
<div class="col-md-6">
<div wicket:id="primaryDeltas"/>
</div>
<div class="col-md-6">
<div wicket:id="secondaryDeltas"/>
</div>
</div>
<div class="row" wicket:id="policyViolationsContainer">
<div class="col-md-12">
<div class="box box-danger">
<div class="box-header">
<h3 class="box-title"><wicket:message key="PagePreviewChanges.policyViolationMessages"/></h3>
</div>
<div class="box-body">
<div wicket:id="policyViolations"/>
</div>
</div>
</div>
</div>
<div class="row" wicket:id="approvalsContainer">
<div class="col-md-12">
<div class="box box-warning">
<div class="box-header">
<h3 class="box-title"><wicket:message key="PagePreviewChanges.approvalsRequired"/></h3>
</div>
<div class="box-body">
<div wicket:id="approvals"/>
</div>
</div>
</div>
</div>

<div wicket:id="tabbedPanel" class="nav-tabs-custom" />
<div class="main-button-bar">
<a class="btn btn-default" wicket:id="continueEditing" />
<a class="btn btn-primary" wicket:id="save" />
Expand Down
Expand Up @@ -15,11 +15,13 @@
*/
package com.evolveum.midpoint.web.component.prism.show;

import com.evolveum.midpoint.gui.api.component.tabs.PanelTab;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.model.api.context.ModelProjectionContext;
import com.evolveum.midpoint.model.api.visualizer.Scene;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectResolver;
Expand All @@ -35,6 +37,7 @@
import com.evolveum.midpoint.web.application.AuthorizationAction;
import com.evolveum.midpoint.web.application.PageDescriptor;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.TabbedPanel;
import com.evolveum.midpoint.web.component.breadcrumbs.Breadcrumb;
import com.evolveum.midpoint.web.component.breadcrumbs.BreadcrumbPageInstance;
import com.evolveum.midpoint.web.component.util.EnableBehaviour;
Expand All @@ -53,6 +56,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleEnforcerHookPreviewOutputType;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
Expand All @@ -63,6 +67,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static org.apache.commons.collections.CollectionUtils.addIgnoreNull;

Expand All @@ -83,145 +88,39 @@
@AuthorizationAction(actionUri = PageAdminServices.AUTH_SERVICES_ALL, label = PageAdminServices.AUTH_SERVICES_ALL_LABEL, description = PageAdminServices.AUTH_SERVICES_ALL_DESCRIPTION),
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_UI_SERVICE_URL, label = "PageService.auth.role.label", description = "PageService.auth.role.description")
})
public class PagePreviewChanges extends PageAdmin {
public class PagePreviewChanges<O extends ObjectType> extends PageAdmin {
private static final long serialVersionUID = 1L;

private static final String ID_PRIMARY_DELTAS_SCENE = "primaryDeltas";
private static final String ID_SECONDARY_DELTAS_SCENE = "secondaryDeltas";
private static final String ID_APPROVALS_CONTAINER = "approvalsContainer";
private static final String ID_APPROVALS = "approvals";
private static final String ID_POLICY_VIOLATIONS_CONTAINER = "policyViolationsContainer";
private static final String ID_POLICY_VIOLATIONS = "policyViolations";

private static final String ID_TABBED_PANEL = "tabbedPanel";
private static final String ID_CONTINUE_EDITING = "continueEditing";
private static final String ID_SAVE = "save";

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

private IModel<SceneDto> primaryDeltasModel;
private IModel<SceneDto> secondaryDeltasModel;
private IModel<List<EvaluatedTriggerGroupDto>> policyViolationsModel;
private IModel<List<ApprovalProcessExecutionInformationDto>> approvalsModel;

public PagePreviewChanges(ModelContext<? extends ObjectType> modelContext, ModelInteractionService modelInteractionService) {
final List<ObjectDelta<? extends ObjectType>> primaryDeltas = new ArrayList<>();
final List<ObjectDelta<? extends ObjectType>> secondaryDeltas = new ArrayList<>();
final List<? extends Scene> primaryScenes;
final List<? extends Scene> secondaryScenes;
try {
if (modelContext != null) {
if (modelContext.getFocusContext() != null) {
addIgnoreNull(primaryDeltas, modelContext.getFocusContext().getPrimaryDelta());
addIgnoreNull(secondaryDeltas, modelContext.getFocusContext().getSecondaryDelta());
}
for (ModelProjectionContext projCtx : modelContext.getProjectionContexts()) {
addIgnoreNull(primaryDeltas, projCtx.getPrimaryDelta());
addIgnoreNull(secondaryDeltas, projCtx.getExecutableDelta());
}
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Primary deltas:\n{}", DebugUtil.debugDump(primaryDeltas));
LOGGER.trace("Secondary deltas:\n{}", DebugUtil.debugDump(secondaryDeltas));
}

Task task = createSimpleTask("visualize");
primaryScenes = modelInteractionService.visualizeDeltas(primaryDeltas, task, task.getResult());
secondaryScenes = modelInteractionService.visualizeDeltas(secondaryDeltas, task, task.getResult());
} catch (SchemaException | ExpressionEvaluationException e) {
throw new SystemException(e); // TODO
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Creating context DTO for primary deltas:\n{}", DebugUtil.debugDump(primaryScenes));
LOGGER.trace("Creating context DTO for secondary deltas:\n{}", DebugUtil.debugDump(secondaryScenes));
}

final WrapperScene primaryScene = new WrapperScene(primaryScenes,
primaryScenes.size() != 1 ? "PagePreviewChanges.primaryChangesMore" : "PagePreviewChanges.primaryChangesOne", primaryScenes.size());
final WrapperScene secondaryScene = new WrapperScene(secondaryScenes,
secondaryScenes.size() != 1 ? "PagePreviewChanges.secondaryChangesMore" : "PagePreviewChanges.secondaryChangesOne", secondaryScenes.size());
final SceneDto primarySceneDto = new SceneDto(primaryScene);
final SceneDto secondarySceneDto = new SceneDto(secondaryScene);
primaryDeltasModel = new AbstractReadOnlyModel<SceneDto>() {
@Override
public SceneDto getObject() {
return primarySceneDto;
}
};
secondaryDeltasModel = new AbstractReadOnlyModel<SceneDto>() {
@Override
public SceneDto getObject() {
return secondarySceneDto;
}
};

PolicyRuleEnforcerHookPreviewOutputType enforcements = modelContext != null
? modelContext.getHookPreviewResult(PolicyRuleEnforcerHookPreviewOutputType.class)
: null;
List<EvaluatedTriggerGroupDto> triggerGroups = enforcements != null
? Collections.singletonList(EvaluatedTriggerGroupDto.initializeFromRules(enforcements.getRule(), false, null))
: Collections.emptyList();
policyViolationsModel = Model.ofList(triggerGroups);
private Map<PrismObject<O>, ModelContext<O>> modelContextMap;
private ModelInteractionService modelInteractionService;

List<ApprovalSchemaExecutionInformationType> approvalsExecutionList = modelContext != null
? modelContext.getHookPreviewResults(ApprovalSchemaExecutionInformationType.class)
: Collections.emptyList();
List<ApprovalProcessExecutionInformationDto> approvals = new ArrayList<>();
if (!approvalsExecutionList.isEmpty()) {
Task opTask = createSimpleTask(PagePreviewChanges.class + ".createApprovals"); // TODO
OperationResult result = opTask.getResult();
ObjectResolver modelObjectResolver = getModelObjectResolver();
try {
for (ApprovalSchemaExecutionInformationType execution : approvalsExecutionList) {
approvals.add(ApprovalProcessExecutionInformationDto
.createFrom(execution, modelObjectResolver, true, opTask, result)); // TODO reuse session
}
result.computeStatus();
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare approval information", t);
result.recordFatalError("Couldn't prepare approval information: " + t.getMessage(), t);
}
if (WebComponentUtil.showResultInPage(result)) {
showResult(result);
}
}
approvalsModel = Model.ofList(approvals);
public PagePreviewChanges(Map<PrismObject<O>, ModelContext<O>> modelContextMap, ModelInteractionService modelInteractionService) {
this.modelContextMap = modelContextMap;
this.modelInteractionService = modelInteractionService;

initLayout();
}

@Override
protected void createBreadcrumb() {
createInstanceBreadcrumb();
}

private void initLayout() {
Form mainForm = new com.evolveum.midpoint.web.component.form.Form("mainForm");
mainForm.setMultiPart(true);
add(mainForm);

mainForm.add(new ScenePanel(ID_PRIMARY_DELTAS_SCENE, primaryDeltasModel));
mainForm.add(new ScenePanel(ID_SECONDARY_DELTAS_SCENE, secondaryDeltasModel));

WebMarkupContainer policyViolationsContainer = new WebMarkupContainer(ID_POLICY_VIOLATIONS_CONTAINER);
policyViolationsContainer.add(new VisibleBehaviour(() -> !violationsEmpty()));
policyViolationsContainer.add(new EvaluatedTriggerGroupListPanel(ID_POLICY_VIOLATIONS, policyViolationsModel));
mainForm.add(policyViolationsContainer);

WebMarkupContainer approvalsContainer = new WebMarkupContainer(ID_APPROVALS_CONTAINER);
approvalsContainer.add(new VisibleBehaviour(() -> violationsEmpty() && !approvalsEmpty()));
approvalsContainer.add(new ApprovalProcessesPreviewPanel(ID_APPROVALS, approvalsModel));
mainForm.add(approvalsContainer);
List<ITab> tabs = createTabs();
TabbedPanel<ITab> previewChangesTabbedPanel = WebComponentUtil.createTabPanel(ID_TABBED_PANEL, this, tabs, null);
previewChangesTabbedPanel.setOutputMarkupId(true);
mainForm.add(previewChangesTabbedPanel);

initButtons(mainForm);
}

private boolean approvalsEmpty() {
return approvalsModel.getObject().isEmpty();
}

private boolean violationsEmpty() {
return EvaluatedTriggerGroupDto.isEmpty(policyViolationsModel.getObject());
}

private void initButtons(Form mainForm) {
AjaxButton cancel = new AjaxButton(ID_CONTINUE_EDITING, createStringResource("PagePreviewChanges.button.continueEditing")) {
@Override
Expand All @@ -238,10 +137,50 @@ public void onClick(AjaxRequestTarget target) {
}
};
//save.add(new EnableBehaviour(() -> violationsEmpty())); // does not work as expected (MID-4252)

save.add(new VisibleBehaviour(() -> violationsEmpty())); // so hiding the button altogether
mainForm.add(save);
}

//TODO relocate the logic from the loop to some util method, code repeats in PreviewChangesTabPanel
private boolean violationsEmpty() {
for (ModelContext<O> modelContext : modelContextMap.values()) {
PolicyRuleEnforcerHookPreviewOutputType enforcements = modelContext != null
? modelContext.getHookPreviewResult(PolicyRuleEnforcerHookPreviewOutputType.class)
: null;
List<EvaluatedTriggerGroupDto> triggerGroups = enforcements != null
? Collections.singletonList(EvaluatedTriggerGroupDto.initializeFromRules(enforcements.getRule(), false, null))
: Collections.emptyList();
if (!EvaluatedTriggerGroupDto.isEmpty(triggerGroups)){
return false;
}
}
return true;
}

private List<ITab> createTabs(){
List<ITab> tabs = new ArrayList<>();
modelContextMap.forEach((object, modelContext) -> {

tabs.add(
new PanelTab(getTabPanelTitleModel(object)){

private static final long serialVersionUID = 1L;

@Override
public WebMarkupContainer createPanel(String panelId) {
return new PreviewChangesTabPanel(panelId, Model.of(modelContext));
}
});
});
return tabs;
}

private IModel<String> getTabPanelTitleModel(PrismObject<? extends ObjectType> object){
return Model.of(object.asObjectable().getName().getOrig());
}


private void cancelPerformed(AjaxRequestTarget target) {
redirectBack();
}
Expand All @@ -261,4 +200,8 @@ private void savePerformed(AjaxRequestTarget target) {
}
}

@Override
protected void createBreadcrumb() {
createInstanceBreadcrumb();
}
}
@@ -0,0 +1,53 @@
<!--
~ Copyright (c) 2010-2017 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div class="row" style="padding-bottom: 20px">
<div class="col-md-6">
<div wicket:id="primaryDeltas"/>
</div>
<div class="col-md-6">
<div wicket:id="secondaryDeltas"/>
</div>
</div>
<div class="row" wicket:id="policyViolationsContainer">
<div class="col-md-12">
<div class="box box-danger">
<div class="box-header">
<h3 class="box-title"><wicket:message key="PagePreviewChanges.policyViolationMessages"/></h3>
</div>
<div class="box-body">
<div wicket:id="policyViolations"/>
</div>
</div>
</div>
</div>
<div class="row" wicket:id="approvalsContainer">
<div class="col-md-12">
<div class="box box-warning">
<div class="box-header">
<h3 class="box-title"><wicket:message key="PagePreviewChanges.approvalsRequired"/></h3>
</div>
<div class="box-body">
<div wicket:id="approvals"/>
</div>
</div>
</div>
</div>
</wicket:panel>
</html>

0 comments on commit 72a3107

Please sign in to comment.