Search in sources :

Example 6 with CapabilityCollectionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType in project midpoint by Evolveum.

the class TestDummySchemaless method test107Capabilities.

@Test
public void test107Capabilities() throws Exception {
    final String TEST_NAME = "test107Capabilities";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    ResourceType resourceType = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_STATIC_SCHEMA_OID, null, null, result).asObjectable();
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertSuccess(result);
    // Check native capabilities
    CapabilityCollectionType nativeCapabilities = resourceType.getCapabilities().getNative();
    System.out.println("Native capabilities: " + PrismTestUtil.serializeAnyDataWrapped(nativeCapabilities));
    System.out.println("resource: " + resourceType.asPrismObject().debugDump());
    List<Object> nativeCapabilitiesList = nativeCapabilities.getAny();
    assertFalse("Empty capabilities returned", nativeCapabilitiesList.isEmpty());
    TestConnectionCapabilityType capTest = CapabilityUtil.getCapability(nativeCapabilitiesList, TestConnectionCapabilityType.class);
    assertNotNull("native test capability not present", capTest);
    ScriptCapabilityType capScript = CapabilityUtil.getCapability(nativeCapabilitiesList, ScriptCapabilityType.class);
    assertNotNull("native script capability not present", capScript);
    assertNotNull("No host in native script capability", capScript.getHost());
    assertFalse("No host in native script capability", capScript.getHost().isEmpty());
    CredentialsCapabilityType capCred = CapabilityUtil.getCapability(nativeCapabilitiesList, CredentialsCapabilityType.class);
    assertNull("Unexpected native credentials capability", capCred);
    ActivationCapabilityType capAct = CapabilityUtil.getCapability(nativeCapabilitiesList, ActivationCapabilityType.class);
    assertNull("Unexpected native activation capability", capAct);
    // Check effective capabilites
    capCred = ResourceTypeUtil.getEffectiveCapability(resourceType, CredentialsCapabilityType.class);
    assertNotNull("password capability not found", capCred.getPassword());
    // Although connector does not support activation, the resource
    // specifies a way how to simulate it.
    // Therefore the following should succeed
    capAct = ResourceTypeUtil.getEffectiveCapability(resourceType, ActivationCapabilityType.class);
    assertNotNull("activation capability not found", capCred.getPassword());
    List<Object> effectiveCapabilities = ResourceTypeUtil.getEffectiveCapabilities(resourceType);
    for (Object capability : effectiveCapabilities) {
        display("Capability " + CapabilityUtil.getCapabilityDisplayName(capability), capability);
    }
}
Also used : ScriptCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType) CapabilityCollectionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType) ActivationCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType) CredentialsCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CredentialsCapabilityType) TestConnectionCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.TestConnectionCapabilityType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PrismObject(com.evolveum.midpoint.prism.PrismObject) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

Example 7 with CapabilityCollectionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType in project midpoint by Evolveum.

the class CapabilityStep method savePerformed.

