Search in sources :

Example 16 with ItemName

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);
                }
            }
        }
    }
}
Also used : QName(javax.xml.namespace.QName) ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 17 with ItemName

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());
}
Also used : QName(javax.xml.namespace.QName) ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 18 with ItemName

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);
        }
    }
}
Also used : MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) QName(javax.xml.namespace.QName) ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 19 with ItemName

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");
}
Also used : MArchetype(com.evolveum.midpoint.repo.sqale.qmodel.role.MArchetype) MReportData(com.evolveum.midpoint.repo.sqale.qmodel.report.MReportData) com.evolveum.midpoint.repo.sqale.qmodel.object(com.evolveum.midpoint.repo.sqale.qmodel.object) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) com.evolveum.midpoint.repo.sqale.qmodel.ref(com.evolveum.midpoint.repo.sqale.qmodel.ref) QSystemConfiguration(com.evolveum.midpoint.repo.sqale.qmodel.system.QSystemConfiguration) BigDecimal(java.math.BigDecimal) DOMUtil(com.evolveum.midpoint.util.DOMUtil) Map(java.util.Map) QNode(com.evolveum.midpoint.repo.sqale.qmodel.node.QNode) BigInteger(java.math.BigInteger) MContainer(com.evolveum.midpoint.repo.sqale.qmodel.common.MContainer) MConnector(com.evolveum.midpoint.repo.sqale.qmodel.connector.MConnector) QUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser) RepoAddOptions.createOverwrite(com.evolveum.midpoint.repo.api.RepoAddOptions.createOverwrite) QContainer(com.evolveum.midpoint.repo.sqale.qmodel.common.QContainer) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) MContainerType(com.evolveum.midpoint.repo.sqale.qmodel.common.MContainerType) MFocus(com.evolveum.midpoint.repo.sqale.qmodel.focus.MFocus) MiscUtil(com.evolveum.midpoint.util.MiscUtil) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) UUID(java.util.UUID) Instant(java.time.Instant) QLookupTableRow(com.evolveum.midpoint.repo.sqale.qmodel.lookuptable.QLookupTableRow) StandardCharsets(java.nio.charset.StandardCharsets) QMessageTemplate(com.evolveum.midpoint.repo.sqale.qmodel.notification.QMessageTemplate) com.evolveum.midpoint.repo.sqale.qmodel.cases.workitem(com.evolveum.midpoint.repo.sqale.qmodel.cases.workitem) QGenericObject(com.evolveum.midpoint.repo.sqale.qmodel.focus.QGenericObject) MTask(com.evolveum.midpoint.repo.sqale.qmodel.task.MTask) List(java.util.List) QConnector(com.evolveum.midpoint.repo.sqale.qmodel.connector.QConnector) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) QName(javax.xml.namespace.QName) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Jsonb(com.evolveum.midpoint.repo.sqale.jsonb.Jsonb) QResource(com.evolveum.midpoint.repo.sqale.qmodel.resource.QResource) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MResource(com.evolveum.midpoint.repo.sqale.qmodel.resource.MResource) QCase(com.evolveum.midpoint.repo.sqale.qmodel.cases.QCase) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest) QConnectorHost(com.evolveum.midpoint.repo.sqale.qmodel.connector.QConnectorHost) MShadow(com.evolveum.midpoint.repo.sqale.qmodel.shadow.MShadow) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) MConnectorHost(com.evolveum.midpoint.repo.sqale.qmodel.connector.MConnectorHost) QReport(com.evolveum.midpoint.repo.sqale.qmodel.report.QReport) Comparator.comparing(java.util.Comparator.comparing) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) Containerable(com.evolveum.midpoint.prism.Containerable) MLookupTableRow(com.evolveum.midpoint.repo.sqale.qmodel.lookuptable.MLookupTableRow) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) DeleteObjectResult(com.evolveum.midpoint.repo.api.DeleteObjectResult) MNode(com.evolveum.midpoint.repo.sqale.qmodel.node.MNode) com.evolveum.midpoint.repo.sqale.qmodel.assignment(com.evolveum.midpoint.repo.sqale.qmodel.assignment) PrismObject(com.evolveum.midpoint.prism.PrismObject) QShadow(com.evolveum.midpoint.repo.sqale.qmodel.shadow.QShadow) MUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser) SimpleExpressionUtil.velocityExpression(com.evolveum.midpoint.schema.util.SimpleExpressionUtil.velocityExpression) ChronoUnit(java.time.temporal.ChronoUnit) ItemName(com.evolveum.midpoint.prism.path.ItemName) QReportData(com.evolveum.midpoint.repo.sqale.qmodel.report.QReportData) MCase(com.evolveum.midpoint.repo.sqale.qmodel.cases.MCase) QArchetype(com.evolveum.midpoint.repo.sqale.qmodel.role.QArchetype) SqaleRepositoryService(com.evolveum.midpoint.repo.sqale.SqaleRepositoryService) QTask(com.evolveum.midpoint.repo.sqale.qmodel.task.QTask) com.evolveum.midpoint.repo.sqale.qmodel.accesscert(com.evolveum.midpoint.repo.sqale.qmodel.accesscert) ItemName(com.evolveum.midpoint.prism.path.ItemName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) MUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 20 with ItemName

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();
    }
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) ItemName(com.evolveum.midpoint.prism.path.ItemName) QExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.QExtItem) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ItemName (com.evolveum.midpoint.prism.path.ItemName)89 Test (org.testng.annotations.Test)24 QName (javax.xml.namespace.QName)19 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)13 NotNull (org.jetbrains.annotations.NotNull)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 Task (com.evolveum.midpoint.task.api.Task)6 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)5 MUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.MUser)5 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)5 Element (org.w3c.dom.Element)5 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)4 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)4 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)4 ArrayList (java.util.ArrayList)4 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)3