Skip to content

Commit

Permalink
fix bugs from testing
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed May 31, 2021
1 parent f3bb1ef commit d5b2cf7
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 128 deletions.
Expand Up @@ -15,8 +15,10 @@
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.prism.wrapper.*;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.task.api.Task;
Expand Down Expand Up @@ -88,7 +90,6 @@ public class PageReport extends PageAdminObjectDetails<ReportType> {

private Boolean runReport = false;
private IModel<Boolean> isShowingPreview = Model.of(Boolean.FALSE);
private IModel<DisplayableValue<String>> archetypeOid;

public PageReport() {
initialize(null);
Expand All @@ -111,18 +112,6 @@ public PageReport(final PrismObject<ReportType> unitToEdit, boolean isNewObject,
initialize(unitToEdit, isNewObject, isReadonly);
}

@Override
protected void initializeModel(PrismObject<ReportType> objectToEdit, boolean isNewObject, boolean isReadonly) {
super.initializeModel(objectToEdit, isNewObject, isReadonly);
ReportType report = getObjectModel().getObject().getObject().asObjectable();
archetypeOid = new Model();
if (WebComponentUtil.hasArchetypeAssignment(report, SystemObjectsType.ARCHETYPE_COLLECTION_REPORT.value())) {
archetypeOid.setObject(getDisplayValue(SystemObjectsType.ARCHETYPE_COLLECTION_REPORT.value()));
} else if (WebComponentUtil.hasArchetypeAssignment(report, SystemObjectsType.ARCHETYPE_DASHBOARD_REPORT.value())) {
archetypeOid.setObject(getDisplayValue(SystemObjectsType.ARCHETYPE_DASHBOARD_REPORT.value()));
}
}

@Override
protected void initLayout() {
super.initLayout();
Expand All @@ -142,15 +131,6 @@ protected void initLayout() {
tableBox.add(reportTable);
}

private SearchValue<String> getDisplayValue(String oid) {
for (DisplayableValue<String> value : TYPE_OF_REPORTS) {
if (oid.equals(value.getValue())) {
return (SearchValue<String>) value;
}
}
return null;
}

@Override
public Class<ReportType> getCompileTimeClass() {
return ReportType.class;
Expand Down Expand Up @@ -253,37 +233,10 @@ protected boolean isChangeArchetypeAllowed() {

@Override
protected void initOperationalButtons(RepeatingView repeatingView) {
String selectHeaderId = repeatingView.newChildId();
String selectTypeId = repeatingView.newChildId();
String refreshId = repeatingView.newChildId();
String showPreviewId = repeatingView.newChildId();
String showPreviewInPopupId = repeatingView.newChildId();

Label label = new Label(selectHeaderId, createStringResource("PageReport.typeOfReport"));
label.add(AttributeAppender.append("style", "padding-right: 0px; padding-top: 4px;"));
label.add(new VisibleBehaviour(() -> archetypeOid.getObject() == null || archetypeOid.getObject().getValue() == null));
repeatingView.add(label);

DropDownChoicePanel dropDownPanel = WebComponentUtil.createDropDownChoices(selectTypeId, archetypeOid, Model.ofList(TYPE_OF_REPORTS), true, this);
dropDownPanel.add(new VisibleBehaviour(() -> archetypeOid.getObject() == null || archetypeOid.getObject().getValue() == null));
dropDownPanel.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
addArchetype(target);
target.add(dropDownPanel);
target.add(repeatingView.get(showPreviewInPopupId));
target.add(repeatingView.get(showPreviewId));
target.add(getOperationalButtonsPanel());
refreshEngineTab(target);
target.add(getMainPanel().getTabbedPanel());
target.add(getMainPanel());
target.add(getFeedbackPanel());
}
});
dropDownPanel.add(AttributeAppender.append("style", "margin-top: -7px; margin-left: -12px;"));
dropDownPanel.setOutputMarkupId(true);
repeatingView.add(dropDownPanel);

AjaxButton refresh = new AjaxButton(refreshId, createStringResource("pageCreateCollectionReport.button.refresh")) {
@Override
public void onClick(AjaxRequestTarget target) {
Expand Down Expand Up @@ -444,41 +397,6 @@ private static void runConfirmPerformed(AjaxRequestTarget target, ReportType rep
target.add(pageBase.getFeedbackPanel());
}

private void refreshEngineTab(AjaxRequestTarget target) {
Component panel = getMainPanel().getTabbedPanel().get(TabbedPanel.TAB_PANEL_ID);
if (panel instanceof EngineReportTabPanel) {
((PanelTab) getMainPanel().getTabbedPanel().getTabs().getObject().get(
getMainPanel().getTabbedPanel().getSelectedTab())).resetPanel();
getMainPanel().getTabbedPanel().setSelectedTab(getMainPanel().getTabbedPanel().getSelectedTab());
target.add(getMainPanel().getTabbedPanel());
target.add(getMainPanel());
}
}

private void addArchetype(AjaxRequestTarget target) {
WebComponentUtil.addNewArchetype(getObjectWrapper(), archetypeOid.getObject().getValue(), target, PageReport.this);
PrismObjectWrapperFactory<ReportType> wrapperFactory = findObjectWrapperFactory(getReport().asPrismObject().getDefinition());
Task task = createSimpleTask(OPERATION_UPDATE_WRAPPER);
OperationResult result = task.getResult();
WrapperContext ctx = new WrapperContext(task, result);
try {
wrapperFactory.updateWrapper(getObjectWrapper(), ctx);

//TODO ugly hack: after updateWrapper method is called, previously set assignment item
// are marked as NOT_CHANGED with the same value.

PrismContainerWrapper<AssignmentType> assignmentWrapper = getObjectWrapper().findContainer(ItemPath.create(TaskType.F_ASSIGNMENT));
for (PrismContainerValueWrapper<AssignmentType> assignmentWrapperValue : assignmentWrapper.getValues()) {
if (WebComponentUtil.isArchetypeAssignment(assignmentWrapperValue.getRealValue())) {
assignmentWrapperValue.setStatus(ValueStatus.ADDED);
}
}

} catch (SchemaException e) {
LOGGER.error("Unexpected problem occurs during updating wrapper. Reason: {}", e.getMessage(), e);
}
}

private ReportType getReport() {
return getObjectWrapper().getObject().asObjectable();
}
Expand All @@ -489,10 +407,7 @@ protected Boolean isOperationalButtonsVisible() {
}

private boolean isCollectionReport() {
if (archetypeOid.getObject() != null) {
return SystemObjectsType.ARCHETYPE_COLLECTION_REPORT.value().equals(archetypeOid.getObject().getValue());
}
return false;
return getObjectWrapper().findItemDefinition(ReportType.F_OBJECT_COLLECTION) != null;
}

private ReportObjectsListPanel getReportTable() {
Expand All @@ -506,5 +421,4 @@ private Component getTableBox() {
private Component getTableContainer() {
return get(ID_TABLE_CONTAINER);
}

}
Expand Up @@ -13,9 +13,10 @@
import com.evolveum.midpoint.web.component.ObjectBasicPanel;
import com.evolveum.midpoint.web.component.prism.ItemVisibility;
import com.evolveum.midpoint.web.model.PrismContainerWrapperModel;
import com.evolveum.midpoint.web.page.admin.reports.PageReport;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;

/**
Expand All @@ -32,9 +33,10 @@ public EngineReportTabPanel(String id, IModel<PrismObjectWrapper<ReportType>> mo

@Override
protected void initLayout() {

if (WebComponentUtil.hasArchetypeAssignment(getReport(), SystemObjectsType.ARCHETYPE_DASHBOARD_REPORT.value())) {
add(new SingleContainerPanel(ID_PANEL, PrismContainerWrapperModel.fromContainerWrapper(
RepeatingView panel = new RepeatingView(ID_PANEL);
add(panel);
if (hasDefinition(ReportType.F_DASHBOARD)) {
panel.add(new SingleContainerPanel(panel.newChildId(), PrismContainerWrapperModel.fromContainerWrapper(
getModel(), ItemPath.create(ReportType.F_DASHBOARD)), DashboardReportEngineConfigurationType.COMPLEX_TYPE) {
@Override
protected ItemVisibility getVisibility(ItemWrapper itemWrapper) {
Expand All @@ -45,8 +47,9 @@ protected ItemVisibility getVisibility(ItemWrapper itemWrapper) {
return super.getVisibility(itemWrapper);
}
});
} else if(WebComponentUtil.hasArchetypeAssignment(getReport(), SystemObjectsType.ARCHETYPE_COLLECTION_REPORT.value())) {
add(new SingleContainerPanel(ID_PANEL, PrismContainerWrapperModel.fromContainerWrapper(
}
if(hasDefinition(ReportType.F_OBJECT_COLLECTION)) {
panel.add(new SingleContainerPanel(panel.newChildId(), PrismContainerWrapperModel.fromContainerWrapper(
getModel(), ItemPath.create(ReportType.F_OBJECT_COLLECTION)), ObjectCollectionReportEngineConfigurationType.COMPLEX_TYPE) {
@Override
protected ItemVisibility getVisibility(ItemWrapper itemWrapper) {
Expand All @@ -57,13 +60,10 @@ protected ItemVisibility getVisibility(ItemWrapper itemWrapper) {
return super.getVisibility(itemWrapper);
}
});
} else {
warn(getPageBase().createStringResource("PageReport.message.selectTypeOfReport").getString());
add(new WebMarkupContainer(ID_PANEL));
}
}

private ReportType getReport() {
return getModelObject().getObject().asObjectable();
private boolean hasDefinition(ItemPath path){
return getModelObject().findItemDefinition(path) != null;
}
}
Expand Up @@ -23,6 +23,7 @@
import com.evolveum.midpoint.gui.impl.prism.panel.SingleContainerPanel;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismContainerDefinition;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
Expand Down Expand Up @@ -169,6 +170,12 @@ protected ItemVisibility getBasicTabVisibility(ItemWrapper<?, ?> itemWrapper) {
public WebMarkupContainer createPanel(String panelId) {
return new EngineReportTabPanel(panelId, getObjectModel());
}

@Override
public boolean isVisible() {
return hasDefinitionFor(ReportType.F_OBJECT_COLLECTION)
|| hasDefinitionFor(ReportType.F_DASHBOARD) ;
}
});
tabs.addAll(createTabsForCollectionReports());
tabs.addAll(createTabsForDashboardReports());
Expand All @@ -195,19 +202,8 @@ protected ItemVisibility getVisibility(ItemWrapper itemWrapper) {
return tabs;
}

private List<ITab> createTabs() {

if (WebComponentUtil.hasArchetypeAssignment(getReport(), SystemObjectsType.ARCHETYPE_COLLECTION_REPORT.value())) {
return createTabsForCollectionReports();
} else if (WebComponentUtil.hasArchetypeAssignment(getReport(), SystemObjectsType.ARCHETYPE_DASHBOARD_REPORT.value())) {
return createTabsForDashboardReports();
}
warn(getPageBase().createStringResource("PageReport.message.selectTypeOfReport").getString());
return Collections.EMPTY_LIST;
}

private ReportType getReport() {
return getObjectModel().getObject().getObject().asObjectable();
private boolean hasDefinitionFor(ItemPath path){
return getObjectModel().getObject().findItemDefinition(path) != null;
}

private List<ITab> createTabsForDashboardReports() {
Expand All @@ -223,7 +219,7 @@ public WebMarkupContainer createPanel(String panelId) {

@Override
public boolean isVisible() {
return WebComponentUtil.hasArchetypeAssignment(getReport(), SystemObjectsType.ARCHETYPE_DASHBOARD_REPORT.value());
return hasDefinitionFor(ItemPath.create(ReportType.F_DASHBOARD, DashboardReportEngineConfigurationType.F_VIEW));
}
});

Expand All @@ -243,7 +239,10 @@ public WebMarkupContainer createPanel(String panelId) {

@Override
public boolean isVisible() {
return WebComponentUtil.hasArchetypeAssignment(getReport(), SystemObjectsType.ARCHETYPE_COLLECTION_REPORT.value());
if (hasDefinitionFor(ReportType.F_OBJECT_COLLECTION)) {

}
return false;
}
});

Expand All @@ -266,7 +265,7 @@ public WebMarkupContainer createPanel(String panelId) {

@Override
public boolean isVisible() {
return WebComponentUtil.hasArchetypeAssignment(getReport(), SystemObjectsType.ARCHETYPE_COLLECTION_REPORT.value());
return hasDefinitionFor(ItemPath.create(ReportType.F_OBJECT_COLLECTION, ObjectCollectionReportEngineConfigurationType.F_VIEW));
}
});

Expand All @@ -279,7 +278,7 @@ public WebMarkupContainer createPanel(String panelId) {

@Override
public boolean isVisible() {
return WebComponentUtil.hasArchetypeAssignment(getReport(), SystemObjectsType.ARCHETYPE_COLLECTION_REPORT.value());
return hasDefinitionFor(ItemPath.create(ReportType.F_OBJECT_COLLECTION, ObjectCollectionReportEngineConfigurationType.F_PARAMETER));
}
});

Expand All @@ -292,7 +291,7 @@ public WebMarkupContainer createPanel(String panelId) {

@Override
public boolean isVisible() {
return WebComponentUtil.hasArchetypeAssignment(getReport(), SystemObjectsType.ARCHETYPE_COLLECTION_REPORT.value());
return hasDefinitionFor(ItemPath.create(ReportType.F_OBJECT_COLLECTION, ObjectCollectionReportEngineConfigurationType.F_SUBREPORT));
}
});

Expand Down
Expand Up @@ -75,8 +75,15 @@ private void initView() {
Task task = getPageBase().createSimpleTask("create compiled view");
view = getPageBase().getReportManager().createCompiledView(getReport().getObjectCollection(), true, task, task.getResult());
} catch (Exception e) {
LOGGER.error("Couldn't create compiled view for report " + getReport(), e);
LOGGER.debug("Couldn't create compiled view for report " + getReport(), e);
}
if (checkViewAfterInicialize()) {
checkView();
}
}

protected boolean checkViewAfterInicialize() {
return false;
}

private ReportType getReport() {
Expand Down
Expand Up @@ -95,10 +95,20 @@ protected void initLayout() {

FeedbackAlerts feedback = new FeedbackAlerts(ID_POPUP_FEEDBACK);
ReportObjectsListPanel table = new ReportObjectsListPanel(ID_TABLE, getModel()){

private final boolean checkViewAfterInitialize = true;
@Override
protected Component getFeedbackPanel() {
return feedback;
}

@Override
protected boolean checkViewAfterInicialize() {
if (checkViewAfterInitialize) {
return true;
}
return super.checkViewAfterInicialize();
}
};
table.setOutputMarkupId(true);
mainForm.add(table);
Expand Down
Expand Up @@ -87,15 +87,8 @@ private ResolutionContext getInitialResolveContextFromVariable() throws Expressi
return IdiResolutionContext.fromAnyObject(variableValue);
} else if (variableValue instanceof PrismValue) {
return new ValueResolutionContext((PrismValue) variableValue, context.getContextDescription());
} else if (!(variableValue instanceof Containerable) && variableValueAndDefinition.getTypeClass().isAssignableFrom(variableValue.getClass())) {
V prismValue;
if (variableValue instanceof Referencable){
prismValue = (V) evaluator.getPrismContext().itemFactory().createReferenceValue(((Referencable) variableValue).getOid(), ((Referencable) variableValue).getType());
((PrismReferenceValue)prismValue).setRelation(((Referencable)variableValue).getRelation());
} else {
prismValue = (V) evaluator.getPrismContext().itemFactory().createPropertyValue(variableValue);
}
return new ValueResolutionContext(prismValue, context.getContextDescription());
} else if (variableValueAndDefinition.getTypeClass().isAssignableFrom(variableValue.getClass())) {
return ValueResolutionContext.fromRealValue(variableValue, context.getContextDescription(), evaluator.getPrismContext());
} else {
throw new ExpressionEvaluationException("Unexpected variable value "+variableValue+" ("+variableValue.getClass()+")");
}
Expand Down
Expand Up @@ -84,4 +84,16 @@ ResolutionContext resolveStructuredProperty(ItemPath pathToResolve, PrismPropert
boolean isNull() {
return false;
}

public static ResolutionContext fromRealValue(Object variableValue, String contextDescription, PrismContext prismContext) {
PrismValue prismValue;
if (variableValue instanceof Referencable){
prismValue = ((Referencable) variableValue).asReferenceValue();
} else if (variableValue instanceof Containerable){
prismValue = ((Containerable) variableValue).asPrismContainerValue();
} else {
prismValue = prismContext.itemFactory().createPropertyValue(variableValue);
}
return new ValueResolutionContext(prismValue, contextDescription);
}
}
Expand Up @@ -21,6 +21,15 @@ protected File getSystemConfigurationFile() {
return SYSTEM_CONFIGURATION_SAFE_FILE;
}

@Test( expectedExceptions = { AssertionError.class }, priority = 102)
public void test102CreateAuditCollectionReportWithView() throws Exception {
super.test102CreateAuditCollectionReportWithView();
}
@Test( expectedExceptions = { AssertionError.class }, priority = 103)
public void test103CreateAuditCollectionReportWithDoubleView() throws Exception {
super.test103CreateAuditCollectionReportWithDoubleView();
}

@Test( expectedExceptions = { AssertionError.class }, priority = 200)
public void test200ImportReportForUser() throws Exception {
super.test200ImportReportForUser();
Expand Down

0 comments on commit d5b2cf7

Please sign in to comment.