private void savePerformed() {
    Task task = getPageBase().createSimpleTask(OPERATION_SAVE_CAPABILITIES);
    OperationResult result = task.getResult();
    ModelService modelService = getPageBase().getModelService();
    boolean saved = false;
    try {
        PrismObject<ResourceType> oldResource;
        final PrismObject<ResourceType> resourceObject = resourceModel.getObject();
        ResourceType resource = resourceObject.asObjectable();
        List<Object> unsupportedCapabilities = new ArrayList<>();
        if (resource.getCapabilities().getConfigured() != null) {
            for (Object o : resource.getCapabilities().getConfigured().getAny()) {
                CapabilityType capabilityType = CapabilityUtil.asCapabilityType(o);
                if (!Capability.supports(capabilityType.getClass())) {
                    unsupportedCapabilities.add(o);
                }
            }
        }
        // AnyArrayList that is used to implement getAny() is really strange (e.g. doesn't support iterator.remove();
        // and its support for clear() is questionable) -- so let's recreate it altogether
        resource.getCapabilities().setConfigured(new CapabilityCollectionType());
        resource.getCapabilities().getConfigured().getAny().addAll(unsupportedCapabilities);
        ObjectFactory capabilityFactory = new ObjectFactory();
        for (CapabilityDto dto : dtoModel.getObject().getCapabilities()) {
            JAXBElement<? extends CapabilityType> jaxbCapability = createJAXBCapability(dto.getCapability(), capabilityFactory);
            if (jaxbCapability != null) {
                resource.getCapabilities().getConfigured().getAny().add(jaxbCapability);
            }
        }
        oldResource = WebModelServiceUtils.loadObject(ResourceType.class, resource.getOid(), getPageBase(), task, result);
        if (oldResource != null) {
            ObjectDelta<ResourceType> delta = parentPage.computeDiff(oldResource, resourceObject);
            if (!delta.isEmpty()) {
                parentPage.logDelta(delta);
                @SuppressWarnings("unchecked") Collection<ObjectDelta<? extends ObjectType>> deltas = WebComponentUtil.createDeltaCollection(delta);
                modelService.executeChanges(deltas, null, getPageBase().createSimpleTask(OPERATION_SAVE_CAPABILITIES), result);
                parentPage.resetModels();
                saved = true;
            }
        }
    } catch (CommonException | RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save capabilities", e);
        result.recordFatalError("Couldn't save capabilities", e);
    } finally {
        result.computeStatusIfUnknown();
        setResult(result);
    }
    if (parentPage.showSaveResultInPage(saved, result)) {
        getPageBase().showResult(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) CapabilityCollectionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ModelService(com.evolveum.midpoint.model.api.ModelService) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) PrismObject(com.evolveum.midpoint.prism.PrismObject) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 8 with CapabilityCollectionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType in project midpoint by Evolveum.

the class TestSanityLegacy method test004Capabilities.

@Test
public void test004Capabilities() throws ObjectNotFoundException, CommunicationException, SchemaException, FaultMessage {
    TestUtil.displayTestTile("test004Capabilities");
    // GIVEN
    checkRepoOpenDjResource();
    assertNoRepoCache();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    // WHEN
    modelWeb.getObject(ObjectTypes.RESOURCE.getTypeQName(), RESOURCE_OPENDJ_OID, options, objectHolder, resultHolder);
    ResourceType resource = (ResourceType) objectHolder.value;
    // THEN
    display("Resource", resource);
    assertNoRepoCache();
    CapabilityCollectionType nativeCapabilities = resource.getCapabilities().getNative();
    List<Object> capabilities = nativeCapabilities.getAny();
    assertFalse("Empty capabilities returned", capabilities.isEmpty());
    for (Object capability : nativeCapabilities.getAny()) {
        System.out.println("Native Capability: " + CapabilityUtil.getCapabilityDisplayName(capability) + " : " + capability);
    }
    if (resource.getCapabilities() != null) {
        for (Object capability : resource.getCapabilities().getConfigured().getAny()) {
            System.out.println("Configured Capability: " + CapabilityUtil.getCapabilityDisplayName(capability) + " : " + capability);
        }
    }
    List<Object> effectiveCapabilities = ResourceTypeUtil.getEffectiveCapabilities(resource);
    for (Object capability : effectiveCapabilities) {
        System.out.println("Efective Capability: " + CapabilityUtil.getCapabilityDisplayName(capability) + " : " + capability);
    }
    CredentialsCapabilityType capCred = CapabilityUtil.getCapability(capabilities, CredentialsCapabilityType.class);
    assertNotNull("password capability not present", capCred.getPassword());
    // Connector cannot do activation, this should be null
    ActivationCapabilityType capAct = CapabilityUtil.getCapability(capabilities, ActivationCapabilityType.class);
    assertNull("Found activation capability while not expecting it", capAct);
    capCred = ResourceTypeUtil.getEffectiveCapability(resource, CredentialsCapabilityType.class);
    assertNotNull("password capability not found", capCred.getPassword());
    // Although connector does not support activation, the resource specifies a way how to simulate it.
    // Therefore the following should succeed
    capAct = ResourceTypeUtil.getEffectiveCapability(resource, ActivationCapabilityType.class);
    assertNotNull("activation capability not found", capAct);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GenericObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType) CapabilityCollectionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ActivationCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType) Holder(javax.xml.ws.Holder) CredentialsCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CredentialsCapabilityType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 9 with CapabilityCollectionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType in project midpoint by Evolveum.

the class AbstractManualResourceTest method test006Capabilities.

