use of org.opengrok.indexer.configuration.Group in project OpenGrok by OpenGrok.
the class PageConfig method getRequestedProjects.
/**
* Same as {@link #getRequestedProjects()}, but with a variable cookieName
* and parameter name.
*
* @param searchAllParamName the name of the request parameter corresponding to search all projects.
* @param projectParamName the name of the request parameter corresponding to a project name.
* @param groupParamName the name of the request parameter corresponding to a group name
* @param cookieName name of the cookie which possible contains project
* names used as fallback
* @return set of project names. Possibly empty set but never {@code null}.
*/
protected SortedSet<String> getRequestedProjects(String searchAllParamName, String projectParamName, String groupParamName, String cookieName) {
TreeSet<String> projectNames = new TreeSet<>();
List<Project> projects = getEnv().getProjectList();
if (Boolean.parseBoolean(req.getParameter(searchAllParamName))) {
return getProjectHelper().getAllProjects().stream().map(Project::getName).collect(Collectors.toCollection(TreeSet::new));
}
// Use a project determined directly from the URL
if (getProject() != null && getProject().isIndexed()) {
projectNames.add(getProject().getName());
return projectNames;
}
// Use a project if there is just a single project.
if (projects.size() == 1) {
Project p = projects.get(0);
if (p.isIndexed() && authFramework.isAllowed(req, p)) {
projectNames.add(p.getName());
}
return projectNames;
}
// Add all projects which match the project parameter name values/
List<String> names = getParameterValues(projectParamName);
for (String projectName : names) {
Project project = Project.getByName(projectName);
if (project != null && project.isIndexed() && authFramework.isAllowed(req, project)) {
projectNames.add(projectName);
}
}
// Add all projects which are part of a group that matches the group parameter name.
names = getParameterValues(groupParamName);
for (String groupName : names) {
Group group = Group.getByName(groupName);
if (group != null) {
projectNames.addAll(getProjectHelper().getAllGrouped(group).stream().filter(Project::isIndexed).map(Project::getName).collect(Collectors.toSet()));
}
}
// Add projects based on cookie.
if (projectNames.isEmpty() && getIntParam(QueryParameters.NUM_SELECTED_PARAM, -1) != 0) {
List<String> cookies = getCookieVals(cookieName);
for (String s : cookies) {
Project x = Project.getByName(s);
if (x != null && x.isIndexed() && authFramework.isAllowed(req, x)) {
projectNames.add(s);
}
}
}
// Add default projects.
if (projectNames.isEmpty()) {
Set<Project> defaultProjects = env.getDefaultProjects();
if (defaultProjects != null) {
for (Project project : defaultProjects) {
if (project.isIndexed() && authFramework.isAllowed(req, project)) {
projectNames.add(project.getName());
}
}
}
}
return projectNames;
}
use of org.opengrok.indexer.configuration.Group in project OpenGrok by OpenGrok.
the class ProjectHelper method hasFavourite.
/**
* Checks if given group contains a favourite project.
*
* Favourite project is a project which is contained in the OpenGrokProject
* cookie, i. e. it has been searched or viewed by the user.
*
* This should by used to determine if this group should be displayed
* expanded or rolled up.
*
* @param group group
* @return true if it has favourite project
*/
@SuppressWarnings(value = "unchecked")
public boolean hasFavourite(Group group) {
Boolean val;
Map<String, Boolean> p = (Map<String, Boolean>) cfg.getRequestAttribute(PROJECT_HELPER_FAVOURITE_GROUP);
if (p == null) {
p = new TreeMap<>();
cfg.setRequestAttribute(PROJECT_HELPER_FAVOURITE_GROUP, p);
}
val = p.get(group.getName());
if (val == null) {
Set<Project> favourite = getAllGrouped();
favourite.removeIf(t -> {
// project is favourite
if (!isFavourite(t)) {
return true;
}
// project is contained in group repositories
if (getRepositories(group).contains(t)) {
return false;
}
// project is contained in group projects
if (getProjects(group).contains(t)) {
return false;
}
// project is contained in subgroup's repositories and projects
for (Group g : filterGroups(group.getDescendants())) {
if (getProjects(g).contains(t)) {
return false;
}
if (getRepositories(g).contains(t)) {
return false;
}
}
return true;
});
val = !favourite.isEmpty();
p.put(group.getName(), val);
}
cfg.setRequestAttribute(PROJECT_HELPER_FAVOURITE_GROUP, p);
return val;
}
use of org.opengrok.indexer.configuration.Group in project OpenGrok by OpenGrok.
the class ProjectHelperTest method testGetProjectsAllowedGroup.
/**
* Test of getProjects method, of class ProjectHelper.
*/
@Test
public void testGetProjectsAllowedGroup() {
for (Group g : RuntimeEnvironment.getInstance().getGroups()) {
if (g.getName().startsWith("allowed_group_0")) {
Set<Project> result = helper.getProjects(g);
assertEquals(2, result.size());
for (Project p : result) {
assertTrue(p.getName().startsWith("allowed_"));
}
}
}
}
use of org.opengrok.indexer.configuration.Group in project OpenGrok by OpenGrok.
the class ProjectHelperTest method testGetRepositoriesAllowedGroup.
/**
* Test of getRepositories method, of class ProjectHelper.
*/
@Test
public void testGetRepositoriesAllowedGroup() {
for (Group g : RuntimeEnvironment.getInstance().getGroups()) {
if (g.getName().startsWith("allowed_group_0")) {
Set<Project> result = helper.getRepositories(g);
assertEquals(2, result.size());
for (Project p : result) {
assertTrue(p.getName().startsWith("allowed_"));
}
}
}
}
use of org.opengrok.indexer.configuration.Group in project OpenGrok by OpenGrok.
the class ProjectHelperExtendedTest method testHasAllowedSubgroupAllowedSubgroups.
@Test
public void testHasAllowedSubgroupAllowedSubgroups() {
Group g = getAllowedGroupWithSubgroups();
assertTrue(helper.hasAllowedSubgroup(g));
}
Aggregations