use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class TestPlentyOfAssignments method initSystem.
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
initDummyResourcePirate(null, RESOURCE_DUMMY_FILE, RESOURCE_DUMMY_OID, initTask, initResult);
importObjectFromFile(ROLE_BASIC_FILE, initResult);
ObjectFactory objectFactory = new ObjectFactory();
generateRoles(NUMBER_OF_GENERATED_EMPTY_ROLES, "Empty Role %04d", GENERATED_EMPTY_ROLE_OID_FORMAT, null, initResult);
generateRoles(NUMBER_OF_GENERATED_DUMMY_ROLES, "Dummy Role %04d", GENERATED_DUMMY_ROLE_OID_FORMAT, (role, i) -> {
ItemPathType attrPath = new ItemPathType(ItemPath.create(new QName(RESOURCE_DUMMY_NS, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME)));
JAXBElement<Object> evaluator = objectFactory.createValue(formatRum(i));
role.beginInducement().beginConstruction().resourceRef(RESOURCE_DUMMY_OID, ResourceType.COMPLEX_TYPE).kind(ShadowKindType.ACCOUNT).beginAttribute().ref(attrPath).beginOutbound().beginExpression().expressionEvaluator(evaluator);
}, initResult);
inspector = new CountingInspector();
InternalMonitor.setInspector(inspector);
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class TestPlentyOfAssignments method test200DummyGroups.
/**
* Create dummy groups that can be used for associationTargetSearch later on.
* Create them from midPoint so they have shadows.
* <p>
* MID-3938 #8
*/
@Test
public void test200DummyGroups() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
// WHEN
when();
PrismObjectDefinition<ShadowType> shadowDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class);
PrismObjectDefinition<RoleType> roleDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(RoleType.class);
ResourceSchema rSchema = ResourceSchemaFactory.getCompleteSchema(getDummyResourceObject());
ResourceObjectClassDefinition rOcDef = rSchema.findObjectClassDefinition(getDummyResourceController().getGroupObjectClass());
ObjectFactory objectFactory = new ObjectFactory();
ItemPath nameAttributePath = ItemPath.create(ShadowType.F_ATTRIBUTES, SchemaConstants.ICFS_NAME);
for (int i = 0; i < NUMBER_OF_GENERATED_DUMMY_GROUPS; i++) {
PrismObject<ShadowType> shadow = shadowDef.instantiate();
ShadowType shadowType = shadow.asObjectable();
shadowType.resourceRef(RESOURCE_DUMMY_OID, ResourceType.COMPLEX_TYPE).objectClass(rOcDef.getTypeName());
ResourceAttributeContainer attributesContainer = ShadowUtil.getOrCreateAttributesContainer(shadow, rOcDef);
ResourceAttribute<String> nameAttribute = attributesContainer.findOrCreateAttribute(SchemaConstants.ICFS_NAME);
String groupName = formatGroupName(i);
nameAttribute.setRealValue(groupName);
display("Group shadow " + i, shadow);
addObject(shadow, task, result);
PrismObject<RoleType> role = roleDef.instantiate();
RoleType roleType = role.asObjectable();
ItemPathType assPath = new ItemPathType(ItemPath.create(RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME));
SearchObjectExpressionEvaluatorType associationTargetSearchType = new SearchObjectExpressionEvaluatorType();
EqualFilter<String> filter = prismContext.queryFactory().createEqual(nameAttributePath, null, null, prismContext, groupName);
SearchFilterType filterType = prismContext.getQueryConverter().createSearchFilterType(filter);
associationTargetSearchType.setFilter(filterType);
associationTargetSearchType.setSearchStrategy(ObjectSearchStrategyType.IN_REPOSITORY);
JAXBElement<SearchObjectExpressionEvaluatorType> evaluator = objectFactory.createAssociationTargetSearch(associationTargetSearchType);
roleType.oid(generateRoleOid(GENERATED_DUMMY_GROUP_ROLE_OID_FORMAT, i)).name(String.format("Group role %04d", i)).beginInducement().beginConstruction().resourceRef(RESOURCE_DUMMY_OID, ResourceType.COMPLEX_TYPE).kind(ShadowKindType.ACCOUNT).beginAssociation().ref(assPath).beginOutbound().beginExpression().expressionEvaluator(evaluator);
try {
IntegrationTestTools.displayXml("RRRRRRRRR group", role);
} catch (SchemaException e) {
throw new SystemException(e);
}
addObject(role, task, result);
}
// THEN
then();
assertSuccess(result);
Collection<DummyGroup> dummyGroups = getDummyResource().listGroups();
assertEquals("Wrong number of dummy groups", NUMBER_OF_GENERATED_DUMMY_GROUPS, dummyGroups.size());
assertShadows(NUMBER_OF_GENERATED_DUMMY_GROUPS);
assertObjects(RoleType.class, NUMBER_OF_GENERATED_EMPTY_ROLES + NUMBER_OF_GENERATED_DUMMY_ROLES + NUMBER_OF_ORDINARY_ROLES + NUMBER_OF_GENERATED_DUMMY_GROUPS);
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class AssignmentEditorPanel method findOrCreateValueConstruction.
private ResourceAttributeDefinitionType findOrCreateValueConstruction(PrismPropertyDefinition<?> attrDef) {
ResourceAttributeDefinitionType construction = new ResourceAttributeDefinitionType();
construction.setRef(new ItemPathType(ItemPath.create(attrDef.getItemName())));
return construction;
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class ACAttributeDto method getConstruction.
public ResourceAttributeDefinitionType getConstruction(PrismContext prismContext) throws SchemaException {
if (isEmpty()) {
return null;
}
ResourceAttributeDefinitionType attrConstruction = new ResourceAttributeDefinitionType();
if (construction != null && construction.getRef() != null) {
// preserves original ref (including xmlns prefix!) - in order to avoid false deltas when comparing old and new values
attrConstruction.setRef(construction.getRef());
} else {
attrConstruction.setRef(new ItemPathType(definition.getItemName()));
}
MappingType outbound;
if (construction != null && construction.getOutbound() != null) {
outbound = construction.getOutbound().clone();
} else {
outbound = new MappingType();
outbound.setStrength(MappingStrengthType.STRONG);
}
attrConstruction.setOutbound(outbound);
ExpressionType expression = new ExpressionType();
outbound.setExpression(expression);
List<ACValueConstructionDto> values = getValues();
PrismProperty property = definition.instantiate();
// needed in serializeValueElements below
property.revive(prismContext);
for (ACValueConstructionDto dto : values) {
if (dto.getValue() == null) {
continue;
}
property.addRealValue(dto.getValue());
}
List evaluators = expression.getExpressionEvaluator();
List<JAXBElement<RawType>> collection = StaticExpressionUtil.serializeValueElements(property);
ObjectFactory of = new ObjectFactory();
for (JAXBElement<RawType> evaluator : collection) {
evaluators.add(evaluator);
}
if (evaluators.isEmpty()) {
return null;
}
return attrConstruction;
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class TestWrapperDelta method test111modifyUserAssignment.
@Test
public void test111modifyUserAssignment() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
PrismObject<UserType> userElaineBefore = getUser(USER_ELAINE_OID);
WrapperContext ctx = new WrapperContext(task, result);
PrismObjectWrapper<UserType> objectWrapper = createObjectWrapper(userElaineBefore, ItemStatus.NOT_CHANGED, ctx);
PrismContainerWrapper<AssignmentType> assignment = objectWrapper.findContainer(UserType.F_ASSIGNMENT);
assertNotNull("unexpected null assignment wrapper", assignment);
assertEquals("Unexpected values for assignment " + assignment.getValues().size(), 1, assignment.getValues().size());
PrismContainerValueWrapper<AssignmentType> assignmentValue = assignment.getValues().iterator().next();
PrismContainerWrapper<ResourceAttributeDefinitionType> resourceAttrDefWrapper = assignmentValue.findContainer(ItemPath.create(AssignmentType.F_CONSTRUCTION, ConstructionType.F_ATTRIBUTE));
assertNotNull("unexpected null assignment wrapper", resourceAttrDefWrapper);
assertEquals("Unexpected values for assignment " + resourceAttrDefWrapper.getValues().size(), 0, resourceAttrDefWrapper.getValues().size());
ModelServiceLocator locator = getServiceLocator(task);
PrismContainerValue<ResourceAttributeDefinitionType> newAttribute = resourceAttrDefWrapper.getItem().createNewValue();
PrismContainerValueWrapper<ResourceAttributeDefinitionType> resourceAttrDefValueWrapper = locator.createValueWrapper(resourceAttrDefWrapper, newAttribute, ValueStatus.ADDED, ctx);
resourceAttrDefWrapper.getValues().add(resourceAttrDefValueWrapper);
PrismPropertyWrapper<ItemPathType> attributeRefWrapper = resourceAttrDefValueWrapper.findProperty(ResourceAttributeDefinitionType.F_REF);
attributeRefWrapper.getValue().setRealValue(new ItemPathType(ItemPath.create(SchemaConstants.ICFS_NAME)));
PrismPropertyWrapper<QName> matchingRule = resourceAttrDefValueWrapper.findProperty(ResourceAttributeDefinitionType.F_MATCHING_RULE);
matchingRule.getValue().setRealValue(PrismConstants.STRING_IGNORE_CASE_MATCHING_RULE_NAME);
PrismContainerWrapper<MappingType> outbound = resourceAttrDefValueWrapper.findContainer(ResourceAttributeDefinitionType.F_OUTBOUND);
PrismContainerValueWrapper<MappingType> mapping = outbound.getValue();
MappingType mappingType = mapping.getRealValue();
mappingType.setExpression(createAsIsExpression());
ObjectDelta<UserType> delta = objectWrapper.getObjectDelta();
assertModificationsSize(delta, 1);
logger.info("Attr delta: {}", delta.debugDump());
ResourceAttributeDefinitionType expectedvalue = new ResourceAttributeDefinitionType(locator.getPrismContext());
expectedvalue.setRef(new ItemPathType(ItemPath.create(SchemaConstants.ICFS_NAME)));
expectedvalue.setMatchingRule(PrismConstants.STRING_IGNORE_CASE_MATCHING_RULE_NAME);
MappingType expectedMapping = new MappingType();
expectedMapping.setExpression(createAsIsExpression());
expectedvalue.setOutbound(expectedMapping);
assertModification(delta, resourceAttrDefValueWrapper.getPath(), ModificationTypeType.ADD, expectedvalue);
executeChanges(delta, executeOptions().raw(), task, result);
display(result);
assertSuccess(result);
PrismObject<UserType> userElaineAfter = getUser(USER_ELAINE_OID);
PrismContainer<AssignmentType> assignmentAfter = userElaineAfter.findContainer(UserType.F_ASSIGNMENT);
assertNotNull("Unexpected null assignment container for " + userElaineAfter, assignmentAfter);
assertEquals("Unexpected number of assignments, " + assignmentAfter.debugDump(), 1, assignmentAfter.getValues().size());
PrismContainerValue<AssignmentType> assignmentTypeAfter = assignmentAfter.getValues().iterator().next();
AssignmentType expected = new AssignmentType(locator.getPrismContext());
ConstructionType constructionType = new ConstructionType(locator.getPrismContext());
ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(resourceDummy.getOid(), ObjectTypes.RESOURCE);
ref.setRelation(SchemaConstants.ORG_DEFAULT);
constructionType.setResourceRef(ref);
constructionType.setKind(ShadowKindType.ACCOUNT);
constructionType.setIntent("default");
constructionType.getAttribute().add(expectedvalue);
expected.setConstruction(constructionType);
ActivationType activationType = new ActivationType(locator.getPrismContext());
activationType.setEffectiveStatus(ActivationStatusType.ENABLED);
expected.setActivation(activationType);
// TODO assertions after
}
Aggregations