Skip to content

Commit

Permalink
Bidirectional link between "advanced filter" panel and query playground.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Aug 1, 2016
1 parent 0de1c97 commit 5de252c
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 50 deletions.
Expand Up @@ -195,17 +195,28 @@ public final class WebComponentUtil {
private static final Trace LOGGER = TraceManager.getTrace(WebComponentUtil.class);
private static DatatypeFactory df = null;

private static Map<Class<?>, Class<? extends PageBase>> objectDetailsMap;
private static Map<Class<?>, Class<? extends PageBase>> objectDetailsPageMap;

static {
objectDetailsMap = new HashMap<>();
objectDetailsMap.put(UserType.class, PageUser.class);
objectDetailsMap.put(OrgType.class, PageOrgUnit.class);
objectDetailsMap.put(RoleType.class, PageRole.class);
objectDetailsMap.put(ServiceType.class, PageService.class);
objectDetailsMap.put(ResourceType.class, PageResource.class);
objectDetailsMap.put(TaskType.class, PageTaskEdit.class);
objectDetailsMap.put(ReportType.class, PageReport.class);
objectDetailsPageMap = new HashMap<>();
objectDetailsPageMap.put(UserType.class, PageUser.class);
objectDetailsPageMap.put(OrgType.class, PageOrgUnit.class);
objectDetailsPageMap.put(RoleType.class, PageRole.class);
objectDetailsPageMap.put(ServiceType.class, PageService.class);
objectDetailsPageMap.put(ResourceType.class, PageResource.class);
objectDetailsPageMap.put(TaskType.class, PageTaskEdit.class);
objectDetailsPageMap.put(ReportType.class, PageReport.class);
}

// only pages that support 'advanced search' are currently listed here (TODO: generalize)
private static Map<Class<?>, Class<? extends PageBase>> objectListPageMap;

static {
objectListPageMap = new HashMap<>();
objectListPageMap.put(UserType.class, PageUsers.class);
objectListPageMap.put(RoleType.class, PageRoles.class);
objectListPageMap.put(ServiceType.class, PageServices.class);
objectListPageMap.put(ResourceType.class, PageResources.class);
}

private static Map<Class<?>, String> storageKeyMap;
Expand Down Expand Up @@ -1546,7 +1557,7 @@ public static void dispatchToObjectDetailsPage(ObjectReferenceType objectRef, Co

// shows the actual object that is passed via parameter (not its state in repository)
public static void dispatchToObjectDetailsPage(PrismObject obj, Component component) {
Class newObjectPageClass = objectDetailsMap.get(obj.getCompileTimeClass());
Class newObjectPageClass = getObjectDetailsPage(obj.getCompileTimeClass());
if (newObjectPageClass == null) {
throw new IllegalArgumentException("Cannot determine details page for "+obj.getCompileTimeClass());
}
Expand Down Expand Up @@ -1574,11 +1585,10 @@ public static void dispatchToObjectDetailsPage(PrismObject obj, Component compon
public static void dispatchToObjectDetailsPage(Class<? extends ObjectType> objectClass, String oid, Component component, boolean failIfUnsupported) {
PageParameters parameters = new PageParameters();
parameters.add(OnePageParameterEncoder.PARAMETER, oid);
Class<? extends PageBase> page = objectDetailsMap.get(objectClass);
Class<? extends PageBase> page = getObjectDetailsPage(objectClass);
if (page != null) {
component.setResponsePage(page, parameters);
} else if (failIfUnsupported) {
// todo maybe we could use "error" + RestartResponseException, as it was e.g. in AbstractRoleMemberPanel before refactoring (MID-3233)
throw new SystemException("Cannot determine details page for "+objectClass);
}
}
Expand All @@ -1589,7 +1599,7 @@ public static boolean hasDetailsPage(PrismObject<?> object) {
}

public static boolean hasDetailsPage(Class<?> clazz) {
return objectDetailsMap.containsKey(clazz);
return objectDetailsPageMap.containsKey(clazz);
}

public static boolean hasDetailsPage(ObjectReferenceType ref) {
Expand All @@ -1603,6 +1613,26 @@ public static boolean hasDetailsPage(ObjectReferenceType ref) {
return hasDetailsPage(t.getClassDefinition());
}

public static String getStorageKeyForPage(Class<?> pageClass) {
return storageKeyMap.get(pageClass);
}

public static Class<? extends PageBase> getObjectDetailsPage(Class<? extends ObjectType> type) {
return objectDetailsPageMap.get(type);
}

public static Class<? extends PageBase> getObjectListPage(Class<? extends ObjectType> type) {
return objectListPageMap.get(type);
}

public static String getStorageKeyForObjectClass(Class<? extends ObjectType> type) {
Class<? extends PageBase> listPageClass = getObjectListPage(type);
if (listPageClass == null) {
return null;
}
return getStorageKeyForPage(listPageClass);
}

@NotNull
public static TabbedPanel<ITab> createTabPanel(
String id, final PageBase parentPage, final List<ITab> tabs, TabbedPanel.RightSideItemProvider provider) {
Expand Down Expand Up @@ -1731,9 +1761,4 @@ public static void setSelectedTabFromPageParameters(TabbedPanel tabbed, PagePara

tabbed.setSelectedTab(tabIndex);
}

public static String getStorageKeyForPage(Class<?> pageClass) {
return storageKeyMap.get(pageClass);
}

}
Expand Up @@ -20,6 +20,7 @@
<div class="form-group has-feedback" wicket:id="advancedGroup">
<label class="control-label" style="vertical-align: top;">
<i class="fa fa-lg" wicket:id="advancedCheck"/>
<div wicket:id="advancedDebug"/>
</label>
<textarea class="form-control input-sm" rows="2" wicket:id="advancedArea"
style="width: 220px; height: 60px; overflow: hidden;"
Expand Down
Expand Up @@ -22,12 +22,15 @@
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
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.column.LinkIconPanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;

import com.evolveum.midpoint.web.page.admin.configuration.PageRepositoryQuery;
import com.evolveum.midpoint.web.security.SecurityUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
Expand All @@ -36,7 +39,6 @@
import org.apache.wicket.ajax.attributes.ThrottlingSettings;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.html.WebMarkupContainer;
Expand All @@ -53,6 +55,7 @@
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.util.time.Duration;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -83,10 +86,12 @@ public class SearchPanel extends BasePanel<Search> {
private static final String ID_MORE_GROUP = "moreGroup";
private static final String ID_ADVANCED_AREA = "advancedArea";
private static final String ID_ADVANCED_CHECK = "advancedCheck";
private static final String ID_ADVANCED_DEBUG = "advancedDebug";
private static final String ID_ADVANCED_ERROR= "advancedError";

private LoadableModel<MoreDialogDto> moreDialogModel;
boolean advancedSearch = true;
boolean queryPlagroundAccessible;

public SearchPanel(String id, IModel<Search> model) {
this(id, model, true);
Expand All @@ -95,6 +100,7 @@ public SearchPanel(String id, IModel<Search> model) {
public SearchPanel(String id, IModel<Search> model, boolean advancedSearch) {
super(id, model);
this.advancedSearch = advancedSearch;
queryPlagroundAccessible = SecurityUtils.isPageAuthorized(PageRepositoryQuery.class);
initLayout();
}

Expand Down Expand Up @@ -204,6 +210,30 @@ public boolean isVisible() {
advancedCheck.add(AttributeAppender.append("class", createAdvancedGroupLabelStyle()));
advancedGroup.add(advancedCheck);

final LinkIconPanel advancedDebug = new LinkIconPanel(ID_ADVANCED_DEBUG, new Model("fa fa-lg fa-bug"), createStringResource("SearchPanel.debug")) {
@Override
protected void onClickPerformed(AjaxRequestTarget target) {
Search search = getModelObject();
PageRepositoryQuery pageQuery;
if (search != null) {
ObjectTypes type = search.getType() != null ? ObjectTypes.getObjectType(search.getType()) : null;
QName typeName = type != null ? type.getTypeQName() : null;
String inner = search.getAdvancedQuery();
if (StringUtils.isNotBlank(inner)) {
inner = "\n" + inner + "\n";
} else if (inner == null) {
inner = "";
}
pageQuery = new PageRepositoryQuery(typeName, "<query>" + inner + "</query>");
} else {
pageQuery = new PageRepositoryQuery();
}
SearchPanel.this.setResponsePage(pageQuery);
}
};
advancedDebug.setVisible(queryPlagroundAccessible);
advancedGroup.add(advancedDebug);

final TextArea advancedArea = new TextArea(ID_ADVANCED_AREA,
new PropertyModel(getModel(), Search.F_ADVANCED_QUERY));
advancedArea.add(new AjaxFormComponentUpdatingBehavior("keyup") {
Expand Down
Expand Up @@ -35,9 +35,10 @@ <h3><wicket:message key="PageRepositoryQuery.midPoint"/></h3>
<select id="querySample" class="input-sm form-control" wicket:id="querySample"/>
</div>
<p class="small" style="margin-top: 5px"><wicket:message key="PageRepositoryQuery.queryVsFilterNote"/></p>
<div class="main-button-bar">
<div class="main-button-bar" wicket:id="midPointQueryButtonBar">
<a class="btn btn-primary" wicket:id="executeMidPoint"/>
<a class="btn btn-default" wicket:id="compileMidPoint"/>
<a class="btn btn-success" wicket:id="useInObjectList"/>
</div>
</div>
<div class="col-md-6">
Expand Down

0 comments on commit 5de252c

Please sign in to comment.