use of com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType in project midpoint by Evolveum.
the class ObjectMerger method computeProjectionDeltas.
private <O extends ObjectType> void computeProjectionDeltas(final ObjectDelta<O> leftLinkDelta, ObjectDelta<O> rightLinkDelta, final PrismObject<O> objectLeft, final PrismObject<O> objectRight, MergeConfigurationType mergeConfiguration, final String mergeConfigurationName, final Task task, final OperationResult result) throws SchemaException, ConfigurationException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, SecurityViolationException {
List<ShadowType> projectionsLeft = getProjections(objectLeft, task, result);
List<ShadowType> projectionsRight = getProjections(objectRight, task, result);
List<ShadowType> mergedProjections = new ArrayList<>();
List<ShadowType> matchedProjections = new ArrayList<>();
ProjectionMergeConfigurationType defaultProjectionMergeConfig = null;
for (ProjectionMergeConfigurationType projectionMergeConfig : mergeConfiguration.getProjection()) {
if (projectionMergeConfig.getProjectionDiscriminator() == null && projectionMergeConfig.getSituation() == null) {
defaultProjectionMergeConfig = projectionMergeConfig;
} else {
takeProjections(projectionMergeConfig.getLeft(), mergedProjections, matchedProjections, projectionsLeft, projectionsLeft, projectionsRight, projectionMergeConfig);
takeProjections(projectionMergeConfig.getRight(), mergedProjections, matchedProjections, projectionsRight, projectionsLeft, projectionsRight, projectionMergeConfig);
}
}
LOGGER.trace("Merged projections (before default): {}", mergedProjections);
LOGGER.trace("Matched projections (before default): {}", matchedProjections);
if (defaultProjectionMergeConfig != null) {
takeUnmatchedProjections(defaultProjectionMergeConfig.getLeft(), mergedProjections, matchedProjections, projectionsLeft);
takeUnmatchedProjections(defaultProjectionMergeConfig.getRight(), mergedProjections, matchedProjections, projectionsRight);
}
LOGGER.trace("Merged projections: {}", mergedProjections);
checkConflict(mergedProjections);
for (ShadowType mergedProjection : mergedProjections) {
PrismReferenceValue leftLinkRef = findLinkRef(objectLeft, mergedProjection);
if (leftLinkRef == null) {
PrismReferenceValue linkRefRight = findLinkRef(objectRight, mergedProjection);
LOGGER.trace("Moving projection right->left: {}", mergedProjection);
addUnlinkDelta(rightLinkDelta, linkRefRight);
addLinkDelta(leftLinkDelta, linkRefRight);
} else {
LOGGER.trace("Projection already at the left: {}", mergedProjection);
}
}
for (PrismReferenceValue leftLinkRef : getLinkRefs(objectLeft)) {
if (!hasProjection(mergedProjections, leftLinkRef)) {
LOGGER.trace("Removing left projection: {}", leftLinkRef);
addUnlinkDelta(leftLinkDelta, leftLinkRef);
} else {
LOGGER.trace("Left projection stays: {}", leftLinkRef);
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType in project midpoint by Evolveum.
the class ObjectMerger method computeItemDeltas.
private <O extends ObjectType> void computeItemDeltas(final ObjectDelta<O> leftObjectDelta, final PrismObject<O> objectLeft, final PrismObject<O> objectRight, final List<ItemPath> processedPaths, MergeConfigurationType mergeConfiguration, final String mergeConfigurationName, final Task task, final OperationResult result) throws SchemaException, ConfigurationException, ExpressionEvaluationException, ObjectNotFoundException {
for (ItemRefMergeConfigurationType itemMergeConfig : mergeConfiguration.getItem()) {
ItemPath itemPath = itemMergeConfig.getRef().getItemPath();
processedPaths.add(itemPath);
ItemDelta itemDelta = mergeItem(objectLeft, objectRight, mergeConfigurationName, itemMergeConfig, itemPath, task, result);
LOGGER.trace("Item {} delta: {}", itemPath, itemDelta);
if (itemDelta != null && !itemDelta.isEmpty()) {
leftObjectDelta.addModification(itemDelta);
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType in project midpoint by Evolveum.
the class MergeObjectsPanel method getMergeTypeNames.
private List<String> getMergeTypeNames() {
List<String> mergeTypeNamesList = new ArrayList<>();
Task task = pageBase.createAnonymousTask(OPERATION_LOAD_MERGE_TYPE_NAMES);
OperationResult result = task.getResult();
PrismObject<SystemConfigurationType> config;
try {
config = pageBase.getModelService().getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, task, result);
} catch (ObjectNotFoundException | SchemaException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
LOGGER.error("Error getting system configuration: {}", e.getMessage(), e);
return null;
}
if (config != null && config.asObjectable() != null) {
List<MergeConfigurationType> list = config.asObjectable().getMergeConfiguration();
if (list != null) {
for (MergeConfigurationType mergeType : list) {
mergeTypeNamesList.add(mergeType.getName());
}
if (mergeTypeNamesList.size() > 0) {
currentMergeType = mergeTypeNamesList.get(0);
}
}
}
return mergeTypeNamesList;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType in project midpoint by Evolveum.
the class ObjectMerger method computeMergeDeltas.
public <O extends ObjectType> MergeDeltas<O> computeMergeDeltas(Class<O> type, String leftOid, String rightOid, final String mergeConfigurationName, final Task task, final OperationResult result) throws ObjectNotFoundException, SchemaException, ConfigurationException, ExpressionEvaluationException, CommunicationException, SecurityViolationException {
final PrismObject<O> objectLeft = (PrismObject<O>) objectResolver.getObjectSimple(type, leftOid, null, task, result).asPrismObject();
final PrismObject<O> objectRight = (PrismObject<O>) objectResolver.getObjectSimple(type, rightOid, null, task, result).asPrismObject();
PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(result);
MergeConfigurationType mergeConfiguration = selectConfiguration(systemConfiguration, mergeConfigurationName);
if (mergeConfiguration == null) {
throw new ConfigurationException("No merge configuration defined");
}
// The "left" object is always the one that will be the result. We will use its OID.
final ObjectDelta<O> leftObjectDelta = objectLeft.createModifyDelta();
final ObjectDelta<O> leftLinkDelta = objectLeft.createModifyDelta();
final ObjectDelta<O> rightLinkDelta = objectRight.createModifyDelta();
final List<ItemPath> processedPaths = new ArrayList<>();
computeItemDeltas(leftObjectDelta, objectLeft, objectRight, processedPaths, mergeConfiguration, mergeConfigurationName, task, result);
computeDefaultDeltas(leftObjectDelta, objectLeft, objectRight, processedPaths, mergeConfiguration, mergeConfigurationName, task, result);
computeProjectionDeltas(leftLinkDelta, rightLinkDelta, objectLeft, objectRight, mergeConfiguration, mergeConfigurationName, task, result);
return new MergeDeltas<>(leftObjectDelta, leftLinkDelta, rightLinkDelta);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType in project midpoint by Evolveum.
the class ObjectMerger method computeDefaultDeltas.
private <O extends ObjectType> void computeDefaultDeltas(final ObjectDelta<O> leftObjectDelta, final PrismObject<O> objectLeft, final PrismObject<O> objectRight, final List<ItemPath> processedPaths, MergeConfigurationType mergeConfiguration, final String mergeConfigurationName, final Task task, final OperationResult result) throws SchemaException, ConfigurationException, ExpressionEvaluationException, ObjectNotFoundException {
final ItemMergeConfigurationType defaultItemMergeConfig = mergeConfiguration.getDefault();
if (defaultItemMergeConfig != null) {
try {
Visitor visitor = new Visitor() {
@Override
public void visit(Visitable visitable) {
if (!(visitable instanceof Item)) {
return;
}
Item item = (Item) visitable;
ItemPath itemPath = item.getPath();
if (itemPath == null || itemPath.isEmpty()) {
return;
}
if (SchemaConstants.PATH_LINK_REF.equivalent(itemPath)) {
// Skip. There is a special processing for this.
return;
}
boolean found = false;
for (ItemPath processedPath : processedPaths) {
// Need to check for super-paths here.
// E.g. if we have already processed metadata, we do not want to process
// metadata/modifyTimestamp
CompareResult compareResult = processedPath.compareComplex(itemPath);
if (compareResult == CompareResult.EQUIVALENT || compareResult == CompareResult.SUBPATH) {
found = true;
break;
}
}
if (found) {
return;
}
processedPaths.add(itemPath);
if (item instanceof PrismContainer<?>) {
if (item.getDefinition().isSingleValue()) {
// we will handle every individual property there.
return;
} else {
// TODO: we may need special handling for multi-value containers
// such as assignment
}
}
ItemDelta itemDelta;
try {
itemDelta = mergeItem(objectLeft, objectRight, mergeConfigurationName, defaultItemMergeConfig, itemPath, task, result);
} catch (SchemaException | ConfigurationException | ExpressionEvaluationException | ObjectNotFoundException e) {
throw new TunnelException(e);
}
LOGGER.trace("Item {} delta (default): {}", itemPath, itemDelta);
if (itemDelta != null && !itemDelta.isEmpty()) {
leftObjectDelta.addModification(itemDelta);
}
}
};
objectLeft.accept(visitor);
objectRight.accept(visitor);
} catch (TunnelException te) {
if (te.getCause() instanceof SchemaException) {
throw (SchemaException) te.getCause();
} else if (te.getCause() instanceof ConfigurationException) {
throw (ConfigurationException) te.getCause();
} else if (te.getCause() instanceof ExpressionEvaluationException) {
throw (ExpressionEvaluationException) te.getCause();
} else if (te.getCause() instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) te.getCause();
} else {
throw new SystemException("Unexpected exception: " + te, te);
}
}
}
}
Aggregations