Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Mar 27, 2023
2 parents 7b8e56c + f3299b9 commit 4c206ae
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void setObject(ObjectTypes object) {
this.multiselect = multiselect;
}

@Override
protected void onInitialize(){
super.onInitialize();
initLayout();
Expand Down Expand Up @@ -163,8 +164,7 @@ protected void onUpdate(AjaxRequestTarget target) {
ObjectListPanel<O> listPanel = createObjectListPanel(objType, multiselect);
add(listPanel);

AjaxButton addButton = new AjaxButton(ID_BUTTON_ADD,
createStringResource("userBrowserDialog.button.addButton")) {
AjaxButton addButton = new AjaxButton(ID_BUTTON_ADD, getAddButtonTitle()) {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -288,4 +288,8 @@ public Component getContent() {
public StringResourceModel getTitle() {
return parentPage.createStringResource("ObjectBrowserPanel.chooseObject");
}

protected StringResourceModel getAddButtonTitle() {
return createStringResource("userBrowserDialog.button.addButton");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ protected IColumn<PO, String> createCustomExportableColumn(IModel<String> column
return new ConfigurableExpressionColumn<>(columnDisplayModel, getSortProperty(customColumn, expression), customColumn, expression, getPageBase());
}

private String getSortProperty(GuiObjectColumnType customColumn, ExpressionType expressionType) {
protected String getSortProperty(GuiObjectColumnType customColumn, ExpressionType expressionType) {
String sortProperty = customColumn.getSortProperty();
if (sortProperty != null) {
return sortProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
*/
package com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.objectType.synchronization;

import com.evolveum.midpoint.gui.api.prism.wrapper.ItemVisibilityHandler;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.impl.page.admin.resource.ResourceDetailsModel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.AbstractValueFormResourceWizardStepPanel;
import com.evolveum.midpoint.web.application.PanelDisplay;
import com.evolveum.midpoint.web.application.PanelInstance;
import com.evolveum.midpoint.web.component.prism.ItemVisibility;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand Down Expand Up @@ -68,4 +70,14 @@ protected IModel<?> getSubTextModel() {
public VisibleEnableBehaviour getBackBehaviour() {
return new VisibleBehaviour(() -> false);
}

@Override
protected ItemVisibilityHandler getVisibilityHandler() {
return wrapper -> {
if (wrapper.getItemName().equals(SynchronizationReactionType.F_LIFECYCLE_STATE)) {
return ItemVisibility.HIDDEN;
}
return ItemVisibility.AUTO;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
package com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.objectType.synchronization;

import com.evolveum.midpoint.gui.api.prism.wrapper.ItemVisibilityHandler;
import com.evolveum.midpoint.web.component.prism.ItemVisibility;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;

Expand Down Expand Up @@ -92,4 +95,14 @@ protected IModel<String> getSubmitLabelModel() {
public VisibleEnableBehaviour getNextBehaviour() {
return VisibleBehaviour.ALWAYS_INVISIBLE;
}

@Override
protected ItemVisibilityHandler getVisibilityHandler() {
return wrapper -> {
if (wrapper.getItemName().equals(SynchronizationReactionType.F_LIFECYCLE_STATE)) {
return ItemVisibility.HIDDEN;
}
return ItemVisibility.AUTO;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.ArrayList;
import java.util.List;

import com.evolveum.midpoint.gui.impl.component.data.column.ToggleSimulationModeColumn;

import org.apache.wicket.Component;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.model.IModel;
Expand Down Expand Up @@ -89,6 +91,8 @@ protected boolean validateChildContainer(ItemDefinition definition) {
}
});

columns.add(new ToggleSimulationModeColumn<>(getContainerModel(), getPageBase()));

return columns;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ private void processReferenceVariables(VariablesMap variablesMap) {

@Override
protected IColumn<SelectableBean<C>, String> createCustomExportableColumn(IModel<String> columnDisplayModel, GuiObjectColumnType customColumn, ExpressionType expression) {
return new ReportExpressionColumn<>(columnDisplayModel, null, customColumn, expression, getPageBase()) {
return new ReportExpressionColumn<>(columnDisplayModel, getSortProperty(customColumn, expression), customColumn, expression, getPageBase()) {

@Override
protected void processReportSpecificVariables(VariablesMap variablesMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,55 @@ public org.apache.wicket.model.StringResourceModel getTitle() {
}
});

items.add(new InlineMenuItem(createStringResource("pageContentAccounts.menu.mark.remove"), true) {
private static final long serialVersionUID = 1L;

@Override
public InlineMenuItemAction initAction() {
return new ColumnMenuAction<SelectableBean<ShadowType>>() {
private static final long serialVersionUID = 1L;

@Override
public void onSubmit(AjaxRequestTarget target) {

var selected = getSelectedShadowsList(getRowModel());
var selectedMarks = collectExistingMarks(selected);

ObjectFilter marksFilter = PrismContext.get().queryFor(MarkType.class)
.item(MarkType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF)
.ref(SystemObjectsType.ARCHETYPE_OBJECT_MARK.value())
.and()
.id(selectedMarks)
.buildFilter();

ObjectBrowserPanel<MarkType> browser = new ObjectBrowserPanel<>(
getPageBase().getMainPopupBodyId(), MarkType.class,
Collections.singletonList(MarkType.COMPLEX_TYPE), true, getPageBase(), marksFilter) {

protected void addPerformed(AjaxRequestTarget target, QName type, List<MarkType> selected) {
LOGGER.warn("Selected marks: {}", selected);

List<String> markOids = Lists.transform(selected, MarkType::getOid);
removeShadowMarks(getRowModel(), markOids, target);
super.addPerformed(target, type, selected);
}

public org.apache.wicket.model.StringResourceModel getTitle() {
return createStringResource("pageContentAccounts.menu.mark.select.remove");
}

protected org.apache.wicket.model.StringResourceModel getAddButtonTitle() {
return createStringResource("pageContentAccounts.menu.mark.remove");
};
};

getPageBase().showMainPopup(browser, target);
}

};
}
});

return items;
}

Expand Down Expand Up @@ -793,7 +842,7 @@ private <F extends FocusType> void setNewShadowOwner(F ownerToChange, Selectable
changeOwnerInternal(ownerToChange.getOid(), ownerToChange.getClass(), Collections.singletonList(delta), target);
}

private void markShadows(IModel<SelectableBean<ShadowType>> rowModel, List<String> markOids,
private void removeShadowMarks(IModel<SelectableBean<ShadowType>> rowModel, List<String> markOids,
AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_MARK_SHADOW);
Task task = getPageBase().createSimpleTask(OPERATION_MARK_SHADOW);
Expand All @@ -806,19 +855,70 @@ private void markShadows(IModel<SelectableBean<ShadowType>> rowModel, List<Strin
return;
}

for (SelectableBean<ShadowType> shadow : selected) {
List<PolicyStatementType> statements = new ArrayList<>();
// We recreate statements (can not reuse them between multiple objects - we can create new or clone
// but for each delta we need separate statement
for (String oid : markOids) {
statements.add(new PolicyStatementType().markRef(oid, MarkType.COMPLEX_TYPE)
.type(PolicyStatementTypeType.APPLY));
for (SelectableBean<ShadowType> shadow : selected) {
List<PolicyStatementType> statements = new ArrayList<>();
// We recreate statements (can not reuse them between multiple objects - we can create new or clone
// but for each delta we need separate statement

for (var statement : shadow.getValue().getPolicyStatement()) {
if (!PolicyStatementTypeType.APPLY.equals(statement.getType())) {
continue;
}
try {
var delta = getPageBase().getPrismContext().deltaFactory().object()
.createModificationAddContainer(ShadowType.class,
shadow.getValue().getOid(), ShadowType.F_POLICY_STATEMENT,
statements.toArray(new PolicyStatementType[0]));
if (markOids.contains(statement.getMarkRef().getOid())) {
statements.add(statement.clone());
}
}
try {
var delta = getPageBase().getPrismContext().deltaFactory().object()
.createModificationDeleteContainer(ShadowType.class,
shadow.getValue().getOid(), ShadowType.F_POLICY_STATEMENT,
statements.toArray(new PolicyStatementType[0]));
getPageBase().getModelService().executeChanges(MiscUtil.createCollection(delta), null, task, result);
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException
| ExpressionEvaluationException | CommunicationException | ConfigurationException
| PolicyViolationException | SecurityViolationException e) {
result.recordPartialError(
createStringResource(
"ResourceContentPanel.message.markShadowPerformed.partialError", shadow)
.getString(),
e);
LOGGER.error("Could not mark shadow {} with marks {}", shadow, markOids, e);
}
}

result.computeStatusIfUnknown();
getPageBase().showResult(result);
refreshTable(target);
target.add(getPageBase().getFeedbackPanel());
}


private void markShadows(IModel<SelectableBean<ShadowType>> rowModel, List<String> markOids,
AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_MARK_SHADOW);
Task task = getPageBase().createSimpleTask(OPERATION_MARK_SHADOW);

var selected = getSelectedShadowsList(rowModel);
if (selected == null || selected.isEmpty()) {
result.recordWarning(createStringResource("ResourceContentPanel.message.markShadowPerformed.warning").getString());
getPageBase().showResult(result);
target.add(getPageBase().getFeedbackPanel());
return;
}

for (SelectableBean<ShadowType> shadow : selected) {
List<PolicyStatementType> statements = new ArrayList<>();
// We recreate statements (can not reuse them between multiple objects - we can create new or clone
// but for each delta we need separate statement
for (String oid : markOids) {
statements.add(new PolicyStatementType().markRef(oid, MarkType.COMPLEX_TYPE)
.type(PolicyStatementTypeType.APPLY));
}
try {
var delta = getPageBase().getPrismContext().deltaFactory().object()
.createModificationAddContainer(ShadowType.class,
shadow.getValue().getOid(), ShadowType.F_POLICY_STATEMENT,
statements.toArray(new PolicyStatementType[0]));
getPageBase().getModelService().executeChanges(MiscUtil.createCollection(delta), null, task, result);
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException
| ExpressionEvaluationException | CommunicationException | ConfigurationException
Expand Down Expand Up @@ -892,6 +992,19 @@ private PrismObjectDefinition<FocusType> getFocusDefinition() {
.findObjectDefinitionByCompileTimeClass(FocusType.class);
}


private String[] collectExistingMarks(List<SelectableBean<ShadowType>> selected) {
Set<String> marks = new HashSet<>();
for (SelectableBean<ShadowType> shadow : selected) {
for (var statement : shadow.getValue().getPolicyStatement()) {
if (PolicyStatementTypeType.APPLY.equals(statement.getType())) {
marks.add(statement.getMarkRef().getOid());
}
}
}
return marks.toArray(new String[] {});
}

protected ModelExecuteOptions createModelExecuteOptions() {
return null;
}
Expand Down

0 comments on commit 4c206ae

Please sign in to comment.