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;
}
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;
}
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());
}
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;
}
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);
}
Aggregations