Search in sources :

Example 36 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class SchemaProcessorTest method testRoundTripGeneric.

@Test
public void testRoundTripGeneric() throws SchemaException {
    // GIVEN
    PrismSchemaImpl schema = new PrismSchemaImpl(MidPointConstants.NS_RI);
    // Ordinary property
    schema.createPropertyDefinition("number1", DOMUtil.XSD_INT);
    // Property container
    MutablePrismContainerDefinition<?> containerDefinition = schema.createContainerDefinition("ContainerType");
    // ... in it ordinary property
    containerDefinition.createPropertyDefinition("login", DOMUtil.XSD_STRING);
    // ... and local property with a type from another schema
    containerDefinition.createPropertyDefinition("password", ProtectedStringType.COMPLEX_TYPE);
    // ... property reference
    containerDefinition.createPropertyDefinition(SchemaConstants.C_CREDENTIALS, CredentialsType.COMPLEX_TYPE);
    // ... read-only int property
    PrismPropertyDefinition counterProperty = containerDefinition.createPropertyDefinition("counter", DOMUtil.XSD_INT);
    counterProperty.toMutable().toMutable().setReadOnly();
    System.out.println("Generic schema before serializing to XSD: ");
    System.out.println(schema.debugDump());
    System.out.println();
    // WHEN
    Document xsd = schema.serializeToXsd();
    String stringXmlSchema = DOMUtil.serializeDOMToString(xsd);
    System.out.println("Generic schema after serializing to XSD: ");
    System.out.println(stringXmlSchema);
    System.out.println();
    Document parsedXsd = DOMUtil.parseDocument(stringXmlSchema);
    PrismSchema newSchema = PrismSchemaImpl.parse(DOMUtil.getFirstChildElement(parsedXsd), true, "serialized schema", PrismTestUtil.getPrismContext());
    System.out.println("Generic schema after parsing from XSD: ");
    System.out.println(newSchema.debugDump());
    System.out.println();
    // THEN
    PrismPropertyDefinition number1def = newSchema.findItemDefinitionByElementName(new ItemName(MidPointConstants.NS_RI, "number1"), PrismPropertyDefinition.class);
    assertEquals(new ItemName(MidPointConstants.NS_RI, "number1"), number1def.getItemName());
    assertEquals(DOMUtil.XSD_INT, number1def.getTypeName());
    PrismContainerDefinition newContainerDef = schema.findContainerDefinitionByType(new ItemName(MidPointConstants.NS_RI, "ContainerType"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "ContainerType"), newContainerDef.getTypeName());
    PrismPropertyDefinition loginDef = newContainerDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "login"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "login"), loginDef.getItemName());
    assertEquals(DOMUtil.XSD_STRING, loginDef.getTypeName());
    assertTrue("Read flag is wrong", loginDef.canRead());
    assertTrue("Create flag is wrong", loginDef.canAdd());
    assertTrue("Update flag is wrong", loginDef.canModify());
    PrismPropertyDefinition passwdDef = newContainerDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "password"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "password"), passwdDef.getItemName());
    assertEquals(ProtectedStringType.COMPLEX_TYPE, passwdDef.getTypeName());
    PrismPropertyDefinition credDef = newContainerDef.findPropertyDefinition(new ItemName(SchemaConstants.NS_C, "credentials"));
    assertEquals(new ItemName(SchemaConstants.NS_C, "credentials"), credDef.getItemName());
    assertEquals(new ItemName(SchemaConstants.NS_C, "CredentialsType"), credDef.getTypeName());
    PrismPropertyDefinition countDef = newContainerDef.findPropertyDefinition(new ItemName(MidPointConstants.NS_RI, "counter"));
    assertEquals(new ItemName(MidPointConstants.NS_RI, "counter"), countDef.getItemName());
    assertEquals(DOMUtil.XSD_INT, countDef.getTypeName());
    assertTrue("Read flag is wrong", countDef.canRead());
    assertFalse("Create flag is wrong", countDef.canAdd());
    assertFalse("Update flag is wrong", countDef.canModify());
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) PrismSchemaImpl(com.evolveum.midpoint.prism.impl.schema.PrismSchemaImpl) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ItemName(com.evolveum.midpoint.prism.path.ItemName) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) MutablePrismContainerDefinition(com.evolveum.midpoint.prism.MutablePrismContainerDefinition) Document(org.w3c.dom.Document) Test(org.testng.annotations.Test) AbstractSchemaTest(com.evolveum.midpoint.schema.AbstractSchemaTest)

Example 37 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class AssignmentCollector method evaluateAssignments.

