Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Aug 24, 2016
2 parents d15f8d8 + 16daac7 commit 0cfe5d9
Show file tree
Hide file tree
Showing 23 changed files with 618 additions and 70 deletions.
Expand Up @@ -34,16 +34,17 @@
import javax.xml.namespace.QName;

import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;

import com.evolveum.prism.xml.ns._public.types_3.EvaluationTimeType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.w3c.dom.Element;

/**
* @author Radovan Semancik
*/
public class PrismReferenceValue extends PrismValue implements DebugDumpable, Serializable {
private static final long serialVersionUID = 1L;

private static final QName F_OID = new QName(PrismConstants.NS_TYPES, "oid");
private static final QName F_OID = new QName(PrismConstants.NS_TYPES, "oid");
private static final QName F_TYPE = new QName(PrismConstants.NS_TYPES, "type");
private static final QName F_RELATION = new QName(PrismConstants.NS_TYPES, "relation");
private String oid = null;
Expand All @@ -52,9 +53,9 @@ public class PrismReferenceValue extends PrismValue implements DebugDumpable, Se
private QName relation = null;
private String description = null;
private SearchFilterType filter = null;
private EvaluationTimeType resolutionTime;
private PolyString targetName = null;


private Referencable referencable;

public PrismReferenceValue() {
Expand Down Expand Up @@ -204,7 +205,15 @@ public SearchFilterType getFilter() {
public void setFilter(SearchFilterType filter) {
this.filter = filter;
}


public EvaluationTimeType getResolutionTime() {
return resolutionTime;
}

public void setResolutionTime(EvaluationTimeType resolutionTime) {
this.resolutionTime = resolutionTime;
}

@Override
public PrismReferenceDefinition getDefinition() {
return (PrismReferenceDefinition) super.getDefinition();
Expand Down Expand Up @@ -344,6 +353,7 @@ public PrismReferenceValue toCannonical() {
can.setTargetType(getTargetType());
can.setRelation(getRelation());
can.setFilter(getFilter());
can.setResolutionTime(getResolutionTime());
can.setDescription(getDescription());
return can;
}
Expand Down Expand Up @@ -472,6 +482,9 @@ public String toString() {
if (filter != null) {
sb.append(", (filter)");
}
if (resolutionTime != null) {
sb.append(", resolutionTime=").append(resolutionTime);
}
if (object != null) {
sb.append(", (object)");
}
Expand Down Expand Up @@ -534,6 +547,7 @@ protected void copyValues(PrismReferenceValue clone) {
}
clone.description = this.description;
clone.filter = this.filter;
clone.resolutionTime = this.resolutionTime;
clone.relation = this.relation;
clone.targetName = this.targetName;
}
Expand Down
Expand Up @@ -47,6 +47,7 @@
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.prism.xml.ns._public.types_3.EvaluationTimeType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
Expand Down Expand Up @@ -779,6 +780,12 @@ public PrismReferenceValue parseReferenceValue(MapXNode xmap, PrismReferenceDefi
refVal.setDescription((String) xmap.getParsedPrimitiveValue(XNode.KEY_REFERENCE_DESCRIPTION, DOMUtil.XSD_STRING));

refVal.setFilter(parseFilter(xmap.get(XNode.KEY_REFERENCE_FILTER), pc));

String resolutionTimeString = (String) xmap.getParsedPrimitiveValue(XNode.KEY_REFERENCE_RESOLUTION_TIME, DOMUtil.XSD_STRING);
if (resolutionTimeString != null) {
EvaluationTimeType resolutionTime = EvaluationTimeType.fromValue(resolutionTimeString);
refVal.setResolutionTime(resolutionTime);
}

XNode xnodeForTargetName = xmap.get(XNode.KEY_REFERENCE_TARGET_NAME);
if (xnodeForTargetName != null) {
Expand Down
Expand Up @@ -49,6 +49,7 @@
import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.prism.xml.ns._public.types_3.EvaluationTimeType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedDataType;

Expand Down Expand Up @@ -288,6 +289,11 @@ private XNode serializeReferenceValue(PrismReferenceValue value, PrismReferenceD
XNode xsubnode = filter.serializeToXNode();
xmap.put(createReferenceQName(XNode.KEY_REFERENCE_FILTER, namespace), xsubnode);
}
EvaluationTimeType resolutionTime = value.getResolutionTime();
if (resolutionTime != null) {
xmap.put(createReferenceQName(XNode.KEY_REFERENCE_RESOLUTION_TIME, namespace),
createPrimitiveXNode(resolutionTime.value(), DOMUtil.XSD_STRING));
}
if (value.getTargetName() != null) {
if (SerializationContext.isSerializeReferenceNames(ctx)) {
XNode xsubnode = createPrimitiveXNode(value.getTargetName(), PolyStringType.COMPLEX_TYPE);
Expand Down
Expand Up @@ -43,6 +43,7 @@ public abstract class XNode implements DebugDumpable, Visitable, Cloneable, Seri
public static final QName KEY_REFERENCE_RELATION = new QName(null, "relation");
public static final QName KEY_REFERENCE_DESCRIPTION = new QName(null, "description");
public static final QName KEY_REFERENCE_FILTER = new QName(null, "filter");
public static final QName KEY_REFERENCE_RESOLUTION_TIME = new QName(null, "resolutionTime");
public static final QName KEY_REFERENCE_TARGET_NAME = new QName(null, "targetName");
public static final QName KEY_REFERENCE_OBJECT = new QName(null, "object");

Expand Down
@@ -0,0 +1,74 @@

package com.evolveum.prism.xml.ns._public.types_3;

import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import javax.xml.bind.annotation.XmlType;


/**
* <p>Java class for EvaluationTimeType.
*
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* &lt;simpleType name="EvaluationTimeType"&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string"&gt;
* &lt;enumeration value="import"/&gt;
* &lt;enumeration value="run"/&gt;
* &lt;/restriction&gt;
* &lt;/simpleType&gt;
* </pre>
*
*/
@XmlType(name = "EvaluationTimeType")
@XmlEnum
public enum EvaluationTimeType {


/**
*
* <pre>
* &lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;p xmlns:a="http://prism.evolveum.com/xml/ns/public/annotation-3" xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:cap="http://midpoint.evolveum.com/xml/ns/public/resource/capabilities-3" xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3" xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3" xmlns:tns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
* Import-time. Evaluation happens when the object is imported
* into midPoint repository.
* &lt;/p&gt;
* </pre>
*
*
*/
@XmlEnumValue("import")
IMPORT("import"),

/**
*
* <pre>
* &lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;p xmlns:a="http://prism.evolveum.com/xml/ns/public/annotation-3" xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:cap="http://midpoint.evolveum.com/xml/ns/public/resource/capabilities-3" xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3" xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3" xmlns:tns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
* Run-time. Evaluation happens every time when the object is used.
* &lt;/p&gt;
* </pre>
*
*
*/
@XmlEnumValue("run")
RUN("run");
private final String value;

EvaluationTimeType(String v) {
value = v;
}

public String value() {
return value;
}

public static EvaluationTimeType fromValue(String v) {
for (EvaluationTimeType c: EvaluationTimeType.values()) {
if (c.value.equals(v)) {
return c;
}
}
throw new IllegalArgumentException(v);
}

}
63 changes: 60 additions & 3 deletions infra/prism/src/main/resources/xml/ns/public/types-3.xsd
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ Copyright (c) 2010-2015 Evolveum
~ Copyright (c) 2010-2016 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,7 +31,7 @@
<xsd:documentation>
Basic Prism types.

Version: 3.3
Version: 3.4.1-SNAPSHOT
Recommended namespace prefix: t
</xsd:documentation>
</xsd:annotation>
Expand Down Expand Up @@ -308,6 +308,26 @@
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="resolutionTime" type="tns:EvaluationTimeType" minOccurs="0" maxOccurs="1" default="import">
<xsd:annotation>
<xsd:documentation>
<p>
Definition of the "time" when the reference will be resolved. Resolving the reference means using
the filter to get object(s) or OID(s).
</p>
<p>
Import-time resolution means that the reference will be resolved once when the file is imported.
OID will be recorded in the reference and then only the OID will be used to follow the reference.
This is a very efficient method and it is the default.
</p>
<p>
Run-time resolution means that the reference will be resolved every time that the reference is
evaluated. This is less efficient but it provides great flexibility as the filter may contain
expressions and therefore the reference target may dynamically change.
</p>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="targetName" type="tns:PolyStringType" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -622,7 +642,44 @@
</xsd:restriction>
</xsd:simpleType>


<xsd:simpleType name="EvaluationTimeType">
<xsd:annotation>
<xsd:documentation>
Enumeration that defines when a specific expression is evaluated, filter is resolved, etc.
It defines the "time" when such evaluation happens, such as import-time, run-time, etc.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumClass/>
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="import">
<xsd:annotation>
<xsd:documentation>
<p>
Import-time. Evaluation happens when the object is imported
into the system.
</p>
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="IMPORT"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="run">
<xsd:annotation>
<xsd:documentation>
<p>
Run-time. Evaluation happens every time when the object is used.
</p>
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="RUN"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

</xsd:schema>

Expand Up @@ -403,7 +403,31 @@
Filter that can be used to dynamically lookup the reference OID e.g. during imports.
It must not be used for normal operations. The filter may be stored in the repository
to avoid data loss. But even if it is stored it will not be used beyond initial
import or unless explicitly requested.
import or unless explicitly requested (e.g. by setting resolutionTime).
</p>
<p>
Note: The filter will NOT be used if the OID in the reference is set. The OID always takes
precedence.
</p>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="resolutionTime" type="t:EvaluationTimeType" minOccurs="0" maxOccurs="1" default="import">
<xsd:annotation>
<xsd:documentation>
<p>
Definition of the "time" when the reference will be resolved. Resolving the reference means using
the filter to get object(s) or OID(s).
</p>
<p>
Import-time resolution means that the reference will be resolved once when the file is imported.
OID will be recorded in the reference and then only the OID will be used to follow the reference.
This is a very efficient method and it is the default.
</p>
<p>
Run-time resolution means that the reference will be resolved every time that the reference is
evaluated. This is less efficient but it provides great flexibility as the filter may contain
expressions and therefore the reference target may dynamically change.
</p>
</xsd:documentation>
</xsd:annotation>
Expand Down Expand Up @@ -462,7 +486,7 @@
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:element name="objectRef" type="tns:ObjectReferenceType"/>
<xsd:element name="objectRef" type="tns:ObjectReferenceType"/>

<xsd:complexType name="ExtensionType">
<xsd:annotation>
Expand Down
Expand Up @@ -45,6 +45,7 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
import com.evolveum.prism.xml.ns._public.types_3.EvaluationTimeType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import com.evolveum.prism.xml.ns._public.types_3.RawType;
Expand Down Expand Up @@ -455,6 +456,12 @@ private void assertResourcePrism(PrismObject<ResourceType> resource, boolean isS
PrismPropertyValue filterValue = (PrismPropertyValue) equalFilter.getValues().get(0);
assertEquals("Wrong filter value", "org.identityconnectors.ldap.LdapConnector", ((String) filterValue.getValue()).trim());
}
EvaluationTimeType resolutionTime = connectorRefVal.getResolutionTime();
if (isSimple) {
assertEquals("Wrong resolution time in connectorRef value", EvaluationTimeType.RUN, resolutionTime);
} else {
assertEquals("Wrong resolution time in connectorRef value", EvaluationTimeType.IMPORT, resolutionTime);
}

PrismContainer<?> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
assertContainerDefinition(configurationContainer, "configuration", ConnectorConfigurationType.COMPLEX_TYPE, 1, 1);
Expand Down Expand Up @@ -534,6 +541,12 @@ private void assertResourceJaxb(ResourceType resourceType, boolean isSimple) thr
assertNotNull("No filter in connectorRef (JAXB)", filter);
MapXNode filterElement = filter.getFilterClauseXNode();
assertNotNull("No filter element in connectorRef (JAXB)", filterElement);
EvaluationTimeType resolutionTime = connectorRef.getResolutionTime();
if (isSimple) {
assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.RUN, resolutionTime);
} else {
assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.IMPORT, resolutionTime);
}

XmlSchemaType xmlSchemaType = resourceType.getSchema();
SchemaHandlingType schemaHandling = resourceType.getSchemaHandling();
Expand Down
Expand Up @@ -60,6 +60,7 @@
</value>
</equal>
</filter>
<resolutionTime>import</resolutionTime>
<description>Reference to the ICF LDAP connector.</description>
</connectorRef>

Expand Down
Expand Up @@ -42,6 +42,7 @@
<q:value>org.identityconnectors.ldap.LdapConnector</q:value>
</q:equal>
</filter>
<resolutionTime>run</resolutionTime>
</connectorRef>

<!-- Resource configuration section -->
Expand Down
3 changes: 2 additions & 1 deletion infra/schema/src/test/resources/common/resource-opendj.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2014 Evolveum
~ Copyright (c) 2010-2016 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 @@ -66,6 +66,7 @@
</q:value>
</q:equal>
</filter>
<resolutionTime>import</resolutionTime>
<description>Reference to the ICF LDAP connector.</description>
</connectorRef>

Expand Down

0 comments on commit 0cfe5d9

Please sign in to comment.