Search in sources :

Example 6 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class AssignmentProcessor method setReferences.

private <F extends ObjectType> void setReferences(LensFocusContext<F> focusContext, QName name, Collection<PrismReferenceValue> targetState) throws SchemaException {
    ItemName itemName = ItemName.fromQName(name);
    PrismObject<F> focusOld = focusContext.getObjectOld();
    if (focusOld == null) {
        if (targetState.isEmpty()) {
            return;
        }
    } else {
        PrismReference existingState = focusOld.findReference(itemName);
        if (existingState == null || existingState.isEmpty()) {
            if (targetState.isEmpty()) {
                return;
            }
        } else {
            // we don't use QNameUtil.match here, because we want to ensure we store qualified values there
            // (and newValues are all qualified)
            Comparator<PrismReferenceValue> comparator = (a, b) -> 2 * a.getOid().compareTo(b.getOid()) + (Objects.equals(a.getRelation(), b.getRelation()) ? 0 : 1);
            if (MiscUtil.unorderedCollectionCompare(targetState, existingState.getValues(), comparator)) {
                return;
            }
        }
    }
    PrismReferenceDefinition itemDef = focusContext.getObjectDefinition().findItemDefinition(itemName, PrismReferenceDefinition.class);
    ReferenceDelta itemDelta = prismContext.deltaFactory().reference().create(itemName, itemDef);
    itemDelta.setValuesToReplace(targetState);
    focusContext.swallowToSecondaryDelta(itemDelta);
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) BooleanUtils(org.apache.commons.lang.BooleanUtils) MappingFactory(com.evolveum.midpoint.model.common.mapping.MappingFactory) QNameUtil(com.evolveum.midpoint.util.QNameUtil) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ProcessorExecution(com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorExecution) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ActivationComputer(com.evolveum.midpoint.common.ActivationComputer) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) Objects(java.util.Objects) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ComplexConstructionConsumer(com.evolveum.midpoint.model.impl.lens.projector.ComplexConstructionConsumer) SystemObjectCache(com.evolveum.midpoint.model.common.SystemObjectCache) ProvisioningService(com.evolveum.midpoint.provisioning.api.ProvisioningService) Entry(java.util.Map.Entry) com.evolveum.midpoint.prism.delta(com.evolveum.midpoint.prism.delta) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) ProcessorMethod(com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod) FocusTypeUtil(com.evolveum.midpoint.schema.util.FocusTypeUtil) ContextLoader(com.evolveum.midpoint.model.impl.lens.projector.ContextLoader) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) ModelBeans(com.evolveum.midpoint.model.impl.ModelBeans) ObjectDeltaObject(com.evolveum.midpoint.prism.util.ObjectDeltaObject) EvaluatedConstructionPack(com.evolveum.midpoint.model.impl.lens.construction.EvaluatedConstructionPack) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ModelImplUtils(com.evolveum.midpoint.model.impl.util.ModelImplUtils) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) SchemaDebugUtil(com.evolveum.midpoint.schema.util.SchemaDebugUtil) MappingEvaluationEnvironment(com.evolveum.midpoint.model.common.mapping.MappingEvaluationEnvironment) com.evolveum.midpoint.model.impl.lens.projector.mappings(com.evolveum.midpoint.model.impl.lens.projector.mappings) RelationRegistry(com.evolveum.midpoint.schema.RelationRegistry) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PathKeyedMap(com.evolveum.midpoint.prism.path.PathKeyedMap) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl) EvaluatedAssignedResourceObjectConstructionImpl(com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl) ProjectorProcessor(com.evolveum.midpoint.model.impl.lens.projector.ProjectorProcessor) ItemValueWithOrigin(com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin) DeltaSetTripleMapConsolidation(com.evolveum.midpoint.model.impl.lens.projector.focus.consolidation.DeltaSetTripleMapConsolidation) LensUtil(com.evolveum.midpoint.model.impl.lens.LensUtil) ConstructionProcessor(com.evolveum.midpoint.model.impl.lens.projector.ConstructionProcessor) AssignmentEvaluator(com.evolveum.midpoint.model.impl.lens.assignments.AssignmentEvaluator) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectResolver(com.evolveum.midpoint.repo.common.ObjectResolver) SynchronizationPolicyDecision(com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ReferenceResolver(com.evolveum.midpoint.model.api.util.ReferenceResolver) Component(org.springframework.stereotype.Component) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ItemName(com.evolveum.midpoint.prism.path.ItemName) PolicyRuleProcessor(com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleProcessor) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 7 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method addAttributeToShadow.

protected <T> void addAttributeToShadow(PrismObject<ShadowType> shadow, PrismObject<ResourceType> resource, String attrName, T attrValue) throws SchemaException {
    ResourceAttributeContainer attrs = ShadowUtil.getAttributesContainer(shadow);
    ResourceAttributeDefinition attrSnDef = attrs.getDefinition().findAttributeDefinition(new ItemName(ResourceTypeUtil.getResourceNamespace(resource), attrName));
    ResourceAttribute<T> attr = attrSnDef.instantiate();
    attr.setRealValue(attrValue);
    attrs.add(attr);
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName)

Example 8 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class ColumnDataConverter method resolvePath.

/**
 * Resolves the path for the record.
 *
 * @return List of values of the item found. (Or empty list of nothing was found.)
 */
@NotNull
private List<? extends PrismValue> resolvePath(ItemPath itemPath) {
    Item<?, ?> currentItem = null;
    Iterator<?> iterator = itemPath.getSegments().iterator();
    while (iterator.hasNext()) {
        ItemName name = ItemPath.toNameOrNull(iterator.next());
        if (name == null) {
            continue;
        }
        if (currentItem == null) {
            currentItem = record.asPrismContainerValue().findItem(name);
        } else {
            currentItem = (Item<?, ?>) currentItem.find(name);
        }
        if (currentItem == null) {
            break;
        }
        if (currentItem instanceof PrismProperty) {
            stateCheck(!iterator.hasNext(), "Cannot continue resolving path in prism property: %s", currentItem);
        } else if (currentItem instanceof PrismReference) {
            if (currentItem.isSingleValue()) {
                Referencable ref = ((PrismReference) currentItem).getRealValue();
                if (ref != null && iterator.hasNext()) {
                    currentItem = reportService.getObjectFromReference(ref, task, result);
                }
            } else {
                stateCheck(!iterator.hasNext(), "Cannot continue resolving path in multivalued reference: %s", currentItem);
            }
        }
    }
    return currentItem != null ? currentItem.getValues() : List.of();
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class ConnIdConfigurationTransformer method transformConnectorConfiguration.

/**
 * Transforms midPoint XML configuration of the connector to the ICF
 * configuration.
 * <p/>
 * The "configuration" part of the XML resource definition will be used.
 * <p/>
 * The provided ICF APIConfiguration will be modified, some values may be
 * overwritten.
 *
 * @throws SchemaException
 * @throws ConfigurationException
 */
public APIConfiguration transformConnectorConfiguration(PrismContainerValue configuration) throws SchemaException, ConfigurationException {
    APIConfiguration apiConfig = cinfo.createDefaultAPIConfiguration();
    ConfigurationProperties configProps = apiConfig.getConfigurationProperties();
    // The namespace of all the configuration properties specific to the
    // connector instance will have a connector instance namespace. This
    // namespace can be found in the resource definition.
    String connectorConfNs = connectorType.getNamespace();
    PrismContainer configurationPropertiesContainer = configuration.findContainer(SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_ELEMENT_QNAME);
    if (configurationPropertiesContainer == null) {
        // Also try this. This is an older way.
        configurationPropertiesContainer = configuration.findContainer(new QName(connectorConfNs, SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_ELEMENT_LOCAL_NAME));
    }
    transformConnectorConfigurationProperties(configProps, configurationPropertiesContainer, connectorConfNs);
    PrismContainer connectorPoolContainer = configuration.findContainer(new QName(SchemaConstants.NS_ICF_CONFIGURATION, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_XML_ELEMENT_NAME));
    ObjectPoolConfiguration connectorPoolConfiguration = apiConfig.getConnectorPoolConfiguration();
    transformConnectorPoolConfiguration(connectorPoolConfiguration, connectorPoolContainer);
    PrismProperty producerBufferSizeProperty = configuration.findProperty(new ItemName(SchemaConstants.NS_ICF_CONFIGURATION, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_PRODUCER_BUFFER_SIZE_XML_ELEMENT_NAME));
    if (producerBufferSizeProperty != null) {
        apiConfig.setProducerBufferSize(parseInt(producerBufferSizeProperty));
    }
    PrismContainer connectorTimeoutsContainer = configuration.findContainer(new QName(SchemaConstants.NS_ICF_CONFIGURATION, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_TIMEOUTS_XML_ELEMENT_NAME));
    transformConnectorTimeoutsConfiguration(apiConfig, connectorTimeoutsContainer);
    PrismContainer resultsHandlerConfigurationContainer = configuration.findContainer(new QName(SchemaConstants.NS_ICF_CONFIGURATION, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ELEMENT_LOCAL_NAME));
    ResultsHandlerConfiguration resultsHandlerConfiguration = apiConfig.getResultsHandlerConfiguration();
    transformResultsHandlerConfiguration(resultsHandlerConfiguration, resultsHandlerConfigurationContainer);
    return apiConfig;
}
Also used : PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ObjectPoolConfiguration(org.identityconnectors.common.pooling.ObjectPoolConfiguration) ResultsHandlerConfiguration(org.identityconnectors.framework.api.ResultsHandlerConfiguration) QName(javax.xml.namespace.QName) APIConfiguration(org.identityconnectors.framework.api.APIConfiguration) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) ItemName(com.evolveum.midpoint.prism.path.ItemName) ConfigurationProperties(org.identityconnectors.framework.api.ConfigurationProperties) GuardedString(org.identityconnectors.common.security.GuardedString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 10 with ItemName

use of com.evolveum.midpoint.prism.path.ItemName in project midpoint by Evolveum.

the class ConnIdToMidPointConversion method convertStandardAttribute.

private void convertStandardAttribute(Attribute connIdAttr, String connIdAttrName, List<Object> values) throws SchemaException {
    ItemName convertedAttrName = ItemName.fromQName(connIdConvertor.connIdNameMapper.convertAttributeNameToQName(connIdAttrName, attributesContainerDefinition));
    // noinspection unchecked
    ResourceAttributeDefinition<Object> convertedAttributeDefinition = (ResourceAttributeDefinition<Object>) findAttributeDefinition(connIdAttrName, convertedAttrName);
    QName normalizedAttributeName;
    if (caseIgnoreAttributeNames) {
        // this is the normalized version
        normalizedAttributeName = convertedAttributeDefinition.getItemName();
    } else {
        normalizedAttributeName = convertedAttrName;
    }
    ResourceAttribute<Object> convertedAttribute = convertedAttributeDefinition.instantiate(normalizedAttributeName);
    convertedAttribute.setIncomplete(isIncomplete(connIdAttr));
    // resource object also with the null-values attributes
    if (full) {
        for (Object connIdValue : values) {
            // Convert the value. While most values do not need conversions, some of them may need it (e.g. GuardedString)
            Object convertedValue = convertValueFromConnId(connIdValue);
            convertedAttribute.addRealValueSkipUniquenessCheck(convertedValue);
        }
        LOGGER.trace("Converted attribute {}", convertedAttribute);
        attributesContainer.getValue().add(convertedAttribute);
    } else {
        // In this case (full=false) we need only the attributes with non-null values.
        for (Object connIdValue : values) {
            if (connIdValue != null) {
                // Convert the value. While most values do not need conversions, some of them may need it (e.g. GuardedString)
                Object convertedValue = convertValueFromConnId(connIdValue);
                convertedAttribute.addRealValueSkipUniquenessCheck(convertedValue);
            }
        }
        if (!convertedAttribute.getValues().isEmpty() || convertedAttribute.isIncomplete()) {
            LOGGER.trace("Converted attribute {}", convertedAttribute);
            attributesContainer.getValue().add(convertedAttribute);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) ItemName(com.evolveum.midpoint.prism.path.ItemName) PrismObject(com.evolveum.midpoint.prism.PrismObject)

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