Search in sources :

Example 26 with SProject

use of jetbrains.buildServer.serverSide.SProject in project teamcity-git by JetBrains.

the class GitHubPasswordAuthHealthPage method isAvailable.

@Override
public boolean isAvailable(@NotNull HttpServletRequest request) {
    if (!super.isAvailable(request))
        return false;
    final SVcsRoot vcsRoot = getRootFromRequest(request);
    if (vcsRoot == null)
        return false;
    final SProject project = vcsRoot.getProject();
    return SessionUser.getUser(request).isPermissionGrantedForProject(project.getProjectId(), Permission.EDIT_PROJECT) && // check vcs root still exists
    project.getOwnVcsRoots().contains(vcsRoot);
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) SProject(jetbrains.buildServer.serverSide.SProject)

Example 27 with SProject

use of jetbrains.buildServer.serverSide.SProject in project teamcity-git by JetBrains.

the class GitUrlSupportTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    super.setUp();
    ServerPaths paths = new ServerPaths(myTempFiles.createTempDir().getAbsolutePath());
    PluginConfig config = new PluginConfigBuilder(paths).build();
    myMirrorManager = new MirrorManagerImpl(config, new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl());
    myProjectMock = mock(SProject.class);
    final Mock pmMock = mock(ProjectManager.class);
    final SProject project = (SProject) myProjectMock.proxy();
    pmMock.stubs().method("findProjectById").will(returnValue(project));
    ProjectManager pm = (ProjectManager) pmMock.proxy();
    final Mock sshMock = mock(ServerSshKeyManager.class);
    sshMock.stubs().method("getKeys").with(eq(project)).will(returnValue(myTestKeys));
    ServerSshKeyManager ssh = (ServerSshKeyManager) sshMock.proxy();
    Mock epMock = mock(ExtensionsProvider.class);
    epMock.stubs().method("getExtensions").with(eq(ServerSshKeyManager.class)).will(returnValue(Collections.singleton(ssh)));
    myGitVcsSupport = gitSupport().withServerPaths(paths).withTestConnectionSupport(vcsRoot -> {
        if (myTestConnectionMocked != null && myTestConnectionMocked)
            return null;
        return myGitVcsSupport.testConnection(vcsRoot);
    }).build();
    myUrlSupport = new GitUrlSupport(myGitVcsSupport) {

        @NotNull
        @Override
        protected VcsRoot createDummyRoot(@NotNull final Map<String, String> props, @Nullable final SProject curProject) {
            return new VcsRootImpl(-1, Constants.VCS_NAME, props);
        }
    };
    myUrlSupport.setProjectManager(pm);
    myUrlSupport.setExtensionsProvider((ExtensionsProvider) epMock.proxy());
}
Also used : SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull) Mock(org.jmock.Mock) ProjectManager(jetbrains.buildServer.serverSide.ProjectManager) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) ServerSshKeyManager(jetbrains.buildServer.ssh.ServerSshKeyManager) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 28 with SProject

use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.

the class Investigation method getFromPostedAndApply.

