Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
package com.evolveum.midpoint.gui.impl.page.admin.certification.component;

import java.io.Serial;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import javax.xml.datatype.XMLGregorianCalendar;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -153,7 +156,9 @@ private int getDaysToDeadline() {
deadline.getYear(),
deadline.getMonth(),
deadline.getDay());
LocalDate now = LocalDate.now();
LocalDate now = Instant.ofEpochMilli(getPageBase().getClock().currentTimeMillis())
.atZone(ZoneId.systemDefault())
.toLocalDate();

return (int) ChronoUnit.DAYS.between(now, deadlineLocalDate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public static String computeDeadlineAsString(AccessCertificationCampaignType cam
if (end == null) {
return "";
} else {
long delta = XmlTypeConverter.toMillis(end) - System.currentTimeMillis();
long delta = XmlTypeConverter.toMillis(end) - page.getClock().currentTimeMillis();

// round to hours; we always round down
long precision = 3600000L; // 1 hour
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,16 @@ public static ObjectProcessingStateType builtInMetricToProcessingState(BuiltInSi
}
}

public static @Nullable String createResultDurationText(@NotNull SimulationResultType result, Component panel) {
public static @Nullable String createResultDurationText(
@NotNull SimulationResultType result, Component panel, long now) {
XMLGregorianCalendar start = result.getStartTimestamp();
if (start == null) {
return panel.getString("SimulationResultsPanel.notStartedYet");
}

XMLGregorianCalendar end = result.getEndTimestamp();
if (end == null) {
end = MiscUtil.asXMLGregorianCalendar(new Date());
end = MiscUtil.asXMLGregorianCalendar(new Date(now));
}

long duration = (end != null ? end.toGregorianCalendar().getTimeInMillis() : 0) - start.toGregorianCalendar().getTimeInMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ protected List<DetailsTableItem> load() {
list.add(new DetailsTableItem(createStringResource("PageSimulationResult.endTimestamp"),
() -> LocalizationUtil.translateMessage(ValueDisplayUtil.toStringValue(new PrismPropertyValueImpl<>(getModelObject().getEndTimestamp())))));
list.add(new DetailsTableItem(createStringResource("PageSimulationResult.finishedIn"),
() -> createResultDurationText(getModelObject(), SimulationResultPanel.this)));
() -> createResultDurationText(
getModelObject(),
SimulationResultPanel.this,
getPageBase().getClock().currentTimeMillis())));
list.add(new DetailsTableItem(createStringResource("PageSimulationResult.rootTask"), null) {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ private IModel<String> createConfirmationMessage(ColumnMenuAction<SelectableBean
@Override
protected List<IColumn<SelectableBean<SimulationResultType>, String>> createDefaultColumns() {
List<IColumn<SelectableBean<SimulationResultType>, String>> columns = super.createDefaultColumns();
columns.add(new LambdaColumn<>(createStringResource("ProcessedObjectsPanel.duration"), row -> createResultDurationText(row.getValue(), this)));
columns.add(new LambdaColumn<>(createStringResource("ProcessedObjectsPanel.duration"),
row -> createResultDurationText(row.getValue(), this, getPageBase().getClock().currentTimeMillis())));
columns.add(new AbstractColumn<>(createStringResource("ProcessedObjectsPanel.executionState")) {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private String computeDeadlineAsString(PageBase page) {
if (end == null) {
return "";
} else {
long delta = XmlTypeConverter.toMillis(end) - System.currentTimeMillis();
long delta = XmlTypeConverter.toMillis(end) - page.getClock().currentTimeMillis();

// round to hours; we always round down
long precision = 3600000L; // 1 hour
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private String computeDeadlineAsString(PageBase page) {
if (deadline == null) {
return "";
} else {
long delta = XmlTypeConverter.toMillis(deadline) - System.currentTimeMillis();
long delta = XmlTypeConverter.toMillis(deadline) - page.getClock().currentTimeMillis();

// round to hours; we always round down
long precision = 3600000L; // 1 hour
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ private static String createExecutionStateMessage(TaskInformation info, PageBase
case RUNNABLE:
case RUNNING_OR_RUNNABLE:
List<Object> localizationObjects = new ArrayList<>();
String key = TaskTypeUtil.createScheduledToRunAgain(task, localizationObjects);
String key = TaskTypeUtil.createScheduledToRunAgain(
task, page.getClock().currentTimeMillis(), localizationObjects);
return LocalizationUtil.translate(key, localizationObjects.toArray());
case WAITING:
case SUSPENDED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ public static ImportOptionsType getDefaultImportOptions() {
return options;
}

public static CachingMetadataType generateCachingMetadata() {
public static CachingMetadataType generateCachingMetadata(@NotNull XMLGregorianCalendar xmlGregorianCalendarNow) {
CachingMetadataType cmd = new CachingMetadataType();
XMLGregorianCalendar xmlGregorianCalendarNow =
XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis());
cmd.setRetrievalTimestamp(xmlGregorianCalendarNow);
cmd.setSerialNumber(generateSerialNumber());
return cmd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public class TaskTypeUtil {
* Returns key for localization representing execution status of a task, additionally populates {@code localizationObject}
* with additional parameters for the localization key.
*/
public static String createScheduledToRunAgain(TaskType task, List<Object> localizationObject) {
public static String createScheduledToRunAgain(TaskType task, long now, List<Object> localizationObject) {
boolean runnable = task.getSchedulingState() == TaskSchedulingStateType.READY;
Long scheduledAfter = getScheduledToStartAgain(task);
Long retryAfter = runnable ? getRetryAfter(task) : null;
Long scheduledAfter = getScheduledToStartAgain(task, now);
Long retryAfter = runnable ? getRetryAfter(task, now) : null;

if (scheduledAfter == null) {
if (retryAfter == null || retryAfter <= 0) {
Expand Down Expand Up @@ -73,14 +73,12 @@ public static String createScheduledToRunAgain(TaskType task, List<Object> local
return key;
}

private static Long getRetryAfter(TaskType task) {
private static Long getRetryAfter(TaskType task, long now) {
XMLGregorianCalendar nextRun = task.getNextRetryTimestamp();
return nextRun != null ? (XmlTypeConverter.toMillis(nextRun) - System.currentTimeMillis()) : null;
return nextRun != null ? (XmlTypeConverter.toMillis(nextRun) - now) : null;
}

public static Long getScheduledToStartAgain(TaskType task) {
long current = System.currentTimeMillis();

public static Long getScheduledToStartAgain(TaskType task, long now) {
if (task.getNodeAsObserved() != null && task.getSchedulingState() != TaskSchedulingStateType.SUSPENDED) {
if (!isTaskRecurring(task)) {
return null;
Expand All @@ -95,9 +93,9 @@ public static Long getScheduledToStartAgain(TaskType task) {
return null;
}

if (nextRunStartTimeLong > current + 1000) {
return nextRunStartTimeLong - System.currentTimeMillis();
} else if (nextRunStartTimeLong < current - 60000) {
if (nextRunStartTimeLong > now + 1000) {
return nextRunStartTimeLong - now;
} else if (nextRunStartTimeLong < now - 60000) {
return ALREADY_PASSED;
} else {
return NOW;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void completeOrCancelWorkItem(@NotNull CaseWorkItemType workItem, @Nulla
private void updateCaseHistory(@NotNull CaseWorkItemType workItem, @NotNull AbstractWorkItemOutputType output) {
WorkItemId workItemId = WorkItemId.create(operation.getCaseOidRequired(), workItem.getId());
WorkItemCompletionEventType event = new WorkItemCompletionEventType(PrismContext.get());
fillInWorkItemEvent(event, operation.getPrincipal(), workItemId, workItem);
fillInWorkItemEvent(event, operation.getPrincipal(), workItemId, workItem, beans.clock.currentTimeMillis());
event.setCause(request.getCauseInformation());
event.setOutput(output);
operation.addCaseHistoryEvent(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void executeDelegation(

WorkItemId workItemId = operation.createWorkItemId(workItem);

WorkItemHelper.fillInWorkItemEvent(event, operation.getPrincipal(), workItemId, workItem);
WorkItemHelper.fillInWorkItemEvent(event, operation.getPrincipal(), workItemId, workItem, beans.clock.currentTimeMillis());
operation.addCaseHistoryEvent(event);

ApprovalStageDefinitionType level = operation.getCurrentStageDefinition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ public static void fillInWorkItemEvent(
WorkItemEventType event,
MidPointPrincipal currentUser,
WorkItemId workItemId,
CaseWorkItemType workItem) {
CaseWorkItemType workItem,
long now) {
if (currentUser != null) {
event.setInitiatorRef(ObjectTypeUtil.createObjectRef(currentUser.getFocus()));
event.setAttorneyRef(ObjectTypeUtil.createObjectRef(currentUser.getAttorney()));
}
event.setTimestamp(XmlTypeConverter.createXMLGregorianCalendar(new Date()));
event.setTimestamp(XmlTypeConverter.createXMLGregorianCalendar(new Date(now)));
event.setExternalWorkItemId(workItemId.asString());
event.setWorkItemId(workItemId.id);
event.setOriginalAssigneeRef(workItem.getOriginalAssigneeRef());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void markCaseAsRemedied(@NotNull String campaignOid, long caseId, Task ta
throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
PropertyDelta<XMLGregorianCalendar> remediedDelta = prismContext.deltaFactory().property().createModificationReplaceProperty(
ItemPath.create(F_CASE, caseId, AccessCertificationCaseType.F_REMEDIED_TIMESTAMP),
generalHelper.getCampaignObjectDefinition(), XmlTypeConverter.createXMLGregorianCalendar(new Date()));
generalHelper.getCampaignObjectDefinition(), clock.currentTimeXMLGregorianCalendar());

updateHelper.modifyObjectPreAuthorized(AccessCertificationCampaignType.class, campaignOid,
Collections.singletonList(remediedDelta), task, parentResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private void cleanupCampaignsByDate(Duration maxAge, Task task, OperationResult
if (maxAge.getSign() > 0) {
maxAge = maxAge.negate();
}
Date deleteCampaignsFinishedUpTo = new Date();
Date deleteCampaignsFinishedUpTo = new Date(clock.currentTimeMillis());
maxAge.addTo(deleteCampaignsFinishedUpTo);

LOGGER.debug("Starting cleanup for closed certification campaigns deleting up to {} (max age '{}').", deleteCampaignsFinishedUpTo, maxAge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ private List<ItemDelta<?,?>> createDeltasToRecordStageOpen(AccessCertificationCa
for (Duration beforeDeadline : stageDef.getNotifyBeforeDeadline()) {
final XMLGregorianCalendar beforeEnd = CloneUtil.clone(stageDeadline);
beforeEnd.add(beforeDeadline.negate());
if (XmlTypeConverter.toMillis(beforeEnd) > System.currentTimeMillis()) {
if (XmlTypeConverter.toMillis(beforeEnd) > clock.currentTimeMillis()) {
final TriggerType triggerBeforeEnd = new TriggerType();
triggerBeforeEnd.setHandlerUri(AccessCertificationCloseStageApproachingTriggerHandler.HANDLER_URI);
triggerBeforeEnd.setTimestamp(beforeEnd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private List<ItemDelta<?,?>> createDeltasToRecordStageOpen(AccessCertificationCa
for (Duration beforeDeadline : stageDef.getNotifyBeforeDeadline()) {
final XMLGregorianCalendar beforeEnd = CloneUtil.clone(stageDeadline);
beforeEnd.add(beforeDeadline.negate());
if (XmlTypeConverter.toMillis(beforeEnd) > System.currentTimeMillis()) {
if (XmlTypeConverter.toMillis(beforeEnd) > getActivityHandler().getModelBeans().clock.currentTimeMillis()) {
final TriggerType triggerBeforeEnd = new TriggerType();
triggerBeforeEnd.setHandlerUri(AccessCertificationCloseStageApproachingTriggerHandler.HANDLER_URI);
triggerBeforeEnd.setTimestamp(beforeEnd);
Expand Down
Loading
Loading