use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType in project midpoint by Evolveum.
the class TestCorrelationConfiramtionEvaluator method test006CorrelationFindCaseInsensitive.
@Test
public void test006CorrelationFindCaseInsensitive() throws Exception {
String TEST_NAME = "test006CorrelationFindCaseInsensitive";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TEST_NAME);
OperationResult result = task.getResult();
// importObjectFromFile(USER_JACK_FILENAME);
PrismObject<UserType> userType = repositoryService.getObject(UserType.class, USER_JACK_OID, null, result);
//assert jack
assertNotNull(userType);
ShadowType shadow = parseObjectType(ACCOUNT_SHADOW_JACK_DUMMY_FILE, ShadowType.class);
ConditionalSearchFilterType query = PrismTestUtil.parseAtomicValue(new File(CORRELATION_CASE_INSENSITIVE), ConditionalSearchFilterType.COMPLEX_TYPE);
List<ConditionalSearchFilterType> queries = new ArrayList<>();
queries.add(query);
//
ResourceType resourceType = parseObjectType(RESOURCE_DUMMY_FILE, ResourceType.class);
// resourceType.getSynchronization().getObjectSynchronization().get(0).getCorrelation().add(query);
userType.asObjectable().setName(new PolyStringType("JACK"));
Collection<? extends ItemDelta> modifications = PropertyDelta.createModificationReplacePropertyCollection(UserType.F_NAME, userType.getDefinition(), new PolyString("JACK", "jack"));
repositoryService.modifyObject(UserType.class, USER_JACK_OID, modifications, result);
List<PrismObject<UserType>> matchedUsers = evaluator.findFocusesByCorrelationRule(UserType.class, shadow, queries, resourceType, getSystemConfiguration(), task, result);
System.out.println("matched users " + matchedUsers);
assertNotNull("Correlation evaluator returned null collection of matched users.", matchedUsers);
assertEquals("Found more than one user.", 1, matchedUsers.size());
PrismObject<UserType> jack = matchedUsers.get(0);
assertUser(jack, "c0c010c0-d34d-b33f-f00d-111111111111", "JACK", "Jack Sparrow", "Jack", "Sparrow");
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType in project midpoint by Evolveum.
the class ContainerWrapperFactory method hasActivationCapability.
private boolean hasActivationCapability(ContainerWrapper cWrapper, PrismPropertyDefinition def) {
ObjectWrapper oWrapper = cWrapper.getObject();
ShadowType shadow = (ShadowType) oWrapper.getObject().asObjectable();
ActivationCapabilityType cap = ResourceTypeUtil.getEffectiveCapability(shadow.getResource(), ActivationCapabilityType.class);
if (ActivationType.F_VALID_FROM.equals(def.getName()) && CapabilityUtil.getEffectiveActivationValidFrom(cap) == null) {
return false;
}
if (ActivationType.F_VALID_TO.equals(def.getName()) && CapabilityUtil.getEffectiveActivationValidTo(cap) == null) {
return false;
}
if (ActivationType.F_ADMINISTRATIVE_STATUS.equals(def.getName()) && CapabilityUtil.getEffectiveActivationStatus(cap) == null) {
return false;
}
return true;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType in project midpoint by Evolveum.
the class DefaultGuiProgressListener method updateStatusItemState.
private void updateStatusItemState(ProgressReportActivityDto si, ProgressInformation progressInformation, ModelContext modelContext) {
si.setActivityType(progressInformation.getActivityType());
si.setResourceShadowDiscriminator(progressInformation.getResourceShadowDiscriminator());
if (progressInformation.getResourceShadowDiscriminator() != null) {
String resourceOid = progressInformation.getResourceShadowDiscriminator().getResourceOid();
String resourceName = resourceOid != null ? getResourceName(resourceOid) : "";
si.setResourceName(resourceName);
}
if (progressInformation.getStateType() == null) {
si.setStatus(null);
} else if (progressInformation.getStateType() == ENTERING) {
si.setStatus(OperationResultStatusType.IN_PROGRESS);
} else {
OperationResult result = progressInformation.getOperationResult();
if (result != null) {
OperationResultStatus status = result.getStatus();
if (status == OperationResultStatus.UNKNOWN) {
status = result.getComputeStatus();
}
si.setStatus(status.createStatusType());
} else {
si.setStatus(OperationResultStatusType.UNKNOWN);
}
}
// information about modifications on a resource
if (progressInformation.getActivityType() == RESOURCE_OBJECT_OPERATION && progressInformation.getStateType() == EXITING && progressInformation.getResourceShadowDiscriminator() != null && progressInformation.getResourceShadowDiscriminator().getResourceOid() != null) {
ModelProjectionContext mpc = modelContext.findProjectionContext(progressInformation.getResourceShadowDiscriminator());
if (mpc != null) {
// it shouldn't be null!
// operations performed (TODO aggregate them somehow?)
List<ResourceOperationResult> resourceOperationResultList = new ArrayList<>();
List<? extends ObjectDeltaOperation> executedDeltas = mpc.getExecutedDeltas();
for (ObjectDeltaOperation executedDelta : executedDeltas) {
ObjectDelta delta = executedDelta.getObjectDelta();
if (delta != null) {
OperationResult r = executedDelta.getExecutionResult();
OperationResultStatus status = r.getStatus();
if (status == OperationResultStatus.UNKNOWN) {
status = r.getComputeStatus();
}
resourceOperationResultList.add(new ResourceOperationResult(delta.getChangeType(), status));
}
}
si.setResourceOperationResultList(resourceOperationResultList);
// object name
PrismObject<ShadowType> object = mpc.getObjectNew();
if (object == null) {
object = mpc.getObjectOld();
}
String name = null;
if (object != null) {
if (object.asObjectable().getName() != null) {
name = PolyString.getOrig(object.asObjectable().getName());
} else {
// determine from attributes
ResourceAttribute nameAttribute = ShadowUtil.getNamingAttribute(object);
if (nameAttribute != null) {
name = String.valueOf(nameAttribute.getAnyRealValue());
}
}
}
if (name != null) {
si.setResourceObjectName(name);
}
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType in project midpoint by Evolveum.
the class OutboundProcessor method evaluateMapping.
private <F extends FocusType, V extends PrismValue, D extends ItemDefinition> Mapping<V, D> evaluateMapping(final Mapping.Builder<V, D> mappingBuilder, QName mappingQName, D targetDefinition, ObjectDeltaObject<F> focusOdo, ObjectDeltaObject<ShadowType> projectionOdo, String operation, RefinedObjectClassDefinition rOcDef, RefinedObjectClassDefinition assocTargetObjectClassDefinition, LensContext<F> context, LensProjectionContext projCtx, final Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
if (!mappingBuilder.isApplicableToChannel(context.getChannel())) {
LOGGER.trace("Skipping outbound mapping for {} because the channel does not match", mappingQName);
return null;
}
// TODO: check access
// This is just supposed to be an optimization. The consolidation should deal with the weak mapping
// even if it is there. But in that case we do not need to evaluate it at all.
// Edit 2017-02-16 pmed: It's not quite true. If the attribute is non-tolerant, it will get removed if we would
// skip evaluation of this mapping. So we really need to do this.
// if (mappingBuilder.getStrength() == MappingStrengthType.WEAK && projCtx.hasValueForAttribute(mappingQName)) {
// LOGGER.trace("Skipping outbound mapping for {} because it is weak", mappingQName);
// return null;
// }
mappingBuilder.setDefaultTargetDefinition(targetDefinition);
mappingBuilder.setSourceContext(focusOdo);
mappingBuilder.setMappingQName(mappingQName);
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_USER, focusOdo);
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_FOCUS, focusOdo);
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, projectionOdo);
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_SHADOW, projectionOdo);
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_PROJECTION, projectionOdo);
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_CONFIGURATION, context.getSystemConfiguration());
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ITERATION, LensUtil.getIterationVariableValue(projCtx));
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ITERATION_TOKEN, LensUtil.getIterationTokenVariableValue(projCtx));
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_RESOURCE, projCtx.getResource());
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_OPERATION, operation);
if (assocTargetObjectClassDefinition != null) {
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION, assocTargetObjectClassDefinition);
}
mappingBuilder.setRootNode(focusOdo);
mappingBuilder.setOriginType(OriginType.OUTBOUND);
mappingBuilder.setRefinedObjectClassDefinition(rOcDef);
StringPolicyResolver stringPolicyResolver = new StringPolicyResolver() {
private ItemPath outputPath;
private ItemDefinition outputDefinition;
@Override
public void setOutputPath(ItemPath outputPath) {
this.outputPath = outputPath;
}
@Override
public void setOutputDefinition(ItemDefinition outputDefinition) {
this.outputDefinition = outputDefinition;
}
@Override
public StringPolicyType resolve() {
if (mappingBuilder.getMappingType().getExpression() != null) {
List<JAXBElement<?>> evaluators = mappingBuilder.getMappingType().getExpression().getExpressionEvaluator();
for (JAXBElement jaxbEvaluator : evaluators) {
Object object = jaxbEvaluator.getValue();
if (object instanceof GenerateExpressionEvaluatorType && ((GenerateExpressionEvaluatorType) object).getValuePolicyRef() != null) {
ObjectReferenceType ref = ((GenerateExpressionEvaluatorType) object).getValuePolicyRef();
try {
ValuePolicyType valuePolicyType = mappingBuilder.getObjectResolver().resolve(ref, ValuePolicyType.class, null, "resolving value policy for generate attribute " + outputDefinition.getName() + "value", task, new OperationResult("Resolving value policy"));
if (valuePolicyType != null) {
return valuePolicyType.getStringPolicy();
}
} catch (CommonException ex) {
throw new SystemException(ex.getMessage(), ex);
}
}
}
}
return null;
}
};
mappingBuilder.setStringPolicyResolver(stringPolicyResolver);
// (e.g. in old values in ADD situations and new values in DELETE situations).
if (focusOdo.getOldObject() == null) {
mappingBuilder.setConditionMaskOld(false);
}
if (focusOdo.getNewObject() == null) {
mappingBuilder.setConditionMaskNew(false);
}
Mapping<V, D> mapping = mappingBuilder.build();
mappingEvaluator.evaluateMapping(mapping, context, projCtx, task, result);
return mapping;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType in project midpoint by Evolveum.
the class OutboundProcessor method processOutbound.
public <F extends FocusType> void processOutbound(LensContext<F> context, LensProjectionContext projCtx, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
ResourceShadowDiscriminator discr = projCtx.getResourceShadowDiscriminator();
ObjectDelta<ShadowType> projectionDelta = projCtx.getDelta();
if (projectionDelta != null && projectionDelta.getChangeType() == ChangeType.DELETE) {
LOGGER.trace("Processing outbound expressions for {} skipped, DELETE account delta", discr);
// No point in evaluating outbound
return;
}
LOGGER.trace("Processing outbound expressions for {} starting", discr);
RefinedObjectClassDefinition rOcDef = projCtx.getStructuralObjectClassDefinition();
if (rOcDef == null) {
LOGGER.error("Definition for {} not found in the context, but it should be there, dumping context:\n{}", discr, context.debugDump());
throw new IllegalStateException("Definition for " + discr + " not found in the context, but it should be there");
}
ObjectDeltaObject<F> focusOdo = context.getFocusContext().getObjectDeltaObject();
ObjectDeltaObject<ShadowType> projectionOdo = projCtx.getObjectDeltaObject();
Construction<F> outboundConstruction = new Construction<>(null, projCtx.getResource());
outboundConstruction.setRefinedObjectClassDefinition(rOcDef);
Collection<RefinedObjectClassDefinition> auxiliaryObjectClassDefinitions = rOcDef.getAuxiliaryObjectClassDefinitions();
if (auxiliaryObjectClassDefinitions != null) {
for (RefinedObjectClassDefinition auxiliaryObjectClassDefinition : auxiliaryObjectClassDefinitions) {
outboundConstruction.addAuxiliaryObjectClassDefinition(auxiliaryObjectClassDefinition);
}
}
String operation = projCtx.getOperation().getValue();
for (QName attributeName : rOcDef.getNamesOfAttributesWithOutboundExpressions()) {
RefinedAttributeDefinition<?> refinedAttributeDefinition = rOcDef.findAttributeDefinition(attributeName);
final MappingType outboundMappingType = refinedAttributeDefinition.getOutboundMappingType();
if (outboundMappingType == null) {
continue;
}
if (refinedAttributeDefinition.isIgnored(LayerType.MODEL)) {
LOGGER.trace("Skipping processing outbound mapping for attribute {} because it is ignored", attributeName);
continue;
}
Mapping.Builder<PrismPropertyValue<?>, RefinedAttributeDefinition<?>> builder = mappingFactory.createMappingBuilder(outboundMappingType, "outbound mapping for " + PrettyPrinter.prettyPrint(refinedAttributeDefinition.getName()) + " in " + rOcDef.getResourceType());
builder = builder.originObject(rOcDef.getResourceType()).originType(OriginType.OUTBOUND);
Mapping<PrismPropertyValue<?>, RefinedAttributeDefinition<?>> evaluatedMapping = evaluateMapping(builder, attributeName, refinedAttributeDefinition, focusOdo, projectionOdo, operation, rOcDef, null, context, projCtx, task, result);
if (evaluatedMapping != null) {
outboundConstruction.addAttributeMapping(evaluatedMapping);
}
}
for (QName assocName : rOcDef.getNamesOfAssociationsWithOutboundExpressions()) {
RefinedAssociationDefinition associationDefinition = rOcDef.findAssociationDefinition(assocName);
final MappingType outboundMappingType = associationDefinition.getOutboundMappingType();
if (outboundMappingType == null) {
continue;
}
// if (associationDefinition.isIgnored(LayerType.MODEL)) {
// LOGGER.trace("Skipping processing outbound mapping for attribute {} because it is ignored", assocName);
// continue;
// }
Mapping.Builder<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> mappingBuilder = mappingFactory.createMappingBuilder(outboundMappingType, "outbound mapping for " + PrettyPrinter.prettyPrint(associationDefinition.getName()) + " in " + rOcDef.getResourceType());
PrismContainerDefinition<ShadowAssociationType> outputDefinition = getAssociationContainerDefinition();
Mapping<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> evaluatedMapping = (Mapping) evaluateMapping(mappingBuilder, assocName, outputDefinition, focusOdo, projectionOdo, operation, rOcDef, associationDefinition.getAssociationTarget(), context, projCtx, task, result);
if (evaluatedMapping != null) {
outboundConstruction.addAssociationMapping(evaluatedMapping);
}
}
projCtx.setOutboundConstruction(outboundConstruction);
}
Aggregations