Skip to content

Commit

Permalink
Merge branch 'feature/simulations' of github.com:Evolveum/midpoint in…
Browse files Browse the repository at this point in the history
…to feature/simulations
  • Loading branch information
1azyman committed Dec 19, 2022
2 parents c019e29 + e788b07 commit 08274d8
Show file tree
Hide file tree
Showing 17 changed files with 266 additions and 20 deletions.
13 changes: 13 additions & 0 deletions config/sql/generic-old/h2-4.6-all.sql
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,13 @@ CREATE TABLE m_generic_object (
oid VARCHAR(36) NOT NULL,
PRIMARY KEY (oid)
);
CREATE TABLE m_tag (
name_norm VARCHAR(255),
name_orig VARCHAR(255),
objectType VARCHAR(255),
oid VARCHAR(36) NOT NULL,
PRIMARY KEY (oid)
);
CREATE TABLE m_global_metadata (
name VARCHAR(255) NOT NULL,
value VARCHAR(255),
Expand Down Expand Up @@ -952,6 +959,10 @@ CREATE INDEX iGenericObjectNameOrig
ON m_generic_object (name_orig);
ALTER TABLE m_generic_object
ADD CONSTRAINT uc_generic_object_name UNIQUE (name_norm);
CREATE INDEX iTagNameOrig
ON m_tag (name_orig);
ALTER TABLE m_tag
ADD CONSTRAINT uc_tag_name UNIQUE (name_norm);
CREATE INDEX iLookupTableNameOrig
ON m_lookup_table (name_orig);
ALTER TABLE m_lookup_table
Expand Down Expand Up @@ -1172,6 +1183,8 @@ ALTER TABLE m_function_library
ADD CONSTRAINT fk_function_library FOREIGN KEY (oid) REFERENCES m_object;
ALTER TABLE m_generic_object
ADD CONSTRAINT fk_generic_object FOREIGN KEY (oid) REFERENCES m_focus;
ALTER TABLE m_tag
ADD CONSTRAINT fk_tag FOREIGN KEY (oid) REFERENCES m_object;
ALTER TABLE m_lookup_table
ADD CONSTRAINT fk_lookup_table FOREIGN KEY (oid) REFERENCES m_object;
ALTER TABLE m_lookup_table_row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public enum ObjectTypeGuiDescriptor {

GENERIC_OBJECT(ObjectTypes.GENERIC_OBJECT, "ObjectTypeGuiDescriptor.genericObject", "silk-page_white_code", "silk-page_white_code"),

TAG(ObjectTypes.TAG, "ObjectTypeGuiDescriptor.tag", "silk-page_white_code", "silk-page_white_code"),

RESOURCE(ObjectTypes.RESOURCE, "ObjectTypeGuiDescriptor.resource", GuiStyleConstants.CLASS_OBJECT_RESOURCE_ICON_COLORED, GuiStyleConstants.CLASS_OBJECT_RESOURCE_ICON),

USER(ObjectTypes.USER, "ObjectTypeGuiDescriptor.user", GuiStyleConstants.CLASS_OBJECT_USER_ICON_COLORED, GuiStyleConstants.CLASS_OBJECT_USER_ICON),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public enum ObjectTypes {
GENERIC_OBJECT(SchemaConstants.C_GENERIC_OBJECT_TYPE,
SchemaConstants.C_GENERIC_OBJECT, GenericObjectType.class, ObjectManager.MODEL, "genericObjects"),

TAG(TagType.COMPLEX_TYPE,
SchemaConstantsGenerated.C_TAG, TagType.class, ObjectManager.MODEL, "tags"),

RESOURCE(SchemaConstants.C_RESOURCE_TYPE, SchemaConstants.C_RESOURCE,
ResourceType.class, ObjectManager.PROVISIONING, "resources"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<xsd:include schemaLocation="http://midpoint.evolveum.com/xml/ns/public/common/common-gui-3" />
<xsd:include schemaLocation="http://midpoint.evolveum.com/xml/ns/public/common/common-provisioning-3" />
<xsd:include schemaLocation="http://midpoint.evolveum.com/xml/ns/public/common/common-correlation-3" />
<xsd:include schemaLocation="http://midpoint.evolveum.com/xml/ns/public/common/common-simulations-3" />

<!-- ################################## -->
<!-- ## Common Schema Layer ## -->
Expand Down Expand Up @@ -758,6 +759,61 @@
</xsd:complexType>
<xsd:element name="genericObject" type="tns:GenericObjectType" substitutionGroup="tns:object"/>

<xsd:complexType name="TagType">
<xsd:annotation>
<xsd:documentation>
A tag is a "mark" given to an object - currently a prism object, an assignment, or audited/simulation event.
Tags are used in various contexts, for example as policy situations or event tags. (More uses are expected
in the future.) This object serves as a point of definition of such tags.

Well-known archetypes: policy situation, event tag.
</xsd:documentation>
<xsd:appinfo>
<a:since>4.7</a:since>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:AssignmentHolderType">
<xsd:sequence>
<xsd:element name="uri" type="xsd:anyURI" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Optional URI assigned to this tag. For example, policy situations had traditionally such URIs.
It should be globally unique.
</xsd:documentation>
<xsd:appinfo>
<a:displayName>TagType.uri</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="display" type="tns:DisplayType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Display properties of the tag. It is used to display the tag in drop-down lists, buttons, etc..
</xsd:documentation>
<xsd:appinfo>
<a:displayName>TagType.display</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="policyRule" type="tns:GlobalPolicyRuleType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Global policy rules that can yield this tag (policy situation or event tag).
By including them here they are evaluated automatically, just like if they would be included
in the system configuration. (Provided that this tag is in appropriate lifecycle state.)
</xsd:documentation>
<xsd:appinfo>
<a:displayName>TagType.uri</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="tag" type="tns:TagType" substitutionGroup="tns:object"/>

<xsd:complexType name="TriggerType">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -14592,13 +14648,14 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="tag" type="xsd:string" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="tagRef" type="tns:ObjectReferenceType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Tag(s) that are the result when this policy rule is triggered.
TODO if this is an URI, what is the default namespace?
These may be implicit if the policy rule is defined as part of tag definition.
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>c:TagType</a:objectReferenceTargetType>
<a:displayName>PolicyRuleType.tag</a:displayName>
<a:help>PolicyRuleType.tag.help</a:help>
<a:since>4.7</a:since>
Expand All @@ -14612,10 +14669,15 @@
triggered. If the situation is not explicitly stated then
default situation will be selected instead. The situation
is determined by the constraint that triggered the rule.
DEPRECATED. Use tagRef instead.

TODO specify the time of planned removal
</xsd:documentation>
<xsd:appinfo>
<a:displayName>PolicyRuleType.policySituation</a:displayName>
<a:help>PolicyRuleType.policySituation.help</a:help>
<a:deprecated>true</a:deprecated>
<a:deprecatedSince>4.7</a:deprecatedSince>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@
<xsd:element name="record" type="tns:RecordPolicyActionType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Record action. The operation will proceed. Policy situation will be recorded for
Record action. The operation will proceed. Policy situation(s) will be recorded for
given object or assignment. It can be reported on or certified later on.
</xsd:documentation>
<xsd:appinfo>
Expand Down Expand Up @@ -2171,6 +2171,7 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<!-- TODO we may select what situation(s) we want to record. The default is all applicable ones. -->
<!--<xsd:element name="situationConstraints" type="tns:SituationConstraintsStorageStrategyType" minOccurs="0">-->
<!--<xsd:annotation>-->
<!--<xsd:documentation>-->
Expand All @@ -2179,7 +2180,6 @@
<!--</xsd:documentation>-->
<!--</xsd:annotation>-->
<!--</xsd:element>-->

</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.evolveum.midpoint.model.impl.lens.projector.policy.ObjectState;
import com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleEvaluationContext;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.impl.binding.AbstractReferencable;
import com.evolveum.midpoint.prism.util.CloneUtil;
import com.evolveum.midpoint.prism.util.PrismPrettyPrinter;
import com.evolveum.midpoint.repo.common.expression.ExpressionFactory;
Expand Down Expand Up @@ -528,7 +529,9 @@ public void setCount(int value) {

@NotNull Collection<String> getEventTags() {
if (isTriggered()) {
return policyRuleBean.getTag();
return policyRuleBean.getTagRef().stream()
.map(AbstractReferencable::getOid)
.collect(Collectors.toSet());
} else {
return Set.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@

import static com.evolveum.midpoint.schema.constants.SchemaConstants.*;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import com.evolveum.midpoint.test.TestResource;

import org.testng.SkipException;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -776,9 +779,12 @@ private void assertTest300UserDeltas(Collection<ObjectDelta<?>> simulatedDeltas,

// TEMPORARY
@SafeVarargs
private void assertUserTags(SimulationResult simResult, String... expectedTags) {
private void assertUserTags(SimulationResult simResult, TestResource<TagType>... expectedTags) {
Collection<String> realTagsOids = simResult.getTagsForObjectType(UserType.class);
assertThat(realTagsOids).as("event tags").containsExactlyInAnyOrder(expectedTags);
Set<String> expectedTagsOids = Arrays.stream(expectedTags)
.map(r -> r.oid)
.collect(Collectors.toSet());
assertThat(realTagsOids).as("event tags").containsExactlyInAnyOrderElementsOf(expectedTagsOids);
}

private boolean isDevelopmentConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,18 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import javax.xml.namespace.QName;
import java.io.File;

import static com.evolveum.midpoint.schema.constants.SchemaConstants.NS_MODEL;
import static com.evolveum.midpoint.schema.constants.SchemaConstants.RI_ACCOUNT_OBJECT_CLASS;
import static com.evolveum.midpoint.util.QNameUtil.qNameToUri;

public class AbstractSimulationsTest extends AbstractEmptyModelIntegrationTest {

private static final File SIM_TEST_DIR = new File("src/test/resources/simulation");

// TEMPORARY
private static final String NS_MODEL_EVENT = NS_MODEL + "/event";
static final String TAG_USER_ADD = qNameToUri(new QName(NS_MODEL_EVENT, "userAdd"));
@SuppressWarnings("unused")
static final String TAG_USER_DELETE = qNameToUri(new QName(NS_MODEL_EVENT, "userDelete"));
static final TestResource<TagType> TAG_USER_ADD = new TestResource<>(
SIM_TEST_DIR, "tag-user-add.xml", "0c31f3a1-a7b1-4fad-8cea-eaafdc15daaf");
private static final TestResource<TagType> TAG_USER_DELETE = new TestResource<>(
SIM_TEST_DIR, "tag-user-delete.xml", "caa2921a-6cf4-4e70-ad2b-bfed278e29cf");

private static final TestResource<RoleType> ROLE_PERSON = new TestResource<>(
SIM_TEST_DIR, "role-person.xml", "ba88cf08-06bc-470f-aeaa-511e86d5ea7f");
Expand Down Expand Up @@ -86,6 +82,9 @@ public class AbstractSimulationsTest extends AbstractEmptyModelIntegrationTest {
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);

repoAdd(TAG_USER_ADD, initResult);
repoAdd(TAG_USER_DELETE, initResult);

repoAdd(ROLE_PERSON, initResult);
repoAdd(ROLE_PERSON_DEV, initResult);
repoAdd(METAROLE, initResult);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~ Copyright (C) 2010-2022 Evolveum and contributors
~ Copyright (c) 2020 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
Expand All @@ -15,7 +15,7 @@
<operation>add</operation>
</modification>
</policyConstraints>
<tag>http://midpoint.evolveum.com/xml/ns/public/model/event#userAdd</tag>
<tagRef oid="0c31f3a1-a7b1-4fad-8cea-eaafdc15daaf"/>
<focusSelector>
<type>UserType</type>
</focusSelector>
Expand All @@ -26,7 +26,7 @@
<operation>delete</operation>
</modification>
</policyConstraints>
<tag>http://midpoint.evolveum.com/xml/ns/public/model/event#userDelete</tag>
<tagRef oid="caa2921a-6cf4-4e70-ad2b-bfed278e29cf"/>
<focusSelector>
<type>UserType</type>
</focusSelector>
Expand Down
11 changes: 11 additions & 0 deletions model/model-intest/src/test/resources/simulation/tag-user-add.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!--
~ Copyright (C) 2010-2022 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<tag xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="0c31f3a1-a7b1-4fad-8cea-eaafdc15daaf">
<name>user-add</name>
</tag>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!--
~ Copyright (C) 2010-2022 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<tag xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="caa2921a-6cf4-4e70-ad2b-bfed278e29cf">
<name>user-delete</name>
</tag>
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class BaseSQLRepoTest extends AbstractSpringTest

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

private static final String NS_EXT = "http://example.com/p";
protected static final String NS_EXT = "http://example.com/p";

static final ItemName EXT_HIDDEN1 = new ItemName(NS_EXT, "hidden1");
static final ItemName EXT_HIDDEN2 = new ItemName(NS_EXT, "hidden2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,42 @@ public void test018QueryGenericLongTwice() throws Exception {
}

@Test
public void test019QueryAccountByNonExistingAttribute() throws Exception {
public void test020QueryTagLong() throws Exception {
Session session = open();
try {

ObjectQuery query = prismContext.queryFor(TagType.class)
.item(F_NAME).eqPoly("tag1")
.and().item(F_EXTENSION, new QName(NS_EXT, "intType")).eq(123)
.build();
String real = getInterpretedQuery(session, TagType.class, query);

assertThat(real).isEqualToIgnoringWhitespace(""
+ "select\n"
+ " _t.oid,\n"
+ " _t.fullObject\n"
+ "from\n"
+ " RTag _t\n"
+ " left join _t.longs _l with (\n"
+ "_l.ownerType = :ownerType and\n"
+ "_l.itemId = :itemId\n"
+ ")\n"
+ "where\n"
+ " (\n"
+ " (\n"
+ " _t.nameCopy.orig = :orig and\n"
+ " _t.nameCopy.norm = :norm\n"
+ " ) and\n"
+ " _l.value = :value\n"
+ " )");

} finally {
close(session);
}
}

@Test
public void test029QueryAccountByNonExistingAttribute() throws Exception {
Session session = open();
try {
String real = getInterpretedQuery(session, ShadowType.class,
Expand Down

0 comments on commit 08274d8

Please sign in to comment.