use of com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType in project midpoint by Evolveum.
the class TestParseResource method assertResourceJaxb.
private void assertResourceJaxb(ResourceType resourceType, boolean isSimple) throws SchemaException {
assertEquals("Wrong oid (JAXB)", TestConstants.RESOURCE_OID, resourceType.getOid());
assertEquals("Wrong name (JAXB)", PrismTestUtil.createPolyStringType("Embedded Test OpenDJ"), resourceType.getName());
assertEquals("Wrong namespace (JAXB)", MidPointConstants.NS_RI, MidPointConstants.NS_RI);
ObjectReferenceType connectorRef = resourceType.getConnectorRef();
assertNotNull("No connectorRef (JAXB)", connectorRef);
assertEquals("Wrong type in connectorRef (JAXB)", ConnectorType.COMPLEX_TYPE, connectorRef.getType());
SearchFilterType filter = connectorRef.getFilter();
assertNotNull("No filter in connectorRef (JAXB)", filter);
MapXNode filterElement = filter.getFilterClauseXNode();
assertNotNull("No filter element in connectorRef (JAXB)", filterElement);
EvaluationTimeType resolutionTime = connectorRef.getResolutionTime();
if (isSimple) {
assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.RUN, resolutionTime);
} else {
assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.IMPORT, resolutionTime);
}
XmlSchemaType xmlSchemaType = resourceType.getSchema();
SchemaHandlingType schemaHandling = resourceType.getSchemaHandling();
if (isSimple) {
assertNull("Schema sneaked in", xmlSchemaType);
assertNull("SchemaHandling sneaked in", schemaHandling);
} else {
assertNotNull("No schema element (JAXB)", xmlSchemaType);
SchemaDefinitionType definition = xmlSchemaType.getDefinition();
assertNotNull("No definition element in schema (JAXB)", definition);
List<Element> anyElements = definition.getAny();
assertNotNull("Null element list in definition element in schema (JAXB)", anyElements);
assertFalse("Empty element list in definition element in schema (JAXB)", anyElements.isEmpty());
assertNotNull("No schema handling (JAXB)", schemaHandling);
for (ResourceObjectTypeDefinitionType accountType : schemaHandling.getObjectType()) {
String name = accountType.getIntent();
assertNotNull("Account type without a name", name);
assertNotNull("Account type " + name + " does not have an objectClass", accountType.getObjectClass());
boolean foundDescription = false;
boolean foundDepartmentNumber = false;
for (ResourceAttributeDefinitionType attributeDefinitionType : accountType.getAttribute()) {
if ("description".equals(ItemPathTypeUtil.asSingleNameOrFail(attributeDefinitionType.getRef()).getLocalPart())) {
foundDescription = true;
MappingType outbound = attributeDefinitionType.getOutbound();
JAXBElement<?> valueEvaluator = outbound.getExpression().getExpressionEvaluator().get(0);
System.out.println("value evaluator for description = " + valueEvaluator);
assertNotNull("no expression evaluator for description", valueEvaluator);
assertEquals("wrong expression evaluator element name for description", SchemaConstantsGenerated.C_VALUE, valueEvaluator.getName());
assertEquals("wrong expression evaluator actual type for description", RawType.class, valueEvaluator.getValue().getClass());
} else if ("departmentNumber".equals(ItemPathTypeUtil.asSingleNameOrFail(attributeDefinitionType.getRef()).getLocalPart())) {
foundDepartmentNumber = true;
MappingType outbound = attributeDefinitionType.getOutbound();
VariableBindingDefinitionType source = outbound.getSource().get(0);
System.out.println("source for departmentNumber = " + source);
assertNotNull("no source for outbound mapping for departmentNumber", source);
// <path xmlns:z="http://z/">$user/extension/z:dept</path>
ItemPath expected = ItemPath.create(new VariableItemPathSegment(new QName("user")), new QName("extension"), namespaces ? new QName("http://z/", "dept") : new QName("dept"));
PrismAsserts.assertPathEqualsExceptForPrefixes("source for departmentNubmer", expected, source.getPath().getItemPath());
}
}
assertTrue("ri:description attribute was not found", foundDescription);
assertTrue("ri:departmentNumber attribute was not found", foundDepartmentNumber);
}
// checking <class> element in fetch result
OperationResultType fetchResult = resourceType.getFetchResult();
assertNotNull("No fetchResult (JAXB)", fetchResult);
JAXBElement<?> value = fetchResult.getParams().getEntry().get(0).getEntryValue();
assertNotNull("No fetchResult param value (JAXB)", value);
assertEquals("Wrong value class", UnknownJavaObjectType.class, value.getValue().getClass());
UnknownJavaObjectType unknownJavaObjectType = (UnknownJavaObjectType) value.getValue();
assertEquals("Wrong value class", "my.class", unknownJavaObjectType.getClazz());
assertEquals("Wrong value toString value", "my.value", unknownJavaObjectType.getToString());
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType in project midpoint by Evolveum.
the class ConsistencyTest method test511AssignAccountMorgan.
/**
* assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
* account should be linked to the user.
* @throws Exception
*/
@Test
public void test511AssignAccountMorgan() throws Exception {
final String TEST_NAME = "test511AssignAccountMorgan";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
openDJController.assumeRunning();
Task task = taskManager.createTaskInstance(ConsistencyTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
//prepare new OU in opendj
Entry entry = openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILENAME);
PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
display("User Morgan: ", user);
PrismReference linkRef = user.findReference(UserType.F_LINK_REF);
ExpressionType expression = new ExpressionType();
ObjectFactory of = new ObjectFactory();
RawType raw = new RawType(new PrimitiveXNode("uid=morgan,ou=users,dc=example,dc=com"), prismContext);
JAXBElement val = of.createValue(raw);
expression.getExpressionEvaluator().add(val);
MappingType mapping = new MappingType();
mapping.setExpression(expression);
ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
attrDefType.setRef(new ItemPathType(new ItemPath(getOpenDjSecondaryIdentifierQName())));
attrDefType.setOutbound(mapping);
ConstructionType construction = new ConstructionType();
construction.getAttribute().add(attrDefType);
construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo));
AssignmentType assignment = new AssignmentType();
assignment.setConstruction(construction);
ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, prismContext, assignment.asPrismContainerValue());
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
// assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
display("User morgan after", userMorgan);
UserType userMorganType = userMorgan.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertShadowModel(accountModel, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
ResourceAttribute attributes = ShadowUtil.getAttribute(accountModel, new QName(resourceTypeOpenDjrepo.getNamespace(), "uid"));
assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType in project midpoint by Evolveum.
the class Construction method evaluateAttribute.
private <T> Mapping<PrismPropertyValue<T>, ResourceAttributeDefinition<T>> evaluateAttribute(ResourceAttributeDefinitionType attribudeDefinitionType, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
QName attrName = ItemPathUtil.getOnlySegmentQName(attribudeDefinitionType.getRef());
if (attrName == null) {
throw new SchemaException("Missing 'ref' in attribute construction in account construction in " + getSource());
}
if (!attribudeDefinitionType.getInbound().isEmpty()) {
throw new SchemaException("Cannot process inbound section in definition of attribute " + attrName + " in account construction in " + getSource());
}
MappingType outboundMappingType = attribudeDefinitionType.getOutbound();
if (outboundMappingType == null) {
throw new SchemaException("No outbound section in definition of attribute " + attrName + " in account construction in " + getSource());
}
ResourceAttributeDefinition<T> outputDefinition = findAttributeDefinition(attrName);
if (outputDefinition == null) {
throw new SchemaException("Attribute " + attrName + " not found in schema for account type " + getIntent() + ", " + getResource(task, result) + " as definied in " + getSource(), attrName);
}
Mapping.Builder<PrismPropertyValue<T>, ResourceAttributeDefinition<T>> builder = mappingFactory.createMappingBuilder(outboundMappingType, "for attribute " + PrettyPrinter.prettyPrint(attrName) + " in " + getSource());
Mapping<PrismPropertyValue<T>, ResourceAttributeDefinition<T>> evaluatedMapping = evaluateMapping(builder, attrName, outputDefinition, null, task, result);
LOGGER.trace("Evaluated mapping for attribute " + attrName + ": " + evaluatedMapping);
return evaluatedMapping;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType in project midpoint by Evolveum.
the class RefinedAttributeDefinitionImpl method isIgnored.
static boolean isIgnored(ResourceAttributeDefinitionType attrDefType) throws SchemaException {
List<PropertyLimitationsType> limitations = attrDefType.getLimitations();
if (limitations == null) {
return false;
}
PropertyLimitationsType limitationsType = MiscSchemaUtil.getLimitationsType(limitations, DEFAULT_LAYER);
if (limitationsType == null) {
return false;
}
if (limitationsType.isIgnore() == null) {
return false;
}
return limitationsType.isIgnore();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType in project midpoint by Evolveum.
the class RefinedAttributeDefinitionImpl method parse.
// schemaHandlingAttrDefType may be null if we are parsing from schema only
static <T> RefinedAttributeDefinition<T> parse(ResourceAttributeDefinition<T> schemaAttrDef, ResourceAttributeDefinitionType schemaHandlingAttrDefType, ObjectClassComplexTypeDefinition objectClassDef, PrismContext prismContext, String contextDescription) throws SchemaException {
RefinedAttributeDefinitionImpl<T> rAttrDef = new RefinedAttributeDefinitionImpl<T>(schemaAttrDef, prismContext);
if (schemaHandlingAttrDefType != null && schemaHandlingAttrDefType.getDisplayName() != null) {
rAttrDef.setDisplayName(schemaHandlingAttrDefType.getDisplayName());
} else {
if (schemaAttrDef.getDisplayName() != null) {
rAttrDef.setDisplayName(schemaAttrDef.getDisplayName());
}
}
if (schemaHandlingAttrDefType != null && schemaHandlingAttrDefType.getDisplayOrder() != null) {
rAttrDef.setDisplayOrder(schemaHandlingAttrDefType.getDisplayOrder());
} else {
if (schemaAttrDef.getDisplayOrder() != null) {
rAttrDef.setDisplayOrder(schemaAttrDef.getDisplayOrder());
}
}
rAttrDef.matchingRuleQName = schemaAttrDef.getMatchingRuleQName();
if (schemaHandlingAttrDefType != null) {
rAttrDef.fetchStrategy = schemaHandlingAttrDefType.getFetchStrategy();
if (schemaHandlingAttrDefType.getMatchingRule() != null) {
rAttrDef.matchingRuleQName = schemaHandlingAttrDefType.getMatchingRule();
}
}
PropertyLimitations schemaLimitations = getOrCreateLimitations(rAttrDef.limitationsMap, LayerType.SCHEMA);
schemaLimitations.setMinOccurs(schemaAttrDef.getMinOccurs());
schemaLimitations.setMaxOccurs(schemaAttrDef.getMaxOccurs());
schemaLimitations.setIgnore(schemaAttrDef.isIgnored());
schemaLimitations.getAccess().setAdd(schemaAttrDef.canAdd());
schemaLimitations.getAccess().setModify(schemaAttrDef.canModify());
schemaLimitations.getAccess().setRead(schemaAttrDef.canRead());
if (schemaHandlingAttrDefType != null) {
if (schemaHandlingAttrDefType.getDescription() != null) {
rAttrDef.setDescription(schemaHandlingAttrDefType.getDescription());
}
if (schemaHandlingAttrDefType.isTolerant() == null) {
rAttrDef.tolerant = true;
} else {
rAttrDef.tolerant = schemaHandlingAttrDefType.isTolerant();
}
if (schemaHandlingAttrDefType.isSecondaryIdentifier() == null) {
rAttrDef.secondaryIdentifier = false;
} else {
rAttrDef.secondaryIdentifier = schemaHandlingAttrDefType.isSecondaryIdentifier();
}
rAttrDef.tolerantValuePattern = schemaHandlingAttrDefType.getTolerantValuePattern();
rAttrDef.intolerantValuePattern = schemaHandlingAttrDefType.getIntolerantValuePattern();
rAttrDef.isExclusiveStrong = BooleanUtils.isTrue(schemaHandlingAttrDefType.isExclusiveStrong());
rAttrDef.isVolatilityTrigger = BooleanUtils.isTrue(schemaHandlingAttrDefType.isVolatilityTrigger());
if (schemaHandlingAttrDefType.getOutbound() != null) {
rAttrDef.setOutboundMappingType(schemaHandlingAttrDefType.getOutbound());
}
if (schemaHandlingAttrDefType.getInbound() != null) {
rAttrDef.setInboundMappingTypes(schemaHandlingAttrDefType.getInbound());
}
rAttrDef.setModificationPriority(schemaHandlingAttrDefType.getModificationPriority());
// may be null at this point
rAttrDef.setReadReplaceMode(schemaHandlingAttrDefType.isReadReplaceMode());
if (schemaHandlingAttrDefType.isDisplayNameAttribute() != null && schemaHandlingAttrDefType.isDisplayNameAttribute()) {
rAttrDef.isDisplayNameAttribute = true;
}
}
PropertyLimitations previousLimitations = null;
for (LayerType layer : LayerType.values()) {
PropertyLimitations limitations = getOrCreateLimitations(rAttrDef.limitationsMap, layer);
if (previousLimitations != null) {
limitations.setMinOccurs(previousLimitations.getMinOccurs());
limitations.setMaxOccurs(previousLimitations.getMaxOccurs());
limitations.setIgnore(previousLimitations.isIgnore());
limitations.getAccess().setAdd(previousLimitations.getAccess().isAdd());
limitations.getAccess().setRead(previousLimitations.getAccess().isRead());
limitations.getAccess().setModify(previousLimitations.getAccess().isModify());
}
previousLimitations = limitations;
if (schemaHandlingAttrDefType != null) {
if (layer != LayerType.SCHEMA) {
// SCHEMA is a pseudo-layer. It cannot be overriden ... unless specified explicitly
PropertyLimitationsType genericLimitationsType = MiscSchemaUtil.getLimitationsType(schemaHandlingAttrDefType.getLimitations(), null);
if (genericLimitationsType != null) {
applyLimitationsType(limitations, genericLimitationsType);
}
}
PropertyLimitationsType layerLimitationsType = MiscSchemaUtil.getLimitationsType(schemaHandlingAttrDefType.getLimitations(), layer);
if (layerLimitationsType != null) {
applyLimitationsType(limitations, layerLimitationsType);
}
}
}
return rAttrDef;
}
Aggregations