Search in sources :

Example 1 with Nullable

use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.

the class PostReviewers method addWholeGroup.

@Nullable
private Addition addWholeGroup(String reviewer, ChangeResource rsrc, ReviewerState state, NotifyHandling notify, ListMultimap<RecipientType, Account.Id> accountsToNotify, boolean confirmed, boolean allowGroup, boolean allowByEmail) throws OrmException, IOException, PermissionBackendException {
    if (!allowGroup) {
        return null;
    }
    GroupDescription.Basic group = null;
    try {
        group = groupsCollection.parseInternal(reviewer);
    } catch (UnprocessableEntityException e) {
        if (!allowByEmail) {
            return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerNotFoundUserOrGroup, reviewer));
        }
        return null;
    }
    if (!isLegalReviewerGroup(group.getGroupUUID())) {
        return fail(reviewer, MessageFormat.format(ChangeMessages.get().groupIsNotAllowed, group.getName()));
    }
    Set<Account.Id> reviewers = new HashSet<>();
    ChangeControl control = rsrc.getControl();
    Set<Account> members;
    try {
        members = groupMembersFactory.create(control.getUser()).listAccounts(group.getGroupUUID(), control.getProject().getNameKey());
    } catch (NoSuchGroupException e) {
        return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerNotFoundUserOrGroup, group.getName()));
    } catch (NoSuchProjectException e) {
        return fail(reviewer, e.getMessage());
    }
    // if maxAllowed is set to 0, it is allowed to add any number of
    // reviewers
    int maxAllowed = cfg.getInt("addreviewer", "maxAllowed", DEFAULT_MAX_REVIEWERS);
    if (maxAllowed > 0 && members.size() > maxAllowed) {
        return fail(reviewer, MessageFormat.format(ChangeMessages.get().groupHasTooManyMembers, group.getName()));
    }
    // if maxWithoutCheck is set to 0, we never ask for confirmation
    int maxWithoutConfirmation = cfg.getInt("addreviewer", "maxWithoutConfirmation", DEFAULT_MAX_REVIEWERS_WITHOUT_CHECK);
    if (!confirmed && maxWithoutConfirmation > 0 && members.size() > maxWithoutConfirmation) {
        return fail(reviewer, true, MessageFormat.format(ChangeMessages.get().groupManyMembersConfirmation, group.getName(), members.size()));
    }
    PermissionBackend.ForRef perm = permissionBackend.user(rsrc.getUser()).ref(rsrc.getChange().getDest());
    for (Account member : members) {
        if (isValidReviewer(member, perm)) {
            reviewers.add(member.getId());
        }
    }
    return new Addition(reviewer, rsrc, reviewers, null, state, notify, accountsToNotify);
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) Account(com.google.gerrit.reviewdb.client.Account) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException) GroupDescription(com.google.gerrit.common.data.GroupDescription) ChangeControl(com.google.gerrit.server.project.ChangeControl) HashSet(java.util.HashSet) Nullable(com.google.gerrit.common.Nullable)

Example 2 with Nullable

use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.

the class AccountLoader method get.

@Nullable
public synchronized AccountInfo get(@Nullable Account.Id id) {
    if (id == null) {
        return null;
    }
    AccountInfo info = created.get(id);
    if (info == null) {
        info = new AccountInfo(id.get());
        created.put(id, info);
    }
    return info;
}
Also used : AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Nullable(com.google.gerrit.common.Nullable)

Example 3 with Nullable

use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.

the class RangeUtil method getRange.

/**
 * Determine the range of values being requested in the given query.
 *
 * @param rangeQuery the raw query, e.g. "{@code added:>12345}"
 * @param minValue the minimum possible value for the field, inclusive
 * @param maxValue the maximum possible value for the field, inclusive
 * @return the calculated {@link Range}, or null if the query is invalid
 */
@Nullable
public static Range getRange(String rangeQuery, int minValue, int maxValue) {
    Matcher m = RANGE_PATTERN.matcher(rangeQuery);
    String prefix;
    String test;
    Integer queryInt;
    if (m.find()) {
        prefix = rangeQuery.substring(0, m.start());
        test = m.group(1);
        queryInt = value(m.group(2));
        if (queryInt == null) {
            return null;
        }
    } else {
        return null;
    }
    return getRange(prefix, test, queryInt, minValue, maxValue);
}
Also used : Matcher(java.util.regex.Matcher) Nullable(com.google.gerrit.common.Nullable)

Example 4 with Nullable

use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.

the class UiActions method describe.

