Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Feb 24, 2021
2 parents 3f7502f + 83efabf commit 01b4080
Show file tree
Hide file tree
Showing 314 changed files with 10,609 additions and 9,826 deletions.
Expand Up @@ -635,7 +635,8 @@ public static TaskType createSingleRecurrenceTask(String taskName, QName applica

task.setBinding(TaskBindingType.LOOSE);
task.setCategory(category);
task.setExecutionStatus(TaskExecutionStatusType.RUNNABLE);
task.setExecutionStatus(TaskExecutionStateType.RUNNABLE);
task.setSchedulingState(TaskSchedulingStateType.READY);
task.setRecurrence(TaskRecurrenceType.SINGLE);
task.setThreadStopAction(ThreadStopActionType.RESTART);
task.setHandlerUri(pageBase.getTaskService().getHandlerUriForCategory(category));
Expand Down Expand Up @@ -667,46 +668,52 @@ public static TaskType createSingleRecurrenceTask(String taskName, QName applica

public static boolean canSuspendTask(TaskType task, PageBase pageBase) {
return pageBase.isAuthorized(ModelAuthorizationAction.SUSPEND_TASK, task.asPrismObject())
&& (isRunnableTask(task) || isRunningTask(task) || isWaitingTask(task))
&& !isWorkflowTask(task);
&& (isRunnableTask(task) || isRunningTask(task) || isWaitingTask(task));
}

public static boolean canResumeTask(TaskType task, PageBase pageBase) {
return pageBase.isAuthorized(ModelAuthorizationAction.RESUME_TASK, task.asPrismObject())
&& (isSuspendedTask(task) || (isClosedTask(task) && isRecurringTask(task)))
&& !isWorkflowTask(task);
&& (isSuspendedTask(task) || (isClosedTask(task) && isRecurringTask(task)));
}

public static boolean canRunNowTask(TaskType task, PageBase pageBase) {
return pageBase.isAuthorized(ModelAuthorizationAction.RUN_TASK_IMMEDIATELY, task.asPrismObject())
&& !isRunningTask(task) && (isRunnableTask(task) || (isClosedTask(task) && !isRecurringTask(task)))
&& !isWorkflowTask(task);
&& !isRunningTask(task) && (isRunnableTask(task) || (isClosedTask(task) && !isRecurringTask(task)));
}

/** Checks user-visible state, not the technical (scheduling) state. So RUNNABLE means the task is not actually running. */
public static boolean isRunnableTask(TaskType task) {
return task != null && TaskExecutionStatusType.RUNNABLE == task.getExecutionStatus();
return task != null && TaskExecutionStateType.RUNNABLE == task.getExecutionStatus();
}

// Or we can test execution state for RUNNING value.
public static boolean isRunningTask(TaskType task) {
return task != null && task.getNodeAsObserved() != null;
}

/** Checks user-visible state, not the technical (scheduling) state. */
public static boolean isWaitingTask(TaskType task) {
return task != null && TaskExecutionStatusType.WAITING == task.getExecutionStatus();
return task != null && TaskExecutionStateType.WAITING == task.getExecutionStatus();
}

/** Checks user-visible state, not the technical (scheduling) state. */
public static boolean isSuspendedTask(TaskType task) {
return task != null && TaskExecutionStatusType.SUSPENDED == task.getExecutionStatus();
return task != null && TaskExecutionStateType.SUSPENDED == task.getExecutionStatus();
}

/** Checks user-visible state, not the technical (scheduling) state. But for closed tasks, these are equivalent. */
public static boolean isClosedTask(TaskType task) {
return task != null && TaskExecutionStatusType.CLOSED == task.getExecutionStatus();
return task != null && TaskExecutionStateType.CLOSED == task.getExecutionStatus();
}

public static boolean isRecurringTask(TaskType task) {
return task != null && TaskRecurrenceType.RECURRING == task.getRecurrence();
}

// We no longer need to treat workflow-related tasks in a different way.
// Approvals are carried out via cases. So the only workflow-related tasks are those that execute
// approved operations. And they can be treated exactly like all the other tasks.
@Deprecated
public static boolean isWorkflowTask(TaskType task) {
return task != null && TaskCategory.WORKFLOW.equals(task.getCategory());
}
Expand Down
Expand Up @@ -295,8 +295,9 @@ public static <T extends ObjectType> PrismObject<T> loadObject(Class<T> type, St
// point to an object that the current user cannot read. This is no big deal.
// Just do not display that object.
subResult.recordHandledError(e);
PrismObject<? extends FocusType> taskOwner = task.getOwner(result);
LOGGER.debug("User {} is not authorized to read {} {}",
task.getOwner() != null ? task.getOwner().getName() : null, type.getSimpleName(), oid);
taskOwner != null ? taskOwner.getName() : null, type.getSimpleName(), oid);
return null;
} catch (ObjectNotFoundException e) {
if (allowNotFound) {
Expand Down
Expand Up @@ -162,7 +162,7 @@ protected boolean isActivationVisible() {
return true;
}

public static void addSummaryPanel(MarkupContainer parentComponent, PrismObject<FocusType> focus, PrismObjectWrapper<FocusType> focusWrapper, String id, ModelServiceLocator serviceLocator) {
public static void addSummaryPanel(MarkupContainer parentComponent, PrismObject<FocusType> focus, String id, ModelServiceLocator serviceLocator) {
if (focus.getCompileTimeClass().equals(UserType.class)) {
parentComponent.add(new UserSummaryPanel(id,
Model.of((UserType) focus.asObjectable()), serviceLocator));
Expand Down
Expand Up @@ -23,17 +23,18 @@
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.prism.ItemStatus;
import com.evolveum.midpoint.gui.api.prism.wrapper.*;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.ShadowWrapper;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.model.api.ModelAuthorizationAction;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.Referencable;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.form.MidpointForm;
Expand Down Expand Up @@ -189,18 +190,19 @@ public WebMarkupContainer createPanel(String panelId) {

@Override
public String getCount() {
try {
PrismReferenceWrapper<Referencable> link = getObjectWrapper().findReference(FocusType.F_LINK_REF);
if (link == null) {
return "0";
}
if (projectionModel.isLoaded()) {
List<ShadowWrapper> shadowWrappers = projectionModel.getObject();
return shadowWrappers == null ? "0" : Integer.toString(shadowWrappers.size());

}

return Integer.toString(link.getValues().size());
} catch (SchemaException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Problem while getting link refs, {}", e, e.getMessage());
PrismObject<F> object = getObject();
if (object == null) {
return "0";
}

return Integer.toString(object.asObjectable().getLinkRef().size());

}
});

Expand Down
Expand Up @@ -28,7 +28,6 @@
import com.evolveum.midpoint.security.api.SecurityContextManager;
import com.evolveum.midpoint.security.api.SecurityUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskExecutionStatus;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
Expand Down Expand Up @@ -455,7 +454,7 @@ public void executeChangesInBackground(Collection<ObjectDelta<? extends ObjectTy
task.setChannel(SchemaConstants.CHANNEL_USER_URI);
task.setHandlerUri(ModelPublicConstants.EXECUTE_DELTAS_TASK_HANDLER_URI);
task.setName("Execute changes");
task.setInitialExecutionStatus(TaskExecutionStatus.RUNNABLE);
task.setInitiallyRunnable();

PrismObject<TaskType> taskType = task.getUpdatedTaskObject();
AssignmentType archetypeAssignment = new AssignmentType();
Expand Down
Expand Up @@ -787,7 +787,8 @@ private void loadParentOrgs(PrismObject<O> object) {
// the permission to read target org
// It is OK to just ignore it.
subResult.muteLastSubresultError();
LOGGER.debug("User {} does not have permission to read parent org unit {} (ignoring error)", task.getOwner().getName(), parentOrgRef.getOid());
PrismObject<? extends FocusType> taskOwner = task.getOwner(subResult);
LOGGER.debug("User {} does not have permission to read parent org unit {} (ignoring error)", taskOwner.getName(), parentOrgRef.getOid());
} catch (Exception ex) {
subResult.recordWarning(createStringResource("PageAdminObjectDetails.message.loadParentOrgs.warning", parentOrgRef.getOid()).getString(), ex);
LOGGER.warn("Cannot load parent org {}: {}", parentOrgRef.getOid(), ex.getMessage(), ex);
Expand Down
Expand Up @@ -110,7 +110,7 @@ private Component createResourceInfoBoxPanel(OperationResult result, Task task)

private Component createTaskInfoBoxPanel(OperationResult result, Task task) {
return new BasicInfoBoxPanel(ID_INFO_BOX_TASKS, getObjectInfoBoxTypeModel(TaskType.class,
Arrays.asList(TaskType.F_EXECUTION_STATUS), TaskExecutionStatusType.RUNNABLE, "object-task-bg",
Arrays.asList(TaskType.F_EXECUTION_STATUS), TaskExecutionStateType.RUNNABLE, "object-task-bg",
GuiStyleConstants.CLASS_OBJECT_TASK_ICON, "PageDashboard.infobox.tasks", result, task),
PageTasks.class);
}
Expand Down
Expand Up @@ -33,8 +33,6 @@
import com.evolveum.midpoint.security.api.MidPointPrincipal;
import com.evolveum.midpoint.security.enforcer.api.AuthorizationParameters;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskBinding;
import com.evolveum.midpoint.task.api.TaskExecutionStatus;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand Down Expand Up @@ -387,8 +385,7 @@ private static void createTask(Task operationalTask, QName type, ObjectQuery mem
MidPointPrincipal owner = SecurityUtils.getPrincipalUser();
operationalTask.setOwner(owner.getFocus().asPrismObject());

operationalTask.setBinding(TaskBinding.LOOSE);
operationalTask.setInitialExecutionStatus(TaskExecutionStatus.RUNNABLE);
operationalTask.setInitiallyRunnable();
operationalTask.setThreadStopAction(ThreadStopActionType.RESTART);
ScheduleType schedule = new ScheduleType();
schedule.setMisfireAction(MisfireActionType.EXECUTE_IMMEDIATELY);
Expand Down
Expand Up @@ -119,7 +119,7 @@ private List<IColumn<SelectableBean<NodeType>, String>> initNodeColumns() {
List<IColumn<SelectableBean<NodeType>, String>> columns = new ArrayList<>();

columns.add(new EnumPropertyColumn<SelectableBean<NodeType>>(createStringResource("pageTasks.node.executionStatus"),
SelectableBeanImpl.F_VALUE + "." + NodeType.F_EXECUTION_STATUS) {
SelectableBeanImpl.F_VALUE + "." + NodeType.F_EXECUTION_STATE) {

@SuppressWarnings("rawtypes")
@Override
Expand Down Expand Up @@ -186,9 +186,9 @@ public void populateItem(Item<ICellPopulator<SelectableBean<NodeType>>> item, St
if (node.getConnectionResult() != null && node.getConnectionResult().getStatus() != OperationResultStatusType.SUCCESS &&
StringUtils.isNotEmpty(node.getConnectionResult().getMessage())) {
statusMessage = node.getConnectionResult().getMessage();
} else if (node.getErrorStatus() != null && node.getErrorStatus() != NodeErrorStatusType.OK) {
statusMessage = node.getErrorStatus().toString(); // TODO: explain and localize this
} else if (node.getExecutionStatus() == NodeExecutionStatusType.ERROR) { // error status not specified
} else if (node.getErrorState() != null && node.getErrorState() != NodeErrorStateType.OK) {
statusMessage = node.getErrorState().toString(); // TODO: explain and localize this
} else if (node.getExecutionState() == NodeExecutionStateType.ERROR) { // error status not specified
statusMessage = "Unspecified error (or the node is just starting or shutting down)";
} else {
statusMessage = "";
Expand Down
Expand Up @@ -518,11 +518,12 @@ public void saveAndRunPerformed(AjaxRequestTarget target) {
private void savePerformed(AjaxRequestTarget target, boolean run) {
PrismObjectWrapper<TaskType> taskWrapper = getObjectWrapper();
try {
PrismPropertyWrapper<TaskExecutionStatusType> executionStatus = taskWrapper.findProperty(ItemPath.create(TaskType.F_EXECUTION_STATUS));
// TODO MID-6783
PrismPropertyWrapper<TaskExecutionStateType> executionStatus = taskWrapper.findProperty(ItemPath.create(TaskType.F_EXECUTION_STATUS));
if (run) {
executionStatus.getValue().setRealValue(TaskExecutionStatusType.RUNNABLE);
executionStatus.getValue().setRealValue(TaskExecutionStateType.RUNNABLE);
} else {
executionStatus.getValue().setRealValue(TaskExecutionStatusType.SUSPENDED);
executionStatus.getValue().setRealValue(TaskExecutionStateType.SUSPENDED);
}

setupOwner(taskWrapper);
Expand Down
Expand Up @@ -13,6 +13,8 @@
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskExecutionStateType;

import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
Expand All @@ -31,7 +33,6 @@
import com.evolveum.midpoint.schema.GetOperationOptionsBuilder;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.task.api.TaskExecutionStatus;
import com.evolveum.midpoint.task.api.TaskUtil;
import com.evolveum.midpoint.web.application.AuthorizationAction;
import com.evolveum.midpoint.web.application.PageDescriptor;
Expand Down Expand Up @@ -136,7 +137,7 @@ public void populateItem(final Item<ICellPopulator<SelectableBean<TaskType>>> it
public Date getObject() {
Date date = getCurrentRuntime(rowModel);
SelectableBean<TaskType> task = rowModel.getObject();
if (getRawExecutionStatus(task.getValue()) == TaskExecutionStatus.CLOSED && date != null) {
if (task.getValue().getExecutionStatus() == TaskExecutionStateType.CLOSED && date != null) {
((DateLabelComponent) item.get(componentId)).setBefore(createStringResource("pageTasks.task.closedAt").getString() + " ");
} else if (date != null) {
((DateLabelComponent) item.get(componentId))
Expand All @@ -154,7 +155,7 @@ public IModel<String> getDataModel(IModel<SelectableBean<TaskType>> rowModel) {
Date date = getCurrentRuntime(rowModel);
String displayValue = "";
if (date != null) {
if (getRawExecutionStatus(task.getValue()) == TaskExecutionStatus.CLOSED) {
if (task.getValue().getExecutionStatus() == TaskExecutionStateType.CLOSED) {
displayValue =
createStringResource("pageTasks.task.closedAt").getString() +
WebComponentUtil.getShortDateTimeFormattedValue(date, PageTasks.this);
Expand Down Expand Up @@ -198,7 +199,7 @@ private Collection<SelectorOptions<GetOperationOptions>> createOperationOptions(
private Date getCurrentRuntime(IModel<SelectableBean<TaskType>> taskModel) {
TaskType task = taskModel.getObject().getValue();

if (getRawExecutionStatus(task) == TaskExecutionStatus.CLOSED) {
if (task.getExecutionStatus() == TaskExecutionStateType.CLOSED) {

Long time = getCompletionTimestamp(task);
if (time == null) {
Expand All @@ -222,11 +223,6 @@ private String createScheduledToRunAgain(IModel<SelectableBean<TaskType>> taskMo
.getString();
}

//TODO why?
public TaskExecutionStatus getRawExecutionStatus(TaskType taskType) {
return TaskExecutionStatus.fromTaskType(taskType.getExecutionStatus());
}

private Long xgc2long(XMLGregorianCalendar gc) {
return gc != null ? XmlTypeConverter.toMillis(gc) : null;
}
Expand Down

0 comments on commit 01b4080

Please sign in to comment.