Search in sources :

Example 1 with Project

use of jetbrains.buildServer.server.rest.model.project.Project in project teamcity-rest by JetBrains.

the class ProjectFinder method getFilter.

@NotNull
@Override
public ItemFilter<SProject> getFilter(@NotNull final Locator locator) {
    final MultiCheckerFilter<SProject> result = new MultiCheckerFilter<SProject>();
    final String id = locator.getSingleDimensionValue(DIMENSION_ID);
    if (id != null) {
        if (TeamCityProperties.getBoolean(APIController.REST_COMPATIBILITY_ALLOW_EXTERNAL_ID_AS_INTERNAL)) {
            result.add(item -> id.equalsIgnoreCase(item.getExternalId()) || id.equalsIgnoreCase(item.getProjectId()));
        } else {
            result.add(item -> id.equalsIgnoreCase(item.getExternalId()));
        }
    }
    final String name = locator.getSingleDimensionValue(DIMENSION_NAME);
    if (name != null) {
        result.add(new FilterConditionChecker<SProject>() {

            public boolean isIncluded(@NotNull final SProject item) {
                return name.equals(item.getName());
            }
        });
    }
    final Boolean archived = locator.getSingleDimensionValueAsBoolean(DIMENSION_ARCHIVED);
    if (archived != null) {
        result.add(new FilterConditionChecker<SProject>() {

            public boolean isIncluded(@NotNull final SProject item) {
                return FilterUtil.isIncludedByBooleanFilter(archived, item.isArchived());
            }
        });
    }
    final Boolean readOnlyUI = locator.getSingleDimensionValueAsBoolean(DIMENSION_READ_ONLY_UI);
    if (readOnlyUI != null) {
        result.add(new FilterConditionChecker<SProject>() {

            public boolean isIncluded(@NotNull final SProject item) {
                return FilterUtil.isIncludedByBooleanFilter(readOnlyUI, item.isReadOnly());
            }
        });
    }
    final String parameterDimension = locator.getSingleDimensionValue(DIMENSION_PARAMETER);
    if (parameterDimension != null) {
        final ParameterCondition parameterCondition = ParameterCondition.create(parameterDimension);
        result.add(new FilterConditionChecker<SProject>() {

            public boolean isIncluded(@NotNull final SProject item) {
                final boolean canView = !Project.shouldRestrictSettingsViewing(item, myPermissionChecker);
                if (!canView) {
                    LOG.debug("While filtering projects by " + DIMENSION_PARAMETER + " user does not have enough permissions to see settings. Excluding project: " + item.describe(false));
                    return false;
                }
                return parameterCondition.matches(item);
            }
        });
    }
    if (locator.isUnused(DIMENSION_PROJECT)) {
        final String directParentLocator = locator.getSingleDimensionValue(DIMENSION_PROJECT);
        if (directParentLocator != null) {
            final SProject directParent = getItem(directParentLocator);
            result.add(new FilterConditionChecker<SProject>() {

                public boolean isIncluded(@NotNull final SProject item) {
                    return directParent.getProjectId().equals(item.getParentProjectId());
                }
            });
        }
    }
    if (locator.isUnused(DIMENSION_AFFECTED_PROJECT)) {
        final SProject parentProject = getParentProject(locator);
        if (parentProject != null) {
            result.add(new FilterConditionChecker<SProject>() {

                public boolean isIncluded(@NotNull final SProject item) {
                    return isSameOrParent(parentProject, item);
                }
            });
        }
    }
    final String featureDimension = locator.getSingleDimensionValue(FEATURE);
    if (featureDimension != null) {
        result.add(new FilterConditionChecker<SProject>() {

            public boolean isIncluded(@NotNull final SProject item) {
                final boolean canView = !Project.shouldRestrictSettingsViewing(item, myPermissionChecker);
                if (!canView) {
                    LOG.debug("While filtering projects by " + DIMENSION_PARAMETER + " user does not have enough permissions to see settings. Excluding project: " + item.describe(false));
                    return false;
                }
                return new PropEntityProjectFeature.ProjectFeatureFinder(item).getItems(featureDimension).myEntries.size() > 0;
            }
        });
    }
    final String defaultTemplateDimension = locator.getSingleDimensionValue(DEFAULT_TEMPLATE);
    if (defaultTemplateDimension != null) {
        Set<String> defaultTemplateIds = myServiceLocator.getSingletonService(BuildTypeFinder.class).getItems(defaultTemplateDimension).myEntries.stream().map(bt -> bt.getInternalId()).collect(Collectors.toSet());
        result.add(item -> {
            final boolean canView = !Project.shouldRestrictSettingsViewing(item, myPermissionChecker);
            if (!canView) {
                LOG.debug("While filtering projects by " + DIMENSION_PARAMETER + " user does not have enough permissions to see settings. Excluding project: " + item.describe(false));
                return false;
            }
            String defaultTemplateId = item.getDefaultTemplateId();
            return defaultTemplateId != null && defaultTemplateIds.contains(defaultTemplateId);
        });
    }
    final String userPermissionDimension = locator.getSingleDimensionValue(USER_PERMISSION);
    if (userPermissionDimension != null) {
        result.add(new PermissionCheck().matches(userPermissionDimension));
    }
    final List<String> poolDimensions = locator.getDimensionValue(AGENT_POOL);
    if (!poolDimensions.isEmpty()) {
        AgentPoolFinder agentPoolFinder = myServiceLocator.getSingletonService(AgentPoolFinder.class);
        for (String poolDimension : poolDimensions) {
            List<AgentPool> pools = agentPoolFinder.getItems(poolDimension).myEntries;
            Set<String> filterProjectInternalIds = new HashSet<>();
            for (AgentPool pool : pools) {
                filterProjectInternalIds.addAll(pool.getProjectIds());
            }
            result.add(item -> filterProjectInternalIds.contains(item.getProjectId()));
        }
    }
    return result;
}
Also used : java.util(java.util) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) LocatorName(jetbrains.buildServer.server.rest.swagger.constants.LocatorName) LocatorResource(jetbrains.buildServer.server.rest.swagger.annotations.LocatorResource) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) PropEntityProjectFeature(jetbrains.buildServer.server.rest.model.project.PropEntityProjectFeature) LocatorDimensionDataType(jetbrains.buildServer.server.rest.swagger.constants.LocatorDimensionDataType) AgentPool(jetbrains.buildServer.serverSide.agentPools.AgentPool) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) StringUtil(jetbrains.buildServer.util.StringUtil) Logger(com.intellij.openapi.diagnostic.Logger) PagerData(jetbrains.buildServer.server.rest.model.PagerData) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) ServiceLocator(jetbrains.buildServer.ServiceLocator) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) Collectors(java.util.stream.Collectors) APIController(jetbrains.buildServer.server.rest.APIController) Project(jetbrains.buildServer.server.rest.model.project.Project) Nullable(org.jetbrains.annotations.Nullable) LocatorDimension(jetbrains.buildServer.server.rest.swagger.annotations.LocatorDimension) Permission(jetbrains.buildServer.serverSide.auth.Permission) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) NotNull(org.jetbrains.annotations.NotNull) SUser(jetbrains.buildServer.users.SUser) BuildProject(jetbrains.buildServer.BuildProject) UserEx(jetbrains.buildServer.users.impl.UserEx) AgentPool(jetbrains.buildServer.serverSide.agentPools.AgentPool) PropEntityProjectFeature(jetbrains.buildServer.server.rest.model.project.PropEntityProjectFeature) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Project