@NotNull
public List<InvestigationWrapper> getFromPostedAndApply(@NotNull final ServiceLocator serviceLocator, final boolean allowMultipleResult) {
    checkIsValid();
    if (target == null) {
        throw new BadRequestException("Invalid 'investigation' entity: 'target' should be specified");
    }
    ProblemTarget.ProblemTargetData targetData;
    try {
        targetData = target.getFromPosted(serviceLocator);
    } catch (BadRequestException e) {
        throw new BadRequestException("Invalid 'investigation' entity: " + e.getMessage());
    }
    ResponsibilityEntry entry = new ResponsibilityEntryEx(TypedFinderBuilder.getEnumValue(state, ResponsibilityEntry.State.class), assignee.getFromPosted(serviceLocator.getSingletonService(UserFinder.class)), serviceLocator.getSingletonService(UserFinder.class).getCurrentUser(), new Date(), assignment == null || assignment.getTextFromPosted() == null ? "" : assignment.getTextFromPosted(), resolution.getFromPostedForInvestigation(serviceLocator));
    ResponsibilityFacadeEx responsibilityFacade = serviceLocator.getSingletonService(ResponsibilityFacadeEx.class);
    InvestigationFinder investigationFinder = serviceLocator.findSingletonService(InvestigationFinder.class);
    assert investigationFinder != null;
    List<InvestigationWrapper> resultEntries = new ArrayList<>(1);
    if (targetData.isAnyProblem()) {
        List<BuildType> buildTypesFromPosted = scope.getBuildTypesFromPosted(serviceLocator);
        if (!allowMultipleResult && buildTypesFromPosted.size() > 1) {
            throw new OnlySingleEntitySupportedException("Invalid 'scope' entity: for this request only single buildType is supported within 'buildTypes' entity");
        }
        for (BuildType buildType : buildTypesFromPosted) {
            responsibilityFacade.setBuildTypeResponsibility(buildType, entry);
            resultEntries.add(investigationFinder.getItem(InvestigationFinder.getLocator((SBuildType) buildType)));
        }
    } else {
        if (scope.buildTypes != null) {
            throw new BadRequestException("Invalid 'investigation' entity: Invalid 'scope' entity: 'buildTypes' should not be specified for not buildType-level investigation");
        }
        SProject project = scope.getProjectFromPosted(serviceLocator);
        List<STest> tests = targetData.getTests();
        if (!tests.isEmpty()) {
            if (!allowMultipleResult && tests.size() > 1) {
                throw new OnlySingleEntitySupportedException("Invalid 'target' entity: for this request only single test is supported within 'tests' entity");
            }
            responsibilityFacade.setTestNameResponsibility(tests.stream().map(sTest -> sTest.getName()).distinct().collect(Collectors.toList()), project.getProjectId(), entry);
            tests.stream().map(test -> // only one item should be found in the project
            investigationFinder.getItem(InvestigationFinder.getLocatorForTest(test.getTestNameId(), project))).distinct().forEachOrdered(resultEntries::add);
        }
        List<Long> problems = targetData.getProblemIds();
        if (!problems.isEmpty()) {
            if (!allowMultipleResult && problems.size() > 1) {
                throw new OnlySingleEntitySupportedException("Invalid 'target' entity: for this request only single problem is supported within 'problems' entity");
            }
            responsibilityFacade.setBuildProblemResponsibility(// seems like only id is used inside
            problems.stream().distinct().map(problemId -> ProblemWrapper.getBuildProblemInfo(problemId.intValue(), project.getProjectId())).collect(Collectors.toList()), project.getProjectId(), entry);
            problems.stream().distinct().map(problemId -> // only one item should be found in the project
            investigationFinder.getItem(InvestigationFinder.getLocatorForProblem(problemId.intValue(), project))).forEachOrdered(resultEntries::add);
        }
    }
    if (!allowMultipleResult && resultEntries.size() != 1) {
        throw new BadRequestException("Invalid 'investigation' entity: Invalid 'target' entity: found " + resultEntries.size() + " result entities, while exactly one is required");
    }
    return resultEntries;
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) User(jetbrains.buildServer.server.rest.model.user.User) Date(java.util.Date) InvestigationFinder(jetbrains.buildServer.server.rest.data.investigations.InvestigationFinder) ArrayList(java.util.ArrayList) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ResponsibilityEntryEx(jetbrains.buildServer.responsibility.ResponsibilityEntryEx) XmlType(javax.xml.bind.annotation.XmlType) Comment(jetbrains.buildServer.server.rest.model.Comment) STest(jetbrains.buildServer.serverSide.STest) TypedFinderBuilder(jetbrains.buildServer.server.rest.data.TypedFinderBuilder) InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) Api(io.swagger.annotations.Api) SBuildType(jetbrains.buildServer.serverSide.SBuildType) ModelDescription(jetbrains.buildServer.server.rest.swagger.annotations.ModelDescription) XmlAttribute(javax.xml.bind.annotation.XmlAttribute) TeamCityProperties(jetbrains.buildServer.serverSide.TeamCityProperties) ProblemWrapper(jetbrains.buildServer.server.rest.data.problem.ProblemWrapper) ServiceLocator(jetbrains.buildServer.ServiceLocator) BuildType(jetbrains.buildServer.BuildType) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) ValueWithDefault(jetbrains.buildServer.server.rest.util.ValueWithDefault) Collectors(java.util.stream.Collectors) List(java.util.List) ResponsibilityEntry(jetbrains.buildServer.responsibility.ResponsibilityEntry) Resolution(jetbrains.buildServer.server.rest.model.problem.Resolution) ResponsibilityFacadeEx(jetbrains.buildServer.responsibility.ResponsibilityFacadeEx) SProject(jetbrains.buildServer.serverSide.SProject) UserFinder(jetbrains.buildServer.server.rest.data.UserFinder) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) ApiModelProperty(io.swagger.annotations.ApiModelProperty) InvestigationRequest(jetbrains.buildServer.server.rest.request.InvestigationRequest) XmlElement(javax.xml.bind.annotation.XmlElement) InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) ResponsibilityFacadeEx(jetbrains.buildServer.responsibility.ResponsibilityFacadeEx) ArrayList(java.util.ArrayList) ResponsibilityEntryEx(jetbrains.buildServer.responsibility.ResponsibilityEntryEx) InvestigationFinder(jetbrains.buildServer.server.rest.data.investigations.InvestigationFinder) SProject(jetbrains.buildServer.serverSide.SProject) Date(java.util.Date) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ResponsibilityEntry(jetbrains.buildServer.responsibility.ResponsibilityEntry) SBuildType(jetbrains.buildServer.serverSide.SBuildType) BuildType(jetbrains.buildServer.BuildType) STest(jetbrains.buildServer.serverSide.STest) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with SProject

