Skip to content

Commit

Permalink
applicable policy panel
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Mar 15, 2018
1 parent a90fc75 commit 8e2c9d1
Show file tree
Hide file tree
Showing 10 changed files with 323 additions and 10 deletions.
Expand Up @@ -45,6 +45,9 @@ public class ComponentConstants {
public static final QName UI_FOCUS_TAB_POLICY_RULES = new QName(NS_COMPONENTS_PREFIX, "focusTabPolicyRules");
public static final String UI_FOCUS_TAB_POLICY_RULES_URL = QNameUtil.qNameToUri(UI_FOCUS_TAB_POLICY_RULES);

public static final QName UI_FOCUS_TAB_APPLICABLE_POLICIES = new QName(NS_COMPONENTS_PREFIX, "focusTabApplicablePolicies");
public static final String UI_FOCUS_TAB_APPLICABLE_POLICIES_URL = QNameUtil.qNameToUri(UI_FOCUS_TAB_APPLICABLE_POLICIES);

public static final QName UI_FOCUS_TAB_CONSENTS = new QName(NS_COMPONENTS_PREFIX, "focusTabConsents");
public static final String UI_FOCUS_TAB_CONSENTS_URL = QNameUtil.qNameToUri(UI_FOCUS_TAB_CONSENTS);

Expand Down
Expand Up @@ -936,6 +936,22 @@ public static <O extends ObjectType> String getName(ObjectReferenceType ref, Pag
return name;
}

public static <O extends ObjectType> String getDisplayNameOrName(ObjectReferenceType ref, PageBase pageBase, String operation) {
String name = getName(ref);
if (StringUtils.isEmpty(name) || name.equals(ref.getOid())) {
String oid = ref.getOid();
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions
.createCollection(GetOperationOptions.createNoFetch());
Class<O> type = (Class<O>) ObjectType.class;
PrismObject<O> object = WebModelServiceUtils.loadObject(type, oid, pageBase,
pageBase.createSimpleTask(operation), new OperationResult(operation));
if (object != null) {
name = getDisplayNameOrName(object);
}
}
return name;
}

public static <O extends ObjectType> String getEffectiveName(ObjectReferenceType ref, QName propertyName, PageBase pageBase, String operation) {
PrismObject<O> object = WebModelServiceUtils.loadObject(ref, pageBase,
pageBase.createSimpleTask(operation), new OperationResult(operation));
Expand Down
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright (c) 2010-2018 Evolveum
~
Expand All @@ -13,3 +14,9 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<wicket:panel xmlns:wicket="http://wicket.apache.org">

<div wicket:id="policiesGroups">
<div wicket:id="policyGroupPanel"/>
</div>
</wicket:panel>
Expand Up @@ -18,13 +18,18 @@
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.model.api.util.ModelContextUtil;
import com.evolveum.midpoint.model.api.util.ModelUtils;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.objectdetails.AbstractObjectMainPanel;
import com.evolveum.midpoint.web.component.prism.ContainerWrapper;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;

import java.util.ArrayList;
Expand All @@ -38,7 +43,10 @@ public class ApplicablePolicyConfigPanel extends BasePanel<ContainerWrapper<Assi

private static final Trace LOGGER = TraceManager.getTrace(ApplicablePolicyConfigPanel.class);
private static final String DOT_CLASS = ApplicablePolicyConfigPanel.class.getName() + ".";
private final static String OPERATION_LOAD_SYS_CONFIG = DOT_CLASS + "loadSystemConfiguration";
private static final String OPERATION_LOAD_SYS_CONFIG = DOT_CLASS + "loadSystemConfiguration";

private static final String ID_POLICY_GROUPS = "policiesGroups";
private static final String ID_POLICY_GROUP_PANEL = "policyGroupPanel";

private LoadableModel<List<ObjectReferenceType>> policyGroupsListModel;

Expand All @@ -48,8 +56,9 @@ public ApplicablePolicyConfigPanel(String id, IModel<ContainerWrapper<Assignment

@Override
protected void onInitialize(){
super.onInitialize();
initModels();
// initLayout();
initLayout();
}

private void initModels(){
Expand All @@ -65,15 +74,10 @@ protected List<ObjectReferenceType> load() {
if (sysConfig == null){
return policyGroupsList;
} else {
List<ObjectPolicyConfigurationType> policiesConfig = sysConfig.getDefaultObjectPolicyConfiguration();
if (policiesConfig == null){
return policyGroupsList;
ObjectPolicyConfigurationType policyConfig = ModelUtils.determineObjectPolicyConfiguration(getMainPanelFocusObject(), sysConfig);
if (policyConfig != null && policyConfig.getApplicablePolicies() != null){
return policyConfig.getApplicablePolicies().getPolicyGroupRef();
}
policiesConfig.forEach(policyConfig -> {
if (policyConfig.getType() != null && policyConfig.getType().equals(RoleType.COMPLEX_TYPE)){
// policyGroupsList = policyConfig.getApplicablePolicies();
}
});
}
} catch (Exception ex){
LoggingUtils.logUnexpectedException(LOGGER, "Cannot retrieve system configuration", ex);
Expand All @@ -83,4 +87,26 @@ protected List<ObjectReferenceType> load() {
};
}

private void initLayout(){
ListView<ObjectReferenceType> policyGroupsPanel = new ListView<ObjectReferenceType>(ID_POLICY_GROUPS, policyGroupsListModel) {
@Override
protected void populateItem(ListItem<ObjectReferenceType> listItem) {
ApplicablePolicyGroupPanel groupPanel = new ApplicablePolicyGroupPanel(ID_POLICY_GROUP_PANEL, listItem.getModel(),
ApplicablePolicyConfigPanel.this.getModel());
groupPanel.setOutputMarkupId(true);
listItem.add(groupPanel);
}
};
policyGroupsPanel.setOutputMarkupId(true);
add(policyGroupsPanel);
}

private PrismObject<FocusType> getMainPanelFocusObject(){
AbstractObjectMainPanel mainPanel = ApplicablePolicyConfigPanel.this.findParent(AbstractObjectMainPanel.class);
if (mainPanel != null){
return mainPanel.getObject();
}
return null;
}

}
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright (c) 2010-2018 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.
-->
<wicket:panel xmlns:wicket="http://wicket.apache.org">

<div>
<div class="box-header with-border">
<h3 class="box-title">
<div wicket:id="policyGroupName"/>
</h3>
</div>
<div class="box-body">
<div wicket:id="policiesContainer">
<div class="row">
<div class="col-md-6">
<div class="pull-left" wicket:id="policyCheckBox"/>
<div class="col-md-4" wicket:id="policyLabel"/>
</div>
</div>
</div>
</div>
</div>
</wicket:panel>
@@ -0,0 +1,125 @@
/**
* Copyright (c) 2015-2018 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.
*/
package com.evolveum.midpoint.web.component.assignment;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.OrgFilter;
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.data.column.CheckBoxPanel;
import com.evolveum.midpoint.web.component.prism.ContainerValueWrapper;
import com.evolveum.midpoint.web.component.prism.ContainerWrapper;
import com.evolveum.midpoint.web.page.admin.users.component.AbstractRoleMemberPanel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import java.util.List;

/**
* Created by honchar.
*/
public class ApplicablePolicyGroupPanel extends BasePanel<ObjectReferenceType>{
private static final long serialVersionUID = 1L;

private static final Trace LOGGER = TraceManager.getTrace(ApplicablePolicyGroupPanel.class);
private static final String DOT_CLASS = ApplicablePolicyGroupPanel.class.getName() + ".";
private static final String OPERATION_LOAD_POLICY_GROUP_MEMBERS = DOT_CLASS + "loadPolicyGroupMembers";
private static final String OPERATION_LOAD_POLICY_GROUP_NAME = DOT_CLASS + "loadPolicyGroupName";

private static final String ID_POLICY_GROUP_NAME = "policyGroupName";
private static final String ID_POLICIES_CONTAINER = "policiesContainer";
private static final String ID_POLICY_CHECK_BOX = "policyCheckBox";
private static final String ID_POLICY_LABEL = "policyLabel";
private LoadableModel<List<PrismObject<AbstractRoleType>>> policiesListModel;
IModel<ContainerWrapper<AssignmentType>> assignmentsModel;

public ApplicablePolicyGroupPanel(String id, IModel<ObjectReferenceType> model, IModel<ContainerWrapper<AssignmentType>> assignmentsModel){
super(id, model);
this.assignmentsModel = assignmentsModel;
}

@Override
protected void onInitialize(){
super.onInitialize();
initModels();
initLayout();
}

private void initModels(){
policiesListModel = new LoadableModel<List<PrismObject<AbstractRoleType>>>() {
@Override
protected List<PrismObject<AbstractRoleType>> load() {
OperationResult result = new OperationResult(OPERATION_LOAD_POLICY_GROUP_MEMBERS);

ObjectReferenceType policyGroupObject = ApplicablePolicyGroupPanel.this.getModelObject();
ObjectQuery membersQuery = QueryBuilder.queryFor(AbstractRoleType.class, getPageBase().getPrismContext())
.isChildOf(policyGroupObject.getOid())
.build();
return WebModelServiceUtils.searchObjects(AbstractRoleType.class, membersQuery, result, getPageBase());
}
};
}

private void initLayout(){
Label policyGroupName = new Label(ID_POLICY_GROUP_NAME, Model.of(WebComponentUtil.getDisplayNameOrName(getModelObject(), getPageBase(), OPERATION_LOAD_POLICY_GROUP_NAME)));
policyGroupName.setOutputMarkupId(true);
add(policyGroupName);

ListView<PrismObject<AbstractRoleType>> policiesPanel = new ListView<PrismObject<AbstractRoleType>>(ID_POLICIES_CONTAINER, policiesListModel){
private static final long serialVersionUID = 1L;

@Override
protected void populateItem(ListItem<PrismObject<AbstractRoleType>> listItem) {
CheckBoxPanel policyCheckBox = new CheckBoxPanel(ID_POLICY_CHECK_BOX,
ApplicablePolicyGroupPanel.this.isRoleAssignedModel(listItem.getModelObject().getOid()));
policyCheckBox.setOutputMarkupId(true);
listItem.add(policyCheckBox);

Label policyLabel = new Label(ID_POLICY_LABEL, Model.of(WebComponentUtil.getDisplayNameOrName(listItem.getModelObject())));
policyLabel.setOutputMarkupId(true);
listItem.add(policyLabel);
}
};
policiesPanel.setOutputMarkupId(true);
add(policiesPanel);
}


private IModel<Boolean> isRoleAssignedModel(String policyRoleOid){
for (ContainerValueWrapper<AssignmentType> assignment : assignmentsModel.getObject().getValues()){
ObjectReferenceType targetRef = assignment.getContainerValue().getValue().getTargetRef();
if (targetRef != null && targetRef.getOid().equals(policyRoleOid)){
return Model.of(true);
}
}
return Model.of(false);
}
}
Expand Up @@ -205,6 +205,18 @@ public String getCount() {
}
});

authorization = new FocusTabVisibleBehavior(unwrapModel(), ComponentConstants.UI_FOCUS_TAB_APPLICABLE_POLICIES_URL);
tabs.add(
new PanelTab(parentPage.createStringResource("pageAdminFocus.applicablePolicies"), authorization) {

private static final long serialVersionUID = 1L;

@Override
public WebMarkupContainer createPanel(String panelId) {
return new FocusApplicablePoliciesTabPanel<>(panelId, getMainForm(), getObjectModel(), parentPage);
}
});

authorization = new FocusTabVisibleBehavior(unwrapModel(),
ComponentConstants.UI_FOCUS_TAB_INDUCEMENTS_URL);
tabs.add(new CountablePanelTab(parentPage.createStringResource("FocusType.inducement"), authorization) {
Expand Down
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2018 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.
-->

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
<div class="row">
<div class="col-md-12">
<div wicket:id="applicablePoliciesContainer">
<div wicket:id="applicablePolicyPanel" />
</div>
</div>
</div>

</wicket:panel>
</body>
</html>

0 comments on commit 8e2c9d1

Please sign in to comment.