private <AH extends AssignmentHolderType> Collection<EvaluatedAssignment<AH>> evaluateAssignments(AH focus, Collection<AssignmentType> assignments, AssignmentOrigin origin, AssignmentEvaluator<AH> assignmentEvaluator, Task task, OperationResult result) {
    List<EvaluatedAssignment<AH>> evaluatedAssignments = new ArrayList<>();
    RepositoryCache.enterLocalCaches(cacheConfigurationManager);
    try {
        PrismContainerDefinition<AssignmentType> standardAssignmentDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(AssignmentHolderType.class).findContainerDefinition(AssignmentHolderType.F_ASSIGNMENT);
        for (AssignmentType assignmentType : emptyIfNull(assignments)) {
            try {
                // noinspection unchecked
                PrismContainerDefinition<AssignmentType> definition = defaultIfNull(assignmentType.asPrismContainerValue().getDefinition(), standardAssignmentDefinition);
                ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(assignmentType), definition);
                EvaluatedAssignment<AH> assignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, focus, focus.toString(), origin, task, result);
                evaluatedAssignments.add(assignment);
            } catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException | PolicyViolationException | SecurityViolationException | ConfigurationException | CommunicationException e) {
                LOGGER.error("Error while processing assignment of {}: {}; assignment: {}", focus, e.getMessage(), assignmentType, e);
            }
        }
    } finally {
        RepositoryCache.exitLocalCaches();
    }
    return evaluatedAssignments;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ArrayList(java.util.ArrayList) EvaluatedAssignment(com.evolveum.midpoint.model.api.context.EvaluatedAssignment) ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) AssignmentHolderType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType)

Example 38 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class SqlQueryContext method orderingPath.

/**
 * @param <CQ> current entity query path type, can change during multi-segment path resolution
 * @param <CR> row type related to {@link CQ}
 */
@SuppressWarnings("unchecked")
private <CQ extends FlexibleRelationalPathBase<CR>, CR> Expression<?> orderingPath(ItemPath orderByItemPath) throws RepositoryException {
    ItemPath path = orderByItemPath;
    QueryModelMapping<?, CQ, CR> mapping = (QueryModelMapping<?, CQ, CR>) entityPathMapping;
    SqlQueryContext<?, CQ, CR> context = (SqlQueryContext<?, CQ, CR>) this;
    // We need definition for proper extension support.
    // For other cases it's safe for this to become null.
    PrismContainerDefinition<?> containerDefinition = (PrismContainerDefinition<?>) entityPathMapping.itemDefinition();
    while (path.size() > 1) {
        // Resolves only first element
        ItemRelationResolver<CQ, CR, ?, ?> resolver = mapping.relationResolver(path);
        ItemRelationResolver.ResolutionResult<?, ?> resolution = resolver.resolve(context);
        if (resolution.subquery) {
            throw new QueryException("Item path '" + orderByItemPath + "' cannot be used for ordering because subquery is used to resolve it.");
        }
        // CQ/CR for the next loop may be actually different from before, but that's OK
        mapping = (QueryModelMapping<?, CQ, CR>) resolution.mapping;
        context = (SqlQueryContext<?, CQ, CR>) resolution.context;
        if (containerDefinition != null) {
            containerDefinition = containerDefinition.findLocalItemDefinition(path.firstToName(), PrismContainerDefinition.class, false);
        }
        path = path.rest();
    }
    QName first = path.firstToQName();
    ItemDefinition<?> definition = first instanceof ItemName && containerDefinition != null ? containerDefinition.findItemDefinition((ItemName) first) : null;
    ItemSqlMapper<CQ, CR> mapper = mapping.itemMapper(first);
    return mapper.primaryPath(context.path(), definition);
}
Also used : QName(javax.xml.namespace.QName) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ItemName(com.evolveum.midpoint.prism.path.ItemName) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 39 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class TestAssignmentProcessor2 method test062JackDeputyOfGuybrushDeputyOfBarbossaInLoginMode.

