Skip to content

Commit

Permalink
Option to define "processing" in schema (ignore, minimal, auto)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Apr 25, 2018
1 parent 26c3d73 commit 670be87
Show file tree
Hide file tree
Showing 29 changed files with 401 additions and 65 deletions.
Expand Up @@ -1017,32 +1017,34 @@ public static <C extends Containerable> String getDisplayName(PrismContainerValu
return "ContainerPanel.containerProperties";
}

C containerable = prismContainerValue.asContainerable();
if (containerable instanceof AssignmentType) {
if (((AssignmentType) containerable).getTargetRef() != null){
ObjectReferenceType assignemntTargetRef = ((AssignmentType) containerable).getTargetRef();

if (prismContainerValue.canRepresent(AssignmentType.class)) {
AssignmentType assignmentType = (AssignmentType) prismContainerValue.asContainerable();
if (assignmentType.getTargetRef() != null){
ObjectReferenceType assignemntTargetRef = assignmentType.getTargetRef();
return getName(assignemntTargetRef) + " - " + normalizeRelation(assignemntTargetRef.getRelation()).getLocalPart();
} else {
return "AssignmentTypeDetailsPanel.containerTitle";
}
}

if (containerable instanceof ExclusionPolicyConstraintType){
ExclusionPolicyConstraintType exclusionConstraint = (ExclusionPolicyConstraintType) containerable;
if (prismContainerValue.canRepresent(ExclusionPolicyConstraintType.class)){
ExclusionPolicyConstraintType exclusionConstraint = (ExclusionPolicyConstraintType) prismContainerValue.asContainerable();
String displayName = (exclusionConstraint.getName() != null ? exclusionConstraint.getName() :
exclusionConstraint.asPrismContainerValue().getParent().getPath().last()) + " - "
+ StringUtils.defaultIfEmpty(getName(exclusionConstraint.getTargetRef()), "");
return StringUtils.isNotEmpty(displayName) ? displayName : "Not defined exclusion name";
}
if (containerable instanceof AbstractPolicyConstraintType){
AbstractPolicyConstraintType constraint = (AbstractPolicyConstraintType) containerable;
if (prismContainerValue.canRepresent(AbstractPolicyConstraintType.class)){
AbstractPolicyConstraintType constraint = (AbstractPolicyConstraintType) prismContainerValue.asContainerable();
String displayName = (StringUtils.isEmpty(constraint.getName()) ? (constraint.asPrismContainerValue().getParent().getPath().last())
: constraint.getName())
+ (StringUtils.isEmpty(constraint.getDescription()) ? "" : (" - " + constraint.getDescription()));
return displayName;
}
if (containerable.getClass() != null){
return containerable.getClass().getSimpleName() + ".details";
Class<C> cvalClass = prismContainerValue.getCompileTimeClass();
if (cvalClass != null){
return cvalClass.getSimpleName() + ".details";
}
return "ContainerPanel.containerProperties";
}
Expand Down
Expand Up @@ -480,7 +480,12 @@ public ContainerWrapper getParent() {
public boolean isVisible() {
PrismContainerDefinition<C> def = getItemDefinition();

if (def.isIgnored() || (def.isOperational()) && (!def.getTypeName().equals(MetadataType.COMPLEX_TYPE))) {
if (def.getProcessing() != null && def.getProcessing() != ItemProcessing.AUTO) {
return false;

}

if (def.isOperational() && (!def.getTypeName().equals(MetadataType.COMPLEX_TYPE))) {
return false;
}

Expand All @@ -503,6 +508,11 @@ public boolean isVisible() {

return false;
}

@Override
public ItemProcessing getProcessing() {
return getItemDefinition().getProcessing();
}

private boolean isNotEmptyAndCanReadAndModify(PrismContainerDefinition<C> def) {
return def.canRead();// && def.canModify();
Expand Down
Expand Up @@ -24,6 +24,7 @@
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.ItemProcessing;
import com.evolveum.midpoint.prism.Revivable;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.DebugDumpable;
Expand Down Expand Up @@ -76,6 +77,8 @@ public interface ItemWrapper<I extends Item, ID extends ItemDefinition, V> exten
* should be displayed or not.
*/
boolean isVisible();

ItemProcessing getProcessing();

/**
* Used to display the form elements with stripe in every other line.
Expand Down
Expand Up @@ -28,6 +28,7 @@
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.ItemProcessing;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.path.ItemPath;
Expand Down Expand Up @@ -121,6 +122,11 @@ public boolean isVisible() {
// }
}

@Override
public ItemProcessing getProcessing() {
return getItemDefinition().getProcessing();
}

private boolean canAddAndShowEmpty() {
return getItemDefinition().canAdd() && isShowEmpty();
}
Expand Down
Expand Up @@ -62,6 +62,7 @@

import javax.annotation.PostConstruct;
import javax.servlet.ServletException;
import javax.xml.namespace.QName;

/**
* @author lazyman
Expand All @@ -72,6 +73,12 @@ public abstract class AbstractGuiIntegrationTest extends AbstractModelIntegratio
private static final Trace LOGGER = TraceManager.getTrace(AbstractGuiIntegrationTest.class);

public static final File FOLDER_BASIC = new File("./src/test/resources/basic");

public static final String NS_PIRACY = "http://midpoint.evolveum.com/xml/ns/samples/piracy";
public static final QName PIRACY_WEAPON = new QName(NS_PIRACY, "weapon");
public static final QName PIRACY_COLORS = new QName(NS_PIRACY, "colors");
public static final QName PIRACY_SECRET = new QName(NS_PIRACY, "secret");
public static final QName PIRACY_RANT = new QName(NS_PIRACY, "rant");

private MidPointApplication application;

Expand Down
Expand Up @@ -25,6 +25,7 @@
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.assertNull;

import java.io.File;
import java.io.IOException;
Expand All @@ -41,6 +42,7 @@
import com.evolveum.icf.dummy.resource.DummyGroup;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.ItemProcessing;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismReferenceValue;
Expand Down Expand Up @@ -152,6 +154,11 @@ public void test100CreateWrapperUserJack() throws Exception {
assertItemWrapperFullConrol(mainContainerValueWrapper, UserType.F_FULL_NAME, true);
assertItemWrapperFullConrol(mainContainerValueWrapper, UserType.F_ADDITIONAL_NAME, false); // not visible, because it is empty
assertItemWrapperFullConrol(mainContainerValueWrapper, UserType.F_LOCALITY, true);

assertItemWrapperProcessing(mainContainerValueWrapper, PIRACY_WEAPON, null);
assertItemWrapperProcessing(mainContainerValueWrapper, PIRACY_COLORS, ItemProcessing.AUTO);
assertItemWrapperProcessing(mainContainerValueWrapper, PIRACY_SECRET, ItemProcessing.IGNORE);
assertItemWrapperProcessing(mainContainerValueWrapper, PIRACY_RANT, ItemProcessing.MINIMAL);

// WHEN
objectWrapper.setShowEmpty(true);
Expand Down Expand Up @@ -519,6 +526,17 @@ private <C extends Containerable> void assertItemWrapperFullConrol(ContainerValu
assertEquals("Wrong "+propName+" definition.canAdd", Boolean.TRUE, (Boolean)itemWrapper.getItemDefinition().canAdd());
assertEquals("Wrong "+propName+" definition.canModify", Boolean.TRUE, (Boolean)itemWrapper.getItemDefinition().canModify());
}

private void assertItemWrapperProcessing(ContainerValueWrapper<UserType> containerWrapper,
QName propName, ItemProcessing expectedProcessing) {
ItemWrapper itemWrapper = containerWrapper.findPropertyWrapper(propName);
if (expectedProcessing == ItemProcessing.IGNORE) {
assertNull("Unexpected ignored item wrapper for "+propName, itemWrapper);
} else {
assertEquals("Wrong processing in item wrapper for "+propName, expectedProcessing, itemWrapper.getProcessing());
}
}


private void cleanupAutzTest(String userOid) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, PolicyViolationException, SecurityViolationException, IOException {
login(userAdministrator);
Expand Down
15 changes: 15 additions & 0 deletions gui/admin-gui/src/test/resources/schema/piracy.xsd
Expand Up @@ -73,11 +73,26 @@
<xsd:annotation>
<xsd:appinfo>
<a:indexed>false</a:indexed>
<a:processing>auto</a:processing>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="mark" type="tns:MarkType" minOccurs="0" maxOccurs="1">
</xsd:element>
<xsd:element name="secret" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:appinfo>
<a:processing>ignore</a:processing>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="rant" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:appinfo>
<a:processing>minimal</a:processing>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

Expand Down
Expand Up @@ -108,6 +108,11 @@ public boolean isObjectMarker() {
public boolean isIgnored() {
return structuralObjectClassDefinition.isIgnored();
}

@Override
public ItemProcessing getProcessing() {
return structuralObjectClassDefinition.getProcessing();
}

@Override
public boolean isEmphasized() {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* 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.
Expand Down Expand Up @@ -151,6 +151,16 @@ public boolean canRead() {
public boolean isIgnored(LayerType layer) {
return refinedAttributeDefinition.isIgnored(layer);
}

@Override
public ItemProcessing getProcessing() {
return refinedAttributeDefinition.getProcessing(layer);
}

@Override
public ItemProcessing getProcessing(LayerType layer) {
return refinedAttributeDefinition.getProcessing(layer);
}

@Override
public boolean canModify() {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* 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.
Expand Down Expand Up @@ -92,7 +92,12 @@ public boolean isIgnored() {
return refinedObjectClassDefinition.isIgnored();
}

public boolean isEmphasized() {
@Override
public ItemProcessing getProcessing() {
return refinedObjectClassDefinition.getProcessing();
}

public boolean isEmphasized() {
return refinedObjectClassDefinition.isEmphasized();
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014 Evolveum
* 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.
Expand All @@ -17,6 +17,7 @@

import java.io.Serializable;

import com.evolveum.midpoint.prism.ItemProcessing;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyAccessType;
Expand All @@ -26,18 +27,19 @@
*
*/
public class PropertyLimitations implements DebugDumpable, Serializable {

private boolean ignore;
private static final long serialVersionUID = 1L;

private ItemProcessing processing;
private int minOccurs;
private int maxOccurs;
private PropertyAccessType access = new PropertyAccessType();

public boolean isIgnore() {
return ignore;
public ItemProcessing getProcessing() {
return processing;
}

public void setIgnore(boolean ignore) {
this.ignore = ignore;
public void setProcessing(ItemProcessing processing) {
this.processing = processing;
}

public int getMinOccurs() {
Expand Down Expand Up @@ -97,8 +99,8 @@ public String toString() {
} else {
sb.append("-");
}
if (ignore) {
sb.append(",ignored");
if (processing != null) {
sb.append(",").append(processing);
}
return sb.toString();
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* 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.
Expand All @@ -18,6 +18,7 @@

import com.evolveum.midpoint.prism.ComplexTypeDefinition;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.ItemProcessing;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AttributeFetchStrategyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LayerType;
Expand All @@ -43,7 +44,10 @@ public interface RefinedAttributeDefinition<T> extends ResourceAttributeDefiniti

boolean canModify(LayerType layer);

@Deprecated
boolean isIgnored(LayerType layer);

ItemProcessing getProcessing(LayerType layer);

String getDescription();

Expand Down

0 comments on commit 670be87

Please sign in to comment.