@Nullable
private <R extends RestResource> UiAction.Description describe(Extension<RestView<R>> e, R resource) {
    int d = e.getExportName().indexOf('.');
    if (d < 0) {
        return null;
    }
    RestView<R> view;
    try {
        view = e.getProvider().get();
    } catch (RuntimeException err) {
        logger.atSevere().withCause(err).log("error creating view %s.%s", e.getPluginName(), e.getExportName());
        return null;
    }
    if (!(view instanceof UiAction)) {
        return null;
    }
    String name = e.getExportName().substring(d + 1);
    UiAction.Description dsc = null;
    try (Timer1.Context<String> ignored = uiActionLatency.start(name)) {
        dsc = ((UiAction<R>) view).getDescription(resource);
    } catch (Exception ex) {
        logger.atSevere().withCause(ex).log("Unable to render UIAction. Will omit from actions");
    }
    if (dsc == null) {
        return null;
    }
    Set<GlobalOrPluginPermission> globalRequired;
    try {
        globalRequired = GlobalPermission.fromAnnotation(e.getPluginName(), view.getClass());
    } catch (PermissionBackendException err) {
        logger.atSevere().withCause(err).log("exception testing view %s.%s", e.getPluginName(), e.getExportName());
        return null;
    }
    if (!globalRequired.isEmpty()) {
        PermissionBackend.WithUser withUser = permissionBackend.currentUser();
        Iterator<GlobalOrPluginPermission> i = globalRequired.iterator();
        BooleanCondition p = withUser.testCond(i.next());
        while (i.hasNext()) {
            p = or(p, withUser.testCond(i.next()));
        }
        dsc.setVisible(and(p, dsc.getVisibleCondition()));
    }
    PrivateInternals_UiActionDescription.setMethod(dsc, e.getExportName().substring(0, d));
    PrivateInternals_UiActionDescription.setId(dsc, PluginName.GERRIT.equals(e.getPluginName()) ? name : e.getPluginName() + '~' + name);
    return dsc;
}
Also used : BooleanCondition(com.google.gerrit.extensions.conditions.BooleanCondition) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) Description(com.google.gerrit.extensions.webui.UiAction.Description) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) UiAction(com.google.gerrit.extensions.webui.UiAction) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) Timer1(com.google.gerrit.metrics.Timer1) GlobalOrPluginPermission(com.google.gerrit.extensions.api.access.GlobalOrPluginPermission) Nullable(com.google.gerrit.common.Nullable)

Example 5 with Nullable

use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.

the class ChangeData method isMergeable.

@Nullable
public Boolean isMergeable() {
    if (mergeable == null) {
        Change c = change();
        if (c == null) {
            return null;
        }
        if (c.isMerged()) {
            mergeable = true;
        } else if (c.isAbandoned()) {
            return null;
        } else if (c.isWorkInProgress()) {
            return null;
        } else {
            if (!lazyload()) {
                return null;
            }
            PatchSet ps = currentPatchSet();
            if (ps == null) {
                return null;
            }
            try (Repository repo = repoManager.openRepository(project())) {
                Ref ref = repo.getRefDatabase().exactRef(c.getDest().branch());
                SubmitTypeRecord str = submitTypeRecord();
                if (!str.isOk()) {
                    // No need to log, as SubmitRuleEvaluator already did it for us.
                    return false;
                }
                String mergeStrategy = mergeUtilFactory.create(projectCache.get(project()).orElseThrow(illegalState(project()))).mergeStrategyName();
                mergeable = mergeabilityCache.get(ps.commitId(), ref, str.type, mergeStrategy, c.getDest(), repo);
            } catch (IOException e) {
                throw new StorageException(e);
            }
        }
    }
    return mergeable;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) StarRef(com.google.gerrit.server.StarredChangesUtil.StarRef) Ref(org.eclipse.jgit.lib.Ref) SubmitTypeRecord(com.google.gerrit.entities.SubmitTypeRecord) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException) Nullable(com.google.gerrit.common.Nullable)

Aggregations

Nullable (com.google.gerrit.common.Nullable)20 IOException (java.io.IOException)6 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)5 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)5 HashSet (java.util.HashSet)4 Ref (org.eclipse.jgit.lib.Ref)4 Account (com.google.gerrit.entities.Account)3 PatchSet (com.google.gerrit.entities.PatchSet)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Change (com.google.gerrit.entities.Change)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 Timer0 (com.google.gerrit.metrics.Timer0)2 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)2 NoSuchProjectException (com.google.gerrit.server.project.NoSuchProjectException)2 Inject (com.google.inject.Inject)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 Repository (org.eclipse.jgit.lib.Repository)2 AutoValue (com.google.auto.value.AutoValue)1