use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.

the class ProjectFinderTest method testUserSelectedDimension.

@Test
public void testUserSelectedDimension() throws Exception {
    myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
    ProjectEx root = myProjectManager.getRootProject();
    final SProject project10 = createProject("p10", "project 10");
    final SProject project20 = createProject("p20", "project 20");
    final SProject project10_10 = project10.createProject("p10_10", "p10 child1");
    final SProject project10_20 = project10.createProject("p10_20", "xxx");
    final SProject project10_10_10 = project10_10.createProject("p10_10_10", "xxx");
    final SProject project10_10_20 = project10_10.createProject("p10_10_20", "p10_10 child2");
    final SProject project10_10_30 = project10_10.createProject("p10_10_30", "p10_10 child3");
    final SProject project30 = createProject(project10.getProjectId(), "project 30");
    final SProject project40 = createProject("p40", "project 40");
    final SUser user2 = createUser("user2");
    user2.addRole(RoleScope.projectScope(project10.getProjectId()), getProjectViewerRole());
    // default sorting is hierarchy-based + name-based within the same level
    check("selectedByUser:(username:user2)", project10, project10_10, project10_10_20, project10_10_30, project10_10_10, project10_20);
    check("selectedByUser:(user:(username:user2),mode:selected_and_unknown)", project10, project10_10, project10_10_20, project10_10_30, project10_10_10, project10_20);
    check("selectedByUser:(user:(username:user2),mode:all_with_order)", root, project10, project10_10, project10_10_20, project10_10_30, project10_10_10, project10_20);
    check("selectedByUser:(user:(username:user2),mode:selected)");
    final SUser user1 = createUser("user1");
    user1.addRole(RoleScope.projectScope(project10.getProjectId()), getProjectViewerRole());
    user1.addRole(RoleScope.projectScope(project20.getProjectId()), getProjectViewerRole());
    user1.addRole(RoleScope.projectScope(project30.getProjectId()), getProjectViewerRole());
    user1.setVisibleProjects(Arrays.asList(project10.getProjectId(), project10_10_20.getProjectId(), project10_10_10.getProjectId(), project40.getProjectId(), project30.getProjectId()));
    user1.setProjectsOrder(Arrays.asList(project10.getProjectId(), project10_10_20.getProjectId(), project10_10_10.getProjectId(), project40.getProjectId(), project30.getProjectId()));
    check("selectedByUser:(username:user1)", project10, project10_10_20, project10_10_10, project30);
    check("selectedByUser:(user:(username:user1))", project10, project10_10_20, project10_10_10, project30);
    check("selectedByUser:(user:(username:user1),mode:selected_and_unknown)", project10, project10_10_20, project10_10_10, project30);
    check("selectedByUser:(user:(username:user1),mode:all_with_order)", root, project10, project10_10, project10_10_20, project10_10_10, project10_10_30, project10_20, project30, project20);
    check("selectedByUser:(user:(username:user1),mode:selected)", project10, project10_10_20, project10_10_10, project30);
    check("selectedByUser:(username:user1),project:(id:_Root)", project10, project30);
    check("selectedByUser:(user:(username:user1),mode:selected_and_unknown),project:(id:_Root)", project10, project30);
    check("selectedByUser:(user:(username:user1),mode:all_with_order),project:(id:_Root)", project10, project30, project20);
    check("selectedByUser:(user:(username:user1),mode:selected),project:(id:_Root)", project10, project30);
    check("selectedByUser:(username:user1),project:(id:p10)");
    check("selectedByUser:(user:(username:user1),mode:selected_and_unknown),project:(id:p10)");
    check("selectedByUser:(user:(username:user1),mode:all_with_order),project:(id:p10)", project10_10, project10_20);
    check("selectedByUser:(user:(username:user1),mode:selected),project:(id:p10)");
    user1.setVisibleProjects(Arrays.asList(project30.getProjectId(), project10_10_20.getProjectId(), project10_10_10.getProjectId()));
    user1.setProjectsOrder(Arrays.asList(project30.getProjectId(), project10_10_20.getProjectId(), project10_10_10.getProjectId()));
    check("selectedByUser:(username:user1)", project30, project10_10_20, project10_10_10);
    check("selectedByUser:(username:user1),project:(id:_Root)", project30);
    checkExceptionOnItemsSearch(LocatorProcessException.class, "selectedByUser:(username:user2,mode:selected)");
    checkExceptionOnItemsSearch(BadRequestException.class, "selectedByUser:(user:(username:user2),mode:aaa)");
    checkExceptionOnItemsSearch(LocatorProcessException.class, "selectedByUser:(user:(username:user2),mode:aaa,ccc:ddd)");
    checkExceptionOnItemsSearch(LocatorProcessException.class, "selectedByUser:(user:(username:user2,aaa:bbb))");
// add checks after    ProjectEx.setOwnProjectsOrder / setOwnBuildTypesOrder
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) SUser(jetbrains.buildServer.users.SUser) SProject(jetbrains.buildServer.serverSide.SProject) Test(org.testng.annotations.Test)

