Skip to content

Commit

Permalink
adding button simulation under shadow table panel on resource page
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Mar 20, 2023
1 parent ff76a99 commit dab7e41
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ private static <C extends Containerable> boolean isUseAsEmptyValue(Item item) {
}

private static <C extends Containerable> boolean isUseAsEmptyValue(Class<?> typeClass) {
return typeClass != null && AbstractSynchronizationActionType.class.isAssignableFrom(typeClass);
return typeClass != null &&
(AbstractSynchronizationActionType.class.isAssignableFrom(typeClass)
|| ActivitySimulationResultDefinitionType.class.isAssignableFrom(typeClass));
}

public static <C extends Containerable> PrismContainerValue<C> cleanupEmptyContainerValue(PrismContainerValue<C> value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import com.evolveum.midpoint.web.component.AjaxIconButton;
import com.evolveum.midpoint.web.component.data.BoxedTablePanel;
import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;

import com.evolveum.midpoint.web.model.ContainerValueWrapperFromObjectWrapperModel;
Expand Down Expand Up @@ -757,8 +758,30 @@ private Collection<? extends Component> createToolbarButtonsList(String buttonId

@Override
public void onClick(AjaxRequestTarget target) {
createReclassifyTask(target);
getShadowTable().startRefreshing(target);
IModel<String> confirmModel;
IModel<PrismContainerValueWrapper<ResourceObjectTypeDefinitionType>> objectType = getResourceObjectTypeValue(null);
if (objectType != null) {
ResourceObjectTypeDefinitionType value = objectType.getObject().getRealValue();
String objectTypeLabel = getPageBase().createStringResource(value.getKind()).getString()
+ "/" + value.getIntent();
confirmModel = getPageBase().createStringResource(
"ResourceCategorizedPanel.button.reclassify.confirmation.objectType",
objectTypeLabel);
} else {
confirmModel = getPageBase().createStringResource(
"ResourceCategorizedPanel.button.reclassify.confirmation.objectClass",
getObjectClass().getLocalPart());
}

ConfirmationPanel confirmationPanel = new ConfirmationPanel(getPageBase().getMainPopupBodyId(), confirmModel) {
@Override
public void yesPerformed(AjaxRequestTarget target) {
createReclassifyTask(target);
getShadowTable().startRefreshing(target);
target.add(getShadowTable());
}
};
getPageBase().showMainPopup(confirmationPanel, target);
}
};
reclassify.add(AttributeAppender.append("class", "btn btn-primary btn-sm mr-2"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ <h3 class="card-title">
<div wicket:id="import"/>
<div wicket:id="reconciliation"/>
<div wicket:id="liveSync"/>
<div wicket:id="simulation"/>
</div>
</div>
</wicket:panel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public abstract class ResourceContentPanel extends BasePanel<PrismObject<Resourc
private static final String ID_IMPORT = "import";
private static final String ID_RECONCILIATION = "reconciliation";
private static final String ID_LIVE_SYNC = "liveSync";
private static final String ID_SIMULATION = "simulation";
private static final String ID_TOTALS = "totals";

private final ShadowKindType kind;
Expand Down Expand Up @@ -309,26 +310,96 @@ public boolean isVisible() {

initButton(
ID_IMPORT,
"Import",
"ResourceContentPanel.button.import",
" fa-download",
SystemObjectsType.ARCHETYPE_IMPORT_TASK.value(),
taskButtonsContainer);
initButton(
ID_RECONCILIATION,
"Reconciliation",
"ResourceContentPanel.button.reconciliation",
" fa-link",
SystemObjectsType.ARCHETYPE_RECONCILIATION_TASK.value(),
taskButtonsContainer);
initButton(
ID_LIVE_SYNC,
"Live Sync",
"ResourceContentPanel.button.liveSync",
" fa-sync-alt",
SystemObjectsType.ARCHETYPE_LIVE_SYNC_TASK.value(),
taskButtonsContainer);

initSimulationButton(
ID_SIMULATION,
"ResourceContentPanel.button.simulation",
" fa-flask",
taskButtonsContainer);

initCustomLayout();
}

private void initSimulationButton(String id, String label, String icon, WebMarkupContainer taskButtonsContainer) {
List<InlineMenuItem> items = new ArrayList<>();

InlineMenuItem item = new InlineMenuItem(getPageBase().createStringResource("ResourceContentPanel.button.simulation.import")) {
private static final long serialVersionUID = 1L;

@Override
public InlineMenuItemAction initAction() {
return new InlineMenuItemAction() {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
newTaskPerformed(target, SystemObjectsType.ARCHETYPE_IMPORT_TASK.value(), true);
}
};
}
};
items.add(item);

item = new InlineMenuItem(getPageBase().createStringResource("ResourceContentPanel.button.simulation.reconciliation")) {
private static final long serialVersionUID = 1L;

@Override
public InlineMenuItemAction initAction() {
return new InlineMenuItemAction() {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
newTaskPerformed(target, SystemObjectsType.ARCHETYPE_RECOMPUTATION_TASK.value(), true);
}
};
}
};
items.add(item);

item = new InlineMenuItem(getPageBase().createStringResource("ResourceContentPanel.button.simulation.liveSync")) {
private static final long serialVersionUID = 1L;

@Override
public InlineMenuItemAction initAction() {
return new InlineMenuItemAction() {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
newTaskPerformed(target, SystemObjectsType.ARCHETYPE_LIVE_SYNC_TASK.value(), true);
}
};
}
};
items.add(item);

DropdownButtonPanel button = new DropdownButtonPanel(id,
new DropdownButtonDto(null, icon, getString(label), items)) {
@Override
protected String getSpecialDropdownMenuClass() {
return "dropdown-menu-left";
}
};
taskButtonsContainer.add(button);
}

