use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.
the class TaskSchedulingTabPanel method initLayoutForSchedulingTable.
private void initLayoutForSchedulingTable() {
// models
final IModel<Boolean> recurringCheckModel = new PropertyModel<>(taskDtoModel, TaskDto.F_RECURRING);
final IModel<Boolean> boundCheckModel = new PropertyModel<Boolean>(taskDtoModel, TaskDto.F_BOUND);
// behaviors
final VisibleEnableBehaviour visibleIfEditAndRunnableOrRunning = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return parentPage.isEdit() && parentPage.getTaskDto().isRunnableOrRunning();
}
};
final VisibleEnableBehaviour visibleIfRecurringAndScheduleIsAccessible = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return recurringCheckModel.getObject() && parentPage.isReadable(new ItemPath(TaskType.F_SCHEDULE));
}
};
final VisibleEnableBehaviour visibleIfRecurringAndLooselyBoundAndScheduleIsAccessible = new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return recurringCheckModel.getObject() && !boundCheckModel.getObject() && parentPage.isReadable(new ItemPath(TaskType.F_SCHEDULE));
}
};
final VisibleEnableBehaviour enabledIfEditAndNotRunningRunnableOrLooselyBoundAndScheduleIsEditable = new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
return parentPage.isEdit() && (!parentPage.getTaskDto().isRunnableOrRunning() || !boundCheckModel.getObject()) && parentPage.isEditable(new ItemPath(TaskType.F_SCHEDULE));
}
};
final VisibleEnableBehaviour enabledIfEditAndNotRunningAndScheduleIsEditable = new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
return parentPage.isEdit() && !parentPage.getTaskDto().isRunning() && parentPage.isEditable(new ItemPath(TaskType.F_SCHEDULE));
}
};
final VisibleEnableBehaviour enabledIfEditAndScheduleIsEditable = new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
return parentPage.isEdit() && parentPage.isEditable(new ItemPath(TaskType.F_SCHEDULE));
}
};
final VisibleEnableBehaviour enabledIfEditAndThreadStopIsEditable = new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
return parentPage.isEdit() && parentPage.isEditable(new ItemPath(TaskType.F_THREAD_STOP_ACTION));
}
};
// components
final WebMarkupContainer schedulingTable = new WebMarkupContainer(ID_SCHEDULING_TABLE);
schedulingTable.setOutputMarkupId(true);
add(schedulingTable);
WebMarkupContainer recurringContainer = new WebMarkupContainer(ID_RECURRING_CONTAINER);
AjaxCheckBox recurringCheck = new AjaxCheckBox(ID_RECURRING_CHECK, recurringCheckModel) {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(schedulingTable);
}
};
recurringCheck.setOutputMarkupId(true);
recurringCheck.add(new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
return parentPage.isEdit() && !parentPage.getTaskDto().isRunnableOrRunning() && parentPage.isEditable(TaskType.F_RECURRENCE);
}
});
recurringContainer.add(recurringCheck);
WebMarkupContainer suspendReqRecurring = new WebMarkupContainer(ID_SUSPEND_REQ_RECURRING);
suspendReqRecurring.add(visibleIfEditAndRunnableOrRunning);
recurringContainer.add(suspendReqRecurring);
recurringContainer.add(parentPage.createVisibleIfAccessible(TaskType.F_RECURRENCE));
schedulingTable.add(recurringContainer);
final WebMarkupContainer boundContainer = new WebMarkupContainer(ID_BOUND_CONTAINER);
boundContainer.setOutputMarkupId(true);
final AjaxCheckBox bound = new AjaxCheckBox(ID_BOUND_CHECK, boundCheckModel) {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(schedulingTable);
}
};
bound.add(new VisibleEnableBehaviour() {
@Override
public boolean isEnabled() {
return parentPage.isEdit() && !parentPage.getTaskDto().isRunnableOrRunning() && parentPage.isEditable(TaskType.F_BINDING);
}
});
boundContainer.add(bound);
WebMarkupContainer suspendReqBound = new WebMarkupContainer(ID_SUSPEND_REQ_BOUND);
suspendReqBound.add(visibleIfEditAndRunnableOrRunning);
boundContainer.add(suspendReqBound);
boundContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return recurringCheckModel.getObject() && parentPage.isReadable(new ItemPath(TaskType.F_BINDING));
}
});
Label boundHelp = new Label(ID_BOUND_HELP);
boundHelp.add(new InfoTooltipBehavior());
boundContainer.add(boundHelp);
schedulingTable.add(boundContainer);
WebMarkupContainer intervalContainer = new WebMarkupContainer(ID_INTERVAL_CONTAINER);
intervalContainer.add(visibleIfRecurringAndScheduleIsAccessible);
intervalContainer.setOutputMarkupId(true);
schedulingTable.add(intervalContainer);
TextField<Integer> interval = new TextField<>(ID_INTERVAL, new PropertyModel<Integer>(taskDtoModel, TaskDto.F_INTERVAL));
interval.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
interval.add(enabledIfEditAndNotRunningRunnableOrLooselyBoundAndScheduleIsEditable);
intervalContainer.add(interval);
WebMarkupContainer cronContainer = new WebMarkupContainer(ID_CRON_CONTAINER);
cronContainer.add(visibleIfRecurringAndLooselyBoundAndScheduleIsAccessible);
cronContainer.setOutputMarkupId(true);
schedulingTable.add(cronContainer);
TextField<String> cron = new TextField<>(ID_CRON, new PropertyModel<String>(taskDtoModel, TaskDto.F_CRON_SPECIFICATION));
cron.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
cron.add(enabledIfEditAndNotRunningRunnableOrLooselyBoundAndScheduleIsEditable);
cronContainer.add(cron);
Label cronHelp = new Label(ID_CRON_HELP);
cronHelp.add(new InfoTooltipBehavior());
cronContainer.add(cronHelp);
WebMarkupContainer notStartBeforeContainer = new WebMarkupContainer(ID_NOT_START_BEFORE_CONTAINER);
DateInput notStartBefore = new DateInput(ID_NOT_START_BEFORE_FIELD, new PropertyModel<Date>(taskDtoModel, TaskDto.F_NOT_START_BEFORE));
notStartBefore.setOutputMarkupId(true);
notStartBefore.add(enabledIfEditAndNotRunningAndScheduleIsEditable);
notStartBeforeContainer.add(notStartBefore);
notStartBeforeContainer.add(parentPage.createVisibleIfAccessible(TaskType.F_SCHEDULE));
schedulingTable.add(notStartBeforeContainer);
WebMarkupContainer notStartAfterContainer = new WebMarkupContainer(ID_NOT_START_AFTER_CONTAINER);
DateInput notStartAfter = new DateInput(ID_NOT_START_AFTER_FIELD, new PropertyModel<Date>(taskDtoModel, TaskDto.F_NOT_START_AFTER));
notStartAfter.setOutputMarkupId(true);
notStartAfter.add(enabledIfEditAndNotRunningAndScheduleIsEditable);
notStartAfterContainer.add(notStartAfter);
notStartAfterContainer.add(parentPage.createVisibleIfAccessible(TaskType.F_SCHEDULE));
schedulingTable.add(notStartAfterContainer);
WebMarkupContainer misfireActionContainer = new WebMarkupContainer(ID_MISFIRE_ACTION_CONTAINER);
DropDownChoice misfire = new DropDownChoice(ID_MISFIRE_ACTION, new PropertyModel<MisfireActionType>(taskDtoModel, TaskDto.F_MISFIRE_ACTION), WebComponentUtil.createReadonlyModelFromEnum(MisfireActionType.class), new EnumChoiceRenderer<MisfireActionType>(parentPage));
misfire.add(enabledIfEditAndScheduleIsEditable);
misfireActionContainer.add(misfire);
misfireActionContainer.add(parentPage.createVisibleIfAccessible(TaskType.F_SCHEDULE));
schedulingTable.add(misfireActionContainer);
WebMarkupContainer threadStopContainer = new WebMarkupContainer(ID_THREAD_STOP_CONTAINER);
DropDownChoice threadStop = new DropDownChoice<>(ID_THREAD_STOP, new Model<ThreadStopActionType>() {
@Override
public ThreadStopActionType getObject() {
return taskDtoModel.getObject().getThreadStopActionType();
}
@Override
public void setObject(ThreadStopActionType object) {
taskDtoModel.getObject().setThreadStopActionType(object);
}
}, WebComponentUtil.createReadonlyModelFromEnum(ThreadStopActionType.class), new EnumChoiceRenderer<ThreadStopActionType>(parentPage));
threadStop.add(enabledIfEditAndThreadStopIsEditable);
threadStopContainer.add(threadStop);
threadStopContainer.add(parentPage.createVisibleIfAccessible(TaskType.F_THREAD_STOP_ACTION));
schedulingTable.add(threadStopContainer);
org.apache.wicket.markup.html.form.Form<?> form = parentPage.getForm();
// TODO implement more intelligently when other tabs have validators as well
for (IFormValidator validator : form.getFormValidators()) {
form.remove(validator);
}
form.add(new StartEndDateValidator(notStartBefore, notStartAfter));
form.add(new ScheduleValidator(parentPage.getTaskManager(), recurringCheck, bound, interval, cron));
}
use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.
the class TaskTabsVisibility method computeProgressVisible.
public boolean computeProgressVisible(PageTaskEdit parentPage) {
final OperationStatsType operationStats = parentPage.getTaskDto().getTaskType().getOperationStats();
progressVisible = !parentPage.isEdit() && operationStats != null && // readability is maybe not required, as the corresponding data would be null if not readable
parentPage.isReadable(new ItemPath(TaskType.F_OPERATION_STATS)) && (operationStats.getIterativeTaskInformation() != null || operationStats.getSynchronizationInformation() != null || operationStats.getActionsExecutedInformation() != null);
return progressVisible;
}
use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.
the class TaskTabsVisibility method computeEnvironmentalPerformanceVisible.
public boolean computeEnvironmentalPerformanceVisible(PageTaskEdit parentPage) {
final OperationStatsType operationStats = parentPage.getTaskDto().getTaskType().getOperationStats();
environmentalPerformanceVisible = !parentPage.isEdit() && parentPage.isReadable(new ItemPath(TaskType.F_OPERATION_STATS)) && operationStats != null && !StatisticsUtil.isEmpty(operationStats.getEnvironmentalPerformanceInformation());
return environmentalPerformanceVisible;
}
use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.
the class PageTaskAdd method createTask.
private TaskType createTask(TaskAddDto dto) throws SchemaException {
TaskType task = new TaskType();
MidPointPrincipal owner = SecurityUtils.getPrincipalUser();
ObjectReferenceType ownerRef = new ObjectReferenceType();
ownerRef.setOid(owner.getOid());
ownerRef.setType(owner.getUser().COMPLEX_TYPE);
task.setOwnerRef(ownerRef);
task.setCategory(dto.getCategory());
String handlerUri = getTaskManager().getHandlerUriForCategory(dto.getCategory());
if (handlerUri == null) {
throw new SystemException("Cannot determine task handler URI for category " + dto.getCategory());
}
task.setHandlerUri(handlerUri);
ObjectReferenceType objectRef;
if (dto.getResource() != null) {
objectRef = new ObjectReferenceType();
objectRef.setOid(dto.getResource().getOid());
objectRef.setType(ResourceType.COMPLEX_TYPE);
task.setObjectRef(objectRef);
}
task.setName(WebComponentUtil.createPolyFromOrigString(dto.getName()));
task.setRecurrence(dto.getReccuring() ? TaskRecurrenceType.RECURRING : TaskRecurrenceType.SINGLE);
task.setBinding(dto.getBound() ? TaskBindingType.TIGHT : TaskBindingType.LOOSE);
ScheduleType schedule = new ScheduleType();
schedule.setInterval(dto.getInterval());
schedule.setCronLikePattern(dto.getCron());
schedule.setEarliestStartTime(MiscUtil.asXMLGregorianCalendar(dto.getNotStartBefore()));
schedule.setLatestStartTime(MiscUtil.asXMLGregorianCalendar(dto.getNotStartAfter()));
schedule.setMisfireAction(dto.getMisfireAction());
task.setSchedule(schedule);
if (dto.getSuspendedState()) {
task.setExecutionStatus(TaskExecutionStatusType.SUSPENDED);
} else {
task.setExecutionStatus(TaskExecutionStatusType.RUNNABLE);
}
if (dto.getThreadStop() != null) {
task.setThreadStopAction(dto.getThreadStop());
} else {
// fill-in default
if (dto.getRunUntilNodeDown() == true) {
task.setThreadStopAction(ThreadStopActionType.CLOSE);
} else {
task.setThreadStopAction(ThreadStopActionType.RESTART);
}
}
if (dto.isDryRun()) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_DRY_RUN);
PrismProperty dryRun = prismTask.findOrCreateProperty(path);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_DRY_RUN);
dryRun.setDefinition(def);
dryRun.setRealValue(true);
}
if (dto.getFocusType() != null) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECT_TYPE);
PrismProperty focusType = prismTask.findOrCreateProperty(path);
focusType.setRealValue(dto.getFocusType());
}
if (dto.getKind() != null) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND);
PrismProperty kind = prismTask.findOrCreateProperty(path);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_KIND);
kind.setDefinition(def);
kind.setRealValue(dto.getKind());
}
if (dto.getIntent() != null && StringUtils.isNotEmpty(dto.getIntent())) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT);
PrismProperty intent = prismTask.findOrCreateProperty(path);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_INTENT);
intent.setDefinition(def);
intent.setRealValue(dto.getIntent());
}
if (dto.getObjectClass() != null && StringUtils.isNotEmpty(dto.getObjectClass())) {
PrismObject<TaskType> prismTask = task.asPrismObject();
ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
PrismProperty objectClassProperty = prismTask.findOrCreateProperty(path);
QName objectClass = null;
for (QName q : model.getObject().getObjectClassList()) {
if (q.getLocalPart().equals(dto.getObjectClass())) {
objectClass = q;
}
}
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
objectClassProperty.setDefinition(def);
objectClassProperty.setRealValue(objectClass);
}
return task;
}
use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.
the class PageTaskController method getDeltasToExecute.
private List<ItemDelta<?, ?>> getDeltasToExecute(TaskDto dto) throws SchemaException {
List<ItemDelta<?, ?>> rv = new ArrayList<>();
TaskEditableState orig = dto.getOriginalEditableState();
TaskEditableState curr = dto.getCurrentEditableState();
if (!StringUtils.equals(orig.getName(), curr.getName())) {
String name = curr.getName() != null ? curr.getName() : "";
addDelta(rv, TaskType.F_NAME, new PolyString(name));
}
if (!StringUtils.equals(orig.getDescription(), curr.getDescription())) {
addDelta(rv, TaskType.F_DESCRIPTION, curr.getDescription());
}
ScheduleType origSchedule = orig.getScheduleType();
ScheduleType currSchedule = curr.getScheduleType();
if (!origSchedule.equals(currSchedule)) {
if (dto.getTaskType().getSchedule() != null) {
currSchedule.setLatestFinishTime(dto.getTaskType().getSchedule().getLatestFinishTime());
}
addDelta(rv, TaskType.F_SCHEDULE, currSchedule);
}
if (orig.isRecurring() != curr.isRecurring()) {
addDelta(rv, TaskType.F_RECURRENCE, curr.isRecurring() ? TaskRecurrenceType.RECURRING : TaskRecurrenceType.SINGLE);
}
if (orig.isBound() != curr.isBound()) {
addDelta(rv, TaskType.F_BINDING, curr.isBound() ? TaskBindingType.TIGHT : TaskBindingType.LOOSE);
}
if (orig.getThreadStopActionType() != curr.getThreadStopActionType()) {
addDelta(rv, TaskType.F_THREAD_STOP_ACTION, curr.getThreadStopActionType());
}
if (!ObjectUtils.equals(orig.getWorkerThreads(), curr.getWorkerThreads())) {
SchemaRegistry registry = parentPage.getPrismContext().getSchemaRegistry();
PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_WORKER_THREADS);
rv.add(DeltaBuilder.deltaFor(TaskType.class, parentPage.getPrismContext()).item(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_WORKER_THREADS), def).replace(curr.getWorkerThreads()).asItemDelta());
}
rv.addAll(dto.getHandlerDto().getDeltasToExecute(orig.getHandlerSpecificState(), curr.getHandlerSpecificState(), parentPage.getPrismContext()));
return rv;
}
Aggregations