Search in sources :

Example 6 with SProject

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;
}
Also used : User(jetbrains.buildServer.users.User) BuildProject(jetbrains.buildServer.BuildProject) SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull) Date(java.util.Date) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) SBuildType(jetbrains.buildServer.serverSide.SBuildType) BuildType(jetbrains.buildServer.BuildType) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with SProject

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;
}
Also used : SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with SProject

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;
}
Also used : SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with SProject

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();
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) java.util(java.util) Test(org.testng.annotations.Test) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) SProjectFeatureDescriptor(jetbrains.buildServer.serverSide.SProjectFeatureDescriptor) StringUtils(org.apache.commons.lang3.StringUtils) Branch(jetbrains.buildServer.server.rest.model.build.Branch) Projects(jetbrains.buildServer.server.rest.model.project.Projects) Option(jetbrains.buildServer.util.Option) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) CollectionsUtil(jetbrains.buildServer.util.CollectionsUtil) RestContext(jetbrains.buildServer.server.rest.data.RestContext) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) ProjectFeatureDescriptorFactory(jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory) MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) OperationRequestor(jetbrains.buildServer.vcs.OperationRequestor) BuildFinderTestBase(jetbrains.buildServer.server.rest.data.BuildFinderTestBase) Branches(jetbrains.buildServer.server.rest.model.build.Branches) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) BeforeMethod(org.testng.annotations.BeforeMethod) RepositoryStateData.createVersionState(jetbrains.buildServer.vcs.RepositoryStateData.createVersionState) Util.map(jetbrains.buildServer.util.Util.map) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTypeEx(jetbrains.buildServer.serverSide.BuildTypeEx) Pair(com.intellij.openapi.util.Pair) SProject(jetbrains.buildServer.serverSide.SProject) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) Projects(jetbrains.buildServer.server.rest.model.project.Projects) RestContext(jetbrains.buildServer.server.rest.data.RestContext) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) Fields(jetbrains.buildServer.server.rest.model.Fields) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) Pair(com.intellij.openapi.util.Pair)

Example 10 with SProject

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);
}
Also used : SProject(jetbrains.buildServer.serverSide.SProject) Test(org.testng.annotations.Test)

Aggregations

SProject (jetbrains.buildServer.serverSide.SProject)40 NotNull (org.jetbrains.annotations.NotNull)21 Test (org.testng.annotations.Test)11 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)10 ProjectManager (jetbrains.buildServer.serverSide.ProjectManager)7 Nullable (org.jetbrains.annotations.Nullable)7 ApiOperation (io.swagger.annotations.ApiOperation)6 SBuildType (jetbrains.buildServer.serverSide.SBuildType)6 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)5 Fields (jetbrains.buildServer.server.rest.model.Fields)5 Permission (jetbrains.buildServer.serverSide.auth.Permission)5 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)5 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 ServiceLocator (jetbrains.buildServer.ServiceLocator)4 AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)4 jetbrains.buildServer.serverSide.agentPools (jetbrains.buildServer.serverSide.agentPools)4 Logger (com.intellij.openapi.diagnostic.Logger)3 Stream (java.util.stream.Stream)3 SpaceExternalChangeViewerExtension (jetbrains.buildServer.buildTriggers.vcs.git.SpaceExternalChangeViewerExtension)3