// goes through assignmentEvaluator in order to employ login mode
// MID-4176
@Test(enabled = FIRST_PART)
public void test062JackDeputyOfGuybrushDeputyOfBarbossaInLoginMode() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = getTestOperationResult();
    PrismObject<UserType> jack = getUser(USER_JACK_OID);
    AssignmentType jackGuybrushAssignment = new AssignmentType(prismContext).targetRef(USER_GUYBRUSH_OID, UserType.COMPLEX_TYPE, SchemaConstants.ORG_DEPUTY);
    jackGuybrushAssignment.beginLimitTargetContent().allowTransitive(true);
    jack.asObjectable().getAssignment().add(jackGuybrushAssignment);
    LensContext<UserType> context = new LensContextPlaceholder<>(jack);
    AssignmentEvaluator<UserType> assignmentEvaluator = new AssignmentEvaluator.Builder<UserType>().referenceResolver(referenceResolver).focusOdo(new ObjectDeltaObject<>(jack, null, jack, jack.getDefinition())).lensContext(context).channel(context.getChannel()).modelBeans(modelBeans).objectResolver(objectResolver).systemObjectCache(systemObjectCache).relationRegistry(relationRegistry).prismContext(prismContext).mappingFactory(mappingFactory).mappingEvaluator(mappingEvaluator).contextLoader(contextLoader).activationComputer(activationComputer).now(clock.currentTimeXMLGregorianCalendar()).systemConfiguration(context.getSystemConfiguration()).loginMode(true).build();
    // noinspection unchecked,rawtypes
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(jackGuybrushAssignment), jackGuybrushAssignment.asPrismContainerValue().getDefinition());
    // WHEN
    when();
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, jack.asObjectable(), jack.toString(), AssignmentOrigin.createInObject(), task, result);
    // THEN
    then();
    displayDumpable("Output context", context);
    displayDumpable("Evaluated assignment", evaluatedAssignment);
    assertSuccess("Assignment evaluator failed (result)", result);
    assertEquals("Wrong evaluatedAssignment.isValid", true, evaluatedAssignment.isValid());
    assertTargets(evaluatedAssignment, true, "R1 R2 O3 R4 R5 R6", null, null, null, null, null);
    assertTargets(evaluatedAssignment, false, "guybrush barbossa MR1 MR2 MR3 MR4 MMR1", null, null, null, null, null);
    assertMembershipRef(evaluatedAssignment, "");
    assertOrgRef(evaluatedAssignment, "O3");
    assertDelegation(evaluatedAssignment, "guybrush barbossa R1 R2 O3 R4 R5 R6");
    PrismReferenceValue guybrushRef = evaluatedAssignment.getDelegationRefVals().stream().filter(v -> USER_GUYBRUSH_OID.equals(v.getOid())).findFirst().orElseThrow(() -> new AssertionError("No guybrush ref in delegation ref vals"));
    assertEquals("Wrong relation for guybrush delegation", SchemaConstants.ORG_DEPUTY, guybrushRef.getRelation());
    // the following entities are not evaluated in login mode
    assertConstructions(evaluatedAssignment, (String) null, null, null, null, null, null);
    assertFocusMappings(evaluatedAssignment, (String) null);
    assertFocusPolicyRules(evaluatedAssignment, (String) null);
    assertTargetPolicyRules(evaluatedAssignment, (String) null, null);
    assertAuthorizations(evaluatedAssignment, "R1 R2 O3 R4 R5 R6");
    assertGuiConfig(evaluatedAssignment, "R1 R2 O3 R4 R5 R6");
    assertSerializable(context);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDeltaObject(com.evolveum.midpoint.prism.util.ObjectDeltaObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) Test(org.testng.annotations.Test)

Example 40 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class ExtensionItemDeltaProcessor method process.

@Override
public void process(ItemDelta<?, ?> modification) throws RepositoryException, SchemaException {
    ItemPath itemPath = modification.getPath();
    if (modification.getDefinition() instanceof PrismContainerDefinition<?>) {
        // We do not index containers
        return;
    }
    Item<PrismValue, ?> item = context.findValueOrItem(itemPath);
    Collection<?> realValues = item != null ? item.getRealValues() : null;
    ItemDefinition<?> definition = modification.getDefinition();
    Objects.requireNonNull(definition, "Item '" + itemPath + "' without definition can't be saved.");
    ExtensionProcessor extProcessor = new ExtensionProcessor(context.repositoryContext());
    ExtensionProcessor.ExtItemInfo extItemInfo = extProcessor.findExtensionItem(definition, holderType);
    if (extItemInfo == null) {
        // not-indexed, no action
        return;
    }
    // If the extension is single value (and we know it now, we should proceed with deletion of
    // multivalue variant and vice-versa (this variants may be indroduced during raw import
    // or changes in multiplicity of extension definition or resource definition
    context.deleteItem(reverseCardinality(extProcessor, extItemInfo.item));
    if (realValues == null || realValues.isEmpty()) {
        context.deleteItem(extItemInfo.getId());
        return;
    }
    // changed value
    context.setChangedItem(extItemInfo.getId(), extProcessor.extItemValue(item, extItemInfo));
}
Also used : PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ExtensionProcessor(com.evolveum.midpoint.repo.sqale.ExtensionProcessor) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)41 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)23 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)18 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)17 Task (com.evolveum.midpoint.task.api.Task)16 Test (org.testng.annotations.Test)16 ItemDeltaItem (com.evolveum.midpoint.repo.common.expression.ItemDeltaItem)15 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)14 ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)13 QName (javax.xml.namespace.QName)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ArrayList (java.util.ArrayList)8 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)6 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)5 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)5 List (java.util.List)5 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)4 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)4 DropDownChoicePanel (com.evolveum.midpoint.web.component.input.DropDownChoicePanel)4