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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations