loadingIcon.setSrc(loadingIconPath);
successIcon.setSrc(successIconPath);
failIcon.setSrc(failedIconPath);
attentionIcon.setSrc(attentionIconPath);
final StaticTextItem groupQueryStatus = new StaticTextItem();
{
groupQueryStatus.setName("groupQueryStatus");
groupQueryStatus.setTitle(MSG.common_title_queryProgress());
groupQueryStatus.setDefaultValue(MSG.common_msg_loading());
groupQueryStatus.setIcons(loadingIcon);
}
availableGroupDetails.setItems(resultCountItem, pageCountItem, groupQueryStatus, adviceItem, searchTextItem);
// Ldap Group Settings region
final DynamicForm ldapGroupSettings = new DynamicForm();
{
ldapGroupSettings.setWidth(groupPanelWidth);
ldapGroupSettings.setHeight(groupPanelHeight);
ldapGroupSettings.setGroupTitle(MSG.view_adminRoles_ldapGroupsSettingsReadOnly());
ldapGroupSettings.setIsGroup(true);
ldapGroupSettings.setWrapItemTitles(false);
}
final TextItem groupSearch = new TextItem("groupSearch", MSG.view_admin_systemSettings_LDAPFilter_name());
{
groupSearch.setCanEdit(false);
groupSearch.setWidth("100%");
}
final TextItem groupMember = new TextItem("groupMember", MSG.view_admin_systemSettings_LDAPGroupMember_name());
{
groupMember.setCanEdit(false);
groupMember.setWidth("100%");
}
final CheckboxItem groupQueryPagingItem = new CheckboxItem("groupQueryEnable",
MSG.view_admin_systemSettings_LDAPGroupUsePaging_name());
{
groupQueryPagingItem.setCanEdit(false);
groupQueryPagingItem.setValue(false);
groupQueryPagingItem.setShowLabel(false);
groupQueryPagingItem.setShowTitle(true);
groupQueryPagingItem.setTitleOrientation(TitleOrientation.LEFT);
//You have to set this attribute
groupQueryPagingItem.setAttribute("labelAsTitle", true);
}
final TextItem groupQueryPagingCountItem = new TextItem("groupQueryCount",
MSG.view_adminRoles_ldapQueryPageSize());
{
groupQueryPagingCountItem.setCanEdit(false);
groupQueryPagingCountItem.setWidth("100%");
}
final CheckboxItem groupUsePosixGroupsItem = new CheckboxItem("groupUsePosixGroups",
MSG.view_admin_systemSettings_LDAPGroupUsePosixGroup_name());
{
groupUsePosixGroupsItem.setCanEdit(false);
groupUsePosixGroupsItem.setValue(false);
groupUsePosixGroupsItem.setShowLabel(false);
groupUsePosixGroupsItem.setShowTitle(true);
groupUsePosixGroupsItem.setTitleOrientation(TitleOrientation.LEFT);
//You have to set this attribute
groupUsePosixGroupsItem.setAttribute("labelAsTitle", true);
}
ldapGroupSettings.setItems(groupSearch, groupMember, groupQueryPagingItem, groupQueryPagingCountItem,
groupUsePosixGroupsItem);
// orient both panels next to each other
HLayout panel = new HLayout();
{
panel.addMember(availableGroupDetails);
DynamicForm spacerWrapper = new DynamicForm();
spacerWrapper.setItems(new SpacerItem());
panel.addMember(spacerWrapper);
panel.addMember(ldapGroupSettings);
}
availableFilterForm.addChild(panel);
final long ldapGroupSelectorRequestId = System.currentTimeMillis();
//launch operations to populate/refresh LDAP Group Query contents.
final Timer ldapPropertiesTimer = new Timer() {
public void run() {
//if system properties not set, launch request/update
String ldapGroupQuery = groupSearch.getValueAsString();
if ((ldapGroupQuery == null) || (ldapGroupQuery.trim().isEmpty())) {
GWTServiceLookup.getSystemService().getSystemSettings(new AsyncCallback<SystemSettings>() {
@Override
public void onFailure(Throwable caught) {
groupQueryStatus.setIcons(failIcon);
groupQueryStatus.setDefaultValue(MSG.view_adminRoles_failLdapGroupsSettings());
CoreGUI.getErrorHandler().handleError(MSG.view_adminRoles_failLdapGroupsSettings(), caught);
Log.debug(MSG.view_adminRoles_failLdapGroupsSettings());
}
@Override
public void onSuccess(SystemSettings settings) {
//retrieve relevant information once and update ui
String ldapGroupFilter = settings.get(SystemSetting.LDAP_GROUP_FILTER);
String ldapGroupMember = settings.get(SystemSetting.LDAP_GROUP_MEMBER);
String ldapGroupPagingEnabled = settings.get(SystemSetting.LDAP_GROUP_PAGING);
String ldapGroupPagingValue = settings.get(SystemSetting.LDAP_GROUP_QUERY_PAGE_SIZE);
String ldapGroupIsPosix = settings.get(SystemSetting.LDAP_GROUP_USE_POSIX);
groupSearch.setValue(ldapGroupFilter);
groupMember.setValue(ldapGroupMember);
groupQueryPagingItem.setValue(Boolean.valueOf(ldapGroupPagingEnabled));
groupQueryPagingCountItem.setValue(ldapGroupPagingValue);
groupUsePosixGroupsItem.setValue(Boolean.valueOf(ldapGroupIsPosix));
ldapGroupSettings.markForRedraw();
}
});
}
}
};
ldapPropertiesTimer.schedule(2000); // repeat interval in milliseconds, e.g. 30000 = 30seconds
//launch operations to populate/refresh LDAP Group Query contents.
final Timer availableGroupsTimer = new Timer() {
public void run() {
final String attention = MSG.common_status_attention();
final String success = MSG.common_status_success();
final String none = MSG.common_val_none();
final String failed = MSG.common_status_failed();
//make request to RHQ about state of latest LDAP GWT request
GWTServiceLookup.getLdapService().findAvailableGroupsStatus(
new AsyncCallback<Set<Map<String, String>>>() {
@Override
public void onFailure(Throwable caught) {
groupQueryStatus.setIcons(failIcon);
groupQueryStatus.setDefaultValue(failed);
String adviceValue = MSG.view_adminRoles_failLdapAvailableGroups();
adviceItem.setValue(adviceValue);
adviceItem.setTooltip(adviceValue);
CoreGUI.getErrorHandler()
.handleError(MSG.view_adminRoles_failLdapAvailableGroups(), caught);
retryAttempt++;
if (retryAttempt > 3) {
cancel();//kill thread
Log.debug(MSG.view_adminRoles_failLdapRetry());
retryAttempt = 0;
}
}
@Override
public void onSuccess(Set<Map<String, String>> results) {
long start = -1, current = -1;
int pageCount = 0;
int resultCountValue = 0;
boolean queryCompleted = false;
for (Map<String, String> map : results) {
String key = map.keySet().toArray()[0] + "";
if (key.equals("query.results.parsed")) {
String value = map.get(key);
resultCountItem.setValue(value);
resultCountValue = Integer.valueOf(value);
} else if (key.equals("query.complete")) {
String value = map.get(key);
queryCompleted = Boolean.valueOf(value);
} else if (key.equals("query.start.time")) {
String value = map.get(key);
start = Long.valueOf(value);
} else if (key.equals("query.current.time")) {
String value = map.get(key);
current = Long.valueOf(value);
} else if (key.equals("query.page.count")) {
String value = map.get(key);
pageCountItem.setValue(value);
pageCount = Integer.valueOf(value);
}
}
if (resultCountValue == 0) {
noProgressAttempts++;
}
//Update status information
String warnTooManyResults = MSG.view_adminRoles_ldapWarnTooManyResults();
String warnQueryTakingLongResults = MSG.view_adminRoles_ldapWarnQueryTakingLongResults();
String warnParsingManyPagesResults = MSG.view_adminRoles_ldapWarnParsingManyPagesResults();
boolean resultCountWarning = false;
boolean pageCountWarning = false;
boolean timePassingWarning = false;
if ((resultCountWarning = (resultCountValue > 5000))
|| (pageCountWarning = (pageCount > 5))
|| (timePassingWarning = (current - start) > 5 * 1000)) {
adviceItem.setDisabled(false);
groupQueryStatus.setIcons(attentionIcon);
if (resultCountWarning) {
adviceItem.setValue(warnTooManyResults);
adviceItem.setTooltip(warnTooManyResults);
} else if (pageCountWarning) {
adviceItem.setValue(warnParsingManyPagesResults);
adviceItem.setTooltip(warnParsingManyPagesResults);
} else if (timePassingWarning) {
adviceItem.setValue(warnQueryTakingLongResults);
adviceItem.setTooltip(warnQueryTakingLongResults);
}
}
//act on status details to add extra perf suggestions. Kill threads older than 30 mins
long parseTime = System.currentTimeMillis() - ldapGroupSelectorRequestId;
if ((queryCompleted) || (parseTime) > 30 * 60 * 1000) {
String tooManyResults = MSG.view_adminRoles_ldapTooManyResults();
String queryTookLongResults = MSG.view_adminRoles_ldapTookLongResults(parseTime + "");
String queryTookManyPagesResults = MSG
.view_adminRoles_ldapTookManyPagesResults(pageCount + "");
adviceItem.setDisabled(false);
groupQueryStatus.setIcons(attentionIcon);
groupQueryStatus.setDefaultValue(attention);
if (resultCountValue > 20000) {//results throttled
adviceItem.setValue(tooManyResults);
adviceItem.setTooltip(tooManyResults);
Log.debug(tooManyResults);//log error to client.
} else if ((current - start) >= 10 * 1000) {// took longer than 10s
adviceItem.setValue(queryTookLongResults);
adviceItem.setTooltip(queryTookLongResults);
Log.debug(queryTookLongResults);//log error to client.
} else if (pageCount >= 20) {// required more than 20 pages of results
adviceItem.setValue(queryTookManyPagesResults);
adviceItem.setTooltip(queryTookManyPagesResults);
Log.debug(queryTookManyPagesResults);//log error to client.
} else {//simple success.
groupQueryStatus.setDefaultValue(success);
groupQueryStatus.setIcons(successIcon);
adviceItem.setValue(none);
adviceItem.setTooltip(none);
adviceItem.setDisabled(true);
}
noProgressAttempts = 0;
//now cancel the timer
cancel();
} else if (noProgressAttempts >= 10) {//availGroups query stuck on server side
//cancel the timer.
cancel();
String clientSideQuitting = MSG.view_adminRoles_failLdapCancelling();//catch all
adviceItem.setDisabled(false);
groupQueryStatus.setIcons(attentionIcon);
adviceItem.setValue(clientSideQuitting);
adviceItem.setTooltip(clientSideQuitting);
noProgressAttempts = 0;
Log.debug(clientSideQuitting);//log error to client.
}