use of com.evolveum.midpoint.schema.processor.ResourceSchema in project midpoint by Evolveum.
the class PageAccounts method loadResourceObjectClass.
private void loadResourceObjectClass() {
AccountDetailsSearchDto dto = searchModel.getObject();
PrismObject<ResourceType> resourcePrism;
OperationResult result = new OperationResult(OPERATION_GET_OBJECT_CLASS);
List<QName> accountObjectClassList = new ArrayList<>();
ResourceItemDto resourceDto = resourceModel.getObject();
String oid = resourceDto.getOid();
try {
resourcePrism = getModelService().getObject(ResourceType.class, oid, null, createSimpleTask(OPERATION_GET_INTENTS), result);
ResourceSchema schema = RefinedResourceSchemaImpl.getResourceSchema(resourcePrism, getPrismContext());
schema.getObjectClassDefinitions();
for (Definition def : schema.getDefinitions()) {
accountObjectClassList.add(def.getTypeName());
}
dto.setObjectClassList(accountObjectClassList);
} catch (Exception e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object class list from resource.", e);
result.recordFatalError("Couldn't load object class list from resource.: " + e.getMessage(), e);
showResult(result, false);
resourceModel.setObject(null);
new RestartResponseException(PageAccounts.this);
}
}
use of com.evolveum.midpoint.schema.processor.ResourceSchema in project midpoint by Evolveum.
the class TestParseResource method testSchemaRoundtrip.
/**
* Serialize and parse "schema" element on its own. There may be problems e.g. with preservation
* of namespace definitions.
*/
@Test
public void testSchemaRoundtrip() throws Exception {
displayTestTitle("testSchemaRoundtrip");
// GIVEN
PrismContext prismContext = getPrismContext();
PrismObject<ResourceType> resource = prismContext.parseObject(getFile(RESOURCE_FILE_BASENAME));
assertResource(resource, true, false, false);
PrismContainer<Containerable> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
System.out.println("Parsed schema:");
System.out.println(schemaContainer.debugDump());
// SERIALIZE
String serializesSchema = prismContext.serializerFor(language).serialize(schemaContainer.getValue(), new QName("fakeNs", "fake"));
System.out.println("serialized schema:");
System.out.println(serializesSchema);
// RE-PARSE
PrismContainer reparsedSchemaContainer = (PrismContainer) prismContext.parserFor(serializesSchema).language(language).definition(schemaContainer.getDefinition()).parseItem();
System.out.println("Re-parsed schema container:");
System.out.println(reparsedSchemaContainer.debugDump());
// String reserializesSchema = prismContext.serializeContainerValueToString(reparsedSchemaContainer.getValue(), new QName("fakeNs", "fake"), PrismContext.LANG_XML);
//
// System.out.println("re-serialized schema:");
// System.out.println(reserializesSchema);
// Document reparsedDocument = DOMUtil.parseDocument(serializesSchema);
// Element reparsedSchemaElement = DOMUtil.getFirstChildElement(DOMUtil.getFirstChildElement(reparsedDocument));
// Element reparsedXsdSchemaElement = DOMUtil.getChildElement(DOMUtil.getFirstChildElement(reparsedSchemaElement), DOMUtil.XSD_SCHEMA_ELEMENT);
XmlSchemaType defType = (XmlSchemaType) reparsedSchemaContainer.getValue().asContainerable();
Element reparsedXsdSchemaElement = defType.getDefinition().getSchema();
ResourceSchema reparsedSchema = ResourceSchemaImpl.parse(reparsedXsdSchemaElement, "reparsed schema", prismContext);
}
use of com.evolveum.midpoint.schema.processor.ResourceSchema in project midpoint by Evolveum.
the class DataModelVisualizerImpl method createDataItems.
private void createDataItems(DataModel model, List<PrismObject<ResourceType>> resources) throws SchemaException {
LOGGER.debug("createDataItems starting");
for (PrismObject<ResourceType> resource : resources) {
final ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
if (resourceSchema == null) {
LOGGER.debug("Resource schema is null, skipping the resource.");
continue;
}
RefinedResourceSchema refinedResourceSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
if (refinedResourceSchema == null) {
// actually shouldn't be null if resource schema exists
LOGGER.debug("Refined resource schema is null, skipping the resource.");
continue;
}
model.registerResource(resource);
List<? extends RefinedObjectClassDefinition> refinedDefinitions = refinedResourceSchema.getRefinedDefinitions();
for (RefinedObjectClassDefinition refinedDefinition : refinedDefinitions) {
LOGGER.debug("Processing refined definition {} in {}", refinedDefinition, resource);
Collection<? extends RefinedAttributeDefinition<?>> attributeDefinitions = refinedDefinition.getAttributeDefinitions();
//Collection<? extends ResourceAttributeDefinition> rawAttributeDefinitions = refinedDefinition.getObjectClassDefinition().getAttributeDefinitions();
final ShadowKindType kind = def(refinedDefinition.getKind());
final String intent = def(refinedDefinition.getIntent());
for (RefinedAttributeDefinition<?> attributeDefinition : attributeDefinitions) {
if (attributeDefinition.isIgnored()) {
continue;
}
LOGGER.debug("Registering refined attribute definition for {}", attributeDefinition.getName());
ResourceDataItem attrItem = new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, attributeDefinition.getName());
attrItem.setRefinedAttributeDefinition(attributeDefinition);
// TODO check the name
model.registerDataItem(attrItem);
}
// TODO check attributes not mentioned in schema handling
Collection<RefinedAssociationDefinition> associationDefinitions = refinedDefinition.getAssociationDefinitions();
for (RefinedAssociationDefinition associationDefinition : associationDefinitions) {
if (associationDefinition.isIgnored()) {
continue;
}
LOGGER.debug("Registering refined association definition for {}", associationDefinition.getName());
ResourceDataItem assocItem = new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, associationDefinition.getName());
model.registerDataItem(assocItem);
}
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_FROM)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_TO)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ACTIVATION_EXISTENCE)));
model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_CREDENTIALS, CredentialsType.F_PASSWORD)));
}
}
// createRepoDataItems(UserType.class);
// createRepoDataItems(RoleType.class);
// createRepoDataItems(OrgType.class);
// createRepoDataItems(ServiceType.class);
LOGGER.debug("createDataItems finished");
}
use of com.evolveum.midpoint.schema.processor.ResourceSchema in project midpoint by Evolveum.
the class AbstractCsvTest method test005ParsedSchema.
@Test
public void test005ParsedSchema() throws Exception {
final String TEST_NAME = "test005ParsedSchema";
TestUtil.displayTestTile(TEST_NAME);
// THEN
// The returned type should have the schema pre-parsed
assertNotNull(RefinedResourceSchemaImpl.hasParsedSchema(resourceType));
// Also test if the utility method returns the same thing
ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resourceType, prismContext);
display("Parsed resource schema", resourceSchema);
assertNotNull("No resource schema", resourceSchema);
ObjectClassComplexTypeDefinition accountDef = resourceSchema.findObjectClassDefinition(RESOURCE_CSV_ACCOUNT_OBJECTCLASS);
assertNotNull("Account definition is missing", accountDef);
assertNotNull("Null identifiers in account", accountDef.getPrimaryIdentifiers());
assertFalse("Empty identifiers in account", accountDef.getPrimaryIdentifiers().isEmpty());
assertNotNull("No naming attribute in account", accountDef.getNamingAttribute());
assertFalse("No nativeObjectClass in account", StringUtils.isEmpty(accountDef.getNativeObjectClass()));
assertAccountDefinition(accountDef);
ResourceAttributeDefinition<String> icfsNameDef = accountDef.findAttributeDefinition(SchemaConstants.ICFS_NAME);
assertNull("ICFS NAME definition sneaked in", icfsNameDef);
ResourceAttributeDefinition<String> icfsUidDef = accountDef.findAttributeDefinition(SchemaConstants.ICFS_UID);
assertNull("ICFS UID definition sneaked in", icfsUidDef);
// Check whether it is reusing the existing schema and not parsing it all over again
// Not equals() but == ... we want to really know if exactly the same
// object instance is returned
assertTrue("Broken caching", resourceSchema == RefinedResourceSchemaImpl.getResourceSchema(resourceType, prismContext));
}
use of com.evolveum.midpoint.schema.processor.ResourceSchema in project midpoint by Evolveum.
the class AbstractCsvTest 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, getResourceOid(), 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(getResourceOid(), task);
// THEN
display("Test result", testResult);
TestUtil.assertSuccess("Test resource failed (result)", testResult);
PrismObject<ResourceType> resourceRepoAfter = repositoryService.getObject(ResourceType.class, getResourceOid(), 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);
// schema will be checked in next test
}
Aggregations