Search in sources :

Example 6 with SchemaRegistry

use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.

the class Validator method initialize.

private void initialize() {
    if (prismContext == null) {
        throw new IllegalStateException("No prism context set during validator initialization");
    }
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    midPointJavaxSchema = schemaRegistry.getJavaxSchema();
    xsdValidator = midPointJavaxSchema.newValidator();
    xsdValidator.setResourceResolver(prismContext.getEntityResolver());
}
Also used : SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry)

Example 7 with SchemaRegistry

use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.

the class WfContextUtil method createTrigger.

@NotNull
private static TriggerType createTrigger(XMLGregorianCalendar triggerTime, WorkItemActionsType actions, Pair<Duration, AbstractWorkItemActionType> notifyInfo, PrismContext prismContext, @Nullable String workItemId, @NotNull String handlerUri) throws SchemaException {
    TriggerType trigger = new TriggerType(prismContext);
    trigger.setTimestamp(triggerTime);
    trigger.setHandlerUri(handlerUri);
    ExtensionType extension = new ExtensionType(prismContext);
    trigger.setExtension(extension);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    if (workItemId != null) {
        // work item id
        @SuppressWarnings("unchecked") @NotNull PrismPropertyDefinition<String> workItemIdDef = prismContext.getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_WORK_ITEM_ID);
        PrismProperty<String> workItemIdProp = workItemIdDef.instantiate();
        workItemIdProp.addRealValue(workItemId);
        trigger.getExtension().asPrismContainerValue().add(workItemIdProp);
    }
    // actions
    if (actions != null) {
        @NotNull PrismContainerDefinition<WorkItemActionsType> workItemActionsDef = schemaRegistry.findContainerDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_WORK_ITEM_ACTIONS);
        PrismContainer<WorkItemActionsType> workItemActionsCont = workItemActionsDef.instantiate();
        workItemActionsCont.add(actions.asPrismContainerValue().clone());
        extension.asPrismContainerValue().add(workItemActionsCont);
    }
    // time before + action
    if (notifyInfo != null) {
        @NotNull PrismContainerDefinition<AbstractWorkItemActionType> workItemActionDef = schemaRegistry.findContainerDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_WORK_ITEM_ACTION);
        PrismContainer<AbstractWorkItemActionType> workItemActionCont = workItemActionDef.instantiate();
        workItemActionCont.add(notifyInfo.getValue().asPrismContainerValue().clone());
        extension.asPrismContainerValue().add(workItemActionCont);
        @SuppressWarnings("unchecked") @NotNull PrismPropertyDefinition<Duration> timeBeforeActionDef = schemaRegistry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_TIME_BEFORE_ACTION);
        PrismProperty<Duration> timeBeforeActionProp = timeBeforeActionDef.instantiate();
        timeBeforeActionProp.addRealValue(notifyInfo.getKey());
        extension.asPrismContainerValue().add(timeBeforeActionProp);
    }
    return trigger;
}
Also used : Duration(javax.xml.datatype.Duration) NotNull(org.jetbrains.annotations.NotNull) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with SchemaRegistry

use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.

the class TestPrismContext method testCompileTimeClassmap.

@Test
public void testCompileTimeClassmap() throws SchemaException, SAXException, IOException {
    System.out.println("===[ testCompileTimeClassmap ]===");
    // WHEN
    PrismContext prismContext = constructInitializedPrismContext();
    // THEN
    assertNotNull("No prism context", prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull("No schema registry in context", schemaRegistry);
    SchemaDescription fooDesc = schemaRegistry.findSchemaDescriptionByNamespace(NS_FOO);
    Map<QName, Class<?>> map = fooDesc.getXsdTypeTocompileTimeClassMap();
    assertNotNull("No XsdTypeTocompileTimeClassMap", map);
    assertFalse("Empty XsdTypeTocompileTimeClassMap", map.isEmpty());
    assertMapping(map, UserType.class, USER_TYPE_QNAME);
    assertMapping(map, AccountType.class, ACCOUNT_TYPE_QNAME);
    assertMapping(map, AssignmentType.class, ASSIGNMENT_TYPE_QNAME);
    assertMapping(map, ActivationType.class, ACTIVATION_TYPE_QNAME);
    // This is not a container, but it should be in the map anyway
    assertMapping(map, AccountConstructionType.class, ACCOUNT_CONSTRUCTION_TYPE_QNAME);
}
Also used : SchemaDescription(com.evolveum.midpoint.prism.schema.SchemaDescription) QName(javax.xml.namespace.QName) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test)

