Search in sources :

Example 31 with ConnectorType

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;
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 32 with ConnectorType

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());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) ComplexTypeDefinition(com.evolveum.midpoint.prism.ComplexTypeDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) CachingMetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

Example 33 with ConnectorType

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;
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) Referencable(com.evolveum.midpoint.prism.Referencable) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 34 with ConnectorType

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();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismContext(com.evolveum.midpoint.prism.PrismContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SystemException(com.evolveum.midpoint.util.exception.SystemException) S_ItemEntry(com.evolveum.midpoint.prism.delta.builder.S_ItemEntry)

Example 35 with ConnectorType

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;
        }
    };
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) IModel(org.apache.wicket.model.IModel) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) DropDownFormGroup(com.evolveum.midpoint.web.component.form.DropDownFormGroup) Label(org.apache.wicket.markup.html.basic.Label) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) List(java.util.List) ArrayList(java.util.ArrayList) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Aggregations

ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)39 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 Test (org.testng.annotations.Test)17 PrismObject (com.evolveum.midpoint.prism.PrismObject)13 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 Task (com.evolveum.midpoint.task.api.Task)12 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)12 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)8 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)8 SystemException (com.evolveum.midpoint.util.exception.SystemException)8 QName (javax.xml.namespace.QName)7 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)4 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)4 ConnectorConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType)4 ConnectorHostType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType)4 XmlSchemaType (com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType)4 Element (org.w3c.dom.Element)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3