Skip to content

Commit

Permalink
Reworking LookupTable to a more generic "relational object".
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 2, 2015
1 parent 0689dd4 commit 6741255
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 99 deletions.
24 changes: 22 additions & 2 deletions infra/prism/src/main/resources/xml/ns/public/annotation-3.xsd
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ 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 @@ -25,7 +25,7 @@
<xsd:documentation>
Common Prism annotations used in various XSD schemas.

Version: 3.1
Version: 3.2-SNAPSHOT
Default prefix: a
</xsd:documentation>
</xsd:annotation>
Expand Down Expand Up @@ -170,6 +170,26 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>

<xsd:element name="expensive" type="xsd:boolean">
<xsd:annotation>
<xsd:documentation>
Marks an expensive item. Expensive items are not returned from some operations
by default. They have to be explicitly requested.
</xsd:documentation>
</xsd:annotation>
</xsd:element>

<xsd:element name="relational" type="xsd:boolean">
<xsd:annotation>
<xsd:documentation>
Marks a container that contains relational data. The relational container
provides data that are normally stored in a simple relational table.
The relational container must only contain primitive items (properties or references, not containers).
It is expected that relational container will have many values.
</xsd:documentation>
</xsd:annotation>
</xsd:element>

<xsd:element name="extension" type="xsd:QName">
<xsd:annotation>
Expand Down
Expand Up @@ -53,12 +53,12 @@ public class GetOperationOptions implements Serializable, Cloneable {
* but they will be most likely omitted from the result.</li>
* </ul>
*/
RetrieveOption retrieve;
private RetrieveOption retrieve;

/**
* Resolve the object reference. This only makes sense with a (path-based) selector.
*/
Boolean resolve;
private Boolean resolve;

/**
* Resolve the object reference names. (Currently applicable only as a top-level option.)
Expand All @@ -67,27 +67,29 @@ public class GetOperationOptions implements Serializable, Cloneable {
*
* EXPERIMENTAL.
*/
Boolean resolveNames;
private Boolean resolveNames;

/**
* No not fetch any information from external sources, e.g. do not fetch account data from resource,
* do not fetch resource schema, etc.
* Such operation returns only the data stored in midPoint repository.
*/
Boolean noFetch;
private Boolean noFetch;

/**
* Avoid any smart processing of the data except for schema application. Do not synchronize the data, do not apply
* any expressions, etc.
*/
Boolean raw;
private Boolean raw;

/**
* Force to get object from the resource even if some of the error occurred.
* If the any copy of the shadow is fetched, we can't delete this object
* from the gui, for example
*/
Boolean doNotDiscovery;
private Boolean doNotDiscovery;

private RelationalValueSearchQuery relationalValueSearchQuery;

/**
* This flag indicated if the "object not found" error is critical for
Expand Down
@@ -0,0 +1,93 @@
/**
* Copyright (c) 2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.schema;

import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.query.ObjectPaging;

/**
* @author semancik
*
*/
public class RelationalValueSearchQuery {
private QName column;
private String searchValue;
private RelationalValueSearchType searchType;
private ObjectPaging paging;

public RelationalValueSearchQuery(QName column, String searchValue, RelationalValueSearchType searchType,
ObjectPaging paging) {
super();
this.column = column;
this.searchValue = searchValue;
this.searchType = searchType;
this.paging = paging;
}

public RelationalValueSearchQuery(QName column, String searchValue, RelationalValueSearchType searchType) {
super();
this.column = column;
this.searchValue = searchValue;
this.searchType = searchType;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((column == null) ? 0 : column.hashCode());
result = prime * result + ((paging == null) ? 0 : paging.hashCode());
result = prime * result + ((searchType == null) ? 0 : searchType.hashCode());
result = prime * result + ((searchValue == null) ? 0 : searchValue.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
RelationalValueSearchQuery other = (RelationalValueSearchQuery) obj;
if (column == null) {
if (other.column != null)
return false;
} else if (!column.equals(other.column))
return false;
if (paging == null) {
if (other.paging != null)
return false;
} else if (!paging.equals(other.paging))
return false;
if (searchType != other.searchType)
return false;
if (searchValue == null) {
if (other.searchValue != null)
return false;
} else if (!searchValue.equals(other.searchValue))
return false;
return true;
}

@Override
public String toString() {
return "RelationalValueSearchQuery(column=" + column + ", searchValue=" + searchValue
+ ", searchType=" + searchType + ", paging=" + paging + ")";
}
}
Expand Up @@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.repo.api;
package com.evolveum.midpoint.schema;

/**
* @author semancik
*
*/
public enum LookupTableSearchType {
public enum RelationalValueSearchType {
EXACT, STARTS_WITH, SUBSTRING;
}
26 changes: 8 additions & 18 deletions infra/schema/src/main/resources/xml/ns/public/common/common-3.xsd
Expand Up @@ -7421,7 +7421,7 @@
<xsd:complexContent>
<xsd:extension base="c:ObjectType">
<xsd:sequence>
<xsd:element name="table" type="tns:LookupTableTableType" minOccurs="0"/>
<xsd:element name="table" type="tns:LookupTableTableType" minOccurs="0" maxOccurs="unbounded"/>
<!-- TODO: Maybe more settings describing the intended use of the lookup table. -->
<!-- TODO: Lookup table synchronization settings? (e.g. resourceRef) -->
</xsd:sequence>
Expand All @@ -7434,29 +7434,18 @@
<xsd:annotation>
<xsd:documentation>
Data structure that represents entire content of the lookup table.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="row" type="tns:LookupTableRowType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:long" use="optional"/>
</xsd:complexType>

<xsd:complexType name="LookupTableRowType">
<xsd:annotation>
<xsd:documentation>
Lookup table row. The table row is a (complex) property. It is intentionally not
a container, so we can avoid maintaining container IDs for each row. The delta semantics
has a slightly different meaning for the lookup tables. Each key must be unique and the key
The delta semantics has a slightly different meaning for the lookup tables. Each key must be unique and the key
functions as an implicit identifier. E.g. adding a new row with a key that does not exist yet
will insert a new row. Adding a new row with key that already exists will overwrite existing row.
Replace operation on this property will efficiently clear the entire table and replace it with a new data.
We do not recommend using this operation as it may be very inefficient. Add and delete operations are
expected during normal operation.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
<a:relational/>
<a:expensive/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="key" type="xsd:string" minOccurs="1" maxOccurs="1">
Expand Down Expand Up @@ -7515,6 +7504,7 @@
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:long" use="optional"/>
</xsd:complexType>

<!-- OPERATIONAL SCHEMA -->
Expand Down
Expand Up @@ -14,7 +14,6 @@
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableTableType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType;
Expand Down Expand Up @@ -88,24 +87,21 @@ private void assertTable(PrismObject<LookupTableType> table) {
assertPropertyValue(table, "description", "description of lookup table");
assertPropertyDefinition(table, "description", DOMUtil.XSD_STRING, 0, 1);
PrismContainer<LookupTableTableType> tableContainer = table.findContainer(LookupTableType.F_TABLE);
assertEquals("wrong number of tables", 1, tableContainer.size());
PrismContainerValue<LookupTableTableType> tableValue = tableContainer.getValue();
PrismProperty rowsProperty = tableValue.findProperty(LookupTableTableType.F_ROW);
assertEquals("wrong number of rows", 2, rowsProperty.size());
assertRow((PrismPropertyValue) rowsProperty.getValue(0),
assertEquals("wrong number of rows", 2, tableContainer.size());
assertRow(tableContainer.getValue(0),
"first key",
"first value",
PrismTestUtil.createPolyStringType("first label"),
XmlTypeConverter.createXMLGregorianCalendar("2013-05-07T10:38:21.350+02:00"));
assertRow((PrismPropertyValue) rowsProperty.getValue(1),
assertRow(tableContainer.getValue(1),
"2 key",
"2 value",
PrismTestUtil.createPolyStringType("second ľábeľ", "second label"),
XmlTypeConverter.createXMLGregorianCalendar("2013-05-07T10:40:21.350+02:00"));
}

private void assertRow(PrismPropertyValue<LookupTableRowType> rowValue, String key, String value, PolyStringType label, XMLGregorianCalendar lastChangeTimestamp) {
LookupTableRowType row = rowValue.getValue();
private void assertRow(PrismContainerValue<LookupTableTableType> tableContainerValue, String key, String value, PolyStringType label, XMLGregorianCalendar lastChangeTimestamp) {
LookupTableTableType row = tableContainerValue.asContainerable();
assertEquals("wrong key", key, row.getKey());
assertEquals("wrong value", value, row.getValue());
assertEquals("wrong label", label, row.getLabel());
Expand Down
6 changes: 2 additions & 4 deletions infra/schema/src/test/resources/common/lookup-table.xml
Expand Up @@ -21,20 +21,18 @@
<name>first lookup</name>
<description>description of lookup table</description>
<table>
<row>
<key>first key</key>
<value>first value</value>
<label>first label</label>
<lastChangeTimestamp>2013-05-07T10:38:21.350+02:00</lastChangeTimestamp>
</row>
<row>
</table>
<table>
<key>2 key</key>
<value>2 value</value>
<label>
<t:orig>second ľábeľ</t:orig>
<t:norm>second label</t:norm>
</label>
<lastChangeTimestamp>2013-05-07T10:40:21.350+02:00</lastChangeTimestamp>
</row>
</table>
</lookupTable>
Expand Up @@ -26,6 +26,7 @@
import com.evolveum.midpoint.prism.query.ObjectPaging;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.RelationalValueSearchType;
import com.evolveum.midpoint.schema.RepositoryDiag;
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.SearchResultList;
Expand All @@ -38,7 +39,6 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
Expand Down Expand Up @@ -478,29 +478,6 @@ <F extends FocusType> PrismObject<F> searchShadowOwner(String shadowOid, Collect
<T extends ShadowType> List<PrismObject<T>> listResourceObjectShadows(String resourceOid,
Class<T> resourceObjectShadowType, OperationResult parentResult) throws ObjectNotFoundException,
SchemaException;

/**
* <p>Select specified rows from the lookup table.</p>
* <p>
* This operation works only on lookup tables. If OID of any other object
* is specified as a parameter it results in an error.
* </p>
*
* @param lookupTableOid OID of the lookup table
* @param column name of the column to search
* @param searchValue value to search for
* @param searchType type of search (exact, substring, ...)
* @param paging paging parameters (page offset and size)
* @return selected table rows
*
* @throws ObjectNotFoundException
* specified object does not exist
* @throws SchemaException
* object is not of type {@link LookupTableType}
*/
List<LookupTableRowType> searchLookupTable(String lookupTableOid, QName column, String searchValue,
LookupTableSearchType searchType, ObjectPaging paging) throws ObjectNotFoundException,
SchemaException;

/**
* Provide repository run-time configuration and diagnostic information.
Expand Down
Expand Up @@ -20,10 +20,10 @@
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.query.ObjectPaging;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.repo.api.LookupTableSearchType;
import com.evolveum.midpoint.repo.api.RepoAddOptions;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.RelationalValueSearchType;
import com.evolveum.midpoint.schema.RepositoryDiag;
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.SearchResultList;
Expand All @@ -36,7 +36,6 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
Expand Down Expand Up @@ -353,11 +352,4 @@ private void log(String message, Object... params) {
PERFORMANCE_ADVISOR.trace(message, params);
}
}

@Override
public List<LookupTableRowType> searchLookupTable(String lookupTableOid, QName column,
String searchValue, LookupTableSearchType searchType, ObjectPaging paging)
throws ObjectNotFoundException, SchemaException {
return repository.searchLookupTable(lookupTableOid, column, searchValue, searchType, paging);
}
}

0 comments on commit 6741255

Please sign in to comment.