use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.
the class ProjectWatch method getWatchers.
/** Returns all watchers that are relevant */
public final Watchers getWatchers(NotifyType type, boolean includeWatchersFromNotifyConfig) throws OrmException {
Watchers matching = new Watchers();
Set<Account.Id> projectWatchers = new HashSet<>();
for (AccountState a : args.accountQueryProvider.get().byWatchedProject(project)) {
Account.Id accountId = a.getAccount().getId();
for (Map.Entry<ProjectWatchKey, Set<NotifyType>> e : a.getProjectWatches().entrySet()) {
if (project.equals(e.getKey().project()) && add(matching, accountId, e.getKey(), e.getValue(), type)) {
// We only want to prevent matching All-Projects if this filter hits
projectWatchers.add(accountId);
}
}
}
for (AccountState a : args.accountQueryProvider.get().byWatchedProject(args.allProjectsName)) {
for (Map.Entry<ProjectWatchKey, Set<NotifyType>> e : a.getProjectWatches().entrySet()) {
if (args.allProjectsName.equals(e.getKey().project())) {
Account.Id accountId = a.getAccount().getId();
if (!projectWatchers.contains(accountId)) {
add(matching, accountId, e.getKey(), e.getValue(), type);
}
}
}
}
if (!includeWatchersFromNotifyConfig) {
return matching;
}
for (ProjectState state : projectState.tree()) {
for (NotifyConfig nc : state.getConfig().getNotifyConfigs()) {
if (nc.isNotify(type)) {
try {
add(matching, nc);
} catch (QueryParseException e) {
log.warn("Project {} has invalid notify {} filter \"{}\": {}", state.getProject().getName(), nc.getName(), nc.getFilter(), e.getMessage());
}
}
}
}
return matching;
}
use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.
the class ProjectLevelConfig method getWithInheritance.
public Config getWithInheritance() {
Config cfgWithInheritance = new Config();
try {
cfgWithInheritance.fromText(get().toText());
} catch (ConfigInvalidException e) {
// cannot happen
}
ProjectState parent = Iterables.getFirst(project.parents(), null);
if (parent != null) {
Config parentCfg = parent.getConfig(fileName).getWithInheritance();
for (String section : parentCfg.getSections()) {
Set<String> allNames = get().getNames(section);
for (String name : parentCfg.getNames(section)) {
if (!allNames.contains(name)) {
cfgWithInheritance.setStringList(section, null, name, Arrays.asList(parentCfg.getStringList(section, null, name)));
}
}
for (String subsection : parentCfg.getSubsections(section)) {
allNames = get().getNames(section, subsection);
for (String name : parentCfg.getNames(section, subsection)) {
if (!allNames.contains(name)) {
cfgWithInheritance.setStringList(section, subsection, name, Arrays.asList(parentCfg.getStringList(section, subsection, name)));
}
}
}
}
}
return cfgWithInheritance;
}
use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.
the class GitwebServlet method service.
@Override
protected void service(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
if (req.getQueryString() == null || req.getQueryString().isEmpty()) {
// No query string? They want the project list, which we don't
// currently support. Return to Gerrit's own web UI.
//
rsp.sendRedirect(req.getContextPath() + "/");
return;
}
final Map<String, String> params = getParameters(req);
String a = params.get("a");
if (a != null) {
if (deniedActions.contains(a)) {
rsp.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
if (a.equals(PROJECT_LIST_ACTION)) {
rsp.sendRedirect(req.getContextPath() + "/#" + PageLinks.ADMIN_PROJECTS + "?filter=" + Url.encode(params.get("pf") + "/"));
return;
}
}
String name = params.get("p");
if (name == null) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
if (name.endsWith(".git")) {
name = name.substring(0, name.length() - 4);
}
Project.NameKey nameKey = Project.nameKey(name);
Optional<ProjectState> projectState;
try {
projectState = projectCache.get(nameKey);
if (!projectState.isPresent()) {
sendErrorOrRedirect(req, rsp, HttpServletResponse.SC_NOT_FOUND);
return;
}
projectState.get().checkStatePermitsRead();
permissionBackend.user(userProvider.get()).project(nameKey).check(ProjectPermission.READ);
} catch (AuthException e) {
sendErrorOrRedirect(req, rsp, HttpServletResponse.SC_NOT_FOUND);
return;
} catch (IOException | PermissionBackendException err) {
logger.atSevere().withCause(err).log("cannot load %s", name);
rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
} catch (ResourceConflictException e) {
sendErrorOrRedirect(req, rsp, HttpServletResponse.SC_CONFLICT);
return;
}
try (Repository repo = repoManager.openRepository(nameKey)) {
CacheHeaders.setNotCacheable(rsp);
exec(req, rsp, projectState.get());
} catch (RepositoryNotFoundException e) {
getServletContext().log("Cannot open repository", e);
rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.
the class ProjectIndexerImpl method index.
@Override
public void index(Project.NameKey nameKey) {
Optional<ProjectState> projectState = projectCache.get(nameKey);
if (projectState.isPresent()) {
logger.atFine().log("Replace project %s in index", nameKey.get());
ProjectData projectData = projectState.get().toProjectData();
for (ProjectIndex i : getWriteIndexes()) {
try (TraceTimer traceTimer = TraceContext.newTimer("Replacing project", Metadata.builder().projectName(nameKey.get()).indexVersion(i.getSchema().getVersion()).build())) {
i.replace(projectData);
} catch (RuntimeException e) {
throw new StorageException(String.format("Failed to replace project %s in index version %d", nameKey.get(), i.getSchema().getVersion()), e);
}
}
fireProjectIndexedEvent(nameKey.get());
} else {
logger.atFine().log("Delete project %s from index", nameKey.get());
for (ProjectIndex i : getWriteIndexes()) {
try (TraceTimer traceTimer = TraceContext.newTimer("Deleting project", Metadata.builder().projectName(nameKey.get()).indexVersion(i.getSchema().getVersion()).build())) {
i.delete(nameKey);
} catch (RuntimeException e) {
throw new StorageException(String.format("Failed to delete project %s from index version %d", nameKey.get(), i.getSchema().getVersion()), e);
}
}
}
}
use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.
the class PatchScriptFactory method call.
@Override
public PatchScript call() throws LargeObjectException, AuthException, InvalidChangeOperationException, IOException, PermissionBackendException {
try {
permissionBackend.user(currentUser).change(notes).check(ChangePermission.READ);
} catch (AuthException e) {
throw new NoSuchChangeException(changeId, e);
}
if (!projectCache.get(notes.getProjectName()).map(ProjectState::statePermitsRead).orElse(false)) {
throw new NoSuchChangeException(changeId);
}
try (Repository git = repoManager.openRepository(notes.getProjectName())) {
try {
validatePatchSetId(psa);
validatePatchSetId(psb);
ObjectId aId = getAId().orElse(null);
ObjectId bId = getBId().orElse(null);
if (bId == null) {
// Change edit: create synthetic PatchSet corresponding to the edit.
Optional<ChangeEdit> edit = editReader.byChange(notes);
if (!edit.isPresent()) {
throw new NoSuchChangeException(notes.getChangeId());
}
bId = edit.get().getEditCommit();
}
return getPatchScript(git, aId, bId);
} catch (DiffNotAvailableException e) {
throw new StorageException(e);
} catch (IOException e) {
logger.atSevere().withCause(e).log("File content unavailable");
throw new NoSuchChangeException(changeId, e);
} catch (org.eclipse.jgit.errors.LargeObjectException err) {
throw new LargeObjectException("File content is too large", err);
}
} catch (RepositoryNotFoundException e) {
logger.atSevere().withCause(e).log("Repository %s not found", notes.getProjectName());
throw new NoSuchChangeException(changeId, e);
} catch (IOException e) {
logger.atSevere().withCause(e).log("Cannot open repository %s", notes.getProjectName());
throw new NoSuchChangeException(changeId, e);
}
}
Aggregations