use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class ResourceContentRepositoryPanel method createTotalsModel.
private LoadableModel<Integer> createTotalsModel(final SynchronizationSituationType situation) {
return new LoadableModel<Integer>(false) {
private static final long serialVersionUID = 1L;
@Override
protected Integer load() {
PrismContext prismContext = getPageBase().getPrismContext();
ObjectFilter resourceFilter = prismContext.queryFor(ShadowType.class).item(ShadowType.F_RESOURCE_REF).ref(ResourceContentRepositoryPanel.this.getResourceModel().getObject().getOid()).buildFilter();
if (resourceFilter == null) {
return 0;
}
ObjectFilter filter = createQuery().getFilter();
if (filter == null) {
return 0;
}
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
Task task = getPageBase().createSimpleTask(OPERATION_GET_TOTALS);
OperationResult result = new OperationResult(OPERATION_GET_TOTALS);
try {
ObjectFilter situationFilter = prismContext.queryFor(ShadowType.class).item(ShadowType.F_SYNCHRONIZATION_SITUATION).eq(situation).buildFilter();
ObjectQuery query = prismContext.queryFactory().createQuery(prismContext.queryFactory().createAnd(filter, situationFilter));
return getPageBase().getModelService().countObjects(ShadowType.class, query, options, task, result);
} catch (CommonException | RuntimeException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't count shadows", ex);
}
return 0;
}
};
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class RepoObjectResolver method resolve.
@Override
public <O extends ObjectType> O resolve(ObjectReferenceType ref, Class<O> expectedType, Collection<SelectorOptions<GetOperationOptions>> options, String contextDescription, Object task, OperationResult result) throws ObjectNotFoundException, SchemaException {
String oid = ref.getOid();
Class<?> typeClass = null;
QName typeQName = ref.getType();
if (typeQName != null) {
typeClass = prismContext.getSchemaRegistry().determineCompileTimeClass(typeQName);
}
if (typeClass != null && expectedType.isAssignableFrom(typeClass)) {
expectedType = (Class<O>) typeClass;
}
try {
return cacheRepositoryService.getObject(expectedType, oid, options, result).asObjectable();
} catch (SystemException ex) {
throw ex;
} catch (ObjectNotFoundException ex) {
throw ex;
} catch (CommonException ex) {
throw new SystemException("Error resolving object with oid '" + oid + "': " + ex.getMessage(), ex);
}
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class ModelObjectResolver method resolve.
@Override
public <O extends ObjectType> O resolve(ObjectReferenceType ref, Class<O> expectedType, Collection<SelectorOptions<GetOperationOptions>> options, String contextDescription, Object task, OperationResult result) throws ObjectNotFoundException, SchemaException {
String oid = ref.getOid();
Class<?> typeClass = null;
QName typeQName = ref.getType();
if (typeQName != null) {
typeClass = prismContext.getSchemaRegistry().determineCompileTimeClass(typeQName);
}
if (typeClass != null && expectedType.isAssignableFrom(typeClass)) {
expectedType = (Class<O>) typeClass;
}
try {
return getObject(expectedType, oid, options, (Task) task, result);
} catch (SystemException ex) {
throw ex;
} catch (ObjectNotFoundException ex) {
throw ex;
} catch (CommonException ex) {
LoggingUtils.logException(LOGGER, "Error resolving object with oid {}", ex, oid);
// Add to result only a short version of the error, the details will be in subresults
result.recordFatalError("Couldn't get object with oid '" + oid + "': " + ex.getOperationResultMessage(), ex);
throw new SystemException("Error resolving object with oid '" + oid + "': " + ex.getMessage(), ex);
}
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class MappingEvaluator method createFocusMapping.
public <V extends PrismValue, D extends ItemDefinition, F extends FocusType, T extends FocusType> Mapping<V, D> createFocusMapping(final MappingFactory mappingFactory, final LensContext<F> context, final MappingType mappingType, ObjectType originObject, ObjectDeltaObject<F> focusOdo, PrismObject<T> defaultTargetObject, AssignmentPathVariables assignmentPathVariables, Integer iteration, String iterationToken, PrismObject<SystemConfigurationType> configuration, XMLGregorianCalendar now, String contextDesc, final Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
if (!Mapping.isApplicableToChannel(mappingType, context.getChannel())) {
LOGGER.trace("Mapping {} not applicable to channel {}, skipping.", mappingType, context.getChannel());
return null;
}
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() {
// TODO need to switch to ObjectValuePolicyEvaluator
if (outputDefinition.getName().equals(PasswordType.F_VALUE)) {
ValuePolicyType passwordPolicy = credentialsProcessor.determinePasswordPolicy(context.getFocusContext(), task, result);
if (passwordPolicy == null) {
return null;
}
return passwordPolicy.getStringPolicy();
}
if (mappingType.getExpression() != null) {
List<JAXBElement<?>> evaluators = mappingType.getExpression().getExpressionEvaluator();
if (evaluators != null) {
for (JAXBElement jaxbEvaluator : evaluators) {
Object object = jaxbEvaluator.getValue();
if (object instanceof GenerateExpressionEvaluatorType && ((GenerateExpressionEvaluatorType) object).getValuePolicyRef() != null) {
ObjectReferenceType ref = ((GenerateExpressionEvaluatorType) object).getValuePolicyRef();
try {
ValuePolicyType valuePolicyType = mappingFactory.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;
}
};
ExpressionVariables variables = new ExpressionVariables();
FOCUS_VARIABLE_NAMES.forEach(name -> variables.addVariableDefinition(name, focusOdo));
variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION, iteration);
variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION_TOKEN, iterationToken);
variables.addVariableDefinition(ExpressionConstants.VAR_CONFIGURATION, configuration);
Collection<V> targetValues = computeTargetValues(mappingType.getTarget(), defaultTargetObject, variables, mappingFactory.getObjectResolver(), contextDesc, task, result);
Mapping.Builder<V, D> mappingBuilder = mappingFactory.<V, D>createMappingBuilder(mappingType, contextDesc).sourceContext(focusOdo).targetContext(defaultTargetObject.getDefinition()).variables(variables).originalTargetValues(targetValues).originType(OriginType.USER_POLICY).originObject(originObject).stringPolicyResolver(stringPolicyResolver).rootNode(focusOdo).now(now);
mappingBuilder = LensUtil.addAssignmentPathVariables(mappingBuilder, assignmentPathVariables);
Mapping<V, D> mapping = mappingBuilder.build();
ItemPath itemPath = mapping.getOutputPath();
if (itemPath == null) {
// no output element, i.e. this is a "validation mapping"
return mapping;
}
if (defaultTargetObject != null) {
Item<V, D> existingTargetItem = (Item<V, D>) defaultTargetObject.findItem(itemPath);
if (existingTargetItem != null && !existingTargetItem.isEmpty() && mapping.getStrength() == MappingStrengthType.WEAK) {
LOGGER.trace("Mapping {} is weak and target already has a value {}, skipping.", mapping, existingTargetItem);
return null;
}
}
return mapping;
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class PageAccounts method createTotalsModel.
private LoadableModel<Integer> createTotalsModel(final SynchronizationSituationType situation) {
return new LoadableModel<Integer>(false) {
@Override
protected Integer load() {
ObjectFilter resourceFilter = createResourceQueryFilter();
if (resourceFilter == null) {
return 0;
}
ObjectFilter filter = createObjectQuery().getFilter();
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
Task task = createSimpleTask(OPERATION_GET_TOTALS);
OperationResult result = new OperationResult(OPERATION_GET_TOTALS);
try {
ObjectFilter situationFilter = QueryBuilder.queryFor(ShadowType.class, getPrismContext()).item(ShadowType.F_SYNCHRONIZATION_SITUATION).eq(situation).buildFilter();
ObjectQuery query = ObjectQuery.createObjectQuery(AndFilter.createAnd(filter, situationFilter));
return getModelService().countObjects(ShadowType.class, query, options, task, result);
} catch (CommonException | RuntimeException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't count shadows", ex);
}
return 0;
}
};
}
Aggregations