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 Sep 5, 2018
2 parents 04534fe + d6292da commit 6ed8e1b
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 108 deletions.
Expand Up @@ -44,13 +44,8 @@

import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.*;

import static java.util.Collections.emptySet;
import static java.util.Collections.singleton;
import static org.apache.commons.collections4.CollectionUtils.emptyIfNull;

/**
Expand Down Expand Up @@ -872,4 +867,40 @@ public static <O extends ObjectType> XMLGregorianCalendar getLastTouchTimestamp(
}
return metadata.getCreateTimestamp();
}

@NotNull
public static List<Item<?, ?>> mapToExtensionItems(Map<QName, Object> values, PrismContainerDefinition<?> extensionDefinition,
PrismContext prismContext) throws SchemaException {
List<Item<?, ?>> extensionItems = new ArrayList<>();
for (Map.Entry<QName, Object> entry : values.entrySet()) {
ItemDefinition<Item<PrismValue, ItemDefinition>> def = extensionDefinition != null
? extensionDefinition.findItemDefinition(entry.getKey())
: null;
if (def == null) {
//noinspection unchecked
def = prismContext.getSchemaRegistry().findItemDefinitionByElementName(entry.getKey()); // a bit of hack here
if (def == null) {
throw new SchemaException("No definition of " + entry.getKey() + " in task extension");
}
}
Item<PrismValue, ItemDefinition> extensionItem = def.instantiate();
if (entry.getValue() != null) {
if (entry.getValue() instanceof Collection) {
for (Object value : (Collection) entry.getValue()) {
addRealValue(extensionItem, value);
}
} else {
addRealValue(extensionItem, entry.getValue());
}
}
extensionItems.add(extensionItem);
}
return extensionItems;
}

private static void addRealValue(Item<PrismValue, ItemDefinition> extensionItem, Object value) throws SchemaException {
if (value != null) {
extensionItem.add(PrismValue.fromRealValue(value).clone());
}
}
}
Expand Up @@ -20,12 +20,7 @@
import java.text.Normalizer;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -37,8 +32,10 @@
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -551,6 +548,16 @@ public Collection<String> getAttributeStringValues(ShadowType shadow, javax.xml.
return ShadowUtil.getAttributeValues(shadow, attributeQname, String.class);
}

public void setExtensionRealValues(PrismContainerValue<?> containerValue, Map<String, Object> map) throws SchemaException {
PrismContainer<Containerable> ext = containerValue.findOrCreateContainer(ObjectType.F_EXTENSION);
Map<QName, Object> qnameKeyedMap = new HashMap<>();
map.forEach((uri, value) -> qnameKeyedMap.put(QNameUtil.uriToQName(uri, true), value));
List<Item<?, ?>> items = ObjectTypeUtil.mapToExtensionItems(qnameKeyedMap, ext.getDefinition(), prismContext);
for (Item<?, ?> item : items) {
ext.getValue().addReplaceExisting(item);
}
}

public <T> T getIdentifierValue(ShadowType shadow) throws SchemaException {
if (shadow == null) {
return null;
Expand Down
Expand Up @@ -28,6 +28,7 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.repo.common.expression.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.Validate;
Expand Down Expand Up @@ -104,10 +105,6 @@
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.cache.RepositoryCache;
import com.evolveum.midpoint.repo.common.CacheRegistry;
import com.evolveum.midpoint.repo.common.expression.ExpressionFactory;
import com.evolveum.midpoint.repo.common.expression.ExpressionVariables;
import com.evolveum.midpoint.repo.common.expression.ItemDeltaItem;
import com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
Expand Down Expand Up @@ -1722,24 +1719,10 @@ public TaskType submitTaskFromTemplate(String templateTaskOid, List<Item<?, ?>>
public TaskType submitTaskFromTemplate(String templateTaskOid, Map<QName, Object> extensionValues, Task opTask, OperationResult parentResult)
throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException,
ConfigurationException, ExpressionEvaluationException, ObjectAlreadyExistsException, PolicyViolationException {
List<Item<?, ?>> extensionItems = new ArrayList<>();
PrismContainerDefinition<?> extDef = prismContext.getSchemaRegistry()
.findObjectDefinitionByCompileTimeClass(TaskType.class).findContainerDefinition(TaskType.F_EXTENSION);
for (Map.Entry<QName, Object> entry : extensionValues.entrySet()) {
ItemDefinition<Item<PrismValue, ItemDefinition>> def = extDef.findItemDefinition(entry.getKey());
if (def == null) {
//noinspection unchecked
def = prismContext.getSchemaRegistry().findItemDefinitionByElementName(entry.getKey()); // a bit of hack here
if (def == null) {
throw new SchemaException("No definition of " + entry.getKey() + " in task extension");
}
}
Item<PrismValue, ItemDefinition> extensionItem = def.instantiate();
if (entry.getValue() != null) {
extensionItem.add(PrismValue.fromRealValue(entry.getValue()).clone());
}
extensionItems.add(extensionItem);
}
List<Item<?, ?>> extensionItems = ObjectTypeUtil.mapToExtensionItems(extensionValues, extDef, prismContext);
return submitTaskFromTemplate(templateTaskOid, extensionItems, opTask, parentResult);
}

}
Expand Up @@ -1020,11 +1020,11 @@ public void test013AddOpenDjAccountToUser() throws Exception {
REQUEST_USER_MODIFY_ADD_ACCOUNT_OPENDJ_FILENAME, ObjectDeltaType.class);

// WHEN
TestUtil.displayWhen(TEST_NAME);
displayWhen(TEST_NAME);
OperationResultType result = modifyObjectViaModelWS(objectChange);

// THEN
TestUtil.displayThen(TEST_NAME);
displayThen(TEST_NAME);
assertNoRepoCache();
displayJaxb("modifyObject result", result, SchemaConstants.C_RESULT);
TestUtil.assertSuccess("modifyObject has failed", result);
Expand Down Expand Up @@ -1657,11 +1657,11 @@ public void test030DisableUser() throws Exception {
assertNoRepoCache();

// WHEN
TestUtil.displayWhen(TEST_NAME);
displayWhen(TEST_NAME);
OperationResultType result = modifyObjectViaModelWS(objectChange);

// THEN
TestUtil.displayThen(TEST_NAME);
displayThen(TEST_NAME);
assertNoRepoCache();
displayJaxb("modifyObject result:", result, SchemaConstants.C_RESULT);
TestUtil.assertSuccess("modifyObject has failed", result);
Expand Down Expand Up @@ -1718,12 +1718,12 @@ public void test030DisableUser() throws Exception {
assertNoRepoCache();

// WHEN
TestUtil.displayWhen(TEST_NAME);
displayWhen(TEST_NAME);
modelWeb.getObject(ObjectTypes.SHADOW.getTypeQName(), accountShadowOidOpendj,
options, objectHolder, resultHolder);

// THEN
TestUtil.displayThen(TEST_NAME);
displayThen(TEST_NAME);
assertNoRepoCache();
displayJaxb("getObject result", resultHolder.value, SchemaConstants.C_RESULT);
TestUtil.assertSuccess("getObject has failed", resultHolder.value);
Expand Down Expand Up @@ -3135,11 +3135,11 @@ public void test400ImportFromResource() throws Exception {
display("Entry from LDIF", addEntry);

// WHEN
TestUtil.displayWhen(TEST_NAME);
displayWhen(TEST_NAME);
TaskType taskType = modelWeb.importFromResource(RESOURCE_OPENDJ_OID, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);

// THEN
TestUtil.displayThen(TEST_NAME);
displayThen(TEST_NAME);
assertNoRepoCache();
displayJaxb("importFromResource result", taskType.getResult(), SchemaConstants.C_RESULT);
AssertJUnit.assertEquals("importFromResource has failed", OperationResultStatusType.IN_PROGRESS, taskType.getResult().getStatus());
Expand Down
95 changes: 29 additions & 66 deletions testing/sanity/src/test/resources/repo/resource-opendj.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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 @@ -140,21 +140,15 @@ This is now the only account type that midPoint can work with. -->
name from user object and string constants.
The expression is marked as "default", therefore it will
be evaluated only if the entry already does not have an DN.
It is an XPath expression, similar to BPEL assignment expressions. -->
be evaluated only if the entry already does not have an DN. -->
<outbound>
<!-- Name cannot be weak. Changes in name trigger object rename. -->
<source>
<path>declare default namespace "http://midpoint.evolveum.com/xml/ns/public/common/common-3";$user/name</path>
<path>$focus/name</path>
</source>
<expression>
<script>
<language>http://www.w3.org/TR/xpath/</language>
<code>
declare namespace i="http://midpoint.evolveum.com/xml/ns/public/common/common-3";
concat('uid=', $i:name, ',ou=people,dc=example,dc=com')
</code>
<code>'uid=' + name + ',ou=people,dc=example,dc=com'</code>
</script>
</expression>
</outbound>
Expand Down Expand Up @@ -218,19 +212,14 @@ This is now the only account type that midPoint can work with. -->
<expression>
<script>
<relativityMode>absolute</relativityMode>
<language>http://www.w3.org/TR/xpath/</language>
<code>
declare namespace c="http://midpoint.evolveum.com/xml/ns/public/common/common-3";
declare namespace ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance/ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff";
func:determineLdapSingleAttributeValue($c:account/c:attributes/ri:dn, 'cn', $c:input)
dn = basic.getAttributeValues(projection, 'http://midpoint.evolveum.com/xml/ns/public/resource/instance/ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff', 'dn')
basic.determineLdapSingleAttributeValue(dn, 'cn', input)
</code>
</script>
</expression>
<target>
<path>
declare namespace i="http://midpoint.evolveum.com/xml/ns/public/common/common-3";
$i:user/i:fullName
</path>
<path>fullName</path>
</target>
</inbound>

Expand All @@ -248,15 +237,7 @@ This is now the only account type that midPoint can work with. -->
</source>
<expression>
<script>
<description>
The expression is using "c" and "t" prefixes without declaring it. The prefix is taken from
the enclosing XML definition.
</description>
<language>http://www.w3.org/TR/xpath/</language>
<code>
declare namespace c="http://midpoint.evolveum.com/xml/ns/public/common/common-3";
$c:familyName
</code>
<code>familyName</code>
</script>
</expression>
</outbound>
Expand All @@ -265,11 +246,9 @@ This is now the only account type that midPoint can work with. -->
<expression>
<script>
<relativityMode>absolute</relativityMode>
<language>http://www.w3.org/TR/xpath/</language>
<code>
declare namespace c="http://midpoint.evolveum.com/xml/ns/public/common/common-3";
declare namespace ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance/ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff";
func:determineLdapSingleAttributeValue($c:account/c:attributes/ri:dn, 'sn', $c:input)
dn = basic.getAttributeValues(projection, 'http://midpoint.evolveum.com/xml/ns/public/resource/instance/ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff', 'dn')
basic.determineLdapSingleAttributeValue(dn, 'sn', input)
</code>
</script>
</expression>
Expand Down Expand Up @@ -300,11 +279,10 @@ This is now the only account type that midPoint can work with. -->
<expression>
<script>
<relativityMode>absolute</relativityMode>
<language>http://www.w3.org/TR/xpath/</language>
<code>
declare namespace c="http://midpoint.evolveum.com/xml/ns/public/common/common-3";
declare namespace ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance/ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff";
func:determineLdapSingleAttributeValue($c:account/c:attributes/ri:dn, 'givenName', $c:input)</code>
dn = basic.getAttributeValues(projection, 'http://midpoint.evolveum.com/xml/ns/public/resource/instance/ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff', 'dn')
basic.determineLdapSingleAttributeValue(dn, 'givenName', input)
</code>
</script>
</expression>
<target>
Expand Down Expand Up @@ -411,11 +389,7 @@ This is now the only account type that midPoint can work with. -->
<strength>weak</strength>
<expression>
<script>
<language>http://www.w3.org/TR/xpath/</language>
<returnType>scalar</returnType>
<c:code>
concat('','')
</c:code>
<c:code>''</c:code>
</script>
</expression>
</outbound>
Expand Down Expand Up @@ -481,21 +455,12 @@ This is now the only account type that midPoint can work with. -->
</source>
<expression>
<script>
<language>http://www.w3.org/TR/xpath/</language>
<returnType>scalar</returnType>
<code>
declare namespace c="http://midpoint.evolveum.com/xml/ns/public/common/common-3";
concat('Number ',$c:employeeNumber)
</code>
<code>'Number ' + employeeNumber</code>
</script>
</expression>
<condition>
<script>
<language>http://www.w3.org/TR/xpath/</language>
<code>
declare namespace c="http://midpoint.evolveum.com/xml/ns/public/common/common-3";
$c:user/c:employeeNumber
</code>
<code>employeeNumber as boolean</code>
</script>
</condition>
</outbound>
Expand All @@ -518,14 +483,12 @@ This is now the only account type that midPoint can work with. -->
</source>
<expression>
<script>
<c:language>http://www.w3.org/TR/xpath/</c:language>
<c:returnType>scalar</c:returnType>
<code>
declare namespace c="http://midpoint.evolveum.com/xml/ns/public/common/common-3";
if (empty($c:user/c:locality)) then
if (locality?.trim()) {
locality
} else {
"middle of nowhere"
else
$c:user/c:locality
}
</code>
</script>
</expression>
Expand Down Expand Up @@ -656,16 +619,16 @@ This is now the only account type that midPoint can work with. -->
equal to the "uid" attribute of the account. Simply speaking,
it will look for match in usernames in the IDM and the resource. -->
<q:equal>
<q:path>declare namespace c="http://midpoint.evolveum.com/xml/ns/public/common/common-3";c:name</q:path>
<q:path>
declare namespace c="http://midpoint.evolveum.com/xml/ns/public/common/common-3";
c:name
</q:path>
<expression>
<script>
<language>http://www.w3.org/TR/xpath/</language>
<code>
declare namespace c="http://midpoint.evolveum.com/xml/ns/public/common/common-3";
declare namespace dj="http://midpoint.evolveum.com/xml/ns/public/resource/instance/ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff";
$c:account/c:attributes/dj:uid
</code>
</script>
<path>
declare namespace c="http://midpoint.evolveum.com/xml/ns/public/common/common-3";
declare namespace dj="http://midpoint.evolveum.com/xml/ns/public/resource/instance/ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff";
$c:account/c:attributes/dj:uid
</path>
</expression>
</q:equal>
</c:correlation>
Expand Down
2 changes: 0 additions & 2 deletions testing/sanity/src/test/resources/request/herman.ldif
@@ -1,7 +1,5 @@
dn: uid=herman,ou=People,dc=example,dc=com
uid: ht
uid: herman
uid: htmarley
cn: Herman Toothrot
cn: Horatio Torquemeda Marley
sn: Marley
Expand Down

0 comments on commit 6ed8e1b

Please sign in to comment.