Search in sources :

Example 31 with CommonException

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();
    }
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 32 with CommonException

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);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) CaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 33 with CommonException

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);
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SystemException(com.evolveum.midpoint.util.exception.SystemException) CommonException(com.evolveum.midpoint.util.exception.CommonException) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Example 34 with CommonException

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());
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceSchemaFactory(com.evolveum.midpoint.schema.processor.ResourceSchemaFactory) com.evolveum.midpoint.web.component.wizard.resource.component.capability(com.evolveum.midpoint.web.component.wizard.resource.component.capability) WebModelServiceUtils(com.evolveum.midpoint.gui.api.util.WebModelServiceUtils) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PageResourceWizard(com.evolveum.midpoint.web.page.admin.resources.PageResourceWizard) IModel(org.apache.wicket.model.IModel) Method(java.lang.reflect.Method) Label(org.apache.wicket.markup.html.basic.Label) IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) Model(org.apache.wicket.model.Model) ResourceTypeUtil(com.evolveum.midpoint.schema.util.ResourceTypeUtil) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) AttributeModifier(org.apache.wicket.AttributeModifier) com.evolveum.midpoint.xml.ns._public.resource.capabilities_3(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3) InvocationTargetException(java.lang.reflect.InvocationTargetException) ModelService(com.evolveum.midpoint.model.api.ModelService) NonEmptyLoadableModel(com.evolveum.midpoint.gui.api.model.NonEmptyLoadableModel) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) PropertyModel(org.apache.wicket.model.PropertyModel) Item(org.apache.wicket.markup.repeater.Item) Type(java.lang.reflect.Type) SystemException(com.evolveum.midpoint.util.exception.SystemException) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) QName(javax.xml.namespace.QName) DataView(org.apache.wicket.markup.repeater.data.DataView) NotNull(org.jetbrains.annotations.NotNull) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) java.util(java.util) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) CapabilityUtil(com.evolveum.midpoint.schema.CapabilityUtil) Capability(com.evolveum.midpoint.web.component.wizard.resource.dto.Capability) CloneUtil(com.evolveum.midpoint.prism.util.CloneUtil) JAXBElement(javax.xml.bind.JAXBElement) WizardStep(com.evolveum.midpoint.web.component.wizard.WizardStep) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow) PrismObject(com.evolveum.midpoint.prism.PrismObject) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) CommonException(com.evolveum.midpoint.util.exception.CommonException) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ParameterizedType(java.lang.reflect.ParameterizedType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) CapabilityCollectionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismObject(com.evolveum.midpoint.prism.PrismObject) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) IModel(org.apache.wicket.model.IModel) QName(javax.xml.namespace.QName) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) NonEmptyLoadableModel(com.evolveum.midpoint.gui.api.model.NonEmptyLoadableModel) PropertyModel(org.apache.wicket.model.PropertyModel) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) NonEmptyLoadableModel(com.evolveum.midpoint.gui.api.model.NonEmptyLoadableModel) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel)

Example 35 with CommonException

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);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) ModelService(com.evolveum.midpoint.model.api.ModelService)

Aggregations

CommonException (com.evolveum.midpoint.util.exception.CommonException)71 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)44 Task (com.evolveum.midpoint.task.api.Task)33 PrismObject (com.evolveum.midpoint.prism.PrismObject)14 SystemException (com.evolveum.midpoint.util.exception.SystemException)14 ArrayList (java.util.ArrayList)12 ModelService (com.evolveum.midpoint.model.api.ModelService)11 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)8 NotNull (org.jetbrains.annotations.NotNull)7 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 ActivityRunException (com.evolveum.midpoint.repo.common.activity.run.ActivityRunException)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 RestartResponseException (org.apache.wicket.RestartResponseException)5 ModelInteractionService (com.evolveum.midpoint.model.api.ModelInteractionService)4 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)4 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)4