Skip to content

Commit

Permalink
adding wizard steps for synchronization of resource object type
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Sep 25, 2022
1 parent 06e83dc commit 7cc5475
Show file tree
Hide file tree
Showing 21 changed files with 902 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,28 @@ public static <C extends Containerable> void cleanupEmptyContainers(PrismContain
PrismContainerValue<C> value = valueIterator.next();

PrismContainerValue<C> valueAfter = cleanupEmptyContainerValue(value);
if (isUseAsEmptyValue(valueAfter)) {
continue;
}
if (valueAfter == null || valueAfter.isIdOnly() || valueAfter.isEmpty()) {
valueIterator.remove();
}
}
}

//TODO quick hack ... use for it wrappers
private static <C extends Containerable> boolean isUseAsEmptyValue(PrismContainerValue<C> valueAfter) {
return valueAfter != null && isUseAsEmptyValue(valueAfter.getRealClass());
}

private static <C extends Containerable> boolean isUseAsEmptyValue(Item item) {
return item != null && isUseAsEmptyValue(item.getDefinition().getTypeClass());
}

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

public static <C extends Containerable> PrismContainerValue<C> cleanupEmptyContainerValue(PrismContainerValue<C> value) {
Collection<Item<?, ?>> items = value.getItems();

Expand All @@ -196,13 +212,13 @@ public static <C extends Containerable> PrismContainerValue<C> cleanupEmptyConta
Item<?, ?> item = iterator.next();

cleanupEmptyValues(item);
if (item.isEmpty()) {
if (!isUseAsEmptyValue(item) && item.isEmpty()) {
iterator.remove();
}
}
}