@Test
public void test006Capabilities() throws Exception {
    final String TEST_NAME = "test006Capabilities";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(AbstractManualResourceTest.class.getName() + "." + TEST_NAME);
    // WHEN
    ResourceType resource = modelService.getObject(ResourceType.class, getResourceOid(), null, null, result).asObjectable();
    // THEN
    display("Resource from provisioninig", resource);
    display("Resource from provisioninig (XML)", PrismTestUtil.serializeObjectToString(resource.asPrismObject(), PrismContext.LANG_XML));
    CapabilityCollectionType nativeCapabilities = resource.getCapabilities().getNative();
    List<Object> nativeCapabilitiesList = nativeCapabilities.getAny();
    assertFalse("Empty capabilities returned", nativeCapabilitiesList.isEmpty());
    CreateCapabilityType capCreate = CapabilityUtil.getCapability(nativeCapabilitiesList, CreateCapabilityType.class);
    assertNotNull("Missing create capability", capCreate);
    assertManual(capCreate);
    ActivationCapabilityType capAct = CapabilityUtil.getCapability(nativeCapabilitiesList, ActivationCapabilityType.class);
    assertNotNull("Missing activation capability", capAct);
    ReadCapabilityType capRead = CapabilityUtil.getCapability(nativeCapabilitiesList, ReadCapabilityType.class);
    assertNotNull("Missing read capability", capRead);
    assertEquals("Wrong caching-only setting in read capability", Boolean.TRUE, capRead.isCachingOnly());
    List<Object> effectiveCapabilities = ResourceTypeUtil.getEffectiveCapabilities(resource);
    for (Object capability : effectiveCapabilities) {
        System.out.println("Capability: " + CapabilityUtil.getCapabilityDisplayName(capability) + " : " + capability);
    }
}
Also used : ReadCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ReadCapabilityType) CapabilityCollectionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType) ActivationCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PrismObject(com.evolveum.midpoint.prism.PrismObject) CreateCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CreateCapabilityType) Test(org.testng.annotations.Test) AbstractConfiguredModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)

Example 10 with CapabilityCollectionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType in project midpoint by Evolveum.

the class AbstractCsvTest method test006Capabilities.

@Test
public void test006Capabilities() throws Exception {
    final String TEST_NAME = "test006Capabilities";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestOpenDj.class.getName() + "." + TEST_NAME);
    // WHEN
    ResourceType resource = provisioningService.getObject(ResourceType.class, getResourceOid(), null, null, result).asObjectable();
    // THEN
    display("Resource from provisioninig", resource);
    display("Resource from provisioninig (XML)", PrismTestUtil.serializeObjectToString(resource.asPrismObject(), PrismContext.LANG_XML));
    CapabilityCollectionType nativeCapabilities = resource.getCapabilities().getNative();
    List<Object> nativeCapabilitiesList = nativeCapabilities.getAny();
    assertFalse("Empty capabilities returned", nativeCapabilitiesList.isEmpty());
    // Connector cannot do activation, this should be null
    ActivationCapabilityType capAct = CapabilityUtil.getCapability(nativeCapabilitiesList, ActivationCapabilityType.class);
    assertNull("Found activation capability while not expecting it", capAct);
    ScriptCapabilityType capScript = CapabilityUtil.getCapability(nativeCapabilitiesList, ScriptCapabilityType.class);
    assertNotNull("No script capability", capScript);
    List<Host> scriptHosts = capScript.getHost();
    assertEquals("Wrong number of script hosts", 1, scriptHosts.size());
    assertScriptHost(capScript, ProvisioningScriptHostType.CONNECTOR);
    List<Object> effectiveCapabilities = ResourceTypeUtil.getEffectiveCapabilities(resource);
    for (Object capability : effectiveCapabilities) {
        System.out.println("Capability: " + CapabilityUtil.getCapabilityDisplayName(capability) + " : " + capability);
    }
}
Also used : ScriptCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType) CapabilityCollectionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType) ActivationCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType) TestOpenDj(com.evolveum.midpoint.provisioning.impl.opendj.TestOpenDj) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PrismObject(com.evolveum.midpoint.prism.PrismObject) Host(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType.Host) Test(org.testng.annotations.Test) AbstractProvisioningIntegrationTest(com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest)

Aggregations

CapabilityCollectionType (com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType)13 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)11 ActivationCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType)10 Test (org.testng.annotations.Test)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)8 CredentialsCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CredentialsCapabilityType)6 ScriptCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType)5 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)3 CapabilitiesType (com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilitiesType)3 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)3 CreateCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CreateCapabilityType)3 ReadCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ReadCapabilityType)3 TestConnectionCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.TestConnectionCapabilityType)3 AbstractProvisioningIntegrationTest (com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest)2 TestOpenDj (com.evolveum.midpoint.provisioning.impl.opendj.TestOpenDj)2 Task (com.evolveum.midpoint.task.api.Task)2 CachingMetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType)2 GenericObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType)2 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)2