Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
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.java
  • Loading branch information
mederly committed Nov 29, 2017
2 parents da7fe41 + 6c11da8 commit b320c56
Show file tree
Hide file tree
Showing 19 changed files with 373 additions and 72 deletions.
Expand Up @@ -37,6 +37,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
Expand Down Expand Up @@ -2295,6 +2296,10 @@ protected CharSequence getDefaultChoice(String selectedValue) {
return dropDown;
}

public static boolean isAllNulls(Iterable<?> array) {
return StreamSupport.stream(array.spliterator(), true).allMatch(o -> o == null);
}

private static IModel<List<Boolean>> createChoices() {
return new AbstractReadOnlyModel<List<Boolean>>() {

Expand Down
Expand Up @@ -29,7 +29,7 @@
</div>

<div class="row" >
<div class="col-md-12" wicket:id="assignmentsTable" style="margin: 5px;"/>
<div class="col-md-12" wicket:id="assignmentsTable" style="margin: 5px 0;"/>
</div>
<div>
<div class="btn btn-success btn-sm" wicket:id="newAssignmentButton"/>
Expand Down
Expand Up @@ -23,6 +23,10 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.query.builder.S_AtomicFilterExit;
import com.evolveum.midpoint.prism.query.builder.S_FilterEntryOrEmpty;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.component.prism.*;
import com.evolveum.midpoint.web.page.admin.PageAdminFocus;
import com.evolveum.midpoint.web.page.admin.users.component.AssignmentInfoDto;
Expand Down Expand Up @@ -224,16 +228,29 @@ protected int getItemsPerPage() {
}

protected ObjectQuery createObjectQuery() {
return QueryBuilder.queryFor(AssignmentType.class, getParentPage().getPrismContext())
.block()
.not()
.item(new ItemPath(AssignmentType.F_CONSTRUCTION, ConstructionType.F_RESOURCE_REF))
.isNull()
.endBlock()
.or()
.item(new ItemPath(AssignmentType.F_TARGET_REF))
.ref(getRelation())
.build();
QName relation = getRelation();
S_AtomicFilterExit tempFilter = QueryBuilder.queryFor(AssignmentType.class, getParentPage().getPrismContext())
.block()
.not()
.item(new ItemPath(AssignmentType.F_CONSTRUCTION, ConstructionType.F_RESOURCE_REF))
.isNull()
.endBlock();
if (PrismConstants.Q_ANY.equals(relation)){
return tempFilter
.or()
.block()
.not()
.item(new ItemPath(AssignmentType.F_TARGET_REF))
.ref(SchemaConstants.ORG_DEPUTY)
.endBlock()
.build();
} else {
return tempFilter
.or()
.item(new ItemPath(AssignmentType.F_TARGET_REF))
.ref(relation)
.build();
}
};

private QName getRelation() {
Expand Down
Expand Up @@ -21,7 +21,7 @@
<div wicket:id="assignments" class="main-form-panel">

<div class="row" >
<div class="col-md-12" wicket:id="assignmentsTable" style="margin: 5px;"/>
<div class="col-md-12" wicket:id="assignmentsTable" style="margin: 5px 0;"/>
</div>
<div>
<div class="btn btn-success btn-sm" wicket:id="newAssignmentButton"/>
Expand Down
@@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2010-2015 Evolveum
~ 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.
Expand All @@ -21,7 +21,7 @@
<wicket:container wicket:id="menuItems">
<li class="header">
<span wicket:id="name"></span>
<i class="fa fa-angle-left pull-right" wicket:id="minimizedIcon"></i>
<i class="pull-right" wicket:id="minimizedIcon"></i>
</li>
<wicket:container wicket:id="items">
<wicket:container wicket:id="item"/>
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* 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.
Expand All @@ -15,16 +15,21 @@
*/
package com.evolveum.midpoint.web.component.menu;

import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.web.component.prism.show.SceneDto;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.security.SecurityUtils;
import com.evolveum.midpoint.web.session.SessionStorage;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebMarkupContainer;
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.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

Expand All @@ -35,8 +40,9 @@
* @author Viliam Repan (lazyman)
*/
public class SideBarMenuPanel extends SimplePanel<List<SideBarMenuItem>> {

private static final String ID_SIDEBAR = "sidebar";
private static final long serialVersionUID = 1L;

private static final String ID_SIDEBAR = "sidebar";
private static final String ID_MENU_ITEMS = "menuItems";
private static final String ID_NAME = "name";
private static final String ID_ITEMS = "items";
Expand All @@ -56,44 +62,52 @@ protected void initLayout() {
add(sidebar);

ListView<SideBarMenuItem> menuItems = new ListView<SideBarMenuItem>(ID_MENU_ITEMS, getModel()) {
private static final long serialVersionUID = 1L;

@Override
@Override
protected void populateItem(final ListItem<SideBarMenuItem> item) {
Label name = new Label(ID_NAME, item.getModelObject().getName());
name.add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;

@Override
@Override
protected void onEvent(AjaxRequestTarget target) {
SideBarMenuItem mainMenu = item.getModelObject();

SessionStorage storage = getPageBase().getSessionStorage();
Map<String, Boolean> menuState = storage.getMainMenuState();

String menuLabel = mainMenu.getName().getObject();
// we'll use menu label as key
Boolean expanded = menuState.get(menuLabel);

if (expanded == null) {
expanded = true;
}

menuState.put(menuLabel, !expanded);

target.add(sidebar);
onMenuClick(sidebar, item, target);
}
});
item.add(name);

WebMarkupContainer icon = new WebMarkupContainer(ID_MINIMIZED_ICON);
icon.add(new VisibleEnableBehaviour() {
icon.add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;

@Override
protected void onEvent(AjaxRequestTarget target) {
onMenuClick(sidebar, item, target);
}
});
icon.add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;

@Override
public boolean isVisible() {
SideBarMenuItem mainMenu = item.getModelObject();
public String getObject() {
SideBarMenuItem mainMenu = item.getModelObject();
if (isMenuExpanded(mainMenu)) {
return GuiStyleConstants.CLASS_ICON_COLLAPSE;
}

return !isMenuExpanded(mainMenu);
return GuiStyleConstants.CLASS_ICON_EXPAND;
}
});
}));
// icon.add(new VisibleEnableBehaviour() {
//
// @Override
// public boolean isVisible() {
// SideBarMenuItem mainMenu = item.getModelObject();
//
// return !isMenuExpanded(mainMenu);
// }
// });
item.add(icon);

ListView<MainMenuItem> items = new ListView<MainMenuItem>(ID_ITEMS,
Expand Down Expand Up @@ -162,6 +176,25 @@ public boolean isVisible() {
};
sidebar.add(menuItems);
}

private void onMenuClick(final WebMarkupContainer sidebar, final ListItem<SideBarMenuItem> item, AjaxRequestTarget target) {
SideBarMenuItem mainMenu = item.getModelObject();

SessionStorage storage = getPageBase().getSessionStorage();
Map<String, Boolean> menuState = storage.getMainMenuState();

String menuLabel = mainMenu.getName().getObject();
// we'll use menu label as key
Boolean expanded = menuState.get(menuLabel);

if (expanded == null) {
expanded = true;
}

menuState.put(menuLabel, !expanded);

target.add(sidebar);
}

private boolean isMenuExpanded(SideBarMenuItem mainMenu) {
SessionStorage storage = getPageBase().getSessionStorage();
Expand Down
Expand Up @@ -18,10 +18,7 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.*;

import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
Expand Down Expand Up @@ -662,10 +659,14 @@ protected ObjectFilter createCustomFilter() {
protected boolean isEditButtonEnabled() {
return valueWrapperModel.getObject().isEditEnabled();
}

@Override
public List<QName> getSupportedTypes() {
return ((ReferenceWrapper) valueWrapperModel.getObject().getItem()).getTargetTypes();
public List<QName> getSupportedTypes() {
List<QName> targetTypeList = ((ReferenceWrapper) valueWrapperModel.getObject().getItem()).getTargetTypes();
if (targetTypeList == null || WebComponentUtil.isAllNulls(targetTypeList)) {
return Arrays.asList(ObjectType.COMPLEX_TYPE);
}
return targetTypeList;
}
};

Expand Down
Expand Up @@ -29,7 +29,7 @@
*/
@PageDescriptor(
urls = {
@Url(mountUrl = "/admin/workItemsAttorney", matchUrlForSecurity = "/admin/workItemsAttorney")
@Url(mountUrl = "/admin/workItemsAttorney")
},
encoder = OnePageParameterEncoder.class,
action = {
Expand Down
Expand Up @@ -122,6 +122,11 @@ th.cog, td.cog {
width: 20px;
}

.sidebar-menu > .header {
// white-space: wrap is problematic in firefox, it wraps expand/collapse icon on next line
white-space: normal !important;
}

.sidebar-form, .sidebar-menu > li.header {
padding: 10px 20px 10px 15px;
text-transform: uppercase;
Expand Down
Expand Up @@ -52,6 +52,9 @@ public class TestDiffEquals {
public static final File TEST_DIR = new File("src/test/resources/diff");
private static final File ROLE_COMPARE_FILE = new File(TEST_DIR, "role-compare.xml");

private static final File ROLE_1 = new File(TEST_DIR, "role-1.xml");
private static final File ROLE_2 = new File(TEST_DIR, "role-2.xml");

private static final String NS_TEST_RI = "http://midpoint.evolveum.com/xml/ns/test/ri-1";

private static final Trace LOGGER = TraceManager.getTrace(TestDiffEquals.class);
Expand Down Expand Up @@ -445,4 +448,13 @@ public void testTriggerCollectionsEqual() throws Exception {
assertEquals("Wrong comparison B-C", false, PolicyRuleTypeUtil.triggerCollectionsEqual(triggerListB, triggerListC));
}

@Test(enabled = false)
public void diffRoles() throws Exception {
PrismObject<RoleType> role1 = PrismTestUtil.parseObject(ROLE_1);
PrismObject<RoleType> role2 = PrismTestUtil.parseObject(ROLE_2);

ObjectDelta<RoleType> delta = role1.diff(role2, true, true);
assertFalse(delta.isEmpty());
}

}
40 changes: 40 additions & 0 deletions infra/schema/src/test/resources/diff/role-1.xml
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<role xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="6077bad0-43ff-4958-acce-73c0e04f178d"
version="4">
<name>asdf</name>
<inducement>
<construction>
<resourceRef type="c:ResourceType">
<filter>
<q:inOid>
<expression>
<script>
<code>
return "1";
</code>
</script>
</expression>
</q:inOid>
</filter>
</resourceRef>
</construction>
</inducement>
</role>

0 comments on commit b320c56

Please sign in to comment.