use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.
the class ItemWrapperComparator method compare.
@Override
public int compare(ItemWrapper p1, ItemWrapper p2) {
ItemDefinition def1 = p1.getItemDefinition();
ItemDefinition def2 = p2.getItemDefinition();
if (isMainContainer(p1)) {
return -1;
}
if (isMainContainer(p2)) {
return 1;
}
Integer index1 = def1.getDisplayOrder();
Integer index2 = def2.getDisplayOrder();
if (index1 != null && index2 != null) {
return index1 - index2;
} else if (index1 != null && index2 == null) {
return -1;
} else if (index1 == null && index2 != null) {
return 1;
}
return String.CASE_INSENSITIVE_ORDER.compare(getDisplayName(def1), getDisplayName(def2));
}
use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.
the class DynamicFieldGroupPanel method createItemWrapper.
private ItemWrapper createItemWrapper(AbstractFormItemType formField, ObjectWrapper objectWrapper) {
ItemPathType itemPathType = GuiImplUtil.getPathType(formField);
if (itemPathType == null) {
getSession().error("Bad form item definition. It has to contain reference to the real attribute");
LOGGER.error("Bad form item definition. It has to contain reference to the real attribute");
throw new RestartResponseException(getPageBase());
}
ItemPath path = itemPathType.getItemPath();
ItemDefinition itemDef = objectWrapper.getObject().getDefinition().findItemDefinition(path);
ItemWrapper itemWrapper = null;
if (itemDef instanceof PrismContainerDefinition) {
itemWrapper = objectWrapper.findContainerWrapper(path);
} else {
itemWrapper = objectWrapper.findPropertyWrapper(path);
}
if (itemWrapper == null) {
getSession().error("Bad form item definition. No attribute with path: " + path + " was found");
LOGGER.error("Bad form item definition. No attribute with path: " + path + " was found");
throw new RestartResponseException(getPageBase());
}
applyFormDefinition(itemWrapper, formField);
return itemWrapper;
}
use of com.evolveum.midpoint.prism.ItemDefinition 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.prism.ItemDefinition in project midpoint by Evolveum.
the class AbstractSecurityTest method assertItemFlags.
protected void assertItemFlags(PrismObjectDefinition<UserType> editSchema, ItemPath itemPath, boolean expectedRead, boolean expectedAdd, boolean expectedModify) {
ItemDefinition itemDefinition = editSchema.findItemDefinition(itemPath);
assertEquals("Wrong readability flag for " + itemPath, expectedRead, itemDefinition.canRead());
assertEquals("Wrong addition flag for " + itemPath, expectedAdd, itemDefinition.canAdd());
assertEquals("Wrong modification flag for " + itemPath, expectedModify, itemDefinition.canModify());
}
use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.
the class RShadow method copyFromJAXB.
public static <T extends ShadowType> void copyFromJAXB(ShadowType jaxb, RShadow<T> repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException {
RObject.copyFromJAXB(jaxb, repo, repositoryContext, generatorResult);
repo.setName(RPolyString.copyFromJAXB(jaxb.getName()));
repo.setObjectClass(RUtil.qnameToString(jaxb.getObjectClass()));
repo.setIntent(jaxb.getIntent());
repo.setKind(RUtil.getRepoEnumValue(jaxb.getKind(), RShadowKind.class));
repo.setFullSynchronizationTimestamp(jaxb.getFullSynchronizationTimestamp());
ItemDefinition def = jaxb.asPrismObject().getDefinition();
RUtil.copyResultFromJAXB(def, ShadowType.F_RESULT, jaxb.getResult(), repo, repositoryContext.prismContext);
if (jaxb.getSynchronizationSituation() != null) {
repo.setSynchronizationSituation(RUtil.getRepoEnumValue(jaxb.getSynchronizationSituation(), RSynchronizationSituation.class));
}
repo.setSynchronizationTimestamp(jaxb.getSynchronizationTimestamp());
repo.setResourceRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getResourceRef(), repositoryContext.prismContext));
repo.setAttemptNumber(jaxb.getAttemptNumber());
repo.setExists(jaxb.isExists());
repo.setDead(jaxb.isDead());
repo.setFailedOperationType(RUtil.getRepoEnumValue(jaxb.getFailedOperationType(), RFailedOperationType.class));
if (jaxb.getResource() != null) {
LOGGER.warn("Resource from resource object shadow type won't be saved. It should be " + "translated to resource reference.");
}
if (jaxb.getAttributes() != null) {
copyFromJAXB(jaxb.getAttributes().asPrismContainerValue(), repo, repositoryContext, RObjectExtensionType.ATTRIBUTES);
}
repo.pendingOperationCount = jaxb.getPendingOperation().size();
}
Aggregations