Example 30 with SProject

use of jetbrains.buildServer.serverSide.SProject in project teamcity-rest by JetBrains.

the class ProjectFinderTest method testProjectBean.

@Test
public void testProjectBean() throws Exception {
    final SProject project10 = createProject("p1", "project 1");
    final SProject project20 = createProject("p2", "project 2");
    final SProject project10_10 = project10.createProject("p10_10", "p1_child1");
    final SProject project10_20 = project10.createProject("p10_20", "xxx");
    final SProject project10_10_10 = project10_10.createProject("p10_10_10", "xxx");
    final SProject project30 = createProject(project10.getProjectId(), "p3");
    Project project = new Project(project10, new Fields("projects($long)"), getBeanContext(myServer));
    assertNotNull(project.projects.projects);
    checkOrderedCollection(CollectionsUtil.convertCollection(project.projects.projects, new Converter<String, Project>() {

        public String createFrom(@NotNull final Project source) {
            return source.id;
        }
    }), project10_10.getExternalId(), project10_20.getExternalId());
    project = new Project(project10, new Fields("projects($long,$locator(name:xxx))"), getBeanContext(myServer));
    assertNotNull(project.projects.projects);
    checkOrderedCollection(CollectionsUtil.convertCollection(project.projects.projects, new Converter<String, Project>() {

        public String createFrom(@NotNull final Project source) {
            return source.id;
        }
    }), project10_20.getExternalId());
    project = new Project(project10, new Fields("projects($long,$locator(project:$any,affectedProject:(" + project10.getExternalId() + ")))"), getBeanContext(myServer));
    assertNotNull(project.projects.projects);
    checkOrderedCollection(CollectionsUtil.convertCollection(project.projects.projects, new Converter<String, Project>() {

        public String createFrom(@NotNull final Project source) {
            return source.id;
        }
    }), project10_10.getExternalId(), project10_20.getExternalId(), project10_10_10.getExternalId());
    ProjectFeatureDescriptorFactory featureDescriptorFactory = myFixture.findSingletonService(ProjectFeatureDescriptorFactory.class);
    assert featureDescriptorFactory != null;
    project10.addFeature(featureDescriptorFactory.createProjectFeature("uniqueId10", "type10", asMap("a", "b", "c", "d"), project10.getProjectId()));
    project10_10.addFeature(featureDescriptorFactory.createProjectFeature("uniqueId20", "type20", asMap("a", "b", "c", "d"), project10_10.getProjectId()));
    project = new Project(project10_10, new Fields("$long"), getBeanContext(myServer));
    assertEquals(project.id, project10_10.getExternalId());
    assertNotNull(project.projectFeatures);
    assertEquals(Integer.valueOf(1), project.projectFeatures.count);
    List<PropEntityProjectFeature> propEntities = project.projectFeatures.propEntities;
    assertEquals(1, propEntities.size());
    PropEntityProjectFeature feature = propEntities.get(0);
    assertEquals("uniqueId20", feature.id);
    assertEquals("type20", feature.type);
    assertEquals(Integer.valueOf(2), feature.properties.count);
    assertEquals("a", feature.properties.properties.get(0).name);
    assertEquals("b", feature.properties.properties.get(0).value);
    assertEquals("c", feature.properties.properties.get(1).name);
    assertEquals("d", feature.properties.properties.get(1).value);
}
Also used : ProjectFeatureDescriptorFactory(jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory) Project(jetbrains.buildServer.server.rest.model.project.Project) SProject(jetbrains.buildServer.serverSide.SProject) Fields(jetbrains.buildServer.server.rest.model.Fields) PropEntityProjectFeature(jetbrains.buildServer.server.rest.model.project.PropEntityProjectFeature) Converter(jetbrains.buildServer.util.Converter) SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull) Test(org.testng.annotations.Test)

Aggregations

SProject (jetbrains.buildServer.serverSide.SProject)42 NotNull (org.jetbrains.annotations.NotNull)22 Test (org.testng.annotations.Test)11 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)10 ProjectManager (jetbrains.buildServer.serverSide.ProjectManager)8 Nullable (org.jetbrains.annotations.Nullable)8 SBuildType (jetbrains.buildServer.serverSide.SBuildType)7 ApiOperation (io.swagger.annotations.ApiOperation)6 Logger (com.intellij.openapi.diagnostic.Logger)5 Collectors (java.util.stream.Collectors)5 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 List (java.util.List)4 ServiceLocator (jetbrains.buildServer.ServiceLocator)4 AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)4 jetbrains.buildServer.serverSide.agentPools (jetbrains.buildServer.serverSide.agentPools)4 Predicate (java.util.function.Predicate)3