Skip to content

Commit

Permalink
Changing schema for multiple role assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 17, 2017
1 parent cab803b commit 2f2e83e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 66 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 Evolveum
* Copyright (c) 2016-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,7 +27,7 @@
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.self.PageAssignmentDetails;
import com.evolveum.midpoint.web.session.RoleCatalogStorage;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentMultiplicityType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentConstraintsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
Expand Down Expand Up @@ -61,7 +61,7 @@ public class MultiButtonTable extends BasePanel<List<AssignmentEditorDto>> {

private static final String DOT_CLASS = AssignmentCatalogPanel.class.getName();
private static final Trace LOGGER = TraceManager.getTrace(AssignmentCatalogPanel.class);
private static final String OPERATION_LOAD_ASSIGNMENT_MULTIPLICITY = DOT_CLASS + "loadAssignmentMultiplicity";
private static final String OPERATION_LOAD_ASSIGNMENT_CONSTRAINTS = DOT_CLASS + "loadAssignmentConstraints";

private String addToCartLinkIcon = "fa fa-times-circle fa-lg text-danger";
private String detailsLinkIcon = "fa fa-arrow-circle-right";
Expand Down Expand Up @@ -132,8 +132,7 @@ public void onClick(AjaxRequestTarget ajaxRequestTarget) {

@Override
public boolean isEnabled(){
return !(AssignmentMultiplicityType.SINGLE.equals(getAssignmentMultiplicity())
&& assignment.isAlreadyAssigned());
return canAssign(assignment);
}
});
cellContainer.add(inner);
Expand All @@ -152,8 +151,7 @@ public void onClick(AjaxRequestTarget ajaxRequestTarget) {

@Override
public boolean isEnabled(){
return !(AssignmentMultiplicityType.SINGLE.equals(getAssignmentMultiplicity())
&& assignment.isAlreadyAssigned());
return canAssign(assignment);
}
});
cellContainer.add(detailsLink);
Expand All @@ -175,8 +173,7 @@ public void onClick(AjaxRequestTarget target) {

@Override
public boolean isEnabled(){
return !(AssignmentMultiplicityType.SINGLE.equals(getAssignmentMultiplicity())
&& assignment.isAlreadyAssigned());
return canAssign(assignment);
}
});
detailsLink.add(detailsLinkIcon);
Expand All @@ -192,8 +189,7 @@ public void onClick(AjaxRequestTarget ajaxRequestTarget) {

@Override
public boolean isEnabled(){
return !(AssignmentMultiplicityType.SINGLE.equals(getAssignmentMultiplicity())
&& assignment.isAlreadyAssigned());
return canAssign(assignment);
}
});
cellContainer.add(addToCartLink);
Expand All @@ -211,8 +207,7 @@ public void onClick(AjaxRequestTarget target) {

@Override
public boolean isEnabled(){
return !(AssignmentMultiplicityType.SINGLE.equals(getAssignmentMultiplicity())
&& assignment.isAlreadyAssigned());
return canAssign(assignment);
}
});
addToCartLink.add(addToCartLinkIcon);
Expand All @@ -223,6 +218,17 @@ public boolean isEnabled(){

}

private boolean canAssign(final AssignmentEditorDto assignment) {
AssignmentConstraintsType assignmentConstraints = getAssignmentConstraints();
if (assignmentConstraints == null) {
return true;
}
// TODO
// return !(AssignmentMultiplicityType.SINGLE.equals(getAssignmentMultiplicity())
// && assignment.isAlreadyAssigned());
return true;
}

