Skip to content

Commit

Permalink
org tree members panel - configurable scope and object type
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Oct 29, 2018
1 parent bc23105 commit e977303
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
Expand Up @@ -48,6 +48,7 @@
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

Expand Down Expand Up @@ -119,12 +120,9 @@ protected enum MemberOperation {
private static final String ID_INDIRECT_MEMBERS = "indirectMembers";

protected static final String ID_SEARCH_SCOPE = "searchScope";
public static final String SEARCH_SCOPE_SUBTREE = "subtree";
protected static final String SEARCH_SCOPE_ONE = "one";
protected static final List<String> SEARCH_SCOPE_VALUES = Arrays.asList(SEARCH_SCOPE_SUBTREE,
SEARCH_SCOPE_ONE);
protected SearchBoxScopeType scopeDefaultValue = null;
protected QName objectTypeDefaultValue = null;


protected static final String ID_SEARCH_BY_RELATION = "searchByRelation";

private static Map<QName, Map<String, String>> authorizations = new HashMap<>();
Expand Down Expand Up @@ -156,12 +154,35 @@ protected void initLayout() {
Form<?> form = new com.evolveum.midpoint.web.component.form.Form(ID_FORM);
form.setOutputMarkupId(true);
add(form);
initDefaultSearchParameters();
initSearch(form);
initMemberTable(form);
setOutputMarkupId(true);

}

private void initDefaultSearchParameters(){
GuiObjectListViewType panelConfig = WebComponentUtil.getViewTypeConfig(getComplexTypeQName(), getPageBase());
if (panelConfig != null && panelConfig.getSearchBoxConfiguration() != null) {
scopeDefaultValue = panelConfig.getSearchBoxConfiguration().getDefaultScope();
objectTypeDefaultValue = panelConfig.getSearchBoxConfiguration().getDefaultObjectType();
}
if (scopeDefaultValue == null){
scopeDefaultValue = SearchBoxScopeType.SUBTREE;
}
if (objectTypeDefaultValue == null){
objectTypeDefaultValue = WebComponentUtil.classToQName(getPrismContext(), getDefaultObjectType());
}
if (getMemberPanelStorage() != null){
if (getMemberPanelStorage().getOrgSearchScope() == null){
getMemberPanelStorage().setOrgSearchScope(scopeDefaultValue);
}
if (getMemberPanelStorage().getType() == null){
getMemberPanelStorage().setType(ObjectTypes.getObjectType(objectTypeDefaultValue.getLocalPart()));
}
}
}

protected Form<?> getForm() {
return (Form) get(ID_FORM);
}
Expand Down Expand Up @@ -541,16 +562,20 @@ protected ObjectQuery getActionQuery(QueryScope scope, Collection<QName> relatio
}

protected void initSearch(Form<?> form) {

DropDownFormGroup<String> searchScrope = createDropDown(ID_SEARCH_SCOPE,
Model.of(getMemberPanelStorage() != null ? getMemberPanelStorage().getOrgSearchScope() : SEARCH_SCOPE_SUBTREE),
SEARCH_SCOPE_VALUES,
new StringResourceChoiceRenderer("TreeTablePanel.search.scope"), "abstractRoleMemberPanel.searchScope", "abstractRoleMemberPanel.searchScope.tooltip");

List<SearchBoxScopeType> scopeValues = Arrays.asList(SearchBoxScopeType.values());
DropDownFormGroup<SearchBoxScopeType> searchScrope = createDropDown(ID_SEARCH_SCOPE,
Model.of(getMemberPanelStorage() != null ? getMemberPanelStorage().getOrgSearchScope() : scopeDefaultValue),
scopeValues,
WebComponentUtil.getEnumChoiceRenderer(AbstractRoleMemberPanel.this),
"abstractRoleMemberPanel.searchScope", "abstractRoleMemberPanel.searchScope.tooltip");
searchScrope.add(new VisibleBehaviour(() -> getModelObject() instanceof OrgType));
form.add(searchScrope);

DropDownFormGroup<QName> typeSelect = createDropDown(ID_OBJECT_TYPE, Model.of(WebComponentUtil.classToQName(getPrismContext(), getDefaultObjectType())),
getSupportedObjectTypes(), new QNameObjectTypeChoiceRenderer(), "abstractRoleMemberPanel.type", "abstractRoleMemberPanel.type.tooltip");
DropDownFormGroup<QName> typeSelect = createDropDown(ID_OBJECT_TYPE,
Model.of(getMemberPanelStorage() != null ? getMemberPanelStorage().getType().getTypeQName() : WebComponentUtil.classToQName(getPrismContext(), getDefaultObjectType())),
getSupportedObjectTypes(), new QNameObjectTypeChoiceRenderer(),
"abstractRoleMemberPanel.type", "abstractRoleMemberPanel.type.tooltip");
form.add(typeSelect);

RelationDropDownChoicePanel relationSelector = new RelationDropDownChoicePanel(ID_SEARCH_BY_RELATION,
Expand Down Expand Up @@ -586,7 +611,8 @@ protected void onUpdate(AjaxRequestTarget target) {

});

includeIndirectMembers.getCheck().add(new EnableBehaviour(() -> getSearchScopeValue().equals(SEARCH_SCOPE_ONE) || !searchScrope.isVisible()));
includeIndirectMembers.getCheck().add(new EnableBehaviour(() ->
getSearchScopeValue().equals(SearchBoxScopeType.ONE_LEVEL) || !searchScrope.isVisible()));
includeIndirectMembers.setOutputMarkupId(true);
form.add(includeIndirectMembers);

Expand Down Expand Up @@ -714,11 +740,11 @@ protected QName getSelectedRelation(){
return relationDropDown.getRelationValue();
}

private String getSearchScopeValue(){
private SearchBoxScopeType getSearchScopeValue(){
if (getMemberPanelStorage() != null){
return getMemberPanelStorage().getOrgSearchScope();
}
DropDownFormGroup<String> searchScopeComponent = (DropDownFormGroup<String>)get(createComponentPath(ID_FORM, ID_SEARCH_SCOPE));
DropDownFormGroup<SearchBoxScopeType> searchScopeComponent = (DropDownFormGroup<SearchBoxScopeType>)get(createComponentPath(ID_FORM, ID_SEARCH_SCOPE));
return searchScopeComponent.getModelObject();
}

Expand Down Expand Up @@ -920,7 +946,8 @@ protected void updateMembersPanelSessionStorage(){
storage.setIndirect(indirectPanel.getValue());
}

DropDownFormGroup<String> searchScopeComponent = (DropDownFormGroup<String>)get(createComponentPath(ID_FORM, ID_SEARCH_SCOPE));
DropDownFormGroup<SearchBoxScopeType> searchScopeComponent =
(DropDownFormGroup<SearchBoxScopeType>)get(createComponentPath(ID_FORM, ID_SEARCH_SCOPE));
storage.setOrgSearchScope(searchScopeComponent.getModelObject());
}
}
Expand Down
Expand Up @@ -67,7 +67,7 @@ protected void initLayout() {
@Override
protected ObjectQuery createMemberQuery(boolean indirect, Collection<QName> relations) {
ObjectTypes searchType = getSearchType();
if (SEARCH_SCOPE_ONE.equals(getOrgSearchScope())) {
if (SearchBoxScopeType.ONE_LEVEL.equals(getOrgSearchScope())) {
if (FocusType.class.isAssignableFrom(searchType.getClassDefinition())) {
return super.createMemberQuery(indirect, relations);
}
Expand All @@ -93,8 +93,8 @@ protected ObjectQuery createMemberQuery(boolean indirect, Collection<QName> rela

}

protected String getOrgSearchScope() {
DropDownFormGroup<String> searchorgScope = (DropDownFormGroup<String>) get(
protected SearchBoxScopeType getOrgSearchScope() {
DropDownFormGroup<SearchBoxScopeType> searchorgScope = (DropDownFormGroup<SearchBoxScopeType>) get(
createComponentPath(ID_FORM, ID_SEARCH_SCOPE));
return searchorgScope.getModelObject();
}
Expand Down
Expand Up @@ -20,11 +20,9 @@
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.web.component.search.Search;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SearchBoxScopeType;

import javax.xml.namespace.QName;

import static com.evolveum.midpoint.web.page.admin.roles.AbstractRoleMemberPanel.SEARCH_SCOPE_SUBTREE;

/**
* Created by honchar
*/
Expand All @@ -34,16 +32,16 @@ public class MemberPanelStorage implements PageStorage{
private ObjectPaging orgMemberPanelPaging;

private Search search;
private String orgSearchScope = SEARCH_SCOPE_SUBTREE;
private SearchBoxScopeType orgSearchScope;
private Boolean isIndirect = false;
private QName relation = null;
private ObjectTypes type = null;

public String getOrgSearchScope() {
public SearchBoxScopeType getOrgSearchScope() {
return orgSearchScope;
}

public void setOrgSearchScope(String orgSearchScope) {
public void setOrgSearchScope(SearchBoxScopeType orgSearchScope) {
this.orgSearchScope = orgSearchScope;
}

Expand Down
Expand Up @@ -1154,4 +1154,6 @@ ObjectType.deputy=Deputy
ObjectType.approver=Approver
ObjectType.owner=Owner
ObjectType.consent=Consent
ObjectType.any=Any
ObjectType.any=Any
SearchBoxScopeType.ONE_LEVEL=One level
SearchBoxScopeType.SUBTREE=Subtree

0 comments on commit e977303

Please sign in to comment.