if (value.getItems() == null || value.getItems().isEmpty()) {
if (!isUseAsEmptyValue(value) && (value.getItems() == null || value.getItems().isEmpty())) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.evolveum.midpoint.gui.impl.component.input;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.util.DisplayableValue;

import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType;
Expand All @@ -26,9 +27,9 @@
*/
public class AutoCompleteDisplayableValueConverter<T> implements IConverter<T> {

private final IModel<List<DisplayableValue<T>>> values;
private final IModel<? extends List<DisplayableValue<T>>> values;

public AutoCompleteDisplayableValueConverter(IModel<List<DisplayableValue<T>>> values) {
public AutoCompleteDisplayableValueConverter(IModel<? extends List<DisplayableValue<T>>> values) {
this.values = values;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Collection;
import java.util.List;

import com.evolveum.midpoint.gui.api.component.result.Toast;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
Expand All @@ -20,12 +19,10 @@
import com.evolveum.midpoint.gui.impl.page.admin.assignmentholder.PageAssignmentHolderDetails;
import com.evolveum.midpoint.gui.impl.page.admin.component.ResourceOperationalButtonsPanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.ResourceWizardPanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.basic.BasicResourceWizardPanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.objectType.ResourceObjectTypeWizardPanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.objectType.attributeMapping.AttributeMappingWizardPanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.objectType.synchronization.SynchronizationConfigWizardPanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.objectType.synchronization.SynchronizationWizardPanel;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
Expand All @@ -35,7 +32,6 @@

import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.web.component.breadcrumbs.Breadcrumb;
import com.evolveum.midpoint.web.page.admin.users.component.ExecuteChangeOptionsDto;
import com.evolveum.midpoint.web.session.ObjectDetailsStorage;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

Expand All @@ -44,7 +40,6 @@
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import com.evolveum.midpoint.gui.api.model.LoadableModel;
Expand Down Expand Up @@ -185,7 +180,7 @@ public void showSynchronizationWizard(AjaxRequestTarget target, IModel<PrismCont
Fragment fragment = new Fragment(ID_DETAILS_VIEW, ID_WIZARD_FRAGMENT, PageResource.this);
fragment.setOutputMarkupId(true);
addOrReplace(fragment);
SynchronizationConfigWizardPanel wizard = new SynchronizationConfigWizardPanel(
SynchronizationWizardPanel wizard = new SynchronizationWizardPanel(
ID_WIZARD, getObjectDetailsModels(), valueModel) {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;

import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDefinitionType;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;

/**
* @author lskublik
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,22 @@
import com.evolveum.midpoint.gui.api.component.wizard.WizardStep;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerWrapper;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.page.admin.resource.ResourceDetailsModel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.AbstractResourceWizardPanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.objectType.attributeMapping.*;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.objectType.credentials.PasswordInboundStepPanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.objectType.credentials.PasswordOutboundStepPanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.objectType.synchronization.DefaultSettingStepPanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.objectType.synchronization.ReactionStepPanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.objectType.synchronization.SynchronizationConfigWizardPanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.objectType.synchronization.SynchronizationWizardPanel;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.model.ContainerValueWrapperFromObjectWrapperModel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDefinitionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
Expand Down Expand Up @@ -112,25 +107,7 @@ protected void onSubmitPerformed(AjaxRequestTarget target) {
.delay(5_000)
.body(getString("ResourceWizardPanel.updateResource.text")).show(target);

ItemPath path = valueModel.getObject().getPath();
if (!path.isEmpty() && ItemPath.isId(path.last())) {
valueModel.detach();
valueModel = new LoadableDetachableModel<>() {
@Override
protected PrismContainerValueWrapper<ResourceObjectTypeDefinitionType> load() {
try {
return getResourceModel().getObjectWrapper().findContainerValue(path);
} catch (SchemaException e) {
LOGGER.error("Cannot find container value wrapper, \nparent: {}, \npath: {}",
getResourceModel().getObjectWrapper(), path);
}
return null;
}
};
} else {
valueModel.detach();
valueModel = getValueWrapperWitLastId(path);
}
valueModel = refreshValueModel(valueModel);
showObjectTypePreviewFragment(valueModel, target);
} else {
target.add(getFeedback());
Expand All @@ -153,42 +130,6 @@ protected boolean isSavedAfterDetailsWizard() {
return true;
}

private IModel<PrismContainerValueWrapper<ResourceObjectTypeDefinitionType>> getValueWrapperWitLastId(ItemPath itemPath) {
return new LoadableDetachableModel<>() {

private ItemPath pathWithId;

@Override
protected PrismContainerValueWrapper<ResourceObjectTypeDefinitionType> load() {
if (!itemPath.isEmpty() && ItemPath.isId(itemPath.last())) {
pathWithId = itemPath;
}

try {
if (pathWithId != null) {
return getResourceModel().getObjectWrapper().findContainerValue(pathWithId);
}
PrismContainerWrapper<ResourceObjectTypeDefinitionType> container = getResourceModel().getObjectWrapper().findContainer(itemPath);
PrismContainerValueWrapper<ResourceObjectTypeDefinitionType> ret = null;
for (PrismContainerValueWrapper<ResourceObjectTypeDefinitionType> value : container.getValues()) {
if (ret == null || ret.getNewValue().getId() == null
|| (value.getNewValue().getId() != null && ret.getNewValue().getId() < value.getNewValue().getId())) {
ret = value;
}
}
if (ret != null && ret.getNewValue().getId() != null) {
pathWithId = ret.getPath();
}
return ret;
} catch (SchemaException e) {
LOGGER.error("Cannot find container value wrapper, \nparent: {}, \npath: {}",
getResourceModel().getObjectWrapper(), pathWithId);
}
return null;
}
};
}

private void showObjectTypePreviewFragment(
IModel<PrismContainerValueWrapper<ResourceObjectTypeDefinitionType>> model, AjaxRequestTarget target) {
showChoiceFragment(target, new ResourceObjectTypeWizardPreviewPanel(getIdOfChoicePanel(), getResourceModel(), model) {
Expand Down Expand Up @@ -221,14 +162,18 @@ private void showSynchronizationConfigWizard(
AjaxRequestTarget target, IModel<PrismContainerValueWrapper<ResourceObjectTypeDefinitionType>> valueModel) {
showWizardFragment(
target,
new SynchronizationConfigWizardPanel(getIdOfWizardPanel(), getResourceModel(), valueModel) {
new SynchronizationWizardPanel(getIdOfWizardPanel(), getResourceModel(), valueModel) {
protected void onExitPerformed(AjaxRequestTarget target) {
showObjectTypePreviewFragment(getValueModel(), target);
}

@Override
protected OperationResult onSaveResourcePerformed(AjaxRequestTarget target) {
return ResourceObjectTypeWizardPanel.this.onSaveResourcePerformed(target);
OperationResult result = ResourceObjectTypeWizardPanel.this.onSaveResourcePerformed(target);
if (result != null && !result.isError()) {
refreshValueModel();
}
return result;
}

@Override
Expand Down Expand Up @@ -286,26 +231,95 @@ protected void onExitPerformed(AjaxRequestTarget target) {

@Override
protected OperationResult onSaveResourcePerformed(AjaxRequestTarget target) {
return ResourceObjectTypeWizardPanel.this.onSaveResourcePerformed(target);
OperationResult result = ResourceObjectTypeWizardPanel.this.onSaveResourcePerformed(target);
if (result != null && !result.isError()) {
refreshValueModel();
}
return result;
}

@Override
protected boolean isSavedAfterWizard() {
return isSavedAfterDetailsWizard();
}
});
}
@Override
protected boolean isSavedAfterWizard () {
return isSavedAfterDetailsWizard();
}
});
}

private void showTableForDataOfCurrentlyObjectType(
AjaxRequestTarget target, IModel<PrismContainerValueWrapper<ResourceObjectTypeDefinitionType>> valueModel) {
showChoiceFragment(target, new PreviewResourceObjectTypeDataWizardPanel(
getIdOfChoicePanel(),
getResourceModel(),
valueModel) {
@Override
protected void onExitPerformed(AjaxRequestTarget target) {
showObjectTypePreviewFragment(getResourceObjectType(), target);

private void showTableForDataOfCurrentlyObjectType (
AjaxRequestTarget target, IModel < PrismContainerValueWrapper < ResourceObjectTypeDefinitionType >> valueModel){
showChoiceFragment(target, new PreviewResourceObjectTypeDataWizardPanel(
getIdOfChoicePanel(),
getResourceModel(),
valueModel) {
@Override
protected void onExitPerformed(AjaxRequestTarget target) {
showObjectTypePreviewFragment(getResourceObjectType(), target);
}
});
}

private <C extends Containerable > IModel < PrismContainerValueWrapper < C >> refreshValueModel(
IModel < PrismContainerValueWrapper < C >> valueModel) {
ItemPath path = valueModel.getObject().getPath();
if (!path.isEmpty() && ItemPath.isId(path.last())) {
valueModel.detach();
return new LoadableDetachableModel<>() {
@Override
protected PrismContainerValueWrapper<C> load() {
try {
return getResourceModel().getObjectWrapper().findContainerValue(path);
} catch (SchemaException e) {
LOGGER.error("Cannot find container value wrapper, \nparent: {}, \npath: {}",
getResourceModel().getObjectWrapper(), path);
}
return null;
}
};
} else {
valueModel.detach();
return getValueWrapperWitLastId(path);
}
});
}

private <C extends Containerable > IModel < PrismContainerValueWrapper < C >> getValueWrapperWitLastId(ItemPath itemPath)
{
return new LoadableDetachableModel<>() {

private ItemPath pathWithId;

@Override
protected PrismContainerValueWrapper<C> load() {
if (!itemPath.isEmpty() && ItemPath.isId(itemPath.last())) {
pathWithId = itemPath;
}

try {
if (pathWithId != null) {
return getResourceModel().getObjectWrapper().findContainerValue(pathWithId);
}
PrismContainerWrapper<C> container = getResourceModel().getObjectWrapper().findContainer(itemPath);
PrismContainerValueWrapper<C> ret = null;
for (PrismContainerValueWrapper<C> value : container.getValues()) {
if (ret == null || ret.getNewValue().getId() == null
|| (value.getNewValue().getId() != null && ret.getNewValue().getId() < value.getNewValue().getId())) {
ret = value;
}
}
if (ret != null && ret.getNewValue().getId() != null) {
pathWithId = ret.getPath();
}
return ret;
} catch (SchemaException e) {
LOGGER.error("Cannot find container value wrapper, \nparent: {}, \npath: {}",
getResourceModel().getObjectWrapper(), pathWithId);
}
return null;
}
};
}

private void refreshValueModel () {
valueModel = refreshValueModel(valueModel);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ protected void onSaveResourcePerformed(AjaxRequestTarget target) {
.delay(5_000)
.body(getString("ResourceWizardPanel.updateResource.text")).show(target);
onExitPerformed(target);
} else {
target.add(getFeedback());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected List<Component> createToolbarButtonsList(String idButton) {

@Override
protected void newItemPerformed(AjaxRequestTarget target, AssignmentObjectRelation relationSpec) {
getContainerModel().getObject().getValues().add(createNewMapping(target));
createNewMapping(target);
refreshTable(target);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected List<Component> createToolbarButtonsList(String idButton) {

@Override
protected void newItemPerformed(AjaxRequestTarget target, AssignmentObjectRelation relationSpec) {
getContainerModel().getObject().getValues().add(createNewOverride(target));
createNewOverride(target);
refreshTable(target);
}

Expand Down

0 comments on commit 7cc5475

Please sign in to comment.