private void assignmentDetailsPerformed(final AssignmentEditorDto assignment, AjaxRequestTarget target){
if (!plusIconClicked) {
IModel<AssignmentEditorDto> assignmentModel = new IModel<AssignmentEditorDto>() {
Expand Down Expand Up @@ -290,20 +296,18 @@ private void addAssignmentPerformed(AssignmentEditorDto assignment, AjaxRequestT

}

private AssignmentMultiplicityType getAssignmentMultiplicity(){
OperationResult result = new OperationResult(OPERATION_LOAD_ASSIGNMENT_MULTIPLICITY);
private AssignmentConstraintsType getAssignmentConstraints() {
OperationResult result = new OperationResult(OPERATION_LOAD_ASSIGNMENT_CONSTRAINTS);
SystemConfigurationType systemConfig = null;
try {
systemConfig = pageBase.getModelInteractionService().getSystemConfiguration(result);
} catch (ObjectNotFoundException | SchemaException e) {
LOGGER.error("Error getting system configuration: {}", e.getMessage(), e);
return AssignmentMultiplicityType.SINGLE;
return null;
}
if (systemConfig != null && systemConfig.getRoleManagement() != null &&
systemConfig.getRoleManagement().getDefaultAssignmentMultiplicity() != null &&
!systemConfig.getRoleManagement().getDefaultAssignmentMultiplicity().toString().equals("")){
return systemConfig.getRoleManagement().getDefaultAssignmentMultiplicity();
if (systemConfig != null && systemConfig.getRoleManagement() != null) {
return systemConfig.getRoleManagement().getDefaultAssignmentConstraints();
}
return AssignmentMultiplicityType.SINGLE;
return null;
}
}
Expand Up @@ -11145,10 +11145,12 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="defaultAssignmentMultiplicity" type="tns:AssignmentMultiplicityType" minOccurs="0" default="single">
<xsd:element name="defaultAssignmentConstraints" type="tns:AssignmentConstraintsType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Default multiplicity or role assignment. This value defines whether the same
Default assignment constraints. These constraints are applied globally to
the entire system.
This value defines whether the same
abstract role may be assigned only once or multiple times to the same focus.
This is the system-wide default value.
It will be possible to override this value for each individual role using the
Expand All @@ -11162,54 +11164,52 @@
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="AssignmentMultiplicityType">
<xsd:complexType name="AssignmentConstraintsType">
<xsd:annotation>
<xsd:documentation>
Multiplicity or role assignment. This value defines whether the same
abstract role may be assigned only once or multiple times to the same focus.
Specifies constraints on assignments that are placed in the same focus. It can be used
to prohibit multiple assignment of the same role and for similar cases.
There are several individual constraints in the type. There is a logical AND between them.
This means that if no contraint can be violated. All active constratints must be satified
at the same time.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumClass/>
<a:since>3.6</a:since>
</xsd:appinfo>
<a:since>3.6</a:since>
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="single">
<xsd:annotation>
<xsd:documentation>
The role may be assigned to each focus only once.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="SINGLE"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="parametricMultiple">
<xsd:annotation>
<xsd:documentation>
The role may be assigned to each focus multiple times,
but easch assignment must have different assignment
parameters.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="PARAMETRIC_MULTIPLE"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="multiple">
<xsd:annotation>
<xsd:documentation>
The role may be assigned to each focus multiple times.
There is no limitation as to the number of assignments.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="MULTIPLE"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

<xsd:sequence>
<xsd:element name="description" type="xsd:string" minOccurs="0"/>
<xsd:element name="prohibitSameTarget" type="xsd:boolean" minOccurs="0" maxOccurs="1" default="false">
<xsd:annotation>
<xsd:documentation>
Constraint all assignments that have the same target. I.e. multiple assignments
of the same (abstract) role.
If prohibitSameTarget=false then multiple assignments of the same role are allowed.
If prohibitSameTarget=true then multiple assignments of the same role are prohibited.
(but see also other constraints in this type)
</xsd:documentation>
<xsd:appinfo>
<a:since>3.6</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="prohibitSameRelation" type="xsd:boolean" minOccurs="0" maxOccurs="1" default="false">
<xsd:annotation>
<xsd:documentation>
Constraint all assignments that have the same relation.
E.g. if prohibitSameTarget=true and prohibitSameRelation=false then multiple assignments
of the same role are allowed as long as they have different relation.
If prohibitSameTarget=true and prohibitSameRelation=false
</xsd:documentation>
<xsd:appinfo>
<a:since>3.6</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<!-- TODO: prohibitSameOrg, prohibitSameTenant, parameter prohibitions -->
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="ObjectCollectionsUseType">
<xsd:annotation>
<xsd:documentation>
Expand Down

0 comments on commit 2f2e83e

Please sign in to comment.