Skip to content

Commit

Permalink
Merge branch 'feature/mapping-container'
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Nov 10, 2017
2 parents 2d2c391 + 80a374d commit 8824c4b
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 140 deletions.
Expand Up @@ -213,23 +213,8 @@ public static <T extends Containerable> boolean setFieldContainerValue(PrismCont
}
fieldContainer = new PrismContainer<T>(fieldName, parent.getPrismContext());
fieldContainer.add(fieldContainerValue);
if (parent.getParent() == null) {
parent.add(fieldContainer); // TODO what if fieldContainer is already there?
} else {
parent.addReplaceExisting(fieldContainer);
}
parent.addReplaceExisting(fieldContainer);
}
// // Make sure that the definition from parent is applied to new field container
// if (fieldContainer.getDefinition() == null) {
// PrismContainer<?> parentContainer = parent.getContainer();
// if (parentContainer != null) {
// PrismContainerDefinition<?> parentDefinition = parentContainer.getDefinition();
// if (parentDefinition != null) {
// PrismContainerDefinition<T> fieldDefinition = parentDefinition.findContainerDefinition(fieldName);
// fieldContainer.setDefinition(fieldDefinition);
// }
// }
// }
} catch (SchemaException e) {
// This should not happen. Code generator and compiler should take care of that.
throw new IllegalStateException("Internal schema error: "+e.getMessage(),e);
Expand Down
Expand Up @@ -5333,6 +5333,9 @@
describe the decisions of the system administrator about the
way how that attribute or association is used in midPoint.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="ref" type="t:ItemPathType">
Expand Down Expand Up @@ -5440,6 +5443,9 @@
describe the decisions of the system administrator about the
way how that attribute or association is used in midPoint.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:ItemRefinedDefinitionType">
Expand Down Expand Up @@ -5568,6 +5574,9 @@
describe the decisions of the system administrator about the
way how that attribute is used in midPoint.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:ResourceItemDefinitionType">
Expand Down Expand Up @@ -5744,6 +5753,11 @@
</xsd:complexType>

<xsd:complexType name="ResourcePasswordDefinitionType">
<xsd:annotation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="fetchStrategy" type="tns:AttributeFetchStrategyType" minOccurs="0"/>
<xsd:element name="outbound" type="tns:MappingType" minOccurs="0" maxOccurs="unbounded">
Expand All @@ -5769,7 +5783,7 @@
Reference to the account type password policy settings.
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>tns:PasswordPolicyType</a:objectReferenceTargetType>
<a:objectReferenceTargetType>tns:ValuePolicyType</a:objectReferenceTargetType>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
Expand All @@ -5781,6 +5795,9 @@
<xsd:documentation>
Defines how the mapping of the activation section is handled for the resource.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="existence" type="tns:ResourceBidirectionalMappingType" minOccurs="0" maxOccurs="1">
Expand Down Expand Up @@ -5831,6 +5848,7 @@
</xsd:documentation>
<xsd:appinfo>
<a:since>3.6</a:since>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
Expand All @@ -5856,6 +5874,11 @@
</xsd:complexType>

<xsd:complexType name="ResourceBidirectionalMappingType">
<xsd:annotation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="fetchStrategy" type="tns:AttributeFetchStrategyType" minOccurs="0"/>
<xsd:element name="outbound" type="tns:MappingType" minOccurs="0" maxOccurs="unbounded">
Expand All @@ -5876,6 +5899,11 @@
</xsd:complexType>

<xsd:complexType name="ResourceBidirectionalMappingAndDefinitionType">
<xsd:annotation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:ResourceBidirectionalMappingType">
<xsd:sequence>
Expand Down Expand Up @@ -6133,6 +6161,9 @@
and therefore it describes the decisions of the system administrator about the
way how entitlements are used in midPoint.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:ResourceItemDefinitionType">
Expand Down Expand Up @@ -6700,6 +6731,9 @@
these cases may simplify the code, as it all can be handled by a
generic library reused in many places through the system.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="name" type="xsd:string" minOccurs="0" maxOccurs="1">
Expand Down Expand Up @@ -10934,6 +10968,9 @@
describe the decisions of the system administrator about the
way how that attribute or association is used in midPoint.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:ItemRefinedDefinitionType">
Expand All @@ -10957,6 +10994,11 @@
</xsd:complexType>

<xsd:complexType name="ObjectTemplateMappingType">
<xsd:annotation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:MappingType">
<xsd:sequence>
Expand Down
Expand Up @@ -150,8 +150,6 @@ private void assertObjectTemplatePrism(PrismObject<ObjectTemplateType> object, Q
assertPropertyValue(object, "name", PrismTestUtil.createPolyString("Default User Template"));
assertPropertyDefinition(object, "name", PolyStringType.COMPLEX_TYPE, 0, 1);

assertPropertyDefinition(object, "mapping", ObjectTemplateMappingType.COMPLEX_TYPE, 0, -1);

}

// checks raw values of mappings
Expand Down
Expand Up @@ -29,7 +29,7 @@
public abstract class AbstractPropertyValueParserTest<T> extends AbstractPrismValueParserTest<PrismPropertyValue<T>> {

@SuppressWarnings("Convert2MethodRef")
protected void processParsings(Class<T> clazz, QName type, PrismPropertyDefinition definition, SerializingFunction<PrismPropertyValue<T>> serializer, String serId) throws Exception {
protected void processParsings(Class<T> clazz, QName type, PrismPropertyDefinition<T> definition, SerializingFunction<PrismPropertyValue<T>> serializer, String serId) throws Exception {
process("parseItemValue - no hint", p -> p.parseItemValue(), serializer, serId);

if (clazz != null) {
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package com.evolveum.midpoint.schema.parser;

import com.evolveum.midpoint.prism.PrismContainerDefinition;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismPropertyValue;
Expand All @@ -34,7 +35,7 @@
*
*/
@SuppressWarnings("Convert2MethodRef")
public class TestParseMapping extends AbstractPropertyValueParserTest<MappingType> {
public class TestParseMapping extends AbstractContainerValueParserTest<MappingType> {

@Override
protected File getFile() {
Expand All @@ -46,66 +47,32 @@ public void testParseFile() throws Exception {
displayTestTitle("testParseFile");
processParsings(null, null);
}

@Test
public void testParseRoundTrip() throws Exception{
displayTestTitle("testParseRoundTrip");

// @Test
// public void testParseRoundTrip() throws Exception{
// displayTestTitle("testParseRoundTrip");
//
// //processParsings(v -> getPrismContext().serializerFor(language).serialize(v)); // no item name nor definition => cannot serialize
// processParsings(v -> getPrismContext().serializerFor(language).root(new QName("dummy")).serialize(v), "s1");
// processParsings(v -> getPrismContext().serializerFor(language).root(SchemaConstantsGenerated.C_USER).serialize(v), "s2"); // misleading item name
// processParsings(v -> getPrismContext().serializerFor(language).serializeRealValue(v.asContainerable()), "s3");
// processParsings(v -> getPrismContext().serializerFor(language).root(new QName("dummy")).serializeAnyData(v.asContainerable()), "s4");
// }

private void processParsings(SerializingFunction<PrismPropertyValue<MappingType>> serializer, String serId) throws Exception {
PrismPropertyDefinition definition = getPrismContext().getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstantsGenerated.C_MAPPING);
processParsings(MappingType.class, MappingType.COMPLEX_TYPE, definition, serializer, serId);
//processParsings(v -> getPrismContext().serializerFor(language).serialize(v)); // no item name nor definition => cannot serialize
processParsings(v -> getPrismContext().serializerFor(language).root(new QName("dummy")).serialize(v), "s1");
processParsings(v -> getPrismContext().serializerFor(language).root(SchemaConstantsGenerated.C_USER).serialize(v), "s2"); // misleading item name
processParsings(v -> getPrismContext().serializerFor(language).root(new QName("dummy")).serializeRealValue(v.asContainerable()), "s3");
processParsings(v -> getPrismContext().serializerFor(language).root(new QName("dummy")).serializeAnyData(v.asContainerable()), "s4");
}

// a bit of hack: RawType gets parsed very soon, so we must test for it almost immediately after parsing
@Override
protected PrismPropertyValue<MappingType> makePPV(MappingType mapping, PrismPropertyDefinition definition) {
RawType variableValue = (RawType) mapping.getExpression().getVariable().get(0).getValue();
AssertJUnit.assertNull("Unexpected raw value in expression variable: " + variableValue.getXnode(), variableValue.getXnode());
return super.makePPV(mapping, definition);
private void processParsings(SerializingFunction<PrismContainerValue<MappingType>> serializer, String serId) throws Exception {
processParsings(MappingType.class, null, MappingType.COMPLEX_TYPE, null, serializer, serId);
}

@Override
protected void assertPrismPropertyValueLocal(PrismPropertyValue<MappingType> value) throws SchemaException {
// todo
protected void assertPrismContainerValueLocal(PrismContainerValue<MappingType> value)
throws SchemaException {
// TODO

}

// private void assertPrismValue(PrismContainerValue<AccessCertificationCaseType> pcv) {
// assertEquals("Wrong id", (Long) 4L, pcv.getId());
// ComplexTypeDefinition ctd = pcv.getComplexTypeDefinition();
// assertNotNull("No CTD", ctd);
// //noinspection ConstantConditions
// assertEquals("Wrong CTD typeName", AccessCertificationAssignmentCaseType.COMPLEX_TYPE, ctd.getTypeName());
// assertEquals("Wrong real class in PCV", AccessCertificationAssignmentCaseType.class, pcv.getRealClass());
// }

// private void assertJaxb(AccessCertificationCaseType aCase) throws SchemaException {
// PrismAsserts.assertRefEquivalent("Wrong objectRef",
// new PrismReferenceValue("ee53eba7-5c16-4c16-ad15-dd6a2360ab1a", UserType.COMPLEX_TYPE),
// aCase.getObjectRef().asReferenceValue());
// PrismAsserts.assertRefEquivalent("Wrong targetRef",
// new PrismReferenceValue("ef2bc95b-76e0-48e2-86d6-3d4f02d3e1a2", ResourceType.COMPLEX_TYPE),
// aCase.getTargetRef().asReferenceValue());
//
// assertTrue(aCase instanceof AccessCertificationAssignmentCaseType);
// AccessCertificationAssignmentCaseType assignmentCase = (AccessCertificationAssignmentCaseType) aCase;
//
// assertNotNull("no assignment", assignmentCase.getAssignment());
// assertEquals((Long) 1L, assignmentCase.getAssignment().getId());
// PrismAsserts.assertRefEquivalent("Wrong resourceRef in assignment",
// new PrismReferenceValue("ef2bc95b-76e0-48e2-86d6-3d4f02d3e1a2", ResourceType.COMPLEX_TYPE),
// assignmentCase.getAssignment().getConstruction().getResourceRef().asReferenceValue());
// assertEquals("wrong isInducement", Boolean.FALSE, assignmentCase.isIsInducement());
// }

@Override
protected boolean isContainer() {
return false;
}

}
Expand Up @@ -16,9 +16,10 @@
package com.evolveum.midpoint.schema.parser;

import static org.testng.AssertJUnit.assertEquals;

import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismParser;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismSerializer;
import com.evolveum.midpoint.prism.xnode.ListXNode;
Expand All @@ -43,7 +44,7 @@
* @author mederly
*
*/
public class TestParseMappingConst extends AbstractPropertyValueParserTest<MappingType> {
public class TestParseMappingConst extends AbstractContainerValueParserTest<MappingType> {

@Override
protected File getFile() {
Expand All @@ -62,7 +63,7 @@ public void testParseSerialize() throws Exception{

PrismContext prismContext = getPrismContext();
PrismParser parser = prismContext.parserFor(getFile());
PrismPropertyValue<MappingType> mappingPval = parser.parseItemValue();
PrismContainerValue<MappingType> mappingPval = parser.parseItemValue();

System.out.println("\nmappingPval:\n"+mappingPval.debugDump(1));

Expand All @@ -86,13 +87,12 @@ public void testParseRoundTrip() throws Exception{
processParsings(v -> getPrismContext().serializerFor(language).root(SchemaConstantsGenerated.C_USER).serialize(v), "s2"); // misleading item name
}

private void processParsings(SerializingFunction<PrismPropertyValue<MappingType>> serializer, String serId) throws Exception {
PrismPropertyDefinition<MappingType> definition = getPrismContext().getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstantsGenerated.C_MAPPING);
processParsings(MappingType.class, MappingType.COMPLEX_TYPE, definition, serializer, serId);
private void processParsings(SerializingFunction<PrismContainerValue<MappingType>> serializer, String serId) throws Exception {
processParsings(MappingType.class, null, MappingType.COMPLEX_TYPE, null, serializer, serId);
}

@Override
protected void assertPrismPropertyValueLocal(PrismPropertyValue<MappingType> value) throws SchemaException {
protected void assertPrismContainerValueLocal(PrismContainerValue<MappingType> value) throws SchemaException {
MappingType mappingType = value.getValue();
ExpressionType expressionType = mappingType.getExpression();
List<JAXBElement<?>> expressionEvaluatorElements = expressionType.getExpressionEvaluator();
Expand Down
Expand Up @@ -60,37 +60,9 @@ private void processParsings(SerializingFunction<PrismContainerValue<MappingsTyp

@Override
public void assertPrismContainerValueLocal(PrismContainerValue<MappingsType> value) throws SchemaException {
// assertPrismValue(value);
// assertJaxb(value.asContainerable());
// TODO
}

// private void assertPrismValue(PrismContainerValue<AccessCertificationCaseType> pcv) {
// assertEquals("Wrong id", (Long) 4L, pcv.getId());
// ComplexTypeDefinition ctd = pcv.getComplexTypeDefinition();
// assertNotNull("No CTD", ctd);
// //noinspection ConstantConditions
// assertEquals("Wrong CTD typeName", AccessCertificationAssignmentCaseType.COMPLEX_TYPE, ctd.getTypeName());
// assertEquals("Wrong real class in PCV", AccessCertificationAssignmentCaseType.class, pcv.getRealClass());
// }

// private void assertJaxb(AccessCertificationCaseType aCase) throws SchemaException {
// PrismAsserts.assertRefEquivalent("Wrong objectRef",
// new PrismReferenceValue("ee53eba7-5c16-4c16-ad15-dd6a2360ab1a", UserType.COMPLEX_TYPE),
// aCase.getObjectRef().asReferenceValue());
// PrismAsserts.assertRefEquivalent("Wrong targetRef",
// new PrismReferenceValue("ef2bc95b-76e0-48e2-86d6-3d4f02d3e1a2", ResourceType.COMPLEX_TYPE),
// aCase.getTargetRef().asReferenceValue());
//
// assertTrue(aCase instanceof AccessCertificationAssignmentCaseType);
// AccessCertificationAssignmentCaseType assignmentCase = (AccessCertificationAssignmentCaseType) aCase;
//
// assertNotNull("no assignment", assignmentCase.getAssignment());
// assertEquals((Long) 1L, assignmentCase.getAssignment().getId());
// PrismAsserts.assertRefEquivalent("Wrong resourceRef in assignment",
// new PrismReferenceValue("ef2bc95b-76e0-48e2-86d6-3d4f02d3e1a2", ResourceType.COMPLEX_TYPE),
// assignmentCase.getAssignment().getConstruction().getResourceRef().asReferenceValue());
// assertEquals("wrong isInducement", Boolean.FALSE, assignmentCase.isIsInducement());
// }

@Override
protected boolean isContainer() {
Expand Down

0 comments on commit 8824c4b

Please sign in to comment.