use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.
the class IntegrationTestTools method assertConnectorSchemaSanity.
public static void assertConnectorSchemaSanity(ConnectorType conn, PrismContext prismContext) throws SchemaException {
XmlSchemaType xmlSchemaType = conn.getSchema();
assertNotNull("xmlSchemaType is null", xmlSchemaType);
Element connectorXsdSchemaElement = ConnectorTypeUtil.getConnectorXsdSchema(conn);
assertNotNull("No schema", connectorXsdSchemaElement);
Element xsdElement = ObjectTypeUtil.findXsdElement(xmlSchemaType);
assertNotNull("No xsd:schema element in xmlSchemaType", xsdElement);
display("XSD schema of " + conn, DOMUtil.serializeDOMToString(xsdElement));
// Try to parse the schema
PrismSchema schema = null;
try {
schema = PrismSchemaImpl.parse(xsdElement, true, "schema of " + conn, prismContext);
} catch (SchemaException e) {
throw new SchemaException("Error parsing schema of " + conn + ": " + e.getMessage(), e);
}
assertConnectorSchemaSanity(schema, conn.toString(), SchemaConstants.ICF_FRAMEWORK_URI.equals(conn.getFramework()));
}
use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.
the class ResourceManager method applyConnectorSchemaToResource.
/**
* Apply proper definition (connector schema) to the resource.
*/
private void applyConnectorSchemaToResource(ConnectorSpec connectorSpec, PrismObjectDefinition<ResourceType> resourceDefinition, PrismObject<ResourceType> resource, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
ConnectorType connectorType = connectorManager.getConnectorTypeReadOnly(connectorSpec, result);
PrismSchema connectorSchema = connectorManager.getConnectorSchema(connectorType);
if (connectorSchema == null) {
throw new SchemaException("No connector schema in " + connectorType);
}
PrismContainerDefinition<ConnectorConfigurationType> configurationContainerDefinition = ConnectorTypeUtil.findConfigurationContainerDefinition(connectorType, connectorSchema);
if (configurationContainerDefinition == null) {
throw new SchemaException("No configuration container definition in schema of " + connectorType);
}
configurationContainerDefinition = configurationContainerDefinition.clone();
PrismContainer<ConnectorConfigurationType> configurationContainer = connectorSpec.getConnectorConfiguration();
// the element is global in the connector schema. therefore it does not have correct maxOccurs
if (configurationContainer != null) {
configurationContainerDefinition.adoptElementDefinitionFrom(configurationContainer.getDefinition());
configurationContainer.applyDefinition(configurationContainerDefinition, true);
try {
configurationContainer.accept(visitable -> {
if ((visitable instanceof PrismProperty<?>)) {
try {
evaluateExpression((PrismProperty<?>) visitable, resource, task, result);
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException e) {
throw new TunnelException(e);
}
}
});
} catch (TunnelException te) {
Throwable e = te.getCause();
if (e instanceof SchemaException) {
throw (SchemaException) e;
} else if (e instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) e;
} else if (e instanceof ExpressionEvaluationException) {
throw (ExpressionEvaluationException) e;
} else if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else if (e instanceof Error) {
throw (Error) e;
} else {
throw new SystemException(e);
}
}
} else {
configurationContainerDefinition.adoptElementDefinitionFrom(resourceDefinition.findContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION));
}
if (connectorSpec.getConnectorName() == null) {
// Default connector, for compatibility
// It does not make sense to update this for any other connectors.
// We cannot have one definition for addiitionalConnector[1]/connectorConfiguraiton and
// different definition for addiitionalConnector[2]/connectorConfiguraiton in the object definition.
// The way to go is to set up definitions on the container level.
resourceDefinition.replaceDefinition(ResourceType.F_CONNECTOR_CONFIGURATION, configurationContainerDefinition);
}
}
use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.
the class ConnectorFactoryConnIdImpl method createConnectorInstance.
/**
* Creates new connector instance.
*
* It will initialize the connector by taking the XML Resource definition,
* transforming it to the ICF configuration and applying that to the new
* connector instance.
*
* @throws ObjectNotFoundException
* @throws SchemaException
*
*/
@Override
public ConnectorInstance createConnectorInstance(ConnectorType connectorType, String namespace, String desc) throws ObjectNotFoundException, SchemaException {
ConnectorInfo cinfo = getConnectorInfo(connectorType);
if (cinfo == null) {
LOGGER.error("Failed to instantiate {}", ObjectTypeUtil.toShortString(connectorType));
LOGGER.debug("Connector key: {}, host: {}", getConnectorKey(connectorType), ObjectTypeUtil.toShortString(connectorType));
LOGGER.trace("Connector object: {}", ObjectTypeUtil.dump(connectorType));
LOGGER.trace("Connector host object: {}", ObjectTypeUtil.dump(connectorType.getConnectorHost()));
throw new ObjectNotFoundException("The classes (JAR) of " + ObjectTypeUtil.toShortString(connectorType) + " were not found by the ICF framework; bundle=" + connectorType.getConnectorBundle() + " connector type=" + connectorType.getConnectorType() + ", version=" + connectorType.getConnectorVersion());
}
PrismSchema connectorSchema = UcfUtil.getConnectorSchema(connectorType, prismContext);
if (connectorSchema == null) {
connectorSchema = generateConnectorConfigurationSchema(cinfo, connectorType);
}
ConnectorInstanceConnIdImpl connectorImpl = new ConnectorInstanceConnIdImpl(cinfo, connectorType, namespace, connectorSchema, protector, prismContext);
connectorImpl.setDescription(desc);
return connectorImpl;
}
use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.
the class ConnectorFactoryConnIdImpl method convertToConnectorType.
/**
* Converts ICF ConnectorInfo into a midPoint XML connector representation.
*
* TODO: schema transformation
*
* @param hostType
* host that this connector runs on or null for local connectors
*/
private ConnectorType convertToConnectorType(ConnectorInfo cinfo, ConnectorHostType hostType) throws SchemaException {
ConnectorType connectorType = new ConnectorType();
ConnectorKey key = cinfo.getConnectorKey();
UcfUtil.addConnectorNames(connectorType, "ConnId", key.getBundleName(), key.getConnectorName(), key.getBundleVersion(), hostType);
String stringID = keyToNamespaceSuffix(key);
connectorType.setFramework(SchemaConstants.ICF_FRAMEWORK_URI);
connectorType.setConnectorType(key.getConnectorName());
connectorType.setNamespace(ICF_CONFIGURATION_NAMESPACE_PREFIX + stringID);
connectorType.setConnectorVersion(key.getBundleVersion());
connectorType.setConnectorBundle(key.getBundleName());
if (hostType != null) {
if (hostType.getOid() != null) {
// bind using connectorHostRef and OID
ObjectReferenceType ref = new ObjectReferenceType();
ref.setOid(hostType.getOid());
ref.setType(ObjectTypes.CONNECTOR_HOST.getTypeQName());
connectorType.setConnectorHostRef(ref);
} else {
// Embed the object
connectorType.setConnectorHost(hostType);
}
}
PrismSchema connectorSchema = generateConnectorConfigurationSchema(cinfo, connectorType);
LOGGER.trace("Generated connector schema for {}: {} definitions", connectorType, connectorSchema.getDefinitions().size());
UcfUtil.setConnectorSchema(connectorType, connectorSchema);
return connectorType;
}
use of com.evolveum.midpoint.prism.schema.PrismSchema in project midpoint by Evolveum.
the class ConnectorFactoryBuiltinImpl method generateConnectorConfigurationSchema.
private PrismSchema generateConnectorConfigurationSchema(ConnectorStruct struct) {
Class<? extends ConnectorInstance> connectorClass = struct.connectorClass;
PropertyDescriptor connectorConfigurationProp = UcfUtil.findAnnotatedProperty(connectorClass, ManagedConnectorConfiguration.class);
PrismSchema connectorSchema = new PrismSchemaImpl(struct.connectorObject.getNamespace(), prismContext);
// Create configuration type - the type used by the "configuration" element
PrismContainerDefinitionImpl<?> configurationContainerDef = ((PrismSchemaImpl) connectorSchema).createPropertyContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart(), SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_TYPE_LOCAL_NAME);
Class<?> configurationClass = connectorConfigurationProp.getPropertyType();
BeanWrapper configurationClassBean = new BeanWrapperImpl(configurationClass);
for (PropertyDescriptor prop : configurationClassBean.getPropertyDescriptors()) {
if (!UcfUtil.hasAnnotation(prop, ConfigurationProperty.class)) {
continue;
}
ItemDefinition<?> itemDef = createPropertyDefinition(configurationContainerDef, prop);
LOGGER.trace("Configuration item definition for {}: {}", prop.getName(), itemDef);
}
return connectorSchema;
}
Aggregations