use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class PerformerCommentsFormatterImpl method formatComment.
private String formatComment(ObjectReferenceType performerRef, AbstractWorkItemOutputType output, AbstractWorkItemType workItem, WorkItemCompletionEventType event, Task task, OperationResult result) {
if (formatting == null || formatting.getCondition() == null && formatting.getValue() == null) {
return output.getComment();
}
ObjectType performer = getPerformer(performerRef, result);
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_PERFORMER, performer, performer.asPrismObject().getDefinition());
variables.put(ExpressionConstants.VAR_OUTPUT, output, AbstractWorkItemOutputType.class);
variables.put(ExpressionConstants.VAR_WORK_ITEM, workItem, AbstractWorkItemType.class);
variables.put(ExpressionConstants.VAR_EVENT, event, WorkItemCompletionEventType.class);
if (formatting.getCondition() != null) {
try {
boolean condition = expressionEvaluationHelper.evaluateBooleanExpression(formatting.getCondition(), variables, "condition in performer comments formatter", task, result);
if (!condition) {
return null;
}
} catch (CommonException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't evaluate condition expression in comments formatter - continuing as if it were true; " + "performer = {}, output = {}, workItem = {}, event = {}", e, performer, output, workItem, event);
}
}
if (formatting.getValue() != null) {
try {
return expressionEvaluationHelper.evaluateStringExpression(formatting.getValue(), variables, "value in performer comments formatter", task, result);
} catch (CommonException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't evaluate value expression in comments formatter - using plain comment value; " + "performer = {}, output = {}, workItem = {}, event = {}", e, performer, output, workItem, event);
return output.getComment();
}
} else {
return output.getComment();
}
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class CaseCleaner method deleteCaseWithChildren.
/**
* Assuming that the case is not indestructible. Unlike in tasks, here the indestructible children do not
* prevent the root nor their siblings from deletion.
*/
private void deleteCaseWithChildren(PrismObject<CaseType> parentCase, DeletionCounters counters, Task task, OperationResult result) {
// get all children cases
ObjectQuery childrenCasesQuery = prismContext.queryFor(CaseType.class).item(CaseType.F_PARENT_REF).ref(parentCase.getOid()).build();
List<PrismObject<CaseType>> childrenCases;
try {
childrenCases = modelService.searchObjects(CaseType.class, childrenCasesQuery, null, task, result);
} catch (CommonException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't look for children of {} - continuing", e, parentCase);
counters.problems++;
return;
}
LOGGER.trace("Removing case {} along with its {} children.", parentCase, childrenCases.size());
for (PrismObject<CaseType> caseToDelete : childrenCases) {
if (ObjectTypeUtil.isIndestructible(caseToDelete)) {
LOGGER.trace("Not deleting sub-case {} as it is indestructible", caseToDelete);
} else {
deleteCaseWithChildren(caseToDelete, counters, task, result);
}
}
deleteCase(parentCase, counters, task, result);
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class AccessCertificationCampaignReiterationTriggerHandler method handle.
@Override
public <O extends ObjectType> void handle(@NotNull PrismObject<O> prismObject, @NotNull TriggerType trigger, @NotNull RunningTask task, @NotNull OperationResult result) {
try {
ObjectType object = prismObject.asObjectable();
if (!(object instanceof AccessCertificationCampaignType)) {
LOGGER.error("Trigger of this type is supported only on {} objects, not on {}", AccessCertificationCampaignType.class.getSimpleName(), object.getClass().getName());
return;
}
AccessCertificationCampaignType campaign = (AccessCertificationCampaignType) object;
LOGGER.info("Automatically reiterating {}", ObjectTypeUtil.toShortString(campaign));
if (CertCampaignTypeUtil.isReiterable(campaign)) {
certificationManager.reiterateCampaign(campaign.getOid(), task, result);
certificationManager.openNextStage(campaign.getOid(), task, result);
} else {
LOGGER.warn("Campaign {} is not reiterable, exiting.", ObjectTypeUtil.toShortString(campaign));
}
} catch (CommonException | RuntimeException e) {
String message = "Couldn't reiterate the campaign and possibly advance to the next one";
LoggingUtils.logUnexpectedException(LOGGER, message, e);
throw new SystemException(message + ": " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class CapabilityStep method editCapabilityPerformed.
@SuppressWarnings("unchecked")
private void editCapabilityPerformed(final AjaxRequestTarget target, CapabilityDto<? extends CapabilityType> capability) {
dtoModel.getObject().setSelected(capability);
WebMarkupContainer config = getConfigContainer();
WebMarkupContainer newConfig;
CapabilityType capType = capability.getCapability();
if (capType instanceof ActivationCapabilityType) {
newConfig = new CapabilityActivationPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<ActivationCapabilityType>) capability), parentPage) {
@Override
public IModel<List<QName>> createAttributeChoiceModel(final IChoiceRenderer<QName> renderer) {
LoadableModel<List<QName>> attributeChoiceModel = new LoadableModel<List<QName>>(false) {
@Override
protected List<QName> load() {
List<QName> choices = new ArrayList<>();
PrismObject<ResourceType> resourcePrism = resourceModel.getObject();
try {
ResourceSchema schema = ResourceSchemaFactory.getCompleteSchema(resourcePrism);
if (schema != null) {
// TODO is this OK?
ResourceObjectTypeDefinition def = schema.findDefaultOrAnyObjectTypeDefinition(ShadowKindType.ACCOUNT);
if (def != null) {
for (ResourceAttributeDefinition<?> attribute : def.getAttributeDefinitions()) {
choices.add(attribute.getItemName());
}
}
}
} catch (CommonException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load resource schema attributes.", e);
getPageBase().error("Couldn't load resource schema attributes" + e);
}
choices.sort((o1, o2) -> {
String s1 = (String) renderer.getDisplayValue(o1);
String s2 = (String) renderer.getDisplayValue(o2);
return String.CASE_INSENSITIVE_ORDER.compare(s1, s2);
});
return choices;
}
};
parentPage.registerDependentModel(attributeChoiceModel);
return attributeChoiceModel;
}
};
} else if (capType instanceof ScriptCapabilityType) {
newConfig = new CapabilityScriptPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<ScriptCapabilityType>) capability), getTable(), parentPage);
} else if (capType instanceof CredentialsCapabilityType) {
newConfig = new CapabilityCredentialsPanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<CredentialsCapabilityType>) capability), getTable(), parentPage);
} else {
newConfig = new CapabilityValuePanel(ID_CAPABILITY_CONFIG, new Model<>((CapabilityDto<CapabilityType>) capability), getTable(), parentPage);
}
// TODO other specific capabilities (paged, count, ...)
newConfig.setOutputMarkupId(true);
config.replaceWith(newConfig);
target.add(newConfig);
target.add(getTable());
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class NameStep method discoverConnectors.
private void discoverConnectors(ConnectorHostType host) {
PageBase page = (PageBase) getPage();
Task task = page.createSimpleTask(OPERATION_DISCOVER_CONNECTORS);
OperationResult result = task.getResult();
try {
ModelService model = page.getModelService();
model.discoverConnectors(host, task, result);
} catch (CommonException | RuntimeException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't discover connectors", ex);
} finally {
result.recomputeStatus();
}
if (WebComponentUtil.showResultInPage(result)) {
page.showResult(result);
}
}
Aggregations