use of jetbrains.buildServer.server.rest.model.project.Project in project teamcity-rest by JetBrains.

the class AgentPoolRequest method addProject.

/**
 * Adds the posted project to the pool associated projects
 * @param agentPoolLocator
 * @param projects
 * @return
 */
@POST
@Path("/{agentPoolLocator}/projects")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Assign the project to the matching agent pool.", nickname = "addProjectToAgentPool")
public Project addProject(@ApiParam(format = LocatorName.AGENT_POOL) @PathParam("agentPoolLocator") String agentPoolLocator, Project project) {
    final jetbrains.buildServer.serverSide.agentPools.AgentPool agentPool = myAgentPoolFinder.getItem(agentPoolLocator);
    final AgentPoolManager agentPoolManager = myServiceLocator.getSingletonService(AgentPoolManager.class);
    final int agentPoolId = agentPool.getAgentPoolId();
    final SProject postedProject = project.getProjectFromPosted(myProjectFinder);
    try {
        agentPoolManager.associateProjectsWithPool(agentPoolId, Collections.singleton(postedProject.getProjectId()));
    } catch (NoSuchAgentPoolException e) {
        throw new BadRequestException("Agent pool with id \'" + agentPoolId + "' is not found.");
    }
    return new Project(postedProject, Fields.LONG, myBeanContext);
}
Also used : Project(jetbrains.buildServer.server.rest.model.project.Project) SProject(jetbrains.buildServer.serverSide.SProject) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) SProject(jetbrains.buildServer.serverSide.SProject) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with Project

use of jetbrains.buildServer.server.rest.model.project.Project in project teamcity-rest by JetBrains.

the class AgentPoolRequest method getPoolProject.

@GET
@Path("/{agentPoolLocator}/projects/{projectLocator}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "getPoolProject", hidden = true)
public Project getPoolProject(@ApiParam(format = LocatorName.AGENT_POOL) @PathParam("agentPoolLocator") String agentPoolLocator, @ApiParam(format = LocatorName.PROJECT) @PathParam("projectLocator") String projectLocator, @QueryParam("fields") String fields) {
    final jetbrains.buildServer.serverSide.agentPools.AgentPool agentPool = myAgentPoolFinder.getItem(agentPoolLocator);
    final SProject project = myProjectFinder.getItem(projectLocator);
    return new Project(project, new Fields(fields), myBeanContext);
}
Also used : Project(jetbrains.buildServer.server.rest.model.project.Project) SProject(jetbrains.buildServer.serverSide.SProject) Fields(jetbrains.buildServer.server.rest.model.Fields) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) SProject(jetbrains.buildServer.serverSide.SProject) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with Project

