Search in sources :

Example 46 with ItemPathType

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);
}
Also used : ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 47 with ItemPathType

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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) SystemException(com.evolveum.midpoint.util.exception.SystemException) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 48 with ItemPathType

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;
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType)

Example 49 with ItemPathType

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;
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) JAXBElement(javax.xml.bind.JAXBElement) List(java.util.List) ArrayList(java.util.ArrayList) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 50 with ItemPathType

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
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) ModelServiceLocator(com.evolveum.midpoint.gui.api.util.ModelServiceLocator) QName(javax.xml.namespace.QName) AbstractInitializedGuiIntegrationTest(com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)114 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)58 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)27 Test (org.testng.annotations.Test)27 QName (javax.xml.namespace.QName)25 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)24 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)21 List (java.util.List)18 NotNull (org.jetbrains.annotations.NotNull)18 PrismObject (com.evolveum.midpoint.prism.PrismObject)15 ArrayList (java.util.ArrayList)15 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)13 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)13 Collectors (java.util.stream.Collectors)13 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)12 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)11 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)11 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)11 OperationResultStatus (com.evolveum.midpoint.schema.result.OperationResultStatus)11 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)11