Skip to content

Commit

Permalink
Form evolution (validation) - work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed May 30, 2018
1 parent 0abdea7 commit cb5916c
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 7 deletions.
Expand Up @@ -758,6 +758,16 @@ public boolean isReferenceMarker() {
public Collection<TypeDefinition> getStaticSubTypes() {
return emptySet();
}

@Override
public Object getAnnotation(QName qname) {
return structuralObjectClassDefinition.getAnnotation(qname);
}

@Override
public void setAnnotation(QName qname, Object value) {
structuralObjectClassDefinition.setAnnotation(qname, value);
}

@Override
public Integer getInstantiationOrder() {
Expand Down
Expand Up @@ -658,6 +658,16 @@ public boolean canBeDefinitionOf(PrismProperty<T> item) {
public boolean canBeDefinitionOf(PrismValue pvalue) {
return refinedAttributeDefinition.canBeDefinitionOf(pvalue);
}

@Override
public Object getAnnotation(QName qname) {
return refinedAttributeDefinition.getAnnotation(qname);
}

@Override
public void setAnnotation(QName qname, Object value) {
refinedAttributeDefinition.setAnnotation(qname, value);
}

@Override
public String toString() {
Expand Down
Expand Up @@ -672,6 +672,16 @@ public boolean isShared() {
public Collection<TypeDefinition> getStaticSubTypes() {
return emptySet(); // not supported for now (this type itself is not statically defined)
}

@Override
public Object getAnnotation(QName qname) {
return refinedObjectClassDefinition.getAnnotation(qname);
}

@Override
public void setAnnotation(QName qname, Object value) {
refinedObjectClassDefinition.setAnnotation(qname, value);
}

@Override
public Integer getInstantiationOrder() {
Expand Down
Expand Up @@ -1346,6 +1346,16 @@ public boolean isShared() {
return shared;
}

@Override
public Object getAnnotation(QName qname) {
return originalObjectClassDefinition.getAnnotation(qname);
}

@Override
public void setAnnotation(QName qname, Object value) {
throw new UnsupportedOperationException("TODO");
}

@Override
public Integer getInstantiationOrder() {
return null;
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 @@ -168,6 +168,24 @@ default SchemaRegistry getSchemaRegistry() {

// todo suspicious, please investigate and document
Class getTypeClass();

/**
* Returns generic definition annotation. Annotations are a method to
* extend schema definitions.
* This may be annotation stored in the schema definition file (e.g. XSD)
* or it may be a dynamic annotation determined at run-time.
*
* Annotation value should be a prism-suported object. E.g. a prims "bean"
* (JAXB annotated class), prism item, prism value or something like that.
*
* EXPERIMENTAL. Hic sunt liones. This may change at any moment.
*
* Note: annotations are only partially supported now (3.8).
* They are somehow transient. E.g. they are not serialized to
* XSD schema definitions (yet).
*/
Object getAnnotation(QName qname);
void setAnnotation(QName qname, Object value);

@NotNull
Definition clone();
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 @@ -17,12 +17,14 @@
package com.evolveum.midpoint.prism;

import com.evolveum.midpoint.prism.xml.XsdTypeMapper;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;

import javax.xml.namespace.QName;

/**
Expand Down Expand Up @@ -61,6 +63,7 @@ public abstract class DefinitionImpl implements Definition {
protected String deprecatedSince;
protected boolean experimental = false;
protected boolean elaborate = false;
private Map<QName,Object> annotations;

/**
* whether an item is inherited from a supertype (experimental feature)
Expand Down Expand Up @@ -243,6 +246,25 @@ public Class getTypeClass() {
return XsdTypeMapper.toJavaType(getTypeName());
}

@Override
public Object getAnnotation(QName qname) {
if (annotations == null) {
return null;
} else {
return annotations.get(qname);
}
}

@Override
public void setAnnotation(QName qname, Object value) {
if (annotations == null) {
// Lazy init. Most definitions will not have any annotations.
// We do not want to fill memory with empty hashmaps.
annotations = new HashMap<>();
}
annotations.put(qname, value);
}

public abstract void revive(PrismContext prismContext);

protected void copyDefinitionData(DefinitionImpl clone) {
Expand Down
Expand Up @@ -6666,6 +6666,20 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<!-- TODO: display as FormItemDisplayType -->
<xsd:element name="validation" type="tns:FormItemValidationType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Validation rules for the item. Validation rule may be applied in the
user interface. But server-side validation may also be applied during
the computation process.
</xsd:documentation>
<xsd:appinfo>
<a:since>3.8</a:since>
<a:experimental>true</a:experimental>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

Expand Down Expand Up @@ -19124,26 +19138,56 @@
used to override this default behavior. It is used for default included
types like text, label, combo, password, checkbox, etc. or class name for
custom implementation.

NOTE: widget was never really working it will probably not work. It is deprecated
now. Later on it will be replaced by an equivalent setting in FormItemDisplayType.
</xsd:documentation>
<xsd:appinfo>
<a:deprecated>true</a:deprecated>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<!-- Note: available values are defined by the "set" in the binding. -->
<xsd:element name="validation" type="tns:FormItemValidationType" minOccurs="0" />
<xsd:element name="validation" type="tns:FormItemValidationType" minOccurs="0">

</xsd:element>
<!-- TODO: condition -->
</xsd:sequence>
</xsd:complexType>
<xsd:element name="formItem" type="tns:AbstractFormItemType" abstract="true" />

<xsd:complexType name="FormItemValidationType">
<xsd:annotation>
<xsd:documentation>
Validation rules for the item. Validation rule may be applied in the
user interface. But server-side validation may also be applied during
the computation process.
</xsd:documentation>
<xsd:appinfo>
<a:experimental>true</a:experimental>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="server" type="xsd:string" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="server" type="tns:FormItemServerValidationType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
<!--TODO -->
Server-side validation.
</xsd:documentation>
<xsd:appinfo>
<a:experimental>true</a:experimental>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="client" type="tns:FormItemClientValidationType" minOccurs="0" />
<xsd:element name="client" type="tns:FormItemClientValidationType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Client-side validation.
</xsd:documentation>
<xsd:appinfo>
<a:experimental>true</a:experimental>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

Expand All @@ -19156,12 +19200,43 @@

TODO: add event type attribute to client element for this validator
</xsd:documentation>
<xsd:appinfo>
<a:experimental>true</a:experimental>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="event" type="xsd:string" minOccurs="1" maxOccurs="unbounded" />
<xsd:element name="script" type="xsd:string" minOccurs="1" />
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="FormItemServerValidationType">
<xsd:annotation>
<xsd:documentation>
Server-side validation rules.
</xsd:documentation>
<xsd:appinfo>
<a:experimental>true</a:experimental>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="expression" type="tns:ExpressionType" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
Validation expression. Value of the validated input will be passed as expression variable.
The expression is supposed to return operation result (OperationResult) indicating success,
failure and providing an optional message.
Null output is considered to be validation success.
</xsd:documentation>
<xsd:appinfo>
<a:since>3.8</a:since>
<a:experimental>true</a:experimental>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<!-- TODO later: limitation of the validation (e.g. GUI-only, projector-only, ... -->
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="FormFieldType">
<xsd:annotation>
Expand Down

0 comments on commit cb5916c

Please sign in to comment.