use of com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType in project midpoint by Evolveum.
the class EvaluatedPlainResourceObjectConstructionImpl method getAttributesToEvaluate.
@Override
protected List<AttributeEvaluation<AH>> getAttributesToEvaluate(ConstructionEvaluation<AH, ?> constructionEvaluation) {
List<AttributeEvaluation<AH>> attributesToEvaluate = new ArrayList<>();
ResourceObjectDefinition objectDefinition = construction.getResourceObjectDefinitionRequired();
for (ResourceAttributeDefinition<?> refinedAttributeDefinition : objectDefinition.getAttributeDefinitions()) {
MappingType outboundMappingBean = refinedAttributeDefinition.getOutboundMappingBean();
if (outboundMappingBean == null) {
continue;
}
if (refinedAttributeDefinition.getProcessing(LayerType.MODEL) == ItemProcessing.IGNORE) {
LOGGER.trace("Skipping processing outbound mapping for attribute {} because it is ignored", refinedAttributeDefinition);
continue;
}
attributesToEvaluate.add(new AttributeEvaluation<>(constructionEvaluation, refinedAttributeDefinition, outboundMappingBean, OriginType.OUTBOUND, MappingKindType.OUTBOUND));
}
return attributesToEvaluate;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType in project midpoint by Evolveum.
the class TestModelServiceContract method test191ModifyUserJackModifyAssignment.
/**
* We try to modify an assignment of the account and see whether changes will be recorded in the account itself.
*
* We also check the metadata.channel migration for both the object and the assignment (MID-6547).
*/
@Test
public void test191ModifyUserJackModifyAssignment() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
PrismObject<ResourceType> dummyResource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(dummyResource);
// This explicitly parses the schema, therefore ...
assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 1);
ResourceObjectTypeDefinition accountDefinition = refinedSchema.findObjectTypeDefinitionRequired(ShadowKindType.ACCOUNT, null);
PrismPropertyDefinition gossipDefinition = accountDefinition.findPropertyDefinition(new ItemName("http://midpoint.evolveum.com/xml/ns/public/resource/instance-3", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME));
assertNotNull("gossip attribute definition not found", gossipDefinition);
ConstructionType accountConstruction = createAccountConstruction(RESOURCE_DUMMY_OID, null);
ResourceAttributeDefinitionType radt = new ResourceAttributeDefinitionType();
radt.setRef(new ItemPathType(gossipDefinition.getItemName()));
MappingType outbound = new MappingType();
radt.setOutbound(outbound);
ExpressionType expression = new ExpressionType();
outbound.setExpression(expression);
MappingType value = new MappingType();
// noinspection unchecked
PrismProperty<String> property = gossipDefinition.instantiate();
property.addRealValue("q");
List evaluators = expression.getExpressionEvaluator();
Collection<JAXBElement<RawType>> collection = StaticExpressionUtil.serializeValueElements(property);
ObjectFactory of = new ObjectFactory();
for (JAXBElement<RawType> obj : collection) {
// noinspection unchecked
evaluators.add(of.createValue(obj.getValue()));
}
value.setExpression(expression);
radt.setOutbound(value);
accountConstruction.getAttribute().add(radt);
PrismObject<UserType> jackBefore = getUserFromRepo(USER_JACK_OID);
assertEquals("Wrong # of assignments", 1, jackBefore.asObjectable().getAssignment().size());
Long assignmentId = jackBefore.asObjectable().getAssignment().get(0).getId();
ObjectDelta<UserType> accountAssignmentUserDelta = createReplaceAccountConstructionUserDelta(USER_JACK_OID, assignmentId, accountConstruction);
deltas.add(accountAssignmentUserDelta);
// Set user and assignment create channel to legacy value.
repositoryService.modifyObject(UserType.class, jackBefore.getOid(), deltaFor(UserType.class).item(UserType.F_METADATA, MetadataType.F_CREATE_CHANNEL).replace(Channel.USER.getLegacyUri()).item(UserType.F_ASSIGNMENT, assignmentId, AssignmentType.F_METADATA, MetadataType.F_CREATE_CHANNEL).replace(Channel.USER.getLegacyUri()).asItemDeltas(), result);
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<UserType> userJackOld = getUser(USER_JACK_OID);
display("User before change execution", userJackOld);
display("Deltas to execute execution", deltas);
when();
modelService.executeChanges(deltas, null, task, result);
then();
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
// First fetch: initial account read
// Second fetch: fetchback after modification to correctly process inbound
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 2);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack, "Jack Sparrow");
accountJackOid = getSingleLinkOid(userJack);
// MID-6547 (channel URI migration)
assertThat(userJack.asObjectable().getMetadata().getCreateChannel()).isEqualTo(Channel.USER.getUri());
assertThat(userJack.asObjectable().getAssignment().get(0).getMetadata().getCreateChannel()).isEqualTo(Channel.USER.getUri());
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, SelectorOptions.createCollection(GetOperationOptions.createRaw()), result);
assertDummyAccountShadowRepo(accountShadow, accountJackOid, USER_JACK_USERNAME);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountJackOid, USER_JACK_USERNAME, "Cpt. Jack Sparrow");
// Check account in dummy resource
assertDefaultDummyAccount(USER_JACK_USERNAME, "Cpt. Jack Sparrow", true);
DummyAccount dummyAccount = getDummyAccount(null, USER_JACK_USERNAME);
display(dummyAccount.debugDump());
assertDummyAccountAttribute(null, USER_JACK_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, "q");
assertDummyScriptsModify(userJack, true);
// Check audit
displayDumpable("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
Collection<ObjectDeltaOperation<? extends ObjectType>> auditExecutionDeltas = dummyAuditService.getExecutionDeltas();
assertEquals("Wrong number of execution deltas", 2, auditExecutionDeltas.size());
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, ShadowType.class);
dummyAuditService.assertTarget(USER_JACK_OID);
dummyAuditService.assertExecutionSuccess();
assertCounterIncrement(InternalCounters.SCRIPT_COMPILE_COUNT, 0);
assertSteadyResources();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType in project midpoint by Evolveum.
the class MappingParser method parseSources.
private void parseSources(OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, SecurityViolationException, ConfigurationException, CommunicationException {
if (m.defaultSource != null) {
m.sources.add(m.defaultSource);
m.defaultSource.recompute();
}
// FIXME remove this ugly hack
if (m.mappingBean instanceof MappingType) {
for (VariableBindingDefinitionType sourceDefinition : m.mappingBean.getSource()) {
Source<?, ?> source = parseSource(sourceDefinition, result);
source.recompute();
// Override existing sources (e.g. default source)
m.sources.removeIf(existing -> existing.getName().equals(source.getName()));
m.sources.add(source);
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType in project midpoint by Evolveum.
the class MappedItem method createMappings.
/**
* Creates the respective mapping(s).
*/
void createMappings(@NotNull PathKeyedMap<List<InboundMappingInContext<?, ?>>> mappingsMap) throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException, ConfigurationException, ObjectNotFoundException {
boolean fromAbsoluteState = processingMode == ProcessingMode.ABSOLUTE_STATE || processingMode == ProcessingMode.ABSOLUTE_STATE_IF_KNOWN;
if (fromAbsoluteState && !source.isAbsoluteStateAvailable()) {
LOGGER.trace("Skipping inbound mapping(s) for {} as they should be processed from absolute state, but we don't" + " have one", itemDescription);
return;
}
Item<V, D> currentProjectionItem = itemProvider.provide();
if (postProcessor != null) {
postProcessor.postProcess(itemAPrioriDelta, currentProjectionItem);
}
LOGGER.trace("Creating {} inbound mapping(s) for {} in {} ({}). Relevant values are:\n" + "- a priori item delta:\n{}\n" + "- current item:\n{}", mappingBeans.size(), itemDescription, source.getProjectionHumanReadableNameLazy(), fromAbsoluteState ? "absolute mode" : "relative mode", DebugUtil.debugDumpLazily(itemAPrioriDelta, 1), DebugUtil.debugDumpLazily(currentProjectionItem, 1));
if (currentProjectionItem != null && currentProjectionItem.hasRaw()) {
throw new SystemException("Property " + currentProjectionItem + " has raw parsing state," + " such property cannot be used in inbound expressions");
}
source.setValueMetadata(currentProjectionItem, itemAPrioriDelta);
ResourceType resource = source.getResource();
// Value for the $shadow ($projection, $account) variable.
// TODO Why do we use "object new" here? (We should perhaps go with ODO, shouldn't we?)
// Bear in mind that the value might not contain the full shadow (for example)
PrismObject<ShadowType> shadowVariableValue = source.getResourceObjectNew();
PrismObjectDefinition<ShadowType> shadowVariableDef = getShadowDefinition(shadowVariableValue);
Source<V, D> defaultSource = new Source<>(currentProjectionItem, itemAPrioriDelta, null, ExpressionConstants.VAR_INPUT_QNAME, itemDefinition);
defaultSource.recompute();
for (MappingType mappingBean : mappingBeans) {
String channel = source.getChannel();
if (!MappingImpl.isApplicableToChannel(mappingBean, channel)) {
LOGGER.trace("Mapping is not applicable to channel {}", channel);
continue;
}
MappingBuilder<V, D> builder = beans.mappingFactory.<V, D>createMappingBuilder().mappingBean(mappingBean).mappingKind(MappingKindType.INBOUND).implicitSourcePath(implicitSourcePath).contextDescription("inbound expression for " + itemDescription + " in " + resource).defaultSource(defaultSource).targetContext(target.focusDefinition).addVariableDefinition(ExpressionConstants.VAR_USER, target.focus, target.focusDefinition).addVariableDefinition(ExpressionConstants.VAR_FOCUS, target.focus, target.focusDefinition).addAliasRegistration(ExpressionConstants.VAR_USER, ExpressionConstants.VAR_FOCUS).addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, shadowVariableValue, shadowVariableDef).addVariableDefinition(ExpressionConstants.VAR_SHADOW, shadowVariableValue, shadowVariableDef).addVariableDefinition(ExpressionConstants.VAR_PROJECTION, shadowVariableValue, shadowVariableDef).addAliasRegistration(ExpressionConstants.VAR_ACCOUNT, ExpressionConstants.VAR_PROJECTION).addAliasRegistration(ExpressionConstants.VAR_SHADOW, ExpressionConstants.VAR_PROJECTION).addVariableDefinition(ExpressionConstants.VAR_RESOURCE, resource, resource.asPrismObject().getDefinition()).addVariableDefinition(ExpressionConstants.VAR_CONFIGURATION, context.getSystemConfiguration(), getSystemConfigurationDefinition()).addVariableDefinition(ExpressionConstants.VAR_OPERATION, context.getOperation(), String.class).variableResolver(variableProducer).valuePolicySupplier(context.createValuePolicySupplier()).originType(OriginType.INBOUND).originObject(resource).now(context.env.now);
if (!target.isFocusBeingDeleted()) {
assert target.focus != null;
TypedValue<PrismObject<F>> targetContext = new TypedValue<>(target.focus);
builder.originalTargetValues(ExpressionUtil.computeTargetValues(mappingBean.getTarget(), targetContext, builder.getVariables(), beans.mappingFactory.getObjectResolver(), "resolving target values", beans.prismContext, context.env.task, context.result));
}
MappingImpl<V, D> mapping = builder.build();
if (checkWeakSkip(mapping)) {
LOGGER.trace("Skipping because of mapping is weak and focus property has already a value");
continue;
}
InboundMappingInContext<V, D> mappingStruct = source.createInboundMappingInContext(mapping);
ItemPath targetFocusItemPath = mapping.getOutputPath();
if (ItemPath.isEmpty(targetFocusItemPath)) {
throw new ConfigurationException("Empty target path in " + mapping.getContextDescription());
}
checkTargetItemDefinitionKnown(targetFocusItemPath);
mappingsMap.computeIfAbsent(targetFocusItemPath, k -> new ArrayList<>()).add(mappingStruct);
}
}
Aggregations