Search in sources :

Example 21 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class UserMenuPanel method loadModel.

private PasswordQuestionsDto loadModel(PageBase parentPage) {
    LOGGER.trace("Loading user for Security Question Page.");
    PasswordQuestionsDto dto = new PasswordQuestionsDto();
    OperationResult result = new OperationResult(OPERATION_LOAD_USER);
    if (parentPage == null) {
        parentPage = ((PageBase) getPage());
    }
    try {
        MidPointPrincipal principal = SecurityUtils.getPrincipalUser();
        if (principal == null) {
            result.recordNotApplicableIfUnknown();
            return null;
        }
        String userOid = principal.getOid();
        Task task = parentPage.createSimpleTask(OPERATION_LOAD_USER);
        OperationResult subResult = result.createSubresult(OPERATION_LOAD_USER);
        Collection options = SelectorOptions.createCollection(UserType.F_JPEG_PHOTO, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
        PrismObject<UserType> user = parentPage.getModelService().getObject(UserType.class, userOid, options, task, subResult);
        userModel.setObject(user);
        jpegPhoto = user == null ? null : (user.asObjectable() == null ? null : user.asObjectable().getJpegPhoto());
        dto.setSecurityAnswers(createUsersSecurityQuestionsList(user));
        subResult.recordSuccessIfUnknown();
    } catch (Exception ex) {
        LoggingUtils.logExceptionOnDebugLevel(LOGGER, "Couldn't get user Questions, Probably not set yet", ex);
    } finally {
        result.recomputeStatus();
        isUserModelLoaded = true;
    }
    return dto;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) PasswordQuestionsDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordQuestionsDto) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 22 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class PageAdminResources method loadResource.

protected PrismObject<ResourceType> loadResource(Collection<SelectorOptions<GetOperationOptions>> options) {
    OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCE);
    PrismObject<ResourceType> resource = null;
    try {
        Task task = createSimpleTask(OPERATION_LOAD_RESOURCE);
        LOGGER.trace("getObject(resource) oid={}, options={}", getResourceOid(), options);
        resource = getModelService().getObject(ResourceType.class, getResourceOid(), options, task, result);
        result.recomputeStatus();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("getObject(resource) result\n:{}", result.debugDump());
        }
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get resource", ex);
        result.recordFatalError("Couldn't get resource, reason: " + ex.getMessage(), ex);
    }
    if (!WebComponentUtil.isSuccessOrHandledError(result)) {
        if (resource != null) {
            showResult(result);
        } else {
            getSession().error(getString("pageAdminResources.message.cantLoadResource"));
            throw new RestartResponseException(PageResources.class);
        }
    }
    return resource;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RestartResponseException(org.apache.wicket.RestartResponseException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 23 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class PageResource method refreshSchemaPerformed.

private void refreshSchemaPerformed(AjaxRequestTarget target) {
    Task task = createSimpleTask(OPERATION_REFRESH_SCHEMA);
    OperationResult parentResult = new OperationResult(OPERATION_REFRESH_SCHEMA);
    try {
        ResourceUtils.deleteSchema(resourceModel.getObject(), getModelService(), getPrismContext(), task, parentResult);
        // try to load fresh scehma
        getModelService().testResource(resourceModel.getObject().getOid(), task);
    } catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Error refreshing resource schema", e);
        parentResult.recordFatalError("Error refreshing resource schema", e);
    }
    parentResult.computeStatus();
    showResult(parentResult, "pageResource.refreshSchema.failed");
    target.add(getFeedbackPanel());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 24 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class Clockwork method triggerReconcileAffected.

private <F extends ObjectType> HookOperationMode triggerReconcileAffected(LensContext<F> context, Task task, OperationResult result) throws SchemaException {
    // check applicability
    if (!ModelExecuteOptions.isReconcileAffected(context.getOptions())) {
        return HookOperationMode.FOREGROUND;
    }
    if (context.getFocusClass() == null || !RoleType.class.isAssignableFrom(context.getFocusClass())) {
        LOGGER.warn("ReconcileAffected requested but not available for {}. Doing nothing.", context.getFocusClass());
        return HookOperationMode.FOREGROUND;
    }
    // check preconditions
    if (context.getFocusContext() == null) {
        throw new IllegalStateException("No focus context when expected it");
    }
    PrismObject<RoleType> role = (PrismObject) context.getFocusContext().getObjectAny();
    if (role == null) {
        throw new IllegalStateException("No role when expected it");
    }
    // preparing the recompute/reconciliation task
    Task reconTask;
    if (task.isPersistent()) {
        reconTask = task.createSubtask();
    } else {
        reconTask = task;
    }
    assert !reconTask.isPersistent();
    // creating object query
    PrismPropertyDefinition propertyDef = prismContext.getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY);
    PrismReferenceValue referenceValue = new PrismReferenceValue(context.getFocusContext().getOid(), RoleType.COMPLEX_TYPE);
    ObjectFilter refFilter = QueryBuilder.queryFor(FocusType.class, prismContext).item(FocusType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(referenceValue).buildFilter();
    SearchFilterType filterType = QueryConvertor.createSearchFilterType(refFilter, prismContext);
    QueryType queryType = new QueryType();
    queryType.setFilter(filterType);
    PrismProperty<QueryType> property = propertyDef.instantiate();
    property.setRealValue(queryType);
    reconTask.addExtensionProperty(property);
    // other parameters
    reconTask.setName("Recomputing users after changing role " + role.asObjectable().getName());
    reconTask.setBinding(TaskBinding.LOOSE);
    reconTask.setInitialExecutionStatus(TaskExecutionStatus.RUNNABLE);
    reconTask.setHandlerUri(RecomputeTaskHandler.HANDLER_URI);
    reconTask.setCategory(TaskCategory.RECOMPUTATION);
    taskManager.switchToBackground(reconTask, result);
    result.setBackgroundTaskOid(reconTask.getOid());
    result.recordStatus(OperationResultStatus.IN_PROGRESS, "Reconciliation task switched to background");
    return HookOperationMode.BACKGROUND;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 25 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class PageTasks method deleteNodesPerformed.

private void deleteNodesPerformed(AjaxRequestTarget target, List<NodeDto> nodes) {
    OperationResult result = new OperationResult(OPERATION_DELETE_NODES);
    Task task = createSimpleTask(OPERATION_DELETE_NODES);
    for (NodeDto nodeDto : nodes) {
        Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
        deltas.add(ObjectDelta.createDeleteDelta(NodeType.class, nodeDto.getOid(), getPrismContext()));
        try {
            getModelService().executeChanges(deltas, null, task, result);
        } catch (Exception e) {
            // until java 7 we do it in this way
            result.recordFatalError("Couldn't delete the node " + nodeDto.getNodeIdentifier(), e);
        }
    }
    result.computeStatus();
    if (result.isSuccess()) {
        result.recordStatus(OperationResultStatus.SUCCESS, "Selected node(s) have been successfully deleted.");
    }
    showResult(result);
    NodeDtoProvider provider = (NodeDtoProvider) getNodeTable().getDataTable().getDataProvider();
    provider.clearCache();
    //refresh feedback and table
    refreshTables(target);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException)

Aggregations

Task (com.evolveum.midpoint.task.api.Task)4943 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4698 Test (org.testng.annotations.Test)3991 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)599 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)542 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)464 PrismObject (com.evolveum.midpoint.prism.PrismObject)327 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)323 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)290 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)282 ArrayList (java.util.ArrayList)249 QName (javax.xml.namespace.QName)208 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)199 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)193 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)175 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)159 AbstractConfiguredModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)140 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)123 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)108 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)108