-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MID-8518:fix for filter parsing panel for attributes of resource
- Loading branch information
Showing
5 changed files
with
150 additions
and
8 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...lveum/midpoint/gui/impl/factory/panel/ResourceAttributeSearchFilterTypeForQueryModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (C) 2023 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
package com.evolveum.midpoint.gui.impl.factory.panel; | ||
|
||
import com.evolveum.midpoint.gui.api.page.PageBase; | ||
import com.evolveum.midpoint.gui.impl.page.admin.resource.PageResource; | ||
import com.evolveum.midpoint.prism.PrismContext; | ||
import com.evolveum.midpoint.prism.PrismObjectDefinition; | ||
import com.evolveum.midpoint.prism.query.ObjectFilter; | ||
import com.evolveum.midpoint.schema.processor.ResourceObjectDefinition; | ||
import com.evolveum.midpoint.schema.util.ShadowUtil; | ||
import com.evolveum.midpoint.util.exception.ConfigurationException; | ||
import com.evolveum.midpoint.util.exception.SchemaException; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType; | ||
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType; | ||
|
||
import org.apache.wicket.model.IModel; | ||
import org.apache.wicket.model.Model; | ||
|
||
import javax.xml.namespace.QName; | ||
|
||
public class ResourceAttributeSearchFilterTypeForQueryModel extends SearchFilterTypeForQueryModel<ShadowType> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private final IModel<QName> objectClass; | ||
|
||
public ResourceAttributeSearchFilterTypeForQueryModel( | ||
IModel<SearchFilterType> valueWrapper, PageBase pageBase, boolean useParsing, IModel<QName> objectClass) { | ||
super(valueWrapper, pageBase, Model.of(ShadowType.class), useParsing); | ||
this.objectClass = objectClass; | ||
} | ||
|
||
protected void parseQuery(String object) throws SchemaException, ConfigurationException { | ||
PrismObjectDefinition<ShadowType> def = PrismContext.get().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class); | ||
ResourceObjectDefinition objectClassDef = | ||
((PageResource) getPageBase()).getObjectDetailsModels().getRefinedSchema().findDefinitionForObjectClass(objectClass.getObject()); | ||
PrismObjectDefinition<ShadowType> newDef = ShadowUtil.applyObjectDefinition(def, objectClassDef); | ||
|
||
ObjectFilter objectFilter = getPageBase().getPrismContext().createQueryParser().parseFilter(newDef, object); | ||
SearchFilterType filter = getPageBase().getQueryConverter().createSearchFilterType(objectFilter); | ||
filter.setText(object); | ||
getBaseModel().setObject(filter); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
.../evolveum/midpoint/gui/impl/factory/panel/ResourceAttributesSearchFilterPanelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (C) 2023 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
package com.evolveum.midpoint.gui.impl.factory.panel; | ||
|
||
import com.evolveum.midpoint.gui.api.model.LoadableModel; | ||
import com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper; | ||
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper; | ||
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismValueWrapper; | ||
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.page.admin.reports.component.SearchFilterConfigurationPanel; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.*; | ||
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType; | ||
|
||
import org.apache.wicket.markup.html.panel.Panel; | ||
import org.apache.wicket.model.IModel; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.xml.namespace.QName; | ||
import java.io.Serializable; | ||
|
||
@Component | ||
public class ResourceAttributesSearchFilterPanelFactory extends SearchFilterPanelFactory implements Serializable { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(ResourceAttributesSearchFilterPanelFactory.class); | ||
|
||
@Override | ||
public <IW extends ItemWrapper<?, ?>> boolean match(IW wrapper) { | ||
return super.match(wrapper) | ||
&& ItemPath.create( | ||
ResourceType.F_SCHEMA_HANDLING, | ||
SchemaHandlingType.F_OBJECT_TYPE, | ||
ResourceObjectTypeDefinitionType.F_DELINEATION, | ||
ResourceObjectTypeDelineationType.F_FILTER) | ||
.equivalent(wrapper.getPath().namedSegmentsOnly()); | ||
} | ||
|
||
@Override | ||
protected Panel getPanel(PrismPropertyPanelContext<SearchFilterType> panelCtx) { | ||
return new SearchFilterConfigurationPanel( | ||
panelCtx.getComponentId(), panelCtx.getItemWrapperModel(), panelCtx.getRealValueModel(), null) { | ||
@Override | ||
protected IModel<String> createQueryModel(IModel model, LoadableModel filterTypeModel, boolean useParsing) { | ||
ItemRealValueModel<QName> objectClassModel = new ItemRealValueModel<>((IModel<? extends PrismValueWrapper<QName>>) () -> { | ||
try { | ||
PrismPropertyWrapper<QName> objectClass = | ||
getItemModelObject().getParent().findProperty(ResourceObjectTypeDelineationType.F_OBJECT_CLASS); | ||
return objectClass.getValue(); | ||
|
||
} catch (SchemaException e) { | ||
LOGGER.error("Couldn't find object class property."); | ||
return null; | ||
} | ||
}); | ||
return new ResourceAttributeSearchFilterTypeForQueryModel(model, getPageBase(), useParsing, objectClassModel); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Integer getOrder() { | ||
return Integer.MAX_VALUE - 10; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters