use of com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition in project midpoint by Evolveum.
the class DefinitionsHelper method applyDefinition.
void applyDefinition(ProvisioningContext ctx, ObjectQuery query) throws SchemaException {
if (query == null) {
return;
}
ObjectFilter filter = query.getFilter();
if (filter == null) {
return;
}
com.evolveum.midpoint.prism.query.Visitor visitor = subFilter -> {
if (subFilter instanceof PropertyValueFilter) {
PropertyValueFilter<?> valueFilter = (PropertyValueFilter<?>) subFilter;
ItemDefinition<?> definition = valueFilter.getDefinition();
if (definition instanceof ResourceAttributeDefinition) {
// already has a resource-related definition
return;
}
if (!ShadowType.F_ATTRIBUTES.equivalent(valueFilter.getParentPath())) {
return;
}
QName attributeName = valueFilter.getElementName();
ResourceAttributeDefinition<?> attributeDefinition = ctx.getObjectDefinitionRequired().findAttributeDefinition(attributeName);
if (attributeDefinition == null) {
throw new TunnelException(new SchemaException("No definition for attribute " + attributeName + " in query " + query));
}
// noinspection unchecked,rawtypes
valueFilter.setDefinition((ResourceAttributeDefinition) attributeDefinition);
}
};
try {
filter.accept(visitor);
} catch (TunnelException te) {
throw (SchemaException) te.getCause();
}
}
use of com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition in project midpoint by Evolveum.
the class AbstractLdapConnTest method test210ModifyAccountBarbossaReplaceTitle.
@Test
public void test210ModifyAccountBarbossaReplaceTitle() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectDelta<ShadowType> delta = prismContext.deltaFactory().object().createEmptyModifyDelta(ShadowType.class, accountBarbossaOid);
QName attrQName = new QName(MidPointConstants.NS_RI, "title");
// noinspection unchecked
ResourceAttributeDefinition<String> attrDef = (ResourceAttributeDefinition<String>) accountDefinition.findAttributeDefinition(attrQName);
PropertyDelta<String> attrDelta = prismContext.deltaFactory().property().createModificationReplaceProperty(ItemPath.create(ShadowType.F_ATTRIBUTES, attrQName), attrDef, "Captain");
delta.addModification(attrDelta);
// WHEN
when();
modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);
// THEN
then();
result.computeStatus();
TestUtil.assertSuccess(result);
Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
assertAttribute(entry, "title", "Captain");
PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
String shadowOid = getSingleLinkOid(user);
assertEquals("Shadows have moved", accountBarbossaOid, shadowOid);
assertLdapConnectorReasonableInstances();
}
use of com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition in project midpoint by Evolveum.
the class AbstractLdapConnTest method test212ModifyAccountBarbossaAddTitleDuplicate.
/**
* Make a duplicate modification. Add a title value that is already there.
* Normal LDAP should fail. So check that connector and midPoint handles that.
*/
@Test
public void test212ModifyAccountBarbossaAddTitleDuplicate() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectDelta<ShadowType> delta = prismContext.deltaFactory().object().createEmptyModifyDelta(ShadowType.class, accountBarbossaOid);
QName attrQName = new QName(MidPointConstants.NS_RI, "title");
// noinspection unchecked
ResourceAttributeDefinition<String> attrDef = (ResourceAttributeDefinition<String>) accountDefinition.findAttributeDefinition(attrQName);
PropertyDelta<String> attrDelta = prismContext.deltaFactory().property().createModificationAddProperty(ItemPath.create(ShadowType.F_ATTRIBUTES, attrQName), attrDef, "Captain");
delta.addModification(attrDelta);
// WHEN
when();
modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);
// THEN
then();
result.computeStatus();
TestUtil.assertSuccess(result);
Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
assertAttribute(entry, "title", "Captain");
PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
String shadowOid = getSingleLinkOid(user);
assertEquals("Shadows have moved", accountBarbossaOid, shadowOid);
assertLdapConnectorReasonableInstances();
}
use of com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition in project midpoint by Evolveum.
the class ShadowCaretaker method applyAttributeDefinition.
// value should be a value of attributes container
private void applyAttributeDefinition(ProvisioningContext ctx, PrismValue value) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
if (!(value instanceof PrismContainerValue)) {
// should never occur
return;
}
PrismContainerValue<ShadowAttributesType> pcv = (PrismContainerValue<ShadowAttributesType>) value;
for (Item<?, ?> item : pcv.getItems()) {
ItemDefinition<?> itemDef = item.getDefinition();
if (!(itemDef instanceof ResourceAttributeDefinition)) {
QName attributeName = item.getElementName();
ResourceAttributeDefinition<?> attributeDefinition = ctx.findAttributeDefinitionRequired(attributeName);
if (itemDef != null) {
// do some basic checks first
if (!QNameUtil.match(itemDef.getTypeName(), attributeDefinition.getTypeName())) {
throw new SchemaException("The value of type " + itemDef.getTypeName() + " cannot be applied to attribute " + attributeName + " which is of type " + attributeDefinition.getTypeName());
}
}
// noinspection unchecked,rawtypes
((Item) item).applyDefinition(attributeDefinition);
}
}
}
use of com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition in project midpoint by Evolveum.
the class AbstractEDirTest method test210ModifyAccountBarbossaTitle.
@Test
public void test210ModifyAccountBarbossaTitle() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
ObjectDelta<ShadowType> delta = prismContext.deltaFactory().object().createEmptyModifyDelta(ShadowType.class, accountBarbossaOid);
QName attrQName = new QName(MidPointConstants.NS_RI, "title");
// noinspection unchecked
ResourceAttributeDefinition<String> attrDef = (ResourceAttributeDefinition<String>) accountDefinition.findAttributeDefinition(attrQName);
PropertyDelta<String> attrDelta = prismContext.deltaFactory().property().createModificationReplaceProperty(ItemPath.create(ShadowType.F_ATTRIBUTES, attrQName), attrDef, "Captain");
delta.addModification(attrDelta);
// WHEN
when();
modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);
// THEN
then();
result.computeStatus();
TestUtil.assertSuccess(result);
Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
assertAttribute(entry, "title", "Captain");
PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
String shadowOid = getSingleLinkOid(user);
assertEquals("Shadows have moved", accountBarbossaOid, shadowOid);
}
Aggregations