use of io.atlasmap.v2.MappingType in project midpoint by Evolveum.
the class TestParseMappingConst method testParseSerialize.
@Test
public void testParseSerialize() throws Exception {
displayTestTitle("testParseSerialize");
PrismContext prismContext = getPrismContext();
PrismParser parser = prismContext.parserFor(getFile());
PrismPropertyValue<MappingType> mappingPval = parser.parseItemValue();
System.out.println("\nmappingPval:\n" + mappingPval.debugDump(1));
PrismSerializer<RootXNode> xserializer = prismContext.xnodeSerializer();
RootXNode xnode = xserializer.root(new QName("dummy")).serialize(mappingPval);
System.out.println("\nSerialized xnode:\n" + xnode.debugDump(1));
MapXNode xexpression = (MapXNode) ((MapXNode) xnode.getSubnode()).get(new QName("expression"));
ListXNode xconstList = (ListXNode) xexpression.get(new QName("const"));
XNode xconst = xconstList.get(0);
if (!(xconst instanceof PrimitiveXNode<?>)) {
AssertJUnit.fail("const is not primitive: " + xconst);
}
}
use of io.atlasmap.v2.MappingType in project midpoint by Evolveum.
the class TestParseMappingConst method assertPrismPropertyValueLocal.
@Override
protected void assertPrismPropertyValueLocal(PrismPropertyValue<MappingType> value) throws SchemaException {
MappingType mappingType = value.getValue();
ExpressionType expressionType = mappingType.getExpression();
List<JAXBElement<?>> expressionEvaluatorElements = expressionType.getExpressionEvaluator();
assertEquals("Wrong number of expression evaluator elemenets", 1, expressionEvaluatorElements.size());
JAXBElement<?> expressionEvaluatorElement = expressionEvaluatorElements.get(0);
Object evaluatorElementObject = expressionEvaluatorElement.getValue();
if (!(evaluatorElementObject instanceof ConstExpressionEvaluatorType)) {
AssertJUnit.fail("Const expression is of type " + evaluatorElementObject.getClass().getName());
}
ConstExpressionEvaluatorType constExpressionEvaluatorType = (ConstExpressionEvaluatorType) evaluatorElementObject;
System.out.println("ConstExpressionEvaluatorType: " + constExpressionEvaluatorType);
assertEquals("Wrong value in const evaluator", "foo", constExpressionEvaluatorType.getValue());
}
use of io.atlasmap.v2.MappingType in project midpoint by Evolveum.
the class OutboundProcessor method processOutbound.
public <F extends FocusType> void processOutbound(LensContext<F> context, LensProjectionContext projCtx, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
ResourceShadowDiscriminator discr = projCtx.getResourceShadowDiscriminator();
ObjectDelta<ShadowType> projectionDelta = projCtx.getDelta();
if (projectionDelta != null && projectionDelta.getChangeType() == ChangeType.DELETE) {
LOGGER.trace("Processing outbound expressions for {} skipped, DELETE account delta", discr);
// No point in evaluating outbound
return;
}
LOGGER.trace("Processing outbound expressions for {} starting", discr);
RefinedObjectClassDefinition rOcDef = projCtx.getStructuralObjectClassDefinition();
if (rOcDef == null) {
LOGGER.error("Definition for {} not found in the context, but it should be there, dumping context:\n{}", discr, context.debugDump());
throw new IllegalStateException("Definition for " + discr + " not found in the context, but it should be there");
}
ObjectDeltaObject<F> focusOdo = context.getFocusContext().getObjectDeltaObject();
ObjectDeltaObject<ShadowType> projectionOdo = projCtx.getObjectDeltaObject();
Construction<F> outboundConstruction = new Construction<>(null, projCtx.getResource());
outboundConstruction.setRefinedObjectClassDefinition(rOcDef);
Collection<RefinedObjectClassDefinition> auxiliaryObjectClassDefinitions = rOcDef.getAuxiliaryObjectClassDefinitions();
if (auxiliaryObjectClassDefinitions != null) {
for (RefinedObjectClassDefinition auxiliaryObjectClassDefinition : auxiliaryObjectClassDefinitions) {
outboundConstruction.addAuxiliaryObjectClassDefinition(auxiliaryObjectClassDefinition);
}
}
String operation = projCtx.getOperation().getValue();
for (QName attributeName : rOcDef.getNamesOfAttributesWithOutboundExpressions()) {
RefinedAttributeDefinition<?> refinedAttributeDefinition = rOcDef.findAttributeDefinition(attributeName);
final MappingType outboundMappingType = refinedAttributeDefinition.getOutboundMappingType();
if (outboundMappingType == null) {
continue;
}
if (refinedAttributeDefinition.isIgnored(LayerType.MODEL)) {
LOGGER.trace("Skipping processing outbound mapping for attribute {} because it is ignored", attributeName);
continue;
}
Mapping.Builder<PrismPropertyValue<?>, RefinedAttributeDefinition<?>> builder = mappingFactory.createMappingBuilder(outboundMappingType, "outbound mapping for " + PrettyPrinter.prettyPrint(refinedAttributeDefinition.getName()) + " in " + rOcDef.getResourceType());
builder = builder.originObject(rOcDef.getResourceType()).originType(OriginType.OUTBOUND);
Mapping<PrismPropertyValue<?>, RefinedAttributeDefinition<?>> evaluatedMapping = evaluateMapping(builder, attributeName, refinedAttributeDefinition, focusOdo, projectionOdo, operation, rOcDef, null, context, projCtx, task, result);
if (evaluatedMapping != null) {
outboundConstruction.addAttributeMapping(evaluatedMapping);
}
}
for (QName assocName : rOcDef.getNamesOfAssociationsWithOutboundExpressions()) {
RefinedAssociationDefinition associationDefinition = rOcDef.findAssociationDefinition(assocName);
final MappingType outboundMappingType = associationDefinition.getOutboundMappingType();
if (outboundMappingType == null) {
continue;
}
// if (associationDefinition.isIgnored(LayerType.MODEL)) {
// LOGGER.trace("Skipping processing outbound mapping for attribute {} because it is ignored", assocName);
// continue;
// }
Mapping.Builder<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> mappingBuilder = mappingFactory.createMappingBuilder(outboundMappingType, "outbound mapping for " + PrettyPrinter.prettyPrint(associationDefinition.getName()) + " in " + rOcDef.getResourceType());
PrismContainerDefinition<ShadowAssociationType> outputDefinition = getAssociationContainerDefinition();
Mapping<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> evaluatedMapping = (Mapping) evaluateMapping(mappingBuilder, assocName, outputDefinition, focusOdo, projectionOdo, operation, rOcDef, associationDefinition.getAssociationTarget(), context, projCtx, task, result);
if (evaluatedMapping != null) {
outboundConstruction.addAssociationMapping(evaluatedMapping);
}
}
projCtx.setOutboundConstruction(outboundConstruction);
}
use of io.atlasmap.v2.MappingType in project midpoint by Evolveum.
the class TestIteration method test200JackAssignAccountDummyPinkConflicting.
@Test
public void test200JackAssignAccountDummyPinkConflicting() throws Exception {
final String TEST_NAME = "test200JackAssignAccountDummyPinkConflicting";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
// Make sure there is a conflicting account and also a shadow for it
DummyAccount account = new DummyAccount(ACCOUNT_JACK_DUMMY_USERNAME);
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Jack Pinky");
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Red Sea");
dummyResourcePink.addAccount(account);
repoAddObject(createShadow(resourceDummyPink, ACCOUNT_JACK_DUMMY_USERNAME), result);
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
// assignment with weapon := 'pistol' (test for
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
AssignmentType assignmentType = createConstructionAssignment(RESOURCE_DUMMY_PINK_OID, ShadowKindType.ACCOUNT, null);
ConstructionType constructionType = assignmentType.getConstruction();
ResourceAttributeDefinitionType attributeDefinitionType = new ResourceAttributeDefinitionType();
attributeDefinitionType.setRef(new ItemPathType(new ItemPath(dummyResourceCtlPink.getAttributeWeaponQName())));
MappingType mappingType = new MappingType();
mappingType.setStrength(MappingStrengthType.STRONG);
ExpressionType expressionType = new ExpressionType();
expressionType.getExpressionEvaluator().add(new ObjectFactory().createValue(RawType.create("pistol", prismContext)));
mappingType.setExpression(expressionType);
attributeDefinitionType.setOutbound(mappingType);
constructionType.getAttribute().add(attributeDefinitionType);
modifications.add(createAssignmentModification(assignmentType, true));
ObjectDelta<UserType> accountAssignmentUserDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
deltas.add(accountAssignmentUserDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack);
assertLinks(userJack, 2);
assertAccount(userJack, RESOURCE_DUMMY_OID);
assertAccount(userJack, RESOURCE_DUMMY_PINK_OID);
String accountPinkOid = getLinkRefOid(userJack, RESOURCE_DUMMY_PINK_OID);
// Check shadow
PrismObject<ShadowType> accountPinkShadow = repositoryService.getObject(ShadowType.class, accountPinkOid, null, result);
assertAccountShadowRepo(accountPinkShadow, accountPinkOid, "jack1", resourceDummyPinkType);
// Check account
PrismObject<ShadowType> accountPinkModel = modelService.getObject(ShadowType.class, accountPinkOid, null, task, result);
assertAccountShadowModel(accountPinkModel, accountPinkOid, "jack1", resourceDummyPinkType);
display("accountPinkModel", accountPinkModel);
PrismAsserts.assertPropertyValue(accountPinkModel, dummyResourceCtlPink.getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME), "pistol");
// Check account in dummy resource
assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
// The original conflicting account should still remain
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Pinky", true);
// The new account
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "jack1", "Jack Sparrow", true);
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
dummyAuditService.assertExecutionSuccess();
}
use of io.atlasmap.v2.MappingType in project midpoint by Evolveum.
the class WizardUtil method createEmptyMapping.
public static MappingType createEmptyMapping() {
MappingType mapping = new MappingType();
mapping.setAuthoritative(true);
return mapping;
}
Aggregations