use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method processOperationCapabilities.
private boolean processOperationCapabilities(OperationResult parentResult) {
capabilities = new ArrayList<>();
// Create capabilities from supported connector operations
InternalMonitor.recordConnectorOperation("getSupportedOperations");
Set<Class<? extends APIOperation>> supportedOperations = connIdConnectorFacade.getSupportedOperations();
LOGGER.trace("Connector supported operations: {}", supportedOperations);
boolean supportsSchema = false;
if (supportedOperations.contains(SchemaApiOp.class)) {
SchemaCapabilityType capSchema = new SchemaCapabilityType();
capabilities.add(CAPABILITY_OBJECT_FACTORY.createSchema(capSchema));
supportsSchema = true;
}
if (supportedOperations.contains(SyncApiOp.class)) {
LiveSyncCapabilityType capSync = new LiveSyncCapabilityType();
capabilities.add(CAPABILITY_OBJECT_FACTORY.createLiveSync(capSync));
}
if (supportedOperations.contains(TestApiOp.class)) {
TestConnectionCapabilityType capTest = new TestConnectionCapabilityType();
capabilities.add(CAPABILITY_OBJECT_FACTORY.createTestConnection(capTest));
}
if (supportedOperations.contains(CreateApiOp.class)) {
CreateCapabilityType capCreate = new CreateCapabilityType();
capabilities.add(CAPABILITY_OBJECT_FACTORY.createCreate(capCreate));
}
if (supportedOperations.contains(GetApiOp.class) || supportedOperations.contains(SearchApiOp.class)) {
ReadCapabilityType capRead = new ReadCapabilityType();
capabilities.add(CAPABILITY_OBJECT_FACTORY.createRead(capRead));
}
if (supportedOperations.contains(UpdateApiOp.class)) {
UpdateCapabilityType capUpdate = new UpdateCapabilityType();
capabilities.add(CAPABILITY_OBJECT_FACTORY.createUpdate(capUpdate));
}
if (supportedOperations.contains(DeleteApiOp.class)) {
DeleteCapabilityType capDelete = new DeleteCapabilityType();
capabilities.add(CAPABILITY_OBJECT_FACTORY.createDelete(capDelete));
}
if (supportedOperations.contains(ScriptOnResourceApiOp.class) || supportedOperations.contains(ScriptOnConnectorApiOp.class)) {
ScriptCapabilityType capScript = new ScriptCapabilityType();
if (supportedOperations.contains(ScriptOnResourceApiOp.class)) {
Host host = new Host();
host.setType(ProvisioningScriptHostType.RESOURCE);
capScript.getHost().add(host);
// language is unknown here
}
if (supportedOperations.contains(ScriptOnConnectorApiOp.class)) {
Host host = new Host();
host.setType(ProvisioningScriptHostType.CONNECTOR);
capScript.getHost().add(host);
// language is unknown here
}
capabilities.add(CAPABILITY_OBJECT_FACTORY.createScript(capScript));
}
return supportsSchema;
}
use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test024Capabilities.
@Test
public void test024Capabilities() throws Exception {
final String TEST_NAME = "test024Capabilities";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + "." + TEST_NAME);
// WHEN
PrismObject<ResourceType> resource = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, result);
ResourceType resourceType = resource.asObjectable();
// THEN
result.computeStatus();
display("getObject result", result);
TestUtil.assertSuccess(result);
// Check native capabilities
CapabilityCollectionType nativeCapabilities = resourceType.getCapabilities().getNative();
display("Native capabilities", PrismTestUtil.serializeAnyDataWrapped(nativeCapabilities));
display("Resource", resourceType);
List<Object> nativeCapabilitiesList = nativeCapabilities.getAny();
assertFalse("Empty capabilities returned", nativeCapabilitiesList.isEmpty());
CredentialsCapabilityType capCred = CapabilityUtil.getCapability(nativeCapabilitiesList, CredentialsCapabilityType.class);
assertNativeCredentialsCapability(capCred);
ActivationCapabilityType capAct = CapabilityUtil.getCapability(nativeCapabilitiesList, ActivationCapabilityType.class);
if (supportsActivation()) {
assertNotNull("native activation capability not present", capAct);
assertNotNull("native activation status capability not present", capAct.getStatus());
} else {
assertNull("native activation capability sneaked in", capAct);
}
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());
// TODO: better look inside
capabilitiesCachingMetadataType = resourceType.getCapabilities().getCachingMetadata();
assertNotNull("No capabilities caching metadata", capabilitiesCachingMetadataType);
assertNotNull("No capabilities caching metadata timestamp", capabilitiesCachingMetadataType.getRetrievalTimestamp());
assertNotNull("No capabilities caching metadata serial number", capabilitiesCachingMetadataType.getSerialNumber());
// 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) {
System.out.println("Capability: " + CapabilityUtil.getCapabilityDisplayName(capability) + " : " + capability);
}
assertSteadyResource();
}
use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType in project midpoint by Evolveum.
the class TestOpenDj method test005Capabilities.
@Test
public void test005Capabilities() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
// WHEN
ResourceType resource = provisioningService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, task, result).asObjectable();
// THEN
display("Resource from provisioninig", resource);
displayValue("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());
CredentialsCapabilityType capCred = CapabilityUtil.getCapability(nativeCapabilitiesList, CredentialsCapabilityType.class);
assertNotNull("credentials capability not found", capCred);
PasswordCapabilityType capPassword = capCred.getPassword();
assertNotNull("password capability not present", capPassword);
assertPasswordCapability(capPassword);
// 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());
Host scriptHost = scriptHosts.get(0);
assertEquals("Wrong script host type", ProvisioningScriptHostType.CONNECTOR, scriptHost.getType());
// assertEquals("Wrong script host language", ....., scriptHost.getLanguage());
ReadCapabilityType capRead = CapabilityUtil.getCapability(nativeCapabilitiesList, ReadCapabilityType.class);
assertNotNull("No read capability", capRead);
assertNull("Read capability is caching only", capRead.isCachingOnly());
assertTrue("Read capability is not 'return default'", capRead.isReturnDefaultAttributesOption());
CreateCapabilityType capCreate = CapabilityUtil.getCapability(nativeCapabilitiesList, CreateCapabilityType.class);
assertNotNull("No create capability", capCreate);
UpdateCapabilityType capUpdate = CapabilityUtil.getCapability(nativeCapabilitiesList, UpdateCapabilityType.class);
assertNotNull("No update capability", capUpdate);
DeleteCapabilityType capDelete = CapabilityUtil.getCapability(nativeCapabilitiesList, DeleteCapabilityType.class);
assertNotNull("No delete capability", capDelete);
List<Object> effectiveCapabilities = ResourceTypeUtil.getEffectiveCapabilities(resource);
for (Object capability : effectiveCapabilities) {
System.out.println("Capability: " + CapabilityUtil.getCapabilityDisplayName(capability) + " : " + capability);
}
capCred = ResourceTypeUtil.getEffectiveCapability(resource, CredentialsCapabilityType.class);
assertNotNull("credentials effective capability not found", capCred);
assertNotNull("password effective 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);
PagedSearchCapabilityType capPage = ResourceTypeUtil.getEffectiveCapability(resource, PagedSearchCapabilityType.class);
assertNotNull("paged search capability not present", capPage);
assertShadows(1);
}
use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType in project midpoint by Evolveum.
the class CapabilityStep method editCapabilityPerformed.
@SuppressWarnings("unchecked")
private void editCapabilityPerformed(final AjaxRequestTarget target, CapabilityDto<? extends CapabilityType> capability) {
dtoModel.getObject().setSelected(capability);
WebMarkupContainer config = getConfigContainer();
WebMarkupContainer newConfig;
CapabilityType capType = capability.getCapability();
if (capType instanceof ActivationCapabilityType) {
newConfig = new CapabilityActivationPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<ActivationCapabilityType>) capability), parentPage) {
@Override
public IModel<List<QName>> createAttributeChoiceModel(final IChoiceRenderer<QName> renderer) {
LoadableModel<List<QName>> attributeChoiceModel = new LoadableModel<List<QName>>(false) {
@Override
protected List<QName> load() {
List<QName> choices = new ArrayList<>();
PrismObject<ResourceType> resourcePrism = resourceModel.getObject();
try {
ResourceSchema schema = ResourceSchemaFactory.getCompleteSchema(resourcePrism);
if (schema != null) {
// TODO is this OK?
ResourceObjectTypeDefinition def = schema.findDefaultOrAnyObjectTypeDefinition(ShadowKindType.ACCOUNT);
if (def != null) {
for (ResourceAttributeDefinition<?> attribute : def.getAttributeDefinitions()) {
choices.add(attribute.getItemName());
}
}
}
} catch (CommonException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load resource schema attributes.", e);
getPageBase().error("Couldn't load resource schema attributes" + e);
}
choices.sort((o1, o2) -> {
String s1 = (String) renderer.getDisplayValue(o1);
String s2 = (String) renderer.getDisplayValue(o2);
return String.CASE_INSENSITIVE_ORDER.compare(s1, s2);
});
return choices;
}
};
parentPage.registerDependentModel(attributeChoiceModel);
return attributeChoiceModel;
}
};
} else if (capType instanceof ScriptCapabilityType) {
newConfig = new CapabilityScriptPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<ScriptCapabilityType>) capability), getTable(), parentPage);
} else if (capType instanceof CredentialsCapabilityType) {
newConfig = new CapabilityCredentialsPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<CredentialsCapabilityType>) capability), getTable(), parentPage);
} else {
newConfig = new CapabilityValuePanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<CapabilityType>) capability), getTable(), parentPage);
}
// TODO other specific capabilities (paged, count, ...)
newConfig.setOutputMarkupId(true);
config.replaceWith(newConfig);
target.add(newConfig);
target.add(getTable());
}
use of com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test025CapabilitiesRepo.
/**
* Check if the cached native capabilities were properly stored in the repo
*/
@Test
public void test025CapabilitiesRepo() throws Exception {
final String TEST_NAME = "test025CapabilitiesRepo";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + "." + TEST_NAME);
// WHEN
PrismObject<ResourceType> resource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
;
// THEN
result.computeStatus();
display("getObject result", result);
TestUtil.assertSuccess(result);
// Check native capabilities
ResourceType resourceType = resource.asObjectable();
CapabilitiesType capabilitiesType = resourceType.getCapabilities();
assertNotNull("No capabilities in repo, the capabilities were not cached", capabilitiesType);
CapabilityCollectionType nativeCapabilities = capabilitiesType.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());
CredentialsCapabilityType capCred = CapabilityUtil.getCapability(nativeCapabilitiesList, CredentialsCapabilityType.class);
assertNotNull("password native capability not present", capCred.getPassword());
ActivationCapabilityType capAct = CapabilityUtil.getCapability(nativeCapabilitiesList, ActivationCapabilityType.class);
if (supportsActivation()) {
assertNotNull("native activation capability not present", capAct);
assertNotNull("native activation status capability not present", capAct.getStatus());
} else {
assertNull("native activation capability sneaked in", capAct);
}
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());
// TODO: better look inside
CachingMetadataType repoCapabilitiesCachingMetadataType = capabilitiesType.getCachingMetadata();
assertNotNull("No repo capabilities caching metadata", repoCapabilitiesCachingMetadataType);
assertNotNull("No repo capabilities caching metadata timestamp", repoCapabilitiesCachingMetadataType.getRetrievalTimestamp());
assertNotNull("No repo capabilities caching metadata serial number", repoCapabilitiesCachingMetadataType.getSerialNumber());
assertEquals("Repo capabilities caching metadata timestamp does not match previously returned value", capabilitiesCachingMetadataType.getRetrievalTimestamp(), repoCapabilitiesCachingMetadataType.getRetrievalTimestamp());
assertEquals("Repo capabilities caching metadata serial does not match previously returned value", capabilitiesCachingMetadataType.getSerialNumber(), repoCapabilitiesCachingMetadataType.getSerialNumber());
assertSteadyResource();
}
Aggregations