use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType in project midpoint by Evolveum.
the class ConnectorManager method getConnectorSchema.
public PrismSchema getConnectorSchema(ConnectorType connectorType) throws SchemaException {
PrismObject<ConnectorType> connector = connectorType.asPrismObject();
PrismSchema connectorSchema;
Object userDataEntry = connector.getUserData(USER_DATA_KEY_PARSED_CONNECTOR_SCHEMA);
if (userDataEntry == null) {
InternalMonitor.recordConnectorSchemaParse();
connectorSchema = ConnectorTypeUtil.parseConnectorSchema(connectorType, prismContext);
if (connectorSchema == null) {
throw new SchemaException("No connector schema in " + connectorType);
}
connector.setUserData(USER_DATA_KEY_PARSED_CONNECTOR_SCHEMA, connectorSchema);
} else {
if (userDataEntry instanceof PrismSchema) {
connectorSchema = (PrismSchema) userDataEntry;
} else {
throw new IllegalStateException("Expected PrismSchema under user data key " + USER_DATA_KEY_PARSED_CONNECTOR_SCHEMA + "in " + connectorType + ", but got " + userDataEntry.getClass());
}
}
return connectorSchema;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType in project midpoint by Evolveum.
the class TestDummyHacks method test003Connection.
/**
* This should be the very first test that works with the resource.
*
* The original repository object does not have resource schema. The schema
* should be generated from the resource on the first use. This is the test
* that executes testResource and checks whether the schema was generated.
*/
@Test
public void test003Connection() throws Exception {
final String TEST_NAME = "test003Connection";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
// Check that there is no schema before test (pre-condition)
ResourceType resourceBefore = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result).asObjectable();
assertNotNull("No connector ref", resourceBefore.getConnectorRef());
assertNotNull("No connector ref OID", resourceBefore.getConnectorRef().getOid());
ConnectorType connector = repositoryService.getObject(ConnectorType.class, resourceBefore.getConnectorRef().getOid(), null, result).asObjectable();
assertNotNull(connector);
XmlSchemaType xmlSchemaTypeBefore = resourceBefore.getSchema();
Element resourceXsdSchemaElementBefore = ResourceTypeUtil.getResourceXsdSchema(resourceBefore);
AssertJUnit.assertNull("Found schema before test connection. Bad test setup?", resourceXsdSchemaElementBefore);
// WHEN
OperationResult testResult = provisioningService.testResource(RESOURCE_DUMMY_OID, task);
// THEN
display("Test result", testResult);
TestUtil.assertSuccess("Test resource failed (result)", testResult);
PrismObject<ResourceType> resourceRepoAfter = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
ResourceType resourceTypeRepoAfter = resourceRepoAfter.asObjectable();
display("Resource after test", resourceTypeRepoAfter);
XmlSchemaType xmlSchemaTypeAfter = resourceTypeRepoAfter.getSchema();
assertNotNull("No schema after test connection", xmlSchemaTypeAfter);
Element resourceXsdSchemaElementAfter = ResourceTypeUtil.getResourceXsdSchema(resourceTypeRepoAfter);
assertNotNull("No schema after test connection", resourceXsdSchemaElementAfter);
String resourceXml = prismContext.serializeObjectToString(resourceRepoAfter, PrismContext.LANG_XML);
display("Resource XML", resourceXml);
CachingMetadataType cachingMetadata = xmlSchemaTypeAfter.getCachingMetadata();
assertNotNull("No caching metadata", cachingMetadata);
assertNotNull("No retrievalTimestamp", cachingMetadata.getRetrievalTimestamp());
assertNotNull("No serialNumber", cachingMetadata.getSerialNumber());
Element xsdElement = ObjectTypeUtil.findXsdElement(xmlSchemaTypeAfter);
ResourceSchema parsedSchema = ResourceSchemaImpl.parse(xsdElement, resourceBefore.toString(), prismContext);
assertNotNull("No schema after parsing", parsedSchema);
display("Parsed schema", parsedSchema);
ComplexTypeDefinition accountDef = parsedSchema.findComplexTypeDefinition(new QName(parsedSchema.getNamespace(), SchemaConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME));
assertNotNull("No account definition in schema after parsing", accountDef);
PrismAsserts.assertPropertyDefinition(accountDef, SchemaConstants.ICFS_NAME, DOMUtil.XSD_STRING, 1, 1);
PrismAsserts.assertPropertyDefinition(accountDef, new QName(SchemaConstants.NS_ICF_SCHEMA, "description"), DOMUtil.XSD_STRING, 0, 1);
// The useless configuration variables should be reflected to the resource now
assertEquals("Wrong useless string", "Shiver me timbers!", dummyResource.getUselessString());
assertEquals("Wrong guarded useless string", "Dead men tell no tales", dummyResource.getUselessGuardedString());
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType in project midpoint by Evolveum.
the class ResourceDetailsModel method createConfigContainerWrappers.
private PrismContainerWrapper<ConnectorConfigurationType> createConfigContainerWrappers(OperationResult result) throws SchemaException {
Task task = getModelServiceLocator().createSimpleTask(OPERATION_CREATE_CONFIGURATION_WRAPPERS);
PrismObjectWrapper<ResourceType> resourceWrapper = getObjectWrapper();
PrismContainerWrapper<ConnectorConfigurationType> configuration = resourceWrapper.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
PrismContainer<ConnectorConfigurationType> connectorConfigurationType = null;
ItemStatus configurationStatus = ItemStatus.NOT_CHANGED;
if (configuration == null || configuration.isEmpty()) {
PrismReferenceWrapper<Referencable> connectorRef = resourceWrapper.findReference(ResourceType.F_CONNECTOR_REF);
if (connectorRef == null || connectorRef.getValue() == null || connectorRef.getValue().getRealValue() == null) {
return null;
}
PrismObject<ConnectorType> connector = WebModelServiceUtils.resolveReferenceNoFetch(connectorRef.getValue().getRealValue(), getPageBase(), task, result);
if (connector == null) {
return null;
}
ConnectorType connectorType = connector.asObjectable();
PrismSchema schema;
try {
schema = ConnectorTypeUtil.parseConnectorSchema(connectorType, getPrismContext());
} catch (SchemaException e) {
throw new SystemException("Couldn't parse connector schema: " + e.getMessage(), e);
}
PrismContainerDefinition<ConnectorConfigurationType> definition = ConnectorTypeUtil.findConfigurationContainerDefinition(connectorType, schema);
// Fixing (errorneously) set maxOccurs = unbounded. See MID-2317 and related issues.
PrismContainerDefinition<ConnectorConfigurationType> definitionFixed = definition.clone();
definitionFixed.toMutable().setMaxOccurs(1);
connectorConfigurationType = definitionFixed.instantiate();
configurationStatus = ItemStatus.ADDED;
WrapperContext ctx = new WrapperContext(task, result);
ctx.setShowEmpty(ItemStatus.ADDED == configurationStatus);
configuration = getModelServiceLocator().createItemWrapper(connectorConfigurationType, configurationStatus, ctx);
}
return configuration;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType in project midpoint by Evolveum.
the class NameStep method applyState.
@Override
public void applyState() {
parentPage.refreshIssues(null);
if (parentPage.isReadOnly() || !isComplete()) {
return;
}
PrismContext prismContext = parentPage.getPrismContext();
Task task = parentPage.createSimpleTask(OPERATION_SAVE_RESOURCE);
OperationResult result = task.getResult();
boolean saved = false;
try {
PrismObject<ResourceType> resource = resourceModelRaw.getObject();
PrismObject<ConnectorType> connector = getSelectedConnector();
if (connector == null) {
// should be treated by form validation
throw new IllegalStateException("No connector selected");
}
ObjectDelta<?> delta;
final String oid = resource.getOid();
boolean isNew = oid == null;
if (isNew) {
resource = prismContext.createObject(ResourceType.class);
ResourceType resourceType = resource.asObjectable();
resourceType.setName(PolyStringType.fromOrig(resourceNameModel.getObject()));
resourceType.setDescription(resourceDescriptionModel.getObject());
resourceType.setConnectorRef(ObjectTypeUtil.createObjectRef(connector, prismContext));
delta = DeltaFactory.Object.createAddDelta(resource);
} else {
PrismObject<ResourceType> oldResourceObject = WebModelServiceUtils.loadObject(ResourceType.class, oid, GetOperationOptions.createRawCollection(), parentPage, parentPage.createSimpleTask("loadResource"), result);
if (oldResourceObject == null) {
throw new SystemException("Resource being edited (" + oid + ") couldn't be retrieved");
}
ResourceType oldResource = oldResourceObject.asObjectable();
S_ItemEntry i = prismContext.deltaFor(ResourceType.class);
if (!StringUtils.equals(PolyString.getOrig(oldResource.getName()), resourceNameModel.getObject())) {
i = i.item(ResourceType.F_NAME).replace(PolyString.fromOrig(resourceNameModel.getObject()));
}
if (!StringUtils.equals(oldResource.getDescription(), resourceDescriptionModel.getObject())) {
i = i.item(ResourceType.F_DESCRIPTION).replace(resourceDescriptionModel.getObject());
}
String oldConnectorOid = oldResource.getConnectorRef() != null ? oldResource.getConnectorRef().getOid() : null;
String newConnectorOid = connector.getOid();
if (!StringUtils.equals(oldConnectorOid, newConnectorOid)) {
i = i.item(ResourceType.F_CONNECTOR_REF).replace(ObjectTypeUtil.createObjectRef(connector, prismContext).asReferenceValue());
}
if (!isConfigurationSchemaCompatible(connector)) {
i = i.item(ResourceType.F_CONNECTOR_CONFIGURATION).replace();
}
delta = i.asObjectDelta(oid);
}
if (!delta.isEmpty()) {
parentPage.logDelta(delta);
WebModelServiceUtils.save(delta, ModelExecuteOptions.create(prismContext).raw(), result, null, parentPage);
parentPage.resetModels();
saved = true;
}
if (isNew) {
parentPage.setEditedResourceOid(delta.getOid());
}
} catch (RuntimeException | SchemaException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save resource", ex);
result.recordFatalError(createStringResource("NameStep.message.saveResource.fatalError", ex.getMessage()).getString(), ex);
} finally {
result.computeStatusIfUnknown();
setResult(result);
}
if (parentPage.showSaveResultInPage(saved, result)) {
parentPage.showResult(result);
}
parentPage.getConfigurationStep().resetConfiguration();
parentPage.getConfigurationStep().updateConfigurationTabs();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType in project midpoint by Evolveum.
the class NameStep method createConnectorDropDown.
private DropDownFormGroup<PrismObject<ConnectorType>> createConnectorDropDown() {
return new DropDownFormGroup<PrismObject<ConnectorType>>(ID_CONNECTOR, selectedConnectorModel, relevantConnectorsModel, new IChoiceRenderer<PrismObject<ConnectorType>>() {
@Override
public PrismObject<ConnectorType> getObject(String id, IModel<? extends List<? extends PrismObject<ConnectorType>>> choices) {
return StringUtils.isNotBlank(id) ? choices.getObject().get(Integer.parseInt(id)) : null;
}
@Override
public Object getDisplayValue(PrismObject<ConnectorType> object) {
return WebComponentUtil.getName(object);
}
@Override
public String getIdValue(PrismObject<ConnectorType> object, int index) {
if (index < 0) {
// noinspection unchecked
List<PrismObject<ConnectorType>> connectors = (List<PrismObject<ConnectorType>>) getConnectorDropDown().getInput().getChoices();
for (PrismObject<ConnectorType> connector : connectors) {
if (connector.getOid().equals(selectedConnectorModel.getObject().getOid())) {
return Integer.toString(connectors.indexOf(connector));
}
}
}
return Integer.toString(index);
}
}, createStringResource("NameStep.connectorType"), "col-md-3", "col-md-6", true) {
@Override
protected DropDownChoice<PrismObject<ConnectorType>> createDropDown(String id, IModel<List<PrismObject<ConnectorType>>> choices, IChoiceRenderer<PrismObject<ConnectorType>> renderer, boolean required) {
DropDownChoice<PrismObject<ConnectorType>> choice = super.createDropDown(id, choices, renderer, required);
choice.add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(getConnectorDropDown().getAdditionalInfoComponent());
}
});
choice.setOutputMarkupId(true);
return choice;
}
@Override
protected Component createAdditionalInfoComponent(String id) {
Label l = new Label(id, schemaChangeWarningModel);
l.add(new AttributeAppender("class", "text-danger"));
l.setOutputMarkupId(true);
return l;
}
};
}
Aggregations