Example 9 with SchemaRegistry

use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.

the class TestPrismContext method testBasicSchemas.

@Test
public void testBasicSchemas() throws SchemaException, SAXException, IOException {
    System.out.println("===[ testBasicSchemas ]===");
    // WHEN
    PrismContext prismContext = constructInitializedPrismContext();
    // THEN
    assertNotNull("No prism context", prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull("No schema registry in context", schemaRegistry);
    System.out.println("Schema registry:");
    System.out.println(schemaRegistry.debugDump());
    PrismSchema fooSchema = schemaRegistry.findSchemaByNamespace(NS_FOO);
    System.out.println("Foo schema:");
    System.out.println(fooSchema.debugDump());
    // Assert USER definition
    PrismObjectDefinition<UserType> userDefinition = fooSchema.findObjectDefinitionByElementName(new QName(NS_FOO, "user"));
    assertNotNull("No user definition", userDefinition);
    System.out.println("User definition:");
    System.out.println(userDefinition.debugDump());
    PrismObjectDefinition<UserType> userDefinitionByClass = schemaRegistry.findObjectDefinitionByCompileTimeClass(UserType.class);
    assertTrue("Different user def", userDefinition == userDefinitionByClass);
    assertUserDefinition(userDefinition);
    // Assert ACCOUNT definition
    PrismObjectDefinition<AccountType> accountDefinition = fooSchema.findObjectDefinitionByElementName(new QName(NS_FOO, "account"));
    assertNotNull("No account definition", accountDefinition);
    System.out.println("Account definition:");
    System.out.println(accountDefinition.debugDump());
    PrismObjectDefinition<AccountType> accountDefinitionByClass = schemaRegistry.findObjectDefinitionByCompileTimeClass(AccountType.class);
    assertTrue("Different user def", accountDefinition == accountDefinitionByClass);
    assertAccountDefinition(accountDefinition);
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) QName(javax.xml.namespace.QName) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) UserType(com.evolveum.midpoint.prism.foo.UserType) AccountType(com.evolveum.midpoint.prism.foo.AccountType) Test(org.testng.annotations.Test)

Example 10 with SchemaRegistry

use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.

the class PageResourceEdit method updateConnectorRef.

/**
     * Method which attempts to resolve connector reference filter to actual connector (if necessary).
     *
     * @param resource {@link PrismObject} resource
     */
private void updateConnectorRef(PrismObject<ResourceType> resource, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    if (resource == null) {
        return;
    }
    PrismReference resourceRef = resource.findReference(ResourceType.F_CONNECTOR_REF);
    if (resourceRef == null || resourceRef.getValue() == null) {
        return;
    }
    PrismReferenceValue refValue = resourceRef.getValue();
    if (StringUtils.isNotEmpty(refValue.getOid())) {
        return;
    }
    if (refValue.getFilter() == null) {
        return;
    }
    SchemaRegistry registry = getPrismContext().getSchemaRegistry();
    PrismObjectDefinition objDef = registry.findObjectDefinitionByCompileTimeClass(ConnectorType.class);
    ObjectFilter filter = QueryConvertor.parseFilter(refValue.getFilter(), objDef);
    List<PrismObject<ConnectorType>> connectors = getModelService().searchObjects(ConnectorType.class, ObjectQuery.createObjectQuery(filter), null, task, result);
    if (connectors.size() != 1) {
        return;
    }
    PrismObject<ConnectorType> connector = connectors.get(0);
    refValue.setOid(connector.getOid());
    refValue.setTargetType(ConnectorType.COMPLEX_TYPE);
    refValue.setFilter(null);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) PrismReference(com.evolveum.midpoint.prism.PrismReference) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry)

Aggregations

SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)39 Test (org.testng.annotations.Test)26 PrismContext (com.evolveum.midpoint.prism.PrismContext)10 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)9 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)9 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 Task (com.evolveum.midpoint.task.api.Task)6 QName (javax.xml.namespace.QName)6 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)5 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)4 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)4 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)3 PrismObjectDefinition (com.evolveum.midpoint.prism.PrismObjectDefinition)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ConnectorConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType)3 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)2 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)2