use of jetbrains.buildServer.server.rest.model.project.Project 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)

Example 5 with Project

use of jetbrains.buildServer.server.rest.model.project.Project in project teamcity-rest by JetBrains.

the class InvestigationRequestTest method testAssignInvestigation.

@Test
void testAssignInvestigation() throws Throwable {
    final SUser user2 = createUser("user2");
    Investigation investigation = new Investigation();
    investigation.state = "taken";
    investigation.assignee = new User();
    investigation.assignee.setId(user2.getId());
    investigation.assignment = new Comment();
    investigation.assignment.text = "comment here";
    investigation.scope = new ProblemScope();
    investigation.scope.project = new Project();
    investigation.scope.project.id = myProject.getExternalId();
    investigation.target = new ProblemTarget();
    investigation.target.tests = new Tests();
    jetbrains.buildServer.server.rest.model.problem.Test test = new jetbrains.buildServer.server.rest.model.problem.Test();
    test.name = "testname";
    investigation.target.tests.items = Collections.singletonList(test);
    investigation.resolution = new Resolution();
    investigation.resolution.type = Resolution.ResolutionType.manually;
    investigation.resolution.time = "20900512T163700";
    assertEmpty(myInvestigationFinder.getItems(null).myEntries);
    createBuildWithFailedTest("testname");
    Investigation result = myRequest.createInstance(investigation, "$long");
    assertEquals("testname", result.target.tests.items.get(0).name);
    List<InvestigationWrapper> currentInvestigations = myInvestigationFinder.getItems(null).myEntries;
    assertEquals(1, currentInvestigations.size());
    InvestigationWrapper investigationWrapper = currentInvestigations.get(0);
    assertEquals(ResponsibilityEntry.State.TAKEN, investigationWrapper.getState());
    assertEquals(user2.getId(), investigationWrapper.getResponsibleUser().getId());
    assertEquals("comment here", investigationWrapper.getComment());
    assertEquals(null, investigationWrapper.getProblemRE());
    assertEquals(myProject.getProjectId(), investigationWrapper.getTestRE().getProjectId());
    assertEquals("testname", investigationWrapper.getTestRE().getTestName().getAsString());
    assertEquals(myProject.getProjectId(), investigationWrapper.getAssignmentProject().getProjectId());
    myRequest.deleteInstance(investigationWrapper.getId());
    assertEmpty(myInvestigationFinder.getItems(null).myEntries);
}
Also used : Comment(jetbrains.buildServer.server.rest.model.Comment) InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) User(jetbrains.buildServer.server.rest.model.user.User) SUser(jetbrains.buildServer.users.SUser) ProblemTarget(jetbrains.buildServer.server.rest.model.buildType.ProblemTarget) SUser(jetbrains.buildServer.users.SUser) Tests(jetbrains.buildServer.server.rest.model.problem.Tests) ProblemScope(jetbrains.buildServer.server.rest.model.buildType.ProblemScope) Project(jetbrains.buildServer.server.rest.model.project.Project) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test) Investigation(jetbrains.buildServer.server.rest.model.buildType.Investigation) Resolution(jetbrains.buildServer.server.rest.model.problem.Resolution) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Aggregations

Project (jetbrains.buildServer.server.rest.model.project.Project)6 PropEntityProjectFeature (jetbrains.buildServer.server.rest.model.project.PropEntityProjectFeature)3 SProject (jetbrains.buildServer.serverSide.SProject)3 SUser (jetbrains.buildServer.users.SUser)3 NotNull (org.jetbrains.annotations.NotNull)3 Logger (com.intellij.openapi.diagnostic.Logger)2 ApiOperation (io.swagger.annotations.ApiOperation)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 BuildProject (jetbrains.buildServer.BuildProject)2 ServiceLocator (jetbrains.buildServer.ServiceLocator)2 APIController (jetbrains.buildServer.server.rest.APIController)2 AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)2 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)2 Fields (jetbrains.buildServer.server.rest.model.Fields)2 PagerData (jetbrains.buildServer.server.rest.model.PagerData)2 LocatorDimension (jetbrains.buildServer.server.rest.swagger.annotations.LocatorDimension)2 LocatorResource (jetbrains.buildServer.server.rest.swagger.annotations.LocatorResource)2 LocatorDimensionDataType (jetbrains.buildServer.server.rest.swagger.constants.LocatorDimensionDataType)2 LocatorName (jetbrains.buildServer.server.rest.swagger.constants.LocatorName)2