Skip to content

Commit

Permalink
Fix the DB upgrade script
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Feb 1, 2023
2 parents 9eef54b + c3dd4fd commit 050861d
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 20 deletions.
2 changes: 1 addition & 1 deletion config/sql/native-new/postgres-new-upgrade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ $aa$);
call apply_change(12, $aa$
do $$
begin
ALTER TYPE ObjectType ADD VALUE IF NOT EXISTS 'SIMULATION_RESULT' AFTER 'SHADOW';
-- Temporary code, to migrate from TagType to MarkType
if 'TAG'::name = any(enum_range(null::ObjectType)::name[]) then
ALTER TYPE ObjectType RENAME VALUE 'TAG' TO 'MARK';
Expand All @@ -182,6 +181,7 @@ call apply_change(12, $aa$
ALTER TYPE ObjectType ADD VALUE IF NOT EXISTS 'MARK' AFTER 'SYSTEM_CONFIGURATION';
ALTER TYPE ReferenceType ADD VALUE IF NOT EXISTS 'PROCESSED_OBJECT_EVENT_MARK' AFTER 'PROJECTION';
end if;
ALTER TYPE ObjectType ADD VALUE IF NOT EXISTS 'SIMULATION_RESULT' AFTER 'SHADOW';
ALTER TYPE ContainerType ADD VALUE IF NOT EXISTS 'SIMULATION_RESULT_PROCESSED_OBJECT' AFTER 'OPERATION_EXECUTION';
end
$$;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@ public StringResourceModel createStringResource(Enum e, String prefix, String nu
return createStringResource(sb.toString());
}

public String getString(Enum<?> e) {
return createStringResource(e).getString();
}

public String getString(String resourceKey, Object... objects) {
return createStringResource(resourceKey, objects).getString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
Expand All @@ -28,21 +30,23 @@
import com.evolveum.midpoint.authentication.api.authorization.AuthorizationAction;
import com.evolveum.midpoint.authentication.api.authorization.PageDescriptor;
import com.evolveum.midpoint.authentication.api.authorization.Url;
import com.evolveum.midpoint.gui.api.component.Badge;
import com.evolveum.midpoint.gui.api.component.wizard.NavigationPanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.gui.impl.component.box.SmallBoxData;
import com.evolveum.midpoint.gui.impl.page.admin.simulation.widget.MetricWidgetPanel;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.impl.PrismPropertyValueImpl;
import com.evolveum.midpoint.schema.util.ValueDisplayUtil;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.admin.PageAdmin;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DashboardWidgetType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SimulationMetricValuesType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SimulationResultType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

/**
* Created by Viliam Repan (lazyman).
Expand Down Expand Up @@ -120,14 +124,21 @@ public Component createValueComponent(String id) {

@Override
public Component createValueComponent(String id) {
return new Label(id); // todo task status badge. Green if running and endTimestamp is not defined, Gray otherwise
return createTaskStateLabel(id, resultModel, PageSimulationResult.this);
}
});
list.add(new ResultDetail("PageSimulationResult.productionConfiguration", null) {

@Override
public Component createValueComponent(String id) {
Label label = new Label(id);
Label label = new Label(id, () -> {
ConfigurationSpecificationType specification = resultModel.getObject().getConfigurationUsed();
if (specification == null || BooleanUtils.isNotFalse(specification.isProductionConfiguration())) {
return getString("PageSimulationResult.production");
}

return getString("PageSimulationResult.development");
});
label.add(AttributeModifier.replace("class", "badge badge-success"));
return label;
}
Expand Down Expand Up @@ -232,4 +243,39 @@ public Component createValueComponent(String id) {
return label;
}
}

public static Component createTaskStateLabel(String id, IModel<SimulationResultType> model, PageBase page) {
IModel<TaskExecutionStateType> stateModel = () -> {
SimulationResultType result = model.getObject();
if (result == null || result.getRootTaskRef() == null) {
return null;
}

PrismObject<TaskType> task = WebModelServiceUtils.loadObject(result.getRootTaskRef(), page);
return task != null ? task.asObjectable().getExecutionState() : null;
};

Label label = new Label(id, () -> {
if (model.getObject().getEndTimestamp() != null) {
return null;
}

TaskExecutionStateType state = stateModel.getObject();
if (state == null) {
return null;
}

return page.getString(state);
});
label.add(AttributeAppender.replace("class", () -> {
TaskExecutionStateType state = stateModel.getObject();
if (state == TaskExecutionStateType.RUNNABLE || state == TaskExecutionStateType.RUNNING) {
return Badge.State.SUCCESS.getCss();
}

return Badge.State.SECONDARY.getCss();
}));

return label;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public PageSimulationResultObject(PageParameters parameters) {
initLayout();
}

@Override
protected void createBreadcrumb() {
}

private void initModels() {
resultModel = new LoadableDetachableModel<>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ protected List<MarkType> load() {
};
}

@Override
protected void createBreadcrumb() {
}

@Override
protected IModel<String> createPageTitleModel() {
return () -> null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,5 @@ protected IModel<String> createPageTitleModel() {

@Override
protected void createBreadcrumb() {
addBreadcrumb(new Breadcrumb(super.getPageTitleModel(), this.getClass(), getPageParameters()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,18 @@

package com.evolveum.midpoint.gui.impl.page.admin.simulation;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import javax.xml.datatype.XMLGregorianCalendar;

import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.util.MiscUtil;

import org.apache.commons.lang3.time.DurationFormatUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.LambdaColumn;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
Expand All @@ -34,6 +27,7 @@
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.web.component.data.column.ColumnMenuAction;
import com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem;
Expand Down Expand Up @@ -89,7 +83,7 @@ public InlineMenuItemAction initAction() {
@Override
public void onClick(AjaxRequestTarget target) {
SelectableBean<SimulationResultType> bean = getRowModel().getObject();
listProcessedObjectsPerformed(target, bean.getValue());
listProcessedObjectsPerformed(bean.getValue());
}
};
}
Expand Down Expand Up @@ -134,25 +128,25 @@ protected List<IColumn<SelectableBean<SimulationResultType>, String>> createDefa
}

long duration = end.toGregorianCalendar().getTimeInMillis() - start.toGregorianCalendar().getTimeInMillis();
if (duration < 0) {
return null;
}

return DurationFormatUtils.formatDurationWords(duration, true, true);
}));
columns.add(new AbstractColumn<>(createStringResource("ProcessedObjectsPanel.executionState")) {

@Override
public void populateItem(Item<ICellPopulator<SelectableBean<SimulationResultType>>> item, String id, IModel<SelectableBean<SimulationResultType>> model) {
Label label = new Label(id, () -> {
return "running"; // todo viliam
});
label.add(AttributeAppender.replace("class", () -> "badge badge-success")); // todo viliam
Component label = PageSimulationResult.createTaskStateLabel(id, () -> model.getObject().getValue(), getPageBase());
item.add(label);
}
});

return columns;
}

private void listProcessedObjectsPerformed(AjaxRequestTarget target, SimulationResultType object) {
private void listProcessedObjectsPerformed(SimulationResultType object) {
PageParameters params = new PageParameters();
params.set(SimulationPage.PAGE_PARAMETER_RESULT_OID, object.getOid());

Expand Down

0 comments on commit 050861d

Please sign in to comment.