Skip to content

Commit

Permalink
Refactoring the support for enumerations a bit. Some work on MID-2260.
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 25, 2015
1 parent a9187bc commit 38130ab
Show file tree
Hide file tree
Showing 17 changed files with 314 additions and 98 deletions.
Expand Up @@ -487,7 +487,7 @@ private boolean isEnum(PrismProperty property){
//
// return ((clazz != null && clazz.isEnum()) || ActivationType.F_ADMINISTRATIVE_STATUS.equals(definition.getName())
// || ActivationType.F_LOCKOUT_STATUS.equals(definition.getName()) || );
return (definition.getAllowedValues() != null && definition.getAllowedValues().length > 0);
return (definition.getAllowedValues() != null && definition.getAllowedValues().size() > 0);
}
//TODO - try to get rid of <br> attributes when creating new lines in association attributes pop-up
private String createAssociationTooltipText(PrismProperty property){
Expand Down
Expand Up @@ -223,7 +223,7 @@ public static DropDownChoicePanel createEnumPanel(final PrismPropertyDefinition
public List<DisplayableValue> getObject() {
List<DisplayableValue> values = null;
if (def.getAllowedValues() != null){
values = new ArrayList<>(def.getAllowedValues().length);
values = new ArrayList<>(def.getAllowedValues().size());
for (Object v : def.getAllowedValues()){
if (v instanceof DisplayableValue){
values.add(((DisplayableValue) v));
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* Copyright (c) 2010-2015 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 @@ -31,6 +31,7 @@
import com.evolveum.midpoint.schema.processor.ResourceAttributeContainerDefinition;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.DisplayableValue;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AttributeFetchStrategyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LayerType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType;
Expand All @@ -39,25 +40,25 @@
* @author semancik
*
*/
public class LayerRefinedAttributeDefinition extends RefinedAttributeDefinition {
public class LayerRefinedAttributeDefinition<T> extends RefinedAttributeDefinition<T> {

private RefinedAttributeDefinition refinedAttributeDefinition;
private RefinedAttributeDefinition<T> refinedAttributeDefinition;
private LayerType layer;
private Boolean overrideCanRead = null;
private Boolean overrideCanAdd = null;
private Boolean overrideCanModify = null;

private LayerRefinedAttributeDefinition(RefinedAttributeDefinition refinedAttributeDefinition, LayerType layer) {
private LayerRefinedAttributeDefinition(RefinedAttributeDefinition<T> refinedAttributeDefinition, LayerType layer) {
super(refinedAttributeDefinition, refinedAttributeDefinition.getPrismContext());
this.refinedAttributeDefinition = refinedAttributeDefinition;
this.layer = layer;
}

static LayerRefinedAttributeDefinition wrap(RefinedAttributeDefinition rAttrDef, LayerType layer) {
static <T> LayerRefinedAttributeDefinition<T> wrap(RefinedAttributeDefinition<T> rAttrDef, LayerType layer) {
if (rAttrDef == null) {
return null;
}
return new LayerRefinedAttributeDefinition(rAttrDef, layer);
return new LayerRefinedAttributeDefinition<T>(rAttrDef, layer);
}

static List<LayerRefinedAttributeDefinition> wrapCollection(
Expand Down Expand Up @@ -253,7 +254,7 @@ public void setCanAdd(boolean create) {
}

@Override
public PropertyDelta createEmptyDelta(ItemPath path) {
public PropertyDelta<T> createEmptyDelta(ItemPath path) {
return refinedAttributeDefinition.createEmptyDelta(path);
}

Expand Down Expand Up @@ -328,17 +329,17 @@ public void setDescription(String description) {
}

@Override
public Class getTypeClass() {
public Class<T> getTypeClass() {
return refinedAttributeDefinition.getTypeClass();
}

@Override
public ResourceAttributeDefinition getAttributeDefinition() {
public ResourceAttributeDefinition<T> getAttributeDefinition() {
return refinedAttributeDefinition.getAttributeDefinition();
}

@Override
public void setAttributeDefinition(ResourceAttributeDefinition attributeDefinition) {
public void setAttributeDefinition(ResourceAttributeDefinition<T> attributeDefinition) {
refinedAttributeDefinition.setAttributeDefinition(attributeDefinition);
}

Expand Down Expand Up @@ -450,7 +451,7 @@ public String getNativeAttributeName() {
}

@Override
public Object[] getAllowedValues() {
public Collection<? extends DisplayableValue<T>> getAllowedValues() {
return refinedAttributeDefinition.getAllowedValues();
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014 Evolveum
* Copyright (c) 2010-2015 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,6 +15,7 @@
*/
package com.evolveum.midpoint.common.refinery;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -30,6 +31,7 @@
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.DisplayableValue;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AttributeFetchStrategyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LayerType;
Expand All @@ -41,7 +43,7 @@
/**
* @author semancik
*/
public class RefinedAttributeDefinition extends ResourceAttributeDefinition implements DebugDumpable {
public class RefinedAttributeDefinition<T> extends ResourceAttributeDefinition<T> implements DebugDumpable {

private static LayerType DEFAULT_LAYER = LayerType.MODEL;

Expand All @@ -52,7 +54,7 @@ public class RefinedAttributeDefinition extends ResourceAttributeDefinition impl
protected boolean secondaryIdentifier = false;
private List<String> intolerantValuePattern;
private List<String> tolerantValuePattern;
private ResourceAttributeDefinition attributeDefinition;
private ResourceAttributeDefinition<T> attributeDefinition;
private AttributeFetchStrategyType fetchStrategy;
private MappingType outboundMappingType;
private List<MappingType> inboundMappingTypes;
Expand All @@ -61,7 +63,7 @@ public class RefinedAttributeDefinition extends ResourceAttributeDefinition impl
private Integer modificationPriority;
private Boolean readReplaceMode;

protected RefinedAttributeDefinition(ResourceAttributeDefinition attrDef, PrismContext prismContext) {
protected RefinedAttributeDefinition(ResourceAttributeDefinition<T> attrDef, PrismContext prismContext) {
super(attrDef.getName(), attrDef.getTypeName(), prismContext);
this.attributeDefinition = attrDef;
}
Expand Down Expand Up @@ -184,11 +186,11 @@ public void setDescription(String description) {
this.description = description;
}

public ResourceAttributeDefinition getAttributeDefinition() {
public ResourceAttributeDefinition<T> getAttributeDefinition() {
return attributeDefinition;
}

public void setAttributeDefinition(ResourceAttributeDefinition attributeDefinition) {
public void setAttributeDefinition(ResourceAttributeDefinition<T> attributeDefinition) {
this.attributeDefinition = attributeDefinition;
}

Expand Down Expand Up @@ -224,7 +226,7 @@ public String getNativeAttributeName() {
return attributeDefinition.getNativeAttributeName();
}

public Object[] getAllowedValues() {
public Collection<? extends DisplayableValue<T>> getAllowedValues() {
return attributeDefinition.getAllowedValues();
}

Expand Down Expand Up @@ -314,11 +316,11 @@ public List<String> getIntolerantValuePattern(){
}

// schemaHandlingAttrDefType may be null if we are parsing from schema only
static RefinedAttributeDefinition parse(ResourceAttributeDefinition schemaAttrDef, ResourceAttributeDefinitionType schemaHandlingAttrDefType,
static <T> RefinedAttributeDefinition<T> parse(ResourceAttributeDefinition<T> schemaAttrDef, ResourceAttributeDefinitionType schemaHandlingAttrDefType,
ObjectClassComplexTypeDefinition objectClassDef, PrismContext prismContext,
String contextDescription) throws SchemaException {

RefinedAttributeDefinition rAttrDef = new RefinedAttributeDefinition(schemaAttrDef, prismContext);
RefinedAttributeDefinition<T> rAttrDef = new RefinedAttributeDefinition<T>(schemaAttrDef, prismContext);

if (schemaHandlingAttrDefType != null && schemaHandlingAttrDefType.getDisplayName() != null) {
rAttrDef.setDisplayName(schemaHandlingAttrDefType.getDisplayName());
Expand Down
Expand Up @@ -72,6 +72,7 @@ public class PrismConstants {
public static final QName A_OBJECT_REFERENCE_TARGET_TYPE = new QName(NS_ANNOTATION, "objectReferenceTargetType");
public static final QName A_COMPOSITE = new QName(NS_ANNOTATION, "composite");
public static final QName A_DEPRECATED = new QName(NS_ANNOTATION, "deprecated");
public static final QName A_LABEL = new QName(NS_ANNOTATION, "label");

public static final QName SCHEMA_DOCUMENTATION = new QName(W3C_XML_SCHEMA_NS_URI, "documentation");
public static final QName SCHEMA_APP_INFO = new QName(W3C_XML_SCHEMA_NS_URI, "appinfo");
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014 Evolveum
* Copyright (c) 2010-2015 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 @@ -16,12 +16,13 @@

package com.evolveum.midpoint.prism;

import java.util.Arrays;
import java.util.Collection;

import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.DisplayableValue;

/**
* Property Definition.
Expand Down Expand Up @@ -56,17 +57,17 @@ public class PrismPropertyDefinition<T> extends ItemDefinition {

private static final long serialVersionUID = 7259761997904371009L;
private QName valueType;
private T[] allowedValues;
private Collection<? extends DisplayableValue<T>> allowedValues;
private Boolean indexed = null;
private T defaultValue;

public PrismPropertyDefinition(QName elementName, QName typeName, PrismContext prismContext) {
super(elementName, typeName, prismContext);
}

public PrismPropertyDefinition(QName elementName, QName typeName, PrismContext prismContext, T[] allowevValues, T defaultValue) {
public PrismPropertyDefinition(QName elementName, QName typeName, PrismContext prismContext, Collection<? extends DisplayableValue<T>> allowedValues, T defaultValue) {
super(elementName, typeName, prismContext);
this.allowedValues = allowevValues;
this.allowedValues = allowedValues;
this.defaultValue = defaultValue;
}

Expand All @@ -75,7 +76,7 @@ public PrismPropertyDefinition(QName elementName, QName typeName, PrismContext p
*
* @return Object array. May be null.
*/
public T[] getAllowedValues() {
public Collection<? extends DisplayableValue<T>> getAllowedValues() {
return allowedValues;
}

Expand Down Expand Up @@ -158,36 +159,51 @@ protected void extendToString(StringBuilder sb) {
sb.append(",I");
}
}

@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((allowedValues == null) ? 0 : allowedValues.hashCode());
result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
result = prime * result + ((indexed == null) ? 0 : indexed.hashCode());
result = prime * result + ((valueType == null) ? 0 : valueType.hashCode());
return result;
}

@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + Arrays.hashCode(allowedValues);
result = prime * result + ((valueType == null) ? 0 : valueType.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
PrismPropertyDefinition other = (PrismPropertyDefinition) obj;
if (allowedValues == null) {
if (other.allowedValues != null)
return false;
} else if (!allowedValues.equals(other.allowedValues))
return false;
if (defaultValue == null) {
if (other.defaultValue != null)
return false;
} else if (!defaultValue.equals(other.defaultValue))
return false;
if (indexed == null) {
if (other.indexed != null)
return false;
} else if (!indexed.equals(other.indexed))
return false;
if (valueType == null) {
if (other.valueType != null)
return false;
} else if (!valueType.equals(other.valueType))
return false;
return true;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
PrismPropertyDefinition other = (PrismPropertyDefinition) obj;
if (!Arrays.equals(allowedValues, other.allowedValues))
return false;
if (valueType == null) {
if (other.valueType != null)
return false;
} else if (!valueType.equals(other.valueType))
return false;
return true;
}

/**
/**
* Return a human readable name of this class suitable for logs.
*/
@Override
Expand Down
Expand Up @@ -449,7 +449,7 @@ private <T> T parseAtomicValueFromPrimitive(PrimitiveXNode<T> xprim, PrismProper
if (prismContext.getBeanConverter().canProcess(typeName) && !typeName.equals(PolyStringType.COMPLEX_TYPE) && !typeName.equals(ItemPathType.COMPLEX_TYPE)) {
// Primitive elements may also have complex Java representations (e.g. enums)
return prismContext.getBeanConverter().unmarshallPrimitive(xprim, typeName);
} else if (def != null && def.isRuntimeSchema() && def.getAllowedValues() != null && def.getAllowedValues().length > 0){
} else if (def != null && def.isRuntimeSchema() && def.getAllowedValues() != null && def.getAllowedValues().size() > 0){
//TODO: ugly hack to support enum in extension schemas --- need to be fixed

realValue = xprim.getParsedValue(DOMUtil.XSD_STRING);
Expand Down Expand Up @@ -479,9 +479,9 @@ private <T> T parseAtomicValueFromPrimitive(PrimitiveXNode<T> xprim, PrismProper
return realValue;
}

private <T> boolean isAllowed(T realValue, Object[] allowedValues){
for (Object o : allowedValues){
if (realValue.equals(((DisplayableValue)o).getValue())){
private <T> boolean isAllowed(T realValue, Collection<DisplayableValue<T>> collection){
for (DisplayableValue<T> o : collection){
if (realValue.equals(o.getValue())){
return true;
}
}
Expand Down

0 comments on commit 38130ab

Please sign in to comment.