use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class ObjectSelectionPanel method initColumns.
private List<IColumn<SelectableBean<ObjectType>, String>> initColumns() {
List<IColumn<SelectableBean<ObjectType>, String>> columns = new ArrayList<>();
IColumn column = new LinkColumn<SelectableBean<ObjectType>>(createStringResource("chooseTypeDialog.column.name"), context.getSortableProperty(), "value.name") {
@Override
public void onClick(AjaxRequestTarget target, IModel<SelectableBean<ObjectType>> rowModel) {
ObjectType object = rowModel.getObject().getValue();
context.chooseOperationPerformed(target, object);
}
};
columns.add(column);
return columns;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class GenerateExpressionEvaluator method evaluate.
/*
* (non-Javadoc)
*
* @see
* com.evolveum.midpoint.common.expression.ExpressionEvaluator#evaluate(java
* .util.Collection, java.util.Map, boolean, java.lang.String,
* com.evolveum.midpoint.schema.result.OperationResult)
*/
@Override
public PrismValueDeltaSetTriple<V> evaluate(ExpressionEvaluationContext context) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
StringPolicyType stringPolicyType = null;
ObjectReferenceType generateEvaluatorValuePolicyRef = generateEvaluatorType.getValuePolicyRef();
if (generateEvaluatorValuePolicyRef != null) {
if (generateEvaluatorType.getValuePolicyRef() != null) {
ValuePolicyType valuePolicyType = objectResolver.resolve(generateEvaluatorValuePolicyRef, ValuePolicyType.class, null, "resolving value policy reference in generateExpressionEvaluator", context.getTask(), context.getResult());
stringPolicyType = valuePolicyType.getStringPolicy();
}
}
// would be generated
if (stringPolicyType == null) {
StringPolicyResolver stringPolicyResolver = context.getStringPolicyResolver();
if (stringPolicyResolver != null) {
stringPolicyType = stringPolicyResolver.resolve();
}
}
elementStringPolicy = stringPolicyType;
// } else {
// stringPolicyType = elementStringPolicy;
// }
//
String stringValue = null;
GenerateExpressionEvaluatorModeType mode = generateEvaluatorType.getMode();
Item<V, D> output = outputDefinition.instantiate();
if (mode == null || mode == GenerateExpressionEvaluatorModeType.POLICY) {
PrismObject<? extends ObjectType> object = getObject(context);
// TODO: generate value based on stringPolicyType (if not null)
if (stringPolicyType != null) {
if (isNotEmptyMinLength(stringPolicyType)) {
stringValue = valuePolicyGenerator.generate(output.getPath(), stringPolicyType, DEFAULT_LENGTH, true, object, context.getContextDescription(), context.getTask(), context.getResult());
} else {
stringValue = valuePolicyGenerator.generate(output.getPath(), stringPolicyType, DEFAULT_LENGTH, false, object, context.getContextDescription(), context.getTask(), context.getResult());
}
context.getResult().computeStatus();
if (context.getResult().isError()) {
throw new ExpressionEvaluationException("Failed to generate value according to policy: " + stringPolicyType.getDescription() + ". " + context.getResult().getMessage());
}
}
if (stringValue == null) {
int length = DEFAULT_LENGTH;
RandomString randomString = new RandomString(length);
stringValue = randomString.nextString();
}
} else if (mode == GenerateExpressionEvaluatorModeType.UUID) {
UUID randomUUID = UUID.randomUUID();
stringValue = randomUUID.toString();
} else {
throw new ExpressionEvaluationException("Unknown mode for generate expression: " + mode);
}
Object value = ExpressionUtil.convertToOutputValue(stringValue, outputDefinition, protector);
if (output instanceof PrismProperty) {
PrismPropertyValue<Object> pValue = new PrismPropertyValue<Object>(value);
((PrismProperty<Object>) output).add(pValue);
} else {
throw new UnsupportedOperationException("Can only generate values of property, not " + output.getClass());
}
return ItemDelta.toDeltaSetTriple(output, null);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class AbstractSearchExpressionEvaluator method executeSearchUsingCache.
private <O extends ObjectType> List<V> executeSearchUsingCache(Class<O> targetTypeClass, final QName targetTypeQName, ObjectQuery query, List<ItemDelta<V, D>> additionalAttributeDeltas, final ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
ObjectSearchStrategyType searchStrategy = getSearchStrategy();
AbstractSearchExpressionEvaluatorCache cache = getCache();
if (cache == null) {
return executeSearch(null, targetTypeClass, targetTypeQName, query, searchStrategy, additionalAttributeDeltas, params, contextDescription, task, result);
}
List<V> list = cache.getQueryResult(targetTypeClass, query, searchStrategy, params, prismContext);
if (list != null) {
LOGGER.trace("Cache: HIT {} ({})", query, targetTypeClass.getSimpleName());
return CloneUtil.clone(list);
}
LOGGER.trace("Cache: MISS {} ({})", query, targetTypeClass.getSimpleName());
List<PrismObject> rawResult = new ArrayList<>();
list = executeSearch(rawResult, targetTypeClass, targetTypeQName, query, searchStrategy, additionalAttributeDeltas, params, contextDescription, task, result);
if (list != null && !list.isEmpty()) {
// we don't want to cache negative results (e.g. if used with focal objects it might mean that they would be attempted to create multiple times)
cache.putQueryResult(targetTypeClass, query, searchStrategy, params, list, rawResult, prismContext);
}
return list;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class AbstractSearchExpressionEvaluator method transformSingleValue.
@Override
protected List<V> transformSingleValue(ExpressionVariables variables, PlusMinusZero valueDestination, boolean useNew, ExpressionEvaluationContext context, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
// if (LOGGER.isTraceEnabled()) {
// LOGGER.trace("transformSingleValue in {}\nvariables:\n{}\nvalueDestination: {}\nuseNew: {}",
// new Object[]{contextDescription, variables.debugDump(1), valueDestination, useNew});
// }
QName targetTypeQName = getExpressionEvaluatorType().getTargetType();
if (targetTypeQName == null) {
targetTypeQName = getDefaultTargetType();
}
if (targetTypeQName != null && QNameUtil.isUnqualified(targetTypeQName)) {
targetTypeQName = getPrismContext().getSchemaRegistry().resolveUnqualifiedTypeName(targetTypeQName);
}
ObjectTypes targetType = ObjectTypes.getObjectTypeFromTypeQName(targetTypeQName);
if (targetType == null) {
throw new SchemaException("Unknown target type " + targetTypeQName + " in " + shortDebugDump());
}
Class<? extends ObjectType> targetTypeClass = targetType.getClassDefinition();
List<V> resultValues = null;
ObjectQuery query = null;
List<ItemDelta<V, D>> additionalAttributeDeltas = null;
PopulateType populateAssignmentType = getExpressionEvaluatorType().getPopulate();
if (populateAssignmentType != null) {
additionalAttributeDeltas = collectAdditionalAttributes(populateAssignmentType, outputDefinition, variables, context, contextDescription, task, result);
}
if (getExpressionEvaluatorType().getOid() != null) {
resultValues = new ArrayList<>(1);
resultValues.add(createPrismValue(getExpressionEvaluatorType().getOid(), targetTypeQName, additionalAttributeDeltas, context));
} else {
SearchFilterType filterType = getExpressionEvaluatorType().getFilter();
if (filterType == null) {
throw new SchemaException("No filter in " + shortDebugDump());
}
query = QueryJaxbConvertor.createObjectQuery(targetTypeClass, filterType, prismContext);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("XML query converted to: {}", query.debugDump());
}
query = ExpressionUtil.evaluateQueryExpressions(query, variables, context.getExpressionFactory(), prismContext, context.getContextDescription(), task, result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Expression in query evaluated to: {}", query.debugDump());
}
query = extendQuery(query, context);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Query after extension: {}", query.debugDump());
}
resultValues = executeSearchUsingCache(targetTypeClass, targetTypeQName, query, additionalAttributeDeltas, context, contextDescription, task, context.getResult());
if (resultValues.isEmpty()) {
ObjectReferenceType defaultTargetRef = getExpressionEvaluatorType().getDefaultTargetRef();
if (defaultTargetRef != null) {
resultValues.add(createPrismValue(defaultTargetRef.getOid(), targetTypeQName, additionalAttributeDeltas, context));
}
}
}
if (resultValues.isEmpty() && getExpressionEvaluatorType().isCreateOnDemand() == Boolean.TRUE && (valueDestination == PlusMinusZero.PLUS || valueDestination == PlusMinusZero.ZERO || useNew)) {
String createdObjectOid = createOnDemand(targetTypeClass, variables, context, context.getContextDescription(), task, context.getResult());
resultValues.add(createPrismValue(createdObjectOid, targetTypeQName, additionalAttributeDeltas, context));
}
LOGGER.trace("Search expression got {} results for query {}", resultValues == null ? "null" : resultValues.size(), query);
return (List<V>) resultValues;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType in project midpoint by Evolveum.
the class ValuePolicyProcessor method validateValue.
public <O extends ObjectType> boolean validateValue(String newValue, ValuePolicyType pp, PrismObject<O> object, StringBuilder message, String shortDesc, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
Validate.notNull(pp, "Value policy must not be null.");
OperationResult result = parentResult.createSubresult(OPERATION_STRING_POLICY_VALIDATION);
result.addParam("policyName", pp.getName());
normalize(pp);
if (newValue == null && (pp.getMinOccurs() == null || XsdTypeMapper.multiplicityToInteger(pp.getMinOccurs()) == 0)) {
// No password is allowed
result.recordSuccess();
return true;
}
if (newValue == null) {
newValue = "";
}
LimitationsType lims = pp.getStringPolicy().getLimitations();
testMinimalLength(newValue, lims, result, message);
testMaximalLength(newValue, lims, result, message);
testMinimalUniqueCharacters(newValue, lims, result, message);
if (lims.getLimit() == null || lims.getLimit().isEmpty()) {
if (message.toString() == null || message.toString().isEmpty()) {
result.computeStatus();
} else {
result.computeStatus(message.toString());
}
return result.isAcceptable();
}
// check limitation
HashSet<String> validChars = null;
HashSet<String> allValidChars = new HashSet<>();
List<String> passwd = StringPolicyUtils.stringTokenizer(newValue);
for (StringLimitType stringLimitationType : lims.getLimit()) {
OperationResult limitResult = new OperationResult("Tested limitation: " + stringLimitationType.getDescription());
validChars = getValidCharacters(stringLimitationType.getCharacterClass(), pp);
int count = countValidCharacters(validChars, passwd);
allValidChars.addAll(validChars);
testMinimalOccurence(stringLimitationType, count, limitResult, message);
testMaximalOccurence(stringLimitationType, count, limitResult, message);
testMustBeFirst(stringLimitationType, count, limitResult, message, newValue, validChars);
limitResult.computeStatus();
result.addSubresult(limitResult);
}
testInvalidCharacters(passwd, allValidChars, result, message);
testCheckExpression(newValue, lims, object, shortDesc, task, result, message);
if (message.toString() == null || message.toString().isEmpty()) {
result.computeStatus();
} else {
result.computeStatus(message.toString());
}
return result.isAcceptable();
}
Aggregations