use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class ObjectRetriever method retrieveAllAttributeValues.
private void retrieveAllAttributeValues(PrismObject<ShadowType> shadowObject, Collection<? extends ROExtValue<?>> dbCollection, boolean raw) throws SchemaException {
PrismContainer<Containerable> attributeContainer = shadowObject.findOrCreateContainer(ShadowType.F_ATTRIBUTES);
// Hack: let's ignore values of attributes that already exist in this container
Set<QName> existingCompleteAttributeNames = attributeContainer.getValue().getItems().stream().filter(item -> !item.isIncomplete()).map(Item::getElementName).collect(Collectors.toSet());
LOGGER.trace("existingAttributeNames = {}", existingCompleteAttributeNames);
for (ROExtValue<?> rValue : dbCollection) {
if (rValue.getOwnerType() == RObjectExtensionType.ATTRIBUTES) {
LOGGER.trace("- processing {}", rValue);
RExtItem extItem = extItemDictionary.getItemById(rValue.getItemId());
if (extItem == null) {
LOGGER.warn("Couldn't get definition for extItem ID {} for value of {} in {} -- it will not be fetched", rValue.getItemId(), rValue, shadowObject);
} else {
ItemName extItemName = RUtil.stringToQName(extItem.getName());
if (!QNameUtil.matchAny(extItemName, existingCompleteAttributeNames)) {
PrismProperty attribute = attributeContainer.findProperty(extItemName);
if (attribute == null) {
if (raw) {
attribute = ((PrismPropertyDefinition) createDynamicDefinition(extItem, extItemName)).instantiate();
} else {
attribute = prismContext.itemFactory().createProperty(extItemName);
}
attributeContainer.add(attribute);
}
// noinspection unchecked
// no polystring nor reference is expected here
attribute.addRealValue(rValue.getValue());
attribute.setIncomplete(false);
}
}
}
}
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class TestUcfOpenDj method test010ConnectorSchemaSanity.
@Test
public void test010ConnectorSchemaSanity() {
IntegrationTestTools.assertConnectorSchemaSanity(connectorSchema, "LDAP connector", true);
PrismContainerDefinition configurationDefinition = connectorSchema.findItemDefinitionByElementName(new QName(ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart()), PrismContainerDefinition.class);
PrismContainerDefinition configurationPropertiesDefinition = configurationDefinition.findContainerDefinition(SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_ELEMENT_QNAME);
PrismPropertyDefinition<String> propHost = configurationPropertiesDefinition.findPropertyDefinition(new ItemName(UcfTestUtil.CONNECTOR_LDAP_NS, "host"));
assertNotNull("No definition for configuration property 'host' in connector schema", propHost);
PrismAsserts.assertDefinition(propHost, new QName(UcfTestUtil.CONNECTOR_LDAP_NS, "host"), DOMUtil.XSD_STRING, 1, 1);
assertEquals("Wrong property 'host' display name", "Host", propHost.getDisplayName());
assertEquals("Wrong property 'host' help", "The name or IP address of the LDAP server host.", propHost.getHelp());
// MID-2642
assertEquals("Wrong property 'host' display order", (Integer) 1, propHost.getDisplayOrder());
PrismPropertyDefinition<String> propPort = configurationPropertiesDefinition.findPropertyDefinition(new ItemName(UcfTestUtil.CONNECTOR_LDAP_NS, "port"));
assertNotNull("No definition for configuration property 'port' in connector schema", propPort);
PrismAsserts.assertDefinition(propPort, new QName(UcfTestUtil.CONNECTOR_LDAP_NS, "port"), DOMUtil.XSD_INT, 0, 1);
assertEquals("Wrong property 'port' display name", "Port number", propPort.getDisplayName());
assertEquals("Wrong property 'port' help", "LDAP server port number.", propPort.getHelp());
// MID-2642
assertEquals("Wrong property 'port' display order", (Integer) 2, propPort.getDisplayOrder());
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class QShadowMapping method applyShadowAttributesDefinitions.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void applyShadowAttributesDefinitions(ShadowType shadowType, Jsonb rowAttributes) throws SchemaException {
Map<QName, MExtItem> definitions = definitionsFrom(rowAttributes);
if (shadowType.getAttributes() == null) {
return;
}
PrismContainerValue<?> attributes = shadowType.getAttributes().asPrismContainerValue();
for (Item<?, ?> attribute : attributes.getItems()) {
ItemName itemName = attribute.getElementName();
MExtItem itemInfo = definitions.get(itemName);
if (itemInfo != null && attribute.getDefinition() == null) {
((Item) attribute).applyDefinition(definitionFrom(itemName, itemInfo, false), true);
}
}
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class SqaleRepoAddDeleteObjectTest method test300AddObjectWithIndexedStringExtension.
// endregion
// region extension attributes
@Test
public void test300AddObjectWithIndexedStringExtension() throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException {
OperationResult result = createOperationResult();
given("object with string extension item");
String objectName = "user" + getTestNumber();
UserType object = new UserType(prismContext).name(objectName).extension(new ExtensionType(prismContext));
ExtensionType extensionContainer = object.getExtension();
addExtensionValue(extensionContainer, "string", "string-value");
when("adding it to the repository");
String returnedOid = repositoryService.addObject(object.asPrismObject(), null, result);
then("operation is successful and ext column contains the value");
assertThatOperationResult(result).isSuccess();
assertThat(returnedOid).isEqualTo(object.getOid());
MUser row = selectObjectByOid(QUser.class, returnedOid);
assertThat(row.oid).isEqualTo(UUID.fromString(returnedOid));
assertThat(row.ext).isNotNull();
assertThat(Jsonb.toMap(row.ext)).containsEntry(extensionKey(extensionContainer, "string"), "string-value");
and("stored object contains the extension item");
PrismObject<UserType> storedObject = repositoryService.getObject(UserType.class, returnedOid, null, result);
assertThat(storedObject.getExtension().findItem(new ItemName("string"))).isNotNull().extracting(i -> i.getRealValue()).isEqualTo("string-value");
}
use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.
the class SqaleRepoBaseTest method extKey.
@NotNull
private String extKey(Containerable extContainer, String itemName, MExtItemHolderType holder) {
PrismContainerValue<?> pcv = extContainer.asPrismContainerValue();
ItemDefinition<?> def = pcv.getDefinition().findItemDefinition(new ItemName(itemName));
MExtItem.Key key = MExtItem.keyFrom(def, holder);
try (JdbcSession jdbcSession = startReadOnlyTransaction()) {
QExtItem ei = QExtItem.DEFAULT;
return jdbcSession.newQuery().from(ei).where(ei.itemName.eq(key.itemName).and(ei.valueType.eq(key.valueType)).and(ei.holderType.eq(key.holderType)).and(ei.cardinality.eq(key.cardinality))).select(ei.id).fetchFirst().toString();
}
}
Aggregations