Search in sources :

Example 16 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class PageUsers method deleteConfirmedPerformed.

private void deleteConfirmedPerformed(AjaxRequestTarget target, UserType userToDelete) {
    List<UserType> users = isAnythingSelected(target, userToDelete);
    if (users.isEmpty()) {
        return;
    }
    OperationResult result = new OperationResult(OPERATION_DELETE_USERS);
    for (UserType user : users) {
        OperationResult subResult = result.createSubresult(OPERATION_DELETE_USER);
        try {
            Task task = createSimpleTask(OPERATION_DELETE_USER);
            ObjectDelta delta = new ObjectDelta(UserType.class, ChangeType.DELETE, getPrismContext());
            delta.setOid(user.getOid());
            ExecuteChangeOptionsDto executeOptions = executeOptionsModel.getObject();
            ModelExecuteOptions options = executeOptions.createOptions();
            LOGGER.debug("Using options {}.", new Object[] { executeOptions });
            getModelService().executeChanges(WebComponentUtil.createDeltaCollection(delta), options, task, subResult);
            subResult.computeStatus();
        } catch (Exception ex) {
            subResult.recomputeStatus();
            subResult.recordFatalError("Couldn't delete user.", ex);
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete user", ex);
        }
    }
    result.computeStatusComposite();
    getTable().clearCache();
    showResult(result);
    target.add(getFeedbackPanel());
    getTable().refreshTable(UserType.class, target);
    getTable().clearCache();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExecuteChangeOptionsDto(com.evolveum.midpoint.web.page.admin.users.component.ExecuteChangeOptionsDto) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 17 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class PageUsers method unlockPerformed.

private void unlockPerformed(AjaxRequestTarget target, UserType selectedUser) {
    List<UserType> users = isAnythingSelected(target, selectedUser);
    if (users.isEmpty()) {
        return;
    }
    OperationResult result = new OperationResult(OPERATION_UNLOCK_USERS);
    for (UserType user : users) {
        OperationResult opResult = result.createSubresult(getString(OPERATION_UNLOCK_USER, user));
        try {
            Task task = createSimpleTask(OPERATION_UNLOCK_USER + user);
            // TODO skip the operation if the user has no password
            // credentials specified (otherwise this would create
            // almost-empty password container)
            ObjectDelta delta = ObjectDelta.createModificationReplaceProperty(UserType.class, user.getOid(), new ItemPath(UserType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS), getPrismContext(), LockoutStatusType.NORMAL);
            Collection<ObjectDelta<? extends ObjectType>> deltas = WebComponentUtil.createDeltaCollection(delta);
            getModelService().executeChanges(deltas, null, task, opResult);
            opResult.computeStatusIfUnknown();
        } catch (Exception ex) {
            opResult.recomputeStatus();
            opResult.recordFatalError("Couldn't unlock user " + user + ".", ex);
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't unlock user " + user + ".", ex);
        }
    }
    result.recomputeStatus();
    showResult(result);
    target.add(getFeedbackPanel());
    getTable().refreshTable(UserType.class, target);
    getTable().clearCache();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 18 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class MergeObjectsPanel method getMergeTypeNames.

private List<String> getMergeTypeNames() {
    List<String> mergeTypeNamesList = new ArrayList<>();
    Task task = pageBase.createAnonymousTask(OPERATION_LOAD_MERGE_TYPE_NAMES);
    OperationResult result = task.getResult();
    PrismObject<SystemConfigurationType> config;
    try {
        config = pageBase.getModelService().getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, task, result);
    } catch (ObjectNotFoundException | SchemaException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        LOGGER.error("Error getting system configuration: {}", e.getMessage(), e);
        return null;
    }
    if (config != null && config.asObjectable() != null) {
        List<MergeConfigurationType> list = config.asObjectable().getMergeConfiguration();
        if (list != null) {
            for (MergeConfigurationType mergeType : list) {
                mergeTypeNamesList.add(mergeType.getName());
            }
            if (mergeTypeNamesList.size() > 0) {
                currentMergeType = mergeTypeNamesList.get(0);
            }
        }
    }
    return mergeTypeNamesList;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MergeConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)

Example 19 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class MergeObjectsPanel method getMergeObjectsResult.

private PrismObject<F> getMergeObjectsResult() {
    OperationResult result = new OperationResult(OPERATION_GET_MERGE_OBJECT_PREVIEW);
    PrismObject<F> mergeResultObject = null;
    try {
        Task task = pageBase.createSimpleTask(OPERATION_GET_MERGE_OBJECT_PREVIEW);
        mergeResultObject = pageBase.getModelInteractionService().mergeObjectsPreviewObject(type, mergeObjectModel.getObject().getOid(), mergeWithObjectModel.getObject().getOid(), currentMergeType, task, result);
        mergeDeltas = pageBase.getModelInteractionService().mergeObjectsPreviewDeltas(type, mergeObjectModel.getObject().getOid(), mergeWithObjectModel.getObject().getOid(), currentMergeType, task, result);
    } catch (Exception ex) {
        result.recomputeStatus();
        result.recordFatalError("Couldn't get merge object for preview.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get merge object for preview", ex);
        pageBase.showResult(result);
    }
    return mergeResultObject;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 20 with OperationResult

use of com.evolveum.midpoint.schema.result.OperationResult in project midpoint by Evolveum.

the class AccessCertificationCampaignCreationTaskHandler method run.

@Override
public TaskRunResult run(Task task) {
    LOGGER.trace("Task run starting");
    long progress = task.getProgress();
    OperationResult opResult = new OperationResult(CLASS_DOT + "run");
    opResult.setSummarizeSuccesses(true);
    TaskRunResult runResult = new TaskRunResult();
    runResult.setOperationResult(opResult);
    String definitionOid = task.getObjectOid();
    if (definitionOid == null) {
        LOGGER.error("No definition OID specified in the task");
        opResult.recordFatalError("No definition OID specified in the task");
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    opResult.addContext("definitionOid", definitionOid);
    long started = 0;
    String campaignName = null;
    String campaignOid = null;
    try {
        task.startCollectingOperationStatsFromStoredValues(true, false, false);
        LOGGER.info("Creating campaign with definition of {}", definitionOid);
        AccessCertificationCampaignType campaign = certificationManager.createCampaign(definitionOid, task, opResult);
        LOGGER.info("Campaign {} was created.", ObjectTypeUtil.toShortString(campaign));
        // TODO split this try-catch to two pieces in order to correctly work with iterative op failure recording
        started = System.currentTimeMillis();
        campaignName = campaign.getName().getOrig();
        campaignOid = campaign.getOid();
        task.recordIterativeOperationStart(campaignName, campaignName, AccessCertificationCampaignType.COMPLEX_TYPE, campaignOid);
        certificationManager.openNextStage(campaign.getOid(), 1, task, opResult);
        LOGGER.info("Campaign {} was started.", ObjectTypeUtil.toShortString(campaign));
        task.recordIterativeOperationEnd(campaignName, campaignName, AccessCertificationCampaignType.COMPLEX_TYPE, campaignOid, started, null);
        opResult.computeStatus();
        runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
        runResult.setProgress(progress + 1);
        return runResult;
    } catch (Exception e) {
        // TODO better error handling
        if (campaignOid != null) {
            task.recordIterativeOperationEnd(campaignName, campaignName, AccessCertificationCampaignType.COMPLEX_TYPE, campaignOid, started, e);
        }
        LoggingUtils.logException(LOGGER, "Error while executing 'create campaign' task handler", e);
        opResult.recordFatalError("Error while executing 'create campaign' task handler: " + e.getMessage(), e);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        runResult.setProgress(progress);
        return runResult;
    } finally {
        task.storeOperationStats();
    }
}
Also used : TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3475 Test (org.testng.annotations.Test)2435 Task (com.evolveum.midpoint.task.api.Task)2390 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1059 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)725 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)637 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)414 PrismObject (com.evolveum.midpoint.prism.PrismObject)388 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)376 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)320 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)288 ArrayList (java.util.ArrayList)262 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)252 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)250 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)231 QName (javax.xml.namespace.QName)198 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)197 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)182 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)171 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)149