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());
}
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;
}
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);
}
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);
}
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);
}
Aggregations