Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Feb 17, 2017
2 parents a385b36 + 17ac84a commit 239d406
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 14 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2016 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 Down Expand Up @@ -27,6 +27,7 @@
public class ComponentConstants {

public static final String NS_COMPONENTS_PREFIX = SchemaConstants.NS_MIDPOINT_PUBLIC_PREFIX + "gui/component-3";
public static final String NS_DASHBOARD_WIDGET = NS_COMPONENTS_PREFIX + "/dashboard/widget";

// UI - Tabs for focus objects
public static final QName UI_FOCUS_TAB_BASIC = new QName(NS_COMPONENTS_PREFIX, "focusTabBasic");
Expand Down Expand Up @@ -60,5 +61,6 @@ public class ComponentConstants {
public static final String UI_FOCUS_TAB_POLICY_CONSTRAINTS_URL = QNameUtil.qNameToUri(UI_FOCUS_TAB_POLICY_CONSTRAINTS);

public static final QName UI_FOCUS_TAB_MEMBERS = new QName(NS_COMPONENTS_PREFIX, "focusTabMembers");
public static final String UI_FOCUS_TAB_MEMBERS_URL = QNameUtil.qNameToUri(UI_FOCUS_TAB_MEMBERS);
public static final String UI_FOCUS_TAB_MEMBERS_URL = QNameUtil.qNameToUri(UI_FOCUS_TAB_MEMBERS);

}
@@ -0,0 +1,51 @@
/**
* Copyright (c) 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.
*/
package com.evolveum.midpoint.gui.api;

import javax.xml.namespace.QName;

import com.evolveum.midpoint.util.QNameUtil;

/**
* @author semancik
*
*/
public enum PredefinedDashboardWidgetId {

SEARCH("search"),
SHORTCUTS("shortcuts"),
MY_WORKITEMS("myWorkitems"),
MY_REQUESTS("myRequests"),
MY_ASSIGNMENTS("myAssignments"),
MY_ACCOUNTS("myAccounts");

private final QName qname;
private final String uri;

private PredefinedDashboardWidgetId(String localPart) {
this.qname = new QName(ComponentConstants.NS_DASHBOARD_WIDGET, localPart);
this.uri = QNameUtil.qNameToUri(qname);
}

public QName getQname() {
return qname;
}

public String getUri() {
return uri;
}

}
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015-2016 Evolveum
* Copyright (c) 2015-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 @@ -17,9 +17,13 @@

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AdminGuiConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DashboardLayoutType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DashboardWidgetType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFormType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFormsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserInterfaceElementVisibilityType;

import org.jetbrains.annotations.NotNull;

import java.util.Iterator;
Expand Down Expand Up @@ -71,6 +75,15 @@ private static void applyAdminGuiConfiguration(AdminGuiConfigurationType composi
}
}
}
if (adminGuiConfiguration.getUserDashboard() != null) {
if (composite.getUserDashboard() == null) {
composite.setUserDashboard(adminGuiConfiguration.getUserDashboard().clone());
} else {
for (DashboardWidgetType widget: adminGuiConfiguration.getUserDashboard().getWidget()) {
mergeWidget(composite.getUserDashboard(), widget);
}
}
}
}

private static void replaceForm(ObjectFormsType objectForms, ObjectFormType newForm) {
Expand All @@ -83,5 +96,49 @@ private static void replaceForm(ObjectFormsType objectForms, ObjectFormType newF
}
objectForms.getObjectForm().add(newForm);
}


private static void mergeWidget(DashboardLayoutType compositeDashboard, DashboardWidgetType newWidget) {
String newWidgetIdentifier = newWidget.getIdentifier();
DashboardWidgetType compositeWidget = findWidget(compositeDashboard, newWidgetIdentifier);
if (compositeWidget == null) {
compositeDashboard.getWidget().add(newWidget.clone());
} else {
mergeWidget(compositeWidget, newWidget);
}
}

private static void mergeWidget(DashboardWidgetType compositeWidget, DashboardWidgetType newWidget) {
UserInterfaceElementVisibilityType newCompositeVisibility = mergeVisibility(compositeWidget.getVisibility(), newWidget.getVisibility());
compositeWidget.setVisibility(newCompositeVisibility);
}

private static UserInterfaceElementVisibilityType mergeVisibility(
UserInterfaceElementVisibilityType compositeVisibility, UserInterfaceElementVisibilityType newVisibility) {
if (compositeVisibility == null) {
compositeVisibility = UserInterfaceElementVisibilityType.VACANT;
}
if (newVisibility == null) {
newVisibility = UserInterfaceElementVisibilityType.VACANT;
}
if (compositeVisibility == UserInterfaceElementVisibilityType.HIDDEN || newVisibility == UserInterfaceElementVisibilityType.HIDDEN) {
return UserInterfaceElementVisibilityType.HIDDEN;
}
if (compositeVisibility == UserInterfaceElementVisibilityType.VISIBLE || newVisibility == UserInterfaceElementVisibilityType.VISIBLE) {
return UserInterfaceElementVisibilityType.VISIBLE;
}
if (compositeVisibility == UserInterfaceElementVisibilityType.AUTOMATIC || newVisibility == UserInterfaceElementVisibilityType.AUTOMATIC) {
return UserInterfaceElementVisibilityType.AUTOMATIC;
}
return UserInterfaceElementVisibilityType.VACANT;
}

