Skip to content

Commit

Permalink
type search improvements. create ObjectTypeSearchItemWrapper for each…
Browse files Browse the repository at this point in the history
… search, if only 1 type is supported the panel is hidden
  • Loading branch information
katkav committed Jan 19, 2023
1 parent 5f3e208 commit 2657053
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,29 +265,34 @@ public static List<ItemPath> getSearchableItemsFor(Class<?> typeClass, PanelType


public enum PanelType {
ROLE_MEMBER_GOVERNANCE(true, "roleMembers"),
ROLE_MEMBER_MEMBER(true, "roleGovernance"),
SERVICE_MEMBER_GOVERNANCE(true, "serviceGovernance"),
SERVICE_MEMBER_MEMBER(true, "serviceMembers"),
ARCHETYPE_MEMBER_GOVERNANCE(true, "archetypeGovernance"),
ARCHETYPE_MEMBER_MEMBER(true, "archetypeMembers"),
ORG_MEMBER_GOVERNANCE(true, "orgGovernance"),
ORG_MEMBER_MEMBER(true, "orgMembers"),
MEMBER_ORGANIZATION(true, null),
CARDS_GOVERNANCE(true, null),
MEMBER_WIZARD(true, null),
RESOURCE_SHADOW(false, null),
REPO_SHADOW(false, null),
PROJECTION_SHADOW(false, null),
DEBUG(false, null),
ASSIGNABLE(false, null);
ROLE_MEMBER_GOVERNANCE(true, "roleGovernance", true, FocusType.COMPLEX_TYPE),
ROLE_MEMBER_MEMBER(true, "roleMembers", true, FocusType.COMPLEX_TYPE),
SERVICE_MEMBER_GOVERNANCE(true, "serviceGovernance", true, FocusType.COMPLEX_TYPE),
SERVICE_MEMBER_MEMBER(true, "serviceMembers", true, FocusType.COMPLEX_TYPE),
ARCHETYPE_MEMBER_GOVERNANCE(true, "archetypeGovernance", true, FocusType.COMPLEX_TYPE),
ARCHETYPE_MEMBER_MEMBER(true, "archetypeMembers", true, AssignmentHolderType.COMPLEX_TYPE),
ORG_MEMBER_GOVERNANCE(true, "orgGovernance", true, FocusType.COMPLEX_TYPE),
ORG_MEMBER_MEMBER(true, "orgMembers", true, AssignmentType.COMPLEX_TYPE),
MEMBER_ORGANIZATION(true, null, true, AssignmentHolderType.COMPLEX_TYPE),
CARDS_GOVERNANCE(true, null, true, FocusType.COMPLEX_TYPE),
MEMBER_WIZARD(true, null, false, UserType.COMPLEX_TYPE),
RESOURCE_SHADOW(false, null, false, null),
REPO_SHADOW(false, null, false, null),
PROJECTION_SHADOW(false, null, false, null),
DEBUG(false, null, false, null),
ASSIGNABLE(false, null, false, null);

private boolean memberPanel;
private String panelInstance;

PanelType(boolean memberPanel, String panelInstance) {
private boolean isAllowAllTypeSearch;
private QName typeForNull;

PanelType(boolean memberPanel, String panelInstance, boolean isAllowAllTypeSearch, QName typeForNull) {
this.memberPanel = memberPanel;
this.panelInstance = panelInstance;
this.isAllowAllTypeSearch = isAllowAllTypeSearch;
this.typeForNull = typeForNull;
}

public boolean isMemberPanel() {
Expand All @@ -305,6 +310,14 @@ public static PanelType getPanelType(String panelInstance) {
}
return null;
}

public QName getTypeForNull() {
return typeForNull;
}

public boolean isAllowAllTypeSearch() {
return isAllowAllTypeSearch;
}
}

public Map<ItemPath, ItemDefinition<?>> createAvailableSearchItems() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,17 @@ public class Search<C extends Containerable> implements Serializable, DebugDumpa

public static final String F_MODE = "defaultSearchBoxMode";
public static final String F_ALLOWED_MODES = "allowedModeList";
public static final String F_ALLOWED_TYPES = "allowedTypeList";

private Class<C> typeClass;

private List<QName> allowedTypeList = new ArrayList<>();
private ObjectTypeSearchItemWrapper<C> type;
private SearchBoxModeType defaultSearchBoxMode;
private List<SearchBoxModeType> allowedModeList = new ArrayList<>();
private AdvancedQueryWrapper advancedQueryWrapper;
private AxiomQueryWrapper axiomQueryWrapper;
private FulltextQueryWrapper fulltextQueryWrapper;
private SearchConfigurationWrapper searchConfigurationWrapper;
private String advancedError;
private PrismContainerDefinition<C> containerDefinitionOverride;
private String collectionViewName;
private String collectionRefOid;
private boolean forceReload;

private List<AvailableFilterType> availableFilterTypes;

Expand All @@ -82,18 +77,15 @@ public void setCollectionRefOid(String collectionRefOid) {
this.collectionRefOid = collectionRefOid;
}

public Search(Class type, SearchBoxConfigurationType searchBoxConfigurationType) {
this.typeClass = type;
public Search(ObjectTypeSearchItemWrapper<C> type, SearchBoxConfigurationType searchBoxConfigurationType) {

this.type = type;
this.defaultSearchBoxMode = searchBoxConfigurationType.getDefaultMode();
this.availableFilterTypes = searchBoxConfigurationType.getAvailableFilter();
}

public void setAllowedTypeList(List<QName> allowedTypeList) {
this.allowedTypeList = allowedTypeList;
}

public List<QName> getAllowedTypeList() {
return allowedTypeList;
return type.getAvailableValues();
}

void setAdvancedQueryWrapper(AdvancedQueryWrapper advancedQueryWrapper) {
Expand All @@ -112,10 +104,6 @@ void setFulltextQueryWrapper(FulltextQueryWrapper fulltextQueryWrapper) {
this.fulltextQueryWrapper = fulltextQueryWrapper;
}

public SearchConfigurationWrapper getSearchConfigurationWrapper() {
return searchConfigurationWrapper;
}

public List<FilterableSearchItemWrapper> getItems() {
return searchConfigurationWrapper.getItemsList();
}
Expand Down Expand Up @@ -188,18 +176,16 @@ private ObjectQuery createAdvancedObjectFilter(PrismContext ctx) throws SchemaEx
}

public Class<C> getTypeClass() {
ObjectTypeSearchItemWrapper<C> objectTypeWrapper = findObjectTypeSearchItemWrapper();
if (SearchBoxModeType.OID.equals(getSearchMode())) {
return (Class<C> ) ObjectType.class;
}
if (objectTypeWrapper != null) {
if (objectTypeWrapper.getValue().getValue() != null){
return (Class<C>) WebComponentUtil.qnameToClass(PrismContext.get(), objectTypeWrapper.getValue().getValue());
} else if (objectTypeWrapper.getValueForNull() != null) {
return (Class<C>) WebComponentUtil.qnameToClass(PrismContext.get(), objectTypeWrapper.getValueForNull());
}
if (type.getValue().getValue() != null){
return (Class<C>) WebComponentUtil.qnameToClass(PrismContext.get(), type.getValue().getValue());
} else if (type.getValueForNull() != null) {
return (Class<C>) WebComponentUtil.qnameToClass(PrismContext.get(), type.getValueForNull());
}
return typeClass;

return null; //should not happen
}

private String createErrorMessage(Exception ex) {
Expand Down Expand Up @@ -307,17 +293,6 @@ public ObjectCollectionSearchItemWrapper findObjectCollectionSearchItemWrapper()
}
return null;
}

public ObjectTypeSearchItemWrapper findObjectTypeSearchItemWrapper() {
List<FilterableSearchItemWrapper> items = searchConfigurationWrapper.getItemsList();
for (FilterableSearchItemWrapper item : items) {
if (item instanceof ObjectTypeSearchItemWrapper) {
return (ObjectTypeSearchItemWrapper) item;
}
}
return null;
}

public AbstractRoleSearchItemWrapper findMemberSearchItem() {
List<FilterableSearchItemWrapper<?>> items = searchConfigurationWrapper.getItemsList();
for (FilterableSearchItemWrapper<?> item : items) {
Expand All @@ -339,7 +314,7 @@ private ObjectQuery createObjectTypeItemQuery(PageBase pageBase) {
}

private ObjectQuery evaluateCollectionFilter(PageBase pageBase) {
CompiledObjectCollectionView view = null;
CompiledObjectCollectionView view;
OperationResult result = new OperationResult(OPERATION_EVALUATE_COLLECTION_FILTER);
Task task = pageBase.createSimpleTask(OPERATION_EVALUATE_COLLECTION_FILTER);
ObjectFilter collectionFilter = null;
Expand Down Expand Up @@ -496,10 +471,6 @@ public String toString() {
'}';
}

public PrismContainerDefinition<C> getContainerDefinitionOverride() {
return containerDefinitionOverride;
}

public boolean searchByNameEquals(String nameValueToCompare) {
String nameValue = null;
if (SearchBoxModeType.BASIC.equals(getSearchMode())) {
Expand All @@ -511,24 +482,8 @@ public boolean searchByNameEquals(String nameValueToCompare) {
return nameValueToCompare != null && nameValueToCompare.equals(nameValue);
}

public void setTypeClass(Class<C> typeClass) {
this.typeClass = typeClass;
}

public QName getType() {
return WebComponentUtil.containerClassToQName(PrismContext.get(), typeClass);
}

public void setType(QName type) {
this.typeClass = WebComponentUtil.qnameToContainerClass(PrismContext.get(), type);
}

public void setForceReload(boolean forceReload) {
this.forceReload = forceReload;
}

public boolean isForceReload() {
return forceReload;
return type.isTypeChanged();
}

public List<AvailableFilterType> getAvailableFilterTypes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,9 @@ private SearchItemType getSearchItemByParameterName(List<SearchItemType> searchI
}

private ObjectTypeSearchItemConfigurationType createObjectTypeSearchItemConfiguration() {
List<QName> supportedTypes = getSupportedObjectTypes(panelType);
if (CollectionUtils.isEmpty(supportedTypes)) {
return null;
}
ObjectTypeSearchItemConfigurationType objectTypeItem = new ObjectTypeSearchItemConfigurationType();
objectTypeItem.setDefaultValue(WebComponentUtil.containerClassToQName(PrismContext.get(), type));
objectTypeItem.getSupportedTypes().addAll(supportedTypes);
objectTypeItem.getSupportedTypes().addAll(getSupportedObjectTypes(panelType));
objectTypeItem.setVisibility(UserInterfaceElementVisibilityType.VISIBLE);
return objectTypeItem;
}
Expand Down Expand Up @@ -355,7 +351,7 @@ private static List<QName> getSupportedGovernanceTabRelations(ModelServiceLocato

public static List<QName> getSupportedObjectTypes(PredefinedSearchableItems.PanelType panelType) {
if (panelType == null) {
return null;
return new ArrayList<>();
}
switch (panelType) {
case ROLE_MEMBER_MEMBER:
Expand All @@ -364,7 +360,7 @@ public static List<QName> getSupportedObjectTypes(PredefinedSearchableItems.Pane
case SERVICE_MEMBER_GOVERNANCE:
case ORG_MEMBER_GOVERNANCE:
case ARCHETYPE_MEMBER_GOVERNANCE:
return WebComponentUtil.createFocusTypeList(true);
return WebComponentUtil.createFocusTypeList();
case ORG_MEMBER_MEMBER:
case MEMBER_ORGANIZATION:
case ARCHETYPE_MEMBER_MEMBER:
Expand All @@ -384,7 +380,7 @@ public static List<QName> getSupportedObjectTypes(PredefinedSearchableItems.Pane
case MEMBER_WIZARD:
return Arrays.asList(UserType.COMPLEX_TYPE);
}
return null;
return new ArrayList<>();
}

public static <C extends Containerable> boolean isFixedItem(Class<C> typeClass, ItemPath path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class SearchConfigurationWrapperFactory {
factories.add(new AutocompleteSearchItemWrapperFactory());
factories.add(new ReferenceSearchItemWrapperFactory());
factories.add(new ObjectClassSearchItemWrapperFactory());
factories.add(new ObjectClassSearchItemWrapperFactory());
factories.add(new ItemPathSearchItemWrapperFactory());
factories.add(new DateSearchItemWrapperFactory());
factories.add(new TextSearchItemWrapperFactory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import javax.xml.namespace.QName;

public class SearchFactory<C extends Containerable> {

private static final Trace LOGGER = TraceManager.getTrace(SearchFactory.class);
Expand Down Expand Up @@ -184,13 +186,10 @@ private Search<C> createSearch(SearchBoxConfigurationType mergedConfig, SearchCo
AdvancedQueryWrapper advancedQueryWrapper = new AdvancedQueryWrapper();
FulltextQueryWrapper fulltextQueryWrapper = new FulltextQueryWrapper();

Search<C> search = new Search<>(type, mergedConfig);
search.setTypeClass(type);

if (mergedConfig.getObjectTypeConfiguration() != null) {
search.setAllowedTypeList(mergedConfig.getObjectTypeConfiguration()
.getSupportedTypes());
}
ObjectTypeSearchItemWrapper<C> objectTypeSearchItemWrapper = new ObjectTypeSearchItemWrapper<>(mergedConfig.getObjectTypeConfiguration());
objectTypeSearchItemWrapper.setAllowAllTypesSearch(isAllowedAllTypesSearch());
objectTypeSearchItemWrapper.setValueForNull(getValueRepresentingAllTypes());
Search<C> search = new Search<>(objectTypeSearchItemWrapper, mergedConfig);

search.setAdvancedQueryWrapper(advancedQueryWrapper);
search.setAxiomQueryWrapper(axiomWrapper);
Expand Down Expand Up @@ -304,4 +303,18 @@ private boolean isAllowToConfigureSearchItems(SearchBoxConfigurationType searchB
return searchBoxConfigurationType.isAllowToConfigureSearchItems();
}

private boolean isAllowedAllTypesSearch() {
if (additionalSearchContext == null || additionalSearchContext.getPanelType() == null) {
return false;
}
return additionalSearchContext.getPanelType().isAllowAllTypeSearch();
}

private QName getValueRepresentingAllTypes() {
if (additionalSearchContext == null || additionalSearchContext.getPanelType() == null) {
return null;
}
return additionalSearchContext.getPanelType().getTypeForNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -162,28 +162,9 @@ protected VisibleEnableBehaviour getSearchButtonVisibleEnableBehavior() {
private void initSearchPanel(String panelId, Form form) {

// type search.. applicable for all types of searches
DropDownChoicePanel<QName> choices = new DropDownChoicePanel<>(ID_TYPE_SEARCH, new PropertyModel<>(getModel(), Search.F_TYPE),
new PropertyModel<>(getModel(), Search.F_ALLOWED_TYPES), new QNameObjectTypeChoiceRenderer(), true) {

private static final long serialVersionUID = 1L;

@Override
protected String getNullValidDisplayValue() {
return getString("ObjectTypes.all");
}
};
choices.getBaseFormComponent().add(new OnChangeAjaxBehavior() {

@Override
protected void onUpdate(AjaxRequestTarget target) {
Search<C> search = getModelObject();
search.setForceReload(true);
SearchPanel.this.searchPerformed(target);
}
});
choices.add(new VisibleBehaviour(() -> getModelObject().getAllowedTypeList().size() > 1));
form.add(choices);

ObjectTypeSearchItemPanel<C> objectTypeSearchItemPanel = new ObjectTypeSearchItemPanel<>(ID_TYPE_SEARCH, new PropertyModel<>(getModel(), Search.F_TYPE));
objectTypeSearchItemPanel.add(new VisibleBehaviour(() -> getModelObject().getAllowedTypeList().size() > 1));
form.add(objectTypeSearchItemPanel);

initSpecificSearchPanel(panelId, form);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public boolean isEnabled() {
return CollectionUtils.isNotEmpty(relationSearchItemConfigurationType.getSupportedRelations());
}

//TODO should be in panel!!!
public boolean isVisible() {
return true;
}
Expand Down Expand Up @@ -88,9 +87,4 @@ public RelationSearchItemConfigurationType getRelationSearchItemConfigurationTyp
return relationSearchItemConfigurationType;
}

//TODO should be in member search
// @Override
// public boolean isApplyFilter(SearchBoxModeType searchBoxMode) {
// return !SearchBoxScopeType.SUBTREE.equals(getSearchConfig().getDefaultScope());
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected Form<?> getForm() {
}

private <AH extends AssignmentHolderType> Class<AH> getDefaultObjectTypeClass() {
return (Class<AH>) AssignmentHolderType.class;
return (Class<AH>) UserType.class;
}
protected <AH extends AssignmentHolderType> void initMemberTable(Form<?> form) {
WebMarkupContainer memberContainer = new WebMarkupContainer(ID_CONTAINER_MEMBER);
Expand Down

0 comments on commit 2657053

Please sign in to comment.