Skip to content

Commit

Permalink
search parameters for history panel (plus some cleanup)
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Aug 7, 2023
1 parent 24bce12 commit 1041cb9
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ public class SearchContext {

private List<SearchBoxModeType> availableSearchBoxModes;

private boolean history;

public ResourceObjectDefinition getResourceObjectDefinition() {
return resourceObjectDefinition;
}


public void setResourceObjectDefinition(ResourceObjectDefinition resourceObjectDefinition) {
this.resourceObjectDefinition = resourceObjectDefinition;
}
Expand Down Expand Up @@ -110,4 +113,12 @@ public List<SearchBoxModeType> getAvailableSearchBoxModes() {
public void setAvailableSearchBoxModes(List<SearchBoxModeType> availableSearchBoxModes) {
this.availableSearchBoxModes = availableSearchBoxModes;
}

public void setHistory(boolean objectHistoryPanel) {
this.history = objectHistoryPanel;
}

public boolean isHistory() {
return history;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class SearchableItemsDefinitions {
private ItemDefinition<?> containerDefinition;

private ResourceObjectDefinition resourceObjectDefinition;
private boolean history;

public SearchableItemsDefinitions(Class<?> type, ModelServiceLocator modelServiceLocator) {
this.type = type;
Expand All @@ -64,6 +65,7 @@ public SearchableItemsDefinitions additionalSearchContext(SearchContext ctx) {
this.containerDefinition = ctx.getDefinitionOverride();
this.assignmentTargetType = ctx.getAssignmentTargetType();
this.collectionPanelType = ctx.getPanelType();
this.history = ctx.isHistory();
return this;
}

Expand Down Expand Up @@ -170,9 +172,7 @@ public SearchableItemsDefinitions additionalSearchContext(SearchContext ctx) {
SEARCHABLE_OBJECTS.put(AuditEventRecordType.class, Arrays.asList(
ItemPath.create(AuditEventRecordType.F_TIMESTAMP),
ItemPath.create(AuditEventRecordType.F_INITIATOR_REF),
ItemPath.create(AuditEventRecordType.F_EVENT_STAGE),
ItemPath.create(AuditEventRecordType.F_EVENT_TYPE),
ItemPath.create(AuditEventRecordType.F_TARGET_REF),
ItemPath.create(AuditEventRecordType.F_TARGET_OWNER_REF),
ItemPath.create(AuditEventRecordType.F_CHANGED_ITEM),
ItemPath.create(AuditEventRecordType.F_OUTCOME),
Expand Down Expand Up @@ -419,6 +419,12 @@ private List<ItemPath> getAvailableSearchableItems(Class<? extends Containerable
auditItems.add(ItemPath.create(AuditEventRecordType.F_RESOURCE_OID));
items = auditItems;
}
if (!history) {
ArrayList<ItemPath> allSearchableItems = new ArrayList<>(items);
allSearchableItems.add(ItemPath.create(AuditEventRecordType.F_EVENT_STAGE));
allSearchableItems.add(ItemPath.create(AuditEventRecordType.F_TARGET_REF));
items = allSearchableItems;
}
}
return items;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
*/
package com.evolveum.midpoint.gui.impl.page.admin.focus.component;

import java.io.Serial;
import java.util.List;

import com.evolveum.midpoint.web.application.PanelTypeConstants;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
Expand Down Expand Up @@ -55,12 +58,12 @@
/**
* Created by honchar.
*/
@PanelType(name = "history")
@PanelType(name = PanelTypeConstants.FOCUS_HISTORY_PANEL)
@PanelInstance(identifier = "history", applicableForType = FocusType.class, applicableForOperation = OperationTypeType.MODIFY,
display = @PanelDisplay(label = "pageAdminFocus.objectHistory", icon = GuiStyleConstants.CLASS_ICON_HISTORY, order = 60))
public class FocusHistoryPanel<F extends FocusType> extends AbstractObjectMainPanel<F, FocusDetailsModels<F>> {

private static final long serialVersionUID = 1L;
@Serial private static final long serialVersionUID = 1L;

private static final String ID_MAIN_PANEL = "mainPanel";
private static final Trace LOGGER = TraceManager.getTrace(FocusHistoryPanel.class);
Expand All @@ -84,63 +87,16 @@ protected void onInitialize() {

protected void initLayout() {
AuditLogViewerPanel panel = new AuditLogViewerPanel(ID_MAIN_PANEL, getPanelConfiguration()) {
private static final long serialVersionUID = 1L;
@Serial private static final long serialVersionUID = 1L;

@Override
protected List<IColumn<SelectableBean<AuditEventRecordType>, String>> createDefaultColumns() {
List<IColumn<SelectableBean<AuditEventRecordType>, String>> columns = super.createDefaultColumns();
if (isPreview()) {
return columns;
}
IColumn<SelectableBean<AuditEventRecordType>, String> column
= new AbstractColumn<>(new Model<>()) {

private static final long serialVersionUID = 1L;

@Override
public void populateItem(Item<ICellPopulator<SelectableBean<AuditEventRecordType>>> cellItem, String componentId,
IModel<SelectableBean<AuditEventRecordType>> rowModel) {

cellItem.add(new MultiButtonPanel<>(componentId, rowModel, 2) {

private static final long serialVersionUID = 1L;

@Override
protected Component createButton(int index, String componentId, IModel<SelectableBean<AuditEventRecordType>> model) {
AjaxIconButton btn = null;
switch (index) {
case 0:
btn = buildDefaultButton(componentId, new Model<>("fa fa-circle-o"),
createStringResource("ObjectHistoryTabPanel.viewHistoricalObjectDataTitle"),
new Model<>("btn btn-sm " + DoubleButtonColumn.ButtonColorClass.INFO),
target ->
currentStateButtonClicked(getObjectWrapper().getOid(),
unwrapModel(model).getEventIdentifier(),
getObjectWrapper().getCompileTimeClass(),
WebComponentUtil.getLocalizedDate(unwrapModel(model).getTimestamp(),
DateLabelComponent.SHORT_NOTIME_STYLE)));
btn.setVisibilityAllowed(isHistoryPageAuthorized());
break;
case 1:
btn = buildDefaultButton(componentId, new Model<>(GuiStyleConstants.CLASS_FILE_TEXT),
createStringResource("ObjectHistoryTabPanel.viewHistoricalObjectXmlTitle"),
new Model<>("btn btn-sm " + DoubleButtonColumn.ButtonColorClass.SUCCESS),
target ->
viewObjectXmlButtonClicked(getObjectWrapper().getOid(),
unwrapModel(model).getEventIdentifier(),
getObjectWrapper().getCompileTimeClass(),
WebComponentUtil.getLocalizedDate(unwrapModel(model).getTimestamp(),
DateLabelComponent.SHORT_NOTIME_STYLE)));
btn.setVisibilityAllowed(SecurityUtils.isPageAuthorized(PageXmlDataReview.class));
break;
}

return btn;
}
});
}
};

IColumn<SelectableBean<AuditEventRecordType>, String> column = createViewButtonsColumns();
columns.add(column);

return columns;
Expand Down Expand Up @@ -176,9 +132,57 @@ protected boolean isObjectHistoryPanel() {
add(panel);
}

protected void currentStateButtonClicked(String oid, String eventIdentifier, Class<F> type, String date) {
PrismObject<F> object = getReconstructedObject(oid, eventIdentifier, type);
private IColumn<SelectableBean<AuditEventRecordType>, String> createViewButtonsColumns() {
return new AbstractColumn<>(new Model<>()) {

@Serial private static final long serialVersionUID = 1L;

@Override
public void populateItem(Item<ICellPopulator<SelectableBean<AuditEventRecordType>>> cellItem, String componentId,
IModel<SelectableBean<AuditEventRecordType>> rowModel) {

cellItem.add(new MultiButtonPanel<>(componentId, rowModel, 2) {

@Serial private static final long serialVersionUID = 1L;

@Override
protected Component createButton(int index, String componentId, IModel<SelectableBean<AuditEventRecordType>> model) {
AjaxIconButton btn = null;
switch (index) {
case 0 -> {
btn = buildDefaultButton(componentId, new Model<>("fa fa-circle-o"),
createStringResource("ObjectHistoryTabPanel.viewHistoricalObjectDataTitle"),
new Model<>("btn btn-sm " + DoubleButtonColumn.ButtonColorClass.INFO),
target ->
currentStateButtonClicked(getObjectWrapper().getOid(),
unwrapModel(model).getEventIdentifier(),
getObjectWrapper().getCompileTimeClass(),
WebComponentUtil.getLocalizedDate(unwrapModel(model).getTimestamp(),
DateLabelComponent.SHORT_NOTIME_STYLE)));
btn.setVisibilityAllowed(isHistoryPageAuthorized());
}
case 1 -> {
btn = buildDefaultButton(componentId, new Model<>(GuiStyleConstants.CLASS_FILE_TEXT),
createStringResource("ObjectHistoryTabPanel.viewHistoricalObjectXmlTitle"),
new Model<>("btn btn-sm " + DoubleButtonColumn.ButtonColorClass.SUCCESS),
target ->
viewObjectXmlButtonClicked(getObjectWrapper().getOid(),
unwrapModel(model).getEventIdentifier(),
getObjectWrapper().getCompileTimeClass(),
WebComponentUtil.getLocalizedDate(unwrapModel(model).getTimestamp(),
DateLabelComponent.SHORT_NOTIME_STYLE)));
btn.setVisibilityAllowed(SecurityUtils.isPageAuthorized(PageXmlDataReview.class));
}
}

return btn;
}
});
}
};
}

protected void currentStateButtonClicked(String oid, String eventIdentifier, Class<F> type, String date) {
//TODO fix sessionStorage
getPageBase().getSessionStorage().setObjectDetailsStorage("details" + type.getSimpleName(), null);

Expand All @@ -187,35 +191,17 @@ protected void currentStateButtonClicked(String oid, String eventIdentifier, Cla
pageParameters.add(EID_PARAMETER_LABEL, eventIdentifier);
pageParameters.add(DATE_PARAMETER_LABEL, date);

Class<F> objectClass = null;
if (object != null) {
objectClass = object.getCompileTimeClass();
}
if (UserType.class.equals(objectClass)) {
if (UserType.class.equals(type)) {
getPageBase().navigateToNext(PageUserHistory.class, pageParameters);
} else if (RoleType.class.equals(objectClass)) {
} else if (RoleType.class.equals(type)) {
getPageBase().navigateToNext(PageRoleHistory.class, pageParameters);
} else if (OrgType.class.equals(objectClass)) {
} else if (OrgType.class.equals(type)) {
getPageBase().navigateToNext(PageOrgHistory.class, pageParameters);
} else if (ServiceType.class.equals(objectClass)) {
} else if (ServiceType.class.equals(type)) {
getPageBase().navigateToNext(PageServiceHistory.class, pageParameters);
}
}

private PrismObject<F> getReconstructedObject(String oid, String eventIdentifier,
Class<F> type) {
OperationResult result = new OperationResult(OPERATION_RESTRUCT_OBJECT);
try {
Task task = getPageBase().createSimpleTask(OPERATION_RESTRUCT_OBJECT);
return WebModelServiceUtils.reconstructObject(type, oid, eventIdentifier, task, result);
} catch (Exception ex) {
result.recordFatalError(getPageBase().createStringResource(
"ObjectHistoryTabPanel.message.getReconstructedObject.fatalError").getString(), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't restruct object", ex);
}
return null;
}

private void viewObjectXmlButtonClicked(String oid, String eventIdentifier, Class<F> type, String date) {
PageParameters pageParameters = new PageParameters();
pageParameters.add(OID_PARAMETER_LABEL, oid);
Expand All @@ -231,4 +217,10 @@ protected boolean isHistoryPageAuthorized() {
return SecurityUtils.isPageAuthorized(pageHistoryDetailsPage);
}

protected AuditEventRecordType unwrapModel(IModel<SelectableBean<AuditEventRecordType>> rowModel) {
if (rowModel == null || rowModel.getObject() == null) {
return null;
}
return rowModel.getObject().getValue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (C) 2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.web.application;

/**
* List of constants used to identify panels.
*/
public class PanelTypeConstants {

public static final String FOCUS_HISTORY_PANEL = "history";
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.impl.component.search.SearchContext;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
Expand Down Expand Up @@ -87,6 +89,13 @@ public AuditLogViewerPanel(String id, ContainerPanelConfigurationType configurat
super(id, AuditEventRecordType.class, configuration);
}

@Override
protected SearchContext createAdditionalSearchContext() {
SearchContext ctx = new SearchContext();
ctx.setHistory(isObjectHistoryPanel());
return ctx;
}

@Override
protected IColumn<SelectableBean<AuditEventRecordType>, String> createNameColumn(IModel<String> displayModel, GuiObjectColumnType customColumn, ExpressionType expression) {
if (displayModel == null || customColumn == null) {
Expand Down

0 comments on commit 1041cb9

Please sign in to comment.