use of com.google.gerrit.common.data.ParameterizedString in project gerrit by GerritCodeReview.
the class LdapGroupBackend method suggestLdap.
private Set<GroupReference> suggestLdap(String name) {
if (name.isEmpty()) {
return Collections.emptySet();
}
Set<GroupReference> out = Sets.newTreeSet(GROUP_REF_NAME_COMPARATOR);
try {
DirContext ctx = helper.open();
try {
// Do exact lookups until there are at least 3 characters.
name = Rdn.escapeValue(name) + ((name.length() >= 3) ? "*" : "");
LdapSchema schema = helper.getSchema(ctx);
ParameterizedString filter = ParameterizedString.asis(schema.groupPattern.replace(GROUPNAME, name).toString());
Set<String> returnAttrs = new HashSet<>(schema.groupName.getParameterNames());
Map<String, String> params = Collections.emptyMap();
for (String groupBase : schema.groupBases) {
LdapQuery query = new LdapQuery(groupBase, schema.groupScope, filter, returnAttrs);
for (LdapQuery.Result res : query.query(ctx, params)) {
out.add(groupReference(schema.groupName, res));
}
}
} finally {
try {
ctx.close();
} catch (NamingException e) {
log.warn("Cannot close LDAP query handle", e);
}
}
} catch (NamingException | LoginException e) {
log.warn("Cannot query LDAP for groups matching requested name", e);
}
return out;
}
use of com.google.gerrit.common.data.ParameterizedString in project gerrit by GerritCodeReview.
the class LdapGroupBackend method suggestLdap.
private Set<GroupReference> suggestLdap(String name) {
if (name.isEmpty()) {
return Collections.emptySet();
}
Set<GroupReference> out = Sets.newTreeSet(GROUP_REF_NAME_COMPARATOR);
try {
DirContext ctx = helper.open();
try {
// Do exact lookups until there are at least 3 characters.
name = Rdn.escapeValue(name) + ((name.length() >= 3) ? "*" : "");
LdapSchema schema = helper.getSchema(ctx);
ParameterizedString filter = ParameterizedString.asis(schema.groupPattern.replace(GROUPNAME, name).toString());
Set<String> returnAttrs = new HashSet<>(schema.groupName.getParameterNames());
Map<String, String> params = Collections.emptyMap();
for (String groupBase : schema.groupBases) {
LdapQuery query = new LdapQuery(groupBase, schema.groupScope, filter, returnAttrs);
for (LdapQuery.Result res : query.query(ctx, params, helper.getGroupSearchLatencyTimer())) {
out.add(groupReference(schema.groupName, res));
}
}
} finally {
helper.close(ctx);
}
} catch (IOException | NamingException | LoginException e) {
logger.atWarning().withCause(e).log("Cannot query LDAP for groups matching requested name");
}
return out;
}
use of com.google.gerrit.common.data.ParameterizedString in project gerrit by GerritCodeReview.
the class LdapRealm method apply.
static String apply(ParameterizedString p, LdapQuery.Result m) throws NamingException {
if (p == null) {
return null;
}
final Map<String, String> values = new HashMap<>();
for (String name : m.attributes()) {
values.put(name, m.get(name));
}
String r = p.replace(values).trim();
return r.isEmpty() ? null : r;
}
use of com.google.gerrit.common.data.ParameterizedString in project gerrit by GerritCodeReview.
the class LdapRealm method apply.
static String apply(ParameterizedString p, LdapQuery.Result m) throws NamingException {
if (p == null) {
return null;
}
final Map<String, String> values = new HashMap<>();
for (final String name : m.attributes()) {
values.put(name, m.get(name));
}
String r = p.replace(values);
return r.isEmpty() ? null : r;
}
use of com.google.gerrit.common.data.ParameterizedString in project gerrit by GerritCodeReview.
the class Submit method getDescription.
@Override
public UiAction.Description getDescription(RevisionResource resource) {
Change change = resource.getChange();
String topic = change.getTopic();
ReviewDb db = dbProvider.get();
ChangeData cd = changeDataFactory.create(db, resource.getControl());
boolean visible;
try {
visible = change.getStatus().isOpen() && resource.isCurrent() && !resource.getPatchSet().isDraft() && resource.permissions().test(ChangePermission.SUBMIT);
MergeOp.checkSubmitRule(cd);
} catch (ResourceConflictException e) {
visible = false;
} catch (PermissionBackendException e) {
log.error("Error checking if change is submittable", e);
throw new OrmRuntimeException("Could not check submit permission", e);
} catch (OrmException e) {
log.error("Error checking if change is submittable", e);
throw new OrmRuntimeException("Could not determine problems for the change", e);
}
if (!visible) {
return new UiAction.Description().setLabel("").setTitle("").setVisible(false);
}
ChangeSet cs;
try {
cs = mergeSuperSet.get().completeChangeSet(db, cd.change(), resource.getControl().getUser());
} catch (OrmException | IOException e) {
throw new OrmRuntimeException("Could not determine complete set of changes to be submitted", e);
}
int topicSize = 0;
if (!Strings.isNullOrEmpty(topic)) {
topicSize = getChangesByTopic(topic).size();
}
boolean treatWithTopic = submitWholeTopic && !Strings.isNullOrEmpty(topic) && topicSize > 1;
String submitProblems = problemsForSubmittingChangeset(cd, cs, resource.getUser());
Boolean enabled;
try {
// Recheck mergeability rather than using value stored in the index,
// which may be stale.
// TODO(dborowitz): This is ugly; consider providing a way to not read
// stored fields from the index in the first place.
// cd.setMergeable(null);
// That was done in unmergeableChanges which was called by
// problemsForSubmittingChangeset, so now it is safe to read from
// the cache, as it yields the same result.
enabled = cd.isMergeable();
} catch (OrmException e) {
throw new OrmRuntimeException("Could not determine mergeability", e);
}
if (submitProblems != null) {
return new UiAction.Description().setLabel(treatWithTopic ? submitTopicLabel : (cs.size() > 1) ? labelWithParents : label).setTitle(submitProblems).setVisible(true).setEnabled(false);
}
if (treatWithTopic) {
Map<String, String> params = ImmutableMap.of("topicSize", String.valueOf(topicSize), "submitSize", String.valueOf(cs.size()));
return new UiAction.Description().setLabel(submitTopicLabel).setTitle(Strings.emptyToNull(submitTopicTooltip.replace(params))).setVisible(true).setEnabled(Boolean.TRUE.equals(enabled));
}
RevId revId = resource.getPatchSet().getRevision();
Map<String, String> params = ImmutableMap.of("patchSet", String.valueOf(resource.getPatchSet().getPatchSetId()), "branch", change.getDest().getShortName(), "commit", ObjectId.fromString(revId.get()).abbreviate(7).name(), "submitSize", String.valueOf(cs.size()));
ParameterizedString tp = cs.size() > 1 ? titlePatternWithAncestors : titlePattern;
return new UiAction.Description().setLabel(cs.size() > 1 ? labelWithParents : label).setTitle(Strings.emptyToNull(tp.replace(params))).setVisible(true).setEnabled(Boolean.TRUE.equals(enabled));
}
Aggregations