use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.
the class InvestigationFinder method getFilter.
@NotNull
@Override
public ItemFilter<InvestigationWrapper> getFilter(@NotNull final Locator locator) {
final MultiCheckerFilter<InvestigationWrapper> result = new MultiCheckerFilter<InvestigationWrapper>();
final String investigatorDimension = locator.getSingleDimensionValue(ASSIGNEE);
if (investigatorDimension != null) {
@NotNull final User user = myUserFinder.getItem(investigatorDimension);
result.add(new FilterConditionChecker<InvestigationWrapper>() {
public boolean isIncluded(@NotNull final InvestigationWrapper item) {
return user.equals(item.getResponsibleUser());
}
});
}
final String reporterDimension = locator.getSingleDimensionValue(REPORTER);
if (reporterDimension != null) {
@NotNull final User user = myUserFinder.getItem(reporterDimension);
result.add(new FilterConditionChecker<InvestigationWrapper>() {
public boolean isIncluded(@NotNull final InvestigationWrapper item) {
return user.equals(item.getReporterUser());
}
});
}
final String typeDimension = locator.getSingleDimensionValue(TYPE);
if (typeDimension != null) {
if (ProblemTarget.getKnownTypesForInvestigation().stream().noneMatch(s -> typeDimension.equalsIgnoreCase(s))) {
throw new BadRequestException("Error in dimension '" + TYPE + "': unknown value '" + typeDimension + "'. Known values: " + StringUtil.join(ProblemTarget.getKnownTypesForInvestigation(), ", "));
}
result.add(new FilterConditionChecker<InvestigationWrapper>() {
public boolean isIncluded(@NotNull final InvestigationWrapper item) {
return typeDimension.equalsIgnoreCase(ProblemTarget.getType(item));
}
});
}
final String stateDimension = locator.getSingleDimensionValue(STATE);
if (stateDimension != null) {
if (!InvestigationWrapper.getKnownStates().contains(stateDimension.toLowerCase())) {
throw new BadRequestException("Error in dimension '" + STATE + "': unknown value '" + stateDimension + "'. Known values: " + StringUtil.join(InvestigationWrapper.getKnownStates(), ", "));
}
result.add(new FilterConditionChecker<InvestigationWrapper>() {
public boolean isIncluded(@NotNull final InvestigationWrapper item) {
return stateDimension.equalsIgnoreCase(item.getState().name());
}
});
}
final String resolutionDimension = locator.getSingleDimensionValue(RESOLUTION);
if (resolutionDimension != null) {
ResponsibilityEntry.RemoveMethod removeMethod = Resolution.getRemoveMethodForInvestigation(resolutionDimension);
result.add(item -> removeMethod.equals(item.getRemoveMethod()));
}
final String assignmentProjectDimension = locator.getSingleDimensionValue(ASSIGNMENT_PROJECT);
if (assignmentProjectDimension != null) {
@NotNull final SProject project = myProjectFinder.getItem(assignmentProjectDimension);
result.add(new FilterConditionChecker<InvestigationWrapper>() {
public boolean isIncluded(@NotNull final InvestigationWrapper item) {
final BuildProject assignmentProject = item.getAssignmentProject();
return assignmentProject != null && project.getProjectId().equals(assignmentProject.getProjectId());
}
});
}
final String affectedProjectDimension = locator.getSingleDimensionValue(AFFECTED_PROJECT);
if (affectedProjectDimension != null) {
@NotNull final SProject project = myProjectFinder.getItem(affectedProjectDimension);
result.add(new FilterConditionChecker<InvestigationWrapper>() {
public boolean isIncluded(@NotNull final InvestigationWrapper item) {
final BuildProject assignmentProject = item.getAssignmentProject();
final BuildType assignmentBuildType = item.getAssignmentBuildType();
final BuildProject buildTypeProject = assignmentBuildType != null ? myProjectFinder.findProjectByInternalId(assignmentBuildType.getProjectId()) : null;
return (assignmentProject != null && ProjectFinder.isSameOrParent(project, assignmentProject)) || (buildTypeProject != null && ProjectFinder.isSameOrParent(project, buildTypeProject));
}
});
}
final String sinceDateDimension = locator.getSingleDimensionValue(SINCE_DATE);
if (sinceDateDimension != null) {
final Date date = DataProvider.getDate(sinceDateDimension);
result.add(new FilterConditionChecker<InvestigationWrapper>() {
public boolean isIncluded(@NotNull final InvestigationWrapper item) {
return date.before(item.getTimestamp());
}
});
}
// todo: add assignmentBuildType
return result;
}
use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.
the class ProblemFinder method getFilter.
@NotNull
@Override
public ItemFilter<ProblemWrapper> getFilter(@NotNull final Locator locator) {
final MultiCheckerFilter<ProblemWrapper> result = new MultiCheckerFilter<ProblemWrapper>();
final String identityDimension = locator.getSingleDimensionValue(IDENTITY);
if (identityDimension != null) {
result.add(new FilterConditionChecker<ProblemWrapper>() {
public boolean isIncluded(@NotNull final ProblemWrapper item) {
return identityDimension.equals(item.getIdentity());
}
});
}
final String typeDimension = locator.getSingleDimensionValue(TYPE);
if (typeDimension != null) {
result.add(new FilterConditionChecker<ProblemWrapper>() {
public boolean isIncluded(@NotNull final ProblemWrapper item) {
return typeDimension.equals(item.getType());
}
});
}
final String affectedProjectDimension = locator.getSingleDimensionValue(AFFECTED_PROJECT);
if (affectedProjectDimension != null) {
@NotNull final SProject project = myProjectFinder.getItem(affectedProjectDimension);
final Set<ProblemWrapper> currentProjectProblems = getCurrentProblemsList(project);
// todo: bug: searches only inside current problems: non-current problems are not returned
result.add(new FilterConditionChecker<ProblemWrapper>() {
public boolean isIncluded(@NotNull final ProblemWrapper item) {
// todo: TeamCity API (VB): is there a dedicated API call for this? -- consider doing this via ProblemOccurrences
return currentProjectProblems.contains(item);
}
});
}
final Boolean currentlyInvestigatedDimension = locator.getSingleDimensionValueAsBoolean(CURRENTLY_INVESTIGATED);
if (currentlyInvestigatedDimension != null) {
result.add(new FilterConditionChecker<ProblemWrapper>() {
public boolean isIncluded(@NotNull final ProblemWrapper item) {
// todo: check investigation in affected Project/buildType only, if set
return FilterUtil.isIncludedByBooleanFilter(currentlyInvestigatedDimension, !item.getInvestigations().isEmpty());
}
});
}
final Boolean currentlyMutedDimension = locator.getSingleDimensionValueAsBoolean(CURRENTLY_MUTED);
if (currentlyMutedDimension != null) {
result.add(new FilterConditionChecker<ProblemWrapper>() {
public boolean isIncluded(@NotNull final ProblemWrapper item) {
// todo: check in affected Project/buildType only, if set
return FilterUtil.isIncludedByBooleanFilter(currentlyMutedDimension, !item.getMutes().isEmpty());
}
});
}
if (locator.isUnused(CURRENT)) {
final Boolean currentDimension = locator.getSingleDimensionValueAsBoolean(CURRENT);
if (currentDimension != null) {
final Set<ProblemWrapper> currentProblems = getCurrentProblemsList(null);
result.add(item -> FilterUtil.isIncludedByBooleanFilter(currentDimension, currentProblems.contains(item)));
}
}
if (locator.isUnused(BUILD)) {
String buildLocator = locator.getSingleDimensionValue(BUILD);
if (buildLocator != null) {
final Set<ProblemWrapper> problems = getProblemsByBuilds(buildLocator);
result.add(new FilterConditionChecker<ProblemWrapper>() {
@Override
public boolean isIncluded(@NotNull final ProblemWrapper item) {
return problems.contains(item);
}
});
}
}
return result;
}
use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.
the class TestScope method getPath.
@NotNull
@Override
public Iterable<Scope> getPath() {
if (myBuildType == null) {
return Collections.emptyList();
}
if (myPath != null) {
return myPath;
}
myPath = new ArrayList<>();
for (SProject ancestor : myBuildType.getProject().getProjectPath()) {
String ancestorId = ancestor.getExternalId();
String id = Hashing.sha1().hashString("P" + ancestor.getExternalId(), Charsets.UTF_8).toString();
myPath.add(new TestScopeInfo(id, ancestorId, TestScopeType.PROJECT));
}
String btId = Hashing.sha1().hashString("BT" + myBuildType.getInternalId(), Charsets.UTF_8).toString();
myPath.add(new TestScopeInfo(btId, myBuildType.getExternalId(), TestScopeType.BUILD_TYPE));
String suiteId = Hashing.sha1().hashString(myBuildType.getExternalId() + "s" + mySuite, Charsets.UTF_8).toString();
myPath.add(new TestScopeInfo(suiteId, mySuite, TestScopeType.SUITE));
String packageName = myPackage == null ? "" : myPackage;
String packageId = Hashing.sha1().hashString(myBuildType.getExternalId() + "s" + mySuite + "p" + packageName, Charsets.UTF_8).toString();
myPath.add(new TestScopeInfo(packageId, packageName, TestScopeType.PACKAGE));
String className = myClass == null ? "" : myClass;
String classId = Hashing.sha1().hashString(myBuildType.getExternalId() + "s" + mySuite + "p" + packageName + "c" + className, Charsets.UTF_8).toString();
myPath.add(new TestScopeInfo(classId, className, TestScopeType.CLASS));
return myPath;
}
use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.
the class ProjectRequestTest method memoryTest.
// @Test
public void memoryTest() throws InterruptedException {
final ProjectRequest request = new ProjectRequest();
request.setInTests(myProjectFinder, myBranchFinder, myBeanContext);
final String locator = "archived:false,affectedProject:_Root";
final String fields = "count,project(id,internalId,name,parentProjectId,archived,readOnlyUI,buildTypes(buildType(id,paused,internalId,projectId,name,type,description)),description)";
Queue<Pair<Integer, ProjectEx>> q = new ArrayDeque<>();
q.add(new Pair<>(0, myProject));
final int max = 2;
final int children = 4;
int counter = 0;
while (!q.isEmpty()) {
Pair<Integer, ProjectEx> p = q.poll();
String prefix = "Bt" + StringUtils.repeat('a', 10 * p.getFirst());
for (int i = 0; i < children; i++) {
ProjectEx c = myFixture.createProject("z-" + p.first + "-" + counter++, p.second);
if (p.first < max) {
q.add(new Pair<>(p.first + 1, c));
}
for (int j = 0; j < children * 4; j++) c.createBuildType(prefix + j);
}
}
System.out.println(counter + " projects created.");
Thread[] ts = new Thread[100];
for (int i = 0; i < ts.length; i++) {
final int threadIdx = i;
ts[i] = new Thread(() -> {
new RestContext(z -> null).run(() -> {
for (int j = 0; j < 100; j++) {
final PagedSearchResult<SProject> result = myProjectFinder.getItems(locator);
Projects projects = new Projects(result.myEntries, null, new Fields(fields), myBeanContext);
projects.projects.stream().flatMap(p -> p.buildTypes.buildTypes.stream()).forEach(bt -> {
bt.getId();
bt.isPaused();
bt.getInternalId();
bt.getProjectId();
bt.getName();
bt.getType();
bt.getDescription();
});
System.out.println(String.format("Finished %d requests in thread %d", j, threadIdx));
}
return null;
});
});
ts[i].start();
}
for (Thread t : ts) t.join();
}
use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.
the class ProjectFinderTest method testAgentPoolDimension.
@Test
public void testAgentPoolDimension() throws Exception {
final SProject project10 = createProject("p10", "project 10");
final SProject project20 = createProject("p20", "project 20");
final SProject project30 = createProject("p30", "project 30");
// - project10, project20
final int poolId0 = BuildAgent.DEFAULT_POOL_ID;
// - project20
final int poolId10 = myFixture.getAgentPoolManager().createNewAgentPool("pool10").getAgentPoolId();
// - project30
final int poolId20 = myFixture.getAgentPoolManager().createNewAgentPool("pool20").getAgentPoolId();
myFixture.getAgentPoolManager().associateProjectsWithPool(poolId10, createSet(project20.getProjectId()));
myFixture.getAgentPoolManager().associateProjectsWithPool(poolId20, createSet(project30.getProjectId()));
myFixture.getAgentPoolManager().dissociateProjectsFromOtherPools(poolId20, createSet(project30.getProjectId()));
check(null, getRootProject(), project10, project20, project30);
check("pool:(id:" + poolId0 + ")", myProjectManager.getRootProject(), project10, project20);
check("pool:(id:" + poolId10 + ")", project20);
check("pool:(id:" + poolId20 + ")", project30);
check("pool:(item:(id:" + poolId0 + "),item:(id:" + poolId10 + "))", myProjectManager.getRootProject(), project10, project20);
check("pool:(item:(id:" + poolId0 + "),item:(id:" + poolId20 + "))", myProjectManager.getRootProject(), project10, project20, project30);
check("pool:(item:(id:" + poolId0 + "),item:(id:" + poolId20 + ")),id:" + project20.getExternalId(), project20);
check("pool:(item:(id:" + poolId0 + "),item:(id:" + poolId20 + ")),pool:(id:" + poolId10 + ")", project20);
check("pool:(id:" + poolId10 + "),pool:(id:" + poolId20 + ")");
check("pool:(id:" + poolId0 + "),pool:(id:" + poolId10 + ")", project20);
check("pool:(id:" + poolId0 + "),not(pool:(id:" + poolId10 + "))", myProjectManager.getRootProject(), project10);
}
Aggregations