Skip to content

Commit

Permalink
configurable date/time format (not finished)
Browse files Browse the repository at this point in the history
# Conflicts:
#	model/model-api/src/main/java/com/evolveum/midpoint/model/api/authentication/CompiledUserProfile.java
#	model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/security/UserProfileCompiler.java
  • Loading branch information
KaterynaHonchar committed Mar 1, 2019
1 parent ad99a68 commit 3fc682a
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 30 deletions.
Expand Up @@ -57,6 +57,7 @@
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.*;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.web.component.DateLabelComponent;
import com.evolveum.midpoint.web.component.breadcrumbs.Breadcrumb;
import com.evolveum.midpoint.web.component.breadcrumbs.BreadcrumbPageClass;
import com.evolveum.midpoint.web.component.breadcrumbs.BreadcrumbPageInstance;
Expand Down Expand Up @@ -1530,6 +1531,38 @@ public static String getLocalizedDate(Date date, String style) {
return converter.convertToString(date, WebComponentUtil.getCurrentLocale());
}

public static String getShortDateTimeFormatValue(XMLGregorianCalendar date, PageBase pageBase) {
return getShortDateTimeFormatValue(XmlTypeConverter.toDate(date), pageBase);
}

public static String getShortDateTimeFormatValue(Date date, PageBase pageBase) {
if (date == null) {
return "";
}
AdminGuiConfigurationDisplayFormatsType displayFormats = pageBase.getCompiledUserProfile().getDisplayFormats();
if (displayFormats == null || StringUtils.isEmpty(displayFormats.getShortDateTimeFormat())){
return getLocalizedDate(date, DateLabelComponent.SHORT_MEDIUM_STYLE);
} else {
return getLocalizedDate(date, displayFormats.getShortDateTimeFormat());
}
}

public static String getLongDateTimeFormatValue(XMLGregorianCalendar date, PageBase pageBase) {
return getLongDateTimeFormatValue(XmlTypeConverter.toDate(date), pageBase);
}

public static String getLongDateTimeFormatValue(Date date, PageBase pageBase) {
if (date == null) {
return "";
}
AdminGuiConfigurationDisplayFormatsType displayFormats = pageBase.getCompiledUserProfile().getDisplayFormats();
if (displayFormats == null || StringUtils.isEmpty(displayFormats.getLongDateTimeFormat())){
return getLocalizedDate(date, DateLabelComponent.LONG_MEDIUM_STYLE);
} else {
return getLocalizedDate(date, displayFormats.getLongDateTimeFormat());
}
}

