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 Oct 12, 2016
2 parents 1c609dd + 1336bd7 commit 7359b46
Show file tree
Hide file tree
Showing 18 changed files with 1,019 additions and 21 deletions.
Expand Up @@ -417,18 +417,22 @@ public static void assertPropertyDelete(Collection<? extends ItemDelta> modifica
assertSet("delta "+propertyDelta+" for "+propertyPath.last(), "delete", propertyDelta.getValuesToDelete(), expectedValues);
}

public static void assertNoItemDelta(ObjectDelta<?> userDelta, ItemPath propertyPath) {
if (userDelta == null) {
public static void assertNoItemDelta(ObjectDelta<?> objectDelta, QName itemName) {
assertNoItemDelta(objectDelta, new ItemPath(itemName));
}

public static void assertNoItemDelta(ObjectDelta<?> objectDelta, ItemPath itemPath) {
if (objectDelta == null) {
return;
}
assert !userDelta.hasItemDelta(propertyPath) : "Delta for item "+propertyPath+" present while not expecting it";
assert !objectDelta.hasItemDelta(itemPath) : "Delta for item "+itemPath+" present while not expecting it";
}

public static ContainerDelta<?> assertContainerAdd(ObjectDelta<?> objectDelta, QName name) {
return assertContainerAdd(objectDelta, new ItemPath(name));
public static ContainerDelta<?> assertContainerAddGetContainerDelta(ObjectDelta<?> objectDelta, QName name) {
return assertContainerAddGetContainerDelta(objectDelta, new ItemPath(name));
}

public static ContainerDelta<?> assertContainerAdd(ObjectDelta<?> objectDelta, ItemPath propertyPath) {
public static ContainerDelta<?> assertContainerAddGetContainerDelta(ObjectDelta<?> objectDelta, ItemPath propertyPath) {
ContainerDelta<?> delta = objectDelta.findContainerDelta(propertyPath);
assertNotNull("Container delta for "+propertyPath+" not found",delta);
assert !delta.isEmpty() : "Container delta for "+propertyPath+" is empty";
Expand All @@ -437,11 +441,11 @@ public static ContainerDelta<?> assertContainerAdd(ObjectDelta<?> objectDelta, I
return delta;
}

public static ContainerDelta<?> assertContainerDelete(ObjectDelta<?> objectDelta, QName name) {
return assertContainerDelete(objectDelta, new ItemPath(name));
public static ContainerDelta<?> assertContainerDeleteGetContainerDelta(ObjectDelta<?> objectDelta, QName name) {
return assertContainerDeleteGetContainerDelta(objectDelta, new ItemPath(name));
}

public static ContainerDelta<?> assertContainerDelete(ObjectDelta<?> objectDelta, ItemPath propertyPath) {
public static ContainerDelta<?> assertContainerDeleteGetContainerDelta(ObjectDelta<?> objectDelta, ItemPath propertyPath) {
ContainerDelta<?> delta = objectDelta.findContainerDelta(propertyPath);
assertNotNull("Container delta for "+propertyPath+" not found",delta);
assert !delta.isEmpty() : "Container delta for "+propertyPath+" is empty";
Expand All @@ -450,6 +454,48 @@ public static ContainerDelta<?> assertContainerDelete(ObjectDelta<?> objectDelta
return delta;
}

public static <C extends Containerable> void assertContainerAdd(ObjectDelta<?> objectDelta, QName itemName, C... containerables) {
assertContainerAdd(objectDelta, new ItemPath(itemName), containerables);
}

public static <C extends Containerable> void assertContainerAdd(ObjectDelta<?> objectDelta, ItemPath propertyPath, C... containerables) {
List<PrismContainerValue<C>> expectedCVals = new ArrayList<>();
for (C expectedContainerable: containerables) {
expectedCVals.add(expectedContainerable.asPrismContainerValue());
}
}

public static <C extends Containerable> void assertContainerAdd(ObjectDelta<?> objectDelta, QName itemName,
PrismContainerValue<C>... expectedCVals) {
assertContainerAdd(objectDelta, new ItemPath(itemName), expectedCVals);
}

public static <C extends Containerable> void assertContainerAdd(ObjectDelta<?> objectDelta, ItemPath propertyPath,
PrismContainerValue<C>... expectedCVals) {
ContainerDelta<C> delta = objectDelta.findContainerDelta(propertyPath);
assertNotNull("Container delta for "+propertyPath+" not found",delta);
assert !delta.isEmpty() : "Container delta for "+propertyPath+" is empty";
assert delta.getValuesToAdd() != null : "Container delta for "+propertyPath+" has null values to add";
assert !delta.getValuesToAdd().isEmpty() : "Container delta for "+propertyPath+" has empty values to add";
assertEquivalentContainerValues("Wrong values in container delta for "+propertyPath,
delta.getValuesToAdd(), expectedCVals);
}

private static <C extends Containerable> void assertEquivalentContainerValues(String message, Collection<PrismContainerValue<C>> haveValues,
PrismContainerValue<C>[] expectedCVals) {
List<PrismContainerValue<C>> expectedValues = Arrays.asList(expectedCVals);
Comparator<PrismContainerValue<C>> comparator = new Comparator<PrismContainerValue<C>>() {
@Override
public int compare(PrismContainerValue<C> a, PrismContainerValue<C> b) {
if (a.equivalent(b)) {
return 0;
}
return 1;
}
};
assert MiscUtil.unorderedCollectionEquals(haveValues, expectedValues, comparator) : message;
}

public static <T> void assertOrigin(ObjectDelta<?> objectDelta, final OriginType... expectedOriginTypes) {
assertOrigin(objectDelta, null, expectedOriginTypes);
}
Expand Down
Expand Up @@ -156,7 +156,7 @@ public void testDiffJack() throws SchemaException, SAXException, IOException {
new NameItemPathSegment(USER_DESCRIPTION_QNAME)),
"Assignment II");

ContainerDelta<?> assignment3Delta = PrismAsserts.assertContainerAdd(jackDelta, new ItemPath(USER_ASSIGNMENT_QNAME));
ContainerDelta<?> assignment3Delta = PrismAsserts.assertContainerAddGetContainerDelta(jackDelta, new ItemPath(USER_ASSIGNMENT_QNAME));
PrismContainerValue<?> assignment3DeltaAddValue = assignment3Delta.getValuesToAdd().iterator().next();
assertEquals("Assignment 3 wrong ID", USER_ASSIGNMENT_3_ID, assignment3DeltaAddValue.getId());

Expand Down
@@ -0,0 +1,47 @@
/**
* Copyright (c) 2016 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.util;

import javax.xml.namespace.QName;

import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;

/**
* @author semancik
*
*/
public class FocusTypeUtil {

public static AssignmentType createRoleAssignment(String roleOid) {
return createTargetAssignment(roleOid, RoleType.COMPLEX_TYPE);
}

public static AssignmentType createOrgAssignment(String roleOid) {
return createTargetAssignment(roleOid, OrgType.COMPLEX_TYPE);
}

public static AssignmentType createTargetAssignment(String targetOid, QName type) {
AssignmentType assignmentType = new AssignmentType();
ObjectReferenceType targetRef = new ObjectReferenceType();
targetRef.setOid(targetOid);
targetRef.setType(type);
assignmentType.setTargetRef(targetRef);
return assignmentType;
}
}
Expand Up @@ -9377,6 +9377,20 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>

<xsd:element name="mergeConfiguration" type="tns:MergeConfigurationType" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
Configuration for object merging. E.g. for merging two users.
Note: this is a single-valued item now. But it will most likely be
switched to multi-valued item in future midPoint versions.
</xsd:documentation>
<xsd:appinfo>
<a:since>3.5</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>

</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
Expand Down Expand Up @@ -12470,5 +12484,83 @@
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="MergeConfigurationType">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="name" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="description" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="item" type="tns:ItemRefMergeConfigurationType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="default" type="tns:ItemMergeConfigurationType" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="ItemMergeConfigurationType">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="left" type="tns:MergeStategyType" minOccurs="0" maxOccurs="1"/>
<xsd:element name="right" type="tns:MergeStategyType" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="ItemRefMergeConfigurationType">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:ItemMergeConfigurationType">
<xsd:sequence>
<xsd:element name="ref" type="t:ItemPathType" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:simpleType name="MergeStategyType">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="ignore">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="IGNORE"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="take">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="TAKE"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

</xsd:schema>
Expand Up @@ -346,7 +346,7 @@ public void testTask() throws SchemaException, SAXException, IOException, JAXBEx
Collection<? extends ItemDelta> modifications = diffDelta.getModifications();
assertEquals("Unexpected number of modifications", 1, modifications.size());
// there is only one property in the container. after deleting this property, all container will be deleted, isn't it right?
PrismAsserts.assertContainerDelete(diffDelta, new ItemPath(TaskType.F_EXTENSION));
PrismAsserts.assertContainerDeleteGetContainerDelta(diffDelta, new ItemPath(TaskType.F_EXTENSION));
// PrismAsserts.assertPropertyDelete(diffDelta, new ItemPath(TaskType.F_EXTENSION,
// new QName("http://midpoint.evolveum.com/xml/ns/public/provisioning/liveSync-1.xsd","token")), 480);

Expand Down Expand Up @@ -430,7 +430,7 @@ public void testResource() throws SchemaException, SAXException, IOException, JA
assertEquals("Wrong change type", ChangeType.MODIFY, resourceDelta.getChangeType());
Collection<? extends ItemDelta> modifications = resourceDelta.getModifications();
assertEquals("Unexpected number of modifications", 7, modifications.size());
PrismAsserts.assertContainerDelete(resourceDelta, ResourceType.F_SCHEMA);
PrismAsserts.assertContainerDeleteGetContainerDelta(resourceDelta, ResourceType.F_SCHEMA);
PrismAsserts.assertPropertyReplace(resourceDelta, pathTimeouts("update"), 3);
PrismAsserts.assertPropertyReplace(resourceDelta, pathTimeouts("scriptOnResource"), 4);
PrismAsserts.assertPropertyDelete(resourceDelta,
Expand Down
Expand Up @@ -19,6 +19,7 @@
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.assertNotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

Expand Down Expand Up @@ -129,6 +130,28 @@ public static <F extends FocusType> void assertAssignedRole(PrismObject<F> user,
public static <F extends FocusType> void assertNotAssignedRole(PrismObject<F> user, String roleOid) {
assertNotAssigned(user, roleOid, RoleType.COMPLEX_TYPE);
}

public static <F extends FocusType> void assertAssignedRoles(PrismObject<F> user, String... roleOids) {
assertAssignedTargets(user, "roles", RoleType.COMPLEX_TYPE, roleOids);
}

public static <F extends FocusType> void assertAssignedOrgs(PrismObject<F> user, String... orgOids) {
assertAssignedTargets(user, "orgs", OrgType.COMPLEX_TYPE, orgOids);
}

public static <F extends FocusType> void assertAssignedTargets(PrismObject<F> user, String typeDesc, QName type, String... expectedTargetOids) {
F userType = user.asObjectable();
List<String> haveTagetOids = new ArrayList<>();
for (AssignmentType assignmentType: userType.getAssignment()) {
ObjectReferenceType targetRef = assignmentType.getTargetRef();
if (targetRef != null) {
if (type.equals(targetRef.getType())) {
haveTagetOids.add(targetRef.getOid());
}
}
}
PrismAsserts.assertSets("Wrong "+typeDesc+" in "+user, haveTagetOids, expectedTargetOids);
}

public static <F extends FocusType> void assertNotAssignedResource(PrismObject<F> user, String resourceOid) {
F userType = user.asObjectable();
Expand Down
Expand Up @@ -56,6 +56,8 @@ public interface ModelInteractionService {
static final String GET_CREDENTIALS_POLICY = CLASS_NAME_WITH_DOT + "getCredentialsPolicy";
static final String CHECK_PASSWORD = CLASS_NAME_WITH_DOT + "checkPassword";
static final String GET_CONNECTOR_OPERATIONAL_STATUS = CLASS_NAME_WITH_DOT + "getConnectorOperationalStatus";
static final String MERGE_OBJECTS_PREVIEW_DELTA = CLASS_NAME_WITH_DOT + "mergeObjectsPreviewDelta";
static final String MERGE_OBJECTS_PREVIEW_OBJECT = CLASS_NAME_WITH_DOT + "mergeObjectsPreviewObject";

/**
* Computes the most likely changes triggered by the provided delta. The delta may be any change of any object, e.g.
Expand Down Expand Up @@ -179,5 +181,13 @@ AccessCertificationConfigurationType getCertificationConfiguration(OperationResu

ConnectorOperationalStatus getConnectorOperationalStatus(String resourceOid, OperationResult parentResult)
throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException;

<O extends ObjectType> ObjectDelta<O> mergeObjectsPreviewDelta(Class<O> type,
String leftOid, String rightOid, Task task, OperationResult result)
throws ObjectNotFoundException, SchemaException, ConfigurationException;

<O extends ObjectType> PrismObject<O> mergeObjectsPreviewObject(Class<O> type,
String leftOid, String rightOid, Task task, OperationResult result)
throws ObjectNotFoundException, SchemaException, ConfigurationException;

}
Expand Up @@ -107,6 +107,7 @@ public interface ModelService {
static final String IMPORT_OBJECTS_FROM_STREAM = CLASS_NAME_WITH_DOT + "importObjectsFromStream";
static final String POST_INIT = CLASS_NAME_WITH_DOT + "postInit";
static final String DISCOVER_CONNECTORS = CLASS_NAME_WITH_DOT + "discoverConnectors";
static final String MERGE_OBJECTS = CLASS_NAME_WITH_DOT + "mergeObjects";

static final String AUTZ_NAMESPACE = AuthorizationConstants.NS_AUTHORIZATION_MODEL;

Expand Down Expand Up @@ -641,17 +642,32 @@ public Set<ConnectorType> discoverConnectors(ConnectorHostType hostType, Task ta
* @param ignoreItemPaths
* @param task
* @param result
* @param <T>
* @param <O>
* @return
* @throws SchemaException
* @throws ObjectNotFoundException
* @throws SecurityViolationException
* @throws CommunicationException
* @throws ConfigurationException
*/
<T extends ObjectType> CompareResultType compareObject(PrismObject<T> object,
<O extends ObjectType> CompareResultType compareObject(PrismObject<O> object,
Collection<SelectorOptions<GetOperationOptions>> readOptions, ModelCompareOptions compareOptions,
@NotNull List<ItemPath> ignoreItemPaths, Task task, OperationResult result)
throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException,
ConfigurationException;

/**
* Merge two objects into one.
*
* EXPERIMENTAL feature. The method signature is likely to change in the future.
*
* @param type object type
* @param leftOid left-side object OID
* @param rightOid right-side object OID
* @param task
* @param result
* @return
*/
<O extends ObjectType> Collection<ObjectDeltaOperation<? extends ObjectType>> mergeObjects(Class<O> type, String leftOid, String rightOid, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ConfigurationException, ObjectAlreadyExistsException, ExpressionEvaluationException, CommunicationException, PolicyViolationException, SecurityViolationException;

}

0 comments on commit 7359b46

Please sign in to comment.