Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Sep 20, 2022
2 parents b632f60 + e7b14e7 commit 66dbd92
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private static String emptyIfNull(String s) {
}

public static String getReferencedObjectDisplayNameAndName(Referencable ref, boolean loadObject, PageBase pageBase) {
if (ref == null) {
if (ref == null || ref.asReferenceValue().isEmpty()) {
return "";
}
if (ref.getOid() != null && ref.asReferenceValue().getObject() == null && !loadObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,41 @@ public static ProvenanceAcquisitionType createAcquition() {
acquisitionType.setTimestamp(app.getClock().currentTimeXMLGregorianCalendar());
return acquisitionType;
}

public static boolean isValueFromResourceTemplate(PrismValue valueFromDelta, PrismContainer parent) {
if (valueFromDelta instanceof PrismObjectValue) {
return false;
}

if (hasValueMetadata(valueFromDelta)) {
return true;
}
Item<PrismValue, ItemDefinition> item = parent.findItem(valueFromDelta.getParent().getPath());
PrismContainerValue<?> value = item.getParent();
while (!(value instanceof PrismObjectValue)) {
if (hasValueMetadata(value)) {
return true;
}
value = value.getParentContainerValue();
}
return false;
}

private static boolean hasValueMetadata(PrismValue value) {
if (value.hasValueMetadata()) {
List<PrismContainerValue<Containerable>> metadataValues = value.getValueMetadata().getValues();

if (metadataValues.size() == 1) {
ProvenanceMetadataType provenance = ((ValueMetadataType) metadataValues.get(0).asContainerable()).getProvenance();
if (provenance != null) {
List<ProvenanceAcquisitionType> acquisitionValues = provenance.getAcquisition();
if (acquisitionValues.size() == 1) {
ObjectReferenceType originRef = acquisitionValues.get(0).getOriginRef();
return originRef != null && StringUtils.isNotEmpty(originRef.getOid());
}
}
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ protected void onSubmitPerformed(AjaxRequestTarget target) {
steps.add(new SelectObjectClassesStepPanel(getResourceModel()) {
@Override
protected void onSubmitPerformed(AjaxRequestTarget target) {
super.onSubmitPerformed(target);
BasicResourceWizardPanel.this.onFinishBasicWizardPerformed(target);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class ObjectClassWrapper extends Selectable<ObjectClassWrapper>

@NotNull private final ResourceObjectClassDefinition definition;

private boolean enabled = true;

public ObjectClassWrapper(@NotNull ResourceObjectClassDefinition definition) {
Validate.notNull(definition, "Refined object definition must not be null.");
this.definition = definition;
Expand Down Expand Up @@ -79,4 +81,12 @@ public int hashCode() {
public boolean isAuxiliary() {
return definition.isAuxiliary();
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public boolean getEnabled() {
return enabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import java.util.stream.Collectors;

/**
* @author lazyman
* @author lskublik
*/
public class ResourceTemplateProvider
extends ObjectDataProvider<TemplateTile<ResourceTemplateProvider.ResourceTemplate>, AssignmentHolderType> {
Expand Down Expand Up @@ -88,57 +88,6 @@ protected Collection<SelectorOptions<GetOperationOptions>> getOptionsToUse() {
return GetOperationOptions.merge(getPrismContext(), getOptions(), getDistinctRelatedOptions(), rawOption);
}

// @Override
// public Iterator<TemplateTile<ResourceTemplate>> internalIterator(long first, long count) {
// LOGGER.trace("begin::iterator() from {} count {}.", first, count);
//
// getAvailableData().clear();
//
// OperationResult result = new OperationResult(OPERATION_SEARCH_OBJECTS);
// try {
// Task task = getPageBase().createSimpleTask(OPERATION_SEARCH_OBJECTS);
//
// ObjectQuery query = getQuery();
// if (query == null) {
// query = getPrismContext().queryFactory().createQuery();
// }
//
// if (LOGGER.isTraceEnabled()) {
// LOGGER.trace("Query {} with {}", getType().getSimpleName(), query.debugDump());
// }
//
// List<PrismObject<AssignmentHolderType>> list = getModelService().searchObjects(getType(), query, getOptionsToUse(), task, result);
//
// if (LOGGER.isTraceEnabled()) {
// LOGGER.trace("Query {} resulted in {} objects", getType().getSimpleName(), list.size());
// }
//
// List<TemplateTile<ResourceTemplate>> tiles = new ArrayList<>();
// for (PrismObject<AssignmentHolderType> object : list) {
// tiles.add(createDataObjectWrapper(object, result));
// }
// Collections.sort(tiles);
// internalSize = tiles.size();
// getAvailableData().addAll(
// tiles.stream()
// .skip(first)
// .limit(count)
// .collect(Collectors.toList()));
// } catch (Exception ex) {
// result.recordFatalError(getPageBase().createStringResource("ObjectDataProvider.message.listObjects.fatalError").getString(), ex);
// LoggingUtils.logUnexpectedException(LOGGER, "Couldn't list objects", ex);
// } finally {
// result.computeStatusIfUnknown();
// }
//
// if (!WebComponentUtil.isSuccessOrHandledError(result)) {
// handleNotSuccessOrHandledErrorInIterator(result);
// }
//
// LOGGER.trace("end::iterator()");
// return getAvailableData().iterator();
// }

@Override
protected ObjectQuery getCustomizeContentQuery() {
if (TemplateType.TEMPLATE == type.getObject()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,31 @@
package com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.basic;

import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebPrismUtil;
import com.evolveum.midpoint.gui.impl.page.admin.resource.ResourceDetailsModel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.AbstractResourceWizardStepPanel;
import com.evolveum.midpoint.gui.impl.prism.wrapper.PrismContainerValueWrapperImpl;
import com.evolveum.midpoint.prism.path.ItemPath;
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.component.AjaxButton;
import com.evolveum.midpoint.web.component.AjaxSubmitButton;
import com.evolveum.midpoint.web.component.data.BoxedTablePanel;
import com.evolveum.midpoint.web.component.data.column.CheckBoxHeaderColumn;

import com.evolveum.midpoint.web.component.form.MidpointForm;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.component.wizard.resource.dto.ObjectClassDto;

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

import com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaGenerationConstraintsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
Expand All @@ -33,19 +44,21 @@
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.jetbrains.annotations.NotNull;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;
import java.util.*;

/**
* @author lskublik
*/
public class SelectObjectClassesStepPanel extends AbstractResourceWizardStepPanel {

private static final Trace LOGGER = TraceManager.getTrace(SelectObjectClassesStepPanel.class);

private static final String ID_SEARCH_FORM = "searchForm";
private static final String ID_SEARCH_FIELD = "searchFiled";
private static final String ID_SEARCH_BUTTON = "searchButton";
Expand All @@ -55,29 +68,37 @@ public class SelectObjectClassesStepPanel extends AbstractResourceWizardStepPane
private static final String ID_DESELECT_BUTTON = "deselectButton";
private static final String ID_TABLE = "table";

private final LoadableModel<List<QName>> selectedItems;
private final LoadableModel<Map<QName, Boolean>> selectedItems;

public SelectObjectClassesStepPanel(ResourceDetailsModel model) {
super(model);
// selectedItems = new ItemRealValueModel<>()

selectedItems = new LoadableModel<>() {
@Override
protected List<QName> load() {
@NotNull ResourceType resource = getResourceModel().getObjectType();
if (resource.getSchema() == null) {
resource.beginSchema();
}
if (resource.getSchema().getGenerationConstraints() == null) {
resource.getSchema().beginGenerationConstraints();
}
protected Map<QName, Boolean> load() {
Map<QName, Boolean> map = new HashMap();
try {
PrismPropertyWrapper<QName> generationConstraints = getResourceModel().getObjectWrapper().findProperty(
ItemPath.create(
ResourceType.F_SCHEMA,
XmlSchemaType.F_GENERATION_CONSTRAINTS,
SchemaGenerationConstraintsType.F_GENERATE_OBJECT_CLASS));
if (generationConstraints != null) {
generationConstraints.getValues().forEach(v -> {
if (v.getRealValue() != null) {
map.put(
v.getRealValue(),
!WebPrismUtil.isValueFromResourceTemplate(
v.getNewValue(),
getResourceModel().getObjectType().asPrismObject())
);
}
});

List<QName> list = new ArrayList<>();
list.addAll(resource.getSchema().getGenerationConstraints().getGenerateObjectClass());
if (list.size() == 1 && list.get(0) == null) {
list.clear();
}
} catch (SchemaException e) {
LOGGER.error("Couldn't find property for schema generation constraints", e);
}
return list;
return map;
}
};
}
Expand Down Expand Up @@ -130,19 +151,24 @@ public void onSubmit(AjaxRequestTarget target) {
WebMarkupContainer selectedItemsContainer = new WebMarkupContainer(ID_SELECTED_ITEMS_CONTAINER);
selectedItemsContainer.setOutputMarkupId(true);
add(selectedItemsContainer);
ListView<QName> selectedContainer = new ListView<>(ID_SELECTED_ITEM_CONTAINER, selectedItems) {

ListView<QName> selectedContainer = new ListView<>(
ID_SELECTED_ITEM_CONTAINER,
() -> new ArrayList<>(selectedItems.getObject().keySet())) {

@Override
protected void populateItem(ListItem<QName> item) {
QName objectClass = item.getModelObject();

item.add(new Label(ID_SELECTED_ITEM, () -> objectClass.getLocalPart()));
item.add(new AjaxButton(ID_DESELECT_BUTTON) {
AjaxButton deselectButton = new AjaxButton(ID_DESELECT_BUTTON) {
@Override
public void onClick(AjaxRequestTarget target) {
deselectItem(objectClass, target);
}
});
};
item.add(deselectButton);
deselectButton.add(new VisibleBehaviour(() -> selectedItems.getObject().get(objectClass)));
}
};
selectedContainer.setOutputMarkupId(true);
Expand Down Expand Up @@ -185,7 +211,9 @@ private List<IColumn<SelectableBean<ObjectClassWrapper>, String>> createColumns(
protected void onUpdateRow(AjaxRequestTarget target, DataTable table, IModel<SelectableBean<ObjectClassWrapper>> rowModel, IModel<Boolean> selected) {
super.onUpdateRow(target, table, rowModel, selected);
if (Boolean.TRUE.equals(selected.getObject())) {
selectedItems.getObject().add(rowModel.getObject().getValue().getObjectClassName());
if (!selectedItems.getObject().containsKey(rowModel.getObject().getValue().getObjectClassName())) {
selectedItems.getObject().put(rowModel.getObject().getValue().getObjectClassName(), true);
}
} else {
selectedItems.getObject().remove(rowModel.getObject().getValue().getObjectClassName());
}
Expand All @@ -197,13 +225,25 @@ protected void onUpdateHeader(AjaxRequestTarget target, boolean selected, DataTa
super.onUpdateHeader(target, selected, table);
ObjectClassDataProvider provider = (ObjectClassDataProvider) table.getDataProvider();
if (selected) {
provider.getListFromModel().forEach(objectClass -> selectedItems.getObject().add(objectClass.getObjectClassName()));
provider.getListFromModel().forEach(objectClass -> {
if (!selectedItems.getObject().containsKey(objectClass.getObjectClassName())) {
selectedItems.getObject().put(objectClass.getObjectClassName(), true);
}
});
} else {
provider.getListFromModel().forEach(objectClass -> selectedItems.getObject().remove(objectClass.getObjectClassName()));
}
target.add(getSelectedItemsContainer());

}

@Override
protected IModel<Boolean> getEnabled(IModel<SelectableBean<ObjectClassWrapper>> rowModel) {
if (rowModel == null) {
return super.getEnabled(rowModel);
}
return new PropertyModel<>(rowModel, "value.enabled");
}
});

columns.add(new AbstractColumn<>(getPageBase().createStringResource("SelectObjectClassesStepPanel.table.column.name")) {
Expand Down Expand Up @@ -249,12 +289,40 @@ private ObjectClassDataProvider createProvider() {
@Override
protected SelectableBean<ObjectClassWrapper> createObjectWrapper(ObjectClassWrapper object) {
SelectableBean<ObjectClassWrapper> wrapper = super.createObjectWrapper(object);
wrapper.setSelected(selectedItems.getObject().contains(object.getObjectClassName()));
if (selectedItems.getObject().containsKey(object.getObjectClassName())) {
wrapper.setSelected(true);
object.setEnabled(selectedItems.getObject().get(object.getObjectClassName()));
}
return wrapper;
}
};
}

@Override
protected void onSubmitPerformed(AjaxRequestTarget target) {
List<QName> classForSave = new ArrayList<>();

selectedItems.getObject().forEach((key, enabled) -> {
if (enabled) {
classForSave.add(key);
}
});

if (classForSave.isEmpty()) {
return;
}

@NotNull ResourceType resource = getResourceModel().getObjectType();
if (resource.getSchema() == null) {
resource.beginSchema();
}
if (resource.getSchema().getGenerationConstraints() == null) {
resource.getSchema().beginGenerationConstraints();
}

resource.getSchema().getGenerationConstraints().getGenerateObjectClass().addAll(classForSave);
}

@Override
protected IModel<String> getSubmitLabelModel() {
return getPageBase().createStringResource("SelectObjectClassesStepPanel.submitLabel");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ private void saveDelegationToUser(PrismObject<UserType> user, AssignmentEditorDt
} finally {
result.recomputeStatus();
}

showResult(result);
}

private Collection<ObjectDelta<? extends ObjectType>> prepareDelegationDelta(PrismObject<UserType> user, AssignmentEditorDto dto)
Expand Down

0 comments on commit 66dbd92

Please sign in to comment.