private static DashboardWidgetType findWidget(DashboardLayoutType dashboard, String widgetIdentifier) {
for (DashboardWidgetType widget: dashboard.getWidget()) {
if (widget.getIdentifier().equals(widgetIdentifier)) {
return widget;
}
}
return null;
}

}
Expand Up @@ -9958,6 +9958,7 @@
<xsd:annotation>
<xsd:documentation>
Application or shortcut links placed on end-user dashboard.
TODO: align with userDashboard
</xsd:documentation>
</xsd:annotation>
</xsd:element>
Expand All @@ -9974,6 +9975,19 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="userDashboard" type="tns:DashboardLayoutType" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
<p>
Specifies the layout of the user dashboard (home screen):
it defines which boxes should be visible, which should be hidden, etc.
</p>
</xsd:documentation>
<xsd:appinfo>
<a:since>3.6</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="defaultTimezone" type="xsd:string" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -10007,6 +10021,125 @@
</xsd:element>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="DashboardLayoutType">
<xsd:annotation>
<xsd:documentation>
Specifies layout of a dashboard, such as the user dashboard (home screen)
or administration dashboard. It specifies which boxes should be visible, which
should be hidden and so on.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
<a:since>3.6</a:since>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="widget" type="tns:DashboardWidgetType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="DashboardWidgetType">
<xsd:annotation>
<xsd:documentation>
Defines properties of a specific dashboard widget.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
<a:since>3.6</a:since>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="identifier" type="xsd:anyURI" minOccurs="1" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
Widget identifier. It defines the identity of the widget and currently
also the placement on the dashboard. The widget specifications that come
from different roles will be merged if they have the same identifier.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- TODO: type
<xsd:element name="type" type="xsd:QName" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
Type of the widget. It is an identifier that specifies the content
of the winget (e.g. what will be inside the box).
THIS IS NOT USED YET. It is only for future use.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
-->
<!-- TODO: placement -->
<xsd:element name="visibility" type="tns:UserInterfaceElementVisibilityType"
minOccurs="0" maxOccurs="1" default="vacant">
<xsd:annotation>
<xsd:documentation>
Defines, whether this widget will be visible or it will be hidden.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="UserInterfaceElementVisibilityType">
<xsd:annotation>
<xsd:documentation>
Defines, whether a user interface element (form, widget) will be visible or it will be hidden.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumClass/>
<a:since>3.6</a:since>
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="automatic">
<xsd:annotation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="AUTOMATIC"/>
</xsd:appinfo>
<xsd:documentation>
The element will be visible if the authorisations of the current user
allows to see (at least a part) of the content that the element displays.
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="visible">
<xsd:annotation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="VISIBLE"/>
</xsd:appinfo>
<xsd:documentation>
The element will be always visible.
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="vacant">
<xsd:annotation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="VACANT"/>
</xsd:appinfo>
<xsd:documentation>
The element will not be visible. Not even if the authorizations allow
to see its content. But if any other role specifies the element as visible
or automatic then it will be visible. This setting is easily overridden.
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="hidden">
<xsd:annotation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="HIDDEN"/>
</xsd:appinfo>
<xsd:documentation>
The element is never visible. Even if any other role specifies the element as
visible then the element will still remain invisible. This setting cannot be
overridden.
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="RichHyperlinkType">
<xsd:annotation>
Expand Down Expand Up @@ -12894,7 +13027,6 @@
<xsd:element name="sequence" type="tns:SequenceType" />



<!-- ============================================================== -->
<!-- FORMS -->
<!-- ============================================================== -->
Expand Down
Expand Up @@ -458,7 +458,7 @@ public void test130GetAdminGuiConfig() throws Exception {
result.computeStatus();
TestUtil.assertSuccess(result);

assertAdminGuiConfigurations(adminGuiConfiguration, 0, 1, 1);
assertAdminGuiConfigurations(adminGuiConfiguration, 0, 1, 1, 0);

RichHyperlinkType link = adminGuiConfiguration.getUserDashboardLink().get(0);
assertEquals("Bad link label", "Foo", link.getLabel());
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2016 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 Down Expand Up @@ -546,7 +546,7 @@ public void test100JackRolePirate() throws Exception {
assertNotAuthorized(principal, AUTZ_LOOT_URL, null);
assertNotAuthorized(principal, AUTZ_COMMAND_URL);

assertAdminGuiConfigurations(principal, 1, 2, 2);
assertAdminGuiConfigurations(principal, 1, 2, 2, 2);
}

@Test
Expand All @@ -572,7 +572,7 @@ public void test109JackUnassignRolePirate() throws Exception {
assertNotAuthorized(principal, AUTZ_LOOT_URL);
assertNotAuthorized(principal, AUTZ_COMMAND_URL);

assertAdminGuiConfigurations(principal, 0, 1, 1);
assertAdminGuiConfigurations(principal, 0, 1, 1, 0);
}

@Test
Expand Down
10 changes: 10 additions & 0 deletions model/model-intest/src/test/resources/common/role-pirate.xml
Expand Up @@ -144,5 +144,15 @@
</formSpecification>
</objectForm>
</objectForms>
<userDashboard>
<widget>
<identifier>http://midpoint.evolveum.com/xml/ns/public/gui/component-3/dashboard/widget#search</identifier>
<visibility>automatic</visibility>
</widget>
<widget>
<identifier>http://midpoint.evolveum.com/xml/ns/public/gui/component-3/dashboard/widget#myWorkitems</identifier>
<visibility>vacant</visibility>
</widget>
</userDashboard>
</adminGuiConfiguration>
</role>

0 comments on commit 239d406

Please sign in to comment.