Skip to content

Commit

Permalink
support for object reference type in search panel (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Aug 14, 2018
1 parent c52c92e commit 518722d
Show file tree
Hide file tree
Showing 14 changed files with 341 additions and 45 deletions.
Expand Up @@ -411,11 +411,11 @@ protected List<ObjectOrdering> createObjectOrderings(SortParam<String> sortParam
}
};
if (options == null){
if (ResourceType.class.equals(type)) {
if (ResourceType.class.equals(type.getClassDefinition())) {
options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
}
} else {
if (ResourceType.class.equals(type)) {
if (ResourceType.class.equals(type.getClassDefinition())) {
GetOperationOptions root = SelectorOptions.findRootOptions(options);
root.setNoFetch(Boolean.TRUE);
}
Expand Down
Expand Up @@ -2405,7 +2405,7 @@ public static ItemVisibility checkShadowActivationAndPasswordVisibility(ItemWrap

}

public static List<QName> getCategoryRelationChoices(AreaCategoryType category, OperationResult result, PageBase pageBase){
public static List<QName> getCategoryRelationChoices(AreaCategoryType category, OperationResult result, ModelServiceLocator pageBase){
List<QName> relationsList = new ArrayList<>();
List<RelationDefinitionType> defList = getRelationDefinitions(result, pageBase);
if (defList != null) {
Expand All @@ -2417,8 +2417,16 @@ public static List<QName> getCategoryRelationChoices(AreaCategoryType category,
}
return relationsList;
}

public static List<QName> getAllRelations(ModelServiceLocator pageBase) {
OperationResult result = new OperationResult("get all relations");
List<RelationDefinitionType> allRelationdefinitions = getRelationDefinitions(result, pageBase);
List<QName> allRelationsQName = new ArrayList<>(allRelationdefinitions.size());
allRelationdefinitions.stream().forEach(relation -> allRelationsQName.add(relation.getRef()));
return allRelationsQName;
}

public static List<RelationDefinitionType> getRelationDefinitions(OperationResult result, PageBase pageBase){
public static List<RelationDefinitionType> getRelationDefinitions(OperationResult result, ModelServiceLocator pageBase){
try {
return pageBase.getModelInteractionService().getRelationDefinitions(result);
} catch (ObjectNotFoundException | SchemaException ex){
Expand Down
Expand Up @@ -21,7 +21,9 @@

import javax.xml.namespace.QName;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.markup.html.WebMarkupContainer;
Expand All @@ -36,6 +38,7 @@

import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.component.ObjectListPanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.impl.model.PropertyWrapperFromContainerValueWrapperModel;
import com.evolveum.midpoint.gui.impl.util.GuiImplUtil;
Expand All @@ -50,7 +53,9 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.AjaxIconButton;
import com.evolveum.midpoint.web.component.data.BaseSortableDataProvider;
import com.evolveum.midpoint.web.component.data.BoxedTablePanel;
import com.evolveum.midpoint.web.component.data.Table;
import com.evolveum.midpoint.web.component.data.column.ColumnMenuAction;
import com.evolveum.midpoint.web.component.data.column.DoubleButtonColumn;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem;
Expand All @@ -61,10 +66,15 @@
import com.evolveum.midpoint.web.component.prism.ObjectWrapper;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.midpoint.web.component.prism.ValueWrapper;
import com.evolveum.midpoint.web.component.search.Search;
import com.evolveum.midpoint.web.component.search.SearchFactory;
import com.evolveum.midpoint.web.component.search.SearchFormPanel;
import com.evolveum.midpoint.web.component.util.MultivalueContainerListDataProvider;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.session.PageStorage;
import com.evolveum.midpoint.web.session.UserProfileStorage.TableId;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.GlobalPolicyRuleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleType;

Expand All @@ -88,16 +98,31 @@ public abstract class MultivalueContainerListPanel<C extends Containerable> exte
private int itemPerPage;
private PageStorage pageStorage;

private LoadableModel<Search> searchModel = null;

public MultivalueContainerListPanel(String id, IModel<ContainerWrapper<C>> model, TableId tableId, int itemPerPage, PageStorage pageStorage) {
super(id, model);
this.tableId = tableId;
this.itemPerPage = itemPerPage;
this.pageStorage = pageStorage;

searchModel = new LoadableModel<Search>(false) {

private static final long serialVersionUID = 1L;

@Override
protected Search load() {
return SearchFactory.createContainerSearch(getModelObject().getItem().getCompileTimeClass(), getPageBase());
}
};
}

@Override
protected void onInitialize() {
super.onInitialize();



initPaging();
initLayout();
}
Expand Down Expand Up @@ -181,7 +206,7 @@ protected void saveProviderPaging(ObjectQuery query, ObjectPaging paging) {

@Override
public ObjectQuery getQuery() {
return createQuery();
return MultivalueContainerListPanel.this.getQuery();
}

@Override
Expand All @@ -198,6 +223,11 @@ protected List<ContainerValueWrapper<C>> searchThroughList() {
containersProvider, columns, tableId, itemPerPage) {
private static final long serialVersionUID = 1L;

@Override
protected WebMarkupContainer createHeader(String headerId) {
return MultivalueContainerListPanel.this.initSearch(headerId);
}

@Override
public int getItemsPerPage() {
return getPageBase().getSessionStorage().getUserProfile().getTables()
Expand Down Expand Up @@ -251,6 +281,58 @@ public boolean isVisible() {

}

protected WebMarkupContainer initSearch(String headerId) {
SearchFormPanel searchPanel = new SearchFormPanel(headerId, searchModel) {

private static final long serialVersionUID = 1L;

@Override
protected void searchPerformed(ObjectQuery query, AjaxRequestTarget target) {
MultivalueContainerListPanel.this.searchPerformed(query, target);
}
};
return searchPanel;
}

private void searchPerformed(ObjectQuery query, AjaxRequestTarget target) {

MultivalueContainerListDataProvider<C> provider = getDataProvider();

ObjectQuery customQuery = getQuery();

if (customQuery == null || customQuery.getFilter() == null) {
customQuery = createQuery();
}

provider.setQuery(customQuery);
// String storageKey = getStorageKey();
// if (StringUtils.isNotEmpty(storageKey)) {
// PageStorage storage = getPageStorage(storageKey);
// if (storage != null) {
// storage.setSearch(searchModel.getObject());
// storage.setPaging(null);
// }
// }
//
Table table = getItemTable();
table.setCurrentPage(null);
target.add((Component) table);
target.add(getPageBase().getFeedbackPanel());

}

private ObjectQuery getQuery() {
Search search = searchModel.getObject();
ObjectQuery query = search.createObjectQuery(getPageBase().getPrismContext());
// query = addFilterToContentQuery(query);
return query;
}

private MultivalueContainerListDataProvider<C> getDataProvider() {
return (MultivalueContainerListDataProvider<C>) getItemTable().getDataTable().getDataProvider();
}


private IModel<String> createStyleClassModelForNewObjectIcon() {
return new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
Expand Down
Expand Up @@ -34,6 +34,9 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.objectdetails.FocusMainPanel;
import com.evolveum.midpoint.web.component.prism.*;
import com.evolveum.midpoint.web.component.search.Search;
import com.evolveum.midpoint.web.component.search.SearchFactory;
import com.evolveum.midpoint.web.component.search.SearchFormPanel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand Down Expand Up @@ -152,7 +155,7 @@ protected MultivalueContainerDetailsPanel<AssignmentType> getMultivalueContainer
ListItem<ContainerValueWrapper<AssignmentType>> item) {
return createMultivalueContainerDetailsPanel(item);
}

};

add(multivalueContainerListPanel);
Expand Down
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>

<!--
~ Copyright (c) 2010-2017 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<html xmlns:wicket="http://wicket.apache.org">
<head/>
<body>
<wicket:panel>
<input wicket:id=oid type="text" class="form-control input-sm" style="width: 150px; min-width: 150px;">
<select wicket:id="type" class="form-control input-sm" style="width: auto; min-width: 150px;"/>
<select wicket:id="relation" class="form-control input-sm" style="width: auto; min-width: 150px;"/>
<span class="input-group-btn">
<a wicket:id="remove" class="btn btn-danger" wicket:message="title:SearchItemPanel.remove">
<i class="fa fa-minus"/>
</a>
<a wicket:id="add" class="btn btn-success" wicket:message="title:SearchItemPanel.add">
<i class="fa fa-plus"/>
</a>
</span>
</wicket:panel>
</body>
</html>
@@ -0,0 +1,66 @@
package com.evolveum.midpoint.web.component.search;

import java.io.Serializable;

import javax.xml.namespace.QName;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.web.component.input.QNameObjectTypeChoiceRenderer;

public class ReferencePopupPanel<T extends Serializable> extends SearchPopupPanel<T>{

private static final long serialVersionUID = 1L;

private static final String ID_OID = "oid";
private static final String ID_TYPE = "type";
private static final String ID_RELATION = "relation";


public ReferencePopupPanel(String id, IModel<T> model) {
super(id, model);
}

@Override
protected void onInitialize() {
super.onInitialize();
initLayout();
}

private void initLayout() {

TextField<String> oidField = new TextField<String>(ID_OID, new PropertyModel<>(getModel(), SearchValue.F_VALUE + ".oid"));

oidField.add(new AjaxFormComponentUpdatingBehavior("blur") {

private static final long serialVersionUID = 1L;

@Override
protected void onUpdate(AjaxRequestTarget target) {

}
});
oidField.setOutputMarkupId(true);
add(oidField);

DropDownChoice<QName> type = new DropDownChoice<>(ID_TYPE, new PropertyModel<QName>(getModel(), SearchValue.F_VALUE + ".type"),
WebComponentUtil.createFocusTypeList(), new QNameObjectTypeChoiceRenderer());
type.setNullValid(true);
type.setOutputMarkupId(true);
add(type);

DropDownChoice<QName> relation = new DropDownChoice<>(ID_RELATION, new PropertyModel<QName>(getModel(), SearchValue.F_VALUE + ".relation"),
WebComponentUtil.getAllRelations(getPageBase()), new QNameObjectTypeChoiceRenderer());
relation.setNullValid(true);
relation.setOutputMarkupId(true);
add(relation);
}


}

0 comments on commit 518722d

Please sign in to comment.