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);
}
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);
}
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();
}
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;
}
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);
}
}
}
Aggregations