protected Collection<? extends Component> createToolbarButtonsList(String buttonId) {
return new ArrayList<>();
}
Expand Down Expand Up @@ -393,15 +464,15 @@ public InlineMenuItemAction initAction() {

@Override
public void onClick(AjaxRequestTarget target) {
newTaskPerformed(target, archetypeOid);
newTaskPerformed(target, archetypeOid, false);
}
};
}
};
items.add(item);

DropdownButtonPanel button = new DropdownButtonPanel(id,
new DropdownButtonDto(String.valueOf(tasksList.size()), icon, label, items)) {
new DropdownButtonDto(String.valueOf(tasksList.size()), icon, getString(label), items)) {
@Override
protected String getSpecialDropdownMenuClass() {
return "dropdown-menu-left";
Expand All @@ -411,14 +482,21 @@ protected String getSpecialDropdownMenuClass() {

}

private void newTaskPerformed(AjaxRequestTarget target, String archetypeOid) {
private void newTaskPerformed(AjaxRequestTarget target, String archetypeOid, boolean isSimulation) {
List<ObjectReferenceType> archetypeRef = Arrays.asList(
new ObjectReferenceType()
.oid(archetypeOid)
.type(ArchetypeType.COMPLEX_TYPE));
try {
TaskType newTask = ResourceTasksPanel.createResourceTask(getPrismContext(), getResourceModel().getObject(), archetypeRef);

if (isSimulation) {
newTask.getActivity().beginExecution()
.mode(ExecutionModeType.SHADOW_MANAGEMENT_PREVIEW)
.beginConfigurationToUse().predefined(PredefinedConfigurationType.DEVELOPMENT);
newTask.getActivity().beginReporting().beginSimulationResult();
}

WebComponentUtil.initNewObjectWithReference(getPageBase(), newTask, archetypeRef);
} catch (SchemaException ex) {
getPageBase().getFeedbackMessages().error(ResourceContentPanel.this, ex.getUserFriendlyMessage());
Expand Down

0 comments on commit dab7e41

Please sign in to comment.