public static boolean isActivationEnabled(PrismObject object) {
Validate.notNull(object);

Expand Down
Expand Up @@ -104,8 +104,7 @@ public String getObject() {
PropertyModel<Object> tempModel = new PropertyModel<>(getModel(),
qname.getLocalPart());
if (tempModel.getObject() instanceof XMLGregorianCalendar){
return WebComponentUtil.getLocalizedDate((XMLGregorianCalendar)tempModel.getObject(),
DateLabelComponent.MEDIUM_MEDIUM_STYLE);
return WebComponentUtil.getLongDateTimeFormatValue((XMLGregorianCalendar)tempModel.getObject(), getPageBase());
} else if (tempModel.getObject() instanceof ObjectReferenceType){
ObjectReferenceType ref = (ObjectReferenceType) tempModel.getObject();
return WebComponentUtil.getName(ref, getPageBase(), OPERATION_LOAD_USER);
Expand Down
Expand Up @@ -24,6 +24,7 @@

import javax.xml.datatype.XMLGregorianCalendar;

import com.evolveum.midpoint.web.page.admin.workflow.PageWorkItems;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand Down Expand Up @@ -252,15 +253,15 @@ public void populateItem(Item<ICellPopulator<CaseWorkItemDto>> item, String comp
final Date created;
if (createdCal != null) {
created = createdCal.toGregorianCalendar().getTime();
item.add(AttributeModifier.replace("title", WebComponentUtil.getLocalizedDate(created, DateLabelComponent.LONG_MEDIUM_STYLE)));
item.add(AttributeModifier.replace("title", WebComponentUtil.getShortDateTimeFormatValue(created, PageCaseWorkItems.this)));
item.add(new TooltipBehavior());
} else {
created = null;
}
item.add(new Label(componentId, new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
return WebComponentUtil.getLocalizedDate(created, DateLabelComponent.LONG_MEDIUM_STYLE);
return WebComponentUtil.getShortDateTimeFormatValue(created, PageCaseWorkItems.this);
}
}));
}
Expand All @@ -277,15 +278,15 @@ public void populateItem(Item<ICellPopulator<CaseWorkItemDto>> item, String comp
final Date deadline;
if (deadlineCal != null) {
deadline = deadlineCal.toGregorianCalendar().getTime();
item.add(AttributeModifier.replace("title", WebComponentUtil.getLocalizedDate(deadline, DateLabelComponent.LONG_MEDIUM_STYLE)));
item.add(AttributeModifier.replace("title", WebComponentUtil.getShortDateTimeFormatValue(deadline, PageCaseWorkItems.this)));
item.add(new TooltipBehavior());
} else {
deadline = null;
}
item.add(new Label(componentId, new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
return WebComponentUtil.getLocalizedDate(deadline, DateLabelComponent.LONG_MEDIUM_STYLE);
return WebComponentUtil.getShortDateTimeFormatValue(deadline, PageCaseWorkItems.this);
}
}));
}
Expand All @@ -302,15 +303,15 @@ public void populateItem(Item<ICellPopulator<CaseWorkItemDto>> item, String comp
final Date closed;
if (closedCal != null) {
closed = closedCal.toGregorianCalendar().getTime();
item.add(AttributeModifier.replace("title", WebComponentUtil.getLocalizedDate(closed, DateLabelComponent.LONG_MEDIUM_STYLE)));
item.add(AttributeModifier.replace("title", WebComponentUtil.getShortDateTimeFormatValue(closed, PageCaseWorkItems.this)));
item.add(new TooltipBehavior());
} else {
closed = null;
}
item.add(new Label(componentId, new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
return WebComponentUtil.getLocalizedDate(closed, DateLabelComponent.LONG_MEDIUM_STYLE);
return WebComponentUtil.getShortDateTimeFormatValue(closed, PageCaseWorkItems.this);
}
}));
}
Expand Down
Expand Up @@ -175,7 +175,7 @@ public void populateItem(Item<ICellPopulator<SelectableBean<CaseType>>> cellItem
cellItem.add(new Label(componentId, new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
return WebComponentUtil.getLocalizedDate(created, DateLabelComponent.LONG_MEDIUM_STYLE);
return WebComponentUtil.getShortDateTimeFormatValue(created, PageCases.this);
}
}));
}
Expand All @@ -199,7 +199,7 @@ public void populateItem(Item<ICellPopulator<SelectableBean<CaseType>>> cellItem
cellItem.add(new Label(componentId, new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
return WebComponentUtil.getLocalizedDate(closed, DateLabelComponent.LONG_MEDIUM_STYLE);
return WebComponentUtil.getShortDateTimeFormatValue(closed, PageCases.this);
}
}));
}
Expand Down
Expand Up @@ -322,7 +322,7 @@ public void populateItem(Item<ICellPopulator<CertWorkItemDto>> item, String comp
CertWorkItemDto dto = rowModel.getObject();
Date started = dto.getStageStarted();
if (started != null) {
item.add(AttributeModifier.replace("title", WebComponentUtil.getLocalizedDate(started, DateLabelComponent.LONG_MEDIUM_STYLE)));
item.add(AttributeModifier.replace("title", WebComponentUtil.getShortDateTimeFormatValue(started, PageCertDecisions.this)));
item.add(new TooltipBehavior());
}
}
Expand Down
Expand Up @@ -227,7 +227,7 @@ private List<IColumn<AuditEventRecordType, String>> initColumns() {
public void populateItem(Item<ICellPopulator<AuditEventRecordType>> item, String componentId,
IModel<AuditEventRecordType> rowModel) {
XMLGregorianCalendar time = rowModel.getObject().getTimestamp();
item.add(new Label(componentId, WebComponentUtil.getLocalizedDate(time, DateLabelComponent.SHORT_SHORT_STYLE)));
item.add(new Label(componentId, WebComponentUtil.getShortDateTimeFormatValue(time, PageAuditLogDetails.this)));
}
};
columns.add(timeColumn);
Expand Down
Expand Up @@ -615,7 +615,7 @@ public Date getObject() {
Date date = getCurrentRuntime(rowModel);
TaskDto task = rowModel.getObject();
if (task.getRawExecutionStatus() == TaskExecutionStatus.CLOSED && date != null) {
((DateLabelComponent) item.get(componentId)).setBefore(createStringResource("pageTasks.task.closedAt").getString());
((DateLabelComponent) item.get(componentId)).setBefore(createStringResource("pageTasks.task.closedAt").getString() + " ");
} else if (date != null) {
((DateLabelComponent) item.get(componentId))
.setBefore(WebComponentUtil.formatDurationWordsForLocal(date.getTime(), true, true, PageTasks.this));
Expand All @@ -634,7 +634,8 @@ public IModel<String> getDataModel(IModel<TaskDto> rowModel) {
if (date != null) {
if (task.getRawExecutionStatus() == TaskExecutionStatus.CLOSED) {
displayValue =
createStringResource("pageTasks.task.closedAt").getString() + WebComponentUtil.getLocalizedDate(date, DateLabelComponent.LONG_MEDIUM_STYLE);
createStringResource("pageTasks.task.closedAt").getString() +
WebComponentUtil.getShortDateTimeFormatValue(date, PageTasks.this);
} else {
displayValue = WebComponentUtil.formatDurationWordsForLocal(date.getTime(), true, true, PageTasks.this);
}
Expand Down
Expand Up @@ -197,7 +197,7 @@ public String getObject() {
@Override
public String getObject() {
if (taskDtoModel.getObject().getCompletionTimestamp() != null) {
return WebComponentUtil.getLocalizedDate(new Date(taskDtoModel.getObject().getCompletionTimestamp()), DateLabelComponent.LONG_MEDIUM_STYLE);
return WebComponentUtil.getLongDateTimeFormatValue(new Date(taskDtoModel.getObject().getCompletionTimestamp()), parentPage);
} else {
return "?";
}
Expand Down
Expand Up @@ -135,7 +135,7 @@ public String getObject() {
if (dto.getLastRunStartTimestampLong() == null) {
return "-";
} else {
return WebComponentUtil.getLocalizedDate(new Date(dto.getLastRunStartTimestampLong()), DateLabelComponent.LONG_MEDIUM_STYLE);
return WebComponentUtil.getLongDateTimeFormatValue(new Date(dto.getLastRunStartTimestampLong()), parentPage);
}
}
});
Expand Down Expand Up @@ -166,7 +166,7 @@ public String getObject() {
if (dto.getLastRunFinishTimestampLong() == null) {
return "-";
} else {
return WebComponentUtil.getLocalizedDate(new Date(dto.getLastRunFinishTimestampLong()), DateLabelComponent.LONG_MEDIUM_STYLE);
return WebComponentUtil.getLongDateTimeFormatValue(new Date(dto.getLastRunFinishTimestampLong()), parentPage);
}
}
});
Expand Down
Expand Up @@ -175,7 +175,7 @@ private String getStageInfo() {
}

public String getRequestedOn() {
return WebComponentUtil.getLocalizedDate(parentPage.getTaskDto().getRequestedOn(), DateLabelComponent.MEDIUM_MEDIUM_STYLE);
return WebComponentUtil.getLongDateTimeFormatValue(parentPage.getTaskDto().getRequestedOn(), parentPage);
}

@Override
Expand Down
Expand Up @@ -88,11 +88,11 @@ public String getObject() {
return null;
}
if (TaskDtoExecutionStatus.RUNNING.equals(dto.getExecution()) || finished == null || finished < started) {
return getString("TaskStatePanel.message.executionTime.notFinished", formatDate(new Date(started)),
return getString("TaskStatePanel.message.executionTime.notFinished", formatDate(new Date(started), pageBase),
DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - started));
} else {
return getString("TaskStatePanel.message.executionTime.finished",
formatDate(new Date(started)), formatDate(new Date(finished)),
formatDate(new Date(started), pageBase), formatDate(new Date(finished), pageBase),
DurationFormatUtils.formatDurationHMS(finished - started));
}
}
Expand Down Expand Up @@ -178,13 +178,13 @@ public String getObject() {
} else {
if (showAgo(dto)) {
return getString("TaskStatePanel.message.timeInfoWithDurationAndAgo",
formatDate(info.getLastSuccessEndTimestamp()),
formatDate(info.getLastSuccessEndTimestamp(), pageBase),
WebComponentUtil.formatDurationWordsForLocal(System.currentTimeMillis() -
XmlTypeConverter.toMillis(info.getLastSuccessEndTimestamp()), true, true, pageBase),
info.getLastSuccessDuration());
} else {
return getString("TaskStatePanel.message.timeInfoWithDuration",
formatDate(info.getLastSuccessEndTimestamp()),
formatDate(info.getLastSuccessEndTimestamp(), pageBase),
info.getLastSuccessDuration());
}
}
Expand Down Expand Up @@ -272,13 +272,13 @@ public String getObject() {
} else {
if (showAgo(dto)) {
return getString("TaskStatePanel.message.timeInfoWithDurationAndAgo",
formatDate(info.getLastFailureEndTimestamp()),
formatDate(info.getLastFailureEndTimestamp(), pageBase),
WebComponentUtil.formatDurationWordsForLocal(System.currentTimeMillis() -
XmlTypeConverter.toMillis(info.getLastFailureEndTimestamp()), true, true, pageBase),
info.getLastFailureDuration());
} else {
return getString("TaskStatePanel.message.timeInfoWithDuration",
formatDate(info.getLastFailureEndTimestamp()),
formatDate(info.getLastFailureEndTimestamp(), pageBase),
info.getLastFailureDuration());
}
}
Expand Down Expand Up @@ -333,7 +333,7 @@ public String getObject() {
return null;
} else {
return getString("TaskStatePanel.message.timeInfoWithAgo",
formatDate(info.getCurrentObjectStartTimestamp()),
formatDate(info.getCurrentObjectStartTimestamp(), pageBase),
WebComponentUtil.formatDurationWordsForLocal(System.currentTimeMillis() -
XmlTypeConverter.toMillis(info.getCurrentObjectStartTimestamp()), true, true, pageBase));
}
Expand Down Expand Up @@ -366,15 +366,15 @@ public String getObject() {
add(objectsTotal);
}

private String formatDate(XMLGregorianCalendar date) {
return formatDate(XmlTypeConverter.toDate(date));
private String formatDate(XMLGregorianCalendar date, PageBase pageBase) {
return formatDate(XmlTypeConverter.toDate(date), pageBase);
}

private String formatDate(Date date) {
private String formatDate(Date date, PageBase pageBase) {
if (date == null) {
return null;
}
return WebComponentUtil.getLocalizedDate(date, DateLabelComponent.LONG_MEDIUM_STYLE);
return WebComponentUtil.getLongDateTimeFormatValue(date, pageBase);
}

protected boolean showAgo(TaskCurrentStateDto dto) {
Expand Down
Expand Up @@ -128,7 +128,8 @@ protected IModel<String> getTitle2Model() {
public String getObject() {
WorkItemType workItem = getModelObject();
return getString("TaskSummaryPanel.requestedOn",
WebComponentUtil.getLocalizedDate(WfContextUtil.getWorkflowContext(workItem).getStartTimestamp(), DateLabelComponent.MEDIUM_MEDIUM_STYLE));
WebComponentUtil.getLongDateTimeFormatValue(WfContextUtil.getWorkflowContext(workItem).getStartTimestamp(),
WorkItemSummaryPanel.this.getPageBase()));
}
};
}
Expand Down

0 comments on commit 3fc682a

Please sign in to comment.